mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-08-14 00:26:21 +00:00
![dependabot[bot]](/assets/img/avatar_default.png)
* Chore(deps-dev): Bump the frontend-jest-dependencies group Bumps the frontend-jest-dependencies group in /src-ui with 4 updates: [jest](https://github.com/jestjs/jest/tree/HEAD/packages/jest), [@types/jest](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/jest), [jest-environment-jsdom](https://github.com/jestjs/jest/tree/HEAD/packages/jest-environment-jsdom) and [jest-preset-angular](https://github.com/thymikee/jest-preset-angular). Updates `jest` from 29.7.0 to 30.0.5 - [Release notes](https://github.com/jestjs/jest/releases) - [Changelog](https://github.com/jestjs/jest/blob/main/CHANGELOG.md) - [Commits](https://github.com/jestjs/jest/commits/v30.0.5/packages/jest) Updates `@types/jest` from 29.5.14 to 30.0.0 - [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases) - [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/jest) Updates `jest-environment-jsdom` from 29.7.0 to 30.0.5 - [Release notes](https://github.com/jestjs/jest/releases) - [Changelog](https://github.com/jestjs/jest/blob/main/CHANGELOG.md) - [Commits](https://github.com/jestjs/jest/commits/v30.0.5/packages/jest-environment-jsdom) Updates `jest-preset-angular` from 14.5.5 to 15.0.0 - [Release notes](https://github.com/thymikee/jest-preset-angular/releases) - [Changelog](https://github.com/thymikee/jest-preset-angular/blob/main/CHANGELOG.md) - [Commits](https://github.com/thymikee/jest-preset-angular/compare/v14.5.5...v15.0.0) --- updated-dependencies: - dependency-name: jest dependency-version: 30.0.5 dependency-type: direct:development update-type: version-update:semver-major dependency-group: frontend-jest-dependencies - dependency-name: "@types/jest" dependency-version: 30.0.0 dependency-type: direct:development update-type: version-update:semver-major dependency-group: frontend-jest-dependencies - dependency-name: jest-environment-jsdom dependency-version: 30.0.5 dependency-type: direct:development update-type: version-update:semver-major dependency-group: frontend-jest-dependencies - dependency-name: jest-preset-angular dependency-version: 15.0.0 dependency-type: direct:development update-type: version-update:semver-major dependency-group: frontend-jest-dependencies ... Signed-off-by: dependabot[bot] <support@github.com> * Update Jest setup for Node util imports and typings * Refactor navigation actions to utility functions --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: shamoon <4887959+shamoon@users.noreply.github.com>
203 lines
7.1 KiB
TypeScript
203 lines
7.1 KiB
TypeScript
import { Component, OnDestroy, OnInit, inject } from '@angular/core'
|
|
import { NgbModal } from '@ng-bootstrap/ng-bootstrap'
|
|
import { NgxBootstrapIconsModule } from 'ngx-bootstrap-icons'
|
|
import { Subject, first, takeUntil } from 'rxjs'
|
|
import { Group } from 'src/app/data/group'
|
|
import { User } from 'src/app/data/user'
|
|
import { IfPermissionsDirective } from 'src/app/directives/if-permissions.directive'
|
|
import { PermissionsService } from 'src/app/services/permissions.service'
|
|
import { GroupService } from 'src/app/services/rest/group.service'
|
|
import { UserService } from 'src/app/services/rest/user.service'
|
|
import { SettingsService } from 'src/app/services/settings.service'
|
|
import { ToastService } from 'src/app/services/toast.service'
|
|
import { setLocationHref } from 'src/app/utils/navigation'
|
|
import { ConfirmDialogComponent } from '../../common/confirm-dialog/confirm-dialog.component'
|
|
import { EditDialogMode } from '../../common/edit-dialog/edit-dialog.component'
|
|
import { GroupEditDialogComponent } from '../../common/edit-dialog/group-edit-dialog/group-edit-dialog.component'
|
|
import { UserEditDialogComponent } from '../../common/edit-dialog/user-edit-dialog/user-edit-dialog.component'
|
|
import { PageHeaderComponent } from '../../common/page-header/page-header.component'
|
|
import { ComponentWithPermissions } from '../../with-permissions/with-permissions.component'
|
|
|
|
@Component({
|
|
selector: 'pngx-users-groups',
|
|
templateUrl: './users-groups.component.html',
|
|
styleUrls: ['./users-groups.component.scss'],
|
|
imports: [
|
|
PageHeaderComponent,
|
|
IfPermissionsDirective,
|
|
NgxBootstrapIconsModule,
|
|
],
|
|
})
|
|
export class UsersAndGroupsComponent
|
|
extends ComponentWithPermissions
|
|
implements OnInit, OnDestroy
|
|
{
|
|
private usersService = inject(UserService)
|
|
private groupsService = inject(GroupService)
|
|
private toastService = inject(ToastService)
|
|
private modalService = inject(NgbModal)
|
|
permissionsService = inject(PermissionsService)
|
|
private settings = inject(SettingsService)
|
|
|
|
users: User[]
|
|
groups: Group[]
|
|
|
|
unsubscribeNotifier: Subject<any> = new Subject()
|
|
|
|
ngOnInit(): void {
|
|
this.usersService
|
|
.listAll(null, null, { full_perms: true })
|
|
.pipe(first(), takeUntil(this.unsubscribeNotifier))
|
|
.subscribe({
|
|
next: (r) => {
|
|
this.users = r.results
|
|
},
|
|
error: (e) => {
|
|
this.toastService.showError($localize`Error retrieving users`, e)
|
|
},
|
|
})
|
|
|
|
this.groupsService
|
|
.listAll(null, null, { full_perms: true })
|
|
.pipe(first(), takeUntil(this.unsubscribeNotifier))
|
|
.subscribe({
|
|
next: (r) => {
|
|
this.groups = r.results
|
|
},
|
|
error: (e) => {
|
|
this.toastService.showError($localize`Error retrieving groups`, e)
|
|
},
|
|
})
|
|
}
|
|
|
|
ngOnDestroy() {
|
|
this.unsubscribeNotifier.next(true)
|
|
}
|
|
|
|
editUser(user: User = null) {
|
|
var modal = this.modalService.open(UserEditDialogComponent, {
|
|
backdrop: 'static',
|
|
size: 'xl',
|
|
})
|
|
modal.componentInstance.dialogMode = user
|
|
? EditDialogMode.EDIT
|
|
: EditDialogMode.CREATE
|
|
modal.componentInstance.object = user
|
|
modal.componentInstance.succeeded
|
|
.pipe(takeUntil(this.unsubscribeNotifier))
|
|
.subscribe((newUser: User) => {
|
|
if (
|
|
newUser.id === this.settings.currentUser.id &&
|
|
(modal.componentInstance as UserEditDialogComponent).passwordIsSet
|
|
) {
|
|
this.toastService.showInfo(
|
|
$localize`Password has been changed, you will be logged out momentarily.`
|
|
)
|
|
setTimeout(() => {
|
|
setLocationHref(
|
|
`${window.location.origin}/accounts/logout/?next=/accounts/login/?next=/`
|
|
)
|
|
}, 2500)
|
|
} else {
|
|
this.toastService.showInfo(
|
|
$localize`Saved user "${newUser.username}".`
|
|
)
|
|
this.usersService.listAll().subscribe((r) => {
|
|
this.users = r.results
|
|
})
|
|
}
|
|
})
|
|
modal.componentInstance.failed
|
|
.pipe(takeUntil(this.unsubscribeNotifier))
|
|
.subscribe((e) => {
|
|
this.toastService.showError($localize`Error saving user.`, e)
|
|
})
|
|
}
|
|
|
|
deleteUser(user: User) {
|
|
let modal = this.modalService.open(ConfirmDialogComponent, {
|
|
backdrop: 'static',
|
|
})
|
|
modal.componentInstance.title = $localize`Confirm delete user account`
|
|
modal.componentInstance.messageBold = $localize`This operation will permanently delete this user account.`
|
|
modal.componentInstance.message = $localize`This operation cannot be undone.`
|
|
modal.componentInstance.btnClass = 'btn-danger'
|
|
modal.componentInstance.btnCaption = $localize`Proceed`
|
|
modal.componentInstance.confirmClicked.subscribe(() => {
|
|
modal.componentInstance.buttonsEnabled = false
|
|
this.usersService.delete(user).subscribe({
|
|
next: () => {
|
|
modal.close()
|
|
this.toastService.showInfo($localize`Deleted user "${user.username}"`)
|
|
this.usersService.listAll().subscribe((r) => {
|
|
this.users = r.results
|
|
})
|
|
},
|
|
error: (e) => {
|
|
this.toastService.showError(
|
|
$localize`Error deleting user "${user.username}".`,
|
|
e
|
|
)
|
|
},
|
|
})
|
|
})
|
|
}
|
|
|
|
editGroup(group: Group = null) {
|
|
var modal = this.modalService.open(GroupEditDialogComponent, {
|
|
backdrop: 'static',
|
|
size: 'lg',
|
|
})
|
|
modal.componentInstance.dialogMode = group
|
|
? EditDialogMode.EDIT
|
|
: EditDialogMode.CREATE
|
|
modal.componentInstance.object = group
|
|
modal.componentInstance.succeeded
|
|
.pipe(takeUntil(this.unsubscribeNotifier))
|
|
.subscribe((newGroup) => {
|
|
this.toastService.showInfo($localize`Saved group "${newGroup.name}".`)
|
|
this.groupsService.listAll().subscribe((r) => {
|
|
this.groups = r.results
|
|
})
|
|
})
|
|
modal.componentInstance.failed
|
|
.pipe(takeUntil(this.unsubscribeNotifier))
|
|
.subscribe((e) => {
|
|
this.toastService.showError($localize`Error saving group.`, e)
|
|
})
|
|
}
|
|
|
|
deleteGroup(group: Group) {
|
|
let modal = this.modalService.open(ConfirmDialogComponent, {
|
|
backdrop: 'static',
|
|
})
|
|
modal.componentInstance.title = $localize`Confirm delete user group`
|
|
modal.componentInstance.messageBold = $localize`This operation will permanently delete this user group.`
|
|
modal.componentInstance.message = $localize`This operation cannot be undone.`
|
|
modal.componentInstance.btnClass = 'btn-danger'
|
|
modal.componentInstance.btnCaption = $localize`Proceed`
|
|
modal.componentInstance.confirmClicked.subscribe(() => {
|
|
modal.componentInstance.buttonsEnabled = false
|
|
this.groupsService.delete(group).subscribe({
|
|
next: () => {
|
|
modal.close()
|
|
this.toastService.showInfo($localize`Deleted group "${group.name}"`)
|
|
this.groupsService.listAll().subscribe((r) => {
|
|
this.groups = r.results
|
|
})
|
|
},
|
|
error: (e) => {
|
|
this.toastService.showError(
|
|
$localize`Error deleting group "${group.name}".`,
|
|
e
|
|
)
|
|
},
|
|
})
|
|
})
|
|
}
|
|
|
|
getGroupName(id: number): string {
|
|
return this.groups?.find((g) => g.id === id)?.name ?? ''
|
|
}
|
|
}
|