Notify local users with internal video privacy

This commit is contained in:
Chocobozzz 2024-08-07 09:26:07 +02:00
parent da992cbcab
commit 56d48fc41b
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
3 changed files with 25 additions and 20 deletions

View File

@ -1,24 +1,24 @@
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
import { expect } from 'chai'
import { wait } from '@peertube/peertube-core-utils' import { wait } from '@peertube/peertube-core-utils'
import { UserNotification, UserNotificationType, VideoPrivacy, VideoStudioTask } from '@peertube/peertube-models' import { UserNotification, UserNotificationType, VideoPrivacy, VideoStudioTask } from '@peertube/peertube-models'
import { buildUUID } from '@peertube/peertube-node-utils' import { buildUUID } from '@peertube/peertube-node-utils'
import { cleanupTests, findExternalSavedVideo, PeerTubeServer, stopFfmpeg, waitJobs } from '@peertube/peertube-server-commands' import { cleanupTests, findExternalSavedVideo, PeerTubeServer, stopFfmpeg, waitJobs } from '@peertube/peertube-server-commands'
import { FIXTURE_URLS } from '@tests/shared/fixture-urls.js'
import { MockSmtpServer } from '@tests/shared/mock-servers/mock-email.js' import { MockSmtpServer } from '@tests/shared/mock-servers/mock-email.js'
import { import {
prepareNotificationsTest,
CheckerBaseParams, CheckerBaseParams,
checkNewVideoFromSubscription,
checkMyVideoIsPublished,
checkVideoStudioEditionIsFinished,
checkMyVideoImportIsFinished, checkMyVideoImportIsFinished,
checkMyVideoIsPublished,
checkNewActorFollow, checkNewActorFollow,
checkNewLiveFromSubscription, checkNewLiveFromSubscription,
checkNewVideoFromSubscription,
checkVideoStudioEditionIsFinished,
prepareNotificationsTest,
waitUntilNotification waitUntilNotification
} from '@tests/shared/notifications.js' } from '@tests/shared/notifications.js'
import { FIXTURE_URLS } from '@tests/shared/fixture-urls.js'
import { uploadRandomVideoOnServers } from '@tests/shared/videos.js' import { uploadRandomVideoOnServers } from '@tests/shared/videos.js'
import { expect } from 'chai'
describe('Test user notifications', function () { describe('Test user notifications', function () {
let servers: PeerTubeServer[] = [] let servers: PeerTubeServer[] = []
@ -72,8 +72,10 @@ describe('Test user notifications', function () {
await servers[0].subscriptions.add({ token: userAccessToken, targetUri: 'root_channel@' + servers[0].host }) await servers[0].subscriptions.add({ token: userAccessToken, targetUri: 'root_channel@' + servers[0].host })
await waitJobs(servers) await waitJobs(servers)
const { name, shortUUID } = await uploadRandomVideoOnServers(servers, 1) for (const privacy of [ VideoPrivacy.PUBLIC, VideoPrivacy.INTERNAL ]) {
await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' }) const { name, shortUUID } = await uploadRandomVideoOnServers(servers, 1, { privacy })
await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' })
}
}) })
it('Should send a new video notification from a remote account', async function () { it('Should send a new video notification from a remote account', async function () {
@ -146,15 +148,16 @@ describe('Test user notifications', function () {
it('Should send a new video notification when a video becomes public', async function () { it('Should send a new video notification when a video becomes public', async function () {
this.timeout(50000) this.timeout(50000)
const data = { privacy: VideoPrivacy.PRIVATE } for (const privacy of [ VideoPrivacy.PUBLIC, VideoPrivacy.INTERNAL ]) {
const { name, uuid, shortUUID } = await uploadRandomVideoOnServers(servers, 1, data) const { name, uuid, shortUUID } = await uploadRandomVideoOnServers(servers, 1, { privacy: VideoPrivacy.PRIVATE })
await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'absence' }) await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'absence' })
await servers[0].videos.update({ id: uuid, attributes: { privacy: VideoPrivacy.PUBLIC } }) await servers[0].videos.update({ id: uuid, attributes: { privacy } })
await waitJobs(servers) await waitJobs(servers)
await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' }) await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID, checkType: 'presence' })
}
}) })
it('Should send a new video notification when a remote video becomes public', async function () { it('Should send a new video notification when a remote video becomes public', async function () {
@ -211,7 +214,6 @@ describe('Test user notifications', function () {
await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID: video.shortUUID, checkType: 'presence' }) await checkNewVideoFromSubscription({ ...baseParams, videoName: name, shortUUID: video.shortUUID, checkType: 'presence' })
}) })
}) })
describe('New live from my subscription notification', function () { describe('New live from my subscription notification', function () {

View File

@ -19,7 +19,11 @@ export class NewVideoOrLiveForSubscribers extends AbstractNotification <MVideoAc
} }
isDisabled () { isDisabled () {
return this.payload.privacy !== VideoPrivacy.PUBLIC || this.payload.state !== VideoState.PUBLISHED || this.payload.isBlacklisted() if (this.payload.privacy !== VideoPrivacy.PUBLIC && this.payload.privacy !== VideoPrivacy.INTERNAL) return true
if (this.payload.state !== VideoState.PUBLISHED) return true
if (this.payload.isBlacklisted()) return true
return false
} }
getSetting (user: MUserWithNotificationSetting) { getSetting (user: MUserWithNotificationSetting) {

View File

@ -156,13 +156,12 @@ export async function addVideoJobsAfterUpdate (options: {
} }
}) })
const wasConfidentialVideo = new Set<VideoPrivacyType>([ const wasConfidentialVideoForNotification = new Set<VideoPrivacyType>([
VideoPrivacy.PRIVATE, VideoPrivacy.PRIVATE,
VideoPrivacy.UNLISTED, VideoPrivacy.UNLISTED
VideoPrivacy.INTERNAL
]).has(oldPrivacy) ]).has(oldPrivacy)
if (wasConfidentialVideo) { if (wasConfidentialVideoForNotification) {
jobs.push({ jobs.push({
type: 'notify', type: 'notify',
payload: { payload: {