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

1703 3 hard delete attachments #1825

Closed
wants to merge 75 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
57c6d00
chore: create and use attachmentDeleteRouter
BCerki Jun 28, 2023
1584e0f
test: jest test attachmentDeleteRouter
BCerki Jun 28, 2023
78213d2
chore: create delete page route
BCerki Jun 28, 2023
56d2cdd
feat: hard delete attachments from GCS
BCerki Jun 28, 2023
f1e5f04
test: add file upload to cypress test
BCerki Jun 28, 2023
83279df
feat: hard delete attachments from GCS
BCerki Jul 6, 2023
133261d
chore: create and use attachmentDeleteRouter
BCerki Jul 6, 2023
229dba1
test: add file upload to cypress test
BCerki Jul 6, 2023
f58f92c
spec work
BCerki Jul 6, 2023
7ce5f33
chore: add delete permissions to attachment table
BCerki Jul 13, 2023
d79a1d1
feat: hard delete attachments from GCS
BCerki Jul 13, 2023
f08c812
test: test AttachmentTableRow
BCerki Jul 13, 2023
6f30fba
chore: spec work
BCerki Jul 13, 2023
06badc1
test: jest tests
BCerki Jul 13, 2023
6857255
feat: hard delete attachments from GCS
BCerki Jul 13, 2023
a8d7424
test: jest
BCerki Jul 13, 2023
0c29399
test: update pgtap tests
BCerki Jul 14, 2023
3455453
test: debug CI cypress tests
BCerki Jul 14, 2023
0b57c19
chore: spec work
BCerki Jul 18, 2023
720a2bd
test: debug CI cypress tests
BCerki Jul 18, 2023
93a2c3b
test: debug CI cypress tests
BCerki Jul 19, 2023
58e095f
test: temporarily delete cypress tests for faster CI
BCerki Jul 19, 2023
4c0c150
test: debug CI cypress tests
BCerki Jul 20, 2023
2363e9f
test: go back to original emissions migration test
BCerki Jul 20, 2023
26c365d
test: debug CI cypress tests
BCerki Jul 20, 2023
18b80ad
test: debug CI cypress tests
BCerki Jul 20, 2023
5a470cf
chore: add GCS auth to github e2e action
BCerki Jul 20, 2023
02084b0
test: debug CI cypress tests
BCerki Jul 20, 2023
c5118ea
chore: remove loop from discard mutation
BCerki Jul 20, 2023
f30c17b
chore: spec work
BCerki Jul 20, 2023
9927a86
chore: refresh after delete
BCerki Jul 21, 2023
4c1108e
test: debug CI cypress tests
BCerki Jul 21, 2023
e07dd17
chore: spec work
BCerki Jul 21, 2023
8a84d82
chore: remove loop from discard mutation
BCerki Jul 21, 2023
54a080c
chore: spec work
BCerki Jul 21, 2023
f823eca
chore: debug cypress CI
BCerki Jul 21, 2023
d1c1a2c
chore: temp remove checks for faster CI
BCerki Jul 24, 2023
a59b83f
chore: debug cypress CI
BCerki Jul 24, 2023
da498c3
chore: debug cypress CI
BCerki Jul 24, 2023
866c718
chore: debug cypress CI
BCerki Jul 24, 2023
9405e19
chore: debug cypress CI
BCerki Jul 24, 2023
696f394
chore: debug cypress CI-bucket error
BCerki Jul 24, 2023
5f4282e
chore: debug cypress CI-missing file
BCerki Jul 24, 2023
93259bb
chore: debug cypress CI-view logs
BCerki Jul 24, 2023
11eb99c
chore: debug cypress CI-tmate
BCerki Jul 24, 2023
6def4bc
chore: add to gitignore
BCerki Jul 24, 2023
2d43475
chore: debug cypress CI-reorder CI steps
BCerki Jul 24, 2023
b73ee17
chore: debug cypress CI--try to set default credentials
BCerki Jul 24, 2023
a805d41
chore: fix stuck CI
BCerki Jul 24, 2023
ec8d940
chore: debug cypress CI--try to set default credentials
BCerki Jul 24, 2023
9e26b04
chore: debug cypress CI--try to set default credentials
BCerki Jul 24, 2023
d79e8cc
chore: remove some whitespace to trigger CI
BCerki Jul 25, 2023
9a843d9
chore: debug cypress CI
BCerki Jul 25, 2023
90f7980
test: add detached true to tmate session
dleard Jul 25, 2023
896c56f
test: workflow uses federated identity
dleard Jul 25, 2023
7a01f13
test: add token permissions to e2e job
dleard Jul 25, 2023
c9e2852
test: export env vars in workflow
dleard Jul 25, 2023
ac0cd95
test: set env var in gh env
dleard Jul 25, 2023
cdc19a1
chore: add test env
dleard Jul 26, 2023
c6a62ec
test: remove run block, it was breaking CI
dleard Jul 26, 2023
d610032
test: debugging ci
dleard Jul 26, 2023
c7c2eea
test: debugging ci
dleard Jul 26, 2023
ea1239b
test: debugging ci
dleard Jul 26, 2023
ed0b0db
test: debugging ci
dleard Jul 26, 2023
1913a67
test: debugging ci
dleard Jul 26, 2023
7f50684
chore: rename cyress env variables
BCerki Jul 28, 2023
1570b79
chore: debug cypress
BCerki Jul 31, 2023
4623101
chore: debug cypress
BCerki Jul 31, 2023
ba4e25e
chore: debug cypress
BCerki Jul 31, 2023
ec269bf
chore: debug CI
BCerki Aug 1, 2023
3be0731
chore: debug CI
BCerki Aug 1, 2023
e982643
chore: debug CI
BCerki Aug 1, 2023
91651b9
chore: debug CI
BCerki Aug 1, 2023
fd7485e
chore: debug CI
BCerki Aug 3, 2023
1f14c08
chore: debug CI
BCerki Aug 3, 2023
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
120 changes: 60 additions & 60 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
@@ -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
27 changes: 26 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand All @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ cypress.env.json
app/cypress.env.json
dev/db/data
**/.DS_Store

gha-creds-*.json
50 changes: 29 additions & 21 deletions app/components/Attachment/AttachmentTableRow.tsx
Original file line number Diff line number Diff line change
@@ -1,35 +1,32 @@
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<Props> = ({
attachment,
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
Expand All @@ -45,32 +42,43 @@ const AttachmentTableRow: React.FC<Props> = ({
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 (
<>
<tr>
<td>{fileName}</td>
<td>{fileType}</td>
<td>{fileSize}</td>
<td>{fullName}</td>
<td>{cifUserByCreatedBy?.fullName}</td>
<td>{createdAt}</td>
<td className="links">
<Link href={getAttachmentDownloadRoute(id)} passHref>
<Button size="small">Download</Button>
</Link>
{!hideDelete && (
<Button
onClick={handleArchiveAttachment}
onClick={() => handleArchiveAttachment(id)}
disabled={isDiscardingProjectAttachmentFormChange}
size="small"
>
Expand Down
17 changes: 17 additions & 0 deletions app/components/Attachment/hardDeleteAttachement.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { getAttachmentDeleteRoute } from "routes/pageRoutes";

const hardDeleteAttachment = (attachmentId, formChangeRowId) => {
fetch(getAttachmentDeleteRoute(attachmentId).pathname, {
method: "DELETE",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
variables: {
input: {
formChangeId: formChangeRowId,
},
},
}),
});
};

export default hardDeleteAttachment;
25 changes: 16 additions & 9 deletions app/components/Form/ProjectAttachmentsForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ const ProjectAttachmentsForm: React.FC<Props> = ({
projectRevision,
onSubmit,
}) => {
const { rowId, projectAttachmentFormChanges } = useFragment(
const brianna = useFragment(
graphql`
fragment ProjectAttachmentsForm_projectRevision on ProjectRevision {
id
rowId
isFirstRevision
projectAttachmentFormChanges: formChangesFor(
first: 500
formDataTableName: "project_attachment"
Expand All @@ -57,6 +59,7 @@ const ProjectAttachmentsForm: React.FC<Props> = ({
projectRevision
);

const { rowId, projectAttachmentFormChanges, isFirstRevision } = brianna;
const attachmentFormChange = projectAttachmentFormChanges.edges[0]?.node;
const [createAttachment, isCreatingAttachment] = useCreateAttachment();
const [createProjectAttachment, isCreatingProjectAttachment] =
Expand Down Expand Up @@ -143,14 +146,18 @@ const ProjectAttachmentsForm: React.FC<Props> = ({
totalRowCount={projectAttachmentFormChanges.totalCount}
filters={tableFilters}
>
{projectAttachmentFormChanges.edges.map(({ node }) => (
<AttachmentTableRow
key={node.id}
attachment={node.asProjectAttachment.attachmentByAttachmentId}
formChangeRowId={node.rowId}
connectionId={projectAttachmentFormChanges.__id}
/>
))}
{projectAttachmentFormChanges.edges.map(({ node }) => {
if (!node) return null;
return (
<AttachmentTableRow
key={node.id}
attachment={node.asProjectAttachment.attachmentByAttachmentId}
formChangeRowId={node.rowId}
connectionId={projectAttachmentFormChanges.__id}
isFirstRevision={isFirstRevision}
/>
);
})}
</Table>
<Button
type="submit"
Expand Down
2 changes: 1 addition & 1 deletion app/components/Form/ProjectAttachmentsFormSummary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ const ProjectAttachmentsFormSummary: React.FC<Props> = ({

const attachmentsSummary =
revision.summaryProjectAttachmentFormChanges.edges[0]?.node;

const projectAttachmentsFormNotUpdated = useMemo(
() =>
!attachmentsSummary ||
Expand Down Expand Up @@ -100,6 +99,7 @@ const ProjectAttachmentsFormSummary: React.FC<Props> = ({
formChangeRowId={node.rowId}
connectionId={revision.summaryProjectAttachmentFormChanges.__id}
hideDelete={true}
isFirstRevision={revision.isFirstRevision}
/>
)
)}
Expand Down
1 change: 1 addition & 0 deletions app/components/Layout/DefaultLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const DefaultLayout: React.FC<Props> = ({

return (
<div id="page-wrap">
<div>{error}</div>
<Navigation
links={subHeaderLinks}
isLoggedIn={Boolean(session)}
Expand Down
2 changes: 1 addition & 1 deletion app/cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default defineConfig({
screenshotOnRunFailure: false,
defaultCommandTimeout: 10000,
retries: {
runMode: 3,
runMode: 0,
openMode: 0,
},
fixturesFolder: "../schema/data",
Expand Down
Loading
Loading