mirror of
https://github.com/ENSL/ensl.org.git
synced 2024-11-15 01:11:23 +00:00
Merge pull request #100 from Absurdon/master
Gave Gathermods simple banning permissions
This commit is contained in:
commit
7d60a90d69
3 changed files with 16 additions and 5 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
<th class="type">Type</th>
|
||||
<th class="expiry">Expiry</th>
|
||||
<th class="reason">Reason</th>
|
||||
<% if cuser and cuser.admin? %>
|
||||
<% if cuser and cuser.allowed_to_ban? %>
|
||||
<th class="actions"></th>
|
||||
<% end %>
|
||||
</tr>
|
||||
|
@ -21,7 +21,7 @@
|
|||
<td><%= ban.types[ban.ban_type] %></td>
|
||||
<td><%= shorttime ban.expiry %></td>
|
||||
<td><%= shorten ban.reason, 30 %></td>
|
||||
<% if cuser and cuser.admin? %>
|
||||
<% if cuser and cuser.allowed_to_ban? %>
|
||||
<td class="actions">
|
||||
<% if ban.can_update? cuser %>
|
||||
<%= link_to icon('pencil'), edit_ban_path(ban) %>
|
||||
|
|
Loading…
Reference in a new issue