diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 8ac3d19895..a963515370 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -1,70 +1,70 @@ -# For most projects, this workflow file will not need changing; you simply need -# to commit it to your repository. -# -# You may wish to alter this file to override the set of languages analyzed, -# or to provide custom queries or build logic. -# -# ******** NOTE ******** -# We have attempted to detect the languages in your repository. Please check -# the `language` matrix defined below to confirm you have the correct set of -# supported CodeQL languages. -# -name: "CodeQL" +# # For most projects, this workflow file will not need changing; you simply need +# # to commit it to your repository. +# # +# # You may wish to alter this file to override the set of languages analyzed, +# # or to provide custom queries or build logic. +# # +# # ******** NOTE ******** +# # We have attempted to detect the languages in your repository. Please check +# # the `language` matrix defined below to confirm you have the correct set of +# # supported CodeQL languages. +# # +# name: "CodeQL" -on: - push: - branches: [develop] - pull_request: - # The branches below must be a subset of the branches above - branches: [develop] - schedule: - - cron: "19 23 * * 5" +# on: +# push: +# branches: [develop] +# pull_request: +# # The branches below must be a subset of the branches above +# branches: [develop] +# schedule: +# - cron: "19 23 * * 5" -jobs: - analyze: - name: Analyze - runs-on: ubuntu-latest - permissions: - actions: read - contents: read - security-events: write +# jobs: +# analyze: +# name: Analyze +# runs-on: ubuntu-latest +# permissions: +# actions: read +# contents: read +# security-events: write - strategy: - fail-fast: false - matrix: - language: [javascript] - # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ] - # Learn more about CodeQL language support at https://git.io/codeql-language-support +# strategy: +# fail-fast: false +# matrix: +# language: [javascript] +# # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ] +# # Learn more about CodeQL language support at https://git.io/codeql-language-support - steps: - - name: Checkout repository - uses: actions/checkout@v3 +# steps: +# - name: Checkout repository +# uses: actions/checkout@v3 - # Initializes the CodeQL tools for scanning. - - name: Initialize CodeQL - uses: github/codeql-action/init@v2 - with: - languages: ${{ matrix.language }} - # If you wish to specify custom queries, you can do so here or in a config file. - # By default, queries listed here will override any specified in a config file. - # Prefix the list here with "+" to use these queries and those in the config file. - # queries: ./path/to/local/query, your-org/your-repo/queries@main +# # Initializes the CodeQL tools for scanning. +# - name: Initialize CodeQL +# uses: github/codeql-action/init@v2 +# with: +# languages: ${{ matrix.language }} +# # If you wish to specify custom queries, you can do so here or in a config file. +# # By default, queries listed here will override any specified in a config file. +# # Prefix the list here with "+" to use these queries and those in the config file. +# # queries: ./path/to/local/query, your-org/your-repo/queries@main - # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). - # If this step fails, then you should remove it and run the build manually (see below) - - name: Autobuild - uses: github/codeql-action/autobuild@v2 +# # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). +# # If this step fails, then you should remove it and run the build manually (see below) +# - name: Autobuild +# uses: github/codeql-action/autobuild@v2 - # ℹī¸ Command-line programs to run using the OS shell. - # 📚 https://git.io/JvXDl +# # ℹī¸ Command-line programs to run using the OS shell. +# # 📚 https://git.io/JvXDl - # ✏ī¸ If the Autobuild fails above, remove it and uncomment the following three lines - # and modify them (or add more) to build your code if your project - # uses a compiled language +# # ✏ī¸ If the Autobuild fails above, remove it and uncomment the following three lines +# # and modify them (or add more) to build your code if your project +# # uses a compiled language - #- run: | - # make bootstrap - # make release +# #- run: | +# # make bootstrap +# # make release - - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v2 +# - name: Perform CodeQL Analysis +# uses: github/codeql-action/analyze@v2 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5137b3db6e..472d1ad924 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -165,12 +165,26 @@ jobs: e2e: needs: ["docker-build", "install-dev-tools"] runs-on: ubuntu-latest + permissions: + contents: "read" + id-token: "write" steps: - uses: actions/checkout@v3 - name: dev env setup uses: ./.github/actions/dev-env-setup + # - name: Setup tmate session + # uses: mxschmitt/action-tmate@v3 + # with: + # detached: true - name: run app locally uses: ./.github/actions/local-app-run + - id: "auth" + name: "Authenticate to Google Cloud" + uses: "google-github-actions/auth@v1" + with: + export_environment_variables: true + workload_identity_provider: ${{secrets.IDENTITY_PROVIDER}} + service_account: ${{secrets.GCS_SERVICE_ACCOUNT}} - name: run e2e tests env: CYPRESS_TEST_INTERNAL_USERNAME: ${{ secrets.TEST_INTERNAL_USERNAME }} @@ -181,7 +195,18 @@ jobs: CYPRESS_TEST_UNAUTHORIZED_PASSWORD: ${{ secrets.TEST_UNAUTHORIZED_PASSWORD }} HAPPO_API_KEY: ${{ secrets.HAPPO_API_KEY }} HAPPO_API_SECRET: ${{ secrets.HAPPO_API_SECRET }} - run: yarn test:e2e + TEST_ENV: "test" + CYPRESS_GOOGLE_APPLICATION_CREDENTIALS: ${{env.GOOGLE_APPLICATION_CREDENTIALS}} + CYPRESS_ATTACHMENTS_BUCKET: ${{secrets.ATTACHMENTS_BUCKET}} + GOOGLE_APPLICATION_CREDENTIALS: ${{env.GOOGLE_APPLICATION_CREDENTIALS}} + ATTACHMENTS_BUCKET: ${{secrets.ATTACHMENTS_BUCKET}} + run: | + echo $CYPRESS_GOOGLE_APPLICATION_CREDENTIALS + echo $TEST_ENV + echo $ATTACHMENTS_BUCKET + echo $CYPRESS_ATTACHMENTS_BUCKET + pwd + yarn test:e2e working-directory: ./app zap-owasp: diff --git a/.gitignore b/.gitignore index 44a91e988f..22c37b0f0e 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,5 @@ cypress.env.json app/cypress.env.json dev/db/data **/.DS_Store + +gha-creds-*.json diff --git a/app/components/Attachment/AttachmentTableRow.tsx b/app/components/Attachment/AttachmentTableRow.tsx index 94ad3cc2c6..6ed59b52b8 100644 --- a/app/components/Attachment/AttachmentTableRow.tsx +++ b/app/components/Attachment/AttachmentTableRow.tsx @@ -1,15 +1,18 @@ import { Button } from "@button-inc/bcgov-theme"; +import useDiscardProjectAttachmentFormChange from "mutations/attachment/discardProjectAttachmentFormChange"; import Link from "next/link"; -import { getAttachmentDownloadRoute } from "routes/pageRoutes"; import { graphql, useFragment } from "react-relay"; -import useDiscardProjectAttachmentFormChange from "mutations/attachment/discardProjectAttachmentFormChange"; +import { getAttachmentDownloadRoute } from "routes/pageRoutes"; import { AttachmentTableRow_attachment$key } from "__generated__/AttachmentTableRow_attachment.graphql"; +import hardDeleteAttachment from "./hardDeleteAttachement"; +import { useRouter } from "next/router"; interface Props { attachment: AttachmentTableRow_attachment$key; connectionId: string; formChangeRowId: number; hideDelete?: boolean; + isFirstRevision: boolean; } const AttachmentTableRow: React.FC = ({ @@ -17,19 +20,13 @@ const AttachmentTableRow: React.FC = ({ connectionId, formChangeRowId, hideDelete, + isFirstRevision, }) => { const [ discardProjectAttachmentFormChange, isDiscardingProjectAttachmentFormChange, ] = useDiscardProjectAttachmentFormChange(); - const { - id, - fileName, - fileType, - fileSize, - createdAt, - cifUserByCreatedBy: { fullName }, - } = useFragment( + const attachmentRow = useFragment( graphql` fragment AttachmentTableRow_attachment on Attachment { id @@ -45,24 +42,35 @@ const AttachmentTableRow: React.FC = ({ attachment ); - const handleArchiveAttachment = () => { - discardProjectAttachmentFormChange({ - variables: { - input: { - formChangeId: formChangeRowId, + const router = useRouter(); + if (!attachmentRow) return null; + const { id, fileName, fileType, fileSize, createdAt, cifUserByCreatedBy } = + attachmentRow; + + const handleArchiveAttachment = (attachmentId) => { + if (isFirstRevision) { + console.log("in if handlearchiveattachment"); + hardDeleteAttachment(attachmentId, formChangeRowId); + router.replace(router.asPath); + } else { + discardProjectAttachmentFormChange({ + variables: { + input: { + formChangeId: formChangeRowId, + }, + connections: [connectionId], }, - connections: [connectionId], - }, - }); + }); + } }; - + console.log("connectionid", connectionId); return ( <> {fileName} {fileType} {fileSize} - {fullName} + {cifUserByCreatedBy?.fullName} {createdAt} @@ -70,7 +78,7 @@ const AttachmentTableRow: React.FC = ({ {!hideDelete && (