Skip to content

Commit

Permalink
Merge branch 'master' into improve_count_performance
Browse files Browse the repository at this point in the history
  • Loading branch information
sarala committed Apr 22, 2020
2 parents e06c884 + c6a57ad commit a41e161
Show file tree
Hide file tree
Showing 12 changed files with 363 additions and 211 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ group :development do
gem "spring"
gem "spring-watcher-listen", "~> 2.0.0"
gem "spring-commands-rspec"
gem "seedbank"
# gem "httplog", "~> 1.0"
end

Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ 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
```

All other seed opntion can be found using rake --tasks

We use Rspec for testing:

```bash
Expand Down
23 changes: 23 additions & 0 deletions app/controllers/dois_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,31 @@ 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],
"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],
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,
Expand All @@ -227,6 +248,7 @@ def index
options[:params] = {
current_ability: current_ability,
detail: params[:detail],
composite: params[:composite],
affiliation: params[:affiliation],
is_collection: options[:is_collection],
}
Expand Down Expand Up @@ -275,6 +297,7 @@ def show
options[:params] = {
current_ability: current_ability,
detail: true,
composite: nil,
affiliation: params[:affiliation],
}

Expand Down
16 changes: 10 additions & 6 deletions app/models/concerns/mailable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.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)

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)

Expand All @@ -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.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)

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)

Expand Down
2 changes: 1 addition & 1 deletion app/serializers/doi_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
15 changes: 15 additions & 0 deletions db/seeds/development/base.seeds.rb
Original file line number Diff line number Diff line change
@@ -0,0 +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") 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)
FactoryBot.create_list(:event_for_datacite_usage, 2, obj_id: dois.first.doi)
13 changes: 13 additions & 0 deletions db/seeds/development/researcher_profile.seeds.rb
Original file line number Diff line number Diff line change
@@ -0,0 +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")

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
12 changes: 10 additions & 2 deletions spec/concerns/mailable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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: "[email protected]") }
let(:client) { create(:client, symbol: "DATACITE.DATACITE", name: "DataCite Repository", system_email: "[email protected]", provider: provider) }
let(:title) { "DataCite Fabrica" }

Expand Down Expand Up @@ -50,9 +50,17 @@

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
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
Loading

0 comments on commit a41e161

Please sign in to comment.