FIX: Individual data assets permissions

This commit is contained in:
Victor Radael
2022-10-04 11:10:40 -03:00
parent 18c3c9c58c
commit 2b03c4e4a9
3 changed files with 29 additions and 6 deletions
+24 -2
View File
@@ -3,6 +3,7 @@ import {
Controller,
Delete,
Get,
HttpException,
Inject,
Param,
Post,
@@ -172,7 +173,11 @@ export class CatalogController {
customer: body.info.customer,
});
const { username, user_id, customer_id, customer_name } = user;
const { username, user_id, customer_id, customer_name, permissions } = user;
const is_data_manager = permissions.includes(
PERMISSIONS_GROUPS.CATALOG.permissions.DATA_MANAGER.seqid,
);
let has_permission = false;
const metadata = PackTheMetadata({
username,
user_id,
@@ -180,6 +185,8 @@ export class CatalogController {
customer_name,
});
const user_roles = await this.catalogService.getUserRolesIds(user_id);
const res = await this.catalogService.getOneDashboardMetabase(
id,
body,
@@ -187,7 +194,22 @@ export class CatalogController {
customer_id,
);
return res;
const dashboard = res.dashboard;
for (const role of user_roles) {
if (dashboard.roles.includes(role)) has_permission = true;
}
if (dashboard.users.includes(user_id)) has_permission = true;
if (is_data_manager || has_permission) {
return res;
}
throw new HttpException(
'You do not have permission to access this data asset.',
403,
);
}
@Get('table-metadata')
+4 -3
View File
@@ -248,14 +248,15 @@ class CatalogService implements OnModuleInit {
}
}
return {
...data,
Object.assign(data.dashboard, {
tags: opensearchTable.tags,
description: opensearchTable.description || null,
roles,
users,
owner,
};
});
return data;
}
async getAllTableMetadata(body) {
+1 -1
View File
File diff suppressed because one or more lines are too long