mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-10-30 03:56:23 -05:00 
			
		
		
		
	Refactor to UiSettings
This commit is contained in:
		| @@ -2,8 +2,8 @@ describe('document-detail', () => { | ||||
|   beforeEach(() => { | ||||
|     this.modifiedDocuments = [] | ||||
|  | ||||
|     cy.intercept('http://localhost:8000/api/frontend_settings/', { | ||||
|       fixture: 'frontend_settings/settings.json', | ||||
|     cy.intercept('http://localhost:8000/api/ui_settings/', { | ||||
|       fixture: 'ui_settings/settings.json', | ||||
|     }) | ||||
|     cy.fixture('documents/documents.json').then((documentsJson) => { | ||||
|       cy.intercept('GET', 'http://localhost:8000/api/documents/1/', (req) => { | ||||
|   | ||||
| @@ -3,8 +3,8 @@ describe('documents-list', () => { | ||||
|     this.bulkEdits = {} | ||||
|  | ||||
|     // mock API methods | ||||
|     cy.intercept('http://localhost:8000/api/frontend_settings/', { | ||||
|       fixture: 'frontend_settings/settings.json', | ||||
|     cy.intercept('http://localhost:8000/api/ui_settings/', { | ||||
|       fixture: 'ui_settings/settings.json', | ||||
|     }) | ||||
|     cy.fixture('documents/documents.json').then((documentsJson) => { | ||||
|       // bulk edit | ||||
|   | ||||
| @@ -1,7 +1,7 @@ | ||||
| describe('manage', () => { | ||||
|   beforeEach(() => { | ||||
|     cy.intercept('http://localhost:8000/api/frontend_settings/', { | ||||
|       fixture: 'frontend_settings/settings.json', | ||||
|     cy.intercept('http://localhost:8000/api/ui_settings/', { | ||||
|       fixture: 'ui_settings/settings.json', | ||||
|     }) | ||||
|     cy.intercept('http://localhost:8000/api/correspondents/*', { | ||||
|       fixture: 'correspondents/correspondents.json', | ||||
|   | ||||
| @@ -3,8 +3,8 @@ describe('settings', () => { | ||||
|     this.modifiedViews = [] | ||||
|  | ||||
|     // mock API methods | ||||
|     cy.intercept('http://localhost:8000/api/frontend_settings/', { | ||||
|       fixture: 'frontend_settings/settings.json', | ||||
|     cy.intercept('http://localhost:8000/api/ui_settings/', { | ||||
|       fixture: 'ui_settings/settings.json', | ||||
|     }).then(() => { | ||||
|       cy.fixture('saved_views/savedviews.json').then((savedViewsJson) => { | ||||
|         // saved views PATCH | ||||
|   | ||||
| @@ -144,7 +144,7 @@ const SETTINGS: PaperlessSettings[] = [ | ||||
| }) | ||||
| export class SettingsService { | ||||
|   private renderer: Renderer2 | ||||
|   protected baseUrl: string = environment.apiBaseUrl + 'frontend_settings/' | ||||
|   protected baseUrl: string = environment.apiBaseUrl + 'ui_settings/' | ||||
|  | ||||
|   private settings: Object = {} | ||||
|  | ||||
|   | ||||
| @@ -14,7 +14,7 @@ class Migration(migrations.Migration): | ||||
| 
 | ||||
|     operations = [ | ||||
|         migrations.CreateModel( | ||||
|             name="FrontendSettings", | ||||
|             name="UiSettings", | ||||
|             fields=[ | ||||
|                 ( | ||||
|                     "id", | ||||
| @@ -30,7 +30,7 @@ class Migration(migrations.Migration): | ||||
|                     "user", | ||||
|                     models.OneToOneField( | ||||
|                         on_delete=django.db.models.deletion.CASCADE, | ||||
|                         related_name="frontend_settings", | ||||
|                         related_name="ui_settings", | ||||
|                         to=settings.AUTH_USER_MODEL, | ||||
|                     ), | ||||
|                 ), | ||||
| @@ -470,12 +470,12 @@ class FileInfo: | ||||
|  | ||||
|  | ||||
| # Extending User Model Using a One-To-One Link | ||||
| class FrontendSettings(models.Model): | ||||
| class UiSettings(models.Model): | ||||
|  | ||||
|     user = models.OneToOneField( | ||||
|         User, | ||||
|         on_delete=models.CASCADE, | ||||
|         related_name="frontend_settings", | ||||
|         related_name="ui_settings", | ||||
|     ) | ||||
|     settings = models.JSONField(null=True) | ||||
|  | ||||
| @@ -484,6 +484,6 @@ class FrontendSettings(models.Model): | ||||
|  | ||||
|  | ||||
| @receiver(post_save, sender=User) | ||||
| def create_user_frontend_settings(sender, instance, created, **kwargs): | ||||
| def create_user_ui_settings(sender, instance, created, **kwargs): | ||||
|     if created: | ||||
|         FrontendSettings.objects.create(user=instance) | ||||
|         UiSettings.objects.create(user=instance) | ||||
|   | ||||
| @@ -11,11 +11,11 @@ from . import bulk_edit | ||||
| from .models import Correspondent | ||||
| from .models import Document | ||||
| from .models import DocumentType | ||||
| from .models import FrontendSettings | ||||
| from .models import MatchingModel | ||||
| from .models import SavedView | ||||
| from .models import SavedViewFilterRule | ||||
| from .models import Tag | ||||
| from .models import UiSettings | ||||
| from .parsers import is_mime_type_supported | ||||
|  | ||||
|  | ||||
| @@ -501,9 +501,9 @@ class BulkDownloadSerializer(DocumentListSerializer): | ||||
|         }[compression] | ||||
|  | ||||
|  | ||||
| class FrontendSettingsViewSerializer(serializers.ModelSerializer): | ||||
| class UiSettingsViewSerializer(serializers.ModelSerializer): | ||||
|     class Meta: | ||||
|         model = FrontendSettings | ||||
|         model = UiSettings | ||||
|         depth = 1 | ||||
|         fields = [ | ||||
|             "id", | ||||
| @@ -511,12 +511,12 @@ class FrontendSettingsViewSerializer(serializers.ModelSerializer): | ||||
|         ] | ||||
|  | ||||
|     def update(self, instance, validated_data): | ||||
|         super(FrontendSettingsViewSerializer, self).update(instance, validated_data) | ||||
|         super(UiSettingsViewSerializer, self).update(instance, validated_data) | ||||
|         return instance | ||||
|  | ||||
|     def create(self, validated_data): | ||||
|         frontend_settings = FrontendSettings.objects.update_or_create( | ||||
|         ui_settings = UiSettings.objects.update_or_create( | ||||
|             user=validated_data.get("user"), | ||||
|             defaults={"settings": validated_data.get("settings", None)}, | ||||
|         ) | ||||
|         return frontend_settings | ||||
|         return ui_settings | ||||
|   | ||||
| @@ -71,11 +71,11 @@ from .serialisers import CorrespondentSerializer | ||||
| from .serialisers import DocumentListSerializer | ||||
| from .serialisers import DocumentSerializer | ||||
| from .serialisers import DocumentTypeSerializer | ||||
| from .serialisers import FrontendSettingsViewSerializer | ||||
| from .serialisers import PostDocumentSerializer | ||||
| from .serialisers import SavedViewSerializer | ||||
| from .serialisers import TagSerializer | ||||
| from .serialisers import TagSerializerVersion1 | ||||
| from .serialisers import UiSettingsViewSerializer | ||||
|  | ||||
| logger = logging.getLogger("paperless.api") | ||||
|  | ||||
| @@ -719,10 +719,10 @@ class RemoteVersionView(GenericAPIView): | ||||
|         ) | ||||
|  | ||||
|  | ||||
| class FrontendSettingsView(GenericAPIView): | ||||
| class UiSettingsView(GenericAPIView): | ||||
|  | ||||
|     permission_classes = (IsAuthenticated,) | ||||
|     serializer_class = FrontendSettingsViewSerializer | ||||
|     serializer_class = UiSettingsViewSerializer | ||||
|  | ||||
|     def get(self, request, format=None): | ||||
|         serializer = self.get_serializer(data=request.data) | ||||
| @@ -730,8 +730,8 @@ class FrontendSettingsView(GenericAPIView): | ||||
|  | ||||
|         user = User.objects.get(pk=request.user.id) | ||||
|         settings = [] | ||||
|         if hasattr(user, "frontend_settings"): | ||||
|             settings = user.frontend_settings.settings | ||||
|         if hasattr(user, "ui_settings"): | ||||
|             settings = user.ui_settings.settings | ||||
|         return Response( | ||||
|             { | ||||
|                 "user_id": user.id, | ||||
|   | ||||
| @@ -11,7 +11,6 @@ from documents.views import BulkDownloadView | ||||
| from documents.views import BulkEditView | ||||
| from documents.views import CorrespondentViewSet | ||||
| from documents.views import DocumentTypeViewSet | ||||
| from documents.views import FrontendSettingsView | ||||
| from documents.views import IndexView | ||||
| from documents.views import LogViewSet | ||||
| from documents.views import PostDocumentView | ||||
| @@ -21,6 +20,7 @@ from documents.views import SearchAutoCompleteView | ||||
| from documents.views import SelectionDataView | ||||
| from documents.views import StatisticsView | ||||
| from documents.views import TagViewSet | ||||
| from documents.views import UiSettingsView | ||||
| from documents.views import UnifiedSearchViewSet | ||||
| from paperless.consumers import StatusConsumer | ||||
| from paperless.views import FaviconView | ||||
| @@ -80,9 +80,9 @@ urlpatterns = [ | ||||
|                     name="remoteversion", | ||||
|                 ), | ||||
|                 re_path( | ||||
|                     r"^frontend_settings/", | ||||
|                     FrontendSettingsView.as_view(), | ||||
|                     name="frontend_settings", | ||||
|                     r"^ui_settings/", | ||||
|                     UiSettingsView.as_view(), | ||||
|                     name="ui_settings", | ||||
|                 ), | ||||
|                 path("token/", views.obtain_auth_token), | ||||
|             ] | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Michael Shamoon
					Michael Shamoon