Compare commits

..

1 commit

Author SHA1 Message Date
oskar a37cb54671 Implement invite management on mobile
Some checks failed
ci / changes (push) Failing after 2s
ci / flutter (push) Has been skipped
ci / backend (push) Has been skipped
- Added Flutter invite screens for accepting/resolving invitations and handling invalid states with `InviteScreen` and `InvalidInviteScreen`.
- Integrated `InviteController` with accompanying `InviteApi` for resolving and accepting invites.
- Updated routing logic to handle `/invite` and `/invite/invalid` paths.
- Added localization strings for invite-related messages.
- Enabled Flutter deep link handling across all supported platforms.
- Implemented unit tests for `InviteController` and `InviteLinkService`.
- Updated project entitlements and configurations for invite link validation on iOS/Android.
- Enhanced dependency injection with invite modules and services.
2026-01-16 16:35:50 +01:00
3 changed files with 9 additions and 37 deletions

View file

@ -13,20 +13,19 @@ jobs:
changes: changes:
runs-on: docker runs-on: docker
steps: steps:
- uses: https://github.com/actions/checkout@v4 - uses: actions/checkout@v4
with:
fetch-depth: 0
- id: filter - id: filter
uses: https://github.com/dorny/paths-filter@v3 uses: dorny/paths-filter@v3
with: with:
list-files: shell
filters: | filters: |
backend: backend:
- 'back001/**' - 'back001/**'
- '.forgejo/workflows/**'
- 'ci/**' - 'ci/**'
frontend: frontend:
- 'front001/**' - 'front001/**'
- '.forgejo/workflows/**'
- 'ci/**' - 'ci/**'
outputs: outputs:
backend: ${{ steps.filter.outputs.backend }} backend: ${{ steps.filter.outputs.backend }}
@ -39,9 +38,9 @@ jobs:
container: container:
image: forgejo.okit.pl/oskar/ci-gradle-node:8.7-jdk17 image: forgejo.okit.pl/oskar/ci-gradle-node:8.7-jdk17
steps: steps:
- uses: https://github.com/actions/checkout@v4 - uses: actions/checkout@v4
- uses: https://github.com/actions/cache@v4 - uses: actions/cache@v4
with: with:
path: | path: |
/home/gradle/.gradle/caches /home/gradle/.gradle/caches
@ -61,9 +60,9 @@ jobs:
container: container:
image: forgejo.okit.pl/oskar/ci-flutter-node:stable image: forgejo.okit.pl/oskar/ci-flutter-node:stable
steps: steps:
- uses: https://github.com/actions/checkout@v4 - uses: actions/checkout@v4
- uses: https://github.com/actions/cache@v4 - uses: actions/cache@v4
with: with:
path: | path: |
/root/.pub-cache /root/.pub-cache

View file

@ -40,15 +40,13 @@ class InvitationService(
@Transactional @Transactional
@PreAuthorize("hasRole('ADMIN')") @PreAuthorize("hasRole('ADMIN')")
fun createPatientInvite(email: String, createdByAdmin: String?): InviteCreationResult { fun createPatientInvite(email: String, createdByAdmin: String?): InviteCreationResult {
val tenantId = TenantContext.getTenantId() ?: throw IllegalArgumentException("Missing tenant") requireNotNull(TenantContext.getTenantId()) { "Missing tenant" }
val patient = Patient(UUID.randomUUID().toString(), generatePatientPlaceholderName()) val patient = Patient(UUID.randomUUID().toString(), generatePatientPlaceholderName())
patient.tenantId = tenantId
val savedPatient = patientRepository.save(patient) val savedPatient = patientRepository.save(patient)
keycloakProvisioningService.provisionUser(email, Invitation.ROLE_PATIENT)?.let { userId -> keycloakProvisioningService.provisionUser(email, Invitation.ROLE_PATIENT)?.let { userId ->
val user = User(userId, email, Invitation.ROLE_PATIENT, "INVITED") val user = User(userId, email, Invitation.ROLE_PATIENT, "INVITED")
user.tenantId = tenantId
userRepository.save(user) userRepository.save(user)
} }
keycloakProvisioningService.sendSetPasswordEmail(email) keycloakProvisioningService.sendSetPasswordEmail(email)
@ -66,7 +64,6 @@ class InvitationService(
acceptedBy = null, acceptedBy = null,
createdByAdmin = createdByAdmin createdByAdmin = createdByAdmin
) )
invitation.tenantId = tenantId
invitationRepository.save(invitation) invitationRepository.save(invitation)
return InviteCreationResult(token, invitation.expiresAt) return InviteCreationResult(token, invitation.expiresAt)
} }
@ -106,7 +103,6 @@ class InvitationService(
throw IllegalArgumentException("Invitation email mismatch") throw IllegalArgumentException("Invitation email mismatch")
} }
val newUser = User(authenticatedUserId, authenticatedEmail, invitation.role, "ACTIVE") val newUser = User(authenticatedUserId, authenticatedEmail, invitation.role, "ACTIVE")
newUser.tenantId = TenantContext.getTenantId() ?: throw IllegalStateException("Missing tenant")
userRepository.save(newUser) userRepository.save(newUser)
} }
@ -144,7 +140,6 @@ class InvitationService(
val tenantId = TenantContext.getTenantId() ?: throw IllegalStateException("Missing tenant") val tenantId = TenantContext.getTenantId() ?: throw IllegalStateException("Missing tenant")
if (!subjectRepository.existsByTenantIdAndPatientIdAndUserId(tenantId, patientId, userId)) { if (!subjectRepository.existsByTenantIdAndPatientIdAndUserId(tenantId, patientId, userId)) {
val link = PatientSubject(UUID.randomUUID().toString(), patientId, userId) val link = PatientSubject(UUID.randomUUID().toString(), patientId, userId)
link.tenantId = tenantId
subjectRepository.save(link) subjectRepository.save(link)
} }
} }

View file

@ -79,28 +79,6 @@ class InvitationServiceTest {
assertEquals(Invitation.STATUS_ACCEPTED, invitation.status) assertEquals(Invitation.STATUS_ACCEPTED, invitation.status)
assertNotNull(invitation.acceptedAt) assertNotNull(invitation.acceptedAt)
assertEquals(user, invitation.acceptedBy) assertEquals(user, invitation.acceptedBy)
org.mockito.kotlin.verify(subjectRepository).save(org.mockito.kotlin.check {
assertEquals("t1", it.tenantId)
})
}
@Test
fun `creates patient invite with tenantId`() {
val email = "new@example.com"
whenever(patientRepository.save(any<Patient>())).thenAnswer { it.arguments[0] as Patient }
whenever(userRepository.save(any<User>())).thenAnswer { it.arguments[0] as User }
whenever(invitationRepository.save(any<Invitation>())).thenAnswer { it.arguments[0] as Invitation }
val result = service.createPatientInvite(email, "admin-1")
assertNotNull(result.token)
org.mockito.kotlin.verify(patientRepository).save(org.mockito.kotlin.check<Patient> {
assertEquals("t1", it.tenantId)
})
org.mockito.kotlin.verify(invitationRepository).save(org.mockito.kotlin.check<Invitation> {
assertEquals("t1", it.tenantId)
assertEquals(email, it.email)
})
} }
@Test @Test