fix: page rules role check (#1447)

* Check rule.roles against permissions

* Added Role Check to EXACT matching

* Code Review Fixes
This commit is contained in:
BobbyB 2020-02-07 14:26:13 -05:00 committed by GitHub
parent a694d26290
commit 7d23344c7a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -173,39 +173,41 @@ module.exports = {
user.groups.forEach(grp => { user.groups.forEach(grp => {
const grpId = _.isObject(grp) ? _.get(grp, 'id', 0) : grp const grpId = _.isObject(grp) ? _.get(grp, 'id', 0) : grp
_.get(WIKI.auth.groups, `${grpId}.pageRules`, []).forEach(rule => { _.get(WIKI.auth.groups, `${grpId}.pageRules`, []).forEach(rule => {
switch (rule.match) { if(_.intersection(rule.roles, permissions).length > 0) {
case 'START': switch (rule.match) {
if (_.startsWith(`/${page.path}`, `/${rule.path}`)) { case 'START':
checkState = this._applyPageRuleSpecificity({ rule, checkState, higherPriority: ['END', 'REGEX', 'EXACT', 'TAG'] }) if (_.startsWith(`/${page.path}`, `/${rule.path}`)) {
} checkState = this._applyPageRuleSpecificity({ rule, checkState, higherPriority: ['END', 'REGEX', 'EXACT', 'TAG'] })
break
case 'END':
if (_.endsWith(page.path, rule.path)) {
checkState = this._applyPageRuleSpecificity({ rule, checkState, higherPriority: ['REGEX', 'EXACT', 'TAG'] })
}
break
case 'REGEX':
const reg = new RegExp(rule.path)
if (reg.test(page.path)) {
checkState = this._applyPageRuleSpecificity({ rule, checkState, higherPriority: ['EXACT', 'TAG'] })
}
break
case 'TAG':
_.get(page, 'tags', []).forEach(tag => {
if (tag.tag === rule.path) {
checkState = this._applyPageRuleSpecificity({
rule,
checkState,
higherPriority: ['EXACT']
})
} }
}) break
break case 'END':
case 'EXACT': if (_.endsWith(page.path, rule.path)) {
if (`/${page.path}` === `/${rule.path}`) { checkState = this._applyPageRuleSpecificity({ rule, checkState, higherPriority: ['REGEX', 'EXACT', 'TAG'] })
checkState = this._applyPageRuleSpecificity({ rule, checkState, higherPriority: [] }) }
} break
break case 'REGEX':
const reg = new RegExp(rule.path)
if (reg.test(page.path)) {
checkState = this._applyPageRuleSpecificity({ rule, checkState, higherPriority: ['EXACT', 'TAG'] })
}
break
case 'TAG':
_.get(page, 'tags', []).forEach(tag => {
if (tag.tag === rule.path) {
checkState = this._applyPageRuleSpecificity({
rule,
checkState,
higherPriority: ['EXACT']
})
}
})
break
case 'EXACT':
if (`/${page.path}` === `/${rule.path}`) {
checkState = this._applyPageRuleSpecificity({ rule, checkState, higherPriority: [] })
}
break
}
} }
}) })
}) })