-
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.
Merge branch 'main' into as-fix-widths-in-repeaters
- Loading branch information
Showing
113 changed files
with
2,472 additions
and
851 deletions.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
apps/contentful-apps/pages/fields/admin-only-boolean-field.tsx
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,16 @@ | ||
import { FieldExtensionSDK } from '@contentful/app-sdk' | ||
import { Paragraph } from '@contentful/f36-components' | ||
import { BooleanEditor } from '@contentful/field-editor-boolean' | ||
import { useSDK } from '@contentful/react-apps-toolkit' | ||
|
||
const AdminOnlyBooleanField = () => { | ||
const sdk = useSDK<FieldExtensionSDK>() | ||
|
||
if (!sdk.user.spaceMembership.admin) { | ||
return <Paragraph>(Only admins can edit this field)</Paragraph> | ||
} | ||
|
||
return <BooleanEditor field={sdk.field} isInitiallyDisabled={false} /> | ||
} | ||
|
||
export default AdminOnlyBooleanField |
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
63 changes: 63 additions & 0 deletions
63
...stem/backend/src/app/modules/case/interceptors/defendantIndictmentAccessed.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,63 @@ | ||
import { | ||
CallHandler, | ||
ExecutionContext, | ||
Injectable, | ||
NestInterceptor, | ||
} from '@nestjs/common' | ||
|
||
import { | ||
DefendantEventType, | ||
isIndictmentCase, | ||
isPrisonAdminUser, | ||
User, | ||
} from '@island.is/judicial-system/types' | ||
|
||
import { DefendantEventLog, DefendantService } from '../../defendant' | ||
import { Case } from '../models/case.model' | ||
|
||
const hasValidOpenByPrisonAdminEvent = ( | ||
defendantEventLogs: DefendantEventLog[], | ||
) => { | ||
const sentToPrisonAdminDate = DefendantEventLog.getDefendantEventLogTypeDate({ | ||
defendantEventLogs, | ||
eventType: DefendantEventType.SENT_TO_PRISON_ADMIN, | ||
}) | ||
const openedByPrisonAdminDate = | ||
DefendantEventLog.getDefendantEventLogTypeDate({ | ||
defendantEventLogs, | ||
eventType: DefendantEventType.OPENED_BY_PRISON_ADMIN, | ||
}) | ||
return ( | ||
sentToPrisonAdminDate && | ||
openedByPrisonAdminDate && | ||
sentToPrisonAdminDate <= openedByPrisonAdminDate | ||
) | ||
} | ||
|
||
@Injectable() | ||
export class DefendantIndictmentAccessedInterceptor implements NestInterceptor { | ||
constructor(private readonly defendantService: DefendantService) {} | ||
|
||
intercept(context: ExecutionContext, next: CallHandler) { | ||
const request = context.switchToHttp().getRequest() | ||
const user: User = request.user | ||
const theCase: Case = request.case | ||
|
||
if (isIndictmentCase(theCase.type) && isPrisonAdminUser(user)) { | ||
const defendantsIndictmentNotOpened = theCase.defendants?.filter( | ||
({ isSentToPrisonAdmin, eventLogs = [] }) => | ||
isSentToPrisonAdmin && !hasValidOpenByPrisonAdminEvent(eventLogs), | ||
) | ||
|
||
// create new events for all defendants that prison admin has not accessed according to defendant event logs | ||
defendantsIndictmentNotOpened?.forEach((defendant) => | ||
this.defendantService.createDefendantEvent({ | ||
caseId: theCase.id, | ||
defendantId: defendant.id, | ||
eventType: DefendantEventType.OPENED_BY_PRISON_ADMIN, | ||
}), | ||
) | ||
} | ||
return next.handle() | ||
} | ||
} |
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
Oops, something went wrong.