Skip to content

Commit

Permalink
refactor(authentication): team permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
kkopanidis committed Jun 13, 2023
1 parent b9d7fdc commit bd65692
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 9 deletions.
36 changes: 32 additions & 4 deletions modules/authentication/src/authz/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,39 @@ export const Team = new ConduitAuthorizedResource(
{
member: 'User',
owner: ['User', 'Team'],
readAll: ['User', 'Team'],
editAll: ['User', 'Team'],
},
{
read: ['member', 'owner->read', 'owner'],
edit: ['owner', 'owner->edit'],
delete: ['owner', 'owner->delete'],
invite: ['owner'],
read: [
'owner->manageSubTeams',
'owner',
'owner->viewSubTeams',
'readAll',
'owner->readAll',
'editAll',
'owner->editAll',
],
edit: ['owner', 'owner->manageSubTeams', 'editAll', 'owner->editAll'],
delete: ['owner', 'owner->manageSubTeams'],
invite: ['owner', 'editAll', 'owner->editAll'],
viewMembers: [
'member',
'owner',
'owner->viewMembers',
'readAll',
'owner->readAll',
'editAll',
'owner->editAll',
],
viewSubTeams: [
'owner->manageSubTeams',
'owner',
'readAll',
'owner->readAll',
'editAll',
'owner->editAll',
],
manageSubTeams: ['owner->manageSubTeams', 'owner', 'editAll', 'owner->editAll'],
},
);
11 changes: 6 additions & 5 deletions modules/authentication/src/handlers/team.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ export class TeamsHandler implements IAuthenticationStrategy {

const allowed = await this.grpcSdk.authorization!.can({
subject: 'User:' + user._id,
actions: ['read'],
actions: ['viewMembers'],
resource: 'Team:' + teamId,
});
if (!allowed.allow) {
Expand Down Expand Up @@ -330,12 +330,13 @@ export class TeamsHandler implements IAuthenticationStrategy {
async getTeam(call: ParsedRouterRequest): Promise<UnparsedRouterResponse> {
const { user } = call.request.context;
const { teamId, populate } = call.request.params;
const allowed = await this.grpcSdk.authorization!.can({
const relations = await this.grpcSdk.authorization!.findRelation({
subject: 'User:' + user._id,
actions: ['read'],
resource: 'Team:' + teamId,
skip: 0,
limit: 1,
});
if (!allowed.allow) {
if (!relations || relations.relations.length === 0) {
throw new GrpcError(
status.PERMISSION_DENIED,
'User does not have permission to view team',
Expand Down Expand Up @@ -383,7 +384,7 @@ export class TeamsHandler implements IAuthenticationStrategy {

const allowed = await this.grpcSdk.authorization!.can({
subject: 'User:' + user._id,
actions: ['read'],
actions: ['viewSubTeams'],
resource: 'Team:' + teamId,
});
if (!allowed.allow) {
Expand Down

0 comments on commit bd65692

Please sign in to comment.