mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 21:00:31 +00:00
WIP Roles and permissions access control.
This commit is contained in:
@@ -20,7 +20,7 @@ const Account = bookshelf.Model.extend({
|
||||
|
||||
balances() {
|
||||
return this.hasMany('AccountBalance', 'accounnt_id');
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
export default bookshelf.model('Account', Account);
|
||||
|
||||
@@ -12,9 +12,7 @@ const AccountBalance = bookshelf.Model.extend({
|
||||
*/
|
||||
hasTimestamps: false,
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
|
||||
account() {
|
||||
return this.belongsTo('Account', 'account_id');
|
||||
},
|
||||
|
||||
25
server/src/models/Permission.js
Normal file
25
server/src/models/Permission.js
Normal file
@@ -0,0 +1,25 @@
|
||||
import bookshelf from './bookshelf';
|
||||
|
||||
const Permission = bookshelf.Model.extend({
|
||||
|
||||
/**
|
||||
* Table name of Role model.
|
||||
* @type {String}
|
||||
*/
|
||||
tableName: 'permissions',
|
||||
|
||||
/**
|
||||
* Timestamp columns.
|
||||
*/
|
||||
hasTimestamps: false,
|
||||
|
||||
role() {
|
||||
return this.belongsTo('Role', 'role_id');
|
||||
},
|
||||
|
||||
resource() {
|
||||
return this.belongsTo('Resource', 'resource_id');
|
||||
},
|
||||
});
|
||||
|
||||
export default bookshelf.model('Permission', Permission);
|
||||
21
server/src/models/Resource.js
Normal file
21
server/src/models/Resource.js
Normal file
@@ -0,0 +1,21 @@
|
||||
import bookshelf from './bookshelf';
|
||||
|
||||
const Resource = bookshelf.Model.extend({
|
||||
/**
|
||||
* Table name.
|
||||
*/
|
||||
tableName: 'resources',
|
||||
|
||||
/**
|
||||
* Timestamp columns.
|
||||
*/
|
||||
hasTimestamps: false,
|
||||
|
||||
permissions() {
|
||||
},
|
||||
|
||||
roles() {
|
||||
},
|
||||
});
|
||||
|
||||
export default bookshelf.model('Resource', Resource);
|
||||
@@ -20,11 +20,18 @@ const Role = bookshelf.Model.extend({
|
||||
return this.belongsToMany('Permission', 'role_has_permissions', 'role_id', 'permission_id');
|
||||
},
|
||||
|
||||
/**
|
||||
* Role may has many resources.
|
||||
*/
|
||||
resources() {
|
||||
return this.belongsToMany('Resource', 'role_has_permissions', 'role_id', 'resource_id');
|
||||
},
|
||||
|
||||
/**
|
||||
* Role model may has many users.
|
||||
*/
|
||||
users() {
|
||||
return this.belongsTo('User');
|
||||
return this.belongsToMany('User', 'user_has_roles');
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -21,6 +21,13 @@ const User = bookshelf.Model.extend({
|
||||
verifyPassword(password) {
|
||||
return bcrypt.compareSync(password, this.get('password'));
|
||||
},
|
||||
|
||||
/**
|
||||
* User model may has many associated roles.
|
||||
*/
|
||||
roles() {
|
||||
return this.belongsToMany('Role', 'user_has_roles', 'user_id', 'role_id');
|
||||
},
|
||||
});
|
||||
|
||||
export default bookshelf.model('User', User);
|
||||
|
||||
Reference in New Issue
Block a user