Skip to content

Commit a5e04dd

Browse files
committed
Removing users works, needs more love though (see TODO)
1 parent 229e0ae commit a5e04dd

File tree

6 files changed

+39
-23
lines changed

6 files changed

+39
-23
lines changed

TODO

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
* show only ENABLED users
2+
* show all admin-privilledge projects
13
* AuthTT re-request
24
* better error handling
35
* visuals

lib/gooddata.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,12 @@ Client.prototype.inviteIntoProject = function(project, users, role, callback) {
140140
});
141141
});
142142
};
143-
Client.prototype.disableUsers = function(users) {
143+
Client.prototype.disableUsers = function(project, users, callback) {
144144
var json = {"users":[]};
145145
users.forEach(function(user) {
146146
json['users'].push({"user":{"content":{"status":"DISABLED"},"links":{"self":user}}});
147147
});
148-
return JSON.stringify(json);
148+
this.post(project+'/users', json, callback);
149149
};
150150
Client.prototype.processSetCookie = function(cookies) {
151151
var that = this;

public/css/style.css

+5
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,9 @@ body {
1111
#remove {
1212
display: none;
1313
margin-top: 20px;
14+
}
15+
16+
#removeUsers {
17+
position: absolute;
18+
left: 600px;
1419
}

server.js

+15-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ app.post('/login', function(req, res){
5151

5252
app.get('/projects', function(req, res) {
5353
var gdc = req.session['client'];
54-
if (!gdc) res.redirect('/');
54+
if (!gdc) res.redirect('/'); // if stored (logged-in) client found in session, redirect to login
5555
else {
5656

5757
if(req.session['projects']) {
@@ -105,6 +105,20 @@ app.post('/add', function(req, res) {
105105
}
106106
});
107107

108+
app.post('/remove', function(req, res) {
109+
var gdc = req.session['client'];
110+
if (!gdc) res.redirect('/');
111+
else {
112+
hash = JSON.parse(req.body.projects);
113+
Object.keys(hash).forEach(function(project) {
114+
gdc.disableUsers(project, hash[project], function(resp, data) {
115+
console.log('Disabled '+sys.inspect(hash[project])+' in '+project+' status: '+resp.statusCode);
116+
});
117+
});
118+
res.send('You\'ve asked me to kick the following users:'+sys.inspect(hash));
119+
}
120+
});
121+
108122
// Only listen on $ node app.js
109123

110124
var port = parseInt(process.env.PORT, 10) || 8000;

views/partials/projectOptions.ejs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<div class="project editable" data-project-uri="<%= project.project.links.self %>">
1+
<div class="project editable">
22
<label>
33
<input type="checkbox" name="projects[]" value="<%= project.project.links.self %>">
44
<%= project.project.meta.title %>

views/projects.ejs

+14-19
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
<h1>Invite user to multiple projects</h1>
22

3-
<form style="float: right">
3+
<form id="removeUsers" action="/remove" method="post" accept-charset="utf-8">
44
<div id="users"></div>
5-
<input type="button" name="remove" value="Remove Selected Users" id="remove">
5+
<input type="hidden" name="projects" value="" id="removeUsersFromProjects">
6+
<input type="submit" name="remove" value="Remove Selected Users" id="remove">
67
</form>
78

89
<form action="/add" method="post" accept-charset="utf-8" id="projects">
@@ -30,8 +31,7 @@
3031
var findUsers = function(elems) {
3132
var urls = [], obj = {}, emails = [];
3233
elems.each(function() {
33-
var parent = $(this).parents('.project');
34-
var uri = $(parent).attr('data-project-uri');
34+
var uri = $(this).val();
3535
if (urls.indexOf(uri) == -1) urls.push(uri);
3636
});
3737
@@ -43,37 +43,32 @@
4343
};
4444
4545
$('#projects .project label').mouseover(function() {
46-
$('#users').html(findUsers($('#projects input:checked').add(this)).join('<br>'));
47-
});
48-
49-
$('#users').delegate('label', 'click', function() {
50-
console.log('test');
51-
if ($('#users input:checked').size() > 0) $('#remove').show();
52-
else $('#remove').hide();
46+
$('#users').html(findUsers($('#projects input:checked').add($(this).children('input'))).join('<br>'));
5347
});
5448
5549
$('#projects input').change(function() {
5650
var elems = $('#projects input:checked');
5751
selectedMode = elems.size();
5852
var emails = findUsers(elems);
5953
$('#users').html(emails.join('<br>'));
60-
console.log($('#users label').size());
54+
});
55+
56+
$('#users').delegate('label', 'click', function() {
57+
if ($('#users input:checked').size() > 0) $('#remove').show();
58+
else $('#remove').hide();
6159
});
6260
6361
$('#remove').click(function() {
64-
var selectedUsers = {};
62+
var selectedUsers = {}, projectsHash = {};
6563
$('#users input:checked').each(function() { selectedUsers[$(this).val()] = []; });
6664
67-
var project, email;
65+
var projects, project, email;
6866
$('#projects input:checked').each(function() {
6967
project = $(this).val();
7068
// filter out users that were checked, send to Client.prototype.disableUsers
71-
users[project].forEach(function(projUser) {
72-
email = projUser.user.content.email;
73-
if (selectedUsers[email]) selectedUsers[email].push(project);
74-
});
69+
projectsHash[project] = users[project].filter(function(user) { return selectedUsers[user.user.content.email]; }).map(function(user) { return user.user.links.self; });
7570
});
76-
console.log(selectedUsers);
71+
$('#removeUsersFromProjects').val(JSON.stringify(projectsHash));
7772
});
7873
});
7974
</script>

0 commit comments

Comments
 (0)