Skip to content

Commit

Permalink
Checkin.
Browse files Browse the repository at this point in the history
No-Issue

Signed-off-by: James Tanner <[email protected]>
  • Loading branch information
jctanner committed Nov 14, 2023
1 parent b328389 commit 506f417
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 35 deletions.
19 changes: 4 additions & 15 deletions galaxy_ng/app/access_control/access_policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -839,5 +829,4 @@ class SurveyAccessPolicy(AccessPolicyBase):
NAME = "SurveyAccessPolicy"

def is_survey_user(self, request, viewset, action):
print('IS_SURVEY_USER')
return True
return True
2 changes: 1 addition & 1 deletion galaxy_ng/app/access_control/statements/survey.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@
"condition": "is_survey_user",
},
]
}
}
11 changes: 5 additions & 6 deletions galaxy_ng/app/api/v3/filtersets/survey.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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


Expand Down
2 changes: 1 addition & 1 deletion galaxy_ng/app/api/v3/serializers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,5 @@
'CollectionSurveySerializer',
'CollectionSurveyRollupSerializer',
'LegacyRoleSurveySerializer',
'LegacyRoleSurveyRollupSerializer',
'LegacyRoleSurveyRollupSerializer',
)
15 changes: 6 additions & 9 deletions galaxy_ng/app/api/v3/viewsets/survey.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -34,6 +27,11 @@
)


GALAXY_AUTHENTICATION_CLASSES = perform_import(
settings.GALAXY_AUTHENTICATION_CLASSES,
'GALAXY_AUTHENTICATION_CLASSES'
)


class CollectionSurveyRollupList(viewsets.ModelViewSet):
queryset = CollectionSurveyRollup.objects.all()
Expand All @@ -43,7 +41,6 @@ class CollectionSurveyRollupList(viewsets.ModelViewSet):
permission_classes = [IsAuthenticatedOrReadOnly]



class LegacyRoleSurveyRollupList(viewsets.ModelViewSet):
queryset = LegacyRoleSurveyRollup.objects.all()
serializer_class = LegacyRoleSurveyRollupSerializer
Expand Down
3 changes: 2 additions & 1 deletion galaxy_ng/app/management/commands/sync-galaxy-collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
}
]
Expand Down
2 changes: 0 additions & 2 deletions galaxy_ng/app/models/survey.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 506f417

Please sign in to comment.