Skip to content

Commit

Permalink
replaces uw-person-client with django-person-client
Browse files Browse the repository at this point in the history
  • Loading branch information
jlaney committed Apr 9, 2024
1 parent dea319e commit dc73a98
Show file tree
Hide file tree
Showing 29 changed files with 318 additions and 289 deletions.
17 changes: 16 additions & 1 deletion .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,21 @@ jobs:

needs: context

services:
postgres:
image: postgres:14
env:
POSTGRES_PASSWORD: postgres
POSTGRES_USER: postgres
# Set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432

steps:
- name: Checkout Repo
uses: actions/checkout@v3
Expand Down Expand Up @@ -114,7 +129,7 @@ jobs:
id: tests
shell: bash
run: >-
docker run -u root -t
docker run -u root -t --network ${{ job.container.network }}
-v ${PWD}:/coverage
-e DJANGO_APP="$DJANGO_APP"
-e "ENV=localdev" -e "AUTH=SAML_MOCK"
Expand Down
6 changes: 6 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ RUN /app/bin/python manage.py collectstatic --noinput

FROM us-docker.pkg.dev/uwit-mci-axdd/containers/django-test-container:${DJANGO_CONTAINER_VERSION} as app-test-container

USER root

RUN apt-get update && apt-get install libpq-dev -y

USER acait

ENV NODE_PATH=/app/lib/node_modules
COPY --from=app-container /app/ /app/
COPY --from=app-container /static/ /static/
4 changes: 0 additions & 4 deletions compass/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

from django.apps import AppConfig
from restclients_core.dao import MockDAO
from uw_person_client.clients.mock_client import MockedUWPersonClient
import os


Expand All @@ -15,6 +14,3 @@ def ready(self):
restclient_mocks = os.path.join(os.path.dirname(__file__),
"resources")
MockDAO.register_mock_path(restclient_mocks)
pds_mocks = os.path.join(os.path.dirname(__file__),
"fixtures/mock_pds_data")
MockedUWPersonClient.register_mock_path(pds_mocks)
14 changes: 0 additions & 14 deletions compass/clients/__init__.py

This file was deleted.

25 changes: 0 additions & 25 deletions compass/clients/mock_person_client.py

This file was deleted.

141 changes: 0 additions & 141 deletions compass/clients/person_client.py

This file was deleted.

88 changes: 88 additions & 0 deletions compass/dao/person.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
# Copyright 2024 UW-IT, University of Washington
# SPDX-License-Identifier: Apache-2.0

from django.db.models import OuterRef, Subquery, F
from django.db.models.functions import JSONObject
from django.conf import settings
from django.core.cache import cache
from uw_person_client.models import (
Person, Adviser, Student, Transcript, Degree)
from uw_person_client.exceptions import (
PersonNotFoundException, AdviserNotFoundException)
from uw_pws import PWS, InvalidNetID, DataFailureException
import re

Expand Down Expand Up @@ -41,3 +49,83 @@ def is_overridable_uwnetid(username):
else:
error_msg = "Error ({}) {}: ".format(err.status, err.msg)
return error_msg


def get_person_by_uwnetid(uwnetid, **kwargs):
return Person.objects.get_person_by_uwnetid(uwnetid, **kwargs)


def get_person_by_uwregid(uwregid, **kwargs):
return Person.objects.get_person_by_uwregid(uwregid, **kwargs)


def get_person_by_system_key(system_key, **kwargs):
return Person.objects.get_person_by_system_key(system_key, **kwargs)


def get_person_by_student_number(student_number, **kwargs):
return Person.objects.get_person_by_student_number(student_number, **kwargs)


def get_appuser_by_uwnetid(uwnetid):
"""
Returns a cached person model for use with AppUser.
"""
cache_key = f'appuser_{uwnetid}'

person_data = cache.get(cache_key)
if person_data is not None:
return Person(**person_data)

person = get_person_by_uwnetid(uwnetid)

cache.set(
cache_key,
person.to_dict(),
timeout=getattr(settings, 'APPUSER_PERSON_EXPIRES', 60 * 60 * 24)
)
return person


def get_adviser_caseload(uwnetid):
adviser = Adviser.objects.get_adviser_by_uwnetid(uwnetid)

return Student.objects.annotate(latest_transcript=Subquery(
Transcript.objects.filter(student=OuterRef('pk')
).values(json=JSONObject(
scholarship_type='scholarship_type',
scholarship_desc='scholarship_desc')
).order_by('-tran_term__year', '-tran_term__quarter')[:1])
).annotate(latest_degree=Subquery(
Degree.objects.filter(student=OuterRef('pk')
).values(json=JSONObject(
degree_status_desc='degree_status_desc')
).order_by('-degree_date')[:1])
).filter(advisers__in=[adviser]).values(
'student_number',
'gender',
'class_desc',
'academic_term__year',
'academic_term__quarter',
'registered_in_quarter',
'registration_hold_ind',
'campus_desc',
'special_program_code',
'special_program_desc',
'enroll_status_code',
'enroll_status_request_code',
'enroll_status_desc',
'person__display_name',
'person__uwnetid',
'person__uwregid',
'person__pronouns',
'person__surname',
'latest_transcript',
'latest_degree'
).annotate(
display_name=F('person__display_name'),
uwnetid=F('person__uwnetid'),
uwregid=F('person__uwregid'),
pronouns=F('person__pronouns'),
surname=F('person__surname')
).order_by('person__surname')
7 changes: 3 additions & 4 deletions compass/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from django.db.utils import IntegrityError
from django.utils.text import slugify
from simple_history.models import HistoricalRecords
from compass.clients import CompassPersonClient, PersonNotFoundException
from compass.dao.person import get_appuser_by_uwnetid, PersonNotFoundException
from compass.dao.group import is_group_member
from compass.dao import current_datetime
from datetime import datetime, timedelta, timezone
Expand All @@ -23,7 +23,7 @@ def upsert_appuser(self, uwnetid):
needed.
"""
# request the current person object for the user
person = CompassPersonClient().get_appuser_by_uwnetid(uwnetid)
person = get_appuser_by_uwnetid(uwnetid)
# check the AppUser table to see if they have an existing entry
user = None
for netid in person.prior_uwnetids + [person.uwnetid]:
Expand Down Expand Up @@ -79,8 +79,7 @@ def __str__(self):
def display_name(self):
if self.uwnetid:
try:
person = CompassPersonClient().get_appuser_by_uwnetid(
self.uwnetid)
person = get_appuser_by_uwnetid(self.uwnetid)
return person.display_name
except PersonNotFoundException:
return self.uwnetid
Expand Down
24 changes: 24 additions & 0 deletions compass/routers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright 2024 UW-IT, University of Washington
# SPDX-License-Identifier: Apache-2.0


class UWPersonRouter():
def db_for_read(self, model, **hints):
if model._meta.app_label == 'uw_person_client':
return 'uw_person'
return None

def db_for_write(self, model, **hints):
if model._meta.app_label == 'uw_person_client':
return 'uw_person'
return None

def allow_relation(self, obj1, obj2, **hints):
return None

def allow_migrate(self, db, app_label, model_name=None, **hints):
if app_label == 'uw_person_client':
return db == 'uw_person'
elif db == 'uw_person':
return False
return None
Loading

0 comments on commit dc73a98

Please sign in to comment.