]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Merge branch 'release/5.0.0' into develop
authorChocobozzz <me@florianbigard.com>
Thu, 19 Jan 2023 14:25:52 +0000 (15:25 +0100)
committerChocobozzz <me@florianbigard.com>
Thu, 19 Jan 2023 14:25:52 +0000 (15:25 +0100)
1  2 
server/models/user/user.ts

index c5c8a1b30d815a08ac57e789e04d40e7a15e4625,3fd808edc9fd3f5bdfa8d05acce0c03278a2e53c..bfc9b30495a55791034fce1768802307949f02fc
@@@ -30,7 -30,6 +30,7 @@@ import 
    MUserNotifSettingChannelDefault,
    MUserWithNotificationSetting
  } from '@server/types/models'
 +import { forceNumber } from '@shared/core-utils'
  import { AttributesOnly } from '@shared/typescript-utils'
  import { hasUserRight, USER_ROLE_LABELS } from '../../../shared/core-utils/users'
  import { AbuseState, MyUser, UserRight, VideoPlaylistType } from '../../../shared/models'
@@@ -64,13 -63,14 +64,13 @@@ import { ActorModel } from '../actor/ac
  import { ActorFollowModel } from '../actor/actor-follow'
  import { ActorImageModel } from '../actor/actor-image'
  import { OAuthTokenModel } from '../oauth/oauth-token'
 -import { getAdminUsersSort, throwIfNotValid } from '../utils'
 +import { getAdminUsersSort, throwIfNotValid } from '../shared'
  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 { forceNumber } from '@shared/core-utils'
  
  enum ScopeNames {
    FOR_ME_API = 'FOR_ME_API',
@@@ -441,17 -441,16 +441,17 @@@ export class UserModel extends Model<Pa
    })
    OAuthTokens: OAuthTokenModel[]
  
 +  // Used if we already set an encrypted password in user model
 +  skipPasswordEncryption = false
 +
    @BeforeCreate
    @BeforeUpdate
 -  static cryptPasswordIfNeeded (instance: UserModel) {
 -    if (instance.changed('password') && instance.password) {
 -      return cryptPassword(instance.password)
 -        .then(hash => {
 -          instance.password = hash
 -          return undefined
 -        })
 -    }
 +  static async cryptPasswordIfNeeded (instance: UserModel) {
 +    if (instance.skipPasswordEncryption) return
 +    if (!instance.changed('password')) return
 +    if (!instance.password) return
 +
 +    instance.password = await cryptPassword(instance.password)
    }
  
    @AfterUpdate
    }
  
    static countTotal () {
-     return this.count()
+     return UserModel.unscoped().count()
    }
  
    static listForAdminApi (parameters: {