From 33fffa1eededbba9a399a9639d5cf4b7af3ff32a Mon Sep 17 00:00:00 2001 From: kjgarza Date: Thu, 30 Jan 2020 16:23:50 +0100 Subject: [PATCH 01/15] factory for orcid_events --- spec/factories/default.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/spec/factories/default.rb b/spec/factories/default.rb index 74c91d0a2..336376d44 100644 --- a/spec/factories/default.rb +++ b/spec/factories/default.rb @@ -358,5 +358,14 @@ relation_type_id { "unique-dataset-investigations-regular" } occurred_at { "2015-06-13T16:14:19Z" } end + + factory :event_for_datacite_orcid_auto_update do + source_id { "datacite-orcid-auto-updatee" } + source_token { "5348967fhdjksr3wyui325" } + sequence(:obj_id) { |n| "https://orcid.org/0000-0003-1419-211{n}" } + sequence(:subj_id) { |n| "http://doi.org/10.5061/DRYAD.47SD5e/#{n}" } + relation_type_id { "is-authored-by" } + occurred_at { "2015-06-13T16:14:19Z" } + end end end From a442139dbc2a31904f4c5b98a20cfc26d23b9d7c Mon Sep 17 00:00:00 2001 From: kjgarza Date: Thu, 30 Jan 2020 16:24:14 +0100 Subject: [PATCH 02/15] added seedbank for better seeding --- Gemfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Gemfile b/Gemfile index e26ed9879..e97328d38 100644 --- a/Gemfile +++ b/Gemfile @@ -86,6 +86,7 @@ group :development do gem "spring" gem "spring-watcher-listen", "~> 2.0.0" gem "spring-commands-rspec" + gem "seedbank" # gem "httplog", "~> 1.0" end From 6aeced43634fa5583aca232e4cccf4b79170bef3 Mon Sep 17 00:00:00 2001 From: kjgarza Date: Thu, 30 Jan 2020 16:24:28 +0100 Subject: [PATCH 03/15] seeding for different cases --- db/seeds/development/base.seeds.rb | 13 +++++++++++++ db/seeds/development/researcher_profile.seeds.rb | 10 ++++++++++ 2 files changed, 23 insertions(+) create mode 100644 db/seeds/development/base.seeds.rb create mode 100644 db/seeds/development/researcher_profile.seeds.rb diff --git a/db/seeds/development/base.seeds.rb b/db/seeds/development/base.seeds.rb new file mode 100644 index 000000000..b5b0f15ca --- /dev/null +++ b/db/seeds/development/base.seeds.rb @@ -0,0 +1,13 @@ +require "factory_bot_rails" + + +FactoryBot.create(:provider, symbol: "ADMIN") +provider = FactoryBot.create(:provider, symbol: "DATACITE") +client = FactoryBot.create(:client, provider: provider, symbol: ENV['MDS_USERNAME'], password: ENV['MDS_PASSWORD']) +prefix = FactoryBot.create(:prefix, prefix: "10.14454") +FactoryBot.create(:client_prefix, client: client, prefix: prefix) +dois = FactoryBot.create_list(:doi,10, client: client) + +FactoryBot.create_list(:event_for_datacite_related, 3, obj_id: dois.first.doi) +FactoryBot.create_list(:event_for_datacite_usage, 2, obj_id: dois.first.doi) + diff --git a/db/seeds/development/researcher_profile.seeds.rb b/db/seeds/development/researcher_profile.seeds.rb new file mode 100644 index 000000000..ca23107b1 --- /dev/null +++ b/db/seeds/development/researcher_profile.seeds.rb @@ -0,0 +1,10 @@ +require "factory_bot_rails" + +after :base do + client = Client.all.first + dois = FactoryBot.create_list(:doi,70, client: client, state: "findable") + + FactoryBot.create_list(:event_for_datacite_related, 34, obj_id: dois.first.doi) + FactoryBot.create_list(:event_for_datacite_usage, 32, obj_id: dois.first.doi) + FactoryBot.create_list(:event_for_datacite_orcid_auto_update, 5, subj_id: dois.first.doi, obj_id: 'http://orcid.org/0000-0003-2926-8353') +end \ No newline at end of file From 60e7c72a51a39ad93daeaa9b8d7c899e0b2ccb14 Mon Sep 17 00:00:00 2001 From: kjgarza Date: Thu, 30 Jan 2020 18:49:42 +0100 Subject: [PATCH 04/15] seedeing after --- db/seeds/development/base.seeds.rb | 2 +- db/seeds/development/researcher_profile.seeds.rb | 5 +++-- spec/factories/default.rb | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/db/seeds/development/base.seeds.rb b/db/seeds/development/base.seeds.rb index b5b0f15ca..bc34588f9 100644 --- a/db/seeds/development/base.seeds.rb +++ b/db/seeds/development/base.seeds.rb @@ -6,7 +6,7 @@ client = FactoryBot.create(:client, provider: provider, symbol: ENV['MDS_USERNAME'], password: ENV['MDS_PASSWORD']) prefix = FactoryBot.create(:prefix, prefix: "10.14454") FactoryBot.create(:client_prefix, client: client, prefix: prefix) -dois = FactoryBot.create_list(:doi,10, client: client) +dois = FactoryBot.create_list(:doi,10, client: client, state: "findable") FactoryBot.create_list(:event_for_datacite_related, 3, obj_id: dois.first.doi) FactoryBot.create_list(:event_for_datacite_usage, 2, obj_id: dois.first.doi) diff --git a/db/seeds/development/researcher_profile.seeds.rb b/db/seeds/development/researcher_profile.seeds.rb index ca23107b1..1cd6dfe54 100644 --- a/db/seeds/development/researcher_profile.seeds.rb +++ b/db/seeds/development/researcher_profile.seeds.rb @@ -1,10 +1,11 @@ require "factory_bot_rails" -after :base do +after "development:base" do client = Client.all.first dois = FactoryBot.create_list(:doi,70, client: client, state: "findable") FactoryBot.create_list(:event_for_datacite_related, 34, obj_id: dois.first.doi) FactoryBot.create_list(:event_for_datacite_usage, 32, obj_id: dois.first.doi) - FactoryBot.create_list(:event_for_datacite_orcid_auto_update, 5, subj_id: dois.first.doi, obj_id: 'http://orcid.org/0000-0003-2926-8353') + FactoryBot.create(:event_for_datacite_orcid_auto_update, subj_id: dois.first.doi, obj_id: 'http://orcid.org/0000-0003-2926-8353') + FactoryBot.create_list(:event_for_datacite_orcid_auto_update, 5, obj_id: 'http://orcid.org/0000-0003-2926-8353') end \ No newline at end of file diff --git a/spec/factories/default.rb b/spec/factories/default.rb index 336376d44..d585541a5 100644 --- a/spec/factories/default.rb +++ b/spec/factories/default.rb @@ -362,7 +362,7 @@ factory :event_for_datacite_orcid_auto_update do source_id { "datacite-orcid-auto-updatee" } source_token { "5348967fhdjksr3wyui325" } - sequence(:obj_id) { |n| "https://orcid.org/0000-0003-1419-211{n}" } + sequence(:obj_id) { |n| "https://orcid.org/0000-0003-1419-211#{n}}" } sequence(:subj_id) { |n| "http://doi.org/10.5061/DRYAD.47SD5e/#{n}" } relation_type_id { "is-authored-by" } occurred_at { "2015-06-13T16:14:19Z" } From 66d098aa18b4e12ed9b53e52894d721ac4eeb09c Mon Sep 17 00:00:00 2001 From: kjgarza Date: Wed, 11 Mar 2020 10:59:29 +0100 Subject: [PATCH 05/15] instructions on how to use --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index d0861d125..c1c022093 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,14 @@ You can now point your browser to `http://localhost:8065` and use the applicatio ## Development +For basic setup one can use the following: + +```bash +bundle exec rake db:create +bundle exec rake db:schema:load +bundle exec rake db:seed:development:base +``` + We use Rspec for testing: ```bash From 86b6c48e1c169960374b87a8883cdf6486f2e9d9 Mon Sep 17 00:00:00 2001 From: kjgarza Date: Wed, 11 Mar 2020 10:59:40 +0100 Subject: [PATCH 06/15] warnings for messages --- db/seeds/development/base.seeds.rb | 18 ++++++++++-------- .../development/researcher_profile.seeds.rb | 12 +++++++----- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/db/seeds/development/base.seeds.rb b/db/seeds/development/base.seeds.rb index bc34588f9..1614d5ed7 100644 --- a/db/seeds/development/base.seeds.rb +++ b/db/seeds/development/base.seeds.rb @@ -1,13 +1,15 @@ require "factory_bot_rails" +fail "Seed tasks can only be used in the development enviroment" if Rails.env.production? +fail "You need to set up a MDS_USERNAME and MDS_PASSWORD" if ENV["MDS_USERNAME"].blank? || ENV["MDS_PASSWORD"].blank? FactoryBot.create(:provider, symbol: "ADMIN") provider = FactoryBot.create(:provider, symbol: "DATACITE") -client = FactoryBot.create(:client, provider: provider, symbol: ENV['MDS_USERNAME'], password: ENV['MDS_PASSWORD']) -prefix = FactoryBot.create(:prefix, prefix: "10.14454") -FactoryBot.create(:client_prefix, client: client, prefix: prefix) -dois = FactoryBot.create_list(:doi,10, client: client, state: "findable") - -FactoryBot.create_list(:event_for_datacite_related, 3, obj_id: dois.first.doi) -FactoryBot.create_list(:event_for_datacite_usage, 2, obj_id: dois.first.doi) - +client = FactoryBot.create(:client, provider: provider, symbol: ENV["MDS_USERNAME"], password: ENV["MDS_PASSWORD"]) +if Prefix.where(prefix: "10.14454").blank? + prefix = FactoryBot.create(:prefix, prefix: "10.14454") + FactoryBot.create(:client_prefix, client: client, prefix: prefix) +end +dois = FactoryBot.create_list(:doi, 10, client: client, state: "findable") +FactoryBot.create_list(:event_for_datacite_related, 3, obj_id: dois.first.doi) +FactoryBot.create_list(:event_for_datacite_usage, 2, obj_id: dois.first.doi) \ No newline at end of file diff --git a/db/seeds/development/researcher_profile.seeds.rb b/db/seeds/development/researcher_profile.seeds.rb index 1cd6dfe54..05819ea0e 100644 --- a/db/seeds/development/researcher_profile.seeds.rb +++ b/db/seeds/development/researcher_profile.seeds.rb @@ -1,11 +1,13 @@ require "factory_bot_rails" +fail "Seed tasks can only be used in the development enviroment" if Rails.env.production? + after "development:base" do client = Client.all.first - dois = FactoryBot.create_list(:doi,70, client: client, state: "findable") + dois = FactoryBot.create_list(:doi, 70, client: client, state: "findable") - FactoryBot.create_list(:event_for_datacite_related, 34, obj_id: dois.first.doi) + FactoryBot.create_list(:event_for_datacite_related, 34, obj_id: dois.first.doi) FactoryBot.create_list(:event_for_datacite_usage, 32, obj_id: dois.first.doi) - FactoryBot.create(:event_for_datacite_orcid_auto_update, subj_id: dois.first.doi, obj_id: 'http://orcid.org/0000-0003-2926-8353') - FactoryBot.create_list(:event_for_datacite_orcid_auto_update, 5, obj_id: 'http://orcid.org/0000-0003-2926-8353') -end \ No newline at end of file + FactoryBot.create(:event_for_datacite_orcid_auto_update, subj_id: dois.first.doi, obj_id: "http://orcid.org/0000-0003-2926-8353") + FactoryBot.create_list(:event_for_datacite_orcid_auto_update, 5, obj_id: "http://orcid.org/0000-0003-2926-8353") +end From fbf2b72f18a5f609331b54ebd91adb355e17ae01 Mon Sep 17 00:00:00 2001 From: kjgarza Date: Wed, 11 Mar 2020 11:57:31 +0100 Subject: [PATCH 07/15] missing factory --- spec/factories/default.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/spec/factories/default.rb b/spec/factories/default.rb index fd27c8b2b..63a48953a 100644 --- a/spec/factories/default.rb +++ b/spec/factories/default.rb @@ -453,6 +453,18 @@ occurred_at { "2015-06-13T16:14:19Z" } end + factory :event_for_datacite_usage do + source_id { "datacite-usage" } + source_token { "5348967fhdjksr3wyui325" } + total { rand(1..100).to_int } + sequence(:subj_id) { |_n| "https://api.test.datacite.org/report/#{SecureRandom.uuid}" } + subj { { "datePublished" => "2006-06-13T16:14:19Z" } } + obj { { "date_published" => "2007-06-13T16:14:19Z" } } + obj_id { "http://doi.org/10.5061/DRYAD.47SD5/1" } + relation_type_id { "unique-dataset-investigations-regular" } + occurred_at { "2015-06-13T16:14:19Z" } + end + factory :event_for_datacite_orcid_auto_update do source_id { "datacite-orcid-auto-update" } source_token { "5348967fhdjksr3wyui325" } From f5a58cd9fe03556c8b8722462375a863cf536e8c Mon Sep 17 00:00:00 2001 From: Martin Fenner Date: Mon, 20 Apr 2020 11:54:09 +0200 Subject: [PATCH 08/15] Include account type in slack messages. #475 --- app/models/concerns/mailable.rb | 16 +++++++---- spec/concerns/mailable_spec.rb | 2 +- .../send_notification_to_slack/succeeds.yml | 28 ++++++------------- .../Mailable/send_welcome_email.yml | 28 ++++++------------- 4 files changed, 29 insertions(+), 45 deletions(-) diff --git a/app/models/concerns/mailable.rb b/app/models/concerns/mailable.rb index 6640c096c..f727701d9 100644 --- a/app/models/concerns/mailable.rb +++ b/app/models/concerns/mailable.rb @@ -28,15 +28,17 @@ def send_welcome_email reset_url = ENV['BRACCO_URL'] + "/reset" title = Rails.env.stage? ? "DataCite Fabrica Test" : "DataCite Fabrica" subject = "#{title}: New Account" + account_type = self.class.name == "Provider" ? member_type : client_type text = User.format_message_text(template: "users/welcome.text.erb", title: title, contact_name: name, name: symbol, url: url, reset_url: reset_url) html = User.format_message_html(template: "users/welcome.html.erb", title: title, contact_name: name, name: symbol, url: url, reset_url: reset_url) response = User.send_message(name: name, email: system_email, subject: subject, text: text, html: html) fields = [ - { title: "Account ID", value: symbol}, - { title: "Contact name", value: name, short: true }, - { title: "Contact email", value: system_email, short: true } + { title: "Account ID", value: symbol, short: true }, + { title: "Account type", value: account_type, short: true }, + { title: "Account name", value: name, short: true }, + { title: "System email", value: system_email, short: true } ] User.send_notification_to_slack(nil, title: subject, level: "good", fields: fields) @@ -46,15 +48,17 @@ def send_welcome_email def send_delete_email title = Rails.env.stage? ? "DataCite Fabrica Test" : "DataCite Fabrica" subject = "#{title}: Account Deleted" + account_type = self.class.name == "Provider" ? member_type : client_type text = User.format_message_text(template: "users/delete.text.erb", title: title, contact_name: name, name: symbol) html = User.format_message_html(template: "users/delete.html.erb", title: title, contact_name: name, name: symbol) response = User.send_message(name: name, email: system_email, subject: subject, text: text, html: html) fields = [ - { title: "Account ID", value: symbol}, - { title: "Contact name", value: name, short: true }, - { title: "Contact email", value: system_email, short: true } + { title: "Account ID", value: symbol, short: true }, + { title: "Account type", value: account_type, short: true }, + { title: "Account name", value: name, short: true }, + { title: "System email", value: system_email, short: true } ] User.send_notification_to_slack(nil, title: subject, level: "warning", fields: fields) diff --git a/spec/concerns/mailable_spec.rb b/spec/concerns/mailable_spec.rb index 056b6aad2..b038859a3 100644 --- a/spec/concerns/mailable_spec.rb +++ b/spec/concerns/mailable_spec.rb @@ -50,7 +50,7 @@ context "send_notification_to_slack" do it "succeeds" do - text = "Using contact email #{client.system_email}." + text = "Using system email #{client.system_email}." options = { title: "TEST: new client account #{client.symbol} created." } expect(Client.send_notification_to_slack(text, options)).to eq("ok") end diff --git a/spec/fixtures/vcr_cassettes/Mailable/send_notification_to_slack/succeeds.yml b/spec/fixtures/vcr_cassettes/Mailable/send_notification_to_slack/succeeds.yml index bd279cb0e..4d93e4e03 100644 --- a/spec/fixtures/vcr_cassettes/Mailable/send_notification_to_slack/succeeds.yml +++ b/spec/fixtures/vcr_cassettes/Mailable/send_notification_to_slack/succeeds.yml @@ -5,7 +5,7 @@ http_interactions: uri: "" body: encoding: US-ASCII - string: payload=%7B%22username%22%3A%22Fabrica%22%2C%22icon_url%22%3A%22https%3A%2F%2Fgithub.com%2Fdatacite%2Fsegugio%2Fblob%2Fmaster%2Fsource%2Fimages%2Ffabrica.png%22%2C%22attachments%22%3A%5B%7B%22title%22%3A%22TEST%3A+new+client+account+DATACITE.DATACITE+created.%22%2C%22text%22%3A%22Using+contact+email+test%40datacite.org.%22%2C%22color%22%3A%22good%22%7D%5D%7D + string: payload=%7B%22username%22%3A%22Fabrica%22%2C%22icon_url%22%3A%22https%3A%2F%2Fgithub.com%2Fdatacite%2Fsegugio%2Fblob%2Fmaster%2Fsource%2Fimages%2Ffabrica.png%22%2C%22attachments%22%3A%5B%7B%22title%22%3A%22TEST%3A+new+client+account+DATACITE.DATACITE+created.%22%2C%22text%22%3A%22Using+system+email+test%40datacite.org.%22%2C%22color%22%3A%22good%22%7D%5D%7D headers: Accept-Encoding: - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 @@ -20,14 +20,8 @@ http_interactions: code: 200 message: OK headers: - Content-Type: - - text/html - Content-Length: - - '22' - Connection: - - keep-alive Date: - - Sat, 28 Mar 2020 07:53:12 GMT + - Mon, 20 Apr 2020 09:51:19 GMT Server: - Apache Vary: @@ -37,24 +31,20 @@ http_interactions: Referrer-Policy: - no-referrer X-Slack-Backend: - - h + - r X-Frame-Options: - SAMEORIGIN Access-Control-Allow-Origin: - "*" + Content-Length: + - '22' + Content-Type: + - text/html X-Via: - - haproxy-www-23wl - X-Cache: - - Miss from cloudfront - Via: - - 1.1 3c2fca5c3988bc152e874a83fac74f4a.cloudfront.net (CloudFront) - X-Amz-Cf-Pop: - - DUS51-C1 - X-Amz-Cf-Id: - - uQ48lYHrWcla25FwUtK7uNbwAgIqhVIp2Klth3f21F2D3Zs6o7nFXA== + - haproxy-www-9hkc body: encoding: ASCII-8BIT string: ok http_version: null - recorded_at: Sat, 28 Mar 2020 07:53:12 GMT + recorded_at: Mon, 20 Apr 2020 09:51:19 GMT recorded_with: VCR 5.1.0 diff --git a/spec/fixtures/vcr_cassettes/Mailable/send_welcome_email.yml b/spec/fixtures/vcr_cassettes/Mailable/send_welcome_email.yml index 35fc020a9..e9ecaf7cf 100644 --- a/spec/fixtures/vcr_cassettes/Mailable/send_welcome_email.yml +++ b/spec/fixtures/vcr_cassettes/Mailable/send_welcome_email.yml @@ -5,7 +5,7 @@ http_interactions: uri: "" body: encoding: US-ASCII - string: payload=%7B%22username%22%3A%22Fabrica%22%2C%22icon_url%22%3A%22https%3A%2F%2Fgithub.com%2Fdatacite%2Fsegugio%2Fblob%2Fmaster%2Fsource%2Fimages%2Ffabrica.png%22%2C%22attachments%22%3A%5B%7B%22title%22%3A%22DataCite+Fabrica%3A+New+Account%22%2C%22color%22%3A%22good%22%2C%22fields%22%3A%5B%7B%22title%22%3A%22Account+ID%22%2C%22value%22%3A%22DATACITE.DATACITE%22%7D%2C%7B%22title%22%3A%22Contact+name%22%2C%22value%22%3A%22DataCite+Repository%22%2C%22short%22%3Atrue%7D%2C%7B%22title%22%3A%22Contact+email%22%2C%22value%22%3A%22test%40datacite.org%22%2C%22short%22%3Atrue%7D%5D%7D%5D%7D + string: payload=%7B%22username%22%3A%22Fabrica%22%2C%22icon_url%22%3A%22https%3A%2F%2Fgithub.com%2Fdatacite%2Fsegugio%2Fblob%2Fmaster%2Fsource%2Fimages%2Ffabrica.png%22%2C%22attachments%22%3A%5B%7B%22title%22%3A%22DataCite+Fabrica%3A+New+Account%22%2C%22color%22%3A%22good%22%2C%22fields%22%3A%5B%7B%22title%22%3A%22Account+ID%22%2C%22value%22%3A%22DATACITE.DATACITE%22%2C%22short%22%3Atrue%7D%2C%7B%22title%22%3A%22Account+type%22%2C%22value%22%3A%22repository%22%2C%22short%22%3Atrue%7D%2C%7B%22title%22%3A%22Account+name%22%2C%22value%22%3A%22DataCite+Repository%22%2C%22short%22%3Atrue%7D%2C%7B%22title%22%3A%22System+email%22%2C%22value%22%3A%22test%40datacite.org%22%2C%22short%22%3Atrue%7D%5D%7D%5D%7D headers: Accept-Encoding: - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 @@ -20,14 +20,8 @@ http_interactions: code: 200 message: OK headers: - Content-Type: - - text/html - Content-Length: - - '22' - Connection: - - keep-alive Date: - - Sat, 28 Mar 2020 07:53:10 GMT + - Mon, 20 Apr 2020 09:51:18 GMT Server: - Apache Vary: @@ -37,24 +31,20 @@ http_interactions: Referrer-Policy: - no-referrer X-Slack-Backend: - - h + - r X-Frame-Options: - SAMEORIGIN Access-Control-Allow-Origin: - "*" + Content-Length: + - '22' + Content-Type: + - text/html X-Via: - - haproxy-www-itvd - X-Cache: - - Miss from cloudfront - Via: - - 1.1 e8640ab30463560abfb6a2665bafb393.cloudfront.net (CloudFront) - X-Amz-Cf-Pop: - - DUS51-C1 - X-Amz-Cf-Id: - - fRUDXsnGgVVW90DuHGE5mmv8Vhm65hUIZrCk5kKvQARvmg0oxt24mw== + - haproxy-www-y6ft body: encoding: ASCII-8BIT string: ok http_version: null - recorded_at: Sat, 28 Mar 2020 07:53:10 GMT + recorded_at: Mon, 20 Apr 2020 09:51:18 GMT recorded_with: VCR 5.1.0 From 076915ea0a48235cdd5ae6d20cbdc1b9c53ff696 Mon Sep 17 00:00:00 2001 From: Martin Fenner Date: Mon, 20 Apr 2020 17:07:42 +0200 Subject: [PATCH 09/15] humanize account_type text. #475 --- app/models/concerns/mailable.rb | 4 +- spec/concerns/mailable_spec.rb | 10 +++- .../send_notification_to_slack/succeeds.yml | 8 +-- .../succeeds.yml | 50 +++++++++++++++++++ .../Mailable/send_welcome_email.yml | 10 ++-- 5 files changed, 70 insertions(+), 12 deletions(-) create mode 100644 spec/fixtures/vcr_cassettes/Mailable/send_notification_to_slack_provider/succeeds.yml diff --git a/app/models/concerns/mailable.rb b/app/models/concerns/mailable.rb index f727701d9..0769c58bb 100644 --- a/app/models/concerns/mailable.rb +++ b/app/models/concerns/mailable.rb @@ -28,7 +28,7 @@ def send_welcome_email reset_url = ENV['BRACCO_URL'] + "/reset" title = Rails.env.stage? ? "DataCite Fabrica Test" : "DataCite Fabrica" subject = "#{title}: New Account" - account_type = self.class.name == "Provider" ? member_type : client_type + account_type = self.class.name == "Provider" ? member_type.humanize : client_type.humanize text = User.format_message_text(template: "users/welcome.text.erb", title: title, contact_name: name, name: symbol, url: url, reset_url: reset_url) html = User.format_message_html(template: "users/welcome.html.erb", title: title, contact_name: name, name: symbol, url: url, reset_url: reset_url) @@ -48,7 +48,7 @@ def send_welcome_email def send_delete_email title = Rails.env.stage? ? "DataCite Fabrica Test" : "DataCite Fabrica" subject = "#{title}: Account Deleted" - account_type = self.class.name == "Provider" ? member_type : client_type + account_type = self.class.name == "Provider" ? member_type.humanize : client_type.humanize text = User.format_message_text(template: "users/delete.text.erb", title: title, contact_name: name, name: symbol) html = User.format_message_html(template: "users/delete.html.erb", title: title, contact_name: name, name: symbol) diff --git a/spec/concerns/mailable_spec.rb b/spec/concerns/mailable_spec.rb index b038859a3..75790be8c 100644 --- a/spec/concerns/mailable_spec.rb +++ b/spec/concerns/mailable_spec.rb @@ -2,7 +2,7 @@ describe "Mailable", type: :model, vcr: true do let(:token) { User.generate_token } - let(:provider) { create(:provider, symbol: "DATACITE") } + let(:provider) { create(:provider, symbol: "DATACITE", name: "DataCite", system_email: "test@datacite.org") } let(:client) { create(:client, symbol: "DATACITE.DATACITE", name: "DataCite Repository", system_email: "test@datacite.org", provider: provider) } let(:title) { "DataCite Fabrica" } @@ -55,4 +55,12 @@ expect(Client.send_notification_to_slack(text, options)).to eq("ok") end end + + context "send_notification_to_slack provider" do + it "succeeds" do + text = "Using system email #{provider.system_email}." + options = { title: "TEST: new provider account #{provider.symbol} created." } + expect(Client.send_notification_to_slack(text, options)).to eq("ok") + end + end end diff --git a/spec/fixtures/vcr_cassettes/Mailable/send_notification_to_slack/succeeds.yml b/spec/fixtures/vcr_cassettes/Mailable/send_notification_to_slack/succeeds.yml index 4d93e4e03..2d448694a 100644 --- a/spec/fixtures/vcr_cassettes/Mailable/send_notification_to_slack/succeeds.yml +++ b/spec/fixtures/vcr_cassettes/Mailable/send_notification_to_slack/succeeds.yml @@ -21,7 +21,7 @@ http_interactions: message: OK headers: Date: - - Mon, 20 Apr 2020 09:51:19 GMT + - Mon, 20 Apr 2020 14:48:47 GMT Server: - Apache Vary: @@ -31,7 +31,7 @@ http_interactions: Referrer-Policy: - no-referrer X-Slack-Backend: - - r + - h X-Frame-Options: - SAMEORIGIN Access-Control-Allow-Origin: @@ -41,10 +41,10 @@ http_interactions: Content-Type: - text/html X-Via: - - haproxy-www-9hkc + - haproxy-www-8gaq body: encoding: ASCII-8BIT string: ok http_version: null - recorded_at: Mon, 20 Apr 2020 09:51:19 GMT + recorded_at: Mon, 20 Apr 2020 14:48:48 GMT recorded_with: VCR 5.1.0 diff --git a/spec/fixtures/vcr_cassettes/Mailable/send_notification_to_slack_provider/succeeds.yml b/spec/fixtures/vcr_cassettes/Mailable/send_notification_to_slack_provider/succeeds.yml new file mode 100644 index 000000000..363740b7b --- /dev/null +++ b/spec/fixtures/vcr_cassettes/Mailable/send_notification_to_slack_provider/succeeds.yml @@ -0,0 +1,50 @@ +--- +http_interactions: +- request: + method: post + uri: "" + body: + encoding: US-ASCII + string: payload=%7B%22username%22%3A%22Fabrica%22%2C%22icon_url%22%3A%22https%3A%2F%2Fgithub.com%2Fdatacite%2Fsegugio%2Fblob%2Fmaster%2Fsource%2Fimages%2Ffabrica.png%22%2C%22attachments%22%3A%5B%7B%22title%22%3A%22TEST%3A+new+provider+account+DATACITE+created.%22%2C%22text%22%3A%22Using+system+email+test%40datacite.org.%22%2C%22color%22%3A%22good%22%7D%5D%7D + headers: + Accept-Encoding: + - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 + Accept: + - "*/*" + User-Agent: + - Ruby + Content-Type: + - application/x-www-form-urlencoded + response: + status: + code: 200 + message: OK + headers: + Date: + - Mon, 20 Apr 2020 14:48:48 GMT + Server: + - Apache + Vary: + - Accept-Encoding + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + Referrer-Policy: + - no-referrer + X-Slack-Backend: + - h + X-Frame-Options: + - SAMEORIGIN + Access-Control-Allow-Origin: + - "*" + Content-Length: + - '22' + Content-Type: + - text/html + X-Via: + - haproxy-www-8k7d + body: + encoding: ASCII-8BIT + string: ok + http_version: null + recorded_at: Mon, 20 Apr 2020 14:48:48 GMT +recorded_with: VCR 5.1.0 diff --git a/spec/fixtures/vcr_cassettes/Mailable/send_welcome_email.yml b/spec/fixtures/vcr_cassettes/Mailable/send_welcome_email.yml index e9ecaf7cf..9bbcc6da2 100644 --- a/spec/fixtures/vcr_cassettes/Mailable/send_welcome_email.yml +++ b/spec/fixtures/vcr_cassettes/Mailable/send_welcome_email.yml @@ -5,7 +5,7 @@ http_interactions: uri: "" body: encoding: US-ASCII - string: payload=%7B%22username%22%3A%22Fabrica%22%2C%22icon_url%22%3A%22https%3A%2F%2Fgithub.com%2Fdatacite%2Fsegugio%2Fblob%2Fmaster%2Fsource%2Fimages%2Ffabrica.png%22%2C%22attachments%22%3A%5B%7B%22title%22%3A%22DataCite+Fabrica%3A+New+Account%22%2C%22color%22%3A%22good%22%2C%22fields%22%3A%5B%7B%22title%22%3A%22Account+ID%22%2C%22value%22%3A%22DATACITE.DATACITE%22%2C%22short%22%3Atrue%7D%2C%7B%22title%22%3A%22Account+type%22%2C%22value%22%3A%22repository%22%2C%22short%22%3Atrue%7D%2C%7B%22title%22%3A%22Account+name%22%2C%22value%22%3A%22DataCite+Repository%22%2C%22short%22%3Atrue%7D%2C%7B%22title%22%3A%22System+email%22%2C%22value%22%3A%22test%40datacite.org%22%2C%22short%22%3Atrue%7D%5D%7D%5D%7D + string: payload=%7B%22username%22%3A%22Fabrica%22%2C%22icon_url%22%3A%22https%3A%2F%2Fgithub.com%2Fdatacite%2Fsegugio%2Fblob%2Fmaster%2Fsource%2Fimages%2Ffabrica.png%22%2C%22attachments%22%3A%5B%7B%22title%22%3A%22DataCite+Fabrica%3A+New+Account%22%2C%22color%22%3A%22good%22%2C%22fields%22%3A%5B%7B%22title%22%3A%22Account+ID%22%2C%22value%22%3A%22DATACITE.DATACITE%22%2C%22short%22%3Atrue%7D%2C%7B%22title%22%3A%22Account+type%22%2C%22value%22%3A%22Repository%22%2C%22short%22%3Atrue%7D%2C%7B%22title%22%3A%22Account+name%22%2C%22value%22%3A%22DataCite+Repository%22%2C%22short%22%3Atrue%7D%2C%7B%22title%22%3A%22System+email%22%2C%22value%22%3A%22test%40datacite.org%22%2C%22short%22%3Atrue%7D%5D%7D%5D%7D headers: Accept-Encoding: - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 @@ -21,7 +21,7 @@ http_interactions: message: OK headers: Date: - - Mon, 20 Apr 2020 09:51:18 GMT + - Mon, 20 Apr 2020 14:48:46 GMT Server: - Apache Vary: @@ -31,7 +31,7 @@ http_interactions: Referrer-Policy: - no-referrer X-Slack-Backend: - - r + - h X-Frame-Options: - SAMEORIGIN Access-Control-Allow-Origin: @@ -41,10 +41,10 @@ http_interactions: Content-Type: - text/html X-Via: - - haproxy-www-y6ft + - haproxy-www-s8m4 body: encoding: ASCII-8BIT string: ok http_version: null - recorded_at: Mon, 20 Apr 2020 09:51:18 GMT + recorded_at: Mon, 20 Apr 2020 14:48:47 GMT recorded_with: VCR 5.1.0 From c59856b7159979d4ea8ab7c393e8c3440982125b Mon Sep 17 00:00:00 2001 From: Martin Fenner Date: Mon, 20 Apr 2020 18:39:49 +0200 Subject: [PATCH 10/15] add additional parameters to cursor-based pagination. #476 --- app/controllers/dois_controller.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/app/controllers/dois_controller.rb b/app/controllers/dois_controller.rb index 039a37a30..b92e6dece 100644 --- a/app/controllers/dois_controller.rb +++ b/app/controllers/dois_controller.rb @@ -216,7 +216,24 @@ def index "provider-id" => params[:provider_id], "consortium-id" => params[:consortium_id], "client-id" => params[:client_id], + "funder-id" => params[:funder_id], + "affiliation-id" => params[:affiliation_id], + "resource-type-id" => params[:resource_type_id], + prefix: params[:prefix], certificate: params[:certificate], + created: params[:created], + registered: params[:registered], + "has-citations" => params[:has_citations], + "has-references" => params[:has_references], + "has-parts" => params[:has_parts], + "has-part-of" => params[:has_part_of], + "has-versions" => params[:has_versions], + "has-version-of" => params[:has_version_of], + "has-views" => params[:has_views], + "has-downloads" => params[:has_downloads], + "has-person" => params[:has_person], + "has-affiliation" => params[:has_affiliation], + "has-funder" => params[:has_funder], # The cursor link should be an array of values, but we want to encode it into a single string for the URL "page[cursor]" => page[:cursor] ? make_cursor(results) : nil, "page[number]" => page[:cursor].nil? && page[:number].present? ? page[:number] + 1 : nil, From 6d4b708044e751ac175dce83a1d81b0a05380ed7 Mon Sep 17 00:00:00 2001 From: kjgarza Date: Mon, 20 Apr 2020 19:20:47 +0200 Subject: [PATCH 11/15] accomodate table prefix changes --- db/seeds/development/base.seeds.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/db/seeds/development/base.seeds.rb b/db/seeds/development/base.seeds.rb index 1614d5ed7..dd1c92b03 100644 --- a/db/seeds/development/base.seeds.rb +++ b/db/seeds/development/base.seeds.rb @@ -3,12 +3,12 @@ fail "Seed tasks can only be used in the development enviroment" if Rails.env.production? fail "You need to set up a MDS_USERNAME and MDS_PASSWORD" if ENV["MDS_USERNAME"].blank? || ENV["MDS_PASSWORD"].blank? -FactoryBot.create(:provider, symbol: "ADMIN") -provider = FactoryBot.create(:provider, symbol: "DATACITE") -client = FactoryBot.create(:client, provider: provider, symbol: ENV["MDS_USERNAME"], password: ENV["MDS_PASSWORD"]) -if Prefix.where(prefix: "10.14454").blank? - prefix = FactoryBot.create(:prefix, prefix: "10.14454") - FactoryBot.create(:client_prefix, client: client, prefix: prefix) +FactoryBot.create(:provider, symbol: "ADMIN") if Provider.where(symbol: "ADMIN").blank? +provider = Provider.where(symbol: "DATACITE").first || FactoryBot.create(:provider, symbol: "DATACITE") +client = Client.where(symbol: "DATACITE.TEST").first || FactoryBot.create(:client, provider: provider, symbol: ENV["MDS_USERNAME"], password: ENV["MDS_PASSWORD"]) +if Prefix.where(uid: "10.14454").blank? + prefix = FactoryBot.create(:prefix, uid: "10.14454") + FactoryBot.create(:client_prefix, client_id: client.id, prefix_id: prefix.id) end dois = FactoryBot.create_list(:doi, 10, client: client, state: "findable") FactoryBot.create_list(:event_for_datacite_related, 3, obj_id: dois.first.doi) From 2a58ab45d2be98a3fc120c8c11ace8abc21739f4 Mon Sep 17 00:00:00 2001 From: kjgarza Date: Mon, 20 Apr 2020 19:25:51 +0200 Subject: [PATCH 12/15] update readme --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index c1c022093..778db40ea 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,8 @@ bundle exec rake db:schema:load bundle exec rake db:seed:development:base ``` +All other seed opntion can be found using rake --tasks + We use Rspec for testing: ```bash From 33e32f5ad5407f47d34108fb35ef053a811d06ab Mon Sep 17 00:00:00 2001 From: Martin Fenner Date: Tue, 21 Apr 2020 12:13:17 +0200 Subject: [PATCH 13/15] opt-out showing related-identifiers in api. #482 --- app/controllers/dois_controller.rb | 2 ++ app/serializers/doi_serializer.rb | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/app/controllers/dois_controller.rb b/app/controllers/dois_controller.rb index b92e6dece..521f824ab 100644 --- a/app/controllers/dois_controller.rb +++ b/app/controllers/dois_controller.rb @@ -244,6 +244,7 @@ def index options[:params] = { current_ability: current_ability, detail: params[:detail], + composite: params[:composite], affiliation: params[:affiliation], is_collection: options[:is_collection], } @@ -292,6 +293,7 @@ def show options[:params] = { current_ability: current_ability, detail: true, + composite: nil, affiliation: params[:affiliation], } diff --git a/app/serializers/doi_serializer.rb b/app/serializers/doi_serializer.rb index f104b9a36..0dcd355cc 100644 --- a/app/serializers/doi_serializer.rb +++ b/app/serializers/doi_serializer.rb @@ -72,7 +72,7 @@ class DoiSerializer Array.wrap(object.identifiers) end - attribute :related_identifiers do |object| + attribute :related_identifiers, if: Proc.new { |object, params| params && params[:composite].blank? } do |object| Array.wrap(object.related_identifiers) end From ff23570f7da3b51a19b5ed041b83669ef7eac99e Mon Sep 17 00:00:00 2001 From: Martin Fenner Date: Tue, 21 Apr 2020 17:44:57 +0200 Subject: [PATCH 14/15] use exclude-registration-agencies option in cursor-based pagination. #476 --- app/controllers/dois_controller.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/dois_controller.rb b/app/controllers/dois_controller.rb index 521f824ab..e3327cf69 100644 --- a/app/controllers/dois_controller.rb +++ b/app/controllers/dois_controller.rb @@ -213,6 +213,7 @@ def index self: request.original_url, next: results.size < page[:size] || page[:size] == 0 ? nil : request.base_url + "/dois?" + { query: params[:query], + "exclude-registration-agencies" => params[:exclude_registration_agencies], "provider-id" => params[:provider_id], "consortium-id" => params[:consortium_id], "client-id" => params[:client_id], From 79707bcd21e52be9a42d410bbfecc532c5e6bae1 Mon Sep 17 00:00:00 2001 From: Martin Fenner Date: Tue, 21 Apr 2020 18:47:35 +0200 Subject: [PATCH 15/15] include composite parameter in pagination. #476 --- app/controllers/dois_controller.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/controllers/dois_controller.rb b/app/controllers/dois_controller.rb index e3327cf69..0387c189a 100644 --- a/app/controllers/dois_controller.rb +++ b/app/controllers/dois_controller.rb @@ -235,6 +235,9 @@ def index "has-person" => params[:has_person], "has-affiliation" => params[:has_affiliation], "has-funder" => params[:has_funder], + detail: params[:detail], + composite: params[:composite], + affiliation: params[:affiliation], # The cursor link should be an array of values, but we want to encode it into a single string for the URL "page[cursor]" => page[:cursor] ? make_cursor(results) : nil, "page[number]" => page[:cursor].nil? && page[:number].present? ? page[:number] + 1 : nil,