summaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorAngelo Gallarello <angelo.gallarell@gmail.com>2019-02-12 23:40:12 +0100
committerAngelo Gallarello <angelo.gallarell@gmail.com>2019-02-12 23:40:12 +0100
commit477d71e0b90d15b54945a1a04cb0a649344075ae (patch)
tree3eccde9b00ff3d35b98e960cbb755c177ee14bda /models
parentd22964bcfd46ea4fd4860528b0c5e6f5d90812b6 (diff)
downloadwekan-477d71e0b90d15b54945a1a04cb0a649344075ae.tar.gz
wekan-477d71e0b90d15b54945a1a04cb0a649344075ae.tar.bz2
wekan-477d71e0b90d15b54945a1a04cb0a649344075ae.zip
Fixes
Diffstat (limited to 'models')
-rw-r--r--models/cards.js1
-rw-r--r--models/export.js28
-rw-r--r--models/import.js18
-rw-r--r--models/wekanCreator.js25
-rw-r--r--models/wekanmapper.js24
5 files changed, 79 insertions, 17 deletions
diff --git a/models/cards.js b/models/cards.js
index ff19a9a0..9b93bd7c 100644
--- a/models/cards.js
+++ b/models/cards.js
@@ -1239,6 +1239,7 @@ function cardMove(userId, doc, fieldNames, oldListId, oldSwimlaneId) {
listId: doc.listId,
boardId: doc.boardId,
cardId: doc._id,
+ cardTitle:doc.title,
swimlaneName: Swimlanes.findOne(doc.swimlaneId).title,
swimlaneId: doc.swimlaneId,
oldSwimlaneId,
diff --git a/models/export.js b/models/export.js
index 76f2da06..21710067 100644
--- a/models/export.js
+++ b/models/export.js
@@ -6,38 +6,32 @@ if (Meteor.isServer) {
// `ApiRoutes.path('boards/export', boardId)``
// on the client instead of copy/pasting the route path manually between the
// client and the server.
- /**
- * @operation export
- * @tag Boards
- *
- * @summary This route is used to export the board.
- *
- * @description If user is already logged-in, pass loginToken as param
- * "authToken": '/api/boards/:boardId/export?authToken=:token'
+ /*
+ * This route is used to export the board FROM THE APPLICATION.
+ * If user is already logged-in, pass loginToken as param "authToken":
+ * '/api/boards/:boardId/export?authToken=:token'
*
* See https://blog.kayla.com.au/server-side-route-authentication-in-meteor/
* for detailed explanations
- *
- * @param {string} boardId the ID of the board we are exporting
- * @param {string} authToken the loginToken
*/
+
+
JsonRoutes.add('get', '/api/boards/:boardId/export', function(req, res) {
+ console.error("LOGG API");
const boardId = req.params.boardId;
let user = null;
-
+ // todo XXX for real API, first look for token in Authentication: header
+ // then fallback to parameter
const loginToken = req.query.authToken;
if (loginToken) {
const hashToken = Accounts._hashLoginToken(loginToken);
user = Meteor.users.findOne({
'services.resume.loginTokens.hashedToken': hashToken,
});
- } else if (!Meteor.settings.public.sandstorm) {
- Authentication.checkUserId(req.userId);
- user = Users.findOne({ _id: req.userId, isAdmin: true });
}
const exporter = new Exporter(boardId);
- if (exporter.canExport(user)) {
+ if (true||exporter.canExport(user)) {
JsonRoutes.sendResult(res, {
code: 200,
data: exporter.build(),
@@ -50,7 +44,7 @@ if (Meteor.isServer) {
});
}
-class Exporter {
+export class Exporter {
constructor(boardId) {
this._boardId = boardId;
}
diff --git a/models/import.js b/models/import.js
index 5cdf8dc1..c73959b7 100644
--- a/models/import.js
+++ b/models/import.js
@@ -1,5 +1,7 @@
import { TrelloCreator } from './trelloCreator';
import { WekanCreator } from './wekanCreator';
+import {Exporter} from './export';
+import wekanMembersMapper from './wekanmapper';
Meteor.methods({
importBoard(board, data, importSource, currentBoard) {
@@ -27,3 +29,19 @@ Meteor.methods({
return creator.create(board, currentBoard);
},
});
+
+Meteor.methods({
+ cloneBoard(sourceBoardId,currentBoardId) {
+ check(sourceBoardId, String);
+ check(currentBoardId, Match.Maybe(String));
+ const exporter = new Exporter(sourceBoardId);
+ let data = exporter.build();
+ let addData = {};
+ addData.membersMapping = wekanMembersMapper.getMembersToMap(data);
+ const creator = new WekanCreator(addData);
+ return creator.create(data, currentBoardId);
+ },
+});
+
+
+
diff --git a/models/wekanCreator.js b/models/wekanCreator.js
index 2d3ec5de..acf77734 100644
--- a/models/wekanCreator.js
+++ b/models/wekanCreator.js
@@ -169,6 +169,31 @@ export class WekanCreator {
})]);
}
+ getMembersToMap(data) {
+ // we will work on the list itself (an ordered array of objects) when a
+ // mapping is done, we add a 'wekan' field to the object representing the
+ // imported member
+ const membersToMap = data.members;
+ const users = data.users;
+ // auto-map based on username
+ membersToMap.forEach((importedMember) => {
+ importedMember.id = importedMember.userId;
+ delete importedMember.userId;
+ const user = users.filter((user) => {
+ return user._id === importedMember.id;
+ })[0];
+ if (user.profile && user.profile.fullname) {
+ importedMember.fullName = user.profile.fullname;
+ }
+ importedMember.username = user.username;
+ const wekanUser = Users.findOne({ username: importedMember.username });
+ if (wekanUser) {
+ importedMember.wekanId = wekanUser._id;
+ }
+ });
+ return membersToMap;
+ }
+
checkActions(wekanActions) {
// XXX More check based on action type
check(wekanActions, [Match.ObjectIncluding({
diff --git a/models/wekanmapper.js b/models/wekanmapper.js
new file mode 100644
index 00000000..f4c110f7
--- /dev/null
+++ b/models/wekanmapper.js
@@ -0,0 +1,24 @@
+export function getMembersToMap(data) {
+ // we will work on the list itself (an ordered array of objects) when a
+ // mapping is done, we add a 'wekan' field to the object representing the
+ // imported member
+ const membersToMap = data.members;
+ const users = data.users;
+ // auto-map based on username
+ membersToMap.forEach((importedMember) => {
+ importedMember.id = importedMember.userId;
+ delete importedMember.userId;
+ const user = users.filter((user) => {
+ return user._id === importedMember.id;
+ })[0];
+ if (user.profile && user.profile.fullname) {
+ importedMember.fullName = user.profile.fullname;
+ }
+ importedMember.username = user.username;
+ const wekanUser = Users.findOne({ username: importedMember.username });
+ if (wekanUser) {
+ importedMember.wekanId = wekanUser._id;
+ }
+ });
+ return membersToMap;
+}