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

233 lines
5 KiB
JavaScript
Raw Normal View History

/*!
* Copyright (c) 2024 PLANKA Software GmbH
* Licensed under the Fair Use License: https://github.com/plankanban/planka/blob/master/LICENSE.md
*/
2019-08-31 04:07:25 +05:00
/**
* User.js
*
* @description :: A model definition represents a database table/collection.
* @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',
};
2024-07-21 19:33:57 +02:00
const LANGUAGES = [
'ar-YE',
2024-07-21 19:33:57 +02:00
'bg-BG',
'cs-CZ',
'da-DK',
'de-DE',
2025-06-06 15:14:00 +03:00
'el-GR',
2024-10-09 14:22:22 +02:00
'en-GB',
2024-07-21 19:33:57 +02:00
'en-US',
'es-ES',
'fa-IR',
2025-06-06 19:00:13 +03:00
'fi-FI',
2024-07-21 19:33:57 +02:00
'fr-FR',
'hu-HU',
'id-ID',
'it-IT',
'ja-JP',
'ko-KR',
'nl-NL',
'pl-PL',
'pt-BR',
'ro-RO',
'ru-RU',
'sk-SK',
2025-06-03 12:46:06 +02:00
'sr-Cyrl-RS',
'sr-Latn-RS',
2024-07-21 19:33:57 +02:00
'sv-SE',
2025-06-12 22:43:00 +03:00
'et-EE',
2024-07-21 19:33:57 +02:00
'tr-TR',
'uk-UA',
'uz-UZ',
'zh-CN',
'zh-TW',
2024-07-21 19:33:57 +02:00
];
const PRIVATE_FIELD_NAMES = ['email', 'isSsoUser'];
const PERSONAL_FIELD_NAMES = [
'language',
'subscribeToOwnCards',
'subscribeToCardWhenCommenting',
'turnOffRecentCardHighlighting',
'enableFavoritesByDefault',
'defaultEditorMode',
'defaultHomeView',
'defaultProjectsOrder',
];
const OIDC = {
id: '_oidc',
};
2019-08-31 04:07:25 +05:00
module.exports = {
Roles,
EditorModes,
HomeViews,
ProjectOrders,
2024-07-21 19:33:57 +02:00
LANGUAGES,
PRIVATE_FIELD_NAMES,
PERSONAL_FIELD_NAMES,
OIDC,
2019-08-31 04:07:25 +05:00
attributes: {
// ╔═╗╦═╗╦╔╦╗╦╔╦╗╦╦ ╦╔═╗╔═╗
// ╠═╝╠╦╝║║║║║ ║ ║╚╗╔╝║╣ ╚═╗
// ╩ ╩╚═╩╩ ╩╩ ╩ ╩ ╚╝ ╚═╝╚═╝
email: {
type: 'string',
isEmail: true,
required: true,
2019-08-31 04:07:25 +05:00
},
password: {
type: 'string',
isNotEmptyString: true,
allowNull: true,
2019-08-31 04:07:25 +05:00
},
role: {
type: 'string',
isIn: Object.values(Roles),
required: true,
2023-10-17 19:18:19 +02:00
},
2019-08-31 04:07:25 +05:00
name: {
type: 'string',
required: true,
2019-08-31 04:07:25 +05:00
},
2020-04-03 00:35:25 +05:00
username: {
type: 'string',
isNotEmptyString: true,
minLength: 3,
maxLength: 32,
2021-04-13 18:59:02 +05:00
regex: /^[a-zA-Z0-9]+((_|\.)?[a-zA-Z0-9])*$/,
2020-04-03 00:35:25 +05:00
allowNull: true,
},
avatar: {
type: 'json',
2019-08-31 04:07:25 +05:00
},
phone: {
type: 'string',
isNotEmptyString: true,
allowNull: true,
},
organization: {
type: 'string',
isNotEmptyString: true,
allowNull: true,
},
language: {
type: 'string',
2024-07-21 19:33:57 +02:00
isIn: LANGUAGES,
allowNull: true,
},
subscribeToOwnCards: {
type: 'boolean',
defaultsTo: false,
columnName: 'subscribe_to_own_cards',
},
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',
2019-08-31 04:07:25 +05:00
},
passwordChangedAt: {
type: 'ref',
columnName: 'password_changed_at',
},
2019-08-31 04:07:25 +05:00
// ╔═╗╔╦╗╔╗ ╔═╗╔╦╗╔═╗
// ║╣ ║║║╠╩╗║╣ ║║╚═╗
// ╚═╝╩ ╩╚═╝╚═╝═╩╝╚═╝
// ╔═╗╔═╗╔═╗╔═╗╔═╗╦╔═╗╔╦╗╦╔═╗╔╗╔╔═╗
// ╠═╣╚═╗╚═╗║ ║║ ║╠═╣ ║ ║║ ║║║║╚═╗
// ╩ ╩╚═╝╚═╝╚═╝╚═╝╩╩ ╩ ╩ ╩╚═╝╝╚╝╚═╝
managerProjects: {
2019-08-31 04:07:25 +05:00
collection: 'Project',
via: 'userId',
through: 'ProjectManager',
},
membershipBoards: {
collection: 'Board',
via: 'userId',
through: 'BoardMembership',
2019-08-31 04:07:25 +05:00
},
subscriptionCards: {
collection: 'Card',
via: 'userId',
through: 'CardSubscription',
2019-08-31 04:07:25 +05:00
},
membershipCards: {
collection: 'Card',
via: 'userId',
through: 'CardMembership',
},
2019-08-31 04:07:25 +05:00
},
tableName: 'user_account',
2019-08-31 04:07:25 +05:00
};