refactor(server scopes): use constants for stream reviewer role

This commit is contained in:
Gergő Jedlicska
2023-07-26 14:14:17 +02:00
parent 23989174d3
commit 8f6ec4a025
5 changed files with 45 additions and 13 deletions
@@ -98,7 +98,11 @@ module.exports = {
subscribe: withFilter(
() => pubsub.asyncIterator([BRANCH_CREATED]),
async (payload, variables, context) => {
await authorizeResolver(context.userId, payload.streamId, 'stream:reviewer')
await authorizeResolver(
context.userId,
payload.streamId,
Roles.Stream.Reviewer
)
return payload.streamId === variables.streamId
}
@@ -109,7 +113,11 @@ module.exports = {
subscribe: withFilter(
() => pubsub.asyncIterator([BRANCH_UPDATED]),
async (payload, variables, context) => {
await authorizeResolver(context.userId, payload.streamId, 'stream:reviewer')
await authorizeResolver(
context.userId,
payload.streamId,
Roles.Stream.Reviewer
)
const streamMatch = payload.streamId === variables.streamId
if (streamMatch && variables.branchId) {
@@ -125,7 +133,11 @@ module.exports = {
subscribe: withFilter(
() => pubsub.asyncIterator([BRANCH_DELETED]),
async (payload, variables, context) => {
await authorizeResolver(context.userId, payload.streamId, 'stream:reviewer')
await authorizeResolver(
context.userId,
payload.streamId,
Roles.Stream.Reviewer
)
return payload.streamId === variables.streamId
}
@@ -199,7 +199,11 @@ module.exports = {
},
async commitReceive(parent, args, context) {
await authorizeResolver(context.userId, args.input.streamId, 'stream:reviewer')
await authorizeResolver(
context.userId,
args.input.streamId,
Roles.Stream.Reviewer
)
const commit = await getCommitById({
streamId: args.input.streamId,
@@ -245,7 +249,11 @@ module.exports = {
subscribe: withFilter(
() => pubsub.asyncIterator([COMMIT_CREATED]),
async (payload, variables, context) => {
await authorizeResolver(context.userId, payload.streamId, 'stream:reviewer')
await authorizeResolver(
context.userId,
payload.streamId,
Roles.Stream.Reviewer
)
return payload.streamId === variables.streamId
}
)
@@ -255,7 +263,11 @@ module.exports = {
subscribe: withFilter(
() => pubsub.asyncIterator([COMMIT_UPDATED]),
async (payload, variables, context) => {
await authorizeResolver(context.userId, payload.streamId, 'stream:reviewer')
await authorizeResolver(
context.userId,
payload.streamId,
Roles.Stream.Reviewer
)
const streamMatch = payload.streamId === variables.streamId
if (streamMatch && variables.commitId) {
@@ -271,7 +283,11 @@ module.exports = {
subscribe: withFilter(
() => pubsub.asyncIterator([COMMIT_DELETED]),
async (payload, variables, context) => {
await authorizeResolver(context.userId, payload.streamId, 'stream:reviewer')
await authorizeResolver(
context.userId,
payload.streamId,
Roles.Stream.Reviewer
)
return payload.streamId === variables.streamId
}
@@ -85,7 +85,7 @@ module.exports = {
throw new StreamNotFoundError('Stream not found')
}
await authorizeResolver(context.userId, args.id, 'stream:reviewer')
await authorizeResolver(context.userId, args.id, Roles.Stream.Reviewer)
if (!stream.isPublic) {
await validateServerRole(context, Roles.Server.User)
@@ -310,7 +310,7 @@ module.exports = {
subscribe: withFilter(
() => pubsub.asyncIterator([STREAM_UPDATED]),
async (payload, variables, context) => {
await authorizeResolver(context.userId, payload.id, 'stream:reviewer')
await authorizeResolver(context.userId, payload.id, Roles.Stream.Reviewer)
return payload.id === variables.streamId
}
)
@@ -320,7 +320,11 @@ module.exports = {
subscribe: withFilter(
() => pubsub.asyncIterator([STREAM_DELETED]),
async (payload, variables, context) => {
await authorizeResolver(context.userId, payload.streamId, 'stream:reviewer')
await authorizeResolver(
context.userId,
payload.streamId,
Roles.Stream.Reviewer
)
return payload.streamId === variables.streamId
}
)
@@ -33,7 +33,7 @@ module.exports = {
}
try {
await authorizeResolver(req.context.userId, streamId, 'stream:reviewer')
await authorizeResolver(req.context.userId, streamId, Roles.Stream.Reviewer)
} catch (err) {
return { result: false, status: 401 }
}
+2 -2
View File
@@ -21,7 +21,7 @@ const { moduleLogger, logger } = require('@/logging/logging')
const {
listenForPreviewGenerationUpdates
} = require('@/modules/previews/services/resultListener')
const { Scopes } = require('@speckle/shared')
const { Scopes, Roles } = require('@speckle/shared')
const httpErrorImage = (httpErrorCode) =>
require.resolve(`#/assets/previews/images/preview_${httpErrorCode}.png`)
@@ -154,7 +154,7 @@ exports.init = (app) => {
await authorizeResolver(
req.context.userId,
req.params.streamId,
'stream:reviewer'
Roles.Stream.Reviewer
)
} catch (err) {
return { hasPermissions: false, httpErrorCode: 401 }