Skip to content

Commit

Permalink
SAK-44666 Turnitin OC: Student changes to the similarity exclusions a…
Browse files Browse the repository at this point in the history
…re saved in the viewer (sakaiproject#8808)
  • Loading branch information
baholladay authored Nov 20, 2020
1 parent 1df3b3f commit c0941bb
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 16 deletions.
12 changes: 12 additions & 0 deletions content-review/impl/turnitin-oc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,18 @@ assignment.useContentReview=true
# turnitin.oc.roles.administrator.mapping=Administrator,Admin
# turnitin.oc.roles.undefined.mapping=""
#turnitin.oc.roles.[TII_ROLE].may_save_report_changes=true/false
# Allows you to customize the default Turnitin setting for each role controlling whether a report can be saved when modified.
# If true, any changes to the report, including changes that effect the score, will be saved and persist for all users.
# Default:
# turnitin.oc.roles.instructor.may_save_report_changes=true
# turnitin.oc.roles.learner.may_save_report_changes=false
# turnitin.oc.roles.editor.may_save_report_changes=false
# turnitin.oc.roles.user.may_save_report_changes=false
# turnitin.oc.roles.applicant.may_save_report_changes=false
# turnitin.oc.roles.administrator.may_save_report_changes=true
# turnitin.oc.roles.undefined.may_save_report_changes=false
# Please make sure the property 'version.sakai' is set correctly
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.URL;
Expand Down Expand Up @@ -167,24 +167,33 @@ public class ContentReviewServiceTurnitinOC extends BaseContentReviewService {
private static final String VIEWER_PERMISSION_MAY_VIEW_MATCH_SUBMISSION_INFO = "may_view_match_submission_info";
private static final String VIEWER_DEFAULT_PERMISSIONS = "viewer_default_permission_set";
private enum ROLES{
INSTRUCTOR(Arrays.asList("Faculty", "Instructor", "Mentor", "Staff", "maintain", "Teaching Assistant")),
LEARNER(Arrays.asList("Learner", "Student", "access")),
EDITOR(Arrays.asList()),
USER(Arrays.asList("Alumni", "guest", "Member", "Observer", "Other")),
APPLICANT(Arrays.asList("ProspectiveStudent")),
ADMINISTRATOR(Arrays.asList("Administrator", "Admin")),
UNDEFINED(Arrays.asList());
INSTRUCTOR(Arrays.asList("Faculty", "Instructor", "Mentor", "Staff", "maintain", "Teaching Assistant"), Boolean.TRUE),
LEARNER(Arrays.asList("Learner", "Student", "access"), Boolean.FALSE),
EDITOR(Arrays.asList(), Boolean.FALSE),
USER(Arrays.asList("Alumni", "guest", "Member", "Observer", "Other"), Boolean.FALSE),
APPLICANT(Arrays.asList("ProspectiveStudent"), Boolean.FALSE),
ADMINISTRATOR(Arrays.asList("Administrator", "Admin"), Boolean.TRUE),
UNDEFINED(Arrays.asList(), Boolean.FALSE);

List<String> mappedRoles;
private ROLES(List<String> mappedRoles) {
Boolean maySaveReportChanges;

private ROLES(List<String> mappedRoles, Boolean maySaveReportChanges) {
this.mappedRoles = mappedRoles;
this.maySaveReportChanges = maySaveReportChanges;
}
private void setMappedRoles(List<String> mappedRoles) {
this.mappedRoles = mappedRoles;
}
private List<String> getMappedRoles() {
return mappedRoles;
}
public Boolean getMaySaveReportChanges() {
return maySaveReportChanges;
}
public void setMaySaveReportChanges(Boolean maySaveReportChanges) {
this.maySaveReportChanges = maySaveReportChanges;
}
};

private static final String GENERATE_REPORTS_IMMEDIATELY_AND_ON_DUE_DATE= "1";
Expand Down Expand Up @@ -335,7 +344,10 @@ public void init() {

// Override default Sakai->Turnitin roles mapping
for(ROLES role : ROLES.values()) {
//map Sakai roles to Turnitin roles
role.setMappedRoles(serverConfigurationService.getStringList("turnitin.oc.roles." + role.name().toLowerCase() + ".mapping", role.getMappedRoles()));
//set maySaveReportChanges permission for each role
role.setMaySaveReportChanges(serverConfigurationService.getBoolean("turnitin.oc.roles." + role.name().toLowerCase() + ".may_save_report_changes", role.getMaySaveReportChanges()));
}

// Populate base headers that are needed for all calls to TCA
Expand Down Expand Up @@ -573,10 +585,11 @@ public String getReviewReportRedirectUrl(String contentId, String assignmentRef,
modes.put(ALL_SOURCES, Boolean.TRUE);
similarity.put(MODES, modes);
Map<String, Object> viewSettings = new HashMap<>();
viewSettings.put(SAVE_CHANGES, Boolean.TRUE);
similarity.put(VIEW_SETTINGS, viewSettings);
data.put(SIMILARITY, similarity);
data.put(VIEWER_DEFAULT_PERMISSIONS, mapUserRole(userId, contextId, isInstructor));
ROLES userRole = mapUserRole(userId, contextId, isInstructor);
data.put(VIEWER_DEFAULT_PERMISSIONS, userRole.name());
viewSettings.put(SAVE_CHANGES, userRole.getMaySaveReportChanges());
//Check if there are any sakai.properties overrides for the default permissions
Map<String, Object> viewerPermissionsOverride = new HashMap<String, Object>();
if(!isInstructor && mayViewSubmissionFullSourceOverrideStudent != null) {
Expand Down Expand Up @@ -929,12 +942,12 @@ private String getSubmissionId(ContentReviewItem item, String fileName, Site sit
Map<String, Object> data = new HashMap<String, Object>();
data.put("owner", userID);
if(site != null) {
data.put("owner_default_permission_set", mapUserRole(userID, site.getId(), false));
data.put("owner_default_permission_set", mapUserRole(userID, site.getId(), false).name());
}
if (StringUtils.isNotBlank(submitterID)) {
data.put("submitter", submitterID);
if(site != null) {
data.put("submitter_default_permission_set", mapUserRole(submitterID, site.getId(), false));
data.put("submitter_default_permission_set", mapUserRole(submitterID, site.getId(), false).name());
}
}
data.put("title", fileName);
Expand Down Expand Up @@ -1865,15 +1878,14 @@ public void webhookEvent(HttpServletRequest request, int providerId, Optional<St
log.info("Turnitin webhook received: " + success + " items processed, " + errors + " errors.");
}

private String mapUserRole(String userId, String contextId, boolean isInstructor) {
String role = isInstructor ? ROLES.INSTRUCTOR.name() : ROLES.UNDEFINED.name();
private ROLES mapUserRole(String userId, String contextId, boolean isInstructor) {
ROLES role = isInstructor ? ROLES.INSTRUCTOR : ROLES.UNDEFINED;
try
{
//get the user's role for this course
String siteRole = securityService.isSuperUser(userId) ? ROLES.ADMINISTRATOR.name() : authzGroupService.getUserRole(userId, siteService.siteReference(contextId));
role = Arrays.asList(ROLES.values()).stream()
.filter(r -> r.getMappedRoles().stream().anyMatch(siteRole::equalsIgnoreCase))
.map(r -> r.name())
.findFirst()
.orElse(role);
}catch(Exception e) {
Expand Down

0 comments on commit c0941bb

Please sign in to comment.