Allow enable/disable update checking (and release notes) in the dialog

This commit is contained in:
shamoon committed 2026-11-18 14:20:10 -08:00
1 parent b1cb8a8365
commit e81ac3799b
5 files changed
+111 -12

No files matched your search

@@ -741,6 +741,19 @@ describe('AppFrameComponent', () => {
httpTestingController.expectNone(`${environment.apiBaseUrl}ui_settings/`)
})
it('should save update checking chosen in the release notes dialog', () => {
const setUpdateCheckingSpy = jest
.spyOn(component, 'setUpdateChecking')
.mockImplementation(() => {})
const modalSpy = jest.spyOn(modalService, 'open')
component.showReleaseNotes()
const dialog = modalSpy.mock.results[0].value
.componentInstance as ReleaseNotesDialogComponent
dialog.updateCheckingChosen.emit(true)
expect(setUpdateCheckingSpy).toHaveBeenCalledWith(true)
})
it('should show new release dot instead of documentation in slim sidebar', () => {
settingsService.set(SETTINGS_KEYS.SLIM_SIDEBAR, true)
settingsService.set(SETTINGS_KEYS.VERSION, '3.5.1')
@@ -559,6 +559,9 @@ export class AppFrameComponent
scrollable: true,
})
modal.componentInstance.load(since)
modal.componentInstance.updateCheckingChosen.subscribe((enable: boolean) =>
this.setUpdateChecking(enable)
)
if (since) {
this.settingsService
.markReleasesSeen()
@@ -22,9 +22,17 @@
</div>
</div>
<div class="modal-body">
@if (!updateCheckingEnabled) {
<p class="mb-0" i18n>Release notes are fetched from GitHub when update checking is enabled.</p>
<ng-container *ngTemplateOutlet="githubLink"></ng-container>
@if (!updateCheckingEnabled()) {
@if (!updateCheckingIsSet() && canChangeUpdateChecking) {
<p class="mb-2" i18n>Paperless-ngx can automatically check for updates and show release notes here, fetched from GitHub.</p>
<div class="btn-group btn-group-sm">
<button type="button" class="btn btn-outline-primary" (click)="setUpdateChecking(true)" i18n>Enable</button>
<button type="button" class="btn btn-outline-secondary" (click)="setUpdateChecking(false)" i18n>Disable</button>
</div>
} @else {
<p class="mb-0" i18n>Release notes are fetched from GitHub when update checking is enabled.</p>
<ng-container *ngTemplateOutlet="githubLink"></ng-container>
}
} @else if (loading()) {
<div class="d-flex align-items-center gap-2 text-muted">
<output class="spinner-border spinner-border-sm"></output>
@@ -7,6 +7,7 @@ import {
import { ComponentFixture, TestBed } from '@angular/core/testing'
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap'
import { SETTINGS_KEYS } from 'src/app/data/ui-settings'
import { PermissionsService } from 'src/app/services/permissions.service'
import { SettingsService } from 'src/app/services/settings.service'
import { environment } from 'src/environments/environment'
import {
@@ -20,13 +21,18 @@ describe('ReleaseNotesDialogComponent', () => {
let httpTestingController: HttpTestingController
let settingsService: SettingsService
function create(updateCheckingEnabled: boolean) {
function create(updateCheckingEnabled?: boolean, canChangeSettings = true) {
settingsService = TestBed.inject(SettingsService)
settingsService.set(SETTINGS_KEYS.VERSION, '3.5.1')
settingsService.set(
SETTINGS_KEYS.UPDATE_CHECKING_ENABLED,
updateCheckingEnabled
)
if (updateCheckingEnabled !== undefined) {
settingsService.set(
SETTINGS_KEYS.UPDATE_CHECKING_ENABLED,
updateCheckingEnabled
)
}
jest
.spyOn(TestBed.inject(PermissionsService), 'currentUserCan')
.mockReturnValue(canChangeSettings)
fixture = TestBed.createComponent(ReleaseNotesDialogComponent)
component = fixture.componentInstance
}
@@ -122,6 +128,53 @@ describe('ReleaseNotesDialogComponent', () => {
)
})
it('should offer to enable update checking if never chosen', () => {
create()
const chosen = jest.fn()
component.updateCheckingChosen.subscribe(chosen)
component.load('3.4.2')
fixture.detectChanges()
const enable = Array.from(
fixture.nativeElement.querySelectorAll('.modal-body button')
).find((b: HTMLButtonElement) => b.textContent.trim() === 'Enable') as
HTMLButtonElement | undefined
expect(enable).toBeTruthy()
httpTestingController.expectNone(`${environment.apiBaseUrl}release_notes/`)
enable.click()
expect(chosen).toHaveBeenCalledWith(true)
httpTestingController
.expectOne(`${environment.apiBaseUrl}release_notes/?since=3.4.2`)
.flush({ version: '3.5.1', releases: [] })
})
it('should show the disabled message after choosing disable', () => {
create()
const chosen = jest.fn()
component.updateCheckingChosen.subscribe(chosen)
component.load(null)
component.setUpdateChecking(false)
fixture.detectChanges()
expect(chosen).toHaveBeenCalledWith(false)
httpTestingController.expectNone(`${environment.apiBaseUrl}release_notes/`)
expect(fixture.nativeElement.textContent).toContain(
'when update checking is enabled'
)
})
it('should not offer to enable update checking without permission', () => {
create(undefined, false)
component.load(null)
fixture.detectChanges()
expect(fixture.nativeElement.textContent).not.toContain('Enable')
expect(fixture.nativeElement.textContent).toContain(
'when update checking is enabled'
)
})
it('should support close', () => {
create(false)
const closeSpy = jest.spyOn(component.activeModal, 'close')
@@ -1,10 +1,15 @@
import { DecimalPipe, NgTemplateOutlet } from '@angular/common'
import { Component, inject, signal } from '@angular/core'
import { Component, inject, output, signal } from '@angular/core'
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap'
import { first } from 'rxjs'
import { BootstrapIconComponent } from 'src/app/components/common/bootstrap-icon/bootstrap-icon.component'
import { SETTINGS_KEYS } from 'src/app/data/ui-settings'
import { CustomDatePipe } from 'src/app/pipes/custom-date.pipe'
import {
PermissionAction,
PermissionsService,
PermissionType,
} from 'src/app/services/permissions.service'
import {
AppRelease,
RemoteVersionService,
@@ -49,6 +54,7 @@ export class ReleaseNotesDialogComponent {
readonly activeModal = inject(NgbActiveModal)
private readonly remoteVersionService = inject(RemoteVersionService)
private readonly settingsService = inject(SettingsService)
private readonly permissionsService = inject(PermissionsService)
readonly since = signal<string | null>(null)
readonly releases = signal<AppRelease[] | null>(null)
@@ -56,9 +62,18 @@ export class ReleaseNotesDialogComponent {
readonly loading = signal(false)
readonly version: string = this.settingsService.get(SETTINGS_KEYS.VERSION)
readonly updateCheckingEnabled: boolean = this.settingsService.get(
SETTINGS_KEYS.UPDATE_CHECKING_ENABLED
readonly updateCheckingEnabled = signal<boolean>(
this.settingsService.get(SETTINGS_KEYS.UPDATE_CHECKING_ENABLED)
)
readonly updateCheckingIsSet = signal(
this.settingsService.updateCheckingIsSet
)
readonly canChangeUpdateChecking = this.permissionsService.currentUserCan(
PermissionAction.Change,
PermissionType.UISettings
)
readonly updateCheckingChosen = output<boolean>()
readonly repoUrl = REPO_URL
readonly releasesUrl = RELEASES_URL
@@ -74,7 +89,7 @@ export class ReleaseNotesDialogComponent {
*/
load(since: string | null): void {
this.since.set(since)
if (!this.updateCheckingEnabled) return
if (!this.updateCheckingEnabled()) return
this.loading.set(true)
this.remoteVersionService
.getReleaseNotes(since ?? undefined)
@@ -97,6 +112,13 @@ export class ReleaseNotesDialogComponent {
})
}
setUpdateChecking(enable: boolean): void {
this.updateCheckingIsSet.set(true)
this.updateCheckingEnabled.set(enable)
this.updateCheckingChosen.emit(enable)
if (enable) this.load(this.since())
}
close(): void {
this.activeModal.close()
}