Skip to content

Commit 2163e5b

Browse files
committed
feat(permission): filter out workspace and admin categories for non-ROLE
1 parent 36cb002 commit 2163e5b

1 file changed

Lines changed: 19 additions & 2 deletions

File tree

  • packages/server/src/enterprise/controllers/auth

packages/server/src/enterprise/controllers/auth/index.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { NextFunction, Request, Response } from 'express'
2+
import { StatusCodes } from 'http-status-codes'
23
import { Platform } from '../../../Interface'
34
import { getRunningExpressApp } from '../../../utils/getRunningExpressApp'
45
import { LoggedInUser } from '../../Interface.Enterprise'
@@ -23,6 +24,21 @@ const getAllPermissions = async (req: Request, res: Response, next: NextFunction
2324
'feat:workspaces': ['workspace:']
2425
}
2526

27+
// Category filtering for non-ROLE type
28+
if (type !== 'ROLE') {
29+
const filteredPermissions: { [key: string]: { key: string; value: string }[] } = {}
30+
31+
for (const [category, categoryPermissions] of Object.entries(allPermissions)) {
32+
// Exclude workspace and admin categories
33+
if (category !== 'workspace' && category !== 'admin') {
34+
filteredPermissions[category] = categoryPermissions
35+
}
36+
}
37+
38+
permissions = filteredPermissions
39+
}
40+
41+
// Feature-based filtering for Cloud platform
2642
if (type !== 'ROLE' && appServer.identityManager.getPlatformType() === Platform.CLOUD) {
2743
const userFeatures = user.features
2844
if (userFeatures) {
@@ -40,7 +56,7 @@ const getAllPermissions = async (req: Request, res: Response, next: NextFunction
4056
// Filter out permissions based on disabled features
4157
const filteredPermissions: { [key: string]: { key: string; value: string }[] } = {}
4258

43-
for (const [category, categoryPermissions] of Object.entries(allPermissions)) {
59+
for (const [category, categoryPermissions] of Object.entries(permissions)) {
4460
const filteredCategoryPermissions = (categoryPermissions as any[]).filter((permission) => {
4561
// Check if this permission starts with any disabled prefix
4662
const isDisabled = disabledPermissionPrefixes.some((prefix) => permission.key.startsWith(prefix))
@@ -57,6 +73,7 @@ const getAllPermissions = async (req: Request, res: Response, next: NextFunction
5773
}
5874
}
5975

76+
// User-level filtering for non-admin users
6077
if (type !== 'ROLE' && user.isOrganizationAdmin === false) {
6178
const userPermissions = user.permissions as string[]
6279
const filteredPermissions: { [key: string]: { key: string; value: string }[] } = {}
@@ -74,7 +91,7 @@ const getAllPermissions = async (req: Request, res: Response, next: NextFunction
7491
permissions = filteredPermissions
7592
}
7693

77-
return res.json(permissions)
94+
return res.status(StatusCodes.OK).json(permissions)
7895
} catch (error) {
7996
next(error)
8097
}

0 commit comments

Comments
 (0)