Skip to content

Commit

Permalink
Merge pull request #13 from indiana-university/LMSA-7975_lookup_paren…
Browse files Browse the repository at this point in the history
…t_course

Lmsa 7975 lookup parent course
  • Loading branch information
dsobiera authored Sep 26, 2023
2 parents 14ccf23 + 7d1185e commit ba41718
Show file tree
Hide file tree
Showing 11 changed files with 754 additions and 1 deletion.
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,37 @@ that need to be accounted for while using this setup.

This is marked as experimental due to the fact that we aren't running with this option at IU. We are running into CORS
issues when trying to talk to our OAuth2 service via swagger, so we can't verify if it really works or not!

# Crosslister Lookup
The Cross-listing Assistant in Canvas at Indiana University has a secondary launch that brings up a user interface to search for a parent
crosslisted course. This is restricted to administrator users only. Configuration is the same as the crosslister with the exceptions listed below.

## Test a local launch
Startup the application with the `LTI_CLIENTREGISTRATION_DEFAULTCLIENT` value set to `saltire`.
Use an LTI tool consumer launcher, like https://saltire.lti.app/platform.
Default values are fine, with the below exceptions...

In the `Message` section, set the following:
<table>
<tr><th>Property</th><th>Value</th></tr>
<tr><td>Custom parameters</td><td>

```
canvas_user_login_id=johnsmith
instructure_membership_roles=http://purl.imsglobal.org/vocab/lis/v2/institution/person#Administrator
```

</td></tr>
</table>

Use an appropriate `canvas_user_login_id`.

From the `Security Model` section, set the following:
<table>
<tr><th>Property</th><th>Value</th></tr>
<tr><td>LTI version</td><td>1.3.0</td></tr>
<tr><td>Message URL</td><td>http://localhost:8080/app/lookup-launch</td></tr>
<tr><td>Client ID</td><td>dev (or whatever is appropriate based on the record inserted in the database table from above)</td></tr>
<tr><td>Initiate login URL</td><td>http://localhost:8080/lti/login_initiation/lms_lti_crosslisting</td></tr>
<tr><td>Redirection URI(s)</td><td>http://localhost:8080/lti/login</td></tr>
</table>
27 changes: 27 additions & 0 deletions examples/crosslisting-lookup.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"title": "Cross-listing Lookup Parent",
"description": "For Looking up a course's parent course if cross-listed in Canvas.",
"oidc_initiation_url": "http://localhost:8080/lti/login_initiation/lms_lti_crosslisting",
"target_link_uri": "http://localhost:8080/app/lookup-launch",
"extensions": [
{
"domain": "localhost",
"platform": "canvas.instructure.com",
"privacy_level": "public",
"settings": {
"placements": [
{
"enabled": true,
"placement": "account_navigation",
"message_type": "LtiResourceLinkRequest"
}
]
}
}
],
"public_jwk_url": "http://localhost:8080/.well-known/jwks.json",
"custom_fields": {
"instructure_membership_roles": "$com.Instructure.membership.roles",
"canvas_user_login_id": "$Canvas.user.loginId"
}
}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
<jdk.target>17</jdk.target>
<jquery.version>3.7.1</jquery.version>
<lms-canvas-rivet.version>5.2.5.2</lms-canvas-rivet.version>
<lms-embedded-services.version>5.2.15</lms-embedded-services.version>
<lms-embedded-services.version>5.2.16</lms-embedded-services.version>
<lms-team-spring-boot-it12>4.8</lms-team-spring-boot-it12>
<spring-cloud.version>2021.0.8</spring-cloud.version>
<webjars-locator.version>0.47</webjars-locator.version>
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/edu/iu/uits/lms/crosslist/CrosslistConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,17 @@ public interface CrosslistConstants {
String ACTION_IMPERSONATE = "impersonate";
String ACTION_END_IMPERSONATE = "end_impersonate";

String LOOKUP_SUCCESS_FOUND_MESSAGE = "Parent course is found";
String LOOKUP_FAILURE_COURSE_NOT_CROSSLISTED_MESSAGE = "This course has not been crosslisted";
String LOOKUP_FAILURE_NOT_FOUND_IN_CANVAS_MESSAGE = "Not found in Canvas";
String LOOKUP_FAILURE_NOT_FOUND_IN_SIS_MESSAGE = "Not found in SIS";

String LOOKUP_SUCCESS_CSS = "rvt-color-green rvt-bg-green-100";
String LOOKUP_FAILURE_CSS = "rvt-orange-green rvt-bg-orange-100";

String LOOKUP_SUCCESS_ICON_NAME = "check";
String LOOKUP_FAILURE_ICON_NAME = "close";

String MODE_EDIT = "editMode";

String STATUS_SUCCESS = "rvt-alert--success";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
*/

import com.fasterxml.jackson.databind.ObjectMapper;
import edu.iu.uits.lms.canvas.helpers.CanvasDateFormatUtil;
import edu.iu.uits.lms.canvas.model.CanvasTerm;
import edu.iu.uits.lms.canvas.model.Course;
import edu.iu.uits.lms.canvas.model.Section;
Expand All @@ -43,6 +44,8 @@
import edu.iu.uits.lms.canvas.services.TermService;
import edu.iu.uits.lms.common.session.CourseSessionService;
import edu.iu.uits.lms.crosslist.CrosslistConstants;
import edu.iu.uits.lms.crosslist.model.FindParentModel;
import edu.iu.uits.lms.crosslist.model.FindParentResult;
import edu.iu.uits.lms.crosslist.model.ImpersonationModel;
import edu.iu.uits.lms.crosslist.model.SectionUIDisplay;
import edu.iu.uits.lms.crosslist.model.SectionWrapper;
Expand Down Expand Up @@ -79,6 +82,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -876,6 +880,77 @@ public String endSelfImpersonation(@PathVariable("courseId") String courseId, @M
return main(courseId, model, session);
}

@RequestMapping("/lookup-launch")
@Secured({LTIConstants.ADMIN_AUTHORITY})
public String lookupLaunch(@ModelAttribute FindParentModel findParentModel, Model model, HttpSession session) {
getTokenWithoutContext();

Date nowDate = new Date();

List<CanvasTerm> terms = termService.getEnrollmentTerms()
.stream()
.filter(term -> term.getSisTermId().compareTo("4218") >= 0 && term.getSisTermId().charAt(0) == '4')
.filter(term -> CanvasDateFormatUtil.string2DateOnly(term.getStartAt()).compareTo(nowDate) < 0)
.sorted(Comparator.comparing(CanvasTerm::getSisTermId).reversed())
.toList();

if (courseSessionService.getAttributeFromSession(session, "all", "terms", List.class) == null) {
courseSessionService.addAttributeToSession(session, "all", "terms", terms);
}

model.addAttribute("terms", terms);

return "findParentCourse";
}

@PostMapping(value = "/lookup-search-sisid")
@Secured({LTIConstants.ADMIN_AUTHORITY})
public String lookupSearchBySisId(@ModelAttribute FindParentModel findParentModel, Model model, HttpSession session) {
getTokenWithoutContext();

FindParentResult findParentResult = null;

List<CanvasTerm> terms = courseSessionService.getAttributeFromSession(session, "all",
"terms", List.class);

SisCourse sisCourse = sisService.getSisCourseBySiteId(findParentModel.getSisIdSearch().trim().toUpperCase());
findParentResult = crosslistService.processSisLookup(sisCourse);

model.addAttribute("terms", terms);

if (findParentResult != null) {
model.addAttribute("findParentResult", findParentResult);
}

return "findParentCourse";
}

@PostMapping(value = "/lookup-search-termandclassnumber")
@Secured({LTIConstants.ADMIN_AUTHORITY})
public String lookupSearchByTermAndClassNUmber(@ModelAttribute FindParentModel findParentModel, Model model, HttpSession session) {
getTokenWithoutContext();

FindParentResult findParentResult = null;

List<CanvasTerm> terms = courseSessionService.getAttributeFromSession(session, "all",
"terms", List.class);

final String strm = findParentModel.getTermByClassNumberSearch().trim();
final String classNumber = findParentModel.getClassNumberSearch().trim();

final String iuSiteId = sisService.getIuSiteIdFromStrmAndClassNumber(strm, classNumber);

SisCourse sisCourse = sisService.getSisCourseBySiteId(iuSiteId);
findParentResult = crosslistService.processSisLookup(sisCourse);

model.addAttribute("terms", terms);

if (findParentResult != null) {
model.addAttribute("findParentResult", findParentResult);
}

return "findParentCourse";
}

private List<SectionUIDisplay> removeSectionUiDisplayBySectionName(@NonNull List<SectionUIDisplay> oldList, @NonNull String toRemoveSectionName) {
List<SectionUIDisplay> newList = new ArrayList<SectionUIDisplay>();
Expand Down
44 changes: 44 additions & 0 deletions src/main/java/edu/iu/uits/lms/crosslist/model/FindParentModel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package edu.iu.uits.lms.crosslist.model;

/*-
* #%L
* lms-lti-crosslist
* %%
* Copyright (C) 2015 - 2023 Indiana University
* %%
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. Neither the name of the Indiana University nor the names of its contributors
* may be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
* #L%
*/

import lombok.Data;

@Data
public class FindParentModel {
private String radioSearch;
private String sisIdSearch;
private String termByClassNumberSearch;
private String classNumberSearch;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package edu.iu.uits.lms.crosslist.model;

/*-
* #%L
* lms-lti-crosslist
* %%
* Copyright (C) 2015 - 2023 Indiana University
* %%
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. Neither the name of the Indiana University nor the names of its contributors
* may be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
* #L%
*/

import edu.iu.uits.lms.crosslist.CrosslistConstants;
import lombok.Data;

@Data
public class FindParentResult {
private String url;
private String name;
private String sisCourseId;
private boolean showCourseInfo;
private String statusMessage;
private String statusIconCssClasses;
private String statusIconName;
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,18 @@
* #L%
*/

import edu.iu.uits.lms.canvas.config.CanvasConfiguration;
import edu.iu.uits.lms.canvas.helpers.CanvasDateFormatUtil;
import edu.iu.uits.lms.canvas.model.Account;
import edu.iu.uits.lms.canvas.model.CanvasTerm;
import edu.iu.uits.lms.canvas.model.Course;
import edu.iu.uits.lms.canvas.model.Section;
import edu.iu.uits.lms.canvas.services.AccountService;
import edu.iu.uits.lms.canvas.services.CourseService;
import edu.iu.uits.lms.canvas.services.SectionService;
import edu.iu.uits.lms.common.session.CourseSessionService;
import edu.iu.uits.lms.crosslist.CrosslistConstants;
import edu.iu.uits.lms.crosslist.model.FindParentResult;
import edu.iu.uits.lms.crosslist.model.SectionUIDisplay;
import edu.iu.uits.lms.iuonly.model.SisCourse;
import edu.iu.uits.lms.iuonly.services.FeatureAccessServiceImpl;
Expand Down Expand Up @@ -88,6 +91,13 @@ public class CrosslistService {
@Autowired
private SisServiceImpl sisService;

@Autowired
private SectionService sectionService;

@Autowired
private CanvasConfiguration canvasConfiguration;


// self reference so can use the cache for getCourseSections() from within this service
@Lazy
@Autowired
Expand Down Expand Up @@ -380,6 +390,61 @@ public boolean canCoursesBeCrosslistedBasedOnEtexts(String sourceSisCourseSiteId
return sourceCourseEtextIsbns.equals(destinationCourseEtextIsbns);
}

public FindParentResult processSisLookup(SisCourse sisCourse) {
FindParentResult findParentResult = new FindParentResult();

if (sisCourse == null || sisCourse.getIuSiteId() == null) {
findParentResult.setShowCourseInfo(false);
findParentResult.setStatusMessage(CrosslistConstants.LOOKUP_FAILURE_NOT_FOUND_IN_SIS_MESSAGE);
findParentResult.setStatusIconCssClasses(CrosslistConstants.LOOKUP_FAILURE_CSS);
findParentResult.setStatusIconName(CrosslistConstants.LOOKUP_FAILURE_ICON_NAME);
return findParentResult;
}

Section section = sectionService.getSection(String.format("sis_section_id:%s", sisCourse.getIuSiteId()));

if (section == null || section.getSis_course_id() == null || section.getSis_section_id() == null) {
findParentResult.setShowCourseInfo(false);
findParentResult.setStatusMessage(CrosslistConstants.LOOKUP_FAILURE_NOT_FOUND_IN_CANVAS_MESSAGE);
findParentResult.setStatusIconCssClasses(CrosslistConstants.LOOKUP_FAILURE_CSS);
findParentResult.setStatusIconName(CrosslistConstants.LOOKUP_FAILURE_ICON_NAME);
return findParentResult;
}

Course course = courseService.getCourse(section.getCourse_id());

if (course == null) {
findParentResult.setShowCourseInfo(false);
findParentResult.setStatusMessage(CrosslistConstants.LOOKUP_FAILURE_NOT_FOUND_IN_CANVAS_MESSAGE);
findParentResult.setStatusIconCssClasses(CrosslistConstants.LOOKUP_FAILURE_CSS);
findParentResult.setStatusIconName(CrosslistConstants.LOOKUP_FAILURE_ICON_NAME);
return findParentResult;
}

if (section.getSis_course_id().equals(section.getSis_section_id())) {
findParentResult.setShowCourseInfo(true);
findParentResult.setStatusMessage(CrosslistConstants.LOOKUP_FAILURE_COURSE_NOT_CROSSLISTED_MESSAGE);
findParentResult.setStatusIconCssClasses(CrosslistConstants.LOOKUP_FAILURE_CSS);
findParentResult.setStatusIconName(CrosslistConstants.LOOKUP_FAILURE_ICON_NAME);
findParentResult.setName(course.getName());
findParentResult.setSisCourseId(course.getSisCourseId());
findParentResult.setUrl(String.format("%s/courses/%s",
canvasConfiguration.getBaseUrl(), course.getId()));
return findParentResult;
}

findParentResult.setShowCourseInfo(true);
findParentResult.setStatusMessage(CrosslistConstants.LOOKUP_SUCCESS_FOUND_MESSAGE);
findParentResult.setStatusIconCssClasses(CrosslistConstants.LOOKUP_SUCCESS_CSS);
findParentResult.setStatusIconName(CrosslistConstants.LOOKUP_SUCCESS_ICON_NAME);
findParentResult.setName(course.getName());
findParentResult.setSisCourseId(course.getSisCourseId());
findParentResult.setUrl(String.format("%s/courses/%s",
canvasConfiguration.getBaseUrl(), course.getId()));

return findParentResult;
}

@Data
private class CourseSisNaturalAndAlien {
String courseId;
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/static/css/crosslisting.css
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,7 @@
.rvt-disclosure__toggle::before {
filter: brightness(0%);
}

.resultsWidth {
width: max-content;
}
Loading

0 comments on commit ba41718

Please sign in to comment.