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 <jenkins@instructure.com> Reviewed-by: Cody Cutrer <cody@instructure.com> QA-Review: Brian Palmer <brianp@instructure.com>
This commit is contained in:
parent
85b4a76ed1
commit
5347ef0fad
|
@ -96,8 +96,6 @@ class Account < ActiveRecord::Base
|
||||||
|
|
||||||
serialize :settings, Hash
|
serialize :settings, Hash
|
||||||
|
|
||||||
scopes_custom_fields
|
|
||||||
|
|
||||||
validates_locale :default_locale, :allow_nil => true
|
validates_locale :default_locale, :allow_nil => true
|
||||||
validate :account_chain_loop, :if => :parent_account_id_changed?
|
validate :account_chain_loop, :if => :parent_account_id_changed?
|
||||||
validate :validate_auth_discovery_url
|
validate :validate_auth_discovery_url
|
||||||
|
|
|
@ -33,8 +33,8 @@ class Assignment < ActiveRecord::Base
|
||||||
:peer_review_count, :peer_reviews_due_at, :peer_reviews_assign_at, :grading_standard_id,
|
:peer_review_count, :peer_reviews_due_at, :peer_reviews_assign_at, :grading_standard_id,
|
||||||
:peer_reviews, :automatic_peer_reviews, :grade_group_students_individually,
|
:peer_reviews, :automatic_peer_reviews, :grade_group_students_individually,
|
||||||
:notify_of_update, :time_zone_edited, :turnitin_enabled, :turnitin_settings,
|
:notify_of_update, :time_zone_edited, :turnitin_enabled, :turnitin_settings,
|
||||||
:set_custom_field_values, :context, :position, :allowed_extensions,
|
:context, :position, :allowed_extensions, :external_tool_tag_attributes,
|
||||||
:external_tool_tag_attributes, :freeze_on_copy, :assignment_group_id
|
:freeze_on_copy, :assignment_group_id
|
||||||
|
|
||||||
attr_accessor :original_id, :updating_user, :copying
|
attr_accessor :original_id, :updating_user, :copying
|
||||||
|
|
||||||
|
@ -124,8 +124,6 @@ class Assignment < ActiveRecord::Base
|
||||||
sanitize_field :description, Instructure::SanitizeField::SANITIZE
|
sanitize_field :description, Instructure::SanitizeField::SANITIZE
|
||||||
copy_authorized_links( :description) { [self.context, nil] }
|
copy_authorized_links( :description) { [self.context, nil] }
|
||||||
|
|
||||||
has_custom_fields :scopes => %w(root_account)
|
|
||||||
|
|
||||||
def root_account
|
def root_account
|
||||||
context && context.root_account
|
context && context.root_account
|
||||||
end
|
end
|
||||||
|
|
|
@ -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
|
|
@ -176,7 +176,6 @@ module Api::V1::Assignment
|
||||||
automatic_peer_reviews
|
automatic_peer_reviews
|
||||||
external_tool_tag_attributes
|
external_tool_tag_attributes
|
||||||
grade_group_students_individually
|
grade_group_students_individually
|
||||||
set_custom_field_values
|
|
||||||
turnitin_enabled
|
turnitin_enabled
|
||||||
turnitin_settings
|
turnitin_settings
|
||||||
grading_standard_id
|
grading_standard_id
|
||||||
|
|
|
@ -145,11 +145,6 @@ describe AssignmentsApiController, :type => :integration do
|
||||||
@group_category = @course.group_categories.create!
|
@group_category = @course.group_categories.create!
|
||||||
@course.any_instantiation.expects(:turnitin_enabled?).
|
@course.any_instantiation.expects(:turnitin_enabled?).
|
||||||
at_least_once.returns true
|
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,
|
@json = api_create_assignment_in_course(@course,
|
||||||
{ 'name' => 'some assignment',
|
{ 'name' => 'some assignment',
|
||||||
'position' => '1',
|
'position' => '1',
|
||||||
|
@ -174,11 +169,6 @@ describe AssignmentsApiController, :type => :integration do
|
||||||
'group_category_id' => @group_category.id,
|
'group_category_id' => @group_category.id,
|
||||||
'turnitin_enabled' => true,
|
'turnitin_enabled' => true,
|
||||||
'grading_type' => 'points',
|
'grading_type' => 'points',
|
||||||
'set_custom_field_values' => {
|
|
||||||
'test_custom' => {
|
|
||||||
'value' => '1'
|
|
||||||
}
|
|
||||||
},
|
|
||||||
'muted' => 'true'
|
'muted' => 'true'
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
@ -221,8 +211,6 @@ describe AssignmentsApiController, :type => :integration do
|
||||||
@json['needs_grading_count'].should == 0
|
@json['needs_grading_count'].should == 0
|
||||||
|
|
||||||
Assignment.count.should == 1
|
Assignment.count.should == 1
|
||||||
a = Assignment.first
|
|
||||||
a.get_custom_field_value('test_custom').true?.should == true
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "does not allow modifying turnitin_enabled when not enabled on the context" do
|
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)
|
@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,{
|
@json = api_update_assignment_call(@course,@assignment,{
|
||||||
'name' => 'some assignment',
|
'name' => 'some assignment',
|
||||||
'points_possible' => '12',
|
'points_possible' => '12',
|
||||||
'assignment_group_id' => @group.id,
|
'assignment_group_id' => @group.id,
|
||||||
'set_custom_field_values' => {
|
|
||||||
'test_custom' => {
|
|
||||||
'value' => '1'
|
|
||||||
}
|
|
||||||
},
|
|
||||||
'peer_reviews' => false,
|
'peer_reviews' => false,
|
||||||
'grading_standard_id' => @new_grading_standard.id,
|
'grading_standard_id' => @new_grading_standard.id,
|
||||||
'group_category_id' => nil,
|
'group_category_id' => nil,
|
||||||
|
@ -454,10 +432,6 @@ describe AssignmentsApiController, :type => :integration do
|
||||||
@json.has_key?( 'peer_reviews_assign_at' ).should == false
|
@json.has_key?( 'peer_reviews_assign_at' ).should == false
|
||||||
end
|
end
|
||||||
|
|
||||||
it "updates custom fields" do
|
|
||||||
@assignment.get_custom_field_value('test_custom').true?.should == true
|
|
||||||
end
|
|
||||||
|
|
||||||
it "updates the grading standard" do
|
it "updates the grading standard" do
|
||||||
@assignment.grading_standard_id.should == @new_grading_standard.id
|
@assignment.grading_standard_id.should == @new_grading_standard.id
|
||||||
@json['grading_standard_id'].should == @new_grading_standard.id
|
@json['grading_standard_id'].should == @new_grading_standard.id
|
||||||
|
|
|
@ -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 <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
|
@ -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 <http://www.gnu.org/licenses/>.
|
|
||||||
#
|
|
||||||
|
|
||||||
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
|
|
|
@ -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 <http://www.gnu.org/licenses/>.
|
|
||||||
#
|
|
||||||
|
|
||||||
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
|
|
|
@ -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 <http://www.gnu.org/licenses/>.
|
|
||||||
#
|
|
||||||
|
|
||||||
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
|
|
|
@ -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 <http://www.gnu.org/licenses/>.
|
|
||||||
#
|
|
||||||
|
|
||||||
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
|
|
|
@ -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 <http://www.gnu.org/licenses/>.
|
|
||||||
#
|
|
||||||
|
|
||||||
if defined?(ActiveRecord::Base)
|
|
||||||
ActiveRecord::Base.send(:extend, HasCustomFields::ClassMethods)
|
|
||||||
end
|
|
|
@ -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 <http://www.gnu.org/licenses/>.
|
|
||||||
#
|
|
||||||
|
|
||||||
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')
|
|
|
@ -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 <http://www.gnu.org/licenses/>.
|
|
||||||
#
|
|
||||||
|
|
||||||
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
|
|
Loading…
Reference in New Issue