diff --git a/app/models/course_section.rb b/app/models/course_section.rb index 24bccafa900..b0f6b192589 100644 --- a/app/models/course_section.rb +++ b/app/models/course_section.rb @@ -117,10 +117,21 @@ class CourseSection < ActiveRecord::Base self.save! end self.move_to_course(course) + if (self.nonxlist_course.course_sections.active.count == 0 || + (self.nonxlist_course.course_sections.active.count == 1 && + self.nonxlist_course.course_sections.active.first.enrollments.count == 0)) && + self.nonxlist_course.workflow_state == "created" + self.nonxlist_course.workflow_state = "deleted" + self.nonxlist_course.save! + end end def uncrosslist return unless self.nonxlist_course + if self.nonxlist_course.workflow_state == "deleted" + self.nonxlist_course.workflow_state = "created" + self.nonxlist_course.save! + end self.move_to_course(self.nonxlist_course) self.nonxlist_course = nil self.account = nil diff --git a/app/views/accounts/_course.html.erb b/app/views/accounts/_course.html.erb index ffd09005d71..7fb2d5e55ce 100644 --- a/app/views/accounts/_course.html.erb +++ b/app/views/accounts/_course.html.erb @@ -13,7 +13,7 @@ <% if course.course_code != course.name %> <%= course.course_code %> <% end %> - <% if current_user_is_site_admin? && course.respond_to?(:sis_source_id) && course.sis_source_id %> + <% if course.respond_to?(:sis_source_id) && course.sis_source_id %> SIS ID: <%= course.sis_source_id %> <% end %> diff --git a/app/views/courses/course_details.html.erb b/app/views/courses/course_details.html.erb index 198a5df7c85..d9ed706d04d 100644 --- a/app/views/courses/course_details.html.erb +++ b/app/views/courses/course_details.html.erb @@ -135,12 +135,12 @@ <% end %> + <% if @context.sis_source_id %> + + <%= f.label :sis_source_id, "SIS ID:" %> + <%= @context.sis_source_id %> + <% end %> <% if current_user_is_site_admin? %> - <% if @context.sis_source_id %> - - <%= f.label :sis_source_id, "SIS ID:" %> - <%= @context.sis_source_id %> - <% end %> <%= f.label :root_account_id, "Root Account:" %> <%= @context.root_account.name %> @@ -326,7 +326,7 @@ ( - <%= pluralize(section.enrollments.count, "User") %><% if current_user_is_site_admin? && section && section.sis_source_id %>, + <%= pluralize(section.enrollments.count, "User") %><% if section && section.sis_source_id %>, SIS ID: <%= section.sis_source_id %> <% end %> ) diff --git a/app/views/sections/show.html.erb b/app/views/sections/show.html.erb index f5e8b4943cc..6c2283260d9 100644 --- a/app/views/sections/show.html.erb +++ b/app/views/sections/show.html.erb @@ -120,7 +120,7 @@ h3 .tally {
<%= pluralize((@current_enrollments + @completed_enrollments).length, 'Enrollment') %>
- <% if current_user_is_site_admin? && @section && @section.sis_source_id %> + <% if @section && @section.sis_source_id %>
SIS ID: <%= @section.sis_source_id %>
<% end %> <% if @section.start_at || @section.end_at %> @@ -174,4 +174,4 @@ $(document).ready(function() { $(".datetime_field").datetime_field(); }); -<% end %> \ No newline at end of file +<% end %> diff --git a/spec/models/course_section_spec.rb b/spec/models/course_section_spec.rb index f572895825a..310f0e0df68 100644 --- a/spec/models/course_section_spec.rb +++ b/spec/models/course_section_spec.rb @@ -96,13 +96,22 @@ describe CourseSection, "moving to new course" do course1 = account1.courses.create! course2 = account2.courses.create! course3 = account3.courses.create! + course2.assert_section + course3.assert_section cs = course1.course_sections.create! u = User.create! u.register! + e = course2.enroll_user(u, 'StudentEnrollment') + e.workflow_state = 'active' + e.save! e = course1.enroll_user(u, 'StudentEnrollment', :section => cs) e.workflow_state = 'active' e.save! course1.reload + course2.reload + course3.workflow_state = 'active' + course3.save + e.reload course1.course_sections.find_by_id(cs.id).should_not be_nil course2.course_sections.find_by_id(cs.id).should be_nil @@ -111,6 +120,9 @@ describe CourseSection, "moving to new course" do cs.nonxlist_course.should be_nil e.root_account.should eql(account1) cs.crosslisted?.should be_false + course1.workflow_state.should == 'created' + course2.workflow_state.should == 'created' + course3.workflow_state.should == 'created' cs.crosslist_to_course(course2) course1.reload @@ -125,6 +137,9 @@ describe CourseSection, "moving to new course" do cs.nonxlist_course.should eql(course1) e.root_account.should eql(account2) cs.crosslisted?.should be_true + course1.workflow_state.should == 'deleted' + course2.workflow_state.should == 'created' + course3.workflow_state.should == 'created' cs.crosslist_to_course(course3) course1.reload @@ -140,6 +155,9 @@ describe CourseSection, "moving to new course" do cs.nonxlist_course.should eql(course1) e.root_account.should eql(account3) cs.crosslisted?.should be_true + course1.workflow_state.should == 'deleted' + course2.workflow_state.should == 'created' + course3.workflow_state.should == 'created' cs.uncrosslist course1.reload @@ -155,6 +173,9 @@ describe CourseSection, "moving to new course" do cs.nonxlist_course.should be_nil e.root_account.should eql(account1) cs.crosslisted?.should be_false + course1.workflow_state.should == 'created' + course2.workflow_state.should == 'created' + course3.workflow_state.should == 'created' end end