WiP on permissions

Doesn't run. This commit is just to backup the changes.
This commit is contained in:
Tomas Bures 2017-07-26 22:42:05 +03:00
parent 5df444f641
commit 89c9615592
37 changed files with 913 additions and 366 deletions

View file

@ -1,75 +1,38 @@
'use strict';
const config = require('config');
// FIXME - redo or delete
/*
class ReportTemplatePermission {
constructor(name) {
this.name = name;
this.entityType = 'report-template';
}
}
const ReportTemplatePermissions = {
View: new ReportTemplatePermission('view'),
Edit: new ReportTemplatePermission('edit'),
Delete: new ReportTemplatePermission('delete')
};
class ListPermission {
constructor(name) {
this.name = name;
this.entityType = 'list';
const entityTypes = {
namespace: {
entitiesTable: 'namespaces',
sharesTable: 'shares_namespace',
permissionsTable: 'permissions_namespace'
},
report: {
entitiesTable: 'reports',
sharesTable: 'shares_report',
permissionsTable: 'permissions_report'
},
reportTemplate: {
entitiesTable: 'report_templates',
sharesTable: 'shares_report_template',
permissionsTable: 'permissions_report_template'
}
}
const ListPermissions = {
View: new ListPermissions('view')
};
class NamespacePermission {
constructor(name) {
this.name = name;
this.entityType = 'namespace';
}
function getEntityTypes() {
return entityTypes;
}
const NamespacePermissions = {
View: new NamespacePermission('view'),
Edit: new NamespacePermission('edit'),
Create: new NamespacePermission('create'),
Delete: new NamespacePermission('delete'),
CreateList: new NamespacePermission('create list')
};
*/
function getEntityType(entityTypeId) {
const entityType = entityTypes[entityTypeId];
/*
async function can(context, operation, entityId) {
if (!context.user) {
return false;
if (!entityType) {
throw new Error(`Unknown entity type ${entityTypeId}`);
}
const result = await knex('permissions_' + operation.entityType).select(['id']).where({
entity: entityId,
user: context.user.id,
operation: operation.name
}).first();
return !!result;
return entityType
}
async function buildPermissions() {
}
can(ctx, ListPermissions.View, 3)
can(ctx, NamespacePermissions.CreateList, 2)
can(ctx, ReportTemplatePermissions.ViewReport, 5)
*/
module.exports = {
getEntityTypes,
getEntityType
}