Copyright(c) digitally induced GmbH 2020
Safe HaskellNone

IHP.AuthSupport.Authorization

Description

 
Synopsis

Documentation

class CanView user model where Source #

Methods

canView :: (?modelContext :: ModelContext) => model -> user -> IO Bool Source #

accessDeniedUnless :: Bool -> IO () Source #

Stops the action execution with an error message when the access condition is false.

Example: Checking a user is author of a blog post.

action EditPostAction { postId } = do
    post <- fetch postId
    accessDeniedUnless (get #authorId post == currentUserId)
    
    renderHtml EditView { .. }

This will throw an error and prevent the view from being rendered when the current user is not author of the post.