diff options
Diffstat (limited to 'server/models')
-rw-r--r-- | server/models/account/user.ts | 23 | ||||
-rw-r--r-- | server/models/video/video-abuse.ts | 8 |
2 files changed, 29 insertions, 2 deletions
diff --git a/server/models/account/user.ts b/server/models/account/user.ts index 026a8c9a0..653921907 100644 --- a/server/models/account/user.ts +++ b/server/models/account/user.ts | |||
@@ -4,7 +4,7 @@ import { | |||
4 | Scopes, Table, UpdatedAt | 4 | Scopes, Table, UpdatedAt |
5 | } from 'sequelize-typescript' | 5 | } from 'sequelize-typescript' |
6 | import { hasUserRight, USER_ROLE_LABELS, UserRight } from '../../../shared' | 6 | import { hasUserRight, USER_ROLE_LABELS, UserRight } from '../../../shared' |
7 | import { User } from '../../../shared/models/users' | 7 | import { User, UserRole } from '../../../shared/models/users' |
8 | import { | 8 | import { |
9 | isUserAutoPlayVideoValid, isUserDisplayNSFWValid, isUserPasswordValid, isUserRoleValid, isUserUsernameValid, | 9 | isUserAutoPlayVideoValid, isUserDisplayNSFWValid, isUserPasswordValid, isUserRoleValid, isUserUsernameValid, |
10 | isUserVideoQuotaValid | 10 | isUserVideoQuotaValid |
@@ -137,6 +137,27 @@ export class UserModel extends Model<UserModel> { | |||
137 | }) | 137 | }) |
138 | } | 138 | } |
139 | 139 | ||
140 | static listEmailsWithRight (right: UserRight) { | ||
141 | const roles = Object.keys(USER_ROLE_LABELS) | ||
142 | .map(k => parseInt(k, 10) as UserRole) | ||
143 | .filter(role => hasUserRight(role, right)) | ||
144 | |||
145 | console.log(roles) | ||
146 | |||
147 | const query = { | ||
148 | attribute: [ 'email' ], | ||
149 | where: { | ||
150 | role: { | ||
151 | [Sequelize.Op.in]: roles | ||
152 | } | ||
153 | } | ||
154 | } | ||
155 | |||
156 | return UserModel.unscoped() | ||
157 | .findAll(query) | ||
158 | .then(u => u.map(u => u.email)) | ||
159 | } | ||
160 | |||
140 | static loadById (id: number) { | 161 | static loadById (id: number) { |
141 | return UserModel.findById(id) | 162 | return UserModel.findById(id) |
142 | } | 163 | } |
diff --git a/server/models/video/video-abuse.ts b/server/models/video/video-abuse.ts index 182971c4e..cc7078ae7 100644 --- a/server/models/video/video-abuse.ts +++ b/server/models/video/video-abuse.ts | |||
@@ -1,7 +1,8 @@ | |||
1 | import { AllowNull, BelongsTo, Column, CreatedAt, ForeignKey, Is, Model, Table, UpdatedAt } from 'sequelize-typescript' | 1 | import { AfterCreate, AllowNull, BelongsTo, Column, CreatedAt, ForeignKey, Is, Model, Table, UpdatedAt } from 'sequelize-typescript' |
2 | import { VideoAbuseObject } from '../../../shared/models/activitypub/objects' | 2 | import { VideoAbuseObject } from '../../../shared/models/activitypub/objects' |
3 | import { isVideoAbuseReasonValid } from '../../helpers/custom-validators/videos' | 3 | import { isVideoAbuseReasonValid } from '../../helpers/custom-validators/videos' |
4 | import { CONFIG } from '../../initializers' | 4 | import { CONFIG } from '../../initializers' |
5 | import { Emailer } from '../../lib/emailer' | ||
5 | import { AccountModel } from '../account/account' | 6 | import { AccountModel } from '../account/account' |
6 | import { getSort, throwIfNotValid } from '../utils' | 7 | import { getSort, throwIfNotValid } from '../utils' |
7 | import { VideoModel } from './video' | 8 | import { VideoModel } from './video' |
@@ -54,6 +55,11 @@ export class VideoAbuseModel extends Model<VideoAbuseModel> { | |||
54 | }) | 55 | }) |
55 | Video: VideoModel | 56 | Video: VideoModel |
56 | 57 | ||
58 | @AfterCreate | ||
59 | static sendEmailNotification (instance: VideoAbuseModel) { | ||
60 | return Emailer.Instance.addVideoAbuseReport(instance.videoId) | ||
61 | } | ||
62 | |||
57 | static listForApi (start: number, count: number, sort: string) { | 63 | static listForApi (start: number, count: number, sort: string) { |
58 | const query = { | 64 | const query = { |
59 | offset: start, | 65 | offset: start, |