K
K
Konstantin2021-02-16 19:01:11
PostgreSQL
Konstantin, 2021-02-16 19:01:11

How to correctly implement the rights to the database object?

Hello, I'm a little confused with the design of the database (project for training)

There are entities of the employee's profile - Employees;
id | ..

Offices:
id | owner_employee_id | ..

Calendar - OfficeCalendars;
id | offices_id | ..

Calendar events CalendarEvents
id | calendar_id | owner_employee_id | ..

Clients - Clients;
id | owner_employee_id | ..

Logic:
- rights can be the owner, manager and just an employee;
- the owner or manager will be able to tie several employees to the office and give them rights;
- the owner of the event will be able to add other employees of the office linked to the calendar to the event;
- the manager and the owner can add employees to the calendar and assign rights to them;
- each user can have several offices and be both the owner/manager in one, and at the same time be an employee in another.

I wanted to implement the following rights:
- the right to edit information about the office - only to the owner;
- rights to edit the calendar - only to the owner of the office or manager;
- rights to access information about customers - only the owner of the office, the manager of the office and the owner of the record about the client - who created it;
However, it should be possible to grant rights. for example, give the owner of the customer data access to another employee, the same with calendar events.

To exclude M:M links and exercise rights, added tables:
- Employees_Offices_Premissions:
Fields: Employee_id | office_id | Premission_Offices_type
- Employees_Calendars_Premissions:
Fields: Employee_id | calendar_id| Premission_Calendar_type
- Employees_Clients_Premissions:
Fields: Employee_id | client_id | Premission_Client_type
- Employees_CalendarEvents:
Fields: Employee_id | CalendarEvent_id

How correct is this solution and is it enough?
I also got confused - what field should it be, for example, in the same calendar event in a link to other employees - Employees or Employees_CalendarEvents?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivan Shumov, 2021-02-16
@Drakonn

I recommend reading about the concept of ABAC or RBAC with business rules

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question