From 5df87e3e45c69bd0a8a3b757c1deeb7f2ad868bf Mon Sep 17 00:00:00 2001 From: Martin Fenner Date: Wed, 24 Oct 2018 02:09:30 +0200 Subject: [PATCH] organization_type and focus area for providers. datacite/datacite#548 --- app/controllers/providers_controller.rb | 4 ++-- app/serializers/member_serializer.rb | 2 +- app/serializers/provider_serializer.rb | 2 +- db/migrate/20181023235649_add_focus_area.rb | 17 +++++++++++++++++ db/schema.rb | 5 ++++- 5 files changed, 25 insertions(+), 5 deletions(-) create mode 100644 db/migrate/20181023235649_add_focus_area.rb diff --git a/app/controllers/providers_controller.rb b/app/controllers/providers_controller.rb index f900292c1..6f949c2a8 100644 --- a/app/controllers/providers_controller.rb +++ b/app/controllers/providers_controller.rb @@ -153,8 +153,8 @@ def set_provider def safe_params fail JSON::ParserError, "You need to provide a payload following the JSONAPI spec" unless params[:data].present? ActiveModelSerializers::Deserialization.jsonapi_parse!( - params, only: [:name, :symbol, :description, :website, :joined, "institution-type", :phone, "contact-name", "contact-email", "is_active", "password-input", :country], - keys: { "institution-type" => :institution_type, "contact-name" => :contact_name, "contact-email" => :contact_email, :country => :country_code, "is-active" => :is_active, "password-input" => :password_input } + params, only: [:name, :symbol, :description, :website, :joined, "organization-type", "focus-area", :phone, "contact-name", "contact-email", "is_active", "password-input", :country], + keys: { "organization-type" => :organization_type, "focus-area" => :focus_area, "contact-name" => :contact_name, "contact-email" => :contact_email, :country => :country_code, "is-active" => :is_active, "password-input" => :password_input } ) end end diff --git a/app/serializers/member_serializer.rb b/app/serializers/member_serializer.rb index 16abc5141..c83efaa48 100644 --- a/app/serializers/member_serializer.rb +++ b/app/serializers/member_serializer.rb @@ -5,7 +5,7 @@ class MemberSerializer set_id :uid # don't cache members, as they use the provider model - attributes :title, :description, :member_type, :institution_type, :region, :country, :year, :logo_url, :email, :website, :phone, :joined, :created, :updated + attributes :title, :description, :member_type, :organization_type, :focus_area, :region, :country, :year, :logo_url, :email, :website, :phone, :joined, :created, :updated attribute :title do |object| object.name diff --git a/app/serializers/provider_serializer.rb b/app/serializers/provider_serializer.rb index 7828e9b97..3d8490242 100644 --- a/app/serializers/provider_serializer.rb +++ b/app/serializers/provider_serializer.rb @@ -4,7 +4,7 @@ class ProviderSerializer set_type :providers set_id :uid - attributes :name, :symbol, :website, :contact_name, :contact_email, :phone, :description, :region, :country, :logo_url, :institution_type, :is_active, :has_password, :joined, :created, :updated + attributes :name, :symbol, :website, :contact_name, :contact_email, :phone, :description, :region, :country, :logo_url, :organization_type, :focus_area, :is_active, :has_password, :joined, :created, :updated has_many :prefixes, record_type: :prefixes diff --git a/db/migrate/20181023235649_add_focus_area.rb b/db/migrate/20181023235649_add_focus_area.rb new file mode 100644 index 000000000..40d995029 --- /dev/null +++ b/db/migrate/20181023235649_add_focus_area.rb @@ -0,0 +1,17 @@ +class AddFocusArea < ActiveRecord::Migration[5.2] + def up + #remove_column :allocator, :institution_type, :string, limit: 191 + + add_column :allocator, :focus_area, :string, limit: 191 + add_column :allocator, :organization_type, :string, limit: 191 + add_index :allocator, [:organization_type], name: "index_allocator_organization_type" + end + + def down + add_column :allocator, :institution_type, :string, limit: 191 + add_index :allocator, [:institution_type], name: "index_member_institution_type" + + remove_column :allocator, :focus_area, :string, limit: 191 + remove_column :allocator, :organization_type, :string, limit: 191 + end +end diff --git a/db/schema.rb b/db/schema.rb index 0fc9b8125..616f0764c 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2018_10_19_133039) do +ActiveRecord::Schema.define(version: 2018_10_23_235649) do create_table "active_storage_attachments", options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t| t.string "name", limit: 191, null: false @@ -57,7 +57,10 @@ t.date "joined" t.string "institution_type", limit: 191 t.string "logo" + t.string "focus_area", limit: 191 + t.string "organization_type", limit: 191 t.index ["institution_type"], name: "index_member_institution_type" + t.index ["organization_type"], name: "index_allocator_organization_type" t.index ["symbol"], name: "symbol", unique: true end