-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 2721012
Showing
24 changed files
with
752 additions
and
0 deletions.
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,12 @@ | ||
root = true | ||
|
||
[*] | ||
indent_style = space | ||
indent_size = 2 | ||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
|
||
[*.md] | ||
trim_trailing_whitespace = false |
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,67 @@ | ||
# Created by https://www.gitignore.io/api/node | ||
|
||
### Node ### | ||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
*.pid.lock | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
|
||
# nyc test coverage | ||
.nyc_output | ||
|
||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# Bower dependency directory (https://bower.io/) | ||
bower_components | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (http://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directories | ||
node_modules/ | ||
jspm_packages/ | ||
|
||
# Typescript v1 declaration files | ||
typings/ | ||
|
||
# Optional npm cache directory | ||
.npm | ||
|
||
# Optional eslint cache | ||
.eslintcache | ||
|
||
# Optional REPL history | ||
.node_repl_history | ||
|
||
# Output of 'npm pack' | ||
*.tgz | ||
|
||
# Yarn Integrity file | ||
.yarn-integrity | ||
|
||
# Yarn lock file | ||
yarn.lock | ||
|
||
# dotenv environment variables file | ||
.env | ||
|
||
|
||
# End of https://www.gitignore.io/api/node |
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,7 @@ | ||
node_modules | ||
npm-debug.log | ||
yarn-debug.log | ||
yarn-error.log | ||
yarn.lock | ||
.travis.yml | ||
.editorconfig |
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,9 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2017 Evgeny Razumov | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
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,19 @@ | ||
# Adonis ACL | ||
|
||
Adonis ACL adds role based permissions to built in Auth System of Adonis Framework. | ||
|
||
## Documentation | ||
|
||
Follow along the [Wiki](https://github.com/enniel/adonis-acl/wiki) to find out more. | ||
|
||
## Credits | ||
|
||
- [Evgeni Razumov](https://github.com/enniel) | ||
|
||
## Support | ||
|
||
Having trouble? [Open an issue](https://github.com/enniel/adonis-acl/issues/new)! | ||
|
||
## License | ||
|
||
The MIT License (MIT). Please see [License File](LICENSE.md) for more information. |
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,51 @@ | ||
'use strict' | ||
|
||
const Ioc = require('adonis-fold').Ioc | ||
const Command = Ioc.use('Adonis/Src/Command') | ||
const Permission = Ioc.use('Adonis/Acl/Permission') | ||
const Database = Ioc.use('Adonis/Src/Database') | ||
|
||
class PermissionCommand extends Command { | ||
/** | ||
* signature defines the requirements and name | ||
* of command. | ||
* | ||
* @return {String} | ||
*/ | ||
get signature () { | ||
return 'acl:permission {slug} {name?} {description?}' | ||
} | ||
|
||
/** | ||
* description is the little helpful information displayed | ||
* on the console. | ||
* | ||
* @return {String} | ||
*/ | ||
get description () { | ||
return 'Create or update permission' | ||
} | ||
|
||
/** | ||
* handle method is invoked automatically by ace, once your | ||
* command has been executed. | ||
* | ||
* @param {Object} args [description] | ||
* @param {Object} options [description] | ||
*/ | ||
* handle ({ slug, name, description }, { permissions }) { | ||
name = name || slug | ||
let permission = yield Permission.query().where('slug', slug).first() | ||
if (!permission) { | ||
permission = new Permission({ slug }) | ||
} | ||
permission.fill({ | ||
name, description | ||
}) | ||
yield permission.save() | ||
this.success(`${this.icon('success')} permission ${name} is updated.`) | ||
Database.close() | ||
} | ||
} | ||
|
||
module.exports = PermissionCommand |
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,73 @@ | ||
'use strict' | ||
|
||
const Ioc = require('adonis-fold').Ioc | ||
const Command = Ioc.use('Adonis/Src/Command') | ||
const Role = Ioc.use('Adonis/Acl/Role') | ||
const Permission = Ioc.use('Adonis/Acl/Permission') | ||
const Database = Ioc.use('Adonis/Src/Database') | ||
const series = require('co-series') | ||
const _ = require('lodash') | ||
|
||
class RoleCommand extends Command { | ||
/** | ||
* signature defines the requirements and name | ||
* of command. | ||
* | ||
* @return {String} | ||
*/ | ||
get signature () { | ||
return 'acl:role {slug} {name?} {description?} {--permissions=@value}' | ||
} | ||
|
||
/** | ||
* description is the little helpful information displayed | ||
* on the console. | ||
* | ||
* @return {String} | ||
*/ | ||
get description () { | ||
return 'Create or update role' | ||
} | ||
|
||
/** | ||
* handle method is invoked automatically by ace, once your | ||
* command has been executed. | ||
* | ||
* @param {Object} args [description] | ||
* @param {Object} options [description] | ||
*/ | ||
* handle ({ slug, name, description }, { permissions }) { | ||
name = name || slug | ||
let role = yield Role.query().where('slug', slug).first() | ||
if (!role) { | ||
role = new Role({ slug }) | ||
} | ||
role.fill({ | ||
name, description | ||
}) | ||
yield role.save() | ||
permissions = _.reduce(_.split(permissions, ','), (result, permission) => { | ||
permission = _.trim(permission) | ||
if (permission.length) { | ||
result.push(permission) | ||
} | ||
return result | ||
}, []) | ||
permissions = yield _.map(permissions, series(function * (permission) { | ||
let entry = yield Permission.query().where('slug', permission).first() | ||
if (!entry) { | ||
entry = yield Permission.create({ | ||
slug: permission, name: permission | ||
}) | ||
} | ||
return entry.id | ||
})) | ||
if (permissions.length) { | ||
yield role.permissions().sync(permissions) | ||
} | ||
this.success(`${this.icon('success')} role ${name} is updated.`) | ||
Database.close() | ||
} | ||
} | ||
|
||
module.exports = RoleCommand |
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,42 @@ | ||
'use strict' | ||
|
||
/** | ||
* adonis-acl | ||
* Copyright(c) 2017 Evgeny Razumov | ||
* MIT Licensed | ||
*/ | ||
|
||
const Ace = require('adonis-ace') | ||
const Ioc = require('adonis-fold').Ioc | ||
const path = require('path') | ||
const Command = Ioc.use('Adonis/Src/Command') | ||
|
||
class SetupCommand extends Command { | ||
get signature () { | ||
return 'acl:setup' | ||
} | ||
|
||
get description () { | ||
return 'Setup migration for ACL' | ||
} | ||
|
||
* handle () { | ||
yield Ace.call('make:migration', ['create_roles_table'], { | ||
template: path.join(__dirname, './templates/roles_schema.mustache') | ||
}) | ||
yield Ace.call('make:migration', ['create_permissions_table'], { | ||
template: path.join(__dirname, './templates/permissions_schema.mustache') | ||
}) | ||
yield Ace.call('make:migration', ['create_role_user_table'], { | ||
template: path.join(__dirname, './templates/role_user_schema.mustache') | ||
}) | ||
yield Ace.call('make:migration', ['create_permission_role_table'], { | ||
template: path.join(__dirname, './templates/permission_role_schema.mustache') | ||
}) | ||
yield Ace.call('make:migration', ['create_permission_user_table'], { | ||
template: path.join(__dirname, './templates/permission_user_schema.mustache') | ||
}) | ||
} | ||
} | ||
|
||
module.exports = SetupCommand |
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,24 @@ | ||
'use strict' | ||
|
||
const Schema = use('Schema') | ||
|
||
class PermissionRoleTableSchema extends Schema { | ||
up () { | ||
this.create('permission_role', table => { | ||
table.increments() | ||
table.integer('permission_id').unsigned().index() | ||
table.foreign('permission_id').references('id').on('permissions').onDelete('cascade') | ||
table.integer('role_id').unsigned().index() | ||
table.foreign('role_id').references('id').on('roles').onDelete('cascade') | ||
table.timestamps() | ||
}) | ||
} | ||
|
||
down () { | ||
this.drop('permission_role') | ||
} | ||
|
||
} | ||
|
||
module.exports = PermissionRoleTableSchema |
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,24 @@ | ||
'use strict' | ||
|
||
const Schema = use('Schema') | ||
|
||
class PermissionUserTableSchema extends Schema { | ||
up () { | ||
this.create('permission_user', table => { | ||
table.increments() | ||
table.integer('permission_id').unsigned().index() | ||
table.foreign('permission_id').references('id').on('permissions').onDelete('cascade') | ||
table.integer('user_id').unsigned().index() | ||
table.foreign('user_id').references('id').on('users').onDelete('cascade') | ||
table.timestamps() | ||
}) | ||
} | ||
|
||
down () { | ||
this.drop('permission_user') | ||
} | ||
|
||
} | ||
|
||
module.exports = PermissionUserTableSchema |
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,23 @@ | ||
'use strict' | ||
|
||
const Schema = use('Schema') | ||
|
||
class PermissionsTableSchema extends Schema { | ||
up () { | ||
this.create('permissions', table => { | ||
table.increments() | ||
table.string('slug').notNullable().unique() | ||
table.string('name').notNullable().unique() | ||
table.text('description').nullable() | ||
table.timestamps() | ||
}) | ||
} | ||
|
||
down () { | ||
this.drop('permissions') | ||
} | ||
|
||
} | ||
|
||
module.exports = PermissionsTableSchema |
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,24 @@ | ||
'use strict' | ||
|
||
const Schema = use('Schema') | ||
|
||
class RoleUserTableSchema extends Schema { | ||
up () { | ||
this.create('role_user', table => { | ||
table.increments() | ||
table.integer('role_id').unsigned().index() | ||
table.foreign('role_id').references('id').on('roles').onDelete('cascade') | ||
table.integer('user_id').unsigned().index() | ||
table.foreign('user_id').references('id').on('users').onDelete('cascade') | ||
table.timestamps() | ||
}) | ||
} | ||
|
||
down () { | ||
this.drop('role_user') | ||
} | ||
|
||
} | ||
|
||
module.exports = RoleUserTableSchema |
Oops, something went wrong.