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 --- server/lib/notifier/notifier.ts | 19 ++++++--- .../instance/direct-registration-for-moderators.ts | 49 ++++++++++++++++++++++ server/lib/notifier/shared/instance/index.ts | 3 +- .../shared/instance/registration-for-moderators.ts | 49 ---------------------- .../registration-request-for-moderators.ts | 48 +++++++++++++++++++++ 5 files changed, 113 insertions(+), 55 deletions(-) create mode 100644 server/lib/notifier/shared/instance/direct-registration-for-moderators.ts delete mode 100644 server/lib/notifier/shared/instance/registration-for-moderators.ts create mode 100644 server/lib/notifier/shared/instance/registration-request-for-moderators.ts (limited to 'server/lib/notifier') diff --git a/server/lib/notifier/notifier.ts b/server/lib/notifier/notifier.ts index 66cfc31c4..920c55df0 100644 --- a/server/lib/notifier/notifier.ts +++ b/server/lib/notifier/notifier.ts @@ -1,4 +1,4 @@ -import { MUser, MUserDefault } from '@server/types/models/user' +import { MRegistration, MUser, MUserDefault } from '@server/types/models/user' import { MVideoBlacklistLightVideo, MVideoBlacklistVideo } from '@server/types/models/video/video-blacklist' import { UserNotificationSettingValue } from '../../../shared/models/users' import { logger } from '../../helpers/logger' @@ -13,6 +13,7 @@ import { AbuseStateChangeForReporter, AutoFollowForInstance, CommentMention, + DirectRegistrationForModerators, FollowForInstance, FollowForUser, ImportFinishedForOwner, @@ -30,7 +31,7 @@ import { OwnedPublicationAfterAutoUnblacklist, OwnedPublicationAfterScheduleUpdate, OwnedPublicationAfterTranscoding, - RegistrationForModerators, + RegistrationRequestForModerators, StudioEditionFinishedForOwner, UnblacklistForOwner } from './shared' @@ -47,7 +48,8 @@ class Notifier { newBlacklist: [ NewBlacklistForOwner ], unblacklist: [ UnblacklistForOwner ], importFinished: [ ImportFinishedForOwner ], - userRegistration: [ RegistrationForModerators ], + directRegistration: [ DirectRegistrationForModerators ], + registrationRequest: [ RegistrationRequestForModerators ], userFollow: [ FollowForUser ], instanceFollow: [ FollowForInstance ], autoInstanceFollow: [ AutoFollowForInstance ], @@ -138,13 +140,20 @@ class Notifier { }) } - notifyOnNewUserRegistration (user: MUserDefault): void { - const models = this.notificationModels.userRegistration + notifyOnNewDirectRegistration (user: MUserDefault): void { + const models = this.notificationModels.directRegistration this.sendNotifications(models, user) .catch(err => logger.error('Cannot notify moderators of new user registration (%s).', user.username, { err })) } + notifyOnNewRegistrationRequest (registration: MRegistration): void { + const models = this.notificationModels.registrationRequest + + this.sendNotifications(models, registration) + .catch(err => logger.error('Cannot notify moderators of new registration request (%s).', registration.username, { err })) + } + notifyOfNewUserFollow (actorFollow: MActorFollowFull): void { const models = this.notificationModels.userFollow diff --git a/server/lib/notifier/shared/instance/direct-registration-for-moderators.ts b/server/lib/notifier/shared/instance/direct-registration-for-moderators.ts new file mode 100644 index 000000000..5044f2068 --- /dev/null +++ b/server/lib/notifier/shared/instance/direct-registration-for-moderators.ts @@ -0,0 +1,49 @@ +import { logger } from '@server/helpers/logger' +import { CONFIG } from '@server/initializers/config' +import { UserModel } from '@server/models/user/user' +import { UserNotificationModel } from '@server/models/user/user-notification' +import { MUserDefault, MUserWithNotificationSetting, UserNotificationModelForApi } from '@server/types/models' +import { UserNotificationType, UserRight } from '@shared/models' +import { AbstractNotification } from '../common/abstract-notification' + +export class DirectRegistrationForModerators extends AbstractNotification { + private moderators: MUserDefault[] + + async prepare () { + this.moderators = await UserModel.listWithRight(UserRight.MANAGE_USERS) + } + + log () { + logger.info('Notifying %s moderators of new user registration of %s.', this.moderators.length, this.payload.username) + } + + getSetting (user: MUserWithNotificationSetting) { + return user.NotificationSetting.newUserRegistration + } + + getTargetUsers () { + return this.moderators + } + + createNotification (user: MUserWithNotificationSetting) { + const notification = UserNotificationModel.build({ + type: UserNotificationType.NEW_USER_REGISTRATION, + userId: user.id, + accountId: this.payload.Account.id + }) + notification.Account = this.payload.Account + + return notification + } + + createEmail (to: string) { + return { + template: 'user-registered', + to, + subject: `A new user registered on ${CONFIG.INSTANCE.NAME}: ${this.payload.username}`, + locals: { + user: this.payload + } + } + } +} diff --git a/server/lib/notifier/shared/instance/index.ts b/server/lib/notifier/shared/instance/index.ts index c3bb22aec..8c75a8ee9 100644 --- a/server/lib/notifier/shared/instance/index.ts +++ b/server/lib/notifier/shared/instance/index.ts @@ -1,3 +1,4 @@ export * from './new-peertube-version-for-admins' export * from './new-plugin-version-for-admins' -export * from './registration-for-moderators' +export * from './direct-registration-for-moderators' +export * from './registration-request-for-moderators' diff --git a/server/lib/notifier/shared/instance/registration-for-moderators.ts b/server/lib/notifier/shared/instance/registration-for-moderators.ts deleted file mode 100644 index e92467424..000000000 --- a/server/lib/notifier/shared/instance/registration-for-moderators.ts +++ /dev/null @@ -1,49 +0,0 @@ -import { logger } from '@server/helpers/logger' -import { CONFIG } from '@server/initializers/config' -import { UserModel } from '@server/models/user/user' -import { UserNotificationModel } from '@server/models/user/user-notification' -import { MUserDefault, MUserWithNotificationSetting, UserNotificationModelForApi } from '@server/types/models' -import { UserNotificationType, UserRight } from '@shared/models' -import { AbstractNotification } from '../common/abstract-notification' - -export class RegistrationForModerators extends AbstractNotification { - private moderators: MUserDefault[] - - async prepare () { - this.moderators = await UserModel.listWithRight(UserRight.MANAGE_USERS) - } - - log () { - logger.info('Notifying %s moderators of new user registration of %s.', this.moderators.length, this.payload.username) - } - - getSetting (user: MUserWithNotificationSetting) { - return user.NotificationSetting.newUserRegistration - } - - getTargetUsers () { - return this.moderators - } - - createNotification (user: MUserWithNotificationSetting) { - const notification = UserNotificationModel.build({ - type: UserNotificationType.NEW_USER_REGISTRATION, - userId: user.id, - accountId: this.payload.Account.id - }) - notification.Account = this.payload.Account - - return notification - } - - createEmail (to: string) { - return { - template: 'user-registered', - to, - subject: `a new user registered on ${CONFIG.INSTANCE.NAME}: ${this.payload.username}`, - locals: { - user: this.payload - } - } - } -} diff --git a/server/lib/notifier/shared/instance/registration-request-for-moderators.ts b/server/lib/notifier/shared/instance/registration-request-for-moderators.ts new file mode 100644 index 000000000..79920245a --- /dev/null +++ b/server/lib/notifier/shared/instance/registration-request-for-moderators.ts @@ -0,0 +1,48 @@ +import { logger } from '@server/helpers/logger' +import { UserModel } from '@server/models/user/user' +import { UserNotificationModel } from '@server/models/user/user-notification' +import { MRegistration, MUserDefault, MUserWithNotificationSetting, UserNotificationModelForApi } from '@server/types/models' +import { UserNotificationType, UserRight } from '@shared/models' +import { AbstractNotification } from '../common/abstract-notification' + +export class RegistrationRequestForModerators extends AbstractNotification { + private moderators: MUserDefault[] + + async prepare () { + this.moderators = await UserModel.listWithRight(UserRight.MANAGE_REGISTRATIONS) + } + + log () { + logger.info('Notifying %s moderators of new user registration request of %s.', this.moderators.length, this.payload.username) + } + + getSetting (user: MUserWithNotificationSetting) { + return user.NotificationSetting.newUserRegistration + } + + getTargetUsers () { + return this.moderators + } + + createNotification (user: MUserWithNotificationSetting) { + const notification = UserNotificationModel.build({ + type: UserNotificationType.NEW_USER_REGISTRATION_REQUEST, + userId: user.id, + userRegistrationId: this.payload.id + }) + notification.UserRegistration = this.payload + + return notification + } + + createEmail (to: string) { + return { + template: 'user-registration-request', + to, + subject: `A new user wants to register: ${this.payload.username}`, + locals: { + registration: this.payload + } + } + } +} -- cgit v1.2.3