Skip to content

Commit 37ab429

Browse files
committed
Fix user banning
1 parent 60a19c1 commit 37ab429

5 files changed

+6
-7
lines changed

app/controllers/application_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ def render_500
195195
end
196196

197197
def require_admin!
198-
return head(:forbidden) unless signed_in? && current_user.admin?
198+
return head(:forbidden) unless is_admin?
199199
end
200200

201201
def is_admin?

app/controllers/bans_controller.rb

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
class BansController < BaseAdminController
2-
32
def create
43
ban_params = params.permit(:user_id)
54
user = User.find(ban_params[:user_id])
65
return redirect_to(badge_url(username: user.username), notice: 'User is already banned.') if user.banned?
76

8-
flash_notice = if Banning::UserBanner.ban(user)
9-
Banning::DeindexUserProtips.run(user)
7+
flash_notice = if UserBannerService.ban(user)
108
'User successfully banned.'
119
else
1210
'User could not be banned.'
1311
end
1412
redirect_to(badge_url(username: user.username), notice: flash_notice)
1513
end
16-
1714
end

app/services/deindex_user_protips_service.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
class DeindexUserProtipsService
1+
module DeindexUserProtipsService
22
def self.run(user)
33
user.protips.each do |tip|
44
ProtipIndexer.new(tip).remove

app/services/index_user_protips_service.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
class IndexUserProtipsService
1+
module IndexUserProtipsService
22
def self.run(user)
33
user.protips.each do |tip|
44
ProtipIndexer.new(tip).store

app/services/user_banner_service.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
class UserBannerService
22
def self.ban(user)
33
user.update_attribute(:banned_at, Time.now.utc)
4+
DeindexUserProtipsService.run(user)
45
end
56

67
def self.unban(user)
78
user.update_attribute(:banned_at, nil)
9+
IndexUserProtipsService.run(user)
810
end
911
end

0 commit comments

Comments
 (0)