From: Anton Khorev Date: Thu, 5 Sep 2024 20:21:24 +0000 (+0300) Subject: Remove nil ApiCapability user branch X-Git-Tag: live~230^2 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/e7fb89c8d016d01accb8714c138ba1ff89e5dce8 Remove nil ApiCapability user branch --- diff --git a/app/abilities/api_capability.rb b/app/abilities/api_capability.rb index 2035afff9..07345d254 100644 --- a/app/abilities/api_capability.rb +++ b/app/abilities/api_capability.rb @@ -5,7 +5,7 @@ class ApiCapability def initialize(token) if Settings.status != "database_offline" - user = (User.find(token.resource_owner_id) if token.respond_to?(:resource_owner_id)) + user = User.find(token.resource_owner_id) if user&.active? can [:create, :comment, :close, :reopen], Note if scope?(token, :write_notes) diff --git a/test/abilities/api_capability_test.rb b/test/abilities/api_capability_test.rb index bcfcaf74e..5e8396c67 100644 --- a/test/abilities/api_capability_test.rb +++ b/test/abilities/api_capability_test.rb @@ -88,12 +88,6 @@ end class UserApiCapabilityTest < ActiveSupport::TestCase test "user preferences" do - # a user with no tokens - capability = ApiCapability.new nil - [:index, :show, :update_all, :update, :destroy].each do |act| - assert capability.cannot? act, UserPreference - end - # A user with empty tokens token = create(:oauth_access_token) capability = ApiCapability.new token