Skip to content

Commit

Permalink
docs: add supabase sql and readme info
Browse files Browse the repository at this point in the history
  • Loading branch information
nrusso committed Nov 17, 2023
1 parent 5962c5b commit 5af9105
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 187 deletions.
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,23 @@ The directory structures for business domains are as follows:

> **Tip** I know it may sound repetitive, but it is not a framework. NExp is a set of tools or libraries working together through a common structure. All structural code within this project is not fixed and can be changed freely.
### Supabase integration

In the infrastructure folder there is a file called `supabase_permissions.sql` this file is used to manage permissions
with these tables.

* roles
* permissions
* users_has_roles
* roles_has_permissions

And a function call `get_authorization`.

## Advantages

The advantages of using this boilerplate is to save time thinking about certain basic structures common to any project to make an API without having to get everything from scratch.
The advantages of using this boilerplate are
to save time thinking about certain basic structures common to any project to make an API
without having to get everything from scratch.

As it is only a boilerplate, you have the freedom to structure the code whatever you want.

Expand Down
6 changes: 0 additions & 6 deletions infrastructure/README.md

This file was deleted.

2 changes: 0 additions & 2 deletions infrastructure/config

This file was deleted.

59 changes: 0 additions & 59 deletions infrastructure/firewall.tf

This file was deleted.

46 changes: 0 additions & 46 deletions infrastructure/instance.tf

This file was deleted.

3 changes: 0 additions & 3 deletions infrastructure/provider.tf

This file was deleted.

33 changes: 0 additions & 33 deletions infrastructure/script.sh

This file was deleted.

42 changes: 42 additions & 0 deletions infrastructure/supabase_permissions.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
CREATE TABLE roles (
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
name TEXT NOT NULL,
slug TEXT UNIQUE NOT NULL
);

CREATE TABLE permissions (
id UUID PRIMARY KEY DEFAULT uuid_generate_v4(),
name TEXT UNIQUE NOT NULL
);

CREATE TABLE users_has_roles (
user_id UUID NOT NULL,
role_id UUID NOT NULL,
PRIMARY KEY (user_id, role_id),
FOREIGN KEY (user_id) REFERENCES auth.users(id),
FOREIGN KEY (role_id) REFERENCES roles(id)
);

CREATE TABLE roles_has_permissions (
role_id UUID NOT NULL,
permission_id UUID NOT NULL,
PRIMARY KEY (role_id, permission_id),
FOREIGN KEY (role_id) REFERENCES roles(id),
FOREIGN KEY (permission_id) REFERENCES permissions(id)
);

CREATE OR REPLACE FUNCTION get_authorization(field_user_id UUID, permission_name TEXT) RETURNS BOOLEAN AS $$
DECLARE
has_permission BOOLEAN;
BEGIN
SELECT EXISTS (
SELECT 1
FROM users_has_roles uhr
JOIN roles_has_permissions rhp ON uhr.role_id = rhp.role_id
JOIN permissions p ON rhp.permission_id = p.id
WHERE uhr.user_id = field_user_id AND p.name = permission_name
) INTO has_permission;

RETURN has_permission;
END;
$$ LANGUAGE plpgsql;
29 changes: 0 additions & 29 deletions infrastructure/vars.tf

This file was deleted.

8 changes: 0 additions & 8 deletions infrastructure/versions.tf

This file was deleted.

0 comments on commit 5af9105

Please sign in to comment.