summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsoohwa <none@none.none>2017-10-13 08:15:19 +0200
committersoohwa <none@none.none>2017-10-13 08:15:19 +0200
commit77d23df87fdbf44e879cd6c4670f804ad3fe9653 (patch)
treeb879eec5b5095da44d96111460e5d45477c1e272
parent3ab33ed82685f1ceb07cdb1a15d1330183115c58 (diff)
downloadwekan-77d23df87fdbf44e879cd6c4670f804ad3fe9653.tar.gz
wekan-77d23df87fdbf44e879cd6c4670f804ad3fe9653.tar.bz2
wekan-77d23df87fdbf44e879cd6c4670f804ad3fe9653.zip
Add the ability for the admin :
- disabling a login for a user (not himself) - enabling a login for a user - transfering the ownership of all user's boards to himself
-rw-r--r--models/boards.js11
-rw-r--r--models/users.js38
-rw-r--r--server/authentication.js5
3 files changed, 53 insertions, 1 deletions
diff --git a/models/boards.js b/models/boards.js
index 8a7844e2..cd633f56 100644
--- a/models/boards.js
+++ b/models/boards.js
@@ -298,6 +298,15 @@ Boards.mutations({
return { $pull: { labels: { _id: labelId } } };
},
+ changeOwnership(fromId, toId) {
+ const memberIndex = this.memberIndex(fromId);
+ return {
+ $set: {
+ [`members.${memberIndex}.userId`]: toId,
+ },
+ };
+ },
+
addMember(memberId) {
const memberIndex = this.memberIndex(memberId);
if (memberIndex >= 0) {
@@ -565,7 +574,7 @@ if (Meteor.isServer) {
const data = Boards.find({
archived: false,
- 'members.userId': req.userId,
+ 'members.userId': paramUserId,
}, {
sort: ['title'],
}).map(function(board) {
diff --git a/models/users.js b/models/users.js
index 3d4ff935..f11ec0db 100644
--- a/models/users.js
+++ b/models/users.js
@@ -112,6 +112,10 @@ Users.attachSchema(new SimpleSchema({
type: Boolean,
optional: true,
},
+ loginDisabled: {
+ type: Boolean,
+ optional: true,
+ },
}));
// Search a user in the complete server database by its name or username. This
@@ -597,6 +601,40 @@ if (Meteor.isServer) {
data: Meteor.users.findOne({ _id: id }),
});
});
+ JsonRoutes.add('PUT', '/api/users/:id', function (req, res, next) {
+ Authentication.checkUserId( req.userId);
+ const id = req.params.id;
+ const action = req.body.action;
+ var data = Meteor.users.findOne({ _id: id });
+ if (data != undefined) {
+ if (action === 'takeOwnership') {
+ data = Boards.find({
+ 'members.userId': id,
+ 'members.isAdmin': true,
+ }).map(function(board) {
+ if (board.hasMember(req.userId)) {
+ board.removeMember(req.userId);
+ }
+ board.changeOwnership(id, req.userId);
+ return {
+ _id: board._id,
+ title: board.title,
+ };
+ });
+ } else {
+ if ((action === 'disableLogin') && (id != req.userId)) {
+ Users.update({ _id: id }, { $set: { loginDisabled: true, 'services.resume.loginTokens': '' } });
+ } else if (action === 'enableLogin') {
+ Users.update({ _id: id }, { $set: { loginDisabled: '' } });
+ }
+ data = Meteor.users.findOne({ _id: id });
+ }
+ }
+ JsonRoutes.sendResult(res, {
+ code: 200,
+ data: data,
+ });
+ });
JsonRoutes.add('POST', '/api/users/', function (req, res, next) {
Authentication.checkUserId( req.userId);
const id = Accounts.createUser({
diff --git a/server/authentication.js b/server/authentication.js
index 23ed8f56..3dd1f478 100644
--- a/server/authentication.js
+++ b/server/authentication.js
@@ -1,4 +1,9 @@
Meteor.startup(() => {
+
+ Accounts.validateLoginAttempt(function (options) {
+ return !options.user.loginDisabled;
+ });
+
Authentication = {};
Authentication.checkUserId = function (userId) {