-
-
Notifications
You must be signed in to change notification settings - Fork 931
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): Allow Roles to be created in other channels
Relates to #12
- Loading branch information
1 parent
6fc421a
commit df5f006
Showing
11 changed files
with
267 additions
and
76 deletions.
There are no files selected for viewing
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
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
38 changes: 38 additions & 0 deletions
38
packages/core/src/service/helpers/utils/get-user-channels-permissions.ts
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { Permission } from '@vendure/common/lib/generated-types'; | ||
import { ID } from '@vendure/common/lib/shared-types'; | ||
import { unique } from '@vendure/common/lib/unique'; | ||
|
||
import { User } from '../../../entity/user/user.entity'; | ||
|
||
export interface UserChannelPermissions { | ||
id: ID; | ||
token: string; | ||
code: string; | ||
permissions: Permission[]; | ||
} | ||
|
||
/** | ||
* Returns an array of Channels and permissions on those Channels for the given User. | ||
*/ | ||
export function getUserChannelsPermissions(user: User): UserChannelPermissions[] { | ||
const channelsMap: { [code: string]: UserChannelPermissions } = {}; | ||
|
||
for (const role of user.roles) { | ||
for (const channel of role.channels) { | ||
if (!channelsMap[channel.code]) { | ||
channelsMap[channel.code] = { | ||
id: channel.id, | ||
token: channel.token, | ||
code: channel.code, | ||
permissions: [], | ||
}; | ||
} | ||
channelsMap[channel.code].permissions = unique([ | ||
...channelsMap[channel.code].permissions, | ||
...role.permissions, | ||
]); | ||
} | ||
} | ||
|
||
return Object.values(channelsMap); | ||
} |
Oops, something went wrong.