From 1498a83f0f8af11d2b771e67844a7ccf9cfd1084 Mon Sep 17 00:00:00 2001 From: nek0 Date: Mon, 8 Sep 2014 03:57:17 +0200 Subject: [PATCH] admin interface for albums by user --- Handler/AdminProfileSettings.hs | 24 ++++++++++++++++++++++++ config/routes | 1 + templates/adminProfileSettings.hamlet | 2 +- templates/adminUserAlbums.hamlet | 10 ++++++++++ 4 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 templates/adminUserAlbums.hamlet diff --git a/Handler/AdminProfileSettings.hs b/Handler/AdminProfileSettings.hs index f51ba7e..e9af6ea 100644 --- a/Handler/AdminProfileSettings.hs +++ b/Handler/AdminProfileSettings.hs @@ -24,6 +24,30 @@ getAdminProfilesR = do setMessage "You must be logged in" redirect $ LoginR +getAdminUserAlbumsR :: UserId -> Handler Html +getAdminUserAlbumsR ownerId = do + msu <- lookupSession "userId" + case msu of + Just tempUserId -> do + userId <- return $ getUserIdFromText tempUserId + user <- runDB $ getJust userId + case userAdmin user of + True -> do + tempOwner <- runDB $ get ownerId + case tempOwner of + Just owner -> do + albums <- runDB $ selectList [AlbumOwner ==. ownerId] [Desc AlbumTitle] + defaultLayout $ do + $(widgetFile "adminUserAlbums") + Nothing -> do + setMessage "This user does not exist" + redirect $ AdminR + False -> do + setMessage "You are no admin" + redirect $ HomeR + Nothing -> do + setMessage "You must be kogged in" + redirect $ LoginR getAdminProfileSettingsR :: UserId -> Handler Html getAdminProfileSettingsR ownerId = do diff --git a/config/routes b/config/routes index 21d197c..7ee5260 100644 --- a/config/routes +++ b/config/routes @@ -25,6 +25,7 @@ /admin AdminR GET /admin/profile AdminProfilesR GET /admin/profile/#UserId AdminProfileSettingsR GET POST +/admin/profile/#UserId/albums AdminUserAlbumsR GET /admin/profile/#UserId/delete AdminProfileDeleteR GET /admin/album AdminAlbumsR GET /admin/album/#AlbumId AdminAlbumSettingsR GET POST diff --git a/templates/adminProfileSettings.hamlet b/templates/adminProfileSettings.hamlet index 289f456..5fa4408 100644 --- a/templates/adminProfileSettings.hamlet +++ b/templates/adminProfileSettings.hamlet @@ -12,6 +12,6 @@ $newline always