I
I
Igor_Petrovv2020-05-21 16:52:20
PostgreSQL
Igor_Petrovv, 2020-05-21 16:52:20

It is necessary to make sure that only managers have access to information about the employee and can change it, how?

There is this code:

CREATE FUNCTION log_salary_access() RETURNS trigger AS $log_salary_access$
BEGIN
IF OLD.manager_id != current_user THEN
RAISE EXCEPTION 'access denied';
END IF;
RETURN NEW;
END;
$log_salary_access$ LANGUAGE plpgsql;
CREATE TRIGGER log_salary_access AFTER UPDATE ON employees
FOR EACH ROW EXECUTE PROCEDURE log_salary_access();
,

But it is not correct, because after checking it was written to me that this would not work correctly:

This is how the table looks like:
5ec685ad35e97748294512.png
Here is the direct control (mediocre) of manager 100: Here is the direct control
5ec6865154f34304110939.png
, that is, manager 100 controls the managers that are in the figure above and manager 100 manages (changes information about them) employees who report to managers, which are in the previous figure. And here is the list of subordinates is much larger than with mediocre management:
5ec6871274e2d587679763.png

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question