2023-11-07 19:07:06 +01:00
|
|
|
import { ReactiveCache, ReactiveMiniMongoIndex } from '/imports/reactiveCache';
|
2020-04-08 11:54:00 -06:00
|
|
|
import { SyncedCron } from 'meteor/percolate:synced-cron';
|
2021-07-10 10:55:54 +02:00
|
|
|
import { TAPi18n } from '/imports/i18n';
|
2021-05-29 00:19:12 +03:00
|
|
|
import ImpersonatedUsers from './impersonatedUsers';
|
2022-09-21 14:33:17 +02:00
|
|
|
import { Index, MongoDBEngine } from 'meteor/easy:search';
|
2020-04-08 11:54:00 -06:00
|
|
|
|
2016-07-11 15:21:19 -07:00
|
|
|
// Sandstorm context is detected using the METEOR_SETTINGS environment variable
|
|
|
|
// in the package definition.
|
2019-06-26 17:47:27 -05:00
|
|
|
const isSandstorm =
|
|
|
|
Meteor.settings && Meteor.settings.public && Meteor.settings.public.sandstorm;
|
2015-12-24 13:07:55 +01:00
|
|
|
Users = Meteor.users;
|
Renaissance
_,,ad8888888888bba,_
,ad88888I888888888888888ba,
,88888888I88888888888888888888a,
,d888888888I8888888888888888888888b,
d88888PP"""" ""YY88888888888888888888b,
,d88"'__,,--------,,,,.;ZZZY8888888888888,
,8IIl'" ;;l"ZZZIII8888888888,
,I88l;' ;lZZZZZ888III8888888,
,II88Zl;. ;llZZZZZ888888I888888,
,II888Zl;. .;;;;;lllZZZ888888I8888b
,II8888Z;; `;;;;;''llZZ8888888I8888,
II88888Z;' .;lZZZ8888888I888b
II88888Z; _,aaa, .,aaaaa,__.l;llZZZ88888888I888
II88888IZZZZZZZZZ, .ZZZZZZZZZZZZZZ;llZZ88888888I888,
II88888IZZ<'(@@>Z| |ZZZ<'(@@>ZZZZ;;llZZ888888888I88I
,II88888; `""" ;| |ZZ; `""" ;;llZ8888888888I888
II888888l `;; .;llZZ8888888888I888,
,II888888Z; ;;; .;;llZZZ8888888888I888I
III888888Zl; .., `;; ,;;lllZZZ88888888888I888
II88888888Z;;...;(_ _) ,;;;llZZZZ88888888888I888,
II88888888Zl;;;;;' `--'Z;. .,;;;;llZZZZ88888888888I888b
]I888888888Z;;;;' ";llllll;..;;;lllZZZZ88888888888I8888,
II888888888Zl.;;"Y88bd888P";;,..;lllZZZZZ88888888888I8888I
II8888888888Zl;.; `"PPP";;;,..;lllZZZZZZZ88888888888I88888
II888888888888Zl;;. `;;;l;;;;lllZZZZZZZZW88888888888I88888
`II8888888888888Zl;. ,;;lllZZZZZZZZWMZ88888888888I88888
II8888888888888888ZbaalllZZZZZZZZZWWMZZZ8888888888I888888,
`II88888888888888888b"WWZZZZZWWWMMZZZZZZI888888888I888888b
`II88888888888888888;ZZMMMMMMZZZZZZZZllI888888888I8888888
`II8888888888888888 `;lZZZZZZZZZZZlllll888888888I8888888,
II8888888888888888, `;lllZZZZllllll;;.Y88888888I8888888b,
,II8888888888888888b .;;lllllll;;;.;..88888888I88888888b,
II888888888888888PZI;. .`;;;.;;;..; ...88888888I8888888888,
II888888888888PZ;;';;. ;. .;. .;. .. Y8888888I88888888888b,
,II888888888PZ;;' `8888888I8888888888888b,
II888888888' 888888I8888888888888888
,II888888888 ,888888I8888888888888888
,d88888888888 d888888I8888888888ZZZZZZ
,ad888888888888I 8888888I8888ZZZZZZZZZZZZ
888888888888888' 888888IZZZZZZZZZZZZZZZZZ
8888888888P'8P' Y888ZZZZZZZZZZZZZZZZZZZZ
888888888, " ,ZZZZZZZZZZZZZZZZZZZZZZZ
8888888888, ,ZZZZZZZZZZZZZZZZZZZZZZZZZZ
888888888888a, _ ,ZZZZZZZZZZZZZZZZZZZZ88888888
888888888888888ba,_d' ,ZZZZZZZZZZZZZZZZZ8888888888888
8888888888888888888888bbbaaa,,,______,ZZZZZZZZZZZZZZZ88888888888888888
88888888888888888888888888888888888ZZZZZZZZZZZZZZZ88888888888888888888
8888888888888888888888888888888888ZZZZZZZZZZZZZZ8888888888888888888888
888888888888888888888888888888888ZZZZZZZZZZZZZZ88888888888888888888888
8888888888888888888888888888888ZZZZZZZZZZZZZZ8888888888888888888888888
88888888888888888888888888888ZZZZZZZZZZZZZZ888888888888888888888888888
8888888888888888888888888888ZZZZZZZZZZZZZZ88888888888888888 Normand 8
88888888888888888888888888ZZZZZZZZZZZZZZ8888888888888888888 Veilleux 8
8888888888888888888888888ZZZZZZZZZZZZZZ8888888888888888888888888888888
2015-05-12 19:20:58 +02:00
|
|
|
|
2019-10-18 16:44:09 -04:00
|
|
|
const allowedSortValues = [
|
|
|
|
'-modifiedAt',
|
|
|
|
'modifiedAt',
|
|
|
|
'-title',
|
|
|
|
'title',
|
|
|
|
'-sort',
|
|
|
|
'sort',
|
|
|
|
];
|
|
|
|
const defaultSortBy = allowedSortValues[0];
|
|
|
|
|
2018-10-26 07:27:24 +02:00
|
|
|
/**
|
|
|
|
* A User in wekan
|
|
|
|
*/
|
2019-06-26 17:47:27 -05:00
|
|
|
Users.attachSchema(
|
|
|
|
new SimpleSchema({
|
|
|
|
username: {
|
|
|
|
/**
|
|
|
|
* the username of the user
|
|
|
|
*/
|
|
|
|
type: String,
|
|
|
|
optional: true,
|
|
|
|
// eslint-disable-next-line consistent-return
|
|
|
|
autoValue() {
|
|
|
|
if (this.isInsert && !this.isSet) {
|
|
|
|
const name = this.field('profile.fullname');
|
|
|
|
if (name.isSet) {
|
|
|
|
return name.value.toLowerCase().replace(/\s/g, '');
|
|
|
|
}
|
2016-05-31 20:03:48 +02:00
|
|
|
}
|
2019-06-26 17:47:27 -05:00
|
|
|
},
|
2016-05-31 20:03:48 +02:00
|
|
|
},
|
2021-06-10 16:38:28 +02:00
|
|
|
orgs: {
|
|
|
|
/**
|
|
|
|
* the list of organizations that a user belongs to
|
|
|
|
*/
|
2022-09-21 14:33:17 +02:00
|
|
|
type: [Object],
|
|
|
|
optional: true,
|
2021-06-10 16:38:28 +02:00
|
|
|
},
|
2022-09-21 14:33:17 +02:00
|
|
|
'orgs.$.orgId': {
|
2021-06-10 16:38:28 +02:00
|
|
|
/**
|
|
|
|
* The uniq ID of the organization
|
|
|
|
*/
|
2022-09-21 14:33:17 +02:00
|
|
|
type: String,
|
2021-06-10 16:38:28 +02:00
|
|
|
},
|
2022-09-21 14:33:17 +02:00
|
|
|
'orgs.$.orgDisplayName': {
|
2021-06-10 16:38:28 +02:00
|
|
|
/**
|
|
|
|
* The display name of the organization
|
|
|
|
*/
|
2022-09-21 14:33:17 +02:00
|
|
|
type: String,
|
2021-06-10 16:38:28 +02:00
|
|
|
},
|
|
|
|
teams: {
|
|
|
|
/**
|
|
|
|
* the list of teams that a user belongs to
|
|
|
|
*/
|
2022-09-21 14:33:17 +02:00
|
|
|
type: [Object],
|
|
|
|
optional: true,
|
2021-06-10 16:38:28 +02:00
|
|
|
},
|
2022-09-21 14:33:17 +02:00
|
|
|
'teams.$.teamId': {
|
2021-06-10 16:38:28 +02:00
|
|
|
/**
|
|
|
|
* The uniq ID of the team
|
|
|
|
*/
|
2022-09-21 14:33:17 +02:00
|
|
|
type: String,
|
2021-06-10 16:38:28 +02:00
|
|
|
},
|
2022-09-21 14:33:17 +02:00
|
|
|
'teams.$.teamDisplayName': {
|
2021-06-10 16:38:28 +02:00
|
|
|
/**
|
|
|
|
* The display name of the team
|
|
|
|
*/
|
2022-09-21 14:33:17 +02:00
|
|
|
type: String,
|
2021-06-10 16:38:28 +02:00
|
|
|
},
|
2019-06-26 17:47:27 -05:00
|
|
|
emails: {
|
|
|
|
/**
|
|
|
|
* the list of emails attached to a user
|
|
|
|
*/
|
|
|
|
type: [Object],
|
|
|
|
optional: true,
|
2016-05-31 20:03:48 +02:00
|
|
|
},
|
2019-06-26 17:47:27 -05:00
|
|
|
'emails.$.address': {
|
|
|
|
/**
|
|
|
|
* The email address
|
|
|
|
*/
|
|
|
|
type: String,
|
|
|
|
regEx: SimpleSchema.RegEx.Email,
|
2016-05-31 20:03:48 +02:00
|
|
|
},
|
2019-06-26 17:47:27 -05:00
|
|
|
'emails.$.verified': {
|
|
|
|
/**
|
|
|
|
* Has the email been verified
|
|
|
|
*/
|
|
|
|
type: Boolean,
|
|
|
|
},
|
|
|
|
createdAt: {
|
|
|
|
/**
|
|
|
|
* creation date of the user
|
|
|
|
*/
|
|
|
|
type: Date,
|
|
|
|
// eslint-disable-next-line consistent-return
|
|
|
|
autoValue() {
|
|
|
|
if (this.isInsert) {
|
|
|
|
return new Date();
|
2019-09-05 12:29:45 -05:00
|
|
|
} else if (this.isUpsert) {
|
2021-05-29 00:19:12 +03:00
|
|
|
return {
|
|
|
|
$setOnInsert: new Date(),
|
|
|
|
};
|
2019-06-26 17:47:27 -05:00
|
|
|
} else {
|
|
|
|
this.unset();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
modifiedAt: {
|
|
|
|
type: Date,
|
|
|
|
denyUpdate: false,
|
|
|
|
// eslint-disable-next-line consistent-return
|
|
|
|
autoValue() {
|
|
|
|
if (this.isInsert || this.isUpsert || this.isUpdate) {
|
|
|
|
return new Date();
|
|
|
|
} else {
|
|
|
|
this.unset();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
profile: {
|
|
|
|
/**
|
|
|
|
* profile settings
|
|
|
|
*/
|
|
|
|
type: Object,
|
|
|
|
optional: true,
|
|
|
|
// eslint-disable-next-line consistent-return
|
|
|
|
autoValue() {
|
|
|
|
if (this.isInsert && !this.isSet) {
|
|
|
|
return {
|
2020-06-08 17:28:53 +03:00
|
|
|
boardView: 'board-view-swimlanes',
|
2019-06-26 17:47:27 -05:00
|
|
|
};
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
'profile.avatarUrl': {
|
|
|
|
/**
|
|
|
|
* URL of the avatar of the user
|
|
|
|
*/
|
|
|
|
type: String,
|
|
|
|
optional: true,
|
|
|
|
},
|
|
|
|
'profile.emailBuffer': {
|
|
|
|
/**
|
|
|
|
* list of email buffers of the user
|
|
|
|
*/
|
|
|
|
type: [String],
|
|
|
|
optional: true,
|
|
|
|
},
|
|
|
|
'profile.fullname': {
|
|
|
|
/**
|
|
|
|
* full name of the user
|
|
|
|
*/
|
|
|
|
type: String,
|
|
|
|
optional: true,
|
|
|
|
},
|
2019-11-19 14:09:36 +02:00
|
|
|
'profile.showDesktopDragHandles': {
|
|
|
|
/**
|
2021-06-12 12:48:12 +03:00
|
|
|
* does the user want to show desktop drag handles?
|
2019-11-19 14:09:36 +02:00
|
|
|
*/
|
|
|
|
type: Boolean,
|
|
|
|
optional: true,
|
|
|
|
},
|
2021-06-12 12:48:12 +03:00
|
|
|
'profile.cardMaximized': {
|
|
|
|
/**
|
|
|
|
* has user clicked maximize card?
|
|
|
|
*/
|
|
|
|
type: Boolean,
|
|
|
|
optional: true,
|
|
|
|
},
|
2021-09-22 12:14:42 +03:00
|
|
|
'profile.customFieldsGrid': {
|
|
|
|
/**
|
|
|
|
* has user at card Custom Fields have Grid (false) or one per row (true) layout?
|
|
|
|
*/
|
|
|
|
type: Boolean,
|
|
|
|
optional: true,
|
|
|
|
},
|
2019-11-19 14:09:36 +02:00
|
|
|
'profile.hiddenMinicardLabelText': {
|
|
|
|
/**
|
|
|
|
* does the user want to hide minicard label texts?
|
|
|
|
*/
|
|
|
|
type: Boolean,
|
|
|
|
optional: true,
|
|
|
|
},
|
2019-06-26 17:47:27 -05:00
|
|
|
'profile.initials': {
|
|
|
|
/**
|
|
|
|
* initials of the user
|
|
|
|
*/
|
|
|
|
type: String,
|
|
|
|
optional: true,
|
|
|
|
},
|
|
|
|
'profile.invitedBoards': {
|
|
|
|
/**
|
|
|
|
* board IDs the user has been invited to
|
|
|
|
*/
|
|
|
|
type: [String],
|
|
|
|
optional: true,
|
|
|
|
},
|
|
|
|
'profile.language': {
|
|
|
|
/**
|
|
|
|
* language of the user
|
|
|
|
*/
|
|
|
|
type: String,
|
|
|
|
optional: true,
|
|
|
|
},
|
2022-09-21 14:33:17 +02:00
|
|
|
'profile.moveAndCopyDialog': {
|
2022-01-10 07:09:07 +01:00
|
|
|
/**
|
|
|
|
* move and copy card dialog
|
|
|
|
*/
|
|
|
|
type: Object,
|
|
|
|
optional: true,
|
|
|
|
blackbox: true,
|
|
|
|
},
|
|
|
|
'profile.moveAndCopyDialog.$.boardId': {
|
|
|
|
/**
|
|
|
|
* last selected board id
|
|
|
|
*/
|
|
|
|
type: String,
|
|
|
|
},
|
|
|
|
'profile.moveAndCopyDialog.$.swimlaneId': {
|
|
|
|
/**
|
|
|
|
* last selected swimlane id
|
|
|
|
*/
|
|
|
|
type: String,
|
|
|
|
},
|
|
|
|
'profile.moveAndCopyDialog.$.listId': {
|
|
|
|
/**
|
|
|
|
* last selected list id
|
|
|
|
*/
|
|
|
|
type: String,
|
|
|
|
},
|
2022-09-21 14:33:17 +02:00
|
|
|
'profile.moveChecklistDialog': {
|
2022-01-11 19:42:57 +01:00
|
|
|
/**
|
2022-01-30 12:32:52 +01:00
|
|
|
* move checklist dialog
|
2022-01-11 19:42:57 +01:00
|
|
|
*/
|
|
|
|
type: Object,
|
|
|
|
optional: true,
|
|
|
|
blackbox: true,
|
|
|
|
},
|
|
|
|
'profile.moveChecklistDialog.$.boardId': {
|
|
|
|
/**
|
|
|
|
* last selected board id
|
|
|
|
*/
|
|
|
|
type: String,
|
|
|
|
},
|
|
|
|
'profile.moveChecklistDialog.$.swimlaneId': {
|
|
|
|
/**
|
|
|
|
* last selected swimlane id
|
|
|
|
*/
|
|
|
|
type: String,
|
|
|
|
},
|
|
|
|
'profile.moveChecklistDialog.$.listId': {
|
|
|
|
/**
|
|
|
|
* last selected list id
|
|
|
|
*/
|
|
|
|
type: String,
|
|
|
|
},
|
|
|
|
'profile.moveChecklistDialog.$.cardId': {
|
|
|
|
/**
|
|
|
|
* last selected card id
|
|
|
|
*/
|
|
|
|
type: String,
|
|
|
|
},
|
2022-09-21 14:33:17 +02:00
|
|
|
'profile.copyChecklistDialog': {
|
2022-01-30 12:32:52 +01:00
|
|
|
/**
|
|
|
|
* copy checklist dialog
|
|
|
|
*/
|
|
|
|
type: Object,
|
|
|
|
optional: true,
|
|
|
|
blackbox: true,
|
|
|
|
},
|
|
|
|
'profile.copyChecklistDialog.$.boardId': {
|
|
|
|
/**
|
|
|
|
* last selected board id
|
|
|
|
*/
|
|
|
|
type: String,
|
|
|
|
},
|
|
|
|
'profile.copyChecklistDialog.$.swimlaneId': {
|
|
|
|
/**
|
|
|
|
* last selected swimlane id
|
|
|
|
*/
|
|
|
|
type: String,
|
|
|
|
},
|
|
|
|
'profile.copyChecklistDialog.$.listId': {
|
|
|
|
/**
|
|
|
|
* last selected list id
|
|
|
|
*/
|
|
|
|
type: String,
|
|
|
|
},
|
|
|
|
'profile.copyChecklistDialog.$.cardId': {
|
|
|
|
/**
|
|
|
|
* last selected card id
|
|
|
|
*/
|
|
|
|
type: String,
|
|
|
|
},
|
2019-06-26 17:47:27 -05:00
|
|
|
'profile.notifications': {
|
|
|
|
/**
|
|
|
|
* enabled notifications for the user
|
|
|
|
*/
|
2020-03-27 11:35:03 -06:00
|
|
|
type: [Object],
|
|
|
|
optional: true,
|
|
|
|
},
|
|
|
|
'profile.notifications.$.activity': {
|
|
|
|
/**
|
|
|
|
* The id of the activity this notification references
|
|
|
|
*/
|
|
|
|
type: String,
|
|
|
|
},
|
|
|
|
'profile.notifications.$.read': {
|
|
|
|
/**
|
|
|
|
* the date on which this notification was read
|
|
|
|
*/
|
|
|
|
type: Date,
|
2019-06-26 17:47:27 -05:00
|
|
|
optional: true,
|
|
|
|
},
|
2022-07-18 15:05:22 +02:00
|
|
|
'profile.rescueCardDescription': {
|
|
|
|
/**
|
|
|
|
* show dialog for saving card description on unintentional card closing
|
|
|
|
*/
|
|
|
|
type: Boolean,
|
|
|
|
optional: true,
|
|
|
|
},
|
2019-06-26 17:47:27 -05:00
|
|
|
'profile.showCardsCountAt': {
|
|
|
|
/**
|
|
|
|
* showCardCountAt field of the user
|
|
|
|
*/
|
|
|
|
type: Number,
|
|
|
|
optional: true,
|
|
|
|
},
|
2020-04-22 14:44:08 +02:00
|
|
|
'profile.startDayOfWeek': {
|
|
|
|
/**
|
|
|
|
* startDayOfWeek field of the user
|
|
|
|
*/
|
|
|
|
type: Number,
|
|
|
|
optional: true,
|
|
|
|
},
|
2019-06-26 17:47:27 -05:00
|
|
|
'profile.starredBoards': {
|
|
|
|
/**
|
|
|
|
* list of starred board IDs
|
|
|
|
*/
|
|
|
|
type: [String],
|
|
|
|
optional: true,
|
|
|
|
},
|
|
|
|
'profile.icode': {
|
|
|
|
/**
|
|
|
|
* icode
|
|
|
|
*/
|
|
|
|
type: String,
|
|
|
|
optional: true,
|
|
|
|
},
|
|
|
|
'profile.boardView': {
|
|
|
|
/**
|
|
|
|
* boardView field of the user
|
|
|
|
*/
|
|
|
|
type: String,
|
|
|
|
optional: true,
|
|
|
|
allowedValues: [
|
|
|
|
'board-view-swimlanes',
|
2020-06-08 17:28:53 +03:00
|
|
|
'board-view-lists',
|
2019-06-26 17:47:27 -05:00
|
|
|
'board-view-cal',
|
|
|
|
],
|
|
|
|
},
|
2019-10-18 16:44:09 -04:00
|
|
|
'profile.listSortBy': {
|
|
|
|
/**
|
|
|
|
* default sort list for user
|
|
|
|
*/
|
|
|
|
type: String,
|
|
|
|
optional: true,
|
|
|
|
defaultValue: defaultSortBy,
|
|
|
|
allowedValues: allowedSortValues,
|
|
|
|
},
|
2019-06-26 17:47:27 -05:00
|
|
|
'profile.templatesBoardId': {
|
|
|
|
/**
|
|
|
|
* Reference to the templates board
|
|
|
|
*/
|
|
|
|
type: String,
|
|
|
|
defaultValue: '',
|
|
|
|
},
|
|
|
|
'profile.cardTemplatesSwimlaneId': {
|
|
|
|
/**
|
|
|
|
* Reference to the card templates swimlane Id
|
|
|
|
*/
|
|
|
|
type: String,
|
|
|
|
defaultValue: '',
|
|
|
|
},
|
|
|
|
'profile.listTemplatesSwimlaneId': {
|
|
|
|
/**
|
|
|
|
* Reference to the list templates swimlane Id
|
|
|
|
*/
|
|
|
|
type: String,
|
|
|
|
defaultValue: '',
|
|
|
|
},
|
|
|
|
'profile.boardTemplatesSwimlaneId': {
|
|
|
|
/**
|
|
|
|
* Reference to the board templates swimlane Id
|
|
|
|
*/
|
|
|
|
type: String,
|
|
|
|
defaultValue: '',
|
|
|
|
},
|
2023-06-12 22:14:06 -05:00
|
|
|
'profile.listWidths': {
|
|
|
|
/**
|
|
|
|
* User-specified width of each list (or nothing if default).
|
|
|
|
* profile[boardId][listId] = width;
|
|
|
|
*/
|
|
|
|
type: Object,
|
|
|
|
defaultValue: {},
|
|
|
|
blackbox: true,
|
|
|
|
},
|
2024-12-07 18:59:01 +02:00
|
|
|
'profile.listConstraints': {
|
|
|
|
/**
|
|
|
|
* User-specified constraint of each list (or nothing if default).
|
|
|
|
* profile[boardId][listId] = constraint;
|
|
|
|
*/
|
|
|
|
type: Object,
|
|
|
|
defaultValue: {},
|
|
|
|
blackbox: true,
|
|
|
|
},
|
2024-12-07 18:57:34 +02:00
|
|
|
'profile.autoWidthBoards': {
|
|
|
|
/**
|
|
|
|
* User-specified flag for enabling auto-width for boards (false is the default).
|
|
|
|
* profile[boardId][listId] = constraint;
|
|
|
|
*/
|
|
|
|
type: Object,
|
|
|
|
defaultValue: {},
|
|
|
|
blackbox: true,
|
|
|
|
},
|
2023-06-12 22:14:06 -05:00
|
|
|
'profile.swimlaneHeights': {
|
|
|
|
/**
|
|
|
|
* User-specified heights of each swimlane (or nothing if default).
|
|
|
|
* profile[boardId][swimlaneId] = height;
|
|
|
|
*/
|
|
|
|
type: Object,
|
|
|
|
defaultValue: {},
|
|
|
|
blackbox: true,
|
|
|
|
},
|
2024-12-25 00:22:37 +02:00
|
|
|
'profile.keyboardShortcuts': {
|
|
|
|
/**
|
|
|
|
* User-specified state of keyboard shortcut activation.
|
|
|
|
*/
|
|
|
|
type: Boolean,
|
|
|
|
defaultValue: true,
|
|
|
|
},
|
2019-06-26 17:47:27 -05:00
|
|
|
services: {
|
|
|
|
/**
|
|
|
|
* services field of the user
|
|
|
|
*/
|
|
|
|
type: Object,
|
|
|
|
optional: true,
|
|
|
|
blackbox: true,
|
|
|
|
},
|
|
|
|
heartbeat: {
|
|
|
|
/**
|
|
|
|
* last time the user has been seen
|
|
|
|
*/
|
|
|
|
type: Date,
|
|
|
|
optional: true,
|
|
|
|
},
|
|
|
|
isAdmin: {
|
|
|
|
/**
|
|
|
|
* is the user an admin of the board?
|
|
|
|
*/
|
|
|
|
type: Boolean,
|
|
|
|
optional: true,
|
|
|
|
},
|
|
|
|
createdThroughApi: {
|
|
|
|
/**
|
|
|
|
* was the user created through the API?
|
|
|
|
*/
|
|
|
|
type: Boolean,
|
|
|
|
optional: true,
|
|
|
|
},
|
|
|
|
loginDisabled: {
|
|
|
|
/**
|
|
|
|
* loginDisabled field of the user
|
|
|
|
*/
|
|
|
|
type: Boolean,
|
|
|
|
optional: true,
|
|
|
|
},
|
|
|
|
authenticationMethod: {
|
|
|
|
/**
|
|
|
|
* authentication method of the user
|
|
|
|
*/
|
|
|
|
type: String,
|
|
|
|
optional: false,
|
|
|
|
defaultValue: 'password',
|
|
|
|
},
|
2021-01-14 16:54:44 +02:00
|
|
|
sessionData: {
|
|
|
|
/**
|
|
|
|
* profile settings
|
|
|
|
*/
|
|
|
|
type: Object,
|
|
|
|
optional: true,
|
|
|
|
// eslint-disable-next-line consistent-return
|
|
|
|
autoValue() {
|
|
|
|
if (this.isInsert && !this.isSet) {
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
'sessionData.totalHits': {
|
|
|
|
/**
|
2021-06-10 16:38:28 +02:00
|
|
|
* Total hits from last searchquery['members.userId'] = Meteor.userId();
|
2021-01-14 16:54:44 +02:00
|
|
|
* last hit that was returned
|
|
|
|
*/
|
|
|
|
type: Number,
|
|
|
|
optional: true,
|
|
|
|
},
|
2021-01-30 02:35:29 +02:00
|
|
|
importUsernames: {
|
|
|
|
/**
|
|
|
|
* username for imported
|
|
|
|
*/
|
|
|
|
type: [String],
|
|
|
|
optional: true,
|
|
|
|
},
|
2022-09-21 14:33:17 +02:00
|
|
|
lastConnectionDate: {
|
|
|
|
type: Date,
|
|
|
|
optional: true,
|
|
|
|
},
|
2019-06-28 12:52:09 -05:00
|
|
|
}),
|
2019-06-26 17:47:27 -05:00
|
|
|
);
|
2016-05-31 20:03:48 +02:00
|
|
|
|
2017-11-08 11:34:37 +07:00
|
|
|
Users.allow({
|
2019-08-20 19:16:44 +03:00
|
|
|
update(userId, doc) {
|
2023-01-16 23:00:10 +01:00
|
|
|
const user = ReactiveCache.getUser(userId) || ReactiveCache.getCurrentUser();
|
|
|
|
if (user?.isAdmin)
|
2019-08-20 19:25:37 +03:00
|
|
|
return true;
|
|
|
|
if (!user) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return doc._id === userId;
|
2017-11-08 11:34:37 +07:00
|
|
|
},
|
2019-04-26 17:53:48 +02:00
|
|
|
remove(userId, doc) {
|
2023-02-22 22:53:48 +01:00
|
|
|
const adminsNumber = ReactiveCache.getUsers({
|
2021-05-29 00:19:12 +03:00
|
|
|
isAdmin: true,
|
2023-02-22 22:53:48 +01:00
|
|
|
}).length;
|
2023-02-04 11:16:53 +01:00
|
|
|
const isAdmin = ReactiveCache.getUser(
|
2021-05-29 00:19:12 +03:00
|
|
|
{
|
|
|
|
_id: userId,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
fields: {
|
|
|
|
isAdmin: 1,
|
|
|
|
},
|
|
|
|
},
|
2019-06-26 17:47:27 -05:00
|
|
|
);
|
2019-04-26 17:53:48 +02:00
|
|
|
|
|
|
|
// Prevents remove of the only one administrator
|
|
|
|
if (adminsNumber === 1 && isAdmin && userId === doc._id) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If it's the user or an admin
|
|
|
|
return userId === doc._id || isAdmin;
|
|
|
|
},
|
|
|
|
fetch: [],
|
2017-11-08 11:34:37 +07:00
|
|
|
});
|
|
|
|
|
2023-04-25 01:54:53 +03:00
|
|
|
// Non-Admin users can not change to Admin
|
|
|
|
Users.deny({
|
|
|
|
update(userId, board, fieldNames) {
|
2023-01-16 23:00:10 +01:00
|
|
|
return _.contains(fieldNames, 'isAdmin') && !ReactiveCache.getCurrentUser().isAdmin;
|
2023-04-25 01:54:53 +03:00
|
|
|
},
|
|
|
|
fetch: [],
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2021-09-22 17:12:35 +02:00
|
|
|
// Search a user in the complete server database by its name, username or emails adress. This
|
Renaissance
_,,ad8888888888bba,_
,ad88888I888888888888888ba,
,88888888I88888888888888888888a,
,d888888888I8888888888888888888888b,
d88888PP"""" ""YY88888888888888888888b,
,d88"'__,,--------,,,,.;ZZZY8888888888888,
,8IIl'" ;;l"ZZZIII8888888888,
,I88l;' ;lZZZZZ888III8888888,
,II88Zl;. ;llZZZZZ888888I888888,
,II888Zl;. .;;;;;lllZZZ888888I8888b
,II8888Z;; `;;;;;''llZZ8888888I8888,
II88888Z;' .;lZZZ8888888I888b
II88888Z; _,aaa, .,aaaaa,__.l;llZZZ88888888I888
II88888IZZZZZZZZZ, .ZZZZZZZZZZZZZZ;llZZ88888888I888,
II88888IZZ<'(@@>Z| |ZZZ<'(@@>ZZZZ;;llZZ888888888I88I
,II88888; `""" ;| |ZZ; `""" ;;llZ8888888888I888
II888888l `;; .;llZZ8888888888I888,
,II888888Z; ;;; .;;llZZZ8888888888I888I
III888888Zl; .., `;; ,;;lllZZZ88888888888I888
II88888888Z;;...;(_ _) ,;;;llZZZZ88888888888I888,
II88888888Zl;;;;;' `--'Z;. .,;;;;llZZZZ88888888888I888b
]I888888888Z;;;;' ";llllll;..;;;lllZZZZ88888888888I8888,
II888888888Zl.;;"Y88bd888P";;,..;lllZZZZZ88888888888I8888I
II8888888888Zl;.; `"PPP";;;,..;lllZZZZZZZ88888888888I88888
II888888888888Zl;;. `;;;l;;;;lllZZZZZZZZW88888888888I88888
`II8888888888888Zl;. ,;;lllZZZZZZZZWMZ88888888888I88888
II8888888888888888ZbaalllZZZZZZZZZWWMZZZ8888888888I888888,
`II88888888888888888b"WWZZZZZWWWMMZZZZZZI888888888I888888b
`II88888888888888888;ZZMMMMMMZZZZZZZZllI888888888I8888888
`II8888888888888888 `;lZZZZZZZZZZZlllll888888888I8888888,
II8888888888888888, `;lllZZZZllllll;;.Y88888888I8888888b,
,II8888888888888888b .;;lllllll;;;.;..88888888I88888888b,
II888888888888888PZI;. .`;;;.;;;..; ...88888888I8888888888,
II888888888888PZ;;';;. ;. .;. .;. .. Y8888888I88888888888b,
,II888888888PZ;;' `8888888I8888888888888b,
II888888888' 888888I8888888888888888
,II888888888 ,888888I8888888888888888
,d88888888888 d888888I8888888888ZZZZZZ
,ad888888888888I 8888888I8888ZZZZZZZZZZZZ
888888888888888' 888888IZZZZZZZZZZZZZZZZZ
8888888888P'8P' Y888ZZZZZZZZZZZZZZZZZZZZ
888888888, " ,ZZZZZZZZZZZZZZZZZZZZZZZ
8888888888, ,ZZZZZZZZZZZZZZZZZZZZZZZZZZ
888888888888a, _ ,ZZZZZZZZZZZZZZZZZZZZ88888888
888888888888888ba,_d' ,ZZZZZZZZZZZZZZZZZ8888888888888
8888888888888888888888bbbaaa,,,______,ZZZZZZZZZZZZZZZ88888888888888888
88888888888888888888888888888888888ZZZZZZZZZZZZZZZ88888888888888888888
8888888888888888888888888888888888ZZZZZZZZZZZZZZ8888888888888888888888
888888888888888888888888888888888ZZZZZZZZZZZZZZ88888888888888888888888
8888888888888888888888888888888ZZZZZZZZZZZZZZ8888888888888888888888888
88888888888888888888888888888ZZZZZZZZZZZZZZ888888888888888888888888888
8888888888888888888888888888ZZZZZZZZZZZZZZ88888888888888888 Normand 8
88888888888888888888888888ZZZZZZZZZZZZZZ8888888888888888888 Veilleux 8
8888888888888888888888888ZZZZZZZZZZZZZZ8888888888888888888888888888888
2015-05-12 19:20:58 +02:00
|
|
|
// is used for instance to add a new user to a board.
|
2022-08-28 12:26:22 -04:00
|
|
|
UserSearchIndex = new Index({
|
2022-08-05 13:06:02 +02:00
|
|
|
collection: Users,
|
2022-08-31 22:00:09 +03:00
|
|
|
fields: ['username', 'profile.fullname', 'profile.avatarUrl'],
|
|
|
|
allowedFields: ['username', 'profile.fullname', 'profile.avatarUrl'],
|
|
|
|
engine: new MongoDBEngine({
|
2022-09-21 14:33:17 +02:00
|
|
|
fields: function (searchObject, options) {
|
2022-08-31 22:00:09 +03:00
|
|
|
return {
|
2022-09-21 14:33:17 +02:00
|
|
|
username: 1,
|
2022-08-31 22:00:09 +03:00
|
|
|
'profile.fullname': 1,
|
2022-09-21 14:33:17 +02:00
|
|
|
'profile.avatarUrl': 1,
|
2022-08-31 22:00:09 +03:00
|
|
|
};
|
2022-09-21 14:33:17 +02:00
|
|
|
},
|
2022-08-31 22:00:09 +03:00
|
|
|
}),
|
Renaissance
_,,ad8888888888bba,_
,ad88888I888888888888888ba,
,88888888I88888888888888888888a,
,d888888888I8888888888888888888888b,
d88888PP"""" ""YY88888888888888888888b,
,d88"'__,,--------,,,,.;ZZZY8888888888888,
,8IIl'" ;;l"ZZZIII8888888888,
,I88l;' ;lZZZZZ888III8888888,
,II88Zl;. ;llZZZZZ888888I888888,
,II888Zl;. .;;;;;lllZZZ888888I8888b
,II8888Z;; `;;;;;''llZZ8888888I8888,
II88888Z;' .;lZZZ8888888I888b
II88888Z; _,aaa, .,aaaaa,__.l;llZZZ88888888I888
II88888IZZZZZZZZZ, .ZZZZZZZZZZZZZZ;llZZ88888888I888,
II88888IZZ<'(@@>Z| |ZZZ<'(@@>ZZZZ;;llZZ888888888I88I
,II88888; `""" ;| |ZZ; `""" ;;llZ8888888888I888
II888888l `;; .;llZZ8888888888I888,
,II888888Z; ;;; .;;llZZZ8888888888I888I
III888888Zl; .., `;; ,;;lllZZZ88888888888I888
II88888888Z;;...;(_ _) ,;;;llZZZZ88888888888I888,
II88888888Zl;;;;;' `--'Z;. .,;;;;llZZZZ88888888888I888b
]I888888888Z;;;;' ";llllll;..;;;lllZZZZ88888888888I8888,
II888888888Zl.;;"Y88bd888P";;,..;lllZZZZZ88888888888I8888I
II8888888888Zl;.; `"PPP";;;,..;lllZZZZZZZ88888888888I88888
II888888888888Zl;;. `;;;l;;;;lllZZZZZZZZW88888888888I88888
`II8888888888888Zl;. ,;;lllZZZZZZZZWMZ88888888888I88888
II8888888888888888ZbaalllZZZZZZZZZWWMZZZ8888888888I888888,
`II88888888888888888b"WWZZZZZWWWMMZZZZZZI888888888I888888b
`II88888888888888888;ZZMMMMMMZZZZZZZZllI888888888I8888888
`II8888888888888888 `;lZZZZZZZZZZZlllll888888888I8888888,
II8888888888888888, `;lllZZZZllllll;;.Y88888888I8888888b,
,II8888888888888888b .;;lllllll;;;.;..88888888I88888888b,
II888888888888888PZI;. .`;;;.;;;..; ...88888888I8888888888,
II888888888888PZ;;';;. ;. .;. .;. .. Y8888888I88888888888b,
,II888888888PZ;;' `8888888I8888888888888b,
II888888888' 888888I8888888888888888
,II888888888 ,888888I8888888888888888
,d88888888888 d888888I8888888888ZZZZZZ
,ad888888888888I 8888888I8888ZZZZZZZZZZZZ
888888888888888' 888888IZZZZZZZZZZZZZZZZZ
8888888888P'8P' Y888ZZZZZZZZZZZZZZZZZZZZ
888888888, " ,ZZZZZZZZZZZZZZZZZZZZZZZ
8888888888, ,ZZZZZZZZZZZZZZZZZZZZZZZZZZ
888888888888a, _ ,ZZZZZZZZZZZZZZZZZZZZ88888888
888888888888888ba,_d' ,ZZZZZZZZZZZZZZZZZ8888888888888
8888888888888888888888bbbaaa,,,______,ZZZZZZZZZZZZZZZ88888888888888888
88888888888888888888888888888888888ZZZZZZZZZZZZZZZ88888888888888888888
8888888888888888888888888888888888ZZZZZZZZZZZZZZ8888888888888888888888
888888888888888888888888888888888ZZZZZZZZZZZZZZ88888888888888888888888
8888888888888888888888888888888ZZZZZZZZZZZZZZ8888888888888888888888888
88888888888888888888888888888ZZZZZZZZZZZZZZ888888888888888888888888888
8888888888888888888888888888ZZZZZZZZZZZZZZ88888888888888888 Normand 8
88888888888888888888888888ZZZZZZZZZZZZZZ8888888888888888888 Veilleux 8
8888888888888888888888888ZZZZZZZZZZZZZZ8888888888888888888888888888888
2015-05-12 19:20:58 +02:00
|
|
|
});
|
|
|
|
|
2021-01-16 19:20:31 +02:00
|
|
|
Users.safeFields = {
|
|
|
|
_id: 1,
|
|
|
|
username: 1,
|
|
|
|
'profile.fullname': 1,
|
|
|
|
'profile.avatarUrl': 1,
|
|
|
|
'profile.initials': 1,
|
2021-07-05 11:27:38 +02:00
|
|
|
orgs: 1,
|
|
|
|
teams: 1,
|
2021-09-01 11:40:54 +02:00
|
|
|
authenticationMethod: 1,
|
2022-09-21 14:33:17 +02:00
|
|
|
lastConnectionDate: 1,
|
2021-01-16 19:20:31 +02:00
|
|
|
};
|
|
|
|
|
2015-10-27 17:40:38 +01:00
|
|
|
if (Meteor.isClient) {
|
|
|
|
Users.helpers({
|
|
|
|
isBoardMember() {
|
2021-11-08 12:05:29 +01:00
|
|
|
const board = Utils.getCurrentBoard();
|
2015-12-08 16:03:31 +08:00
|
|
|
return board && board.hasMember(this._id);
|
2015-10-27 17:40:38 +01:00
|
|
|
},
|
2015-11-13 12:35:41 +01:00
|
|
|
|
2018-09-04 20:09:36 +03:00
|
|
|
isNotNoComments() {
|
2021-11-08 12:05:29 +01:00
|
|
|
const board = Utils.getCurrentBoard();
|
2019-06-26 17:47:27 -05:00
|
|
|
return (
|
|
|
|
board && board.hasMember(this._id) && !board.hasNoComments(this._id)
|
|
|
|
);
|
2018-09-04 20:09:36 +03:00
|
|
|
},
|
|
|
|
|
|
|
|
isNoComments() {
|
2021-11-08 12:05:29 +01:00
|
|
|
const board = Utils.getCurrentBoard();
|
2018-09-04 20:09:36 +03:00
|
|
|
return board && board.hasNoComments(this._id);
|
|
|
|
},
|
|
|
|
|
2017-03-18 18:49:39 -04:00
|
|
|
isNotCommentOnly() {
|
2021-11-08 12:05:29 +01:00
|
|
|
const board = Utils.getCurrentBoard();
|
2019-06-26 17:47:27 -05:00
|
|
|
return (
|
|
|
|
board && board.hasMember(this._id) && !board.hasCommentOnly(this._id)
|
|
|
|
);
|
2017-03-18 18:49:39 -04:00
|
|
|
},
|
|
|
|
|
2017-03-18 15:22:40 -04:00
|
|
|
isCommentOnly() {
|
2021-11-08 12:05:29 +01:00
|
|
|
const board = Utils.getCurrentBoard();
|
2017-03-18 15:22:40 -04:00
|
|
|
return board && board.hasCommentOnly(this._id);
|
|
|
|
},
|
|
|
|
|
2020-01-05 21:28:14 +02:00
|
|
|
isNotWorker() {
|
2021-11-08 12:05:29 +01:00
|
|
|
const board = Utils.getCurrentBoard();
|
2020-01-05 21:28:14 +02:00
|
|
|
return board && board.hasMember(this._id) && !board.hasWorker(this._id);
|
|
|
|
},
|
|
|
|
|
|
|
|
isWorker() {
|
2021-11-08 12:05:29 +01:00
|
|
|
const board = Utils.getCurrentBoard();
|
2020-01-05 21:28:14 +02:00
|
|
|
return board && board.hasWorker(this._id);
|
|
|
|
},
|
|
|
|
|
2021-11-08 12:05:29 +01:00
|
|
|
isBoardAdmin(boardId) {
|
|
|
|
let board;
|
|
|
|
if (boardId) {
|
2023-01-14 13:29:57 +01:00
|
|
|
board = ReactiveCache.getBoard(boardId);
|
2021-11-08 12:05:29 +01:00
|
|
|
} else {
|
|
|
|
board = Utils.getCurrentBoard();
|
|
|
|
}
|
2015-12-08 16:03:31 +08:00
|
|
|
return board && board.hasAdmin(this._id);
|
2015-10-27 17:40:38 +01:00
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
2015-11-13 12:35:41 +01:00
|
|
|
|
2021-05-29 00:19:12 +03:00
|
|
|
Users.parseImportUsernames = (usernamesString) => {
|
2021-01-30 02:35:29 +02:00
|
|
|
return usernamesString.trim().split(new RegExp('\\s*[,;]\\s*'));
|
|
|
|
};
|
|
|
|
|
Renaissance
_,,ad8888888888bba,_
,ad88888I888888888888888ba,
,88888888I88888888888888888888a,
,d888888888I8888888888888888888888b,
d88888PP"""" ""YY88888888888888888888b,
,d88"'__,,--------,,,,.;ZZZY8888888888888,
,8IIl'" ;;l"ZZZIII8888888888,
,I88l;' ;lZZZZZ888III8888888,
,II88Zl;. ;llZZZZZ888888I888888,
,II888Zl;. .;;;;;lllZZZ888888I8888b
,II8888Z;; `;;;;;''llZZ8888888I8888,
II88888Z;' .;lZZZ8888888I888b
II88888Z; _,aaa, .,aaaaa,__.l;llZZZ88888888I888
II88888IZZZZZZZZZ, .ZZZZZZZZZZZZZZ;llZZ88888888I888,
II88888IZZ<'(@@>Z| |ZZZ<'(@@>ZZZZ;;llZZ888888888I88I
,II88888; `""" ;| |ZZ; `""" ;;llZ8888888888I888
II888888l `;; .;llZZ8888888888I888,
,II888888Z; ;;; .;;llZZZ8888888888I888I
III888888Zl; .., `;; ,;;lllZZZ88888888888I888
II88888888Z;;...;(_ _) ,;;;llZZZZ88888888888I888,
II88888888Zl;;;;;' `--'Z;. .,;;;;llZZZZ88888888888I888b
]I888888888Z;;;;' ";llllll;..;;;lllZZZZ88888888888I8888,
II888888888Zl.;;"Y88bd888P";;,..;lllZZZZZ88888888888I8888I
II8888888888Zl;.; `"PPP";;;,..;lllZZZZZZZ88888888888I88888
II888888888888Zl;;. `;;;l;;;;lllZZZZZZZZW88888888888I88888
`II8888888888888Zl;. ,;;lllZZZZZZZZWMZ88888888888I88888
II8888888888888888ZbaalllZZZZZZZZZWWMZZZ8888888888I888888,
`II88888888888888888b"WWZZZZZWWWMMZZZZZZI888888888I888888b
`II88888888888888888;ZZMMMMMMZZZZZZZZllI888888888I8888888
`II8888888888888888 `;lZZZZZZZZZZZlllll888888888I8888888,
II8888888888888888, `;lllZZZZllllll;;.Y88888888I8888888b,
,II8888888888888888b .;;lllllll;;;.;..88888888I88888888b,
II888888888888888PZI;. .`;;;.;;;..; ...88888888I8888888888,
II888888888888PZ;;';;. ;. .;. .;. .. Y8888888I88888888888b,
,II888888888PZ;;' `8888888I8888888888888b,
II888888888' 888888I8888888888888888
,II888888888 ,888888I8888888888888888
,d88888888888 d888888I8888888888ZZZZZZ
,ad888888888888I 8888888I8888ZZZZZZZZZZZZ
888888888888888' 888888IZZZZZZZZZZZZZZZZZ
8888888888P'8P' Y888ZZZZZZZZZZZZZZZZZZZZ
888888888, " ,ZZZZZZZZZZZZZZZZZZZZZZZ
8888888888, ,ZZZZZZZZZZZZZZZZZZZZZZZZZZ
888888888888a, _ ,ZZZZZZZZZZZZZZZZZZZZ88888888
888888888888888ba,_d' ,ZZZZZZZZZZZZZZZZZ8888888888888
8888888888888888888888bbbaaa,,,______,ZZZZZZZZZZZZZZZ88888888888888888
88888888888888888888888888888888888ZZZZZZZZZZZZZZZ88888888888888888888
8888888888888888888888888888888888ZZZZZZZZZZZZZZ8888888888888888888888
888888888888888888888888888888888ZZZZZZZZZZZZZZ88888888888888888888888
8888888888888888888888888888888ZZZZZZZZZZZZZZ8888888888888888888888888
88888888888888888888888888888ZZZZZZZZZZZZZZ888888888888888888888888888
8888888888888888888888888888ZZZZZZZZZZZZZZ88888888888888888 Normand 8
88888888888888888888888888ZZZZZZZZZZZZZZ8888888888888888888 Veilleux 8
8888888888888888888888888ZZZZZZZZZZZZZZ8888888888888888888888888888888
2015-05-12 19:20:58 +02:00
|
|
|
Users.helpers({
|
2021-01-30 02:35:29 +02:00
|
|
|
importUsernamesString() {
|
|
|
|
if (this.importUsernames) {
|
|
|
|
return this.importUsernames.join(', ');
|
|
|
|
}
|
|
|
|
return '';
|
|
|
|
},
|
2021-12-21 02:39:16 +02:00
|
|
|
teamIds() {
|
|
|
|
if (this.teams) {
|
2021-12-22 00:33:13 +02:00
|
|
|
// TODO: Should the Team collection be queried to determine if the team isActive?
|
2022-09-21 14:33:17 +02:00
|
|
|
return this.teams.map((team) => {
|
|
|
|
return team.teamId;
|
|
|
|
});
|
2021-12-21 02:39:16 +02:00
|
|
|
}
|
|
|
|
return [];
|
|
|
|
},
|
|
|
|
orgIds() {
|
|
|
|
if (this.orgs) {
|
2021-12-22 00:33:13 +02:00
|
|
|
// TODO: Should the Org collection be queried to determine if the organization isActive?
|
2022-09-21 14:33:17 +02:00
|
|
|
return this.orgs.map((org) => {
|
|
|
|
return org.orgId;
|
|
|
|
});
|
2021-12-21 02:39:16 +02:00
|
|
|
}
|
|
|
|
return [];
|
|
|
|
},
|
2021-06-10 16:38:28 +02:00
|
|
|
orgsUserBelongs() {
|
|
|
|
if (this.orgs) {
|
2022-09-21 14:33:17 +02:00
|
|
|
return this.orgs
|
|
|
|
.map(function (org) {
|
|
|
|
return org.orgDisplayName;
|
|
|
|
})
|
|
|
|
.sort()
|
|
|
|
.join(',');
|
2021-06-10 16:38:28 +02:00
|
|
|
}
|
|
|
|
return '';
|
|
|
|
},
|
|
|
|
orgIdsUserBelongs() {
|
2023-03-22 22:13:31 +01:00
|
|
|
let ret = '';
|
2021-06-10 16:38:28 +02:00
|
|
|
if (this.orgs) {
|
2023-03-22 22:13:31 +01:00
|
|
|
ret = this.orgs.map(org => org.orgId).join(',');
|
2021-06-10 16:38:28 +02:00
|
|
|
}
|
2023-03-22 22:13:31 +01:00
|
|
|
return ret;
|
2021-06-10 16:38:28 +02:00
|
|
|
},
|
|
|
|
teamsUserBelongs() {
|
|
|
|
if (this.teams) {
|
2022-09-21 14:33:17 +02:00
|
|
|
return this.teams
|
|
|
|
.map(function (team) {
|
|
|
|
return team.teamDisplayName;
|
|
|
|
})
|
|
|
|
.sort()
|
|
|
|
.join(',');
|
2021-06-10 16:38:28 +02:00
|
|
|
}
|
|
|
|
return '';
|
|
|
|
},
|
|
|
|
teamIdsUserBelongs() {
|
2023-03-22 22:13:31 +01:00
|
|
|
let ret = '';
|
2021-06-10 16:38:28 +02:00
|
|
|
if (this.teams) {
|
2023-03-22 22:13:31 +01:00
|
|
|
ret = this.teams.map(team => team.teamId).join(',');
|
2021-06-10 16:38:28 +02:00
|
|
|
}
|
2023-03-22 22:13:31 +01:00
|
|
|
return ret;
|
2021-06-10 16:38:28 +02:00
|
|
|
},
|
2015-09-03 23:12:46 +02:00
|
|
|
boards() {
|
2022-09-21 14:33:17 +02:00
|
|
|
return Boards.userBoards(this._id, null, {}, { sort: { sort: 1 } });
|
Renaissance
_,,ad8888888888bba,_
,ad88888I888888888888888ba,
,88888888I88888888888888888888a,
,d888888888I8888888888888888888888b,
d88888PP"""" ""YY88888888888888888888b,
,d88"'__,,--------,,,,.;ZZZY8888888888888,
,8IIl'" ;;l"ZZZIII8888888888,
,I88l;' ;lZZZZZ888III8888888,
,II88Zl;. ;llZZZZZ888888I888888,
,II888Zl;. .;;;;;lllZZZ888888I8888b
,II8888Z;; `;;;;;''llZZ8888888I8888,
II88888Z;' .;lZZZ8888888I888b
II88888Z; _,aaa, .,aaaaa,__.l;llZZZ88888888I888
II88888IZZZZZZZZZ, .ZZZZZZZZZZZZZZ;llZZ88888888I888,
II88888IZZ<'(@@>Z| |ZZZ<'(@@>ZZZZ;;llZZ888888888I88I
,II88888; `""" ;| |ZZ; `""" ;;llZ8888888888I888
II888888l `;; .;llZZ8888888888I888,
,II888888Z; ;;; .;;llZZZ8888888888I888I
III888888Zl; .., `;; ,;;lllZZZ88888888888I888
II88888888Z;;...;(_ _) ,;;;llZZZZ88888888888I888,
II88888888Zl;;;;;' `--'Z;. .,;;;;llZZZZ88888888888I888b
]I888888888Z;;;;' ";llllll;..;;;lllZZZZ88888888888I8888,
II888888888Zl.;;"Y88bd888P";;,..;lllZZZZZ88888888888I8888I
II8888888888Zl;.; `"PPP";;;,..;lllZZZZZZZ88888888888I88888
II888888888888Zl;;. `;;;l;;;;lllZZZZZZZZW88888888888I88888
`II8888888888888Zl;. ,;;lllZZZZZZZZWMZ88888888888I88888
II8888888888888888ZbaalllZZZZZZZZZWWMZZZ8888888888I888888,
`II88888888888888888b"WWZZZZZWWWMMZZZZZZI888888888I888888b
`II88888888888888888;ZZMMMMMMZZZZZZZZllI888888888I8888888
`II8888888888888888 `;lZZZZZZZZZZZlllll888888888I8888888,
II8888888888888888, `;lllZZZZllllll;;.Y88888888I8888888b,
,II8888888888888888b .;;lllllll;;;.;..88888888I88888888b,
II888888888888888PZI;. .`;;;.;;;..; ...88888888I8888888888,
II888888888888PZ;;';;. ;. .;. .;. .. Y8888888I88888888888b,
,II888888888PZ;;' `8888888I8888888888888b,
II888888888' 888888I8888888888888888
,II888888888 ,888888I8888888888888888
,d88888888888 d888888I8888888888ZZZZZZ
,ad888888888888I 8888888I8888ZZZZZZZZZZZZ
888888888888888' 888888IZZZZZZZZZZZZZZZZZ
8888888888P'8P' Y888ZZZZZZZZZZZZZZZZZZZZ
888888888, " ,ZZZZZZZZZZZZZZZZZZZZZZZ
8888888888, ,ZZZZZZZZZZZZZZZZZZZZZZZZZZ
888888888888a, _ ,ZZZZZZZZZZZZZZZZZZZZ88888888
888888888888888ba,_d' ,ZZZZZZZZZZZZZZZZZ8888888888888
8888888888888888888888bbbaaa,,,______,ZZZZZZZZZZZZZZZ88888888888888888
88888888888888888888888888888888888ZZZZZZZZZZZZZZZ88888888888888888888
8888888888888888888888888888888888ZZZZZZZZZZZZZZ8888888888888888888888
888888888888888888888888888888888ZZZZZZZZZZZZZZ88888888888888888888888
8888888888888888888888888888888ZZZZZZZZZZZZZZ8888888888888888888888888
88888888888888888888888888888ZZZZZZZZZZZZZZ888888888888888888888888888
8888888888888888888888888888ZZZZZZZZZZZZZZ88888888888888888 Normand 8
88888888888888888888888888ZZZZZZZZZZZZZZ8888888888888888888 Veilleux 8
8888888888888888888888888ZZZZZZZZZZZZZZ8888888888888888888888888888888
2015-05-12 19:20:58 +02:00
|
|
|
},
|
2015-09-05 01:31:25 +02:00
|
|
|
|
2015-09-03 23:12:46 +02:00
|
|
|
starredBoards() {
|
2019-06-26 17:47:27 -05:00
|
|
|
const { starredBoards = [] } = this.profile || {};
|
2021-12-21 02:39:16 +02:00
|
|
|
return Boards.userBoards(
|
|
|
|
this._id,
|
|
|
|
false,
|
|
|
|
{ _id: { $in: starredBoards } },
|
2022-09-21 14:33:17 +02:00
|
|
|
{ sort: { sort: 1 } },
|
2020-04-19 12:30:21 +03:00
|
|
|
);
|
Renaissance
_,,ad8888888888bba,_
,ad88888I888888888888888ba,
,88888888I88888888888888888888a,
,d888888888I8888888888888888888888b,
d88888PP"""" ""YY88888888888888888888b,
,d88"'__,,--------,,,,.;ZZZY8888888888888,
,8IIl'" ;;l"ZZZIII8888888888,
,I88l;' ;lZZZZZ888III8888888,
,II88Zl;. ;llZZZZZ888888I888888,
,II888Zl;. .;;;;;lllZZZ888888I8888b
,II8888Z;; `;;;;;''llZZ8888888I8888,
II88888Z;' .;lZZZ8888888I888b
II88888Z; _,aaa, .,aaaaa,__.l;llZZZ88888888I888
II88888IZZZZZZZZZ, .ZZZZZZZZZZZZZZ;llZZ88888888I888,
II88888IZZ<'(@@>Z| |ZZZ<'(@@>ZZZZ;;llZZ888888888I88I
,II88888; `""" ;| |ZZ; `""" ;;llZ8888888888I888
II888888l `;; .;llZZ8888888888I888,
,II888888Z; ;;; .;;llZZZ8888888888I888I
III888888Zl; .., `;; ,;;lllZZZ88888888888I888
II88888888Z;;...;(_ _) ,;;;llZZZZ88888888888I888,
II88888888Zl;;;;;' `--'Z;. .,;;;;llZZZZ88888888888I888b
]I888888888Z;;;;' ";llllll;..;;;lllZZZZ88888888888I8888,
II888888888Zl.;;"Y88bd888P";;,..;lllZZZZZ88888888888I8888I
II8888888888Zl;.; `"PPP";;;,..;lllZZZZZZZ88888888888I88888
II888888888888Zl;;. `;;;l;;;;lllZZZZZZZZW88888888888I88888
`II8888888888888Zl;. ,;;lllZZZZZZZZWMZ88888888888I88888
II8888888888888888ZbaalllZZZZZZZZZWWMZZZ8888888888I888888,
`II88888888888888888b"WWZZZZZWWWMMZZZZZZI888888888I888888b
`II88888888888888888;ZZMMMMMMZZZZZZZZllI888888888I8888888
`II8888888888888888 `;lZZZZZZZZZZZlllll888888888I8888888,
II8888888888888888, `;lllZZZZllllll;;.Y88888888I8888888b,
,II8888888888888888b .;;lllllll;;;.;..88888888I88888888b,
II888888888888888PZI;. .`;;;.;;;..; ...88888888I8888888888,
II888888888888PZ;;';;. ;. .;. .;. .. Y8888888I88888888888b,
,II888888888PZ;;' `8888888I8888888888888b,
II888888888' 888888I8888888888888888
,II888888888 ,888888I8888888888888888
,d88888888888 d888888I8888888888ZZZZZZ
,ad888888888888I 8888888I8888ZZZZZZZZZZZZ
888888888888888' 888888IZZZZZZZZZZZZZZZZZ
8888888888P'8P' Y888ZZZZZZZZZZZZZZZZZZZZ
888888888, " ,ZZZZZZZZZZZZZZZZZZZZZZZ
8888888888, ,ZZZZZZZZZZZZZZZZZZZZZZZZZZ
888888888888a, _ ,ZZZZZZZZZZZZZZZZZZZZ88888888
888888888888888ba,_d' ,ZZZZZZZZZZZZZZZZZ8888888888888
8888888888888888888888bbbaaa,,,______,ZZZZZZZZZZZZZZZ88888888888888888
88888888888888888888888888888888888ZZZZZZZZZZZZZZZ88888888888888888888
8888888888888888888888888888888888ZZZZZZZZZZZZZZ8888888888888888888888
888888888888888888888888888888888ZZZZZZZZZZZZZZ88888888888888888888888
8888888888888888888888888888888ZZZZZZZZZZZZZZ8888888888888888888888888
88888888888888888888888888888ZZZZZZZZZZZZZZ888888888888888888888888888
8888888888888888888888888888ZZZZZZZZZZZZZZ88888888888888888 Normand 8
88888888888888888888888888ZZZZZZZZZZZZZZ8888888888888888888 Veilleux 8
8888888888888888888888888ZZZZZZZZZZZZZZ8888888888888888888888888888888
2015-05-12 19:20:58 +02:00
|
|
|
},
|
2015-09-05 01:31:25 +02:00
|
|
|
|
2015-09-03 23:12:46 +02:00
|
|
|
hasStarred(boardId) {
|
2019-06-26 17:47:27 -05:00
|
|
|
const { starredBoards = [] } = this.profile || {};
|
2015-10-22 04:02:12 +02:00
|
|
|
return _.contains(starredBoards, boardId);
|
Renaissance
_,,ad8888888888bba,_
,ad88888I888888888888888ba,
,88888888I88888888888888888888a,
,d888888888I8888888888888888888888b,
d88888PP"""" ""YY88888888888888888888b,
,d88"'__,,--------,,,,.;ZZZY8888888888888,
,8IIl'" ;;l"ZZZIII8888888888,
,I88l;' ;lZZZZZ888III8888888,
,II88Zl;. ;llZZZZZ888888I888888,
,II888Zl;. .;;;;;lllZZZ888888I8888b
,II8888Z;; `;;;;;''llZZ8888888I8888,
II88888Z;' .;lZZZ8888888I888b
II88888Z; _,aaa, .,aaaaa,__.l;llZZZ88888888I888
II88888IZZZZZZZZZ, .ZZZZZZZZZZZZZZ;llZZ88888888I888,
II88888IZZ<'(@@>Z| |ZZZ<'(@@>ZZZZ;;llZZ888888888I88I
,II88888; `""" ;| |ZZ; `""" ;;llZ8888888888I888
II888888l `;; .;llZZ8888888888I888,
,II888888Z; ;;; .;;llZZZ8888888888I888I
III888888Zl; .., `;; ,;;lllZZZ88888888888I888
II88888888Z;;...;(_ _) ,;;;llZZZZ88888888888I888,
II88888888Zl;;;;;' `--'Z;. .,;;;;llZZZZ88888888888I888b
]I888888888Z;;;;' ";llllll;..;;;lllZZZZ88888888888I8888,
II888888888Zl.;;"Y88bd888P";;,..;lllZZZZZ88888888888I8888I
II8888888888Zl;.; `"PPP";;;,..;lllZZZZZZZ88888888888I88888
II888888888888Zl;;. `;;;l;;;;lllZZZZZZZZW88888888888I88888
`II8888888888888Zl;. ,;;lllZZZZZZZZWMZ88888888888I88888
II8888888888888888ZbaalllZZZZZZZZZWWMZZZ8888888888I888888,
`II88888888888888888b"WWZZZZZWWWMMZZZZZZI888888888I888888b
`II88888888888888888;ZZMMMMMMZZZZZZZZllI888888888I8888888
`II8888888888888888 `;lZZZZZZZZZZZlllll888888888I8888888,
II8888888888888888, `;lllZZZZllllll;;.Y88888888I8888888b,
,II8888888888888888b .;;lllllll;;;.;..88888888I88888888b,
II888888888888888PZI;. .`;;;.;;;..; ...88888888I8888888888,
II888888888888PZ;;';;. ;. .;. .;. .. Y8888888I88888888888b,
,II888888888PZ;;' `8888888I8888888888888b,
II888888888' 888888I8888888888888888
,II888888888 ,888888I8888888888888888
,d88888888888 d888888I8888888888ZZZZZZ
,ad888888888888I 8888888I8888ZZZZZZZZZZZZ
888888888888888' 888888IZZZZZZZZZZZZZZZZZ
8888888888P'8P' Y888ZZZZZZZZZZZZZZZZZZZZ
888888888, " ,ZZZZZZZZZZZZZZZZZZZZZZZ
8888888888, ,ZZZZZZZZZZZZZZZZZZZZZZZZZZ
888888888888a, _ ,ZZZZZZZZZZZZZZZZZZZZ88888888
888888888888888ba,_d' ,ZZZZZZZZZZZZZZZZZ8888888888888
8888888888888888888888bbbaaa,,,______,ZZZZZZZZZZZZZZZ88888888888888888
88888888888888888888888888888888888ZZZZZZZZZZZZZZZ88888888888888888888
8888888888888888888888888888888888ZZZZZZZZZZZZZZ8888888888888888888888
888888888888888888888888888888888ZZZZZZZZZZZZZZ88888888888888888888888
8888888888888888888888888888888ZZZZZZZZZZZZZZ8888888888888888888888888
88888888888888888888888888888ZZZZZZZZZZZZZZ888888888888888888888888888
8888888888888888888888888888ZZZZZZZZZZZZZZ88888888888888888 Normand 8
88888888888888888888888888ZZZZZZZZZZZZZZ8888888888888888888 Veilleux 8
8888888888888888888888888ZZZZZZZZZZZZZZ8888888888888888888888888888888
2015-05-12 19:20:58 +02:00
|
|
|
},
|
2015-09-05 01:31:25 +02:00
|
|
|
|
2024-12-07 18:59:30 +02:00
|
|
|
isAutoWidth(boardId) {
|
|
|
|
const { autoWidthBoards = {} } = this.profile || {};
|
|
|
|
return autoWidthBoards[boardId] === true;
|
2024-11-28 01:18:51 +02:00
|
|
|
},
|
|
|
|
|
2015-12-07 11:15:57 +08:00
|
|
|
invitedBoards() {
|
2019-06-26 17:47:27 -05:00
|
|
|
const { invitedBoards = [] } = this.profile || {};
|
2021-12-21 02:39:16 +02:00
|
|
|
return Boards.userBoards(
|
|
|
|
this._id,
|
|
|
|
false,
|
|
|
|
{ _id: { $in: invitedBoards } },
|
2022-09-21 14:33:17 +02:00
|
|
|
{ sort: { sort: 1 } },
|
2020-04-19 12:30:21 +03:00
|
|
|
);
|
2015-12-07 11:15:57 +08:00
|
|
|
},
|
|
|
|
|
|
|
|
isInvitedTo(boardId) {
|
2019-06-26 17:47:27 -05:00
|
|
|
const { invitedBoards = [] } = this.profile || {};
|
2015-12-07 11:15:57 +08:00
|
|
|
return _.contains(invitedBoards, boardId);
|
|
|
|
},
|
|
|
|
|
2019-10-18 16:44:09 -04:00
|
|
|
_getListSortBy() {
|
|
|
|
const profile = this.profile || {};
|
|
|
|
const sortBy = profile.listSortBy || defaultSortBy;
|
|
|
|
const keyPattern = /^(-{0,1})(.*$)/;
|
|
|
|
const ret = [];
|
|
|
|
if (keyPattern.exec(sortBy)) {
|
|
|
|
ret[0] = RegExp.$2;
|
|
|
|
ret[1] = RegExp.$1 ? -1 : 1;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
},
|
2019-11-19 14:09:36 +02:00
|
|
|
hasSortBy() {
|
|
|
|
// if use doesn't have dragHandle, then we can let user to choose sort list by different order
|
|
|
|
return !this.hasShowDesktopDragHandles();
|
|
|
|
},
|
2019-10-18 16:44:09 -04:00
|
|
|
getListSortBy() {
|
|
|
|
return this._getListSortBy()[0];
|
|
|
|
},
|
|
|
|
getListSortTypes() {
|
|
|
|
return allowedSortValues;
|
|
|
|
},
|
|
|
|
getListSortByDirection() {
|
|
|
|
return this._getListSortBy()[1];
|
|
|
|
},
|
|
|
|
|
2023-06-12 22:14:06 -05:00
|
|
|
getListWidths() {
|
2024-12-07 18:59:30 +02:00
|
|
|
const { listWidths = {}, } = this.profile || {};
|
2023-06-12 22:14:06 -05:00
|
|
|
return listWidths;
|
|
|
|
},
|
|
|
|
getListWidth(boardId, listId) {
|
|
|
|
const listWidths = this.getListWidths();
|
|
|
|
if (listWidths[boardId] && listWidths[boardId][listId]) {
|
|
|
|
return listWidths[boardId][listId];
|
|
|
|
} else {
|
|
|
|
return 270; //TODO(mark-i-m): default?
|
|
|
|
}
|
|
|
|
},
|
2024-12-07 18:59:30 +02:00
|
|
|
getListConstraints() {
|
|
|
|
const { listConstraints = {} } = this.profile || {};
|
|
|
|
return listConstraints;
|
|
|
|
},
|
|
|
|
getListConstraint(boardId, listId) {
|
|
|
|
const listConstraints = this.getListConstraints();
|
|
|
|
if (listConstraints[boardId] && listConstraints[boardId][listId]) {
|
|
|
|
return listConstraints[boardId][listId];
|
|
|
|
} else {
|
2024-12-10 21:23:12 +02:00
|
|
|
return 550;
|
2024-12-07 18:59:30 +02:00
|
|
|
}
|
|
|
|
},
|
2023-06-12 22:14:06 -05:00
|
|
|
|
2023-06-13 13:43:09 -05:00
|
|
|
getSwimlaneHeights() {
|
|
|
|
const { swimlaneHeights = {} } = this.profile || {};
|
|
|
|
return swimlaneHeights;
|
|
|
|
},
|
|
|
|
getSwimlaneHeight(boardId, listId) {
|
|
|
|
const swimlaneHeights = this.getSwimlaneHeights();
|
|
|
|
if (swimlaneHeights[boardId] && swimlaneHeights[boardId][listId]) {
|
|
|
|
return swimlaneHeights[boardId][listId];
|
|
|
|
} else {
|
2023-08-03 19:17:36 -05:00
|
|
|
return -1;
|
2023-06-13 13:43:09 -05:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2022-01-10 07:09:07 +01:00
|
|
|
/** returns all confirmed move and copy dialog field values
|
|
|
|
* <li> the board, swimlane and list id is stored for each board
|
|
|
|
*/
|
|
|
|
getMoveAndCopyDialogOptions() {
|
2022-09-21 14:33:17 +02:00
|
|
|
let _ret = {};
|
2022-01-10 07:09:07 +01:00
|
|
|
if (this.profile && this.profile.moveAndCopyDialog) {
|
|
|
|
_ret = this.profile.moveAndCopyDialog;
|
|
|
|
}
|
|
|
|
return _ret;
|
|
|
|
},
|
|
|
|
|
2022-01-11 19:42:57 +01:00
|
|
|
/** returns all confirmed move checklist dialog field values
|
|
|
|
* <li> the board, swimlane, list and card id is stored for each board
|
|
|
|
*/
|
|
|
|
getMoveChecklistDialogOptions() {
|
2022-09-21 14:33:17 +02:00
|
|
|
let _ret = {};
|
2022-01-11 19:42:57 +01:00
|
|
|
if (this.profile && this.profile.moveChecklistDialog) {
|
|
|
|
_ret = this.profile.moveChecklistDialog;
|
|
|
|
}
|
|
|
|
return _ret;
|
|
|
|
},
|
|
|
|
|
2022-01-30 12:32:52 +01:00
|
|
|
/** returns all confirmed copy checklist dialog field values
|
|
|
|
* <li> the board, swimlane, list and card id is stored for each board
|
|
|
|
*/
|
|
|
|
getCopyChecklistDialogOptions() {
|
2022-09-21 14:33:17 +02:00
|
|
|
let _ret = {};
|
2022-01-30 12:32:52 +01:00
|
|
|
if (this.profile && this.profile.copyChecklistDialog) {
|
|
|
|
_ret = this.profile.copyChecklistDialog;
|
|
|
|
}
|
|
|
|
return _ret;
|
|
|
|
},
|
|
|
|
|
2016-01-05 23:26:02 +08:00
|
|
|
hasTag(tag) {
|
2019-06-26 17:47:27 -05:00
|
|
|
const { tags = [] } = this.profile || {};
|
2016-01-05 23:26:02 +08:00
|
|
|
return _.contains(tags, tag);
|
|
|
|
},
|
|
|
|
|
|
|
|
hasNotification(activityId) {
|
2019-06-26 17:47:27 -05:00
|
|
|
const { notifications = [] } = this.profile || {};
|
2016-01-05 23:26:02 +08:00
|
|
|
return _.contains(notifications, activityId);
|
|
|
|
},
|
|
|
|
|
2020-03-27 11:35:03 -06:00
|
|
|
notifications() {
|
|
|
|
const { notifications = [] } = this.profile || {};
|
|
|
|
for (const index in notifications) {
|
|
|
|
if (!notifications.hasOwnProperty(index)) continue;
|
|
|
|
const notification = notifications[index];
|
|
|
|
// this preserves their db sort order for editing
|
|
|
|
notification.dbIndex = index;
|
2023-11-07 19:05:11 +01:00
|
|
|
if (!notification.activityObj && typeof(notification.activity) === 'string') {
|
2023-11-07 19:07:06 +01:00
|
|
|
notification.activityObj = ReactiveMiniMongoIndex.getActivityWithId(notification.activity);
|
2023-11-07 19:05:11 +01:00
|
|
|
}
|
2020-03-27 11:35:03 -06:00
|
|
|
}
|
2023-11-07 19:07:34 +01:00
|
|
|
// newest first. don't use reverse() because it changes the array inplace, so sometimes the array is reversed twice and oldest items at top again
|
|
|
|
const ret = notifications.toReversed();
|
|
|
|
return ret;
|
2020-03-27 11:35:03 -06:00
|
|
|
},
|
|
|
|
|
2019-11-19 14:09:36 +02:00
|
|
|
hasShowDesktopDragHandles() {
|
|
|
|
const profile = this.profile || {};
|
|
|
|
return profile.showDesktopDragHandles || false;
|
|
|
|
},
|
|
|
|
|
2021-09-22 12:14:42 +03:00
|
|
|
hasCustomFieldsGrid() {
|
|
|
|
const profile = this.profile || {};
|
|
|
|
return profile.customFieldsGrid || false;
|
|
|
|
},
|
|
|
|
|
2021-06-12 12:48:12 +03:00
|
|
|
hasCardMaximized() {
|
|
|
|
const profile = this.profile || {};
|
|
|
|
return profile.cardMaximized || false;
|
|
|
|
},
|
|
|
|
|
2019-11-19 14:09:36 +02:00
|
|
|
hasHiddenMinicardLabelText() {
|
|
|
|
const profile = this.profile || {};
|
|
|
|
return profile.hiddenMinicardLabelText || false;
|
|
|
|
},
|
|
|
|
|
2022-09-21 14:33:17 +02:00
|
|
|
hasRescuedCardDescription() {
|
2022-07-18 15:05:22 +02:00
|
|
|
const profile = this.profile || {};
|
|
|
|
return profile.rescueCardDescription || false;
|
|
|
|
},
|
|
|
|
|
2016-01-06 16:59:25 +08:00
|
|
|
getEmailBuffer() {
|
2019-06-26 17:47:27 -05:00
|
|
|
const { emailBuffer = [] } = this.profile || {};
|
2016-01-06 16:59:25 +08:00
|
|
|
return emailBuffer;
|
2016-01-05 23:26:02 +08:00
|
|
|
},
|
|
|
|
|
2015-09-03 23:12:46 +02:00
|
|
|
getInitials() {
|
|
|
|
const profile = this.profile || {};
|
2019-06-26 17:47:27 -05:00
|
|
|
if (profile.initials) return profile.initials;
|
2015-06-10 17:10:32 +02:00
|
|
|
else if (profile.fullname) {
|
2019-06-26 17:47:27 -05:00
|
|
|
return profile.fullname
|
|
|
|
.split(/\s+/)
|
|
|
|
.reduce((memo, word) => {
|
|
|
|
return memo + word[0];
|
|
|
|
}, '')
|
|
|
|
.toUpperCase();
|
2015-06-10 17:10:32 +02:00
|
|
|
} else {
|
2015-06-16 22:13:46 +02:00
|
|
|
return this.username[0].toUpperCase();
|
2015-06-10 17:10:32 +02:00
|
|
|
}
|
|
|
|
},
|
2015-12-04 10:39:51 +08:00
|
|
|
|
2016-11-25 21:45:11 +01:00
|
|
|
getLimitToShowCardsCount() {
|
2019-11-19 14:09:36 +02:00
|
|
|
const profile = this.profile || {};
|
|
|
|
return profile.showCardsCountAt;
|
2016-11-25 21:45:11 +01:00
|
|
|
},
|
|
|
|
|
2015-12-04 10:39:51 +08:00
|
|
|
getName() {
|
|
|
|
const profile = this.profile || {};
|
|
|
|
return profile.fullname || this.username;
|
|
|
|
},
|
|
|
|
|
|
|
|
getLanguage() {
|
|
|
|
const profile = this.profile || {};
|
|
|
|
return profile.language || 'en';
|
|
|
|
},
|
2019-02-22 22:59:19 +01:00
|
|
|
|
2020-04-22 14:44:08 +02:00
|
|
|
getStartDayOfWeek() {
|
|
|
|
const profile = this.profile || {};
|
2020-04-28 20:50:55 +02:00
|
|
|
if (typeof profile.startDayOfWeek === 'undefined') {
|
|
|
|
// default is 'Monday' (1)
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return profile.startDayOfWeek;
|
2020-04-22 14:44:08 +02:00
|
|
|
},
|
|
|
|
|
2019-02-22 23:48:23 +01:00
|
|
|
getTemplatesBoardId() {
|
2019-05-09 14:32:38 +03:00
|
|
|
return (this.profile || {}).templatesBoardId;
|
2019-02-22 23:48:23 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
getTemplatesBoardSlug() {
|
2023-02-04 16:57:56 +01:00
|
|
|
//return (ReactiveCache.getBoard((this.profile || {}).templatesBoardId) || {}).slug;
|
2021-12-25 21:59:43 +02:00
|
|
|
return 'templates';
|
2019-02-22 22:59:19 +01:00
|
|
|
},
|
2019-04-26 17:53:48 +02:00
|
|
|
|
2024-12-25 00:22:37 +02:00
|
|
|
isKeyboardShortcuts() {
|
|
|
|
const { keyboardShortcuts = false } = this.profile || {};
|
|
|
|
return keyboardShortcuts;
|
|
|
|
},
|
|
|
|
|
2019-04-26 17:53:48 +02:00
|
|
|
remove() {
|
2021-05-29 00:19:12 +03:00
|
|
|
User.remove({
|
|
|
|
_id: this._id,
|
|
|
|
});
|
2019-04-26 17:53:48 +02:00
|
|
|
},
|
2015-09-08 20:19:42 +02:00
|
|
|
});
|
2015-06-10 17:10:32 +02:00
|
|
|
|
2015-09-08 20:19:42 +02:00
|
|
|
Users.mutations({
|
2022-01-10 07:09:07 +01:00
|
|
|
/** set the confirmed board id/swimlane id/list id of a board
|
|
|
|
* @param boardId the current board id
|
|
|
|
* @param options an object with the confirmed field values
|
|
|
|
*/
|
|
|
|
setMoveAndCopyDialogOption(boardId, options) {
|
|
|
|
let currentOptions = this.getMoveAndCopyDialogOptions();
|
|
|
|
currentOptions[boardId] = options;
|
|
|
|
return {
|
|
|
|
$set: {
|
|
|
|
'profile.moveAndCopyDialog': currentOptions,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
},
|
2022-01-30 12:32:52 +01:00
|
|
|
/** set the confirmed board id/swimlane id/list id/card id of a board (move checklist)
|
2022-01-11 19:42:57 +01:00
|
|
|
* @param boardId the current board id
|
|
|
|
* @param options an object with the confirmed field values
|
|
|
|
*/
|
|
|
|
setMoveChecklistDialogOption(boardId, options) {
|
|
|
|
let currentOptions = this.getMoveChecklistDialogOptions();
|
|
|
|
currentOptions[boardId] = options;
|
|
|
|
return {
|
|
|
|
$set: {
|
|
|
|
'profile.moveChecklistDialog': currentOptions,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
},
|
2022-01-30 12:32:52 +01:00
|
|
|
/** set the confirmed board id/swimlane id/list id/card id of a board (copy checklist)
|
|
|
|
* @param boardId the current board id
|
|
|
|
* @param options an object with the confirmed field values
|
|
|
|
*/
|
|
|
|
setCopyChecklistDialogOption(boardId, options) {
|
|
|
|
let currentOptions = this.getCopyChecklistDialogOptions();
|
|
|
|
currentOptions[boardId] = options;
|
|
|
|
return {
|
|
|
|
$set: {
|
|
|
|
'profile.copyChecklistDialog': currentOptions,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
},
|
2015-09-03 23:12:46 +02:00
|
|
|
toggleBoardStar(boardId) {
|
|
|
|
const queryKind = this.hasStarred(boardId) ? '$pull' : '$addToSet';
|
2015-09-08 20:19:42 +02:00
|
|
|
return {
|
2015-09-03 23:12:46 +02:00
|
|
|
[queryKind]: {
|
|
|
|
'profile.starredBoards': boardId,
|
|
|
|
},
|
2015-09-08 20:19:42 +02:00
|
|
|
};
|
|
|
|
},
|
2024-11-28 01:18:51 +02:00
|
|
|
toggleAutoWidth(boardId) {
|
2024-12-07 18:59:30 +02:00
|
|
|
const { autoWidthBoards = {} } = this.profile || {};
|
|
|
|
autoWidthBoards[boardId] = !autoWidthBoards[boardId];
|
2024-11-28 01:18:51 +02:00
|
|
|
return {
|
|
|
|
$set: {
|
2024-12-07 18:59:30 +02:00
|
|
|
'profile.autoWidthBoards': autoWidthBoards,
|
2024-11-28 01:18:51 +02:00
|
|
|
},
|
|
|
|
};
|
|
|
|
},
|
2024-12-25 00:22:37 +02:00
|
|
|
toggleKeyboardShortcuts() {
|
|
|
|
const { keyboardShortcuts = false } = this.profile || {};
|
|
|
|
return {
|
|
|
|
$set: {
|
|
|
|
'profile.keyboardShortcuts': !keyboardShortcuts,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
},
|
2015-09-08 20:19:42 +02:00
|
|
|
|
2015-12-07 11:15:57 +08:00
|
|
|
addInvite(boardId) {
|
|
|
|
return {
|
|
|
|
$addToSet: {
|
|
|
|
'profile.invitedBoards': boardId,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
removeInvite(boardId) {
|
|
|
|
return {
|
|
|
|
$pull: {
|
|
|
|
'profile.invitedBoards': boardId,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
2016-01-05 23:26:02 +08:00
|
|
|
addTag(tag) {
|
|
|
|
return {
|
|
|
|
$addToSet: {
|
|
|
|
'profile.tags': tag,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
removeTag(tag) {
|
|
|
|
return {
|
|
|
|
$pull: {
|
|
|
|
'profile.tags': tag,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
toggleTag(tag) {
|
2019-06-26 17:47:27 -05:00
|
|
|
if (this.hasTag(tag)) this.removeTag(tag);
|
|
|
|
else this.addTag(tag);
|
2016-01-05 23:26:02 +08:00
|
|
|
},
|
|
|
|
|
2019-10-18 16:44:09 -04:00
|
|
|
setListSortBy(value) {
|
|
|
|
return {
|
|
|
|
$set: {
|
|
|
|
'profile.listSortBy': value,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
},
|
2020-12-18 05:46:04 +02:00
|
|
|
|
|
|
|
setName(value) {
|
|
|
|
return {
|
|
|
|
$set: {
|
|
|
|
'profile.fullname': value,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
2019-11-19 14:09:36 +02:00
|
|
|
toggleDesktopHandles(value = false) {
|
|
|
|
return {
|
|
|
|
$set: {
|
|
|
|
'profile.showDesktopDragHandles': !value,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
},
|
2019-09-17 01:39:10 +03:00
|
|
|
|
2021-09-22 12:14:42 +03:00
|
|
|
toggleFieldsGrid(value = false) {
|
|
|
|
return {
|
|
|
|
$set: {
|
|
|
|
'profile.customFieldsGrid': !value,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
2021-06-12 12:48:12 +03:00
|
|
|
toggleCardMaximized(value = false) {
|
|
|
|
return {
|
|
|
|
$set: {
|
|
|
|
'profile.cardMaximized': !value,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
2019-11-19 14:09:36 +02:00
|
|
|
toggleLabelText(value = false) {
|
|
|
|
return {
|
|
|
|
$set: {
|
|
|
|
'profile.hiddenMinicardLabelText': !value,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
},
|
2022-07-18 15:05:22 +02:00
|
|
|
toggleRescueCardDescription(value = false) {
|
|
|
|
return {
|
|
|
|
$set: {
|
|
|
|
'profile.rescueCardDescription': !value,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
},
|
2019-11-19 14:09:36 +02:00
|
|
|
|
2016-01-05 23:26:02 +08:00
|
|
|
addNotification(activityId) {
|
|
|
|
return {
|
|
|
|
$addToSet: {
|
2021-05-29 00:19:12 +03:00
|
|
|
'profile.notifications': {
|
|
|
|
activity: activityId,
|
|
|
|
},
|
2016-01-05 23:26:02 +08:00
|
|
|
},
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
removeNotification(activityId) {
|
|
|
|
return {
|
|
|
|
$pull: {
|
2021-05-29 00:19:12 +03:00
|
|
|
'profile.notifications': {
|
|
|
|
activity: activityId,
|
|
|
|
},
|
2016-01-05 23:26:02 +08:00
|
|
|
},
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
2016-01-06 16:59:25 +08:00
|
|
|
addEmailBuffer(text) {
|
2016-01-05 23:26:02 +08:00
|
|
|
return {
|
|
|
|
$addToSet: {
|
2016-01-06 16:59:25 +08:00
|
|
|
'profile.emailBuffer': text,
|
2016-01-05 23:26:02 +08:00
|
|
|
},
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
2016-01-06 16:59:25 +08:00
|
|
|
clearEmailBuffer() {
|
2016-01-05 23:26:02 +08:00
|
|
|
return {
|
|
|
|
$set: {
|
2016-01-06 16:59:25 +08:00
|
|
|
'profile.emailBuffer': [],
|
2016-01-05 23:26:02 +08:00
|
|
|
},
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
2015-09-08 20:19:42 +02:00
|
|
|
setAvatarUrl(avatarUrl) {
|
2021-05-29 00:19:12 +03:00
|
|
|
return {
|
|
|
|
$set: {
|
|
|
|
'profile.avatarUrl': avatarUrl,
|
|
|
|
},
|
|
|
|
};
|
2015-09-03 23:12:46 +02:00
|
|
|
},
|
2016-11-25 21:45:11 +01:00
|
|
|
|
|
|
|
setShowCardsCountAt(limit) {
|
2021-05-29 00:19:12 +03:00
|
|
|
return {
|
|
|
|
$set: {
|
|
|
|
'profile.showCardsCountAt': limit,
|
|
|
|
},
|
|
|
|
};
|
2016-11-25 21:45:11 +01:00
|
|
|
},
|
2018-04-16 14:33:53 -03:00
|
|
|
|
2020-04-22 14:44:08 +02:00
|
|
|
setStartDayOfWeek(startDay) {
|
2021-05-29 00:19:12 +03:00
|
|
|
return {
|
|
|
|
$set: {
|
|
|
|
'profile.startDayOfWeek': startDay,
|
|
|
|
},
|
|
|
|
};
|
2020-04-22 14:44:08 +02:00
|
|
|
},
|
|
|
|
|
2018-04-16 14:33:53 -03:00
|
|
|
setBoardView(view) {
|
|
|
|
return {
|
2019-06-26 17:47:27 -05:00
|
|
|
$set: {
|
2018-04-16 14:33:53 -03:00
|
|
|
'profile.boardView': view,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
},
|
2023-06-12 22:14:06 -05:00
|
|
|
|
|
|
|
setListWidth(boardId, listId, width) {
|
|
|
|
let currentWidths = this.getListWidths();
|
|
|
|
if (!currentWidths[boardId]) {
|
|
|
|
currentWidths[boardId] = {};
|
|
|
|
}
|
|
|
|
currentWidths[boardId][listId] = width;
|
|
|
|
return {
|
|
|
|
$set: {
|
|
|
|
'profile.listWidths': currentWidths,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
},
|
2023-06-13 13:43:09 -05:00
|
|
|
|
2024-12-07 18:59:01 +02:00
|
|
|
setListConstraint(boardId, listId, constraint) {
|
|
|
|
let currentConstraints = this.getListConstraints();
|
|
|
|
if (!currentConstraints[boardId]) {
|
|
|
|
currentConstraints[boardId] = {};
|
|
|
|
}
|
|
|
|
currentConstraints[boardId][listId] = constraint;
|
|
|
|
return {
|
|
|
|
$set: {
|
|
|
|
'profile.listConstraints': currentConstraints,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
2023-06-13 13:43:09 -05:00
|
|
|
setSwimlaneHeight(boardId, swimlaneId, height) {
|
|
|
|
let currentHeights = this.getSwimlaneHeights();
|
|
|
|
if (!currentHeights[boardId]) {
|
|
|
|
currentHeights[boardId] = {};
|
|
|
|
}
|
|
|
|
currentHeights[boardId][swimlaneId] = height;
|
|
|
|
return {
|
|
|
|
$set: {
|
|
|
|
'profile.swimlaneHeights': currentHeights,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
},
|
Renaissance
_,,ad8888888888bba,_
,ad88888I888888888888888ba,
,88888888I88888888888888888888a,
,d888888888I8888888888888888888888b,
d88888PP"""" ""YY88888888888888888888b,
,d88"'__,,--------,,,,.;ZZZY8888888888888,
,8IIl'" ;;l"ZZZIII8888888888,
,I88l;' ;lZZZZZ888III8888888,
,II88Zl;. ;llZZZZZ888888I888888,
,II888Zl;. .;;;;;lllZZZ888888I8888b
,II8888Z;; `;;;;;''llZZ8888888I8888,
II88888Z;' .;lZZZ8888888I888b
II88888Z; _,aaa, .,aaaaa,__.l;llZZZ88888888I888
II88888IZZZZZZZZZ, .ZZZZZZZZZZZZZZ;llZZ88888888I888,
II88888IZZ<'(@@>Z| |ZZZ<'(@@>ZZZZ;;llZZ888888888I88I
,II88888; `""" ;| |ZZ; `""" ;;llZ8888888888I888
II888888l `;; .;llZZ8888888888I888,
,II888888Z; ;;; .;;llZZZ8888888888I888I
III888888Zl; .., `;; ,;;lllZZZ88888888888I888
II88888888Z;;...;(_ _) ,;;;llZZZZ88888888888I888,
II88888888Zl;;;;;' `--'Z;. .,;;;;llZZZZ88888888888I888b
]I888888888Z;;;;' ";llllll;..;;;lllZZZZ88888888888I8888,
II888888888Zl.;;"Y88bd888P";;,..;lllZZZZZ88888888888I8888I
II8888888888Zl;.; `"PPP";;;,..;lllZZZZZZZ88888888888I88888
II888888888888Zl;;. `;;;l;;;;lllZZZZZZZZW88888888888I88888
`II8888888888888Zl;. ,;;lllZZZZZZZZWMZ88888888888I88888
II8888888888888888ZbaalllZZZZZZZZZWWMZZZ8888888888I888888,
`II88888888888888888b"WWZZZZZWWWMMZZZZZZI888888888I888888b
`II88888888888888888;ZZMMMMMMZZZZZZZZllI888888888I8888888
`II8888888888888888 `;lZZZZZZZZZZZlllll888888888I8888888,
II8888888888888888, `;lllZZZZllllll;;.Y88888888I8888888b,
,II8888888888888888b .;;lllllll;;;.;..88888888I88888888b,
II888888888888888PZI;. .`;;;.;;;..; ...88888888I8888888888,
II888888888888PZ;;';;. ;. .;. .;. .. Y8888888I88888888888b,
,II888888888PZ;;' `8888888I8888888888888b,
II888888888' 888888I8888888888888888
,II888888888 ,888888I8888888888888888
,d88888888888 d888888I8888888888ZZZZZZ
,ad888888888888I 8888888I8888ZZZZZZZZZZZZ
888888888888888' 888888IZZZZZZZZZZZZZZZZZ
8888888888P'8P' Y888ZZZZZZZZZZZZZZZZZZZZ
888888888, " ,ZZZZZZZZZZZZZZZZZZZZZZZ
8888888888, ,ZZZZZZZZZZZZZZZZZZZZZZZZZZ
888888888888a, _ ,ZZZZZZZZZZZZZZZZZZZZ88888888
888888888888888ba,_d' ,ZZZZZZZZZZZZZZZZZ8888888888888
8888888888888888888888bbbaaa,,,______,ZZZZZZZZZZZZZZZ88888888888888888
88888888888888888888888888888888888ZZZZZZZZZZZZZZZ88888888888888888888
8888888888888888888888888888888888ZZZZZZZZZZZZZZ8888888888888888888888
888888888888888888888888888888888ZZZZZZZZZZZZZZ88888888888888888888888
8888888888888888888888888888888ZZZZZZZZZZZZZZ8888888888888888888888888
88888888888888888888888888888ZZZZZZZZZZZZZZ888888888888888888888888888
8888888888888888888888888888ZZZZZZZZZZZZZZ88888888888888888 Normand 8
88888888888888888888888888ZZZZZZZZZZZZZZ8888888888888888888 Veilleux 8
8888888888888888888888888ZZZZZZZZZZZZZZ8888888888888888888888888888888
2015-05-12 19:20:58 +02:00
|
|
|
});
|
|
|
|
|
2015-06-01 17:56:00 +02:00
|
|
|
Meteor.methods({
|
2019-10-18 16:44:09 -04:00
|
|
|
setListSortBy(value) {
|
|
|
|
check(value, String);
|
2023-01-16 23:00:10 +01:00
|
|
|
ReactiveCache.getCurrentUser().setListSortBy(value);
|
2019-10-18 16:44:09 -04:00
|
|
|
},
|
2019-11-19 14:09:36 +02:00
|
|
|
toggleDesktopDragHandles() {
|
2023-01-16 23:00:10 +01:00
|
|
|
const user = ReactiveCache.getCurrentUser();
|
2019-11-19 14:09:36 +02:00
|
|
|
user.toggleDesktopHandles(user.hasShowDesktopDragHandles());
|
|
|
|
},
|
2020-06-09 23:32:00 +02:00
|
|
|
toggleHideCheckedItems() {
|
2023-01-16 23:00:10 +01:00
|
|
|
const user = ReactiveCache.getCurrentUser();
|
2020-06-09 23:32:00 +02:00
|
|
|
user.toggleHideCheckedItems();
|
|
|
|
},
|
2021-09-22 12:14:42 +03:00
|
|
|
toggleCustomFieldsGrid() {
|
2023-01-16 23:00:10 +01:00
|
|
|
const user = ReactiveCache.getCurrentUser();
|
2021-09-22 12:14:42 +03:00
|
|
|
user.toggleFieldsGrid(user.hasCustomFieldsGrid());
|
|
|
|
},
|
2021-06-12 12:48:12 +03:00
|
|
|
toggleCardMaximized() {
|
2023-01-16 23:00:10 +01:00
|
|
|
const user = ReactiveCache.getCurrentUser();
|
2021-06-12 12:48:12 +03:00
|
|
|
user.toggleCardMaximized(user.hasCardMaximized());
|
|
|
|
},
|
2019-11-19 14:09:36 +02:00
|
|
|
toggleMinicardLabelText() {
|
2023-01-16 23:00:10 +01:00
|
|
|
const user = ReactiveCache.getCurrentUser();
|
2019-11-19 14:09:36 +02:00
|
|
|
user.toggleLabelText(user.hasHiddenMinicardLabelText());
|
|
|
|
},
|
2022-07-18 15:05:22 +02:00
|
|
|
toggleRescueCardDescription() {
|
2023-01-16 23:00:10 +01:00
|
|
|
const user = ReactiveCache.getCurrentUser();
|
2022-07-18 15:05:22 +02:00
|
|
|
user.toggleRescueCardDescription(user.hasRescuedCardDescription());
|
|
|
|
},
|
2016-11-25 21:45:11 +01:00
|
|
|
changeLimitToShowCardsCount(limit) {
|
|
|
|
check(limit, Number);
|
2023-01-16 23:00:10 +01:00
|
|
|
ReactiveCache.getCurrentUser().setShowCardsCountAt(limit);
|
2016-11-25 21:53:18 +01:00
|
|
|
},
|
2020-04-22 14:44:08 +02:00
|
|
|
changeStartDayOfWeek(startDay) {
|
|
|
|
check(startDay, Number);
|
2023-01-16 23:00:10 +01:00
|
|
|
ReactiveCache.getCurrentUser().setStartDayOfWeek(startDay);
|
2020-04-22 14:44:08 +02:00
|
|
|
},
|
2024-12-07 18:59:01 +02:00
|
|
|
applyListWidth(boardId, listId, width, constraint) {
|
2023-06-12 22:14:06 -05:00
|
|
|
check(boardId, String);
|
|
|
|
check(listId, String);
|
|
|
|
check(width, Number);
|
2024-12-07 18:59:01 +02:00
|
|
|
check(constraint, Number);
|
2023-07-31 22:37:55 +02:00
|
|
|
const user = ReactiveCache.getCurrentUser();
|
2023-06-12 22:14:06 -05:00
|
|
|
user.setListWidth(boardId, listId, width);
|
2024-12-07 18:59:01 +02:00
|
|
|
user.setListConstraint(boardId, listId, constraint);
|
2023-06-12 22:14:06 -05:00
|
|
|
},
|
2023-06-13 13:43:09 -05:00
|
|
|
applySwimlaneHeight(boardId, swimlaneId, height) {
|
|
|
|
check(boardId, String);
|
|
|
|
check(swimlaneId, String);
|
|
|
|
check(height, Number);
|
2023-07-31 22:37:55 +02:00
|
|
|
const user = ReactiveCache.getCurrentUser();
|
2023-06-13 13:43:09 -05:00
|
|
|
user.setSwimlaneHeight(boardId, swimlaneId, height);
|
|
|
|
},
|
2015-06-01 17:56:00 +02:00
|
|
|
});
|
|
|
|
|
2015-12-07 11:15:57 +08:00
|
|
|
if (Meteor.isServer) {
|
|
|
|
Meteor.methods({
|
2021-01-30 02:35:29 +02:00
|
|
|
setCreateUser(
|
|
|
|
fullname,
|
|
|
|
username,
|
2021-02-24 18:31:44 +02:00
|
|
|
initials,
|
2021-01-30 02:35:29 +02:00
|
|
|
password,
|
|
|
|
isAdmin,
|
|
|
|
isActive,
|
|
|
|
email,
|
|
|
|
importUsernames,
|
2021-06-10 16:38:28 +02:00
|
|
|
userOrgsArray,
|
|
|
|
userTeamsArray,
|
2021-01-30 02:35:29 +02:00
|
|
|
) {
|
2021-06-11 14:28:25 +03:00
|
|
|
check(fullname, String);
|
|
|
|
check(username, String);
|
|
|
|
check(initials, String);
|
|
|
|
check(password, String);
|
|
|
|
check(isAdmin, String);
|
|
|
|
check(isActive, String);
|
|
|
|
check(email, String);
|
|
|
|
check(importUsernames, Array);
|
|
|
|
check(userOrgsArray, Array);
|
|
|
|
check(userTeamsArray, Array);
|
2023-10-31 16:04:25 +02:00
|
|
|
// Prevent Hyperlink Injection https://github.com/wekan/wekan/issues/5176
|
|
|
|
// Thanks to mc-marcy and xet7 !
|
|
|
|
if (fullname.includes('/') ||
|
|
|
|
username.includes('/') ||
|
|
|
|
email.includes('/') ||
|
|
|
|
initials.includes('/')) {
|
|
|
|
return false;
|
|
|
|
}
|
2023-01-16 23:00:10 +01:00
|
|
|
if (ReactiveCache.getCurrentUser()?.isAdmin) {
|
2023-02-22 22:53:48 +01:00
|
|
|
const nUsersWithUsername = ReactiveCache.getUsers({
|
2021-05-29 00:19:12 +03:00
|
|
|
username,
|
2023-02-22 22:53:48 +01:00
|
|
|
}).length;
|
|
|
|
const nUsersWithEmail = ReactiveCache.getUsers({
|
2021-05-29 00:19:12 +03:00
|
|
|
email,
|
2023-02-22 22:53:48 +01:00
|
|
|
}).length;
|
2020-03-01 20:59:53 +02:00
|
|
|
if (nUsersWithUsername > 0) {
|
|
|
|
throw new Meteor.Error('username-already-taken');
|
|
|
|
} else if (nUsersWithEmail > 0) {
|
|
|
|
throw new Meteor.Error('email-already-taken');
|
|
|
|
} else {
|
|
|
|
Accounts.createUser({
|
|
|
|
username,
|
|
|
|
password,
|
|
|
|
isAdmin,
|
|
|
|
isActive,
|
|
|
|
email: email.toLowerCase(),
|
|
|
|
from: 'admin',
|
|
|
|
});
|
2021-05-29 00:19:12 +03:00
|
|
|
const user =
|
2023-02-04 11:16:53 +01:00
|
|
|
ReactiveCache.getUser(username) ||
|
|
|
|
ReactiveCache.getUser({ username });
|
2020-12-18 05:46:04 +02:00
|
|
|
if (user) {
|
|
|
|
Users.update(user._id, {
|
2021-02-24 18:31:44 +02:00
|
|
|
$set: {
|
|
|
|
'profile.fullname': fullname,
|
|
|
|
importUsernames,
|
|
|
|
'profile.initials': initials,
|
2021-06-10 16:38:28 +02:00
|
|
|
orgs: userOrgsArray,
|
|
|
|
teams: userTeamsArray,
|
2021-02-24 18:31:44 +02:00
|
|
|
},
|
2020-12-18 05:46:04 +02:00
|
|
|
});
|
|
|
|
}
|
2020-03-01 20:59:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
setUsername(username, userId) {
|
2021-06-11 14:28:25 +03:00
|
|
|
check(username, String);
|
|
|
|
check(userId, String);
|
2023-10-31 16:04:25 +02:00
|
|
|
// Prevent Hyperlink Injection https://github.com/wekan/wekan/issues/5176
|
|
|
|
// Thanks to mc-marcy and xet7 !
|
|
|
|
if (username.includes('/') ||
|
|
|
|
userId.includes('/')) {
|
|
|
|
return false;
|
|
|
|
}
|
2023-01-16 23:00:10 +01:00
|
|
|
if (ReactiveCache.getCurrentUser()?.isAdmin) {
|
2023-02-22 22:53:48 +01:00
|
|
|
const nUsersWithUsername = ReactiveCache.getUsers({
|
2021-05-29 00:19:12 +03:00
|
|
|
username,
|
2023-02-22 22:53:48 +01:00
|
|
|
}).length;
|
2020-03-01 20:59:53 +02:00
|
|
|
if (nUsersWithUsername > 0) {
|
|
|
|
throw new Meteor.Error('username-already-taken');
|
|
|
|
} else {
|
2021-05-29 00:19:12 +03:00
|
|
|
Users.update(userId, {
|
|
|
|
$set: {
|
|
|
|
username,
|
|
|
|
},
|
|
|
|
});
|
2020-03-01 20:59:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
setEmail(email, userId) {
|
2021-06-11 14:28:25 +03:00
|
|
|
check(email, String);
|
|
|
|
check(username, String);
|
2023-10-31 16:04:25 +02:00
|
|
|
// Prevent Hyperlink Injection https://github.com/wekan/wekan/issues/5176
|
|
|
|
// Thanks to mc-marcy and xet7 !
|
|
|
|
if (username.includes('/') ||
|
|
|
|
email.includes('/')) {
|
|
|
|
return false;
|
|
|
|
}
|
2023-01-16 23:00:10 +01:00
|
|
|
if (ReactiveCache.getCurrentUser()?.isAdmin) {
|
2020-03-01 20:59:53 +02:00
|
|
|
if (Array.isArray(email)) {
|
|
|
|
email = email.shift();
|
|
|
|
}
|
2023-02-04 11:16:53 +01:00
|
|
|
const existingUser = ReactiveCache.getUser(
|
2021-05-29 00:19:12 +03:00
|
|
|
{
|
|
|
|
'emails.address': email,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
fields: {
|
|
|
|
_id: 1,
|
|
|
|
},
|
|
|
|
},
|
2020-03-01 20:59:53 +02:00
|
|
|
);
|
|
|
|
if (existingUser) {
|
|
|
|
throw new Meteor.Error('email-already-taken');
|
|
|
|
} else {
|
|
|
|
Users.update(userId, {
|
|
|
|
$set: {
|
|
|
|
emails: [
|
|
|
|
{
|
|
|
|
address: email,
|
|
|
|
verified: false,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
setUsernameAndEmail(username, email, userId) {
|
2021-06-11 14:28:25 +03:00
|
|
|
check(username, String);
|
|
|
|
check(email, String);
|
|
|
|
check(userId, String);
|
2023-10-31 16:04:25 +02:00
|
|
|
// Prevent Hyperlink Injection https://github.com/wekan/wekan/issues/5176
|
|
|
|
// Thanks to mc-marcy and xet7 !
|
|
|
|
if (username.includes('/') ||
|
|
|
|
email.includes('/') ||
|
|
|
|
userId.includes('/')) {
|
|
|
|
return false;
|
|
|
|
}
|
2023-01-16 23:00:10 +01:00
|
|
|
if (ReactiveCache.getCurrentUser()?.isAdmin) {
|
2020-03-01 20:59:53 +02:00
|
|
|
if (Array.isArray(email)) {
|
|
|
|
email = email.shift();
|
|
|
|
}
|
|
|
|
Meteor.call('setUsername', username, userId);
|
|
|
|
Meteor.call('setEmail', email, userId);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
setPassword(newPassword, userId) {
|
2021-06-11 14:28:25 +03:00
|
|
|
check(userId, String);
|
|
|
|
check(newPassword, String);
|
2023-01-16 23:00:10 +01:00
|
|
|
if (ReactiveCache.getCurrentUser()?.isAdmin) {
|
|
|
|
Accounts.setPassword(userId, newPassword);
|
2020-03-01 20:59:53 +02:00
|
|
|
}
|
|
|
|
},
|
2020-12-29 15:33:14 +02:00
|
|
|
setEmailVerified(email, verified, userId) {
|
2021-06-11 14:28:25 +03:00
|
|
|
check(email, String);
|
|
|
|
check(verified, Boolean);
|
|
|
|
check(userId, String);
|
2023-10-31 16:04:25 +02:00
|
|
|
// Prevent Hyperlink Injection https://github.com/wekan/wekan/issues/5176
|
|
|
|
// Thanks to mc-marcy and xet7 !
|
|
|
|
if (email.includes('/') ||
|
|
|
|
userId.includes('/')) {
|
|
|
|
return false;
|
|
|
|
}
|
2023-01-16 23:00:10 +01:00
|
|
|
if (ReactiveCache.getCurrentUser()?.isAdmin) {
|
2020-12-29 15:33:14 +02:00
|
|
|
Users.update(userId, {
|
|
|
|
$set: {
|
|
|
|
emails: [
|
|
|
|
{
|
|
|
|
address: email,
|
|
|
|
verified,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
setInitials(initials, userId) {
|
2021-06-11 14:28:25 +03:00
|
|
|
check(initials, String);
|
|
|
|
check(userId, String);
|
2023-10-31 16:04:25 +02:00
|
|
|
// Prevent Hyperlink Injection https://github.com/wekan/wekan/issues/5176
|
|
|
|
// Thanks to mc-marcy and xet7 !
|
|
|
|
if (initials.includes('/') ||
|
|
|
|
userId.includes('/')) {
|
|
|
|
return false;
|
|
|
|
}
|
2023-01-16 23:00:10 +01:00
|
|
|
if (ReactiveCache.getCurrentUser()?.isAdmin) {
|
2020-12-29 15:33:14 +02:00
|
|
|
Users.update(userId, {
|
|
|
|
$set: {
|
|
|
|
'profile.initials': initials,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
2015-12-07 11:15:57 +08:00
|
|
|
// we accept userId, username, email
|
|
|
|
inviteUserToBoard(username, boardId) {
|
|
|
|
check(username, String);
|
|
|
|
check(boardId, String);
|
2023-10-31 16:04:25 +02:00
|
|
|
// Prevent Hyperlink Injection https://github.com/wekan/wekan/issues/5176
|
|
|
|
// Thanks to mc-marcy and xet7 !
|
|
|
|
if (username.includes('/') ||
|
|
|
|
boardId.includes('/')) {
|
|
|
|
return false;
|
|
|
|
}
|
2023-01-16 23:00:10 +01:00
|
|
|
const inviter = ReactiveCache.getCurrentUser();
|
2023-01-14 13:29:57 +01:00
|
|
|
const board = ReactiveCache.getBoard(boardId);
|
2019-06-26 17:47:27 -05:00
|
|
|
const allowInvite =
|
|
|
|
inviter &&
|
2017-04-27 20:49:24 +03:00
|
|
|
board &&
|
|
|
|
board.members &&
|
|
|
|
_.contains(_.pluck(board.members, 'userId'), inviter._id) &&
|
2021-05-29 00:19:12 +03:00
|
|
|
_.where(board.members, {
|
|
|
|
userId: inviter._id,
|
|
|
|
})[0].isActive;
|
2019-08-15 13:29:37 +03:00
|
|
|
// GitHub issue 2060
|
|
|
|
//_.where(board.members, { userId: inviter._id })[0].isAdmin;
|
2015-12-07 11:15:57 +08:00
|
|
|
if (!allowInvite) throw new Meteor.Error('error-board-notAMember');
|
|
|
|
|
|
|
|
this.unblock();
|
|
|
|
|
|
|
|
const posAt = username.indexOf('@');
|
|
|
|
let user = null;
|
2017-04-27 20:49:24 +03:00
|
|
|
if (posAt >= 0) {
|
2023-02-04 11:16:53 +01:00
|
|
|
user = ReactiveCache.getUser({
|
2021-05-29 00:19:12 +03:00
|
|
|
emails: {
|
|
|
|
$elemMatch: {
|
|
|
|
address: username,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
2015-12-07 11:15:57 +08:00
|
|
|
} else {
|
2021-05-29 00:19:12 +03:00
|
|
|
user =
|
2023-02-04 11:16:53 +01:00
|
|
|
ReactiveCache.getUser(username) ||
|
|
|
|
ReactiveCache.getUser({ username });
|
2015-12-07 11:15:57 +08:00
|
|
|
}
|
|
|
|
if (user) {
|
2019-06-26 17:47:27 -05:00
|
|
|
if (user._id === inviter._id)
|
|
|
|
throw new Meteor.Error('error-user-notAllowSelf');
|
2015-12-07 11:15:57 +08:00
|
|
|
} else {
|
|
|
|
if (posAt <= 0) throw new Meteor.Error('error-user-doesNotExist');
|
2022-12-13 23:20:04 +01:00
|
|
|
if (ReactiveCache.getCurrentSetting().disableRegistration) {
|
2019-06-26 17:47:27 -05:00
|
|
|
throw new Meteor.Error('error-user-notCreated');
|
2020-03-01 20:59:53 +02:00
|
|
|
}
|
2017-03-04 20:42:25 -05:00
|
|
|
// Set in lowercase email before creating account
|
|
|
|
const email = username.toLowerCase();
|
2015-12-07 11:15:57 +08:00
|
|
|
username = email.substring(0, posAt);
|
2023-10-31 16:04:25 +02:00
|
|
|
// Prevent Hyperlink Injection https://github.com/wekan/wekan/issues/5176
|
|
|
|
// Thanks to mc-marcy and xet7 !
|
|
|
|
if (username.includes('/') ||
|
|
|
|
email.includes('/')) {
|
|
|
|
return false;
|
|
|
|
}
|
2021-05-29 00:19:12 +03:00
|
|
|
const newUserId = Accounts.createUser({
|
|
|
|
username,
|
|
|
|
email,
|
|
|
|
});
|
2015-12-07 11:15:57 +08:00
|
|
|
if (!newUserId) throw new Meteor.Error('error-user-notCreated');
|
|
|
|
// assume new user speak same language with inviter
|
|
|
|
if (inviter.profile && inviter.profile.language) {
|
|
|
|
Users.update(newUserId, {
|
|
|
|
$set: {
|
|
|
|
'profile.language': inviter.profile.language,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}
|
|
|
|
Accounts.sendEnrollmentEmail(newUserId);
|
2023-01-15 01:11:16 +01:00
|
|
|
user = ReactiveCache.getUser(newUserId);
|
2015-12-07 11:15:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
board.addMember(user._id);
|
|
|
|
user.addInvite(boardId);
|
|
|
|
|
2020-04-09 19:10:50 +01:00
|
|
|
//Check if there is a subtasks board
|
2020-04-11 17:28:15 -06:00
|
|
|
if (board.subtasksDefaultBoardId) {
|
2023-01-14 13:29:57 +01:00
|
|
|
const subBoard = ReactiveCache.getBoard(board.subtasksDefaultBoardId);
|
2020-04-09 19:10:50 +01:00
|
|
|
//If there is, also add user to that board
|
|
|
|
if (subBoard) {
|
|
|
|
subBoard.addMember(user._id);
|
|
|
|
user.addInvite(subBoard._id);
|
|
|
|
}
|
|
|
|
}
|
2020-04-11 17:28:15 -06:00
|
|
|
|
2017-04-01 21:46:09 +02:00
|
|
|
try {
|
2022-09-21 14:33:17 +02:00
|
|
|
const fullName =
|
|
|
|
inviter.profile !== undefined &&
|
2023-04-05 22:10:11 +02:00
|
|
|
inviter.profile.fullname !== undefined
|
2022-09-21 14:33:17 +02:00
|
|
|
? inviter.profile.fullname
|
|
|
|
: '';
|
|
|
|
const userFullName =
|
|
|
|
user.profile !== undefined && user.profile.fullname !== undefined
|
|
|
|
? user.profile.fullname
|
|
|
|
: '';
|
2017-04-01 21:46:09 +02:00
|
|
|
const params = {
|
2022-09-21 14:33:17 +02:00
|
|
|
user:
|
|
|
|
userFullName != ''
|
|
|
|
? userFullName + ' (' + user.username + ' )'
|
|
|
|
: user.username,
|
|
|
|
inviter:
|
|
|
|
fullName != ''
|
|
|
|
? fullName + ' (' + inviter.username + ' )'
|
|
|
|
: inviter.username,
|
2017-04-01 21:46:09 +02:00
|
|
|
board: board.title,
|
|
|
|
url: board.absoluteUrl(),
|
|
|
|
};
|
|
|
|
const lang = user.getLanguage();
|
2021-08-21 16:32:07 +03:00
|
|
|
|
2022-09-21 14:33:17 +02:00
|
|
|
/*
|
2021-08-21 16:32:07 +03:00
|
|
|
if (process.env.MAIL_SERVICE !== '') {
|
|
|
|
let transporter = nodemailer.createTransport({
|
|
|
|
service: process.env.MAIL_SERVICE,
|
|
|
|
auth: {
|
|
|
|
user: process.env.MAIL_SERVICE_USER,
|
|
|
|
pass: process.env.MAIL_SERVICE_PASSWORD
|
|
|
|
},
|
|
|
|
})
|
|
|
|
let info = transporter.sendMail({
|
|
|
|
to: user.emails[0].address.toLowerCase(),
|
|
|
|
from: Accounts.emailTemplates.from,
|
|
|
|
subject: TAPi18n.__('email-invite-subject', params, lang),
|
|
|
|
text: TAPi18n.__('email-invite-text', params, lang),
|
|
|
|
})
|
2021-08-27 14:35:37 +03:00
|
|
|
} else {
|
2021-08-21 16:32:07 +03:00
|
|
|
Email.send({
|
|
|
|
to: user.emails[0].address.toLowerCase(),
|
|
|
|
from: Accounts.emailTemplates.from,
|
|
|
|
subject: TAPi18n.__('email-invite-subject', params, lang),
|
|
|
|
text: TAPi18n.__('email-invite-text', params, lang),
|
|
|
|
});
|
|
|
|
}
|
2021-10-07 08:47:10 +03:00
|
|
|
*/
|
|
|
|
Email.send({
|
|
|
|
to: user.emails[0].address.toLowerCase(),
|
|
|
|
from: Accounts.emailTemplates.from,
|
|
|
|
subject: TAPi18n.__('email-invite-subject', params, lang),
|
|
|
|
text: TAPi18n.__('email-invite-text', params, lang),
|
|
|
|
});
|
2017-04-01 21:46:09 +02:00
|
|
|
} catch (e) {
|
|
|
|
throw new Meteor.Error('email-fail', e.message);
|
2015-12-07 11:15:57 +08:00
|
|
|
}
|
2021-05-29 00:19:12 +03:00
|
|
|
return {
|
|
|
|
username: user.username,
|
|
|
|
email: user.emails[0].address,
|
|
|
|
};
|
2015-12-07 11:15:57 +08:00
|
|
|
},
|
2020-09-16 18:11:19 +00:00
|
|
|
impersonate(userId) {
|
|
|
|
check(userId, String);
|
|
|
|
|
2023-02-04 17:25:09 +01:00
|
|
|
if (!ReactiveCache.getUser(userId))
|
2020-09-16 18:11:19 +00:00
|
|
|
throw new Meteor.Error(404, 'User not found');
|
2023-01-16 23:00:10 +01:00
|
|
|
if (!ReactiveCache.getCurrentUser().isAdmin)
|
2020-09-16 18:11:19 +00:00
|
|
|
throw new Meteor.Error(403, 'Permission denied');
|
|
|
|
|
2022-09-21 14:33:17 +02:00
|
|
|
ImpersonatedUsers.insert({
|
2023-01-16 23:00:10 +01:00
|
|
|
adminId: ReactiveCache.getCurrentUser()._id,
|
2022-09-21 14:33:17 +02:00
|
|
|
userId: userId,
|
|
|
|
reason: 'clickedImpersonate',
|
|
|
|
});
|
2020-09-16 18:11:19 +00:00
|
|
|
this.setUserId(userId);
|
|
|
|
},
|
2021-05-29 00:19:12 +03:00
|
|
|
isImpersonated(userId) {
|
|
|
|
check(userId, String);
|
2023-02-05 00:29:41 +01:00
|
|
|
const isImpersonated = ReactiveCache.getImpersonatedUser({ userId: userId });
|
2021-05-29 00:19:12 +03:00
|
|
|
return isImpersonated;
|
|
|
|
},
|
2021-12-22 11:49:50 +01:00
|
|
|
setUsersTeamsTeamDisplayName(teamId, teamDisplayName) {
|
|
|
|
check(teamId, String);
|
|
|
|
check(teamDisplayName, String);
|
2023-01-16 23:00:10 +01:00
|
|
|
if (ReactiveCache.getCurrentUser()?.isAdmin) {
|
2023-02-22 22:53:48 +01:00
|
|
|
ReactiveCache.getUsers({
|
2021-12-22 11:49:50 +01:00
|
|
|
teams: {
|
2022-09-21 14:33:17 +02:00
|
|
|
$elemMatch: { teamId: teamId },
|
|
|
|
},
|
|
|
|
}).forEach((user) => {
|
|
|
|
Users.update(
|
|
|
|
{
|
|
|
|
_id: user._id,
|
|
|
|
teams: {
|
|
|
|
$elemMatch: { teamId: teamId },
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
$set: {
|
|
|
|
'teams.$.teamDisplayName': teamDisplayName,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
);
|
2021-12-22 11:49:50 +01:00
|
|
|
});
|
2021-12-22 13:48:37 +01:00
|
|
|
}
|
2021-12-22 11:49:50 +01:00
|
|
|
},
|
|
|
|
setUsersOrgsOrgDisplayName(orgId, orgDisplayName) {
|
|
|
|
check(orgId, String);
|
|
|
|
check(orgDisplayName, String);
|
2023-01-16 23:00:10 +01:00
|
|
|
if (ReactiveCache.getCurrentUser()?.isAdmin) {
|
2023-02-22 22:53:48 +01:00
|
|
|
ReactiveCache.getUsers({
|
2021-12-22 11:49:50 +01:00
|
|
|
orgs: {
|
2022-09-21 14:33:17 +02:00
|
|
|
$elemMatch: { orgId: orgId },
|
|
|
|
},
|
|
|
|
}).forEach((user) => {
|
|
|
|
Users.update(
|
|
|
|
{
|
|
|
|
_id: user._id,
|
|
|
|
orgs: {
|
|
|
|
$elemMatch: { orgId: orgId },
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
$set: {
|
|
|
|
'orgs.$.orgDisplayName': orgDisplayName,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
);
|
2021-12-22 11:49:50 +01:00
|
|
|
});
|
2021-12-22 13:48:37 +01:00
|
|
|
}
|
2021-12-22 11:49:50 +01:00
|
|
|
},
|
2015-12-07 11:15:57 +08:00
|
|
|
});
|
2017-02-24 22:10:38 +08:00
|
|
|
Accounts.onCreateUser((options, user) => {
|
2023-07-31 21:38:00 +02:00
|
|
|
const userCount = ReactiveCache.getUsers({}, {}, true).count();
|
|
|
|
user.isAdmin = userCount === 0;
|
2017-09-25 21:03:18 +09:00
|
|
|
|
2018-04-09 16:49:07 +02:00
|
|
|
if (user.services.oidc) {
|
2019-06-29 10:02:23 -04:00
|
|
|
let email = user.services.oidc.email;
|
|
|
|
if (Array.isArray(email)) {
|
|
|
|
email = email.shift();
|
|
|
|
}
|
|
|
|
email = email.toLowerCase();
|
2018-10-02 00:21:43 +03:00
|
|
|
user.username = user.services.oidc.username;
|
2021-05-29 00:19:12 +03:00
|
|
|
user.emails = [
|
|
|
|
{
|
|
|
|
address: email,
|
|
|
|
verified: true,
|
|
|
|
},
|
|
|
|
];
|
2023-10-31 16:04:25 +02:00
|
|
|
|
|
|
|
|
|
|
|
// Prevent Hyperlink Injection https://github.com/wekan/wekan/issues/5176
|
|
|
|
// Thanks to mc-marcy and xet7 !
|
|
|
|
if (user.username.includes('/') ||
|
|
|
|
email.includes('/')) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-06-26 17:47:27 -05:00
|
|
|
const initials = user.services.oidc.fullname
|
2021-01-27 01:43:01 +00:00
|
|
|
.split(/\s+/)
|
|
|
|
.reduce((memo, word) => {
|
|
|
|
return memo + word[0];
|
|
|
|
}, '')
|
2019-06-26 17:47:27 -05:00
|
|
|
.toUpperCase();
|
|
|
|
user.profile = {
|
|
|
|
initials,
|
|
|
|
fullname: user.services.oidc.fullname,
|
2020-06-08 17:28:53 +03:00
|
|
|
boardView: 'board-view-swimlanes',
|
2019-06-26 17:47:27 -05:00
|
|
|
};
|
2018-10-09 21:16:47 +03:00
|
|
|
user.authenticationMethod = 'oauth2';
|
2018-04-09 16:49:07 +02:00
|
|
|
|
2018-04-10 11:44:54 +02:00
|
|
|
// see if any existing user has this email address or username, otherwise create new
|
2023-02-04 17:25:09 +01:00
|
|
|
const existingUser = ReactiveCache.getUser({
|
2021-05-29 00:19:12 +03:00
|
|
|
$or: [
|
|
|
|
{
|
|
|
|
'emails.address': email,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
username: user.username,
|
|
|
|
},
|
|
|
|
],
|
2019-06-26 17:47:27 -05:00
|
|
|
});
|
|
|
|
if (!existingUser) return user;
|
2018-04-10 11:44:54 +02:00
|
|
|
|
|
|
|
// copy across new service info
|
2018-08-25 00:49:02 +03:00
|
|
|
const service = _.keys(user.services)[0];
|
2018-04-10 11:44:54 +02:00
|
|
|
existingUser.services[service] = user.services[service];
|
|
|
|
existingUser.emails = user.emails;
|
|
|
|
existingUser.username = user.username;
|
|
|
|
existingUser.profile = user.profile;
|
2018-10-09 21:16:47 +03:00
|
|
|
existingUser.authenticationMethod = user.authenticationMethod;
|
2018-04-10 11:44:54 +02:00
|
|
|
|
2021-05-29 00:19:12 +03:00
|
|
|
Meteor.users.remove({
|
|
|
|
_id: user._id,
|
|
|
|
});
|
|
|
|
Meteor.users.remove({
|
|
|
|
_id: existingUser._id,
|
|
|
|
}); // is going to be created again
|
2018-04-10 11:44:54 +02:00
|
|
|
return existingUser;
|
|
|
|
}
|
2018-04-09 16:49:07 +02:00
|
|
|
|
2017-09-25 22:14:13 +09:00
|
|
|
if (options.from === 'admin') {
|
2017-10-06 23:08:22 +09:00
|
|
|
user.createdThroughApi = true;
|
2017-09-25 21:03:18 +09:00
|
|
|
return user;
|
|
|
|
}
|
|
|
|
|
2022-12-13 23:20:04 +01:00
|
|
|
const disableRegistration = ReactiveCache.getCurrentSetting().disableRegistration;
|
2018-12-13 14:27:34 +02:00
|
|
|
// If this is the first Authentication by the ldap and self registration disabled
|
2018-12-13 20:07:55 +02:00
|
|
|
if (disableRegistration && options && options.ldap) {
|
2018-12-13 14:27:34 +02:00
|
|
|
user.authenticationMethod = 'ldap';
|
|
|
|
return user;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If self registration enabled
|
2018-11-22 18:00:21 +01:00
|
|
|
if (!disableRegistration) {
|
2017-02-24 22:10:38 +08:00
|
|
|
return user;
|
|
|
|
}
|
|
|
|
|
2017-03-28 00:48:18 +08:00
|
|
|
if (!options || !options.profile) {
|
2019-06-26 17:47:27 -05:00
|
|
|
throw new Meteor.Error(
|
|
|
|
'error-invitation-code-blank',
|
2019-06-28 12:52:09 -05:00
|
|
|
'The invitation code is required',
|
2019-06-26 17:47:27 -05:00
|
|
|
);
|
2017-03-28 00:48:18 +08:00
|
|
|
}
|
2023-02-05 11:17:56 +01:00
|
|
|
const invitationCode = ReactiveCache.getInvitationCode({
|
2017-11-08 11:34:37 +07:00
|
|
|
code: options.profile.invitationcode,
|
|
|
|
email: options.email,
|
2017-11-16 14:14:03 +07:00
|
|
|
valid: true,
|
2017-11-08 11:34:37 +07:00
|
|
|
});
|
2017-02-24 22:10:38 +08:00
|
|
|
if (!invitationCode) {
|
2019-06-26 17:47:27 -05:00
|
|
|
throw new Meteor.Error(
|
|
|
|
'error-invitation-code-not-exist',
|
2019-06-28 12:52:09 -05:00
|
|
|
// eslint-disable-next-line quotes
|
|
|
|
"The invitation code doesn't exist",
|
2019-06-26 17:47:27 -05:00
|
|
|
);
|
2017-04-27 20:49:24 +03:00
|
|
|
} else {
|
2021-05-29 00:19:12 +03:00
|
|
|
user.profile = {
|
|
|
|
icode: options.profile.invitationcode,
|
|
|
|
};
|
2020-06-08 17:28:53 +03:00
|
|
|
user.profile.boardView = 'board-view-swimlanes';
|
2018-07-16 19:20:47 +02:00
|
|
|
|
2018-07-18 10:07:03 +02:00
|
|
|
// Deletes the invitation code after the user was created successfully.
|
2019-06-26 17:47:27 -05:00
|
|
|
setTimeout(
|
|
|
|
Meteor.bindEnvironment(() => {
|
2021-05-29 00:19:12 +03:00
|
|
|
InvitationCodes.remove({
|
|
|
|
_id: invitationCode._id,
|
|
|
|
});
|
2019-06-26 17:47:27 -05:00
|
|
|
}),
|
2019-06-28 12:52:09 -05:00
|
|
|
200,
|
2019-06-26 17:47:27 -05:00
|
|
|
);
|
2018-07-18 10:07:03 +02:00
|
|
|
return user;
|
|
|
|
}
|
2017-02-24 22:10:38 +08:00
|
|
|
});
|
2015-12-07 11:15:57 +08:00
|
|
|
}
|
|
|
|
|
2020-04-08 11:54:00 -06:00
|
|
|
const addCronJob = _.debounce(
|
|
|
|
Meteor.bindEnvironment(function notificationCleanupDebounced() {
|
|
|
|
// passed in the removeAge has to be a number standing for the number of days after a notification is read before we remove it
|
2020-04-08 23:16:48 +03:00
|
|
|
const envRemoveAge =
|
|
|
|
process.env.NOTIFICATION_TRAY_AFTER_READ_DAYS_BEFORE_REMOVE;
|
2020-04-08 11:54:00 -06:00
|
|
|
// default notifications will be removed 2 days after they are read
|
|
|
|
const defaultRemoveAge = 2;
|
|
|
|
const removeAge = parseInt(envRemoveAge, 10) || defaultRemoveAge;
|
|
|
|
|
|
|
|
SyncedCron.add({
|
|
|
|
name: 'notification_cleanup',
|
2021-05-29 00:19:12 +03:00
|
|
|
schedule: (parser) => parser.text('every 1 days'),
|
2020-04-08 11:54:00 -06:00
|
|
|
job: () => {
|
2023-02-22 22:53:48 +01:00
|
|
|
for (const user of ReactiveCache.getUsers()) {
|
2020-04-11 17:28:15 -06:00
|
|
|
if (!user.profile || !user.profile.notifications) continue;
|
2020-04-08 11:54:00 -06:00
|
|
|
for (const notification of user.profile.notifications) {
|
|
|
|
if (notification.read) {
|
|
|
|
const removeDate = new Date(notification.read);
|
|
|
|
removeDate.setDate(removeDate.getDate() + removeAge);
|
|
|
|
if (removeDate <= new Date()) {
|
|
|
|
user.removeNotification(notification.activity);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
SyncedCron.start();
|
|
|
|
}),
|
|
|
|
500,
|
|
|
|
);
|
|
|
|
|
Renaissance
_,,ad8888888888bba,_
,ad88888I888888888888888ba,
,88888888I88888888888888888888a,
,d888888888I8888888888888888888888b,
d88888PP"""" ""YY88888888888888888888b,
,d88"'__,,--------,,,,.;ZZZY8888888888888,
,8IIl'" ;;l"ZZZIII8888888888,
,I88l;' ;lZZZZZ888III8888888,
,II88Zl;. ;llZZZZZ888888I888888,
,II888Zl;. .;;;;;lllZZZ888888I8888b
,II8888Z;; `;;;;;''llZZ8888888I8888,
II88888Z;' .;lZZZ8888888I888b
II88888Z; _,aaa, .,aaaaa,__.l;llZZZ88888888I888
II88888IZZZZZZZZZ, .ZZZZZZZZZZZZZZ;llZZ88888888I888,
II88888IZZ<'(@@>Z| |ZZZ<'(@@>ZZZZ;;llZZ888888888I88I
,II88888; `""" ;| |ZZ; `""" ;;llZ8888888888I888
II888888l `;; .;llZZ8888888888I888,
,II888888Z; ;;; .;;llZZZ8888888888I888I
III888888Zl; .., `;; ,;;lllZZZ88888888888I888
II88888888Z;;...;(_ _) ,;;;llZZZZ88888888888I888,
II88888888Zl;;;;;' `--'Z;. .,;;;;llZZZZ88888888888I888b
]I888888888Z;;;;' ";llllll;..;;;lllZZZZ88888888888I8888,
II888888888Zl.;;"Y88bd888P";;,..;lllZZZZZ88888888888I8888I
II8888888888Zl;.; `"PPP";;;,..;lllZZZZZZZ88888888888I88888
II888888888888Zl;;. `;;;l;;;;lllZZZZZZZZW88888888888I88888
`II8888888888888Zl;. ,;;lllZZZZZZZZWMZ88888888888I88888
II8888888888888888ZbaalllZZZZZZZZZWWMZZZ8888888888I888888,
`II88888888888888888b"WWZZZZZWWWMMZZZZZZI888888888I888888b
`II88888888888888888;ZZMMMMMMZZZZZZZZllI888888888I8888888
`II8888888888888888 `;lZZZZZZZZZZZlllll888888888I8888888,
II8888888888888888, `;lllZZZZllllll;;.Y88888888I8888888b,
,II8888888888888888b .;;lllllll;;;.;..88888888I88888888b,
II888888888888888PZI;. .`;;;.;;;..; ...88888888I8888888888,
II888888888888PZ;;';;. ;. .;. .;. .. Y8888888I88888888888b,
,II888888888PZ;;' `8888888I8888888888888b,
II888888888' 888888I8888888888888888
,II888888888 ,888888I8888888888888888
,d88888888888 d888888I8888888888ZZZZZZ
,ad888888888888I 8888888I8888ZZZZZZZZZZZZ
888888888888888' 888888IZZZZZZZZZZZZZZZZZ
8888888888P'8P' Y888ZZZZZZZZZZZZZZZZZZZZ
888888888, " ,ZZZZZZZZZZZZZZZZZZZZZZZ
8888888888, ,ZZZZZZZZZZZZZZZZZZZZZZZZZZ
888888888888a, _ ,ZZZZZZZZZZZZZZZZZZZZ88888888
888888888888888ba,_d' ,ZZZZZZZZZZZZZZZZZ8888888888888
8888888888888888888888bbbaaa,,,______,ZZZZZZZZZZZZZZZ88888888888888888
88888888888888888888888888888888888ZZZZZZZZZZZZZZZ88888888888888888888
8888888888888888888888888888888888ZZZZZZZZZZZZZZ8888888888888888888888
888888888888888888888888888888888ZZZZZZZZZZZZZZ88888888888888888888888
8888888888888888888888888888888ZZZZZZZZZZZZZZ8888888888888888888888888
88888888888888888888888888888ZZZZZZZZZZZZZZ888888888888888888888888888
8888888888888888888888888888ZZZZZZZZZZZZZZ88888888888888888 Normand 8
88888888888888888888888888ZZZZZZZZZZZZZZ8888888888888888888 Veilleux 8
8888888888888888888888888ZZZZZZZZZZZZZZ8888888888888888888888888888888
2015-05-12 19:20:58 +02:00
|
|
|
if (Meteor.isServer) {
|
2015-06-01 17:56:00 +02:00
|
|
|
// Let mongoDB ensure username unicity
|
2015-09-03 23:12:46 +02:00
|
|
|
Meteor.startup(() => {
|
2021-05-29 00:19:12 +03:00
|
|
|
allowedSortValues.forEach((value) => {
|
2021-10-09 15:56:16 +03:00
|
|
|
Lists._collection.createIndex(value);
|
2019-10-18 16:44:09 -04:00
|
|
|
});
|
2021-10-09 15:56:16 +03:00
|
|
|
Users._collection.createIndex({
|
2021-05-29 00:19:12 +03:00
|
|
|
modifiedAt: -1,
|
|
|
|
});
|
2023-11-09 12:11:36 +02:00
|
|
|
// Avatar URLs from CollectionFS to Meteor-Files, at users collection avatarUrl field:
|
|
|
|
Users.find({ "profile.avatarUrl": { $regex: "/cfs/files/avatars/" } }).forEach(function (doc) {
|
|
|
|
doc.profile.avatarUrl = doc.profile.avatarUrl.replace("/cfs/files/avatars/", "/cdn/storage/avatars/");
|
2023-11-09 17:16:02 +02:00
|
|
|
// Try to fix Users.save is not a fuction, by commenting it out:
|
|
|
|
//Users.save(doc);
|
2023-11-09 12:11:36 +02:00
|
|
|
});
|
|
|
|
/* TODO: Optionally, for additional complexity:
|
|
|
|
a) Support SubURLs with parthname from ROOT_URL
|
|
|
|
b) Remove beginning or avatar URL, replace it with pathname and new avatar URL
|
|
|
|
c) Does all avatar and attachment URLs need to be fixed every time when starting or restarting?
|
|
|
|
d) What if avatar URL is at some other server? In that case, links would point incorrectly to this instance, if ROOT_URL and path part is removed.
|
|
|
|
doc.profile.avatarUrl = process.env.ROOT_URL.pathname + doc.profile.avatarUrl.replace("/cfs/files/avatars/", "/cdn/storage/avatars/").substring(str.indexOf("/cdn/storage/avatars"));
|
|
|
|
*/
|
2022-09-21 14:33:17 +02:00
|
|
|
/* Commented out extra index because of IndexOptionsConflict.
|
2021-10-09 15:56:16 +03:00
|
|
|
Users._collection.createIndex(
|
2019-06-26 17:47:27 -05:00
|
|
|
{
|
|
|
|
username: 1,
|
|
|
|
},
|
2021-05-29 00:19:12 +03:00
|
|
|
{
|
|
|
|
unique: true,
|
|
|
|
},
|
2019-06-26 17:47:27 -05:00
|
|
|
);
|
2021-10-09 16:11:19 +03:00
|
|
|
*/
|
2020-04-08 11:54:00 -06:00
|
|
|
Meteor.defer(() => {
|
|
|
|
addCronJob();
|
|
|
|
});
|
2015-06-01 17:56:00 +02:00
|
|
|
});
|
|
|
|
|
2019-05-09 16:17:53 +03:00
|
|
|
// OLD WAY THIS CODE DID WORK: When user is last admin of board,
|
|
|
|
// if admin is removed, board is removed.
|
|
|
|
// NOW THIS IS COMMENTED OUT, because other board users still need to be able
|
|
|
|
// to use that board, and not have board deleted.
|
|
|
|
// Someone can be later changed to be admin of board, by making change to database.
|
|
|
|
// TODO: Add UI for changing someone as board admin.
|
|
|
|
//Users.before.remove((userId, doc) => {
|
|
|
|
// Boards
|
|
|
|
// .find({members: {$elemMatch: {userId: doc._id, isAdmin: true}}})
|
|
|
|
// .forEach((board) => {
|
|
|
|
// // If only one admin for the board
|
|
|
|
// if (board.members.filter((e) => e.isAdmin).length === 1) {
|
|
|
|
// Boards.remove(board._id);
|
|
|
|
// }
|
|
|
|
// });
|
|
|
|
//});
|
2019-04-26 17:53:48 +02:00
|
|
|
|
Renaissance
_,,ad8888888888bba,_
,ad88888I888888888888888ba,
,88888888I88888888888888888888a,
,d888888888I8888888888888888888888b,
d88888PP"""" ""YY88888888888888888888b,
,d88"'__,,--------,,,,.;ZZZY8888888888888,
,8IIl'" ;;l"ZZZIII8888888888,
,I88l;' ;lZZZZZ888III8888888,
,II88Zl;. ;llZZZZZ888888I888888,
,II888Zl;. .;;;;;lllZZZ888888I8888b
,II8888Z;; `;;;;;''llZZ8888888I8888,
II88888Z;' .;lZZZ8888888I888b
II88888Z; _,aaa, .,aaaaa,__.l;llZZZ88888888I888
II88888IZZZZZZZZZ, .ZZZZZZZZZZZZZZ;llZZ88888888I888,
II88888IZZ<'(@@>Z| |ZZZ<'(@@>ZZZZ;;llZZ888888888I88I
,II88888; `""" ;| |ZZ; `""" ;;llZ8888888888I888
II888888l `;; .;llZZ8888888888I888,
,II888888Z; ;;; .;;llZZZ8888888888I888I
III888888Zl; .., `;; ,;;lllZZZ88888888888I888
II88888888Z;;...;(_ _) ,;;;llZZZZ88888888888I888,
II88888888Zl;;;;;' `--'Z;. .,;;;;llZZZZ88888888888I888b
]I888888888Z;;;;' ";llllll;..;;;lllZZZZ88888888888I8888,
II888888888Zl.;;"Y88bd888P";;,..;lllZZZZZ88888888888I8888I
II8888888888Zl;.; `"PPP";;;,..;lllZZZZZZZ88888888888I88888
II888888888888Zl;;. `;;;l;;;;lllZZZZZZZZW88888888888I88888
`II8888888888888Zl;. ,;;lllZZZZZZZZWMZ88888888888I88888
II8888888888888888ZbaalllZZZZZZZZZWWMZZZ8888888888I888888,
`II88888888888888888b"WWZZZZZWWWMMZZZZZZI888888888I888888b
`II88888888888888888;ZZMMMMMMZZZZZZZZllI888888888I8888888
`II8888888888888888 `;lZZZZZZZZZZZlllll888888888I8888888,
II8888888888888888, `;lllZZZZllllll;;.Y88888888I8888888b,
,II8888888888888888b .;;lllllll;;;.;..88888888I88888888b,
II888888888888888PZI;. .`;;;.;;;..; ...88888888I8888888888,
II888888888888PZ;;';;. ;. .;. .;. .. Y8888888I88888888888b,
,II888888888PZ;;' `8888888I8888888888888b,
II888888888' 888888I8888888888888888
,II888888888 ,888888I8888888888888888
,d88888888888 d888888I8888888888ZZZZZZ
,ad888888888888I 8888888I8888ZZZZZZZZZZZZ
888888888888888' 888888IZZZZZZZZZZZZZZZZZ
8888888888P'8P' Y888ZZZZZZZZZZZZZZZZZZZZ
888888888, " ,ZZZZZZZZZZZZZZZZZZZZZZZ
8888888888, ,ZZZZZZZZZZZZZZZZZZZZZZZZZZ
888888888888a, _ ,ZZZZZZZZZZZZZZZZZZZZ88888888
888888888888888ba,_d' ,ZZZZZZZZZZZZZZZZZ8888888888888
8888888888888888888888bbbaaa,,,______,ZZZZZZZZZZZZZZZ88888888888888888
88888888888888888888888888888888888ZZZZZZZZZZZZZZZ88888888888888888888
8888888888888888888888888888888888ZZZZZZZZZZZZZZ8888888888888888888888
888888888888888888888888888888888ZZZZZZZZZZZZZZ88888888888888888888888
8888888888888888888888888888888ZZZZZZZZZZZZZZ8888888888888888888888888
88888888888888888888888888888ZZZZZZZZZZZZZZ888888888888888888888888888
8888888888888888888888888888ZZZZZZZZZZZZZZ88888888888888888 Normand 8
88888888888888888888888888ZZZZZZZZZZZZZZ8888888888888888888 Veilleux 8
8888888888888888888888888ZZZZZZZZZZZZZZ8888888888888888888888888888888
2015-05-12 19:20:58 +02:00
|
|
|
// Each board document contains the de-normalized number of users that have
|
|
|
|
// starred it. If the user star or unstar a board, we need to update this
|
|
|
|
// counter.
|
|
|
|
// We need to run this code on the server only, otherwise the incrementation
|
|
|
|
// will be done twice.
|
2021-05-29 00:19:12 +03:00
|
|
|
Users.after.update(function (userId, user, fieldNames) {
|
Renaissance
_,,ad8888888888bba,_
,ad88888I888888888888888ba,
,88888888I88888888888888888888a,
,d888888888I8888888888888888888888b,
d88888PP"""" ""YY88888888888888888888b,
,d88"'__,,--------,,,,.;ZZZY8888888888888,
,8IIl'" ;;l"ZZZIII8888888888,
,I88l;' ;lZZZZZ888III8888888,
,II88Zl;. ;llZZZZZ888888I888888,
,II888Zl;. .;;;;;lllZZZ888888I8888b
,II8888Z;; `;;;;;''llZZ8888888I8888,
II88888Z;' .;lZZZ8888888I888b
II88888Z; _,aaa, .,aaaaa,__.l;llZZZ88888888I888
II88888IZZZZZZZZZ, .ZZZZZZZZZZZZZZ;llZZ88888888I888,
II88888IZZ<'(@@>Z| |ZZZ<'(@@>ZZZZ;;llZZ888888888I88I
,II88888; `""" ;| |ZZ; `""" ;;llZ8888888888I888
II888888l `;; .;llZZ8888888888I888,
,II888888Z; ;;; .;;llZZZ8888888888I888I
III888888Zl; .., `;; ,;;lllZZZ88888888888I888
II88888888Z;;...;(_ _) ,;;;llZZZZ88888888888I888,
II88888888Zl;;;;;' `--'Z;. .,;;;;llZZZZ88888888888I888b
]I888888888Z;;;;' ";llllll;..;;;lllZZZZ88888888888I8888,
II888888888Zl.;;"Y88bd888P";;,..;lllZZZZZ88888888888I8888I
II8888888888Zl;.; `"PPP";;;,..;lllZZZZZZZ88888888888I88888
II888888888888Zl;;. `;;;l;;;;lllZZZZZZZZW88888888888I88888
`II8888888888888Zl;. ,;;lllZZZZZZZZWMZ88888888888I88888
II8888888888888888ZbaalllZZZZZZZZZWWMZZZ8888888888I888888,
`II88888888888888888b"WWZZZZZWWWMMZZZZZZI888888888I888888b
`II88888888888888888;ZZMMMMMMZZZZZZZZllI888888888I8888888
`II8888888888888888 `;lZZZZZZZZZZZlllll888888888I8888888,
II8888888888888888, `;lllZZZZllllll;;.Y88888888I8888888b,
,II8888888888888888b .;;lllllll;;;.;..88888888I88888888b,
II888888888888888PZI;. .`;;;.;;;..; ...88888888I8888888888,
II888888888888PZ;;';;. ;. .;. .;. .. Y8888888I88888888888b,
,II888888888PZ;;' `8888888I8888888888888b,
II888888888' 888888I8888888888888888
,II888888888 ,888888I8888888888888888
,d88888888888 d888888I8888888888ZZZZZZ
,ad888888888888I 8888888I8888ZZZZZZZZZZZZ
888888888888888' 888888IZZZZZZZZZZZZZZZZZ
8888888888P'8P' Y888ZZZZZZZZZZZZZZZZZZZZ
888888888, " ,ZZZZZZZZZZZZZZZZZZZZZZZ
8888888888, ,ZZZZZZZZZZZZZZZZZZZZZZZZZZ
888888888888a, _ ,ZZZZZZZZZZZZZZZZZZZZ88888888
888888888888888ba,_d' ,ZZZZZZZZZZZZZZZZZ8888888888888
8888888888888888888888bbbaaa,,,______,ZZZZZZZZZZZZZZZ88888888888888888
88888888888888888888888888888888888ZZZZZZZZZZZZZZZ88888888888888888888
8888888888888888888888888888888888ZZZZZZZZZZZZZZ8888888888888888888888
888888888888888888888888888888888ZZZZZZZZZZZZZZ88888888888888888888888
8888888888888888888888888888888ZZZZZZZZZZZZZZ8888888888888888888888888
88888888888888888888888888888ZZZZZZZZZZZZZZ888888888888888888888888888
8888888888888888888888888888ZZZZZZZZZZZZZZ88888888888888888 Normand 8
88888888888888888888888888ZZZZZZZZZZZZZZ8888888888888888888 Veilleux 8
8888888888888888888888888ZZZZZZZZZZZZZZ8888888888888888888888888888888
2015-05-12 19:20:58 +02:00
|
|
|
// The `starredBoards` list is hosted on the `profile` field. If this
|
|
|
|
// field hasn't been modificated we don't need to run this hook.
|
2019-06-26 17:47:27 -05:00
|
|
|
if (!_.contains(fieldNames, 'profile')) return;
|
Renaissance
_,,ad8888888888bba,_
,ad88888I888888888888888ba,
,88888888I88888888888888888888a,
,d888888888I8888888888888888888888b,
d88888PP"""" ""YY88888888888888888888b,
,d88"'__,,--------,,,,.;ZZZY8888888888888,
,8IIl'" ;;l"ZZZIII8888888888,
,I88l;' ;lZZZZZ888III8888888,
,II88Zl;. ;llZZZZZ888888I888888,
,II888Zl;. .;;;;;lllZZZ888888I8888b
,II8888Z;; `;;;;;''llZZ8888888I8888,
II88888Z;' .;lZZZ8888888I888b
II88888Z; _,aaa, .,aaaaa,__.l;llZZZ88888888I888
II88888IZZZZZZZZZ, .ZZZZZZZZZZZZZZ;llZZ88888888I888,
II88888IZZ<'(@@>Z| |ZZZ<'(@@>ZZZZ;;llZZ888888888I88I
,II88888; `""" ;| |ZZ; `""" ;;llZ8888888888I888
II888888l `;; .;llZZ8888888888I888,
,II888888Z; ;;; .;;llZZZ8888888888I888I
III888888Zl; .., `;; ,;;lllZZZ88888888888I888
II88888888Z;;...;(_ _) ,;;;llZZZZ88888888888I888,
II88888888Zl;;;;;' `--'Z;. .,;;;;llZZZZ88888888888I888b
]I888888888Z;;;;' ";llllll;..;;;lllZZZZ88888888888I8888,
II888888888Zl.;;"Y88bd888P";;,..;lllZZZZZ88888888888I8888I
II8888888888Zl;.; `"PPP";;;,..;lllZZZZZZZ88888888888I88888
II888888888888Zl;;. `;;;l;;;;lllZZZZZZZZW88888888888I88888
`II8888888888888Zl;. ,;;lllZZZZZZZZWMZ88888888888I88888
II8888888888888888ZbaalllZZZZZZZZZWWMZZZ8888888888I888888,
`II88888888888888888b"WWZZZZZWWWMMZZZZZZI888888888I888888b
`II88888888888888888;ZZMMMMMMZZZZZZZZllI888888888I8888888
`II8888888888888888 `;lZZZZZZZZZZZlllll888888888I8888888,
II8888888888888888, `;lllZZZZllllll;;.Y88888888I8888888b,
,II8888888888888888b .;;lllllll;;;.;..88888888I88888888b,
II888888888888888PZI;. .`;;;.;;;..; ...88888888I8888888888,
II888888888888PZ;;';;. ;. .;. .;. .. Y8888888I88888888888b,
,II888888888PZ;;' `8888888I8888888888888b,
II888888888' 888888I8888888888888888
,II888888888 ,888888I8888888888888888
,d88888888888 d888888I8888888888ZZZZZZ
,ad888888888888I 8888888I8888ZZZZZZZZZZZZ
888888888888888' 888888IZZZZZZZZZZZZZZZZZ
8888888888P'8P' Y888ZZZZZZZZZZZZZZZZZZZZ
888888888, " ,ZZZZZZZZZZZZZZZZZZZZZZZ
8888888888, ,ZZZZZZZZZZZZZZZZZZZZZZZZZZ
888888888888a, _ ,ZZZZZZZZZZZZZZZZZZZZ88888888
888888888888888ba,_d' ,ZZZZZZZZZZZZZZZZZ8888888888888
8888888888888888888888bbbaaa,,,______,ZZZZZZZZZZZZZZZ88888888888888888
88888888888888888888888888888888888ZZZZZZZZZZZZZZZ88888888888888888888
8888888888888888888888888888888888ZZZZZZZZZZZZZZ8888888888888888888888
888888888888888888888888888888888ZZZZZZZZZZZZZZ88888888888888888888888
8888888888888888888888888888888ZZZZZZZZZZZZZZ8888888888888888888888888
88888888888888888888888888888ZZZZZZZZZZZZZZ888888888888888888888888888
8888888888888888888888888888ZZZZZZZZZZZZZZ88888888888888888 Normand 8
88888888888888888888888888ZZZZZZZZZZZZZZ8888888888888888888 Veilleux 8
8888888888888888888888888ZZZZZZZZZZZZZZ8888888888888888888888888888888
2015-05-12 19:20:58 +02:00
|
|
|
|
|
|
|
// To calculate a diff of board starred ids, we get both the previous
|
|
|
|
// and the newly board ids list
|
2015-09-03 23:12:46 +02:00
|
|
|
function getStarredBoardsIds(doc) {
|
Renaissance
_,,ad8888888888bba,_
,ad88888I888888888888888ba,
,88888888I88888888888888888888a,
,d888888888I8888888888888888888888b,
d88888PP"""" ""YY88888888888888888888b,
,d88"'__,,--------,,,,.;ZZZY8888888888888,
,8IIl'" ;;l"ZZZIII8888888888,
,I88l;' ;lZZZZZ888III8888888,
,II88Zl;. ;llZZZZZ888888I888888,
,II888Zl;. .;;;;;lllZZZ888888I8888b
,II8888Z;; `;;;;;''llZZ8888888I8888,
II88888Z;' .;lZZZ8888888I888b
II88888Z; _,aaa, .,aaaaa,__.l;llZZZ88888888I888
II88888IZZZZZZZZZ, .ZZZZZZZZZZZZZZ;llZZ88888888I888,
II88888IZZ<'(@@>Z| |ZZZ<'(@@>ZZZZ;;llZZ888888888I88I
,II88888; `""" ;| |ZZ; `""" ;;llZ8888888888I888
II888888l `;; .;llZZ8888888888I888,
,II888888Z; ;;; .;;llZZZ8888888888I888I
III888888Zl; .., `;; ,;;lllZZZ88888888888I888
II88888888Z;;...;(_ _) ,;;;llZZZZ88888888888I888,
II88888888Zl;;;;;' `--'Z;. .,;;;;llZZZZ88888888888I888b
]I888888888Z;;;;' ";llllll;..;;;lllZZZZ88888888888I8888,
II888888888Zl.;;"Y88bd888P";;,..;lllZZZZZ88888888888I8888I
II8888888888Zl;.; `"PPP";;;,..;lllZZZZZZZ88888888888I88888
II888888888888Zl;;. `;;;l;;;;lllZZZZZZZZW88888888888I88888
`II8888888888888Zl;. ,;;lllZZZZZZZZWMZ88888888888I88888
II8888888888888888ZbaalllZZZZZZZZZWWMZZZ8888888888I888888,
`II88888888888888888b"WWZZZZZWWWMMZZZZZZI888888888I888888b
`II88888888888888888;ZZMMMMMMZZZZZZZZllI888888888I8888888
`II8888888888888888 `;lZZZZZZZZZZZlllll888888888I8888888,
II8888888888888888, `;lllZZZZllllll;;.Y88888888I8888888b,
,II8888888888888888b .;;lllllll;;;.;..88888888I88888888b,
II888888888888888PZI;. .`;;;.;;;..; ...88888888I8888888888,
II888888888888PZ;;';;. ;. .;. .;. .. Y8888888I88888888888b,
,II888888888PZ;;' `8888888I8888888888888b,
II888888888' 888888I8888888888888888
,II888888888 ,888888I8888888888888888
,d88888888888 d888888I8888888888ZZZZZZ
,ad888888888888I 8888888I8888ZZZZZZZZZZZZ
888888888888888' 888888IZZZZZZZZZZZZZZZZZ
8888888888P'8P' Y888ZZZZZZZZZZZZZZZZZZZZ
888888888, " ,ZZZZZZZZZZZZZZZZZZZZZZZ
8888888888, ,ZZZZZZZZZZZZZZZZZZZZZZZZZZ
888888888888a, _ ,ZZZZZZZZZZZZZZZZZZZZ88888888
888888888888888ba,_d' ,ZZZZZZZZZZZZZZZZZ8888888888888
8888888888888888888888bbbaaa,,,______,ZZZZZZZZZZZZZZZ88888888888888888
88888888888888888888888888888888888ZZZZZZZZZZZZZZZ88888888888888888888
8888888888888888888888888888888888ZZZZZZZZZZZZZZ8888888888888888888888
888888888888888888888888888888888ZZZZZZZZZZZZZZ88888888888888888888888
8888888888888888888888888888888ZZZZZZZZZZZZZZ8888888888888888888888888
88888888888888888888888888888ZZZZZZZZZZZZZZ888888888888888888888888888
8888888888888888888888888888ZZZZZZZZZZZZZZ88888888888888888 Normand 8
88888888888888888888888888ZZZZZZZZZZZZZZ8888888888888888888 Veilleux 8
8888888888888888888888888ZZZZZZZZZZZZZZ8888888888888888888888888888888
2015-05-12 19:20:58 +02:00
|
|
|
return doc.profile && doc.profile.starredBoards;
|
2015-09-03 23:12:46 +02:00
|
|
|
}
|
2017-11-08 11:34:37 +07:00
|
|
|
|
2015-09-03 23:12:46 +02:00
|
|
|
const oldIds = getStarredBoardsIds(this.previous);
|
|
|
|
const newIds = getStarredBoardsIds(user);
|
Renaissance
_,,ad8888888888bba,_
,ad88888I888888888888888ba,
,88888888I88888888888888888888a,
,d888888888I8888888888888888888888b,
d88888PP"""" ""YY88888888888888888888b,
,d88"'__,,--------,,,,.;ZZZY8888888888888,
,8IIl'" ;;l"ZZZIII8888888888,
,I88l;' ;lZZZZZ888III8888888,
,II88Zl;. ;llZZZZZ888888I888888,
,II888Zl;. .;;;;;lllZZZ888888I8888b
,II8888Z;; `;;;;;''llZZ8888888I8888,
II88888Z;' .;lZZZ8888888I888b
II88888Z; _,aaa, .,aaaaa,__.l;llZZZ88888888I888
II88888IZZZZZZZZZ, .ZZZZZZZZZZZZZZ;llZZ88888888I888,
II88888IZZ<'(@@>Z| |ZZZ<'(@@>ZZZZ;;llZZ888888888I88I
,II88888; `""" ;| |ZZ; `""" ;;llZ8888888888I888
II888888l `;; .;llZZ8888888888I888,
,II888888Z; ;;; .;;llZZZ8888888888I888I
III888888Zl; .., `;; ,;;lllZZZ88888888888I888
II88888888Z;;...;(_ _) ,;;;llZZZZ88888888888I888,
II88888888Zl;;;;;' `--'Z;. .,;;;;llZZZZ88888888888I888b
]I888888888Z;;;;' ";llllll;..;;;lllZZZZ88888888888I8888,
II888888888Zl.;;"Y88bd888P";;,..;lllZZZZZ88888888888I8888I
II8888888888Zl;.; `"PPP";;;,..;lllZZZZZZZ88888888888I88888
II888888888888Zl;;. `;;;l;;;;lllZZZZZZZZW88888888888I88888
`II8888888888888Zl;. ,;;lllZZZZZZZZWMZ88888888888I88888
II8888888888888888ZbaalllZZZZZZZZZWWMZZZ8888888888I888888,
`II88888888888888888b"WWZZZZZWWWMMZZZZZZI888888888I888888b
`II88888888888888888;ZZMMMMMMZZZZZZZZllI888888888I8888888
`II8888888888888888 `;lZZZZZZZZZZZlllll888888888I8888888,
II8888888888888888, `;lllZZZZllllll;;.Y88888888I8888888b,
,II8888888888888888b .;;lllllll;;;.;..88888888I88888888b,
II888888888888888PZI;. .`;;;.;;;..; ...88888888I8888888888,
II888888888888PZ;;';;. ;. .;. .;. .. Y8888888I88888888888b,
,II888888888PZ;;' `8888888I8888888888888b,
II888888888' 888888I8888888888888888
,II888888888 ,888888I8888888888888888
,d88888888888 d888888I8888888888ZZZZZZ
,ad888888888888I 8888888I8888ZZZZZZZZZZZZ
888888888888888' 888888IZZZZZZZZZZZZZZZZZ
8888888888P'8P' Y888ZZZZZZZZZZZZZZZZZZZZ
888888888, " ,ZZZZZZZZZZZZZZZZZZZZZZZ
8888888888, ,ZZZZZZZZZZZZZZZZZZZZZZZZZZ
888888888888a, _ ,ZZZZZZZZZZZZZZZZZZZZ88888888
888888888888888ba,_d' ,ZZZZZZZZZZZZZZZZZ8888888888888
8888888888888888888888bbbaaa,,,______,ZZZZZZZZZZZZZZZ88888888888888888
88888888888888888888888888888888888ZZZZZZZZZZZZZZZ88888888888888888888
8888888888888888888888888888888888ZZZZZZZZZZZZZZ8888888888888888888888
888888888888888888888888888888888ZZZZZZZZZZZZZZ88888888888888888888888
8888888888888888888888888888888ZZZZZZZZZZZZZZ8888888888888888888888888
88888888888888888888888888888ZZZZZZZZZZZZZZ888888888888888888888888888
8888888888888888888888888888ZZZZZZZZZZZZZZ88888888888888888 Normand 8
88888888888888888888888888ZZZZZZZZZZZZZZ8888888888888888888 Veilleux 8
8888888888888888888888888ZZZZZZZZZZZZZZ8888888888888888888888888888888
2015-05-12 19:20:58 +02:00
|
|
|
|
|
|
|
// The _.difference(a, b) method returns the values from a that are not in
|
|
|
|
// b. We use it to find deleted and newly inserted ids by using it in one
|
|
|
|
// direction and then in the other.
|
2015-09-03 23:12:46 +02:00
|
|
|
function incrementBoards(boardsIds, inc) {
|
2021-05-29 00:19:12 +03:00
|
|
|
boardsIds.forEach((boardId) => {
|
|
|
|
Boards.update(boardId, {
|
|
|
|
$inc: {
|
|
|
|
stars: inc,
|
|
|
|
},
|
|
|
|
});
|
Renaissance
_,,ad8888888888bba,_
,ad88888I888888888888888ba,
,88888888I88888888888888888888a,
,d888888888I8888888888888888888888b,
d88888PP"""" ""YY88888888888888888888b,
,d88"'__,,--------,,,,.;ZZZY8888888888888,
,8IIl'" ;;l"ZZZIII8888888888,
,I88l;' ;lZZZZZ888III8888888,
,II88Zl;. ;llZZZZZ888888I888888,
,II888Zl;. .;;;;;lllZZZ888888I8888b
,II8888Z;; `;;;;;''llZZ8888888I8888,
II88888Z;' .;lZZZ8888888I888b
II88888Z; _,aaa, .,aaaaa,__.l;llZZZ88888888I888
II88888IZZZZZZZZZ, .ZZZZZZZZZZZZZZ;llZZ88888888I888,
II88888IZZ<'(@@>Z| |ZZZ<'(@@>ZZZZ;;llZZ888888888I88I
,II88888; `""" ;| |ZZ; `""" ;;llZ8888888888I888
II888888l `;; .;llZZ8888888888I888,
,II888888Z; ;;; .;;llZZZ8888888888I888I
III888888Zl; .., `;; ,;;lllZZZ88888888888I888
II88888888Z;;...;(_ _) ,;;;llZZZZ88888888888I888,
II88888888Zl;;;;;' `--'Z;. .,;;;;llZZZZ88888888888I888b
]I888888888Z;;;;' ";llllll;..;;;lllZZZZ88888888888I8888,
II888888888Zl.;;"Y88bd888P";;,..;lllZZZZZ88888888888I8888I
II8888888888Zl;.; `"PPP";;;,..;lllZZZZZZZ88888888888I88888
II888888888888Zl;;. `;;;l;;;;lllZZZZZZZZW88888888888I88888
`II8888888888888Zl;. ,;;lllZZZZZZZZWMZ88888888888I88888
II8888888888888888ZbaalllZZZZZZZZZWWMZZZ8888888888I888888,
`II88888888888888888b"WWZZZZZWWWMMZZZZZZI888888888I888888b
`II88888888888888888;ZZMMMMMMZZZZZZZZllI888888888I8888888
`II8888888888888888 `;lZZZZZZZZZZZlllll888888888I8888888,
II8888888888888888, `;lllZZZZllllll;;.Y88888888I8888888b,
,II8888888888888888b .;;lllllll;;;.;..88888888I88888888b,
II888888888888888PZI;. .`;;;.;;;..; ...88888888I8888888888,
II888888888888PZ;;';;. ;. .;. .;. .. Y8888888I88888888888b,
,II888888888PZ;;' `8888888I8888888888888b,
II888888888' 888888I8888888888888888
,II888888888 ,888888I8888888888888888
,d88888888888 d888888I8888888888ZZZZZZ
,ad888888888888I 8888888I8888ZZZZZZZZZZZZ
888888888888888' 888888IZZZZZZZZZZZZZZZZZ
8888888888P'8P' Y888ZZZZZZZZZZZZZZZZZZZZ
888888888, " ,ZZZZZZZZZZZZZZZZZZZZZZZ
8888888888, ,ZZZZZZZZZZZZZZZZZZZZZZZZZZ
888888888888a, _ ,ZZZZZZZZZZZZZZZZZZZZ88888888
888888888888888ba,_d' ,ZZZZZZZZZZZZZZZZZ8888888888888
8888888888888888888888bbbaaa,,,______,ZZZZZZZZZZZZZZZ88888888888888888
88888888888888888888888888888888888ZZZZZZZZZZZZZZZ88888888888888888888
8888888888888888888888888888888888ZZZZZZZZZZZZZZ8888888888888888888888
888888888888888888888888888888888ZZZZZZZZZZZZZZ88888888888888888888888
8888888888888888888888888888888ZZZZZZZZZZZZZZ8888888888888888888888888
88888888888888888888888888888ZZZZZZZZZZZZZZ888888888888888888888888888
8888888888888888888888888888ZZZZZZZZZZZZZZ88888888888888888 Normand 8
88888888888888888888888888ZZZZZZZZZZZZZZ8888888888888888888 Veilleux 8
8888888888888888888888888ZZZZZZZZZZZZZZ8888888888888888888888888888888
2015-05-12 19:20:58 +02:00
|
|
|
});
|
2015-09-03 23:12:46 +02:00
|
|
|
}
|
2017-11-08 11:34:37 +07:00
|
|
|
|
Renaissance
_,,ad8888888888bba,_
,ad88888I888888888888888ba,
,88888888I88888888888888888888a,
,d888888888I8888888888888888888888b,
d88888PP"""" ""YY88888888888888888888b,
,d88"'__,,--------,,,,.;ZZZY8888888888888,
,8IIl'" ;;l"ZZZIII8888888888,
,I88l;' ;lZZZZZ888III8888888,
,II88Zl;. ;llZZZZZ888888I888888,
,II888Zl;. .;;;;;lllZZZ888888I8888b
,II8888Z;; `;;;;;''llZZ8888888I8888,
II88888Z;' .;lZZZ8888888I888b
II88888Z; _,aaa, .,aaaaa,__.l;llZZZ88888888I888
II88888IZZZZZZZZZ, .ZZZZZZZZZZZZZZ;llZZ88888888I888,
II88888IZZ<'(@@>Z| |ZZZ<'(@@>ZZZZ;;llZZ888888888I88I
,II88888; `""" ;| |ZZ; `""" ;;llZ8888888888I888
II888888l `;; .;llZZ8888888888I888,
,II888888Z; ;;; .;;llZZZ8888888888I888I
III888888Zl; .., `;; ,;;lllZZZ88888888888I888
II88888888Z;;...;(_ _) ,;;;llZZZZ88888888888I888,
II88888888Zl;;;;;' `--'Z;. .,;;;;llZZZZ88888888888I888b
]I888888888Z;;;;' ";llllll;..;;;lllZZZZ88888888888I8888,
II888888888Zl.;;"Y88bd888P";;,..;lllZZZZZ88888888888I8888I
II8888888888Zl;.; `"PPP";;;,..;lllZZZZZZZ88888888888I88888
II888888888888Zl;;. `;;;l;;;;lllZZZZZZZZW88888888888I88888
`II8888888888888Zl;. ,;;lllZZZZZZZZWMZ88888888888I88888
II8888888888888888ZbaalllZZZZZZZZZWWMZZZ8888888888I888888,
`II88888888888888888b"WWZZZZZWWWMMZZZZZZI888888888I888888b
`II88888888888888888;ZZMMMMMMZZZZZZZZllI888888888I8888888
`II8888888888888888 `;lZZZZZZZZZZZlllll888888888I8888888,
II8888888888888888, `;lllZZZZllllll;;.Y88888888I8888888b,
,II8888888888888888b .;;lllllll;;;.;..88888888I88888888b,
II888888888888888PZI;. .`;;;.;;;..; ...88888888I8888888888,
II888888888888PZ;;';;. ;. .;. .;. .. Y8888888I88888888888b,
,II888888888PZ;;' `8888888I8888888888888b,
II888888888' 888888I8888888888888888
,II888888888 ,888888I8888888888888888
,d88888888888 d888888I8888888888ZZZZZZ
,ad888888888888I 8888888I8888ZZZZZZZZZZZZ
888888888888888' 888888IZZZZZZZZZZZZZZZZZ
8888888888P'8P' Y888ZZZZZZZZZZZZZZZZZZZZ
888888888, " ,ZZZZZZZZZZZZZZZZZZZZZZZ
8888888888, ,ZZZZZZZZZZZZZZZZZZZZZZZZZZ
888888888888a, _ ,ZZZZZZZZZZZZZZZZZZZZ88888888
888888888888888ba,_d' ,ZZZZZZZZZZZZZZZZZ8888888888888
8888888888888888888888bbbaaa,,,______,ZZZZZZZZZZZZZZZ88888888888888888
88888888888888888888888888888888888ZZZZZZZZZZZZZZZ88888888888888888888
8888888888888888888888888888888888ZZZZZZZZZZZZZZ8888888888888888888888
888888888888888888888888888888888ZZZZZZZZZZZZZZ88888888888888888888888
8888888888888888888888888888888ZZZZZZZZZZZZZZ8888888888888888888888888
88888888888888888888888888888ZZZZZZZZZZZZZZ888888888888888888888888888
8888888888888888888888888888ZZZZZZZZZZZZZZ88888888888888888 Normand 8
88888888888888888888888888ZZZZZZZZZZZZZZ8888888888888888888 Veilleux 8
8888888888888888888888888ZZZZZZZZZZZZZZ8888888888888888888888888888888
2015-05-12 19:20:58 +02:00
|
|
|
incrementBoards(_.difference(oldIds, newIds), -1);
|
|
|
|
incrementBoards(_.difference(newIds, oldIds), +1);
|
|
|
|
});
|
|
|
|
|
2020-05-29 22:29:42 +02:00
|
|
|
// Override getUserId so that we can TODO get the current userId
|
2016-03-29 18:36:16 +02:00
|
|
|
const fakeUserId = new Meteor.EnvironmentVariable();
|
|
|
|
const getUserId = CollectionHooks.getUserId;
|
|
|
|
CollectionHooks.getUserId = () => {
|
|
|
|
return fakeUserId.get() || getUserId();
|
|
|
|
};
|
2016-07-11 15:21:19 -07:00
|
|
|
if (!isSandstorm) {
|
|
|
|
Users.after.insert((userId, doc) => {
|
|
|
|
const fakeUser = {
|
|
|
|
extendAutoValueContext: {
|
|
|
|
userId: doc._id,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
fakeUserId.withValue(doc._id, () => {
|
2019-06-26 17:47:27 -05:00
|
|
|
/*
|
2019-02-22 22:59:19 +01:00
|
|
|
|
2021-06-16 19:06:10 +03:00
|
|
|
// Insert the Welcome Board
|
|
|
|
Boards.insert({
|
|
|
|
title: TAPi18n.__('welcome-board'),
|
|
|
|
permission: 'private',
|
|
|
|
}, fakeUser, (err, boardId) => {
|
|
|
|
|
|
|
|
Swimlanes.insert({
|
|
|
|
title: TAPi18n.__('welcome-swimlane'),
|
|
|
|
boardId,
|
|
|
|
sort: 1,
|
|
|
|
}, fakeUser);
|
|
|
|
|
|
|
|
['welcome-list1', 'welcome-list2'].forEach((title, titleIndex) => {
|
|
|
|
Lists.insert({title: TAPi18n.__(title), boardId, sort: titleIndex}, fakeUser);
|
|
|
|
});
|
|
|
|
});
|
2021-06-29 14:03:47 +03:00
|
|
|
*/
|
2021-06-16 19:06:10 +03:00
|
|
|
|
|
|
|
// Insert Template Container
|
2020-06-08 17:35:25 +03:00
|
|
|
const Future = require('fibers/future');
|
2020-07-21 17:36:46 +02:00
|
|
|
const future1 = new Future();
|
|
|
|
const future2 = new Future();
|
|
|
|
const future3 = new Future();
|
2019-06-26 17:47:27 -05:00
|
|
|
Boards.insert(
|
|
|
|
{
|
|
|
|
title: TAPi18n.__('templates'),
|
|
|
|
permission: 'private',
|
2019-02-24 00:13:35 +01:00
|
|
|
type: 'template-container',
|
2019-06-26 17:47:27 -05:00
|
|
|
},
|
|
|
|
fakeUser,
|
|
|
|
(err, boardId) => {
|
|
|
|
// Insert the reference to our templates board
|
|
|
|
Users.update(fakeUserId.get(), {
|
2021-05-29 00:19:12 +03:00
|
|
|
$set: {
|
|
|
|
'profile.templatesBoardId': boardId,
|
|
|
|
},
|
2019-06-26 17:47:27 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
// Insert the card templates swimlane
|
|
|
|
Swimlanes.insert(
|
|
|
|
{
|
|
|
|
title: TAPi18n.__('card-templates-swimlane'),
|
|
|
|
boardId,
|
|
|
|
sort: 1,
|
|
|
|
type: 'template-container',
|
|
|
|
},
|
|
|
|
fakeUser,
|
|
|
|
(err, swimlaneId) => {
|
|
|
|
// Insert the reference to out card templates swimlane
|
|
|
|
Users.update(fakeUserId.get(), {
|
2021-05-29 00:19:12 +03:00
|
|
|
$set: {
|
|
|
|
'profile.cardTemplatesSwimlaneId': swimlaneId,
|
|
|
|
},
|
2019-06-26 17:47:27 -05:00
|
|
|
});
|
2020-06-08 17:35:25 +03:00
|
|
|
future1.return();
|
2019-06-28 12:52:09 -05:00
|
|
|
},
|
2019-06-26 17:47:27 -05:00
|
|
|
);
|
|
|
|
|
|
|
|
// Insert the list templates swimlane
|
|
|
|
Swimlanes.insert(
|
|
|
|
{
|
|
|
|
title: TAPi18n.__('list-templates-swimlane'),
|
|
|
|
boardId,
|
|
|
|
sort: 2,
|
|
|
|
type: 'template-container',
|
|
|
|
},
|
|
|
|
fakeUser,
|
|
|
|
(err, swimlaneId) => {
|
|
|
|
// Insert the reference to out list templates swimlane
|
|
|
|
Users.update(fakeUserId.get(), {
|
2021-05-29 00:19:12 +03:00
|
|
|
$set: {
|
|
|
|
'profile.listTemplatesSwimlaneId': swimlaneId,
|
|
|
|
},
|
2019-06-26 17:47:27 -05:00
|
|
|
});
|
2020-06-08 17:35:25 +03:00
|
|
|
future2.return();
|
2019-06-28 12:52:09 -05:00
|
|
|
},
|
2019-06-26 17:47:27 -05:00
|
|
|
);
|
|
|
|
|
|
|
|
// Insert the board templates swimlane
|
|
|
|
Swimlanes.insert(
|
|
|
|
{
|
|
|
|
title: TAPi18n.__('board-templates-swimlane'),
|
|
|
|
boardId,
|
|
|
|
sort: 3,
|
|
|
|
type: 'template-container',
|
|
|
|
},
|
|
|
|
fakeUser,
|
|
|
|
(err, swimlaneId) => {
|
|
|
|
// Insert the reference to out board templates swimlane
|
|
|
|
Users.update(fakeUserId.get(), {
|
2021-05-29 00:19:12 +03:00
|
|
|
$set: {
|
|
|
|
'profile.boardTemplatesSwimlaneId': swimlaneId,
|
|
|
|
},
|
2019-06-26 17:47:27 -05:00
|
|
|
});
|
2020-06-08 17:35:25 +03:00
|
|
|
future3.return();
|
2019-06-28 12:52:09 -05:00
|
|
|
},
|
2019-06-26 17:47:27 -05:00
|
|
|
);
|
2019-06-28 12:52:09 -05:00
|
|
|
},
|
2019-06-26 17:47:27 -05:00
|
|
|
);
|
2020-06-08 17:35:25 +03:00
|
|
|
// HACK
|
|
|
|
future1.wait();
|
|
|
|
future2.wait();
|
|
|
|
future3.wait();
|
2021-06-29 14:03:47 +03:00
|
|
|
// End of Insert Template Container
|
Renaissance
_,,ad8888888888bba,_
,ad88888I888888888888888ba,
,88888888I88888888888888888888a,
,d888888888I8888888888888888888888b,
d88888PP"""" ""YY88888888888888888888b,
,d88"'__,,--------,,,,.;ZZZY8888888888888,
,8IIl'" ;;l"ZZZIII8888888888,
,I88l;' ;lZZZZZ888III8888888,
,II88Zl;. ;llZZZZZ888888I888888,
,II888Zl;. .;;;;;lllZZZ888888I8888b
,II8888Z;; `;;;;;''llZZ8888888I8888,
II88888Z;' .;lZZZ8888888I888b
II88888Z; _,aaa, .,aaaaa,__.l;llZZZ88888888I888
II88888IZZZZZZZZZ, .ZZZZZZZZZZZZZZ;llZZ88888888I888,
II88888IZZ<'(@@>Z| |ZZZ<'(@@>ZZZZ;;llZZ888888888I88I
,II88888; `""" ;| |ZZ; `""" ;;llZ8888888888I888
II888888l `;; .;llZZ8888888888I888,
,II888888Z; ;;; .;;llZZZ8888888888I888I
III888888Zl; .., `;; ,;;lllZZZ88888888888I888
II88888888Z;;...;(_ _) ,;;;llZZZZ88888888888I888,
II88888888Zl;;;;;' `--'Z;. .,;;;;llZZZZ88888888888I888b
]I888888888Z;;;;' ";llllll;..;;;lllZZZZ88888888888I8888,
II888888888Zl.;;"Y88bd888P";;,..;lllZZZZZ88888888888I8888I
II8888888888Zl;.; `"PPP";;;,..;lllZZZZZZZ88888888888I88888
II888888888888Zl;;. `;;;l;;;;lllZZZZZZZZW88888888888I88888
`II8888888888888Zl;. ,;;lllZZZZZZZZWMZ88888888888I88888
II8888888888888888ZbaalllZZZZZZZZZWWMZZZ8888888888I888888,
`II88888888888888888b"WWZZZZZWWWMMZZZZZZI888888888I888888b
`II88888888888888888;ZZMMMMMMZZZZZZZZllI888888888I8888888
`II8888888888888888 `;lZZZZZZZZZZZlllll888888888I8888888,
II8888888888888888, `;lllZZZZllllll;;.Y88888888I8888888b,
,II8888888888888888b .;;lllllll;;;.;..88888888I88888888b,
II888888888888888PZI;. .`;;;.;;;..; ...88888888I8888888888,
II888888888888PZ;;';;. ;. .;. .;. .. Y8888888I88888888888b,
,II888888888PZ;;' `8888888I8888888888888b,
II888888888' 888888I8888888888888888
,II888888888 ,888888I8888888888888888
,d88888888888 d888888I8888888888ZZZZZZ
,ad888888888888I 8888888I8888ZZZZZZZZZZZZ
888888888888888' 888888IZZZZZZZZZZZZZZZZZ
8888888888P'8P' Y888ZZZZZZZZZZZZZZZZZZZZ
888888888, " ,ZZZZZZZZZZZZZZZZZZZZZZZ
8888888888, ,ZZZZZZZZZZZZZZZZZZZZZZZZZZ
888888888888a, _ ,ZZZZZZZZZZZZZZZZZZZZ88888888
888888888888888ba,_d' ,ZZZZZZZZZZZZZZZZZ8888888888888
8888888888888888888888bbbaaa,,,______,ZZZZZZZZZZZZZZZ88888888888888888
88888888888888888888888888888888888ZZZZZZZZZZZZZZZ88888888888888888888
8888888888888888888888888888888888ZZZZZZZZZZZZZZ8888888888888888888888
888888888888888888888888888888888ZZZZZZZZZZZZZZ88888888888888888888888
8888888888888888888888888888888ZZZZZZZZZZZZZZ8888888888888888888888888
88888888888888888888888888888ZZZZZZZZZZZZZZ888888888888888888888888888
8888888888888888888888888888ZZZZZZZZZZZZZZ88888888888888888 Normand 8
88888888888888888888888888ZZZZZZZZZZZZZZ8888888888888888888 Veilleux 8
8888888888888888888888888ZZZZZZZZZZZZZZ8888888888888888888888888888888
2015-05-12 19:20:58 +02:00
|
|
|
});
|
|
|
|
});
|
2016-07-11 15:21:19 -07:00
|
|
|
}
|
2017-02-24 22:10:38 +08:00
|
|
|
|
2020-06-08 17:35:25 +03:00
|
|
|
Users.after.insert((userId, doc) => {
|
|
|
|
// HACK
|
2023-01-15 01:11:16 +01:00
|
|
|
doc = ReactiveCache.getUser(doc._id);
|
2017-10-06 23:08:22 +09:00
|
|
|
if (doc.createdThroughApi) {
|
2017-10-07 08:33:28 +09:00
|
|
|
// The admin user should be able to create a user despite disabling registration because
|
|
|
|
// it is two different things (registration and creation).
|
2017-10-08 18:15:11 +09:00
|
|
|
// So, when a new user is created via the api (only admin user can do that) one must avoid
|
2017-10-07 08:33:28 +09:00
|
|
|
// the disableRegistration check.
|
|
|
|
// Issue : https://github.com/wekan/wekan/issues/1232
|
|
|
|
// PR : https://github.com/wekan/wekan/pull/1251
|
2021-05-29 00:19:12 +03:00
|
|
|
Users.update(doc._id, {
|
|
|
|
$set: {
|
|
|
|
createdThroughApi: '',
|
|
|
|
},
|
|
|
|
});
|
2017-09-25 22:14:13 +09:00
|
|
|
return;
|
2017-10-06 01:21:45 +09:00
|
|
|
}
|
2017-09-25 21:03:18 +09:00
|
|
|
|
2017-02-24 22:10:38 +08:00
|
|
|
//invite user to corresponding boards
|
2023-07-20 21:08:39 +02:00
|
|
|
const disableRegistration = ReactiveCache.getCurrentSetting().disableRegistration;
|
2018-10-03 11:50:52 +03:00
|
|
|
// If ldap, bypass the inviation code if the self registration isn't allowed.
|
|
|
|
// TODO : pay attention if ldap field in the user model change to another content ex : ldap field to connection_type
|
2018-10-09 21:16:47 +03:00
|
|
|
if (doc.authenticationMethod !== 'ldap' && disableRegistration) {
|
2021-12-17 18:56:40 +01:00
|
|
|
let invitationCode = null;
|
2022-09-21 14:33:17 +02:00
|
|
|
if (doc.authenticationMethod.toLowerCase() == 'oauth2') {
|
|
|
|
// OIDC authentication mode
|
2023-02-05 11:17:56 +01:00
|
|
|
invitationCode = ReactiveCache.getInvitationCode({
|
2021-12-17 18:56:40 +01:00
|
|
|
email: doc.emails[0].address.toLowerCase(),
|
|
|
|
valid: true,
|
|
|
|
});
|
2022-09-21 14:33:17 +02:00
|
|
|
} else {
|
2023-02-05 11:17:56 +01:00
|
|
|
invitationCode = ReactiveCache.getInvitationCode({
|
2021-12-17 18:56:40 +01:00
|
|
|
code: doc.profile.icode,
|
|
|
|
valid: true,
|
|
|
|
});
|
|
|
|
}
|
2017-02-24 22:10:38 +08:00
|
|
|
if (!invitationCode) {
|
2017-03-28 00:48:18 +08:00
|
|
|
throw new Meteor.Error('error-invitation-code-not-exist');
|
2017-04-27 20:49:24 +03:00
|
|
|
} else {
|
2021-05-29 00:19:12 +03:00
|
|
|
invitationCode.boardsToBeInvited.forEach((boardId) => {
|
2023-01-14 13:29:57 +01:00
|
|
|
const board = ReactiveCache.getBoard(boardId);
|
2017-02-24 22:10:38 +08:00
|
|
|
board.addMember(doc._id);
|
|
|
|
});
|
2017-03-28 00:48:18 +08:00
|
|
|
if (!doc.profile) {
|
|
|
|
doc.profile = {};
|
|
|
|
}
|
|
|
|
doc.profile.invitedBoards = invitationCode.boardsToBeInvited;
|
2021-05-29 00:19:12 +03:00
|
|
|
Users.update(doc._id, {
|
|
|
|
$set: {
|
|
|
|
profile: doc.profile,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
InvitationCodes.update(invitationCode._id, {
|
|
|
|
$set: {
|
|
|
|
valid: false,
|
|
|
|
},
|
|
|
|
});
|
2017-02-24 22:10:38 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
Renaissance
_,,ad8888888888bba,_
,ad88888I888888888888888ba,
,88888888I88888888888888888888a,
,d888888888I8888888888888888888888b,
d88888PP"""" ""YY88888888888888888888b,
,d88"'__,,--------,,,,.;ZZZY8888888888888,
,8IIl'" ;;l"ZZZIII8888888888,
,I88l;' ;lZZZZZ888III8888888,
,II88Zl;. ;llZZZZZ888888I888888,
,II888Zl;. .;;;;;lllZZZ888888I8888b
,II8888Z;; `;;;;;''llZZ8888888I8888,
II88888Z;' .;lZZZ8888888I888b
II88888Z; _,aaa, .,aaaaa,__.l;llZZZ88888888I888
II88888IZZZZZZZZZ, .ZZZZZZZZZZZZZZ;llZZ88888888I888,
II88888IZZ<'(@@>Z| |ZZZ<'(@@>ZZZZ;;llZZ888888888I88I
,II88888; `""" ;| |ZZ; `""" ;;llZ8888888888I888
II888888l `;; .;llZZ8888888888I888,
,II888888Z; ;;; .;;llZZZ8888888888I888I
III888888Zl; .., `;; ,;;lllZZZ88888888888I888
II88888888Z;;...;(_ _) ,;;;llZZZZ88888888888I888,
II88888888Zl;;;;;' `--'Z;. .,;;;;llZZZZ88888888888I888b
]I888888888Z;;;;' ";llllll;..;;;lllZZZZ88888888888I8888,
II888888888Zl.;;"Y88bd888P";;,..;lllZZZZZ88888888888I8888I
II8888888888Zl;.; `"PPP";;;,..;lllZZZZZZZ88888888888I88888
II888888888888Zl;;. `;;;l;;;;lllZZZZZZZZW88888888888I88888
`II8888888888888Zl;. ,;;lllZZZZZZZZWMZ88888888888I88888
II8888888888888888ZbaalllZZZZZZZZZWWMZZZ8888888888I888888,
`II88888888888888888b"WWZZZZZWWWMMZZZZZZI888888888I888888b
`II88888888888888888;ZZMMMMMMZZZZZZZZllI888888888I8888888
`II8888888888888888 `;lZZZZZZZZZZZlllll888888888I8888888,
II8888888888888888, `;lllZZZZllllll;;.Y88888888I8888888b,
,II8888888888888888b .;;lllllll;;;.;..88888888I88888888b,
II888888888888888PZI;. .`;;;.;;;..; ...88888888I8888888888,
II888888888888PZ;;';;. ;. .;. .;. .. Y8888888I88888888888b,
,II888888888PZ;;' `8888888I8888888888888b,
II888888888' 888888I8888888888888888
,II888888888 ,888888I8888888888888888
,d88888888888 d888888I8888888888ZZZZZZ
,ad888888888888I 8888888I8888ZZZZZZZZZZZZ
888888888888888' 888888IZZZZZZZZZZZZZZZZZ
8888888888P'8P' Y888ZZZZZZZZZZZZZZZZZZZZ
888888888, " ,ZZZZZZZZZZZZZZZZZZZZZZZ
8888888888, ,ZZZZZZZZZZZZZZZZZZZZZZZZZZ
888888888888a, _ ,ZZZZZZZZZZZZZZZZZZZZ88888888
888888888888888ba,_d' ,ZZZZZZZZZZZZZZZZZ8888888888888
8888888888888888888888bbbaaa,,,______,ZZZZZZZZZZZZZZZ88888888888888888
88888888888888888888888888888888888ZZZZZZZZZZZZZZZ88888888888888888888
8888888888888888888888888888888888ZZZZZZZZZZZZZZ8888888888888888888888
888888888888888888888888888888888ZZZZZZZZZZZZZZ88888888888888888888888
8888888888888888888888888888888ZZZZZZZZZZZZZZ8888888888888888888888888
88888888888888888888888888888ZZZZZZZZZZZZZZ888888888888888888888888888
8888888888888888888888888888ZZZZZZZZZZZZZZ88888888888888888 Normand 8
88888888888888888888888888ZZZZZZZZZZZZZZ8888888888888888888 Veilleux 8
8888888888888888888888888ZZZZZZZZZZZZZZ8888888888888888888888888888888
2015-05-12 19:20:58 +02:00
|
|
|
}
|
2017-04-27 20:49:24 +03:00
|
|
|
|
|
|
|
// USERS REST API
|
|
|
|
if (Meteor.isServer) {
|
2018-07-24 18:09:30 +02:00
|
|
|
// Middleware which checks that API is enabled.
|
2021-05-29 00:19:12 +03:00
|
|
|
JsonRoutes.Middleware.use(function (req, res, next) {
|
2019-08-06 21:14:33 -05:00
|
|
|
const api = req.url.startsWith('/api');
|
|
|
|
if ((api === true && process.env.WITH_API === 'true') || api === false) {
|
2018-07-24 18:09:30 +02:00
|
|
|
return next();
|
2019-06-26 17:47:27 -05:00
|
|
|
} else {
|
2021-05-29 00:19:12 +03:00
|
|
|
res.writeHead(301, {
|
|
|
|
Location: '/',
|
|
|
|
});
|
2018-07-24 18:09:30 +02:00
|
|
|
return res.end();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-10-26 07:27:24 +02:00
|
|
|
/**
|
|
|
|
* @operation get_current_user
|
|
|
|
*
|
|
|
|
* @summary returns the current user
|
|
|
|
* @return_type Users
|
|
|
|
*/
|
2021-05-29 00:19:12 +03:00
|
|
|
JsonRoutes.add('GET', '/api/user', function (req, res) {
|
2017-10-15 07:39:48 +02:00
|
|
|
try {
|
|
|
|
Authentication.checkLoggedIn(req.userId);
|
2023-02-04 17:25:09 +01:00
|
|
|
const data = ReactiveCache.getUser({
|
2021-05-29 00:19:12 +03:00
|
|
|
_id: req.userId,
|
|
|
|
});
|
2017-10-15 07:39:48 +02:00
|
|
|
delete data.services;
|
2020-05-03 01:29:28 +02:00
|
|
|
|
|
|
|
// get all boards where the user is member of
|
2023-02-25 20:19:18 +01:00
|
|
|
let boards = ReactiveCache.getBoards(
|
2020-05-03 01:29:28 +02:00
|
|
|
{
|
|
|
|
type: 'board',
|
|
|
|
'members.userId': req.userId,
|
|
|
|
},
|
|
|
|
{
|
2021-05-29 00:19:12 +03:00
|
|
|
fields: {
|
|
|
|
_id: 1,
|
|
|
|
members: 1,
|
|
|
|
},
|
2020-05-03 01:29:28 +02:00
|
|
|
},
|
|
|
|
);
|
2021-05-29 00:19:12 +03:00
|
|
|
boards = boards.map((b) => {
|
|
|
|
const u = b.members.find((m) => m.userId === req.userId);
|
2020-05-03 01:29:28 +02:00
|
|
|
delete u.userId;
|
|
|
|
u.boardId = b._id;
|
|
|
|
return u;
|
|
|
|
});
|
|
|
|
|
|
|
|
data.boards = boards;
|
2017-10-15 07:39:48 +02:00
|
|
|
JsonRoutes.sendResult(res, {
|
|
|
|
code: 200,
|
|
|
|
data,
|
|
|
|
});
|
2019-06-26 17:47:27 -05:00
|
|
|
} catch (error) {
|
2017-10-15 07:39:48 +02:00
|
|
|
JsonRoutes.sendResult(res, {
|
|
|
|
code: 200,
|
|
|
|
data: error,
|
|
|
|
});
|
|
|
|
}
|
2017-05-15 18:44:54 +02:00
|
|
|
});
|
|
|
|
|
2018-10-26 07:27:24 +02:00
|
|
|
/**
|
|
|
|
* @operation get_all_users
|
|
|
|
*
|
|
|
|
* @summary return all the users
|
|
|
|
*
|
|
|
|
* @description Only the admin user (the first user) can call the REST API.
|
|
|
|
* @return_type [{ _id: string,
|
|
|
|
* username: string}]
|
|
|
|
*/
|
2021-05-29 00:19:12 +03:00
|
|
|
JsonRoutes.add('GET', '/api/users', function (req, res) {
|
2017-10-15 07:39:48 +02:00
|
|
|
try {
|
|
|
|
Authentication.checkUserId(req.userId);
|
|
|
|
JsonRoutes.sendResult(res, {
|
|
|
|
code: 200,
|
2021-05-29 00:19:12 +03:00
|
|
|
data: Meteor.users.find({}).map(function (doc) {
|
|
|
|
return {
|
|
|
|
_id: doc._id,
|
|
|
|
username: doc.username,
|
|
|
|
};
|
2017-10-15 07:39:48 +02:00
|
|
|
}),
|
|
|
|
});
|
2019-06-26 17:47:27 -05:00
|
|
|
} catch (error) {
|
2017-10-15 07:39:48 +02:00
|
|
|
JsonRoutes.sendResult(res, {
|
|
|
|
code: 200,
|
|
|
|
data: error,
|
|
|
|
});
|
|
|
|
}
|
2017-04-27 20:49:24 +03:00
|
|
|
});
|
2017-10-15 07:39:48 +02:00
|
|
|
|
2018-10-26 07:27:24 +02:00
|
|
|
/**
|
|
|
|
* @operation get_user
|
|
|
|
*
|
|
|
|
* @summary get a given user
|
|
|
|
*
|
|
|
|
* @description Only the admin user (the first user) can call the REST API.
|
|
|
|
*
|
2021-02-05 19:58:24 +01:00
|
|
|
* @param {string} userId the user ID or username
|
2018-10-26 07:27:24 +02:00
|
|
|
* @return_type Users
|
|
|
|
*/
|
2021-05-29 00:19:12 +03:00
|
|
|
JsonRoutes.add('GET', '/api/users/:userId', function (req, res) {
|
2017-10-15 07:39:48 +02:00
|
|
|
try {
|
|
|
|
Authentication.checkUserId(req.userId);
|
2021-02-05 19:58:24 +01:00
|
|
|
let id = req.params.userId;
|
2023-02-04 17:25:09 +01:00
|
|
|
let user = ReactiveCache.getUser({
|
2021-05-29 00:19:12 +03:00
|
|
|
_id: id,
|
|
|
|
});
|
2021-02-05 19:58:24 +01:00
|
|
|
if (!user) {
|
2023-02-04 17:25:09 +01:00
|
|
|
user = ReactiveCache.getUser({
|
2021-05-29 00:19:12 +03:00
|
|
|
username: id,
|
|
|
|
});
|
2021-02-05 19:58:24 +01:00
|
|
|
id = user._id;
|
|
|
|
}
|
2020-05-03 01:29:28 +02:00
|
|
|
|
|
|
|
// get all boards where the user is member of
|
2023-02-25 20:19:18 +01:00
|
|
|
let boards = ReactiveCache.getBoards(
|
2020-05-03 01:29:28 +02:00
|
|
|
{
|
|
|
|
type: 'board',
|
|
|
|
'members.userId': id,
|
|
|
|
},
|
|
|
|
{
|
2021-05-29 00:19:12 +03:00
|
|
|
fields: {
|
|
|
|
_id: 1,
|
|
|
|
members: 1,
|
|
|
|
},
|
2020-05-03 01:29:28 +02:00
|
|
|
},
|
|
|
|
);
|
2021-05-29 00:19:12 +03:00
|
|
|
boards = boards.map((b) => {
|
|
|
|
const u = b.members.find((m) => m.userId === id);
|
2020-05-03 01:29:28 +02:00
|
|
|
delete u.userId;
|
|
|
|
u.boardId = b._id;
|
|
|
|
return u;
|
|
|
|
});
|
|
|
|
|
|
|
|
user.boards = boards;
|
2017-10-15 07:39:48 +02:00
|
|
|
JsonRoutes.sendResult(res, {
|
|
|
|
code: 200,
|
2020-05-03 01:29:28 +02:00
|
|
|
data: user,
|
2017-10-15 07:39:48 +02:00
|
|
|
});
|
2019-06-26 17:47:27 -05:00
|
|
|
} catch (error) {
|
2017-10-15 07:39:48 +02:00
|
|
|
JsonRoutes.sendResult(res, {
|
|
|
|
code: 200,
|
|
|
|
data: error,
|
|
|
|
});
|
|
|
|
}
|
2017-04-27 20:49:24 +03:00
|
|
|
});
|
2017-10-15 07:39:48 +02:00
|
|
|
|
2018-10-26 07:27:24 +02:00
|
|
|
/**
|
|
|
|
* @operation edit_user
|
|
|
|
*
|
|
|
|
* @summary edit a given user
|
|
|
|
*
|
|
|
|
* @description Only the admin user (the first user) can call the REST API.
|
|
|
|
*
|
|
|
|
* Possible values for *action*:
|
|
|
|
* - `takeOwnership`: The admin takes the ownership of ALL boards of the user (archived and not archived) where the user is admin on.
|
|
|
|
* - `disableLogin`: Disable a user (the user is not allowed to login and his login tokens are purged)
|
|
|
|
* - `enableLogin`: Enable a user
|
|
|
|
*
|
|
|
|
* @param {string} userId the user ID
|
|
|
|
* @param {string} action the action
|
|
|
|
* @return_type {_id: string,
|
|
|
|
* title: string}
|
|
|
|
*/
|
2021-05-29 00:19:12 +03:00
|
|
|
JsonRoutes.add('PUT', '/api/users/:userId', function (req, res) {
|
2017-10-15 07:39:48 +02:00
|
|
|
try {
|
|
|
|
Authentication.checkUserId(req.userId);
|
2018-06-26 11:10:16 +02:00
|
|
|
const id = req.params.userId;
|
2017-10-15 07:39:48 +02:00
|
|
|
const action = req.body.action;
|
2023-02-04 17:25:09 +01:00
|
|
|
let data = ReactiveCache.getUser({
|
2021-05-29 00:19:12 +03:00
|
|
|
_id: id,
|
|
|
|
});
|
2017-10-15 07:39:48 +02:00
|
|
|
if (data !== undefined) {
|
|
|
|
if (action === 'takeOwnership') {
|
2023-02-25 20:19:18 +01:00
|
|
|
data = ReactiveCache.getBoards(
|
2020-04-19 12:30:21 +03:00
|
|
|
{
|
|
|
|
'members.userId': id,
|
|
|
|
'members.isAdmin': true,
|
|
|
|
},
|
2021-05-29 00:19:12 +03:00
|
|
|
{
|
|
|
|
sort: {
|
|
|
|
sort: 1 /* boards default sorting */,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
).map(function (board) {
|
2017-10-15 07:39:48 +02:00
|
|
|
if (board.hasMember(req.userId)) {
|
|
|
|
board.removeMember(req.userId);
|
|
|
|
}
|
|
|
|
board.changeOwnership(id, req.userId);
|
|
|
|
return {
|
|
|
|
_id: board._id,
|
|
|
|
title: board.title,
|
|
|
|
};
|
|
|
|
});
|
|
|
|
} else {
|
2019-06-26 17:47:27 -05:00
|
|
|
if (action === 'disableLogin' && id !== req.userId) {
|
|
|
|
Users.update(
|
2021-05-29 00:19:12 +03:00
|
|
|
{
|
|
|
|
_id: id,
|
|
|
|
},
|
2019-06-26 17:47:27 -05:00
|
|
|
{
|
|
|
|
$set: {
|
|
|
|
loginDisabled: true,
|
|
|
|
'services.resume.loginTokens': '',
|
|
|
|
},
|
2019-06-28 12:52:09 -05:00
|
|
|
},
|
2019-06-26 17:47:27 -05:00
|
|
|
);
|
2017-10-15 07:39:48 +02:00
|
|
|
} else if (action === 'enableLogin') {
|
2021-05-29 00:19:12 +03:00
|
|
|
Users.update(
|
|
|
|
{
|
|
|
|
_id: id,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
$set: {
|
|
|
|
loginDisabled: '',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
);
|
2017-10-13 08:46:25 +02:00
|
|
|
}
|
2023-02-04 17:25:09 +01:00
|
|
|
data = ReactiveCache.getUser(id);
|
2017-10-13 08:15:19 +02:00
|
|
|
}
|
|
|
|
}
|
2017-10-15 07:39:48 +02:00
|
|
|
JsonRoutes.sendResult(res, {
|
|
|
|
code: 200,
|
|
|
|
data,
|
|
|
|
});
|
2019-06-26 17:47:27 -05:00
|
|
|
} catch (error) {
|
2017-10-15 07:39:48 +02:00
|
|
|
JsonRoutes.sendResult(res, {
|
2018-10-02 00:21:43 +03:00
|
|
|
code: 200,
|
|
|
|
data: error,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-10-26 07:27:24 +02:00
|
|
|
/**
|
|
|
|
* @operation add_board_member
|
|
|
|
* @tag Boards
|
|
|
|
*
|
|
|
|
* @summary Add New Board Member with Role
|
|
|
|
*
|
|
|
|
* @description Only the admin user (the first user) can call the REST API.
|
|
|
|
*
|
|
|
|
* **Note**: see [Boards.set_board_member_permission](#set_board_member_permission)
|
|
|
|
* to later change the permissions.
|
|
|
|
*
|
|
|
|
* @param {string} boardId the board ID
|
|
|
|
* @param {string} userId the user ID
|
2023-04-05 22:10:11 +02:00
|
|
|
* @param {string} action the action (needs to be `add`)
|
2018-10-26 07:27:24 +02:00
|
|
|
* @param {boolean} isAdmin is the user an admin of the board
|
|
|
|
* @param {boolean} isNoComments disable comments
|
|
|
|
* @param {boolean} isCommentOnly only enable comments
|
2023-04-05 22:10:11 +02:00
|
|
|
* @param {boolean} isWorker is the user a board worker
|
2018-10-26 07:27:24 +02:00
|
|
|
* @return_type {_id: string,
|
|
|
|
* title: string}
|
|
|
|
*/
|
2021-05-29 00:19:12 +03:00
|
|
|
JsonRoutes.add(
|
|
|
|
'POST',
|
|
|
|
'/api/boards/:boardId/members/:userId/add',
|
|
|
|
function (req, res) {
|
|
|
|
try {
|
|
|
|
Authentication.checkUserId(req.userId);
|
|
|
|
const userId = req.params.userId;
|
|
|
|
const boardId = req.params.boardId;
|
|
|
|
const action = req.body.action;
|
2023-04-05 22:10:11 +02:00
|
|
|
const { isAdmin, isNoComments, isCommentOnly, isWorker } = req.body;
|
2023-02-04 17:25:09 +01:00
|
|
|
let data = ReactiveCache.getUser(userId);
|
2021-05-29 00:19:12 +03:00
|
|
|
if (data !== undefined) {
|
|
|
|
if (action === 'add') {
|
2023-02-25 20:19:18 +01:00
|
|
|
data = ReactiveCache.getBoards({
|
2021-05-29 00:19:12 +03:00
|
|
|
_id: boardId,
|
|
|
|
}).map(function (board) {
|
|
|
|
if (!board.hasMember(userId)) {
|
|
|
|
board.addMember(userId);
|
|
|
|
|
|
|
|
function isTrue(data) {
|
|
|
|
return data.toLowerCase() === 'true';
|
|
|
|
}
|
|
|
|
board.setMemberPermission(
|
|
|
|
userId,
|
|
|
|
isTrue(isAdmin),
|
|
|
|
isTrue(isNoComments),
|
|
|
|
isTrue(isCommentOnly),
|
2023-04-05 22:10:11 +02:00
|
|
|
isTrue(isWorker),
|
2021-05-29 00:19:12 +03:00
|
|
|
userId,
|
|
|
|
);
|
2018-10-02 00:21:43 +03:00
|
|
|
}
|
2021-05-29 00:19:12 +03:00
|
|
|
return {
|
|
|
|
_id: board._id,
|
|
|
|
title: board.title,
|
|
|
|
};
|
|
|
|
});
|
|
|
|
}
|
2018-10-02 00:21:43 +03:00
|
|
|
}
|
2023-04-05 22:10:11 +02:00
|
|
|
JsonRoutes.sendResult(res, { code: 200, data });
|
2021-05-29 00:19:12 +03:00
|
|
|
} catch (error) {
|
|
|
|
JsonRoutes.sendResult(res, {
|
|
|
|
code: 200,
|
|
|
|
data: error,
|
|
|
|
});
|
2018-10-02 00:21:43 +03:00
|
|
|
}
|
2021-05-29 00:19:12 +03:00
|
|
|
},
|
|
|
|
);
|
2018-10-02 00:21:43 +03:00
|
|
|
|
2018-10-26 07:27:24 +02:00
|
|
|
/**
|
|
|
|
* @operation remove_board_member
|
|
|
|
* @tag Boards
|
|
|
|
*
|
|
|
|
* @summary Remove Member from Board
|
|
|
|
*
|
|
|
|
* @description Only the admin user (the first user) can call the REST API.
|
|
|
|
*
|
|
|
|
* @param {string} boardId the board ID
|
|
|
|
* @param {string} userId the user ID
|
|
|
|
* @param {string} action the action (needs to be `remove`)
|
|
|
|
* @return_type {_id: string,
|
|
|
|
* title: string}
|
|
|
|
*/
|
2019-06-26 17:47:27 -05:00
|
|
|
JsonRoutes.add(
|
|
|
|
'POST',
|
|
|
|
'/api/boards/:boardId/members/:userId/remove',
|
2021-05-29 00:19:12 +03:00
|
|
|
function (req, res) {
|
2019-06-26 17:47:27 -05:00
|
|
|
try {
|
|
|
|
Authentication.checkUserId(req.userId);
|
|
|
|
const userId = req.params.userId;
|
|
|
|
const boardId = req.params.boardId;
|
|
|
|
const action = req.body.action;
|
2023-02-04 17:25:09 +01:00
|
|
|
let data = ReactiveCache.getUser(userId);
|
2019-06-26 17:47:27 -05:00
|
|
|
if (data !== undefined) {
|
|
|
|
if (action === 'remove') {
|
2023-02-25 20:19:18 +01:00
|
|
|
data = ReactiveCache.getBoards({
|
2019-06-26 17:47:27 -05:00
|
|
|
_id: boardId,
|
2021-05-29 00:19:12 +03:00
|
|
|
}).map(function (board) {
|
2019-06-26 17:47:27 -05:00
|
|
|
if (board.hasMember(userId)) {
|
|
|
|
board.removeMember(userId);
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
_id: board._id,
|
|
|
|
title: board.title,
|
|
|
|
};
|
|
|
|
});
|
|
|
|
}
|
2018-10-02 00:21:43 +03:00
|
|
|
}
|
2023-04-05 22:10:11 +02:00
|
|
|
JsonRoutes.sendResult(res, { code: 200, data });
|
2019-06-26 17:47:27 -05:00
|
|
|
} catch (error) {
|
|
|
|
JsonRoutes.sendResult(res, {
|
|
|
|
code: 200,
|
|
|
|
data: error,
|
|
|
|
});
|
2018-10-02 00:21:43 +03:00
|
|
|
}
|
2019-06-28 12:52:09 -05:00
|
|
|
},
|
2019-06-26 17:47:27 -05:00
|
|
|
);
|
2017-04-27 20:49:24 +03:00
|
|
|
|
2018-10-26 07:27:24 +02:00
|
|
|
/**
|
|
|
|
* @operation new_user
|
|
|
|
*
|
|
|
|
* @summary Create a new user
|
|
|
|
*
|
|
|
|
* @description Only the admin user (the first user) can call the REST API.
|
|
|
|
*
|
|
|
|
* @param {string} username the new username
|
|
|
|
* @param {string} email the email of the new user
|
|
|
|
* @param {string} password the password of the new user
|
|
|
|
* @return_type {_id: string}
|
|
|
|
*/
|
2021-05-29 00:19:12 +03:00
|
|
|
JsonRoutes.add('POST', '/api/users/', function (req, res) {
|
2017-10-15 07:39:48 +02:00
|
|
|
try {
|
|
|
|
Authentication.checkUserId(req.userId);
|
|
|
|
const id = Accounts.createUser({
|
|
|
|
username: req.body.username,
|
|
|
|
email: req.body.email,
|
|
|
|
password: req.body.password,
|
|
|
|
from: 'admin',
|
|
|
|
});
|
|
|
|
JsonRoutes.sendResult(res, {
|
|
|
|
code: 200,
|
|
|
|
data: {
|
|
|
|
_id: id,
|
|
|
|
},
|
|
|
|
});
|
2019-06-26 17:47:27 -05:00
|
|
|
} catch (error) {
|
2017-10-15 07:39:48 +02:00
|
|
|
JsonRoutes.sendResult(res, {
|
|
|
|
code: 200,
|
|
|
|
data: error,
|
|
|
|
});
|
|
|
|
}
|
2017-04-27 20:49:24 +03:00
|
|
|
});
|
|
|
|
|
2018-10-26 07:27:24 +02:00
|
|
|
/**
|
|
|
|
* @operation delete_user
|
|
|
|
*
|
|
|
|
* @summary Delete a user
|
|
|
|
*
|
|
|
|
* @description Only the admin user (the first user) can call the REST API.
|
|
|
|
*
|
|
|
|
* @param {string} userId the ID of the user to delete
|
|
|
|
* @return_type {_id: string}
|
|
|
|
*/
|
2021-05-29 00:19:12 +03:00
|
|
|
JsonRoutes.add('DELETE', '/api/users/:userId', function (req, res) {
|
2017-10-15 07:39:48 +02:00
|
|
|
try {
|
|
|
|
Authentication.checkUserId(req.userId);
|
2018-06-26 11:10:16 +02:00
|
|
|
const id = req.params.userId;
|
2021-06-24 22:29:03 +03:00
|
|
|
// Delete user is enabled, but is still has bug of leaving empty user avatars
|
2020-12-18 05:46:04 +02:00
|
|
|
// to boards: boards members, card members and assignees have
|
2021-06-24 22:29:03 +03:00
|
|
|
// empty users. So it would be better to delete user from all boards before
|
|
|
|
// deleting user.
|
|
|
|
// See:
|
2020-12-18 05:46:04 +02:00
|
|
|
// - wekan/client/components/settings/peopleBody.jade deleteButton
|
|
|
|
// - wekan/client/components/settings/peopleBody.js deleteButton
|
|
|
|
// - wekan/client/components/sidebar/sidebar.js Popup.afterConfirm('removeMember'
|
|
|
|
// that does now remove member from board, card members and assignees correctly,
|
|
|
|
// but that should be used to remove user from all boards similarly
|
|
|
|
// - wekan/models/users.js Delete is not enabled
|
2021-06-24 22:29:03 +03:00
|
|
|
Meteor.users.remove({ _id: id });
|
2017-10-15 07:39:48 +02:00
|
|
|
JsonRoutes.sendResult(res, {
|
|
|
|
code: 200,
|
|
|
|
data: {
|
|
|
|
_id: id,
|
|
|
|
},
|
|
|
|
});
|
2019-06-26 17:47:27 -05:00
|
|
|
} catch (error) {
|
2017-10-15 07:39:48 +02:00
|
|
|
JsonRoutes.sendResult(res, {
|
|
|
|
code: 200,
|
|
|
|
data: error,
|
|
|
|
});
|
|
|
|
}
|
2017-04-27 20:49:24 +03:00
|
|
|
});
|
2021-02-02 17:06:06 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @operation create_user_token
|
|
|
|
*
|
|
|
|
* @summary Create a user token
|
|
|
|
*
|
|
|
|
* @description Only the admin user (the first user) can call the REST API.
|
|
|
|
*
|
2021-02-02 20:51:41 +02:00
|
|
|
* @param {string} userId the ID of the user to create token for.
|
2021-02-02 17:06:06 +01:00
|
|
|
* @return_type {_id: string}
|
|
|
|
*/
|
2021-05-29 00:19:12 +03:00
|
|
|
JsonRoutes.add('POST', '/api/createtoken/:userId', function (req, res) {
|
2021-02-02 17:06:06 +01:00
|
|
|
try {
|
|
|
|
Authentication.checkUserId(req.userId);
|
|
|
|
const id = req.params.userId;
|
|
|
|
const token = Accounts._generateStampedLoginToken();
|
|
|
|
Accounts._insertLoginToken(id, token);
|
|
|
|
|
|
|
|
JsonRoutes.sendResult(res, {
|
|
|
|
code: 200,
|
|
|
|
data: {
|
|
|
|
_id: id,
|
|
|
|
authToken: token.token,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
} catch (error) {
|
|
|
|
JsonRoutes.sendResult(res, {
|
|
|
|
code: 200,
|
|
|
|
data: error,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2022-11-16 23:58:04 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @operation delete_user_token
|
|
|
|
*
|
|
|
|
* @summary Delete one or all user token.
|
|
|
|
*
|
|
|
|
* @description Only the admin user (the first user) can call the REST API.
|
|
|
|
*
|
|
|
|
* @param {string} userId the user ID
|
2022-11-17 00:31:30 +03:00
|
|
|
* @param {string} token the user hashedToken
|
2022-11-16 23:58:04 +03:00
|
|
|
* @return_type {message: string}
|
|
|
|
*/
|
|
|
|
JsonRoutes.add('POST', '/api/deletetoken', function (req, res) {
|
|
|
|
try {
|
|
|
|
const { userId, token } = req.body;
|
|
|
|
Authentication.checkUserId(req.userId);
|
|
|
|
|
|
|
|
let data = {
|
|
|
|
message: 'Expected a userId to be set but received none.',
|
|
|
|
};
|
|
|
|
|
|
|
|
if (token && userId) {
|
|
|
|
Accounts.destroyToken(userId, token);
|
|
|
|
data.message = 'Delete token: [' + token + '] from user: ' + userId;
|
|
|
|
} else if (userId) {
|
2023-02-20 01:21:33 +02:00
|
|
|
check(userId, String);
|
2022-11-16 23:58:04 +03:00
|
|
|
Users.update(
|
|
|
|
{
|
|
|
|
_id: userId,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
$set: {
|
|
|
|
'services.resume.loginTokens': '',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
);
|
|
|
|
data.message = 'Delete all token from user: ' + userId;
|
|
|
|
}
|
|
|
|
|
|
|
|
JsonRoutes.sendResult(res, {
|
|
|
|
code: 200,
|
|
|
|
data,
|
|
|
|
});
|
|
|
|
} catch (error) {
|
|
|
|
JsonRoutes.sendResult(res, {
|
|
|
|
code: 200,
|
|
|
|
data: error,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2017-04-27 20:49:24 +03:00
|
|
|
}
|
2019-06-26 17:47:27 -05:00
|
|
|
|
|
|
|
export default Users;
|