Skip to content

Commit

Permalink
fix: bug printInput isAuthorized
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolaslabbe committed Nov 25, 2016
1 parent 2d89cf9 commit cf43231
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 21 deletions.
6 changes: 3 additions & 3 deletions src/cli/cms/editor/handlebars/printBlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export default function printBlock (ctx, root) {
res += printInput(ctx[0], root)
}

var template = cmsTemplates.Handlebars.compile(res)
return new cmsTemplates.Handlebars.SafeString(template(ctx, {data: {intl: config.intlData}}))
// return res
// var template = cmsTemplates.Handlebars.compile(res)
// return new cmsTemplates.Handlebars.SafeString(template(ctx, {data: {intl: config.intlData}}))
return res
}
6 changes: 5 additions & 1 deletion src/cli/cms/editor/handlebars/printInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import sourceAutocomplete from './sourceAutocomplete'
import sourceOption from './sourceOption'
import {
abeExtend
,User
} from '../../../'

/**
Expand Down Expand Up @@ -37,7 +38,10 @@ export default function printInput (params, root) {
userWorkflow = root.user.role.workflow
}

var disabled = `{{#isAuthorized '/abe/save/${params.status}/edit' "${userWorkflow}"}}{{else}}disabled="disabled"{{/isAuthorized}}"`
var disabled = ''
if (!User.utils.isUserAllowedOnRoute(userWorkflow, `/abe/save/${params.status}/edit`)) {
disabled = 'disabled="disabled"'
}
if (params.tab == 'slug') {
disabled = ''
}
Expand Down
36 changes: 20 additions & 16 deletions src/cli/users/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,26 +204,30 @@ export function isAbeRestrictedUrl(currentRoute) {
}

export function isUserAllowedOnRoute(workflow, currentRoute) {
if( currentRoute.indexOf('/abe/users/forgot') > -1 || currentRoute.indexOf('/abe/users/login') > -1 || !/^\/abe/.test(currentRoute)) {
return true
}

var isAllowed = false

if (currentRoute.indexOf('abe/') === -1) {
isAllowed = true
}
if (config.users.enable) {
if( currentRoute.indexOf('/abe/users/forgot') > -1 || currentRoute.indexOf('/abe/users/login') > -1 || !/^\/abe/.test(currentRoute)) {
return true
}

if (workflow != null) {
var routes = config.users.routes
if(typeof routes[workflow] !== 'undefined' && routes[workflow] !== null) {
Array.prototype.forEach.call(routes[workflow], (route) => {
var reg = new RegExp(route)
if(reg.test(currentRoute)) {
isAllowed = true
}
})
if (currentRoute.indexOf('abe/') === -1) {
isAllowed = true
}

if (workflow != null) {
var routes = config.users.routes
if(typeof routes[workflow] !== 'undefined' && routes[workflow] !== null) {
Array.prototype.forEach.call(routes[workflow], (route) => {
var reg = new RegExp(route)
if(reg.test(currentRoute)) {
isAllowed = true
}
})
}
}
}else {
isAllowed = true
}

return isAllowed
Expand Down
2 changes: 1 addition & 1 deletion src/server/views/partials/menu-left.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ <h1><small>{{@root.text.site}}</small></h1>
{{/if}}
{{#isAuthorized '/abe/list-url' @root.user.role.workflow}}
<li class="list-group-item pointer">
<a href="/abe/list-url">Admin url list</a>
<a href="/abe/list-url">User roles</a>
</li>
{{/isAuthorized}}
{{abeImport 'menu-left-addons' manager.config this}}
Expand Down

0 comments on commit cf43231

Please sign in to comment.