-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1230 from jembi/Rework-roles-and-permissions
Rework roles and permissions
- Loading branch information
Showing
40 changed files
with
16,667 additions
and
1,948 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,36 @@ | ||
'use strict' | ||
|
||
import {ChannelModelAPI} from '../model/channels' | ||
import { RoleModelAPI } from '../model/role' | ||
|
||
export function inGroup(group, user) { | ||
return user.groups.indexOf(group) >= 0 | ||
} | ||
|
||
const getUserChannelsByPermissions = (user, allPermission, specifiedPermission) => | ||
RoleModelAPI.find({name: {$in: user.groups}}).then(roles => { | ||
if (roles.find(role => role.permissions[allPermission] || role.permissions[allPermission.replace('view', 'manage')])) { | ||
return ChannelModelAPI.find({}).exec() | ||
} | ||
const specifiedChannels = roles.reduce((prev, curr) => | ||
prev.concat(curr.permissions[specifiedPermission], curr.permissions[specifiedPermission.replace('view', 'manage')]), | ||
[] | ||
) | ||
return ChannelModelAPI.find({_id: {$in: specifiedChannels}}).exec() | ||
}) | ||
|
||
/** | ||
* A promise returning function that returns the list | ||
* of viewable channels for a user. | ||
*/ | ||
export function getUserViewableChannels(user, access = 'txViewAcl') { | ||
// if admin find all channels | ||
if (inGroup('admin', user)) { | ||
return ChannelModelAPI.find({}).exec() | ||
} else { | ||
// otherwise only channels that this user has access to | ||
return ChannelModelAPI.find({[access]: {$in: user.groups}}).exec() | ||
} | ||
export function getUserViewableChannels(user) { | ||
return getUserChannelsByPermissions(user, 'channel-view-all', 'channel-view-specified') | ||
} | ||
|
||
/** | ||
* A promise returning function that returns the list | ||
* of rerunnable channels for a user. | ||
*/ | ||
export function getUserRerunableChannels(user) { | ||
// if admin allow all channel | ||
if (inGroup('admin', user)) { | ||
return ChannelModelAPI.find({}).exec() | ||
} else { | ||
// otherwise figure out what this user can rerun | ||
return ChannelModelAPI.find({txRerunAcl: {$in: user.groups}}).exec() | ||
} | ||
return getUserChannelsByPermissions(user, 'transaction-rerun-all', 'transaction-rerun-specified') | ||
} |
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.