Skip to content

Commit

Permalink
fix: add support for 7.6
Browse files Browse the repository at this point in the history
  • Loading branch information
philtweir committed May 15, 2024
1 parent 1e1debe commit b90895b
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 53 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ RUN set -ex \
&& apt-get install -y --no-install-recommends curl ca-certificates gnupg \
&& mkdir -p /etc/apt/keyrings \
&& curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg \
&& NODE_MAJOR=16 \
&& NODE_MAJOR=18 \
&& (echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" > /etc/apt/sources.list.d/nodesource.list) \
&& curl -sL https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - \
&& add-apt-repository "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -sc)-pgdg main" \
Expand Down
4 changes: 4 additions & 0 deletions arches/app/permissions/arches_standard.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,9 +483,12 @@ def get_editable_resource_types(self, user: User) -> list[str]:
"""

print("GEDRT")
if self.user_is_resource_editor(user):
print("GEDRT0", self.get_resource_types_by_perm(user, ["models.write_nodegroup", "models.delete_nodegroup"]))
return self.get_resource_types_by_perm(user, ["models.write_nodegroup", "models.delete_nodegroup"])
else:
print("GEDRT1")
return []


Expand Down Expand Up @@ -588,6 +591,7 @@ def group_required(self, user: User, *group_names: list[str]) -> bool:
# - Resource Exporter
# - System Administrator

print("WAT", user, user.is_authenticated, user.is_superuser, user.groups, group_names)
if user.is_authenticated:
if user.is_superuser or bool(user.groups.filter(name__in=group_names)):
return True
Expand Down
1 change: 1 addition & 0 deletions arches/app/templates/javascript.htm
Original file line number Diff line number Diff line change
Expand Up @@ -1009,6 +1009,7 @@
resource_permission_data="{% url 'resource_permission_data' %}"
permission_manager_data="{% url 'permission_manager_data' %}"
clear_user_permission_cache="{% url 'clear_user_permission_cache' %}"
get_user_details="{% url 'get_user_details' %}"
get_user_names="{% url 'get_user_names' %}"
get_user_roles="{% url 'get_user_roles' %}"
feature_popup_content="{% url 'feature_popup_content' %}"
Expand Down
3 changes: 2 additions & 1 deletion arches/app/utils/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ def group_required(*group_names, raise_exception=False):
"""

def in_groups(u):
passed = permission_group_required(u, *group_names)
if permission_group_required(u, *group_names):
return True
if raise_exception:
raise PermissionDenied
# else: user_passes_test() redirects to nowhere
Expand Down
6 changes: 2 additions & 4 deletions arches/app/views/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,9 +465,6 @@ def get_localized_descriptor(resource, descriptor_type, language_codes):
resource["_source"][descriptor_type] = _("Undefined")
count = dsl.count(index=RESOURCES_INDEX)

for key, value in list(search_results_object.items()):
ret[key] = value

return search_results_object, count, results


Expand Down Expand Up @@ -500,7 +497,8 @@ def get_provisional_type(provisional_filter, user):


def get_permitted_nodegroups(user):
return get_nodegroups_by_perm(user, "models.read_nodegroup")
# Until we can properly separate read/write
return get_nodegroups_by_perm(user, "models.write_nodegroup")


def buffer(request):
Expand Down
106 changes: 62 additions & 44 deletions arches/app/views/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,60 +45,71 @@
logger = logging.getLogger(__name__)


class UserView(BaseManagerView):
@method_decorator(group_required("System Administrator"), name="dispatch")
def get(self, request):
# For now, to double-check:
if request.user.is_authenticated and request.user.is_superuser:
full_details = request.GET.get("fullDetails", False) == "true"
with_groups = request.GET.get("withGroups", False) == "true"
identities = []
if with_groups:
for group in Group.objects.all():
groupUsers = [
{
"id": user.id,
"first_name": user.first_name,
"last_name": user.last_name,
"email": user.email,
"last_login": UserManagerView.get_last_login(user.last_login),
"username": user.username,
"groups": [gp.id for gp in user.groups.all()],
}
for user in group.user_set.all()
]
details = {"name": group.name, "type": "group", "id": group.pk}
if full_details:
details.update({"users": groupUsers, "default_permissions": group.permissions.all()})
identities.append(details)
for user in User.objects.filter():
groups = []
group_ids = []
default_perms = []
details = {
"name": user.email or user.username,
"type": "user",
"id": user.pk,
"first_name": user.first_name,
"last_name": user.last_name,
"email": user.email,
}
if full_details:
for group in user.groups.all():
groups.append(group.name)
group_ids.append(group.id)
default_perms = default_perms + list(group.permissions.all())
details.update({
"groups": ", ".join(groups),
"default_permissions": set(default_perms),
"is_superuser": user.is_superuser,
"group_ids": group_ids,
})
identities.append(details)

return JSONResponse({"identities": identities})

class UserManagerView(BaseManagerView):
action = ""

def get_last_login(self, date):
@staticmethod
def get_last_login(date):
result = _("Not yet logged in")
try:
result = datetime.strftime(date, "%Y-%m-%d %H:%M")
except TypeError as e:
pass
return result

def get_user_details(self, user):
identities = []
for group in Group.objects.all():
groupUsers = [
{
"id": user.id,
"first_name": user.first_name,
"last_name": user.last_name,
"email": user.email,
"last_login": self.get_last_login(user.last_login),
"username": user.username,
"groups": [gp.id for gp in user.groups.all()],
}
for user in group.user_set.all()
]
identities.append(
{"name": group.name, "type": "group", "id": group.pk, "users": groupUsers, "default_permissions": group.permissions.all()}
)
for user in User.objects.filter():
groups = []
group_ids = []
default_perms = []
for group in user.groups.all():
groups.append(group.name)
group_ids.append(group.id)
default_perms = default_perms + list(group.permissions.all())
identities.append(
{
"name": user.email or user.username,
"groups": ", ".join(groups),
"type": "user",
"id": user.pk,
"default_permissions": set(default_perms),
"is_superuser": user.is_superuser,
"group_ids": group_ids,
"first_name": user.first_name,
"last_name": user.last_name,
"email": user.email,
}
)

return {"identities": identities}

def get(self, request):

if self.request.user.is_authenticated and self.request.user.username != "anonymous":
Expand Down Expand Up @@ -129,6 +140,13 @@ def get(self, request):

def post(self, request):

if self.action == "get_user_details":
data = {}
if self.request.user.is_authenticated and user_is_resource_reviewer(request.user):
userids = json.loads(request.POST.get("userids", "[]"))
data = {u.id: u.username for u in User.objects.filter(id__in=userids)}
return JSONResponse(data)

if self.action == "get_user_names":
data = {}
if self.request.user.is_authenticated and user_is_resource_reviewer(request.user):
Expand Down
2 changes: 1 addition & 1 deletion arches/install/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Django>=4.2.11,<5.0.0
psycopg2==2.9.9
urllib3<2
elasticsearch>=8.3.1,<9.0.0
elasticsearch>=8.3.1,<8.4.1
rdflib==4.2.2
django-guardian==2.4.0
python-memcached==1.59
Expand Down
2 changes: 1 addition & 1 deletion arches/settings_docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def get_optional_env_variable(var_name):

CANTALOUPE_HTTP_ENDPOINT = "http://{}:{}".format(get_env_variable("CANTALOUPE_HOST"), get_env_variable("CANTALOUPE_PORT"))
ELASTICSEARCH_HTTP_PORT = get_env_variable("ESPORT")
ELASTICSEARCH_HOSTS = [{"host": get_env_variable("ESHOST"), "port": int(ELASTICSEARCH_HTTP_PORT)}]
ELASTICSEARCH_HOSTS = [{"scheme": "http", "host": get_env_variable("ESHOST"), "port": int(ELASTICSEARCH_HTTP_PORT)}]

USER_ELASTICSEARCH_PREFIX = get_optional_env_variable("ELASTICSEARCH_PREFIX")
if USER_ELASTICSEARCH_PREFIX:
Expand Down
3 changes: 2 additions & 1 deletion arches/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
from arches.app.views.plugin import PluginView
from arches.app.views.workflow_history import WorkflowHistoryView
from arches.app.views.concept import RDMView
from arches.app.views.user import UserManagerView
from arches.app.views.user import UserManagerView, UserView
from arches.app.views.tile import TileData
from arches.app.views.transaction import ReverseTransaction
from arches.app.views.notifications import NotificationView
Expand Down Expand Up @@ -234,6 +234,7 @@
re_path(r"^map_layer_manager/*", MapLayerManagerView.as_view(), name="map_layer_manager"),
re_path(r"^feature_popup_content$", main.feature_popup_content, name="feature_popup_content"),
re_path(r"^user$", UserManagerView.as_view(), name="user_profile_manager"),
re_path(r"^user/get_user_details$", UserView.as_view(), name="get_user_details"),
re_path(r"^user/get_user_names$", UserManagerView.as_view(action="get_user_names"), name="get_user_names"),
re_path(r"^user/get_user_roles$", UserManagerView.as_view(action="get_user_roles"), name="get_user_roles"),
re_path(r"^notifications$", NotificationView.as_view(), name="get_notifications"),
Expand Down
4 changes: 4 additions & 0 deletions arches/yarn.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1


0 comments on commit b90895b

Please sign in to comment.