From 506f417cc0e97ccd2b22260b97e35467a6b1eb23 Mon Sep 17 00:00:00 2001 From: James Tanner Date: Tue, 14 Nov 2023 14:43:09 -0500 Subject: [PATCH] Checkin. No-Issue Signed-off-by: James Tanner --- galaxy_ng/app/access_control/access_policy.py | 19 ++++--------------- .../app/access_control/statements/survey.py | 2 +- galaxy_ng/app/api/v3/filtersets/survey.py | 11 +++++------ galaxy_ng/app/api/v3/serializers/__init__.py | 2 +- galaxy_ng/app/api/v3/viewsets/survey.py | 15 ++++++--------- .../commands/sync-galaxy-collections.py | 3 ++- galaxy_ng/app/models/survey.py | 2 -- 7 files changed, 19 insertions(+), 35 deletions(-) diff --git a/galaxy_ng/app/access_control/access_policy.py b/galaxy_ng/app/access_control/access_policy.py index 15cb647448..b3a8177fbe 100644 --- a/galaxy_ng/app/access_control/access_policy.py +++ b/galaxy_ng/app/access_control/access_policy.py @@ -126,17 +126,11 @@ class AccessPolicyBase(AccessPolicyFromDB): @classmethod def get_access_policy(cls, view): - print(f'GET_ACCESS_POLICY cls.NAME:{cls.NAME} view:{view}') - statements = GALAXY_STATEMENTS - from pprint import pprint; pprint(statements) # If this is a galaxy access policy, load from the statement file if cls.NAME: - #return statements.get_pulp_access_policy(cls.NAME, default=[]) - res = statements.get_pulp_access_policy(cls.NAME, default=[]) - print(f'RETURN(1) {res}') - return res + return statements.get_pulp_access_policy(cls.NAME, default=[]) # Check if the view has a url pattern. If it does, check for customized # policies from statements/pulp.py @@ -145,19 +139,15 @@ def get_access_policy(cls, view): override_ap = PULP_VIEWSETS.get(viewname, None) if override_ap: - print(f'RETURN(2) MOCK {override_ap}') return MockPulpAccessPolicy(override_ap) - except AttributeError as e: - print(f'ERROR(1) {e}') + except AttributeError: pass # If no customized policies exist, try to load the one defined on the view itself try: - print(f'RETURN(3) view.DEFAULT_ACCESS_POLICY') return MockPulpAccessPolicy(view.DEFAULT_ACCESS_POLICY) - except AttributeError as e: - print(f'ERROR(2) {e}') + except AttributeError: pass # As a last resort, require admin rights @@ -839,5 +829,4 @@ class SurveyAccessPolicy(AccessPolicyBase): NAME = "SurveyAccessPolicy" def is_survey_user(self, request, viewset, action): - print('IS_SURVEY_USER') - return True \ No newline at end of file + return True diff --git a/galaxy_ng/app/access_control/statements/survey.py b/galaxy_ng/app/access_control/statements/survey.py index 74167db785..d727c84183 100644 --- a/galaxy_ng/app/access_control/statements/survey.py +++ b/galaxy_ng/app/access_control/statements/survey.py @@ -19,4 +19,4 @@ "condition": "is_survey_user", }, ] -} \ No newline at end of file +} diff --git a/galaxy_ng/app/api/v3/filtersets/survey.py b/galaxy_ng/app/api/v3/filtersets/survey.py index 0c80eb68e9..30280dfc7d 100644 --- a/galaxy_ng/app/api/v3/filtersets/survey.py +++ b/galaxy_ng/app/api/v3/filtersets/survey.py @@ -1,9 +1,7 @@ from django.db.models import Q -from django.db.models import Case, Value, When from django_filters import filters from django_filters.rest_framework import filterset -from galaxy_ng.app.models.auth import User from galaxy_ng.app.models.survey import LegacyRoleSurvey from galaxy_ng.app.models.survey import CollectionSurvey @@ -14,19 +12,20 @@ class BaseSurveyFilter(filterset.FilterSet): sort = filters.OrderingFilter( fields=( - ('created','created'), + ('created', 'created'), ) ) def user_filter(self, queryset, name, value): - print(f'FILTER {name} {value}') + + # allow filtering on uid and username ... if value.isdigit(): queryset = queryset.filter( - Q(user__id=int(value)) | - Q(user__username=value) + Q(user__id=int(value)) | Q(user__username=value) ) else: queryset = queryset.filter(user__username=value) + return queryset diff --git a/galaxy_ng/app/api/v3/serializers/__init__.py b/galaxy_ng/app/api/v3/serializers/__init__.py index a134808ca9..d331a807d9 100644 --- a/galaxy_ng/app/api/v3/serializers/__init__.py +++ b/galaxy_ng/app/api/v3/serializers/__init__.py @@ -49,5 +49,5 @@ 'CollectionSurveySerializer', 'CollectionSurveyRollupSerializer', 'LegacyRoleSurveySerializer', - 'LegacyRoleSurveyRollupSerializer', + 'LegacyRoleSurveyRollupSerializer', ) diff --git a/galaxy_ng/app/api/v3/viewsets/survey.py b/galaxy_ng/app/api/v3/viewsets/survey.py index de7b4a20c2..3b2d2aa731 100644 --- a/galaxy_ng/app/api/v3/viewsets/survey.py +++ b/galaxy_ng/app/api/v3/viewsets/survey.py @@ -2,18 +2,11 @@ from django_filters import rest_framework as filters from rest_framework import viewsets -from galaxy_ng.app.access_control.access_policy import SurveyAccessPolicy +# from galaxy_ng.app.access_control.access_policy import SurveyAccessPolicy -from rest_framework.permissions import AllowAny from rest_framework.settings import perform_import from rest_framework.permissions import IsAuthenticatedOrReadOnly -GALAXY_AUTHENTICATION_CLASSES = perform_import( - settings.GALAXY_AUTHENTICATION_CLASSES, - 'GALAXY_AUTHENTICATION_CLASSES' -) - - from galaxy_ng.app.models import ( CollectionSurvey, CollectionSurveyRollup, @@ -34,6 +27,11 @@ ) +GALAXY_AUTHENTICATION_CLASSES = perform_import( + settings.GALAXY_AUTHENTICATION_CLASSES, + 'GALAXY_AUTHENTICATION_CLASSES' +) + class CollectionSurveyRollupList(viewsets.ModelViewSet): queryset = CollectionSurveyRollup.objects.all() @@ -43,7 +41,6 @@ class CollectionSurveyRollupList(viewsets.ModelViewSet): permission_classes = [IsAuthenticatedOrReadOnly] - class LegacyRoleSurveyRollupList(viewsets.ModelViewSet): queryset = LegacyRoleSurveyRollup.objects.all() serializer_class = LegacyRoleSurveyRollupSerializer diff --git a/galaxy_ng/app/management/commands/sync-galaxy-collections.py b/galaxy_ng/app/management/commands/sync-galaxy-collections.py index 1c46bf489b..f1b534b61d 100644 --- a/galaxy_ng/app/management/commands/sync-galaxy-collections.py +++ b/galaxy_ng/app/management/commands/sync-galaxy-collections.py @@ -107,10 +107,11 @@ def handle(self, *args, **options): ] } else: + fqn = collection_info['namespace']['name'] + '.' + collection_info['name'] requirements = { 'collections': [ { - 'name': collection_info['namespace']['name'] + '.' + collection_info['name'], + 'name': fqn, 'version': collection_info['latest_version']['version'] } ] diff --git a/galaxy_ng/app/models/survey.py b/galaxy_ng/app/models/survey.py index c85e3a69a5..f010b5e74e 100644 --- a/galaxy_ng/app/models/survey.py +++ b/galaxy_ng/app/models/survey.py @@ -1,7 +1,5 @@ from django.db import models from django.contrib.auth import get_user_model -from django.contrib.contenttypes.fields import GenericForeignKey -from django.contrib.contenttypes.models import ContentType from django.core.validators import MinValueValidator, MaxValueValidator from pulp_ansible.app.models import Collection