From 006d711d2628fc968c0e90bf552708263f24efed Mon Sep 17 00:00:00 2001 From: Martin Lettry Date: Wed, 19 Apr 2023 14:06:35 +0200 Subject: [PATCH] wip group membership support * added migration recipe * closes https://github.com/inveniosoftware/invenio-app-rdm/issues/2186 --- .../04480be1593e_add_actionsystemroles.py | 2 +- ...82633b_add_on_delete_cascade_constraint.py | 2 +- .../2f63be7b7572_create_access_tables.py | 2 +- .../67ba0de65fbb_create_access_branch.py | 2 +- ...b56e60_change_fk_accountsrole_to_string.py | 71 +++++++++++++++++++ ...bfda43_prevent_null_in_actionusers_for_.py | 2 +- invenio_access/models.py | 2 +- invenio_access/translations/messages.pot | 10 +-- 8 files changed, 82 insertions(+), 11 deletions(-) create mode 100644 invenio_access/alembic/842a62b56e60_change_fk_accountsrole_to_string.py diff --git a/invenio_access/alembic/04480be1593e_add_actionsystemroles.py b/invenio_access/alembic/04480be1593e_add_actionsystemroles.py index b686984..c6208e9 100644 --- a/invenio_access/alembic/04480be1593e_add_actionsystemroles.py +++ b/invenio_access/alembic/04480be1593e_add_actionsystemroles.py @@ -15,7 +15,7 @@ revision = "04480be1593e" down_revision = "dbe499bfda43" branch_labels = () -depends_on = None +depends_on = "eb9743315a9d" def upgrade(): diff --git a/invenio_access/alembic/2069a982633b_add_on_delete_cascade_constraint.py b/invenio_access/alembic/2069a982633b_add_on_delete_cascade_constraint.py index f81a5d0..508257f 100644 --- a/invenio_access/alembic/2069a982633b_add_on_delete_cascade_constraint.py +++ b/invenio_access/alembic/2069a982633b_add_on_delete_cascade_constraint.py @@ -14,7 +14,7 @@ revision = "2069a982633b" down_revision = "2f63be7b7572" branch_labels = () -depends_on = "35c1075e6360" # invenio-db "Force naming convention" +depends_on = ("35c1075e6360", "eb9743315a9d") # invenio-db "Force naming convention" def upgrade(): diff --git a/invenio_access/alembic/2f63be7b7572_create_access_tables.py b/invenio_access/alembic/2f63be7b7572_create_access_tables.py index 3f542b8..4eb36fa 100644 --- a/invenio_access/alembic/2f63be7b7572_create_access_tables.py +++ b/invenio_access/alembic/2f63be7b7572_create_access_tables.py @@ -15,7 +15,7 @@ revision = "2f63be7b7572" down_revision = "67ba0de65fbb" branch_labels = () -depends_on = "9848d0149abd" +depends_on = ("9848d0149abd", "eb9743315a9d") def upgrade(): diff --git a/invenio_access/alembic/67ba0de65fbb_create_access_branch.py b/invenio_access/alembic/67ba0de65fbb_create_access_branch.py index a01242a..94b50a1 100644 --- a/invenio_access/alembic/67ba0de65fbb_create_access_branch.py +++ b/invenio_access/alembic/67ba0de65fbb_create_access_branch.py @@ -15,7 +15,7 @@ revision = "67ba0de65fbb" down_revision = None branch_labels = ("invenio_access",) -depends_on = "dbdbc1b19cf2" +depends_on = ("dbdbc1b19cf2", "eb9743315a9d") def upgrade(): diff --git a/invenio_access/alembic/842a62b56e60_change_fk_accountsrole_to_string.py b/invenio_access/alembic/842a62b56e60_change_fk_accountsrole_to_string.py new file mode 100644 index 0000000..7e1e216 --- /dev/null +++ b/invenio_access/alembic/842a62b56e60_change_fk_accountsrole_to_string.py @@ -0,0 +1,71 @@ +# +# This file is part of Invenio. +# Copyright (C) 2016-2018 CERN. +# +# Invenio is free software; you can redistribute it and/or modify it +# under the terms of the MIT License; see LICENSE file for more details. + +"""Change FK AccountsRole to string.""" + +import sqlalchemy as sa +from alembic import op + +# revision identifiers, used by Alembic. +revision = "842a62b56e60" +down_revision = "04480be1593e" +branch_labels = () +depends_on = "8f11b75e0995" + + +def upgrade(): + """Upgrade database.""" + # ### commands auto generated by Alembic - please adjust! ### + # op.drop_index("ix_uq_partial_files_object_is_head", table_name="files_object") + # ### end Alembic commands ### + + #op.drop_constraint( + # "fk_access_actionsroles_role_id_accounts_role", + # "access_actionsroles", + # type_="foreignkey", + #) + + op.alter_column( + "access_actionsroles", + "role_id", + existing_type=sa.Integer, + type_=sa.String(80), + postgresql_using="role_id::integer", + ) + #op.create_foreign_key( + # op.f("fk_access_actionsroles_role_id_accounts_role"), + # "access_actionsroles", + # "accounts_role", + # ["role_id"], + # ["id"], + # ondelete="CASCADE", + #) + + +def downgrade(): + """Downgrade database.""" + # ### commands auto generated by Alembic - please adjust! ### + op.drop_constraint( + "fk_access_actionsroles_role_id_accounts_role", + "access_actionsroles", + type_="foreignkey", + ) + op.alter_column( + "access_actionsroles", + "role_id", + existing_type=sa.String(80), + type_=sa.Integer, + postgresql_using="role_id::integer", + ) + op.create_foreign_key( + op.f("fk_access_actionsroles_role_id_accounts_role"), + "access_actionsroles", + "accounts_role", + ["role_id"], + ["id"], + ondelete="CASCADE", + ) diff --git a/invenio_access/alembic/dbe499bfda43_prevent_null_in_actionusers_for_.py b/invenio_access/alembic/dbe499bfda43_prevent_null_in_actionusers_for_.py index 8fa011b..e83b437 100644 --- a/invenio_access/alembic/dbe499bfda43_prevent_null_in_actionusers_for_.py +++ b/invenio_access/alembic/dbe499bfda43_prevent_null_in_actionusers_for_.py @@ -15,7 +15,7 @@ revision = "dbe499bfda43" down_revision = "2069a982633b" branch_labels = () -depends_on = None +depends_on = "eb9743315a9d" def upgrade(): diff --git a/invenio_access/models.py b/invenio_access/models.py index e83af76..b915712 100644 --- a/invenio_access/models.py +++ b/invenio_access/models.py @@ -156,7 +156,7 @@ class ActionRoles(ActionNeedMixin, db.Model): ) role_id = db.Column( - db.Integer(), + db.String(80), db.ForeignKey(Role.id, ondelete="CASCADE"), nullable=False, index=True, diff --git a/invenio_access/translations/messages.pot b/invenio_access/translations/messages.pot index e3d48a2..36e31f1 100644 --- a/invenio_access/translations/messages.pot +++ b/invenio_access/translations/messages.pot @@ -1,22 +1,22 @@ # Translations template for invenio-access. -# Copyright (C) 2022 CERN +# Copyright (C) 2023 CERN # This file is distributed under the same license as the invenio-access # project. -# FIRST AUTHOR , 2022. +# FIRST AUTHOR , 2023. # #, fuzzy msgid "" msgstr "" -"Project-Id-Version: invenio-access 1.4.4\n" +"Project-Id-Version: invenio-access 1.4.5\n" "Report-Msgid-Bugs-To: info@inveniosoftware.org\n" -"POT-Creation-Date: 2022-10-12 09:03+0000\n" +"POT-Creation-Date: 2023-04-28 15:49+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=utf-8\n" "Content-Transfer-Encoding: 8bit\n" -"Generated-By: Babel 2.10.3\n" +"Generated-By: Babel 2.12.1\n" #: invenio_access/admin.py:39 msgid "Email"