Skip to content

Commit

Permalink
Merge pull request #9675 from archesproject/extend_dev_user_perms
Browse files Browse the repository at this point in the history
Gives dev user admin page perms
  • Loading branch information
chrabyrd authored Jun 21, 2023
2 parents a937c2c + f3de74e commit 17927dd
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
12 changes: 12 additions & 0 deletions arches/management/commands/add_test_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -46,17 +47,28 @@ def add_users(self):
"groups": [
"Graph Editor",
"Resource Editor",
"Resource Exporter",
"Resource Reviewer",
"Application Administrator",
"Crowdsource Editor",
"Guest",
"RDM Administrator",
"Resource Reviewer",
"System Administrator",
"Developer",
],
},
)

try:
dev_group = Group.objects.create(name='Developer')
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)
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"])
Expand Down
5 changes: 2 additions & 3 deletions arches/management/commands/packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 7 additions & 2 deletions arches/management/commands/setup_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand All @@ -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
Expand Down Expand Up @@ -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_<package_name>"
WARNING: This will destroy data
Expand Down Expand Up @@ -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")

0 comments on commit 17927dd

Please sign in to comment.