Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/muwm 5362 #3152

Open
wants to merge 9 commits into
base: qa
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ env:
# defined in the "deploy" job
on:
push:
branches: [main, master, qa, develop, vue/dev]
branches: [main, master, qa, develop, fix/MUWM-5362]
pull_request:
branches: [main, master, qa, develop, vue/dev]
branches: [main, master, qa, develop, fix/MUWM-5362]
types: [opened, reopened, synchronize]
release:
branches: [main, master]
Expand Down Expand Up @@ -304,7 +304,7 @@ jobs:
app_instance: dev

- name: Deploy Vue Branch
if: needs.context.outputs.git_repo_branch == 'vue/dev'
if: needs.context.outputs.git_repo_branch == 'fix/MUWM-5362'
uses: uw-it-aca/actions/cicd-deploy@main
with:
release_name: ${{ env.RELEASE_NAME }}
Expand All @@ -322,7 +322,7 @@ jobs:
if: github.event_name == 'push' &&
(endsWith(github.ref, '/main') || endsWith(github.ref, '/master') ||
endsWith(github.ref, '/qa') || endsWith(github.ref, '/develop') ||
endsWith(github.ref, '/vue/dev'))
endsWith(github.ref, '/fix/MUWM-5362'))

needs: [context, build, deploy]

Expand Down
53 changes: 36 additions & 17 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.info({'canvas_act_enrollments':
request.canvas_act_enrollments[0].json_data()})
return request.canvas_act_enrollments


Expand All @@ -38,22 +42,38 @@ 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
for section in schedule.sections:
section_labels.add(section.section_label())
section_label = section.section_label()
try:
canvas_sis_ids[section.canvas_section_sis_id()] = section_label
logger.info({
'canvas_section_sis_id': section.canvas_section_sis_id()})
except Exception as ex:
log_err(logger, f"{section_label} {ex}", traceback, request)
try:
canvas_sis_ids[section.canvas_course_sis_id()] = section_label
except Exception as ex:
log_err(logger, f"{section_label} {ex}", traceback, request)

canvas_links = {} # sis_course_id: canvas course_url
canvas_links = {} # section_label: 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
if enrollment.sis_section_id in canvas_sis_ids:
section_label = canvas_sis_ids[enrollment.sis_section_id]
else:
if enrollment.sis_course_id in canvas_sis_ids:
section_label = canvas_sis_ids[enrollment.sis_course_id]

logger.info({
'section_label': section_label,
'canvas_course_url': enrollment.course_url})
if section_label and section_label not in canvas_links:
canvas_links[section_label] = enrollment.course_url

for section in schedule.sections:
try:
section.canvas_course_url = canvas_links.get(
section.canvas_course_sis_id())
section.section_label())
except InvalidCanvasIndependentStudyCourse as ex:
# REQ3132940 known SWS issue:
# prior quarter's registration data has
Expand Down Expand Up @@ -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
9 changes: 5 additions & 4 deletions myuw/test/dao/test_canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,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 @@ -67,8 +67,9 @@ def test_get_canvas_active_enrollments(self):
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
self.assertEqual(
schedule.sections[0].canvas_course_url,
'https://test.edu/courses/249652')

def test_get_canvas_course_url(self):
person = Person()
Expand Down
Loading