metaspace2020 / metaspace

Cloud engine and platform for metabolite annotation for imaging mass spectrometry
https://metaspace2020.eu/
Apache License 2.0
48 stars 10 forks source link

Implement User Access Control with Plans Schema and API Usage Logging #1592

Closed lmacielvieira closed 3 weeks ago

lmacielvieira commented 3 weeks ago

Description

This update introduces a Plans schema to enhance user access control within METASPACE. Users can now be associated with specific plans, each of which can have customizable rules that apply to datasets, groups, projects, and users. These rules allow for granular control, such as limiting the number of downloads or other resource usage.

Additionally, this PR adds functionality to log API usage in the database, enabling better tracking and management of user activity. Also, the number of downloads was limited to 2 per day, both for web and API

image

Steps to run from scratch

1 - Run migrations 2 - Access postgres 3 - Create plans, plans rules and associate user to plan

-- create regular plan
insert into "public"."plan" (id, name, created_at, is_active) values (1, 'regular', now(), true);

-- limit download to 2 per day
insert into "public"."plan_rule" (id, plan_id, action_type, period, period_type, "limit", type, visibility, source, created_at) values (1, 1, 'download', 1, 'day', 2, 'dataset', 'private', 'web', now());
insert into "public"."plan_rule" (id, plan_id, action_type, period, period_type, "limit", type, visibility, source, created_at) values (2, 1, 'download', 1, 'day', 2, 'dataset', 'public', 'web', now());
insert into "public"."plan_rule" (id, plan_id, action_type, period, period_type, "limit", type, visibility, source, created_at) values (3, 1, 'download', 1, 'day', 2, 'dataset', 'private', 'api', now());
insert into "public"."plan_rule" (id, plan_id, action_type, period, period_type, "limit", type, visibility, source, created_at) values (4, 1, 'download', 1, 'day', 2, 'dataset', 'public', 'api', now());

-- set users to regular plan
update "graphql"."user" set plan_id = 1;