mirror of
https://github.com/wekan/wekan.git
synced 2025-12-18 00:10:13 +01:00
REST API better error output. Thanks to soohwa ! Related #1037
This commit is contained in:
commit
c01335ee29
7 changed files with 609 additions and 366 deletions
|
|
@ -3,7 +3,8 @@
|
|||
This release adds the following new features:
|
||||
|
||||
* [Markdown in card/minicard/checlist titles and checklist items. Next line: Shift+Enter. Submit: Enter.](https://github.com/wekan/wekan/pull/1334);
|
||||
* [User Admin to Admin Panel: List users. Change: is user admin, name, fullname, email address, is user active. Not changing password yet.](https://github.com/wekan/wekan/pull/1325).
|
||||
* [User Admin to Admin Panel: List users. Change: is user admin, name, fullname, email address, is user active. Not changing password yet.](https://github.com/wekan/wekan/pull/1325);
|
||||
* [REST API better error output](https://github.com/wekan/wekan/pull/1323).
|
||||
|
||||
and fixes the following bugs:
|
||||
|
||||
|
|
@ -12,7 +13,7 @@ and fixes the following bugs:
|
|||
* [Whitespace trimming breaks Markdown code block indentation](https://github.com/wekan/wekan/issues/1288):
|
||||
* [Helper to list boards for user](https://github.com/wekan/wekan/pull/1327).
|
||||
|
||||
Thanks to Github users brooksbecton, milesibastos, thuanpq and xet7 for their contributions.
|
||||
Thanks to Github users brooksbecton, milesibastos, soohwa, thuanpq and xet7 for their contributions.
|
||||
|
||||
# v0.54 2017-11-02 Wekan release
|
||||
|
||||
|
|
|
|||
|
|
@ -566,6 +566,7 @@ if (Meteor.isServer) {
|
|||
//BOARDS REST API
|
||||
if (Meteor.isServer) {
|
||||
JsonRoutes.add('GET', '/api/users/:userId/boards', function (req, res, next) {
|
||||
try {
|
||||
Authentication.checkLoggedIn(req.userId);
|
||||
const paramUserId = req.params.userId;
|
||||
// A normal user should be able to see their own boards,
|
||||
|
|
@ -585,9 +586,17 @@ if (Meteor.isServer) {
|
|||
});
|
||||
|
||||
JsonRoutes.sendResult(res, {code: 200, data});
|
||||
}
|
||||
catch (error) {
|
||||
JsonRoutes.sendResult(res, {
|
||||
code: 200,
|
||||
data: error,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
JsonRoutes.add('GET', '/api/boards', function (req, res, next) {
|
||||
try {
|
||||
Authentication.checkUserId(req.userId);
|
||||
JsonRoutes.sendResult(res, {
|
||||
code: 200,
|
||||
|
|
@ -598,9 +607,17 @@ if (Meteor.isServer) {
|
|||
};
|
||||
}),
|
||||
});
|
||||
}
|
||||
catch (error) {
|
||||
JsonRoutes.sendResult(res, {
|
||||
code: 200,
|
||||
data: error,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
JsonRoutes.add('GET', '/api/boards/:id', function (req, res, next) {
|
||||
try {
|
||||
const id = req.params.id;
|
||||
Authentication.checkBoardAccess(req.userId, id);
|
||||
|
||||
|
|
@ -608,9 +625,17 @@ if (Meteor.isServer) {
|
|||
code: 200,
|
||||
data: Boards.findOne({ _id: id }),
|
||||
});
|
||||
}
|
||||
catch (error) {
|
||||
JsonRoutes.sendResult(res, {
|
||||
code: 200,
|
||||
data: error,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
JsonRoutes.add('POST', '/api/boards', function (req, res, next) {
|
||||
try {
|
||||
Authentication.checkUserId(req.userId);
|
||||
const id = Boards.insert({
|
||||
title: req.body.title,
|
||||
|
|
@ -631,9 +656,17 @@ if (Meteor.isServer) {
|
|||
_id: id,
|
||||
},
|
||||
});
|
||||
}
|
||||
catch (error) {
|
||||
JsonRoutes.sendResult(res, {
|
||||
code: 200,
|
||||
data: error,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
JsonRoutes.add('DELETE', '/api/boards/:id', function (req, res, next) {
|
||||
try {
|
||||
Authentication.checkUserId(req.userId);
|
||||
const id = req.params.id;
|
||||
Boards.remove({ _id: id });
|
||||
|
|
@ -643,5 +676,12 @@ if (Meteor.isServer) {
|
|||
_id: id,
|
||||
},
|
||||
});
|
||||
}
|
||||
catch (error) {
|
||||
JsonRoutes.sendResult(res, {
|
||||
code: 200,
|
||||
data: error,
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -88,6 +88,7 @@ if (Meteor.isServer) {
|
|||
//CARD COMMENT REST API
|
||||
if (Meteor.isServer) {
|
||||
JsonRoutes.add('GET', '/api/boards/:boardId/cards/:cardId/comments', function (req, res, next) {
|
||||
try {
|
||||
Authentication.checkUserId( req.userId);
|
||||
const paramBoardId = req.params.boardId;
|
||||
const paramCardId = req.params.cardId;
|
||||
|
|
@ -101,9 +102,17 @@ if (Meteor.isServer) {
|
|||
};
|
||||
}),
|
||||
});
|
||||
}
|
||||
catch (error) {
|
||||
JsonRoutes.sendResult(res, {
|
||||
code: 200,
|
||||
data: error,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
JsonRoutes.add('GET', '/api/boards/:boardId/cards/:cardId/comments/:commentId', function (req, res, next) {
|
||||
try {
|
||||
Authentication.checkUserId( req.userId);
|
||||
const paramBoardId = req.params.boardId;
|
||||
const paramCommentId = req.params.commentId;
|
||||
|
|
@ -112,9 +121,17 @@ if (Meteor.isServer) {
|
|||
code: 200,
|
||||
data: CardComments.findOne({ _id: paramCommentId, cardId: paramCardId, boardId: paramBoardId }),
|
||||
});
|
||||
}
|
||||
catch (error) {
|
||||
JsonRoutes.sendResult(res, {
|
||||
code: 200,
|
||||
data: error,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
JsonRoutes.add('POST', '/api/boards/:boardId/cards/:cardId/comments', function (req, res, next) {
|
||||
try {
|
||||
Authentication.checkUserId( req.userId);
|
||||
const paramBoardId = req.params.boardId;
|
||||
const paramCardId = req.params.cardId;
|
||||
|
|
@ -134,9 +151,17 @@ if (Meteor.isServer) {
|
|||
|
||||
const cardComment = CardComments.findOne({_id: id, cardId:paramCardId, boardId: paramBoardId });
|
||||
commentCreation(req.body.authorId, cardComment);
|
||||
}
|
||||
catch (error) {
|
||||
JsonRoutes.sendResult(res, {
|
||||
code: 200,
|
||||
data: error,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
JsonRoutes.add('DELETE', '/api/boards/:boardId/cards/:cardId/comments/:commentId', function (req, res, next) {
|
||||
try {
|
||||
Authentication.checkUserId( req.userId);
|
||||
const paramBoardId = req.params.boardId;
|
||||
const paramCommentId = req.params.commentId;
|
||||
|
|
@ -148,5 +173,12 @@ if (Meteor.isServer) {
|
|||
_id: paramCardId,
|
||||
},
|
||||
});
|
||||
}
|
||||
catch (error) {
|
||||
JsonRoutes.sendResult(res, {
|
||||
code: 200,
|
||||
data: error,
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -259,6 +259,7 @@ if (Meteor.isServer) {
|
|||
//CARD COMMENT REST API
|
||||
if (Meteor.isServer) {
|
||||
JsonRoutes.add('GET', '/api/boards/:boardId/cards/:cardId/checklists', function (req, res, next) {
|
||||
try {
|
||||
Authentication.checkUserId( req.userId);
|
||||
const paramCardId = req.params.cardId;
|
||||
JsonRoutes.sendResult(res, {
|
||||
|
|
@ -270,9 +271,17 @@ if (Meteor.isServer) {
|
|||
};
|
||||
}),
|
||||
});
|
||||
}
|
||||
catch (error) {
|
||||
JsonRoutes.sendResult(res, {
|
||||
code: 200,
|
||||
data: error,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
JsonRoutes.add('GET', '/api/boards/:boardId/cards/:cardId/checklists/:checklistId', function (req, res, next) {
|
||||
try {
|
||||
Authentication.checkUserId( req.userId);
|
||||
const paramChecklistId = req.params.checklistId;
|
||||
const paramCardId = req.params.cardId;
|
||||
|
|
@ -280,9 +289,17 @@ if (Meteor.isServer) {
|
|||
code: 200,
|
||||
data: Checklists.findOne({ _id: paramChecklistId, cardId: paramCardId }),
|
||||
});
|
||||
}
|
||||
catch (error) {
|
||||
JsonRoutes.sendResult(res, {
|
||||
code: 200,
|
||||
data: error,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
JsonRoutes.add('POST', '/api/boards/:boardId/cards/:cardId/checklists', function (req, res, next) {
|
||||
try {
|
||||
Authentication.checkUserId( req.userId);
|
||||
const paramCardId = req.params.cardId;
|
||||
|
||||
|
|
@ -303,9 +320,17 @@ if (Meteor.isServer) {
|
|||
_id: id,
|
||||
},
|
||||
});
|
||||
}
|
||||
catch (error) {
|
||||
JsonRoutes.sendResult(res, {
|
||||
code: 200,
|
||||
data: error,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
JsonRoutes.add('DELETE', '/api/boards/:boardId/cards/:cardId/checklists/:checklistId', function (req, res, next) {
|
||||
try {
|
||||
Authentication.checkUserId( req.userId);
|
||||
const paramCommentId = req.params.commentId;
|
||||
const paramCardId = req.params.cardId;
|
||||
|
|
@ -316,5 +341,12 @@ if (Meteor.isServer) {
|
|||
_id: paramCardId,
|
||||
},
|
||||
});
|
||||
}
|
||||
catch (error) {
|
||||
JsonRoutes.sendResult(res, {
|
||||
code: 200,
|
||||
data: error,
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -60,6 +60,7 @@ Integrations.allow({
|
|||
if (Meteor.isServer) {
|
||||
// Get all integrations in board
|
||||
JsonRoutes.add('GET', '/api/boards/:boardId/integrations', function(req, res, next) {
|
||||
try {
|
||||
const paramBoardId = req.params.boardId;
|
||||
Authentication.checkBoardAccess(req.userId, paramBoardId);
|
||||
|
||||
|
|
@ -68,10 +69,18 @@ if (Meteor.isServer) {
|
|||
});
|
||||
|
||||
JsonRoutes.sendResult(res, {code: 200, data});
|
||||
}
|
||||
catch (error) {
|
||||
JsonRoutes.sendResult(res, {
|
||||
code: 200,
|
||||
data: error,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Get a single integration in board
|
||||
JsonRoutes.add('GET', '/api/boards/:boardId/integrations/:intId', function(req, res, next) {
|
||||
try {
|
||||
const paramBoardId = req.params.boardId;
|
||||
const paramIntId = req.params.intId;
|
||||
Authentication.checkBoardAccess(req.userId, paramBoardId);
|
||||
|
|
@ -80,10 +89,18 @@ if (Meteor.isServer) {
|
|||
code: 200,
|
||||
data: Integrations.findOne({ _id: paramIntId, boardId: paramBoardId }, { fields: { token: 0 } }),
|
||||
});
|
||||
}
|
||||
catch (error) {
|
||||
JsonRoutes.sendResult(res, {
|
||||
code: 200,
|
||||
data: error,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Create a new integration
|
||||
JsonRoutes.add('POST', '/api/boards/:boardId/integrations', function(req, res, next) {
|
||||
try {
|
||||
const paramBoardId = req.params.boardId;
|
||||
Authentication.checkBoardAccess(req.userId, paramBoardId);
|
||||
|
||||
|
|
@ -99,10 +116,18 @@ if (Meteor.isServer) {
|
|||
_id: id,
|
||||
},
|
||||
});
|
||||
}
|
||||
catch (error) {
|
||||
JsonRoutes.sendResult(res, {
|
||||
code: 200,
|
||||
data: error,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Edit integration data
|
||||
JsonRoutes.add('PUT', '/api/boards/:boardId/integrations/:intId', function (req, res, next) {
|
||||
try {
|
||||
const paramBoardId = req.params.boardId;
|
||||
const paramIntId = req.params.intId;
|
||||
Authentication.checkBoardAccess(req.userId, paramBoardId);
|
||||
|
|
@ -139,10 +164,18 @@ if (Meteor.isServer) {
|
|||
_id: paramIntId,
|
||||
},
|
||||
});
|
||||
}
|
||||
catch (error) {
|
||||
JsonRoutes.sendResult(res, {
|
||||
code: 200,
|
||||
data: error,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Delete subscribed activities
|
||||
JsonRoutes.add('DELETE', '/api/boards/:boardId/integrations/:intId/activities', function (req, res, next) {
|
||||
try {
|
||||
const paramBoardId = req.params.boardId;
|
||||
const paramIntId = req.params.intId;
|
||||
const newActivities = req.body.activities;
|
||||
|
|
@ -155,10 +188,18 @@ if (Meteor.isServer) {
|
|||
code: 200,
|
||||
data: Integrations.findOne({_id: paramIntId, boardId: paramBoardId}, { fields: {_id: 1, activities: 1}}),
|
||||
});
|
||||
}
|
||||
catch (error) {
|
||||
JsonRoutes.sendResult(res, {
|
||||
code: 200,
|
||||
data: error,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Add subscribed activities
|
||||
JsonRoutes.add('POST', '/api/boards/:boardId/integrations/:intId/activities', function (req, res, next) {
|
||||
try {
|
||||
const paramBoardId = req.params.boardId;
|
||||
const paramIntId = req.params.intId;
|
||||
const newActivities = req.body.activities;
|
||||
|
|
@ -171,10 +212,18 @@ if (Meteor.isServer) {
|
|||
code: 200,
|
||||
data: Integrations.findOne({_id: paramIntId, boardId: paramBoardId}, { fields: {_id: 1, activities: 1}}),
|
||||
});
|
||||
}
|
||||
catch (error) {
|
||||
JsonRoutes.sendResult(res, {
|
||||
code: 200,
|
||||
data: error,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Delete integration
|
||||
JsonRoutes.add('DELETE', '/api/boards/:boardId/integrations/:intId', function (req, res, next) {
|
||||
try {
|
||||
const paramBoardId = req.params.boardId;
|
||||
const paramIntId = req.params.intId;
|
||||
Authentication.checkBoardAccess(req.userId, paramBoardId);
|
||||
|
|
@ -186,5 +235,12 @@ if (Meteor.isServer) {
|
|||
_id: paramIntId,
|
||||
},
|
||||
});
|
||||
}
|
||||
catch (error) {
|
||||
JsonRoutes.sendResult(res, {
|
||||
code: 200,
|
||||
data: error,
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -198,6 +198,7 @@ if (Meteor.isServer) {
|
|||
//LISTS REST API
|
||||
if (Meteor.isServer) {
|
||||
JsonRoutes.add('GET', '/api/boards/:boardId/lists', function (req, res, next) {
|
||||
try {
|
||||
const paramBoardId = req.params.boardId;
|
||||
Authentication.checkBoardAccess( req.userId, paramBoardId);
|
||||
|
||||
|
|
@ -210,9 +211,17 @@ if (Meteor.isServer) {
|
|||
};
|
||||
}),
|
||||
});
|
||||
}
|
||||
catch (error) {
|
||||
JsonRoutes.sendResult(res, {
|
||||
code: 200,
|
||||
data: error,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
JsonRoutes.add('GET', '/api/boards/:boardId/lists/:listId', function (req, res, next) {
|
||||
try {
|
||||
const paramBoardId = req.params.boardId;
|
||||
const paramListId = req.params.listId;
|
||||
Authentication.checkBoardAccess( req.userId, paramBoardId);
|
||||
|
|
@ -220,9 +229,17 @@ if (Meteor.isServer) {
|
|||
code: 200,
|
||||
data: Lists.findOne({ _id: paramListId, boardId: paramBoardId, archived: false }),
|
||||
});
|
||||
}
|
||||
catch (error) {
|
||||
JsonRoutes.sendResult(res, {
|
||||
code: 200,
|
||||
data: error,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
JsonRoutes.add('POST', '/api/boards/:boardId/lists', function (req, res, next) {
|
||||
try {
|
||||
Authentication.checkUserId( req.userId);
|
||||
const paramBoardId = req.params.boardId;
|
||||
const id = Lists.insert({
|
||||
|
|
@ -235,9 +252,17 @@ if (Meteor.isServer) {
|
|||
_id: id,
|
||||
},
|
||||
});
|
||||
}
|
||||
catch (error) {
|
||||
JsonRoutes.sendResult(res, {
|
||||
code: 200,
|
||||
data: error,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
JsonRoutes.add('DELETE', '/api/boards/:boardId/lists/:listId', function (req, res, next) {
|
||||
try {
|
||||
Authentication.checkUserId( req.userId);
|
||||
const paramBoardId = req.params.boardId;
|
||||
const paramListId = req.params.listId;
|
||||
|
|
@ -248,6 +273,13 @@ if (Meteor.isServer) {
|
|||
_id: paramListId,
|
||||
},
|
||||
});
|
||||
}
|
||||
catch (error) {
|
||||
JsonRoutes.sendResult(res, {
|
||||
code: 200,
|
||||
data: error,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -589,6 +589,7 @@ if (Meteor.isServer) {
|
|||
// USERS REST API
|
||||
if (Meteor.isServer) {
|
||||
JsonRoutes.add('GET', '/api/user', function(req, res, next) {
|
||||
try {
|
||||
Authentication.checkLoggedIn(req.userId);
|
||||
const data = Meteor.users.findOne({ _id: req.userId});
|
||||
delete data.services;
|
||||
|
|
@ -596,9 +597,17 @@ if (Meteor.isServer) {
|
|||
code: 200,
|
||||
data,
|
||||
});
|
||||
}
|
||||
catch (error) {
|
||||
JsonRoutes.sendResult(res, {
|
||||
code: 200,
|
||||
data: error,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
JsonRoutes.add('GET', '/api/users', function (req, res, next) {
|
||||
try {
|
||||
Authentication.checkUserId(req.userId);
|
||||
JsonRoutes.sendResult(res, {
|
||||
code: 200,
|
||||
|
|
@ -606,16 +615,34 @@ if (Meteor.isServer) {
|
|||
return { _id: doc._id, username: doc.username };
|
||||
}),
|
||||
});
|
||||
}
|
||||
catch (error) {
|
||||
JsonRoutes.sendResult(res, {
|
||||
code: 200,
|
||||
data: error,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
JsonRoutes.add('GET', '/api/users/:id', function (req, res, next) {
|
||||
try {
|
||||
Authentication.checkUserId(req.userId);
|
||||
const id = req.params.id;
|
||||
JsonRoutes.sendResult(res, {
|
||||
code: 200,
|
||||
data: Meteor.users.findOne({ _id: id }),
|
||||
});
|
||||
}
|
||||
catch (error) {
|
||||
JsonRoutes.sendResult(res, {
|
||||
code: 200,
|
||||
data: error,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
JsonRoutes.add('PUT', '/api/users/:id', function (req, res, next) {
|
||||
try {
|
||||
Authentication.checkUserId(req.userId);
|
||||
const id = req.params.id;
|
||||
const action = req.body.action;
|
||||
|
|
@ -648,8 +675,17 @@ if (Meteor.isServer) {
|
|||
code: 200,
|
||||
data,
|
||||
});
|
||||
}
|
||||
catch (error) {
|
||||
JsonRoutes.sendResult(res, {
|
||||
code: 200,
|
||||
data: error,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
JsonRoutes.add('POST', '/api/users/', function (req, res, next) {
|
||||
try {
|
||||
Authentication.checkUserId(req.userId);
|
||||
const id = Accounts.createUser({
|
||||
username: req.body.username,
|
||||
|
|
@ -657,16 +693,23 @@ if (Meteor.isServer) {
|
|||
password: req.body.password,
|
||||
from: 'admin',
|
||||
});
|
||||
|
||||
JsonRoutes.sendResult(res, {
|
||||
code: 200,
|
||||
data: {
|
||||
_id: id,
|
||||
},
|
||||
});
|
||||
}
|
||||
catch (error) {
|
||||
JsonRoutes.sendResult(res, {
|
||||
code: 200,
|
||||
data: error,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
JsonRoutes.add('DELETE', '/api/users/:id', function (req, res, next) {
|
||||
try {
|
||||
Authentication.checkUserId(req.userId);
|
||||
const id = req.params.id;
|
||||
Meteor.users.remove({ _id: id });
|
||||
|
|
@ -676,6 +719,13 @@ if (Meteor.isServer) {
|
|||
_id: id,
|
||||
},
|
||||
});
|
||||
}
|
||||
catch (error) {
|
||||
JsonRoutes.sendResult(res, {
|
||||
code: 200,
|
||||
data: error,
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue