changed order of checks to better ordering

This commit is contained in:
nek0 2014-09-08 03:56:30 +02:00
parent b4b09cde37
commit 61e94cfa91

View file

@ -26,9 +26,6 @@ getAdminAlbumsR = do
getAdminAlbumSettingsR :: AlbumId -> Handler Html getAdminAlbumSettingsR :: AlbumId -> Handler Html
getAdminAlbumSettingsR albumId = do getAdminAlbumSettingsR albumId = do
tempAlbum <- runDB $ get albumId
case tempAlbum of
Just album -> do
msu <- lookupSession "userId" msu <- lookupSession "userId"
case msu of case msu of
Just tempUserId -> do Just tempUserId -> do
@ -36,24 +33,24 @@ getAdminAlbumSettingsR albumId = do
user <- runDB $ getJust userId user <- runDB $ getJust userId
case userAdmin user of case userAdmin user of
True -> do True -> do
tempAlbum <- runDB $ get albumId
case tempAlbum of
Just album -> do
(adminAlbumSettingsWidget, enctype) <- generateFormPost $ adminAlbumSettingsForm album albumId (adminAlbumSettingsWidget, enctype) <- generateFormPost $ adminAlbumSettingsForm album albumId
defaultLayout $ do defaultLayout $ do
$(widgetFile "adminAlbumSet") $(widgetFile "adminAlbumSet")
Nothing -> do
setMessage "This album does not exist"
redirect $ AdminR
False -> do False -> do
setMessage "You must be admin" setMessage "You are no admin"
redirect $ HomeR redirect $ HomeR
Nothing -> do Nothing -> do
setMessage "You must be logged in" setMessage "You must be logged in"
redirect $ LoginR redirect $ LoginR
Nothing -> do
setMessage "This album does not exist"
redirect $ AdminR
postAdminAlbumSettingsR :: AlbumId -> Handler Html postAdminAlbumSettingsR :: AlbumId -> Handler Html
postAdminAlbumSettingsR albumId = do postAdminAlbumSettingsR albumId = do
tempAlbum <- runDB $ get albumId
case tempAlbum of
Just album -> do
msu <- lookupSession "userId" msu <- lookupSession "userId"
case msu of case msu of
Just tempUserId -> do Just tempUserId -> do
@ -61,6 +58,9 @@ postAdminAlbumSettingsR albumId = do
user <- runDB $ getJust userId user <- runDB $ getJust userId
case userAdmin user of case userAdmin user of
True -> do True -> do
tempAlbum <- runDB $ get albumId
case tempAlbum of
Just album -> do
((res, adminAlbumSettingsWidget), enctype) <- runFormPost $ adminAlbumSettingsForm album albumId ((res, adminAlbumSettingsWidget), enctype) <- runFormPost $ adminAlbumSettingsForm album albumId
case res of case res of
FormSuccess temp -> do FormSuccess temp -> do
@ -73,15 +73,15 @@ postAdminAlbumSettingsR albumId = do
_ -> do _ -> do
setMessage "There was an error while changing the settings" setMessage "There was an error while changing the settings"
redirect $ AdminAlbumSettingsR albumId redirect $ AdminAlbumSettingsR albumId
Nothing -> do
setMessage "This album does not exist"
redirect $ AdminR
False -> do False -> do
setMessage "You must be admin" setMessage "You are no admin"
redirect $ HomeR redirect $ HomeR
Nothing -> do Nothing -> do
setMessage "You must be logged in" setMessage "You must be logged in"
redirect $ LoginR redirect $ LoginR
Nothing -> do
setMessage "This album does not exist"
redirect $ AdminR
adminAlbumSettingsForm :: Album -> AlbumId -> Form Album adminAlbumSettingsForm :: Album -> AlbumId -> Form Album
adminAlbumSettingsForm album albumId = renderDivs $ Album adminAlbumSettingsForm album albumId = renderDivs $ Album
@ -96,9 +96,6 @@ adminAlbumSettingsForm album albumId = renderDivs $ Album
getAdminAlbumDeleteR :: AlbumId -> Handler Html getAdminAlbumDeleteR :: AlbumId -> Handler Html
getAdminAlbumDeleteR albumId = do getAdminAlbumDeleteR albumId = do
tempAlbum <- runDB $ get albumId
case tempAlbum of
Just album -> do
msu <- lookupSession "userId" msu <- lookupSession "userId"
case msu of case msu of
Just tempUserId -> do Just tempUserId -> do
@ -106,6 +103,9 @@ getAdminAlbumDeleteR albumId = do
user <- runDB $ getJust userId user <- runDB $ getJust userId
case userAdmin user of case userAdmin user of
True -> do True -> do
tempAlbum <- runDB $ get albumId
case tempAlbum of
Just album -> do
-- remove reference from owner -- remove reference from owner
ownerId <- return $ albumOwner album ownerId <- return $ albumOwner album
owner <- runDB $ getJust ownerId owner <- runDB $ getJust ownerId
@ -120,12 +120,12 @@ getAdminAlbumDeleteR albumId = do
-- outro -- outro
setMessage "Album deleted successfully" setMessage "Album deleted successfully"
redirect $ AdminR redirect $ AdminR
_ -> do Nothing -> do
setMessage "This album dies not exist"
redirect $ AdminR
False -> do
setMessage "You are no admin" setMessage "You are no admin"
redirect $ HomeR redirect $ HomeR
Nothing -> do Nothing -> do
setMessage "You must be logged in" setMessage "You must be logged in"
redirect $ LoginR redirect $ LoginR
Nothing -> do
setMessage "This Album does not exist"
redirect $ AdminR