Skip to content
This repository has been archived by the owner on Nov 21, 2024. It is now read-only.

Commit

Permalink
feat(user.model): Add checkGroups method
Browse files Browse the repository at this point in the history
  • Loading branch information
EndyKaufman committed Jan 9, 2018
1 parent 22e4405 commit 7849399
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions libs/core/src/shared/models/user.model.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { BaseResourceModel } from './../base/models/base-resource.model';
import { translate } from './../common/utils';
import { Group } from './group.model';
import * as lodashImported from 'lodash'; const _ = lodashImported;

export class User extends BaseResourceModel {
static titles: any = {
Expand Down Expand Up @@ -119,6 +120,26 @@ export class User extends BaseResourceModel {
}
return false;
}
checkGroups(groupNames: string[]) {
const result = this.groups && this.groups.filter(
group => groupNames.filter(
groupName => _.camelCase(group.name).toLowerCase() === _.camelCase(groupName).toLowerCase()
).length > 0
).length > 0;
if (!result) {
groupNames = groupNames.map(groupName => {
return groupName
.replace(groupName.split('_')[0], 'manage');
});
return this.groups && this.groups.filter(
group => groupNames.filter(
groupName => _.camelCase(group.name).toLowerCase() === _.camelCase(groupName).toLowerCase()
).length > 0
).length > 0;
} else {
return result;
}
}
checkPermissions(permissionNames: string[]) {
if (this.fullAccess || this.checkRoles(permissionNames)) {
return true;
Expand Down

0 comments on commit 7849399

Please # to comment.