diff options
author | Chocobozzz <me@florianbigard.com> | 2023-01-19 09:27:16 +0100 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2023-01-19 13:53:40 +0100 |
commit | e364e31e25bd1d4b8d801c845a96d6be708f0a18 (patch) | |
tree | 220785a42af361706eb8243960c5da9cddf4d2be /server/lib/notifier | |
parent | bc48e33b80f357767b98c1d310b04bdda24c6d46 (diff) | |
download | PeerTube-e364e31e25bd1d4b8d801c845a96d6be708f0a18.tar.gz PeerTube-e364e31e25bd1d4b8d801c845a96d6be708f0a18.tar.zst PeerTube-e364e31e25bd1d4b8d801c845a96d6be708f0a18.zip |
Implement signup approval in server
Diffstat (limited to 'server/lib/notifier')
-rw-r--r-- | server/lib/notifier/notifier.ts | 19 | ||||
-rw-r--r-- | server/lib/notifier/shared/instance/direct-registration-for-moderators.ts (renamed from server/lib/notifier/shared/instance/registration-for-moderators.ts) | 4 | ||||
-rw-r--r-- | server/lib/notifier/shared/instance/index.ts | 3 | ||||
-rw-r--r-- | server/lib/notifier/shared/instance/registration-request-for-moderators.ts | 48 |
4 files changed, 66 insertions, 8 deletions
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 @@ | |||
1 | import { MUser, MUserDefault } from '@server/types/models/user' | 1 | import { MRegistration, MUser, MUserDefault } from '@server/types/models/user' |
2 | import { MVideoBlacklistLightVideo, MVideoBlacklistVideo } from '@server/types/models/video/video-blacklist' | 2 | import { MVideoBlacklistLightVideo, MVideoBlacklistVideo } from '@server/types/models/video/video-blacklist' |
3 | import { UserNotificationSettingValue } from '../../../shared/models/users' | 3 | import { UserNotificationSettingValue } from '../../../shared/models/users' |
4 | import { logger } from '../../helpers/logger' | 4 | import { logger } from '../../helpers/logger' |
@@ -13,6 +13,7 @@ import { | |||
13 | AbuseStateChangeForReporter, | 13 | AbuseStateChangeForReporter, |
14 | AutoFollowForInstance, | 14 | AutoFollowForInstance, |
15 | CommentMention, | 15 | CommentMention, |
16 | DirectRegistrationForModerators, | ||
16 | FollowForInstance, | 17 | FollowForInstance, |
17 | FollowForUser, | 18 | FollowForUser, |
18 | ImportFinishedForOwner, | 19 | ImportFinishedForOwner, |
@@ -30,7 +31,7 @@ import { | |||
30 | OwnedPublicationAfterAutoUnblacklist, | 31 | OwnedPublicationAfterAutoUnblacklist, |
31 | OwnedPublicationAfterScheduleUpdate, | 32 | OwnedPublicationAfterScheduleUpdate, |
32 | OwnedPublicationAfterTranscoding, | 33 | OwnedPublicationAfterTranscoding, |
33 | RegistrationForModerators, | 34 | RegistrationRequestForModerators, |
34 | StudioEditionFinishedForOwner, | 35 | StudioEditionFinishedForOwner, |
35 | UnblacklistForOwner | 36 | UnblacklistForOwner |
36 | } from './shared' | 37 | } from './shared' |
@@ -47,7 +48,8 @@ class Notifier { | |||
47 | newBlacklist: [ NewBlacklistForOwner ], | 48 | newBlacklist: [ NewBlacklistForOwner ], |
48 | unblacklist: [ UnblacklistForOwner ], | 49 | unblacklist: [ UnblacklistForOwner ], |
49 | importFinished: [ ImportFinishedForOwner ], | 50 | importFinished: [ ImportFinishedForOwner ], |
50 | userRegistration: [ RegistrationForModerators ], | 51 | directRegistration: [ DirectRegistrationForModerators ], |
52 | registrationRequest: [ RegistrationRequestForModerators ], | ||
51 | userFollow: [ FollowForUser ], | 53 | userFollow: [ FollowForUser ], |
52 | instanceFollow: [ FollowForInstance ], | 54 | instanceFollow: [ FollowForInstance ], |
53 | autoInstanceFollow: [ AutoFollowForInstance ], | 55 | autoInstanceFollow: [ AutoFollowForInstance ], |
@@ -138,13 +140,20 @@ class Notifier { | |||
138 | }) | 140 | }) |
139 | } | 141 | } |
140 | 142 | ||
141 | notifyOnNewUserRegistration (user: MUserDefault): void { | 143 | notifyOnNewDirectRegistration (user: MUserDefault): void { |
142 | const models = this.notificationModels.userRegistration | 144 | const models = this.notificationModels.directRegistration |
143 | 145 | ||
144 | this.sendNotifications(models, user) | 146 | this.sendNotifications(models, user) |
145 | .catch(err => logger.error('Cannot notify moderators of new user registration (%s).', user.username, { err })) | 147 | .catch(err => logger.error('Cannot notify moderators of new user registration (%s).', user.username, { err })) |
146 | } | 148 | } |
147 | 149 | ||
150 | notifyOnNewRegistrationRequest (registration: MRegistration): void { | ||
151 | const models = this.notificationModels.registrationRequest | ||
152 | |||
153 | this.sendNotifications(models, registration) | ||
154 | .catch(err => logger.error('Cannot notify moderators of new registration request (%s).', registration.username, { err })) | ||
155 | } | ||
156 | |||
148 | notifyOfNewUserFollow (actorFollow: MActorFollowFull): void { | 157 | notifyOfNewUserFollow (actorFollow: MActorFollowFull): void { |
149 | const models = this.notificationModels.userFollow | 158 | const models = this.notificationModels.userFollow |
150 | 159 | ||
diff --git a/server/lib/notifier/shared/instance/registration-for-moderators.ts b/server/lib/notifier/shared/instance/direct-registration-for-moderators.ts index e92467424..5044f2068 100644 --- a/server/lib/notifier/shared/instance/registration-for-moderators.ts +++ b/server/lib/notifier/shared/instance/direct-registration-for-moderators.ts | |||
@@ -6,7 +6,7 @@ import { MUserDefault, MUserWithNotificationSetting, UserNotificationModelForApi | |||
6 | import { UserNotificationType, UserRight } from '@shared/models' | 6 | import { UserNotificationType, UserRight } from '@shared/models' |
7 | import { AbstractNotification } from '../common/abstract-notification' | 7 | import { AbstractNotification } from '../common/abstract-notification' |
8 | 8 | ||
9 | export class RegistrationForModerators extends AbstractNotification <MUserDefault> { | 9 | export class DirectRegistrationForModerators extends AbstractNotification <MUserDefault> { |
10 | private moderators: MUserDefault[] | 10 | private moderators: MUserDefault[] |
11 | 11 | ||
12 | async prepare () { | 12 | async prepare () { |
@@ -40,7 +40,7 @@ export class RegistrationForModerators extends AbstractNotification <MUserDefaul | |||
40 | return { | 40 | return { |
41 | template: 'user-registered', | 41 | template: 'user-registered', |
42 | to, | 42 | to, |
43 | subject: `a new user registered on ${CONFIG.INSTANCE.NAME}: ${this.payload.username}`, | 43 | subject: `A new user registered on ${CONFIG.INSTANCE.NAME}: ${this.payload.username}`, |
44 | locals: { | 44 | locals: { |
45 | user: this.payload | 45 | user: this.payload |
46 | } | 46 | } |
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 @@ | |||
1 | export * from './new-peertube-version-for-admins' | 1 | export * from './new-peertube-version-for-admins' |
2 | export * from './new-plugin-version-for-admins' | 2 | export * from './new-plugin-version-for-admins' |
3 | export * from './registration-for-moderators' | 3 | export * from './direct-registration-for-moderators' |
4 | export * from './registration-request-for-moderators' | ||
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 @@ | |||
1 | import { logger } from '@server/helpers/logger' | ||
2 | import { UserModel } from '@server/models/user/user' | ||
3 | import { UserNotificationModel } from '@server/models/user/user-notification' | ||
4 | import { MRegistration, MUserDefault, MUserWithNotificationSetting, UserNotificationModelForApi } from '@server/types/models' | ||
5 | import { UserNotificationType, UserRight } from '@shared/models' | ||
6 | import { AbstractNotification } from '../common/abstract-notification' | ||
7 | |||
8 | export class RegistrationRequestForModerators extends AbstractNotification <MRegistration> { | ||
9 | private moderators: MUserDefault[] | ||
10 | |||
11 | async prepare () { | ||
12 | this.moderators = await UserModel.listWithRight(UserRight.MANAGE_REGISTRATIONS) | ||
13 | } | ||
14 | |||
15 | log () { | ||
16 | logger.info('Notifying %s moderators of new user registration request of %s.', this.moderators.length, this.payload.username) | ||
17 | } | ||
18 | |||
19 | getSetting (user: MUserWithNotificationSetting) { | ||
20 | return user.NotificationSetting.newUserRegistration | ||
21 | } | ||
22 | |||
23 | getTargetUsers () { | ||
24 | return this.moderators | ||
25 | } | ||
26 | |||
27 | createNotification (user: MUserWithNotificationSetting) { | ||
28 | const notification = UserNotificationModel.build<UserNotificationModelForApi>({ | ||
29 | type: UserNotificationType.NEW_USER_REGISTRATION_REQUEST, | ||
30 | userId: user.id, | ||
31 | userRegistrationId: this.payload.id | ||
32 | }) | ||
33 | notification.UserRegistration = this.payload | ||
34 | |||
35 | return notification | ||
36 | } | ||
37 | |||
38 | createEmail (to: string) { | ||
39 | return { | ||
40 | template: 'user-registration-request', | ||
41 | to, | ||
42 | subject: `A new user wants to register: ${this.payload.username}`, | ||
43 | locals: { | ||
44 | registration: this.payload | ||
45 | } | ||
46 | } | ||
47 | } | ||
48 | } | ||