2014-03-23 00:22:25 +00:00
|
|
|
class IssuesController < ApplicationController
|
2014-03-31 21:33:16 +00:00
|
|
|
before_filter :get_issue, only: [:show, :edit, :update, :destroy]
|
2014-03-23 00:22:25 +00:00
|
|
|
|
|
|
|
def index
|
2017-06-24 18:43:42 +00:00
|
|
|
raise AccessError unless cuser and (cuser.admin? or cuser.moderator?)
|
2014-03-23 00:22:25 +00:00
|
|
|
|
|
|
|
sort = case params['sort']
|
|
|
|
when "title" then "title"
|
|
|
|
when "status" then "status"
|
|
|
|
when "assigned" then "assigned_id"
|
|
|
|
when "category" then "category_id"
|
|
|
|
else "created_at DESC"
|
|
|
|
end
|
|
|
|
|
2017-06-24 18:43:42 +00:00
|
|
|
allowed = Issue::allowed_categories cuser
|
2017-07-03 06:50:00 +00:00
|
|
|
qstring = 'category_id IN (?)'
|
|
|
|
qstring += ' OR category_id IS NULL' if cuser.admin?
|
2017-06-24 18:43:42 +00:00
|
|
|
|
2017-07-02 20:48:33 +00:00
|
|
|
@open = Issue.where(qstring, allowed).with_status(Issue::STATUS_OPEN).all order: sort
|
|
|
|
@solved = Issue.where(qstring, allowed).with_status(Issue::STATUS_SOLVED).all order: sort
|
|
|
|
@rejected = Issue.where(qstring, allowed).with_status(Issue::STATUS_REJECTED).all order: sort
|
2014-03-23 00:22:25 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
|
|
|
raise AccessError unless @issue.can_show? cuser
|
|
|
|
@issue.read_by! cuser
|
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
|
|
|
@issue = Issue.new
|
|
|
|
raise AccessError unless @issue.can_create? cuser
|
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
|
|
|
raise AccessError unless @issue.can_update? cuser
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
|
|
@issue = Issue.new(params[:issue])
|
|
|
|
@issue.author = cuser if cuser
|
|
|
|
raise AccessError unless @issue.can_create? cuser
|
|
|
|
|
|
|
|
if @issue.save
|
|
|
|
flash[:notice] = t(:issues_create)
|
|
|
|
if cuser
|
|
|
|
redirect_to(@issue)
|
|
|
|
else
|
|
|
|
redirect_to_home
|
|
|
|
end
|
|
|
|
else
|
2014-03-31 21:33:16 +00:00
|
|
|
render :new
|
2014-03-23 00:22:25 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2017-06-24 18:43:42 +00:00
|
|
|
raise AccessError unless @issue.can_update?(cuser, params[:issue])
|
2014-03-23 00:22:25 +00:00
|
|
|
if @issue.update_attributes(params[:issue])
|
|
|
|
flash[:notice] = t(:issues_update)
|
|
|
|
redirect_to(@issue)
|
|
|
|
else
|
2014-03-31 21:33:16 +00:00
|
|
|
render :edit
|
2014-03-23 00:22:25 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
raise AccessError unless @issue.can_destroy? cuser
|
|
|
|
@issue.destroy
|
|
|
|
redirect_to(issues_url)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def get_issue
|
|
|
|
@issue = Issue.find params[:id]
|
|
|
|
end
|
|
|
|
end
|