1
0
Fork 0
mirror of https://github.com/plankanban/planka.git synced 2025-07-18 20:59:44 +02:00

feat: Version 2

Closes #627, closes #1047
This commit is contained in:
Maksim Eltyshev 2025-05-10 02:09:06 +02:00
parent ad7fb51cfa
commit 2ee1166747
1557 changed files with 76832 additions and 47042 deletions

View file

@ -1,3 +1,8 @@
/*!
* Copyright (c) 2024 PLANKA Software GmbH
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
*/
/**
* User.js
*
@ -5,6 +10,29 @@
* @docs :: https://sailsjs.com/docs/concepts/models-and-orm/models
*/
const Roles = {
ADMIN: 'admin',
PROJECT_OWNER: 'projectOwner',
BOARD_USER: 'boardUser',
};
// TODO: should not be here
const EditorModes = {
WYSIWYG: 'wysiwyg',
MARKUP: 'markup',
};
const HomeViews = {
GRID_PROJECTS: 'gridProjects',
GROUPED_PROJECTS: 'groupedProjects',
};
const ProjectOrders = {
BY_DEFAULT: 'byDefault',
ALPHABETICALLY: 'alphabetically',
BY_CREATION_TIME: 'byCreationTime',
};
const LANGUAGES = [
'ar-YE',
'bg-BG',
@ -37,12 +65,31 @@ const LANGUAGES = [
'zh-TW',
];
const PRIVATE_FIELD_NAMES = ['email', 'isSsoUser'];
const PERSONAL_FIELD_NAMES = [
'language',
'subscribeToOwnCards',
'subscribeToCardWhenCommenting',
'turnOffRecentCardHighlighting',
'enableFavoritesByDefault',
'defaultEditorMode',
'defaultHomeView',
'defaultProjectsOrder',
];
const OIDC = {
id: '_oidc',
};
module.exports = {
Roles,
EditorModes,
HomeViews,
ProjectOrders,
LANGUAGES,
PRIVATE_FIELD_NAMES,
PERSONAL_FIELD_NAMES,
OIDC,
attributes: {
@ -57,16 +104,13 @@ module.exports = {
},
password: {
type: 'string',
isNotEmptyString: true,
allowNull: true,
},
isAdmin: {
type: 'boolean',
defaultsTo: false,
columnName: 'is_admin',
},
isSso: {
type: 'boolean',
defaultsTo: false,
columnName: 'is_sso',
role: {
type: 'string',
isIn: Object.values(Roles),
required: true,
},
name: {
type: 'string',
@ -103,9 +147,48 @@ module.exports = {
defaultsTo: false,
columnName: 'subscribe_to_own_cards',
},
deletedAt: {
type: 'ref',
columnName: 'deleted_at',
subscribeToCardWhenCommenting: {
type: 'boolean',
defaultsTo: true,
columnName: 'subscribe_to_card_when_commenting',
},
turnOffRecentCardHighlighting: {
type: 'boolean',
defaultsTo: false,
columnName: 'turn_off_recent_card_highlighting',
},
enableFavoritesByDefault: {
type: 'boolean',
defaultsTo: false,
columnName: 'enable_favorites_by_default',
},
defaultEditorMode: {
type: 'string',
isIn: Object.values(EditorModes),
defaultsTo: EditorModes.WYSIWYG,
columnName: 'default_editor_mode',
},
defaultHomeView: {
type: 'string',
isIn: Object.values(HomeViews),
defaultsTo: HomeViews.GROUPED_PROJECTS,
columnName: 'default_home_view',
},
defaultProjectsOrder: {
type: 'string',
isIn: Object.values(ProjectOrders),
defaultsTo: ProjectOrders.BY_DEFAULT,
columnName: 'default_projects_order',
},
isSsoUser: {
type: 'boolean',
defaultsTo: false,
columnName: 'is_sso_user',
},
isDeactivated: {
type: 'boolean',
defaultsTo: false,
columnName: 'is_deactivated',
},
passwordChangedAt: {
type: 'ref',
@ -140,27 +223,7 @@ module.exports = {
via: 'userId',
through: 'CardMembership',
},
identityProviders: {
collection: 'IdentityProviderUser',
via: 'userId',
},
},
tableName: 'user_account',
customToJSON() {
const fileManager = sails.hooks['file-manager'].getInstance();
const isDefaultAdmin = this.email === sails.config.custom.defaultAdminEmail;
return {
..._.omit(this, ['password', 'isSso', 'avatar', 'passwordChangedAt']),
isLocked: this.isSso || isDefaultAdmin,
isRoleLocked: (this.isSso && !sails.config.custom.oidcIgnoreRoles) || isDefaultAdmin,
isUsernameLocked: (this.isSso && !sails.config.custom.oidcIgnoreUsername) || isDefaultAdmin,
isDeletionLocked: isDefaultAdmin,
avatarUrl:
this.avatar &&
`${fileManager.buildUrl(`${sails.config.custom.userAvatarsPathSegment}/${this.avatar.dirname}/square-100.${this.avatar.extension}`)}`,
};
},
};