From b1f72dbd4a3db1326a1a80bc441087bd0e27a5d0 Mon Sep 17 00:00:00 2001 From: Martin Fenner Date: Tue, 15 Dec 2020 10:51:29 +0100 Subject: [PATCH] fix permissions for domains attribute. #687 --- app/serializers/client_serializer.rb | 13 +++++++++++++ app/serializers/repository_serializer.rb | 13 +++++++++++++ spec/requests/clients_spec.rb | 3 +-- 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/app/serializers/client_serializer.rb b/app/serializers/client_serializer.rb index 52469376b..19582fa38 100644 --- a/app/serializers/client_serializer.rb +++ b/app/serializers/client_serializer.rb @@ -48,6 +48,19 @@ class ClientSerializer object.password.present? end + attribute :domains, + if: + Proc.new { |object, params| + params[:current_ability] && + params[:current_ability].can?( + :read_contact_information, + object, + ) == + true + } do |object| + object.domains + end + attribute :contact_email, if: Proc.new { |object, params| diff --git a/app/serializers/repository_serializer.rb b/app/serializers/repository_serializer.rb index 007b2e260..c986c4f07 100644 --- a/app/serializers/repository_serializer.rb +++ b/app/serializers/repository_serializer.rb @@ -43,6 +43,19 @@ class RepositorySerializer object.is_active.getbyte(0) == 1 end + attribute :domains, + if: + Proc.new { |object, params| + params[:current_ability] && + params[:current_ability].can?( + :read_contact_information, + object, + ) == + true + } do |object| + object.domains + end + attribute :has_password, if: Proc.new { |object, params| diff --git a/spec/requests/clients_spec.rb b/spec/requests/clients_spec.rb index fb50a0b96..cc28a63f1 100644 --- a/spec/requests/clients_spec.rb +++ b/spec/requests/clients_spec.rb @@ -297,7 +297,7 @@ before do ProviderPrefix.import - sleep 2 + sleep 3 end it "updates the record" do @@ -332,7 +332,6 @@ ).to eq(client.symbol.downcase) get "provider-prefixes?query=#{prefix.uid}" - puts json expect( json.dig("meta", "total"), ).to eq(1)