From 5347ef0fad794de4918cfbb4282ab4da190682c2 Mon Sep 17 00:00:00 2001 From: Brian Palmer Date: Wed, 13 Mar 2013 10:24:24 -0600 Subject: [PATCH] remove the has_custom_fields plugin from vendor/ This was written 2 years ago and never used, I've verified the DB tables are empty. Change-Id: I405e009be2eb657c4ebfb63da21dbcfee92efc0d Reviewed-on: https://gerrit.instructure.com/18564 Tested-by: Jenkins Reviewed-by: Cody Cutrer QA-Review: Brian Palmer --- app/models/account.rb | 2 - app/models/assignment.rb | 6 +- ...20130313162706_drop_custom_field_tables.rb | 12 ++ lib/api/v1/assignment.rb | 1 - spec/apis/v1/assignments_api_spec.rb | 26 ---- vendor/plugins/has_custom_fields/README.md | 29 ----- .../app/helpers/has_custom_fields_helper.rb | 34 ----- .../app/models/custom_field.rb | 31 ----- .../app/models/custom_field_value.rb | 30 ----- .../20101206150923_install_custom_fields.rb | 52 -------- vendor/plugins/has_custom_fields/init.rb | 21 ---- vendor/plugins/has_custom_fields/install.rb | 24 ---- .../lib/has_custom_fields.rb | 117 ------------------ 13 files changed, 14 insertions(+), 371 deletions(-) create mode 100644 db/migrate/20130313162706_drop_custom_field_tables.rb delete mode 100644 vendor/plugins/has_custom_fields/README.md delete mode 100644 vendor/plugins/has_custom_fields/app/helpers/has_custom_fields_helper.rb delete mode 100644 vendor/plugins/has_custom_fields/app/models/custom_field.rb delete mode 100644 vendor/plugins/has_custom_fields/app/models/custom_field_value.rb delete mode 100644 vendor/plugins/has_custom_fields/db/migrate/20101206150923_install_custom_fields.rb delete mode 100644 vendor/plugins/has_custom_fields/init.rb delete mode 100644 vendor/plugins/has_custom_fields/install.rb delete mode 100644 vendor/plugins/has_custom_fields/lib/has_custom_fields.rb diff --git a/app/models/account.rb b/app/models/account.rb index 6deccbebc95..b77f0bb0993 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -96,8 +96,6 @@ class Account < ActiveRecord::Base serialize :settings, Hash - scopes_custom_fields - validates_locale :default_locale, :allow_nil => true validate :account_chain_loop, :if => :parent_account_id_changed? validate :validate_auth_discovery_url diff --git a/app/models/assignment.rb b/app/models/assignment.rb index 060fa61e69c..18cd690ab23 100644 --- a/app/models/assignment.rb +++ b/app/models/assignment.rb @@ -33,8 +33,8 @@ class Assignment < ActiveRecord::Base :peer_review_count, :peer_reviews_due_at, :peer_reviews_assign_at, :grading_standard_id, :peer_reviews, :automatic_peer_reviews, :grade_group_students_individually, :notify_of_update, :time_zone_edited, :turnitin_enabled, :turnitin_settings, - :set_custom_field_values, :context, :position, :allowed_extensions, - :external_tool_tag_attributes, :freeze_on_copy, :assignment_group_id + :context, :position, :allowed_extensions, :external_tool_tag_attributes, + :freeze_on_copy, :assignment_group_id attr_accessor :original_id, :updating_user, :copying @@ -124,8 +124,6 @@ class Assignment < ActiveRecord::Base sanitize_field :description, Instructure::SanitizeField::SANITIZE copy_authorized_links( :description) { [self.context, nil] } - has_custom_fields :scopes => %w(root_account) - def root_account context && context.root_account end diff --git a/db/migrate/20130313162706_drop_custom_field_tables.rb b/db/migrate/20130313162706_drop_custom_field_tables.rb new file mode 100644 index 00000000000..ac1f59f2a7a --- /dev/null +++ b/db/migrate/20130313162706_drop_custom_field_tables.rb @@ -0,0 +1,12 @@ +class DropCustomFieldTables < ActiveRecord::Migration + tag :postdeploy + + def self.up + # these tables may not have ever been created + drop_table "custom_fields" if table_exists?("custom_fields") + drop_table "custom_field_values" if table_exists?("custom_field_values") + end + + def self.down + end +end diff --git a/lib/api/v1/assignment.rb b/lib/api/v1/assignment.rb index 6740ad5c85b..eda6a252144 100644 --- a/lib/api/v1/assignment.rb +++ b/lib/api/v1/assignment.rb @@ -176,7 +176,6 @@ module Api::V1::Assignment automatic_peer_reviews external_tool_tag_attributes grade_group_students_individually - set_custom_field_values turnitin_enabled turnitin_settings grading_standard_id diff --git a/spec/apis/v1/assignments_api_spec.rb b/spec/apis/v1/assignments_api_spec.rb index 7ef7f610241..cc4a8da2853 100644 --- a/spec/apis/v1/assignments_api_spec.rb +++ b/spec/apis/v1/assignments_api_spec.rb @@ -145,11 +145,6 @@ describe AssignmentsApiController, :type => :integration do @group_category = @course.group_categories.create! @course.any_instantiation.expects(:turnitin_enabled?). at_least_once.returns true - # make sure we can assign a custom field during creation - CustomField.create!(:name => 'test_custom', - :field_type => 'boolean', - :default_value => false, - :target_type => 'assignments') @json = api_create_assignment_in_course(@course, { 'name' => 'some assignment', 'position' => '1', @@ -174,11 +169,6 @@ describe AssignmentsApiController, :type => :integration do 'group_category_id' => @group_category.id, 'turnitin_enabled' => true, 'grading_type' => 'points', - 'set_custom_field_values' => { - 'test_custom' => { - 'value' => '1' - } - }, 'muted' => 'true' } ) @@ -221,8 +211,6 @@ describe AssignmentsApiController, :type => :integration do @json['needs_grading_count'].should == 0 Assignment.count.should == 1 - a = Assignment.first - a.get_custom_field_value('test_custom').true?.should == true end it "does not allow modifying turnitin_enabled when not enabled on the context" do @@ -351,20 +339,10 @@ describe AssignmentsApiController, :type => :integration do @new_grading_standard = grading_standard_for(@course) - # make sure we can assign a custom field during update - CustomField.create!(:name => 'test_custom', - :field_type => 'boolean', - :default_value => false, - :target_type => 'assignments') @json = api_update_assignment_call(@course,@assignment,{ 'name' => 'some assignment', 'points_possible' => '12', 'assignment_group_id' => @group.id, - 'set_custom_field_values' => { - 'test_custom' => { - 'value' => '1' - } - }, 'peer_reviews' => false, 'grading_standard_id' => @new_grading_standard.id, 'group_category_id' => nil, @@ -454,10 +432,6 @@ describe AssignmentsApiController, :type => :integration do @json.has_key?( 'peer_reviews_assign_at' ).should == false end - it "updates custom fields" do - @assignment.get_custom_field_value('test_custom').true?.should == true - end - it "updates the grading standard" do @assignment.grading_standard_id.should == @new_grading_standard.id @json['grading_standard_id'].should == @new_grading_standard.id diff --git a/vendor/plugins/has_custom_fields/README.md b/vendor/plugins/has_custom_fields/README.md deleted file mode 100644 index f12271297d5..00000000000 --- a/vendor/plugins/has_custom_fields/README.md +++ /dev/null @@ -1,29 +0,0 @@ -# has\_custom\_fields - -Allows adding custom fields to any ActiveRecord model, without modifying that -class' database table. You can also scope the fields in a pretty flexible -manner, for instance if you only want to add a field to User instances in a -specific Account instance. - -This plugin is intended to be a separate project from Canvas, but it's not -mature enough at this point for an independent release. So for now it lives in -the Canvas repo. - -# License - -Copyright (C) 2011 Instructure, Inc. - -This plugin is part of Canvas. - -Canvas is free software: you can redistribute it and/or modify it under -the terms of the GNU Affero General Public License as published by the Free -Software Foundation, version 3 of the License. - -Canvas is distributed in the hope that it will be useful, but WITHOUT ANY -WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR -A PARTICULAR PURPOSE. See the GNU Affero General Public License for more -details. - -You should have received a copy of the GNU Affero General Public License along -with this program. If not, see . - diff --git a/vendor/plugins/has_custom_fields/app/helpers/has_custom_fields_helper.rb b/vendor/plugins/has_custom_fields/app/helpers/has_custom_fields_helper.rb deleted file mode 100644 index a49eb37c60c..00000000000 --- a/vendor/plugins/has_custom_fields/app/helpers/has_custom_fields_helper.rb +++ /dev/null @@ -1,34 +0,0 @@ -# -# Copyright (C) 2011 Instructure, Inc. -# -# This file is part of Canvas. -# -# Canvas is free software: you can redistribute it and/or modify it under -# the terms of the GNU Affero General Public License as published by the Free -# Software Foundation, version 3 of the License. -# -# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR -# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more -# details. -# -# You should have received a copy of the GNU Affero General Public License along -# with this program. If not, see . -# - -module HasCustomFieldsHelper - # Note we're not using this yet -- Canvas only sets custom fields via the API - # so far. - def custom_field_form_element(custom_field, form, opts = {}) - cfv = form.object.get_custom_field_value(custom_field) - # Need to figure out how to make this play nice with form.fields_for, it'd - # be a lot less crufty. - case custom_field.field_type - when 'boolean' - hidden_field_tag("#{form.object_name}[set_custom_field_values][#{custom_field.id}][value]", "0") + - check_box_tag("#{form.object_name}[set_custom_field_values][#{custom_field.id}][value]", "1", cfv.true?) - else - raise "Whoops, need to implement this" - end - end -end diff --git a/vendor/plugins/has_custom_fields/app/models/custom_field.rb b/vendor/plugins/has_custom_fields/app/models/custom_field.rb deleted file mode 100644 index 77b66f3f3c6..00000000000 --- a/vendor/plugins/has_custom_fields/app/models/custom_field.rb +++ /dev/null @@ -1,31 +0,0 @@ -# -# Copyright (C) 2011 Instructure, Inc. -# -# This file is part of Canvas. -# -# Canvas is free software: you can redistribute it and/or modify it under -# the terms of the GNU Affero General Public License as published by the Free -# Software Foundation, version 3 of the License. -# -# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR -# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more -# details. -# -# You should have received a copy of the GNU Affero General Public License along -# with this program. If not, see . -# - -class CustomField < ActiveRecord::Base - has_many :custom_field_values, :dependent => :destroy - - validates_inclusion_of :field_type, :in => %w(boolean) - - validates_uniqueness_of :name, :scope => %w(scoper_type scoper_id target_type) - - belongs_to :scoper, :polymorphic => true - - named_scope :for_class, lambda { |klass| - { :conditions => { :target_type => klass.name.underscore.pluralize } } - } -end diff --git a/vendor/plugins/has_custom_fields/app/models/custom_field_value.rb b/vendor/plugins/has_custom_fields/app/models/custom_field_value.rb deleted file mode 100644 index bbdf7688530..00000000000 --- a/vendor/plugins/has_custom_fields/app/models/custom_field_value.rb +++ /dev/null @@ -1,30 +0,0 @@ -# -# Copyright (C) 2011 Instructure, Inc. -# -# This file is part of Canvas. -# -# Canvas is free software: you can redistribute it and/or modify it under -# the terms of the GNU Affero General Public License as published by the Free -# Software Foundation, version 3 of the License. -# -# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR -# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more -# details. -# -# You should have received a copy of the GNU Affero General Public License along -# with this program. If not, see . -# - -class CustomFieldValue < ActiveRecord::Base - belongs_to :custom_field - belongs_to :customized, :polymorphic => true - - def after_initialize - self.value ||= custom_field.default_value - end - - def true? - value == "1" - end -end diff --git a/vendor/plugins/has_custom_fields/db/migrate/20101206150923_install_custom_fields.rb b/vendor/plugins/has_custom_fields/db/migrate/20101206150923_install_custom_fields.rb deleted file mode 100644 index 2ffc58152ee..00000000000 --- a/vendor/plugins/has_custom_fields/db/migrate/20101206150923_install_custom_fields.rb +++ /dev/null @@ -1,52 +0,0 @@ -# -# Copyright (C) 2011 Instructure, Inc. -# -# This file is part of Canvas. -# -# Canvas is free software: you can redistribute it and/or modify it under -# the terms of the GNU Affero General Public License as published by the Free -# Software Foundation, version 3 of the License. -# -# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR -# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more -# details. -# -# You should have received a copy of the GNU Affero General Public License along -# with this program. If not, see . -# - -class InstallCustomFields < ActiveRecord::Migration - def self.up - create_table :custom_fields, :force => true do |t| - t.string :name - t.string :description - - t.string :field_type - t.string :default_value - - t.string :scoper_type - t.integer :scoper_id, :limit => 8 - - t.string :target_type - - t.timestamps - end - add_index :custom_fields, %w(scoper_type scoper_id target_type name), :name => "custom_field_lookup" - - create_table :custom_field_values, :force => true do |t| - t.integer :custom_field_id, :limit => 8 - t.string :value - - t.string :customized_type - t.integer :customized_id, :limit => 8 - - t.timestamps - end - end - - def self.down - drop_table :custom_field_values - drop_table :custom_fields - end -end diff --git a/vendor/plugins/has_custom_fields/init.rb b/vendor/plugins/has_custom_fields/init.rb deleted file mode 100644 index b294f70cc94..00000000000 --- a/vendor/plugins/has_custom_fields/init.rb +++ /dev/null @@ -1,21 +0,0 @@ -# -# Copyright (C) 2011 Instructure, Inc. -# -# This file is part of Canvas. -# -# Canvas is free software: you can redistribute it and/or modify it under -# the terms of the GNU Affero General Public License as published by the Free -# Software Foundation, version 3 of the License. -# -# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR -# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more -# details. -# -# You should have received a copy of the GNU Affero General Public License along -# with this program. If not, see . -# - -if defined?(ActiveRecord::Base) - ActiveRecord::Base.send(:extend, HasCustomFields::ClassMethods) -end diff --git a/vendor/plugins/has_custom_fields/install.rb b/vendor/plugins/has_custom_fields/install.rb deleted file mode 100644 index f978e2de185..00000000000 --- a/vendor/plugins/has_custom_fields/install.rb +++ /dev/null @@ -1,24 +0,0 @@ -# -# Copyright (C) 2011 Instructure, Inc. -# -# This file is part of Canvas. -# -# Canvas is free software: you can redistribute it and/or modify it under -# the terms of the GNU Affero General Public License as published by the Free -# Software Foundation, version 3 of the License. -# -# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR -# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more -# details. -# -# You should have received a copy of the GNU Affero General Public License along -# with this program. If not, see . -# - -require 'fileutils' - -migration_dir = Rails.root.join('db', 'migrate') -FileUtils.cp( - File.dirname(__FILE__)+'/db/migrate/20101206150923_install_custom_fields.rb', - migration_dir+'20101206150923_install_custom_fields.rb') diff --git a/vendor/plugins/has_custom_fields/lib/has_custom_fields.rb b/vendor/plugins/has_custom_fields/lib/has_custom_fields.rb deleted file mode 100644 index 1badb56fcb6..00000000000 --- a/vendor/plugins/has_custom_fields/lib/has_custom_fields.rb +++ /dev/null @@ -1,117 +0,0 @@ -# -# Copyright (C) 2011 Instructure, Inc. -# -# This file is part of Canvas. -# -# Canvas is free software: you can redistribute it and/or modify it under -# the terms of the GNU Affero General Public License as published by the Free -# Software Foundation, version 3 of the License. -# -# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY -# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR -# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more -# details. -# -# You should have received a copy of the GNU Affero General Public License along -# with this program. If not, see . -# - -module HasCustomFields - module ClassMethods - # Define this model as having custom fields. This mixes in - # HasCustomFields::InstanceMethods. For example, this will scope custom - # fields both globally, and to the user's account: - # - # class User < ActiveRecord::Base - # belongs_to :account - # has_custom_fields :scopes => [:account] - # end - # - # class Account < ActiveRecord::Base - # scopes_custom_fields - # end - # - # Options: - # * :scopes - An array of scopes to check for custom fields, beyond the - # global custom fields. - def has_custom_fields(opts = {}) - class_inheritable_accessor :custom_fields_options - opts[:scopes] = Array(opts[:scopes]) - self.custom_fields_options = opts - - has_many :custom_field_values, - :as => :customized, - :include => :custom_field, - :dependent => :destroy, - :autosave => true - self.send :include, HasCustomFields::InstanceMethods - end - - # Define this model as scoping custom fields for other models. See - # has_custom_fields - def scopes_custom_fields - has_many :custom_fields, - :as => :scoper, - :dependent => :destroy - end - end - - # The methods available on an instance of a class that has_custom_fields - module InstanceMethods - # The available custom fields for this instance. Note this is per-instance, - # because custom fields can be scoped to associations. So not all instances - # of the same model will have the same custom fields available. - def available_custom_fields - # This is basically equivalent to, but does everything in one query: - # # global custom fields for this type - # fields = CustomField.scoped(:conditions => { :scoper_id => nil }).for_class(self.class) - # # scoped custom fields for this type - # fields + - # self.class.custom_fields_options[:scopes].inject([]) do |a, scope| - # a + self.send(scope).custom_fields.for_class(self.class) - # end - conditions = ["scoper_id IS NULL"] - self.class.custom_fields_options[:scopes].each do |scope| - obj = self.send(scope) - next unless obj - conditions << "(scoper_type = '#{obj.class.base_class.name}' AND scoper_id = '#{obj.id}')" - end - CustomField.for_class(self.class).scoped(:conditions => conditions.join(" OR ")) - end - - # vals is a hash { custom_field_id => new_val } - # Note custom fields can't reliably be set in the creation hash, because of - # race conditions. For instance, if a User custom field is scoped to a - # certain Account, User.create(:account_id => 1, :set_custom_field_values => - # { ... }) might try to set the custom fields before the account id, and the - # field would appear to be unavailable. - def set_custom_field_values=(vals) - custom_fields = available_custom_fields.to_a - vals.each do |field_id, params| - custom_field = custom_fields.find { |f| f.id == field_id.to_i || f.name == field_id } - next unless custom_field - cfv = get_custom_field_value(custom_field) - cfv.value = params['value'] - end - end - - # Returns the CustomFieldValue for the name [String] or field [CustomField] - # passed in. Creates (but doesn't save) the value if necessary. - def get_custom_field_value(name_or_field) - return nil unless name_or_field - - custom_field = case name_or_field - when String - available_custom_fields.find_by_name(name_or_field) - when CustomField - name_or_field - else - raise ArgumentError - end - return nil unless custom_field - - custom_field_values.find_by_custom_field_id(custom_field.id) || - custom_field_values.build(:custom_field => custom_field) - end - end -end