1
0
Fork 0

Reorganize shared models

This commit is contained in:
Chocobozzz 2020-08-06 14:58:01 +02:00 committed by Chocobozzz
parent 583eb04b54
commit bd45d503e5
59 changed files with 155 additions and 144 deletions

View file

@ -5,12 +5,12 @@ import { Injectable } from '@angular/core'
import { ComponentPagination, RestExtractor, RestService } from '@app/core'
import { PluginService } from '@app/core/plugins/plugin.service'
import { I18n } from '@ngx-translate/i18n-polyfill'
import { peertubeTranslate } from '@shared/core-utils/i18n'
import {
InstallOrUpdatePlugin,
ManagePlugin,
PeerTubePlugin,
PeerTubePluginIndex,
peertubeTranslate,
PluginType,
RegisteredServerSettings,
ResultList

View file

@ -1,8 +1,9 @@
import { OnInit, Directive } from '@angular/core'
import { Directive, OnInit } from '@angular/core'
import { ConfigService } from '@app/+admin/config/shared/config.service'
import { AuthService, ScreenService, ServerService, User } from '@app/core'
import { FormReactive } from '@app/shared/shared-forms'
import { ServerConfig, USER_ROLE_LABELS, UserAdminFlag, UserRole, VideoResolution } from '@shared/models'
import { USER_ROLE_LABELS } from '@shared/core-utils/users'
import { ServerConfig, UserAdminFlag, UserRole, VideoResolution } from '@shared/models'
@Directive()
export abstract class UserEdit extends FormReactive implements OnInit {

View file

@ -5,7 +5,8 @@ import { Injectable } from '@angular/core'
import { RestExtractor, ServerService } from '@app/core'
import { immutableAssign } from '@app/helpers'
import { VideoService } from '@app/shared/shared-main'
import { peertubeTranslate, VideosOverview as VideosOverviewServer } from '@shared/models'
import { peertubeTranslate } from '@shared/core-utils/i18n'
import { VideosOverview as VideosOverviewServer } from '@shared/models'
import { environment } from '../../../../environments/environment'
import { VideosOverview } from './videos-overview.model'

View file

@ -13,7 +13,8 @@ import { InstanceConfigWarningModalComponent } from '@app/modal/instance-config-
import { WelcomeModalComponent } from '@app/modal/welcome-modal.component'
import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
import { I18n } from '@ngx-translate/i18n-polyfill'
import { BroadcastMessageLevel, getShortLocale, is18nPath, ServerConfig, UserRole } from '@shared/models'
import { getShortLocale, is18nPath } from '@shared/core-utils/i18n'
import { BroadcastMessageLevel, ServerConfig, UserRole } from '@shared/models'
import { MenuService } from './core/menu/menu.service'
import { POP_STATE_MODAL_DISMISS } from './helpers'
import { peertubeLocalStorage } from '@root-helpers/peertube-web-storage'

View file

@ -5,7 +5,7 @@ import { BrowserModule } from '@angular/platform-browser'
import { ServerService } from '@app/core'
import localeOc from '@app/helpers/locales/oc'
import { MetaLoader, MetaModule, MetaStaticLoader, PageTitlePositioning } from '@ngx-meta/core'
import { buildFileLocale, getCompleteLocale, isDefaultLocale } from '@shared/models'
import { buildFileLocale, getCompleteLocale, isDefaultLocale } from '@shared/core-utils/i18n'
import { AppRoutingModule } from './app-routing.module'
import { AppComponent } from './app.component'
import { CoreModule } from './core'

View file

@ -1,9 +1,9 @@
import { Observable, of } from 'rxjs'
import { map } from 'rxjs/operators'
import { User } from '@app/core/users/user.model'
import { peertubeLocalStorage } from '@root-helpers/peertube-web-storage'
import { peertubeLocalStorage } from '@app/helpers/peertube-web-storage'
import { hasUserRight } from '@shared/core-utils/users'
import {
hasUserRight,
MyUser as ServerMyUserModel,
MyUserSpecialPlaylist,
NSFWPolicyType,

View file

@ -9,15 +9,13 @@ import { RestExtractor } from '@app/core/rest'
import { ServerService } from '@app/core/server/server.service'
import { getDevLocale, importModule, isOnDevLocale } from '@app/helpers'
import { CustomModalComponent } from '@app/modal/custom-modal.component'
import { getCompleteLocale, isDefaultLocale, peertubeTranslate } from '@shared/core-utils/i18n'
import { getHookType, internalRunHook } from '@shared/core-utils/plugins/hooks'
import {
ClientHook,
ClientHookName,
clientHookObject,
ClientScript,
getCompleteLocale,
isDefaultLocale,
peertubeTranslate,
PluginClientScope,
PluginTranslation,
PluginType,

View file

@ -4,15 +4,8 @@ import { HttpClient } from '@angular/common/http'
import { Inject, Injectable, LOCALE_ID } from '@angular/core'
import { getDevLocale, isOnDevLocale, sortBy } from '@app/helpers'
import { peertubeLocalStorage } from '@root-helpers/peertube-web-storage'
import {
getCompleteLocale,
isDefaultLocale,
peertubeTranslate,
SearchTargetType,
ServerConfig,
ServerStats,
VideoConstant
} from '@shared/models'
import { getCompleteLocale, isDefaultLocale, peertubeTranslate } from '@shared/core-utils/i18n'
import { SearchTargetType, ServerConfig, ServerStats, VideoConstant } from '@shared/models'
import { environment } from '../../../environments/environment'
@Injectable()

View file

@ -1,7 +1,7 @@
import { Account } from '@app/shared/shared-main/account/account.model'
import { hasUserRight } from '@shared/core-utils/users'
import {
Avatar,
hasUserRight,
NSFWPolicyType,
User as UserServerModel,
UserAdminFlag,

View file

@ -1,7 +1,7 @@
import { Component, ElementRef, Inject, LOCALE_ID, ViewChild } from '@angular/core'
import { getDevLocale, isOnDevLocale, sortBy } from '@app/helpers'
import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
import { getCompleteLocale, getShortLocale, I18N_LOCALES } from '@shared/models'
import { getCompleteLocale, getShortLocale, I18N_LOCALES } from '@shared/core-utils/i18n'
@Component({
selector: 'my-language-chooser',

View file

@ -3,7 +3,8 @@ import { catchError, map } from 'rxjs/operators'
import { HttpClient } from '@angular/common/http'
import { Injectable } from '@angular/core'
import { MarkdownService, RestExtractor, ServerService } from '@app/core'
import { About, peertubeTranslate } from '@shared/models'
import { peertubeTranslate } from '@shared/core-utils/i18n'
import { About } from '@shared/models'
import { environment } from '../../../environments/environment'
@Injectable()

View file

@ -5,7 +5,8 @@ import { Injectable } from '@angular/core'
import { RestExtractor, ServerService } from '@app/core'
import { objectToFormData, sortBy } from '@app/helpers'
import { VideoService } from '@app/shared/shared-main/video'
import { peertubeTranslate, ResultList, VideoCaption } from '@shared/models'
import { peertubeTranslate } from '@shared/core-utils/i18n'
import { ResultList, VideoCaption } from '@shared/models'
import { VideoCaptionEdit } from './video-caption-edit.model'
@Injectable()

View file

@ -5,7 +5,8 @@ import { HttpClient, HttpParams } from '@angular/common/http'
import { Injectable } from '@angular/core'
import { RestExtractor, RestPagination, RestService, ServerService, UserService } from '@app/core'
import { objectToFormData } from '@app/helpers'
import { peertubeTranslate, ResultList, VideoImport, VideoImportCreate, VideoUpdate } from '@shared/models'
import { peertubeTranslate } from '@shared/core-utils/i18n'
import { ResultList, VideoImport, VideoImportCreate, VideoUpdate } from '@shared/models'
import { environment } from '../../../../environments/environment'
@Injectable()

View file

@ -1,9 +1,9 @@
import { AuthUser } from '@app/core'
import { User } from '@app/core/users/user.model'
import { durationToString, getAbsoluteAPIUrl, getAbsoluteEmbedUrl } from '@app/helpers'
import { peertubeTranslate } from '@shared/core-utils/i18n'
import {
Avatar,
peertubeTranslate,
ServerConfig,
UserRight,
Video as VideoServerModel,

View file

@ -6,7 +6,8 @@ import { Account } from '@app/shared/shared-main'
import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap/modal/modal-ref'
import { I18n } from '@ngx-translate/i18n-polyfill'
import { abusePredefinedReasonsMap, AbusePredefinedReasonsString } from '@shared/models'
import { abusePredefinedReasonsMap } from '@shared/core-utils/abuse'
import { AbusePredefinedReasonsString } from '@shared/models'
import { AbuseService } from '../abuse.service'
@Component({

View file

@ -6,7 +6,8 @@ import { VideoComment } from '@app/shared/shared-video-comment'
import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap/modal/modal-ref'
import { I18n } from '@ngx-translate/i18n-polyfill'
import { abusePredefinedReasonsMap, AbusePredefinedReasonsString } from '@shared/models'
import { abusePredefinedReasonsMap } from '@shared/core-utils/abuse'
import { AbusePredefinedReasonsString } from '@shared/models'
import { AbuseService } from '../abuse.service'
@Component({

View file

@ -7,7 +7,8 @@ import { AbuseValidatorsService, FormReactive, FormValidatorService } from '@app
import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap/modal/modal-ref'
import { I18n } from '@ngx-translate/i18n-polyfill'
import { abusePredefinedReasonsMap, AbusePredefinedReasonsString } from '@shared/models'
import { abusePredefinedReasonsMap } from '@shared/core-utils/abuse'
import { AbusePredefinedReasonsString } from '@shared/models'
import { Video } from '../../shared-main'
import { AbuseService } from '../abuse.service'

View file

@ -1,8 +1,8 @@
import { getAbsoluteAPIUrl } from '@app/helpers'
import { Actor } from '@app/shared/shared-main'
import { peertubeTranslate } from '@shared/core-utils/i18n'
import {
AccountSummary,
peertubeTranslate,
VideoChannelSummary,
VideoConstant,
VideoPlaylist as ServerVideoPlaylist,

View file

@ -19,7 +19,8 @@ import './videojs-components/settings-panel'
import './videojs-components/settings-panel-child'
import './videojs-components/theater-button'
import videojs from 'video.js'
import { isDefaultLocale, VideoFile } from '@shared/models'
import { VideoFile } from '@shared/models'
import { isDefaultLocale } from '@shared/core-utils/i18n'
import { RedundancyUrlManager } from './p2p-media-loader/redundancy-url-manager'
import { segmentUrlBuilderFactory } from './p2p-media-loader/segment-url-builder'
import { segmentValidatorFactory } from './p2p-media-loader/segment-validator'

View file

@ -1,4 +1,4 @@
import { getCompleteLocale, getShortLocale, is18nLocale, isDefaultLocale } from '@shared/models'
import { getCompleteLocale, getShortLocale, is18nLocale, isDefaultLocale } from '@shared/core-utils/i18n'
export class TranslationsManager {
private static videojsLocaleCache: { [ path: string ]: any } = {}

View file

@ -1,8 +1,8 @@
import './embed.scss'
import videojs from 'video.js'
import { objectToUrlEncoded, peertubeLocalStorage, PureAuthUser } from '@root-helpers/index'
import { peertubeTranslate } from '../../../../shared/core-utils/i18n'
import {
peertubeTranslate,
ResultList,
ServerConfig,
UserRefreshToken,

View file

@ -29,6 +29,7 @@ module.exports = function () {
'video.js$': path.resolve('node_modules/video.js/core.js'),
'@root-helpers': path.resolve('src/root-helpers'),
'@shared/models': path.resolve('../shared/models'),
'@shared/core-utils': path.resolve('../shared/core-utils')
}
},

View file

@ -1,9 +1,12 @@
import * as express from 'express'
import { logger } from '@server/helpers/logger'
import { createAccountAbuse, createVideoAbuse, createVideoCommentAbuse } from '@server/lib/moderation'
import { Notifier } from '@server/lib/notifier'
import { AbuseModel } from '@server/models/abuse/abuse'
import { AbuseMessageModel } from '@server/models/abuse/abuse-message'
import { getServerActor } from '@server/models/application/application'
import { AbuseCreate, abusePredefinedReasonsMap, AbuseState, UserRight } from '../../../shared'
import { abusePredefinedReasonsMap } from '@shared/core-utils/abuse'
import { AbuseCreate, AbuseState, UserRight } from '../../../shared'
import { getFormattedObjects } from '../../helpers/utils'
import { sequelizeTypescript } from '../../initializers/database'
import {
@ -25,8 +28,6 @@ import {
setDefaultSort
} from '../../middlewares'
import { AccountModel } from '../../models/account/account'
import { Notifier } from '@server/lib/notifier'
import { logger } from '@server/helpers/logger'
const abuseRouter = express.Router()

View file

@ -1,13 +1,13 @@
import { constants, promises as fs } from 'fs'
import * as express from 'express'
import { constants, promises as fs } from 'fs'
import { join } from 'path'
import { root } from '../helpers/core-utils'
import { ACCEPT_HEADERS, STATIC_MAX_AGE } from '../initializers/constants'
import { asyncMiddleware, embedCSP } from '../middlewares'
import { buildFileLocale, getCompleteLocale, is18nLocale, LOCALE_FILES } from '../../shared/models/i18n/i18n'
import { ClientHtml } from '../lib/client-html'
import { logger } from '../helpers/logger'
import { CONFIG } from '@server/initializers/config'
import { buildFileLocale, getCompleteLocale, is18nLocale, LOCALE_FILES } from '@shared/core-utils/i18n'
import { root } from '../helpers/core-utils'
import { logger } from '../helpers/logger'
import { ACCEPT_HEADERS, STATIC_MAX_AGE } from '../initializers/constants'
import { ClientHtml } from '../lib/client-html'
import { asyncMiddleware, embedCSP } from '../middlewares'
const clientsRouter = express.Router()

View file

@ -6,7 +6,7 @@ import { getPluginValidator, pluginStaticDirectoryValidator, getExternalAuthVali
import { serveThemeCSSValidator } from '../middlewares/validators/themes'
import { PluginType } from '../../shared/models/plugins/plugin.type'
import { isTestInstance } from '../helpers/core-utils'
import { getCompleteLocale, is18nLocale } from '../../shared/models/i18n'
import { getCompleteLocale, is18nLocale } from '../../shared/core-utils/i18n'
import { logger } from '@server/helpers/logger'
const sendFileOptions = {

View file

@ -1,5 +1,6 @@
import validator from 'validator'
import { AbuseFilter, abusePredefinedReasonsMap, AbusePredefinedReasonsString, AbuseVideoIs, AbuseCreate } from '@shared/models'
import { abusePredefinedReasonsMap } from '@shared/core-utils/abuse'
import { AbuseCreate, AbuseFilter, AbusePredefinedReasonsString, AbuseVideoIs } from '@shared/models'
import { ABUSE_STATES, CONSTRAINTS_FIELDS } from '../../initializers/constants'
import { exists, isArray } from './misc'

View file

@ -8,7 +8,8 @@ import { isUrlValid } from './activitypub/misc'
const PLUGINS_CONSTRAINTS_FIELDS = CONSTRAINTS_FIELDS.PLUGINS
function isPluginTypeValid (value: any) {
return exists(value) && validator.isInt('' + value) && PluginType[value] !== undefined
return exists(value) &&
(value === PluginType.PLUGIN || value === PluginType.THEME)
}
function isPluginNameValid (value: string) {

View file

@ -10,7 +10,8 @@ function isVideoBlacklistReasonValid (value: string) {
}
function isVideoBlacklistTypeValid (value: any) {
return exists(value) && validator.isInt('' + value) && VideoBlacklistType[value] !== undefined
return exists(value) &&
(value === VideoBlacklistType.AUTO_BEFORE_PUBLISHED || value === VideoBlacklistType.MANUAL)
}
// ---------------------------------------------------------------------------

View file

@ -2,7 +2,8 @@ import { createAccountAbuse, createVideoAbuse, createVideoCommentAbuse } from '@
import { AccountModel } from '@server/models/account/account'
import { VideoModel } from '@server/models/video/video'
import { VideoCommentModel } from '@server/models/video/video-comment'
import { AbuseObject, abusePredefinedReasonsMap, AbuseState, ActivityCreate, ActivityFlag } from '../../../../shared'
import { abusePredefinedReasonsMap } from '@shared/core-utils/abuse'
import { AbuseObject, AbuseState, ActivityCreate, ActivityFlag } from '../../../../shared'
import { getAPId } from '../../../helpers/activitypub'
import { retryTransactionWrapper } from '../../../helpers/database-utils'
import { logger } from '../../../helpers/logger'

View file

@ -1,5 +1,5 @@
import * as express from 'express'
import { buildFileLocale, getDefaultLocale, is18nLocale, POSSIBLE_LOCALES } from '../../shared/models/i18n/i18n'
import { buildFileLocale, getDefaultLocale, is18nLocale, POSSIBLE_LOCALES } from '../../shared/core-utils/i18n/i18n'
import {
AVATARS_SIZE,
CUSTOM_HTML_TAG_COMMENTS,

View file

@ -6,7 +6,7 @@ function ensureUserHasRight (userRight: UserRight) {
return function (req: express.Request, res: express.Response, next: express.NextFunction) {
const user = res.locals.oauth.token.user
if (user.hasRight(userRight) === false) {
const message = `User ${user.username} does not have right ${UserRight[userRight]} to access to ${req.path}.`
const message = `User ${user.username} does not have right ${userRight} to access to ${req.path}.`
logger.info(message)
return res.status(403).json({ error: message })

View file

@ -17,11 +17,11 @@ import {
UpdatedAt
} from 'sequelize-typescript'
import { isAbuseModerationCommentValid, isAbuseReasonValid, isAbuseStateValid } from '@server/helpers/custom-validators/abuses'
import { abusePredefinedReasonsMap } from '@shared/core-utils/abuse'
import {
AbuseFilter,
AbuseObject,
AbusePredefinedReasons,
abusePredefinedReasonsMap,
AbusePredefinedReasonsString,
AbuseState,
AbuseVideoIs,
@ -646,8 +646,10 @@ export class AbuseModel extends Model<AbuseModel> {
}
private static getPredefinedReasonsStrings (predefinedReasons: AbusePredefinedReasons[]): AbusePredefinedReasonsString[] {
const invertedPredefinedReasons = invert(abusePredefinedReasonsMap)
return (predefinedReasons || [])
.filter(r => r in AbusePredefinedReasons)
.map(r => invert(abusePredefinedReasonsMap)[r] as AbusePredefinedReasonsString)
.map(r => invertedPredefinedReasons[r] as AbusePredefinedReasonsString)
.filter(v => !!v)
}
}

View file

@ -1,3 +1,5 @@
import * as Bluebird from 'bluebird'
import { values } from 'lodash'
import { col, FindOptions, fn, literal, Op, QueryTypes, where, WhereOptions } from 'sequelize'
import {
AfterDestroy,
@ -19,8 +21,21 @@ import {
Table,
UpdatedAt
} from 'sequelize-typescript'
import { hasUserRight, MyUser, USER_ROLE_LABELS, UserRight, AbuseState, VideoPlaylistType, VideoPrivacy } from '../../../shared'
import {
MMyUserFormattable,
MUserDefault,
MUserFormattable,
MUserId,
MUserNotifSettingChannelDefault,
MUserWithNotificationSetting,
MVideoFullLight
} from '@server/types/models'
import { hasUserRight, USER_ROLE_LABELS } from '../../../shared/core-utils/users'
import { AbuseState, MyUser, UserRight, VideoPlaylistType, VideoPrivacy } from '../../../shared/models'
import { User, UserRole } from '../../../shared/models/users'
import { UserAdminFlag } from '../../../shared/models/users/user-flag.model'
import { NSFWPolicyType } from '../../../shared/models/videos/nsfw-policy.type'
import { isThemeNameValid } from '../../helpers/custom-validators/plugins'
import {
isNoInstanceConfigWarningModal,
isNoWelcomeModal,
@ -42,33 +57,19 @@ import {
isUserWebTorrentEnabledValid
} from '../../helpers/custom-validators/users'
import { comparePassword, cryptPassword } from '../../helpers/peertube-crypto'
import { OAuthTokenModel } from '../oauth/oauth-token'
import { getSort, throwIfNotValid } from '../utils'
import { VideoChannelModel } from '../video/video-channel'
import { VideoPlaylistModel } from '../video/video-playlist'
import { AccountModel } from './account'
import { NSFWPolicyType } from '../../../shared/models/videos/nsfw-policy.type'
import { values } from 'lodash'
import { DEFAULT_USER_THEME_NAME, NSFW_POLICY_TYPES } from '../../initializers/constants'
import { clearCacheByUserId } from '../../lib/oauth-model'
import { UserNotificationSettingModel } from './user-notification-setting'
import { VideoModel } from '../video/video'
import { getThemeOrDefault } from '../../lib/plugins/theme-utils'
import { ActorModel } from '../activitypub/actor'
import { ActorFollowModel } from '../activitypub/actor-follow'
import { OAuthTokenModel } from '../oauth/oauth-token'
import { getSort, throwIfNotValid } from '../utils'
import { VideoModel } from '../video/video'
import { VideoChannelModel } from '../video/video-channel'
import { VideoImportModel } from '../video/video-import'
import { UserAdminFlag } from '../../../shared/models/users/user-flag.model'
import { isThemeNameValid } from '../../helpers/custom-validators/plugins'
import { getThemeOrDefault } from '../../lib/plugins/theme-utils'
import * as Bluebird from 'bluebird'
import {
MMyUserFormattable,
MUserDefault,
MUserFormattable,
MUserId,
MUserNotifSettingChannelDefault,
MUserWithNotificationSetting,
MVideoFullLight
} from '@server/types/models'
import { VideoPlaylistModel } from '../video/video-playlist'
import { AccountModel } from './account'
import { UserNotificationSettingModel } from './user-notification-setting'
enum ScopeNames {
FOR_ME_API = 'FOR_ME_API',

View file

@ -0,0 +1,14 @@
import { AbusePredefinedReasons, AbusePredefinedReasonsString } from '../../models/moderation/abuse/abuse-reason.model'
export const abusePredefinedReasonsMap: {
[key in AbusePredefinedReasonsString]: AbusePredefinedReasons
} = {
violentOrRepulsive: AbusePredefinedReasons.VIOLENT_OR_REPULSIVE,
hatefulOrAbusive: AbusePredefinedReasons.HATEFUL_OR_ABUSIVE,
spamOrMisleading: AbusePredefinedReasons.SPAM_OR_MISLEADING,
privacy: AbusePredefinedReasons.PRIVACY,
rights: AbusePredefinedReasons.RIGHTS,
serverRules: AbusePredefinedReasons.SERVER_RULES,
thumbnails: AbusePredefinedReasons.THUMBNAILS,
captions: AbusePredefinedReasons.CAPTIONS
}

View file

@ -0,0 +1 @@
export * from './abuse-predefined-reasons'

View file

@ -0,0 +1 @@
export * from './user-role'

View file

@ -0,0 +1,35 @@
import { UserRight, UserRole } from '../../models/users'
export const USER_ROLE_LABELS: { [ id in UserRole ]: string } = {
[UserRole.USER]: 'User',
[UserRole.MODERATOR]: 'Moderator',
[UserRole.ADMINISTRATOR]: 'Administrator'
}
const userRoleRights: { [ id in UserRole ]: UserRight[] } = {
[UserRole.ADMINISTRATOR]: [
UserRight.ALL
],
[UserRole.MODERATOR]: [
UserRight.MANAGE_VIDEO_BLACKLIST,
UserRight.MANAGE_ABUSES,
UserRight.REMOVE_ANY_VIDEO,
UserRight.REMOVE_ANY_VIDEO_CHANNEL,
UserRight.REMOVE_ANY_VIDEO_PLAYLIST,
UserRight.REMOVE_ANY_VIDEO_COMMENT,
UserRight.UPDATE_ANY_VIDEO,
UserRight.SEE_ALL_VIDEOS,
UserRight.MANAGE_ACCOUNTS_BLOCKLIST,
UserRight.MANAGE_SERVERS_BLOCKLIST,
UserRight.MANAGE_USERS
],
[UserRole.USER]: []
}
export function hasUserRight (userRole: UserRole, userRight: UserRight) {
const userRights = userRoleRights[userRole]
return userRights.includes(UserRight.ALL) || userRights.includes(userRight)
}

View file

@ -1,4 +1,4 @@
export enum FeedFormat {
export const enum FeedFormat {
RSS = 'xml',
ATOM = 'atom',
JSON = 'json'

View file

@ -7,7 +7,6 @@ export * from './redundancy'
export * from './users'
export * from './videos'
export * from './feeds'
export * from './i18n'
export * from './overviews'
export * from './plugins'
export * from './search'

View file

@ -1,4 +1,4 @@
export enum AbusePredefinedReasons {
export const enum AbusePredefinedReasons {
VIOLENT_OR_REPULSIVE = 1,
HATEFUL_OR_ABUSIVE,
SPAM_OR_MISLEADING,
@ -18,16 +18,3 @@ export type AbusePredefinedReasonsString =
'serverRules' |
'thumbnails' |
'captions'
export const abusePredefinedReasonsMap: {
[key in AbusePredefinedReasonsString]: AbusePredefinedReasons
} = {
violentOrRepulsive: AbusePredefinedReasons.VIOLENT_OR_REPULSIVE,
hatefulOrAbusive: AbusePredefinedReasons.HATEFUL_OR_ABUSIVE,
spamOrMisleading: AbusePredefinedReasons.SPAM_OR_MISLEADING,
privacy: AbusePredefinedReasons.PRIVACY,
rights: AbusePredefinedReasons.RIGHTS,
serverRules: AbusePredefinedReasons.SERVER_RULES,
thumbnails: AbusePredefinedReasons.THUMBNAILS,
captions: AbusePredefinedReasons.CAPTIONS
}

View file

@ -1,4 +1,4 @@
export enum AbuseState {
export const enum AbuseState {
PENDING = 1,
REJECTED = 2,
ACCEPTED = 3

View file

@ -1,4 +1,4 @@
export enum HookType {
export const enum HookType {
STATIC = 1,
ACTION = 2,
FILTER = 3

View file

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

View file

@ -1,4 +1,4 @@
export enum UserNotificationSettingValue {
export const enum UserNotificationSettingValue {
NONE = 0,
WEB = 1 << 0,
EMAIL = 1 << 1

View file

@ -1,4 +1,4 @@
export enum UserRight {
export const enum UserRight {
ALL,
MANAGE_USERS,

View file

@ -1,42 +1,6 @@
import { UserRight } from './user-right.enum'
// Keep the order
export enum UserRole {
ADMINISTRATOR = 0,
MODERATOR = 1,
USER = 2
}
export const USER_ROLE_LABELS: { [ id in UserRole ]: string } = {
[UserRole.USER]: 'User',
[UserRole.MODERATOR]: 'Moderator',
[UserRole.ADMINISTRATOR]: 'Administrator'
}
const userRoleRights: { [ id in UserRole ]: UserRight[] } = {
[UserRole.ADMINISTRATOR]: [
UserRight.ALL
],
[UserRole.MODERATOR]: [
UserRight.MANAGE_VIDEO_BLACKLIST,
UserRight.MANAGE_ABUSES,
UserRight.REMOVE_ANY_VIDEO,
UserRight.REMOVE_ANY_VIDEO_CHANNEL,
UserRight.REMOVE_ANY_VIDEO_PLAYLIST,
UserRight.REMOVE_ANY_VIDEO_COMMENT,
UserRight.UPDATE_ANY_VIDEO,
UserRight.SEE_ALL_VIDEOS,
UserRight.MANAGE_ACCOUNTS_BLOCKLIST,
UserRight.MANAGE_SERVERS_BLOCKLIST,
UserRight.MANAGE_USERS
],
[UserRole.USER]: []
}
export function hasUserRight (userRole: UserRole, userRight: UserRight) {
const userRights = userRoleRights[userRole]
return userRights.includes(UserRight.ALL) || userRights.includes(userRight)
}

View file

@ -1,6 +1,6 @@
import { Video } from '../video.model'
export enum VideoBlacklistType {
export const enum VideoBlacklistType {
MANUAL = 1,
AUTO_BEFORE_PUBLISHED = 2
}

View file

@ -1,4 +1,4 @@
export enum VideoImportState {
export const enum VideoImportState {
PENDING = 1,
SUCCESS = 2,
FAILED = 3,

View file

@ -1,6 +1,6 @@
import { Video } from '../video.model'
export enum VideoPlaylistElementType {
export const enum VideoPlaylistElementType {
REGULAR = 0,
DELETED = 1,
PRIVATE = 2,

View file

@ -1,4 +1,4 @@
export enum VideoPlaylistPrivacy {
export const enum VideoPlaylistPrivacy {
PUBLIC = 1,
UNLISTED = 2,
PRIVATE = 3

View file

@ -1,4 +1,4 @@
export enum VideoPlaylistType {
export const enum VideoPlaylistType {
REGULAR = 1,
WATCH_LATER = 2
}

View file

@ -1,4 +1,4 @@
export enum ThumbnailType {
export const enum ThumbnailType {
MINIATURE = 1,
PREVIEW = 2
}

View file

@ -10,7 +10,7 @@ export interface VideoChangeOwnership {
createdAt: Date
}
export enum VideoChangeOwnershipStatus {
export const enum VideoChangeOwnershipStatus {
WAITING = 'WAITING',
ACCEPTED = 'ACCEPTED',
REFUSED = 'REFUSED'

View file

@ -1,4 +1,4 @@
export enum VideoPrivacy {
export const enum VideoPrivacy {
PUBLIC = 1,
UNLISTED = 2,
PRIVATE = 3,

View file

@ -1,6 +1,6 @@
import { VideoTranscodingFPS } from './video-transcoding-fps.model'
export enum VideoResolution {
export const enum VideoResolution {
H_NOVIDEO = 0,
H_240P = 240,
H_360P = 360,

View file

@ -1,4 +1,4 @@
export enum VideoState {
export const enum VideoState {
PUBLISHED = 1,
TO_TRANSCODE = 2,
TO_IMPORT = 3

View file

@ -1,3 +1,3 @@
export enum VideoStreamingPlaylistType {
export const enum VideoStreamingPlaylistType {
HLS = 1
}