Fix filter field setting for user classes, where field is named 'username', not 'name'

This commit is contained in:
Michael DeHaan
2013-04-17 21:36:12 -04:00
parent 5336316f2e
commit 296c6e8cd4

View File

@@ -1,16 +1,16 @@
# Copyright (c) 2013 AnsibleWorks, Inc. # Copyright (c) 2013 AnsibleWorks, Inc.
# #
# This file is part of Ansible Commander. # This file is part of Ansible Commander.
# #
# Ansible Commander is free software: you can redistribute it and/or modify # Ansible Commander is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 3 of the License. # the Free Software Foundation, version 3 of the License.
# #
# Ansible Commander is distributed in the hope that it will be useful, # Ansible Commander is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details. # GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with Ansible Commander. If not, see <http://www.gnu.org/licenses/>. # along with Ansible Commander. If not, see <http://www.gnu.org/licenses/>.
@@ -94,6 +94,7 @@ class OrganizationsUsersList(BaseSubList):
relationship = 'users' relationship = 'users'
postable = True postable = True
inject_primary_key_on_post_as = 'organization' inject_primary_key_on_post_as = 'organization'
filter_fields = ('username',)
def _get_queryset(self): def _get_queryset(self):
''' to list users in the organization, I must be a superuser or org admin ''' ''' to list users in the organization, I must be a superuser or org admin '''
@@ -111,6 +112,7 @@ class OrganizationsAdminsList(BaseSubList):
relationship = 'admins' relationship = 'admins'
postable = True postable = True
inject_primary_key_on_post_as = 'organization' inject_primary_key_on_post_as = 'organization'
filter_fields = ('username',)
def _get_queryset(self): def _get_queryset(self):
''' to list admins in the organization, I must be a superuser or org admin ''' ''' to list admins in the organization, I must be a superuser or org admin '''
@@ -128,6 +130,7 @@ class OrganizationsProjectsList(BaseSubList):
relationship = 'projects' # " " relationship = 'projects' # " "
postable = True postable = True
inject_primary_key_on_post_as = 'organization' inject_primary_key_on_post_as = 'organization'
filter_fields = ('name',)
def _get_queryset(self): def _get_queryset(self):
''' to list projects in the organization, I must be a superuser or org admin ''' ''' to list projects in the organization, I must be a superuser or org admin '''
@@ -145,6 +148,7 @@ class OrganizationsTagsList(BaseSubList):
relationship = 'tags' # " " relationship = 'tags' # " "
postable = True postable = True
inject_primary_key_on_post_as = 'organization' inject_primary_key_on_post_as = 'organization'
filter_fields = ('name',)
def _get_queryset(self): def _get_queryset(self):
''' to list tags in the organization, I must be a superuser or org admin ''' ''' to list tags in the organization, I must be a superuser or org admin '''
@@ -164,6 +168,7 @@ class OrganizationsTeamsList(BaseSubList):
postable = True postable = True
inject_primary_key_on_post_as = 'organization' inject_primary_key_on_post_as = 'organization'
severable = False severable = False
filter_fields = ('name',)
def _get_queryset(self): def _get_queryset(self):
''' to list users in the organization, I must be a superuser or org admin ''' ''' to list users in the organization, I must be a superuser or org admin '''
@@ -177,6 +182,7 @@ class TeamsList(BaseList):
model = Team model = Team
serializer_class = TeamSerializer serializer_class = TeamSerializer
permission_classes = (CustomRbac,) permission_classes = (CustomRbac,)
filter_fields = ('name',)
# I can see a team if: # I can see a team if:
# I am a superuser # I am a superuser
@@ -210,6 +216,7 @@ class TeamsUsersList(BaseSubList):
postable = True postable = True
inject_primary_key_on_post_as = 'team' inject_primary_key_on_post_as = 'team'
severable = True severable = True
filter_fields = ('username',)
def _get_queryset(self): def _get_queryset(self):
# FIXME: audit all BaseSubLists to check for permissions on the original object too # FIXME: audit all BaseSubLists to check for permissions on the original object too
@@ -231,6 +238,7 @@ class TeamsCredentialsList(BaseSubList):
relationship = 'credentials' relationship = 'credentials'
postable = True postable = True
inject_primary_key_on_post_as = 'team' inject_primary_key_on_post_as = 'team'
filter_fields = ('name',)
def _get_queryset(self): def _get_queryset(self):
team = Team.objects.get(pk=self.kwargs['pk']) team = Team.objects.get(pk=self.kwargs['pk'])
@@ -248,6 +256,7 @@ class ProjectsList(BaseList):
model = Project model = Project
serializer_class = ProjectSerializer serializer_class = ProjectSerializer
permission_classes = (CustomRbac,) permission_classes = (CustomRbac,)
filter_fields = ('name',)
# I can see a project if # I can see a project if
# I am a superuser # I am a superuser
@@ -281,6 +290,7 @@ class ProjectsOrganizationsList(BaseSubList):
parent_model = Project parent_model = Project
relationship = 'organizations' relationship = 'organizations'
postable = False postable = False
filter_fields = ('name',)
def _get_queryset(self): def _get_queryset(self):
project = Project.objects.get(pk=self.kwargs['pk']) project = Project.objects.get(pk=self.kwargs['pk'])
@@ -299,6 +309,7 @@ class UsersList(BaseList):
model = User model = User
serializer_class = UserSerializer serializer_class = UserSerializer
permission_classes = (CustomRbac,) permission_classes = (CustomRbac,)
filter_fields = ('username',)
def post(self, request, *args, **kwargs): def post(self, request, *args, **kwargs):
password = request.DATA.get('password', None) password = request.DATA.get('password', None)
@@ -325,6 +336,7 @@ class UsersMeList(BaseList):
model = User model = User
serializer_class = UserSerializer serializer_class = UserSerializer
permission_classes = (CustomRbac,) permission_classes = (CustomRbac,)
filter_fields = ('username',)
def post(self, request, *args, **kwargs): def post(self, request, *args, **kwargs):
raise PermissionDenied() raise PermissionDenied()
@@ -341,6 +353,7 @@ class UsersTeamsList(BaseSubList):
parent_model = User parent_model = User
relationship = 'teams' relationship = 'teams'
postable = False postable = False
filter_fields = ('name',)
def _get_queryset(self): def _get_queryset(self):
user = User.objects.get(pk=self.kwargs['pk']) user = User.objects.get(pk=self.kwargs['pk'])
@@ -356,6 +369,7 @@ class UsersProjectsList(BaseSubList):
parent_model = User parent_model = User
relationship = 'teams' relationship = 'teams'
postable = False postable = False
filter_fields = ('name',)
def _get_queryset(self): def _get_queryset(self):
user = User.objects.get(pk=self.kwargs['pk']) user = User.objects.get(pk=self.kwargs['pk'])
@@ -373,6 +387,7 @@ class UsersCredentialsList(BaseSubList):
relationship = 'credentials' relationship = 'credentials'
postable = True postable = True
inject_primary_key_on_post_as = 'user' inject_primary_key_on_post_as = 'user'
filter_fields = ('name',)
def _get_queryset(self): def _get_queryset(self):
user = User.objects.get(pk=self.kwargs['pk']) user = User.objects.get(pk=self.kwargs['pk'])
@@ -391,6 +406,7 @@ class UsersOrganizationsList(BaseSubList):
parent_model = User parent_model = User
relationship = 'organizations' relationship = 'organizations'
postable = False postable = False
filter_fields = ('name',)
def _get_queryset(self): def _get_queryset(self):
user = User.objects.get(pk=self.kwargs['pk']) user = User.objects.get(pk=self.kwargs['pk'])
@@ -406,6 +422,7 @@ class UsersAdminOrganizationsList(BaseSubList):
parent_model = User parent_model = User
relationship = 'admin_of_organizations' relationship = 'admin_of_organizations'
postable = False postable = False
filter_fields = ('name',)
def _get_queryset(self): def _get_queryset(self):
user = User.objects.get(pk=self.kwargs['pk']) user = User.objects.get(pk=self.kwargs['pk'])
@@ -441,6 +458,7 @@ class InventoryList(BaseList):
model = Inventory model = Inventory
serializer_class = InventorySerializer serializer_class = InventorySerializer
permission_classes = (CustomRbac,) permission_classes = (CustomRbac,)
filter_fields = ('name',)
def _filter_queryset(self, base): def _filter_queryset(self, base):
if self.request.user.is_superuser: if self.request.user.is_superuser:
@@ -472,6 +490,7 @@ class HostsList(BaseList):
model = Host model = Host
serializer_class = HostSerializer serializer_class = HostSerializer
permission_classes = (CustomRbac,) permission_classes = (CustomRbac,)
filter_fields = ('name',)
def _get_queryset(self): def _get_queryset(self):
''' '''
@@ -513,6 +532,7 @@ class InventoryHostsList(BaseSubList):
# FIXME: go back and add these to other SubLists # FIXME: go back and add these to other SubLists
inject_primary_key_on_post_as = 'inventory' inject_primary_key_on_post_as = 'inventory'
severable = False severable = False
filter_fields = ('name',)
def _get_queryset(self): def _get_queryset(self):
inventory = Inventory.objects.get(pk=self.kwargs['pk']) inventory = Inventory.objects.get(pk=self.kwargs['pk'])
@@ -525,6 +545,7 @@ class GroupsList(BaseList):
model = Group model = Group
serializer_class = GroupSerializer serializer_class = GroupSerializer
permission_classes = (CustomRbac,) permission_classes = (CustomRbac,)
filter_fields = ('name',)
def _get_queryset(self): def _get_queryset(self):
''' '''
@@ -556,6 +577,7 @@ class GroupsChildrenList(BaseSubList):
relationship = 'children' relationship = 'children'
postable = True postable = True
inject_primary_key_on_post_as = 'parent' inject_primary_key_on_post_as = 'parent'
filter_fields = ('name',)
def _get_queryset(self): def _get_queryset(self):
@@ -589,6 +611,7 @@ class GroupsHostsList(BaseSubList):
relationship = 'hosts' relationship = 'hosts'
postable = True postable = True
inject_primary_key_on_post_as = 'group' inject_primary_key_on_post_as = 'group'
filter_fields = ('name',)
def _get_queryset(self): def _get_queryset(self):
@@ -619,10 +642,11 @@ class GroupsAllHostsList(BaseSubList):
permission_classes = (CustomRbac,) permission_classes = (CustomRbac,)
parent_model = Group parent_model = Group
relationship = 'hosts' relationship = 'hosts'
filter_fields = ('name',)
def _child_hosts(self, parent): def _child_hosts(self, parent):
# TODO: should probably be a method on the model # TODO: should probably be a method on the model
result = parent.hosts.distinct() result = parent.hosts.distinct()
if parent.children.count() == 0: if parent.children.count() == 0:
return result return result
else: else:
@@ -634,9 +658,9 @@ class GroupsAllHostsList(BaseSubList):
return result return result
def _get_queryset(self): def _get_queryset(self):
parent = Group.objects.get(pk=self.kwargs['pk']) parent = Group.objects.get(pk=self.kwargs['pk'])
# FIXME: verify read permissions on this object are still required at a higher level # FIXME: verify read permissions on this object are still required at a higher level
base = self._child_hosts(parent) base = self._child_hosts(parent)
@@ -675,6 +699,7 @@ class InventoryGroupsList(BaseSubList):
# FIXME: go back and add these to other SubLists # FIXME: go back and add these to other SubLists
inject_primary_key_on_post_as = 'inventory' inject_primary_key_on_post_as = 'inventory'
severable = False severable = False
filter_fields = ('name',)
def _get_queryset(self): def _get_queryset(self):
# FIXME: share code with inventory filter queryset methods (make that a classmethod) # FIXME: share code with inventory filter queryset methods (make that a classmethod)