mirror of
https://github.com/wekan/wekan.git
synced 2025-12-16 15:30:13 +01:00
export board to Wekan JSON
This commit is contained in:
parent
b719968df5
commit
f20b5d04f5
6 changed files with 61 additions and 0 deletions
|
|
@ -73,3 +73,4 @@ perak:markdown
|
||||||
seriousm:emoji-continued
|
seriousm:emoji-continued
|
||||||
templates:tabs
|
templates:tabs
|
||||||
verron:autosize
|
verron:autosize
|
||||||
|
simple:json-routes
|
||||||
|
|
|
||||||
|
|
@ -125,6 +125,7 @@ seriousm:emoji-continued@1.4.0
|
||||||
service-configuration@1.0.5
|
service-configuration@1.0.5
|
||||||
session@1.1.1
|
session@1.1.1
|
||||||
sha@1.0.4
|
sha@1.0.4
|
||||||
|
simple:json-routes@1.0.4
|
||||||
softwarerero:accounts-t9n@1.1.7
|
softwarerero:accounts-t9n@1.1.7
|
||||||
spacebars@1.0.7
|
spacebars@1.0.7
|
||||||
spacebars-compiler@1.0.7
|
spacebars-compiler@1.0.7
|
||||||
|
|
|
||||||
|
|
@ -56,6 +56,7 @@ template(name="boardMenuPopup")
|
||||||
if currentUser.isBoardAdmin
|
if currentUser.isBoardAdmin
|
||||||
hr
|
hr
|
||||||
ul.pop-over-list
|
ul.pop-over-list
|
||||||
|
li: a.js-export-board(href="{{urlExport}}", download) {{_ 'export-board'}}
|
||||||
li: a.js-archive-board {{_ 'archive-board'}}
|
li: a.js-archive-board {{_ 'archive-board'}}
|
||||||
|
|
||||||
template(name="boardVisibilityList")
|
template(name="boardVisibilityList")
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,12 @@ Template.boardMenuPopup.events({
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Template.boardMenuPopup.helpers({
|
||||||
|
urlExport() {
|
||||||
|
return Meteor.absoluteUrl(`api/b/${Session.get('currentBoard')}`);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
Template.boardChangeTitlePopup.events({
|
Template.boardChangeTitlePopup.events({
|
||||||
submit(evt, tpl) {
|
submit(evt, tpl) {
|
||||||
const newTitle = tpl.$('.js-board-name').val().trim();
|
const newTitle = tpl.$('.js-board-name').val().trim();
|
||||||
|
|
|
||||||
|
|
@ -147,6 +147,7 @@
|
||||||
"error-user-doesNotExist": "This user does not exist",
|
"error-user-doesNotExist": "This user does not exist",
|
||||||
"error-user-notAllowSelf": "This action on self is not allowed",
|
"error-user-notAllowSelf": "This action on self is not allowed",
|
||||||
"error-user-notCreated": "This user is not created",
|
"error-user-notCreated": "This user is not created",
|
||||||
|
"export-board": "Export board",
|
||||||
"filter": "Filter",
|
"filter": "Filter",
|
||||||
"filter-cards": "Filter Cards",
|
"filter-cards": "Filter Cards",
|
||||||
"filter-clear": "Clear filter",
|
"filter-clear": "Clear filter",
|
||||||
|
|
|
||||||
51
models/export.js
Normal file
51
models/export.js
Normal file
|
|
@ -0,0 +1,51 @@
|
||||||
|
/* global JsonRoutes */
|
||||||
|
JsonRoutes.add('get', '/api/b/:id', function (req, res) {
|
||||||
|
const id = req.params.id;
|
||||||
|
const exporter = new Exporter(id);
|
||||||
|
JsonRoutes.sendResult(res, 200, exporter.build());
|
||||||
|
});
|
||||||
|
|
||||||
|
class Exporter {
|
||||||
|
constructor(boardId) {
|
||||||
|
this._boardId = boardId;
|
||||||
|
}
|
||||||
|
|
||||||
|
build() {
|
||||||
|
const byBoard = {boardId: this._boardId};
|
||||||
|
const fields = {fields: {boardId: 0}};
|
||||||
|
const result = Boards.findOne(this._boardId);
|
||||||
|
result.lists = Lists.find(byBoard, fields).fetch();
|
||||||
|
result.cards = Cards.find(byBoard, fields).fetch();
|
||||||
|
result.comments = CardComments.find(byBoard, fields).fetch();
|
||||||
|
result.activities = Activities.find(byBoard, fields).fetch();
|
||||||
|
|
||||||
|
// we also have to export some user data - as the other elements only include id
|
||||||
|
// but we have to be careful:
|
||||||
|
// 1- only exports users that are linked somehow to that board
|
||||||
|
// 2- do not export any sensitive information
|
||||||
|
const users = {};
|
||||||
|
result.members.forEach((member) => {users[member.userId] = true;});
|
||||||
|
result.lists.forEach((list) => {users[list.userId] = true;});
|
||||||
|
result.cards.forEach((card) => {
|
||||||
|
users[card.userId] = true;
|
||||||
|
if (card.members) {
|
||||||
|
card.members.forEach((memberId) => {users[memberId] = true;});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
result.comments.forEach((comment) => {users[comment.userId] = true;});
|
||||||
|
result.activities.forEach((activity) => {users[activity.userId] = true;});
|
||||||
|
const byUserIds = {_id: {$in: Object.getOwnPropertyNames(users)}};
|
||||||
|
// we use whitelist to be sure we do not expose inadvertently
|
||||||
|
// some secret fields that gets added to User later.
|
||||||
|
const userFields = {fields: {
|
||||||
|
_id: 1,
|
||||||
|
username: 1,
|
||||||
|
'profile.fullname': 1,
|
||||||
|
'profile.initials': 1,
|
||||||
|
'profile.avatarUrl': 1,
|
||||||
|
}};
|
||||||
|
result.users = Users.find(byUserIds, userFields).fetch();
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue