From b338186e009368e28d418e310ef11302e5e7b53b Mon Sep 17 00:00:00 2001 From: Cyrus Hiatt Date: Mon, 19 Jun 2023 14:32:50 -0700 Subject: [PATCH 1/5] Gives dev user admin page perms --- arches/management/commands/add_test_users.py | 106 +++++++++++++++++++ 1 file changed, 106 insertions(+) diff --git a/arches/management/commands/add_test_users.py b/arches/management/commands/add_test_users.py index 587d3d3270f..f2788547d30 100644 --- a/arches/management/commands/add_test_users.py +++ b/arches/management/commands/add_test_users.py @@ -19,6 +19,7 @@ from django.core.management.base import BaseCommand from django.contrib.auth.models import User from django.contrib.auth.models import Group +from django.contrib.auth.models import Permission from guardian.shortcuts import assign_perm from arches.app.models import models @@ -53,10 +54,115 @@ def add_users(self): "RDM Administrator", "Resource Reviewer", "System Administrator", + "Developer", ], }, ) + dev_perm_codenames = ["add_cardmodel", + "change_cardmodel", + "delete_cardmodel", + "view_cardmodel", + "add_cardcomponent", + "change_cardcomponent", + "delete_cardcomponent", + "view_cardcomponent", + "add_cardxnodexwidget", + "change_cardxnodexwidget", + "delete_cardxnodexwidget", + "view_cardxnodexwidget", + "add_concept", + "change_concept", + "delete_concept", + "view_concept", + "add_ddatatype", + "change_ddatatype", + "delete_ddatatype", + "view_ddatatype", + "add_function", + "change_function", + "delete_function", + "view_function", + "add_functionxgraph", + "change_functionxgraph", + "delete_functionxgraph", + "view_functionxgraph", + "add_reporttemplate", + "change_reporttemplate", + "delete_reporttemplate", + "view_reporttemplate", + "no_access_to_resourceinstance", + "add_searchcomponent", + "change_searchcomponent", + "delete_searchcomponent", + "view_searchcomponent", + "add_widget", + "change_widget", + "delete_widget", + "view_widget", + "add_plugin", + "change_plugin", + "delete_plugin", + "view_plugin", + "add_iiifmanifest", + "change_iiifmanifest", + "delete_iiifmanifest", + "view_iiifmanifest", + "add_vwannotation", + "change_vwannotation", + "delete_vwannotation", + "view_vwannotation", + "add_etlmodule", + "change_etlmodule", + "delete_etlmodule", + "view_etlmodule", + "add_spatialview", + "change_spatialview", + "delete_spatialview", + "view_spatialview", + "add_card", + "change_card", + "delete_card", + "view_card", + "view_resourceinstance", + "change_resourceinstance", + "delete_resourceinstance", + "add_resourceinstance", + "add_permission", + "change_permission", + "delete_permission", + "view_permission", + "add_group", + "change_group", + "delete_group", + "view_group", + "add_user", + "change_user", + "delete_user", + "view_user", + "add_groupobjectpermission", + "change_groupobjectpermission", + "delete_groupobjectpermission", + "view_groupobjectpermission", + "add_userobjectpermission", + "change_userobjectpermission", + "delete_userobjectpermission", + "view_userobjectpermission", + "add_archestemplate", + "change_archestemplate", + "delete_archestemplate", + "view_archestemplate", + ] + + try: + dev_group = Group.objects.create(name='Developer') + dev_perms = Permission.objects.filter(codename__in=dev_perm_codenames).values("id") + perm_ids = [int(perm['id']) for perm in dev_perms] + for permission in perm_ids: + dev_group.permissions.add(permission) + except Exception as e: + print(e) + for profile in profiles: try: user = User.objects.create_user(username=profile["name"], email=profile["email"], password=profile["password"]) From b688244290e82a61b870c360caf9b0f7ac129b9c Mon Sep 17 00:00:00 2001 From: Cyrus Hiatt Date: Tue, 20 Jun 2023 08:48:16 -0700 Subject: [PATCH 2/5] Add all perms to dev --- arches/management/commands/add_test_users.py | 97 +------------------- 1 file changed, 1 insertion(+), 96 deletions(-) diff --git a/arches/management/commands/add_test_users.py b/arches/management/commands/add_test_users.py index f2788547d30..8661104ca54 100644 --- a/arches/management/commands/add_test_users.py +++ b/arches/management/commands/add_test_users.py @@ -59,104 +59,9 @@ def add_users(self): }, ) - dev_perm_codenames = ["add_cardmodel", - "change_cardmodel", - "delete_cardmodel", - "view_cardmodel", - "add_cardcomponent", - "change_cardcomponent", - "delete_cardcomponent", - "view_cardcomponent", - "add_cardxnodexwidget", - "change_cardxnodexwidget", - "delete_cardxnodexwidget", - "view_cardxnodexwidget", - "add_concept", - "change_concept", - "delete_concept", - "view_concept", - "add_ddatatype", - "change_ddatatype", - "delete_ddatatype", - "view_ddatatype", - "add_function", - "change_function", - "delete_function", - "view_function", - "add_functionxgraph", - "change_functionxgraph", - "delete_functionxgraph", - "view_functionxgraph", - "add_reporttemplate", - "change_reporttemplate", - "delete_reporttemplate", - "view_reporttemplate", - "no_access_to_resourceinstance", - "add_searchcomponent", - "change_searchcomponent", - "delete_searchcomponent", - "view_searchcomponent", - "add_widget", - "change_widget", - "delete_widget", - "view_widget", - "add_plugin", - "change_plugin", - "delete_plugin", - "view_plugin", - "add_iiifmanifest", - "change_iiifmanifest", - "delete_iiifmanifest", - "view_iiifmanifest", - "add_vwannotation", - "change_vwannotation", - "delete_vwannotation", - "view_vwannotation", - "add_etlmodule", - "change_etlmodule", - "delete_etlmodule", - "view_etlmodule", - "add_spatialview", - "change_spatialview", - "delete_spatialview", - "view_spatialview", - "add_card", - "change_card", - "delete_card", - "view_card", - "view_resourceinstance", - "change_resourceinstance", - "delete_resourceinstance", - "add_resourceinstance", - "add_permission", - "change_permission", - "delete_permission", - "view_permission", - "add_group", - "change_group", - "delete_group", - "view_group", - "add_user", - "change_user", - "delete_user", - "view_user", - "add_groupobjectpermission", - "change_groupobjectpermission", - "delete_groupobjectpermission", - "view_groupobjectpermission", - "add_userobjectpermission", - "change_userobjectpermission", - "delete_userobjectpermission", - "view_userobjectpermission", - "add_archestemplate", - "change_archestemplate", - "delete_archestemplate", - "view_archestemplate", - ] - try: dev_group = Group.objects.create(name='Developer') - dev_perms = Permission.objects.filter(codename__in=dev_perm_codenames).values("id") + dev_perms = Permission.objects.all().values("id") perm_ids = [int(perm['id']) for perm in dev_perms] for permission in perm_ids: dev_group.permissions.add(permission) From 1bfa2740682a78978175b9aed28b2eefc9628ab6 Mon Sep 17 00:00:00 2001 From: Cyrus Hiatt Date: Tue, 20 Jun 2023 08:49:08 -0700 Subject: [PATCH 3/5] Move addtion of test users from pkg load to setup_db --- arches/management/commands/packages.py | 5 ++--- arches/management/commands/setup_db.py | 9 +++++++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/arches/management/commands/packages.py b/arches/management/commands/packages.py index 5e44d566190..f8c0048327f 100644 --- a/arches/management/commands/packages.py +++ b/arches/management/commands/packages.py @@ -897,9 +897,8 @@ def handle_source(source): raise Exception("this is an invalid package source") if setup_db: - management.call_command("setup_db", force=True) - if dev: - management.call_command("add_test_users") + management.call_command("setup_db", force=True, dev=dev) + load_ontologies(package_location) print("loading Kibana objects") load_kibana_objects(package_location) diff --git a/arches/management/commands/setup_db.py b/arches/management/commands/setup_db.py index ba3eb898455..99900211b08 100644 --- a/arches/management/commands/setup_db.py +++ b/arches/management/commands/setup_db.py @@ -41,6 +41,8 @@ def add_arguments(self, parser): parser.add_argument( "--force", action="store_true", default=False, help='used to force a yes answer to any user input "continue? y/n" prompt' ) + + parser.add_argument("-dev", "--dev", action="store_true", dest="dev", help="Add users for development") def handle(self, *args, **options): @@ -49,7 +51,7 @@ def handle(self, *args, **options): if not proceed: exit() - self.setup_db() + self.setup_db(development=options["dev"]) def get_connection(self): """This method acquires a connection to the database, first trying to use @@ -171,7 +173,7 @@ def drop_and_recreate_db(self, cursor): print(msg) exit() - def setup_db(self): + def setup_db(self, development=False): """ Drops and re-installs the database found at "arches_" WARNING: This will destroy data @@ -208,3 +210,6 @@ def setup_db(self): management.call_command("packages", operation="import_business_data", source=settings_data_local, overwrite="overwrite") management.call_command("graph", operation="publish") + + if development: + management.call_command("add_test_users") From 61933caf7924bdec2f6d7ffc8193a51ad982eccf Mon Sep 17 00:00:00 2001 From: Cyrus Hiatt Date: Tue, 20 Jun 2023 08:49:19 -0700 Subject: [PATCH 4/5] nit --- arches/management/commands/setup_db.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arches/management/commands/setup_db.py b/arches/management/commands/setup_db.py index 99900211b08..4bce034bffa 100644 --- a/arches/management/commands/setup_db.py +++ b/arches/management/commands/setup_db.py @@ -212,4 +212,4 @@ def setup_db(self, development=False): management.call_command("graph", operation="publish") if development: - management.call_command("add_test_users") + management.call_command("add_test_users") \ No newline at end of file From f3de74ec75134161e22663842af03f242b96e80e Mon Sep 17 00:00:00 2001 From: Cyrus Hiatt Date: Tue, 20 Jun 2023 08:53:53 -0700 Subject: [PATCH 5/5] Add dev to Resource Exporter group --- arches/management/commands/add_test_users.py | 1 + 1 file changed, 1 insertion(+) diff --git a/arches/management/commands/add_test_users.py b/arches/management/commands/add_test_users.py index 8661104ca54..eb10f709f83 100644 --- a/arches/management/commands/add_test_users.py +++ b/arches/management/commands/add_test_users.py @@ -47,6 +47,7 @@ def add_users(self): "groups": [ "Graph Editor", "Resource Editor", + "Resource Exporter", "Resource Reviewer", "Application Administrator", "Crowdsource Editor",