Skip to content

Commit

Permalink
Merge pull request #6317 from espoon-voltti/more-auth-improvements
Browse files Browse the repository at this point in the history
Kevytkirjautumisen / palvelutuottajien kirjautumisen pikkuparannuksia
  • Loading branch information
Gekkio authored Jan 30, 2025
2 parents c5d99b8 + 88fd3ec commit cf12ef3
Show file tree
Hide file tree
Showing 13 changed files with 95 additions and 106 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ export function EmployeeList({ employees }: Props) {
externalId,
employeeNumber,
temporaryUnitName,
active
active,
hasSsn
}) => (
<LinkTr key={id} onClick={() => navigate(`/employees/${id}`)}>
<Td>
Expand All @@ -71,6 +72,7 @@ export function EmployeeList({ employees }: Props) {
</Name>
<Email>{email}</Email>
{!!externalId && <Details>{externalId}</Details>}
{hasSsn && <Details>{i18n.employees.hasSsn}</Details>}
{!!employeeNumber && (
<Details>
{i18n.employees.employeeNumber}: {employeeNumber}
Expand Down Expand Up @@ -155,6 +157,7 @@ export function EmployeeList({ employees }: Props) {
<Th>{i18n.employees.name}</Th>
<Th>{i18n.employees.rights}</Th>
<Th>{i18n.employees.lastLogin}</Th>
<Th />
</Tr>
</Thead>
<Tbody>{rows}</Tbody>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
//
// SPDX-License-Identifier: LGPL-2.1-or-later

import React, { useState } from 'react'
import React, { useCallback, useState } from 'react'
import { useNavigate } from 'react-router'
import styled from 'styled-components'

import { Failure } from 'lib-common/api'
import { globalRoles } from 'lib-common/api-types/employee-auth'
import { string } from 'lib-common/form/fields'
import { object, required, validated } from 'lib-common/form/form'
Expand All @@ -27,10 +28,10 @@ import {
FixedSpaceFlexWrap,
FixedSpaceRow
} from 'lib-components/layout/flex-helpers'
import { AlertBox } from 'lib-components/molecules/MessageBoxes'
import { MutateFormModal } from 'lib-components/molecules/modals/FormModal'
import { Label } from 'lib-components/typography'
import { faPlus } from 'lib-icons'
import { faSearch } from 'lib-icons'
import { faPlus, faSearch } from 'lib-icons'

import { useTranslation } from '../../state/i18n'
import { RequirePermittedGlobalAction } from '../../utils/roles'
Expand Down Expand Up @@ -183,16 +184,30 @@ const CreateModal = React.memo(function CreateModal({
const { i18n } = useTranslation()
const t = i18n.employees.newSsnEmployeeModal

const [ssnConflict, setSsnConflict] = useState(false)
const form = useForm(
createForm,
() => ({ ssn: '', firstName: '', lastName: '', email: '' }),
i18n.validationErrors
i18n.validationErrors,
{
onUpdate: (prev, next) => {
if (prev.ssn !== next.ssn) {
setSsnConflict(false)
}
return next
}
}
)
const ssn = useFormField(form, 'ssn')
const firstName = useFormField(form, 'firstName')
const lastName = useFormField(form, 'lastName')
const email = useFormField(form, 'email')

const onFailure = useCallback(
(failure: Failure<unknown>) => setSsnConflict(failure.statusCode === 409),
[setSsnConflict]
)

return (
<MutateFormModal
icon={faPlus}
Expand All @@ -203,8 +218,9 @@ const CreateModal = React.memo(function CreateModal({
body: form.value()
})}
resolveLabel={t.createButton}
resolveDisabled={!form.isValid()}
resolveDisabled={!form.isValid() || ssnConflict}
onSuccess={({ id }) => onSuccess(id)}
onFailure={onFailure}
rejectAction={onClose}
rejectLabel={i18n.common.cancel}
>
Expand Down Expand Up @@ -250,6 +266,7 @@ const CreateModal = React.memo(function CreateModal({
bind={email}
/>
</div>
{ssnConflict && <AlertBox message={t.ssnConflict} />}
</FixedSpaceColumn>
</MutateFormModal>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ export default React.memo(function UnitAccessControl({
employees.filter(
(employee) =>
employee.id !== user?.id &&
employee.externalId !== null &&
(employee.externalId !== null || employee.hasSsn) &&
employee.temporaryInUnitId === null &&
!daycareAclRows.some((row) => row.employee.id === employee.id)
),
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/lib-common/generated/api-types/pis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ export interface Employee {
email: string | null
externalId: string | null
firstName: string
hasSsn: boolean
id: EmployeeId
lastName: string
preferredFirstName: string | null
Expand Down Expand Up @@ -247,6 +248,7 @@ export interface EmployeeWithDaycareRoles {
externalId: string | null
firstName: string
globalRoles: UserRole[]
hasSsn: boolean
id: EmployeeId
lastLogin: HelsinkiDateTime | null
lastName: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2104,7 +2104,7 @@ const sv: Translations = {
unverifiedEmailWarning:
'Inloggning med e-post är endast tillåten om du har bekräftat din e-postadress',
updatePassword: 'Uppdatera lösenord',
activateCredentials: 'Salli sähköpostikirjautuminen',
activateCredentials: 'Tillåt inloggning med e-post',
activationSuccess: 'E-postinloggning aktiverad',
activationSuccessOk: 'Klart',
confirmPassword: 'Bekräfta lösenordet',
Expand Down
6 changes: 4 additions & 2 deletions frontend/src/lib-customizations/defaults/employee/i18n/fi.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4710,8 +4710,10 @@ export const fi = {
createNewSsnEmployee: 'Luo uusi hetullinen käyttäjä',
newSsnEmployeeModal: {
title: 'Lisää uusi hetullinen käyttäjä',
createButton: 'Luo tunnus'
}
createButton: 'Luo tunnus',
ssnConflict: 'Hetu on jo käytössä'
},
hasSsn: 'Hetullinen käyttäjä'
},
financeBasics: {
fees: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ class EmployeeControllerIntegrationTest : FullApplicationTest(resetDbBeforeEach
id = EmployeeId(UUID.randomUUID()),
temporaryInUnitId = null,
active = true,
hasSsn = false,
)

val employee2 =
Expand All @@ -293,6 +294,7 @@ class EmployeeControllerIntegrationTest : FullApplicationTest(resetDbBeforeEach
id = EmployeeId(UUID.randomUUID()),
temporaryInUnitId = null,
active = true,
hasSsn = false,
)

private fun Database.Read.hasActiveMessagingAccount(employeeId: EmployeeId) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ class VtjClientServiceTest : FullApplicationTest(resetDbBeforeEach = false) {
updated = null,
temporaryInUnitId = null,
active = true,
hasSsn = false,
)

private fun vtjRequestType(requestType: RequestType): RequestMatcher =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import fi.espoo.evaka.shared.*
import fi.espoo.evaka.shared.db.Database
import fi.espoo.evaka.shared.db.PredicateSql
import fi.espoo.evaka.shared.db.Row
import fi.espoo.evaka.shared.db.freeTextSearchPredicate
import fi.espoo.evaka.shared.db.personFreeTextSearchPredicate
import fi.espoo.evaka.shared.domain.EvakaClock
import fi.espoo.evaka.shared.domain.HelsinkiDateTime
import fi.espoo.evaka.shared.security.actionrule.AccessControlFilter
Expand Down Expand Up @@ -367,7 +367,8 @@ fun Database.Read.fetchApplicationSummaries(
)
}
else null,
if (searchTerms.isNotBlank()) freeTextSearchPredicate(listOf("child"), searchTerms)
if (searchTerms.isNotBlank())
personFreeTextSearchPredicate(listOf("child"), searchTerms)
else null,
when (transferApplications) {
TransferApplicationFilter.TRANSFER_ONLY ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import fi.espoo.evaka.shared.db.Database
import fi.espoo.evaka.shared.db.Predicate
import fi.espoo.evaka.shared.db.PredicateSql
import fi.espoo.evaka.shared.db.QuerySql
import fi.espoo.evaka.shared.db.freeTextSearchPredicate
import fi.espoo.evaka.shared.db.personFreeTextSearchPredicate
import fi.espoo.evaka.shared.domain.FiniteDateRange
import fi.espoo.evaka.shared.domain.HelsinkiDateTime
import fi.espoo.evaka.shared.mapToPaged
Expand Down Expand Up @@ -292,7 +292,7 @@ fun Database.Read.paginatedSearch(
}
else null,
if (searchTerms.isNotBlank())
freeTextSearchPredicate(listOf("head", "child"), searchTerms)
personFreeTextSearchPredicate(listOf("head", "child"), searchTerms)
else null,
if (periodStart != null) PredicateSql { where("invoice_date >= ${bind(periodStart)}") }
else null,
Expand Down
1 change: 1 addition & 0 deletions service/src/main/kotlin/fi/espoo/evaka/pis/Employee.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ data class Employee(
val updated: HelsinkiDateTime?,
val temporaryInUnitId: DaycareId?,
val active: Boolean,
val hasSsn: Boolean,
)

data class TemporaryEmployee(
Expand Down
Loading

0 comments on commit cf12ef3

Please sign in to comment.