Skip to content

Commit 67bcc2a

Browse files
authored
Merge pull request #336 from turnitin/develop
Develop to master for release
2 parents e6a53eb + a5b9578 commit 67bcc2a

14 files changed

+311
-29
lines changed

CHANGELOG.md

+23
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,26 @@
1+
### 2018-June-26
2+
### v2018062601
3+
4+
#### Fixes and enhancements
5+
6+
---
7+
8+
#### Resubmissions now overwrite the previous submission
9+
10+
When a student made a resubmission to Turnitin, their previous submission wasn't removed from the assignment inbox; this led to confusion for instructors, who weren't too sure which submission was the most up-to-date version. We've made sure that resubmissions now overwrite the existing submission.
11+
12+
> **Known issue:** While we've been able to fix this issue for students, if an instructor resubmits on behalf of a student, multiple submissions may still appear in Turnitin. We're working on a fix for this and will update you as soon as we find one!
13+
14+
#### The Plagiarism Plugin now works on Moodle 3.1 and earlier versions
15+
16+
Users running Moodle version 3.1 or earlier encountered an unexpected error when submitting a file. The error message, referring to an invalid parameter, was the result of a change made in our previous release. We apologize for the trouble this may have caused and can confirm that Moodle version 3.1 and earlier now function correctly.
17+
18+
#### Moodle unit tests now pass
19+
20+
We’ve ensured all Moodle unit tests now pass with the plugin installed. Thanks to @danmarsden and @kenneth-hendricks for their contributions.
21+
22+
---
23+
124
### Date: 2018-May-24
225
### Release: v2018052401
326

classes/digitalreceipt/pp_receipt_message.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,10 @@ public function send_message($userid, $message, $courseid) {
5252
$eventdata->fullmessagehtml = $message;
5353
$eventdata->smallmessage = '';
5454
$eventdata->notification = 1; // This is only set to 0 for personal messages between users.
55-
$eventdata->courseid = $courseid;
55+
56+
if ($CFG->branch >= 32) {
57+
$eventdata->courseid = $courseid;
58+
}
5659

5760
message_send($eventdata);
5861
}

classes/modules/turnitin_assign.class.php

+21-8
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public function set_content($linkarray, $cm) {
6868
*
6969
* @param $assignid
7070
*/
71-
public function is_resubmission_allowed($assignid, $reportgenspeed, $submissiontype, $attemptreopenmethod) {
71+
public function is_resubmission_allowed($assignid, $reportgenspeed, $submissiontype, $attemptreopenmethod, $attemptreopened = null) {
7272
global $DB, $CFG;
7373

7474
// Get the maximum number of file submissions allowed.
@@ -82,12 +82,20 @@ public function is_resubmission_allowed($assignid, $reportgenspeed, $submissiont
8282
$maxfilesubmissions = $result->value;
8383
}
8484

85-
if ($CFG->branch <= 32) {
86-
require_once($CFG->dirroot.'/mod/assign/lib.php');
85+
require_once($CFG->dirroot . '/mod/assign/locallib.php');
86+
87+
// If resubmissions are enabled in a Turnitin sense.
88+
if ($reportgenspeed > 0) {
89+
// If the attempt reopened method is none, or an attempt has not been reopened/has previous submission.
90+
if ($attemptreopenmethod == ASSIGN_ATTEMPT_REOPEN_METHOD_NONE || $attemptreopened == 'submitted') {
91+
// If this is a text or file submission, or we can only submit one file.
92+
if ($submissiontype == 'text_content' || ($submissiontype == 'file' && $maxfilesubmissions == 1)) {
93+
// Treat this as a resubmission.
94+
return true;
95+
}
96+
}
8797
}
88-
89-
return ($reportgenspeed > 0 && $attemptreopenmethod == ASSIGN_ATTEMPT_REOPEN_METHOD_NONE
90-
&& ($submissiontype == 'text_content' || $maxfilesubmissions == 1));
98+
return false;
9199
}
92100

93101
public function get_onlinetext($userid, $cm) {
@@ -102,8 +110,13 @@ public function get_onlinetext($userid, $cm) {
102110

103111
$onlinetextdata = new stdClass();
104112
$onlinetextdata->itemid = $submission->id;
105-
$onlinetextdata->onlinetext = $moodletextsubmission->onlinetext;
106-
$onlinetextdata->onlineformat = $moodletextsubmission->onlineformat;
113+
114+
if (isset($moodletextsubmission->onlinetext)) {
115+
$onlinetextdata->onlinetext = $moodletextsubmission->onlinetext;
116+
}
117+
if (isset($moodletextsubmission->onlineformat)) {
118+
$onlinetextdata->onlineformat = $moodletextsubmission->onlineformat;
119+
}
107120

108121
return $onlinetextdata;
109122
}

classes/privacy/provider.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,10 @@ public static function _get_contexts_for_userid($userid) {
119119
public static function _export_plagiarism_user_data($userid, \context $context, array $subcontext, array $linkarray) {
120120
global $DB;
121121

122+
if (empty($userid)) {
123+
return;
124+
}
125+
122126
$user = $DB->get_record('user', array('id' => $userid));
123127

124128
$params = ['userid' => $user->id];
@@ -176,12 +180,8 @@ public static function _delete_plagiarism_for_context(\context $context) {
176180
return;
177181
}
178182

179-
$instanceid = $DB->get_field('course_modules', 'instance', ['id' => $context->instanceid], MUST_EXIST);
180-
181-
$cm = get_coursemodule_from_instance('assign', $instanceid);
182-
183183
// Delete all submissions.
184-
$DB->delete_records('plagiarism_turnitin_files', ['cm' => $cm->id]);
184+
$DB->delete_records('plagiarism_turnitin_files', ['cm' => $context->instanceid]);
185185

186186
}
187187

jquery/turnitin_module.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ jQuery(document).ready(function($) {
194194

195195
// Open the DV in a new window in such a way as to not be blocked by popups.
196196
function openDV(dvtype, submissionid, coursemoduleid, url) {
197-
dvWindow = window.open('', '_blank');
197+
dvWindow = window.open('', 'turnitin_viewer');
198198
var loading = '<div class="tii_dv_loading" style="text-align:center;">';
199199
loading += '<img src="' + M.cfg.wwwroot + '/plagiarism/turnitin/pix/tiiIcon.svg" style="width:100px; height: 100px">';
200200
loading += '<p style="font-family: Arial, Helvetica, sans-serif;">' + M.str.plagiarism_turnitin.loadingdv + '</p>';

jquery/turnitin_module_post29.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ require(['jquery'], function($) {
194194

195195
// Open the DV in a new window in such a way as to not be blocked by popups.
196196
function openDV(dvtype, submissionid, coursemoduleid, url) {
197-
dvWindow = window.open('', '_blank');
197+
dvWindow = window.open('', 'turnitin_viewer');
198198
var loading = '<div class="tii_dv_loading" style="text-align:center;">';
199199
loading += '<img src="' + M.cfg.wwwroot + '/plagiarism/turnitin/pix/tiiIcon.svg" style="width:100px; height: 100px">';
200200
loading += '<p style="font-family: Arial, Helvetica, sans-serif;">' + M.str.plagiarism_turnitin.loadingdv + '</p>';

lib.php

+34-9
Original file line numberDiff line numberDiff line change
@@ -2127,7 +2127,7 @@ public function migrate_previous_course($coursedata, $turnitincid, $workflowcont
21272127
* @param int $itemid
21282128
* @return bool
21292129
*/
2130-
public function queue_submission_to_turnitin($cm, $author, $submitter, $identifier, $submissiontype, $itemid = 0) {
2130+
public function queue_submission_to_turnitin($cm, $author, $submitter, $identifier, $submissiontype, $itemid = 0, $eventtype = null) {
21312131
global $CFG, $DB, $turnitinacceptedfiles;
21322132
$errorcode = 0;
21332133
$attempt = 0;
@@ -2141,13 +2141,31 @@ public function queue_submission_to_turnitin($cm, $author, $submitter, $identifi
21412141
// Get module data.
21422142
$moduledata = $DB->get_record($cm->modname, array('id' => $cm->instance));
21432143
$moduledata->resubmission_allowed = false;
2144+
21442145
if ($cm->modname == 'assign') {
2146+
if (!isset($_SESSION["moodlesubmissionstatus"])) {
2147+
$_SESSION["moodlesubmissionstatus"] = null;
2148+
}
2149+
2150+
if ($eventtype == "content_uploaded" || $eventtype == "file_uploaded") {
2151+
$moodlesubmission = $DB->get_record('assign_submission',
2152+
array('assignment' => $cm->instance,
2153+
'userid' => $author,
2154+
'id' => $itemid), 'status');
2155+
$_SESSION["moodlesubmissionstatus"] = $moodlesubmission->status;
2156+
}
2157+
21452158
$moduledata->resubmission_allowed = $moduleobject->is_resubmission_allowed(
21462159
$cm->instance,
21472160
$settings["plagiarism_report_gen"],
21482161
$submissiontype,
2149-
$moduledata->attemptreopenmethod
2162+
$moduledata->attemptreopenmethod,
2163+
$_SESSION["moodlesubmissionstatus"]
21502164
);
2165+
2166+
if ($eventtype != "content_uploaded" && $eventtype != "file_uploaded") {
2167+
unset($_SESSION["moodlesubmissionstatus"]);
2168+
}
21512169
}
21522170

21532171
// Work out submission method.
@@ -2188,8 +2206,8 @@ public function queue_submission_to_turnitin($cm, $author, $submitter, $identifi
21882206

21892207
// Check if this content/file has been submitted previously.
21902208
$previoussubmissions = $DB->get_records_select('plagiarism_turnitin_files',
2191-
" cm = ? AND userid = ? AND ".$typefield." = ? AND identifier = ? ",
2192-
array($cm->id, $author, $submissiontype, $identifier),
2209+
" cm = ? AND userid = ? AND ".$typefield." = ? ",
2210+
array($cm->id, $author, $submissiontype),
21932211
'id', $submissionfields);
21942212
$previoussubmission = end($previoussubmissions);
21952213

@@ -2199,7 +2217,7 @@ public function queue_submission_to_turnitin($cm, $author, $submitter, $identifi
21992217
&& $timemodified <= $previoussubmission->lastmodified) {
22002218
return true;
22012219
} else if ($moduledata->resubmission_allowed) {
2202-
// Replace submission in the specific circumstance where Turnitin can accomodate resubmissions.
2220+
// Replace submission in the specific circumstance where Turnitin can accommodate resubmissions.
22032221
$submissionid = $previoussubmission->id;
22042222
$this->reset_tii_submission($cm, $author, $identifier, $previoussubmission, $submissiontype);
22052223
$tiisubmissionid = $previoussubmission->externalid;
@@ -2209,6 +2227,7 @@ public function queue_submission_to_turnitin($cm, $author, $submitter, $identifi
22092227
$this->reset_tii_submission($cm, $author, $identifier, $previoussubmission, $submissiontype);
22102228
} else {
22112229
$submissionid = $this->create_new_tii_submission($cm, $author, $identifier, $submissiontype);
2230+
$tiisubmissionid = $previoussubmission->externalid;
22122231
}
22132232
}
22142233
$attempt = $previoussubmission->attempt;
@@ -2389,7 +2408,7 @@ public function event_handler($eventdata) {
23892408
return true;
23902409
} else {
23912410
$result = $this->queue_submission_to_turnitin(
2392-
$cm, $author, $submitter, $identifier, $submissiontype, $eventdata['objectid']);
2411+
$cm, $author, $submitter, $identifier, $submissiontype, $eventdata['objectid'], $eventdata['eventtype']);
23932412
}
23942413
}
23952414

@@ -2422,7 +2441,7 @@ public function event_handler($eventdata) {
24222441

24232442
$result = $result && $this->queue_submission_to_turnitin(
24242443
$cm, $author, $submitter, $pathnamehash, 'file',
2425-
$eventdata['objectid']);
2444+
$eventdata['objectid'], $eventdata['eventtype']);
24262445
}
24272446
}
24282447

@@ -2691,11 +2710,18 @@ function plagiarism_turnitin_send_queued_submissions() {
26912710
// Get module data.
26922711
$moduledata = $DB->get_record($cm->modname, array('id' => $cm->instance));
26932712
$moduledata->resubmission_allowed = false;
2713+
26942714
if ($cm->modname == 'assign') {
2715+
$moodlesubmission = $DB->get_record('assign_submission',
2716+
array('assignment' => $cm->instance,
2717+
'userid' => $queueditem->userid,
2718+
'id' => $queueditem->itemid), 'status');
2719+
26952720
$moduledata->resubmission_allowed = $moduleobject->is_resubmission_allowed(
26962721
$cm->instance, $settings["plagiarism_report_gen"],
26972722
$queueditem->submissiontype,
2698-
$moduledata->attemptreopenmethod
2723+
$moduledata->attemptreopenmethod,
2724+
$moodlesubmission->status
26992725
);
27002726
}
27012727

@@ -2814,7 +2840,6 @@ function plagiarism_turnitin_send_queued_submissions() {
28142840
if (is_null($queueditem->externalid)) {
28152841
$apimethod = "createSubmission";
28162842
} else {
2817-
28182843
$apimethod = ($moduledata->resubmission_allowed) ? "replaceSubmission" : "createSubmission";
28192844

28202845
// Delete old text content submissions from Turnitin if not replacing.

tests/behat/assignment.feature

+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
@plugin @plagiarism @plagiarism_turnitin @plagiarism_turnitin_sanity @plagairism_turnitin_smoke @plagiarism_turnitin_assignment
2+
Feature: Plagiarism plugin works with a Moodle Assignment
3+
In order to allow students to send assignment submissions to Turnitin
4+
As a user
5+
I need to create an assignment with the plugin enabled and the assignment to launch successfully.
6+
7+
Background: Set up the plugin
8+
Given the following "courses" exist:
9+
| fullname | shortname | category | groupmode |
10+
| Course 1 | C1 | 0 | 0 |
11+
And I create a unique user with username "student1"
12+
And I create a unique user with username "instructor1"
13+
And the following "course enrolments" exist:
14+
| user | course | role |
15+
| student1 | C1 | student |
16+
| instructor1 | C1 | teacher |
17+
And I log in as "admin"
18+
And I navigate to "Advanced features" node in "Site administration"
19+
And I set the field "Enable plagiarism plugins" to "1"
20+
And I press "Save changes"
21+
And I navigate to "Turnitin" node in "Site administration > Plugins > Plagiarism"
22+
And I set the following fields to these values:
23+
| Enable Turnitin | 1 |
24+
| Enable Turnitin for assign | 1 |
25+
And I press "Save changes"
26+
And I navigate to "Turnitin Assignment 2" node in "Site administration > Plugins > Activity modules"
27+
And I configure Turnitin URL
28+
And I configure Turnitin credentials
29+
And I set the following fields to these values:
30+
| Enable Diagnostic Mode | Standard |
31+
And I press "Save changes"
32+
Then the following should exist in the "plugins-control-panel" table:
33+
| Plugin name |
34+
| plagiarism_turnitin |
35+
# Create Assignment.
36+
And I am on "Course 1" course homepage with editing mode on
37+
And I add a "Assignment" to section "1" and I fill the form with:
38+
| Assignment name | Test assignment name |
39+
| use_turnitin | 1 |
40+
| plagiarism_compare_student_papers | 1 |
41+
Then I should see "Test assignment name"
42+
43+
@javascript
44+
Scenario: Student accepts eula, submits and instructor opens the viewer
45+
Given I log out
46+
# Student accepts eula.
47+
And I log in as "student1"
48+
And I am on "Course 1" course homepage
49+
And I follow "Test assignment name"
50+
And I press "Add submission"
51+
And I click on ".pp_turnitin_eula_link" "css_element"
52+
And I wait until ".cboxIframe" "css_element" exists
53+
And I switch to iframe with locator ".cboxIframe"
54+
And I wait until the page is ready
55+
And I click on ".agree-button" "css_element"
56+
And I wait until the page is ready
57+
Then I should see "Test assignment name"
58+
# Student submits.
59+
And I am on "Course 1" course homepage
60+
And I follow "Test assignment name"
61+
And I press "Add submission"
62+
And I upload "plagiarism/turnitin/tests/fixtures/testfile.txt" file to "File submissions" filemanager
63+
And I press "Save changes"
64+
Then I should see "Submitted for grading"
65+
And I should see "Queued"
66+
# Trigger cron as admin for submission
67+
And I log out
68+
And I log in as "admin"
69+
And I run the scheduled task "plagiarism_turnitin\task\send_submissions"
70+
# Instructor opens viewer
71+
And I log out
72+
And I log in as "instructor1"
73+
And I am on "Course 1" course homepage
74+
And I follow "Test assignment name"
75+
Then I should see "View all submissions"
76+
When I navigate to "View all submissions" in current page administration
77+
Then I should see "Turnitin ID:"
78+
# Trigger cron as admin for report
79+
And I log out
80+
And I log in as "admin"
81+
And I run the scheduled task "\plagiarism_turnitin\task\update_reports"
82+
# Instructor opens viewer
83+
And I log out
84+
And I log in as "instructor1"
85+
And I am on "Course 1" course homepage
86+
And I follow "Test assignment name"
87+
Then I should see "View all submissions"
88+
When I navigate to "View all submissions" in current page administration
89+
And I wait until "[alt='GradeMark']" "css_element" exists
90+
And I click on "[alt='GradeMark']" "css_element"
91+
And I switch to "turnitin_viewer" window
92+
And I wait until the page is ready
93+
And I click on ".agree-button" "css_element"
94+
And I wait until the page is ready
95+
Then I should see "testfile.txt"

0 commit comments

Comments
 (0)