rubrics getting deleted incorrectly
a rubric should only be deleted once it's not being used anymore. It should only be unbookmarked from a given context when it's not being used in that context anymore. fixes #3309 Change-Id: Icb8a79baeb0c0ec2195b7e19b1d9768eadfeb97e Reviewed-on: https://gerrit.instructure.com/2518 Tested-by: Hudson <hudson@instructure.com> Reviewed-by: JT Olds <jt@instructure.com> Reviewed-by: Brian Palmer <brianp@instructure.com>
This commit is contained in:
parent
65ed7cb284
commit
d6e9f03968
|
@ -55,7 +55,11 @@ class RubricAssociationsController < ApplicationController
|
|||
@rubric = @association.rubric
|
||||
if authorized_action(@association, @current_user, :delete)
|
||||
@association.destroy
|
||||
if !RubricAssociation.for_purpose('bookmark').find_by_rubric_id(@rubric.id)
|
||||
# If the rubric wasn't created as a general course rubric,
|
||||
# and this was the last place it was being used in the course,
|
||||
# go ahead and delete the rubric from the course.
|
||||
association_count = RubricAssociation.scoped(:conditions => {:context_id => @context.id, :context_type => @context.class.to_s, :rubric_id => @rubric.id}).for_grading.count
|
||||
if !RubricAssociation.for_purpose('bookmark').find_by_rubric_id(@rubric.id) && association_count == 0
|
||||
@rubric.destroy_for(@context)
|
||||
end
|
||||
render :json => @association.to_json
|
||||
|
|
|
@ -99,9 +99,14 @@ class Rubric < ActiveRecord::Base
|
|||
self.save
|
||||
end
|
||||
|
||||
# If any rubric_associations for a given context are marked as
|
||||
# bookmarked, then the rubric will show up in the context's list
|
||||
# of rubrics. The two main values for the 'purpose' field on
|
||||
# a rubric_association are 'grading' and 'bookmark'. Confusing,
|
||||
# I know.
|
||||
def destroy_for(context)
|
||||
RubricAssociation.update_all({:bookmarked => false, :updated_at => Time.now}, {:rubric_id => self.id, :context_id => context.id, :context_type => context.class.to_s})
|
||||
if !self.read_only && self.rubric_associations.for_grading.length < 2
|
||||
if RubricAssociation.scoped(:conditions => {:rubric_id => self.id, :bookmarked => true}).count == 0
|
||||
self.destroy
|
||||
end
|
||||
end
|
||||
|
|
|
@ -130,7 +130,7 @@ class RubricAssociation < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def update_values
|
||||
self.bookmarked = true if self.purpose == 'bookmark'
|
||||
self.bookmarked = true if self.purpose == 'bookmark' || self.bookmarked.nil?
|
||||
self.context_code ||= "#{self.context_type.underscore}_#{self.context_id}" rescue nil
|
||||
self.title ||= (self.association.title rescue self.association.name) rescue nil
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue