Add MANAGE_PEERTUBE_FOLLOW right
This commit is contained in:
parent
ce548a10db
commit
8e69648749
|
@ -46,7 +46,7 @@ async function accountFollowersController (req: express.Request, res: express.Re
|
||||||
const page = req.params.page || 1
|
const page = req.params.page || 1
|
||||||
const { start, count } = pageToStartAndCount(page, ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE)
|
const { start, count } = pageToStartAndCount(page, ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE)
|
||||||
|
|
||||||
const result = await db.Account.listFollowerUrlsForApi(account.id, start, count)
|
const result = await db.Account.listAcceptedFollowerUrlsForApi(account.id, start, count)
|
||||||
const activityPubResult = activityPubCollectionPagination(req.url, page, result)
|
const activityPubResult = activityPubCollectionPagination(req.url, page, result)
|
||||||
|
|
||||||
return res.json(activityPubResult)
|
return res.json(activityPubResult)
|
||||||
|
@ -58,7 +58,7 @@ async function accountFollowingController (req: express.Request, res: express.Re
|
||||||
const page = req.params.page || 1
|
const page = req.params.page || 1
|
||||||
const { start, count } = pageToStartAndCount(page, ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE)
|
const { start, count } = pageToStartAndCount(page, ACTIVITY_PUB.COLLECTION_ITEMS_PER_PAGE)
|
||||||
|
|
||||||
const result = await db.Account.listFollowingUrlsForApi(account.id, start, count)
|
const result = await db.Account.listAcceptedFollowingUrlsForApi(account.id, start, count)
|
||||||
const activityPubResult = activityPubCollectionPagination(req.url, page, result)
|
const activityPubResult = activityPubCollectionPagination(req.url, page, result)
|
||||||
|
|
||||||
return res.json(activityPubResult)
|
return res.json(activityPubResult)
|
||||||
|
|
|
@ -11,6 +11,9 @@ import { setFollowingSort } from '../../middlewares/sort'
|
||||||
import { followValidator } from '../../middlewares/validators/pods'
|
import { followValidator } from '../../middlewares/validators/pods'
|
||||||
import { followersSortValidator, followingSortValidator } from '../../middlewares/validators/sort'
|
import { followersSortValidator, followingSortValidator } from '../../middlewares/validators/sort'
|
||||||
import { sendFollow } from '../../lib/activitypub/send-request'
|
import { sendFollow } from '../../lib/activitypub/send-request'
|
||||||
|
import { authenticate } from '../../middlewares/oauth'
|
||||||
|
import { ensureUserHasRight } from '../../middlewares/user-right'
|
||||||
|
import { UserRight } from '../../../shared/models/users/user-right.enum'
|
||||||
|
|
||||||
const podsRouter = express.Router()
|
const podsRouter = express.Router()
|
||||||
|
|
||||||
|
@ -23,6 +26,8 @@ podsRouter.get('/following',
|
||||||
)
|
)
|
||||||
|
|
||||||
podsRouter.post('/follow',
|
podsRouter.post('/follow',
|
||||||
|
authenticate,
|
||||||
|
ensureUserHasRight(UserRight.MANAGE_PEERTUBE_FOLLOW),
|
||||||
followValidator,
|
followValidator,
|
||||||
setBodyHostsPort,
|
setBodyHostsPort,
|
||||||
asyncMiddleware(follow)
|
asyncMiddleware(follow)
|
||||||
|
|
|
@ -85,7 +85,7 @@ export {
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
async function broadcastToFollowers (data: any, fromAccount: AccountInstance, t: Sequelize.Transaction) {
|
async function broadcastToFollowers (data: any, fromAccount: AccountInstance, t: Sequelize.Transaction) {
|
||||||
const result = await db.Account.listFollowerUrlsForApi(fromAccount.id, 0)
|
const result = await db.Account.listAcceptedFollowerUrlsForApi(fromAccount.id, 0)
|
||||||
|
|
||||||
const jobPayload = {
|
const jobPayload = {
|
||||||
uris: result.data,
|
uris: result.data,
|
||||||
|
|
|
@ -14,8 +14,8 @@ export namespace AccountMethods {
|
||||||
export type LoadAccountByPodAndUUID = (uuid: string, podId: number, transaction: Sequelize.Transaction) => Bluebird<AccountInstance>
|
export type LoadAccountByPodAndUUID = (uuid: string, podId: number, transaction: Sequelize.Transaction) => Bluebird<AccountInstance>
|
||||||
export type LoadLocalAccountByNameAndPod = (name: string, host: string) => Bluebird<AccountInstance>
|
export type LoadLocalAccountByNameAndPod = (name: string, host: string) => Bluebird<AccountInstance>
|
||||||
export type ListOwned = () => Bluebird<AccountInstance[]>
|
export type ListOwned = () => Bluebird<AccountInstance[]>
|
||||||
export type ListFollowerUrlsForApi = (id: number, start: number, count?: number) => Promise< ResultList<string> >
|
export type ListAcceptedFollowerUrlsForApi = (id: number, start: number, count?: number) => Promise< ResultList<string> >
|
||||||
export type ListFollowingUrlsForApi = (id: number, start: number, count?: number) => Promise< ResultList<string> >
|
export type ListAcceptedFollowingUrlsForApi = (id: number, start: number, count?: number) => Promise< ResultList<string> >
|
||||||
export type ListFollowingForApi = (id: number, start: number, count: number, sort: string) => Bluebird< ResultList<AccountInstance> >
|
export type ListFollowingForApi = (id: number, start: number, count: number, sort: string) => Bluebird< ResultList<AccountInstance> >
|
||||||
export type ListFollowersForApi = (id: number, start: number, count: number, sort: string) => Bluebird< ResultList<AccountInstance> >
|
export type ListFollowersForApi = (id: number, start: number, count: number, sort: string) => Bluebird< ResultList<AccountInstance> >
|
||||||
|
|
||||||
|
@ -36,8 +36,8 @@ export interface AccountClass {
|
||||||
loadByUrl: AccountMethods.LoadByUrl
|
loadByUrl: AccountMethods.LoadByUrl
|
||||||
loadLocalAccountByNameAndPod: AccountMethods.LoadLocalAccountByNameAndPod
|
loadLocalAccountByNameAndPod: AccountMethods.LoadLocalAccountByNameAndPod
|
||||||
listOwned: AccountMethods.ListOwned
|
listOwned: AccountMethods.ListOwned
|
||||||
listFollowerUrlsForApi: AccountMethods.ListFollowerUrlsForApi
|
listAcceptedFollowerUrlsForApi: AccountMethods.ListAcceptedFollowerUrlsForApi
|
||||||
listFollowingUrlsForApi: AccountMethods.ListFollowingUrlsForApi
|
listAcceptedFollowingUrlsForApi: AccountMethods.ListAcceptedFollowingUrlsForApi
|
||||||
listFollowingForApi: AccountMethods.ListFollowingForApi
|
listFollowingForApi: AccountMethods.ListFollowingForApi
|
||||||
listFollowersForApi: AccountMethods.ListFollowersForApi
|
listFollowersForApi: AccountMethods.ListFollowersForApi
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,8 +33,8 @@ let loadByUUID: AccountMethods.LoadByUUID
|
||||||
let loadByUrl: AccountMethods.LoadByUrl
|
let loadByUrl: AccountMethods.LoadByUrl
|
||||||
let loadLocalAccountByNameAndPod: AccountMethods.LoadLocalAccountByNameAndPod
|
let loadLocalAccountByNameAndPod: AccountMethods.LoadLocalAccountByNameAndPod
|
||||||
let listOwned: AccountMethods.ListOwned
|
let listOwned: AccountMethods.ListOwned
|
||||||
let listFollowerUrlsForApi: AccountMethods.ListFollowerUrlsForApi
|
let listAcceptedFollowerUrlsForApi: AccountMethods.ListAcceptedFollowerUrlsForApi
|
||||||
let listFollowingUrlsForApi: AccountMethods.ListFollowingUrlsForApi
|
let listAcceptedFollowingUrlsForApi: AccountMethods.ListAcceptedFollowingUrlsForApi
|
||||||
let listFollowingForApi: AccountMethods.ListFollowingForApi
|
let listFollowingForApi: AccountMethods.ListFollowingForApi
|
||||||
let listFollowersForApi: AccountMethods.ListFollowersForApi
|
let listFollowersForApi: AccountMethods.ListFollowersForApi
|
||||||
let isOwned: AccountMethods.IsOwned
|
let isOwned: AccountMethods.IsOwned
|
||||||
|
@ -201,8 +201,8 @@ export default function defineAccount (sequelize: Sequelize.Sequelize, DataTypes
|
||||||
loadByUrl,
|
loadByUrl,
|
||||||
loadLocalAccountByNameAndPod,
|
loadLocalAccountByNameAndPod,
|
||||||
listOwned,
|
listOwned,
|
||||||
listFollowerUrlsForApi,
|
listAcceptedFollowerUrlsForApi,
|
||||||
listFollowingUrlsForApi,
|
listAcceptedFollowingUrlsForApi,
|
||||||
listFollowingForApi,
|
listFollowingForApi,
|
||||||
listFollowersForApi
|
listFollowersForApi
|
||||||
]
|
]
|
||||||
|
@ -365,12 +365,12 @@ listOwned = function () {
|
||||||
return Account.findAll(query)
|
return Account.findAll(query)
|
||||||
}
|
}
|
||||||
|
|
||||||
listFollowerUrlsForApi = function (id: number, start: number, count?: number) {
|
listAcceptedFollowerUrlsForApi = function (id: number, start: number, count?: number) {
|
||||||
return createListFollowForApiQuery('followers', id, start, count)
|
return createListAcceptedFollowForApiQuery('followers', id, start, count)
|
||||||
}
|
}
|
||||||
|
|
||||||
listFollowingUrlsForApi = function (id: number, start: number, count?: number) {
|
listAcceptedFollowingUrlsForApi = function (id: number, start: number, count?: number) {
|
||||||
return createListFollowForApiQuery('following', id, start, count)
|
return createListAcceptedFollowForApiQuery('following', id, start, count)
|
||||||
}
|
}
|
||||||
|
|
||||||
listFollowingForApi = function (id: number, start: number, count: number, sort: string) {
|
listFollowingForApi = function (id: number, start: number, count: number, sort: string) {
|
||||||
|
@ -506,7 +506,7 @@ loadAccountByPodAndUUID = function (uuid: string, podId: number, transaction: Se
|
||||||
|
|
||||||
// ------------------------------ UTILS ------------------------------
|
// ------------------------------ UTILS ------------------------------
|
||||||
|
|
||||||
async function createListFollowForApiQuery (type: 'followers' | 'following', id: number, start: number, count?: number) {
|
async function createListAcceptedFollowForApiQuery (type: 'followers' | 'following', id: number, start: number, count?: number) {
|
||||||
let firstJoin: string
|
let firstJoin: string
|
||||||
let secondJoin: string
|
let secondJoin: string
|
||||||
|
|
||||||
|
@ -525,7 +525,7 @@ async function createListFollowForApiQuery (type: 'followers' | 'following', id:
|
||||||
let query = 'SELECT ' + selection + ' FROM "Account" ' +
|
let query = 'SELECT ' + selection + ' FROM "Account" ' +
|
||||||
'INNER JOIN "AccountFollower" ON "AccountFollower"."' + firstJoin + '" = "Account"."id" ' +
|
'INNER JOIN "AccountFollower" ON "AccountFollower"."' + firstJoin + '" = "Account"."id" ' +
|
||||||
'INNER JOIN "Account" AS "Follows" ON "Followers"."id" = "Follows"."' + secondJoin + '" ' +
|
'INNER JOIN "Account" AS "Follows" ON "Followers"."id" = "Follows"."' + secondJoin + '" ' +
|
||||||
'WHERE "Account"."id" = $id ' +
|
'WHERE "Account"."id" = $id AND "AccountFollower"."state" = \'accepted\' ' +
|
||||||
'LIMIT ' + start
|
'LIMIT ' + start
|
||||||
|
|
||||||
if (count !== undefined) query += ', ' + count
|
if (count !== undefined) query += ', ' + count
|
||||||
|
|
|
@ -1,9 +1,8 @@
|
||||||
export enum UserRight {
|
export enum UserRight {
|
||||||
ALL,
|
ALL,
|
||||||
MANAGE_USERS,
|
MANAGE_USERS,
|
||||||
MANAGE_PODS,
|
MANAGE_PEERTUBE_FOLLOW,
|
||||||
MANAGE_VIDEO_ABUSES,
|
MANAGE_VIDEO_ABUSES,
|
||||||
MANAGE_REQUEST_SCHEDULERS,
|
|
||||||
MANAGE_VIDEO_BLACKLIST,
|
MANAGE_VIDEO_BLACKLIST,
|
||||||
REMOVE_ANY_VIDEO,
|
REMOVE_ANY_VIDEO,
|
||||||
REMOVE_ANY_VIDEO_CHANNEL,
|
REMOVE_ANY_VIDEO_CHANNEL,
|
||||||
|
|
Loading…
Reference in New Issue