mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-28 03:26:45 +00:00
[PUI] Updates for AdminButton (#8434)
* [PUI] Updates for AdminButton - Hide if django admin interface is disabled - Use correct admin URL * Adjust InfoView * Add playwright tests
This commit is contained in:
parent
93a8090e99
commit
245803b0d4
@ -236,6 +236,9 @@ class InfoView(AjaxView):
|
||||
'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)
|
||||
|
@ -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,
|
||||
|
@ -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';
|
||||
@ -24,6 +25,7 @@ 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
|
||||
@ -31,10 +33,13 @@ export default function AdminButton(props: Readonly<AdminButtonProps>) {
|
||||
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;
|
||||
@ -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
|
||||
|
@ -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 {
|
||||
|
@ -47,6 +47,7 @@ export interface ServerAPIProps {
|
||||
installer: null | string;
|
||||
target: null | string;
|
||||
default_locale: null | string;
|
||||
django_admin: null | string;
|
||||
}
|
||||
|
||||
export interface AuthProps {
|
||||
|
@ -110,3 +110,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();
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user