Skip to content

Commit

Permalink
feat: Added read role for reading specific endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
aleklundeq authored Sep 8, 2023
1 parent 2fa6c9b commit 2aabb06
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static IAuthorizationRequirementRule FullControlExternal(this IAuthorizat
return builder;
}

public static IAuthorizationRequirementRule GlobalRoleAccess(this IAuthorizationRequirementRule builder, params string[] roles)
public static IAuthorizationRequirementRule GlobalRoleAccess(this IAuthorizationRequirementRule builder, params string[] roles)
{
return builder.AddRule(new GlobalRoleRequirement(roles));
}
Expand Down Expand Up @@ -152,6 +152,17 @@ public static IAuthorizationRequirementRule FullControl(this IAuthorizationRequi
return builder;
}

public static IAuthorizationRequirementRule ResourcesRead(this IAuthorizationRequirementRule builder)
{
var policy = new AuthorizationPolicyBuilder()
.RequireAssertion(c => c.User.IsInRole("Fusion.Resources.Read"))
.Build();

builder.AddRule((auth, user) => auth.AuthorizeAsync(user, policy));

return builder;
}

public static IAuthorizationRequirementRule CurrentUserIs(this IAuthorizationRequirementRule builder, PersonIdentifier personIdentifier)
{
builder.AddRule(new CurrentUserIsRequirement(personIdentifier));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,7 @@ public async Task<ActionResult<ApiCollection<ApiResourceAllocationRequest>>> Get
);
or.HaveOrgUnitScopedRole(DepartmentId.FromFullPath(departmentString), AccessRoles.ResourceOwner);
}
or.ResourcesRead();
});
});

Expand Down

0 comments on commit 2aabb06

Please sign in to comment.