Abstracting permissions with Yesod

Hello, everyone! I'm going to try creating a blog and my first post is dedicated to how I am writing my isAuthorized function: http://blog.felipe.lessa.nom.br/?p=7 I'd be thrilled if you could tell me if you like the idea! Something similar could be done on Yesod 0.10, either on yesod-core or on the scaffold. I didn't try writing some generic code yet because I'd like to gather comments here first. Cheers, =) -- Felipe.

On Mon, Jan 16, 2012 at 2:14 PM, Felipe Almeida Lessa
Hello, everyone!
I'm going to try creating a blog and my first post is dedicated to how I am writing my isAuthorized function:
http://blog.felipe.lessa.nom.br/?p=7
I'd be thrilled if you could tell me if you like the idea! Something similar could be done on Yesod 0.10, either on yesod-core or on the scaffold. I didn't try writing some generic code yet because I'd like to gather comments here first.
Cheers, =)
-- Felipe.
I like it. I could imagine a setup like this: class YesodPermissions master where data Permission master hasPermissionTo :: ... ... isAuthorizedPermissions :: YesodPermissions master => Route master -> Bool -> GHandler sub master AuthorizationResult It could sit next to YesodBreadcrumbs in Yesod.Core as a "you don't *have* to use it, but it's really convenient to do so." Michael

I've created an issue on GitHub [1] so that we don't forget about this. Cheers! [1] https://github.com/yesodweb/yesod/issues/236 -- Felipe.

Hi Felipe,
I like it a lot!
I like it so much that I thought about it a really long time and ended
up writing a "blog" of my own in response. :)
Please excuse this abuse of gists, but I have no other convenient way
of creating a post with markdown and haskell markup[1] readily
available to me:
https://gist.github.com/1725600
-Bryan
[1] Github Pages doesn't seem to use Github-flavored markdown!
On Tue, Jan 24, 2012 at 13:17, Felipe Almeida Lessa
I've created an issue on GitHub [1] so that we don't forget about this.
Cheers!
[1] https://github.com/yesodweb/yesod/issues/236
-- Felipe.

On 2 February 2012 21:37, Bryan Richter
[1] Github Pages doesn't seem to use Github-flavored markdown!
They do use Jekyll though, so If you put a YAML frontmatter in, you can use the Liquid filter. Example using an empty frontmatter: --- --- {% highlight haskell %} ... {% endhighlight %}

On Thu, Feb 2, 2012 at 6:37 PM, Bryan Richter
I like it a lot!
That's great to hear =).
I like it so much that I thought about it a really long time and ended up writing a "blog" of my own in response. :)
Please excuse this abuse of gists, but I have no other convenient way of creating a post with markdown and haskell markup[1] readily available to me:
If I'm correctly understanding your concerns (and please correct me if I'm wrong), your qualm is only with the name "Permission" which you think that should be "Credential". When you say that many actions may be satisfied by the same crendential, you're absolutely right. On my project we have 6 times more routes than permissions ;-). So perhaps I'm already doing what you're proposing but using another name? Alas, you could say "permission to modify box" =). Regarding the foldM, I'm just not used to monadic folds enough to see them in the heat of battle =). Thanks for sharing your thoughts! -- Felipe.

On Fri, Feb 3, 2012 at 04:17, Felipe Almeida Lessa
On Thu, Feb 2, 2012 at 6:37 PM, Bryan Richter
wrote: If I'm correctly understanding your concerns (and please correct me if I'm wrong), your qualm is only with the name "Permission" which you think that should be "Credential". When you say that many actions may be satisfied by the same crendential, you're absolutely right. On my project we have 6 times more routes than permissions ;-). So perhaps I'm already doing what you're proposing but using another name? Alas, you could say "permission to modify box" =).
Yep, that's pretty much it. And given how much longer you've used your system than I have, I'm prepared to be okay with just using 'Permission'. :) Just for reference, though I fear this horse might be quite dead, here is the motivating scenario that led me to 'Credential'. Names have been changed to protect the innocent. In my app are two model objects, Persona and Group. Person represents a user's on-site persona (so a user can log in but still not be fully registered), and each Group has a private, shared, facebook-style wall. There are three relevant routes: NewPersonaR, (GroupR gid), and DefaultGroupR. On the first, a user can set up their persona (including joining groups), the second has a Group's wall, and the third is a convenience route that redirects to the first Group a user is a member of. The authorization rules are: (1.) To access (GroupR gid), one must be a member of said group. (2.) Accessing DefaultGroupR will redirect to NewPersonaR if the user has no group memberships. (Users aren't group members, only Personas are.) (3.) A user must be logged in to access NewPersonaR. so: permissionsRequiredFor r _ = case r of NewPersonaR -> ModifyPersona -- rather opaque DefaultGroupR -> ? -- "HaveAGroup"? "LookAtSomeGroup"? (GroupR gid) -> ? -- "InGroup"? "RWAccessGroup?" I couldn't think of good names for the last two. However, this was pretty easy to come up with, and strikes me as much more natural: credentialsRequiredFor NewPersonR _ = LoggedIn credentialsRequiredFor DefaultGroupR _ = InSomeGroup credentialsRequiredFor (GroupR gid) _ = InGroup gid Can you maybe suggest better names for Permissions I could use in this scenario? Thanks again for sparking this discussion.

On Fri, Feb 3, 2012 at 3:11 PM, Bryan Richter
Yep, that's pretty much it. And given how much longer you've used your system than I have, I'm prepared to be okay with just using 'Permission'. :)
I don't have any strong opinions either way, Credentials may be a better name. (Also, I'm not a native English speaker.)
credentialsRequiredFor NewPersonR _ = LoggedIn credentialsRequiredFor DefaultGroupR _ = InSomeGroup credentialsRequiredFor (GroupR gid) _ = InGroup gid
Can you maybe suggest better names for Permissions I could use in this scenario?
These are good enough for me. Use whatever name that floats your boat =). Cheers! -- Felipe.
participants (4)
-
Bryan Richter
-
dag.odenhall@gmail.com
-
Felipe Almeida Lessa
-
Michael Snoyman