diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index b3c4d97e6..0f4b406b4 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -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] }} diff --git a/app/controllers/contacts_controller.rb b/app/controllers/contacts_controller.rb index 93c69abf1..5bd9f6bcf 100644 --- a/app/controllers/contacts_controller.rb +++ b/app/controllers/contacts_controller.rb @@ -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, ) diff --git a/app/controllers/providers_controller.rb b/app/controllers/providers_controller.rb index 30570714e..c1b519e36 100644 --- a/app/controllers/providers_controller.rb +++ b/app/controllers/providers_controller.rb @@ -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, ) diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index c25323c1e..200ef0e07 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -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, ) diff --git a/app/models/ability.rb b/app/models/ability.rb index 1df633604..58282468b 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -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) diff --git a/app/models/client.rb b/app/models/client.rb index c9b6ea25f..1922b49c0 100644 --- a/app/models/client.rb +++ b/app/models/client.rb @@ -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) diff --git a/app/models/contact.rb b/app/models/contact.rb index 51ce40f17..94a7bd9bc 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -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 diff --git a/app/models/provider.rb b/app/models/provider.rb index e163233f3..6b16dbfd0 100644 --- a/app/models/provider.rb +++ b/app/models/provider.rb @@ -870,7 +870,7 @@ def self.export(query: nil) page_num += 1 end - { "message" => "#{total} records exported." } + { "message" => "#{total} providers exported." } end private diff --git a/spec/requests/contacts_spec.rb b/spec/requests/contacts_spec.rb index ba0629399..3508d4521 100644 --- a/spec/requests/contacts_spec.rb +++ b/spec/requests/contacts_spec.rb @@ -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 @@ -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) } @@ -78,7 +78,7 @@ before do Contact.import - sleep 1 + sleep 2 end it "returns contacts" do @@ -148,7 +148,7 @@ before do Contact.import - sleep 1 + sleep 2 end it "returns contacts" do @@ -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") @@ -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) @@ -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" => "bob@example.com", - # "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" => "bob@example.com", + "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("bob@example.com") - # 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("bob@example.com") + 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("bob@example.com") - # 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("bob@example.com") + 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