Skip to content

Commit

Permalink
support for globus_uuid, including uuid validation. #936
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Jan 22, 2020
1 parent 8269a00 commit eeb811c
Show file tree
Hide file tree
Showing 17 changed files with 144 additions and 34 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ gem "graphql-cache", "~> 0.6.0", git: "https://github.com/stackshareio/graphql-c
gem "apollo-federation", "~> 0.5.1"
gem "google-protobuf", "3.10.0.rc.1"
gem "sprockets", "~> 3.7", ">= 3.7.2"
gem 'uuid', '~> 2.3', '>= 2.3.9'

group :development, :test do
gem "rspec-rails", "~> 3.8", ">= 3.8.2"
Expand Down
30 changes: 18 additions & 12 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ GEM
audited (4.9.0)
activerecord (>= 4.2, < 6.1)
aws-eventstream (1.0.3)
aws-partitions (1.263.0)
aws-sdk-core (3.88.0)
aws-partitions (1.267.0)
aws-sdk-core (3.89.1)
aws-eventstream (~> 1.0, >= 1.0.2)
aws-partitions (~> 1, >= 1.239.0)
aws-sigv4 (~> 1.1)
jmespath (~> 1.0)
aws-sdk-kms (1.27.0)
aws-sdk-kms (1.28.0)
aws-sdk-core (~> 3, >= 3.71.0)
aws-sigv4 (~> 1.1)
aws-sdk-s3 (1.60.1)
Expand Down Expand Up @@ -137,7 +137,7 @@ GEM
bootsnap (1.4.5)
msgpack (~> 1.0)
builder (3.2.4)
byebug (11.0.1)
byebug (11.1.0)
cancancan (2.3.0)
capybara (3.30.0)
addressable
Expand All @@ -151,7 +151,7 @@ GEM
activesupport
citeproc (1.0.10)
namae (~> 1.0)
citeproc-ruby (1.1.10)
citeproc-ruby (1.1.12)
citeproc (~> 1.0, >= 1.0.9)
csl (~> 1.5)
coderay (1.1.2)
Expand All @@ -169,7 +169,7 @@ GEM
sort_alphabetical (~> 1.0)
crack (0.4.3)
safe_yaml (~> 1.0.0)
crass (1.0.5)
crass (1.0.6)
csl (1.5.1)
namae (~> 1.0)
csl-styles (1.0.1.10)
Expand Down Expand Up @@ -230,7 +230,7 @@ GEM
faraday (>= 0.15)
fast_jsonapi (1.5)
activesupport (>= 4.2)
ffi (1.11.3)
ffi (1.12.1)
flipper (0.17.2)
flipper-active_support_cache_store (0.17.2)
activesupport (>= 4.2, < 7)
Expand All @@ -241,7 +241,7 @@ GEM
globalid (0.4.2)
activesupport (>= 4.2.0)
google-protobuf (3.10.0.rc.1)
graphql (1.9.17)
graphql (1.10.0)
graphql-batch (0.4.2)
graphql (>= 1.3, < 2)
promise.rb (~> 0.7.2)
Expand All @@ -257,7 +257,7 @@ GEM
htmlentities (4.3.4)
http-cookie (1.0.3)
domain_name (~> 0.5)
i18n (1.8.1)
i18n (1.8.2)
concurrent-ruby (~> 1.0)
i18n_data (0.8.0)
iso8601 (0.9.1)
Expand Down Expand Up @@ -309,6 +309,8 @@ GEM
loofah (2.4.0)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
macaddr (1.7.2)
systemu (~> 2.6.5)
mail (2.7.1)
mini_mime (>= 0.1.1)
mailgun-ruby (1.2.0)
Expand Down Expand Up @@ -346,7 +348,7 @@ GEM
nio4r (2.5.2)
nokogiri (1.10.7)
mini_portile2 (~> 2.4.0)
oj (3.10.0)
oj (3.10.1)
oj_mimic_json (1.0.1)
optimist (3.0.0)
pandoc-ruby (2.0.2)
Expand Down Expand Up @@ -512,6 +514,7 @@ GEM
sxp (1.1.0)
rdf (~> 3.1)
sysrandom (1.0.5)
systemu (2.6.5)
temple (0.8.2)
test-prof (0.10.2)
thor (0.20.3)
Expand All @@ -527,10 +530,12 @@ GEM
unf (0.1.4)
unf_ext
unf_ext (0.0.7.6)
unicode-display_width (1.6.0)
unicode-display_width (1.6.1)
unicode_utils (1.4.0)
uuid (2.3.9)
macaddr (~> 1.0)
vcr (3.0.3)
webmock (3.7.6)
webmock (3.8.0)
addressable (>= 2.3.6)
crack (>= 0.3.2)
hashdiff (>= 0.4.0, < 2.0.0)
Expand Down Expand Up @@ -629,6 +634,7 @@ DEPENDENCIES
strip_attributes (~> 1.8)
test-prof (~> 0.10.2)
turnout (~> 2.5)
uuid (~> 2.3, >= 2.3.9)
vcr (~> 3.0.3)
webmock (~> 3.1)

Expand Down
4 changes: 2 additions & 2 deletions app/controllers/clients_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ def set_client
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: [:symbol, :name, "systemEmail", "contactEmail", :domains, :provider, :url, "repositoryType", { "repositoryType" => [] }, :description, :language, { language: [] }, "alternateName", :software, "targetId", "isActive", "passwordInput", "clientType", :re3data, :opendoar, :issn, { issn: [:issnl, :electronic, :print] }, :certificate, { certificate: [] }, "serviceContact", { "serviceContact": [:email, "givenName", "familyName"] }, "salesforceId"],
keys: { "systemEmail" => :system_email, "contactEmail" => :system_email, "salesforceId" => :salesforce_id, "targetId" => :target_id, "isActive" => :is_active, "passwordInput" => :password_input, "clientType" => :client_type, "alternateName" => :alternate_name, "repositoryType" => :repository_type, "serviceContact" => :service_contact }
params, only: [:symbol, :name, "systemEmail", "contactEmail", "globusUuid", :domains, :provider, :url, "repositoryType", { "repositoryType" => [] }, :description, :language, { language: [] }, "alternateName", :software, "targetId", "isActive", "passwordInput", "clientType", :re3data, :opendoar, :issn, { issn: [:issnl, :electronic, :print] }, :certificate, { certificate: [] }, "serviceContact", { "serviceContact": [:email, "givenName", "familyName"] }, "salesforceId"],
keys: { "systemEmail" => :system_email, "contactEmail" => :system_email, "globusUuid" => :globus_uuid, "salesforceId" => :salesforce_id, "targetId" => :target_id, "isActive" => :is_active, "passwordInput" => :password_input, "clientType" => :client_type, "alternateName" => :alternate_name, "repositoryType" => :repository_type, "serviceContact" => :service_contact }
)
end
end
5 changes: 3 additions & 2 deletions app/controllers/providers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ def safe_params
ActiveModelSerializers::Deserialization.jsonapi_parse!(
params,
only: [
:name, "displayName", :symbol, :description, :website, :joined, "organizationType", "focusArea", :consortium, "systemEmail", "groupEmail", "isActive", "passwordInput", :country, "billingInformation", { "billingInformation": ["postCode", :state, :city, :address, :department, :organization, :country]}, "rorId", "twitterHandle","memberType", "nonProfitStatus", "salesforceId",
:name, "displayName", :symbol, :description, :website, :joined, "globusUuid", "organizationType", "focusArea", :consortium, "systemEmail", "groupEmail", "isActive", "passwordInput", :country, "billingInformation", { "billingInformation": ["postCode", :state, :city, :address, :department, :organization, :country]}, "rorId", "twitterHandle","memberType", "nonProfitStatus", "salesforceId",
"technicalContact", { "technicalContact": [:email, "givenName", "familyName"] },
"secondaryTechnicalContact", { "secondaryTechnicalContact": [:email, "givenName", "familyName"] },
"secondaryBillingContact", { "secondaryBillingContact": [:email, "givenName", "familyName"] },
Expand All @@ -325,7 +325,8 @@ def safe_params
"groupEmail" => :group_email,
"systemEmail" => :system_email,
"nonProfitStatus" => :non_profit_status,
"salesforceId" => :salesforce_id
"salesforceId" => :salesforce_id,
"globusUuid" => :globus_uuid
}
)
end
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/repositories_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,8 @@ def set_repository
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: [:symbol, :name, "systemEmail", :domains, :provider, :url, "repositoryType", { "repositoryType" => [] }, :description, :language, { language: [] }, "alternateName", :software, "targetId", "isActive", "passwordInput", "clientType", :re3data, :opendoar, :issn, { issn: [:issnl, :electronic, :print] }, :certificate, { certificate: [] }, "serviceContact", { "serviceContact": [:email, "givenName", "familyName"] }, "salesforceId"],
keys: { "systemEmail" => :system_email, "salesforceId" => :salesforce_id, "targetId" => :target_id, "isActive" => :is_active, "passwordInput" => :password_input, "clientType" => :client_type, "alternateName" => :alternate_name, "repositoryType" => :repository_type, "serviceContact" => :service_contact }
params, only: [:symbol, :name, "systemEmail", :domains, :provider, :url, "globusUuid", "repositoryType", { "repositoryType" => [] }, :description, :language, { language: [] }, "alternateName", :software, "targetId", "isActive", "passwordInput", "clientType", :re3data, :opendoar, :issn, { issn: [:issnl, :electronic, :print] }, :certificate, { certificate: [] }, "serviceContact", { "serviceContact": [:email, "givenName", "familyName"] }, "salesforceId"],
keys: { "systemEmail" => :system_email, "salesforceId" => :salesforce_id, "globusUuid" => :globus_uuid, "targetId" => :target_id, "isActive" => :is_active, "passwordInput" => :password_input, "clientType" => :client_type, "alternateName" => :alternate_name, "repositoryType" => :repository_type, "serviceContact" => :service_contact }
)
end
end
8 changes: 8 additions & 0 deletions app/models/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class Client < ActiveRecord::Base
validate :check_issn, if: :issn?
validate :check_certificate, if: :certificate?
validate :check_repository_type, if: :repository_type?
validate :uuid_format, if: :globus_uuid?
strip_attributes

belongs_to :provider, foreign_key: :allocator, touch: true
Expand Down Expand Up @@ -88,6 +89,7 @@ class Client < ActiveRecord::Base
indexes :re3data_id, type: :keyword
indexes :opendoar_id, type: :integer
indexes :salesforce_id, type: :keyword
indexes :globus_uuid, type: :keyword
indexes :issn, type: :object, properties: {
issnl: { type: :keyword },
electronic: { type: :keyword },
Expand Down Expand Up @@ -123,6 +125,7 @@ class Client < ActiveRecord::Base
id: { type: :keyword },
uid: { type: :keyword },
symbol: { type: :keyword },
globus_uuid: { type: :keyword },
client_ids: { type: :keyword },
prefix_ids: { type: :keyword },
name: { type: :text, fields: { keyword: { type: "keyword" }, raw: { type: "text", "analyzer": "string_lowercase", "fielddata": true }} },
Expand Down Expand Up @@ -211,6 +214,7 @@ def as_indexed_json(options={})
"re3data_id" => re3data_id,
"opendoar_id" => opendoar_id,
"salesforce_id" => salesforce_id,
"globus_uuid" => globus_uuid,
"issn" => issn,
"prefix_ids" => prefix_ids,
"name" => name,
Expand Down Expand Up @@ -424,6 +428,10 @@ def check_repository_type
end
end

def uuid_format
errors.add(:globus_uuid, "#{globus_uuid} is not a valid UUID") unless UUID.validate(globus_uuid)
end

def freeze_symbol
errors.add(:symbol, "cannot be changed") if symbol_changed?
end
Expand Down
7 changes: 7 additions & 0 deletions app/models/provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class Provider < ActiveRecord::Base
validates_inclusion_of :focus_area, :in => %w(naturalSciences engineeringAndTechnology medicalAndHealthSciences agriculturalSciences socialSciences humanities general), message: "focus area %s is not included in the list", if: :focus_area?
validate :freeze_symbol, :on => :update
validate :can_be_in_consortium
validate :uuid_format, if: :globus_uuid?
validates_format_of :ror_id, :with => /\Ahttps:\/\/ror\.org\/0\w{6}\d{2}\z/, if: :ror_id?, message: "ROR ID should be a url"
validates_format_of :twitter_handle, :with => /\A@[a-zA-Z0-9_]{1,15}\z/, if: :twitter_handle?

Expand Down Expand Up @@ -91,6 +92,7 @@ class Provider < ActiveRecord::Base
indexes :id, type: :keyword
indexes :uid, type: :keyword
indexes :symbol, type: :keyword
indexes :globus_uuid, type: :keyword
indexes :client_ids, type: :keyword
indexes :prefix_ids, type: :keyword
indexes :name, type: :text, fields: { keyword: { type: "keyword" }, raw: { type: "text", "analyzer": "string_lowercase", "fielddata": true }}
Expand Down Expand Up @@ -202,6 +204,7 @@ def as_indexed_json(options={})
"twitter_handle" => twitter_handle,
"ror_id" => ror_id,
"salesforce_id" => salesforce_id,
"globus_uuid" => globus_uuid,
"billing_information" => {
"address" => billing_address,
"organization" => billing_organization,
Expand Down Expand Up @@ -528,6 +531,10 @@ def can_be_in_consortium
end
end

def uuid_format
errors.add(:globus_uuid, "#{globus_uuid} is not a valid UUID") unless UUID.validate(globus_uuid)
end

def freeze_symbol
errors.add(:symbol, "cannot be changed") if self.symbol_changed?
end
Expand Down
6 changes: 5 additions & 1 deletion app/serializers/client_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class ClientSerializer
set_type :clients
set_id :uid

attributes :name, :symbol, :year, :contact_email, :alternate_name, :description, :language, :client_type, :domains, :re3data, :opendoar, :issn, :url, :salesforce_id, :created, :updated
attributes :name, :symbol, :year, :contact_email, :globus_uuid, :alternate_name, :description, :language, :client_type, :domains, :re3data, :opendoar, :issn, :url, :salesforce_id, :created, :updated

belongs_to :provider, record_type: :providers
belongs_to :consortium, record_type: :providers, serializer: ProviderSerializer, if: Proc.new { |client| client.consortium_id }
Expand All @@ -26,6 +26,10 @@ class ClientSerializer
object.salesforce_id
end

attribute :globus_uuid, if: Proc.new { |object, params| params[:current_ability] && params[:current_ability].can?(:read_billing_information, object) == true } do |object|
object.globus_uuid
end

attribute :re3data do |object|
"https://doi.org/#{object.re3data_id}" if object.re3data_id.present?
end
Expand Down
6 changes: 5 additions & 1 deletion app/serializers/provider_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class ProviderSerializer
set_id :uid
# cache_options enabled: true, cache_length: 24.hours ### we cannot filter if we cache

attributes :name, :display_name, :symbol, :website, :system_email, :group_email, :description, :region, :country, :logo_url, :member_type, :organization_type, :focus_area, :non_profit_status, :is_active, :has_password, :joined, :twitter_handle, :billing_information, :ror_id, :salesforce_id, :technical_contact, :secondary_technical_contact, :billing_contact, :secondary_billing_contact, :service_contact, :secondary_service_contact, :voting_contact, :created, :updated
attributes :name, :display_name, :symbol, :website, :system_email, :group_email, :globus_uuid, :description, :region, :country, :logo_url, :member_type, :organization_type, :focus_area, :non_profit_status, :is_active, :has_password, :joined, :twitter_handle, :billing_information, :ror_id, :salesforce_id, :technical_contact, :secondary_technical_contact, :billing_contact, :secondary_billing_contact, :service_contact, :secondary_service_contact, :voting_contact, :created, :updated

has_many :clients, record_type: :clients
has_many :prefixes, record_type: :prefixes
Expand All @@ -32,6 +32,10 @@ class ProviderSerializer
object.twitter_handle
end

attribute :globus_uuid, if: Proc.new { |object, params| params[:current_ability] && params[:current_ability].can?(:read_billing_information, object) == true } do |object|
object.globus_uuid
end

# Convert all contacts json models back to json style camelCase
attribute :technical_contact do |object|
object.technical_contact.present? ? object.technical_contact.transform_keys!{ |key| key.to_s.camelcase(:lower) } : {}
Expand Down
6 changes: 5 additions & 1 deletion app/serializers/repository_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class RepositorySerializer
set_type :repositories
set_id :uid

attributes :name, :symbol, :re3data, :opendoar, :year, :system_email, :alternate_name, :description, :client_type, :repository_type, :language, :certificate, :domains, :issn, :url, :salesforce_id, :created, :updated
attributes :name, :symbol, :re3data, :opendoar, :year, :system_email, :globus_uuid, :alternate_name, :description, :client_type, :repository_type, :language, :certificate, :domains, :issn, :url, :salesforce_id, :created, :updated

belongs_to :provider, record_type: :providers
has_many :prefixes, record_type: :prefixes
Expand All @@ -29,6 +29,10 @@ class RepositorySerializer
object.service_contact.present? ? object.service_contact.transform_keys!{ |key| key.to_s.camelcase(:lower) } : {}
end

attribute :globus_uuid, if: Proc.new { |object, params| params[:current_ability] && params[:current_ability].can?(:read_billing_information, object) == true } do |object|
object.globus_uuid
end

attribute :salesforce_id, if: Proc.new { |object, params| params[:current_ability] && params[:current_ability].can?(:read_salesforce_id, object) == true } do |object|
object.salesforce_id
end
Expand Down
9 changes: 9 additions & 0 deletions db/migrate/20200122153731_add_globus_uuid.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class AddGlobusUuid < ActiveRecord::Migration[5.2]
def change
add_column :datacentre, :globus_uuid, :string, limit: 191
add_column :allocator, :globus_uuid, :string, limit: 191

add_index :datacentre, [:globus_uuid], name: "index_datacentre_on_globus_uuid", length: { globus_uuid: 191 }
add_index :allocator, [:globus_uuid], name: "index_allocator_on_globus_uuid", length: { globus_uuid: 191 }
end
end
Loading

0 comments on commit eeb811c

Please sign in to comment.