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