Skip to content
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

Merged
merged 6 commits into from
Jan 13, 2019

Conversation

tabascq
Copy link
Contributor

@tabascq tabascq commented Dec 23, 2018

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.

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)
Copy link
Collaborator

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.

Copy link
Contributor Author

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))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://docs.microsoft.com/en-us/aspnet/core/security/authorization/views?view=aspnetcore-2.2&tabs=aspnetcore2x

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)

Copy link
Contributor Author

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?

@tabascq
Copy link
Contributor Author

tabascq commented Jan 13, 2019

I think I've made all the changes; this is ready for re-review. Thanks!

ServerCore/Pages/Events/Map.cshtml.cs Outdated Show resolved Hide resolved
ServerCore/Pages/Puzzles/Edit.cshtml.cs Outdated Show resolved Hide resolved
ServerCore/Pages/Teams/Status.cshtml.cs Outdated Show resolved Hide resolved
@tabascq tabascq merged commit 5bed424 into PuzzleServer:master Jan 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants