update permissions service code
This commit is contained in:
parent
7af8945fcb
commit
1bbe74dda9
@ -11,71 +11,44 @@ import { DossierWrapper } from '@state/model/dossier.wrapper';
|
|||||||
export class PermissionsService {
|
export class PermissionsService {
|
||||||
constructor(
|
constructor(
|
||||||
private readonly _appStateService: AppStateService,
|
private readonly _appStateService: AppStateService,
|
||||||
private _userService: UserService
|
private readonly _userService: UserService
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
get currentUser() {
|
get currentUser(): UserWrapper {
|
||||||
return this._userService.user;
|
return this._userService.user;
|
||||||
}
|
}
|
||||||
|
|
||||||
get currentUserId() {
|
|
||||||
return this._userService.userId;
|
|
||||||
}
|
|
||||||
|
|
||||||
isManager(user?: User) {
|
isManager(user?: User) {
|
||||||
return this._userService.isManager(user);
|
return this._userService.isManager(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
isReviewerOrApprover(fileStatus?: FileStatusWrapper) {
|
isReviewerOrApprover(fileStatus?: FileStatusWrapper): boolean {
|
||||||
return this.isFileReviewer(fileStatus) || this.isApprover();
|
return this.isFileReviewer(fileStatus) || this.isApprover();
|
||||||
}
|
}
|
||||||
|
|
||||||
dossierReanalysisRequired(dossier?: DossierWrapper) {
|
dossierReanalysisRequired(dossier: DossierWrapper): boolean {
|
||||||
for (const file of dossier.files) {
|
for (const file of dossier.files) if (this.fileRequiresReanalysis(file)) return true;
|
||||||
const fileReanalysisRequired = this.fileRequiresReanalysis(file);
|
|
||||||
if (fileReanalysisRequired) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fileRequiresReanalysis(fileStatus?: FileStatusWrapper) {
|
fileRequiresReanalysis(fileStatus = this._activeFile): boolean {
|
||||||
if (!fileStatus) {
|
|
||||||
fileStatus = this._appStateService.activeFile;
|
|
||||||
}
|
|
||||||
if (!fileStatus) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return fileStatus.analysisRequired;
|
return fileStatus.analysisRequired;
|
||||||
}
|
}
|
||||||
|
|
||||||
displayReanalyseBtn(dossier?: DossierWrapper) {
|
displayReanalyseBtn(dossier = this._activeDossier): boolean {
|
||||||
if (!dossier) {
|
|
||||||
dossier = this._appStateService.activeDossier;
|
|
||||||
}
|
|
||||||
if (!dossier) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return (
|
return (
|
||||||
this.isApprover(dossier) &&
|
this.isApprover(dossier) &&
|
||||||
dossier.files.filter(file => this.fileRequiresReanalysis(file)).length > 0
|
dossier.files.filter(file => this.fileRequiresReanalysis(file)).length > 0
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
canToggleAnalysis(fileStatus: FileStatusWrapper) {
|
canToggleAnalysis(fileStatus: FileStatusWrapper): boolean {
|
||||||
return (
|
return (
|
||||||
this.isManager() &&
|
this.isManager() &&
|
||||||
['UNASSIGNED', 'UNDER_REVIEW', 'UNDER_APPROVAL'].includes(fileStatus.status)
|
['UNASSIGNED', 'UNDER_REVIEW', 'UNDER_APPROVAL'].includes(fileStatus.status)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
canReanalyseFile(fileStatus?: FileStatusWrapper) {
|
canReanalyseFile(fileStatus = this._activeFile): boolean {
|
||||||
if (!fileStatus) {
|
|
||||||
fileStatus = this._appStateService.activeFile;
|
|
||||||
}
|
|
||||||
if (!fileStatus) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return (
|
return (
|
||||||
(this.fileRequiresReanalysis(fileStatus) &&
|
(this.fileRequiresReanalysis(fileStatus) &&
|
||||||
(this.isReviewerOrApprover(fileStatus) || fileStatus.isUnassigned)) ||
|
(this.isReviewerOrApprover(fileStatus) || fileStatus.isUnassigned)) ||
|
||||||
@ -83,38 +56,19 @@ export class PermissionsService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
isFileReviewer(fileStatus?: FileStatusWrapper) {
|
isFileReviewer(fileStatus = this._activeFile): boolean {
|
||||||
if (!fileStatus) {
|
|
||||||
fileStatus = this._appStateService.activeFile;
|
|
||||||
}
|
|
||||||
if (!fileStatus) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return fileStatus.currentReviewer === this._userService.userId;
|
return fileStatus.currentReviewer === this._userService.userId;
|
||||||
}
|
}
|
||||||
|
|
||||||
canDeleteFile(fileStatus?: FileStatusWrapper, dossier?: DossierWrapper) {
|
canDeleteFile(fileStatus = this._activeFile, dossier?: DossierWrapper): boolean {
|
||||||
return this.isOwner(dossier) || fileStatus.isUnassigned;
|
return this.isOwner(dossier) || fileStatus.isUnassigned;
|
||||||
}
|
}
|
||||||
|
|
||||||
isApprovedOrUnderApproval(fileStatus?: FileStatusWrapper) {
|
isApprovedOrUnderApproval(fileStatus = this._activeFile): boolean {
|
||||||
if (!fileStatus) {
|
|
||||||
fileStatus = this._appStateService.activeFile;
|
|
||||||
}
|
|
||||||
if (!fileStatus) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return fileStatus.isApprovedOrUnderApproval;
|
return fileStatus.isApprovedOrUnderApproval;
|
||||||
}
|
}
|
||||||
|
|
||||||
canAssignToSelf(fileStatus?: FileStatusWrapper) {
|
canAssignToSelf(fileStatus = this._activeFile): boolean {
|
||||||
if (!fileStatus) {
|
|
||||||
fileStatus = this._appStateService.activeFile;
|
|
||||||
}
|
|
||||||
if (!fileStatus) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
const precondition =
|
const precondition =
|
||||||
this.isDossierMember() &&
|
this.isDossierMember() &&
|
||||||
!fileStatus.isProcessing &&
|
!fileStatus.isProcessing &&
|
||||||
@ -134,14 +88,7 @@ export class PermissionsService {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
canAssignUser(fileStatus?: FileStatusWrapper) {
|
canAssignUser(fileStatus = this._activeFile): boolean {
|
||||||
if (!fileStatus) {
|
|
||||||
fileStatus = this._appStateService.activeFile;
|
|
||||||
}
|
|
||||||
if (!fileStatus) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
const precondition =
|
const precondition =
|
||||||
this.isDossierMember() &&
|
this.isDossierMember() &&
|
||||||
!fileStatus.isProcessing &&
|
!fileStatus.isProcessing &&
|
||||||
@ -152,237 +99,119 @@ export class PermissionsService {
|
|||||||
if (precondition) {
|
if (precondition) {
|
||||||
if (
|
if (
|
||||||
(fileStatus.isUnassigned || fileStatus.isUnderReview) &&
|
(fileStatus.isUnassigned || fileStatus.isUnderReview) &&
|
||||||
this._appStateService.activeDossier.hasMoreThanOneReviewer
|
this._activeDossier.hasMoreThanOneReviewer
|
||||||
) {
|
) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (
|
if (fileStatus.isUnderApproval && this._activeDossier.hasMoreThanOneApprover) {
|
||||||
fileStatus.isUnderApproval &&
|
|
||||||
this.isApprover() &&
|
|
||||||
this._appStateService.activeDossier.hasMoreThanOneApprover
|
|
||||||
) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
canSetUnderReview(fileStatus?: FileStatusWrapper) {
|
canSetUnderReview(fileStatus = this._activeFile): boolean {
|
||||||
if (!fileStatus) {
|
return fileStatus?.isUnderApproval && this.isApprover();
|
||||||
fileStatus = this._appStateService.activeFile;
|
|
||||||
}
|
|
||||||
if (!fileStatus) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return fileStatus.isUnderApproval && this.isApprover();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
isReadyForApproval(fileStatus?: FileStatusWrapper) {
|
isReadyForApproval(fileStatus = this._activeFile): boolean {
|
||||||
if (!fileStatus) {
|
|
||||||
fileStatus = this._appStateService.activeFile;
|
|
||||||
}
|
|
||||||
if (!fileStatus) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return this.canSetUnderReview(fileStatus);
|
return this.canSetUnderReview(fileStatus);
|
||||||
}
|
}
|
||||||
|
|
||||||
canApprove(fileStatus?: FileStatusWrapper) {
|
canApprove(fileStatus = this._activeFile): boolean {
|
||||||
if (!fileStatus) {
|
return !fileStatus?.analysisRequired;
|
||||||
fileStatus = this._appStateService.activeFile;
|
|
||||||
}
|
|
||||||
if (!fileStatus) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return !fileStatus.analysisRequired;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
canSetUnderApproval(fileStatus?: FileStatusWrapper) {
|
canSetUnderApproval(fileStatus = this._activeFile): boolean {
|
||||||
if (!fileStatus) {
|
return fileStatus?.isUnderReview && this.isReviewerOrApprover(fileStatus);
|
||||||
fileStatus = this._appStateService.activeFile;
|
|
||||||
}
|
|
||||||
if (!fileStatus) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return fileStatus.isUnderReview && this.isReviewerOrApprover(fileStatus);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
isOwner(dossier?: DossierWrapper, user?: UserWrapper) {
|
isOwner(dossier = this._activeDossier, user = this.currentUser): boolean {
|
||||||
if (!user) {
|
return dossier?.ownerId === user.id;
|
||||||
user = this._userService.user;
|
|
||||||
}
|
|
||||||
if (!dossier) {
|
|
||||||
dossier = this._appStateService.activeDossier;
|
|
||||||
}
|
|
||||||
if (!dossier) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return dossier.ownerId === user.id;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
isApprover(dossier?: DossierWrapper, user?: UserWrapper) {
|
isApprover(dossier = this._activeDossier, user = this.currentUser): boolean {
|
||||||
if (!user) {
|
return dossier?.approverIds.indexOf(user.id) >= 0;
|
||||||
user = this._userService.user;
|
|
||||||
}
|
|
||||||
if (!dossier) {
|
|
||||||
dossier = this._appStateService.activeDossier;
|
|
||||||
}
|
|
||||||
if (!dossier) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return dossier.approverIds?.indexOf(user.id) >= 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
isDossierMember(dossier?: DossierWrapper, user?: UserWrapper) {
|
isReviewer(dossier = this._activeDossier, user = this.currentUser): boolean {
|
||||||
if (!user) {
|
return this.isDossierMember(dossier, user) && !this.isApprover(dossier, user);
|
||||||
user = this._userService.user;
|
|
||||||
}
|
|
||||||
if (!dossier) {
|
|
||||||
dossier = this._appStateService.activeDossier;
|
|
||||||
}
|
|
||||||
if (!dossier) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return dossier.memberIds?.includes(user.id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
canPerformAnnotationActions(fileStatus?: FileStatusWrapper) {
|
isDossierMember(dossier = this._activeDossier, user = this.currentUser): boolean {
|
||||||
if (!fileStatus) {
|
return dossier?.memberIds.includes(user.id);
|
||||||
fileStatus = this._appStateService.activeFile;
|
|
||||||
}
|
|
||||||
if (!fileStatus) {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
canPerformAnnotationActions(fileStatus = this._activeFile): boolean {
|
||||||
return (
|
return (
|
||||||
(fileStatus.status === 'UNDER_APPROVAL' || fileStatus.status === 'UNDER_REVIEW') &&
|
['UNDER_REVIEW', 'UNDER_APPROVAL'].includes(fileStatus?.status) &&
|
||||||
this.isFileReviewer(fileStatus)
|
this.isFileReviewer(fileStatus)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
canOpenFile(fileStatus: FileStatusWrapper) {
|
canOpenFile(fileStatus = this._activeFile): boolean {
|
||||||
if (!fileStatus) {
|
return !fileStatus?.isError && !fileStatus?.isProcessing && !fileStatus?.isPending;
|
||||||
fileStatus = this._appStateService.activeFile;
|
|
||||||
}
|
|
||||||
if (!fileStatus) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return !fileStatus.isError && !fileStatus.isProcessing && !fileStatus.isPending;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
canUndoApproval(fileStatus: FileStatusWrapper) {
|
canUndoApproval(fileStatus = this._activeFile): boolean {
|
||||||
if (!fileStatus) {
|
return fileStatus?.isApproved && this.isApprover();
|
||||||
fileStatus = this._appStateService.activeFile;
|
|
||||||
}
|
|
||||||
if (!fileStatus) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return fileStatus.status === 'APPROVED' && this.isApprover();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
canUndoUnderApproval(fileStatus: any) {
|
canUndoUnderApproval(fileStatus = this._activeFile): boolean {
|
||||||
if (!fileStatus) {
|
return fileStatus?.isUnderApproval && this.isDossierMember();
|
||||||
fileStatus = this._appStateService.activeFile;
|
|
||||||
}
|
|
||||||
if (!fileStatus) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return fileStatus.status === 'UNDER_APPROVAL' && this.isDossierMember();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
canMarkPagesAsViewed(fileStatus?: FileStatusWrapper) {
|
canMarkPagesAsViewed(fileStatus = this._activeFile): boolean {
|
||||||
if (!fileStatus) {
|
|
||||||
fileStatus = this._appStateService.activeFile;
|
|
||||||
}
|
|
||||||
if (!fileStatus) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return (
|
return (
|
||||||
(fileStatus.status === 'UNDER_REVIEW' || fileStatus.status === 'UNDER_APPROVAL') &&
|
['UNDER_REVIEW', 'UNDER_APPROVAL'].includes(fileStatus?.status) &&
|
||||||
this.isFileReviewer(fileStatus)
|
this.isFileReviewer(fileStatus)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
canDownloadFiles(fileStatus: FileStatusWrapper) {
|
canDownloadFiles(fileStatus = this._activeFile): boolean {
|
||||||
if (!fileStatus) {
|
const dossier = this._appStateService.getDossierById(fileStatus?.dossierId);
|
||||||
fileStatus = this._appStateService.activeFile;
|
if (!dossier) return false;
|
||||||
}
|
|
||||||
if (!fileStatus) {
|
return fileStatus.isApproved && this.isApprover(dossier);
|
||||||
return false;
|
|
||||||
}
|
|
||||||
const dossier = this._appStateService.getDossierById(fileStatus.dossierId);
|
|
||||||
if (!dossier) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return fileStatus.status === 'APPROVED' && this.isApprover(dossier);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
canDeleteDossier(dossier?: DossierWrapper) {
|
canDeleteDossier(dossier = this._activeDossier): boolean {
|
||||||
if (!dossier) {
|
return dossier?.files.reduce((acc, file) => acc && this.canDeleteFile(file, dossier), true);
|
||||||
dossier = this._appStateService.activeDossier;
|
|
||||||
}
|
|
||||||
if (!dossier) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return dossier.files.reduce((acc, file) => acc && this.canDeleteFile(file, dossier), true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
isAdmin(user?: UserWrapper) {
|
isAdmin(user = this.currentUser): boolean {
|
||||||
if (!user) {
|
|
||||||
user = this._userService.user;
|
|
||||||
}
|
|
||||||
if (!user) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return user.isAdmin;
|
return user.isAdmin;
|
||||||
}
|
}
|
||||||
|
|
||||||
isUserAdmin(user?: UserWrapper) {
|
isUserAdmin(user = this.currentUser): boolean {
|
||||||
if (!user) {
|
|
||||||
user = this._userService.user;
|
|
||||||
}
|
|
||||||
if (!user) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return user.isUserAdmin;
|
return user.isUserAdmin;
|
||||||
}
|
}
|
||||||
|
|
||||||
isUser(user?: UserWrapper) {
|
isUser(user = this.currentUser): boolean {
|
||||||
if (!user) {
|
|
||||||
user = this._userService.user;
|
|
||||||
}
|
|
||||||
if (!user) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return user.isUser;
|
return user.isUser;
|
||||||
}
|
}
|
||||||
|
|
||||||
canOcrFile(fileStatus?: FileStatusWrapper) {
|
canOcrFile(fileStatus = this._activeFile): boolean {
|
||||||
if (!fileStatus) {
|
|
||||||
fileStatus = this._appStateService.activeFile;
|
|
||||||
}
|
|
||||||
if (!fileStatus) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return (
|
return (
|
||||||
!fileStatus.isExcluded &&
|
!fileStatus.isExcluded &&
|
||||||
!fileStatus.ocrTime &&
|
!fileStatus.ocrTime &&
|
||||||
(fileStatus.status === 'UNASSIGNED' ||
|
['UNASSIGNED', 'UNDER_REVIEW', 'UNDER_APPROVAL'].includes(fileStatus.status)
|
||||||
fileStatus.status === 'UNDER_REVIEW' ||
|
|
||||||
fileStatus.status === 'UNDER_APPROVAL')
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
canManageUsers(user?: UserWrapper) {
|
canManageUsers(user?: UserWrapper): boolean {
|
||||||
return this.isUserAdmin(user);
|
return this.isUserAdmin(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
canAddComment(fileStatus?: FileStatusWrapper) {
|
canAddComment(fileStatus = this._activeFile): boolean {
|
||||||
if (!fileStatus) {
|
|
||||||
fileStatus = this._appStateService.activeFile;
|
|
||||||
}
|
|
||||||
if (!fileStatus) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return this.isFileReviewer(fileStatus) || this.isApprover();
|
return this.isFileReviewer(fileStatus) || this.isApprover();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private get _activeFile(): FileStatusWrapper | undefined {
|
||||||
|
return this._appStateService.activeFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
private get _activeDossier(): DossierWrapper | undefined {
|
||||||
|
return this._appStateService.activeDossier;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -127,7 +127,7 @@ export class AppStateService {
|
|||||||
return this._appState.activeDossierId;
|
return this._appState.activeDossierId;
|
||||||
}
|
}
|
||||||
|
|
||||||
get activeDossier(): DossierWrapper {
|
get activeDossier(): DossierWrapper | undefined {
|
||||||
return this._appState.dossiers.find(p => p.dossierId === this.activeDossierId);
|
return this._appState.dossiers.find(p => p.dossierId === this.activeDossierId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -139,7 +139,7 @@ export class AppStateService {
|
|||||||
return this.allDossiers?.length > 0;
|
return this.allDossiers?.length > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
get activeFile(): FileStatusWrapper {
|
get activeFile(): FileStatusWrapper | undefined {
|
||||||
return this.activeDossier?.files.find(f => f.fileId === this.activeFileId);
|
return this.activeDossier?.files.find(f => f.fileId === this.activeFileId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user