-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(j-s): Prison users access to appeal case files (#15844)
* Create CaseFileInterceptor * Filter case files in interceptor * Only send appeal ruling for completed appeals * Refactor * Remove unused code * Refactor * Allow defence users to see all files * Refactor * Fix tests --------- Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
- Loading branch information
Showing
11 changed files
with
97 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
apps/judicial-system/backend/src/app/modules/case/interceptors/caseFile.interceptor.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import { Observable } from 'rxjs' | ||
import { map } from 'rxjs/operators' | ||
|
||
import { | ||
CallHandler, | ||
ExecutionContext, | ||
Injectable, | ||
NestInterceptor, | ||
} from '@nestjs/common' | ||
|
||
import { | ||
CaseAppealState, | ||
CaseFileCategory, | ||
isDefenceUser, | ||
isPrisonStaffUser, | ||
isPrisonSystemUser, | ||
User, | ||
} from '@island.is/judicial-system/types' | ||
|
||
import { Case } from '../models/case.model' | ||
|
||
@Injectable() | ||
export class CaseFileInterceptor implements NestInterceptor { | ||
intercept(context: ExecutionContext, next: CallHandler): Observable<Case> { | ||
const request = context.switchToHttp().getRequest() | ||
const user: User = request.user | ||
|
||
return next.handle().pipe( | ||
map((data: Case) => { | ||
if (isDefenceUser(user)) { | ||
return data | ||
} | ||
|
||
if ( | ||
isPrisonStaffUser(user) || | ||
data.appealState !== CaseAppealState.COMPLETED | ||
) { | ||
data.caseFiles?.splice(0, data.caseFiles.length) | ||
} else if (isPrisonSystemUser(user)) { | ||
data.caseFiles?.splice( | ||
0, | ||
data.caseFiles.length, | ||
...data.caseFiles.filter( | ||
(cf) => cf.category === CaseFileCategory.APPEAL_RULING, | ||
), | ||
) | ||
} | ||
|
||
return data | ||
}), | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters