Skip to content
This repository has been archived by the owner on Apr 5, 2024. It is now read-only.

feat: e2esdk [DO NOT MERGE] #169

Draft
wants to merge 8 commits into
base: hasura
Choose a base branch
from
Draft
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
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,7 @@ cypress/videos
cypress/screenshots

# Robots.txt
robots.txt
robots.txt

# local volume
.storage
17 changes: 17 additions & 0 deletions .kontinuous/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ app:
imagePackage: app
containerPort: 3000
probesPath: "/healthz"
volumes:
- name: uploads
emptyDir: {}
volumeMounts:
- name: uploads
mountPath: /uploads
env:
- name: STORAGE_DIR
value: /uploads
envFrom:
- configMapRef:
name: app
Expand Down Expand Up @@ -148,6 +157,10 @@ keycloakx:
- name: compile-realm
image: hairyhenderson/gomplate:v3.10.0-alpine
imagePullPolicy: IfNotPresent
securityContext:
allowPrivilegeEscalation: false
runAsNonRoot: true
runAsUser: 100
volumeMounts:
- name: keycloak-realm-tpl
mountPath: "/realm-tpl/"
Expand All @@ -170,6 +183,10 @@ keycloakx:
- "cat /realm-tpl/realm.json.envtpl | gomplate > /realm/realm.json"
- name: fetch-keycloak-providers
image: curlimages/curl
securityContext:
allowPrivilegeEscalation: false
runAsNonRoot: true
runAsUser: 405
imagePullPolicy: IfNotPresent
command:
- sh
Expand Down
270 changes: 179 additions & 91 deletions .talismanrc

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions csp.config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const ContentSecurityPolicy = `
default-src 'self' *.fabrique.social.gouv.fr;
img-src 'self' data: *.fabrique.social.gouv.fr https://dummyimage.com/;
script-src 'self' *.fabrique.social.gouv.fr ${
img-src 'self' blob: data: *.fabrique.social.gouv.fr https://dummyimage.com/;
script-src 'self' *.fabrique.social.gouv.fr 'wasm-unsafe-eval' ${
process.env.NODE_ENV !== "production" && "'unsafe-eval' 'unsafe-inline'"
};
connect-src 'self' *.fabrique.social.gouv.fr ${
connect-src 'self' data: wss: *.fabrique.social.gouv.fr ${
process.env.NODE_ENV !== "production" && "http://localhost:8082"
};
frame-src 'self' *.fabrique.social.gouv.fr;
Expand Down
40 changes: 40 additions & 0 deletions hasura/metadata/databases/default/tables/public_answers.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
table:
name: answers
schema: public
array_relationships:
- name: answers_files
using:
foreign_key_constraint_on:
column: answer_uuid
table:
name: answers_files
schema: public
insert_permissions:
- role: anonymous
permission:
check: {}
columns:
- created_at
- data
- id
- public_key
- sealed_secret
- signature
- submission_bucket_id
select_permissions:
- role: anonymous
permission:
columns:
- id
filter: {}
- role: user
permission:
columns:
- id
- data
- public_key
- sealed_secret
- signature
- submission_bucket_id
- created_at
filter: {}
23 changes: 23 additions & 0 deletions hasura/metadata/databases/default/tables/public_answers_files.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
table:
name: answers_files
schema: public
object_relationships:
- name: answer
using:
foreign_key_constraint_on: answer_uuid
insert_permissions:
- role: anonymous
permission:
check: {}
columns:
- answer_uuid
- file_hash
select_permissions:
- role: user
permission:
columns:
- answer_uuid
- file_hash
- id
filter: {}
allow_aggregations: true
22 changes: 22 additions & 0 deletions hasura/metadata/databases/default/tables/public_files.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
table:
name: files
schema: public
insert_permissions:
- role: anonymous
permission:
check: {}
columns:
- hash
- key
select_permissions:
- role: user
permission:
columns:
- hash
- key
filter: {}
delete_permissions:
- role: user
permission:
backend_only: false
filter: {}
2 changes: 2 additions & 0 deletions hasura/metadata/databases/default/tables/tables.yaml
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
- "!include public_answers.yaml"
- "!include public_answers_files.yaml"
- "!include public_books.yaml"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DROP TABLE "public"."answers";
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREATE TABLE "public"."answers" ("id" serial NOT NULL, "created_at" timestamptz NOT NULL DEFAULT now(), "submission_bucket_id" text NOT NULL, "sealed_secret" text NOT NULL, "public_key" text NOT NULL, "data" text NOT NULL, PRIMARY KEY ("id") , UNIQUE ("id"), UNIQUE ("sealed_secret"), UNIQUE ("public_key"));
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- Could not auto-generate a down migration.
-- Please write an appropriate down migration for the SQL below:
-- alter table "public"."answers" add column "signature" text
-- not null unique;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
alter table "public"."answers" add column "signature" text
not null unique;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DROP TABLE "public"."files";
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREATE TABLE "public"."files" ("hash" text NOT NULL, "key" text NOT NULL, PRIMARY KEY ("hash") );
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DROP TABLE "public"."answers_files";
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREATE TABLE "public"."answers_files" ("id" serial NOT NULL, "answer_id" integer NOT NULL, "file_hash" text NOT NULL, PRIMARY KEY ("id") , FOREIGN KEY ("answer_id") REFERENCES "public"."answers"("id") ON UPDATE cascade ON DELETE cascade, FOREIGN KEY ("file_hash") REFERENCES "public"."files"("hash") ON UPDATE cascade ON DELETE cascade, UNIQUE ("answer_id", "file_hash"));
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
alter table "public"."files" drop constraint "files_hash_key";
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
alter table "public"."files" add constraint "files_hash_key" unique ("hash");
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- Could not auto-generate a down migration.
-- Please write an appropriate down migration for the SQL below:
-- alter table "public"."answers" add column "uuid" uuid
-- not null;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
alter table "public"."answers" add column "uuid" uuid
not null;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE "public"."answers" ALTER COLUMN "uuid" drop default;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
alter table "public"."answers" alter column "uuid" set default gen_random_uuid();
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
alter table "public"."answers_files" add constraint "answers_files_answer_id_file_hash_key" unique (answer_id, file_hash);
alter table "public"."answers_files"
add constraint "answers_files_answer_id_fkey"
foreign key (answer_id)
references "public"."answers"
(id) on update cascade on delete cascade;
alter table "public"."answers_files" alter column "answer_id" drop not null;
alter table "public"."answers_files" add column "answer_id" int4;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
alter table "public"."answers_files" drop column "answer_id" cascade;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- Could not auto-generate a down migration.
-- Please write an appropriate down migration for the SQL below:
-- alter table "public"."answers_files" add column "answer_uuid" uuid
-- not null;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
alter table "public"."answers_files" add column "answer_uuid" uuid
not null;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
alter table "public"."answers" drop constraint "answers_pkey";
alter table "public"."answers"
add constraint "answers_pkey"
primary key ("id");
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
BEGIN TRANSACTION;
ALTER TABLE "public"."answers" DROP CONSTRAINT "answers_pkey";

ALTER TABLE "public"."answers"
ADD CONSTRAINT "answers_pkey" PRIMARY KEY ("uuid");
COMMIT TRANSACTION;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
alter table "public"."answers_files" drop constraint "answers_files_answer_uuid_fkey";
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
alter table "public"."answers_files"
add constraint "answers_files_answer_uuid_fkey"
foreign key ("answer_uuid")
references "public"."answers"
("uuid") on update cascade on delete cascade;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
alter table "public"."answers_files" drop constraint "answers_files_file_hash_answer_uuid_key";
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
alter table "public"."answers_files" add constraint "answers_files_file_hash_answer_uuid_key" unique ("file_hash", "answer_uuid");
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- Could not auto-generate a down migration.
-- Please write an appropriate down migration for the SQL below:
-- alter table "public"."files" add column "answers_files_id" integer
-- null;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
alter table "public"."files" add column "answers_files_id" integer
null;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
alter table "public"."files" drop constraint "files_answers_files_id_fkey";
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
alter table "public"."files"
add constraint "files_answers_files_id_fkey"
foreign key ("answers_files_id")
references "public"."answers_files"
("id") on update cascade on delete cascade;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
-- Could not auto-generate a down migration.
-- Please write an appropriate down migration for the SQL below:
-- alter table "public"."answers_files" add column "key" text
-- not null;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
alter table "public"."answers_files" add column "key" text
not null;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
alter table "public"."files"
add constraint "files_answers_files_id_fkey"
foreign key ("answers_files_id")
references "public"."answers_files"
("id") on update cascade on delete cascade;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
alter table "public"."files" drop constraint "files_answers_files_id_fkey";
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
alter table "public"."files" add constraint "files_hash_key" unique ("hash");
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
alter table "public"."files" drop constraint "files_hash_key";
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-- Could not auto-generate a down migration.
-- Please write an appropriate down migration for the SQL below:
-- DROP TABLE files CASCADE;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DROP TABLE files CASCADE;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
alter table "public"."answers_files" rename column "file_key" to "key";
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
alter table "public"."answers_files" rename column "key" to "file_key";
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
alter table "public"."answers_files" alter column "file_key" drop not null;
alter table "public"."answers_files" add column "file_key" text;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
alter table "public"."answers_files" drop column "file_key" cascade;
10 changes: 10 additions & 0 deletions next-auth.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import NextAuth, { DefaultSession } from "next-auth";

// augment default Session type
declare module "next-auth" {
interface Session {
user: {
id: string;
} & DefaultSession["user"];
}
}
14 changes: 13 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,24 @@
"@mui/x-data-grid": "^5.17.16",
"@mui/x-date-pickers": "^5.0.11",
"@sentry/nextjs": "^7.60.1",
"@socialgouv/e2esdk-client": "1.0.0-beta.28",
"@socialgouv/e2esdk-crypto": "1.0.0-beta.20",
"@socialgouv/e2esdk-devtools": "1.0.0-beta.38",
"@socialgouv/e2esdk-react": "1.0.0-beta.28",
"@socialgouv/matomo-next": "^1.6.1",
"boring-avatars": "^1.7.0",
"dayjs": "^1.11.9",
"formidable": "3.2.5",
"js-image-generator": "^1.0.4",
"next": "13.4.12",
"next-auth": "^4.22.3",
"random-words": "^1.3.0",
"react": "18.2.0",
"react-dom": "18.2.0",
"tss-react": "^4.8.8"
"react-dropzone": "^14.2.3",
"react-hook-form": "^7.44.2",
"tss-react": "^4.8.8",
"zod": "^3.21.4"
},
"devDependencies": {
"@babel/core": "^7.22.9",
Expand All @@ -55,6 +66,7 @@
"@storybook/testing-library": "^0.0.11",
"@testing-library/jest-dom": "^5.17.0",
"@testing-library/react": "^14.0.0",
"@types/formidable": "^2.0.6",
"@types/node": "18.11.17",
"@types/react": "^18.2.0",
"@types/react-dom": "^18.2.0",
Expand Down
17 changes: 17 additions & 0 deletions src/components/devtools.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import '@socialgouv/e2esdk-devtools'
import { E2ESDKDevtoolsElement } from '@socialgouv/e2esdk-devtools'
import { useE2ESDKClient } from '@socialgouv/e2esdk-react'
import React from 'react'

export const Devtools = () => {
const client = useE2ESDKClient()
const ref = React.useRef<E2ESDKDevtoolsElement>(null)
React.useEffect(() => {
if (!ref.current) {
return
}
ref.current.client = client
}, [client])
return <e2esdk-devtools ref={ref} theme="dark" />
}

5 changes: 5 additions & 0 deletions src/config/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import path from "node:path";

export const storageDir =
process.env.STORAGE_DIR ||
path.resolve(process.cwd(), "./.storage/answers_files");
Loading
Loading