diff --git a/.sqlx/query-ca879d63b2e3a9e270d43619fa7dbad82bdb46902e973d72b9467b92bc6490fd.json b/.sqlx/query-2e5f35966af96b8c8285a3d2e963650beb4bc2c993298f66225f63ccb66b5543.json similarity index 82% rename from .sqlx/query-ca879d63b2e3a9e270d43619fa7dbad82bdb46902e973d72b9467b92bc6490fd.json rename to .sqlx/query-2e5f35966af96b8c8285a3d2e963650beb4bc2c993298f66225f63ccb66b5543.json index c66eaca..0fc1ca3 100644 --- a/.sqlx/query-ca879d63b2e3a9e270d43619fa7dbad82bdb46902e973d72b9467b92bc6490fd.json +++ b/.sqlx/query-2e5f35966af96b8c8285a3d2e963650beb4bc2c993298f66225f63ccb66b5543.json @@ -1,6 +1,6 @@ { "db_name": "PostgreSQL", - "query": "SELECT id, approved, revoked, created_at, deleted_at, updated_at, approved_at, revoked_at, ctype_hash, credential, claimer, marked_approve, tx_state as \"tx_state: TxState\"\n FROM attestation_requests WHERE id = $1 AND deleted_at is NULL", + "query": "SELECT id, approved, revoked, created_at, deleted_at, approved_at, revoked_at, ctype_hash, credential, claimer, marked_approve, tx_state as \"tx_state: TxState\"\n FROM attestation_requests WHERE id = $1 AND deleted_at is NULL", "describe": { "columns": [ { @@ -30,41 +30,36 @@ }, { "ordinal": 5, - "name": "updated_at", - "type_info": "Timestamp" - }, - { - "ordinal": 6, "name": "approved_at", "type_info": "Timestamp" }, { - "ordinal": 7, + "ordinal": 6, "name": "revoked_at", "type_info": "Timestamp" }, { - "ordinal": 8, + "ordinal": 7, "name": "ctype_hash", "type_info": "Varchar" }, { - "ordinal": 9, + "ordinal": 8, "name": "credential", "type_info": "Jsonb" }, { - "ordinal": 10, + "ordinal": 9, "name": "claimer", "type_info": "Varchar" }, { - "ordinal": 11, + "ordinal": 10, "name": "marked_approve", "type_info": "Bool" }, { - "ordinal": 12, + "ordinal": 11, "name": "tx_state: TxState", "type_info": { "Custom": { @@ -94,7 +89,6 @@ true, true, true, - true, false, false, false, @@ -102,5 +96,5 @@ true ] }, - "hash": "ca879d63b2e3a9e270d43619fa7dbad82bdb46902e973d72b9467b92bc6490fd" + "hash": "2e5f35966af96b8c8285a3d2e963650beb4bc2c993298f66225f63ccb66b5543" } diff --git a/.sqlx/query-dc2f422454de99671ed8a29efaf7c35b6abdf8b8d9b14a91c717c2e9cc5c2cf7.json b/.sqlx/query-8f57f0e917def134ac69060649168112422168d012fcb0785804182369eec0f6.json similarity index 80% rename from .sqlx/query-dc2f422454de99671ed8a29efaf7c35b6abdf8b8d9b14a91c717c2e9cc5c2cf7.json rename to .sqlx/query-8f57f0e917def134ac69060649168112422168d012fcb0785804182369eec0f6.json index 8102a48..9e430e4 100644 --- a/.sqlx/query-dc2f422454de99671ed8a29efaf7c35b6abdf8b8d9b14a91c717c2e9cc5c2cf7.json +++ b/.sqlx/query-8f57f0e917def134ac69060649168112422168d012fcb0785804182369eec0f6.json @@ -1,6 +1,6 @@ { "db_name": "PostgreSQL", - "query": "SELECT id, approved, revoked, created_at, deleted_at, updated_at, approved_at, revoked_at, ctype_hash, marked_approve, credential, claimer, tx_state as \"tx_state: TxState\" \n FROM attestation_requests WHERE id = $1 AND approved = true AND revoked = false AND deleted_at IS NULL", + "query": "SELECT id, approved, revoked, created_at, deleted_at, approved_at, revoked_at, ctype_hash, marked_approve, credential, claimer, tx_state as \"tx_state: TxState\" \n FROM attestation_requests WHERE id = $1 AND approved = false AND revoked = false AND deleted_at IS NULL", "describe": { "columns": [ { @@ -30,41 +30,36 @@ }, { "ordinal": 5, - "name": "updated_at", - "type_info": "Timestamp" - }, - { - "ordinal": 6, "name": "approved_at", "type_info": "Timestamp" }, { - "ordinal": 7, + "ordinal": 6, "name": "revoked_at", "type_info": "Timestamp" }, { - "ordinal": 8, + "ordinal": 7, "name": "ctype_hash", "type_info": "Varchar" }, { - "ordinal": 9, + "ordinal": 8, "name": "marked_approve", "type_info": "Bool" }, { - "ordinal": 10, + "ordinal": 9, "name": "credential", "type_info": "Jsonb" }, { - "ordinal": 11, + "ordinal": 10, "name": "claimer", "type_info": "Varchar" }, { - "ordinal": 12, + "ordinal": 11, "name": "tx_state: TxState", "type_info": { "Custom": { @@ -94,7 +89,6 @@ true, true, true, - true, false, false, false, @@ -102,5 +96,5 @@ true ] }, - "hash": "dc2f422454de99671ed8a29efaf7c35b6abdf8b8d9b14a91c717c2e9cc5c2cf7" + "hash": "8f57f0e917def134ac69060649168112422168d012fcb0785804182369eec0f6" } diff --git a/.sqlx/query-9093f75fcf4fa199013f93ab791f314d4114f19afe1de7c7e0dfc742250b94ab.json b/.sqlx/query-9093f75fcf4fa199013f93ab791f314d4114f19afe1de7c7e0dfc742250b94ab.json deleted file mode 100644 index 386734a..0000000 --- a/.sqlx/query-9093f75fcf4fa199013f93ab791f314d4114f19afe1de7c7e0dfc742250b94ab.json +++ /dev/null @@ -1,107 +0,0 @@ -{ - "db_name": "PostgreSQL", - "query": "UPDATE attestation_requests SET credential = $1 WHERE id = $2 AND approved = false AND deleted_at IS NULL \n RETURNING id, approved, revoked, created_at, deleted_at, updated_at, approved_at, revoked_at, ctype_hash, marked_approve, credential, claimer, tx_state as \"tx_state: TxState\"", - "describe": { - "columns": [ - { - "ordinal": 0, - "name": "id", - "type_info": "Uuid" - }, - { - "ordinal": 1, - "name": "approved", - "type_info": "Bool" - }, - { - "ordinal": 2, - "name": "revoked", - "type_info": "Bool" - }, - { - "ordinal": 3, - "name": "created_at", - "type_info": "Timestamp" - }, - { - "ordinal": 4, - "name": "deleted_at", - "type_info": "Timestamp" - }, - { - "ordinal": 5, - "name": "updated_at", - "type_info": "Timestamp" - }, - { - "ordinal": 6, - "name": "approved_at", - "type_info": "Timestamp" - }, - { - "ordinal": 7, - "name": "revoked_at", - "type_info": "Timestamp" - }, - { - "ordinal": 8, - "name": "ctype_hash", - "type_info": "Varchar" - }, - { - "ordinal": 9, - "name": "marked_approve", - "type_info": "Bool" - }, - { - "ordinal": 10, - "name": "credential", - "type_info": "Jsonb" - }, - { - "ordinal": 11, - "name": "claimer", - "type_info": "Varchar" - }, - { - "ordinal": 12, - "name": "tx_state: TxState", - "type_info": { - "Custom": { - "name": "tx_states", - "kind": { - "Enum": [ - "Succeeded", - "Failed", - "Pending", - "InFlight" - ] - } - } - } - } - ], - "parameters": { - "Left": [ - "Jsonb", - "Uuid" - ] - }, - "nullable": [ - false, - false, - false, - false, - true, - true, - true, - true, - false, - false, - false, - false, - true - ] - }, - "hash": "9093f75fcf4fa199013f93ab791f314d4114f19afe1de7c7e0dfc742250b94ab" -} diff --git a/.sqlx/query-34e3e01ed0e984aa687fa71899351a6a5cbbabe1deb45c99838c04e94855fa81.json b/.sqlx/query-a579c8b9d6cd68a9e78c3859b1645fff5f920aa4e75ee00b9b7c4e1b0cb54928.json similarity index 84% rename from .sqlx/query-34e3e01ed0e984aa687fa71899351a6a5cbbabe1deb45c99838c04e94855fa81.json rename to .sqlx/query-a579c8b9d6cd68a9e78c3859b1645fff5f920aa4e75ee00b9b7c4e1b0cb54928.json index 1f52a5f..b8f32bc 100644 --- a/.sqlx/query-34e3e01ed0e984aa687fa71899351a6a5cbbabe1deb45c99838c04e94855fa81.json +++ b/.sqlx/query-a579c8b9d6cd68a9e78c3859b1645fff5f920aa4e75ee00b9b7c4e1b0cb54928.json @@ -1,6 +1,6 @@ { "db_name": "PostgreSQL", - "query": "INSERT INTO attestation_requests (ctype_hash, claimer, credential) VALUES ($1, $2, $3) \n RETURNING id, approved, revoked, created_at, deleted_at, updated_at, approved_at, revoked_at, ctype_hash, credential, claimer, marked_approve, tx_state as \"tx_state: TxState\"", + "query": "INSERT INTO attestation_requests (ctype_hash, claimer, credential) VALUES ($1, $2, $3) \n RETURNING id, approved, revoked, created_at, deleted_at, approved_at, revoked_at, ctype_hash, credential, claimer, marked_approve, tx_state as \"tx_state: TxState\"", "describe": { "columns": [ { @@ -30,41 +30,36 @@ }, { "ordinal": 5, - "name": "updated_at", - "type_info": "Timestamp" - }, - { - "ordinal": 6, "name": "approved_at", "type_info": "Timestamp" }, { - "ordinal": 7, + "ordinal": 6, "name": "revoked_at", "type_info": "Timestamp" }, { - "ordinal": 8, + "ordinal": 7, "name": "ctype_hash", "type_info": "Varchar" }, { - "ordinal": 9, + "ordinal": 8, "name": "credential", "type_info": "Jsonb" }, { - "ordinal": 10, + "ordinal": 9, "name": "claimer", "type_info": "Varchar" }, { - "ordinal": 11, + "ordinal": 10, "name": "marked_approve", "type_info": "Bool" }, { - "ordinal": 12, + "ordinal": 11, "name": "tx_state: TxState", "type_info": { "Custom": { @@ -96,7 +91,6 @@ true, true, true, - true, false, false, false, @@ -104,5 +98,5 @@ true ] }, - "hash": "34e3e01ed0e984aa687fa71899351a6a5cbbabe1deb45c99838c04e94855fa81" + "hash": "a579c8b9d6cd68a9e78c3859b1645fff5f920aa4e75ee00b9b7c4e1b0cb54928" } diff --git a/.sqlx/query-9e47cf812bb738074de7081e7c9426ee2786b591b8a7c4b870dbd407f06175bc.json b/.sqlx/query-c90fa202bc60b1d7cd9f92f3b396e9423a5fe086ac5b823540a4455644b85ec1.json similarity index 58% rename from .sqlx/query-9e47cf812bb738074de7081e7c9426ee2786b591b8a7c4b870dbd407f06175bc.json rename to .sqlx/query-c90fa202bc60b1d7cd9f92f3b396e9423a5fe086ac5b823540a4455644b85ec1.json index 4c18791..3f6f762 100644 --- a/.sqlx/query-9e47cf812bb738074de7081e7c9426ee2786b591b8a7c4b870dbd407f06175bc.json +++ b/.sqlx/query-c90fa202bc60b1d7cd9f92f3b396e9423a5fe086ac5b823540a4455644b85ec1.json @@ -1,6 +1,6 @@ { "db_name": "PostgreSQL", - "query": "UPDATE attestation_requests SET revoked = true, revoked_at = NOW() WHERE id = $1 AND deleted_at IS NULL", + "query": "UPDATE attestation_requests SET revoked = true, revoked_at = NOW(), tx_state = 'Succeeded' WHERE id = $1 AND deleted_at IS NULL", "describe": { "columns": [], "parameters": { @@ -10,5 +10,5 @@ }, "nullable": [] }, - "hash": "9e47cf812bb738074de7081e7c9426ee2786b591b8a7c4b870dbd407f06175bc" + "hash": "c90fa202bc60b1d7cd9f92f3b396e9423a5fe086ac5b823540a4455644b85ec1" } diff --git a/.sqlx/query-7ec6055601d89f355371e41b9326b6943ab963af7660420a2ae688ad9a6cd9d4.json b/.sqlx/query-e80145ae80d036ed10fa4f7f35dc737cd4621c76eb46054d8fc93388c0177742.json similarity index 80% rename from .sqlx/query-7ec6055601d89f355371e41b9326b6943ab963af7660420a2ae688ad9a6cd9d4.json rename to .sqlx/query-e80145ae80d036ed10fa4f7f35dc737cd4621c76eb46054d8fc93388c0177742.json index f262366..29633f7 100644 --- a/.sqlx/query-7ec6055601d89f355371e41b9326b6943ab963af7660420a2ae688ad9a6cd9d4.json +++ b/.sqlx/query-e80145ae80d036ed10fa4f7f35dc737cd4621c76eb46054d8fc93388c0177742.json @@ -1,6 +1,6 @@ { "db_name": "PostgreSQL", - "query": "SELECT id, approved, revoked, created_at, deleted_at, updated_at, approved_at, revoked_at, ctype_hash, marked_approve, credential, claimer, tx_state as \"tx_state: TxState\" \n FROM attestation_requests WHERE id = $1 AND approved = false AND revoked = false AND deleted_at IS NULL", + "query": "SELECT id, approved, revoked, created_at, deleted_at, approved_at, revoked_at, ctype_hash, marked_approve, credential, claimer, tx_state as \"tx_state: TxState\" \n FROM attestation_requests WHERE id = $1 AND approved = true AND revoked = false AND deleted_at IS NULL", "describe": { "columns": [ { @@ -30,41 +30,36 @@ }, { "ordinal": 5, - "name": "updated_at", - "type_info": "Timestamp" - }, - { - "ordinal": 6, "name": "approved_at", "type_info": "Timestamp" }, { - "ordinal": 7, + "ordinal": 6, "name": "revoked_at", "type_info": "Timestamp" }, { - "ordinal": 8, + "ordinal": 7, "name": "ctype_hash", "type_info": "Varchar" }, { - "ordinal": 9, + "ordinal": 8, "name": "marked_approve", "type_info": "Bool" }, { - "ordinal": 10, + "ordinal": 9, "name": "credential", "type_info": "Jsonb" }, { - "ordinal": 11, + "ordinal": 10, "name": "claimer", "type_info": "Varchar" }, { - "ordinal": 12, + "ordinal": 11, "name": "tx_state: TxState", "type_info": { "Custom": { @@ -94,7 +89,6 @@ true, true, true, - true, false, false, false, @@ -102,5 +96,5 @@ true ] }, - "hash": "7ec6055601d89f355371e41b9326b6943ab963af7660420a2ae688ad9a6cd9d4" + "hash": "e80145ae80d036ed10fa4f7f35dc737cd4621c76eb46054d8fc93388c0177742" } diff --git a/frontend/src/components/AttestationList.tsx b/frontend/src/components/AttestationList.tsx index adf4691..926e82d 100644 --- a/frontend/src/components/AttestationList.tsx +++ b/frontend/src/components/AttestationList.tsx @@ -8,255 +8,257 @@ import { useNotify, useTheme, useRefresh, -} from 'react-admin' -import ReactJson from 'react-json-view' -import Fab from '@mui/material/Fab' -import DoneIcon from '@mui/icons-material/Done' -import RemoveIcon from '@mui/icons-material/Remove' -import CircularProgress from '@mui/material/CircularProgress' -import Tooltip from '@mui/material/Tooltip' -import DownloadIcon from '@mui/icons-material/Download' -import BookmarkAddedIcon from '@mui/icons-material/BookmarkAdded'; -import { ICType } from '@kiltprotocol/sdk-js' -import { getExtensions } from '@kiltprotocol/kilt-extension-api' +} from "react-admin"; +import ReactJson from "react-json-view"; +import Fab from "@mui/material/Fab"; +import DoneIcon from "@mui/icons-material/Done"; +import RemoveIcon from "@mui/icons-material/Remove"; +import CircularProgress from "@mui/material/CircularProgress"; +import Tooltip from "@mui/material/Tooltip"; +import DownloadIcon from "@mui/icons-material/Download"; +import BookmarkAddedIcon from "@mui/icons-material/BookmarkAdded"; +import { ICType } from "@kiltprotocol/sdk-js"; +import { getExtensions } from "@kiltprotocol/kilt-extension-api"; -import { AttestationRequest } from '../utils/types' -import { useState } from 'react' -import { getAxiosClient } from '../api/dataProvider' -import { getSession } from '../api/session' -import { isUserAdmin } from '../utils/utils' -import { InjectedWindowProvider } from '../session' -import { fetchCredential } from '../api/credential' +import { AttestationRequest } from "../utils/types"; +import { useState } from "react"; +import { getAxiosClient } from "../api/dataProvider"; +import { getSession } from "../api/session"; +import { isUserAdmin } from "../utils/utils"; +import { InjectedWindowProvider } from "../session"; +import { fetchCredential } from "../api/credential"; const ExpandAttestation = () => { - const record = useRecordContext() + const record = useRecordContext(); // eslint-disable-next-line @typescript-eslint/no-unused-vars - const [theme, _] = useTheme() + const [theme, _] = useTheme(); return ( - ) -} - + ); +}; const ApproveButton = () => { - const record = useRecordContext() + const record = useRecordContext(); const isApproved = record.marked_approve; if (isApproved) { - return ( - - ) + return ; } - return ( - - ) -} + return ; +}; const ClaimButton = () => { - const record = useRecordContext() - const apiURL = import.meta.env.VITE_SIMPLE_REST_URL - const [isLoading, setIsLoading] = useState(false) - const notify = useNotify() - const refresh = useRefresh() + const record = useRecordContext(); + const apiURL = import.meta.env.VITE_SIMPLE_REST_URL; + const [isLoading, setIsLoading] = useState(false); + const notify = useNotify(); + const refresh = useRefresh(); const handleClick = async () => { if (isLoading) { - return + return; } - setIsLoading(true) - const client = await getAxiosClient() - await client.put(apiURL + '/attestation_request/' + record.id + '/approve') + setIsLoading(true); + const client = await getAxiosClient(); + await client.put(apiURL + "/attestation_request/" + record.id + "/approve"); setTimeout(() => { - setIsLoading(false) - refresh() - notify("Transaction finished") - }, 60_000) - refresh() - notify('Transaction for approval is fired') - } + setIsLoading(false); + refresh(); + notify("Transaction finished"); + }, 60_000); + refresh(); + notify("Transaction for approval is fired"); + }; return ( - + - {isLoading ? : } + {isLoading ? : } - ) -} + ); +}; const MarkApproveButton = () => { - const record = useRecordContext() - const apiURL = import.meta.env.VITE_SIMPLE_REST_URL - const [isLoading, setIsLoading] = useState(false) - const notify = useNotify() - const refresh = useRefresh() + const record = useRecordContext(); + const apiURL = import.meta.env.VITE_SIMPLE_REST_URL; + const [isLoading, setIsLoading] = useState(false); + const notify = useNotify(); + const refresh = useRefresh(); const handleClick = async () => { if (isLoading) { - return + return; } - setIsLoading(true) - const client = await getAxiosClient() - await client.put(apiURL + '/attestation_request/' + record.id + '/mark_approve') - refresh() - notify('Marked as claimable') - setIsLoading(false) - } + setIsLoading(true); + const client = await getAxiosClient(); + await client.put( + apiURL + "/attestation_request/" + record.id + "/mark_approve" + ); + refresh(); + notify("Marked as claimable"); + setIsLoading(false); + }; return ( - + - {isLoading ? : } + {isLoading ? ( + + ) : ( + + )} - ) -} - - + ); +}; const DisableEditButton = () => { - const record = useRecordContext() - return -} + const record = useRecordContext(); + return ; +}; const RevokeButton = () => { - const record = useRecordContext() - const [isLoading, setIsLoading] = useState(false) - const apiURL = import.meta.env.VITE_SIMPLE_REST_URL - const notify = useNotify() - const refresh = useRefresh() + const record = useRecordContext(); + const [isLoading, setIsLoading] = useState(false); + const apiURL = import.meta.env.VITE_SIMPLE_REST_URL; + const notify = useNotify(); + const refresh = useRefresh(); const handleClick = async () => { if (isLoading) { - return + return; } - setIsLoading(true) - const client = await getAxiosClient() + setIsLoading(true); + const client = await getAxiosClient(); - await client.put(apiURL + '/attestation_request/' + record.id + '/revoke') + await client.put(apiURL + "/attestation_request/" + record.id + "/revoke"); setTimeout(() => { - setIsLoading(false) - refresh() - notify('Transaction is finished!') - }, 60_000) - notify('Transaction for revokation is fired.') - } + setIsLoading(false); + refresh(); + notify("Transaction is finished!"); + }, 60_000); + notify("Transaction for revokation is fired."); + }; return ( - + {isLoading ? : } - ) -} + ); +}; const DownloadCredential = () => { - const record = useRecordContext() - const [isLoading, setIsLoading] = useState(false) - const notify = useNotify() - const refresh = useRefresh() + const record = useRecordContext(); + const [isLoading, setIsLoading] = useState(false); + const notify = useNotify(); + const refresh = useRefresh(); - const extensions = getExtensions() - const hasExtension = extensions.length > 0 + const extensions = getExtensions(); + const hasExtension = extensions.length > 0; const handleClick = async () => { - setIsLoading(true) - const extensionName = 'Sporran' - const extension: InjectedWindowProvider = extensions.find((val) => val.name === extensionName) + setIsLoading(true); + const extensionName = "Sporran"; + const extension: InjectedWindowProvider = extensions.find( + (val) => val.name === extensionName + ); try { - const { session, sessionId } = await getSession(extension) + const { session, sessionId } = await getSession(extension); await fetchCredential(session, sessionId, record.id); - refresh() - notify("Claim created") - setIsLoading(false) - } - catch { - notify("Could not claim credential.", { type: "error" }) - setIsLoading(false) + refresh(); + notify("Claim created"); + setIsLoading(false); + } catch { + notify("Could not claim credential.", { type: "error" }); + setIsLoading(false); } - - } + }; return ( <> {hasExtension && ( - + {isLoading ? : } )} - ) -} + ); +}; const URLField = ({ baseURL }: { source: string; baseURL: string }) => { - const record = useRecordContext() - let ctype = record.ctype_hash + const record = useRecordContext(); + let ctype = record.ctype_hash; - if (!ctype.startsWith('kilt:ctype:')) { - ctype = `kilt:ctype:${ctype}` as ICType['$id'] + if (!ctype.startsWith("kilt:ctype:")) { + ctype = `kilt:ctype:${ctype}` as ICType["$id"]; } - return {ctype} -} + return {ctype}; +}; export const AttestationList = () => { return ( - - - - - - - + + + + + + {isUserAdmin() && } {isUserAdmin() && } @@ -264,5 +266,5 @@ export const AttestationList = () => { - ) -} + ); +}; diff --git a/frontend/src/utils/types.ts b/frontend/src/utils/types.ts index a8a7bb3..592cd11 100644 --- a/frontend/src/utils/types.ts +++ b/frontend/src/utils/types.ts @@ -11,7 +11,6 @@ export interface AttestationRequest { ctype_hash: ICType['$id'] deleted_at?: string id: UUID - updated_at?: string approved_at?: string revoked_at?: string txState: string diff --git a/migrations/20240111103915_remove_update_at.down.sql b/migrations/20240111103915_remove_update_at.down.sql new file mode 100644 index 0000000..c00c38b --- /dev/null +++ b/migrations/20240111103915_remove_update_at.down.sql @@ -0,0 +1,2 @@ +-- Add down migration script here +-- No way to re create the deleted column \ No newline at end of file diff --git a/migrations/20240111103915_remove_update_at.up.sql b/migrations/20240111103915_remove_update_at.up.sql new file mode 100644 index 0000000..c8a0932 --- /dev/null +++ b/migrations/20240111103915_remove_update_at.up.sql @@ -0,0 +1,4 @@ +-- Add up migration script here +ALTER TABLE attestation_requests DROP COLUMN updated_at; +DROP TRIGGER IF EXISTS update ON attestation_requests; +DROP FUNCTION IF EXISTS update_updated_at(); diff --git a/src/database/dto/attestation_requests.rs b/src/database/dto/attestation_requests.rs index 959ea19..fd90722 100644 --- a/src/database/dto/attestation_requests.rs +++ b/src/database/dto/attestation_requests.rs @@ -40,7 +40,6 @@ pub struct AttestationResponse { pub marked_approve: bool, pub created_at: NaiveDateTime, pub deleted_at: Option, - pub updated_at: Option, pub approved_at: Option, pub revoked_at: Option, pub ctype_hash: String, diff --git a/src/database/querys.rs b/src/database/querys.rs index e77a42f..f7c6ca7 100644 --- a/src/database/querys.rs +++ b/src/database/querys.rs @@ -12,7 +12,7 @@ pub async fn get_attestation_request_by_id( ) -> Result { sqlx::query_as!( AttestationResponse, - r#"SELECT id, approved, revoked, created_at, deleted_at, updated_at, approved_at, revoked_at, ctype_hash, credential, claimer, marked_approve, tx_state as "tx_state: TxState" + r#"SELECT id, approved, revoked, created_at, deleted_at, approved_at, revoked_at, ctype_hash, credential, claimer, marked_approve, tx_state as "tx_state: TxState" FROM attestation_requests WHERE id = $1 AND deleted_at is NULL"#, attestation_request_id, ) @@ -108,7 +108,7 @@ pub async fn insert_attestation_request( sqlx::query_as!( AttestationResponse, r#"INSERT INTO attestation_requests (ctype_hash, claimer, credential) VALUES ($1, $2, $3) - RETURNING id, approved, revoked, created_at, deleted_at, updated_at, approved_at, revoked_at, ctype_hash, credential, claimer, marked_approve, tx_state as "tx_state: TxState""#, + RETURNING id, approved, revoked, created_at, deleted_at, approved_at, revoked_at, ctype_hash, credential, claimer, marked_approve, tx_state as "tx_state: TxState""#, ctype_hash, claimer, serde_json::json!(credential) @@ -123,7 +123,7 @@ pub async fn can_approve_attestation_tx( ) -> Result { sqlx::query_as!( AttestationResponse, - r#"SELECT id, approved, revoked, created_at, deleted_at, updated_at, approved_at, revoked_at, ctype_hash, marked_approve, credential, claimer, tx_state as "tx_state: TxState" + r#"SELECT id, approved, revoked, created_at, deleted_at, approved_at, revoked_at, ctype_hash, marked_approve, credential, claimer, tx_state as "tx_state: TxState" FROM attestation_requests WHERE id = $1 AND approved = false AND revoked = false AND deleted_at IS NULL"#, attestation_request_id ) @@ -173,7 +173,7 @@ pub async fn can_revoke_attestation( ) -> Result { sqlx::query_as!( AttestationResponse, - r#"SELECT id, approved, revoked, created_at, deleted_at, updated_at, approved_at, revoked_at, ctype_hash, marked_approve, credential, claimer, tx_state as "tx_state: TxState" + r#"SELECT id, approved, revoked, created_at, deleted_at, approved_at, revoked_at, ctype_hash, marked_approve, credential, claimer, tx_state as "tx_state: TxState" FROM attestation_requests WHERE id = $1 AND approved = true AND revoked = false AND deleted_at IS NULL"#, attestation_request_id ) @@ -186,29 +186,13 @@ pub async fn revoke_attestation_request( tx: &mut sqlx::Transaction<'_, Postgres>, ) -> Result { sqlx::query!( - "UPDATE attestation_requests SET revoked = true, revoked_at = NOW() WHERE id = $1 AND deleted_at IS NULL", + "UPDATE attestation_requests SET revoked = true, revoked_at = NOW(), tx_state = 'Succeeded' WHERE id = $1 AND deleted_at IS NULL", attestation_request_id ) .execute(&mut **tx) .await } -pub async fn update_attestation_request( - attestation_request_id: &Uuid, - credential: &Credential, - db_executor: &PgPool, -) -> Result { - sqlx::query_as!( - AttestationResponse, - r#"UPDATE attestation_requests SET credential = $1 WHERE id = $2 AND approved = false AND deleted_at IS NULL - RETURNING id, approved, revoked, created_at, deleted_at, updated_at, approved_at, revoked_at, ctype_hash, marked_approve, credential, claimer, tx_state as "tx_state: TxState""#, - serde_json::json!(credential), - attestation_request_id - ) - .fetch_one(db_executor) - .await -} - pub async fn attestation_requests_kpis(pool: &PgPool) -> Result { let attestations_created_over_time = sqlx::query_as!( AttestationCreatedOverTime, diff --git a/src/database/tests.rs b/src/database/tests.rs index d88d0ff..2fa41d9 100644 --- a/src/database/tests.rs +++ b/src/database/tests.rs @@ -7,7 +7,7 @@ use crate::database::querys::{ can_revoke_attestation, construct_query, delete_attestation_request, get_attestation_request_by_id, get_attestation_requests, get_attestations_count, insert_attestation_request, mark_attestation_request_in_flight, - record_attestation_request_failed, revoke_attestation_request, update_attestation_request, + record_attestation_request_failed, revoke_attestation_request, }; fn get_default_attestation_request() -> Credential { @@ -63,7 +63,6 @@ async fn test_insert_attestation_request_valid(db_executor: PgPool) { assert!(!attestation.approved); assert!(!attestation.revoked); assert!(attestation.deleted_at.is_none()); - assert!(attestation.updated_at.is_none()); } #[sqlx::test] @@ -305,47 +304,6 @@ fn test_build_pagination_query_no_pagination() { assert_eq!(query.1, Vec::::new()); } -#[sqlx::test] -async fn test_update_attestation_request_valid_update(db_executor: PgPool) { - // Arrange: Insert an attestation request into the database and create an updated credential. - let mut default_credential = get_default_attestation_request(); - let inserted_request = insert_attestation_request(&default_credential, &db_executor) - .await - .expect("Inserting attestation request should not fail"); - - default_credential.root_hash = "UPDATED ROOT HASH".to_string(); - - // Act: Update the attestation request with the new credential. - let result = - update_attestation_request(&inserted_request.id, &default_credential, &db_executor).await; - - // Assert: Check that the update is successful, and the updated credential matches the expected one. - assert!(result.is_ok()); - let updated_request = result.unwrap(); - - let updated_credential: Credential = serde_json::from_value(updated_request.credential) - .expect("Serde JSON from value should not fail."); - - assert_eq!(updated_credential, default_credential); -} - -#[sqlx::test] -async fn test_update_attestation_request_invalid_update(db_executor: PgPool) { - // Arrange: Insert an attestation request with the default credential into the database and create an invalid ID. - let default_credential = get_default_attestation_request(); - - insert_attestation_request(&default_credential, &db_executor) - .await - .expect("Inserting attestation request should not fail"); - - let invalid_id = Uuid::new_v4(); - - // Act: Attempt to update an attestation request with an invalid ID. - let result = update_attestation_request(&invalid_id, &default_credential, &db_executor).await; - - // Assert: Check that the update operation fails as expected. - assert!(result.is_err()); -} #[sqlx::test] async fn test_can_approve_attestation_tx_valid(db_executor: PgPool) { // Arrange: Start a transaction and insert a default attestation request. diff --git a/src/routes/attestation_requests.rs b/src/routes/attestation_requests.rs index b5753e1..2b93cff 100644 --- a/src/routes/attestation_requests.rs +++ b/src/routes/attestation_requests.rs @@ -17,7 +17,6 @@ use crate::{ get_attestation_requests, get_attestations_count, insert_attestation_request, mark_attestation_approve, mark_attestation_request_in_flight, record_attestation_request_failed, revoke_attestation_request, - update_attestation_request, }, }, error::AppError, @@ -265,30 +264,6 @@ async fn revoke_attestation( Ok(HttpResponse::Ok().json("ok")) } -#[put("/{attestation_request_id}")] -async fn update_attestation( - attestation_id: web::Path, - state: web::Data, - user: ReqData, - credential: web::Json, -) -> Result { - // check role - let is_user_allowed = - is_user_allowed_to_update_data(&user, &attestation_id, &state.db_executor).await?; - - if !is_user_allowed { - Err(actix_web::error::ErrorUnauthorized( - "User is not allowed to see data", - ))? - } - - // update - let attestation = - update_attestation_request(&attestation_id, &credential, &state.db_executor).await?; - log::info!("Attestation with id {:?} is updated", attestation_id); - Ok(HttpResponse::Ok().json(serde_json::to_value(&attestation)?)) -} - #[get("/metric/kpis")] async fn get_attestation_kpis(state: web::Data) -> Result { let kpis = attestation_requests_kpis(&state.db_executor).await?; @@ -302,7 +277,6 @@ pub fn get_attestation_request_scope() -> Scope { .service(get_attestations) .service(post_attestation) .service(delete_attestation) - .service(update_attestation) .service(revoke_attestation) .service(get_attestation_kpis) .service(mark_approve_attestation_request)