Skip to content

Commit

Permalink
Merge branch 'master' of github.com:datacite/lupo
Browse files Browse the repository at this point in the history
  • Loading branch information
richardhallett committed Mar 30, 2021
2 parents 10675e8 + 615c066 commit 76d2029
Show file tree
Hide file tree
Showing 9 changed files with 106 additions and 102 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ jobs:
uses: actions/setup-ruby@v1
with:
ruby-version: '2.6.x'
# - uses: actions/cache@v2
# with:
# path: vendor/bundle
# key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}
# restore-keys: |
# ${{ runner.os }}-gems-
- uses: actions/cache@v2
with:
path: vendor/bundle
key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }}
restore-keys: |
${{ runner.os }}-gems-
- name: Install
env:
MYSQL_PORT: ${{ job.services.mysql.ports[3306] }}
Expand Down
1 change: 1 addition & 0 deletions app/controllers/contacts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def index
role_name: params[:role_name],
provider_id: params[:provider_id],
consortium_id: params[:consortium_id],
include_deleted: params[:include_deleted],
page: page,
sort: sort,
)
Expand Down
1 change: 1 addition & 0 deletions app/controllers/providers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def index
organization_type: params[:organization_type],
focus_area: params[:focus_area],
non_profit_status: params[:non_profit_status],
include_deleted: params[:include_deleted],
page: page,
sort: sort,
)
Expand Down
1 change: 1 addition & 0 deletions app/controllers/repositories_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def index
certificate: params[:certificate],
repository_type: params[:repository_type],
client_type: params[:client_type],
include_deleted: params[:include_deleted],
page: page,
sort: sort,
)
Expand Down
11 changes: 6 additions & 5 deletions app/models/ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,12 @@ def initialize(user)
provider_prefix.provider &&
user.provider_id.casecmp(provider_prefix.provider.consortium_id)
end
can %i[manage], Contact do |contact|
contact.provider &&
(user.provider_id.casecmp(contact.provider.consortium_id) ||
user.provider_id.casecmp(contact.provider_id))
end
can %i[manage], Contact
# TODO limit contact management to consortium
# contact.provider &&
# (user.provider_id.casecmp(contact.provider.consortium_id) ||
# user.provider_id.casecmp(contact.provider_id))
# end
can %i[manage transfer read_contact_information], Client do |client|
client.provider &&
user.provider_id.casecmp(client.provider.consortium_id)
Expand Down
2 changes: 1 addition & 1 deletion app/models/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ def self.export(query: nil)
page_num += 1
end

{ "message" => "#{total} records exported." }
{ "message" => "#{total} clients exported." }
end

def self.export_doi_counts(query: nil)
Expand Down
2 changes: 1 addition & 1 deletion app/models/contact.rb
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ def self.export(query: nil)
page_num += 1
end

{ "message" => "#{total} records exported." }
{ "message" => "#{total} contacts exported." }
end

def self.import_from_providers
Expand Down
2 changes: 1 addition & 1 deletion app/models/provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -870,7 +870,7 @@ def self.export(query: nil)
page_num += 1
end

{ "message" => "#{total} records exported." }
{ "message" => "#{total} providers exported." }
end

private
Expand Down
176 changes: 88 additions & 88 deletions spec/requests/contacts_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,26 @@
require "rails_helper"

describe ContactsController, type: :request, elasticsearch: true do
let(:consortium) { create(:provider, name: "DC", role_name: "ROLE_CONSORTIUM") }
let(:consortium) { create(:provider, role_name: "ROLE_CONSORTIUM") }
let(:provider) do
create(
:provider,
consortium: consortium, role_name: "ROLE_CONSORTIUM_ORGANIZATION",
consortium: consortium,
symbol: "ABC",
role_name: "ROLE_CONSORTIUM_ORGANIZATION",
password_input: "12345",
)
end
let(:bearer) do
User.generate_token(
role_id: "provider_admin", provider_id: provider.uid,
)
end
let(:consortium_bearer) do
User.generate_token(
role_id: "consortium_admin", provider_id: consortium.uid,
)
end
let(:bearer) { User.generate_token }
let(:provider_bearer) { User.generate_token(
role_id: "provider_admin", provider_id: provider.uid,
) }
let(:consortium_bearer) { User.generate_token(
role_id: "consortium_admin", provider_id: consortium.uid,
) }
let!(:service_contact) { create(:contact, provider: provider, role_name: ["service"]) }
let!(:contact) { create(:contact, provider: provider, role_name: ["billing"]) }
let(:params) do
Expand Down Expand Up @@ -49,12 +55,6 @@
"HTTP_AUTHORIZATION" => "Bearer " + consortium_bearer,
}
end
let(:provider_headers) do
{
"HTTP_ACCEPT" => "application/vnd.api+json",
"HTTP_AUTHORIZATION" => "Bearer " + provider_bearer,
}
end

describe "GET /contacts", elasticsearch: true do
let!(:contacts) { create_list(:contact, 3) }
Expand All @@ -78,7 +78,7 @@

before do
Contact.import
sleep 1
sleep 2
end

it "returns contacts" do
Expand Down Expand Up @@ -148,7 +148,7 @@

before do
Contact.import
sleep 1
sleep 2
end

it "returns contacts" do
Expand Down Expand Up @@ -219,7 +219,7 @@

context "when the request is valid provider_admin" do
it "creates a contact" do
post "/contacts", params, provider_headers
post "/contacts", params, headers

expect(last_response.status).to eq(201)
attributes = json.dig("data", "attributes")
Expand All @@ -233,7 +233,7 @@
Contact.import
sleep 2

get "/contacts", nil, provider_headers
get "/contacts", nil, headers

expect(last_response.status).to eq(200)
expect(json.dig("data").length).to eq(3)
Expand All @@ -250,90 +250,90 @@
end
end

# context "when the request is valid consortium_admin" do
# let(:params) do
# {
# "data" => {
# "type" => "contacts",
# "attributes" => {
# "givenName" => "Josiah",
# "familyName" => "Carberry",
# "email" => "[email protected]",
# "roleName" => ["voting"]
# },
# "relationships": {
# "provider": {
# "data": { "type": "providers", "id": consortium.uid },
# }
# },
# },
# }
# end

# it "creates a contact" do
# post "/contacts", params, consortium_headers
context "when the request is valid consortium_admin" do
let(:params) do
{
"data" => {
"type" => "contacts",
"attributes" => {
"givenName" => "Josiah",
"familyName" => "Carberry",
"email" => "[email protected]",
"roleName" => ["voting"]
},
"relationships": {
"provider": {
"data": { "type": "providers", "id": consortium.uid },
}
},
},
}
end

# expect(last_response.status).to eq(201)
# attributes = json.dig("data", "attributes")
# expect(attributes["name"]).to eq("Josiah Carberry")
# expect(attributes["email"]).to eq("[email protected]")
# expect(attributes["roleName"]).to eq(["voting"])
it "creates a contact" do
post "/contacts", params, consortium_headers
puts last_response.body
expect(last_response.status).to eq(201)
attributes = json.dig("data", "attributes")
expect(attributes["name"]).to eq("Josiah Carberry")
expect(attributes["email"]).to eq("[email protected]")
expect(attributes["roleName"]).to eq(["voting"])

# relationships = json.dig("data", "relationships")
# expect(relationships).to eq("provider" => { "data" => { "id" => consortium.uid, "type" => "providers" } })
relationships = json.dig("data", "relationships")
expect(relationships).to eq("provider" => { "data" => { "id" => consortium.uid, "type" => "providers" } })

# Contact.import
# sleep 2
Contact.import
sleep 2

# get "/contacts", nil, consortium_headers
get "/contacts", nil, consortium_headers

# expect(last_response.status).to eq(200)
# expect(json.dig("data").length).to eq(3)
expect(last_response.status).to eq(200)
expect(json.dig("data").length).to eq(3)

# attributes = json.dig("data", 1, "attributes")
# expect(attributes["name"]).to eq("Josiah Carberry")
# expect(attributes["email"]).to start_with("josiah")
# expect(attributes["roleName"]).to eq(["billing"])
attributes = json.dig("data", 1, "attributes")
expect(attributes["name"]).to eq("Josiah Carberry")
expect(attributes["email"]).to start_with("josiah")
expect(attributes["roleName"]).to eq(["billing"])

# relationships = json.dig("data", 1, "relationships")
# expect(relationships.dig("provider", "data", "id")).to eq(
# consortium.uid,
# )
# end
# end
relationships = json.dig("data", 1, "relationships")
expect(relationships.dig("provider", "data", "id")).to eq(
provider.uid,
)
end
end

# context "when the request is valid consortium_admin for provider" do
# it "creates a contact" do
# post "/contacts", params, consortium_headers
context "when the request is valid consortium_admin for provider" do
it "creates a contact" do
post "/contacts", params, consortium_headers

# expect(last_response.status).to eq(201)
# attributes = json.dig("data", "attributes")
# expect(attributes["name"]).to eq("Josiah Carberry")
# expect(attributes["email"]).to eq("[email protected]")
# expect(attributes["roleName"]).to eq(["voting"])
expect(last_response.status).to eq(201)
attributes = json.dig("data", "attributes")
expect(attributes["name"]).to eq("Josiah Carberry")
expect(attributes["email"]).to eq("[email protected]")
expect(attributes["roleName"]).to eq(["voting"])

# relationships = json.dig("data", "relationships")
# expect(relationships).to eq("provider" => { "data" => { "id" => provider.uid, "type" => "providers" } })
relationships = json.dig("data", "relationships")
expect(relationships).to eq("provider" => { "data" => { "id" => provider.uid, "type" => "providers" } })

# Contact.import
# sleep 2
Contact.import
sleep 2

# get "/contacts", nil, consortium_headers
get "/contacts", nil, consortium_headers

# expect(last_response.status).to eq(200)
# expect(json.dig("data").length).to eq(3)
expect(last_response.status).to eq(200)
expect(json.dig("data").length).to eq(3)

# attributes = json.dig("data", 1, "attributes")
# expect(attributes["name"]).to eq("Josiah Carberry")
# expect(attributes["email"]).to start_with("josiah")
# expect(attributes["roleName"]).to eq(["billing"])
attributes = json.dig("data", 1, "attributes")
expect(attributes["name"]).to eq("Josiah Carberry")
expect(attributes["email"]).to start_with("josiah")
expect(attributes["roleName"]).to eq(["billing"])

# relationships = json.dig("data", 1, "relationships")
# expect(relationships.dig("provider", "data", "id")).to eq(
# consortium.uid,
# )
# end
# end
relationships = json.dig("data", 1, "relationships")
expect(relationships.dig("provider", "data", "id")).to eq(
provider.uid,
)
end
end

context "when the request is invalid" do
let(:params) do
Expand Down

0 comments on commit 76d2029

Please sign in to comment.