-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Author versus Admin views on puzzles #148
Author versus Admin views on puzzles #148
Conversation
Author and admin views are implemented for pages that show lists of puzzles - index, per-team status, and the map. The author view filters these lists, and also performs an access check before accessing the author/admin pages in the Puzzles folder. Along the way, I standardized the constructor for EventSpecificPageModel - but I didn't add every single access check we'll need in the other folders.
} | ||
|
||
public EventSpecificPageModel(PuzzleServerContext serverContext, UserManager<IdentityUser> manager) | ||
public async Task<bool> CanAdminPuzzle(Puzzle puzzle) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be handled through the authorization policy. Give me a little time now that I'm not visiting family and I'll get those changes merged in.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for checking in the authorization stuff - which parts of this can the authorization policy handle?
return NotFound(); | ||
} | ||
|
||
if (puzzle != null && !await CanAdminPuzzle(puzzle)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For example, in this case you'd have an attribute on the StatusModel page that's [Authorize(Policy = "IsEventAdminOrEventAuthor")]
The base class & child classes need an IAuthorizationService passed into the constructor (I believe asp.net handles getting that to them, it just needs to be requested).
Then to see if someone is the author of a puzzle you'd do a check against the policy:
bool isAuthorized = await AuthorizationService.AuthorizeAsync(User, "IsAuthorOfPuzzle"); (I don't have the exact syntax in front of me and we have people who just arrived for dinner, but if you can't find it let me know and I'll track it down after dinner)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see the example of an [Authorize] attribute on event create, and I see the example of AuthorizeAsync() in the link you provided - but this comment suggests that I need both at all times, and neither example appears to use both. Do I need to use both mechanisms at the same time, or do I choose only one at a time depending on need?
I think I've made all the changes; this is ready for re-review. Thanks! |
Author and admin views are implemented for pages that show lists of puzzles - index, per-team status, and the map. The author view filters these lists, and also performs an access check before accessing the author/admin pages in the Puzzles folder.
Along the way, I standardized the constructor for EventSpecificPageModel - but I didn't add every single access check we'll need in the other folders.