mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-10-30 03:56:23 -05:00 
			
		
		
		
	Better migration of update checking settings, offer reload, strip backend_setting from db
This commit is contained in:
		| @@ -1,4 +1,4 @@ | |||||||
| import { Component, HostListener } from '@angular/core' | import { Component, HostListener, OnInit } from '@angular/core' | ||||||
| import { FormControl } from '@angular/forms' | import { FormControl } from '@angular/forms' | ||||||
| import { ActivatedRoute, Router } from '@angular/router' | import { ActivatedRoute, Router } from '@angular/router' | ||||||
| import { from, Observable } from 'rxjs' | import { from, Observable } from 'rxjs' | ||||||
| @@ -32,7 +32,7 @@ import { ToastService } from 'src/app/services/toast.service' | |||||||
|   templateUrl: './app-frame.component.html', |   templateUrl: './app-frame.component.html', | ||||||
|   styleUrls: ['./app-frame.component.scss'], |   styleUrls: ['./app-frame.component.scss'], | ||||||
| }) | }) | ||||||
| export class AppFrameComponent implements ComponentCanDeactivate { | export class AppFrameComponent implements OnInit, ComponentCanDeactivate { | ||||||
|   constructor( |   constructor( | ||||||
|     public router: Router, |     public router: Router, | ||||||
|     private activatedRoute: ActivatedRoute, |     private activatedRoute: ActivatedRoute, | ||||||
| @@ -44,11 +44,13 @@ export class AppFrameComponent implements ComponentCanDeactivate { | |||||||
|     public settingsService: SettingsService, |     public settingsService: SettingsService, | ||||||
|     public tasksService: TasksService, |     public tasksService: TasksService, | ||||||
|     private readonly toastService: ToastService |     private readonly toastService: ToastService | ||||||
|   ) { |   ) {} | ||||||
|     if (settingsService.updateCheckingEnabled) { |  | ||||||
|  |   ngOnInit(): void { | ||||||
|  |     if (this.settingsService.get(SETTINGS_KEYS.UPDATE_CHECKING_ENABLED)) { | ||||||
|       this.checkForUpdates() |       this.checkForUpdates() | ||||||
|     } |     } | ||||||
|     tasksService.reload() |     this.tasksService.reload() | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   versionString = `${environment.appTitle} ${environment.version}` |   versionString = `${environment.appTitle} ${environment.version}` | ||||||
|   | |||||||
| @@ -209,5 +209,5 @@ | |||||||
|  |  | ||||||
|   <div [ngbNavOutlet]="nav" class="border-start border-end border-bottom p-3 mb-3 shadow-sm"></div> |   <div [ngbNavOutlet]="nav" class="border-start border-end border-bottom p-3 mb-3 shadow-sm"></div> | ||||||
|  |  | ||||||
|   <button type="submit" class="btn btn-primary" [disabled]="!(isDirty$ | async)" i18n>Save</button> |   <button type="submit" class="btn btn-primary mb-2" [disabled]="!(isDirty$ | async)" i18n>Save</button> | ||||||
| </form> | </form> | ||||||
|   | |||||||
| @@ -67,13 +67,6 @@ export class SettingsComponent | |||||||
|     ) |     ) | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   get displayLanguageIsDirty(): boolean { |  | ||||||
|     return ( |  | ||||||
|       this.settingsForm.get('displayLanguage').value != |  | ||||||
|       this.store?.getValue()['displayLanguage'] |  | ||||||
|     ) |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   constructor( |   constructor( | ||||||
|     public savedViewService: SavedViewService, |     public savedViewService: SavedViewService, | ||||||
|     private documentListViewService: DocumentListViewService, |     private documentListViewService: DocumentListViewService, | ||||||
| @@ -197,7 +190,13 @@ export class SettingsComponent | |||||||
|   } |   } | ||||||
|  |  | ||||||
|   private saveLocalSettings() { |   private saveLocalSettings() { | ||||||
|     const reloadRequired = this.displayLanguageIsDirty // just this one, for now |     const reloadRequired = | ||||||
|  |       this.settingsForm.value.displayLanguage != | ||||||
|  |         this.store?.getValue()['displayLanguage'] || // displayLanguage is dirty | ||||||
|  |       (this.settingsForm.value.updateCheckingEnabled != | ||||||
|  |         this.store?.getValue()['updateCheckingEnabled'] && | ||||||
|  |         this.settingsForm.value.updateCheckingEnabled) // update checking was turned on | ||||||
|  |  | ||||||
|     this.settings.set( |     this.settings.set( | ||||||
|       SETTINGS_KEYS.BULK_EDIT_APPLY_ON_CLOSE, |       SETTINGS_KEYS.BULK_EDIT_APPLY_ON_CLOSE, | ||||||
|       this.settingsForm.value.bulkEditApplyOnClose |       this.settingsForm.value.bulkEditApplyOnClose | ||||||
|   | |||||||
| @@ -410,30 +410,31 @@ export class SettingsService { | |||||||
|           }, |           }, | ||||||
|         }) |         }) | ||||||
|     } |     } | ||||||
|   } |  | ||||||
|  |  | ||||||
|   get updateCheckingEnabled(): boolean { |  | ||||||
|     const backendSetting = this.get( |  | ||||||
|       SETTINGS_KEYS.UPDATE_CHECKING_BACKEND_SETTING |  | ||||||
|     ) |  | ||||||
|  |  | ||||||
|     if ( |     if ( | ||||||
|       !this.settingIsSet(SETTINGS_KEYS.UPDATE_CHECKING_ENABLED) && |       !this.settingIsSet(SETTINGS_KEYS.UPDATE_CHECKING_ENABLED) && | ||||||
|       backendSetting != 'default' |       this.get(SETTINGS_KEYS.UPDATE_CHECKING_BACKEND_SETTING) != 'default' | ||||||
|     ) { |     ) { | ||||||
|       this.set(SETTINGS_KEYS.UPDATE_CHECKING_ENABLED, backendSetting === 'true') |       this.set( | ||||||
|     } |         SETTINGS_KEYS.UPDATE_CHECKING_ENABLED, | ||||||
|     return ( |         this.get(SETTINGS_KEYS.UPDATE_CHECKING_BACKEND_SETTING).toString() === | ||||||
|       this.get(SETTINGS_KEYS.UPDATE_CHECKING_ENABLED) || |           'true' | ||||||
|       (!this.settingIsSet(SETTINGS_KEYS.UPDATE_CHECKING_ENABLED) && |  | ||||||
|         backendSetting == 'true') |  | ||||||
|       ) |       ) | ||||||
|  |  | ||||||
|  |       this.storeSettings() | ||||||
|  |         .pipe(first()) | ||||||
|  |         .subscribe({ | ||||||
|  |           error: (e) => { | ||||||
|  |             this.toastService.showError( | ||||||
|  |               'Error migrating update checking setting' | ||||||
|  |             ) | ||||||
|  |             console.log(e) | ||||||
|  |           }, | ||||||
|  |         }) | ||||||
|  |     } | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   get updateCheckingIsSet(): boolean { |   get updateCheckingIsSet(): boolean { | ||||||
|     return ( |     return this.settingIsSet(SETTINGS_KEYS.UPDATE_CHECKING_ENABLED) | ||||||
|       this.settingIsSet(SETTINGS_KEYS.UPDATE_CHECKING_ENABLED) || |  | ||||||
|       this.get(SETTINGS_KEYS.UPDATE_CHECKING_BACKEND_SETTING) != 'default' |  | ||||||
|     ) |  | ||||||
|   } |   } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -608,6 +608,15 @@ class UiSettingsViewSerializer(serializers.ModelSerializer): | |||||||
|             "settings", |             "settings", | ||||||
|         ] |         ] | ||||||
|  |  | ||||||
|  |     def validate_settings(self, settings): | ||||||
|  |         # we never save update checking backend setting | ||||||
|  |         if "update_checking" in settings: | ||||||
|  |             try: | ||||||
|  |                 settings["update_checking"].pop("backend_setting") | ||||||
|  |             except KeyError: | ||||||
|  |                 pass | ||||||
|  |         return settings | ||||||
|  |  | ||||||
|     def create(self, validated_data): |     def create(self, validated_data): | ||||||
|         ui_settings = UiSettings.objects.update_or_create( |         ui_settings = UiSettings.objects.update_or_create( | ||||||
|             user=validated_data.get("user"), |             user=validated_data.get("user"), | ||||||
|   | |||||||
| @@ -847,7 +847,7 @@ class UiSettingsView(GenericAPIView): | |||||||
|         ui_settings = {} |         ui_settings = {} | ||||||
|         if hasattr(user, "ui_settings"): |         if hasattr(user, "ui_settings"): | ||||||
|             ui_settings = user.ui_settings.settings |             ui_settings = user.ui_settings.settings | ||||||
|         if ui_settings["update_checking"]: |         if "update_checking" in ui_settings: | ||||||
|             ui_settings["update_checking"][ |             ui_settings["update_checking"][ | ||||||
|                 "backend_setting" |                 "backend_setting" | ||||||
|             ] = settings.ENABLE_UPDATE_CHECK |             ] = settings.ENABLE_UPDATE_CHECK | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Michael Shamoon
					Michael Shamoon