Skip to content

Commit

Permalink
Merge pull request #3156 from uw-it-aca/qa
Browse files Browse the repository at this point in the history
Qa
  • Loading branch information
fanglinfang authored Sep 24, 2024
2 parents 0be02cf + 062a2fb commit b2bb56a
Show file tree
Hide file tree
Showing 10 changed files with 93 additions and 55 deletions.
2 changes: 1 addition & 1 deletion docker/prod-values.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
autoscaling:
enabled: true
minReplicas: 4
maxReplicas: 120
maxReplicas: 150
targetAverageUtilization: 100
resources:
limits:
Expand Down
73 changes: 46 additions & 27 deletions myuw/dao/canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@
from uw_canvas.sections import Sections
from uw_canvas.courses import Courses
from uw_canvas.models import CanvasCourse, CanvasSection
from uw_sws.exceptions import InvalidCanvasIndependentStudyCourse
from uw_sws.exceptions import (
InvalidCanvasIndependentStudyCourse, InvalidCanvasSection)
from myuw.dao import log_err
from myuw.dao.pws import get_regid_of_current_user
from myuw.dao.term import get_comparison_datetime

logger = logging.getLogger(__name__)
canvas_enrollments = Enrollments()


def canvas_prefetch():
Expand All @@ -26,9 +28,11 @@ def _method(request):
def get_canvas_active_enrollments(request):
if not hasattr(request, "canvas_act_enrollments"):
request.canvas_act_enrollments = (
Enrollments().get_enrollments_for_regid(
canvas_enrollments.get_enrollments_for_regid(
get_regid_of_current_user(request),
{'type': ['StudentEnrollment'], 'state': ['active']}))
logger.debug({'canvas_act_enrollments':
request.canvas_act_enrollments[0].json_data()})
return request.canvas_act_enrollments


Expand All @@ -37,34 +41,50 @@ def set_section_canvas_course_urls(canvas_active_enrollments, schedule,
"""
Set canvas_course_url in schedule.sections
"""
now = get_comparison_datetime(request)
section_labels = set()
canvas_sis_ids = {}
# MUWM-5362 {canvas_section_sis_id: primary_section_label}
for section in schedule.sections:
section_labels.add(section.section_label())
section_label = section.section_label()

canvas_links = {} # sis_course_id: canvas course_url
for enrollment in canvas_active_enrollments:
(sws_label, inst_regid) = sws_section_label(enrollment.sis_course_id)
if sws_label is not None and sws_label in section_labels:
sis_course_id = enrollment.sis_course_id
if sis_course_id not in canvas_links:
canvas_links[sis_course_id] = enrollment.course_url

for section in schedule.sections:
try:
section.canvas_course_url = canvas_links.get(
section.canvas_course_sis_id())
cid = section.canvas_course_sis_id()
if cid not in canvas_sis_ids:
canvas_sis_ids[cid] = section.primary_section_label()
except InvalidCanvasIndependentStudyCourse as ex:
# REQ3132940 known SWS issue:
# prior quarter's registration data has
# no independent study instructor.
# If independent_study_instructor being None occurs
# in current or future quarter, likely is a data error.
if not section.term.is_past(now):
log_err(logger,
"{} {}".format(section.section_label(), ex),
traceback, request)
pass
log_err(
logger, f"canvas_course_sis_id of {section_label} {ex}",
traceback, request)
continue
try:
cid = section.canvas_section_sis_id()
canvas_sis_ids[cid] = section.primary_section_label()
except Exception as ex:
log_err(
logger, f"canvas_section_sis_id of {section_label} {ex}",
traceback, request)
logger.debug({'canvas_sis_ids': canvas_sis_ids})

canvas_links = {} # primary_section_label: canvas course_url
for enrollment in canvas_active_enrollments:
psection_label = None
# MUWM-5362 check both course and section
if enrollment.sis_section_id in canvas_sis_ids:
psection_label = canvas_sis_ids[enrollment.sis_section_id]
else:
if enrollment.sis_course_id in canvas_sis_ids:
psection_label = canvas_sis_ids[enrollment.sis_course_id]
if psection_label and psection_label not in canvas_links:
canvas_links[psection_label] = enrollment.course_url
logger.debug({'canvas_links': canvas_links})

for section in schedule.sections:
section.canvas_course_url = canvas_links.get(
section.primary_section_label())


def get_canvas_course_from_section(sws_section):
Expand All @@ -91,12 +111,11 @@ def get_canvas_course_url(sws_section, person):
def sws_section_label(sis_id):
canvas_section = CanvasSection(sis_section_id=sis_id)
sws_label = canvas_section.sws_section_id()
if sws_label is None:
canvas_course = CanvasCourse(sis_course_id=sis_id)
sws_label = canvas_course.sws_course_id()
return (sws_label, canvas_course.sws_instructor_regid())
else:
if sws_label is not None:
return (sws_label, canvas_section.sws_instructor_regid())
canvas_course = CanvasCourse(sis_course_id=sis_id)
sws_label = canvas_course.sws_course_id()
return (sws_label, canvas_course.sws_instructor_regid())


def get_viewable_course_sections(canvas_course_id, canvas_user_id):
Expand All @@ -108,7 +127,7 @@ def get_viewable_course_sections(canvas_course_id, canvas_user_id):
limit_privileges_to_course_section = False
limit_sections = {}

enrollments = Enrollments().get_enrollments_for_course(
enrollments = canvas_enrollments.get_enrollments_for_course(
canvas_course_id, params={'user_id': canvas_user_id})

for enrollment in enrollments:
Expand Down
2 changes: 1 addition & 1 deletion myuw/data/category_links_import.csv
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Category,Subcategory,affiliation,Central (not campus specific),Central Title,Seattle,Seattle (link text),Bothell (destination URL),Bothell (link text),Tacoma,Tacoma Title,Open in a new tab?,,,,,,,,,,,,,
PageAcademics,Online Learning,all,,,https://academicsupport.uw.edu/online-learning/,Online Learning Tips and Resources,,,,,no,,,,,,,,,,,,,
PageAcademics,Online Learning,all,,,https://academicsupport.uw.edu/study-skills/online-learning/,Online Learning Resources,,,,,no,,,,,,,,,,,,,
PageAcademics,Online Learning,all,,,,,https://www.uwb.edu/it/learning,Student Help for Learning Online,,,no,,,,,,,,,,,,,
PageAcademics,Online Learning,all,,,,,https://www.uwb.edu/academic-support-programs/,Academic Support Services,,,no,,,,,,,,,,,,,
PageAcademics,Online Learning,all,,,,,https://www.uwb.edu/it/service-catalog/teaching-learning/tech-lending-program,Laptop and WiFi Hotspot Lending Program,,,no,,,,,,,,,,,,,
Expand Down
2 changes: 1 addition & 1 deletion myuw/data/resource_link_import.csv
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ Campus Life,Campus Safety,all,http://www.washington.edu/safecampus/,SafeCampus,,
Campus Life,Campus Safety,all,,,https://www.ehs.washington.edu/,Environmental Health & Safety,https://www.uwb.edu/safety/ehs-emergency/environment-health-safety,Environmental Health & Safety,https://www.tacoma.uw.edu/fa/environmental-health-safety,Environmental Health & Safety,no
Campus Life,Campus Safety,all,https://mychem.ehs.washington.edu/,MyChem,,,,,,,no
Campus Life,Campus Safety,all,,,https://www.washington.edu/uwem/,UW Emergency Management,https://www.uwb.edu/emergency,UW Bothell Emergency Page,https://www.tacoma.uw.edu/fa/safety/emergency-preparedness,UW Tacoma Emergency Response,no
Campus Life,Getting Around Campus,all,,,http://www.washington.edu/maps/,Campus Map,https://www.uwb.edu/wp-content/uploads/2024/04/uw-bothell-campus-map.pdf,Campus Map,http://www.tacoma.uw.edu/campus-map/campus-map,Campus Map,no
Campus Life,Getting Around Campus,all,,,http://www.washington.edu/maps/,Campus Map,https://www.uwb.edu/about/directions,Campus Map,http://www.tacoma.uw.edu/campus-map/campus-map,Campus Map,no
Campus Life,Getting Around Campus,all,,,https://transportation.uw.edu/getting-here,Getting to Seattle Campus,http://www.uwb.edu/visitors/directions,Getting to UW Bothell Campus,https://www.tacoma.uw.edu/fa/facilities/transportation/parking-and-transportation-resources#permalink-19448,Getting to UW Tacoma Campus,no
Campus Life,Getting Around Campus,all,,,https://transportation.uw.edu/getting-here/transit/u-pass#u-pass-students,U-PASS for Students,https://www.uwb.edu/commuter-services/transportation/upass,U-PASS,https://www.tacoma.uw.edu/uwt/fa/facilities/transportation/u-pass,U-PASS,no
Campus Life,Getting Around Campus,all,,,https://transportation.uw.edu/getting-here/transit/u-pass#u-pass-faculty-staff,U-PASS for Employees,,,,,no
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<h1>Canvas Student Active Enrollments</h1>
<form method="post" action="{{form_action}}">
{% csrf_token %}
<p>
<label for="uwregid">UW NetID or RegID:</label>
<input id="uwregid" name="uwregid" size="32" type="text">
</p>
<p>
<input value="Submit" type="submit">
</p>
</form>
7 changes: 7 additions & 0 deletions myuw/templates/supporttools/custom_sidebar_links.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ <h3>Web Services</h3>
</li>
{% endif %}

{% url 'myuw_rest_search' 'canvas' 'active_enrollments.html' as canvas_url %}
{% if canvas_url %}
<li>
<a href="{{ canvas_url }}">Canvas Student</a>
</li>
{% endif %}

{% url 'myuw_rest_search' 'hfs' 'accounts.html' as hfs_url %}
{% if hfs_url %}
<li>
Expand Down
15 changes: 11 additions & 4 deletions myuw/test/dao/test_canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# SPDX-License-Identifier: Apache-2.0

from django.test import TestCase
from restclients_core.exceptions import DataFailureException
from myuw.dao.canvas import (
get_canvas_active_enrollments, set_section_canvas_course_urls,
get_canvas_course_from_section,
Expand Down Expand Up @@ -29,9 +30,9 @@ def test_get_canvas_active_enrollments(self):

set_section_canvas_course_urls(canvas_active_enrollments,
schedule, req)
section1 = schedule.sections[0]
section1 = schedule.sections[2]
self.assertEqual(section1.section_label(),
"2013,spring,PHYS,121/A")
"2013,spring,PHYS,121/AQ")
self.assertEqual(section1.canvas_course_url,
'https://test.edu/courses/249652')

Expand Down Expand Up @@ -60,15 +61,21 @@ def test_get_canvas_active_enrollments(self):
self.assertEqual(section.section_label(), "2013,spring,TRAIN,101/A")
self.assertIsNotNone(section.canvas_course_url)

req = get_request_with_user("jbothell")
schedule = get_schedule_by_term(req, get_current_quarter(req))
self.assertRaises(
DataFailureException, get_canvas_active_enrollments, req)

def test_InvalidCanvasIndependentStudyCourse_case(self):
req = get_request_with_user("jeos",
get_request_with_date("2013-10-01"))
schedule = get_schedule_by_term(req, get_current_quarter(req))
canvas_active_enrollments = get_canvas_active_enrollments(req)
self.assertIsNotNone(req.canvas_act_enrollments)
set_section_canvas_course_urls(canvas_active_enrollments,
schedule, req)
with self.assertRaises(AttributeError):
a = schedule.sections[0].canvas_course_url
# InvalidCanvasIndependentStudyCourse
self.assertIsNone(schedule.sections[0].canvas_course_url)

def test_get_canvas_course_url(self):
person = Person()
Expand Down
5 changes: 5 additions & 0 deletions myuw/test/util/test_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ def test_get_cache_time(self):
self.assertEqual(cache.get_cache_expiration_time(
"mailman", "/uw_list_manager/api/v1/list/", status=500), 60 * 15)

self.assertEqual(cache.get_cache_expiration_time(
"uwidp", "/idp/profile/oidc/keyset", status=404), 60 * 7)
self.assertEqual(cache.get_cache_expiration_time(
"uwidp", "/idp/profile/oidc/keyset", status=500), 60 * 15)


class TestMyUWCache(TestCase):

Expand Down
26 changes: 5 additions & 21 deletions myuw/util/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ def get_cache_expiration_time(self, service, url, status=None):
if "myplan" == service:
return FIVE_SECONDS

if "sws" == service:
if status and status != 200:
if status >= 500:
return FIFTEEN_MINS
return SEVEN_MINS
if status and status != 200:
if status >= 500:
return FIFTEEN_MINS
return SEVEN_MINS

if "sws" == service:
if re.match(r'^/student/v5/term/', url):
return ONE_DAY

Expand All @@ -52,31 +52,15 @@ def get_cache_expiration_time(self, service, url, status=None):
return ONE_DAY

if "gws" == service:
if status and status != 200:
if status >= 500:
return FIFTEEN_MINS
return SEVEN_MINS
return HALF_HOUR

if "pws" == service:
if status and status != 200:
if status >= 500:
return FIFTEEN_MINS
return SEVEN_MINS
return ONE_HOUR

if "uwnetid" == service:
if status and status != 200:
if status >= 500:
return FIFTEEN_MINS
return SEVEN_MINS
return FOUR_HOURS

if "mailman" == service:
if status and status != 200:
if status >= 500:
return FIFTEEN_MINS
return SEVEN_MINS
return ONE_DAY

return FOUR_HOURS
Expand Down
5 changes: 5 additions & 0 deletions myuw/views/rest_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ def get_proxy_url(self, request, service, url):
"uw/json_utf8_202007.ubs",
get_input_value(request.POST, "quarter"),
get_input_value(request.POST, "sln1"))
elif service == "canvas":
regid = get_regid(get_input_value(request.POST, "uwregid"))
url = (
f"api/v1/users/sis_user_id:{regid}/enrollments?" +
f"state[]=active&type[]=StudentEnrollment")
elif service == "grad":
params = self.format_params(request)
params['id'] = get_student_system_key(params['id'])
Expand Down

0 comments on commit b2bb56a

Please sign in to comment.