Skip to content

Commit

Permalink
Merge branch 'master' into pui-cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
SchrodingersGat authored Nov 6, 2024
2 parents 5146461 + e46ae1a commit 54a321a
Show file tree
Hide file tree
Showing 13 changed files with 64 additions and 27 deletions.
3 changes: 3 additions & 0 deletions src/backend/InvenTree/InvenTree/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,9 @@ def get(self, request, *args, **kwargs):
'platform': InvenTree.version.inventreePlatform() if is_staff else None,
'installer': InvenTree.version.inventreeInstaller() if is_staff else None,
'target': InvenTree.version.inventreeTarget() if is_staff else None,
'django_admin': settings.INVENTREE_ADMIN_URL
if (is_staff and settings.INVENTREE_ADMIN_ENABLED)
else None,
}

return JsonResponse(data)
Expand Down
1 change: 1 addition & 0 deletions src/backend/InvenTree/part/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1886,6 +1886,7 @@ class BomList(BomMixin, DataExportViewMixin, ListCreateDestroyAPIView):
'inherited',
'optional',
'consumable',
'reference',
'validated',
'pricing_min',
'pricing_max',
Expand Down
3 changes: 2 additions & 1 deletion src/frontend/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ export default defineConfig({
command: 'invoke dev.server -a 127.0.0.1:8000',
env: {
INVENTREE_DEBUG: 'True',
INVENTREE_PLUGINS_ENABLED: 'True'
INVENTREE_PLUGINS_ENABLED: 'True',
INVENTREE_ADMIN_URL: 'test-admin'
},
url: 'http://127.0.0.1:8000/api/',
reuseExistingServer: !process.env.CI,
Expand Down
13 changes: 9 additions & 4 deletions src/frontend/src/components/buttons/AdminButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { IconUserStar } from '@tabler/icons-react';
import { useCallback, useMemo } from 'react';

import { ModelType } from '../../enums/ModelType';
import { useServerApiState } from '../../states/ApiState';
import { useLocalState } from '../../states/LocalState';
import { useUserState } from '../../states/UserState';
import { ModelInformationDict } from '../render/ModelType';
Expand All @@ -24,17 +25,21 @@ export type AdminButtonProps = {
*/
export default function AdminButton(props: Readonly<AdminButtonProps>) {
const user = useUserState();
const server = useServerApiState();

const enabled: boolean = useMemo(() => {
// Only users with superuser permission will see this button
if (!user || !user.isLoggedIn() || !user.isSuperuser()) {
return false;
}

// TODO: Check if the server has the admin interface enabled

const modelDef = ModelInformationDict[props.model];

// Check if the server has the admin interface enabled
if (!server.server.django_admin) {
return false;
}

// No admin URL associated with the model
if (!modelDef.admin_url) {
return false;
Expand All @@ -57,8 +62,8 @@ export default function AdminButton(props: Readonly<AdminButtonProps>) {
return;
}

// TODO: Check the actual "admin" URL (it may be custom)
const url = `${host}/admin${modelDef.admin_url}${props.pk}/`;
// Generate the URL for the admin interface
const url = `${host}/${server.server.django_admin}${modelDef.admin_url}${props.pk}/`;

if (event?.ctrlKey || event?.shiftKey) {
// Open the link in a new tab
Expand Down
3 changes: 2 additions & 1 deletion src/frontend/src/components/nav/NotificationDrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { ApiEndpoints } from '../../enums/ApiEndpoints';
import { ModelType } from '../../enums/ModelType';
import { navigateToLink } from '../../functions/navigation';
import { getDetailUrl } from '../../functions/urls';
import { base_url } from '../../main';
import { apiUrl } from '../../states/ApiState';
import { useUserState } from '../../states/UserState';
import { Boundary } from '../Boundary';
Expand Down Expand Up @@ -66,7 +67,7 @@ function NotificationEntry({
>
<Stack gap={2}>
<Anchor
href={link}
href={link ? `/${base_url}${link}` : '#'}
underline="hover"
target="_blank"
onClick={(event: any) => {
Expand Down
3 changes: 2 additions & 1 deletion src/frontend/src/defaults/defaults.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ export const emptyServerAPI = {
platform: null,
installer: null,
target: null,
default_locale: null
default_locale: null,
django_admin: null
};

export interface SiteMarkProps {
Expand Down
11 changes: 6 additions & 5 deletions src/frontend/src/forms/PurchaseOrderForms.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,8 @@ function LineItemFormRow({
if (
!record.destination &&
!record.destination_detail &&
location === record.part_detail.category_default_location
record.part_detail &&
location === record.part_detail?.category_default_location
) {
return t`Part category default location selected`;
}
Expand Down Expand Up @@ -511,17 +512,17 @@ function LineItemFormRow({
}
/>
<Flex style={{ marginBottom: '7px' }}>
{(record.part_detail.default_location ||
record.part_detail.category_default_location) && (
{(record.part_detail?.default_location ||
record.part_detail?.category_default_location) && (
<ActionButton
icon={<InvenTreeIcon icon="default_location" />}
tooltip={t`Store at default location`}
onClick={() =>
props.changeFn(
props.idx,
'location',
record.part_detail.default_location ??
record.part_detail.category_default_location
record.part_detail?.default_location ??
record.part_detail?.category_default_location
)
}
tooltipAlignment="top"
Expand Down
16 changes: 8 additions & 8 deletions src/frontend/src/forms/StockForms.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -325,14 +325,14 @@ function StockItemDefaultMove({
const { data } = useSuspenseQuery({
queryKey: [
'location',
stockItem.part_detail.default_location ??
stockItem.part_detail.category_default_location
stockItem.part_detail?.default_location ??
stockItem.part_detail?.category_default_location
],
queryFn: async () => {
const url = apiUrl(
ApiEndpoints.stock_location_list,
stockItem.part_detail.default_location ??
stockItem.part_detail.category_default_location
stockItem.part_detail?.default_location ??
stockItem.part_detail?.category_default_location
);

return api
Expand Down Expand Up @@ -384,8 +384,8 @@ function moveToDefault(
children: <StockItemDefaultMove stockItem={stockItem} value={value} />,
onConfirm: () => {
if (
stockItem.location === stockItem.part_detail.default_location ||
stockItem.location === stockItem.part_detail.category_default_location
stockItem.location === stockItem.part_detail?.default_location ||
stockItem.location === stockItem.part_detail?.category_default_location
) {
return;
}
Expand All @@ -400,8 +400,8 @@ function moveToDefault(
}
],
location:
stockItem.part_detail.default_location ??
stockItem.part_detail.category_default_location
stockItem.part_detail?.default_location ??
stockItem.part_detail?.category_default_location
})
.then((response) => {
refresh();
Expand Down
15 changes: 10 additions & 5 deletions src/frontend/src/pages/build/BuildDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ export default function BuildDetail() {

const user = useUserState();

const buildStatus = useStatusCodes({ modelType: ModelType.build });

const {
instance: build,
refreshInstance,
Expand Down Expand Up @@ -269,8 +271,10 @@ export default function BuildDetail() {
<BuildOutputTable build={build} refreshBuild={refreshInstance} />
) : (
<Skeleton />
)
// TODO: Hide if build is complete
),
hidden:
build.status == buildStatus.COMPLETE ||
build.status == buildStatus.CANCELLED
},
{
name: 'complete-outputs',
Expand All @@ -291,6 +295,9 @@ export default function BuildDetail() {
name: 'allocated-stock',
label: t`Allocated Stock`,
icon: <IconList />,
hidden:
build.status == buildStatus.COMPLETE ||
build.status == buildStatus.CANCELLED,
content: build.pk ? (
<BuildAllocatedStockTable buildId={build.pk} showPartInfo allowEdit />
) : (
Expand Down Expand Up @@ -355,7 +362,7 @@ export default function BuildDetail() {
model_id: build.pk
})
];
}, [build, id, user]);
}, [build, id, user, buildStatus]);

const buildOrderFields = useBuildOrderFields({ create: false });

Expand All @@ -379,8 +386,6 @@ export default function BuildDetail() {
modelType: ModelType.build
});

const buildStatus = useStatusCodes({ modelType: ModelType.build });

const cancelOrder = useCreateApiFormModal({
url: apiUrl(ApiEndpoints.build_order_cancel, build.pk),
title: t`Cancel Build Order`,
Expand Down
1 change: 1 addition & 0 deletions src/frontend/src/states/states.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export interface ServerAPIProps {
installer: null | string;
target: null | string;
default_locale: null | string;
django_admin: null | string;
}

export interface AuthProps {
Expand Down
3 changes: 3 additions & 0 deletions src/frontend/src/tables/part/PartTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,9 @@ export function PartListTable({
modelType: ModelType.part,
tableFilters: tableFilters,
tableActions: tableActions,
enableSelection: true,
enableReports: true,
enableLabels: true,
params: {
...props.params,
category_detail: true,
Expand Down
4 changes: 2 additions & 2 deletions src/frontend/src/tables/settings/CustomUnitsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,15 @@ export default function CustomUnitsTable() {
let actions = [];

actions.push(
// TODO: Adjust actions based on user permissions
<AddItemButton
tooltip={t`Add custom unit`}
onClick={() => newUnit.open()}
hidden={!user.isStaff() || !user.hasChangeRole(UserRoles.admin)}
/>
);

return actions;
}, []);
}, [user]);

return (
<>
Expand Down
15 changes: 15 additions & 0 deletions src/frontend/tests/pui_general.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,18 @@ test('Company', async ({ page }) => {
await page.getByText('Enter a valid URL.').waitFor();
await page.getByRole('button', { name: 'Cancel' }).click();
});

/**
* Test for integration of django admin button
*/
test('Admin Button', async ({ page }) => {
await doQuickLogin(page, 'admin', 'inventree');
await page.goto(`${baseUrl}/company/1/details`);

// Click on the admin button
await page.getByLabel(/action-button-open-in-admin/).click();

await page.waitForURL('**/test-admin/company/company/1/change/**');
await page.getByRole('heading', { name: 'Change Company' }).waitFor();
await page.getByRole('link', { name: 'View on site' }).waitFor();
});

0 comments on commit 54a321a

Please sign in to comment.