Skip to content

Commit 189ce7e

Browse files
committed
make Turnitin::Client#id shard aware
refs CNVS-17473 fixes CNVS-21075 Test plan: turnitin still works Change-Id: I36c34b2a4be67e4d0348dba2de43880ce4a8520a Reviewed-on: https://gerrit.instructure.com/56782 Reviewed-by: Josh Simpson <jsimpson@instructure.com> Tested-by: Jenkins QA-Review: Jason Carter <jcarter@instructure.com> Product-Review: Cameron Matheson <cameron@instructure.com>
1 parent 127452d commit 189ce7e

7 files changed

Lines changed: 39 additions & 11 deletions

File tree

app/models/assignment.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class Assignment < ActiveRecord::Base
3232
include DatesOverridable
3333
include SearchTermHelper
3434
include Canvas::DraftStateValidations
35+
include TurnitinID
3536

3637
attr_accessible :title, :name, :description, :due_at, :points_possible,
3738
:grading_type, :submission_types, :assignment_group, :unlock_at, :lock_at,

app/models/course.rb

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class Course < ActiveRecord::Base
2626
include HtmlTextHelper
2727
include TimeZoneHelper
2828
include ContentLicenses
29+
include TurnitinID
2930

3031
attr_accessor :teacher_names
3132
attr_writer :student_count, :primary_enrollment_type, :primary_enrollment_role_id, :primary_enrollment_rank, :primary_enrollment_state, :invitation
@@ -1792,14 +1793,6 @@ def turnitin_enabled?
17921793
!!self.turnitin_settings
17931794
end
17941795

1795-
def generate_turnitin_id!
1796-
# the reason we don't just use the global_id all the time is so that the
1797-
# turnitin_id is preserved when shard splits/etc. occur
1798-
unless turnitin_id
1799-
update_attribute(:turnitin_id, global_id)
1800-
end
1801-
end
1802-
18031796
def self.migrate_content_links(html, from_context, to_context, supported_types=nil, user_to_check_for_permission=nil)
18041797
return html unless html.present? && to_context
18051798

app/models/user.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
require 'atom'
2020

2121
class User < ActiveRecord::Base
22+
include TurnitinID
23+
2224
# this has to be before include Context to prevent a circular dependency in Course
2325
def self.sortable_name_order_by_clause(table = nil)
2426
col = table ? "#{table}.sortable_name" : 'sortable_name'
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class NeedsMoreTurnitinId < ActiveRecord::Migration
2+
tag :predeploy
3+
4+
def change
5+
add_column :assignments, :turnitin_id, :integer, limit: 8, unique: :true
6+
add_column :users, :turnitin_id, :integer, limit: 8, unique: :true
7+
end
8+
end

lib/turnitin.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ def initialize(account_id, shared_secret, host=nil, testing=false)
6262
def id(obj)
6363
if @testing
6464
"test_#{obj.asset_string}"
65+
elsif obj.respond_to?(:turnitin_id)
66+
obj.turnitin_asset_string
6567
else
6668
"#{account_id}_#{obj.asset_string}"
6769
end
@@ -72,9 +74,7 @@ def email(item)
7274
email = if item.is_a?(User)
7375
item.email
7476
elsif item.respond_to?(:turnitin_id)
75-
item.generate_turnitin_id!
76-
item_type = item.class.reflection_type_name
77-
"#{item_type}_#{item.turnitin_id}@null.instructure.example.com"
77+
"#{item.turnitin_asset_string}@null.instructure.example.com"
7878
end
7979
email ||= "#{item.asset_string}@null.instructure.example.com"
8080
end

lib/turnitin_id.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
module TurnitinID
2+
def generate_turnitin_id!
3+
# the reason we don't just use the global_id all the time is so that the
4+
# turnitin_id is preserved when shard splits/etc. occur
5+
turnitin_id || update_attribute(:turnitin_id, global_id)
6+
end
7+
8+
def turnitin_asset_string
9+
generate_turnitin_id!
10+
"#{self.class.reflection_type_name}_#{turnitin_id}"
11+
end
12+
end

spec/lib/turnitin_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,4 +350,16 @@ def stub_net_http_to_return(partial_body, return_code = 1)
350350
expect(@course.turnitin_id).to eql @course.global_id
351351
end
352352
end
353+
354+
describe '#id' do
355+
it "uses turnitin_id when defined" do
356+
turnitin = Turnitin::Client.new('blah', 'blah')
357+
student_in_course active_all: true
358+
assignment = @course.assignments.create!
359+
360+
expect(turnitin.id(@course)).to eql "course_#{@course.turnitin_id}"
361+
expect(turnitin.id(assignment)).to eql "assignment_#{assignment.turnitin_id}"
362+
expect(turnitin.id(@student)).to eql "user_#{@student.turnitin_id}"
363+
end
364+
end
353365
end

0 commit comments

Comments
 (0)