diff options
author | Lauri Ojansivu <x@xet7.org> | 2017-10-16 18:43:22 +0300 |
---|---|---|
committer | Lauri Ojansivu <x@xet7.org> | 2017-10-16 18:43:22 +0300 |
commit | 0d7c1501ce1df3bb7687b6d148502c769c37df81 (patch) | |
tree | ecc0f52df26c815610cf757991a60342647aad0e /models/users.js | |
parent | 93d8a3f88a01fe4f51f36b5d0a5b7365a3d7d294 (diff) | |
parent | 624719974e578caa92217bb51d67a0a307f35ce6 (diff) | |
download | wekan-0d7c1501ce1df3bb7687b6d148502c769c37df81.tar.gz wekan-0d7c1501ce1df3bb7687b6d148502c769c37df81.tar.bz2 wekan-0d7c1501ce1df3bb7687b6d148502c769c37df81.zip |
Merge branch '1285-feature-disable-user' of https://github.com/soohwa/wekan into soohwa-1285-feature-disable-user
Diffstat (limited to 'models/users.js')
-rw-r--r-- | models/users.js | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/models/users.js b/models/users.js index 3d4ff935..abc0f82d 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; + let 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, + }); + }); JsonRoutes.add('POST', '/api/users/', function (req, res, next) { Authentication.checkUserId( req.userId); const id = Accounts.createUser({ |