mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-07-28 18:24:38 -05:00
Feature: Share links (#3996)
* Implement share links Basic implementation of share links Make certain share link fields not editable, automatically grant permissions on migrate Updated styling, error messages from expired / deleted links frontend code linting, reversable sharelink migration testing coverage Update translation strings No links message * Consolidate file response methods * improvements to share links on mobile devices * Refactor share links file_version * Add docs for share links * Apply suggestions from code review * When filtering share links, use the timezone aware now() * Removes extra call to setup directories for usage in testing * FIx copied badge display on some browsers * Move copy to ngx-clipboard library --------- Co-authored-by: Trenton H <797416+stumpylog@users.noreply.github.com>
This commit is contained in:
@@ -10,7 +10,7 @@ export abstract class AbstractPaperlessService<T extends ObjectWithId> {
|
||||
|
||||
constructor(
|
||||
protected http: HttpClient,
|
||||
private resourceName: string
|
||||
protected resourceName: string
|
||||
) {}
|
||||
|
||||
protected getResourceUrl(id: number = null, action: string = null): string {
|
||||
|
42
src-ui/src/app/services/rest/share-link.service.spec.ts
Normal file
42
src-ui/src/app/services/rest/share-link.service.spec.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import { HttpTestingController } from '@angular/common/http/testing'
|
||||
import { TestBed } from '@angular/core/testing'
|
||||
import { Subscription } from 'rxjs'
|
||||
import { environment } from 'src/environments/environment'
|
||||
import { commonAbstractPaperlessServiceTests } from './abstract-paperless-service.spec'
|
||||
import { ShareLinkService } from './share-link.service'
|
||||
|
||||
let httpTestingController: HttpTestingController
|
||||
let service: ShareLinkService
|
||||
let subscription: Subscription
|
||||
const endpoint = 'share_links'
|
||||
|
||||
// run common tests
|
||||
commonAbstractPaperlessServiceTests(endpoint, ShareLinkService)
|
||||
|
||||
describe(`Additional service tests for ShareLinkService`, () => {
|
||||
beforeEach(() => {
|
||||
// Dont need to setup again
|
||||
|
||||
httpTestingController = TestBed.inject(HttpTestingController)
|
||||
service = TestBed.inject(ShareLinkService)
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
subscription?.unsubscribe()
|
||||
httpTestingController.verify()
|
||||
})
|
||||
|
||||
it('should support creating link for document', () => {
|
||||
subscription = service.createLinkForDocument(0).subscribe()
|
||||
httpTestingController
|
||||
.expectOne(`${environment.apiBaseUrl}${endpoint}/`)
|
||||
.flush({})
|
||||
})
|
||||
|
||||
it('should support get links for a document', () => {
|
||||
subscription = service.getLinksForDocument(0).subscribe()
|
||||
httpTestingController
|
||||
.expectOne(`${environment.apiBaseUrl}documents/0/${endpoint}/`)
|
||||
.flush({})
|
||||
})
|
||||
})
|
36
src-ui/src/app/services/rest/share-link.service.ts
Normal file
36
src-ui/src/app/services/rest/share-link.service.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import { Injectable } from '@angular/core'
|
||||
import {
|
||||
PaperlessShareLink,
|
||||
PaperlessFileVersion,
|
||||
} from 'src/app/data/paperless-share-link'
|
||||
import { AbstractNameFilterService } from './abstract-name-filter-service'
|
||||
import { HttpClient } from '@angular/common/http'
|
||||
import { Observable } from 'rxjs'
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class ShareLinkService extends AbstractNameFilterService<PaperlessShareLink> {
|
||||
constructor(http: HttpClient) {
|
||||
super(http, 'share_links')
|
||||
}
|
||||
|
||||
getLinksForDocument(documentId: number): Observable<PaperlessShareLink[]> {
|
||||
return this.http.get<PaperlessShareLink[]>(
|
||||
`${this.baseUrl}documents/${documentId}/${this.resourceName}/`
|
||||
)
|
||||
}
|
||||
|
||||
createLinkForDocument(
|
||||
documentId: number,
|
||||
file_version: PaperlessFileVersion = PaperlessFileVersion.Archive,
|
||||
expiration: Date = null
|
||||
) {
|
||||
this.clearCache()
|
||||
return this.http.post<PaperlessShareLink>(this.getResourceUrl(), {
|
||||
document: documentId,
|
||||
file_version,
|
||||
expiration: expiration?.toISOString(),
|
||||
})
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user