Skip to content

Commit

Permalink
feat: reflect django permissions on UI
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaaybi committed Nov 11, 2022
1 parent 1dc2717 commit 4603813
Show file tree
Hide file tree
Showing 24 changed files with 301 additions and 113 deletions.
63 changes: 55 additions & 8 deletions src-ui/src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { DocumentAsnComponent } from './components/document-asn/document-asn.com
import { DirtyFormGuard } from './guards/dirty-form.guard'
import { StoragePathListComponent } from './components/manage/storage-path-list/storage-path-list.component'
import { TasksComponent } from './components/manage/tasks/tasks.component'
import { AuthGard } from './guards/auth.gard'
import { DirtyDocGuard } from './guards/dirty-doc.guard'
import { DirtySavedViewGuard } from './guards/dirty-saved-view.guard'

Expand All @@ -29,25 +30,71 @@ const routes: Routes = [
path: 'documents',
component: DocumentListComponent,
canDeactivate: [DirtySavedViewGuard],
canActivate: [AuthGard],
data: { requiredPermission: 'documents.view_document' },
},
{
path: 'view/:id',
component: DocumentListComponent,
canDeactivate: [DirtySavedViewGuard],
canActivate: [AuthGard],
data: { requiredPermission: 'documents.view_savedview' },
},
{
path: 'documents/:id',
component: DocumentDetailComponent,
canActivate: [AuthGard],
data: { requiredPermission: 'documents.view_document' },
},
{
path: 'asn/:id',
component: DocumentAsnComponent,
canActivate: [AuthGard],
data: { requiredPermission: 'documents.view_document' },
},
{
path: 'tags',
component: TagListComponent,
canActivate: [AuthGard],
data: { requiredPermission: 'documents.view_tag' },
},
{
path: 'documenttypes',
component: DocumentTypeListComponent,
canActivate: [AuthGard],
data: { requiredPermission: 'documents.view_documenttype' },
},
{
path: 'correspondents',
component: CorrespondentListComponent,
canActivate: [AuthGard],
data: { requiredPermission: 'documents.view_correspondent' },
},
{
path: 'storagepaths',
component: StoragePathListComponent,
canActivate: [AuthGard],
data: { requiredPermission: 'documents.view_storagepath' },
},
{
path: 'logs',
component: LogsComponent,
canActivate: [AuthGard],
data: { requiredPermission: 'documents.view_log' },
},
{ path: 'documents/:id', component: DocumentDetailComponent },
{ path: 'asn/:id', component: DocumentAsnComponent },
{ path: 'tags', component: TagListComponent },
{ path: 'documenttypes', component: DocumentTypeListComponent },
{ path: 'correspondents', component: CorrespondentListComponent },
{ path: 'storagepaths', component: StoragePathListComponent },
{ path: 'logs', component: LogsComponent },
{
path: 'settings',
component: SettingsComponent,
canDeactivate: [DirtyFormGuard],
canActivate: [AuthGard],
data: { requiredPermission: 'documents.view_uisettings' },
},
{
path: 'tasks',
component: TasksComponent,
canActivate: [AuthGard],
data: { requiredPermission: 'documents.view_paperlesstask' },
},
{ path: 'tasks', component: TasksComponent },
],
},

Expand Down
35 changes: 26 additions & 9 deletions src-ui/src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,27 @@ export class AppComponent implements OnInit, OnDestroy {
if (
this.showNotification(SETTINGS_KEYS.NOTIFICATIONS_CONSUMER_SUCCESS)
) {
this.toastService.show({
title: $localize`Document added`,
delay: 10000,
content: $localize`Document ${status.filename} was added to paperless.`,
actionName: $localize`Open document`,
action: () => {
this.router.navigate(['documents', status.documentId])
},
// TODO - Is this the only way to allow/disallow from permissions?
var canOpenDocuments = false
this.settings.permissions().subscribe((perm) => {
canOpenDocuments = perm.includes('documents.view_document')
})
if (canOpenDocuments)
this.toastService.show({
title: $localize`Document added`,
delay: 10000,
content: $localize`Document ${status.filename} was added to paperless.`,
actionName: $localize`Open document`,
action: () => {
this.router.navigate(['documents', status.documentId])
},
})
else
this.toastService.show({
title: $localize`Document added`,
delay: 10000,
content: $localize`Document ${status.filename} was added to paperless.`,
})
}
})

Expand Down Expand Up @@ -199,7 +211,12 @@ export class AppComponent implements OnInit, OnDestroy {
}

public get dragDropEnabled(): boolean {
return !this.router.url.includes('dashboard')
// TODO - Is this the only way to allow/disallow from permissions?
var canAddDocuments = false
this.settings.permissions().subscribe((perm) => {
canAddDocuments = perm.includes('documents.add_document')
})
return !this.router.url.includes('dashboard') && canAddDocuments
}

public fileOver() {
Expand Down
4 changes: 4 additions & 0 deletions src-ui/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import { SelectComponent } from './components/common/input/select/select.compone
import { CheckComponent } from './components/common/input/check/check.component'
import { SaveViewConfigDialogComponent } from './components/document-list/save-view-config-dialog/save-view-config-dialog.component'
import { TagsComponent } from './components/common/input/tags/tags.component'
import { IfPermissionsDirective } from './directives/if-permissions.directive'
import { SortableDirective } from './directives/sortable.directive'
import { CookieService } from 'ngx-cookie-service'
import { CsrfInterceptor } from './interceptors/csrf.interceptor'
Expand Down Expand Up @@ -69,6 +70,7 @@ import { ColorSliderModule } from 'ngx-color/slider'
import { ColorComponent } from './components/common/input/color/color.component'
import { DocumentAsnComponent } from './components/document-asn/document-asn.component'
import { DocumentCommentsComponent } from './components/document-comments/document-comments.component'
import { AuthGard } from './guards/auth.gard'
import { DirtyDocGuard } from './guards/dirty-doc.guard'
import { DirtySavedViewGuard } from './guards/dirty-saved-view.guard'
import { StoragePathListComponent } from './components/manage/storage-path-list/storage-path-list.component'
Expand Down Expand Up @@ -159,6 +161,7 @@ function initializeApp(settings: SettingsService) {
CheckComponent,
SaveViewConfigDialogComponent,
TagsComponent,
IfPermissionsDirective,
SortableDirective,
SavedViewWidgetComponent,
StatisticsWidgetComponent,
Expand Down Expand Up @@ -217,6 +220,7 @@ function initializeApp(settings: SettingsService) {
DocumentTitlePipe,
{ provide: NgbDateAdapter, useClass: ISODateAdapter },
{ provide: NgbDateParserFormatter, useClass: LocalizedDateParserFormatter },
AuthGard,
DirtyDocGuard,
DirtySavedViewGuard,
],
Expand Down

0 comments on commit 4603813

Please sign in to comment.