]> cat aescling's git repositories - mastodon.git/commitdiff
Allow mods to disable login, improve message when login disabled (#8329)
authorEugen Rochko <eugen@zeonfederated.com>
Thu, 23 Aug 2018 21:26:29 +0000 (23:26 +0200)
committerGitHub <noreply@github.com>
Thu, 23 Aug 2018 21:26:29 +0000 (23:26 +0200)
* Allow moderators to disable/enable login

* Instead of rejecting login, show forbidden error when login disabled

Avoid confusion because when login is rejected, the message is that
the account is not activated, which is wrong.

* Fix tests

app/controllers/api/base_controller.rb
app/controllers/application_controller.rb
app/controllers/auth/sessions_controller.rb
app/models/user.rb
app/policies/user_policy.rb
spec/models/user_spec.rb

index 770a69921a8a4da6f1bc78de85a8afc0ec005b3f..0b3735087264ce667571b8ffff8000beed15d224 100644 (file)
@@ -7,6 +7,8 @@ class Api::BaseController < ApplicationController
   include RateLimitHeaders
 
   skip_before_action :store_current_location
+  skip_before_action :check_user_permissions
+
   protect_from_forgery with: :null_session
 
   rescue_from ActiveRecord::RecordInvalid, Mastodon::ValidationError do |e|
index 7ddd26ec03c0e7264658a6dfc5562a95d5299b83..d266fa1bd37335c0d36814ac26f914861e99c342 100644 (file)
@@ -24,7 +24,7 @@ class ApplicationController < ActionController::Base
   rescue_from Mastodon::NotPermittedError, with: :forbidden
 
   before_action :store_current_location, except: :raise_not_found, unless: :devise_controller?
-  before_action :check_suspension, if: :user_signed_in?
+  before_action :check_user_permissions, if: :user_signed_in?
 
   def raise_not_found
     raise ActionController::RoutingError, "No route matches #{params[:unmatched_route]}"
@@ -48,8 +48,8 @@ class ApplicationController < ActionController::Base
     forbidden unless current_user&.staff?
   end
 
-  def check_suspension
-    forbidden if current_user.account.suspended?
+  def check_user_permissions
+    forbidden if current_user.disabled? || current_user.account.suspended?
   end
 
   def after_sign_out_path_for(_resource_or_scope)
index 2e721160bbcb0df34f80df99d75d0f652cdd7486..62b4a6377e79239900c6e6f19b26119eda4c29ce 100644 (file)
@@ -6,7 +6,7 @@ class Auth::SessionsController < Devise::SessionsController
   layout 'auth'
 
   skip_before_action :require_no_authentication, only: [:create]
-  skip_before_action :check_suspension, only: [:destroy]
+  skip_before_action :check_user_permissions, only: [:destroy]
   prepend_before_action :authenticate_with_two_factor, if: :two_factor_enabled?, only: [:create]
   before_action :set_instance_presenter, only: [:new]
   before_action :set_body_classes
index a2cf2565fd55b8b70d326cc51a6a4d36923a246a..75b7e9e7c40d84c9d7ec595c0945554eec707dd7 100644 (file)
@@ -216,10 +216,6 @@ class User < ApplicationRecord
     save!
   end
 
-  def active_for_authentication?
-    super && !disabled?
-  end
-
   def setting_default_privacy
     settings.default_privacy || (account.locked? ? 'private' : 'public')
   end
index dabdf707a4b3df7eefdb1dbae72ce2d74f7913c3..57af5c61c86b32b7cd32aacdcbde5462de9d4145 100644 (file)
@@ -18,11 +18,11 @@ class UserPolicy < ApplicationPolicy
   end
 
   def enable?
-    admin?
+    staff?
   end
 
   def disable?
-    admin? && !record.admin?
+    staff? && !record.admin?
   end
 
   def promote?
index 93a6c26fb25abfbd7709125092984d4fc1aff401..015e90edcdedef6fd471aa7605f00a5605876fad 100644 (file)
@@ -512,7 +512,7 @@ RSpec.describe User, type: :model do
       context 'when user is confirmed' do
         let(:confirmed_at) { Time.zone.now }
 
-        it { is_expected.to be false }
+        it { is_expected.to be true }
       end
 
       context 'when user is not confirmed' do