[web-devel] [Yesod] Abstracting permissions with Yesod

Michael Snoyman michael at snoyman.com
Sun Sep 9 12:39:21 CEST 2012


On Sun, Sep 9, 2012 at 1:36 PM, Arthur Clemens <arthurclemens at gmail.com> wrote:
> It would be nice if there was the possibility to give an entire site section
> permissions. What I have now very easily creates bugs, exactly what you
> don't want in restricted site parts:
>
> data Permission = Admin | Public
>
> permissionsRequiredFor :: Route App -> Bool -> [Permission]
> permissionsRequiredFor AdminR                 False = [Admin]
> permissionsRequiredFor AdminCategoriesR       False = [Admin]
> permissionsRequiredFor AdminAddCategoryR      False = [Admin]
> permissionsRequiredFor (AdminEditCategoryR _) False = [Admin]
> permissionsRequiredFor (AdminCategoryR _)     False = [Admin]
> permissionsRequiredFor AdminEmailsR           False = [Admin]
> permissionsRequiredFor AdminProductsR         False = [Admin]
> permissionsRequiredFor (AdminProductR _)      False = [Admin]
> permissionsRequiredFor AdminAddProductR       False = [Admin]
> permissionsRequiredFor (AdminEditProductR _)  False = [Admin]
> permissionsRequiredFor _          _    = []
>
> --
> Arthur

Starting with Yesod 1.1, hierarchical routes are now available. So you
can do something like:

/admin AdminR:
    /product/#ProductId AdminProductR GET POST
    ...

And then

permissionsRequiredFor AdminR{} False = [Admin]

Michael



More information about the web-devel mailing list