Skip to content

Commit

Permalink
Merge pull request #863 from ds-wizard/release/3.25.0
Browse files Browse the repository at this point in the history
Release 3.25.0
  • Loading branch information
janslifka committed Jul 4, 2023
2 parents 99615df + df80240 commit 01dc4e6
Show file tree
Hide file tree
Showing 52 changed files with 1,214 additions and 465 deletions.
18 changes: 16 additions & 2 deletions engine-shared/elm/Shared/Api/Auth.elm
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
module Shared.Api.Auth exposing (authRedirectUrl, getToken)
module Shared.Api.Auth exposing (authRedirectUrl, getToken, postConsents)

import Json.Encode as E
import Json.Encode.Extra as E
import Shared.AbstractAppState exposing (AbstractAppState)
import Shared.Api exposing (ToMsg, httpGet)
import Shared.Api exposing (ToMsg, httpFetch, httpGet)
import Shared.Data.BootstrapConfig.AuthenticationConfig.OpenIDServiceConfig exposing (OpenIDServiceConfig)
import Shared.Data.TokenResponse as TokenResponse exposing (TokenResponse)
import String.Extra as String
Expand All @@ -15,3 +17,15 @@ getToken id mbError mbCode mbSessionState =
authRedirectUrl : OpenIDServiceConfig -> AbstractAppState a -> String
authRedirectUrl config appState =
appState.apiUrl ++ "/auth/" ++ config.id


postConsents : String -> String -> Maybe String -> AbstractAppState a -> ToMsg TokenResponse msg -> Cmd msg
postConsents id hash mbSessionState =
let
body =
E.object
[ ( "hash", E.string hash )
, ( "sessionState", E.maybe E.string mbSessionState )
]
in
httpFetch ("/auth/" ++ id ++ "/consents") TokenResponse.decoder body
14 changes: 13 additions & 1 deletion engine-shared/elm/Shared/Api/Tokens.elm
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module Shared.Api.Tokens exposing
( deleteToken
( deleteCurrentToken
, deleteToken
, deleteTokens
, fetchToken
, getTokens
)
Expand All @@ -26,3 +28,13 @@ getTokens =
deleteToken : Uuid -> AbstractAppState a -> ToMsg () msg -> Cmd msg
deleteToken uuid =
jwtDelete ("/tokens/" ++ Uuid.toString uuid)


deleteCurrentToken : AbstractAppState a -> ToMsg () msg -> Cmd msg
deleteCurrentToken =
jwtDelete "/tokens/current"


deleteTokens : AbstractAppState a -> ToMsg () msg -> Cmd msg
deleteTokens =
jwtDelete "/tokens"
8 changes: 1 addition & 7 deletions engine-shared/elm/Shared/Api/Users.elm
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
module Shared.Api.Users exposing
( deleteToken
, deleteUser
( deleteUser
, getCurrentUser
, getUser
, getUsers
Expand Down Expand Up @@ -117,8 +116,3 @@ putUserActivation uuid hash =
deleteUser : String -> AbstractAppState a -> ToMsg () msg -> Cmd msg
deleteUser uuid =
jwtDelete ("/users/" ++ uuid)


deleteToken : AbstractAppState a -> ToMsg () msg -> Cmd msg
deleteToken =
jwtDelete "/users/current/token"
96 changes: 95 additions & 1 deletion engine-shared/elm/Shared/Data/QuestionnaireDetail.elm
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ module Shared.Data.QuestionnaireDetail exposing
, deleteComment
, deleteCommentThread
, editComment
, generateReplies
, getCommentCount
, getComments
, getItemTitle
Expand All @@ -39,10 +40,12 @@ module Shared.Data.QuestionnaireDetail exposing
)

import Dict exposing (Dict)
import Dict.Extra as Dict
import Json.Decode as D exposing (Decoder)
import Json.Decode.Pipeline as D
import List.Extra as List
import Maybe.Extra as Maybe
import Random exposing (Seed)
import Regex
import Shared.AbstractAppState exposing (AbstractAppState)
import Shared.Auth.Session as Session
Expand Down Expand Up @@ -72,7 +75,7 @@ import Shared.Data.UserInfo as UserInfo
import Shared.Data.WebSockets.QuestionnaireAction.SetQuestionnaireData exposing (SetQuestionnaireData)
import Shared.Markdown as Markdown
import Shared.RegexPatterns as RegexPatterns
import Shared.Utils exposing (boolToInt)
import Shared.Utils exposing (boolToInt, getUuidString)
import String.Extra as String
import Time
import Tuple.Extra as Tuple
Expand Down Expand Up @@ -771,6 +774,97 @@ evaluateAnswerItem questionnaire path questions uuid =



-- Generating Replies


generateReplies : Time.Posix -> Seed -> String -> KnowledgeModel -> QuestionnaireDetail -> ( Seed, Maybe String, QuestionnaireDetail )
generateReplies currentTime seed questionUuid km questionnaireDetail =
let
parentMap =
KnowledgeModel.createParentMap km

( newSeed, mbChapterUuid, replies ) =
foldReplies currentTime km parentMap seed questionUuid Dict.empty
in
( newSeed
, mbChapterUuid
, { questionnaireDetail | replies = replies }
)


foldReplies : Time.Posix -> KnowledgeModel -> KnowledgeModel.ParentMap -> Seed -> String -> Dict String Reply -> ( Seed, Maybe String, Dict String Reply )
foldReplies currentTime km parentMap seed questionUuid replies =
let
parentUuid =
KnowledgeModel.getParent parentMap questionUuid

prefixPaths prefix repliesDict =
Dict.mapKeys (\k -> prefix ++ "." ++ k) repliesDict

foldReplies_ =
foldReplies currentTime km parentMap
in
case
( KnowledgeModel.getChapter parentUuid km
, KnowledgeModel.getQuestion parentUuid km
, KnowledgeModel.getAnswer parentUuid km
)
of
( Just chapter, Nothing, Nothing ) ->
-- just prefix replies with chapter uuid
( seed, Just chapter.uuid, prefixPaths chapter.uuid replies )

( Nothing, Just question, Nothing ) ->
-- add item to question, get parent question and continue
let
( itemUuid, newSeed ) =
getUuidString seed

reply =
{ value = ReplyValue.ItemListReply [ itemUuid ]
, createdAt = currentTime
, createdBy = Nothing
}

listQuestionUuid =
Question.getUuid question
in
foldReplies_ newSeed
listQuestionUuid
(Dict.insert listQuestionUuid reply (prefixPaths listQuestionUuid (prefixPaths itemUuid replies)))

( Nothing, Nothing, Just answer ) ->
-- select answer, get parent question and continue
let
answerParentQuestionUuid =
KnowledgeModel.getParent parentMap answer.uuid
in
case KnowledgeModel.getQuestion answerParentQuestionUuid km of
Just question ->
let
reply =
{ value = ReplyValue.AnswerReply answer.uuid
, createdAt = currentTime
, createdBy = Nothing
}

answerQuestionUuid =
Question.getUuid question
in
foldReplies_ seed
answerQuestionUuid
(Dict.insert answerQuestionUuid reply (prefixPaths answerQuestionUuid (prefixPaths answer.uuid replies)))

Nothing ->
-- should not happen
( seed, Nothing, replies )

_ ->
-- should not happen
( seed, Nothing, replies )



-- Utils


Expand Down
21 changes: 9 additions & 12 deletions engine-shared/elm/Shared/Data/TokenResponse.elm
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
module Shared.Data.TokenResponse exposing (TokenResponse(..), decoder, toToken)
module Shared.Data.TokenResponse exposing
( TokenResponse(..)
, decoder
)

import Json.Decode as D exposing (Decoder)
import Json.Decode.Extra as D
import Json.Decode.Pipeline as D
import Shared.Data.Token as Token exposing (Token)
import Time


type TokenResponse
= Token String Time.Posix
| CodeRequired
| ConsentsRequired String


decoder : Decoder TokenResponse
Expand All @@ -26,16 +29,10 @@ decoder =
"CodeRequired" ->
D.succeed CodeRequired

"ConsentsRequired" ->
D.succeed ConsentsRequired
|> D.required "hash" D.string

_ ->
D.fail <| "Unexpected token response type " ++ type_
)


toToken : TokenResponse -> Maybe Token
toToken response =
case response of
Token token expiresAt ->
Just (Token.create token expiresAt)

CodeRequired ->
Nothing
2 changes: 1 addition & 1 deletion engine-wizard/docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ RUN apk --purge del curl

# Install dart-sass
RUN apk add --update npm
RUN npm install -g sass@1.62.1
RUN npm install -g sass@1.63.6

# Dependencies needed to rebuild styles
COPY node_modules/bootstrap src/~bootstrap
Expand Down
3 changes: 2 additions & 1 deletion engine-wizard/elm/Wizard/Auth/Update.elm
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module Wizard.Auth.Update exposing (update)

import Gettext exposing (gettext)
import Shared.Api.Tokens as TokensApi
import Shared.Api.Users as UsersApi
import Shared.Auth.Session as Session
import Shared.Data.User as User exposing (User)
Expand Down Expand Up @@ -95,7 +96,7 @@ logoutTo route model =
cmd =
Cmd.batch
[ Ports.clearSession ()
, UsersApi.deleteToken model.appState (Wizard.Msgs.AuthMsg << always AuthMsgs.LogoutDone)
, TokensApi.deleteCurrentToken model.appState (Wizard.Msgs.AuthMsg << always AuthMsgs.LogoutDone)
, cmdNavigate model.appState route
]
in
Expand Down
Loading

0 comments on commit 01dc4e6

Please sign in to comment.