Files
planka/server/api/models/User.js

412 lines
11 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
*/
2025-09-08 16:20:27 +02:00
/**
* @swagger
* components:
* schemas:
* User:
* type: object
* required:
* - id
* - email
* - role
* - name
* - termsType
* properties:
* id:
* type: string
* description: Unique identifier for the user
2025-09-08 19:14:31 +02:00
* example: "1357158568008091264"
2025-09-08 16:20:27 +02:00
* email:
* type: string
* format: email
* description: Email address for login and notifications (private field)
* example: john.doe@example.com
* role:
* type: string
* enum: [admin, projectOwner, boardUser]
* description: User role defining access permissions
* example: admin
* name:
* type: string
* description: Full display name of the user
* example: John Doe
* username:
* type: string
* minLength: 3
* maxLength: 32
* pattern: "^[a-zA-Z0-9]+((_{1}|\\.|){1}[a-zA-Z0-9])*$"
* nullable: true
* description: Unique username for user identification
* example: john_doe
* avatar:
* type: object
* required:
* - url
* - thumbnailUrls
* nullable: true
* description: Avatar information for the user with generated URLs
* properties:
* url:
* type: string
* format: uri
* description: URL to the full-size avatar image
* example: https://storage.example.com/user-avatars/1357158568008091264/original.jpg
* thumbnailUrls:
* type: object
* required:
* - cover180
* description: URLs for different thumbnail sizes
* properties:
* cover180:
* type: string
* format: uri
* description: URL for 180px cover thumbnail
* example: https://storage.example.com/user-avatars/1357158568008091264/cover-180.jpg
* gravatarUrl:
* type: string
* format: uri
* nullable: true
* description: Gravatar URL for the user (conditionally added if configured)
* example: https://www.gravatar.com/avatar/abc123
* phone:
* type: string
* nullable: true
* description: Contact phone number
* example: +1234567890
* organization:
* type: string
* nullable: true
* description: Organization or company name
* example: Acme Corporation
* language:
* type: string
* enum: [ar-YE, bg-BG, cs-CZ, da-DK, de-DE, el-GR, en-GB, en-US, es-ES, et-EE, fa-IR, fi-FI, fr-FR, hu-HU, id-ID, it-IT, ja-JP, ko-KR, nl-NL, pl-PL, pt-BR, pt-PT, ro-RO, ru-RU, sk-SK, sr-Cyrl-RS, sr-Latn-RS, sv-SE, tr-TR, uk-UA, uz-UZ, zh-CN, zh-TW]
* nullable: true
* description: Preferred language for user interface and notifications (personal field)
* example: en-US
* subscribeToOwnCards:
* type: boolean
* default: false
* description: Whether the user subscribes to their own cards (personal field)
* example: false
* subscribeToCardWhenCommenting:
* type: boolean
* default: true
* description: Whether the user subscribes to cards when commenting (personal field)
* example: true
* turnOffRecentCardHighlighting:
* type: boolean
* default: false
* description: Whether recent card highlighting is disabled (personal field)
* example: false
* enableFavoritesByDefault:
* type: boolean
* default: false
* description: Whether favorites are enabled by default (personal field)
* example: false
* defaultEditorMode:
* type: string
* enum: [wysiwyg, markup]
* default: wysiwyg
* description: Default markdown editor mode (personal field)
* example: wysiwyg
* defaultHomeView:
* type: string
* enum: [gridProjects, groupedProjects]
* default: groupedProjects
* description: Default view mode for the home page (personal field)
* example: groupedProjects
* defaultProjectsOrder:
* type: string
* enum: [byDefault, alphabetically, byCreationTime]
* default: byDefault
* description: Default sort order for projects display (personal field)
* example: byDefault
* termsType:
* type: string
* description: Type of terms applicable to the user based on role
* example: general
* isSsoUser:
* type: boolean
* default: false
* description: Whether the user is SSO user (private field)
* example: false
* isDeactivated:
* type: boolean
* default: false
* description: Whether the user account is deactivated and cannot log in
* example: false
* isDefaultAdmin:
* type: boolean
* nullable: true
* description: Whether the user is the default admin (visible only to current user or admin)
* example: false
* lockedFieldNames:
* type: array
* items:
* type: string
* nullable: true
* description: List of fields locked from editing (visible only to current user or admin)
* example: [email, password, name]
* createdAt:
* type: string
* format: date-time
* description: When the user was created
* example: 2024-01-01T00:00:00.000Z
* updatedAt:
* type: string
* format: date-time
* description: When the user was last updated
* example: 2024-01-01T00:00:00.000Z
*/
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',
2025-06-16 21:39:50 +03:00
'et-EE',
2024-07-21 19:33:57 +02:00
'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',
'pt-PT',
2024-07-21 19:33:57 +02:00
'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',
'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 INTERNAL = {
id: '_internal',
role: Roles.ADMIN,
};
const OIDC = {
id: '_oidc',
role: Roles.ADMIN,
};
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,
INTERNAL,
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',
},
2025-08-21 15:10:02 +02:00
termsSignature: {
type: 'string',
isNotEmptyString: true,
allowNull: true,
columnName: 'terms_signature',
},
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',
},
2025-08-21 15:10:02 +02:00
termsAcceptedAt: {
type: 'ref',
columnName: 'terms_accepted_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
};