From 39758ff86c591454492e856129e72306601c3a9e Mon Sep 17 00:00:00 2001 From: Absurdon Date: Mon, 6 Mar 2017 02:33:12 +0100 Subject: [PATCH] Gave Gathermods simple banning permissions --- app/models/ban.rb | 13 ++++++++++--- app/models/user.rb | 4 ++++ app/views/bans/_list.html.erb | 4 ++-- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/app/models/ban.rb b/app/models/ban.rb index 936173e..b0f721d 100755 --- a/app/models/ban.rb +++ b/app/models/ban.rb @@ -37,6 +37,7 @@ class Ban < ActiveRecord::Base validate :validate_type validate :validate_ventban + validate :validate_permission validates :steamid, length: {maximum: 14}, format: /\A0:[01]:[0-9]{1,10}\Z/, allow_blank: true validates :addr, format: /\A([0-9]{1,3}\.){3}[0-9]{1,3}:?[0-9]{0,5}\z/, allow_blank: true validates :reason, length: {maximum: 255}, allow_blank: true @@ -69,6 +70,12 @@ class Ban < ActiveRecord::Base end end + def validate_permission + unless creator.admin? or (creator.gather_moderator? and self.ban_type == TYPE_GATHER) + errors.add :ban_type, 'Gather Moderators can only create gather bans' + end + end + def check_user if user_name self.user = User.find_by_username(user_name) @@ -79,14 +86,14 @@ class Ban < ActiveRecord::Base end def can_create? cuser - cuser and cuser.admin? + cuser and cuser.allowed_to_ban? end def can_update? cuser - cuser and cuser.admin? + cuser and (cuser.admin? or (self.creator == cuser and cuser.allowed_to_ban?)) end def can_destroy? cuser - cuser and cuser.admin? + cuser and (cuser.admin? or (self.creator == cuser and cuser.allowed_to_ban?)) end end diff --git a/app/models/user.rb b/app/models/user.rb index 1d28615..db83fea 100755 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -209,6 +209,10 @@ class User < ActiveRecord::Base groups.exists? id: Group::GATHER_MODERATORS end + def allowed_to_ban? + admin? or gather_moderator? + end + def verified? # created_at < DateTime.now.ago(VERIFICATION_TIME) true diff --git a/app/views/bans/_list.html.erb b/app/views/bans/_list.html.erb index f3d7ddd..52ad151 100644 --- a/app/views/bans/_list.html.erb +++ b/app/views/bans/_list.html.erb @@ -4,7 +4,7 @@ Type Expiry Reason - <% if cuser and cuser.admin? %> + <% if cuser and cuser.allowed_to_ban? %> <% end %> @@ -21,7 +21,7 @@ <%= ban.types[ban.ban_type] %> <%= shorttime ban.expiry %> <%= shorten ban.reason, 30 %> - <% if cuser and cuser.admin? %> + <% if cuser and cuser.allowed_to_ban? %> <% if ban.can_update? cuser %> <%= link_to icon('pencil'), edit_ban_path(ban) %>