diff --git a/src/elm/Main.elm b/src/elm/Main.elm index 7f1115614..f57fb8107 100644 --- a/src/elm/Main.elm +++ b/src/elm/Main.elm @@ -514,9 +514,16 @@ update msg model = body : Http.Body body = Http.jsonBody <| encodeUpdateRepository payload + + action = + if Pages.Settings.validEventsUpdate model.repo payload then + Api.try (RepoUpdatedResponse field) (Api.updateRepository model org repo body) + + else + addErrorString "Could not disable webhook event. At least one event must be active." in ( model - , Api.try (RepoUpdatedResponse field) (Api.updateRepository model org repo body) + , action ) UpdateRepoAccess org repo field value -> @@ -530,7 +537,7 @@ update msg model = Http.jsonBody <| encodeUpdateRepository payload action = - if accessChanged model.repo payload then + if Pages.Settings.validAccessUpdate model.repo payload then Api.try (RepoUpdatedResponse field) (Api.updateRepository model org repo body) else @@ -1716,6 +1723,15 @@ addError error = |> perform identity +{-| addErrorString : takes a string and produces a Cmd Msg that invokes an action in the Errors module +-} +addErrorString : String -> Cmd Msg +addErrorString error = + succeed + (Error <| error) + |> perform identity + + {-| toFailure : maps a detailed error into a WebData Failure value -} toFailure : Http.Detailed.Error String -> WebData a @@ -1936,27 +1952,6 @@ shouldSearch filter = String.length filter > 2 -{-| refreshPage : takes model webdata repo and repo visibility update and determines if an update is necessary --} -accessChanged : WebData Repository -> UpdateRepositoryPayload -> Bool -accessChanged originalRepo repoUpdate = - case originalRepo of - RemoteData.Success repo -> - case repoUpdate.visibility of - Just visibility -> - if repo.visibility /= visibility then - True - - else - False - - Nothing -> - False - - _ -> - False - - {-| clickHook : takes model org repo and build number and fetches build information from the api -} clickHook : Model -> Org -> Repo -> BuildNumber -> ( HookBuilds, Cmd Msg ) diff --git a/src/elm/Pages/Settings.elm b/src/elm/Pages/Settings.elm index 7e1be7366..c4c88759f 100644 --- a/src/elm/Pages/Settings.elm +++ b/src/elm/Pages/Settings.elm @@ -13,6 +13,8 @@ module Pages.Settings exposing , timeout , timeoutInput , timeoutWarning + , validAccessUpdate + , validEventsUpdate , view ) @@ -21,6 +23,7 @@ import Html ( Html , button , div + , em , input , label , p @@ -43,7 +46,7 @@ import Html.Events exposing (onCheck, onClick, onInput) import RemoteData exposing (RemoteData(..), WebData) import SvgBuilder import Util -import Vela exposing (Field, Repository) +import Vela exposing (Field, Repository, UpdateRepositoryPayload) @@ -110,7 +113,7 @@ access : Repository -> RadioUpdate msg -> Html msg access repo msg = div [ class "category", Util.testAttribute "repo-settings-access" ] [ div [ class "header" ] [ span [ class "text" ] [ text "Access" ] ] - , div [ class "description" ] [ text "Change who can access build information" ] + , div [ class "description" ] [ text "Change who can access build information." ] , div [ class "inputs", class "radios" ] [ radio repo.visibility "private" "Private" <| msg repo.org repo.name "visibility" "private" , radio repo.visibility "public" "Any" <| msg repo.org repo.name "visibility" "public" @@ -124,7 +127,8 @@ events : Repository -> CheckboxUpdate msg -> Html msg events repo msg = div [ class "category", Util.testAttribute "repo-settings-events" ] [ div [ class "header" ] [ span [ class "text" ] [ text "Webhook Events" ] ] - , div [ class "description" ] [ text "Control which events on Git will trigger Vela pipelines" ] + , div [ class "description" ] [ text "Control which events on Git will trigger Vela pipelines." ] + , div [ class "description" ] [ em [] [ text "Active repositories must have at least one event enabled." ] ] , div [ class "inputs" ] [ checkbox "Push" "allow_push" @@ -156,7 +160,7 @@ timeout : Maybe Int -> Repository -> NumberInputChange msg -> (String -> msg) -> timeout inTimeout repo clickMsg inputMsg = div [ class "category", Util.testAttribute "repo-settings-timeout" ] [ div [ class "header" ] [ span [ class "text" ] [ text "Build Timeout" ] ] - , div [ class "description" ] [ text "Builds that reach this timeout setting will be stopped" ] + , div [ class "description" ] [ text "Builds that reach this timeout setting will be stopped." ] , timeoutInput repo inTimeout inputMsg @@ -300,6 +304,42 @@ validTimeout inTimeout repoTimeout = True +{-| validAccessUpdate : takes model webdata repo and repo visibility update and determines if an update is necessary +-} +validAccessUpdate : WebData Repository -> UpdateRepositoryPayload -> Bool +validAccessUpdate originalRepo repoUpdate = + case originalRepo of + RemoteData.Success repo -> + case repoUpdate.visibility of + Just visibility -> + if repo.visibility /= visibility then + True + + else + False + + Nothing -> + False + + _ -> + False + + +{-| validEventsUpdate : takes model webdata repo and repo events update and determines if an update is necessary +-} +validEventsUpdate : WebData Repository -> UpdateRepositoryPayload -> Bool +validEventsUpdate originalRepo repoUpdate = + case originalRepo of + RemoteData.Success repo -> + Maybe.withDefault repo.allow_push repoUpdate.allow_push + || Maybe.withDefault repo.allow_pull repoUpdate.allow_pull + || Maybe.withDefault repo.allow_deploy repoUpdate.allow_deploy + || Maybe.withDefault repo.allow_tag repoUpdate.allow_tag + + _ -> + False + + {-| updateTip : takes field and returns the tip to display after the label. -} updateTip : Field -> Html msg