diff --git a/app/controllers/templates_controller.rb b/app/controllers/templates_controller.rb index 742ce33c5d..42eb4eedc4 100644 --- a/app/controllers/templates_controller.rb +++ b/app/controllers/templates_controller.rb @@ -11,7 +11,7 @@ class TemplatesController < ApplicationController def admin_index authorize Template - funder_templates, org_templates, customizations = [], [], [] + funder_templates, org_templates = [], [] # Get all of the unique template family ids (dmptemplate_id) for each funder and the current org funder_ids = Org.funders.includes(:templates).collect{|f| f.templates.where(published: true).valid.collect{|ft| ft.dmptemplate_id } }.flatten.uniq @@ -131,7 +131,7 @@ def admin_transfer_customization # find corresponding question in new template customization_question = customization_section.questions.where(number: question.number).first # apply annotations - question.annotations.each do |annotation| + question.annotations.where(org_id: current_user.org_id).each do |annotation| annotation_copy = Annotation.deep_copy(annotation) annotation_copy.question_id = customization_question.id annotation_copy.save! @@ -213,7 +213,7 @@ def admin_template new_version.save @template = new_version # @current = Template.current(@template.dmptemplate_id) - end + end else flash[:notice] = _('You are viewing a historical version of this template. You will not be able to make changes.') end diff --git a/lib/tasks/migrate.rake b/lib/tasks/migrate.rake index f4365861ea..acbbf3cd7b 100644 --- a/lib/tasks/migrate.rake +++ b/lib/tasks/migrate.rake @@ -219,15 +219,15 @@ namespace :migrate do if IdentifierScheme.find_by(name: 'orcid').nil? IdentifierScheme.create!(name: 'orcid', description: 'ORCID', active: true) end - + scheme = IdentifierScheme.find_by(name: 'orcid') - + unless scheme.nil? User.all.each do |u| if u.respond_to?(:orcid_id) - if u.orcid_id.present? + if u.orcid_id.present? if u.orcid_id.gsub('orcid.org/', '').match(/^[\d-]+/) - u.user_identifiers << UserIdentifier.new(identifier_scheme: scheme, + u.user_identifiers << UserIdentifier.new(identifier_scheme: scheme, identifier: u.orcid_id.gsub('orcid.org/', '')) u.save! end @@ -253,5 +253,16 @@ namespace :migrate do end end end - + + desc "remove duplicate annotations caused by bug" + task remove_duplicate_annotations: :environment do + questions = Question.joins(:annotations).group("questions.id").having("count(annotations.id) > count(DISTINCT annotations.text)") + questions.each do |q| + q.annotations.each do |a| + conflicts = Annotation.where(question_id: a.question_id, text: a.text).where.not(id: a.id) + conflicts.each {|c| matches += 1 } + end + end + end + end