const user = await userToUpdate.save()
// Destroy user token to refresh rights
- if (roleChanged) {
- await OAuthTokenModel.deleteUserToken(userToUpdate.id)
- }
+ if (roleChanged) await OAuthTokenModel.deleteUserToken(userToUpdate.id)
- auditLogger.update(
- getAuditIdFromRes(res),
- new UserAuditView(user.toFormattedJSON()),
- oldUserAuditView
- )
+ auditLogger.update(getAuditIdFromRes(res), new UserAuditView(user.toFormattedJSON()), oldUserAuditView)
// Don't need to send this update to followers, these attributes are not propagated
await Emailer.Instance.addUserBlockJob(user, block, reason)
- auditLogger.update(
- getAuditIdFromRes(res),
- new UserAuditView(user.toFormattedJSON()),
- oldUserAuditView
- )
+ auditLogger.update(getAuditIdFromRes(res), new UserAuditView(user.toFormattedJSON()), oldUserAuditView)
}
import { ActorFollowModel } from '../../../models/activitypub/actor-follow'
import { JobQueue } from '../../../lib/job-queue'
import { logger } from '../../../helpers/logger'
+import { AccountModel } from '../../../models/account/account'
const auditLogger = auditLoggerFactory('users-me')
if (body.autoPlayVideo !== undefined) user.autoPlayVideo = body.autoPlayVideo
await sequelizeTypescript.transaction(async t => {
+ const userAccount = await AccountModel.load(user.Account.id)
+
await user.save({ transaction: t })
- if (body.displayName !== undefined) user.Account.name = body.displayName
- if (body.description !== undefined) user.Account.description = body.description
- await user.Account.save({ transaction: t })
+ if (body.displayName !== undefined) userAccount.name = body.displayName
+ if (body.description !== undefined) userAccount.description = body.description
+ await userAccount.save({ transaction: t })
- await sendUpdateActor(user.Account, t)
+ 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)
const avatarPhysicalFile = req.files[ 'avatarfile' ][ 0 ]
const user: UserModel = res.locals.oauth.token.user
const oldUserAuditView = new UserAuditView(user.toFormattedJSON())
- const account = user.Account
- const avatar = await updateActorAvatarFile(avatarPhysicalFile, account.Actor, account)
+ const userAccount = await AccountModel.load(user.Account.id)
- auditLogger.update(
- getAuditIdFromRes(res),
- new UserAuditView(user.toFormattedJSON()),
- oldUserAuditView
- )
+ const avatar = await updateActorAvatarFile(avatarPhysicalFile, userAccount.Actor, userAccount)
+
+ auditLogger.update(getAuditIdFromRes(res), new UserAuditView(user.toFormattedJSON()), oldUserAuditView)
return res.json({ avatar: avatar.toFormattedJSON() })
}
import { updateActorAvatarFile } from '../../lib/avatar'
import { auditLoggerFactory, getAuditIdFromRes, VideoChannelAuditView } from '../../helpers/audit-logger'
import { resetSequelizeInstance } from '../../helpers/database-utils'
+import { UserModel } from '../../models/account/user'
const auditLogger = auditLoggerFactory('channels')
const reqAvatarFile = createReqFiles([ 'avatarfile' ], IMAGE_MIMETYPE_EXT, { avatarfile: CONFIG.STORAGE.AVATARS_DIR })
async function addVideoChannel (req: express.Request, res: express.Response) {
const videoChannelInfo: VideoChannelCreate = req.body
- const account: AccountModel = res.locals.oauth.token.User.Account
const videoChannelCreated: VideoChannelModel = await sequelizeTypescript.transaction(async t => {
+ const account = await AccountModel.load((res.locals.oauth.token.User as UserModel).Account.id, t)
+
return createVideoChannel(videoChannelInfo, account, t)
})
setAsyncActorKeys(videoChannelCreated.Actor)
.catch(err => logger.error('Cannot set async actor keys for account %s.', videoChannelCreated.Actor.uuid, { err }))
- auditLogger.create(
- getAuditIdFromRes(res),
- new VideoChannelAuditView(videoChannelCreated.toFormattedJSON())
- )
+ auditLogger.create(getAuditIdFromRes(res), new VideoChannelAuditView(videoChannelCreated.toFormattedJSON()))
logger.info('Video channel with uuid %s created.', videoChannelCreated.Actor.uuid)
return res.json({
import { VideoModel } from '../../../models/video/video'
import { VideoAbuseModel } from '../../../models/video/video-abuse'
import { auditLoggerFactory, VideoAbuseAuditView } from '../../../helpers/audit-logger'
+import { UserModel } from '../../../models/account/user'
const auditLogger = auditLoggerFactory('abuse')
const abuseVideoRouter = express.Router()
async function reportVideoAbuse (req: express.Request, res: express.Response) {
const videoInstance = res.locals.video as VideoModel
- const reporterAccount = res.locals.oauth.token.User.Account as AccountModel
const body: VideoAbuseCreate = req.body
- const abuseToCreate = {
- reporterAccountId: reporterAccount.id,
- reason: body.reason,
- videoId: videoInstance.id,
- state: VideoAbuseState.PENDING
- }
-
const videoAbuse: VideoAbuseModel = await sequelizeTypescript.transaction(async t => {
+ const reporterAccount = await AccountModel.load((res.locals.oauth.token.User as UserModel).Account.id, t)
+
+ const abuseToCreate = {
+ reporterAccountId: reporterAccount.id,
+ reason: body.reason,
+ videoId: videoInstance.id,
+ state: VideoAbuseState.PENDING
+ }
+
const videoAbuseInstance = await VideoAbuseModel.create(abuseToCreate, { transaction: t })
videoAbuseInstance.Video = videoInstance
videoAbuseInstance.Account = reporterAccount
})
logger.info('Abuse report for video %s created.', videoInstance.name)
- return res.json({
- videoAbuse: videoAbuse.toFormattedJSON()
- }).end()
+
+ return res.json({ videoAbuse: videoAbuse.toFormattedJSON() }).end()
}
import { VideoModel } from '../../../models/video/video'
import { VideoCommentModel } from '../../../models/video/video-comment'
import { auditLoggerFactory, CommentAuditView, getAuditIdFromRes } from '../../../helpers/audit-logger'
+import { AccountModel } from '../../../models/account/account'
+import { UserModel } from '../../../models/account/user'
const auditLogger = auditLoggerFactory('comments')
const videoCommentRouter = express.Router()
const videoCommentInfo: VideoCommentCreate = req.body
const comment = await sequelizeTypescript.transaction(async t => {
+ const account = await AccountModel.load((res.locals.oauth.token.User as UserModel).Account.id, t)
+
return createVideoComment({
text: videoCommentInfo.text,
inReplyToComment: null,
video: res.locals.video,
- account: res.locals.oauth.token.User.Account
+ account
}, t)
})
const videoCommentInfo: VideoCommentCreate = req.body
const comment = await sequelizeTypescript.transaction(async t => {
+ const account = await AccountModel.load((res.locals.oauth.token.User as UserModel).Account.id, t)
+
return createVideoComment({
text: videoCommentInfo.text,
inReplyToComment: res.locals.videoComment,
video: res.locals.video,
- account: res.locals.oauth.token.User.Account
+ account
}, t)
})
auditLogger.create(getAuditIdFromRes(res), new CommentAuditView(comment.toFormattedJSON()))
- return res.json({
- comment: comment.toFormattedJSON()
- }).end()
+ return res.json({ comment: comment.toFormattedJSON() }).end()
}
async function removeVideoComment (req: express.Request, res: express.Response) {
import { getFormattedObjects } from '../../../helpers/utils'
import { changeVideoChannelShare } from '../../../lib/activitypub'
import { sendUpdateVideo } from '../../../lib/activitypub/send'
+import { UserModel } from '../../../models/account/user'
const ownershipVideoRouter = express.Router()
async function giveVideoOwnership (req: express.Request, res: express.Response) {
const videoInstance = res.locals.video as VideoModel
- const initiatorAccount = res.locals.oauth.token.User.Account as AccountModel
+ const initiatorAccountId = (res.locals.oauth.token.User as UserModel).Account.id
const nextOwner = res.locals.nextOwner as AccountModel
await sequelizeTypescript.transaction(t => {
return VideoChangeOwnershipModel.findOrCreate({
where: {
- initiatorAccountId: initiatorAccount.id,
+ initiatorAccountId,
nextOwnerAccountId: nextOwner.id,
videoId: videoInstance.id,
status: VideoChangeOwnershipStatus.WAITING
},
defaults: {
- initiatorAccountId: initiatorAccount.id,
+ initiatorAccountId,
nextOwnerAccountId: nextOwner.id,
videoId: videoInstance.id,
status: VideoChangeOwnershipStatus.WAITING
},
transaction: t
})
-
})
logger.info('Ownership change for video %s created.', videoInstance.name)
}
async function listVideoOwnership (req: express.Request, res: express.Response) {
- const currentAccount = res.locals.oauth.token.User.Account as AccountModel
+ const currentAccountId = (res.locals.oauth.token.User as UserModel).Account.id
+
const resultList = await VideoChangeOwnershipModel.listForApi(
- currentAccount.id,
+ currentAccountId,
req.query.start || 0,
req.query.count || 10,
req.query.sort || 'createdAt'
const body: UserVideoRateUpdate = req.body
const rateType = body.rating
const videoInstance: VideoModel = res.locals.video
- const accountInstance: AccountModel = res.locals.oauth.token.User.Account
await sequelizeTypescript.transaction(async t => {
const sequelizeOptions = { transaction: t }
+
+ const accountInstance = await AccountModel.load(res.locals.oauth.token.User.Account.id, t)
const previousRate = await AccountVideoRateModel.load(accountInstance.id, videoInstance.id, t)
let likesToIncrement = 0
else if (previousRate.type === VIDEO_RATE_TYPES.DISLIKE) dislikesToIncrement--
if (rateType === 'none') { // Destroy previous rate
- await previousRate.destroy({ transaction: t })
+ await previousRate.destroy(sequelizeOptions)
} else { // Update previous rate
previousRate.type = rateType
- await previousRate.save({ transaction: t })
+ await previousRate.save(sequelizeOptions)
}
} else if (rateType !== 'none') { // There was not a previous rate, insert a new one if there is a rate
const query = {
await videoInstance.increment(incrementQuery, sequelizeOptions)
await sendVideoRateChange(accountInstance, videoInstance, likesToIncrement, dislikesToIncrement, t)
- })
- logger.info('Account video rate for video %s of account %s updated.', videoInstance.name, accountInstance.name)
+ logger.info('Account video rate for video %s of account %s updated.', videoInstance.name, accountInstance.name)
+ })
return res.type('json').status(204).end()
}
syncParam: SyncParam,
refreshViews: boolean
}): Promise<VideoModel> {
+ if (!options.video.isOutdated()) return options.video
+
// We need more attributes if the argument video was fetched with not enough joints
const video = options.fetchedType === 'all' ? options.video : await VideoModel.loadByUrlAndPopulateAccount(options.video.url)
- if (!video.isOutdated()) return video
-
try {
const { response, videoObject } = await fetchRemoteVideo(video.url)
if (response.statusCode === 404) {
-
-
import { AbstractScheduler } from './abstract-scheduler'
import { SCHEDULER_INTERVALS_MS } from '../../initializers'
-import { logger } from '../../helpers/logger'
-import * as request from 'request'
-import { createWriteStream, ensureDir, writeFile } from 'fs-extra'
-import { join } from 'path'
-import { root } from '../../helpers/core-utils'
import { updateYoutubeDLBinary } from '../../helpers/youtube-dl'
export class YoutubeDlUpdateScheduler extends AbstractScheduler {
return undefined
}
- static load (id: number) {
- return AccountModel.findById(id)
+ static load (id: number, transaction?: Sequelize.Transaction) {
+ return AccountModel.findById(id, { transaction })
}
static loadByUUID (uuid: string) {
import { AllowNull, BelongsTo, Column, CreatedAt, ForeignKey, Model, Scopes, Table, UpdatedAt } from 'sequelize-typescript'
import { logger } from '../../helpers/logger'
-import { AccountModel } from '../account/account'
import { UserModel } from '../account/user'
import { OAuthClientModel } from './oauth-client'
import { Transaction } from 'sequelize'
+import { AccountModel } from '../account/account'
+import { ActorModel } from '../activitypub/actor'
export type OAuthTokenInfo = {
refreshToken: string
}
enum ScopeNames {
- WITH_ACCOUNT = 'WITH_ACCOUNT'
+ WITH_USER = 'WITH_USER'
}
@Scopes({
- [ScopeNames.WITH_ACCOUNT]: {
+ [ScopeNames.WITH_USER]: {
include: [
{
- model: () => UserModel,
+ model: () => UserModel.unscoped(),
+ required: true,
include: [
{
- model: () => AccountModel,
- required: true
+ attributes: [ 'id' ],
+ model: () => AccountModel.unscoped(),
+ required: true,
+ include: [
+ {
+ attributes: [ 'id' ],
+ model: () => ActorModel.unscoped(),
+ required: true
+ }
+ ]
}
]
}
}
}
- return OAuthTokenModel.scope(ScopeNames.WITH_ACCOUNT).findOne(query).then(token => {
+ return OAuthTokenModel.scope(ScopeNames.WITH_USER).findOne(query).then(token => {
if (token) token['user'] = token.User
return token
}
}
- return OAuthTokenModel.scope(ScopeNames.WITH_ACCOUNT)
+ return OAuthTokenModel.scope(ScopeNames.WITH_USER)
.findOne(query)
.then(token => {
if (token) {