diff --git a/backend/lcfs/web/api/organizations/views.py b/backend/lcfs/web/api/organizations/views.py index 8ff755fc9..9f3e8f517 100644 --- a/backend/lcfs/web/api/organizations/views.py +++ b/backend/lcfs/web/api/organizations/views.py @@ -162,25 +162,23 @@ async def get_organization_types( return await service.get_organization_types() -# TODO review security of this endpoint around returning balances -# for all organizations @router.get( "/names/", response_model=List[OrganizationSummaryResponseSchema], status_code=status.HTTP_200_OK, ) -@cache(expire=1) # cache for 1 hour -@view_handler(["*"]) +@cache(expire=1) # Cache for 1 hour +@view_handler( + [RoleEnum.GOVERNMENT] +) # Ensure only government can access this endpoint because it returns balances async def get_organization_names( - request: Request, service: OrganizationsService = Depends() + request: Request, + only_registered: bool = Query(True), + service: OrganizationsService = Depends(), ): - """Fetch all organization names""" - - # Set the default sorting order + """Fetch all organization names.""" order_by = ("name", "asc") - - # Call the service with only_registered set to True to fetch only registered organizations - return await service.get_organization_names(True, order_by) + return await service.get_organization_names(only_registered, order_by) @router.get( diff --git a/frontend/src/hooks/useOrganizations.js b/frontend/src/hooks/useOrganizations.js index 7cc6f4bfc..e665e145b 100644 --- a/frontend/src/hooks/useOrganizations.js +++ b/frontend/src/hooks/useOrganizations.js @@ -11,13 +11,16 @@ export const useOrganizationStatuses = (options) => { }) } -export const useOrganizationNames = (options) => { +export const useOrganizationNames = (onlyRegistered = true, options) => { const client = useApiService() return useQuery({ - queryKey: ['organization-names'], - queryFn: async () => (await client.get('/organizations/names/')).data, - ...options + queryKey: ['organization-names', onlyRegistered], + queryFn: async () => { + const response = await client.get(`/organizations/names/?only_registered=${onlyRegistered}`) + return response.data + }, + ...options, }) } diff --git a/frontend/src/views/Transactions/components/TransactionDetails.jsx b/frontend/src/views/Transactions/components/TransactionDetails.jsx index 81fdd1b3b..1d674d651 100644 --- a/frontend/src/views/Transactions/components/TransactionDetails.jsx +++ b/frontend/src/views/Transactions/components/TransactionDetails.jsx @@ -16,7 +16,7 @@ import { } from '@mui/material' import { dateFormatter, numberFormatter } from '@/utils/formatters' import { useFormContext, Controller } from 'react-hook-form' -import { useRegExtOrgs } from '@/hooks/useOrganizations' +import { useOrganizationNames } from '@/hooks/useOrganizations' import { useOrganizationBalance } from '@/hooks/useOrganization' import Loading from '@/components/Loading' import { @@ -34,7 +34,7 @@ export const TransactionDetails = ({ transactionId, isEditable }) => { control } = useFormContext() - const { data: orgData } = useRegExtOrgs() + const { data: orgData } = useOrganizationNames(false) const organizations = orgData?.map((org) => ({ value: parseInt(org.organizationId),