Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

patch(v0.21.1/secrets): allow schedules for secret form if on allowlist #719

Merged
merged 1 commit into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions cypress/integration/secrets.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,34 @@ context('Secrets', () => {
.contains('Remove');
});

context(
'allowlist contains *',
{
env: {
VELA_SCHEDULE_ALLOWLIST: '*',
},
},
() => {
it('add button should show', () => {
cy.get('[data-test=repo-checkbox-schedule]').should('exist');
});
},
);

context(
'allowlist is empty',
{
env: {
VELA_SCHEDULE_ALLOWLIST: ' ',
},
},
() => {
it('add button should not show', () => {
cy.get('[data-test=repo-checkbox-schedule]').should('not.exist');
});
},
);

context('click Remove', () => {
beforeEach(() => {
cy.get('[data-test=secret-delete-button]').click();
Expand Down
1 change: 1 addition & 0 deletions src/elm/Main.elm
Original file line number Diff line number Diff line change
Expand Up @@ -3733,6 +3733,7 @@ loadOrgSecretsPage model maybePage maybePerPage engine org =
{ secretsModel
| orgSecrets = Loading
, org = org
, repo = ""
, engine = engine
, type_ = Vela.OrgSecret
}
Expand Down
22 changes: 19 additions & 3 deletions src/elm/Pages/Secrets/Form.elm
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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" ]
Expand Down Expand Up @@ -207,6 +222,7 @@ viewEventsSelect secretUpdate =
(eventEnabled "deployment" secretUpdate.events)
<|
OnChangeEvent "deployment"
, scheduleOption
]
]

Expand Down
1 change: 1 addition & 0 deletions src/elm/Pages/Secrets/Model.elm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 14 additions & 15 deletions src/elm/Pages/Secrets/View.elm
Original file line number Diff line number Diff line change
Expand Up @@ -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(..))
Expand Down Expand Up @@ -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
]
]

Expand All @@ -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
Expand All @@ -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" ]
]
]

Expand Down Expand Up @@ -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
]
]

Expand Down Expand Up @@ -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
]