Prosody: instance moderators and administrators are automatically owner of rooms.
This commit is contained in:
parent
8e62e00a92
commit
07353bd327
34
server/lib/prosody/config/affiliations.ts
Normal file
34
server/lib/prosody/config/affiliations.ts
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
interface Affiliations { [jid: string]: 'outcast' | 'none' | 'member' | 'admin' | 'owner' }
|
||||||
|
|
||||||
|
async function getVideoAffiliations (options: RegisterServerOptions, _video: MVideoThumbnail): Promise<Affiliations> {
|
||||||
|
const peertubeHelpers = options.peertubeHelpers
|
||||||
|
// Get all admins and moderators
|
||||||
|
const [results] = await peertubeHelpers.database.query(
|
||||||
|
'SELECT "username" FROM "user"' +
|
||||||
|
' WHERE "user"."role" IN (0, 1)'
|
||||||
|
)
|
||||||
|
if (!Array.isArray(results)) {
|
||||||
|
throw new Error('getVideoAffiliations: query result is not an array.')
|
||||||
|
}
|
||||||
|
const r: Affiliations = {}
|
||||||
|
for (let i = 0; i < results.length; i++) {
|
||||||
|
const result = results[i]
|
||||||
|
if (typeof result !== 'object') {
|
||||||
|
throw new Error('getVideoAffiliations: query result is not an object')
|
||||||
|
}
|
||||||
|
if (!('username' in result)) {
|
||||||
|
throw new Error('getVideoAffiliations: no username field in result')
|
||||||
|
}
|
||||||
|
const jid = (result.username as string) + '@localhost'
|
||||||
|
r[jid] = 'owner'
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: add a 'admin' affiliation for video owner
|
||||||
|
|
||||||
|
return r
|
||||||
|
}
|
||||||
|
|
||||||
|
export {
|
||||||
|
Affiliations,
|
||||||
|
getVideoAffiliations
|
||||||
|
}
|
@ -3,6 +3,7 @@ import { videoHasWebchat } from '../../../shared/lib/video'
|
|||||||
import { asyncMiddleware } from '../middlewares/async'
|
import { asyncMiddleware } from '../middlewares/async'
|
||||||
import { prosodyCheckUserPassword, prosodyRegisterUser, prosodyUserRegistered } from '../prosody/auth'
|
import { prosodyCheckUserPassword, prosodyRegisterUser, prosodyUserRegistered } from '../prosody/auth'
|
||||||
import { getAuthUser, getUserNickname } from '../helpers'
|
import { getAuthUser, getUserNickname } from '../helpers'
|
||||||
|
import { Affiliations, getVideoAffiliations } from '../prosody/config/affiliations'
|
||||||
|
|
||||||
// See here for description: https://modules.prosody.im/mod_muc_http_defaults.html
|
// See here for description: https://modules.prosody.im/mod_muc_http_defaults.html
|
||||||
interface RoomDefaults {
|
interface RoomDefaults {
|
||||||
@ -21,11 +22,7 @@ interface RoomDefaults {
|
|||||||
moderated?: boolean
|
moderated?: boolean
|
||||||
archiving?: boolean
|
archiving?: boolean
|
||||||
}
|
}
|
||||||
affiliations?: Array<{
|
affiliations?: Affiliations
|
||||||
jid: string
|
|
||||||
affiliation: 'outcast' | 'none' | 'member' | 'admin' | 'owner'
|
|
||||||
nick?: string
|
|
||||||
}>
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function initApiRouter (options: RegisterServerOptions): Promise<Router> {
|
async function initApiRouter (options: RegisterServerOptions): Promise<Router> {
|
||||||
@ -68,6 +65,15 @@ async function initApiRouter (options: RegisterServerOptions): Promise<Router> {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let affiliations: Affiliations
|
||||||
|
try {
|
||||||
|
affiliations = await getVideoAffiliations(options, video)
|
||||||
|
} catch (error) {
|
||||||
|
logger.error(`Failed to get video affiliations for ${video.uuid}:`, error)
|
||||||
|
// affiliations: should at least be {}, so that the first user will not be moderator/admin
|
||||||
|
affiliations = {}
|
||||||
|
}
|
||||||
|
|
||||||
const roomDefaults: RoomDefaults = {
|
const roomDefaults: RoomDefaults = {
|
||||||
config: {
|
config: {
|
||||||
name: video.name,
|
name: video.name,
|
||||||
@ -75,7 +81,7 @@ async function initApiRouter (options: RegisterServerOptions): Promise<Router> {
|
|||||||
language: video.language,
|
language: video.language,
|
||||||
subject: video.name
|
subject: video.name
|
||||||
},
|
},
|
||||||
affiliations: [] // so that the first user will not be moderator/admin
|
affiliations: affiliations
|
||||||
}
|
}
|
||||||
res.json(roomDefaults)
|
res.json(roomDefaults)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user