-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enhancement: merge abe users into core
- Loading branch information
nicolaslabbe
committed
Nov 23, 2016
1 parent
20c0d7d
commit 38e5c73
Showing
30 changed files
with
525 additions
and
285 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,37 @@ | ||
# Abe handlebars helpers | ||
|
||
> Is user authorized for an action | ||
### Example | ||
|
||
if user authorized to call url `/abe/deleteAll` show button delete | ||
|
||
{{#isAuthorized '/abe/deleteAll' @root.user.role.workflow}} | ||
<div> | ||
I can delete everything ! | ||
</div> | ||
{{/isAuthorized}} | ||
|
||
### Example of config into abe.json | ||
|
||
```json | ||
{ | ||
"users": { | ||
"roles": [ | ||
{ | ||
"workflow":"CustomUser", | ||
"name":"CustomUser" | ||
} | ||
{ | ||
"workflow":"admin", | ||
"name":"Admin" | ||
} | ||
], | ||
"routes": { | ||
"admin": [], | ||
"CustomUser": [ | ||
"\/abe\/deleteAll.*" | ||
], | ||
``` | ||
|
||
Because **CustomUser** has an entry with `\/abe\/deleteAll.*` he would not be allowed to call |
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
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
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,5 @@ | ||
export default function concat() { | ||
var arg = Array.prototype.slice.call(arguments,0) | ||
arg.pop() | ||
return arg.join('') | ||
} |
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
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,30 @@ | ||
import Cookies from 'cookies' | ||
import jwt from 'jwt-simple' | ||
|
||
import { | ||
config, | ||
User | ||
} from '../../../' | ||
|
||
/** | ||
* Handlebars helper, to print className and escape it string | ||
*/ | ||
export default function isAuthorized(route, role, ctx) { | ||
var isAuthorized = true | ||
|
||
if (config.users.enable) { | ||
var allowedRoutes = User.getUserRoutes(role) | ||
Array.prototype.forEach.call(allowedRoutes, (allowedRoute) => { | ||
var reg = new RegExp(allowedRoute) | ||
if (reg.test(route)) { | ||
isAuthorized = false | ||
} | ||
}) | ||
} | ||
|
||
if (isAuthorized) { | ||
return ctx.fn(this) | ||
}else { | ||
return ctx.inverse(this) | ||
} | ||
} |
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
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
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
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
Oops, something went wrong.