diff --git a/nesis/api/alembic/versions/3d6d802ca102_remove_model_role_entities.py b/nesis/api/alembic/versions/3d6d802ca102_remove_model_role_entities.py index eb12300..359f4dc 100644 --- a/nesis/api/alembic/versions/3d6d802ca102_remove_model_role_entities.py +++ b/nesis/api/alembic/versions/3d6d802ca102_remove_model_role_entities.py @@ -22,42 +22,15 @@ def upgrade() -> None: # ### commands auto generated by Alembic - please adjust! ### op.drop_index("idx_model_name", table_name="model") - op.drop_table("model") op.drop_table("model_rule") op.drop_constraint("fk_rule_model", "prediction", type_="foreignkey") + op.drop_table("model") # ### end Alembic commands ### def downgrade() -> None: # ### commands auto generated by Alembic - please adjust! ### - op.create_table( - "model_rule", - sa.Column("id", sa.BIGINT(), autoincrement=True, nullable=False), - sa.Column("name", sa.VARCHAR(length=255), autoincrement=False, nullable=True), - sa.Column("model", sa.BIGINT(), autoincrement=False, nullable=False), - sa.Column( - "description", sa.VARCHAR(length=255), autoincrement=False, nullable=True - ), - sa.Column( - "created_by", sa.VARCHAR(length=255), autoincrement=False, nullable=True - ), - sa.Column( - "create_date", postgresql.TIMESTAMP(), autoincrement=False, nullable=False - ), - sa.Column( - "value", - postgresql.JSONB(astext_type=sa.Text()), - autoincrement=False, - nullable=False, - ), - sa.Column("enabled", sa.BOOLEAN(), autoincrement=False, nullable=False), - sa.ForeignKeyConstraint( - ["model"], ["model.id"], name="fk_model_rule_model", ondelete="CASCADE" - ), - sa.PrimaryKeyConstraint("id", name="model_rule_pkey"), - sa.UniqueConstraint("name", name="model_rule_name_key"), - ) op.create_table( "model", sa.Column("id", sa.BIGINT(), autoincrement=True, nullable=False), @@ -87,6 +60,34 @@ def downgrade() -> None: sa.PrimaryKeyConstraint("id", name="model_pkey"), sa.UniqueConstraint("module", "name", name="uq_model_module_name"), ) + + op.create_table( + "model_rule", + sa.Column("id", sa.BIGINT(), autoincrement=True, nullable=False), + sa.Column("name", sa.VARCHAR(length=255), autoincrement=False, nullable=True), + sa.Column("model", sa.BIGINT(), autoincrement=False, nullable=False), + sa.Column( + "description", sa.VARCHAR(length=255), autoincrement=False, nullable=True + ), + sa.Column( + "created_by", sa.VARCHAR(length=255), autoincrement=False, nullable=True + ), + sa.Column( + "create_date", postgresql.TIMESTAMP(), autoincrement=False, nullable=False + ), + sa.Column( + "value", + postgresql.JSONB(astext_type=sa.Text()), + autoincrement=False, + nullable=False, + ), + sa.Column("enabled", sa.BOOLEAN(), autoincrement=False, nullable=False), + sa.ForeignKeyConstraint( + ["model"], ["model.id"], name="fk_model_rule_model", ondelete="CASCADE" + ), + sa.PrimaryKeyConstraint("id", name="model_rule_pkey"), + sa.UniqueConstraint("name", name="model_rule_name_key"), + ) op.create_index("idx_model_name", "model", ["module", "name"], unique=False) op.create_foreign_key( "fk_rule_model", "prediction", "model", ["model"], ["id"], ondelete="CASCADE" diff --git a/nesis/api/alembic/versions/50bebf15de30_add_tasks_to_role_action_resource_type.py b/nesis/api/alembic/versions/50bebf15de30_add_tasks_to_role_action_resource_type.py new file mode 100644 index 0000000..1448dae --- /dev/null +++ b/nesis/api/alembic/versions/50bebf15de30_add_tasks_to_role_action_resource_type.py @@ -0,0 +1,35 @@ +"""add tasks to role_action_resource_type + +Revision ID: 50bebf15de30 +Revises: 3d6d802ca102 +Create Date: 2024-06-13 23:41:54.517558 + +""" + +from typing import Sequence, Union + +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision: str = "50bebf15de30" +down_revision: Union[str, None] = "3d6d802ca102" +branch_labels: Union[str, Sequence[str], None] = None +depends_on: Union[str, Sequence[str], None] = None + + +def upgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.execute("ALTER TYPE role_action_resource_type ADD VALUE 'APPS';") + op.execute("ALTER TYPE role_action_resource_type ADD VALUE 'TASKS';") + # ### end Alembic commands ### + + +def downgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + """ + We keep the APPS and TASKS types as might be used by the application + """ + pass + # ### end Alembic commands ### diff --git a/nesis/api/alembic/versions/cbad6afbe13d_add_parent_id_to_task_unique_constraint.py b/nesis/api/alembic/versions/cbad6afbe13d_add_parent_id_to_task_unique_constraint.py new file mode 100644 index 0000000..24ce66b --- /dev/null +++ b/nesis/api/alembic/versions/cbad6afbe13d_add_parent_id_to_task_unique_constraint.py @@ -0,0 +1,35 @@ +"""add parent_id to task unique constraint + +Revision ID: cbad6afbe13d +Revises: 50bebf15de30 +Create Date: 2024-06-13 23:59:45.211996 + +""" + +from typing import Sequence, Union + +from alembic import op +import sqlalchemy as sa + + +# revision identifiers, used by Alembic. +revision: str = "cbad6afbe13d" +down_revision: Union[str, None] = "50bebf15de30" +branch_labels: Union[str, Sequence[str], None] = None +depends_on: Union[str, Sequence[str], None] = None + + +def upgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.drop_constraint("uq_task_type_schedule", "task", type_="unique") + op.create_unique_constraint( + "uq_task_parent_id_type_schedule", "task", ["parent_id", "type", "schedule"] + ) + # ### end Alembic commands ### + + +def downgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.drop_constraint("uq_task_parent_id_type_schedule", "task", type_="unique") + op.create_unique_constraint("uq_task_type_schedule", "task", ["type", "schedule"]) + # ### end Alembic commands ### diff --git a/nesis/api/core/models/entities.py b/nesis/api/core/models/entities.py index e6fb5b5..cf9bd2e 100644 --- a/nesis/api/core/models/entities.py +++ b/nesis/api/core/models/entities.py @@ -395,7 +395,9 @@ class Task(Base): update_date = Column(DateTime, default=dt.datetime.utcnow, nullable=False) __table_args__ = ( - UniqueConstraint("type", "schedule", name="uq_task_type_schedule"), + UniqueConstraint( + "parent_id", "type", "schedule", name="uq_task_parent_id_type_schedule" + ), Index("idx_task_type", "type"), Index("idx_task_parent", "parent_id"), ) diff --git a/nesis/api/core/services/task_service.py b/nesis/api/core/services/task_service.py index 82dfa7a..b74f490 100644 --- a/nesis/api/core/services/task_service.py +++ b/nesis/api/core/services/task_service.py @@ -205,7 +205,7 @@ def create(self, **kwargs): error_str = str(exc).lower() if ("unique constraint" in error_str) and ( - "uq_task_type_schedule" in error_str + "uq_task_parent_id_type_schedule" in error_str ): # valid failure raise ConflictException("Task already scheduled on this type") diff --git a/nesis/frontend/client/src/SessionContext.js b/nesis/frontend/client/src/SessionContext.js index 2425ae1..929da17 100644 --- a/nesis/frontend/client/src/SessionContext.js +++ b/nesis/frontend/client/src/SessionContext.js @@ -77,16 +77,18 @@ export function useSignOut(client, config) { async function logoutMicrosoft(config) { try { - const msalInstance = new PublicClientApplication({ - auth: { - clientId: config?.auth?.OAUTH_AZURE_CLIENT_ID, - authority: config?.auth?.OAUTH_AZURE_AUTHORITY, - redirectUri: config?.auth?.OAUTH_AZURE_REDIRECTURI, - postLogoutRedirectUri: config?.auth?.OAUTH_AZURE_REDIRECTURI, - }, - }); - await msalInstance.initialize(); - await msalInstance.logoutRedirect(); + if (config?.auth?.NESIS_OAUTH_AZURE_ENABLED) { + const msalInstance = new PublicClientApplication({ + auth: { + clientId: config?.auth?.OAUTH_AZURE_CLIENT_ID, + authority: config?.auth?.OAUTH_AZURE_AUTHORITY, + redirectUri: config?.auth?.OAUTH_AZURE_REDIRECTURI, + postLogoutRedirectUri: config?.auth?.OAUTH_AZURE_REDIRECTURI, + }, + }); + await msalInstance.initialize(); + await msalInstance.logoutRedirect(); + } } catch (e) { /* ignored */ }