[PUI] Tweaks (#6516)

* Enable editing "part" in PartTestTemplate

* Hide part if user is not staff

* API: allow filtering of templates by key

* Update API docs
This commit is contained in:
Oliver 2024-02-19 17:05:36 +11:00 committed by GitHub
parent 3b11a01966
commit 3a52a1631d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 17 additions and 4 deletions

View File

@ -1,11 +1,14 @@
"""InvenTree API version information.""" """InvenTree API version information."""
# InvenTree API version # InvenTree API version
INVENTREE_API_VERSION = 170 INVENTREE_API_VERSION = 171
"""Increment this API version number whenever there is a significant change to the API that any clients need to know about.""" """Increment this API version number whenever there is a significant change to the API that any clients need to know about."""
INVENTREE_API_TEXT = """ INVENTREE_API_TEXT = """
v171 - 2024-02-19 : https://github.com/inventree/InvenTree/pull/6516
- Adds "key" as a filterable parameter to PartTestTemplate list endpoint
v170 -> 2024-02-19 : https://github.com/inventree/InvenTree/pull/6514 v170 -> 2024-02-19 : https://github.com/inventree/InvenTree/pull/6514
- Adds "has_results" filter to the PartTestTemplate list endpoint - Adds "has_results" filter to the PartTestTemplate list endpoint

View File

@ -375,7 +375,7 @@ class PartTestTemplateFilter(rest_filters.FilterSet):
"""Metaclass options for this filterset.""" """Metaclass options for this filterset."""
model = PartTestTemplate model = PartTestTemplate
fields = ['required', 'requires_value', 'requires_attachment'] fields = ['required', 'requires_value', 'requires_attachment', 'key']
part = rest_filters.ModelChoiceFilter( part = rest_filters.ModelChoiceFilter(
queryset=Part.objects.filter(trackable=True), queryset=Part.objects.filter(trackable=True),

View File

@ -17,6 +17,8 @@ interface UserStateProps {
hasChangeRole: (role: UserRoles) => boolean; hasChangeRole: (role: UserRoles) => boolean;
hasAddRole: (role: UserRoles) => boolean; hasAddRole: (role: UserRoles) => boolean;
hasViewRole: (role: UserRoles) => boolean; hasViewRole: (role: UserRoles) => boolean;
isStaff: () => boolean;
isSuperuser: () => boolean;
} }
/** /**
@ -91,6 +93,14 @@ export const useUserState = create<UserStateProps>((set, get) => ({
return user?.roles[role]?.includes(permission) ?? false; return user?.roles[role]?.includes(permission) ?? false;
}, },
isStaff: () => {
const user: UserProps = get().user as UserProps;
return user?.is_staff ?? false;
},
isSuperuser: () => {
const user: UserProps = get().user as UserProps;
return user?.is_superuser ?? false;
},
hasDeleteRole: (role: UserRoles) => { hasDeleteRole: (role: UserRoles) => {
return get().checkUserRole(role, UserPermissions.delete); return get().checkUserRole(role, UserPermissions.delete);
}, },

View File

@ -94,7 +94,7 @@ export default function PartTestTemplateTable({ partId }: { partId: number }) {
const partTestTemplateFields: ApiFormFieldSet = useMemo(() => { const partTestTemplateFields: ApiFormFieldSet = useMemo(() => {
return { return {
part: { part: {
hidden: true hidden: !user.isStaff()
}, },
test_name: {}, test_name: {},
description: {}, description: {},
@ -102,7 +102,7 @@ export default function PartTestTemplateTable({ partId }: { partId: number }) {
requires_value: {}, requires_value: {},
requires_attachment: {} requires_attachment: {}
}; };
}, []); }, [user]);
const newTestTemplate = useCreateApiFormModal({ const newTestTemplate = useCreateApiFormModal({
url: ApiEndpoints.part_test_template_list, url: ApiEndpoints.part_test_template_list,