mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-29 12:06:44 +00:00
Owner list API updates (#5906)
* Implement better search matching for owner list API * Update UserSerializer -Add filterset fields to various API endpoints * Allow owner list to be filtered by "is_active" status - Only applies to users (not groups) * Add ability to filter "owner" list by "is_active" status - Only applies to users * Use "is_active" filter for "responsible" form field
This commit is contained in:
parent
8972dcb506
commit
ac26f61ecd
@ -113,6 +113,9 @@ function buildFormFields() {
|
|||||||
},
|
},
|
||||||
responsible: {
|
responsible: {
|
||||||
icon: 'fa-users',
|
icon: 'fa-users',
|
||||||
|
filters: {
|
||||||
|
is_active: true,
|
||||||
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -172,6 +172,9 @@ function partFields(options={}) {
|
|||||||
},
|
},
|
||||||
responsible: {
|
responsible: {
|
||||||
icon: 'fa-user',
|
icon: 'fa-user',
|
||||||
|
filters: {
|
||||||
|
is_active: true,
|
||||||
|
}
|
||||||
},
|
},
|
||||||
component: {
|
component: {
|
||||||
default: global_settings.PART_COMPONENT,
|
default: global_settings.PART_COMPONENT,
|
||||||
|
@ -139,6 +139,9 @@ function purchaseOrderFields(options={}) {
|
|||||||
},
|
},
|
||||||
responsible: {
|
responsible: {
|
||||||
icon: 'fa-user',
|
icon: 'fa-user',
|
||||||
|
filters: {
|
||||||
|
is_active: true,
|
||||||
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -104,6 +104,9 @@ function returnOrderFields(options={}) {
|
|||||||
},
|
},
|
||||||
responsible: {
|
responsible: {
|
||||||
icon: 'fa-user',
|
icon: 'fa-user',
|
||||||
|
filters: {
|
||||||
|
is_active: true,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -130,6 +130,9 @@ function salesOrderFields(options={}) {
|
|||||||
},
|
},
|
||||||
responsible: {
|
responsible: {
|
||||||
icon: 'fa-user',
|
icon: 'fa-user',
|
||||||
|
filters: {
|
||||||
|
is_active: true,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -10,6 +10,7 @@ from rest_framework import exceptions, permissions
|
|||||||
from rest_framework.response import Response
|
from rest_framework.response import Response
|
||||||
from rest_framework.views import APIView
|
from rest_framework.views import APIView
|
||||||
|
|
||||||
|
import InvenTree.helpers
|
||||||
from InvenTree.filters import SEARCH_ORDER_FILTER
|
from InvenTree.filters import SEARCH_ORDER_FILTER
|
||||||
from InvenTree.mixins import (ListAPI, ListCreateAPI, RetrieveAPI,
|
from InvenTree.mixins import (ListAPI, ListCreateAPI, RetrieveAPI,
|
||||||
RetrieveUpdateAPI, RetrieveUpdateDestroyAPI)
|
RetrieveUpdateAPI, RetrieveUpdateDestroyAPI)
|
||||||
@ -42,18 +43,38 @@ class OwnerList(ListAPI):
|
|||||||
but until we determine a better way, this is what we have...
|
but until we determine a better way, this is what we have...
|
||||||
"""
|
"""
|
||||||
search_term = str(self.request.query_params.get('search', '')).lower()
|
search_term = str(self.request.query_params.get('search', '')).lower()
|
||||||
|
is_active = self.request.query_params.get('is_active', None)
|
||||||
|
|
||||||
queryset = super().filter_queryset(queryset)
|
queryset = super().filter_queryset(queryset)
|
||||||
|
|
||||||
if not search_term:
|
|
||||||
return queryset
|
|
||||||
|
|
||||||
results = []
|
results = []
|
||||||
|
|
||||||
# Extract search term f
|
# Get a list of all matching users, depending on the *is_active* flag
|
||||||
|
if is_active is not None:
|
||||||
|
is_active = InvenTree.helpers.str2bool(is_active)
|
||||||
|
matching_user_ids = User.objects.filter(is_active=is_active).values_list('pk', flat=True)
|
||||||
|
|
||||||
for result in queryset.all():
|
for result in queryset.all():
|
||||||
if search_term in result.name().lower():
|
|
||||||
|
name = str(result.name()).lower().strip()
|
||||||
|
search_match = True
|
||||||
|
|
||||||
|
# Extract search term f
|
||||||
|
if search_term:
|
||||||
|
for entry in search_term.strip().split(' '):
|
||||||
|
if entry not in name:
|
||||||
|
search_match = False
|
||||||
|
break
|
||||||
|
|
||||||
|
if not search_match:
|
||||||
|
continue
|
||||||
|
|
||||||
|
if is_active is not None:
|
||||||
|
# Skip any users which do not match the required *is_active* value
|
||||||
|
if result.owner_type.name == 'user' and result.owner_id not in matching_user_ids:
|
||||||
|
continue
|
||||||
|
|
||||||
|
# If we get here, there is no reason *not* to include this result
|
||||||
results.append(result)
|
results.append(result)
|
||||||
|
|
||||||
return results
|
return results
|
||||||
@ -156,6 +177,12 @@ class UserList(ListCreateAPI):
|
|||||||
'is_active',
|
'is_active',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
filterset_fields = [
|
||||||
|
'is_staff',
|
||||||
|
'is_active',
|
||||||
|
'is_superuser',
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
class GroupDetail(RetrieveUpdateDestroyAPI):
|
class GroupDetail(RetrieveUpdateDestroyAPI):
|
||||||
"""Detail endpoint for a particular auth group"""
|
"""Detail endpoint for a particular auth group"""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user