diff options
author | Lauri Ojansivu <x@xet7.org> | 2018-10-23 20:44:35 +0300 |
---|---|---|
committer | Lauri Ojansivu <x@xet7.org> | 2018-10-23 20:44:35 +0300 |
commit | 0de01356197d0317f538aa9a3c6e0213b5dfd396 (patch) | |
tree | 5a691082a3da622f0ccbef723f07619ed463b6e4 | |
parent | fa548a4c3266beaaa8da1049dc76602bfd3676e7 (diff) | |
parent | dfdba25ea0b9c3bcca81a9c8ba6a3e9ed7f4eec7 (diff) | |
download | wekan-0de01356197d0317f538aa9a3c6e0213b5dfd396.tar.gz wekan-0de01356197d0317f538aa9a3c6e0213b5dfd396.tar.bz2 wekan-0de01356197d0317f538aa9a3c6e0213b5dfd396.zip |
Merge branch 'api-fixes' of https://github.com/bentiss/wekan into bentiss-api-fixes
-rw-r--r-- | Dockerfile | 1 | ||||
-rw-r--r-- | models/boards.js | 44 | ||||
-rw-r--r-- | models/cards.js | 10 | ||||
-rw-r--r-- | models/customFields.js | 8 | ||||
-rw-r--r-- | models/export.js | 2 | ||||
-rw-r--r-- | models/users.js | 12 |
6 files changed, 63 insertions, 14 deletions
@@ -136,6 +136,7 @@ ENV BUILD_DEPS="apt-utils bsdtar gnupg gosu wget curl bzip2 build-essential pyth COPY ${SRC_PATH} /home/wekan/app RUN \ + set -o xtrace && \ # Add non-root user wekan useradd --user-group --system --home-dir /home/wekan wekan && \ \ diff --git a/models/boards.js b/models/boards.js index 52d0ca87..cae6cf9f 100644 --- a/models/boards.js +++ b/models/boards.js @@ -276,6 +276,10 @@ Boards.helpers({ return Users.find({ _id: { $in: _.pluck(this.members, 'userId') } }); }, + getMember(id) { + return _.findWhere(this.members, { userId: id }); + }, + getLabel(name, color) { return _.findWhere(this.labels, { name, color }); }, @@ -823,9 +827,9 @@ if (Meteor.isServer) { } }); - JsonRoutes.add('GET', '/api/boards/:id', function (req, res) { + JsonRoutes.add('GET', '/api/boards/:boardId', function (req, res) { try { - const id = req.params.id; + const id = req.params.boardId; Authentication.checkBoardAccess(req.userId, id); JsonRoutes.sendResult(res, { @@ -841,6 +845,34 @@ if (Meteor.isServer) { } }); + JsonRoutes.add('PUT', '/api/boards/:boardId/members', function (req, res) { + Authentication.checkUserId(req.userId); + try { + const boardId = req.params.boardId; + const board = Boards.findOne({ _id: boardId }); + const userId = req.body.userId; + const user = Users.findOne({ _id: userId }); + + if (!board.getMember(userId)) { + user.addInvite(boardId); + board.addMember(userId); + JsonRoutes.sendResult(res, { + code: 200, + data: id, + }); + } else { + JsonRoutes.sendResult(res, { + code: 200, + }); + } + } + catch (error) { + JsonRoutes.sendResult(res, { + data: error, + }); + } + }); + JsonRoutes.add('POST', '/api/boards', function (req, res) { try { Authentication.checkUserId(req.userId); @@ -878,10 +910,10 @@ if (Meteor.isServer) { } }); - JsonRoutes.add('DELETE', '/api/boards/:id', function (req, res) { + JsonRoutes.add('DELETE', '/api/boards/:boardId', function (req, res) { try { Authentication.checkUserId(req.userId); - const id = req.params.id; + const id = req.params.boardId; Boards.remove({ _id: id }); JsonRoutes.sendResult(res, { code: 200, @@ -898,9 +930,9 @@ if (Meteor.isServer) { } }); - JsonRoutes.add('PUT', '/api/boards/:id/labels', function (req, res) { + JsonRoutes.add('PUT', '/api/boards/:boardId/labels', function (req, res) { Authentication.checkUserId(req.userId); - const id = req.params.id; + const id = req.params.boardId; try { if (req.body.hasOwnProperty('label')) { const board = Boards.findOne({ _id: id }); diff --git a/models/cards.js b/models/cards.js index 25692c25..9bb67f41 100644 --- a/models/cards.js +++ b/models/cards.js @@ -1514,6 +1514,16 @@ if (Meteor.isServer) { Cards.direct.update({_id: paramCardId, listId: paramListId, boardId: paramBoardId, archived: false}, {$set: {customFields: newcustomFields}}); } + if (req.body.hasOwnProperty('members')) { + const newmembers = req.body.members; + Cards.direct.update({_id: paramCardId, listId: paramListId, boardId: paramBoardId, archived: false}, + {$set: {members: newmembers}}); + } + if (req.body.hasOwnProperty('swimlaneId')) { + const newParamSwimlaneId = req.body.swimlaneId; + Cards.direct.update({_id: paramCardId, listId: paramListId, boardId: paramBoardId, archived: false}, + {$set: {swimlaneId: newParamSwimlaneId}}); + } JsonRoutes.sendResult(res, { code: 200, data: { diff --git a/models/customFields.js b/models/customFields.js index 38481d8c..203e46d0 100644 --- a/models/customFields.js +++ b/models/customFields.js @@ -87,7 +87,13 @@ if (Meteor.isServer) { const paramBoardId = req.params.boardId; JsonRoutes.sendResult(res, { code: 200, - data: CustomFields.find({ boardId: paramBoardId }), + data: CustomFields.find({ boardId: paramBoardId }).map(function (cf) { + return { + _id: cf._id, + name: cf.name, + type: cf.type, + }; + }), }); }); diff --git a/models/export.js b/models/export.js index 0911a631..62d2687a 100644 --- a/models/export.js +++ b/models/export.js @@ -48,7 +48,7 @@ class Exporter { build() { const byBoard = { boardId: this._boardId }; - const byBoardNoLinked = { boardId: this._boardId, linkedId: '' }; + const byBoardNoLinked = { boardId: this._boardId, linkedId: {$in: ['', null] } }; // we do not want to retrieve boardId in related elements const noBoardId = { fields: { diff --git a/models/users.js b/models/users.js index 4f2184e4..630f4703 100644 --- a/models/users.js +++ b/models/users.js @@ -713,10 +713,10 @@ if (Meteor.isServer) { } }); - JsonRoutes.add('GET', '/api/users/:id', function (req, res) { + JsonRoutes.add('GET', '/api/users/:userId', function (req, res) { try { Authentication.checkUserId(req.userId); - const id = req.params.id; + const id = req.params.userId; JsonRoutes.sendResult(res, { code: 200, data: Meteor.users.findOne({ _id: id }), @@ -730,10 +730,10 @@ if (Meteor.isServer) { } }); - JsonRoutes.add('PUT', '/api/users/:id', function (req, res) { + JsonRoutes.add('PUT', '/api/users/:userId', function (req, res) { try { Authentication.checkUserId(req.userId); - const id = req.params.id; + const id = req.params.userId; const action = req.body.action; let data = Meteor.users.findOne({ _id: id }); if (data !== undefined) { @@ -872,10 +872,10 @@ if (Meteor.isServer) { } }); - JsonRoutes.add('DELETE', '/api/users/:id', function (req, res) { + JsonRoutes.add('DELETE', '/api/users/:userId', function (req, res) { try { Authentication.checkUserId(req.userId); - const id = req.params.id; + const id = req.params.userId; Meteor.users.remove({ _id: id }); JsonRoutes.sendResult(res, { code: 200, |