From 8bf2ead240f5daeac98b3a92c81f37b77fd4ddbd Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Thu, 4 Sep 2014 16:24:00 -0400 Subject: make users admins --- public/assets/javascripts/ui/site/StaffView.js | 29 ++++++++++- server/lib/views/staff.js | 22 ++++---- views/staff/_header.ejs | 1 + views/staff/_users.ejs | 6 +++ views/staff/_users_recent.ejs | 8 +++ views/staff/users/show.ejs | 70 ++++++++++++++++++++++++++ 6 files changed, 125 insertions(+), 11 deletions(-) diff --git a/public/assets/javascripts/ui/site/StaffView.js b/public/assets/javascripts/ui/site/StaffView.js index 115d417..8f677cb 100644 --- a/public/assets/javascripts/ui/site/StaffView.js +++ b/public/assets/javascripts/ui/site/StaffView.js @@ -1,6 +1,15 @@ var StaffView = View.extend({ + el: ".page", + + events: { + "click #toggle-staff": "toggleStaff", + }, initialize: function() { + this.$toggleStaff = $("#toggle-staff") + if (this.$toggleStaff.data().isstaff) { + this.$toggleStaff.html("Is Staff") + } }, load: function() { @@ -9,6 +18,24 @@ var StaffView = View.extend({ }) this.projectList = new ProjectList () - } + }, + + toggleStaff: function(){ + var state = ! this.$toggleStaff.data().isstaff + $.ajax({ + type: "put", + dataType: "json", + url: window.location.href + "/bless", + data: { + state: state, + _csrf: $("#_csrf").val(), + }, + success: function(data){ + this.$toggleStaff.data("isstaff", data.state) + this.$toggleStaff.html(data.state ? "Is Staff" : "Make Staff") + $("#is-staff").html(data.state ? "yes" : "no") + }.bind(this) + }) + }, }) diff --git a/server/lib/views/staff.js b/server/lib/views/staff.js index ae414d7..b78fd5a 100644 --- a/server/lib/views/staff.js +++ b/server/lib/views/staff.js @@ -111,7 +111,7 @@ var staff = module.exports = { if (username) { User.findOne({ username: username }, function (err, user) { if (user) { - res.locals.profile = staff.helpers.user(user) + res.locals.profile = req.method == "GET" ? staff.helpers.user(user) : user } else { res.locals.profile = null @@ -236,6 +236,14 @@ var staff = module.exports = { staff.users.show ); + app.put('/staff/users/:username/bless', + middleware.ensureAuthenticated, + middleware.ensureIsStaff, + + staff.middleware.ensureProfile, + + staff.users.bless + ); app.get('/staff/projects', middleware.ensureAuthenticated, middleware.ensureIsStaff, @@ -259,12 +267,6 @@ var staff = module.exports = { staff.projects.show ); - app.put('/staff/users/:username/bless', - middleware.ensureAuthenticated, - middleware.ensureIsStaff, - - staff.users.bless - ); }, index: function(req, res){ @@ -288,9 +290,9 @@ var staff = module.exports = { } }, bless: function(req, res){ - res.locals.profile.isStaff = req.body.isStaff - res.locals.profile.save(function(){ - res.redirect("/staff") + res.locals.profile.isStaff = req.body.state == "true" + res.locals.profile.save(function(err, user){ + res.json({ state: user.isStaff }) }) }, }, diff --git a/views/staff/_header.ejs b/views/staff/_header.ejs index 1880c98..3bbf4f1 100644 --- a/views/staff/_header.ejs +++ b/views/staff/_header.ejs @@ -5,6 +5,7 @@ [[ include ../partials/meta ]] +
diff --git a/views/staff/_users.ejs b/views/staff/_users.ejs index ab8c9b3..344ee0c 100644 --- a/views/staff/_users.ejs +++ b/views/staff/_users.ejs @@ -1,12 +1,18 @@ [[ users.forEach(function(user){ ]] + + diff --git a/views/staff/_users_recent.ejs b/views/staff/_users_recent.ejs index ff3fd55..e55fe28 100644 --- a/views/staff/_users_recent.ejs +++ b/views/staff/_users_recent.ejs @@ -6,9 +6,17 @@ [[ users.forEach(function(user){ ]] + + diff --git a/views/staff/users/show.ejs b/views/staff/users/show.ejs index d306443..2315043 100644 --- a/views/staff/users/show.ejs +++ b/views/staff/users/show.ejs @@ -9,8 +9,78 @@
+
+
+
[[- user.username ]] [[- user.displayName ]] [[- user.last_seen ]]
+ [[ if (user.photo) { ]] +
+ [[ } ]] +
[[- user.username ]] [[- user.displayName ]]
+ + + + + + +
+
+
+ [[- profile.username ]] + + [[- profile.displayName ]] +
+
+ + + + + + + + + + + + + + + + + + + + + + +
+ location + + [[- profile.location ]] +
+ last seen + + [[- profile.last_seen ]] +
+ ip addresses + + [[- profile.created_ip ]] + [[- profile.last_ip ]] +
+ is admin? + + [[- profile.isStaff ? "yes" : "no" ]] +
+ + [[ if (String(user._id) != String(profile._id)) { ]] + + [[ } ]] +
+

[[- profileJSON ]]
[[ include ../_footer ]] + \ No newline at end of file -- cgit v1.2.3-70-g09d2