Skip to content

Commit 42b646f

Browse files
committed
Add functions product access rights
1 parent 540f786 commit 42b646f

File tree

16 files changed

+666
-81
lines changed

16 files changed

+666
-81
lines changed

packages/models-library/src/models_library/functions.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from models_library.basic_regex import UUID_RE_BASE
88
from models_library.basic_types import ConstrainedStr
99
from models_library.groups import GroupID
10+
from models_library.products import ProductName
1011
from models_library.services_types import ServiceKey, ServiceVersion
1112
from models_library.users import UserID
1213
from pydantic import BaseModel, ConfigDict, Field
@@ -278,6 +279,7 @@ class FunctionGroupAccessRights(FunctionAccessRights):
278279

279280
class FunctionAccessRightsDB(BaseModel):
280281
group_id: GroupID | None = None
282+
product_name: ProductName | None = None
281283
read: bool = False
282284
write: bool = False
283285
execute: bool = False
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
"""Add functions product access
2+
3+
Revision ID: fa3c3a9a1f7f
4+
Revises: 275642b33db0
5+
Create Date: 2025-05-30 11:28:17.223201+00:00
6+
7+
"""
8+
9+
import sqlalchemy as sa
10+
from alembic import op
11+
12+
# revision identifiers, used by Alembic.
13+
revision = "fa3c3a9a1f7f"
14+
down_revision = "275642b33db0"
15+
branch_labels = None
16+
depends_on = None
17+
18+
19+
def upgrade():
20+
# ### commands auto generated by Alembic - please adjust! ###
21+
op.add_column(
22+
"funcapi_function_job_collections_access_rights",
23+
sa.Column("product_name", sa.String(), nullable=False),
24+
)
25+
op.create_foreign_key(
26+
"fk_func_access_to_products_product_name",
27+
"funcapi_function_job_collections_access_rights",
28+
"products",
29+
["product_name"],
30+
["name"],
31+
onupdate="CASCADE",
32+
ondelete="CASCADE",
33+
)
34+
op.add_column(
35+
"funcapi_function_jobs_access_rights",
36+
sa.Column("product_name", sa.String(), nullable=False),
37+
)
38+
op.create_foreign_key(
39+
"fk_func_access_to_products_product_name",
40+
"funcapi_function_jobs_access_rights",
41+
"products",
42+
["product_name"],
43+
["name"],
44+
onupdate="CASCADE",
45+
ondelete="CASCADE",
46+
)
47+
op.add_column(
48+
"funcapi_functions_access_rights",
49+
sa.Column("product_name", sa.String(), nullable=False),
50+
)
51+
op.create_foreign_key(
52+
"fk_func_access_to_products_product_name",
53+
"funcapi_functions_access_rights",
54+
"products",
55+
["product_name"],
56+
["name"],
57+
onupdate="CASCADE",
58+
ondelete="CASCADE",
59+
)
60+
# ### end Alembic commands ###
61+
62+
63+
def downgrade():
64+
# ### commands auto generated by Alembic - please adjust! ###
65+
op.drop_constraint(
66+
"fk_func_access_to_products_product_name",
67+
"funcapi_functions_access_rights",
68+
type_="foreignkey",
69+
)
70+
op.drop_column("funcapi_functions_access_rights", "product_name")
71+
op.drop_constraint(
72+
"fk_func_access_to_products_product_name",
73+
"funcapi_function_jobs_access_rights",
74+
type_="foreignkey",
75+
)
76+
op.drop_column("funcapi_function_jobs_access_rights", "product_name")
77+
op.drop_constraint(
78+
"fk_func_access_to_products_product_name",
79+
"funcapi_function_job_collections_access_rights",
80+
type_="foreignkey",
81+
)
82+
op.drop_column("funcapi_function_job_collections_access_rights", "product_name")
83+
# ### end Alembic commands ###

packages/postgres-database/src/simcore_postgres_database/models/funcapi_function_job_collections_access_rights_table.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,20 @@
3232
onupdate=RefActions.CASCADE,
3333
ondelete=RefActions.CASCADE,
3434
),
35-
nullable=True,
35+
nullable=False,
3636
doc="Group id",
3737
),
38+
sa.Column(
39+
"product_name",
40+
sa.ForeignKey(
41+
"products.name",
42+
name="fk_func_access_to_products_product_name",
43+
onupdate=RefActions.CASCADE,
44+
ondelete=RefActions.CASCADE,
45+
),
46+
nullable=False,
47+
doc="Name of the product",
48+
),
3849
sa.Column(
3950
"read",
4051
sa.Boolean,
@@ -58,6 +69,7 @@
5869
sa.PrimaryKeyConstraint(
5970
"function_job_collection_uuid",
6071
"group_id",
72+
"product_name",
6173
name="pk_func_access_to_func_job_colls_group",
6274
),
6375
)

packages/postgres-database/src/simcore_postgres_database/models/funcapi_function_jobs_access_rights_table.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,17 @@
3535
nullable=False,
3636
doc="Group id",
3737
),
38+
sa.Column(
39+
"product_name",
40+
sa.ForeignKey(
41+
"products.name",
42+
name="fk_func_access_to_products_product_name",
43+
onupdate=RefActions.CASCADE,
44+
ondelete=RefActions.CASCADE,
45+
),
46+
nullable=False,
47+
doc="Name of the product",
48+
),
3849
sa.Column(
3950
"read",
4051
sa.Boolean,

packages/postgres-database/src/simcore_postgres_database/models/funcapi_functions_access_rights_table.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,17 @@
3535
nullable=False,
3636
doc="Group id",
3737
),
38+
sa.Column(
39+
"product_name",
40+
sa.ForeignKey(
41+
"products.name",
42+
name="fk_func_access_to_products_product_name",
43+
onupdate=RefActions.CASCADE,
44+
ondelete=RefActions.CASCADE,
45+
),
46+
nullable=False,
47+
doc="Name of the product",
48+
),
3849
sa.Column(
3950
"read",
4051
sa.Boolean,
@@ -56,6 +67,6 @@
5667
column_created_datetime(),
5768
column_modified_datetime(),
5869
sa.PrimaryKeyConstraint(
59-
"function_uuid", "group_id", name="pk_func_access_to_func_group"
70+
"function_uuid", "group_id", "product_name", name="pk_func_access_to_func_group"
6071
),
6172
)

0 commit comments

Comments
 (0)