From ba75d268596bc7b289bacf1cc4cb53493d6ad444 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 1 Feb 2018 11:08:10 +0100 Subject: Send an email on video abuse report --- server/models/account/user.ts | 23 ++++++++++++++++++++++- server/models/video/video-abuse.ts | 8 +++++++- 2 files changed, 29 insertions(+), 2 deletions(-) (limited to 'server/models') 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 { Scopes, Table, UpdatedAt } from 'sequelize-typescript' import { hasUserRight, USER_ROLE_LABELS, UserRight } from '../../../shared' -import { User } from '../../../shared/models/users' +import { User, UserRole } from '../../../shared/models/users' import { isUserAutoPlayVideoValid, isUserDisplayNSFWValid, isUserPasswordValid, isUserRoleValid, isUserUsernameValid, isUserVideoQuotaValid @@ -137,6 +137,27 @@ export class UserModel extends Model { }) } + static listEmailsWithRight (right: UserRight) { + const roles = Object.keys(USER_ROLE_LABELS) + .map(k => parseInt(k, 10) as UserRole) + .filter(role => hasUserRight(role, right)) + + console.log(roles) + + const query = { + attribute: [ 'email' ], + where: { + role: { + [Sequelize.Op.in]: roles + } + } + } + + return UserModel.unscoped() + .findAll(query) + .then(u => u.map(u => u.email)) + } + static loadById (id: number) { return UserModel.findById(id) } 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 @@ -import { AllowNull, BelongsTo, Column, CreatedAt, ForeignKey, Is, Model, Table, UpdatedAt } from 'sequelize-typescript' +import { AfterCreate, AllowNull, BelongsTo, Column, CreatedAt, ForeignKey, Is, Model, Table, UpdatedAt } from 'sequelize-typescript' import { VideoAbuseObject } from '../../../shared/models/activitypub/objects' import { isVideoAbuseReasonValid } from '../../helpers/custom-validators/videos' import { CONFIG } from '../../initializers' +import { Emailer } from '../../lib/emailer' import { AccountModel } from '../account/account' import { getSort, throwIfNotValid } from '../utils' import { VideoModel } from './video' @@ -54,6 +55,11 @@ export class VideoAbuseModel extends Model { }) Video: VideoModel + @AfterCreate + static sendEmailNotification (instance: VideoAbuseModel) { + return Emailer.Instance.addVideoAbuseReport(instance.videoId) + } + static listForApi (start: number, count: number, sort: string) { const query = { offset: start, -- cgit v1.2.3