C
C#2y ago
Angius

❔ Ownership-based permission system...?

So, in my ASP.NET 7 app I have a system of user clubs. Each club can have a founder and members, and each member can also be a mod for that community. The roles of a founder and moderator are represented as an enum on the join table. Now, I want to restrict some stuff to given roles. Like, only the founder can edit the settings of the club, and only the moderators or founders can kick or ban users. And you need to be a member to post there, etc. Currently, I just add one more .Where() to each query that checks for the given role, but maybe there's some better solution? Some middleware or something that'd let me just slap [Authorize(PolicyNames.ClubFounder)] onto a controller and be done with it?
6 Replies
Angius
AngiusOP2y ago
Sure, for the users of my app it might make sense But they're the users of my app first, and then members of their respective clubs within that app So the clubs are kinda-sorta multi-tenant thingamajig...?
ChucklesTheBeard
RBAC (role based access control) lets you specify [Authorize(Roles = "Admin")] in the controller https://learn.microsoft.com/en-us/aspnet/core/security/authorization/roles?view=aspnetcore-5.0&preserve-view=true#adding-role-checks
Role-based authorization in ASP.NET Core
Learn how to restrict ASP.NET Core controller and action access by passing roles to the Authorize attribute.
Angius
AngiusOP2y ago
Yeah, for the built-in Identity roles Where each user has a role within my app Thing is, users can have roles within my app, and within their clubs So the user can be a Moderator of a "Fizzy Pickle Juice Fanclub", but that doesn't mean they're the moderator of "Spoiled Milk Sucks", let alone the moderator of my site
ChucklesTheBeard
Ah, hmm.
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server