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>
This commit is contained in:
parent
127452d0df
commit
189ce7e3f2
|
@ -32,6 +32,7 @@ class Assignment < ActiveRecord::Base
|
|||
include DatesOverridable
|
||||
include SearchTermHelper
|
||||
include Canvas::DraftStateValidations
|
||||
include TurnitinID
|
||||
|
||||
attr_accessible :title, :name, :description, :due_at, :points_possible,
|
||||
:grading_type, :submission_types, :assignment_group, :unlock_at, :lock_at,
|
||||
|
|
|
@ -26,6 +26,7 @@ class Course < ActiveRecord::Base
|
|||
include HtmlTextHelper
|
||||
include TimeZoneHelper
|
||||
include ContentLicenses
|
||||
include TurnitinID
|
||||
|
||||
attr_accessor :teacher_names
|
||||
attr_writer :student_count, :primary_enrollment_type, :primary_enrollment_role_id, :primary_enrollment_rank, :primary_enrollment_state, :invitation
|
||||
|
@ -1792,14 +1793,6 @@ class Course < ActiveRecord::Base
|
|||
!!self.turnitin_settings
|
||||
end
|
||||
|
||||
def generate_turnitin_id!
|
||||
# the reason we don't just use the global_id all the time is so that the
|
||||
# turnitin_id is preserved when shard splits/etc. occur
|
||||
unless turnitin_id
|
||||
update_attribute(:turnitin_id, global_id)
|
||||
end
|
||||
end
|
||||
|
||||
def self.migrate_content_links(html, from_context, to_context, supported_types=nil, user_to_check_for_permission=nil)
|
||||
return html unless html.present? && to_context
|
||||
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
require 'atom'
|
||||
|
||||
class User < ActiveRecord::Base
|
||||
include TurnitinID
|
||||
|
||||
# this has to be before include Context to prevent a circular dependency in Course
|
||||
def self.sortable_name_order_by_clause(table = nil)
|
||||
col = table ? "#{table}.sortable_name" : 'sortable_name'
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
class NeedsMoreTurnitinId < ActiveRecord::Migration
|
||||
tag :predeploy
|
||||
|
||||
def change
|
||||
add_column :assignments, :turnitin_id, :integer, limit: 8, unique: :true
|
||||
add_column :users, :turnitin_id, :integer, limit: 8, unique: :true
|
||||
end
|
||||
end
|
|
@ -62,6 +62,8 @@ module Turnitin
|
|||
def id(obj)
|
||||
if @testing
|
||||
"test_#{obj.asset_string}"
|
||||
elsif obj.respond_to?(:turnitin_id)
|
||||
obj.turnitin_asset_string
|
||||
else
|
||||
"#{account_id}_#{obj.asset_string}"
|
||||
end
|
||||
|
@ -72,9 +74,7 @@ module Turnitin
|
|||
email = if item.is_a?(User)
|
||||
item.email
|
||||
elsif item.respond_to?(:turnitin_id)
|
||||
item.generate_turnitin_id!
|
||||
item_type = item.class.reflection_type_name
|
||||
"#{item_type}_#{item.turnitin_id}@null.instructure.example.com"
|
||||
"#{item.turnitin_asset_string}@null.instructure.example.com"
|
||||
end
|
||||
email ||= "#{item.asset_string}@null.instructure.example.com"
|
||||
end
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
module TurnitinID
|
||||
def generate_turnitin_id!
|
||||
# the reason we don't just use the global_id all the time is so that the
|
||||
# turnitin_id is preserved when shard splits/etc. occur
|
||||
turnitin_id || update_attribute(:turnitin_id, global_id)
|
||||
end
|
||||
|
||||
def turnitin_asset_string
|
||||
generate_turnitin_id!
|
||||
"#{self.class.reflection_type_name}_#{turnitin_id}"
|
||||
end
|
||||
end
|
|
@ -350,4 +350,16 @@ describe Turnitin::Client do
|
|||
expect(@course.turnitin_id).to eql @course.global_id
|
||||
end
|
||||
end
|
||||
|
||||
describe '#id' do
|
||||
it "uses turnitin_id when defined" do
|
||||
turnitin = Turnitin::Client.new('blah', 'blah')
|
||||
student_in_course active_all: true
|
||||
assignment = @course.assignments.create!
|
||||
|
||||
expect(turnitin.id(@course)).to eql "course_#{@course.turnitin_id}"
|
||||
expect(turnitin.id(assignment)).to eql "assignment_#{assignment.turnitin_id}"
|
||||
expect(turnitin.id(@student)).to eql "user_#{@student.turnitin_id}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue