mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-04-02 13:45:10 -05:00
Add ability to set owner per object
This commit is contained in:
parent
f846c2934c
commit
a5ab6f2558
@ -109,6 +109,7 @@ import localeSv from '@angular/common/locales/sv'
|
||||
import localeTr from '@angular/common/locales/tr'
|
||||
import localeZh from '@angular/common/locales/zh'
|
||||
import { PermissionsDialogComponent } from './components/common/permissions-dialog/permissions-dialog.component'
|
||||
import { PermissionsFormComponent } from './components/common/input/permissions-form/permissions-form.component'
|
||||
|
||||
registerLocaleData(localeBe)
|
||||
registerLocaleData(localeCs)
|
||||
@ -205,6 +206,7 @@ function initializeApp(settings: SettingsService) {
|
||||
IfOwnerDirective,
|
||||
IfObjectPermissionsDirective,
|
||||
PermissionsDialogComponent,
|
||||
PermissionsFormComponent,
|
||||
],
|
||||
imports: [
|
||||
BrowserModule,
|
||||
|
@ -12,19 +12,7 @@
|
||||
<app-input-check *ngIf="patternRequired" i18n-title title="Case insensitive" formControlName="is_insensitive" novalidate></app-input-check>
|
||||
|
||||
<div *ifOwner="object">
|
||||
<h5 i18n>Permissions</h5>
|
||||
<div formGroupName="set_permissions">
|
||||
<h6 i18n>View</h6>
|
||||
<div formGroupName="view">
|
||||
<app-permissions-user type="view" formControlName="users"></app-permissions-user>
|
||||
<app-permissions-group type="view" formControlName="groups"></app-permissions-group>
|
||||
</div>
|
||||
<h6 i18n>Edit</h6>
|
||||
<div formGroupName="change">
|
||||
<app-permissions-user type="change" formControlName="users"></app-permissions-user>
|
||||
<app-permissions-group type="change" formControlName="groups"></app-permissions-group>
|
||||
</div>
|
||||
</div>
|
||||
<app-permissions-form [users]="users" formControlName="permissions_form"></app-permissions-form>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
@ -5,6 +5,7 @@ import { EditDialogComponent } from 'src/app/components/common/edit-dialog/edit-
|
||||
import { DEFAULT_MATCHING_ALGORITHM } from 'src/app/data/matching-model'
|
||||
import { PaperlessCorrespondent } from 'src/app/data/paperless-correspondent'
|
||||
import { CorrespondentService } from 'src/app/services/rest/correspondent.service'
|
||||
import { UserService } from 'src/app/services/rest/user.service'
|
||||
|
||||
@Component({
|
||||
selector: 'app-correspondent-edit-dialog',
|
||||
@ -12,8 +13,12 @@ import { CorrespondentService } from 'src/app/services/rest/correspondent.servic
|
||||
styleUrls: ['./correspondent-edit-dialog.component.scss'],
|
||||
})
|
||||
export class CorrespondentEditDialogComponent extends EditDialogComponent<PaperlessCorrespondent> {
|
||||
constructor(service: CorrespondentService, activeModal: NgbActiveModal) {
|
||||
super(service, activeModal)
|
||||
constructor(
|
||||
service: CorrespondentService,
|
||||
activeModal: NgbActiveModal,
|
||||
userService: UserService
|
||||
) {
|
||||
super(service, activeModal, userService)
|
||||
}
|
||||
|
||||
getCreateTitle() {
|
||||
@ -30,16 +35,7 @@ export class CorrespondentEditDialogComponent extends EditDialogComponent<Paperl
|
||||
matching_algorithm: new FormControl(DEFAULT_MATCHING_ALGORITHM),
|
||||
match: new FormControl(''),
|
||||
is_insensitive: new FormControl(true),
|
||||
set_permissions: new FormGroup({
|
||||
view: new FormGroup({
|
||||
users: new FormControl(null),
|
||||
groups: new FormControl(null),
|
||||
}),
|
||||
change: new FormGroup({
|
||||
users: new FormControl(null),
|
||||
groups: new FormControl(null),
|
||||
}),
|
||||
}),
|
||||
permissions_form: new FormControl(null),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -6,25 +6,15 @@
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
|
||||
<app-input-text i18n-title title="Name" formControlName="name" [error]="error?.name"></app-input-text>
|
||||
<app-input-select i18n-title title="Matching algorithm" [items]="getMatchingAlgorithms()" formControlName="matching_algorithm"></app-input-select>
|
||||
<app-input-text *ngIf="patternRequired" i18n-title title="Matching pattern" formControlName="match" [error]="error?.match"></app-input-text>
|
||||
<app-input-check *ngIf="patternRequired" i18n-title title="Case insensitive" formControlName="is_insensitive"></app-input-check>
|
||||
<div class="col">
|
||||
<app-input-text i18n-title title="Name" formControlName="name" [error]="error?.name"></app-input-text>
|
||||
<app-input-select i18n-title title="Matching algorithm" [items]="getMatchingAlgorithms()" formControlName="matching_algorithm"></app-input-select>
|
||||
<app-input-text *ngIf="patternRequired" i18n-title title="Matching pattern" formControlName="match" [error]="error?.match"></app-input-text>
|
||||
<app-input-check *ngIf="patternRequired" i18n-title title="Case insensitive" formControlName="is_insensitive"></app-input-check>
|
||||
</div>
|
||||
|
||||
<div *ifOwner="object">
|
||||
<h5 i18n>Permissions</h5>
|
||||
<div formGroupName="set_permissions">
|
||||
<h6 i18n>View</h6>
|
||||
<div formGroupName="view">
|
||||
<app-permissions-user type="view" formControlName="users"></app-permissions-user>
|
||||
<app-permissions-group type="view" formControlName="groups"></app-permissions-group>
|
||||
</div>
|
||||
<h6 i18n>Edit</h6>
|
||||
<div formGroupName="change">
|
||||
<app-permissions-user type="change" formControlName="users"></app-permissions-user>
|
||||
<app-permissions-group type="change" formControlName="groups"></app-permissions-group>
|
||||
</div>
|
||||
</div>
|
||||
<app-permissions-form [users]="users" formControlName="permissions_form"></app-permissions-form>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
@ -5,6 +5,7 @@ import { EditDialogComponent } from 'src/app/components/common/edit-dialog/edit-
|
||||
import { DEFAULT_MATCHING_ALGORITHM } from 'src/app/data/matching-model'
|
||||
import { PaperlessDocumentType } from 'src/app/data/paperless-document-type'
|
||||
import { DocumentTypeService } from 'src/app/services/rest/document-type.service'
|
||||
import { UserService } from 'src/app/services/rest/user.service'
|
||||
|
||||
@Component({
|
||||
selector: 'app-document-type-edit-dialog',
|
||||
@ -12,8 +13,12 @@ import { DocumentTypeService } from 'src/app/services/rest/document-type.service
|
||||
styleUrls: ['./document-type-edit-dialog.component.scss'],
|
||||
})
|
||||
export class DocumentTypeEditDialogComponent extends EditDialogComponent<PaperlessDocumentType> {
|
||||
constructor(service: DocumentTypeService, activeModal: NgbActiveModal) {
|
||||
super(service, activeModal)
|
||||
constructor(
|
||||
service: DocumentTypeService,
|
||||
activeModal: NgbActiveModal,
|
||||
userService: UserService
|
||||
) {
|
||||
super(service, activeModal, userService)
|
||||
}
|
||||
|
||||
getCreateTitle() {
|
||||
@ -30,16 +35,7 @@ export class DocumentTypeEditDialogComponent extends EditDialogComponent<Paperle
|
||||
matching_algorithm: new FormControl(DEFAULT_MATCHING_ALGORITHM),
|
||||
match: new FormControl(''),
|
||||
is_insensitive: new FormControl(true),
|
||||
set_permissions: new FormGroup({
|
||||
view: new FormGroup({
|
||||
users: new FormControl(null),
|
||||
groups: new FormControl(null),
|
||||
}),
|
||||
change: new FormGroup({
|
||||
users: new FormControl(null),
|
||||
groups: new FormControl(null),
|
||||
}),
|
||||
}),
|
||||
permissions_form: new FormControl(null),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,10 @@ import { Observable } from 'rxjs'
|
||||
import { MATCHING_ALGORITHMS, MATCH_AUTO } from 'src/app/data/matching-model'
|
||||
import { ObjectWithId } from 'src/app/data/object-with-id'
|
||||
import { ObjectWithPermissions } from 'src/app/data/object-with-permissions'
|
||||
import { PaperlessUser } from 'src/app/data/paperless-user'
|
||||
import { AbstractPaperlessService } from 'src/app/services/rest/abstract-paperless-service'
|
||||
import { UserService } from 'src/app/services/rest/user.service'
|
||||
import { PermissionsFormObject } from '../input/permissions-form/permissions-form.component'
|
||||
|
||||
@Directive()
|
||||
export abstract class EditDialogComponent<
|
||||
@ -14,9 +17,12 @@ export abstract class EditDialogComponent<
|
||||
{
|
||||
constructor(
|
||||
private service: AbstractPaperlessService<T>,
|
||||
private activeModal: NgbActiveModal
|
||||
private activeModal: NgbActiveModal,
|
||||
private userService: UserService
|
||||
) {}
|
||||
|
||||
users: PaperlessUser[]
|
||||
|
||||
@Input()
|
||||
dialogMode: string = 'create'
|
||||
|
||||
@ -41,6 +47,12 @@ export abstract class EditDialogComponent<
|
||||
if (this.object['permissions']) {
|
||||
this.object['set_permissions'] = this.object['permissions']
|
||||
}
|
||||
console.log(this.object)
|
||||
|
||||
this.object['permissions_form'] = {
|
||||
owner: (this.object as ObjectWithPermissions).owner,
|
||||
set_permissions: (this.object as ObjectWithPermissions).permissions,
|
||||
}
|
||||
this.objectForm.patchValue(this.object)
|
||||
}
|
||||
|
||||
@ -48,6 +60,8 @@ export abstract class EditDialogComponent<
|
||||
setTimeout(() => {
|
||||
this.closeEnabled = true
|
||||
})
|
||||
|
||||
this.userService.listAll().subscribe((r) => (this.users = r.results))
|
||||
}
|
||||
|
||||
getCreateTitle() {
|
||||
@ -82,10 +96,16 @@ export abstract class EditDialogComponent<
|
||||
}
|
||||
|
||||
save() {
|
||||
var newObject = Object.assign(
|
||||
Object.assign({}, this.object),
|
||||
this.objectForm.value
|
||||
)
|
||||
const formValues = Object.assign({}, this.objectForm.value)
|
||||
const permissionsObject: PermissionsFormObject =
|
||||
this.objectForm.get('permissions_form').value
|
||||
if (permissionsObject) {
|
||||
formValues.owner = permissionsObject.owner
|
||||
formValues.set_permissions = permissionsObject.set_permissions
|
||||
delete formValues.permissions_form
|
||||
}
|
||||
|
||||
var newObject = Object.assign(Object.assign({}, this.object), formValues)
|
||||
var serverResponse: Observable<T>
|
||||
switch (this.dialogMode) {
|
||||
case 'create':
|
||||
|
@ -4,6 +4,7 @@ import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap'
|
||||
import { EditDialogComponent } from 'src/app/components/common/edit-dialog/edit-dialog.component'
|
||||
import { PaperlessGroup } from 'src/app/data/paperless-group'
|
||||
import { GroupService } from 'src/app/services/rest/group.service'
|
||||
import { UserService } from 'src/app/services/rest/user.service'
|
||||
|
||||
@Component({
|
||||
selector: 'app-group-edit-dialog',
|
||||
@ -11,8 +12,12 @@ import { GroupService } from 'src/app/services/rest/group.service'
|
||||
styleUrls: ['./group-edit-dialog.component.scss'],
|
||||
})
|
||||
export class GroupEditDialogComponent extends EditDialogComponent<PaperlessGroup> {
|
||||
constructor(service: GroupService, activeModal: NgbActiveModal) {
|
||||
super(service, activeModal)
|
||||
constructor(
|
||||
service: GroupService,
|
||||
activeModal: NgbActiveModal,
|
||||
userService: UserService
|
||||
) {
|
||||
super(service, activeModal, userService)
|
||||
}
|
||||
|
||||
getCreateTitle() {
|
||||
|
@ -7,6 +7,7 @@ import {
|
||||
PaperlessMailAccount,
|
||||
} from 'src/app/data/paperless-mail-account'
|
||||
import { MailAccountService } from 'src/app/services/rest/mail-account.service'
|
||||
import { UserService } from 'src/app/services/rest/user.service'
|
||||
|
||||
const IMAP_SECURITY_OPTIONS = [
|
||||
{ id: IMAPSecurity.None, name: $localize`No encryption` },
|
||||
@ -20,8 +21,12 @@ const IMAP_SECURITY_OPTIONS = [
|
||||
styleUrls: ['./mail-account-edit-dialog.component.scss'],
|
||||
})
|
||||
export class MailAccountEditDialogComponent extends EditDialogComponent<PaperlessMailAccount> {
|
||||
constructor(service: MailAccountService, activeModal: NgbActiveModal) {
|
||||
super(service, activeModal)
|
||||
constructor(
|
||||
service: MailAccountService,
|
||||
activeModal: NgbActiveModal,
|
||||
userService: UserService
|
||||
) {
|
||||
super(service, activeModal, userService)
|
||||
}
|
||||
|
||||
getCreateTitle() {
|
||||
|
@ -17,6 +17,7 @@ import { CorrespondentService } from 'src/app/services/rest/correspondent.servic
|
||||
import { DocumentTypeService } from 'src/app/services/rest/document-type.service'
|
||||
import { MailAccountService } from 'src/app/services/rest/mail-account.service'
|
||||
import { MailRuleService } from 'src/app/services/rest/mail-rule.service'
|
||||
import { UserService } from 'src/app/services/rest/user.service'
|
||||
|
||||
const ATTACHMENT_TYPE_OPTIONS = [
|
||||
{
|
||||
@ -97,9 +98,10 @@ export class MailRuleEditDialogComponent extends EditDialogComponent<PaperlessMa
|
||||
activeModal: NgbActiveModal,
|
||||
accountService: MailAccountService,
|
||||
correspondentService: CorrespondentService,
|
||||
documentTypeService: DocumentTypeService
|
||||
documentTypeService: DocumentTypeService,
|
||||
userService: UserService
|
||||
) {
|
||||
super(service, activeModal)
|
||||
super(service, activeModal, userService)
|
||||
|
||||
accountService
|
||||
.listAll()
|
||||
|
@ -17,19 +17,7 @@
|
||||
<app-input-check *ngIf="patternRequired" i18n-title title="Case insensitive" formControlName="is_insensitive"></app-input-check>
|
||||
|
||||
<div *ifOwner="object">
|
||||
<h5 i18n>Permissions</h5>
|
||||
<div formGroupName="set_permissions">
|
||||
<h6 i18n>View</h6>
|
||||
<div formGroupName="view">
|
||||
<app-permissions-user type="view" formControlName="users"></app-permissions-user>
|
||||
<app-permissions-group type="view" formControlName="groups"></app-permissions-group>
|
||||
</div>
|
||||
<h6 i18n>Edit</h6>
|
||||
<div formGroupName="change">
|
||||
<app-permissions-user type="change" formControlName="users"></app-permissions-user>
|
||||
<app-permissions-group type="change" formControlName="groups"></app-permissions-group>
|
||||
</div>
|
||||
</div>
|
||||
<app-permissions-form [users]="users" formControlName="permissions_form"></app-permissions-form>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
@ -5,6 +5,7 @@ import { EditDialogComponent } from 'src/app/components/common/edit-dialog/edit-
|
||||
import { DEFAULT_MATCHING_ALGORITHM } from 'src/app/data/matching-model'
|
||||
import { PaperlessStoragePath } from 'src/app/data/paperless-storage-path'
|
||||
import { StoragePathService } from 'src/app/services/rest/storage-path.service'
|
||||
import { UserService } from 'src/app/services/rest/user.service'
|
||||
|
||||
@Component({
|
||||
selector: 'app-storage-path-edit-dialog',
|
||||
@ -12,8 +13,12 @@ import { StoragePathService } from 'src/app/services/rest/storage-path.service'
|
||||
styleUrls: ['./storage-path-edit-dialog.component.scss'],
|
||||
})
|
||||
export class StoragePathEditDialogComponent extends EditDialogComponent<PaperlessStoragePath> {
|
||||
constructor(service: StoragePathService, activeModal: NgbActiveModal) {
|
||||
super(service, activeModal)
|
||||
constructor(
|
||||
service: StoragePathService,
|
||||
activeModal: NgbActiveModal,
|
||||
userService: UserService
|
||||
) {
|
||||
super(service, activeModal, userService)
|
||||
}
|
||||
|
||||
get pathHint() {
|
||||
@ -41,16 +46,7 @@ export class StoragePathEditDialogComponent extends EditDialogComponent<Paperles
|
||||
matching_algorithm: new FormControl(DEFAULT_MATCHING_ALGORITHM),
|
||||
match: new FormControl(''),
|
||||
is_insensitive: new FormControl(true),
|
||||
set_permissions: new FormGroup({
|
||||
view: new FormGroup({
|
||||
users: new FormControl(null),
|
||||
groups: new FormControl(null),
|
||||
}),
|
||||
change: new FormGroup({
|
||||
users: new FormControl(null),
|
||||
groups: new FormControl(null),
|
||||
}),
|
||||
}),
|
||||
permissions_form: new FormControl(null),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -15,19 +15,7 @@
|
||||
<app-input-check *ngIf="patternRequired" i18n-title title="Case insensitive" formControlName="is_insensitive"></app-input-check>
|
||||
|
||||
<div *ifOwner="object">
|
||||
<h5 i18n>Permissions</h5>
|
||||
<div formGroupName="set_permissions">
|
||||
<h6 i18n>View</h6>
|
||||
<div formGroupName="view">
|
||||
<app-permissions-user type="view" formControlName="users"></app-permissions-user>
|
||||
<app-permissions-group type="view" formControlName="groups"></app-permissions-group>
|
||||
</div>
|
||||
<h6 i18n>Edit</h6>
|
||||
<div formGroupName="change">
|
||||
<app-permissions-user type="change" formControlName="users"></app-permissions-user>
|
||||
<app-permissions-group type="change" formControlName="groups"></app-permissions-group>
|
||||
</div>
|
||||
</div>
|
||||
<app-permissions-form [users]="users" formControlName="permissions_form"></app-permissions-form>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
@ -6,6 +6,7 @@ import { PaperlessTag } from 'src/app/data/paperless-tag'
|
||||
import { TagService } from 'src/app/services/rest/tag.service'
|
||||
import { randomColor } from 'src/app/utils/color'
|
||||
import { DEFAULT_MATCHING_ALGORITHM } from 'src/app/data/matching-model'
|
||||
import { UserService } from 'src/app/services/rest/user.service'
|
||||
|
||||
@Component({
|
||||
selector: 'app-tag-edit-dialog',
|
||||
@ -13,8 +14,12 @@ import { DEFAULT_MATCHING_ALGORITHM } from 'src/app/data/matching-model'
|
||||
styleUrls: ['./tag-edit-dialog.component.scss'],
|
||||
})
|
||||
export class TagEditDialogComponent extends EditDialogComponent<PaperlessTag> {
|
||||
constructor(service: TagService, activeModal: NgbActiveModal) {
|
||||
super(service, activeModal)
|
||||
constructor(
|
||||
service: TagService,
|
||||
activeModal: NgbActiveModal,
|
||||
userService: UserService
|
||||
) {
|
||||
super(service, activeModal, userService)
|
||||
}
|
||||
|
||||
getCreateTitle() {
|
||||
@ -33,16 +38,7 @@ export class TagEditDialogComponent extends EditDialogComponent<PaperlessTag> {
|
||||
matching_algorithm: new FormControl(DEFAULT_MATCHING_ALGORITHM),
|
||||
match: new FormControl(''),
|
||||
is_insensitive: new FormControl(true),
|
||||
set_permissions: new FormGroup({
|
||||
view: new FormGroup({
|
||||
users: new FormControl(null),
|
||||
groups: new FormControl(null),
|
||||
}),
|
||||
change: new FormGroup({
|
||||
users: new FormControl(null),
|
||||
groups: new FormControl(null),
|
||||
}),
|
||||
}),
|
||||
permissions_form: new FormControl(null),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ export class UserEditDialogComponent
|
||||
activeModal: NgbActiveModal,
|
||||
groupsService: GroupService
|
||||
) {
|
||||
super(service, activeModal)
|
||||
super(service, activeModal, service)
|
||||
|
||||
groupsService
|
||||
.listAll()
|
||||
|
@ -0,0 +1,53 @@
|
||||
<h5 i18n>Permissions</h5>
|
||||
<div [formGroup]="form">
|
||||
<div class="row">
|
||||
<div class="col-lg-3">
|
||||
<label class="form-label d-block my-2" i18n>Owner:</label>
|
||||
</div>
|
||||
<div class="col-lg-9">
|
||||
<app-input-select [items]="users" bindLabel="username" formControlName="owner" [allowNull]="true"></app-input-select>
|
||||
</div>
|
||||
</div>
|
||||
<small class="form-text text-muted text-end d-block mt-n2" i18n>Objects without an owner can be viewed and edited by all users</small>
|
||||
<div formGroupName="set_permissions">
|
||||
<h6 class="mt-3" i18n>View</h6>
|
||||
<div formGroupName="view" class="mb-2">
|
||||
<div class="row mb-1">
|
||||
<div class="col-lg-3">
|
||||
<label class="form-label d-block my-2" i18n>Users:</label>
|
||||
</div>
|
||||
<div class="col-lg-9">
|
||||
<app-permissions-user type="view" formControlName="users"></app-permissions-user>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-lg-3">
|
||||
<label class="form-label d-block my-2" i18n>Groups:</label>
|
||||
</div>
|
||||
<div class="col-lg-9">
|
||||
<app-permissions-group type="view" formControlName="groups"></app-permissions-group>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<h6 class="mt-4" i18n>Edit</h6>
|
||||
<div formGroupName="change">
|
||||
<div class="row mb-1">
|
||||
<div class="col-lg-3">
|
||||
<label class="form-label d-block my-2" i18n>Users:</label>
|
||||
</div>
|
||||
<div class="col-lg-9">
|
||||
<app-permissions-user type="change" formControlName="users"></app-permissions-user>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-lg-3">
|
||||
<label class="form-label d-block my-2" i18n>Groups:</label>
|
||||
</div>
|
||||
<div class="col-lg-9">
|
||||
<app-permissions-group type="change" formControlName="groups"></app-permissions-group>
|
||||
</div>
|
||||
</div>
|
||||
<small class="form-text text-muted text-end d-block" i18n>Edit permissions also grant viewing permissions</small>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
@ -0,0 +1,66 @@
|
||||
import { Component, forwardRef, Input, OnInit } from '@angular/core'
|
||||
import { FormControl, FormGroup, NG_VALUE_ACCESSOR } from '@angular/forms'
|
||||
import { PaperlessUser } from 'src/app/data/paperless-user'
|
||||
import { AbstractInputComponent } from '../abstract-input'
|
||||
|
||||
export interface PermissionsFormObject {
|
||||
owner?: number
|
||||
set_permissions?: {
|
||||
view?: {
|
||||
users?: number[]
|
||||
groups?: number[]
|
||||
}
|
||||
change?: {
|
||||
users?: number[]
|
||||
groups?: number[]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Component({
|
||||
providers: [
|
||||
{
|
||||
provide: NG_VALUE_ACCESSOR,
|
||||
useExisting: forwardRef(() => PermissionsFormComponent),
|
||||
multi: true,
|
||||
},
|
||||
],
|
||||
selector: 'app-permissions-form',
|
||||
templateUrl: './permissions-form.component.html',
|
||||
styleUrls: ['./permissions-form.component.scss'],
|
||||
})
|
||||
export class PermissionsFormComponent
|
||||
extends AbstractInputComponent<PermissionsFormObject>
|
||||
implements OnInit
|
||||
{
|
||||
@Input()
|
||||
users: PaperlessUser[]
|
||||
|
||||
form = new FormGroup({
|
||||
owner: new FormControl(null),
|
||||
set_permissions: new FormGroup({
|
||||
view: new FormGroup({
|
||||
users: new FormControl([]),
|
||||
groups: new FormControl([]),
|
||||
}),
|
||||
change: new FormGroup({
|
||||
users: new FormControl([]),
|
||||
groups: new FormControl([]),
|
||||
}),
|
||||
}),
|
||||
})
|
||||
|
||||
constructor() {
|
||||
super()
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.form.valueChanges.subscribe((value) => {
|
||||
this.onChange(value)
|
||||
})
|
||||
}
|
||||
|
||||
writeValue(newValue: any): void {
|
||||
this.form.patchValue(newValue, { emitEvent: false })
|
||||
}
|
||||
}
|
@ -1,15 +1,13 @@
|
||||
<div class="mb-3 paperless-input-select">
|
||||
<label class="form-label" [for]="inputId">{{title}}</label>
|
||||
<div>
|
||||
<ng-select name="inputId" [(ngModel)]="value"
|
||||
[disabled]="disabled"
|
||||
clearable="true"
|
||||
[items]="groups"
|
||||
multiple="true"
|
||||
bindLabel="name"
|
||||
bindValue="id"
|
||||
(change)="onChange(value)">
|
||||
</ng-select>
|
||||
</div>
|
||||
<small *ngIf="hint" class="form-text text-muted">{{hint}}</small>
|
||||
</div>
|
||||
<div class="paperless-input-select">
|
||||
<div>
|
||||
<ng-select name="inputId" [(ngModel)]="value"
|
||||
[disabled]="disabled"
|
||||
clearable="true"
|
||||
[items]="groups"
|
||||
multiple="true"
|
||||
bindLabel="name"
|
||||
bindValue="id"
|
||||
(change)="onChange(value)">
|
||||
</ng-select>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -3,7 +3,6 @@ import { NG_VALUE_ACCESSOR } from '@angular/forms'
|
||||
import { first } from 'rxjs/operators'
|
||||
import { PaperlessGroup } from 'src/app/data/paperless-group'
|
||||
import { GroupService } from 'src/app/services/rest/group.service'
|
||||
import { SettingsService } from 'src/app/services/settings.service'
|
||||
import { AbstractInputComponent } from '../abstract-input'
|
||||
|
||||
@Component({
|
||||
@ -18,31 +17,14 @@ import { AbstractInputComponent } from '../abstract-input'
|
||||
templateUrl: './permissions-group.component.html',
|
||||
styleUrls: ['./permissions-group.component.scss'],
|
||||
})
|
||||
export class PermissionsGroupComponent
|
||||
extends AbstractInputComponent<PaperlessGroup>
|
||||
implements OnInit
|
||||
{
|
||||
export class PermissionsGroupComponent extends AbstractInputComponent<PaperlessGroup> {
|
||||
groups: PaperlessGroup[]
|
||||
|
||||
@Input()
|
||||
type: string
|
||||
|
||||
constructor(groupService: GroupService, settings: SettingsService) {
|
||||
constructor(groupService: GroupService) {
|
||||
super()
|
||||
groupService
|
||||
.listAll()
|
||||
.pipe(first())
|
||||
.subscribe((result) => (this.groups = result.results))
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
if (this.type == 'view') {
|
||||
this.title = $localize`Groups can view`
|
||||
} else if (this.type == 'change') {
|
||||
this.title = $localize`Groups can edit`
|
||||
this.hint = $localize`Edit permissions also grant viewing permissions`
|
||||
}
|
||||
|
||||
super.ngOnInit()
|
||||
}
|
||||
}
|
||||
|
@ -1,15 +1,13 @@
|
||||
<div class="mb-3 paperless-input-select">
|
||||
<label class="form-label" [for]="inputId">{{title}}</label>
|
||||
<div>
|
||||
<ng-select name="inputId" [(ngModel)]="value"
|
||||
[disabled]="disabled"
|
||||
clearable="true"
|
||||
[items]="users"
|
||||
multiple="true"
|
||||
bindLabel="username"
|
||||
bindValue="id"
|
||||
(change)="onChange(value)">
|
||||
</ng-select>
|
||||
</div>
|
||||
<small *ngIf="hint" class="form-text text-muted">{{hint}}</small>
|
||||
<div class="paperless-input-select">
|
||||
<div>
|
||||
<ng-select name="inputId" [(ngModel)]="value"
|
||||
[disabled]="disabled"
|
||||
clearable="true"
|
||||
[items]="users"
|
||||
multiple="true"
|
||||
bindLabel="username"
|
||||
bindValue="id"
|
||||
(change)="onChange(value)">
|
||||
</ng-select>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -18,15 +18,11 @@ import { AbstractInputComponent } from '../abstract-input'
|
||||
templateUrl: './permissions-user.component.html',
|
||||
styleUrls: ['./permissions-user.component.scss'],
|
||||
})
|
||||
export class PermissionsUserComponent
|
||||
extends AbstractInputComponent<PaperlessUser>
|
||||
implements OnInit
|
||||
{
|
||||
export class PermissionsUserComponent extends AbstractInputComponent<
|
||||
PaperlessUser[]
|
||||
> {
|
||||
users: PaperlessUser[]
|
||||
|
||||
@Input()
|
||||
type: string
|
||||
|
||||
constructor(userService: UserService, settings: SettingsService) {
|
||||
super()
|
||||
userService
|
||||
@ -39,15 +35,4 @@ export class PermissionsUserComponent
|
||||
))
|
||||
)
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
if (this.type == 'view') {
|
||||
this.title = $localize`Users can view`
|
||||
} else if (this.type == 'change') {
|
||||
this.title = $localize`Users can edit`
|
||||
this.hint = $localize`Edit permissions also grant viewing permissions`
|
||||
}
|
||||
|
||||
super.ngOnInit()
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
<div class="mb-3 paperless-input-select">
|
||||
<label class="form-label" [for]="inputId">{{title}}</label>
|
||||
<label *ngIf="title" class="form-label" [for]="inputId">{{title}}</label>
|
||||
<div [class.input-group]="allowCreateNew">
|
||||
<ng-select name="inputId" [(ngModel)]="value"
|
||||
[disabled]="disabled"
|
||||
|
@ -9,12 +9,15 @@
|
||||
|
||||
<form [formGroup]="form">
|
||||
<div formGroupName="set_permissions">
|
||||
<app-input-select [items]="users" i18n-title title="Owner" bindLabel="username" formControlName="owner" [allowNull]="true"></app-input-select>
|
||||
<small class="form-text text-muted" i18n>Objects without an owner can be viewed and edited by all users</small>
|
||||
<h6 i18n>View</h6>
|
||||
<div formGroupName="view">
|
||||
<app-permissions-user type="view" formControlName="users"></app-permissions-user>
|
||||
<app-permissions-group type="view" formControlName="groups"></app-permissions-group>
|
||||
</div>
|
||||
<h6 i18n>Edit</h6>
|
||||
<small class="form-text text-muted" i18n>Edit permissions also grant viewing permissions</small>
|
||||
<div formGroupName="change">
|
||||
<app-permissions-user type="change" formControlName="users"></app-permissions-user>
|
||||
<app-permissions-group type="change" formControlName="groups"></app-permissions-group>
|
||||
|
@ -3,6 +3,7 @@ import { FormControl, FormGroup } from '@angular/forms'
|
||||
import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap'
|
||||
import { PaperlessGroup } from 'src/app/data/paperless-group'
|
||||
import { PaperlessUser } from 'src/app/data/paperless-user'
|
||||
import { UserService } from 'src/app/services/rest/user.service'
|
||||
|
||||
@Component({
|
||||
selector: 'app-permissions-dialog',
|
||||
@ -10,7 +11,14 @@ import { PaperlessUser } from 'src/app/data/paperless-user'
|
||||
styleUrls: ['./permissions-dialog.component.scss'],
|
||||
})
|
||||
export class PermissionsDialogComponent implements OnInit {
|
||||
constructor(public activeModal: NgbActiveModal) {}
|
||||
users: PaperlessUser[]
|
||||
|
||||
constructor(
|
||||
public activeModal: NgbActiveModal,
|
||||
private userService: UserService
|
||||
) {
|
||||
this.userService.listAll().subscribe((r) => (this.users = r.results))
|
||||
}
|
||||
|
||||
@Output()
|
||||
public confirmClicked = new EventEmitter()
|
||||
|
@ -181,18 +181,7 @@
|
||||
<li [ngbNavItem]="6" *ifOwner="document">
|
||||
<a ngbNavLink i18n>Permissions</a>
|
||||
<ng-template ngbNavContent>
|
||||
<div formGroupName="set_permissions">
|
||||
<h6 i18n>View</h6>
|
||||
<div formGroupName="view">
|
||||
<app-permissions-user type="view" formControlName="users"></app-permissions-user>
|
||||
<app-permissions-group type="view" formControlName="groups"></app-permissions-group>
|
||||
</div>
|
||||
<h6 i18n>Edit</h6>
|
||||
<div formGroupName="change">
|
||||
<app-permissions-user type="change" formControlName="users"></app-permissions-user>
|
||||
<app-permissions-group type="change" formControlName="groups"></app-permissions-group>
|
||||
</div>
|
||||
</div>
|
||||
<app-permissions-form [users]="users" formControlName="permissions_form"></app-permissions-form>
|
||||
</ng-template>
|
||||
</li>
|
||||
</ul>
|
||||
|
@ -41,6 +41,7 @@ import {
|
||||
PermissionType,
|
||||
} from 'src/app/services/permissions.service'
|
||||
import { PaperlessUser } from 'src/app/data/paperless-user'
|
||||
import { UserService } from 'src/app/services/rest/user.service'
|
||||
|
||||
@Component({
|
||||
selector: 'app-document-detail',
|
||||
@ -64,6 +65,7 @@ export class DocumentDetailComponent
|
||||
document: PaperlessDocument
|
||||
metadata: PaperlessDocumentMetadata
|
||||
suggestions: PaperlessDocumentSuggestions
|
||||
users: PaperlessUser[]
|
||||
|
||||
title: string
|
||||
titleSubject: Subject<string> = new Subject()
|
||||
@ -84,16 +86,7 @@ export class DocumentDetailComponent
|
||||
storage_path: new FormControl(),
|
||||
archive_serial_number: new FormControl(),
|
||||
tags: new FormControl([]),
|
||||
set_permissions: new FormGroup({
|
||||
view: new FormGroup({
|
||||
users: new FormControl(null),
|
||||
groups: new FormControl(null),
|
||||
}),
|
||||
change: new FormGroup({
|
||||
users: new FormControl(null),
|
||||
groups: new FormControl(null),
|
||||
}),
|
||||
}),
|
||||
permissions_form: new FormControl(null),
|
||||
})
|
||||
|
||||
previewCurrentPage: number = 1
|
||||
@ -138,7 +131,8 @@ export class DocumentDetailComponent
|
||||
private toastService: ToastService,
|
||||
private settings: SettingsService,
|
||||
private storagePathService: StoragePathService,
|
||||
private permissionsService: PermissionsService
|
||||
private permissionsService: PermissionsService,
|
||||
private userService: UserService
|
||||
) {}
|
||||
|
||||
titleKeyUp(event) {
|
||||
@ -160,7 +154,13 @@ export class DocumentDetailComponent
|
||||
.pipe(takeUntil(this.unsubscribeNotifier))
|
||||
.subscribe(() => {
|
||||
this.error = null
|
||||
Object.assign(this.document, this.documentForm.value)
|
||||
const docValues = Object.assign({}, this.documentForm.value)
|
||||
docValues['owner'] =
|
||||
this.documentForm.get('permissions_form').value['owner']
|
||||
docValues['set_permissions'] =
|
||||
this.documentForm.get('permissions_form').value['set_permissions']
|
||||
delete docValues['permissions_form']
|
||||
Object.assign(this.document, docValues)
|
||||
})
|
||||
|
||||
this.correspondentService
|
||||
@ -178,6 +178,11 @@ export class DocumentDetailComponent
|
||||
.pipe(first())
|
||||
.subscribe((result) => (this.storagePaths = result.results))
|
||||
|
||||
this.userService
|
||||
.listAll()
|
||||
.pipe(first())
|
||||
.subscribe((result) => (this.users = result.results))
|
||||
|
||||
this.route.paramMap
|
||||
.pipe(
|
||||
takeUntil(this.unsubscribeNotifier),
|
||||
@ -241,7 +246,10 @@ export class DocumentDetailComponent
|
||||
storage_path: doc.storage_path,
|
||||
archive_serial_number: doc.archive_serial_number,
|
||||
tags: [...doc.tags],
|
||||
set_permissions: doc.permissions,
|
||||
permissions_form: {
|
||||
owner: doc.owner,
|
||||
set_permissions: doc.permissions,
|
||||
},
|
||||
})
|
||||
|
||||
this.isDirty$ = dirtyCheck(
|
||||
@ -296,8 +304,13 @@ export class DocumentDetailComponent
|
||||
},
|
||||
})
|
||||
this.title = this.documentTitlePipe.transform(doc.title)
|
||||
doc['set_permissions'] = doc.permissions
|
||||
this.documentForm.patchValue(doc)
|
||||
const docFormValues = Object.assign({}, doc)
|
||||
docFormValues['permissions_form'] = {
|
||||
owner: doc.owner,
|
||||
set_permissions: doc.permissions,
|
||||
}
|
||||
|
||||
this.documentForm.patchValue(docFormValues, { emitEvent: false })
|
||||
if (!this.userCanEdit) this.documentForm.disable()
|
||||
}
|
||||
|
||||
@ -586,18 +599,25 @@ export class DocumentDetailComponent
|
||||
}
|
||||
|
||||
get userIsOwner(): boolean {
|
||||
return (
|
||||
!this.document ||
|
||||
this.permissionsService.currentUserOwnsObject(this.document)
|
||||
)
|
||||
let doc: PaperlessDocument = Object.assign({}, this.document)
|
||||
// dont disable while editing
|
||||
if (this.document && this.store?.value.owner) {
|
||||
doc.owner = this.store?.value.owner
|
||||
}
|
||||
return !this.document || this.permissionsService.currentUserOwnsObject(doc)
|
||||
}
|
||||
|
||||
get userCanEdit(): boolean {
|
||||
let doc: PaperlessDocument = Object.assign({}, this.document)
|
||||
// dont disable while editing
|
||||
if (this.document && this.store?.value.owner) {
|
||||
doc.owner = this.store?.value.owner
|
||||
}
|
||||
return (
|
||||
!this.document ||
|
||||
this.permissionsService.currentUserHasObjectPermissions(
|
||||
PermissionAction.Change,
|
||||
this.document
|
||||
doc
|
||||
)
|
||||
)
|
||||
}
|
||||
|
@ -56,7 +56,6 @@ def get_groups_with_only_permission(obj, codename):
|
||||
|
||||
|
||||
def set_permissions_for_object(permissions, object):
|
||||
print(permissions, object)
|
||||
for action in permissions:
|
||||
permission = f"{action}_{object.__class__.__name__.lower()}"
|
||||
# users
|
||||
|
@ -117,9 +117,9 @@ class SetPermissionsMixin:
|
||||
if set_permissions is not None:
|
||||
for action in permissions_dict:
|
||||
users = set_permissions[action]["users"]
|
||||
self._validate_user_ids(users)
|
||||
permissions_dict[action]["users"] = self._validate_user_ids(users)
|
||||
groups = set_permissions[action]["groups"]
|
||||
self._validate_group_ids(groups)
|
||||
permissions_dict[action]["groups"] = self._validate_group_ids(groups)
|
||||
return permissions_dict
|
||||
|
||||
def _set_permissions(self, permissions, object):
|
||||
|
Loading…
x
Reference in New Issue
Block a user