-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(general): added permissions model
- Loading branch information
1 parent
0630881
commit 7825467
Showing
5 changed files
with
159 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
module.exports = { | ||
up: (queryInterface, Sequelize) => queryInterface.createTable('permissions', { | ||
id: { | ||
allowNull: false, | ||
autoIncrement: true, | ||
primaryKey: true, | ||
type: Sequelize.INTEGER | ||
}, | ||
scope: { | ||
type: Sequelize.STRING, | ||
allowNull: false | ||
}, | ||
action: { | ||
type: Sequelize.STRING, | ||
allowNull: false | ||
}, | ||
object: { | ||
type: Sequelize.STRING, | ||
allowNull: false | ||
}, | ||
combined: { | ||
type: Sequelize.STRING, | ||
allowNull: false | ||
}, | ||
description: { | ||
type: Sequelize.TEXT, | ||
allowNull: false | ||
}, | ||
filters: { | ||
type: Sequelize.ARRAY(Sequelize.STRING), | ||
allowNull: false, | ||
defaultValue: [] | ||
}, | ||
created_at: { | ||
allowNull: false, | ||
type: Sequelize.DATE | ||
}, | ||
updated_at: { | ||
allowNull: false, | ||
type: Sequelize.DATE | ||
} | ||
}), | ||
down: (queryInterface) => queryInterface.dropTable('permissions') | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
module.exports = { | ||
up: (queryInterface, Sequelize) => queryInterface.createTable('circle_permissions', { | ||
id: { | ||
allowNull: false, | ||
autoIncrement: true, | ||
primaryKey: true, | ||
type: Sequelize.INTEGER | ||
}, | ||
circle_id: { | ||
type: Sequelize.INTEGER, | ||
allowNull: false, | ||
references: { | ||
model: 'circles', | ||
key: 'id' | ||
} | ||
}, | ||
permission_id: { | ||
type: Sequelize.INTEGER, | ||
allowNull: false, | ||
references: { | ||
model: 'permissions', | ||
key: 'id' | ||
} | ||
}, | ||
created_at: { | ||
allowNull: false, | ||
type: Sequelize.DATE | ||
}, | ||
updated_at: { | ||
allowNull: false, | ||
type: Sequelize.DATE | ||
} | ||
}), | ||
down: (queryInterface) => queryInterface.dropTable('circle_permissions') | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
const { sequelize } = require('../lib/sequelize'); | ||
|
||
const CirclePermission = sequelize.define('circle_permission', {}, { | ||
underscored: true, | ||
tableName: 'circle_permissions', | ||
createdAt: 'created_at', | ||
updatedAt: 'updated_at', | ||
}); | ||
|
||
module.exports = CirclePermission; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
const { Sequelize, sequelize } = require('../lib/sequelize'); | ||
|
||
const Permission = sequelize.define('permission', { | ||
scope: { | ||
type: Sequelize.ENUM('global', 'global'), | ||
allowNull: false, | ||
defaultValue: '', | ||
validate: { | ||
isIn: { | ||
args: [['global', 'local']], | ||
msg: 'Permission scope should be one of these: "global", "local".' | ||
} | ||
} | ||
}, | ||
action: { | ||
type: Sequelize.STRING, | ||
allowNull: false, | ||
defaultValue: '', | ||
validate: { | ||
notEmpty: { msg: 'Action should be set.' }, | ||
}, | ||
}, | ||
object: { | ||
type: Sequelize.STRING, | ||
allowNull: false, | ||
defaultValue: '', | ||
validate: { | ||
notEmpty: { msg: 'Object should be set.' }, | ||
}, | ||
}, | ||
combined: { | ||
type: Sequelize.STRING, | ||
allowNull: true | ||
}, | ||
description: { | ||
type: Sequelize.STRING, | ||
allowNull: false, | ||
defaultValue: '', | ||
validate: { | ||
notEmpty: { msg: 'Description should be set.' }, | ||
}, | ||
}, | ||
filters: { | ||
type: Sequelize.ARRAY(Sequelize.STRING), | ||
allowNull: false, | ||
defaultValue: [] | ||
} | ||
}, { | ||
underscored: true, | ||
tableName: 'permissions', | ||
createdAt: 'created_at', | ||
updatedAt: 'updated_at', | ||
}); | ||
|
||
Permission.afterValidate((permission) => { | ||
permission.combined = [ | ||
permission.scope, | ||
permission.action, | ||
permission.object | ||
].join(':'); | ||
}); | ||
|
||
module.exports = Permission; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters