mirror of
https://github.com/ENSL/ensl.org.git
synced 2025-01-29 12:40:44 +00:00
Merge pull request #100 from Absurdon/master
Gave Gathermods simple banning permissions
This commit is contained in:
commit
dc4ee1c28f
3 changed files with 16 additions and 5 deletions
|
@ -37,6 +37,7 @@ class Ban < ActiveRecord::Base
|
||||||
|
|
||||||
validate :validate_type
|
validate :validate_type
|
||||||
validate :validate_ventban
|
validate :validate_ventban
|
||||||
|
validate :validate_permission
|
||||||
validates :steamid, length: {maximum: 14}, format: /\A0:[01]:[0-9]{1,10}\Z/, allow_blank: true
|
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 :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
|
validates :reason, length: {maximum: 255}, allow_blank: true
|
||||||
|
@ -69,6 +70,12 @@ class Ban < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
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
|
def check_user
|
||||||
if user_name
|
if user_name
|
||||||
self.user = User.find_by_username(user_name)
|
self.user = User.find_by_username(user_name)
|
||||||
|
@ -79,14 +86,14 @@ class Ban < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def can_create? cuser
|
def can_create? cuser
|
||||||
cuser and cuser.admin?
|
cuser and cuser.allowed_to_ban?
|
||||||
end
|
end
|
||||||
|
|
||||||
def can_update? cuser
|
def can_update? cuser
|
||||||
cuser and cuser.admin?
|
cuser and (cuser.admin? or (self.creator == cuser and cuser.allowed_to_ban?))
|
||||||
end
|
end
|
||||||
|
|
||||||
def can_destroy? cuser
|
def can_destroy? cuser
|
||||||
cuser and cuser.admin?
|
cuser and (cuser.admin? or (self.creator == cuser and cuser.allowed_to_ban?))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -209,6 +209,10 @@ class User < ActiveRecord::Base
|
||||||
groups.exists? id: Group::GATHER_MODERATORS
|
groups.exists? id: Group::GATHER_MODERATORS
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def allowed_to_ban?
|
||||||
|
admin? or gather_moderator?
|
||||||
|
end
|
||||||
|
|
||||||
def verified?
|
def verified?
|
||||||
# created_at < DateTime.now.ago(VERIFICATION_TIME)
|
# created_at < DateTime.now.ago(VERIFICATION_TIME)
|
||||||
true
|
true
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
<th class="type">Type</th>
|
<th class="type">Type</th>
|
||||||
<th class="expiry">Expiry</th>
|
<th class="expiry">Expiry</th>
|
||||||
<th class="reason">Reason</th>
|
<th class="reason">Reason</th>
|
||||||
<% if cuser and cuser.admin? %>
|
<% if cuser and cuser.allowed_to_ban? %>
|
||||||
<th class="actions"></th>
|
<th class="actions"></th>
|
||||||
<% end %>
|
<% end %>
|
||||||
</tr>
|
</tr>
|
||||||
|
@ -21,7 +21,7 @@
|
||||||
<td><%= ban.types[ban.ban_type] %></td>
|
<td><%= ban.types[ban.ban_type] %></td>
|
||||||
<td><%= shorttime ban.expiry %></td>
|
<td><%= shorttime ban.expiry %></td>
|
||||||
<td><%= shorten ban.reason, 30 %></td>
|
<td><%= shorten ban.reason, 30 %></td>
|
||||||
<% if cuser and cuser.admin? %>
|
<% if cuser and cuser.allowed_to_ban? %>
|
||||||
<td class="actions">
|
<td class="actions">
|
||||||
<% if ban.can_update? cuser %>
|
<% if ban.can_update? cuser %>
|
||||||
<%= link_to icon('pencil'), edit_ban_path(ban) %>
|
<%= link_to icon('pencil'), edit_ban_path(ban) %>
|
||||||
|
|
Loading…
Reference in a new issue