Skip to content

Commit

Permalink
fix: edit the deleting function
Browse files Browse the repository at this point in the history
Closes: #218
  • Loading branch information
ColinRgm committed Jan 13, 2025
1 parent 405260c commit e5f1021
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
16 changes: 8 additions & 8 deletions database/migration/deploy/new_way_delete_esp_permission.sql
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,25 @@ BEGIN;


-- Remove permission to DELETE on data and esp tables
REVOKE DELETE ON api.data FROM web_user;
REVOKE DELETE ON api.esp FROM web_user;
REVOKE DELETE ON api.data FROM web_user; -- Revoke permission for the user to DELETE datas on table DATA
REVOKE DELETE ON api.esp FROM web_user; -- Revoke permission for the user to DELETE datas on table ESP

-- Add permission to DELETE on data and esp tables
GRANT DELETE ON api.data TO web_user;
GRANT DELETE ON api.esp TO web_user;
GRANT DELETE ON api.data TO web_user; -- Add permission for the user to DELETE datas on table DATA
GRANT DELETE ON api.esp TO web_user; -- Add permission for the user to DELETE datas on table ESP

-- Delete the function if exists
DROP FUNCTION IF EXISTS api.delete_esp_data_and_esp();
-- DROP FUNCTION IF EXISTS api.delete_esp_data_and_esp();

-- Create the function
CREATE FUNCTION api.delete_esp_data_and_esp()
CREATE FUNCTION api.delete_esp_data_and_esp(id INT)
RETURNS VOID AS $$

BEGIN

-- DELETE on data and esp tables
DELETE FROM api.data WHERE esp_id = ${id};
DELETE FROM api.esp WHERE id = ${id};
DELETE FROM api.data WHERE esp_id = id;
DELETE FROM api.esp WHERE id = id;

END;
$$ LANGUAGE plpgsql;
Expand Down
2 changes: 1 addition & 1 deletion database/migration/revert/add_new_permission.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

BEGIN;

revoke update on api.users to web_user; -- any user can edit users
revoke update on api.users from web_user; -- any user can edit users

COMMIT;
3 changes: 1 addition & 2 deletions nextjs-interface/src/app/ui/dashboard/DeleteEsp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export default function DeleteEsp({ id }: { id: string }) {
try {
const response = await fetch(url, {
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${getToken()}`,
},
});
Expand All @@ -33,4 +32,4 @@ export default function DeleteEsp({ id }: { id: string }) {
<Trash2 onClick={() => deleteEsp(id)} />
</div>
);
}
}

0 comments on commit e5f1021

Please sign in to comment.