gave gathermods the possibility to respond to gather issues

This commit is contained in:
Absurdon 2017-06-24 20:43:42 +02:00
parent 313500c257
commit 8579d0b569
5 changed files with 46 additions and 15 deletions

View file

@ -2,7 +2,7 @@ class IssuesController < ApplicationController
before_filter :get_issue, only: [:show, :edit, :update, :destroy]
def index
raise AccessError unless cuser and cuser.admin?
raise AccessError unless cuser and (cuser.admin? or cuser.moderator?)
sort = case params['sort']
when "title" then "title"
@ -12,9 +12,11 @@ class IssuesController < ApplicationController
else "created_at DESC"
end
@open = Issue.with_status(Issue::STATUS_OPEN).all order: sort
@solved = Issue.with_status(Issue::STATUS_SOLVED).all order: sort
@rejected = Issue.with_status(Issue::STATUS_REJECTED).all order: sort
allowed = Issue::allowed_categories cuser
@open = Issue.where(category_id: allowed).with_status(Issue::STATUS_OPEN).all order: sort
@solved = Issue.where(category_id: allowed).with_status(Issue::STATUS_SOLVED).all order: sort
@rejected = Issue.where(category_id: allowed).with_status(Issue::STATUS_REJECTED).all order: sort
end
def show
@ -49,7 +51,7 @@ class IssuesController < ApplicationController
end
def update
raise AccessError unless @issue.can_update? cuser
raise AccessError unless @issue.can_update?(cuser, params[:issue])
if @issue.update_attributes(params[:issue])
flash[:notice] = t(:issues_update)
redirect_to(@issue)

View file

@ -96,18 +96,36 @@ class Issue < ActiveRecord::Base
end
def can_show? cuser
cuser and !cuser.nil? and ((author == cuser) or cuser.admin?)
cuser and ((author == cuser) or (Issue::allowed_categories(cuser).include?(self.category_id)))
end
def can_create? cuser
true
end
def can_update? cuser
cuser and cuser.admin?
def can_update?(cuser, params = {})
ret = cuser && Issue::allowed_categories(cuser).include?(self.category_id)
if ret && !cuser.admin? && params.member?(:category_id)
ret = (self.category_id.to_s == params[:category_id])
end
ret
end
def can_destroy? cuser
cuser and cuser.admin?
end
# STATIC METHODS
def self.allowed_categories cuser
allowed = []
allowed << 54 if cuser.admin? || cuser.gather_moderator? # gather
allowed << 17 if cuser.admin? # website
allowed << 22 if cuser.admin? # league
allowed << 20 if cuser.admin? # ensl plugin
allowed
end
end

View file

@ -190,19 +190,24 @@ class User < ActiveRecord::Base
end
def admin?
groups.exists? :id => Group::ADMINS
groups.exists? id: Group::ADMINS
end
def ref?
groups.exists? :id => Group::REFEREES
groups.exists? id: Group::REFEREES
end
def staff?
groups.exists? :id => Group::STAFF
groups.exists? id: Group::STAFF
end
def caster?
groups.exists? :id => Group::CASTERS
groups.exists? id: Group::CASTERS
end
# might seem redundant but allows for later extensions like forum moderators
def moderator?
groups.exists? id: Group::GATHER_MODERATORS
end
def gather_moderator?
@ -210,7 +215,7 @@ class User < ActiveRecord::Base
end
def allowed_to_ban?
admin? or gather_moderator?
admin? or moderator?
end
def verified?

View file

@ -4,7 +4,7 @@
<%= f.label :title %>
<%= f.text_field :title %>
</div>
<% if cuser and cuser.admin? %>
<% if cuser and Issue::allowed_categories(cuser).include?(@issue.category_id) %>
<div class="fields horizontal">
<%= f.label :status %>
<%= f.select :status, @issue.statuses.invert %>
@ -22,7 +22,7 @@
<%= f.label :text %>
<%= f.text_area :text, rows: 7 %>
</div>
<% if cuser and cuser.admin? %>
<% if cuser and Issue::allowed_categories(cuser).include?(@issue.category_id) %>
<div class="fields horizontal">
<%= f.label :solution %>
<%= f.text_area :solution, rows: 7 %>

View file

@ -7,6 +7,12 @@
Admin (<%= Issue.with_status(0).count %>) <%= icon 'wrench' %>
<% end %>
</li>
<% elsif cuser.moderator? %>
<li>
<%= link_to issues_path, class: 'admin' do %>
Issues (<%= Issue.where(category_id: Issue.allowed_categories(cuser)).with_status(0).count %>) <%= icon 'wrench' %>
<% end %>
</li>
<% end %>
<li>
<%= link_to user_path(cuser) do %>