1
0
Fork 0
mirror of https://github.com/plankanban/planka.git synced 2025-07-19 05:09:43 +02:00
planka/server/api/models/User.js

162 lines
3.6 KiB
JavaScript
Raw Normal View History

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
*/
2024-07-21 19:33:57 +02:00
const LANGUAGES = [
'bg-BG',
'cs-CZ',
'da-DK',
'de-DE',
'en-US',
'es-ES',
'fa-IR',
'fr-FR',
'hu-HU',
'id-ID',
'it-IT',
'ja-JP',
'ko-KR',
'nl-NL',
'pl-PL',
'pt-BR',
'ro-RO',
'ru-RU',
'sk-SK',
'sv-SE',
'tr-TR',
'uk-UA',
'uz-UZ',
'zh-CN',
'zh-TW',
2024-07-21 19:33:57 +02:00
];
const OIDC = {
id: '_oidc',
};
2019-08-31 04:07:25 +05:00
module.exports = {
2024-07-21 19:33:57 +02:00
LANGUAGES,
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',
},
isAdmin: {
type: 'boolean',
defaultsTo: false,
columnName: 'is_admin',
2019-08-31 04:07:25 +05:00
},
2023-10-17 19:18:19 +02:00
isSso: {
type: 'boolean',
defaultsTo: false,
columnName: 'is_sso',
},
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: 16,
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',
},
2019-08-31 04:07:25 +05:00
deletedAt: {
type: 'ref',
columnName: 'deleted_at',
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',
},
2023-09-04 10:06:59 -05:00
identityProviders: {
collection: 'IdentityProviderUser',
via: 'userId',
},
2019-08-31 04:07:25 +05:00
},
tableName: 'user_account',
customToJSON() {
const isDefaultAdmin = this.email === sails.config.custom.defaultAdminEmail;
2023-10-17 19:18:19 +02:00
2019-08-31 04:07:25 +05:00
return {
2023-10-17 19:18:19 +02:00
..._.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,
2020-04-21 05:04:34 +05:00
avatarUrl:
this.avatar &&
`${sails.config.custom.userAvatarsUrl}/${this.avatar.dirname}/square-100.${this.avatar.extension}`,
2019-08-31 04:07:25 +05:00
};
},
2019-08-31 04:07:25 +05:00
};