]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/models/user/user.ts
Fix lint
[github/Chocobozzz/PeerTube.git] / server / models / user / user.ts
index 85720abfb59348a2b1547456cb7a383e96f09b8d..3fd359359c0364e327ab2db691511753206da49a 100644 (file)
@@ -22,18 +22,18 @@ import {
   UpdatedAt
 } from 'sequelize-typescript'
 import { TokensCache } from '@server/lib/auth/tokens-cache'
+import { LiveQuotaStore } from '@server/lib/live'
 import {
   MMyUserFormattable,
   MUser,
   MUserDefault,
   MUserFormattable,
   MUserNotifSettingChannelDefault,
-  MUserWithNotificationSetting,
-  MVideoWithRights
+  MUserWithNotificationSetting
 } from '@server/types/models'
 import { AttributesOnly } from '@shared/typescript-utils'
 import { hasUserRight, USER_ROLE_LABELS } from '../../../shared/core-utils/users'
-import { AbuseState, MyUser, UserRight, VideoPlaylistType, VideoPrivacy } from '../../../shared/models'
+import { AbuseState, MyUser, UserRight, VideoPlaylistType } 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'
@@ -65,15 +65,13 @@ import { ActorModel } from '../actor/actor'
 import { ActorFollowModel } from '../actor/actor-follow'
 import { ActorImageModel } from '../actor/actor-image'
 import { OAuthTokenModel } from '../oauth/oauth-token'
-import { getSort, throwIfNotValid } from '../utils'
+import { getAdminUsersSort, throwIfNotValid } from '../utils'
 import { VideoModel } from '../video/video'
 import { VideoChannelModel } from '../video/video-channel'
 import { VideoImportModel } from '../video/video-import'
 import { VideoLiveModel } from '../video/video-live'
 import { VideoPlaylistModel } from '../video/video-playlist'
 import { UserNotificationSettingModel } from './user-notification-setting'
-import { LiveQuotaStore } from '@server/lib/live'
-import { logger } from '@server/helpers/logger'
 
 enum ScopeNames {
   FOR_ME_API = 'FOR_ME_API',
@@ -462,7 +460,7 @@ export class UserModel extends Model<Partial<AttributesOnly<UserModel>>> {
     return this.count()
   }
 
-  static listForApi (parameters: {
+  static listForAdminApi (parameters: {
     start: number
     count: number
     sort: string
@@ -490,15 +488,13 @@ export class UserModel extends Model<Partial<AttributesOnly<UserModel>>> {
     }
 
     if (blocked !== undefined) {
-      Object.assign(where, {
-        blocked: blocked
-      })
+      Object.assign(where, { blocked })
     }
 
     const query: FindOptions = {
       offset: start,
       limit: count,
-      order: getSort(sort),
+      order: getAdminUsersSort(sort),
       where
     }
 
@@ -820,10 +816,10 @@ export class UserModel extends Model<Partial<AttributesOnly<UserModel>>> {
         }
       }
 
-      return UserModel.count(query)
+      return UserModel.unscoped().count(query)
     }
 
-    const totalUsers = await UserModel.count()
+    const totalUsers = await UserModel.unscoped().count()
     const totalDailyActiveUsers = await getActiveUsers(1)
     const totalWeeklyActiveUsers = await getActiveUsers(7)
     const totalMonthlyActiveUsers = await getActiveUsers(30)
@@ -852,22 +848,6 @@ export class UserModel extends Model<Partial<AttributesOnly<UserModel>>> {
                     .then(u => u.map(u => u.username))
   }
 
-  canGetVideo (video: MVideoWithRights) {
-    const videoUserId = video.VideoChannel.Account.userId
-
-    if (video.isBlacklisted()) {
-      return videoUserId === this.id || this.hasRight(UserRight.MANAGE_VIDEO_BLACKLIST)
-    }
-
-    if (video.privacy === VideoPrivacy.PRIVATE) {
-      return video.VideoChannel && videoUserId === this.id || this.hasRight(UserRight.MANAGE_VIDEO_BLACKLIST)
-    }
-
-    if (video.privacy === VideoPrivacy.INTERNAL) return true
-
-    return false
-  }
-
   hasRight (right: UserRight) {
     return hasUserRight(this.role, right)
   }