-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
414 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
import {AuthPolicy} from '@gravity-ui/expresskit'; | ||
import {AppConfig} from '@gravity-ui/nodekit'; | ||
|
||
export default {} as Partial<AppConfig>; | ||
export default { | ||
zitadelEnabled: true, | ||
accessServiceEnabled: true, | ||
appAuthPolicy: AuthPolicy.required, | ||
} as Partial<AppConfig>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,61 @@ | ||
import {AppContext, AppError} from '@gravity-ui/nodekit'; | ||
import type {CheckOrganizationPermission, CheckProjectPermission} from './types'; | ||
import {OrganizationPermission, ProjectPermission} from '../../../../components/iam'; | ||
import {US_ERRORS} from '../../../../const'; | ||
import {ZitadelUserRole} from '../../../../types/zitadel'; | ||
|
||
export const checkOrganizationPermission: CheckOrganizationPermission = async () => {}; | ||
const throwAccessServicePermissionDenied = () => { | ||
throw new AppError(US_ERRORS.ACCESS_SERVICE_PERMISSION_DENIED, { | ||
code: US_ERRORS.ACCESS_SERVICE_PERMISSION_DENIED, | ||
}); | ||
}; | ||
|
||
export const checkProjectPermission: CheckProjectPermission = async () => {}; | ||
export const checkOrganizationPermission: CheckOrganizationPermission = async (args: { | ||
ctx: AppContext; | ||
permission: OrganizationPermission; | ||
}) => { | ||
const {ctx, permission} = args; | ||
const {zitadelUserRole: role} = ctx.get('info'); | ||
|
||
switch (permission) { | ||
case OrganizationPermission.UseInstance: | ||
break; | ||
|
||
case OrganizationPermission.ManageInstance: | ||
if (role !== ZitadelUserRole.Admin) { | ||
throwAccessServicePermissionDenied(); | ||
} | ||
break; | ||
|
||
case OrganizationPermission.CreateCollectionInRoot: | ||
case OrganizationPermission.CreateWorkbookInRoot: | ||
if (role !== ZitadelUserRole.Editor && role !== ZitadelUserRole.Admin) { | ||
throwAccessServicePermissionDenied(); | ||
} | ||
break; | ||
|
||
default: | ||
throwAccessServicePermissionDenied(); | ||
} | ||
}; | ||
|
||
export const checkProjectPermission: CheckProjectPermission = async (args: { | ||
ctx: AppContext; | ||
permission: ProjectPermission; | ||
}) => { | ||
const {ctx, permission} = args; | ||
|
||
const {zitadelUserRole: role} = ctx.get('info'); | ||
|
||
switch (permission) { | ||
case ProjectPermission.CreateCollectionInRoot: | ||
case ProjectPermission.CreateWorkbookInRoot: | ||
if (role !== ZitadelUserRole.Editor && role !== ZitadelUserRole.Admin) { | ||
throwAccessServicePermissionDenied(); | ||
} | ||
break; | ||
|
||
default: | ||
throwAccessServicePermissionDenied(); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import {Request, Response, NextFunction} from '@gravity-ui/expresskit'; | ||
|
||
jest.mock('../../../components/middlewares/auth-zitadel', () => { | ||
const originalModule = jest.requireActual('../../../components/middlewares/auth-zitadel'); | ||
|
||
return { | ||
...originalModule, | ||
|
||
authZitadel: jest.fn((req: Request, res: Response, next: NextFunction) => { | ||
const {ZITADEL_USER_ROLE_HEADER} = require('../constants'); | ||
const {ZitadelUserRole} = require('../../../types/zitadel'); | ||
const role = req.headers[ZITADEL_USER_ROLE_HEADER]; | ||
res.locals.zitadelUserRole = role ?? ZitadelUserRole.Viewer; | ||
return next(); | ||
}), | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import './auth-zitadel'; |
Oops, something went wrong.