2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-17 20:45:44 +00:00

remove ui preference - there is no decision anymore

This commit is contained in:
Matthias Mair
2025-01-08 20:07:28 +01:00
parent 1191d1cd82
commit f84ce83e8f
4 changed files with 1 additions and 92 deletions

View File

@ -25,7 +25,6 @@ import report.api
import stock.api import stock.api
import users.api import users.api
from plugin.urls import get_plugin_urls from plugin.urls import get_plugin_urls
from web.urls import api_urls as web_api_urls
from web.urls import urlpatterns as platform_urls from web.urls import urlpatterns as platform_urls
from .api import ( from .api import (
@ -73,7 +72,6 @@ apipatterns = [
]), ]),
), ),
path('user/', include(users.api.user_urls)), path('user/', include(users.api.user_urls)),
path('web/', include(web_api_urls)),
# Plugin endpoints # Plugin endpoints
path('', include(plugin.api.plugin_api_urls)), path('', include(plugin.api.plugin_api_urls)),
# Common endpoints endpoint # Common endpoints endpoint

View File

@ -96,11 +96,6 @@ class UserAPITests(InvenTreeAPITestCase):
def test_login_redirect(self): def test_login_redirect(self):
"""Test login redirect endpoint.""" """Test login redirect endpoint."""
response = self.get(reverse('api-login-redirect'), expected_code=302) response = self.get(reverse('api-login-redirect'), expected_code=302)
self.assertEqual(response.url, '/index/')
# PUI
self.put(reverse('api-ui-preference'), {'preferred_method': 'pui'})
response = self.get(reverse('api-login-redirect'), expected_code=302)
self.assertEqual(response.url, '/platform/logged-in/') self.assertEqual(response.url, '/platform/logged-in/')

View File

@ -5,10 +5,8 @@ import os
from pathlib import Path from pathlib import Path
from unittest import mock from unittest import mock
from django.urls import reverse
from InvenTree.config import get_frontend_settings from InvenTree.config import get_frontend_settings
from InvenTree.unit_test import InvenTreeAPITestCase, InvenTreeTestCase from InvenTree.unit_test import InvenTreeTestCase
from .templatetags import spa_helper from .templatetags import spa_helper
@ -92,26 +90,3 @@ class TemplateTagTest(InvenTreeTestCase):
"""Test the redirect helper.""" """Test the redirect helper."""
response = self.client.get('/assets/testpath') response = self.client.get('/assets/testpath')
self.assertEqual(response.url, '/static/web/assets/testpath') self.assertEqual(response.url, '/static/web/assets/testpath')
class TestWebHelpers(InvenTreeAPITestCase):
"""Tests for the web helpers."""
def test_ui_preference(self):
"""Test the UI preference API."""
url = reverse('api-ui-preference')
# Test default
resp = self.get(url)
data = json.loads(resp.content)
self.assertTrue(data['cui'])
self.assertFalse(data['pui'])
self.assertEqual(data['preferred_method'], 'cui')
# Set to PUI
resp = self.put(url, {'preferred_method': 'pui'})
data = json.loads(resp.content)
self.assertEqual(resp.status_code, 200)
self.assertFalse(data['cui'])
self.assertTrue(data['pui'])
self.assertEqual(data['preferred_method'], 'pui')

View File

@ -1,16 +1,11 @@
"""URLs for web app.""" """URLs for web app."""
from django.conf import settings from django.conf import settings
from django.http import JsonResponse
from django.shortcuts import redirect from django.shortcuts import redirect
from django.urls import include, path, re_path from django.urls import include, path, re_path
from django.views.decorators.csrf import ensure_csrf_cookie from django.views.decorators.csrf import ensure_csrf_cookie
from django.views.generic import TemplateView from django.views.generic import TemplateView
from rest_framework import permissions, serializers
from InvenTree.mixins import RetrieveUpdateAPI
class RedirectAssetView(TemplateView): class RedirectAssetView(TemplateView):
"""View to redirect to static asset.""" """View to redirect to static asset."""
@ -22,55 +17,6 @@ class RedirectAssetView(TemplateView):
) )
class PreferredSerializer(serializers.Serializer):
"""Serializer for the preferred serializer session setting."""
preferred_method = serializers.ChoiceField(choices=['cui', 'pui'])
pui = serializers.SerializerMethodField(read_only=True)
cui = serializers.SerializerMethodField(read_only=True)
def get_pui(self, obj) -> bool:
"""Return true if preferred method is PUI."""
return obj['preferred_method'] == 'pui'
def get_cui(self, obj) -> bool:
"""Return true if preferred method is CUI."""
return obj['preferred_method'] == 'cui'
class Meta:
"""Meta class for PreferedSerializer."""
fields = '__all__'
class PreferredUiView(RetrieveUpdateAPI):
"""Set preferred UI (CIU/PUI)."""
permission_classes = [permissions.AllowAny]
serializer_class = PreferredSerializer
http_method_names = ['get', 'post', 'put', 'head', 'options']
def retrieve(self, request, *args, **kwargs):
"""Retrieve the preferred UI method."""
session = self.request.session
session['preferred_method'] = session.get('preferred_method', 'cui')
serializer = self.get_serializer(data=dict(session))
serializer.is_valid(raise_exception=True)
return JsonResponse(serializer.data)
def update(self, request, *args, **kwargs):
"""Update the preferred UI method."""
serializer = self.get_serializer(data=self.clean_data(request.data))
serializer.is_valid(raise_exception=True)
# Run update
session = self.request.session
session['preferred_method'] = serializer.validated_data['preferred_method']
session.modified = True
return JsonResponse(serializer.data)
spa_view = ensure_csrf_cookie(TemplateView.as_view(template_name='web/index.html')) spa_view = ensure_csrf_cookie(TemplateView.as_view(template_name='web/index.html'))
assets_path = path('assets/<path:path>', RedirectAssetView.as_view()) assets_path = path('assets/<path:path>', RedirectAssetView.as_view())
@ -91,8 +37,3 @@ urlpatterns = [
assets_path, assets_path,
path(settings.FRONTEND_URL_BASE, spa_view, name='platform'), path(settings.FRONTEND_URL_BASE, spa_view, name='platform'),
] ]
api_urls = [
# UI Preference
path('ui_preference/', PreferredUiView.as_view(), name='api-ui-preference')
]