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