mirror of https://github.com/Chocobozzz/PeerTube
Fix follow constraint check with an account
parent
0015924ad6
commit
11ae7e2917
|
@ -1458,6 +1458,12 @@ export class VideoModel extends Model<Partial<AttributesOnly<VideoModel>>> {
|
|||
const query = 'SELECT 1 FROM "videoShare" ' +
|
||||
'INNER JOIN "actorFollow" ON "actorFollow"."targetActorId" = "videoShare"."actorId" ' +
|
||||
'WHERE "actorFollow"."actorId" = $followerActorId AND "actorFollow"."state" = \'accepted\' AND "videoShare"."videoId" = $videoId ' +
|
||||
'UNION ' +
|
||||
'SELECT 1 FROM "video" ' +
|
||||
'INNER JOIN "videoChannel" ON "videoChannel"."id" = "video"."channelId" ' +
|
||||
'INNER JOIN "account" ON "account"."id" = "videoChannel"."accountId" ' +
|
||||
'INNER JOIN "actorFollow" ON "actorFollow"."targetActorId" = "account"."actorId" ' +
|
||||
'WHERE "actorFollow"."actorId" = $followerActorId AND "actorFollow"."state" = \'accepted\' AND "video"."id" = $videoId ' +
|
||||
'LIMIT 1'
|
||||
|
||||
const options = {
|
||||
|
|
|
@ -1,8 +1,15 @@
|
|||
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
|
||||
|
||||
import { expect } from 'chai'
|
||||
import { cleanupTests, createMultipleServers, doubleFollow, PeerTubeServer, setAccessTokensToServers } from '@shared/server-commands'
|
||||
import { HttpStatusCode, PeerTubeProblemDocument, ServerErrorCode } from '@shared/models'
|
||||
import {
|
||||
cleanupTests,
|
||||
createMultipleServers,
|
||||
doubleFollow,
|
||||
PeerTubeServer,
|
||||
setAccessTokensToServers,
|
||||
waitJobs
|
||||
} from '@shared/server-commands'
|
||||
|
||||
describe('Test follow constraints', function () {
|
||||
let servers: PeerTubeServer[] = []
|
||||
|
@ -189,6 +196,7 @@ describe('Test follow constraints', function () {
|
|||
})
|
||||
|
||||
describe('With a logged user', function () {
|
||||
|
||||
it('Should get the local video', async function () {
|
||||
await servers[0].videos.getWithToken({ token: userToken, id: video1UUID })
|
||||
})
|
||||
|
@ -229,6 +237,84 @@ describe('Test follow constraints', function () {
|
|||
})
|
||||
})
|
||||
|
||||
describe('When following a remote account', function () {
|
||||
|
||||
before(async function () {
|
||||
this.timeout(60000)
|
||||
|
||||
await servers[0].follows.follow({ handles: [ 'root@' + servers[1].host ] })
|
||||
await waitJobs(servers)
|
||||
})
|
||||
|
||||
it('Should get the remote video with an unlogged user', async function () {
|
||||
await servers[0].videos.get({ id: video2UUID })
|
||||
})
|
||||
|
||||
it('Should get the remote video with a logged in user', async function () {
|
||||
await servers[0].videos.getWithToken({ token: userToken, id: video2UUID })
|
||||
})
|
||||
})
|
||||
|
||||
describe('When unfollowing a remote account', function () {
|
||||
|
||||
before(async function () {
|
||||
this.timeout(60000)
|
||||
|
||||
await servers[0].follows.unfollow({ target: 'root@' + servers[1].host })
|
||||
await waitJobs(servers)
|
||||
})
|
||||
|
||||
it('Should not get the remote video with an unlogged user', async function () {
|
||||
const body = await servers[0].videos.get({ id: video2UUID, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
|
||||
|
||||
const error = body as unknown as PeerTubeProblemDocument
|
||||
expect(error.code).to.equal(ServerErrorCode.DOES_NOT_RESPECT_FOLLOW_CONSTRAINTS)
|
||||
})
|
||||
|
||||
it('Should get the remote video with a logged in user', async function () {
|
||||
await servers[0].videos.getWithToken({ token: userToken, id: video2UUID })
|
||||
})
|
||||
})
|
||||
|
||||
describe('When following a remote channel', function () {
|
||||
|
||||
before(async function () {
|
||||
this.timeout(60000)
|
||||
|
||||
await servers[0].follows.follow({ handles: [ 'root_channel@' + servers[1].host ] })
|
||||
await waitJobs(servers)
|
||||
})
|
||||
|
||||
it('Should get the remote video with an unlogged user', async function () {
|
||||
await servers[0].videos.get({ id: video2UUID })
|
||||
})
|
||||
|
||||
it('Should get the remote video with a logged in user', async function () {
|
||||
await servers[0].videos.getWithToken({ token: userToken, id: video2UUID })
|
||||
})
|
||||
})
|
||||
|
||||
describe('When unfollowing a remote channel', function () {
|
||||
|
||||
before(async function () {
|
||||
this.timeout(60000)
|
||||
|
||||
await servers[0].follows.unfollow({ target: 'root_channel@' + servers[1].host })
|
||||
await waitJobs(servers)
|
||||
})
|
||||
|
||||
it('Should not get the remote video with an unlogged user', async function () {
|
||||
const body = await servers[0].videos.get({ id: video2UUID, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
|
||||
|
||||
const error = body as unknown as PeerTubeProblemDocument
|
||||
expect(error.code).to.equal(ServerErrorCode.DOES_NOT_RESPECT_FOLLOW_CONSTRAINTS)
|
||||
})
|
||||
|
||||
it('Should get the remote video with a logged in user', async function () {
|
||||
await servers[0].videos.getWithToken({ token: userToken, id: video2UUID })
|
||||
})
|
||||
})
|
||||
|
||||
after(async function () {
|
||||
await cleanupTests(servers)
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue