From 25256a484914ee40d829d9184fb4107dd0a77d44 Mon Sep 17 00:00:00 2001 From: Chris Flipse Date: Sun, 17 Jun 2018 20:27:17 -0400 Subject: [PATCH] Make rubocop happy --- Gemfile | 2 +- app/controllers/application_controller.rb | 2 +- app/controllers/diary_entry_controller.rb | 2 -- app/models/ability.rb | 4 +--- app/models/capability.rb | 8 +++++--- test/models/abilities_test.rb | 6 ------ test/test_helper.rb | 1 - 7 files changed, 8 insertions(+), 17 deletions(-) diff --git a/Gemfile b/Gemfile index 8b8eae0bb..a385851ff 100644 --- a/Gemfile +++ b/Gemfile @@ -42,6 +42,7 @@ gem "image_optim_rails" # Load rails plugins gem "actionpack-page_caching" +gem "cancancan" gem "composite_primary_keys", "~> 10.0.0" gem "dynamic_form" gem "http_accept_language", "~> 2.0.0" @@ -54,7 +55,6 @@ gem "rails-i18n", "~> 4.0.0" gem "record_tag_helper" gem "rinku", ">= 1.2.2", :require => "rails_rinku" gem "validates_email_format_of", ">= 1.5.1" -gem "cancancan" # Native OSM extensions gem "quad_tile", "~> 1.0.1" diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 2be8c1637..eed183893 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -478,7 +478,7 @@ class ApplicationController < ActionController::Base Capability.new(current_user, current_token) end - def deny_access(exception) + def deny_access(_exception) if current_user set_locale report_error t("oauth.permissions.missing"), :forbidden diff --git a/app/controllers/diary_entry_controller.rb b/app/controllers/diary_entry_controller.rb index ff8758990..6e9268008 100644 --- a/app/controllers/diary_entry_controller.rb +++ b/app/controllers/diary_entry_controller.rb @@ -11,7 +11,6 @@ class DiaryEntryController < ApplicationController before_action :check_database_writable, :only => [:new, :edit, :comment, :hide, :hidecomment, :subscribe, :unsubscribe] before_action :allow_thirdparty_images, :only => [:new, :edit, :list, :view, :comments] - def new @title = t "diary_entry.new.title" @@ -247,7 +246,6 @@ class DiaryEntryController < ApplicationController params.require(:diary_comment).permit(:body) end - ## # decide on a location for the diary entry map def set_map_location diff --git a/app/models/ability.rb b/app/models/ability.rb index 2f86ea412..5be0b37e5 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -17,9 +17,7 @@ class Ability can [:create, :edit, :comment, :subscribe, :unsubscribe], DiaryEntry - if user.administrator? - can [:hide, :hidecomment], [DiaryEntry, DiaryComment] - end + can [:hide, :hidecomment], [DiaryEntry, DiaryComment] if user.administrator? end # Define abilities for the passed in user here. For example: # diff --git a/app/models/capability.rb b/app/models/capability.rb index 174687503..db2d71711 100644 --- a/app/models/capability.rb +++ b/app/models/capability.rb @@ -5,15 +5,17 @@ class Capability def initialize(user, token) if user - can [:read, :read_one], UserPreference if has_capability?(token, :allow_read_prefs) - can [:update, :update_one, :delete_one], UserPreference if has_capability?(token, :allow_write_prefs) + can [:read, :read_one], UserPreference if capability?(token, :allow_read_prefs) + can [:update, :update_one, :delete_one], UserPreference if capability?(token, :allow_write_prefs) end end + private + # If a user provides no tokens, they've authenticated via a non-oauth method # and permission to access to all capabilities is assumed. - def has_capability?(token, cap) + def capability?(token, cap) token.nil? || token.read_attribute(cap) end end diff --git a/test/models/abilities_test.rb b/test/models/abilities_test.rb index 77c14f40f..28a5c7fd9 100644 --- a/test/models/abilities_test.rb +++ b/test/models/abilities_test.rb @@ -6,7 +6,6 @@ class AbilityTest < ActiveSupport::TestCase end class GuestAbilityTest < AbilityTest - test "geocoder permission for a guest" do ability = Ability.new nil @@ -27,11 +26,9 @@ class GuestAbilityTest < AbilityTest assert ability.cannot?(action, DiaryComment), "should be able to #{action} DiaryEntries" end end - end class UserAbilityTest < AbilityTest - test "Diary permissions" do ability = Ability.new create(:user) @@ -47,7 +44,6 @@ class UserAbilityTest < AbilityTest end class AdministratorAbilityTest < AbilityTest - test "Diary for an administrator" do ability = Ability.new create(:administrator_user) [:list, :rss, :view, :comments, :create, :edit, :comment, :subscribe, :unsubscribe, :hide, :hidecomment].each do |action| @@ -66,6 +62,4 @@ class AdministratorAbilityTest < AbilityTest assert ability.cannot? act, UserPreference end end - - end diff --git a/test/test_helper.rb b/test/test_helper.rb index 39e8cdd05..df88a6ee0 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -95,7 +95,6 @@ module ActiveSupport end end - ## # set request readers to ask for a particular error format def error_format(format) -- 2.39.5