From a7541f4076f54d13690f804de5b357c89a3836ff Mon Sep 17 00:00:00 2001 From: Tore Brede <Tore.Brede@uib.no> Date: Thu, 7 Apr 2022 11:02:57 +0200 Subject: [PATCH] GREG-204: Showing sponsor name for role --- frontend/public/locales/en/common.json | 1 + frontend/public/locales/nb/common.json | 1 + frontend/public/locales/nn/common.json | 1 + frontend/src/components/roleLine/index.tsx | 1 + frontend/src/interfaces/index.ts | 2 ++ frontend/src/routes/sponsor/guest/guestInfo/index.tsx | 1 + .../src/routes/sponsor/guest/guestRoleInfo/index.tsx | 8 ++++++++ frontend/src/utils/index.ts | 1 + gregui/api/serializers/role.py | 9 ++++++--- gregui/tests/api/serializers/test_guest.py | 1 + 10 files changed, 23 insertions(+), 3 deletions(-) diff --git a/frontend/public/locales/en/common.json b/frontend/public/locales/en/common.json index d577a248..4fb32e74 100644 --- a/frontend/public/locales/en/common.json +++ b/frontend/public/locales/en/common.json @@ -82,6 +82,7 @@ "name": "Name", "role": "Guest role", "period": "Period", + "host": "Host", "ou": "Organisation", "department": "Department", "choice": "Choices", diff --git a/frontend/public/locales/nb/common.json b/frontend/public/locales/nb/common.json index c1c20c7e..93451ae3 100644 --- a/frontend/public/locales/nb/common.json +++ b/frontend/public/locales/nb/common.json @@ -82,6 +82,7 @@ "name": "Navn", "role": "Gjesterolle", "period": "Periode", + "host": "Vert", "ou": "Organisasjon", "department": "Avdeling", "choice": "Valg", diff --git a/frontend/public/locales/nn/common.json b/frontend/public/locales/nn/common.json index 23cc4172..c649f55b 100644 --- a/frontend/public/locales/nn/common.json +++ b/frontend/public/locales/nn/common.json @@ -82,6 +82,7 @@ "name": "Namn", "role": "Gjesterolle", "period": "Periode", + "host": "Vert", "ou": "Organisasjonsenhet", "department": "Enhet", "choice": "Val", diff --git a/frontend/src/components/roleLine/index.tsx b/frontend/src/components/roleLine/index.tsx index f57d3e68..9bd73c40 100644 --- a/frontend/src/components/roleLine/index.tsx +++ b/frontend/src/components/roleLine/index.tsx @@ -22,6 +22,7 @@ const RoleLine = ({ role, pid }: RoleLineProps) => { {role.start_date ? format(role.start_date, 'yyyy-MM-dd') : null} -{' '} {format(role.end_date, 'yyyy-MM-dd')} </TableCell> + <TableCell align="left">{role.sponsor_name}</TableCell> <TableCell> <Button variant="contained" diff --git a/frontend/src/interfaces/index.ts b/frontend/src/interfaces/index.ts index fe1309b2..4e5766da 100644 --- a/frontend/src/interfaces/index.ts +++ b/frontend/src/interfaces/index.ts @@ -55,6 +55,7 @@ export type Role = { max_days: number contact_person_unit: string | null comments: string | null + sponsor_name: string } export type FetchedRole = { @@ -68,6 +69,7 @@ export type FetchedRole = { max_days: number contact_person_unit: string | null comments: string | null + sponsor_name: string } export type ConsentType = { diff --git a/frontend/src/routes/sponsor/guest/guestInfo/index.tsx b/frontend/src/routes/sponsor/guest/guestInfo/index.tsx index c691d114..ba55ea72 100644 --- a/frontend/src/routes/sponsor/guest/guestInfo/index.tsx +++ b/frontend/src/routes/sponsor/guest/guestInfo/index.tsx @@ -362,6 +362,7 @@ export default function GuestInfo({ <TableHeadCell align="left">{t('common:role')}</TableHeadCell> <TableHeadCell align="left">{t('common:ou')}</TableHeadCell> <TableHeadCell align="left">{t('common:period')}</TableHeadCell> + <TableHeadCell align="left">{t('common:host')}</TableHeadCell> <TableHeadCell align="left" /> </TableRow> {guest.roles.map((role) => ( diff --git a/frontend/src/routes/sponsor/guest/guestRoleInfo/index.tsx b/frontend/src/routes/sponsor/guest/guestRoleInfo/index.tsx index c63c674b..a9ac0366 100644 --- a/frontend/src/routes/sponsor/guest/guestRoleInfo/index.tsx +++ b/frontend/src/routes/sponsor/guest/guestRoleInfo/index.tsx @@ -115,6 +115,7 @@ export default function GuestRoleInfo({ max_days: 365, contact_person_unit: null, comments: null, + sponsor_name: '', }) // Prepare min and max date values const today = new Date() @@ -268,6 +269,13 @@ export default function GuestRoleInfo({ <TableCell align="left">{getRoleOuName(role)}</TableCell> <TableCell align="left" /> </TableRow> + <TableRow> + <TableCell align="left" sx={{ fontWeight: 'bold' }}> + {t('common:host')} + </TableCell> + <TableCell align="left">{role.sponsor_name}</TableCell> + <TableCell align="left" /> + </TableRow> {displayContactAtUnit && ( <TableRow> <TableCell align="left" sx={{ fontWeight: 'bold' }}> diff --git a/frontend/src/utils/index.ts b/frontend/src/utils/index.ts index d89b2418..430805b2 100644 --- a/frontend/src/utils/index.ts +++ b/frontend/src/utils/index.ts @@ -150,6 +150,7 @@ export function parseRole(role: FetchedRole): Role { max_days: role.max_days, contact_person_unit: role.contact_person_unit, comments: role.comments, + sponsor_name: role.sponsor_name, } } diff --git a/gregui/api/serializers/role.py b/gregui/api/serializers/role.py index 40b2e809..4353e4b5 100644 --- a/gregui/api/serializers/role.py +++ b/gregui/api/serializers/role.py @@ -103,6 +103,7 @@ class ExtendedRoleSerializer(serializers.ModelSerializer): ou_nb = SerializerMethodField(source="orgunit") ou_en = SerializerMethodField(source="orgunit") max_days = SerializerMethodField(source="type") + sponsor_name = SerializerMethodField(source="sponsor") def get_name_nb(self, obj): return obj.type.name_nb @@ -119,6 +120,9 @@ class ExtendedRoleSerializer(serializers.ModelSerializer): def get_max_days(self, obj): return obj.type.max_days + def get_sponsor_name(self, obj): + return f"{obj.sponsor.first_name} {obj.sponsor.last_name}" + class Meta: model = Role fields = [ @@ -132,7 +136,6 @@ class ExtendedRoleSerializer(serializers.ModelSerializer): "max_days", "contact_person_unit", "comments", + "sponsor_name", ] - read_only_fields = [ - "contact_person_unit", - ] + read_only_fields = ["contact_person_unit", "sponsor_name"] diff --git a/gregui/tests/api/serializers/test_guest.py b/gregui/tests/api/serializers/test_guest.py index 456f7034..ed473128 100644 --- a/gregui/tests/api/serializers/test_guest.py +++ b/gregui/tests/api/serializers/test_guest.py @@ -34,6 +34,7 @@ def test_serialize_guest(invited_person): "max_days": 365, "contact_person_unit": "", "comments": "", + "sponsor_name": "Sponsor Bar", }, ], "verified": False, -- GitLab