From e364e31e25bd1d4b8d801c845a96d6be708f0a18 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 19 Jan 2023 09:27:16 +0100 Subject: Implement signup approval in server --- shared/core-utils/users/user-role.ts | 3 ++- shared/models/plugins/server/server-hook.model.ts | 7 ++++++ shared/models/server/custom-config.model.ts | 1 + shared/models/server/server-config.model.ts | 1 + shared/models/server/server-error-code.enum.ts | 10 ++++++-- shared/models/users/index.ts | 2 +- shared/models/users/registration/index.ts | 5 ++++ .../users/registration/user-register.model.ts | 12 +++++++++ .../user-registration-request.model.ts | 5 ++++ .../registration/user-registration-state.model.ts | 5 ++++ .../user-registration-update-state.model.ts | 3 +++ .../users/registration/user-registration.model.ts | 29 ++++++++++++++++++++++ shared/models/users/user-notification.model.ts | 9 ++++++- shared/models/users/user-register.model.ts | 12 --------- shared/models/users/user-right.enum.ts | 4 ++- 15 files changed, 90 insertions(+), 18 deletions(-) create mode 100644 shared/models/users/registration/index.ts create mode 100644 shared/models/users/registration/user-register.model.ts create mode 100644 shared/models/users/registration/user-registration-request.model.ts create mode 100644 shared/models/users/registration/user-registration-state.model.ts create mode 100644 shared/models/users/registration/user-registration-update-state.model.ts create mode 100644 shared/models/users/registration/user-registration.model.ts delete mode 100644 shared/models/users/user-register.model.ts (limited to 'shared') diff --git a/shared/core-utils/users/user-role.ts b/shared/core-utils/users/user-role.ts index cc757d779..5f3b9a10f 100644 --- a/shared/core-utils/users/user-role.ts +++ b/shared/core-utils/users/user-role.ts @@ -23,7 +23,8 @@ const userRoleRights: { [ id in UserRole ]: UserRight[] } = { UserRight.MANAGE_ACCOUNTS_BLOCKLIST, UserRight.MANAGE_SERVERS_BLOCKLIST, UserRight.MANAGE_USERS, - UserRight.SEE_ALL_COMMENTS + UserRight.SEE_ALL_COMMENTS, + UserRight.MANAGE_REGISTRATIONS ], [UserRole.USER]: [] diff --git a/shared/models/plugins/server/server-hook.model.ts b/shared/models/plugins/server/server-hook.model.ts index f11d2050b..dd9cc3ad6 100644 --- a/shared/models/plugins/server/server-hook.model.ts +++ b/shared/models/plugins/server/server-hook.model.ts @@ -91,6 +91,10 @@ export const serverFilterHookObject = { // Filter result used to check if a user can register on the instance 'filter:api.user.signup.allowed.result': true, + // Filter result used to check if a user can send a registration request on the instance + // PeerTube >= 5.1 + 'filter:api.user.request-signup.allowed.result': true, + // Filter result used to check if video/torrent download is allowed 'filter:api.download.video.allowed.result': true, 'filter:api.download.torrent.allowed.result': true, @@ -156,6 +160,9 @@ export const serverActionHookObject = { 'action:api.user.unblocked': true, // Fired when a user registered on the instance 'action:api.user.registered': true, + // Fired when a user requested registration on the instance + // PeerTube >= 5.1 + 'action:api.user.requested-registration': true, // Fired when an admin/moderator created a user 'action:api.user.created': true, // Fired when a user is removed by an admin/moderator diff --git a/shared/models/server/custom-config.model.ts b/shared/models/server/custom-config.model.ts index 7d9d570b1..846bf6159 100644 --- a/shared/models/server/custom-config.model.ts +++ b/shared/models/server/custom-config.model.ts @@ -83,6 +83,7 @@ export interface CustomConfig { signup: { enabled: boolean limit: number + requiresApproval: boolean requiresEmailVerification: boolean minimumAge: number } diff --git a/shared/models/server/server-config.model.ts b/shared/models/server/server-config.model.ts index 3b6d0597c..d0bd9a00f 100644 --- a/shared/models/server/server-config.model.ts +++ b/shared/models/server/server-config.model.ts @@ -131,6 +131,7 @@ export interface ServerConfig { allowed: boolean allowedForCurrentIP: boolean requiresEmailVerification: boolean + requiresApproval: boolean minimumAge: number } diff --git a/shared/models/server/server-error-code.enum.ts b/shared/models/server/server-error-code.enum.ts index 0e70ea0a7..a39cde1b3 100644 --- a/shared/models/server/server-error-code.enum.ts +++ b/shared/models/server/server-error-code.enum.ts @@ -39,7 +39,13 @@ export const enum ServerErrorCode { */ INCORRECT_FILES_IN_TORRENT = 'incorrect_files_in_torrent', - COMMENT_NOT_ASSOCIATED_TO_VIDEO = 'comment_not_associated_to_video' + COMMENT_NOT_ASSOCIATED_TO_VIDEO = 'comment_not_associated_to_video', + + MISSING_TWO_FACTOR = 'missing_two_factor', + INVALID_TWO_FACTOR = 'invalid_two_factor', + + ACCOUNT_WAITING_FOR_APPROVAL = 'account_waiting_for_approval', + ACCOUNT_APPROVAL_REJECTED = 'account_approval_rejected' } /** @@ -70,5 +76,5 @@ export const enum OAuth2ErrorCode { * * @see https://github.com/oauthjs/node-oauth2-server/blob/master/lib/errors/invalid-token-error.js */ - INVALID_TOKEN = 'invalid_token', + INVALID_TOKEN = 'invalid_token' } diff --git a/shared/models/users/index.ts b/shared/models/users/index.ts index 32f7a441c..4a050c870 100644 --- a/shared/models/users/index.ts +++ b/shared/models/users/index.ts @@ -1,3 +1,4 @@ +export * from './registration' export * from './two-factor-enable-result.model' export * from './user-create-result.model' export * from './user-create.model' @@ -6,7 +7,6 @@ export * from './user-login.model' export * from './user-notification-setting.model' export * from './user-notification.model' export * from './user-refresh-token.model' -export * from './user-register.model' export * from './user-right.enum' export * from './user-role' export * from './user-scoped-token' diff --git a/shared/models/users/registration/index.ts b/shared/models/users/registration/index.ts new file mode 100644 index 000000000..593740c4f --- /dev/null +++ b/shared/models/users/registration/index.ts @@ -0,0 +1,5 @@ +export * from './user-register.model' +export * from './user-registration-request.model' +export * from './user-registration-state.model' +export * from './user-registration-update-state.model' +export * from './user-registration.model' diff --git a/shared/models/users/registration/user-register.model.ts b/shared/models/users/registration/user-register.model.ts new file mode 100644 index 000000000..cf9a43a67 --- /dev/null +++ b/shared/models/users/registration/user-register.model.ts @@ -0,0 +1,12 @@ +export interface UserRegister { + username: string + password: string + email: string + + displayName?: string + + channel?: { + name: string + displayName: string + } +} diff --git a/shared/models/users/registration/user-registration-request.model.ts b/shared/models/users/registration/user-registration-request.model.ts new file mode 100644 index 000000000..6c38817e0 --- /dev/null +++ b/shared/models/users/registration/user-registration-request.model.ts @@ -0,0 +1,5 @@ +import { UserRegister } from './user-register.model' + +export interface UserRegistrationRequest extends UserRegister { + registrationReason: string +} diff --git a/shared/models/users/registration/user-registration-state.model.ts b/shared/models/users/registration/user-registration-state.model.ts new file mode 100644 index 000000000..e4c835f78 --- /dev/null +++ b/shared/models/users/registration/user-registration-state.model.ts @@ -0,0 +1,5 @@ +export const enum UserRegistrationState { + PENDING = 1, + REJECTED = 2, + ACCEPTED = 3 +} diff --git a/shared/models/users/registration/user-registration-update-state.model.ts b/shared/models/users/registration/user-registration-update-state.model.ts new file mode 100644 index 000000000..636e22c32 --- /dev/null +++ b/shared/models/users/registration/user-registration-update-state.model.ts @@ -0,0 +1,3 @@ +export interface UserRegistrationUpdateState { + moderationResponse: string +} diff --git a/shared/models/users/registration/user-registration.model.ts b/shared/models/users/registration/user-registration.model.ts new file mode 100644 index 000000000..0d74dc28b --- /dev/null +++ b/shared/models/users/registration/user-registration.model.ts @@ -0,0 +1,29 @@ +import { UserRegistrationState } from './user-registration-state.model' + +export interface UserRegistration { + id: number + + state: { + id: UserRegistrationState + label: string + } + + registrationReason: string + moderationResponse: string + + username: string + email: string + emailVerified: boolean + + accountDisplayName: string + + channelHandle: string + channelDisplayName: string + + createdAt: Date + updatedAt: Date + + user?: { + id: number + } +} diff --git a/shared/models/users/user-notification.model.ts b/shared/models/users/user-notification.model.ts index 0fd7a7181..294c921bd 100644 --- a/shared/models/users/user-notification.model.ts +++ b/shared/models/users/user-notification.model.ts @@ -32,7 +32,9 @@ export const enum UserNotificationType { NEW_PLUGIN_VERSION = 17, NEW_PEERTUBE_VERSION = 18, - MY_VIDEO_STUDIO_EDITION_FINISHED = 19 + MY_VIDEO_STUDIO_EDITION_FINISHED = 19, + + NEW_USER_REGISTRATION_REQUEST = 20 } export interface VideoInfo { @@ -126,6 +128,11 @@ export interface UserNotification { latestVersion: string } + registration?: { + id: number + username: string + } + createdAt: string updatedAt: string } diff --git a/shared/models/users/user-register.model.ts b/shared/models/users/user-register.model.ts deleted file mode 100644 index cf9a43a67..000000000 --- a/shared/models/users/user-register.model.ts +++ /dev/null @@ -1,12 +0,0 @@ -export interface UserRegister { - username: string - password: string - email: string - - displayName?: string - - channel?: { - name: string - displayName: string - } -} diff --git a/shared/models/users/user-right.enum.ts b/shared/models/users/user-right.enum.ts index 9c6828aa5..42e5c8cd6 100644 --- a/shared/models/users/user-right.enum.ts +++ b/shared/models/users/user-right.enum.ts @@ -43,5 +43,7 @@ export const enum UserRight { MANAGE_VIDEO_FILES = 25, RUN_VIDEO_TRANSCODING = 26, - MANAGE_VIDEO_IMPORTS = 27 + MANAGE_VIDEO_IMPORTS = 27, + + MANAGE_REGISTRATIONS = 28 } -- cgit v1.2.3