Skip to content
Snippets Groups Projects
Verified Commit d5984d30 authored by Andreas Ellewsen's avatar Andreas Ellewsen
Browse files

Show invalid email status for invites in frontend

Introduces the invalid field on the Identity model. The field is used to
indicate that the Identity is in invalid. This is useful when a value is
not a working value, even though the value passes validation checks,
like unused national id numbers, emails tied to non-existing domains,
etc.

Resolves: GREG-252
parent 8b2effcc
No related branches found
No related tags found
1 merge request!326Notify sponsors of bad emails in sent invites
Pipeline #135303 passed
......@@ -82,7 +82,7 @@
"name": "Name",
"role": "Guest role",
"period": "Period",
"host": "Host",
"host": "Host",
"ou": "Organisation",
"department": "Department",
"choice": "Choices",
......@@ -103,6 +103,7 @@
"expiring_other": "Expiring in {{count}} days",
"expiring_one": "Expiring in {{count}} day",
"waitingForGuest": "Waiting for guest",
"invalidEmail": "Invalid e-mail address",
"waitingForSponsor": "Needs confirmation",
"invitationExpired": "Invitation expired"
},
......
......@@ -82,7 +82,7 @@
"name": "Navn",
"role": "Gjesterolle",
"period": "Periode",
"host": "Vert",
"host": "Vert",
"ou": "Organisasjon",
"department": "Avdeling",
"choice": "Valg",
......@@ -103,6 +103,7 @@
"expiring_other": "Utløper om {{count}} dager",
"expiring_one": "Utløper om {{count}} dag",
"waitingForGuest": "Venter på gjest",
"invalidEmail": "Ugyldig e-postadresse",
"waitingForSponsor": "Trenger godkjenning",
"invitationExpired": "Invitasjon utløpt"
},
......
......@@ -82,7 +82,7 @@
"name": "Namn",
"role": "Gjesterolle",
"period": "Periode",
"host": "Vert",
"host": "Vert",
"ou": "Organisasjonsenhet",
"department": "Enhet",
"choice": "Val",
......@@ -103,6 +103,7 @@
"expiring_other": "Utløper om {{count}} dagar",
"expiring_one": "Utløper om {{count}} dag",
"waitingForGuest": "Venter på gjest",
"invalidEmail": "Ugyldig e-postadresse",
"waitingForSponsor": "Trenger godkjenning",
"invitationExpired": "Invitasjon utløpt"
},
......
......@@ -82,16 +82,17 @@ const StyledTableHead = styled(TableHead)(({ theme }) => ({
borderRadius: '0',
}))
const Status = ({ person, role }: StatusProps) => {
const calculateStatus = (person: Guest, role: Role): [string, number] => {
const today = new Date()
today.setHours(0, 0, 0, 0)
const { t } = useTranslation('common')
let status = ''
const days = differenceInDays(role.end_date, today)
if (!person.registered) {
status = 'waitingForGuest'
if (person.invitation_status !== 'active') {
if (person.invitation_status === 'invalidEmail') {
status = 'invalidEmail'
} else if (person.invitation_status !== 'active') {
status = 'invitationExpired'
}
} else if (person.registered && !person.verified) {
......@@ -105,6 +106,12 @@ const Status = ({ person, role }: StatusProps) => {
status = 'active'
}
}
return [status, days]
}
const Status = ({ person, role }: StatusProps) => {
const { t } = useTranslation('common')
const [status, days] = calculateStatus(person, role)
switch (status) {
case 'active':
......@@ -143,6 +150,12 @@ const Status = ({ person, role }: StatusProps) => {
<Trans t={t} i18nKey="statusText.expiring" count={days} />
</TableCell>
)
case 'invalidEmail':
return (
<TableCell sx={{ color: 'error.main' }} align="left">
<Trans t={t} i18nKey="statusText.invalidEmail" count={days} />
</TableCell>
)
default:
return (
<TableCell sx={{ color: 'error.main' }} align="left">
......
......@@ -172,6 +172,9 @@ export default function GuestInfo({
})
}
})
// Reload guests to update status on sponsor frontpage
// in case the email was invalid before update
reloadGuests()
}
const onSubmit = handleSubmit(submit)
......
# Generated by Django 4.0.2 on 2022-05-24 08:16
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('greg', '0022_alter_identity_type'),
]
operations = [
migrations.AddField(
model_name='identity',
name='invalid',
field=models.BooleanField(null=True),
),
]
......@@ -264,6 +264,21 @@ class Notification(BaseModel):
class Identity(BaseModel):
"""
Model used for storing identifiers of a person
A person must have at least one verified PASSPORT_NUMBER or
NORWEGIAN_NATIONAL_ID_NUMBER to be active.
If for some reason we find that a value is invalid, even if it has
been verified, it can be marked as invalid by setting the invalid
field to True.
MIGRATION_ID is used to identify persons imported from another
source system.
PRIVATE_EMAIL is used when sending invitation emails.
"""
class IdentityType(models.TextChoices):
FEIDE_ID = "feide_id"
FEIDE_EMAIL = "feide_email"
......@@ -294,6 +309,7 @@ class Identity(BaseModel):
blank=True,
)
verified_at = models.DateTimeField(null=True, blank=True)
invalid = models.BooleanField(null=True)
def __str__(self) -> str:
return "{}(id={!r}, type={!r}, value={!r})".format(
......
......@@ -40,6 +40,7 @@ def create_identity_or_update(
)
else:
existing_identity.value = value
existing_identity.invalid = None
existing_identity.save()
......@@ -257,6 +258,9 @@ class GuestSerializer(serializers.ModelSerializer):
return obj.feide_id and obj.feide_id.value
def get_invitation_status(self, obj):
if obj.private_email and obj.private_email.invalid:
return "invalidEmail"
invitation_links = InvitationLink.objects.filter(
invitation__role__person__id=obj.id
)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment