Add group, WIP on role (#17)

This commit is contained in:
2026-08-01 22:45:18 -04:00
parent 2241742ab8
commit e7261f6019
13 changed files with 539 additions and 72 deletions
+1 -1
View File
@@ -13,7 +13,7 @@ module Dashboard =
// GET /admin/dashboard
let user : HttpHandler =
requireAccess Author
requireAccess ContentAuthor
>=> fun next ctx -> task {
let getCount (f: WebLogId -> Task<int>) = f ctx.WebLog.Id
let data = ctx.Data
+1 -1
View File
@@ -88,7 +88,7 @@ let private generateViewContext messages viewCtx (ctx: HttpContext) =
CurrentPage = ctx.Request.Path.Value[1..]
Messages = messages
Generator = ctx.Generator
IsAuthor = ctx.HasAccessLevel Author
IsAuthor = ctx.HasAccessLevel ContentAuthor
IsEditor = ctx.HasAccessLevel Editor
IsWebLogAdmin = ctx.HasAccessLevel WebLogAdmin
IsAdministrator = ctx.HasAccessLevel Administrator }
+10 -10
View File
@@ -8,7 +8,7 @@ open MyWebLog.ViewModels
// GET /admin/pages
// GET /admin/pages/page/{pageNbr}
let all pageNbr : HttpHandler =
requireAccess Author
requireAccess ContentAuthor
>=> fun next ctx -> task {
let! pages = ctx.Data.Page.FindPageOfPages ctx.WebLog.Id pageNbr
let displayPages =
@@ -24,7 +24,7 @@ let all pageNbr : HttpHandler =
// GET /admin/page/{id}/edit
let edit pgId : HttpHandler =
requireAccess Author
requireAccess ContentAuthor
>=> fun next ctx -> task {
let! result = task {
match pgId with
@@ -57,7 +57,7 @@ let delete pgId : HttpHandler =
// GET /admin/page/{id}/permalinks
let editPermalinks pgId : HttpHandler =
requireAccess Author
requireAccess ContentAuthor
>=> fun next ctx -> task {
match! ctx.Data.Page.FindFullById (PageId pgId) ctx.WebLog.Id with
| Some pg when canEdit pg.AuthorId ctx ->
@@ -71,7 +71,7 @@ let editPermalinks pgId : HttpHandler =
// POST /admin/page/permalinks
let savePermalinks : HttpHandler =
requireAccess Author
requireAccess ContentAuthor
>=> validateCsrf
>=> fun next ctx -> task {
let! model = ctx.BindFormAsync<ManagePermalinksModel>()
@@ -90,7 +90,7 @@ let savePermalinks : HttpHandler =
// GET /admin/page/{id}/revisions
let editRevisions pgId : HttpHandler =
requireAccess Author
requireAccess ContentAuthor
>=> fun next ctx -> task {
match! ctx.Data.Page.FindFullById (PageId pgId) ctx.WebLog.Id with
| Some pg when canEdit pg.AuthorId ctx ->
@@ -104,7 +104,7 @@ let editRevisions pgId : HttpHandler =
// DELETE /admin/page/{id}/revisions
let purgeRevisions pgId : HttpHandler =
requireAccess Author
requireAccess ContentAuthor
>=> fun next ctx -> task {
let data = ctx.Data
match! data.Page.FindFullById (PageId pgId) ctx.WebLog.Id with
@@ -128,7 +128,7 @@ let private findPageRevision pgId revDate (ctx: HttpContext) = task {
// GET /admin/page/{id}/revision/{revision-date}/preview
let previewRevision (pgId, revDate) : HttpHandler =
requireAccess Author
requireAccess ContentAuthor
>=> fun next ctx -> task {
match! findPageRevision pgId revDate ctx with
| Some pg, Some rev when canEdit pg.AuthorId ctx ->
@@ -139,7 +139,7 @@ let previewRevision (pgId, revDate) : HttpHandler =
// POST /admin/page/{id}/revision/{revision-date}/restore
let restoreRevision (pgId, revDate) : HttpHandler =
requireAccess Author
requireAccess ContentAuthor
>=> validateCsrf
>=> fun next ctx -> task {
match! findPageRevision pgId revDate ctx with
@@ -157,7 +157,7 @@ let restoreRevision (pgId, revDate) : HttpHandler =
// DELETE /admin/page/{id}/revision/{revision-date}
let deleteRevision (pgId, revDate) : HttpHandler =
requireAccess Author
requireAccess ContentAuthor
>=> fun next ctx -> task {
match! findPageRevision pgId revDate ctx with
| Some pg, Some rev when canEdit pg.AuthorId ctx ->
@@ -171,7 +171,7 @@ let deleteRevision (pgId, revDate) : HttpHandler =
// POST /admin/page/save
let save : HttpHandler =
requireAccess Author
requireAccess ContentAuthor
>=> validateCsrf
>=> fun next ctx -> task {
let! model = ctx.BindFormAsync<EditPageModel>()
+14 -14
View File
@@ -253,7 +253,7 @@ let chapters (post: Post) : HttpHandler = fun next ctx ->
// GET /admin/posts
// GET /admin/posts/page/{pageNbr}
let all pageNbr : HttpHandler =
requireAccess Author
requireAccess ContentAuthor
>=> fun next ctx -> task {
let data = ctx.Data
let! posts = data.Post.FindPageOfPosts ctx.WebLog.Id pageNbr 25
@@ -263,7 +263,7 @@ let all pageNbr : HttpHandler =
// GET /admin/post/{id}/edit
let edit postId : HttpHandler =
requireAccess Author
requireAccess ContentAuthor
>=> fun next ctx -> task {
let data = ctx.Data
let! result = task {
@@ -302,7 +302,7 @@ let delete postId : HttpHandler =
// GET /admin/post/{id}/permalinks
let editPermalinks postId : HttpHandler =
requireAccess Author
requireAccess ContentAuthor
>=> fun next ctx -> task {
match! ctx.Data.Post.FindFullById (PostId postId) ctx.WebLog.Id with
| Some post when canEdit post.AuthorId ctx ->
@@ -316,7 +316,7 @@ let editPermalinks postId : HttpHandler =
// POST /admin/post/permalinks
let savePermalinks : HttpHandler =
requireAccess Author
requireAccess ContentAuthor
>=> validateCsrf
>=> fun next ctx -> task {
let! model = ctx.BindFormAsync<ManagePermalinksModel>()
@@ -335,7 +335,7 @@ let savePermalinks : HttpHandler =
// GET /admin/post/{id}/revisions
let editRevisions postId : HttpHandler =
requireAccess Author
requireAccess ContentAuthor
>=> fun next ctx -> task {
match! ctx.Data.Post.FindFullById (PostId postId) ctx.WebLog.Id with
| Some post when canEdit post.AuthorId ctx ->
@@ -349,7 +349,7 @@ let editRevisions postId : HttpHandler =
// DELETE /admin/post/{id}/revisions
let purgeRevisions postId : HttpHandler =
requireAccess Author
requireAccess ContentAuthor
>=> fun next ctx -> task {
let data = ctx.Data
match! data.Post.FindFullById (PostId postId) ctx.WebLog.Id with
@@ -374,7 +374,7 @@ let private findPostRevision postId revDate (ctx: HttpContext) = task {
// GET /admin/post/{id}/revision/{revision-date}/preview
let previewRevision (postId, revDate) : HttpHandler =
requireAccess Author
requireAccess ContentAuthor
>=> fun next ctx -> task {
match! findPostRevision postId revDate ctx with
| Some post, Some rev when canEdit post.AuthorId ctx ->
@@ -385,7 +385,7 @@ let previewRevision (postId, revDate) : HttpHandler =
// POST /admin/post/{id}/revision/{revision-date}/restore
let restoreRevision (postId, revDate) : HttpHandler =
requireAccess Author
requireAccess ContentAuthor
>=> validateCsrf
>=> fun next ctx -> task {
match! findPostRevision postId revDate ctx with
@@ -403,7 +403,7 @@ let restoreRevision (postId, revDate) : HttpHandler =
// DELETE /admin/post/{id}/revision/{revision-date}
let deleteRevision (postId, revDate) : HttpHandler =
requireAccess Author
requireAccess ContentAuthor
>=> fun next ctx -> task {
match! findPostRevision postId revDate ctx with
| Some post, Some rev when canEdit post.AuthorId ctx ->
@@ -417,7 +417,7 @@ let deleteRevision (postId, revDate) : HttpHandler =
// GET /admin/post/{id}/chapters
let manageChapters postId : HttpHandler =
requireAccess Author
requireAccess ContentAuthor
>=> fun next ctx -> task {
match! ctx.Data.Post.FindById (PostId postId) ctx.WebLog.Id with
| Some post
@@ -432,7 +432,7 @@ let manageChapters postId : HttpHandler =
// GET /admin/post/{id}/chapter/{idx}
let editChapter (postId, index) : HttpHandler =
requireAccess Author
requireAccess ContentAuthor
>=> fun next ctx -> task {
match! ctx.Data.Post.FindById (PostId postId) ctx.WebLog.Id with
| Some post
@@ -455,7 +455,7 @@ let editChapter (postId, index) : HttpHandler =
// POST /admin/post/{id}/chapter/{idx}
let saveChapter (postId, index) : HttpHandler =
requireAccess Author
requireAccess ContentAuthor
>=> validateCsrf
>=> fun next ctx -> task {
let data = ctx.Data
@@ -488,7 +488,7 @@ let saveChapter (postId, index) : HttpHandler =
// DELETE /admin/post/{id}/chapter/{idx}
let deleteChapter (postId, index) : HttpHandler =
requireAccess Author
requireAccess ContentAuthor
>=> fun next ctx -> task {
let data = ctx.Data
match! data.Post.FindById (PostId postId) ctx.WebLog.Id with
@@ -512,7 +512,7 @@ let deleteChapter (postId, index) : HttpHandler =
// POST /admin/post/save
let save : HttpHandler =
requireAccess Author
requireAccess ContentAuthor
>=> validateCsrf
>=> fun next ctx -> task {
let! model = ctx.BindFormAsync<EditPostModel>()
+3 -3
View File
@@ -91,7 +91,7 @@ let makeSlug it = (Regex """\s+""").Replace((Regex "[^A-z0-9 -]").Replace(it, ""
// GET /admin/uploads
let list : HttpHandler =
requireAccess Author
requireAccess ContentAuthor
>=> fun next ctx -> task {
let webLog = ctx.WebLog
let! dbUploads = ctx.Data.Upload.FindByWebLog webLog.Id
@@ -127,12 +127,12 @@ let list : HttpHandler =
// GET /admin/upload/new
let showNew : HttpHandler =
requireAccess Author
requireAccess ContentAuthor
>=> fun next ctx -> adminPage "Upload a File" next ctx Views.WebLog.uploadNew
// POST /admin/upload/save
let save : HttpHandler =
requireAccess Author
requireAccess ContentAuthor
>=> validateCsrf
>=> fun next ctx -> task {
if ctx.Request.HasFormContentType && ctx.Request.Form.Files.Count > 0 then
+2 -2
View File
@@ -142,7 +142,7 @@ let delete userId : HttpHandler =
// GET /admin/my-info
let myInfo : HttpHandler =
requireAccess Author
requireAccess ContentAuthor
>=> fun next ctx -> task {
match! ctx.Data.WebLogUser.FindById ctx.UserId ctx.WebLog.Id with
| Some user ->
@@ -154,7 +154,7 @@ let myInfo : HttpHandler =
// POST /admin/my-info
let saveMyInfo : HttpHandler =
requireAccess Author
requireAccess ContentAuthor
>=> validateCsrf
>=> fun next ctx -> task {
let! model = ctx.BindFormAsync<EditMyInfoModel>()
+1 -1
View File
@@ -133,7 +133,7 @@ let userList (model: WebLogUser list) app =
| Administrator -> span [ _class $"{badge}-success" ] [ raw "ADMINISTRATOR" ]
| WebLogAdmin -> span [ _class $"{badge}-primary" ] [ raw "WEB LOG ADMIN" ]
| Editor -> span [ _class $"{badge}-secondary" ] [ raw "EDITOR" ]
| Author -> span [ _class $"{badge}-dark" ] [ raw "AUTHOR" ]
| ContentAuthor -> span [ _class $"{badge}-dark" ] [ raw "AUTHOR" ]
br []
if app.IsAdministrator || (app.IsWebLogAdmin && not (user.AccessLevel = Administrator)) then
let userUrl = relUrl app $"admin/settings/user/{user.Id}"