Skip to content

Commit

Permalink
Merge branch 'main' into IDPF-306
Browse files Browse the repository at this point in the history
  • Loading branch information
alsyx committed Feb 25, 2025
2 parents 30c7796 + 946a615 commit e65ed35
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 15 deletions.
2 changes: 1 addition & 1 deletion conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def uk_staff_location():
)


@pytest.fixture(autouse=True, scope="function")
@pytest.fixture(scope="function")
def manager_user():
return User.objects.create_user(
sso_email_id="[email protected]",
Expand Down
13 changes: 6 additions & 7 deletions core/api/people_finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

from core import services as core_services
from core.schemas import Error
from core.schemas.peoplefinder import MinimalPeopleFinderProfile
from core.schemas.profiles import (
PeopleFinderProfileRequestSchema,
PeopleFinderProfileResponseSchema,
ProfileMinimal,
UkStaffLocationSchema,
)
from profiles.models.combined import Profile
Expand All @@ -20,21 +20,20 @@
router.add_router("reference", reference_router)


# NB this is a placeholder to get the router running, it may need editing or deleting etc.
@profile_router.get(
"{slug}",
response={
200: ProfileMinimal,
200: MinimalPeopleFinderProfile,
404: Error,
},
)
def get_profile(request, slug: str):
"""Just a demo, do not build against this"""
"""Optimised, low-flexibility endpoint to return a minimal peoplefinder profile record"""
try:
return core_services.get_profile_by_slug(slug=slug)
except Profile.DoesNotExist:
return core_services.get_peoplefinder_profile_by_slug(slug=slug)
except PeopleFinderProfile.DoesNotExist:
return 404, {
"message": "Unable to find user",
"message": "Unable to find people finder profile",
}


Expand Down
49 changes: 49 additions & 0 deletions core/schemas/peoplefinder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
from dataclasses import dataclass
from typing import Optional

from ninja import Schema

from profiles.models import PeopleFinderProfile


@dataclass
class Email:
value: str
type: str | None = None
primary: bool = False


class MinimalPeopleFinderProfile(Schema):
# Basic Profile info
slug: str
first_name: str
last_name: str
sso_email_id: str
preferred_first_name: Optional[str]
pronouns: Optional[str]
name_pronunciation: Optional[str]
email: Optional[str]
contact_email: Optional[str]
primary_phone_number: Optional[str]
secondary_phone_number: Optional[str]
photo: Optional[str] # ImageField is represented as a string (file path or URL)
photo_small: Optional[
str
] # ImageField is represented as a string (file path or URL)
grade: Optional[str]

@staticmethod
def resolve_slug(obj: PeopleFinderProfile):
return str(obj.slug)

@staticmethod
def resolve_sso_email_id(obj: PeopleFinderProfile):
return obj.user.sso_email_id

@staticmethod
def resolve_email(obj: PeopleFinderProfile):
return obj.email.address

@staticmethod
def resolve_contact_email(obj: PeopleFinderProfile):
return obj.contact_email.address
12 changes: 8 additions & 4 deletions core/schemas/profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,23 @@ class PeopleFinderProfileResponseSchema(Schema):
last_name: Optional[str] = Field(alias="last_name")
pronouns: Optional[str] = Field(alias="pronouns")
name_pronunciation: Optional[str] = Field(alias="name_pronunciation")
email_address: Optional[str] = Field(alias="email.address")
contact_email_address: Optional[str] = Field(alias="contact_email.address")
email_address: Optional[str] = Field(alias="email.address", default=None)
contact_email_address: Optional[str] = Field(
alias="contact_email.address", default=None
)
primary_phone_number: Optional[str] = Field(alias="primary_phone_number")
secondary_phone_number: Optional[str] = Field(alias="secondary_phone_number")
photo: Optional[str] = Field(alias="photo")
photo_small: Optional[str] = Field(alias="photo_small")
grade: Optional[str] = Field(alias="grade")
manager_slug: Optional[UUID] = Field(alias="manager.slug")
manager_slug: Optional[UUID] = Field(alias="manager.slug", default=None)
not_employee: Optional[bool] = Field(alias="not_employee")
workdays: Optional[List[str]] = Field(alias="workdays")
remote_working: Optional[str] = Field(alias="remote_working")
usual_office_days: Optional[str] = Field(alias="usual_office_days")
uk_office_location_id: Optional[str] = Field(alias="uk_office_location.code")
uk_office_location_id: Optional[str] = Field(
alias="uk_office_location.code", default=None
)
location_in_building: Optional[str] = Field(alias="location_in_building")
international_building: Optional[str] = Field(alias="international_building")
country_id: Optional[str] = Field(alias="country.reference_id")
Expand Down
11 changes: 9 additions & 2 deletions core/services.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import logging
from datetime import datetime
from typing import Any, Optional
from typing import Optional

from profiles import services as profile_services
from profiles.models import PeopleFinderProfile
from profiles.models.combined import Profile
from profiles.models.generic import UkStaffLocation
from profiles.models.peoplefinder import PeopleFinderProfile
from profiles.types import UNSET, Unset # noqa
from user import services as user_services
from user.models import User


SSO_EMAIL_ADDRESSES = "dit:emailAddress"
Expand Down Expand Up @@ -278,5 +278,12 @@ def delete_identity(profile: Profile) -> None:
user_services.delete_from_database(user=user)


def get_peoplefinder_profile_by_slug(slug: str) -> PeopleFinderProfile:
"""
Retrieve peoplefinder profile by its slug.
"""
return profile_services.get_peoplefinder_profile_by_slug(slug=slug)


def get_uk_staff_locations() -> list[UkStaffLocation]:
return profile_services.get_uk_staff_locations()
6 changes: 5 additions & 1 deletion profiles/admin.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from django.contrib import admin

from profiles.models import PeopleFinderProfile
from profiles.models.combined import Profile
from profiles.models.generic import Email
from profiles.models.generic import Country, Email, UkStaffLocation
from profiles.models.staff_sso import StaffSSOProfile, StaffSSOProfileEmail


Expand All @@ -10,3 +11,6 @@
admin.site.register(StaffSSOProfile)
admin.site.register(StaffSSOProfileEmail)
admin.site.register(Profile)
admin.site.register(UkStaffLocation)
admin.site.register(Country)
admin.site.register(PeopleFinderProfile)
8 changes: 8 additions & 0 deletions profiles/services/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,5 +394,13 @@ def delete(profile_id: str) -> dict[str, models.Model]:
return all_profiles


def get_peoplefinder_profile_by_slug(slug: str) -> PeopleFinderProfile:
"""
Gets peoplefinder profile from peoplefinder service
:param slug: Peoplefinder profile slug
"""
return peoplefinder.get_by_slug(slug=slug)


def get_uk_staff_locations() -> list[UkStaffLocation]:
return peoplefinder.get_uk_staff_locations()

0 comments on commit e65ed35

Please sign in to comment.