mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-11-22 04:25:32 +00:00
Compare commits
53
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c04cd35a1b | ||
|
|
e9c267bc19 | ||
|
|
c6d75ea118 | ||
|
|
f8a7a3ba01 | ||
|
|
ec1cdf9855 | ||
|
|
b6a85dcb13 | ||
|
|
db60bf5ee8 | ||
|
|
393efcfd65 | ||
|
|
f01c889806 | ||
|
|
fea6ccdcad | ||
|
|
a547636e5e | ||
|
|
ef039e092a | ||
|
|
89fbbd8ba6 | ||
|
|
e81ac3799b | ||
|
|
b1cb8a8365 | ||
|
|
423e63b3d0 | ||
|
|
bd67bbea29 | ||
|
|
031d565d0e | ||
|
|
657dd5365f | ||
|
|
2e515ae4f8 | ||
|
|
1a2ab96ddc | ||
|
|
ad6ea30d0d | ||
|
|
df30b75c61 | ||
|
|
0fc148d755 | ||
|
|
a5aa92519b | ||
|
|
6cffa8cb91 | ||
|
|
908a4d6217 | ||
|
|
4da1f36403 | ||
|
|
06a6c2887c | ||
|
|
5fae2c240f | ||
|
|
f3ee22c548 | ||
|
|
0d2625e4ac | ||
|
|
1ac12b9fa4 | ||
|
|
7af74a9746 | ||
|
|
f482fd6c3c | ||
|
|
084a3b1cb8 | ||
|
|
a1a2eb5b36 | ||
|
|
fb4e644df7 | ||
|
|
1356da49ae | ||
|
|
ef1a0f0166 | ||
|
|
da5d1780d9 | ||
|
|
a127ecd35d | ||
|
|
068fc4b8bc | ||
|
|
e7a4367540 | ||
|
|
9f57da5193 | ||
|
|
c091766a86 | ||
|
|
ffe042e5ba | ||
|
|
7f10b918ae | ||
|
|
c944aaedd3 | ||
|
|
45dac15aef | ||
|
|
d6c18ac04d | ||
|
|
3921311901 | ||
|
|
3dc86ba484 |
No files matched your search
@@ -361,8 +361,9 @@
|
||||
</a>
|
||||
</li>
|
||||
}
|
||||
<li class="nav-item mt-2 position-relative" [class.d-none]="settingsService.sidebarItemIsHidden(HideableSidebarItemID.Documentation) && !settingsService.organizingSidebarItems()" tourAnchor="tour.outro">
|
||||
<a class="text-muted small d-flex align-items-center flex-wrap text-decoration-none nav-anchor" [class.opacity-50]="settingsService.sidebarItemIsHidden(HideableSidebarItemID.Documentation)" [class.pe-5]="settingsService.organizingSidebarItems() && !slimSidebarEnabled && !slimSidebarAnimating()"
|
||||
<li class="nav-item mt-2 position-relative" [class.d-none]="settingsService.sidebarItemIsHidden(HideableSidebarItemID.Documentation) && !settingsService.organizingSidebarItems()"
|
||||
[class.d-md-block]="slimSidebarEnabled && settingsService.unseenReleasesSince()" tourAnchor="tour.outro">
|
||||
<a class="text-muted small d-flex align-items-center flex-wrap text-decoration-none nav-anchor" [class.d-md-none]="slimSidebarEnabled && settingsService.unseenReleasesSince()" [class.opacity-50]="settingsService.sidebarItemIsHidden(HideableSidebarItemID.Documentation)" [class.pe-5]="settingsService.organizingSidebarItems() && !slimSidebarEnabled && !slimSidebarAnimating()"
|
||||
target="_blank" rel="noopener noreferrer" href="https://docs.paperless-ngx.com" ngbPopover="Documentation"
|
||||
i18n-ngbPopover [disablePopover]="!slimSidebarPopoversEnabled" placement="end" container="body"
|
||||
triggers="mouseenter:mouseleave" popoverClass="popover-slim">
|
||||
@@ -371,23 +372,35 @@
|
||||
@if (settingsService.organizingSidebarItems()) {
|
||||
<pngx-input-switch class="position-absolute top-50 end-0 translate-middle-y me-1" [class.d-none]="slimSidebarEnabled || slimSidebarAnimating()" [compact]="true" title="Documentation" i18n-title [ngModel]="!settingsService.sidebarItemIsHidden(HideableSidebarItemID.Documentation)" (ngModelChange)="toggleSidebarItem(HideableSidebarItemID.Documentation, $event)"></pngx-input-switch>
|
||||
}
|
||||
@if (slimSidebarEnabled && settingsService.unseenReleasesSince()) {
|
||||
<button type="button" class="btn btn-link border-0 w-100 text-muted small d-none d-md-flex align-items-center nav-anchor position-relative" (click)="showReleaseNotes()"
|
||||
aria-label="See what's new in this version" i18n-aria-label
|
||||
ngbPopover="What's new" i18n-ngbPopover placement="end" container="body"
|
||||
triggers="mouseenter:mouseleave" popoverClass="popover-slim">
|
||||
<pngx-bs-icon class="d-flex" name="info-circle"></pngx-bs-icon>
|
||||
<div class="position-absolute top-0 start-50 ms-1 p-1 bg-success rounded-circle"></div>
|
||||
</button>
|
||||
}
|
||||
</li>
|
||||
<li class="nav-item" [class.visually-hidden]="slimSidebarEnabled">
|
||||
<div class="text-muted small d-flex align-items-center flex-wrap nav-label">
|
||||
<div class="me-2">
|
||||
<a class="text-muted text-decoration-none" target="_blank" rel="noopener noreferrer"
|
||||
href="https://github.com/paperless-ngx/paperless-ngx" ngbPopover="GitHub" i18n-ngbPopover
|
||||
[disablePopover]="!slimSidebarPopoversEnabled" placement="end" container="body"
|
||||
triggers="mouseenter:mouseleave" popoverClass="popover-slim">
|
||||
<button type="button" class="bg-transparent border-0 p-0 text-muted" (click)="showReleaseNotes()" title="See what's new in this version" i18n-title>
|
||||
{{ versionString }}
|
||||
</a>
|
||||
</button>
|
||||
@if (settingsService.unseenReleasesSince()) {
|
||||
<div class="btn-group ms-2 align-baseline">
|
||||
<button type="button" class="btn btn-whats-new rounded-start-pill smaller py-1 px-2 fw-bold lh-sm" (click)="showReleaseNotes()"
|
||||
title="See what's new in this version" i18n-title i18n>New</button>
|
||||
<button type="button" class="btn btn-whats-new rounded-end-pill smaller py-1 px-1 lh-sm d-flex align-items-center" (click)="dismissReleaseNotes()"
|
||||
title="Dismiss" i18n-title aria-label="Dismiss" i18n-aria-label>
|
||||
<pngx-bs-icon name="x" class="d-flex" width="1em" height="1em"></pngx-bs-icon>
|
||||
</button>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
@if (!settingsService.updateCheckingIsSet || appRemoteVersion()) {
|
||||
<div class="version-check d-flex align-items-center">
|
||||
<ng-template #updateAvailablePopContent>
|
||||
<span class="small">Paperless-ngx {{ appRemoteVersion().version }} <ng-container i18n>is
|
||||
available.</ng-container><br /><ng-container i18n>Click to view.</ng-container></span>
|
||||
</ng-template>
|
||||
<ng-template #updateCheckingNotEnabledPopContent>
|
||||
<p class="small mb-2">
|
||||
<ng-container i18n>Paperless-ngx can automatically check for updates</ng-container>
|
||||
@@ -404,15 +417,13 @@
|
||||
</ng-template>
|
||||
@if (settingsService.updateCheckingIsSet) {
|
||||
@if (appRemoteVersion().update_available) {
|
||||
<a class="small text-decoration-none" target="_blank" rel="noopener noreferrer"
|
||||
href="https://github.com/paperless-ngx/paperless-ngx/releases"
|
||||
[ngbPopover]="updateAvailablePopContent" popoverClass="shadow" triggers="mouseenter:mouseleave"
|
||||
container="body">
|
||||
<button type="button" class="bg-transparent border-0 p-0 small text-primary" (click)="showAvailableReleaseNotes()"
|
||||
title="Paperless-ngx {{ appRemoteVersion().version }} is available" i18n-title>
|
||||
<pngx-bs-icon width="1.2em" height="1.2em" name="info-circle" class="me-1"></pngx-bs-icon>
|
||||
@if (appRemoteVersion()?.update_available) {
|
||||
<ng-container i18n>Update available</ng-container>
|
||||
}
|
||||
</a>
|
||||
</button>
|
||||
}
|
||||
} @else {
|
||||
<a *pngxIfPermissions="{ action: PermissionAction.Change, type: PermissionType.UISettings }" class="small text-decoration-none" routerLink="/settings" fragment="update-checking" aria-label="Configure update checking" i18n-aria-label
|
||||
|
||||
@@ -700,3 +700,15 @@ main {
|
||||
.smaller {
|
||||
font-size: 0.75rem;
|
||||
}
|
||||
|
||||
// From active / hover of sidebar nav links
|
||||
.btn-whats-new {
|
||||
--bs-btn-color: var(--bs-primary);
|
||||
--bs-btn-bg: color-mix(in srgb, var(--bs-primary) 13%, transparent);
|
||||
--bs-btn-border-width: 0;
|
||||
--bs-btn-font-weight: 600;
|
||||
--bs-btn-hover-color: var(--bs-primary);
|
||||
--bs-btn-hover-bg: color-mix(in srgb, var(--bs-primary) 20%, transparent);
|
||||
--bs-btn-active-color: var(--bs-primary);
|
||||
--bs-btn-active-bg: color-mix(in srgb, var(--bs-primary) 20%, transparent);
|
||||
}
|
||||
@@ -42,6 +42,7 @@ import { environment } from 'src/environments/environment'
|
||||
import { ProfileEditDialogComponent } from '../common/profile-edit-dialog/profile-edit-dialog.component'
|
||||
import { UploadStatusTrayComponent } from '../common/upload-status-tray/upload-status-tray.component'
|
||||
import { DocumentDetailComponent } from '../document-detail/document-detail.component'
|
||||
import { ReleaseNotesDialogComponent } from '../common/release-notes-dialog/release-notes-dialog.component'
|
||||
import { AppFrameComponent } from './app-frame.component'
|
||||
import { GlobalSearchComponent } from './global-search/global-search.component'
|
||||
|
||||
@@ -695,6 +696,131 @@ describe('AppFrameComponent', () => {
|
||||
expect(maybeRefreshSpy).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('should show new release pill and mark releases seen on click', () => {
|
||||
settingsService.set(SETTINGS_KEYS.VERSION, '3.5.1')
|
||||
settingsService.set(SETTINGS_KEYS.WHATS_NEW_LAST_SEEN_VERSION, '3.4.2')
|
||||
fixture.detectChanges()
|
||||
|
||||
const pill = fixture.debugElement
|
||||
.queryAll(By.css('button'))
|
||||
.find((b) => b.nativeElement.textContent.trim() === 'New')
|
||||
expect(pill).toBeTruthy()
|
||||
|
||||
pill.nativeElement.click()
|
||||
const req = httpTestingController.expectOne(
|
||||
`${environment.apiBaseUrl}ui_settings/`
|
||||
)
|
||||
expect(req.request.body.settings.whats_new.last_seen_version).toEqual(
|
||||
'3.5.1'
|
||||
)
|
||||
req.flush({ success: true })
|
||||
fixture.detectChanges()
|
||||
|
||||
expect(
|
||||
fixture.debugElement
|
||||
.queryAll(By.css('button'))
|
||||
.find((b) => b.nativeElement.textContent.trim() === 'New')
|
||||
).toBeUndefined()
|
||||
})
|
||||
|
||||
it('should dismiss new release pill without opening release notes', () => {
|
||||
settingsService.set(SETTINGS_KEYS.VERSION, '3.5.1')
|
||||
settingsService.set(SETTINGS_KEYS.WHATS_NEW_LAST_SEEN_VERSION, '3.4.2')
|
||||
fixture.detectChanges()
|
||||
const modalSpy = jest.spyOn(modalService, 'open')
|
||||
|
||||
fixture.debugElement
|
||||
.query(By.css('button[aria-label="Dismiss"]'))
|
||||
.nativeElement.click()
|
||||
const req = httpTestingController.expectOne(
|
||||
`${environment.apiBaseUrl}ui_settings/`
|
||||
)
|
||||
expect(req.request.body.settings.whats_new.last_seen_version).toEqual(
|
||||
'3.5.1'
|
||||
)
|
||||
req.flush({ success: true })
|
||||
fixture.detectChanges()
|
||||
|
||||
expect(modalSpy).not.toHaveBeenCalled()
|
||||
expect(
|
||||
fixture.debugElement.query(By.css('button[aria-label="Dismiss"]'))
|
||||
).toBeNull()
|
||||
})
|
||||
|
||||
it('should open current release notes from the version without marking seen', () => {
|
||||
settingsService.set(SETTINGS_KEYS.VERSION, '3.5.1')
|
||||
settingsService.set(SETTINGS_KEYS.WHATS_NEW_LAST_SEEN_VERSION, '3.5.1')
|
||||
fixture.detectChanges()
|
||||
const modalSpy = jest.spyOn(modalService, 'open')
|
||||
|
||||
const versionButton = fixture.debugElement
|
||||
.queryAll(By.css('button'))
|
||||
.find((b) => b.nativeElement.textContent.includes('3.5.1'))
|
||||
versionButton.nativeElement.click()
|
||||
|
||||
expect(modalSpy).toHaveBeenCalledWith(
|
||||
ReleaseNotesDialogComponent,
|
||||
expect.anything()
|
||||
)
|
||||
httpTestingController.expectNone(`${environment.apiBaseUrl}ui_settings/`)
|
||||
})
|
||||
|
||||
it('should open available release notes from update available', () => {
|
||||
jest
|
||||
.spyOn(remoteVersionService, 'checkForUpdates')
|
||||
.mockReturnValue(of({ version: '3.6.0', update_available: true }))
|
||||
settingsService.set(SETTINGS_KEYS.VERSION, '3.5.1')
|
||||
settingsService.set(SETTINGS_KEYS.UPDATE_CHECKING_ENABLED, true)
|
||||
component.ngOnInit()
|
||||
fixture.detectChanges()
|
||||
const modalSpy = jest.spyOn(modalService, 'open')
|
||||
const saveSpy = jest.spyOn(settingsService, 'markReleasesSeen')
|
||||
|
||||
const updateButton = fixture.debugElement
|
||||
.queryAll(By.css('button'))
|
||||
.find((b) => b.nativeElement.textContent.includes('Update available'))
|
||||
expect(updateButton.nativeElement.title).toEqual(
|
||||
'Paperless-ngx 3.6.0 is available'
|
||||
)
|
||||
updateButton.nativeElement.click()
|
||||
|
||||
const dialog = modalSpy.mock.results[0].value
|
||||
.componentInstance as ReleaseNotesDialogComponent
|
||||
expect(dialog.since()).toEqual('3.5.1')
|
||||
expect(dialog.until()).toEqual('3.6.0')
|
||||
expect(saveSpy).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
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')
|
||||
settingsService.set(SETTINGS_KEYS.WHATS_NEW_LAST_SEEN_VERSION, '3.4.2')
|
||||
fixture.detectChanges()
|
||||
|
||||
const whatsNew = fixture.debugElement.query(
|
||||
By.css('button[aria-label="See what\'s new in this version"]')
|
||||
).nativeElement
|
||||
const docs = fixture.debugElement.query(
|
||||
By.css('a[href="https://docs.paperless-ngx.com"].nav-anchor')
|
||||
).nativeElement
|
||||
expect(docs.classList).toContain('d-md-none')
|
||||
// both share one li so the tour anchor points at whichever is shown
|
||||
expect(whatsNew.closest('li')).toBe(docs.closest('li'))
|
||||
})
|
||||
|
||||
it('should show tasks badge for needs-attention tasks', () => {
|
||||
jest
|
||||
.spyOn(tasksService, 'needsAttentionTasksCount', 'get')
|
||||
|
||||
@@ -68,6 +68,7 @@ import { SwitchComponent } from '../common/input/switch/switch.component'
|
||||
import { BrandMarkComponent } from '../common/logo/brand-mark/brand-mark.component'
|
||||
import { LogoComponent } from '../common/logo/logo.component'
|
||||
import { ProfileEditDialogComponent } from '../common/profile-edit-dialog/profile-edit-dialog.component'
|
||||
import { ReleaseNotesDialogComponent } from '../common/release-notes-dialog/release-notes-dialog.component'
|
||||
import { UploadStatusTrayComponent } from '../common/upload-status-tray/upload-status-tray.component'
|
||||
import { DocumentDetailComponent } from '../document-detail/document-detail.component'
|
||||
import { ComponentWithPermissions } from '../with-permissions/with-permissions.component'
|
||||
@@ -551,6 +552,44 @@ export class AppFrameComponent
|
||||
})
|
||||
}
|
||||
|
||||
private openReleaseNotes(
|
||||
since: string | null,
|
||||
until: string | null = null
|
||||
): void {
|
||||
const modal = this.modalService.open(ReleaseNotesDialogComponent, {
|
||||
size: 'lg',
|
||||
scrollable: true,
|
||||
})
|
||||
modal.componentInstance.load(since, until)
|
||||
modal.componentInstance.updateCheckingChosen.subscribe((enable: boolean) =>
|
||||
this.setUpdateChecking(enable)
|
||||
)
|
||||
}
|
||||
|
||||
showReleaseNotes() {
|
||||
const since = this.settingsService.unseenReleasesSince()
|
||||
this.openReleaseNotes(since)
|
||||
if (since) {
|
||||
this.dismissReleaseNotes()
|
||||
}
|
||||
}
|
||||
|
||||
/** Mark the running version's release notes seen, hiding "New" */
|
||||
dismissReleaseNotes() {
|
||||
this.settingsService
|
||||
.markReleasesSeen()
|
||||
.pipe(first())
|
||||
.subscribe({ error: () => {} })
|
||||
}
|
||||
|
||||
/** Notes for releases newer than the running version, not yet installed */
|
||||
showAvailableReleaseNotes() {
|
||||
this.openReleaseNotes(
|
||||
this.settingsService.get(SETTINGS_KEYS.VERSION),
|
||||
this.appRemoteVersion()?.version
|
||||
)
|
||||
}
|
||||
|
||||
setUpdateChecking(enable: boolean) {
|
||||
this.settingsService.set(SETTINGS_KEYS.UPDATE_CHECKING_ENABLED, enable)
|
||||
this.settingsService
|
||||
|
||||
@@ -87,6 +87,7 @@ import folderFill from 'bootstrap-icons/icons/folder-fill.svg'
|
||||
import folder from 'bootstrap-icons/icons/folder.svg'
|
||||
import funnel from 'bootstrap-icons/icons/funnel.svg'
|
||||
import gear from 'bootstrap-icons/icons/gear.svg'
|
||||
import github from 'bootstrap-icons/icons/github.svg'
|
||||
import globe2 from 'bootstrap-icons/icons/globe2.svg'
|
||||
import google from 'bootstrap-icons/icons/google.svg'
|
||||
import grid from 'bootstrap-icons/icons/grid.svg'
|
||||
@@ -249,6 +250,7 @@ export const icons: Record<string, string> = {
|
||||
folderFill,
|
||||
funnel,
|
||||
gear,
|
||||
github,
|
||||
globe2,
|
||||
google,
|
||||
grid,
|
||||
|
||||
+92
@@ -0,0 +1,92 @@
|
||||
<div class="modal-header">
|
||||
<div>
|
||||
@if (until()) {
|
||||
<h4 class="modal-title" i18n>Paperless-ngx {{ until() }} is available</h4>
|
||||
<p class="text-muted small mb-0" i18n>You are running {{ version }}</p>
|
||||
} @else {
|
||||
<h4 class="modal-title" i18n>What's new in Paperless-ngx</h4>
|
||||
@if (since()) {
|
||||
<p class="text-muted small mb-0" i18n>Updated from {{ since() }} to {{ version }}</p>
|
||||
}
|
||||
}
|
||||
</div>
|
||||
<div class="d-flex align-items-center gap-3 ms-auto">
|
||||
<div class="btn-group btn-group-sm" role="group">
|
||||
<a tabindex="-1" class="btn btn-dark border-dark-subtle d-flex align-items-center" [href]="repoUrl" target="_blank" rel="noopener noreferrer"
|
||||
title="Star Paperless-ngx on GitHub" i18n-title>
|
||||
<pngx-bs-icon name="github" class="me-1 d-flex" width="12" height="12"></pngx-bs-icon><span class="small" i18n>Star</span>
|
||||
</a>
|
||||
@if (stars() !== null) {
|
||||
<a tabindex="-1" class="btn btn-dark border-dark-subtle d-flex align-items-center" [href]="repoUrl + '/stargazers'" target="_blank" rel="noopener noreferrer"
|
||||
title="Stargazers" i18n-title>
|
||||
<span class="small">{{ stars() | number }}</span>
|
||||
</a>
|
||||
}
|
||||
</div>
|
||||
<button type="button" class="btn-close m-0" aria-label="Close" i18n-aria-label (click)="close()"></button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
@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>
|
||||
<ng-container i18n>Loading release notes...</ng-container>
|
||||
</div>
|
||||
} @else if (!releases()?.length) {
|
||||
<p class="mb-0" i18n>Release notes could not be loaded.</p>
|
||||
<ng-container *ngTemplateOutlet="githubLink"></ng-container>
|
||||
} @else {
|
||||
@for (release of releases(); track release.version) {
|
||||
<section class="release-notes" [class.border-top]="!$first" [class.pt-3]="!$first" [class.mt-3]="!$first">
|
||||
<div class="d-flex align-items-baseline gap-2 mb-2">
|
||||
<h5 class="mb-0">{{ release.version }}</h5>
|
||||
<a class="d-flex flex-row align-items-center text-secondary btn-link" [href]="release.html_url" target="_blank" rel="noopener noreferrer"
|
||||
title="View on GitHub" i18n-title>
|
||||
@if (release.published_at) {
|
||||
<span class="text-muted small me-2">{{ release.published_at | customDate }}</span>
|
||||
}
|
||||
<pngx-bs-icon name="box-arrow-up-right" class="mt-n1" width=".7rem"></pngx-bs-icon>
|
||||
</a>
|
||||
</div>
|
||||
<div class="release-notes-body" [innerHTML]="release.body_html"></div>
|
||||
</section>
|
||||
}
|
||||
}
|
||||
</div>
|
||||
<div class="modal-footer justify-content-between">
|
||||
<div class="d-flex flex-wrap gap-3 small">
|
||||
<a class="link-secondary text-decoration-none d-flex align-items-center" [href]="releasesUrl" target="_blank" rel="noopener noreferrer">
|
||||
<pngx-bs-icon name="clock-history" class="me-1"></pngx-bs-icon><ng-container i18n>All releases</ng-container>
|
||||
</a>
|
||||
<a class="link-secondary text-decoration-none d-flex align-items-center" [href]="discussionsUrl" target="_blank" rel="noopener noreferrer">
|
||||
<pngx-bs-icon name="chat-left-text" class="me-1"></pngx-bs-icon><ng-container i18n>Need support? Ask in Discussions</ng-container>
|
||||
</a>
|
||||
</div>
|
||||
<div class="d-flex gap-3">
|
||||
<button type="button" class="btn btn-outline-secondary" (click)="close()" i18n>Close</button>
|
||||
@if (until()) {
|
||||
<a class="btn btn-primary d-flex align-items-center" [href]="updatingDocsUrl" target="_blank" rel="noopener noreferrer">
|
||||
<ng-container i18n>How to update</ng-container>
|
||||
<pngx-bs-icon name="box-arrow-up-right" class="ms-2" width=".8rem"></pngx-bs-icon>
|
||||
</a>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<ng-template #githubLink>
|
||||
<a class="small" [href]="releaseUrl" target="_blank" rel="noopener noreferrer">
|
||||
<ng-container i18n>View on GitHub</ng-container>
|
||||
<pngx-bs-icon name="box-arrow-up-right" class="ms-1"></pngx-bs-icon>
|
||||
</a>
|
||||
</ng-template>
|
||||
+77
@@ -0,0 +1,77 @@
|
||||
// Styles for GitHub-rendered release notes (body_html)
|
||||
:host ::ng-deep .release-notes-body {
|
||||
// Repeats the version heading
|
||||
> h2:first-child {
|
||||
display: none;
|
||||
}
|
||||
|
||||
// Section labels e.g. "Bug Fixes"
|
||||
> h3 {
|
||||
color: var(--bs-secondary-color);
|
||||
font-size: 0.875rem;
|
||||
font-weight: 600;
|
||||
margin-top: 1rem;
|
||||
margin-bottom: 0.375rem;
|
||||
}
|
||||
|
||||
ul {
|
||||
padding-left: 1.25rem;
|
||||
margin-bottom: 0.75rem;
|
||||
}
|
||||
|
||||
li {
|
||||
margin-bottom: 0.25rem;
|
||||
|
||||
&::marker {
|
||||
color: var(--bs-secondary-color);
|
||||
}
|
||||
}
|
||||
|
||||
a {
|
||||
text-decoration: none;
|
||||
|
||||
&:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
}
|
||||
|
||||
a.user-mention {
|
||||
color: var(--bs-secondary-color);
|
||||
}
|
||||
|
||||
details {
|
||||
margin-bottom: 0.75rem;
|
||||
|
||||
> summary {
|
||||
color: var(--bs-secondary-color);
|
||||
font-size: 0.875rem;
|
||||
cursor: pointer;
|
||||
margin-bottom: 0.375rem;
|
||||
}
|
||||
}
|
||||
|
||||
// Keep the link underline off code, where it hides underscores
|
||||
// e.g. PAPERLESS_ALLOWED_HOSTS
|
||||
a code {
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
// GitHub alerts, e.g. > [!NOTE]
|
||||
.markdown-alert {
|
||||
background-color: color-mix(in srgb, var(--bs-primary) 8%, transparent);
|
||||
border-left: 0.25rem solid var(--bs-primary);
|
||||
border-radius: var(--bs-border-radius);
|
||||
padding: 0.75rem 1rem;
|
||||
margin-bottom: 1rem;
|
||||
|
||||
> :last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.markdown-alert-title {
|
||||
color: var(--bs-primary);
|
||||
font-weight: 600;
|
||||
margin-bottom: 0.25rem;
|
||||
}
|
||||
}
|
||||
+210
@@ -0,0 +1,210 @@
|
||||
import { DatePipe } from '@angular/common'
|
||||
import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http'
|
||||
import {
|
||||
HttpTestingController,
|
||||
provideHttpClientTesting,
|
||||
} from '@angular/common/http/testing'
|
||||
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 {
|
||||
prepareReleaseHtml,
|
||||
ReleaseNotesDialogComponent,
|
||||
} from './release-notes-dialog.component'
|
||||
|
||||
describe('ReleaseNotesDialogComponent', () => {
|
||||
let component: ReleaseNotesDialogComponent
|
||||
let fixture: ComponentFixture<ReleaseNotesDialogComponent>
|
||||
let httpTestingController: HttpTestingController
|
||||
let settingsService: SettingsService
|
||||
|
||||
function create(updateCheckingEnabled?: boolean, canChangeSettings = true) {
|
||||
settingsService = TestBed.inject(SettingsService)
|
||||
settingsService.set(SETTINGS_KEYS.VERSION, '3.5.1')
|
||||
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
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
imports: [ReleaseNotesDialogComponent],
|
||||
providers: [
|
||||
DatePipe,
|
||||
NgbActiveModal,
|
||||
provideHttpClient(withInterceptorsFromDi()),
|
||||
provideHttpClientTesting(),
|
||||
],
|
||||
})
|
||||
httpTestingController = TestBed.inject(HttpTestingController)
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
httpTestingController.verify()
|
||||
})
|
||||
|
||||
it('should load and render release notes since a version', () => {
|
||||
create(true)
|
||||
component.load('3.4.2')
|
||||
const req = httpTestingController.expectOne(
|
||||
`${environment.apiBaseUrl}release_notes/?since=3.4.2`
|
||||
)
|
||||
req.flush({
|
||||
version: '3.5.1',
|
||||
releases: [
|
||||
{
|
||||
version: '3.5.1',
|
||||
name: 'Paperless-ngx v3.5.1',
|
||||
body_html:
|
||||
'<h2>paperless-ngx 3.5.1</h2><h3>Bug Fixes</h3><ul><li>Fix: a thing</li></ul>' +
|
||||
'<h3>All App Changes</h3><details><summary>1 change</summary><ul><li>Fix: a thing</li></ul></details>',
|
||||
html_url: '',
|
||||
published_at: '2026-11-18T05:22:01Z',
|
||||
},
|
||||
],
|
||||
})
|
||||
fixture.detectChanges()
|
||||
|
||||
const text = fixture.nativeElement.textContent
|
||||
expect(text).toContain('Updated from 3.4.2 to 3.5.1')
|
||||
expect(text).toContain('Bug Fixes')
|
||||
expect(
|
||||
fixture.nativeElement.querySelector('.modal-footer a.btn-primary')
|
||||
).toBeNull()
|
||||
expect(
|
||||
fixture.nativeElement.querySelector('.release-notes-body details summary')
|
||||
.textContent
|
||||
).toEqual('1 change')
|
||||
})
|
||||
|
||||
it('should load release notes for an available update', () => {
|
||||
create(true)
|
||||
component.load('3.5.1', '3.6.0')
|
||||
httpTestingController
|
||||
.expectOne(
|
||||
`${environment.apiBaseUrl}release_notes/?since=3.5.1&until=3.6.0`
|
||||
)
|
||||
.flush({ version: '3.5.1', releases: [] })
|
||||
fixture.detectChanges()
|
||||
|
||||
const text = fixture.nativeElement.textContent
|
||||
expect(text).toContain('Paperless-ngx 3.6.0 is available')
|
||||
expect(text).toContain('You are running 3.5.1')
|
||||
expect(component.releaseUrl).toEqual(
|
||||
'https://github.com/paperless-ngx/paperless-ngx/releases/tag/v3.6.0'
|
||||
)
|
||||
expect(
|
||||
fixture.nativeElement
|
||||
.querySelector('.modal-footer a.btn-primary')
|
||||
.getAttribute('href')
|
||||
).toEqual('https://docs.paperless-ngx.com/administration/#updating')
|
||||
})
|
||||
|
||||
it('should open release note links safely and drop svg icons', () => {
|
||||
const html = prepareReleaseHtml(
|
||||
'<div class="markdown-alert"><p class="markdown-alert-title"><svg><path d="M0"></path></svg>Note</p></div>' +
|
||||
'<p><a href="https://github.com/paperless-ngx/paperless-ngx/pull/1" data-hovercard-type="pull_request">#1</a></p>'
|
||||
)
|
||||
const doc = new DOMParser().parseFromString(html, 'text/html')
|
||||
expect(doc.querySelector('svg')).toBeNull()
|
||||
expect(doc.querySelector('.markdown-alert-title').textContent).toEqual(
|
||||
'Note'
|
||||
)
|
||||
const link = doc.querySelector('a')
|
||||
expect(link.getAttribute('target')).toEqual('_blank')
|
||||
expect(link.getAttribute('rel')).toEqual('noopener noreferrer nofollow')
|
||||
expect(link.hasAttribute('data-hovercard-type')).toBe(false)
|
||||
})
|
||||
|
||||
it('should show a message if release notes could not be loaded', () => {
|
||||
create(true)
|
||||
component.load(null)
|
||||
httpTestingController
|
||||
.expectOne(`${environment.apiBaseUrl}release_notes/`)
|
||||
.flush('error', { status: 500, statusText: 'error' })
|
||||
fixture.detectChanges()
|
||||
|
||||
expect(fixture.nativeElement.textContent).toContain(
|
||||
'Release notes could not be loaded'
|
||||
)
|
||||
})
|
||||
|
||||
it('should not fetch release notes if update checking is disabled', () => {
|
||||
create(false)
|
||||
component.load('3.4.2')
|
||||
fixture.detectChanges()
|
||||
|
||||
httpTestingController.expectNone(`${environment.apiBaseUrl}release_notes/`)
|
||||
expect(fixture.nativeElement.textContent).toContain(
|
||||
'when update checking is enabled'
|
||||
)
|
||||
expect(component.releaseUrl).toEqual(
|
||||
'https://github.com/paperless-ngx/paperless-ngx/releases/tag/v3.5.1'
|
||||
)
|
||||
})
|
||||
|
||||
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')
|
||||
component.close()
|
||||
expect(closeSpy).toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
+131
@@ -0,0 +1,131 @@
|
||||
import { DecimalPipe, NgTemplateOutlet } from '@angular/common'
|
||||
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,
|
||||
} from 'src/app/services/rest/remote-version.service'
|
||||
import { SettingsService } from 'src/app/services/settings.service'
|
||||
|
||||
const REPO_URL = 'https://github.com/paperless-ngx/paperless-ngx'
|
||||
const RELEASES_URL = `${REPO_URL}/releases`
|
||||
const DISCUSSIONS_URL = `${REPO_URL}/discussions/new/choose`
|
||||
const UPDATING_DOCS_URL =
|
||||
'https://docs.paperless-ngx.com/administration/#updating'
|
||||
|
||||
/**
|
||||
* Tweak GitHub release HTML: open links in a new tab, add no referrer etc,
|
||||
* drop inline svgs and GH `data-*` attributes. Angular sanitizes all of this anyway.
|
||||
*/
|
||||
export function prepareReleaseHtml(html: string): string {
|
||||
const doc = new DOMParser().parseFromString(html, 'text/html')
|
||||
doc.querySelectorAll('svg').forEach((svg) => svg.remove())
|
||||
doc.body.querySelectorAll('*').forEach((el) => {
|
||||
for (const attr of Array.from(el.attributes)) {
|
||||
if (attr.name.startsWith('data-')) el.removeAttribute(attr.name)
|
||||
}
|
||||
})
|
||||
doc.querySelectorAll('a').forEach((a) => {
|
||||
a.setAttribute('target', '_blank')
|
||||
a.setAttribute('rel', 'noopener noreferrer nofollow')
|
||||
})
|
||||
return doc.body.innerHTML
|
||||
}
|
||||
|
||||
@Component({
|
||||
selector: 'pngx-release-notes-dialog',
|
||||
templateUrl: './release-notes-dialog.component.html',
|
||||
styleUrls: ['./release-notes-dialog.component.scss'],
|
||||
imports: [
|
||||
BootstrapIconComponent,
|
||||
CustomDatePipe,
|
||||
NgTemplateOutlet,
|
||||
DecimalPipe,
|
||||
],
|
||||
})
|
||||
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 until = signal<string | null>(null)
|
||||
readonly releases = signal<AppRelease[] | null>(null)
|
||||
readonly stars = signal<number | null>(null)
|
||||
readonly loading = signal(false)
|
||||
|
||||
readonly version: string = this.settingsService.get(SETTINGS_KEYS.VERSION)
|
||||
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
|
||||
readonly discussionsUrl = DISCUSSIONS_URL
|
||||
readonly updatingDocsUrl = UPDATING_DOCS_URL
|
||||
|
||||
get releaseUrl(): string {
|
||||
const version = this.until() ?? this.version
|
||||
return version ? `${RELEASES_URL}/tag/v${version}` : RELEASES_URL
|
||||
}
|
||||
|
||||
/**
|
||||
* Load notes for releases after `since` up to `until` (default: the
|
||||
* running version), or just the `until` version's notes if `since` is null.
|
||||
*/
|
||||
load(since: string | null, until: string | null = null): void {
|
||||
this.since.set(since)
|
||||
this.until.set(until)
|
||||
if (!this.updateCheckingEnabled()) return
|
||||
this.loading.set(true)
|
||||
this.remoteVersionService
|
||||
.getReleaseNotes(since ?? undefined, until ?? undefined)
|
||||
.pipe(first())
|
||||
.subscribe({
|
||||
next: (notes) => {
|
||||
this.releases.set(
|
||||
notes.releases.map((release) => ({
|
||||
...release,
|
||||
body_html: prepareReleaseHtml(release.body_html),
|
||||
}))
|
||||
)
|
||||
this.stars.set(notes.stars ?? null)
|
||||
this.loading.set(false)
|
||||
},
|
||||
error: () => {
|
||||
this.releases.set([])
|
||||
this.loading.set(false)
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
setUpdateChecking(enable: boolean): void {
|
||||
this.updateCheckingIsSet.set(true)
|
||||
this.updateCheckingEnabled.set(enable)
|
||||
this.updateCheckingChosen.emit(enable)
|
||||
if (enable) this.load(this.since(), this.until())
|
||||
}
|
||||
|
||||
close(): void {
|
||||
this.activeModal.close()
|
||||
}
|
||||
}
|
||||
@@ -75,6 +75,7 @@ export const SETTINGS_KEYS = {
|
||||
UPDATE_CHECKING_ENABLED: 'general-settings:update-checking:enabled',
|
||||
UPDATE_CHECKING_BACKEND_SETTING:
|
||||
'general-settings:update-checking:backend-setting',
|
||||
WHATS_NEW_LAST_SEEN_VERSION: 'general-settings:whats-new:last-seen-version',
|
||||
SAVED_VIEWS_WARN_ON_UNSAVED_CHANGE:
|
||||
'general-settings:saved-views:warn-on-unsaved-change',
|
||||
DASHBOARD_VIEWS_VISIBLE_IDS:
|
||||
@@ -223,6 +224,11 @@ export const SETTINGS: UiSetting[] = [
|
||||
type: 'string',
|
||||
default: '',
|
||||
},
|
||||
{
|
||||
key: SETTINGS_KEYS.WHATS_NEW_LAST_SEEN_VERSION,
|
||||
type: 'string',
|
||||
default: '',
|
||||
},
|
||||
{
|
||||
key: SETTINGS_KEYS.SAVED_VIEWS_WARN_ON_UNSAVED_CHANGE,
|
||||
type: 'boolean',
|
||||
|
||||
@@ -40,4 +40,28 @@ describe('RemoteVersionService', () => {
|
||||
)
|
||||
expect(req.request.method).toEqual('GET')
|
||||
})
|
||||
|
||||
it('should call release notes endpoint without since', () => {
|
||||
subscription = service.getReleaseNotes().subscribe()
|
||||
const req = httpTestingController.expectOne(
|
||||
`${environment.apiBaseUrl}release_notes/`
|
||||
)
|
||||
expect(req.request.method).toEqual('GET')
|
||||
expect(req.request.params.has('since')).toBe(false)
|
||||
})
|
||||
|
||||
it('should pass since to release notes endpoint', () => {
|
||||
subscription = service.getReleaseNotes('3.4.2').subscribe()
|
||||
const req = httpTestingController.expectOne(
|
||||
`${environment.apiBaseUrl}release_notes/?since=3.4.2`
|
||||
)
|
||||
expect(req.request.method).toEqual('GET')
|
||||
})
|
||||
|
||||
it('should pass until to release notes endpoint', () => {
|
||||
subscription = service.getReleaseNotes('3.5.1', '3.6.0').subscribe()
|
||||
httpTestingController.expectOne(
|
||||
`${environment.apiBaseUrl}release_notes/?since=3.5.1&until=3.6.0`
|
||||
)
|
||||
})
|
||||
})
|
||||
@@ -1,4 +1,4 @@
|
||||
import { HttpClient } from '@angular/common/http'
|
||||
import { HttpClient, HttpParams } from '@angular/common/http'
|
||||
import { Injectable, inject } from '@angular/core'
|
||||
import { Observable } from 'rxjs'
|
||||
import { environment } from 'src/environments/environment'
|
||||
@@ -8,6 +8,20 @@ export interface AppRemoteVersion {
|
||||
update_available: boolean
|
||||
}
|
||||
|
||||
export interface AppRelease {
|
||||
version: string
|
||||
name: string
|
||||
body_html: string
|
||||
html_url: string
|
||||
published_at: string
|
||||
}
|
||||
|
||||
export interface AppReleaseNotes {
|
||||
version: string
|
||||
releases: AppRelease[]
|
||||
stars: number | null
|
||||
}
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
@@ -19,4 +33,21 @@ export class RemoteVersionService {
|
||||
`${environment.apiBaseUrl}remote_version/`
|
||||
)
|
||||
}
|
||||
|
||||
public getReleaseNotes(
|
||||
since?: string,
|
||||
until?: string
|
||||
): Observable<AppReleaseNotes> {
|
||||
let params = new HttpParams()
|
||||
if (since) {
|
||||
params = params.set('since', since)
|
||||
}
|
||||
if (until) {
|
||||
params = params.set('until', until)
|
||||
}
|
||||
return this.http.get<AppReleaseNotes>(
|
||||
`${environment.apiBaseUrl}release_notes/`,
|
||||
{ params }
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -398,6 +398,60 @@ describe('SettingsService', () => {
|
||||
expect(req.request.method).toEqual('POST')
|
||||
})
|
||||
|
||||
it('seeds last seen version on first load', () => {
|
||||
const settings = {
|
||||
...ui_settings,
|
||||
user: { ...ui_settings.user, is_superuser: true },
|
||||
settings: {
|
||||
...ui_settings.settings,
|
||||
documentListSize: 50,
|
||||
update_checking: { enabled: false, backend_setting: 'default' },
|
||||
},
|
||||
}
|
||||
settings.settings['version'] = '3.5.1'
|
||||
httpTestingController
|
||||
.expectOne(`${environment.apiBaseUrl}ui_settings/`)
|
||||
.flush(settings)
|
||||
|
||||
const req = httpTestingController.expectOne(
|
||||
`${environment.apiBaseUrl}ui_settings/`
|
||||
)
|
||||
expect(req.request.method).toEqual('POST')
|
||||
expect(req.request.body.settings.whats_new.last_seen_version).toEqual(
|
||||
'3.5.1'
|
||||
)
|
||||
expect(settingsService.unseenReleasesSince()).toBeNull()
|
||||
})
|
||||
|
||||
it('reports unseen releases and marks them seen', () => {
|
||||
const settings = {
|
||||
...ui_settings,
|
||||
user: { ...ui_settings.user, is_superuser: true },
|
||||
settings: {
|
||||
...ui_settings.settings,
|
||||
documentListSize: 50,
|
||||
update_checking: { enabled: false, backend_setting: 'default' },
|
||||
},
|
||||
}
|
||||
settings.settings['version'] = '3.5.1'
|
||||
settings.settings['whats_new'] = { last_seen_version: '3.4.2' }
|
||||
httpTestingController
|
||||
.expectOne(`${environment.apiBaseUrl}ui_settings/`)
|
||||
.flush(settings)
|
||||
httpTestingController.expectNone(`${environment.apiBaseUrl}ui_settings/`)
|
||||
|
||||
expect(settingsService.unseenReleasesSince()).toEqual('3.4.2')
|
||||
|
||||
subscription = settingsService.markReleasesSeen().subscribe()
|
||||
const req = httpTestingController.expectOne(
|
||||
`${environment.apiBaseUrl}ui_settings/`
|
||||
)
|
||||
expect(req.request.body.settings.whats_new.last_seen_version).toEqual(
|
||||
'3.5.1'
|
||||
)
|
||||
expect(settingsService.unseenReleasesSince()).toBeNull()
|
||||
})
|
||||
|
||||
it('updates settings on complete tour', () => {
|
||||
let req = httpTestingController.expectOne(
|
||||
`${environment.apiBaseUrl}ui_settings/`
|
||||
|
||||
@@ -20,6 +20,7 @@ import {
|
||||
hexToHsl,
|
||||
} from 'src/app/utils/color'
|
||||
import { DEFAULT_APP_TITLE, environment } from 'src/environments/environment'
|
||||
import { compareVersions } from 'src/app/utils/version'
|
||||
import { DEFAULT_DISPLAY_FIELDS, DisplayField } from '../data/document'
|
||||
import { RemoteOCRModeConfig } from '../data/paperless-config'
|
||||
import { SavedView } from '../data/saved-view'
|
||||
@@ -327,6 +328,18 @@ export class SettingsService {
|
||||
SETTINGS_KEYS.SIDEBAR_HIDDEN_ITEMS
|
||||
)
|
||||
|
||||
/**
|
||||
* The last version the user saw release notes for, if the running
|
||||
* version is newer, or null.
|
||||
*/
|
||||
readonly unseenReleasesSince = computed<string | null>(() => {
|
||||
this.settingsVersion()
|
||||
const currentVersion = this.get(SETTINGS_KEYS.VERSION)
|
||||
const lastSeen = this.get(SETTINGS_KEYS.WHATS_NEW_LAST_SEEN_VERSION)
|
||||
if (!currentVersion || !lastSeen) return null
|
||||
return compareVersions(currentVersion, lastSeen) > 0 ? lastSeen : null
|
||||
})
|
||||
|
||||
readonly allDisplayFields = signal<Array<{ id: DisplayField; name: string }>>(
|
||||
DEFAULT_DISPLAY_FIELDS
|
||||
)
|
||||
@@ -384,6 +397,7 @@ export class SettingsService {
|
||||
uisettings.permissions,
|
||||
this.currentUser()
|
||||
)
|
||||
this.maybeSeedLastSeenVersion()
|
||||
|
||||
this.initializeDisplayFields()
|
||||
})
|
||||
@@ -713,6 +727,34 @@ export class SettingsService {
|
||||
return this.settingIsSet(SETTINGS_KEYS.UPDATE_CHECKING_ENABLED)
|
||||
}
|
||||
|
||||
/**
|
||||
* Record the baseline version for "what's new" tracking.
|
||||
*/
|
||||
private maybeSeedLastSeenVersion() {
|
||||
const currentVersion = this.get(SETTINGS_KEYS.VERSION)
|
||||
if (
|
||||
!currentVersion ||
|
||||
this.get(SETTINGS_KEYS.WHATS_NEW_LAST_SEEN_VERSION) ||
|
||||
!this.permissionsService.currentUserCan(
|
||||
PermissionAction.Change,
|
||||
PermissionType.UISettings
|
||||
)
|
||||
)
|
||||
return
|
||||
this.set(SETTINGS_KEYS.WHATS_NEW_LAST_SEEN_VERSION, currentVersion)
|
||||
this.storeSettings()
|
||||
.pipe(first())
|
||||
.subscribe({ error: () => {} })
|
||||
}
|
||||
|
||||
public markReleasesSeen(): Observable<any> {
|
||||
this.set(
|
||||
SETTINGS_KEYS.WHATS_NEW_LAST_SEEN_VERSION,
|
||||
this.get(SETTINGS_KEYS.VERSION)
|
||||
)
|
||||
return this.storeSettings()
|
||||
}
|
||||
|
||||
/**
|
||||
* Offering remote OCR as a choice only makes sense when an engine
|
||||
* is configured but is not already handling every document.
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
import { compareVersions } from './version'
|
||||
|
||||
describe('compareVersions', () => {
|
||||
it('should compare versions numerically', () => {
|
||||
expect(compareVersions('3.5.1', '3.5.0')).toBeGreaterThan(0)
|
||||
expect(compareVersions('3.10.0', '3.9.9')).toBeGreaterThan(0)
|
||||
expect(compareVersions('3.4.2', '3.5.0')).toBeLessThan(0)
|
||||
expect(compareVersions('3.5.0', '3.5.0')).toEqual(0)
|
||||
expect(compareVersions('3.5', '3.5.0')).toEqual(0)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,13 @@
|
||||
/**
|
||||
* Compare two X.Y.Z version strings numerically.
|
||||
* Returns a positive number if a > b, negative if a < b, 0 if equal.
|
||||
*/
|
||||
export function compareVersions(a: string, b: string): number {
|
||||
const partsA = a.split('.').map((p) => Number.parseInt(p, 10) || 0)
|
||||
const partsB = b.split('.').map((p) => Number.parseInt(p, 10) || 0)
|
||||
for (let i = 0; i < Math.max(partsA.length, partsB.length); i++) {
|
||||
const diff = (partsA[i] ?? 0) - (partsB[i] ?? 0)
|
||||
if (diff !== 0) return diff
|
||||
}
|
||||
return 0
|
||||
}
|
||||
@@ -13,6 +13,9 @@ $form-file-button-hover-bg: var(--pngx-bg-alt);
|
||||
@include meta.load-css("print");
|
||||
|
||||
// re-created bootstrap styles
|
||||
.mt-n1 {
|
||||
margin-top: -0.25rem;
|
||||
}
|
||||
.mt-n2 {
|
||||
margin-top: -0.5rem;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,341 @@
|
||||
from unittest import mock
|
||||
|
||||
import pytest
|
||||
from django.core.cache import cache
|
||||
from pytest_httpx import HTTPXMock
|
||||
from rest_framework import status
|
||||
from rest_framework.test import APIClient
|
||||
|
||||
from paperless import version
|
||||
|
||||
REPO_URL = "https://api.github.com/repos/paperless-ngx/paperless-ngx"
|
||||
RELEASES_URL = f"{REPO_URL}/releases?per_page=10&page=1"
|
||||
|
||||
|
||||
def _page_url(page: int) -> str:
|
||||
return f"{REPO_URL}/releases?per_page=10&page={page}"
|
||||
|
||||
|
||||
def _tag_url(version_str: str) -> str:
|
||||
return f"{REPO_URL}/releases/tags/v{version_str}"
|
||||
|
||||
|
||||
def _release(tag: str, **kwargs) -> dict:
|
||||
return {
|
||||
"tag_name": tag,
|
||||
"name": f"Paperless-ngx {tag}",
|
||||
"body_html": f"<h2>paperless-ngx {tag}</h2>",
|
||||
"html_url": f"https://github.com/paperless-ngx/paperless-ngx/releases/tag/{tag}",
|
||||
"published_at": "2026-11-17T03:36:20Z",
|
||||
"draft": False,
|
||||
"prerelease": False,
|
||||
**kwargs,
|
||||
}
|
||||
|
||||
|
||||
def _bump(minor: int = 0, patch: int = 0) -> str:
|
||||
major, cur_minor, cur_patch = version.__version__
|
||||
return f"{major}.{cur_minor + minor}.{cur_patch + patch}"
|
||||
|
||||
|
||||
CURRENT = version.__full_version_str__
|
||||
PREVIOUS = f"{version.__version__[0]}.{version.__version__[1] - 1}.0"
|
||||
OLDER = f"{version.__version__[0]}.{version.__version__[1] - 2}.0"
|
||||
|
||||
|
||||
class TestApiReleaseNotes:
|
||||
ENDPOINT = "/api/release_notes/"
|
||||
|
||||
def setup_method(self) -> None:
|
||||
cache.clear()
|
||||
|
||||
@pytest.fixture
|
||||
def releases(self, httpx_mock: HTTPXMock) -> HTTPXMock:
|
||||
httpx_mock.add_response(
|
||||
url=RELEASES_URL,
|
||||
match_headers={"Accept": "application/vnd.github.html+json"},
|
||||
json=[
|
||||
_release(f"v{_bump(patch=1)}"),
|
||||
_release(f"v{_bump(minor=1)}-beta.1", prerelease=True),
|
||||
_release(f"v{CURRENT}"),
|
||||
_release(f"v{PREVIOUS}"),
|
||||
_release(f"ngx-{OLDER}"),
|
||||
],
|
||||
)
|
||||
return httpx_mock
|
||||
|
||||
@pytest.fixture
|
||||
def current_release(self, httpx_mock: HTTPXMock) -> HTTPXMock:
|
||||
httpx_mock.add_response(
|
||||
url=_tag_url(CURRENT),
|
||||
match_headers={"Accept": "application/vnd.github.html+json"},
|
||||
json=_release(f"v{CURRENT}"),
|
||||
)
|
||||
return httpx_mock
|
||||
|
||||
@pytest.fixture
|
||||
def stars(self, httpx_mock: HTTPXMock) -> HTTPXMock:
|
||||
httpx_mock.add_response(url=REPO_URL, json={"stargazers_count": 1234})
|
||||
return httpx_mock
|
||||
|
||||
@pytest.mark.usefixtures("stars")
|
||||
def test_since_returns_newer_up_to_current(
|
||||
self,
|
||||
rest_api_client: APIClient,
|
||||
releases: HTTPXMock,
|
||||
) -> None:
|
||||
"""
|
||||
GIVEN:
|
||||
- GitHub releases older, equal to, and newer than the running version
|
||||
WHEN:
|
||||
- Release notes are requested since an older version
|
||||
THEN:
|
||||
- Only releases after `since` up to the running version are returned,
|
||||
newest first, excluding prereleases and the `since` release itself
|
||||
"""
|
||||
response = rest_api_client.get(self.ENDPOINT, {"since": OLDER})
|
||||
|
||||
assert response.status_code == status.HTTP_200_OK
|
||||
assert response.data["version"] == CURRENT
|
||||
assert [r["version"] for r in response.data["releases"]] == [
|
||||
CURRENT,
|
||||
PREVIOUS,
|
||||
]
|
||||
assert response.data["releases"][0]["html_url"].endswith(f"v{CURRENT}")
|
||||
assert (
|
||||
response.data["releases"][0]["body_html"]
|
||||
== f"<h2>paperless-ngx v{CURRENT}</h2>"
|
||||
)
|
||||
|
||||
@pytest.mark.usefixtures("stars")
|
||||
def test_without_since_fetches_current_only(
|
||||
self,
|
||||
rest_api_client: APIClient,
|
||||
current_release: HTTPXMock,
|
||||
) -> None:
|
||||
"""
|
||||
GIVEN:
|
||||
- A GitHub release for the running version
|
||||
WHEN:
|
||||
- Release notes are requested without `since`
|
||||
THEN:
|
||||
- Only that release is fetched, by tag, and returned
|
||||
"""
|
||||
response = rest_api_client.get(self.ENDPOINT)
|
||||
|
||||
assert response.status_code == status.HTTP_200_OK
|
||||
assert [r["version"] for r in response.data["releases"]] == [CURRENT]
|
||||
assert len(current_release.get_requests(url=_tag_url(CURRENT))) == 1
|
||||
|
||||
@pytest.mark.usefixtures("stars")
|
||||
def test_since_pages_back_to_since(
|
||||
self,
|
||||
rest_api_client: APIClient,
|
||||
httpx_mock: HTTPXMock,
|
||||
) -> None:
|
||||
"""
|
||||
GIVEN:
|
||||
- More releases since `since` than fit on one page
|
||||
WHEN:
|
||||
- Release notes are requested since that version
|
||||
THEN:
|
||||
- GitHub is paged until `since` is reached and all releases are returned
|
||||
"""
|
||||
major, minor, _ = version.__version__
|
||||
page_one = [f"{major}.{minor - 1}.{patch}" for patch in range(10, 0, -1)]
|
||||
httpx_mock.add_response(
|
||||
url=_page_url(1),
|
||||
json=[_release(f"v{v}") for v in page_one],
|
||||
)
|
||||
httpx_mock.add_response(
|
||||
url=_page_url(2),
|
||||
json=[_release(f"v{PREVIOUS}"), _release(f"v{OLDER}")],
|
||||
)
|
||||
|
||||
response = rest_api_client.get(self.ENDPOINT, {"since": OLDER})
|
||||
|
||||
assert [r["version"] for r in response.data["releases"]] == [
|
||||
*page_one,
|
||||
PREVIOUS,
|
||||
]
|
||||
|
||||
@pytest.mark.usefixtures("stars")
|
||||
def test_since_paging_is_capped(
|
||||
self,
|
||||
rest_api_client: APIClient,
|
||||
httpx_mock: HTTPXMock,
|
||||
) -> None:
|
||||
"""
|
||||
GIVEN:
|
||||
- Full pages of releases that never reach `since`
|
||||
WHEN:
|
||||
- Release notes are requested since a very old version
|
||||
THEN:
|
||||
- Paging stops after the page cap
|
||||
"""
|
||||
major, minor, _ = version.__version__
|
||||
for page in range(1, 4):
|
||||
httpx_mock.add_response(
|
||||
url=_page_url(page),
|
||||
json=[
|
||||
_release(f"v{major}.{minor}.{page * 100 + patch}")
|
||||
for patch in range(10)
|
||||
],
|
||||
)
|
||||
|
||||
rest_api_client.get(self.ENDPOINT, {"since": "0.1.0"})
|
||||
|
||||
assert len(httpx_mock.get_requests()) == 4 # 3 pages + stars
|
||||
|
||||
@pytest.mark.usefixtures("stars")
|
||||
@pytest.mark.usefixtures("current_release")
|
||||
def test_releases_are_cached(
|
||||
self,
|
||||
rest_api_client: APIClient,
|
||||
releases: HTTPXMock,
|
||||
) -> None:
|
||||
for _ in range(2):
|
||||
rest_api_client.get(self.ENDPOINT, {"since": OLDER})
|
||||
rest_api_client.get(self.ENDPOINT)
|
||||
|
||||
assert len(releases.get_requests(url=RELEASES_URL)) == 1
|
||||
assert len(releases.get_requests(url=_tag_url(CURRENT))) == 1
|
||||
assert len(releases.get_requests(url=REPO_URL)) == 1
|
||||
|
||||
@pytest.mark.usefixtures("stars")
|
||||
def test_new_running_version_refetches_releases(
|
||||
self,
|
||||
rest_api_client: APIClient,
|
||||
releases: HTTPXMock,
|
||||
) -> None:
|
||||
"""
|
||||
GIVEN:
|
||||
- GitHub releases cached for the running version
|
||||
WHEN:
|
||||
- The running version changes (i.e. paperless was upgraded)
|
||||
THEN:
|
||||
- The cached releases are not reused and GitHub is queried again
|
||||
"""
|
||||
upgraded = _bump(patch=1)
|
||||
releases.add_response(url=RELEASES_URL, json=[_release(f"v{upgraded}")])
|
||||
|
||||
rest_api_client.get(self.ENDPOINT, {"since": OLDER})
|
||||
with mock.patch.object(version, "__full_version_str__", upgraded):
|
||||
response = rest_api_client.get(self.ENDPOINT, {"since": CURRENT})
|
||||
|
||||
assert len(releases.get_requests(url=RELEASES_URL)) == 2
|
||||
assert [r["version"] for r in response.data["releases"]] == [upgraded]
|
||||
|
||||
@pytest.mark.usefixtures("stars")
|
||||
def test_until_returns_newer_releases(
|
||||
self,
|
||||
rest_api_client: APIClient,
|
||||
releases: HTTPXMock,
|
||||
) -> None:
|
||||
"""
|
||||
GIVEN:
|
||||
- A GitHub release newer than the running version
|
||||
WHEN:
|
||||
- Release notes are requested from the running version until the newer one
|
||||
THEN:
|
||||
- Only the newer release is returned, excluding prereleases
|
||||
"""
|
||||
response = rest_api_client.get(
|
||||
self.ENDPOINT,
|
||||
{"since": CURRENT, "until": _bump(minor=1)},
|
||||
)
|
||||
|
||||
assert response.status_code == status.HTTP_200_OK
|
||||
assert [r["version"] for r in response.data["releases"]] == [
|
||||
_bump(patch=1),
|
||||
]
|
||||
|
||||
@pytest.mark.parametrize("param", ["since", "until"])
|
||||
def test_invalid_version(
|
||||
self,
|
||||
rest_api_client: APIClient,
|
||||
param: str,
|
||||
) -> None:
|
||||
response = rest_api_client.get(self.ENDPOINT, {param: "not-a-version"})
|
||||
|
||||
assert response.status_code == status.HTTP_400_BAD_REQUEST
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"mock_kwargs",
|
||||
[
|
||||
pytest.param({"status_code": 503}, id="http-error"),
|
||||
pytest.param(
|
||||
{
|
||||
"content": b'{ "blah":',
|
||||
"headers": {"Content-Type": "application/json"},
|
||||
},
|
||||
id="bad-json",
|
||||
),
|
||||
],
|
||||
)
|
||||
def test_github_failure_returns_empty_and_is_not_cached(
|
||||
self,
|
||||
rest_api_client: APIClient,
|
||||
httpx_mock: HTTPXMock,
|
||||
mock_kwargs: dict,
|
||||
) -> None:
|
||||
httpx_mock.add_response(url=_tag_url(CURRENT), **mock_kwargs)
|
||||
httpx_mock.add_response(url=_tag_url(CURRENT), json=_release(f"v{CURRENT}"))
|
||||
httpx_mock.add_response(
|
||||
url=REPO_URL,
|
||||
json={"stargazers_count": 1234},
|
||||
is_reusable=True,
|
||||
)
|
||||
|
||||
response = rest_api_client.get(self.ENDPOINT)
|
||||
assert response.status_code == status.HTTP_200_OK
|
||||
assert response.data["releases"] == []
|
||||
|
||||
response = rest_api_client.get(self.ENDPOINT)
|
||||
assert [r["version"] for r in response.data["releases"]] == [CURRENT]
|
||||
|
||||
@pytest.mark.usefixtures("current_release", "stars")
|
||||
def test_stars_are_returned_and_cached(
|
||||
self,
|
||||
rest_api_client: APIClient,
|
||||
httpx_mock: HTTPXMock,
|
||||
) -> None:
|
||||
"""
|
||||
GIVEN:
|
||||
- The GitHub repository reports a star count
|
||||
WHEN:
|
||||
- Release notes are requested twice
|
||||
THEN:
|
||||
- The star count is included and GitHub is only asked once
|
||||
"""
|
||||
response = rest_api_client.get(self.ENDPOINT)
|
||||
assert response.data["stars"] == 1234
|
||||
|
||||
response = rest_api_client.get(self.ENDPOINT)
|
||||
assert response.data["stars"] == 1234
|
||||
assert len(httpx_mock.get_requests(url=REPO_URL)) == 1
|
||||
|
||||
@pytest.mark.usefixtures("current_release")
|
||||
def test_stars_failure_returns_none_and_is_not_cached(
|
||||
self,
|
||||
rest_api_client: APIClient,
|
||||
httpx_mock: HTTPXMock,
|
||||
) -> None:
|
||||
"""
|
||||
GIVEN:
|
||||
- The GitHub repository request fails, then succeeds
|
||||
WHEN:
|
||||
- Release notes are requested twice
|
||||
THEN:
|
||||
- Stars are null at first, then fetched again rather than cached
|
||||
"""
|
||||
httpx_mock.add_response(url=REPO_URL, status_code=503)
|
||||
httpx_mock.add_response(url=REPO_URL, json={"stargazers_count": 1234})
|
||||
|
||||
response = rest_api_client.get(self.ENDPOINT)
|
||||
assert response.status_code == status.HTTP_200_OK
|
||||
assert response.data["stars"] is None
|
||||
assert len(response.data["releases"]) == 1
|
||||
|
||||
response = rest_api_client.get(self.ENDPOINT)
|
||||
assert response.data["stars"] == 1234
|
||||
@@ -4314,6 +4314,139 @@ class UiSettingsView(GenericAPIView[Any]):
|
||||
)
|
||||
|
||||
|
||||
GITHUB_CACHE_KEY = "github_data:%s"
|
||||
GITHUB_RELEASES_CACHE_TIMEOUT = 60 * 60 * 12
|
||||
GITHUB_REQUEST_TIMEOUT = 5
|
||||
|
||||
|
||||
GITHUB_RELEASES_URL = (
|
||||
"https://api.github.com/repos/paperless-ngx/paperless-ngx/releases"
|
||||
)
|
||||
GITHUB_RELEASES_PER_PAGE = 10
|
||||
# Caps how far back a range can walk, e.g. for a bad `since`
|
||||
GITHUB_RELEASES_MAX_PAGES = 3
|
||||
|
||||
|
||||
def _fetch_github_releases_json(url: str, params: dict | None = None) -> Any | None:
|
||||
try:
|
||||
resp = httpx.get(
|
||||
url,
|
||||
params=params,
|
||||
# GitHub renders release bodies as HTML
|
||||
headers={"Accept": "application/vnd.github.html+json"},
|
||||
timeout=GITHUB_REQUEST_TIMEOUT,
|
||||
)
|
||||
resp.raise_for_status()
|
||||
return resp.json()
|
||||
except ValueError as e:
|
||||
logger.debug(f"An error occurred parsing GitHub releases json: {e}")
|
||||
except httpx.HTTPError as e:
|
||||
logger.debug(f"An error occurred fetching GitHub releases: {e}")
|
||||
return None
|
||||
|
||||
|
||||
def _parse_github_release(release: dict[str, Any]) -> dict[str, Any] | None:
|
||||
if release.get("draft") or release.get("prerelease"):
|
||||
return None
|
||||
try:
|
||||
# Some early tags used ngx-x.y.z
|
||||
release_version = packaging_version.parse(
|
||||
release["tag_name"].removeprefix("ngx-"),
|
||||
)
|
||||
except packaging_version.InvalidVersion:
|
||||
return None
|
||||
return {
|
||||
"version": str(release_version),
|
||||
"name": release.get("name") or release["tag_name"],
|
||||
"body_html": release.get("body_html") or "",
|
||||
"html_url": release["html_url"],
|
||||
"published_at": release.get("published_at"),
|
||||
}
|
||||
|
||||
|
||||
def get_github_release(version_str: str) -> dict[str, Any] | None:
|
||||
"""
|
||||
Fetch a single pngx release from GitHub by version.
|
||||
"""
|
||||
cache_key = GITHUB_CACHE_KEY % f"release:{version_str}"
|
||||
release = cache.get(cache_key)
|
||||
if release is not None:
|
||||
return release
|
||||
data = _fetch_github_releases_json(f"{GITHUB_RELEASES_URL}/tags/v{version_str}")
|
||||
if data is None:
|
||||
return None
|
||||
try:
|
||||
release = _parse_github_release(data)
|
||||
except (KeyError, TypeError, AttributeError) as e:
|
||||
logger.debug(f"An error occurred parsing GitHub release json: {e}")
|
||||
return None
|
||||
if release is not None:
|
||||
cache.set(cache_key, release, GITHUB_RELEASES_CACHE_TIMEOUT)
|
||||
return release
|
||||
|
||||
|
||||
def get_github_releases(
|
||||
since: packaging_version.Version,
|
||||
until: packaging_version.Version,
|
||||
) -> list[dict[str, Any]] | None:
|
||||
"""
|
||||
Fetch pngx releases from GitHub after `since` up to and including `until`,
|
||||
newest first.
|
||||
"""
|
||||
# Keyed on the range so an upgrade (pill) or a newly detected release
|
||||
# (update available) changes `until` and gets a fresh fetch
|
||||
cache_key = GITHUB_CACHE_KEY % f"releases:{since}:{until}"
|
||||
releases = cache.get(cache_key)
|
||||
if releases is not None:
|
||||
return releases
|
||||
releases = []
|
||||
# Releases are listed newest first, so stop paging once we reach `since`
|
||||
for page in range(1, GITHUB_RELEASES_MAX_PAGES + 1):
|
||||
data = _fetch_github_releases_json(
|
||||
GITHUB_RELEASES_URL,
|
||||
params={"per_page": GITHUB_RELEASES_PER_PAGE, "page": page},
|
||||
)
|
||||
if data is None:
|
||||
return None
|
||||
try:
|
||||
batch = [r for r in map(_parse_github_release, data) if r is not None]
|
||||
except (KeyError, TypeError, AttributeError) as e:
|
||||
logger.debug(f"An error occurred parsing GitHub releases json: {e}")
|
||||
return None
|
||||
releases.extend(batch)
|
||||
if len(data) < GITHUB_RELEASES_PER_PAGE or any(
|
||||
packaging_version.parse(r["version"]) <= since for r in batch
|
||||
):
|
||||
break
|
||||
releases = [
|
||||
r for r in releases if since < packaging_version.parse(r["version"]) <= until
|
||||
]
|
||||
cache.set(cache_key, releases, GITHUB_RELEASES_CACHE_TIMEOUT)
|
||||
return releases
|
||||
|
||||
|
||||
def get_github_stars() -> int | None:
|
||||
"""
|
||||
Fetch the number of stars for the Paperless-NGX repository from GitHub.
|
||||
"""
|
||||
count = cache.get(GITHUB_CACHE_KEY % "stars")
|
||||
if count is not None:
|
||||
return count
|
||||
try:
|
||||
resp = httpx.get(
|
||||
"https://api.github.com/repos/paperless-ngx/paperless-ngx",
|
||||
headers={"Accept": "application/vnd.github+json"},
|
||||
timeout=GITHUB_REQUEST_TIMEOUT,
|
||||
)
|
||||
resp.raise_for_status()
|
||||
count = resp.json()["stargazers_count"]
|
||||
except Exception as e:
|
||||
logger.debug(f"An error occurred fetching GitHub stars: {e}")
|
||||
return None
|
||||
cache.set(GITHUB_CACHE_KEY % "stars", count, 60 * 60)
|
||||
return count
|
||||
|
||||
|
||||
@extend_schema_view(
|
||||
get=extend_schema(
|
||||
description="Get the current version of the Paperless-NGX server",
|
||||
@@ -4361,6 +4494,61 @@ class RemoteVersionView(GenericAPIView[Any]):
|
||||
)
|
||||
|
||||
|
||||
@extend_schema_view(
|
||||
get=extend_schema(
|
||||
description=(
|
||||
"Get release notes from GitHub for releases newer than `since`, "
|
||||
"up to and including `until` (default: the running version). "
|
||||
"Without `since`, only the `until` version's notes are returned."
|
||||
),
|
||||
parameters=[
|
||||
OpenApiParameter(
|
||||
name="since",
|
||||
type=OpenApiTypes.STR,
|
||||
location=OpenApiParameter.QUERY,
|
||||
required=False,
|
||||
),
|
||||
OpenApiParameter(
|
||||
name="until",
|
||||
type=OpenApiTypes.STR,
|
||||
location=OpenApiParameter.QUERY,
|
||||
required=False,
|
||||
),
|
||||
],
|
||||
responses={
|
||||
(200, "application/json"): OpenApiTypes.OBJECT,
|
||||
},
|
||||
),
|
||||
)
|
||||
class ReleaseNotesView(GenericAPIView[Any]):
|
||||
def get(self, request, format=None):
|
||||
current_version = packaging_version.parse(version.__full_version_str__)
|
||||
since = until = None
|
||||
try:
|
||||
if since_param := request.query_params.get("since"):
|
||||
since = packaging_version.parse(since_param)
|
||||
if until_param := request.query_params.get("until"):
|
||||
until = packaging_version.parse(until_param)
|
||||
except packaging_version.InvalidVersion:
|
||||
return HttpResponseBadRequest("Invalid version")
|
||||
# Newer releases can be requested e.g. for "update available"
|
||||
until = until or current_version
|
||||
|
||||
if since is None:
|
||||
release = get_github_release(str(until))
|
||||
releases = [release] if release else []
|
||||
else:
|
||||
releases = get_github_releases(since, until) or []
|
||||
|
||||
return Response(
|
||||
{
|
||||
"version": version.__full_version_str__,
|
||||
"releases": releases,
|
||||
"stars": get_github_stars(),
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
class _TasksViewSetSchema(AutoSchema):
|
||||
_UNPAGINATED_ACTIONS = frozenset({"summary", "active", "status_counts"})
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@ from documents.views import LogViewSet
|
||||
from documents.views import MergeDocumentsAsVersionsView
|
||||
from documents.views import MergeDocumentsView
|
||||
from documents.views import PostDocumentView
|
||||
from documents.views import ReleaseNotesView
|
||||
from documents.views import RemoteVersionView
|
||||
from documents.views import RemovePasswordDocumentsView
|
||||
from documents.views import ReprocessDocumentsView
|
||||
@@ -219,6 +220,11 @@ urlpatterns = [
|
||||
RemoteVersionView.as_view(),
|
||||
name="remoteversion",
|
||||
),
|
||||
re_path(
|
||||
"^release_notes/",
|
||||
ReleaseNotesView.as_view(),
|
||||
name="release_notes",
|
||||
),
|
||||
re_path(
|
||||
"^ui_settings/",
|
||||
UiSettingsView.as_view(),
|
||||
|
||||
Reference in new issue
Block a user