reportportal / service-api

Report portal. Main API Service
Apache License 2.0
43 stars 65 forks source link

[Info] Automatically adding a new user to the list of projects #1954

Closed shaburov closed 3 months ago

shaburov commented 3 months ago

In order to simplify adding users to “public” projects, you can add an SQL trigger, which will trigger when an entry is added to the users table and provide access to the listed public projects. This is especially convenient if you have SAML authentication enabled.

CREATE OR REPLACE FUNCTION provide_projects_access_with_customer_role()
    returns trigger
as
$$
BEGIN
    INSERT INTO project_user (user_id, project_id, project_role)
    VALUES (NEW.id, 3, 'CUSTOMER')
    ON CONFLICT(user_id, project_id) DO NOTHING;
    RETURN NEW;
END
-- $$ LANGUAGE plpgsql;

CREATE TRIGGER customer_project_access_for_new_user
    AFTER INSERT ON users
    FOR EACH ROW
EXECUTE FUNCTION provide_projects_access_with_customer_role();

This issue is for informational purposes only.

raikbitters commented 3 months ago

@shaburov hello. I wouldn't say I like approaches that add business logic to a database level. We have some legacy. However, we are trying to avoid this for new features, and I want to develop ReportPortal as a vendor-agnostic product. Moreover, there are performance issues with using triggers in PostgreSQL.

@pbortnik, @irynakozak2, can you review this proposal? We may have differing opinions on it.

pbortnik commented 3 months ago

@shaburov, @raikbitters If we want to have this functionality, it is better to implement it in service-api. Using triggers is not recommended for such cases.

shaburov commented 3 months ago

So many users are created that the trigger affects the performance? Why do you have such a monstrous staff turnover?

AFTER INSERT ON users

Don't talk nonsense my friends.

raikbitters commented 3 months ago

@shaburov check my first point, please. Performance issue isn't essential reason.