Add user adminFlags

pull/1773/head
Chocobozzz 2019-04-15 10:49:46 +02:00
parent 31b48aad47
commit 1eddc9a74f
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
65 changed files with 982 additions and 591 deletions

View File

@ -8,6 +8,7 @@ import { FormValidatorService } from '@app/shared/forms/form-validators/form-val
import { UserValidatorsService } from '@app/shared/forms/form-validators/user-validators.service'
import { ConfigService } from '@app/+admin/config/shared/config.service'
import { UserService } from '@app/shared'
import { UserAdminFlag } from '@shared/models/users/user-flag.model'
@Component({
selector: 'my-user-create',
@ -45,7 +46,8 @@ export class UserCreateComponent extends UserEdit implements OnInit {
password: this.userValidatorsService.USER_PASSWORD,
role: this.userValidatorsService.USER_ROLE,
videoQuota: this.userValidatorsService.USER_VIDEO_QUOTA,
videoQuotaDaily: this.userValidatorsService.USER_VIDEO_QUOTA_DAILY
videoQuotaDaily: this.userValidatorsService.USER_VIDEO_QUOTA_DAILY,
byPassAutoBlacklist: null
}, defaultValues)
}
@ -54,8 +56,11 @@ export class UserCreateComponent extends UserEdit implements OnInit {
const userCreate: UserCreate = this.form.value
userCreate.adminFlags = this.buildAdminFlags(this.form.value)
// A select in HTML is always mapped as a string, we convert it to number
userCreate.videoQuota = parseInt(this.form.value['videoQuota'], 10)
userCreate.videoQuotaDaily = parseInt(this.form.value['videoQuotaDaily'], 10)
this.userService.addUser(userCreate).subscribe(
() => {

View File

@ -79,6 +79,13 @@
</div>
</div>
<div class="form-group">
<my-peertube-checkbox
inputName="byPassAutoBlacklist" formControlName="byPassAutoBlacklist"
i18n-labelText labelText="Bypass video auto blacklist"
></my-peertube-checkbox>
</div>
<input type="submit" value="{{ getFormButtonTitle() }}" [disabled]="!form.valid">
</form>

View File

@ -2,6 +2,7 @@ import { ServerService } from '../../../core'
import { FormReactive } from '../../../shared'
import { USER_ROLE_LABELS, VideoResolution } from '../../../../../../shared'
import { ConfigService } from '@app/+admin/config/shared/config.service'
import { UserAdminFlag } from '@shared/models/users/user-flag.model'
export abstract class UserEdit extends FormReactive {
videoQuotaOptions: { value: string, label: string }[] = []
@ -42,6 +43,10 @@ export abstract class UserEdit extends FormReactive {
return
}
protected buildAdminFlags (formValue: any) {
return formValue.byPassAutoBlacklist ? UserAdminFlag.BY_PASS_VIDEO_AUTO_BLACKLIST : UserAdminFlag.NONE
}
protected buildQuotaOptions () {
// These are used by a HTML select, so convert key into strings
this.videoQuotaOptions = this.configService

View File

@ -10,6 +10,7 @@ import { FormValidatorService } from '@app/shared/forms/form-validators/form-val
import { UserValidatorsService } from '@app/shared/forms/form-validators/user-validators.service'
import { ConfigService } from '@app/+admin/config/shared/config.service'
import { UserService } from '@app/shared'
import { UserAdminFlag } from '@shared/models/users/user-flag.model'
@Component({
selector: 'my-user-update',
@ -46,7 +47,8 @@ export class UserUpdateComponent extends UserEdit implements OnInit, OnDestroy {
email: this.userValidatorsService.USER_EMAIL,
role: this.userValidatorsService.USER_ROLE,
videoQuota: this.userValidatorsService.USER_VIDEO_QUOTA,
videoQuotaDaily: this.userValidatorsService.USER_VIDEO_QUOTA_DAILY
videoQuotaDaily: this.userValidatorsService.USER_VIDEO_QUOTA_DAILY,
byPassAutoBlacklist: null
}, defaultValues)
this.paramsSub = this.route.params.subscribe(routeParams => {
@ -67,6 +69,7 @@ export class UserUpdateComponent extends UserEdit implements OnInit, OnDestroy {
this.error = undefined
const userUpdate: UserUpdate = this.form.value
userUpdate.adminFlags = this.buildAdminFlags(this.form.value)
// A select in HTML is always mapped as a string, we convert it to number
userUpdate.videoQuota = parseInt(this.form.value['videoQuota'], 10)
@ -111,7 +114,8 @@ export class UserUpdateComponent extends UserEdit implements OnInit, OnDestroy {
email: userJson.email,
role: userJson.role,
videoQuota: userJson.videoQuota,
videoQuotaDaily: userJson.videoQuotaDaily
videoQuotaDaily: userJson.videoQuotaDaily,
byPassAutoBlacklist: userJson.adminFlags & UserAdminFlag.BY_PASS_VIDEO_AUTO_BLACKLIST
})
}
}

View File

@ -107,7 +107,7 @@
<my-global-icon iconName="users"></my-global-icon>
<div class="message">
Your instance has <a (click)="markAsRead(notification)" [routerLink]="notification.instanceFollowUrl">a new follower</a>
Your instance has <a (click)="markAsRead(notification)" [routerLink]="notification.instanceFollowUrl">a new follower</a> ({{ notification.actorFollow.follower.host }})
<ng-container *ngIf="notification.actorFollow.state === 'pending'"> awaiting your approval</ng-container>
</div>
</ng-container>

View File

@ -2,15 +2,18 @@ import { hasUserRight, User as UserServerModel, UserNotificationSetting, UserRig
import { NSFWPolicyType } from '../../../../../shared/models/videos/nsfw-policy.type'
import { Account } from '@app/shared/account/account.model'
import { Avatar } from '../../../../../shared/models/avatars/avatar.model'
import { UserAdminFlag } from '@shared/models/users/user-flag.model'
export class User implements UserServerModel {
id: number
username: string
email: string
emailVerified: boolean
role: UserRole
nsfwPolicy: NSFWPolicyType
role: UserRole
roleLabel: string
webTorrentEnabled: boolean
autoPlayVideo: boolean
videosHistoryEnabled: boolean
@ -21,6 +24,8 @@ export class User implements UserServerModel {
videoChannels: VideoChannel[]
createdAt: Date
adminFlags?: UserAdminFlag
blocked: boolean
blockedReason?: string
@ -30,6 +35,7 @@ export class User implements UserServerModel {
this.id = hash.id
this.username = hash.username
this.email = hash.email
this.role = hash.role
this.videoChannels = hash.videoChannels
@ -40,6 +46,9 @@ export class User implements UserServerModel {
this.videosHistoryEnabled = hash.videosHistoryEnabled
this.autoPlayVideo = hash.autoPlayVideo
this.createdAt = hash.createdAt
this.adminFlags = hash.adminFlags
this.blocked = hash.blocked
this.blockedReason = hash.blockedReason

View File

@ -255,6 +255,8 @@ async function startApplication () {
// Make server listening
server.listen(port, hostname, () => {
logger.debug('CONFIG', { CONFIG })
logger.info('Server listening on %s:%d', hostname, port)
logger.info('Web server: %s', WEBSERVER.URL)
})

View File

@ -45,6 +45,7 @@ import { Notifier } from '../../../lib/notifier'
import { mySubscriptionsRouter } from './my-subscriptions'
import { CONFIG } from '../../../initializers/config'
import { sequelizeTypescript } from '../../../initializers/database'
import { UserAdminFlag } from '../../../../shared/models/users/user-flag.model'
const auditLogger = auditLoggerFactory('users')
@ -175,7 +176,8 @@ async function createUser (req: express.Request, res: express.Response) {
autoPlayVideo: true,
role: body.role,
videoQuota: body.videoQuota,
videoQuotaDaily: body.videoQuotaDaily
videoQuotaDaily: body.videoQuotaDaily,
adminFlags: body.adminFlags || UserAdminFlag.NONE
})
const { user, account } = await createUserAccountAndChannelAndPlaylist(userToCreate)
@ -241,7 +243,7 @@ async function blockUser (req: express.Request, res: express.Response) {
}
function getUser (req: express.Request, res: express.Response) {
return res.json(res.locals.user.toFormattedJSON())
return res.json(res.locals.user.toFormattedJSON({ withAdminFlags: true }))
}
async function autocompleteUsers (req: express.Request, res: express.Response) {
@ -253,7 +255,7 @@ async function autocompleteUsers (req: express.Request, res: express.Response) {
async function listUsers (req: express.Request, res: express.Response) {
const resultList = await UserModel.listForApi(req.query.start, req.query.count, req.query.sort, req.query.search)
return res.json(getFormattedObjects(resultList.data, resultList.total))
return res.json(getFormattedObjects(resultList.data, resultList.total, { withAdminFlags: true }))
}
async function removeUser (req: express.Request, res: express.Response) {
@ -278,6 +280,7 @@ async function updateUser (req: express.Request, res: express.Response) {
if (body.videoQuota !== undefined) userToUpdate.videoQuota = body.videoQuota
if (body.videoQuotaDaily !== undefined) userToUpdate.videoQuotaDaily = body.videoQuotaDaily
if (body.role !== undefined) userToUpdate.role = body.role
if (body.adminFlags !== undefined) userToUpdate.adminFlags = body.adminFlags
const user = await userToUpdate.save()

View File

@ -129,7 +129,7 @@ async function getUserInformation (req: express.Request, res: express.Response)
// We did not load channels in res.locals.user
const user = await UserModel.loadByUsernameAndPopulateChannels(res.locals.oauth.token.user.username)
return res.json(user.toFormattedJSON())
return res.json(user.toFormattedJSON({}))
}
async function getUserVideoQuotaUsed (req: express.Request, res: express.Response) {
@ -164,7 +164,7 @@ async function deleteMe (req: express.Request, res: express.Response) {
await user.destroy()
auditLogger.delete(getAuditIdFromRes(res), new UserAuditView(user.toFormattedJSON()))
auditLogger.delete(getAuditIdFromRes(res), new UserAuditView(user.toFormattedJSON({})))
return res.sendStatus(204)
}
@ -173,7 +173,7 @@ async function updateMe (req: express.Request, res: express.Response) {
const body: UserUpdateMe = req.body
const user = res.locals.oauth.token.user
const oldUserAuditView = new UserAuditView(user.toFormattedJSON())
const oldUserAuditView = new UserAuditView(user.toFormattedJSON({}))
if (body.password !== undefined) user.password = body.password
if (body.email !== undefined) user.email = body.email
@ -193,7 +193,7 @@ async function updateMe (req: express.Request, res: express.Response) {
await sendUpdateActor(userAccount, t)
auditLogger.update(getAuditIdFromRes(res), new UserAuditView(user.toFormattedJSON()), oldUserAuditView)
auditLogger.update(getAuditIdFromRes(res), new UserAuditView(user.toFormattedJSON({})), oldUserAuditView)
})
return res.sendStatus(204)
@ -202,13 +202,13 @@ async function updateMe (req: express.Request, res: express.Response) {
async function updateMyAvatar (req: express.Request, res: express.Response) {
const avatarPhysicalFile = req.files[ 'avatarfile' ][ 0 ]
const user = res.locals.oauth.token.user
const oldUserAuditView = new UserAuditView(user.toFormattedJSON())
const oldUserAuditView = new UserAuditView(user.toFormattedJSON({}))
const userAccount = await AccountModel.load(user.Account.id)
const avatar = await updateActorAvatarFile(avatarPhysicalFile, userAccount)
auditLogger.update(getAuditIdFromRes(res), new UserAuditView(user.toFormattedJSON()), oldUserAuditView)
auditLogger.update(getAuditIdFromRes(res), new UserAuditView(user.toFormattedJSON({})), oldUserAuditView)
return res.json({ avatar: avatar.toFormattedJSON() })
}

View File

@ -1,13 +1,77 @@
import * as AsyncLRU from 'async-lru'
import * as jsonld from 'jsonld'
import * as jsig from 'jsonld-signatures'
import { logger } from './logger'
const CACHE = {
'https://w3id.org/security/v1': {
'@context': {
'id': '@id',
'type': '@type',
'dc': 'http://purl.org/dc/terms/',
'sec': 'https://w3id.org/security#',
'xsd': 'http://www.w3.org/2001/XMLSchema#',
'EcdsaKoblitzSignature2016': 'sec:EcdsaKoblitzSignature2016',
'Ed25519Signature2018': 'sec:Ed25519Signature2018',
'EncryptedMessage': 'sec:EncryptedMessage',
'GraphSignature2012': 'sec:GraphSignature2012',
'LinkedDataSignature2015': 'sec:LinkedDataSignature2015',
'LinkedDataSignature2016': 'sec:LinkedDataSignature2016',
'CryptographicKey': 'sec:Key',
'authenticationTag': 'sec:authenticationTag',
'canonicalizationAlgorithm': 'sec:canonicalizationAlgorithm',
'cipherAlgorithm': 'sec:cipherAlgorithm',
'cipherData': 'sec:cipherData',
'cipherKey': 'sec:cipherKey',
'created': { '@id': 'dc:created', '@type': 'xsd:dateTime' },
'creator': { '@id': 'dc:creator', '@type': '@id' },
'digestAlgorithm': 'sec:digestAlgorithm',
'digestValue': 'sec:digestValue',
'domain': 'sec:domain',
'encryptionKey': 'sec:encryptionKey',
'expiration': { '@id': 'sec:expiration', '@type': 'xsd:dateTime' },
'expires': { '@id': 'sec:expiration', '@type': 'xsd:dateTime' },
'initializationVector': 'sec:initializationVector',
'iterationCount': 'sec:iterationCount',
'nonce': 'sec:nonce',
'normalizationAlgorithm': 'sec:normalizationAlgorithm',
'owner': { '@id': 'sec:owner', '@type': '@id' },
'password': 'sec:password',
'privateKey': { '@id': 'sec:privateKey', '@type': '@id' },
'privateKeyPem': 'sec:privateKeyPem',
'publicKey': { '@id': 'sec:publicKey', '@type': '@id' },
'publicKeyBase58': 'sec:publicKeyBase58',
'publicKeyPem': 'sec:publicKeyPem',
'publicKeyWif': 'sec:publicKeyWif',
'publicKeyService': { '@id': 'sec:publicKeyService', '@type': '@id' },
'revoked': { '@id': 'sec:revoked', '@type': 'xsd:dateTime' },
'salt': 'sec:salt',
'signature': 'sec:signature',
'signatureAlgorithm': 'sec:signingAlgorithm',
'signatureValue': 'sec:signatureValue'
}
}
}
const nodeDocumentLoader = jsonld.documentLoaders.node()
const lru = new AsyncLRU({
max: 10,
load: (key, cb) => {
nodeDocumentLoader(key, cb)
load: (url, cb) => {
if (CACHE[ url ] !== undefined) {
logger.debug('Using cache for JSON-LD %s.', url)
return cb(null, {
contextUrl: null,
document: CACHE[ url ],
documentUrl: url
})
}
nodeDocumentLoader(url, cb)
}
})

View File

@ -1,9 +1,10 @@
import 'express-validator'
import * as validator from 'validator'
import { UserRole } from '../../../shared'
import { UserNotificationSettingValue, UserRole } from '../../../shared'
import { CONSTRAINTS_FIELDS, NSFW_POLICY_TYPES } from '../../initializers/constants'
import { exists, isFileValid, isBooleanValid } from './misc'
import { values } from 'lodash'
import { UserAdminFlag } from '../../../shared/models/users/user-flag.model'
const USERS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.USERS
@ -54,6 +55,10 @@ function isUserAutoPlayVideoValid (value: any) {
return isBooleanValid(value)
}
function isUserAdminFlagsValid (value: any) {
return exists(value) && validator.isInt('' + value)
}
function isUserBlockedValid (value: any) {
return isBooleanValid(value)
}
@ -85,6 +90,7 @@ export {
isUserVideoQuotaValid,
isUserVideoQuotaDailyValid,
isUserUsernameValid,
isUserAdminFlagsValid,
isUserEmailVerifiedValid,
isUserNSFWPolicyValid,
isUserWebTorrentEnabledValid,

View File

@ -14,7 +14,7 @@ import { CONFIG, registerConfigChangedHandler } from './config'
// ---------------------------------------------------------------------------
const LAST_MIGRATION_VERSION = 360
const LAST_MIGRATION_VERSION = 365
// ---------------------------------------------------------------------------

View File

@ -0,0 +1,40 @@
import * as Sequelize from 'sequelize'
async function up (utils: {
transaction: Sequelize.Transaction,
queryInterface: Sequelize.QueryInterface,
sequelize: Sequelize.Sequelize,
db: any
}): Promise<void> {
{
const data = {
type: Sequelize.INTEGER,
defaultValue: null,
allowNull: true
}
await utils.queryInterface.addColumn('user', 'adminFlags', data)
}
{
const query = 'UPDATE "user" SET "adminFlags" = 0'
await utils.sequelize.query(query)
}
{
const data = {
type: Sequelize.INTEGER,
defaultValue: null,
allowNull: false
}
await utils.queryInterface.changeColumn('user', 'adminFlags', data)
}
}
function down (options) {
throw new Error('Not implemented.')
}
export {
up,
down
}

View File

@ -1,15 +1,16 @@
import * as sequelize from 'sequelize'
import { CONFIG } from '../initializers/config'
import { VideoBlacklistType, UserRight } from '../../shared/models'
import { UserRight, VideoBlacklistType } from '../../shared/models'
import { VideoBlacklistModel } from '../models/video/video-blacklist'
import { UserModel } from '../models/account/user'
import { VideoModel } from '../models/video/video'
import { logger } from '../helpers/logger'
import { UserAdminFlag } from '../../shared/models/users/user-flag.model'
async function autoBlacklistVideoIfNeeded (video: VideoModel, user: UserModel, transaction: sequelize.Transaction) {
if (!CONFIG.AUTO_BLACKLIST.VIDEOS.OF_USERS.ENABLED) return false
if (user.hasRight(UserRight.MANAGE_VIDEO_BLACKLIST)) return false
if (user.hasRight(UserRight.MANAGE_VIDEO_BLACKLIST) || user.hasAdminFlag(UserAdminFlag.BY_PASS_VIDEO_AUTO_BLACKLIST)) return false
const sequelizeOptions = { transaction }
const videoBlacklistToCreate = {
@ -19,6 +20,7 @@ async function autoBlacklistVideoIfNeeded (video: VideoModel, user: UserModel, t
type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED
}
await VideoBlacklistModel.create(videoBlacklistToCreate, sequelizeOptions)
logger.info('Video %s auto-blacklisted.', video.uuid)
return true

View File

@ -5,6 +5,7 @@ import { body, param } from 'express-validator/check'
import { omit } from 'lodash'
import { isIdOrUUIDValid } from '../../helpers/custom-validators/misc'
import {
isUserAdminFlagsValid,
isUserAutoPlayVideoValid,
isUserBlockedReasonValid,
isUserDescriptionValid,
@ -32,6 +33,7 @@ const usersAddValidator = [
body('videoQuota').custom(isUserVideoQuotaValid).withMessage('Should have a valid user quota'),
body('videoQuotaDaily').custom(isUserVideoQuotaDailyValid).withMessage('Should have a valid daily user quota'),
body('role').custom(isUserRoleValid).withMessage('Should have a valid role'),
body('adminFlags').optional().custom(isUserAdminFlagsValid).withMessage('Should have a valid admin flags'),
async (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking usersAdd parameters', { parameters: omit(req.body, 'password') })
@ -120,6 +122,7 @@ const usersUpdateValidator = [
body('videoQuota').optional().custom(isUserVideoQuotaValid).withMessage('Should have a valid user quota'),
body('videoQuotaDaily').optional().custom(isUserVideoQuotaDailyValid).withMessage('Should have a valid daily user quota'),
body('role').optional().custom(isUserRoleValid).withMessage('Should have a valid role'),
body('adminFlags').optional().custom(isUserAdminFlagsValid).withMessage('Should have a valid admin flags'),
async (req: express.Request, res: express.Response, next: express.NextFunction) => {
logger.debug('Checking usersUpdate parameters', { parameters: req.body })

View File

@ -22,6 +22,7 @@ import {
import { hasUserRight, USER_ROLE_LABELS, UserRight } from '../../../shared'
import { User, UserRole } from '../../../shared/models/users'
import {
isUserAdminFlagsValid,
isUserAutoPlayVideoValid,
isUserBlockedReasonValid,
isUserBlockedValid,
@ -49,6 +50,7 @@ import { VideoModel } from '../video/video'
import { ActorModel } from '../activitypub/actor'
import { ActorFollowModel } from '../activitypub/actor-follow'
import { VideoImportModel } from '../video/video-import'
import { UserAdminFlag } from '../../../shared/models/users/user-flag.model'
enum ScopeNames {
WITH_VIDEO_CHANNEL = 'WITH_VIDEO_CHANNEL'
@ -140,6 +142,12 @@ export class UserModel extends Model<UserModel> {
@Column
autoPlayVideo: boolean
@AllowNull(false)
@Default(UserAdminFlag.NONE)
@Is('UserAdminFlags', value => throwIfNotValid(value, isUserAdminFlagsValid, 'user admin flags'))
@Column
adminFlags?: UserAdminFlag
@AllowNull(false)
@Default(false)
@Is('UserBlocked', value => throwIfNotValid(value, isUserBlockedValid, 'blocked boolean'))
@ -516,11 +524,15 @@ export class UserModel extends Model<UserModel> {
return hasUserRight(this.role, right)
}
hasAdminFlag (flag: UserAdminFlag) {
return this.adminFlags & flag
}
isPasswordMatch (password: string) {
return comparePassword(password, this.password)
}
toFormattedJSON (): User {
toFormattedJSON (parameters: { withAdminFlags?: boolean } = {}): User {
const videoQuotaUsed = this.get('videoQuotaUsed')
const videoQuotaUsedDaily = this.get('videoQuotaUsedDaily')
@ -551,6 +563,10 @@ export class UserModel extends Model<UserModel> {
: undefined
}
if (parameters.withAdminFlags) {
Object.assign(json, { adminFlags: this.adminFlags })
}
if (Array.isArray(this.Account.VideoChannels) === true) {
json.videoChannels = this.Account.VideoChannels
.map(c => c.toFormattedJSON())

View File

@ -38,7 +38,7 @@ describe('Test ActivityPub fetcher', function () {
const user = { username: 'user1', password: 'password' }
for (const server of servers) {
await createUser(server.url, server.accessToken, user.username, user.password)
await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
}
const userAccessToken = await userLogin(servers[0], user)

View File

@ -36,7 +36,7 @@ describe('Test blocklist API validators', function () {
server = servers[0]
const user = { username: 'user1', password: 'password' }
await createUser(server.url, server.accessToken, user.username, user.password)
await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
userAccessToken = await userLogin(server, user)

View File

@ -110,7 +110,7 @@ describe('Test config API validators', function () {
username: 'user1',
password: 'password'
}
await createUser(server.url, server.accessToken, user.username, user.password)
await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
userAccessToken = await userLogin(server, user)
})

View File

@ -33,7 +33,7 @@ describe('Test debug API validators', function () {
username: 'user1',
password: 'my super password'
}
await createUser(server.url, server.accessToken, user.username, user.password)
await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
userAccessToken = await userLogin(server, user)
})

View File

@ -35,7 +35,7 @@ describe('Test server follows API validators', function () {
password: 'password'
}
await createUser(server.url, server.accessToken, user.username, user.password)
await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
userAccessToken = await userLogin(server, user)
})

View File

@ -38,7 +38,7 @@ describe('Test jobs API validators', function () {
username: 'user1',
password: 'my super password'
}
await createUser(server.url, server.accessToken, user.username, user.password)
await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
userAccessToken = await userLogin(server, user)
})

View File

@ -33,7 +33,7 @@ describe('Test logs API validators', function () {
username: 'user1',
password: 'my super password'
}
await createUser(server.url, server.accessToken, user.username, user.password)
await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
userAccessToken = await userLogin(server, user)
})

View File

@ -34,7 +34,7 @@ describe('Test server redundancy API validators', function () {
password: 'password'
}
await createUser(servers[0].url, servers[0].accessToken, user.username, user.password)
await createUser({ url: servers[ 0 ].url, accessToken: servers[ 0 ].accessToken, username: user.username, password: user.password })
userAccessToken = await userLogin(servers[0], user)
})

View File

@ -42,7 +42,7 @@ describe('Test user subscriptions API validators', function () {
username: 'user1',
password: 'my super password'
}
await createUser(server.url, server.accessToken, user.username, user.password)
await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
userAccessToken = await userLogin(server, user)
})

View File

@ -19,6 +19,7 @@ import { getMagnetURI, getMyVideoImports, getYoutubeVideoUrl, importVideo } from
import { VideoPrivacy } from '../../../../shared/models/videos'
import { waitJobs } from '../../../../shared/utils/server/jobs'
import { expect } from 'chai'
import { UserAdminFlag } from '../../../../shared/models/users/user-flag.model'
describe('Test users API validators', function () {
const path = '/api/v1/users/'
@ -47,7 +48,13 @@ describe('Test users API validators', function () {
await setAccessTokensToServers([ server ])
const videoQuota = 42000000
await createUser(server.url, server.accessToken, user.username, user.password, videoQuota)
await createUser({
url: server.url,
accessToken: server.accessToken,
username: user.username,
password: user.password,
videoQuota: videoQuota
})
userAccessToken = await userLogin(server, user)
{
@ -99,7 +106,8 @@ describe('Test users API validators', function () {
password: 'my super password',
videoQuota: -1,
videoQuotaDaily: -1,
role: UserRole.USER
role: UserRole.USER,
adminFlags: UserAdminFlag.BY_PASS_VIDEO_AUTO_BLACKLIST
}
it('Should fail with a too small username', async function () {
@ -150,6 +158,12 @@ describe('Test users API validators', function () {
await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
})
it('Should fail with invalid admin flags', async function () {
const fields = immutableAssign(baseCorrectParams, { adminFlags: 'toto' })
await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
})
it('Should fail with an non authenticated user', async function () {
await makePostBodyRequest({
url: server.url,
@ -498,6 +512,12 @@ describe('Test users API validators', function () {
await makePutBodyRequest({ url: server.url, path: path + rootId, token: server.accessToken, fields })
})
it('Should fail with invalid admin flags', async function () {
const fields = { adminFlags: 'toto' }
await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
})
it('Should succeed with the correct params', async function () {
const fields = {
email: 'email@example.com',

View File

@ -41,7 +41,7 @@ describe('Test video abuses API validators', function () {
const username = 'user1'
const password = 'my super password'
await createUser(server.url, server.accessToken, username, password)
await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password })
userAccessToken = await userLogin(server, { username, password })
const res = await uploadVideo(server.url, server.accessToken, {})

View File

@ -8,7 +8,6 @@ import {
flushAndRunMultipleServers,
flushTests,
getBlacklistedVideosList,
getBlacklistedVideosListWithTypeFilter,
getVideo,
getVideoWithToken,
killallServers,
@ -49,14 +48,14 @@ describe('Test video blacklist API validators', function () {
{
const username = 'user1'
const password = 'my super password'
await createUser(servers[0].url, servers[0].accessToken, username, password)
await createUser({ url: servers[ 0 ].url, accessToken: servers[ 0 ].accessToken, username: username, password: password })
userAccessToken1 = await userLogin(servers[0], { username, password })
}
{
const username = 'user2'
const password = 'my super password'
await createUser(servers[0].url, servers[0].accessToken, username, password)
await createUser({ url: servers[ 0 ].url, accessToken: servers[ 0 ].accessToken, username: username, password: password })
userAccessToken2 = await userLogin(servers[0], { username, password })
}
@ -221,11 +220,11 @@ describe('Test video blacklist API validators', function () {
const basePath = '/api/v1/videos/blacklist/'
it('Should fail with a non authenticated user', async function () {
await getBlacklistedVideosList(servers[0].url, 'fake token', 401)
await getBlacklistedVideosList({ url: servers[0].url, token: 'fake token', specialStatus: 401 })
})
it('Should fail with a non admin user', async function () {
await getBlacklistedVideosList(servers[0].url, userAccessToken2, 403)
await getBlacklistedVideosList({ url: servers[0].url, token: userAccessToken2, specialStatus: 403 })
})
it('Should fail with a bad start pagination', async function () {
@ -241,11 +240,11 @@ describe('Test video blacklist API validators', function () {
})
it('Should fail with an invalid type', async function () {
await getBlacklistedVideosListWithTypeFilter(servers[0].url, servers[0].accessToken, 0, 400)
await getBlacklistedVideosList({ url: servers[0].url, token: servers[0].accessToken, type: 0, specialStatus: 400 })
})
it('Should succeed with the correct parameters', async function () {
await getBlacklistedVideosListWithTypeFilter(servers[0].url, servers[0].accessToken, VideoBlacklistType.MANUAL)
await getBlacklistedVideosList({ url: servers[0].url, token: servers[0].accessToken, type: VideoBlacklistType.MANUAL })
})
})

View File

@ -45,7 +45,7 @@ describe('Test video captions API validator', function () {
username: 'user1',
password: 'my super password'
}
await createUser(server.url, server.accessToken, user.username, user.password)
await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
userAccessToken = await userLogin(server, user)
}
})

View File

@ -53,7 +53,7 @@ describe('Test video channels API validator', function () {
}
{
await createUser(server.url, server.accessToken, user.username, user.password)
await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
accessTokenUser = await userLogin(server, user)
}
})

View File

@ -52,7 +52,7 @@ describe('Test video comments API validator', function () {
username: 'user1',
password: 'my super password'
}
await createUser(server.url, server.accessToken, user.username, user.password)
await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
userAccessToken = await userLogin(server, user)
}
})

View File

@ -46,7 +46,7 @@ describe('Test video imports API validator', function () {
const username = 'user1'
const password = 'my super password'
await createUser(server.url, server.accessToken, username, password)
await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password })
userAccessToken = await userLogin(server, { username, password })
{
@ -167,7 +167,7 @@ describe('Test video imports API validator', function () {
username: 'fake',
password: 'fake_password'
}
await createUser(server.url, server.accessToken, user.username, user.password)
await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
const accessTokenUser = await userLogin(server, user)
const res = await getMyUserInformation(server.url, accessTokenUser)

View File

@ -56,18 +56,20 @@ describe('Test videos filters', function () {
await setDefaultVideoChannel([ server ])
const user = { username: 'user1', password: 'my super password' }
await createUser(server.url, server.accessToken, user.username, user.password)
await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
userAccessToken = await userLogin(server, user)
const moderator = { username: 'moderator', password: 'my super password' }
await createUser(
server.url,
server.accessToken,
moderator.username,
moderator.password,
undefined,
undefined,
UserRole.MODERATOR
{
url: server.url,
accessToken: server.accessToken,
username: moderator.username,
password: moderator.password,
videoQuota: undefined,
videoQuotaDaily: undefined,
role: UserRole.MODERATOR
}
)
moderatorAccessToken = await userLogin(server, moderator)

View File

@ -41,7 +41,7 @@ describe('Test videos API validator', function () {
const username = 'user1'
const password = 'my super password'
await createUser(server.url, server.accessToken, username, password)
await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password })
userAccessToken = await userLogin(server, { username, password })
{
@ -265,7 +265,7 @@ describe('Test videos API validator', function () {
username: 'fake',
password: 'fake_password'
}
await createUser(server.url, server.accessToken, user.username, user.password)
await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
const accessTokenUser = await userLogin(server, user)
const res = await getMyUserInformation(server.url, accessTokenUser)

View File

@ -133,7 +133,13 @@ describe('Test users notifications', function () {
username: 'user_1',
password: 'super password'
}
await createUser(servers[0].url, servers[0].accessToken, user.username, user.password, 10 * 1000 * 1000)
await createUser({
url: servers[ 0 ].url,
accessToken: servers[ 0 ].accessToken,
username: user.username,
password: user.password,
videoQuota: 10 * 1000 * 1000
})
userAccessToken = await userLogin(servers[0], user)
await updateMyNotificationSettings(servers[0].url, userAccessToken, allNotificationSettings)

View File

@ -40,7 +40,7 @@ describe('Test a ActivityPub video channels search', function () {
await setAccessTokensToServers(servers)
{
await createUser(servers[0].url, servers[0].accessToken, 'user1_server1', 'password')
await createUser({ url: servers[ 0 ].url, accessToken: servers[ 0 ].accessToken, username: 'user1_server1', password: 'password' })
const channel = {
name: 'channel1_server1',
displayName: 'Channel 1 server 1'
@ -50,7 +50,7 @@ describe('Test a ActivityPub video channels search', function () {
{
const user = { username: 'user1_server2', password: 'password' }
await createUser(servers[1].url, servers[1].accessToken, user.username, user.password)
await createUser({ url: servers[ 1 ].url, accessToken: servers[ 1 ].accessToken, username: user.username, password: user.password })
userServer2Token = await userLogin(servers[1], user)
const channel = {

View File

@ -54,7 +54,7 @@ describe('Test emails', function () {
await setAccessTokensToServers([ server ])
{
const res = await createUser(server.url, server.accessToken, user.username, user.password)
const res = await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
userId = res.body.user.id
userAccessToken = await userLogin(server, user)

View File

@ -47,7 +47,7 @@ describe('Test follow constraints', function () {
username: 'user1',
password: 'super_password'
}
await createUser(servers[0].url, servers[0].accessToken, user.username, user.password)
await createUser({ url: servers[ 0 ].url, accessToken: servers[ 0 ].accessToken, username: user.username, password: user.password })
userAccessToken = await userLogin(servers[0], user)
await doubleFollow(servers[0], servers[1])

View File

@ -263,7 +263,7 @@ describe('Test follows', function () {
{
const user = { username: 'captain', password: 'password' }
await createUser(servers[ 2 ].url, servers[ 2 ].accessToken, user.username, user.password)
await createUser({ url: servers[ 2 ].url, accessToken: servers[ 2 ].accessToken, username: user.username, password: user.password })
const userAccessToken = await userLogin(servers[ 2 ], user)
const resVideos = await getVideosList(servers[ 2 ].url)

View File

@ -37,7 +37,7 @@ describe('Test stats (excluding redundancy)', function () {
username: 'user1',
password: 'super_password'
}
await createUser(servers[0].url, servers[0].accessToken, user.username, user.password)
await createUser({ url: servers[ 0 ].url, accessToken: servers[ 0 ].accessToken, username: user.username, password: user.password })
const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { fixture: 'video_short.webm' })
const videoUUID = resVideo.body.video.uuid

View File

@ -86,7 +86,7 @@ describe('Test blocklist', function () {
{
const user = { username: 'user1', password: 'password' }
await createUser(servers[0].url, servers[0].accessToken, user.username, user.password)
await createUser({ url: servers[ 0 ].url, accessToken: servers[ 0 ].accessToken, username: user.username, password: user.password })
userToken1 = await userLogin(servers[0], user)
await uploadVideo(servers[0].url, userToken1, { name: 'video user 1' })
@ -94,14 +94,14 @@ describe('Test blocklist', function () {
{
const user = { username: 'moderator', password: 'password' }
await createUser(servers[0].url, servers[0].accessToken, user.username, user.password)
await createUser({ url: servers[ 0 ].url, accessToken: servers[ 0 ].accessToken, username: user.username, password: user.password })
userModeratorToken = await userLogin(servers[0], user)
}
{
const user = { username: 'user2', password: 'password' }
await createUser(servers[1].url, servers[1].accessToken, user.username, user.password)
await createUser({ url: servers[ 1 ].url, accessToken: servers[ 1 ].accessToken, username: user.username, password: user.password })
userToken2 = await userLogin(servers[1], user)
await uploadVideo(servers[1].url, userToken2, { name: 'video user 2' })

View File

@ -45,7 +45,7 @@ describe('Test users subscriptions', function () {
{
for (const server of servers) {
const user = { username: 'user' + server.serverNumber, password: 'password' }
await createUser(server.url, server.accessToken, user.username, user.password)
await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
const accessToken = await userLogin(server, user)
users.push({ accessToken })

View File

@ -57,7 +57,12 @@ describe('Test users with multiple servers', function () {
username: 'user1',
password: 'password'
}
const res = await createUser(servers[ 0 ].url, servers[ 0 ].accessToken, user.username, user.password)
const res = await createUser({
url: servers[ 0 ].url,
accessToken: servers[ 0 ].accessToken,
username: user.username,
password: user.password
})
userId = res.body.user.id
userAccessToken = await userLogin(servers[ 0 ], user)
}

File diff suppressed because it is too large Load Diff

View File

@ -164,7 +164,7 @@ describe('Test multiple servers', function () {
username: 'user1',
password: 'super_password'
}
await createUser(servers[1].url, servers[1].accessToken, user.username, user.password)
await createUser({ url: servers[ 1 ].url, accessToken: servers[ 1 ].accessToken, username: user.username, password: user.password })
const userAccessToken = await userLogin(servers[1], user)
const videoAttributes = {

View File

@ -5,29 +5,31 @@ import { orderBy } from 'lodash'
import 'mocha'
import {
addVideoToBlacklist,
createUser,
flushAndRunMultipleServers,
getBlacklistedVideosList,
getBlacklistedVideosListWithTypeFilter,
getMyVideos,
getSortedBlacklistedVideosList,
getVideosList,
killallServers,
removeVideoFromBlacklist,
reRunServer,
searchVideo,
ServerInfo,
setAccessTokensToServers,
updateVideo,
updateVideoBlacklist,
uploadVideo,
viewVideo
userLogin
} from '../../../../shared/utils/index'
import { doubleFollow } from '../../../../shared/utils/server/follows'
import { waitJobs } from '../../../../shared/utils/server/jobs'
import { VideoBlacklist, VideoBlacklistType } from '../../../../shared/models/videos'
import { UserAdminFlag } from '../../../../shared/models/users/user-flag.model'
import { UserRole } from '../../../../shared/models/users'
const expect = chai.expect
describe('Test video blacklist management', function () {
describe('Test video blacklist', function () {
let servers: ServerInfo[] = []
let videoId: number
@ -104,7 +106,7 @@ describe('Test video blacklist management', function () {
describe('When listing manually blacklisted videos', function () {
it('Should display all the blacklisted videos', async function () {
const res = await getBlacklistedVideosList(servers[0].url, servers[0].accessToken)
const res = await getBlacklistedVideosList({ url: servers[0].url, token: servers[0].accessToken })
expect(res.body.total).to.equal(2)
@ -119,7 +121,11 @@ describe('Test video blacklist management', function () {
})
it('Should display all the blacklisted videos when applying manual type filter', async function () {
const res = await getBlacklistedVideosListWithTypeFilter(servers[0].url, servers[0].accessToken, VideoBlacklistType.MANUAL)
const res = await getBlacklistedVideosList({
url: servers[ 0 ].url,
token: servers[ 0 ].accessToken,
type: VideoBlacklistType.MANUAL
})
expect(res.body.total).to.equal(2)
@ -129,7 +135,11 @@ describe('Test video blacklist management', function () {
})
it('Should display nothing when applying automatic type filter', async function () {
const res = await getBlacklistedVideosListWithTypeFilter(servers[0].url, servers[0].accessToken, VideoBlacklistType.AUTO_BEFORE_PUBLISHED) // tslint:disable:max-line-length
const res = await getBlacklistedVideosList({
url: servers[ 0 ].url,
token: servers[ 0 ].accessToken,
type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED
})
expect(res.body.total).to.equal(0)
@ -139,7 +149,7 @@ describe('Test video blacklist management', function () {
})
it('Should get the correct sort when sorting by descending id', async function () {
const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-id')
const res = await getBlacklistedVideosList({ url: servers[ 0 ].url, token: servers[ 0 ].accessToken, sort: '-id' })
expect(res.body.total).to.equal(2)
const blacklistedVideos = res.body.data
@ -152,7 +162,7 @@ describe('Test video blacklist management', function () {
})
it('Should get the correct sort when sorting by descending video name', async function () {
const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-name')
const res = await getBlacklistedVideosList({ url: servers[ 0 ].url, token: servers[ 0 ].accessToken, sort: '-name' })
expect(res.body.total).to.equal(2)
const blacklistedVideos = res.body.data
@ -165,7 +175,7 @@ describe('Test video blacklist management', function () {
})
it('Should get the correct sort when sorting by ascending creation date', async function () {
const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, 'createdAt')
const res = await getBlacklistedVideosList({ url: servers[ 0 ].url, token: servers[ 0 ].accessToken, sort: 'createdAt' })
expect(res.body.total).to.equal(2)
const blacklistedVideos = res.body.data
@ -182,7 +192,7 @@ describe('Test video blacklist management', function () {
it('Should change the reason', async function () {
await updateVideoBlacklist(servers[0].url, servers[0].accessToken, videoId, 'my super reason updated')
const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-name')
const res = await getBlacklistedVideosList({ url: servers[ 0 ].url, token: servers[ 0 ].accessToken, sort: '-name' })
const video = res.body.data.find(b => b.video.id === videoId)
expect(video.reason).to.equal('my super reason updated')
@ -218,7 +228,7 @@ describe('Test video blacklist management', function () {
it('Should remove a video from the blacklist on server 1', async function () {
// Get one video in the blacklist
const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-name')
const res = await getBlacklistedVideosList({ url: servers[ 0 ].url, token: servers[ 0 ].accessToken, sort: '-name' })
videoToRemove = res.body.data[0]
blacklist = res.body.data.slice(1)
@ -239,7 +249,7 @@ describe('Test video blacklist management', function () {
})
it('Should not have the ex-blacklisted video in videos blacklist list on server 1', async function () {
const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-name')
const res = await getBlacklistedVideosList({ url: servers[ 0 ].url, token: servers[ 0 ].accessToken, sort: '-name' })
expect(res.body.total).to.equal(1)
const videos = res.body.data
@ -313,7 +323,7 @@ describe('Test video blacklist management', function () {
})
it('Should have the correct video blacklist unfederate attribute', async function () {
const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, 'createdAt')
const res = await getBlacklistedVideosList({ url: servers[ 0 ].url, token: servers[ 0 ].accessToken, sort: 'createdAt' })
const blacklistedVideos: VideoBlacklist[] = res.body.data
const video3Blacklisted = blacklistedVideos.find(b => b.video.uuid === video3UUID)
@ -338,6 +348,83 @@ describe('Test video blacklist management', function () {
})
describe('When auto blacklist videos', function () {
let userWithoutFlag: string
let userWithFlag: string
before(async function () {
this.timeout(20000)
killallServers([ servers[0] ])
const config = {
'auto_blacklist': {
videos: {
'of_users': {
enabled: true
}
}
}
}
await reRunServer(servers[0], config)
{
const user = { username: 'user_without_flag', password: 'password' }
await createUser({
url: servers[ 0 ].url,
accessToken: servers[ 0 ].accessToken,
username: user.username,
adminFlags: UserAdminFlag.NONE,
password: user.password,
role: UserRole.USER
})
userWithoutFlag = await userLogin(servers[0], user)
}
{
const user = { username: 'user_with_flag', password: 'password' }
await createUser({
url: servers[ 0 ].url,
accessToken: servers[ 0 ].accessToken,
username: user.username,
adminFlags: UserAdminFlag.BY_PASS_VIDEO_AUTO_BLACKLIST,
password: user.password,
role: UserRole.USER
})
userWithFlag = await userLogin(servers[0], user)
}
await waitJobs(servers)
})
it('Should auto blacklist a video', async function () {
await uploadVideo(servers[0].url, userWithoutFlag, { name: 'blacklisted' })
const res = await getBlacklistedVideosList({
url: servers[ 0 ].url,
token: servers[ 0 ].accessToken,
type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED
})
expect(res.body.total).to.equal(1)
expect(res.body.data[0].video.name).to.equal('blacklisted')
})
it('Should not auto blacklist a video', async function () {
await uploadVideo(servers[0].url, userWithFlag, { name: 'not blacklisted' })
const res = await getBlacklistedVideosList({
url: servers[ 0 ].url,
token: servers[ 0 ].accessToken,
type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED
})
expect(res.body.total).to.equal(1)
})
})
after(async function () {
killallServers(servers)
})

View File

@ -46,8 +46,20 @@ describe('Test video change ownership - nominal', function () {
await setAccessTokensToServers(servers)
const videoQuota = 42000000
await createUser(servers[0].url, servers[0].accessToken, firstUser.username, firstUser.password, videoQuota)
await createUser(servers[0].url, servers[0].accessToken, secondUser.username, secondUser.password, videoQuota)
await createUser({
url: servers[ 0 ].url,
accessToken: servers[ 0 ].accessToken,
username: firstUser.username,
password: firstUser.password,
videoQuota: videoQuota
})
await createUser({
url: servers[ 0 ].url,
accessToken: servers[ 0 ].accessToken,
username: secondUser.username,
password: secondUser.password,
videoQuota: videoQuota
})
firstUserAccessToken = await userLogin(servers[0], firstUser)
secondUserAccessToken = await userLogin(servers[0], secondUser)
@ -219,8 +231,20 @@ describe('Test video change ownership - quota too small', function () {
const videoQuota = 42000000
const limitedVideoQuota = 10
await createUser(server.url, server.accessToken, firstUser.username, firstUser.password, videoQuota)
await createUser(server.url, server.accessToken, secondUser.username, secondUser.password, limitedVideoQuota)
await createUser({
url: server.url,
accessToken: server.accessToken,
username: firstUser.username,
password: firstUser.password,
videoQuota: videoQuota
})
await createUser({
url: server.url,
accessToken: server.accessToken,
username: secondUser.username,
password: secondUser.password,
videoQuota: limitedVideoQuota
})
firstUserAccessToken = await userLogin(server, firstUser)
secondUserAccessToken = await userLogin(server, secondUser)

View File

@ -270,7 +270,7 @@ describe('Test video channels', function () {
}
{
await createUser(servers[ 0 ].url, servers[ 0 ].accessToken, 'toto', 'password')
await createUser({ url: servers[ 0 ].url, accessToken: servers[ 0 ].accessToken, username: 'toto', password: 'password' })
const accessToken = await userLogin(servers[ 0 ], { username: 'toto', password: 'password' })
const res = await getMyUserInformation(servers[ 0 ].url, accessToken)

View File

@ -144,7 +144,7 @@ describe('Test video NSFW policy', function () {
it('Should create a user having the default nsfw policy', async function () {
const username = 'user1'
const password = 'my super password'
await createUser(server.url, server.accessToken, username, password)
await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password })
userAccessToken = await userLogin(server, { username, password })

View File

@ -815,7 +815,12 @@ describe('Test video playlists', function () {
this.timeout(30000)
const user = { username: 'user_1', password: 'password' }
const res = await createUser(servers[0].url, servers[0].accessToken, user.username, user.password)
const res = await createUser({
url: servers[ 0 ].url,
accessToken: servers[ 0 ].accessToken,
username: user.username,
password: user.password
})
const userId = res.body.user.id
const userAccessToken = await userLogin(servers[0], user)

View File

@ -78,7 +78,7 @@ describe('Test video privacy', function () {
username: 'hello',
password: 'super password'
}
await createUser(servers[0].url, servers[0].accessToken, user.username, user.password)
await createUser({ url: servers[ 0 ].url, accessToken: servers[ 0 ].accessToken, username: user.username, password: user.password })
const token = await userLogin(servers[0], user)
await getVideoWithToken(servers[0].url, token, privateVideoUUID, 403)

View File

@ -64,13 +64,15 @@ describe('Test videos filter validator', function () {
for (const server of servers) {
const moderator = { username: 'moderator', password: 'my super password' }
await createUser(
server.url,
server.accessToken,
moderator.username,
moderator.password,
undefined,
undefined,
UserRole.MODERATOR
{
url: server.url,
accessToken: server.accessToken,
username: moderator.username,
password: moderator.password,
videoQuota: undefined,
videoQuotaDaily: undefined,
role: UserRole.MODERATOR
}
)
server['moderatorAccessToken'] = await userLogin(server, moderator)

View File

@ -58,7 +58,7 @@ describe('Test videos history', function () {
username: 'user_1',
password: 'super password'
}
await createUser(server.url, server.accessToken, user.username, user.password)
await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
userAccessToken = await userLogin(server, user)
})

View File

@ -24,7 +24,7 @@ describe('Test CLI wrapper', function () {
server = await runServer(1)
await setAccessTokensToServers([ server ])
await createUser(server.url, server.accessToken, 'user_1', 'super password')
await createUser({ url: server.url, accessToken: server.accessToken, username: 'user_1', password: 'super password' })
})
it('Should display no selected instance', async function () {

View File

@ -22,7 +22,7 @@ describe('Test reset password scripts', function () {
server = await runServer(1)
await setAccessTokensToServers([ server ])
await createUser(server.url, server.accessToken, 'user_1', 'super password')
await createUser({ url: server.url, accessToken: server.accessToken, username: 'user_1', password: 'super password' })
})
it('Should change the user password from CLI', async function () {

View File

@ -50,7 +50,7 @@ describe('Test update host scripts', function () {
await uploadVideo(server.url, server.accessToken, videoAttributes)
// Create a user
await createUser(server.url, server.accessToken, 'toto', 'coucou')
await createUser({ url: server.url, accessToken: server.accessToken, username: 'toto', password: 'coucou' })
// Create channel
const videoChannel = {

View File

@ -50,7 +50,7 @@ describe('Test syndication feeds', () => {
{
const attr = { username: 'john', password: 'password' }
await createUser(servers[0].url, servers[0].accessToken, attr.username, attr.password)
await createUser({ url: servers[ 0 ].url, accessToken: servers[ 0 ].accessToken, username: attr.username, password: attr.password })
userAccessToken = await userLogin(servers[0], attr)
const res = await getMyUserInformation(servers[0].url, userAccessToken)

View File

@ -149,8 +149,8 @@ describe('Test misc endpoints', function () {
await addVideoChannel(server.url, server.accessToken, { name: 'channel1', displayName: 'channel 1' })
await addVideoChannel(server.url, server.accessToken, { name: 'channel2', displayName: 'channel 2' })
await createUser(server.url, server.accessToken, 'user1', 'password')
await createUser(server.url, server.accessToken, 'user2', 'password')
await createUser({ url: server.url, accessToken: server.accessToken, username: 'user1', password: 'password' })
await createUser({ url: server.url, accessToken: server.accessToken, username: 'user2', password: 'password' })
const res = await makeGetRequest({
url: server.url,

View File

@ -78,7 +78,7 @@ function createUserCustom (server: ServerInfo) {
const username = Date.now().toString() + getRandomInt(0, 100000)
console.log('Creating user %s.', username)
return createUser(server.url, server.accessToken, username, 'coucou')
return createUser({ url: server.url, accessToken: server.accessToken, username: username, password: 'coucou' })
}
function uploadCustom (server: ServerInfo) {

View File

@ -1,4 +1,5 @@
import { UserRole } from './user-role'
import { UserAdminFlag } from './user-flag.model'
export interface UserCreate {
username: string
@ -7,4 +8,5 @@ export interface UserCreate {
videoQuota: number
videoQuotaDaily: number
role: UserRole
adminFlags?: UserAdminFlag
}

View File

@ -0,0 +1,4 @@
export enum UserAdminFlag {
NONE = 0,
BY_PASS_VIDEO_AUTO_BLACKLIST = 1 << 0
}

View File

@ -1,4 +1,5 @@
import { UserRole } from './user-role'
import { UserAdminFlag } from './user-flag.model'
export interface UserUpdate {
password?: string
@ -7,4 +8,5 @@ export interface UserUpdate {
videoQuota?: number
videoQuotaDaily?: number
role?: UserRole
adminFlags?: UserAdminFlag
}

View File

@ -3,6 +3,7 @@ import { VideoChannel } from '../videos/channel/video-channel.model'
import { UserRole } from './user-role'
import { NSFWPolicyType } from '../videos/nsfw-policy.type'
import { UserNotificationSetting } from './user-notification-setting.model'
import { UserAdminFlag } from './user-flag.model'
export interface User {
id: number
@ -11,11 +12,15 @@ export interface User {
emailVerified: boolean
nsfwPolicy: NSFWPolicyType
adminFlags?: UserAdminFlag
autoPlayVideo: boolean
webTorrentEnabled: boolean
videosHistoryEnabled: boolean
role: UserRole
roleLabel: string
videoQuota: number
videoQuotaDaily: number
createdAt: Date

View File

@ -4,22 +4,37 @@ import { makePostBodyRequest, makePutBodyRequest, updateAvatarRequest } from '..
import { UserRole } from '../../index'
import { NSFWPolicyType } from '../../models/videos/nsfw-policy.type'
import { ServerInfo, userLogin } from '..'
import { UserAdminFlag } from '../../models/users/user-flag.model'
function createUser (
url: string,
type CreateUserArgs = { url: string,
accessToken: string,
username: string,
password: string,
videoQuota = 1000000,
videoQuotaDaily = -1,
role: UserRole = UserRole.USER,
specialStatus = 200
) {
videoQuota?: number,
videoQuotaDaily?: number,
role?: UserRole,
adminFlags?: UserAdminFlag,
specialStatus?: number
}
function createUser (parameters: CreateUserArgs) {
const {
url,
accessToken,
username,
adminFlags,
password = 'password',
videoQuota = 1000000,
videoQuotaDaily = -1,
role = UserRole.USER,
specialStatus = 200
} = parameters
const path = '/api/v1/users'
const body = {
username,
password,
role,
adminFlags,
email: username + '@example.com',
videoQuota,
videoQuotaDaily
@ -35,7 +50,7 @@ function createUser (
async function generateUserAccessToken (server: ServerInfo, username: string) {
const password = 'my super password'
await createUser(server.url, server.accessToken, username, password)
await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password })
return userLogin(server, { username, password })
}
@ -222,6 +237,7 @@ function updateUser (options: {
videoQuota?: number,
videoQuotaDaily?: number,
password?: string,
adminFlags?: UserAdminFlag,
role?: UserRole
}) {
const path = '/api/v1/users/' + options.userId
@ -233,6 +249,7 @@ function updateUser (options: {
if (options.videoQuota !== undefined && options.videoQuota !== null) toSend['videoQuota'] = options.videoQuota
if (options.videoQuotaDaily !== undefined && options.videoQuotaDaily !== null) toSend['videoQuotaDaily'] = options.videoQuotaDaily
if (options.role !== undefined && options.role !== null) toSend['role'] = options.role
if (options.adminFlags !== undefined && options.adminFlags !== null) toSend['adminFlags'] = options.adminFlags
return makePutBodyRequest({
url: options.url,

View File

@ -1,4 +1,6 @@
import * as request from 'supertest'
import { VideoBlacklistType } from '../../models/videos'
import { makeGetRequest } from '..'
function addVideoToBlacklist (
url: string,
@ -39,40 +41,25 @@ function removeVideoFromBlacklist (url: string, token: string, videoId: number |
.expect(specialStatus)
}
function getBlacklistedVideosList (url: string, token: string, specialStatus = 200) {
function getBlacklistedVideosList (parameters: {
url: string,
token: string,
sort?: string,
type?: VideoBlacklistType,
specialStatus?: number
}) {
let { url, token, sort, type, specialStatus = 200 } = parameters
const path = '/api/v1/videos/blacklist/'
return request(url)
.get(path)
.query({ sort: 'createdAt' })
.set('Accept', 'application/json')
.set('Authorization', 'Bearer ' + token)
.expect(specialStatus)
.expect('Content-Type', /json/)
}
const query = { sort, type }
function getBlacklistedVideosListWithTypeFilter (url: string, token: string, type: number, specialStatus = 200) {
const path = '/api/v1/videos/blacklist/'
return request(url)
.get(path)
.query({ sort: 'createdAt', type })
.set('Accept', 'application/json')
.set('Authorization', 'Bearer ' + token)
.expect(specialStatus)
.expect('Content-Type', /json/)
}
function getSortedBlacklistedVideosList (url: string, token: string, sort: string, specialStatus = 200) {
const path = '/api/v1/videos/blacklist/'
return request(url)
.get(path)
.query({ sort: sort })
.set('Accept', 'application/json')
.set('Authorization', 'Bearer ' + token)
.expect(specialStatus)
.expect('Content-Type', /json/)
return makeGetRequest({
url,
path,
query,
token,
statusCodeExpected: specialStatus
})
}
// ---------------------------------------------------------------------------
@ -81,7 +68,5 @@ export {
addVideoToBlacklist,
removeVideoFromBlacklist,
getBlacklistedVideosList,
getBlacklistedVideosListWithTypeFilter,
getSortedBlacklistedVideosList,
updateVideoBlacklist
}