Computation of permissions seems to somehow work.
This commit is contained in:
parent
e7bdfb7745
commit
5df444f641
12 changed files with 286 additions and 133 deletions
|
@ -1,58 +1,33 @@
|
|||
exports.up = function(knex, Promise) {
|
||||
return knex.schema.createTable('namespaces', table => {
|
||||
const entityTypesAddNamespace = ['list', 'report', 'report_template', 'user'];
|
||||
let schema = knex.schema;
|
||||
|
||||
schema = schema.createTable('namespaces', table => {
|
||||
table.increments('id').primary();
|
||||
table.string('name');
|
||||
table.text('description');
|
||||
table.integer('namespace').unsigned().references('namespaces.id').onDelete('CASCADE');
|
||||
})
|
||||
|
||||
.then(() => knex('namespaces').insert({
|
||||
id: 1,
|
||||
name: 'Global',
|
||||
description: 'Global namespace'
|
||||
}))
|
||||
}));
|
||||
|
||||
.then(() => knex.schema.table('users', table => {
|
||||
table.integer('namespace').unsigned().notNullable();
|
||||
}))
|
||||
.then(() => knex('users').update({
|
||||
namespace: 1
|
||||
}))
|
||||
.then(() => knex.schema.table('users', table => {
|
||||
table.foreign('namespace').references('namespaces.id').onDelete('CASCADE');
|
||||
}))
|
||||
for (const entityType of entityTypesAddNamespace) {
|
||||
schema = schema
|
||||
.then(() => knex.schema.table(`${entityType}s`, table => {
|
||||
table.integer('namespace').unsigned().notNullable();
|
||||
}))
|
||||
.then(() => knex(`${entityType}s`).update({
|
||||
namespace: 1
|
||||
}))
|
||||
.then(() => knex.schema.table(`${entityType}s`, table => {
|
||||
table.foreign('namespace').references('namespaces.id').onDelete('CASCADE');
|
||||
}));
|
||||
}
|
||||
|
||||
.then(() => knex.schema.table('lists', table => {
|
||||
table.integer('namespace').unsigned().notNullable();
|
||||
}))
|
||||
.then(() => knex('lists').update({
|
||||
namespace: 1
|
||||
}))
|
||||
.then(() => knex.schema.table('lists', table => {
|
||||
table.foreign('namespace').references('namespaces.id').onDelete('CASCADE');
|
||||
}))
|
||||
|
||||
.then(() => knex.schema.table('report_templates', table => {
|
||||
table.integer('namespace').unsigned().notNullable();
|
||||
}))
|
||||
.then(() => knex('report_templates').update({
|
||||
namespace: 1
|
||||
}))
|
||||
.then(() => knex.schema.table('report_templates', table => {
|
||||
table.foreign('namespace').references('namespaces.id').onDelete('CASCADE');
|
||||
}))
|
||||
|
||||
.then(() => knex.schema.table('reports', table => {
|
||||
table.integer('namespace').unsigned().notNullable();
|
||||
}))
|
||||
.then(() => knex('reports').update({
|
||||
namespace: 1
|
||||
}))
|
||||
.then(() => knex.schema.table('reports', table => {
|
||||
table.foreign('namespace').references('namespaces.id').onDelete('CASCADE');
|
||||
}))
|
||||
|
||||
;
|
||||
return schema;
|
||||
};
|
||||
|
||||
exports.down = function(knex, Promise) {
|
||||
|
|
|
@ -1,67 +1,44 @@
|
|||
const config = require('../config');
|
||||
const shareableEntityTypes = ['list', 'report', 'report_template', 'namespace'];
|
||||
|
||||
exports.up = function(knex, Promise) {
|
||||
return knex.schema.createTable('shares_list', table => {
|
||||
table.increments('id').primary();
|
||||
table.integer('entity').unsigned().notNullable().references('lists.id').onDelete('CASCADE');
|
||||
table.integer('user').unsigned().notNullable().references('users.id').onDelete('CASCADE');
|
||||
table.string('role', 64).notNullable();
|
||||
table.unique(['entity', 'user']);
|
||||
})
|
||||
let schema = knex.schema;
|
||||
|
||||
.createTable('permissions_list', table => {
|
||||
table.increments('id').primary();
|
||||
table.integer('entity').unsigned().notNullable().references('lists.id').onDelete('CASCADE');
|
||||
table.integer('user').unsigned().notNullable().references('users.id').onDelete('CASCADE');
|
||||
table.string('operation', 64).notNullable();
|
||||
table.unique(['entity', 'user', 'operation']);
|
||||
})
|
||||
for (const entityType of shareableEntityTypes) {
|
||||
schema = schema
|
||||
.createTable(`shares_${entityType}`, table => {
|
||||
table.increments('id').primary();
|
||||
table.integer('entity').unsigned().notNullable().references(`${entityType}s.id`).onDelete('CASCADE');
|
||||
table.integer('user').unsigned().notNullable().references('users.id').onDelete('CASCADE');
|
||||
table.string('role', 64).notNullable();
|
||||
table.unique(['entity', 'user']);
|
||||
})
|
||||
.createTable(`permissions_${entityType}`, table => {
|
||||
table.increments('id').primary();
|
||||
table.integer('entity').unsigned().notNullable().references(`${entityType}s.id`).onDelete('CASCADE');
|
||||
table.integer('user').unsigned().notNullable().references('users.id').onDelete('CASCADE');
|
||||
table.string('operation', 64).notNullable();
|
||||
table.unique(['entity', 'user', 'operation']);
|
||||
});
|
||||
}
|
||||
|
||||
.createTable('shares_report_template', table => {
|
||||
table.increments('id').primary();
|
||||
table.integer('entity').unsigned().notNullable().references('report_templates.id').onDelete('CASCADE');
|
||||
table.integer('user').unsigned().notNullable().references('users.id').onDelete('CASCADE');
|
||||
table.string('role', 64).notNullable();
|
||||
table.unique(['entity', 'user']);
|
||||
})
|
||||
|
||||
.createTable('permissions_report_template', table => {
|
||||
table.increments('id').primary();
|
||||
table.integer('entity').unsigned().notNullable().references('report_templates.id').onDelete('CASCADE');
|
||||
table.integer('user').unsigned().notNullable().references('users.id').onDelete('CASCADE');
|
||||
table.string('operation', 64).notNullable();
|
||||
table.unique(['entity', 'user', 'operation']);
|
||||
})
|
||||
|
||||
.createTable('shares_namespace', table => {
|
||||
table.increments('id').primary();
|
||||
table.integer('entity').unsigned().notNullable().references('namespaces.id').onDelete('CASCADE');
|
||||
table.integer('user').unsigned().notNullable().references('users.id').onDelete('CASCADE');
|
||||
table.string('role', 64).notNullable();
|
||||
table.unique(['entity', 'user']);
|
||||
})
|
||||
|
||||
.createTable('permissions_namespace', table => {
|
||||
table.increments('id').primary();
|
||||
table.integer('entity').unsigned().notNullable().references('namespaces.id').onDelete('CASCADE');
|
||||
table.integer('user').unsigned().notNullable().references('users.id').onDelete('CASCADE');
|
||||
table.string('operation', 64).notNullable();
|
||||
table.unique(['entity', 'user', 'operation']);
|
||||
})
|
||||
|
||||
.then(() => knex('shares_namespace').insert({
|
||||
schema = schema.then(() => knex('shares_namespace').insert({
|
||||
id: 1,
|
||||
entity: 1,
|
||||
user: 1,
|
||||
role: 'master'
|
||||
}))
|
||||
}));
|
||||
|
||||
;
|
||||
return schema;
|
||||
};
|
||||
|
||||
exports.down = function(knex, Promise) {
|
||||
return knex.schema.dropTable('shares_namespace')
|
||||
.dropTable('shares_list')
|
||||
.dropTable('permissions_namespace')
|
||||
.dropTable('permissions_list');
|
||||
let schema = knex.schema;
|
||||
|
||||
for (const entityType of shareableEntityTypes) {
|
||||
schema = schema
|
||||
.dropTable(`shares_${entityType}`)
|
||||
.dropTable(`permissions_${entityType}`);
|
||||
}
|
||||
|
||||
return schema;
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue