Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix checking permissions for creating workbooks and collections #186

Merged
merged 1 commit into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dev/env/opensource/development.env
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ CONTROL_MASTER_TOKEN=development-control-master-token

US_SURPRESS_DB_STATUS_LOGS=true

ZITADEL=false
ZITADEL=true

ZITADEL_URI=http://localhost:8085

Expand Down
2 changes: 1 addition & 1 deletion src/configs/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default {

dlsEnabled: false,
accessServiceEnabled: Utils.isTrueArg(Utils.getEnvVariable('ZITADEL')),
accessBindingsServiceEnabled: false,
accessBindingsServiceEnabled: Utils.isTrueArg(Utils.getEnvVariable('ZITADEL')),

masterToken: Utils.getEnvTokenVariable('MASTER_TOKEN'),

Expand Down
19 changes: 16 additions & 3 deletions src/registry/common/entities/collection/collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@ export const Collection: CollectionConstructor = class Collection implements Col
this.model = model;
}

private getAllPermissions() {
private isEditorOrAdmin() {
const {zitadelUserRole: role} = this.ctx.get('info');
return role === ZitadelUserRole.Editor || role === ZitadelUserRole.Admin;
}

const isEditorOrAdmin = role === ZitadelUserRole.Editor || role === ZitadelUserRole.Admin;
private getAllPermissions() {
const isEditorOrAdmin = this.isEditorOrAdmin();

const permissions = {
listAccessBindings: true,
Expand All @@ -37,7 +40,17 @@ export const Collection: CollectionConstructor = class Collection implements Col
return permissions;
}

async register() {}
async register() {
const isEditorOrAdmin = this.isEditorOrAdmin();

if (!isEditorOrAdmin) {
throw new AppError(US_ERRORS.ACCESS_SERVICE_PERMISSION_DENIED, {
code: US_ERRORS.ACCESS_SERVICE_PERMISSION_DENIED,
});
}

return Promise.resolve();
}

async checkPermission(args: {
parentIds: string[];
Expand Down
17 changes: 14 additions & 3 deletions src/registry/common/entities/workbook/workbook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@ export const Workbook: WorkbookConstructor<WorkbookInstance> = class Workbook
this.model = model;
}

private getAllPermissions() {
private isEditorOrAdmin() {
const {zitadelUserRole: role} = this.ctx.get('info');
return role === ZitadelUserRole.Editor || role === ZitadelUserRole.Admin;
}

const isEditorOrAdmin = role === ZitadelUserRole.Editor || role === ZitadelUserRole.Admin;
private getAllPermissions() {
const isEditorOrAdmin = this.isEditorOrAdmin();

const permissions = {
listAccessBindings: true,
Expand All @@ -39,7 +42,15 @@ export const Workbook: WorkbookConstructor<WorkbookInstance> = class Workbook
return permissions;
}

async register(_args: {parentIds: string[]}): Promise<unknown> {
async register() {
const isEditorOrAdmin = this.isEditorOrAdmin();

if (!isEditorOrAdmin) {
throw new AppError(US_ERRORS.ACCESS_SERVICE_PERMISSION_DENIED, {
code: US_ERRORS.ACCESS_SERVICE_PERMISSION_DENIED,
});
}

return Promise.resolve();
}

Expand Down
Loading