diff --git a/src/elm/Pages/Secrets/Form.elm b/src/elm/Pages/Secrets/Form.elm index 8c693fa7e..d0b901133 100644 --- a/src/elm/Pages/Secrets/Form.elm +++ b/src/elm/Pages/Secrets/Form.elm @@ -49,7 +49,7 @@ import Html.Attributes ) import Html.Events exposing (onClick, onInput) import Pages.RepoSettings exposing (checkbox) -import Pages.Secrets.Model exposing (DeleteSecretState(..), Model, Msg(..), SecretForm) +import Pages.Secrets.Model exposing (DeleteSecretState(..), Model, Msg(..), PartialModel, SecretForm) import Util import Vela exposing (Field) @@ -166,8 +166,23 @@ viewValueInput val placeholder_ = {-| viewEventsSelect : renders events input selection -} -viewEventsSelect : SecretForm -> Html Msg -viewEventsSelect secretUpdate = +viewEventsSelect : SecretForm -> PartialModel a msg -> Html Msg +viewEventsSelect secretUpdate model = + let + schedulesAllowed = + Util.checkScheduleAllowlist model.secretsModel.org model.secretsModel.repo model.velaScheduleAllowlist + + scheduleOption = + if schedulesAllowed then + checkbox "Schedule" + "schedule" + (eventEnabled "schedule" secretUpdate.events) + <| + OnChangeEvent "schedule" + + else + text "" + in section [] [ div [ for "events-select" ] [ strong [] [ text "Limit to Events" ] @@ -181,6 +196,7 @@ viewEventsSelect secretUpdate = , div [ class "form-controls" , class "-stack" + , Util.testAttribute "event-checkbox" ] [ checkbox "Push" "push" @@ -207,6 +223,7 @@ viewEventsSelect secretUpdate = (eventEnabled "deployment" secretUpdate.events) <| OnChangeEvent "deployment" + , scheduleOption ] ] diff --git a/src/elm/Pages/Secrets/Model.elm b/src/elm/Pages/Secrets/Model.elm index 7fb2173f1..cd7aec763 100644 --- a/src/elm/Pages/Secrets/Model.elm +++ b/src/elm/Pages/Secrets/Model.elm @@ -36,6 +36,7 @@ import Vela exposing (Copy, Engine, Key, Org, Repo, Secret, SecretType, Secrets, type alias PartialModel a msg = { a | velaAPI : String + , velaScheduleAllowlist : List ( Org, Repo ) , session : Session , page : Page , secretsModel : Model msg diff --git a/src/elm/Pages/Secrets/View.elm b/src/elm/Pages/Secrets/View.elm index 63c517582..ca6ed327b 100644 --- a/src/elm/Pages/Secrets/View.elm +++ b/src/elm/Pages/Secrets/View.elm @@ -15,8 +15,7 @@ import Http import Pages.Secrets.Form exposing (viewAllowCommandCheckbox, viewEventsSelect, viewHelp, viewImagesInput, viewInput, viewNameInput, viewSubmitButtons, viewValueInput) import Pages.Secrets.Model exposing - ( Model - , Msg + ( Msg , PartialModel ) import RemoteData exposing (RemoteData(..)) @@ -540,7 +539,7 @@ addSecret model = div [ class "manage-secret", Util.testAttribute "manage-secret" ] [ div [] [ h2 [] [ addLabel model.secretsModel.type_ ] - , addForm model.secretsModel + , addForm model ] ] @@ -562,14 +561,14 @@ addLabel type_ = {-| addForm : renders secret update form for adding a new secret -} -addForm : Model msg -> Html Msg -addForm secretsModel = +addForm : PartialModel a msg -> Html Msg +addForm partialModel = let secretUpdate = - secretsModel.form + partialModel.secretsModel.form teamForm = - if secretsModel.team == "*" && secretsModel.type_ == SharedSecret then + if partialModel.secretsModel.team == "*" && partialModel.secretsModel.type_ == SharedSecret then viewInput "Team" secretUpdate.team "Team Name" else @@ -579,12 +578,12 @@ addForm secretsModel = [ teamForm , viewNameInput secretUpdate.name False , viewValueInput secretUpdate.value "Secret Value" - , viewEventsSelect secretUpdate + , viewEventsSelect secretUpdate partialModel , viewImagesInput secretUpdate secretUpdate.imageInput , viewAllowCommandCheckbox secretUpdate , viewHelp , div [ class "form-action" ] - [ button [ class "button", class "-outline", onClick <| Pages.Secrets.Model.AddSecret secretsModel.engine ] [ text "Add" ] + [ button [ class "button", class "-outline", onClick <| Pages.Secrets.Model.AddSecret partialModel.secretsModel.engine ] [ text "Add" ] ] ] @@ -617,7 +616,7 @@ editSecret model = div [ class "manage-secret", Util.testAttribute "manage-secret" ] [ div [] [ h2 [] [ editHeader model.secretsModel.type_ ] - , editForm model.secretsModel + , editForm model ] ] @@ -645,18 +644,18 @@ editHeader type_ = {-| editForm : renders secret update form for updating a preexisting secret -} -editForm : Model msg -> Html Msg -editForm secretsModel = +editForm : PartialModel a msg -> Html Msg +editForm partialModel = let secretUpdate = - secretsModel.form + partialModel.secretsModel.form in div [ class "secret-form", class "edit-form" ] [ viewNameInput secretUpdate.name True , viewValueInput secretUpdate.value "Secret Value (leave blank to make no change)" - , viewEventsSelect secretUpdate + , viewEventsSelect secretUpdate partialModel , viewImagesInput secretUpdate secretUpdate.imageInput , viewAllowCommandCheckbox secretUpdate , viewHelp - , viewSubmitButtons secretsModel + , viewSubmitButtons partialModel.secretsModel ]