Fix: disable toggle for share link creation without archive version, fix auto-copy in Safari (#4885)

* Fix: disable share link archive switch if archive version doesnt exist

* Fix: Add brief timeout before copy after share link creation for Safari, only show if succeeded

* Update messages.xlf
This commit is contained in:
shamoon 2023-12-07 13:48:33 -08:00 committed by GitHub
parent 5cd17e71e2
commit 5942cd6cd2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 65 additions and 39 deletions

View File

@ -247,18 +247,18 @@
<source>Document <x id="PH" equiv-text="status.filename"/> was added to Paperless-ngx.</source> <source>Document <x id="PH" equiv-text="status.filename"/> was added to Paperless-ngx.</source>
<context-group purpose="location"> <context-group purpose="location">
<context context-type="sourcefile">src/app/app.component.ts</context> <context context-type="sourcefile">src/app/app.component.ts</context>
<context context-type="linenumber">83</context> <context context-type="linenumber">81</context>
</context-group> </context-group>
<context-group purpose="location"> <context-group purpose="location">
<context context-type="sourcefile">src/app/app.component.ts</context> <context context-type="sourcefile">src/app/app.component.ts</context>
<context context-type="linenumber">92</context> <context context-type="linenumber">90</context>
</context-group> </context-group>
</trans-unit> </trans-unit>
<trans-unit id="1931214133925051574" datatype="html"> <trans-unit id="1931214133925051574" datatype="html">
<source>Open document</source> <source>Open document</source>
<context-group purpose="location"> <context-group purpose="location">
<context context-type="sourcefile">src/app/app.component.ts</context> <context context-type="sourcefile">src/app/app.component.ts</context>
<context context-type="linenumber">85</context> <context context-type="linenumber">83</context>
</context-group> </context-group>
<context-group purpose="location"> <context-group purpose="location">
<context context-type="sourcefile">src/app/components/dashboard/widgets/upload-file-widget/upload-file-widget.component.html</context> <context context-type="sourcefile">src/app/components/dashboard/widgets/upload-file-widget/upload-file-widget.component.html</context>
@ -269,28 +269,28 @@
<source>Could not add <x id="PH" equiv-text="status.filename"/>: <x id="PH_1" equiv-text="status.message"/></source> <source>Could not add <x id="PH" equiv-text="status.filename"/>: <x id="PH_1" equiv-text="status.message"/></source>
<context-group purpose="location"> <context-group purpose="location">
<context context-type="sourcefile">src/app/app.component.ts</context> <context context-type="sourcefile">src/app/app.component.ts</context>
<context context-type="linenumber">107</context> <context context-type="linenumber">105</context>
</context-group> </context-group>
</trans-unit> </trans-unit>
<trans-unit id="1218124467712564468" datatype="html"> <trans-unit id="1218124467712564468" datatype="html">
<source>Document <x id="PH" equiv-text="status.filename"/> is being processed by Paperless-ngx.</source> <source>Document <x id="PH" equiv-text="status.filename"/> is being processed by Paperless-ngx.</source>
<context-group purpose="location"> <context-group purpose="location">
<context context-type="sourcefile">src/app/app.component.ts</context> <context context-type="sourcefile">src/app/app.component.ts</context>
<context context-type="linenumber">122</context> <context context-type="linenumber">120</context>
</context-group> </context-group>
</trans-unit> </trans-unit>
<trans-unit id="2501522447884928778" datatype="html"> <trans-unit id="2501522447884928778" datatype="html">
<source>Prev</source> <source>Prev</source>
<context-group purpose="location"> <context-group purpose="location">
<context context-type="sourcefile">src/app/app.component.ts</context> <context context-type="sourcefile">src/app/app.component.ts</context>
<context context-type="linenumber">128</context> <context context-type="linenumber">126</context>
</context-group> </context-group>
</trans-unit> </trans-unit>
<trans-unit id="3885497195825665706" datatype="html"> <trans-unit id="3885497195825665706" datatype="html">
<source>Next</source> <source>Next</source>
<context-group purpose="location"> <context-group purpose="location">
<context context-type="sourcefile">src/app/app.component.ts</context> <context context-type="sourcefile">src/app/app.component.ts</context>
<context context-type="linenumber">129</context> <context context-type="linenumber">127</context>
</context-group> </context-group>
<context-group purpose="location"> <context-group purpose="location">
<context context-type="sourcefile">src/app/components/document-detail/document-detail.component.html</context> <context context-type="sourcefile">src/app/components/document-detail/document-detail.component.html</context>
@ -301,98 +301,98 @@
<source>End</source> <source>End</source>
<context-group purpose="location"> <context-group purpose="location">
<context context-type="sourcefile">src/app/app.component.ts</context> <context context-type="sourcefile">src/app/app.component.ts</context>
<context context-type="linenumber">130</context> <context context-type="linenumber">128</context>
</context-group> </context-group>
</trans-unit> </trans-unit>
<trans-unit id="3909462337752654810" datatype="html"> <trans-unit id="3909462337752654810" datatype="html">
<source>The dashboard can be used to show saved views, such as an &apos;Inbox&apos;. Those settings are found under Settings &gt; Saved Views once you have created some.</source> <source>The dashboard can be used to show saved views, such as an &apos;Inbox&apos;. Those settings are found under Settings &gt; Saved Views once you have created some.</source>
<context-group purpose="location"> <context-group purpose="location">
<context context-type="sourcefile">src/app/app.component.ts</context> <context context-type="sourcefile">src/app/app.component.ts</context>
<context context-type="linenumber">136</context> <context context-type="linenumber">134</context>
</context-group> </context-group>
</trans-unit> </trans-unit>
<trans-unit id="9075755296812854717" datatype="html"> <trans-unit id="9075755296812854717" datatype="html">
<source>Drag-and-drop documents here to start uploading or place them in the consume folder. You can also drag-and-drop documents anywhere on all other pages of the web app. Once you do, Paperless-ngx will start training its machine learning algorithms.</source> <source>Drag-and-drop documents here to start uploading or place them in the consume folder. You can also drag-and-drop documents anywhere on all other pages of the web app. Once you do, Paperless-ngx will start training its machine learning algorithms.</source>
<context-group purpose="location"> <context-group purpose="location">
<context context-type="sourcefile">src/app/app.component.ts</context> <context context-type="sourcefile">src/app/app.component.ts</context>
<context context-type="linenumber">143</context> <context context-type="linenumber">141</context>
</context-group> </context-group>
</trans-unit> </trans-unit>
<trans-unit id="7495498057594070122" datatype="html"> <trans-unit id="7495498057594070122" datatype="html">
<source>The documents list shows all of your documents and allows for filtering as well as bulk-editing. There are three different view styles: list, small cards and large cards. A list of documents currently opened for editing is shown in the sidebar.</source> <source>The documents list shows all of your documents and allows for filtering as well as bulk-editing. There are three different view styles: list, small cards and large cards. A list of documents currently opened for editing is shown in the sidebar.</source>
<context-group purpose="location"> <context-group purpose="location">
<context context-type="sourcefile">src/app/app.component.ts</context> <context context-type="sourcefile">src/app/app.component.ts</context>
<context context-type="linenumber">148</context> <context context-type="linenumber">146</context>
</context-group> </context-group>
</trans-unit> </trans-unit>
<trans-unit id="1334220418719920556" datatype="html"> <trans-unit id="1334220418719920556" datatype="html">
<source>The filtering tools allow you to quickly find documents using various searches, dates, tags, etc.</source> <source>The filtering tools allow you to quickly find documents using various searches, dates, tags, etc.</source>
<context-group purpose="location"> <context-group purpose="location">
<context context-type="sourcefile">src/app/app.component.ts</context> <context context-type="sourcefile">src/app/app.component.ts</context>
<context context-type="linenumber">155</context> <context context-type="linenumber">153</context>
</context-group> </context-group>
</trans-unit> </trans-unit>
<trans-unit id="5427326625898532358" datatype="html"> <trans-unit id="5427326625898532358" datatype="html">
<source>Any combination of filters can be saved as a &apos;view&apos; which can then be displayed on the dashboard and / or sidebar.</source> <source>Any combination of filters can be saved as a &apos;view&apos; which can then be displayed on the dashboard and / or sidebar.</source>
<context-group purpose="location"> <context-group purpose="location">
<context context-type="sourcefile">src/app/app.component.ts</context> <context context-type="sourcefile">src/app/app.component.ts</context>
<context context-type="linenumber">161</context> <context context-type="linenumber">159</context>
</context-group> </context-group>
</trans-unit> </trans-unit>
<trans-unit id="2804886236408698479" datatype="html"> <trans-unit id="2804886236408698479" datatype="html">
<source>Tags, correspondents, document types and storage paths can all be managed using these pages. They can also be created from the document edit view.</source> <source>Tags, correspondents, document types and storage paths can all be managed using these pages. They can also be created from the document edit view.</source>
<context-group purpose="location"> <context-group purpose="location">
<context context-type="sourcefile">src/app/app.component.ts</context> <context context-type="sourcefile">src/app/app.component.ts</context>
<context context-type="linenumber">166</context> <context context-type="linenumber">164</context>
</context-group> </context-group>
</trans-unit> </trans-unit>
<trans-unit id="7851939076947092983" datatype="html"> <trans-unit id="7851939076947092983" datatype="html">
<source>Manage e-mail accounts and rules for automatically importing documents.</source> <source>Manage e-mail accounts and rules for automatically importing documents.</source>
<context-group purpose="location"> <context-group purpose="location">
<context context-type="sourcefile">src/app/app.component.ts</context> <context context-type="sourcefile">src/app/app.component.ts</context>
<context context-type="linenumber">174</context> <context context-type="linenumber">172</context>
</context-group> </context-group>
</trans-unit> </trans-unit>
<trans-unit id="1347174817382304718" datatype="html"> <trans-unit id="1347174817382304718" datatype="html">
<source>Consumption templates give you finer control over the document ingestion process.</source> <source>Consumption templates give you finer control over the document ingestion process.</source>
<context-group purpose="location"> <context-group purpose="location">
<context context-type="sourcefile">src/app/app.component.ts</context> <context context-type="sourcefile">src/app/app.component.ts</context>
<context context-type="linenumber">182</context> <context context-type="linenumber">180</context>
</context-group> </context-group>
</trans-unit> </trans-unit>
<trans-unit id="4680387114119209483" datatype="html"> <trans-unit id="4680387114119209483" datatype="html">
<source>File Tasks shows you documents that have been consumed, are waiting to be, or may have failed during the process.</source> <source>File Tasks shows you documents that have been consumed, are waiting to be, or may have failed during the process.</source>
<context-group purpose="location"> <context-group purpose="location">
<context context-type="sourcefile">src/app/app.component.ts</context> <context context-type="sourcefile">src/app/app.component.ts</context>
<context context-type="linenumber">190</context> <context context-type="linenumber">188</context>
</context-group> </context-group>
</trans-unit> </trans-unit>
<trans-unit id="1453710303796913192" datatype="html"> <trans-unit id="1453710303796913192" datatype="html">
<source>Check out the settings for various tweaks to the web app and toggle settings for saved views.</source> <source>Check out the settings for various tweaks to the web app and toggle settings for saved views.</source>
<context-group purpose="location"> <context-group purpose="location">
<context context-type="sourcefile">src/app/app.component.ts</context> <context context-type="sourcefile">src/app/app.component.ts</context>
<context context-type="linenumber">198</context> <context context-type="linenumber">196</context>
</context-group> </context-group>
</trans-unit> </trans-unit>
<trans-unit id="7172877665285340082" datatype="html"> <trans-unit id="7172877665285340082" datatype="html">
<source>Thank you! 🙏</source> <source>Thank you! 🙏</source>
<context-group purpose="location"> <context-group purpose="location">
<context context-type="sourcefile">src/app/app.component.ts</context> <context context-type="sourcefile">src/app/app.component.ts</context>
<context context-type="linenumber">206</context> <context context-type="linenumber">204</context>
</context-group> </context-group>
</trans-unit> </trans-unit>
<trans-unit id="7354947513482088740" datatype="html"> <trans-unit id="7354947513482088740" datatype="html">
<source>There are &lt;em&gt;tons&lt;/em&gt; more features and info we didn&apos;t cover here, but this should get you started. Check out the documentation or visit the project on GitHub to learn more or to report issues.</source> <source>There are &lt;em&gt;tons&lt;/em&gt; more features and info we didn&apos;t cover here, but this should get you started. Check out the documentation or visit the project on GitHub to learn more or to report issues.</source>
<context-group purpose="location"> <context-group purpose="location">
<context context-type="sourcefile">src/app/app.component.ts</context> <context context-type="sourcefile">src/app/app.component.ts</context>
<context context-type="linenumber">208</context> <context context-type="linenumber">206</context>
</context-group> </context-group>
</trans-unit> </trans-unit>
<trans-unit id="4270528545616947218" datatype="html"> <trans-unit id="4270528545616947218" datatype="html">
<source>Lastly, on behalf of every contributor to this community-supported project, thank you for using Paperless-ngx!</source> <source>Lastly, on behalf of every contributor to this community-supported project, thank you for using Paperless-ngx!</source>
<context-group purpose="location"> <context-group purpose="location">
<context context-type="sourcefile">src/app/app.component.ts</context> <context context-type="sourcefile">src/app/app.component.ts</context>
<context context-type="linenumber">210</context> <context context-type="linenumber">208</context>
</context-group> </context-group>
</trans-unit> </trans-unit>
<trans-unit id="4804785061014590286" datatype="html"> <trans-unit id="4804785061014590286" datatype="html">
@ -3884,7 +3884,7 @@
</context-group> </context-group>
<context-group purpose="location"> <context-group purpose="location">
<context context-type="sourcefile">src/app/components/common/share-links-dropdown/share-links-dropdown.component.ts</context> <context context-type="sourcefile">src/app/components/common/share-links-dropdown/share-links-dropdown.component.ts</context>
<context context-type="linenumber">93</context> <context context-type="linenumber">97</context>
</context-group> </context-group>
</trans-unit> </trans-unit>
<trans-unit id="8542568275115626925" datatype="html"> <trans-unit id="8542568275115626925" datatype="html">
@ -3912,28 +3912,28 @@
<source>Error retrieving links</source> <source>Error retrieving links</source>
<context-group purpose="location"> <context-group purpose="location">
<context context-type="sourcefile">src/app/components/common/share-links-dropdown/share-links-dropdown.component.ts</context> <context context-type="sourcefile">src/app/components/common/share-links-dropdown/share-links-dropdown.component.ts</context>
<context context-type="linenumber">74</context> <context context-type="linenumber">78</context>
</context-group> </context-group>
</trans-unit> </trans-unit>
<trans-unit id="3242255798983858463" datatype="html"> <trans-unit id="3242255798983858463" datatype="html">
<source><x id="PH" equiv-text="days"/> days</source> <source><x id="PH" equiv-text="days"/> days</source>
<context-group purpose="location"> <context-group purpose="location">
<context context-type="sourcefile">src/app/components/common/share-links-dropdown/share-links-dropdown.component.ts</context> <context context-type="sourcefile">src/app/components/common/share-links-dropdown/share-links-dropdown.component.ts</context>
<context context-type="linenumber">93</context> <context context-type="linenumber">97</context>
</context-group> </context-group>
</trans-unit> </trans-unit>
<trans-unit id="2897042887615940599" datatype="html"> <trans-unit id="2897042887615940599" datatype="html">
<source>Error deleting link</source> <source>Error deleting link</source>
<context-group purpose="location"> <context-group purpose="location">
<context context-type="sourcefile">src/app/components/common/share-links-dropdown/share-links-dropdown.component.ts</context> <context context-type="sourcefile">src/app/components/common/share-links-dropdown/share-links-dropdown.component.ts</context>
<context context-type="linenumber">120</context> <context context-type="linenumber">126</context>
</context-group> </context-group>
</trans-unit> </trans-unit>
<trans-unit id="8400747326190565173" datatype="html"> <trans-unit id="8400747326190565173" datatype="html">
<source>Error creating link</source> <source>Error creating link</source>
<context-group purpose="location"> <context-group purpose="location">
<context context-type="sourcefile">src/app/components/common/share-links-dropdown/share-links-dropdown.component.ts</context> <context context-type="sourcefile">src/app/components/common/share-links-dropdown/share-links-dropdown.component.ts</context>
<context context-type="linenumber">148</context> <context context-type="linenumber">156</context>
</context-group> </context-group>
</trans-unit> </trans-unit>
<trans-unit id="5611592591303869712" datatype="html"> <trans-unit id="5611592591303869712" datatype="html">

View File

@ -38,7 +38,7 @@
<li class="list-group-item pt-3 pb-2"> <li class="list-group-item pt-3 pb-2">
<div class="input-group input-group-sm w-100"> <div class="input-group input-group-sm w-100">
<div class="form-check form-switch ms-auto"> <div class="form-check form-switch ms-auto">
<input class="form-check-input" type="checkbox" role="switch" id="versionSwitch" [(ngModel)]="archiveVersion"> <input class="form-check-input" type="checkbox" role="switch" id="versionSwitch" [disabled]="!hasArchiveVersion" [(ngModel)]="useArchiveVersion">
<label class="form-check-label small" for="versionSwitch" i18n>Share archive version</label> <label class="form-check-label small" for="versionSwitch" i18n>Share archive version</label>
</div> </div>
</div> </div>

View File

@ -19,6 +19,7 @@ import { ToastService } from 'src/app/services/toast.service'
import { environment } from 'src/environments/environment' import { environment } from 'src/environments/environment'
import { ShareLinksDropdownComponent } from './share-links-dropdown.component' import { ShareLinksDropdownComponent } from './share-links-dropdown.component'
import { Clipboard } from '@angular/cdk/clipboard' import { Clipboard } from '@angular/cdk/clipboard'
import { By } from '@angular/platform-browser'
describe('ShareLinksDropdownComponent', () => { describe('ShareLinksDropdownComponent', () => {
let component: ShareLinksDropdownComponent let component: ShareLinksDropdownComponent
@ -88,7 +89,7 @@ describe('ShareLinksDropdownComponent', () => {
.mockReturnValueOnce(throwError(() => new Error('Unable to get links'))) .mockReturnValueOnce(throwError(() => new Error('Unable to get links')))
component.documentId = 99 component.documentId = 99
component.refresh() component.ngOnInit()
fixture.detectChanges() fixture.detectChanges()
expect(toastSpy).toHaveBeenCalled() expect(toastSpy).toHaveBeenCalled()
}) })
@ -97,12 +98,13 @@ describe('ShareLinksDropdownComponent', () => {
const createSpy = jest.spyOn(shareLinkService, 'createLinkForDocument') const createSpy = jest.spyOn(shareLinkService, 'createLinkForDocument')
component.documentId = 99 component.documentId = 99
component.expirationDays = 7 component.expirationDays = 7
component.archiveVersion = false component.useArchiveVersion = false
const expiration = new Date() const expiration = new Date()
expiration.setDate(expiration.getDate() + 7) expiration.setDate(expiration.getDate() + 7)
const copySpy = jest.spyOn(clipboard, 'copy') const copySpy = jest.spyOn(clipboard, 'copy')
copySpy.mockReturnValue(true)
const refreshSpy = jest.spyOn(component, 'refresh') const refreshSpy = jest.spyOn(component, 'refresh')
component.createLink() component.createLink()
@ -117,8 +119,10 @@ describe('ShareLinksDropdownComponent', () => {
fixture.detectChanges() fixture.detectChanges()
tick(3000) tick(3000)
expect(copySpy).toHaveBeenCalled()
expect(refreshSpy).toHaveBeenCalled() expect(refreshSpy).toHaveBeenCalled()
expect(copySpy).toHaveBeenCalled()
expect(component.copied).toEqual(1)
tick(100) // copy timeout
})) }))
it('should show error on link creation if needed', () => { it('should show error on link creation if needed', () => {
@ -212,4 +216,16 @@ describe('ShareLinksDropdownComponent', () => {
'http://example.domainwithapiinit.com:1234/subpath/share/123abc123' 'http://example.domainwithapiinit.com:1234/subpath/share/123abc123'
) )
}) })
it('should disable archive switch & option if no archive available', () => {
component.hasArchiveVersion = false
component.ngOnInit()
fixture.detectChanges()
expect(component.useArchiveVersion).toBeFalsy()
expect(
fixture.debugElement.query(By.css("input[type='checkbox']")).attributes[
'ng-reflect-is-disabled'
]
).toBeTruthy()
})
}) })

View File

@ -38,6 +38,9 @@ export class ShareLinksDropdownComponent implements OnInit {
@Input() @Input()
disabled: boolean = false disabled: boolean = false
@Input()
hasArchiveVersion: boolean = true
shareLinks: PaperlessShareLink[] shareLinks: PaperlessShareLink[]
loading: boolean = false loading: boolean = false
@ -46,7 +49,7 @@ export class ShareLinksDropdownComponent implements OnInit {
expirationDays: number = 7 expirationDays: number = 7
archiveVersion: boolean = true useArchiveVersion: boolean = true
constructor( constructor(
private shareLinkService: ShareLinkService, private shareLinkService: ShareLinkService,
@ -56,6 +59,7 @@ export class ShareLinksDropdownComponent implements OnInit {
ngOnInit(): void { ngOnInit(): void {
if (this._documentId !== undefined) this.refresh() if (this._documentId !== undefined) this.refresh()
this.useArchiveVersion = this.hasArchiveVersion
} }
refresh() { refresh() {
@ -94,11 +98,13 @@ export class ShareLinksDropdownComponent implements OnInit {
} }
copy(link: PaperlessShareLink) { copy(link: PaperlessShareLink) {
this.clipboard.copy(this.getShareUrl(link)) const success = this.clipboard.copy(this.getShareUrl(link))
this.copied = link.id if (success) {
setTimeout(() => { this.copied = link.id
this.copied = null setTimeout(() => {
}, 3000) this.copied = null
}, 3000)
}
} }
canShare(link: PaperlessShareLink): boolean { canShare(link: PaperlessShareLink): boolean {
@ -132,7 +138,7 @@ export class ShareLinksDropdownComponent implements OnInit {
this.shareLinkService this.shareLinkService
.createLinkForDocument( .createLinkForDocument(
this._documentId, this._documentId,
this.archiveVersion this.useArchiveVersion
? PaperlessFileVersion.Archive ? PaperlessFileVersion.Archive
: PaperlessFileVersion.Original, : PaperlessFileVersion.Original,
expiration expiration
@ -140,7 +146,9 @@ export class ShareLinksDropdownComponent implements OnInit {
.subscribe({ .subscribe({
next: (result) => { next: (result) => {
this.loading = false this.loading = false
this.copy(result) setTimeout(() => {
this.copy(result)
}, 10)
this.refresh() this.refresh()
}, },
error: (e) => { error: (e) => {

View File

@ -69,7 +69,7 @@
(added)="addField($event)"> (added)="addField($event)">
</pngx-custom-fields-dropdown> </pngx-custom-fields-dropdown>
<pngx-share-links-dropdown [documentId]="documentId" [disabled]="!userIsOwner" *pngxIfPermissions="{ action: PermissionAction.Add, type: PermissionType.ShareLink }"></pngx-share-links-dropdown> <pngx-share-links-dropdown [documentId]="documentId" [hasArchiveVersion]="!!document?.archived_file_name" [disabled]="!userIsOwner" *pngxIfPermissions="{ action: PermissionAction.Add, type: PermissionType.ShareLink }"></pngx-share-links-dropdown>
</pngx-page-header> </pngx-page-header>
<div class="row"> <div class="row">

View File

@ -50,6 +50,8 @@ export interface PaperlessDocument extends ObjectWithPermissions {
original_file_name?: string original_file_name?: string
archived_file_name?: string
download_url?: string download_url?: string
thumbnail_url?: string thumbnail_url?: string