Completed
Pull Request — master (#40)
by
unknown
02:53
created

src/cli/cms/templates/handlebars/isAuthorized.js   A

Complexity

Total Complexity 5
Complexity/F 2.5

Size

Lines of Code 27
Function Count 2

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 0
wmc 5
nc 1
mnd 2
bc 6
fnc 2
dl 0
loc 27
rs 10
bpm 3
cpm 2.5
noi 0
c 1
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A isAuthorized.js ➔ isAuthorized 0 19 3
1
import {
2
  config,
3
	User
4
} from '../../../'
5
6
/**
7
 * Handlebars helper, to print className and escape it string
8
 */
9
export default function isAuthorized(route, role, ctx) {
10
  var isAuthorized = true
11
12
  if (config.users.enable) {
13
    var allowedRoutes = User.utils.getUserRoutes(role)
14
    Array.prototype.forEach.call(allowedRoutes, (allowedRoute) => {
15
      var reg = new RegExp(allowedRoute)
16
      if (reg.test(route)) {
17
        isAuthorized = false
18
      }
19
    })
20
  }
21
22
  if (isAuthorized) {
23
    return ctx.fn(this)
24
  }else {
25
    return ctx.inverse(this)
26
  }
27
}
28