Towards using short GUIDs (#1)

Also updated dependencies and moved to .NET Core 2.2; the Giraffe token router doesn't have a parser for short GUIDs yet
This commit is contained in:
Daniel J. Summers
2019-02-22 21:54:31 -06:00
parent fae4ebf9e7
commit dab6c59a37
15 changed files with 82 additions and 92 deletions

View File

@@ -3,8 +3,6 @@
open Giraffe.GiraffeViewEngine
open PrayerTracker.Entities
open PrayerTracker.ViewModels
open System
open System.Collections.Generic
/// View for the church edit page
let edit (m : EditChurch) ctx vi =
@@ -14,7 +12,7 @@ let edit (m : EditChurch) ctx vi =
style [ _scoped ]
[ rawText "#name { width: 20rem; } #city { width: 10rem; } #st { width: 3rem; } #interfaceAddress { width: 30rem; }" ]
csrfToken ctx
input [ _type "hidden"; _name "churchId"; _value (m.churchId.ToString "N") ]
input [ _type "hidden"; _name "churchId"; _value (flatGuid m.churchId) ]
div [ _class "pt-field-row" ] [
div [ _class "pt-field" ] [
label [ _for "name" ] [ encLocText s.["Church Name"] ]
@@ -79,7 +77,7 @@ let maintain (churches : Church list) (stats : Map<string, ChurchStats>) ctx vi
]
churches
|> List.map (fun ch ->
let chId = ch.churchId.ToString "N"
let chId = flatGuid ch.churchId
let delAction = sprintf "/church/%s/delete" chId
let delPrompt = s.["Are you want to delete this {0}? This action cannot be undone.",
sprintf "%s (%s)" (s.["Church"].Value.ToLower ()) ch.name]

View File

@@ -7,6 +7,7 @@ open Microsoft.AspNetCore.Antiforgery
open Microsoft.AspNetCore.Http
open Microsoft.AspNetCore.Mvc.Localization
open Microsoft.Extensions.Localization
open System
open System.IO
open System.Text.Encodings.Web
@@ -101,8 +102,11 @@ let selectDefault text = sprintf "— %s —" text
/// Generate a standard submit button with icon and text
let submit attrs ico text = button (_type "submit" :: attrs) [ icon ico; rawText " &nbsp;"; encLocText text ]
/// Format a GUID with no dashes (used for URLs and forms)
let flatGuid (x : Guid) = x.ToString "N"
/// An empty GUID string (used for "add" actions)
let emptyGuid = System.Guid.Empty.ToString "N"
let emptyGuid = flatGuid Guid.Empty
/// blockquote tag

View File

@@ -17,7 +17,7 @@ let edit (m : EditRequest) today ctx vi =
let pageTitle = match m.isNew () with true -> "Add a New Request" | false -> "Edit Request"
[ form [ _action "/prayer-request/save"; _method "post"; _class "pt-center-columns" ] [
csrfToken ctx
input [ _type "hidden"; _name "requestId"; _value (m.requestId.ToString "N") ]
input [ _type "hidden"; _name "requestId"; _value (flatGuid m.requestId) ]
div [ _class "pt-field-row" ] [
yield div [ _class "pt-field" ] [
label [ _for "requestType" ] [ encLocText s.["Request Type"] ]
@@ -139,7 +139,7 @@ let lists (grps : SmallGroup list) vi =
]
grps
|> List.map (fun grp ->
let grpId = grp.smallGroupId.ToString "N"
let grpId = flatGuid grp.smallGroupId
tr [] [
match grp.preferences.isPublic with
| true ->
@@ -175,7 +175,7 @@ let maintain (reqs : PrayerRequest seq) (grp : SmallGroup) onlyActive (ctx : Htt
let requests =
reqs
|> Seq.map (fun req ->
let reqId = req.prayerRequestId.ToString "N"
let reqId = flatGuid req.prayerRequestId
let reqText = Utils.htmlToPlainText req.text
let delAction = sprintf "/prayer-request/%s/delete" reqId
let delPrompt = s.["Are you want to delete this prayer request? This action cannot be undone.\\n(If the prayer request has been answered, or an event has passed, consider inactivating it instead.)"].Value

View File

@@ -21,13 +21,13 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Giraffe" Version="3.1.0" />
<PackageReference Include="MailKit" Version="2.0.6" />
<PackageReference Include="Microsoft.AspNetCore.Html.Abstractions" Version="2.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Http" Version="2.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Http.Extensions" Version="2.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.1.3" />
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
<PackageReference Include="Giraffe" Version="3.6.0" />
<PackageReference Include="MailKit" Version="2.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Html.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Http" Version="2.2.2" />
<PackageReference Include="Microsoft.AspNetCore.Http.Extensions" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
</ItemGroup>
<ItemGroup>
@@ -89,7 +89,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Update="FSharp.Core" Version="4.5.2" />
<PackageReference Update="FSharp.Core" Version="4.6.2" />
</ItemGroup>
</Project>

View File

@@ -20,7 +20,7 @@ let announcement isAdmin ctx vi =
]
]
match isAdmin with
| true ->
| true ->
yield div [ _class "pt-field-row" ] [
div [ _class "pt-field" ] [
label [] [ encLocText s.["Send Announcement to"]; rawText ":" ]
@@ -77,7 +77,7 @@ let edit (m : EditSmallGroup) (churches : Church list) ctx vi =
let pageTitle = match m.isNew () with true -> "Add a New Group" | false -> "Edit Group"
form [ _action "/small-group/save"; _method "post"; _class "pt-center-columns" ] [
csrfToken ctx
input [ _type "hidden"; _name "smallGroupId"; _value (m.smallGroupId.ToString "N") ]
input [ _type "hidden"; _name "smallGroupId"; _value (flatGuid m.smallGroupId) ]
div [ _class "pt-field-row" ] [
div [ _class "pt-field" ] [
label [ _for "name" ] [ encLocText s.["Group Name"] ]
@@ -89,9 +89,9 @@ let edit (m : EditSmallGroup) (churches : Church list) ctx vi =
label [ _for "churchId" ] [ encLocText s.["Church"] ]
seq {
yield "", selectDefault s.["Select Church"].Value
yield! churches |> List.map (fun c -> c.churchId.ToString "N", c.name)
yield! churches |> List.map (fun c -> flatGuid c.churchId, c.name)
}
|> selectList "churchId" (m.churchId.ToString "N") [ _required ]
|> selectList "churchId" (flatGuid m.churchId) [ _required ]
]
]
div [ _class "pt-field-row" ] [ submit [] "save" s.["Save Group"] ]
@@ -108,7 +108,7 @@ let editMember (m : EditMember) (typs : (string * LocalizedString) seq) ctx vi =
form [ _action "/small-group/member/save"; _method "post"; _class "pt-center-columns" ] [
style [ _scoped ] [ rawText "#memberName { width: 15rem; } #emailAddress { width: 20rem; }" ]
csrfToken ctx
input [ _type "hidden"; _name "memberId"; _value (m.memberId.ToString "N") ]
input [ _type "hidden"; _name "memberId"; _value (flatGuid m.memberId) ]
div [ _class "pt-field-row" ] [
div [ _class "pt-field" ] [
label [ _for "memberName" ] [ encLocText s.["Member Name"] ]
@@ -148,7 +148,7 @@ let logOn (grps : SmallGroup list) grpId ctx vi =
| _ ->
yield "", selectDefault s.["Select Group"].Value
yield! grps
|> List.map (fun grp -> grp.smallGroupId.ToString "N", sprintf "%s | %s" grp.church.name grp.name)
|> List.map (fun grp -> flatGuid grp.smallGroupId, sprintf "%s | %s" grp.church.name grp.name)
}
|> selectList "smallGroupId" grpId [ _required ]
]
@@ -197,7 +197,7 @@ let maintain (grps : SmallGroup list) ctx vi =
]
grps
|> List.map (fun g ->
let grpId = g.smallGroupId.ToString "N"
let grpId = flatGuid g.smallGroupId
let delAction = sprintf "/small-group/%s/delete" grpId
let delPrompt = s.["Are you want to delete this {0}? This action cannot be undone.",
sprintf "%s (%s)" (s.["Small Group"].Value.ToLower ()) g.name].Value
@@ -243,7 +243,7 @@ let members (mbrs : Member list) (emailTyps : Map<string, LocalizedString>) ctx
]
mbrs
|> List.map (fun mbr ->
let mbrId = mbr.memberId.ToString "N"
let mbrId = flatGuid mbr.memberId
let delAction = sprintf "/small-group/member/%s/delete" mbrId
let delPrompt = s.["Are you want to delete this {0} ({1})? This action cannot be undone.",
s.["group member"], mbr.memberName].Value

View File

@@ -5,12 +5,12 @@ open PrayerTracker.Entities
open PrayerTracker.ViewModels
/// View for the group assignment page
let assignGroups m (groups : Map<string, string>) (curGroups : string list) ctx vi =
let assignGroups m groups curGroups ctx vi =
let s = I18N.localizer.Force ()
let pageTitle = sprintf "%s %A" m.userName s.["Assign Groups"]
form [ _action "/user/small-groups/save"; _method "post"; _class "pt-center-columns" ] [
csrfToken ctx
input [ _type "hidden"; _name "userId"; _value (m.userId.ToString "N") ]
input [ _type "hidden"; _name "userId"; _value (flatGuid m.userId) ]
input [ _type "hidden"; _name "userName"; _value m.userName ]
table [ _class "pt-table" ] [
thead [] [
@@ -20,19 +20,18 @@ let assignGroups m (groups : Map<string, string>) (curGroups : string list) ctx
]
]
groups
|> Seq.map (fun grp ->
let inputId = sprintf "id-%s" grp.Key
|> List.map (fun (grpId, grpName) ->
let inputId = sprintf "id-%s" grpId
tr [] [
td [] [
input [ yield _type "checkbox"
yield _name "smallGroups"
yield _id inputId
yield _value grp.Key
match curGroups |> List.contains grp.Key with true -> yield _checked | false -> () ]
yield _value grpId
match curGroups |> List.contains grpId with true -> yield _checked | false -> () ]
]
td [] [ label [ _for inputId ] [ encodedText grp.Value ] ]
td [] [ label [ _for inputId ] [ encodedText grpName ] ]
])
|> List.ofSeq
|> tbody []
]
div [ _class "pt-field-row" ] [ submit [] "save" s.["Save Group Assignments"] ]
@@ -89,7 +88,7 @@ let edit (m : EditUser) ctx vi =
style [ _scoped ]
[ rawText "#firstName, #lastName, #password, #passwordConfirm { width: 10rem; } #emailAddress { width: 20rem; } " ]
csrfToken ctx
input [ _type "hidden"; _name "userId"; _value (m.userId.ToString "N") ]
input [ _type "hidden"; _name "userId"; _value (flatGuid m.userId) ]
div [ _class "pt-field-row" ] [
div [ _class "pt-field" ] [
label [ _for "firstName" ] [ encLocText s.["First Name"] ]
@@ -131,7 +130,7 @@ let edit (m : EditUser) ctx vi =
/// View for the user log on page
let logOn (m : UserLogOn) (groups : Map<string, string>) ctx vi =
let logOn (m : UserLogOn) groups ctx vi =
let s = I18N.localizer.Force ()
form [ _action "/user/log-on"; _method "post"; _class "pt-center-columns" ] [
style [ _scoped ] [ rawText "#emailAddress { width: 20rem; }" ]
@@ -153,7 +152,7 @@ let logOn (m : UserLogOn) (groups : Map<string, string>) ctx vi =
label [ _for "smallGroupId" ] [ encLocText s.["Group"] ]
seq {
yield "", selectDefault s.["Select Group"].Value
yield! groups |> Seq.sortBy (fun x -> x.Value) |> Seq.map (fun x -> x.Key, x.Value)
yield! groups
}
|> selectList "smallGroupId" "" [ _required ]
@@ -193,7 +192,7 @@ let maintain (users : User list) ctx vi =
]
users
|> List.map (fun user ->
let userId = user.userId.ToString "N"
let userId = flatGuid user.userId
let delAction = sprintf "/user/%s/delete" userId
let delPrompt = s.["Are you want to delete this {0}? This action cannot be undone.",
(sprintf "%s (%s)" (s.["User"].Value.ToLower()) user.fullName)].Value