2011-12-19 15:30:14 +00:00
|
|
|
class IssuesController < ApplicationController
|
|
|
|
before_filter :authenticate_user!
|
2011-12-21 14:48:16 +00:00
|
|
|
before_filter :find_project, :except => [:destroy]
|
|
|
|
before_filter :find_issue_by_serial_id, :only => [:show, :edit]
|
2011-12-19 15:30:14 +00:00
|
|
|
|
2011-12-21 14:48:16 +00:00
|
|
|
load_and_authorize_resource :except => [:show, :edit, :index]
|
|
|
|
authorize_resource :only => [:show, :edit]
|
|
|
|
#authorize_resource :through => :project, :only => [:index], :shallow => true
|
|
|
|
authorize_resource :project, :only => [:index]
|
2011-12-19 15:30:14 +00:00
|
|
|
autocomplete :user, :uname
|
|
|
|
|
2011-12-20 16:57:34 +00:00
|
|
|
def show
|
|
|
|
end
|
|
|
|
|
2011-12-19 15:30:14 +00:00
|
|
|
def index
|
|
|
|
@issues = @project.issues.paginate :per_page => 10, :page => params[:page]
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
|
|
@user_id = params[:user_id]
|
|
|
|
@user_uname = params[:user_uname]
|
|
|
|
|
|
|
|
@issue = Issue.new(params[:issue])
|
|
|
|
@issue.user_id = @user_id
|
|
|
|
@issue.project_id = @project.id
|
|
|
|
if @issue.save!
|
|
|
|
flash[:notice] = I18n.t("flash.issue.saved")
|
|
|
|
redirect_to project_issues_path(@project)
|
|
|
|
else
|
|
|
|
flash[:error] = I18n.t("flash.issue.saved_error")
|
|
|
|
render :action => :new
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-12-21 14:48:16 +00:00
|
|
|
def edit
|
|
|
|
@user_id = @issue.user_id
|
|
|
|
@user_uname = @issue.user.uname
|
|
|
|
end
|
|
|
|
|
2011-12-19 15:30:14 +00:00
|
|
|
def update
|
|
|
|
@user_id = params[:user_id]
|
|
|
|
@user_uname = params[:user_uname]
|
|
|
|
|
|
|
|
if @issue.update_attributes( params[:issue].merge({:user_id => @user_id}) )
|
|
|
|
flash[:notice] = I18n.t("flash.issue.saved")
|
2011-12-21 14:48:16 +00:00
|
|
|
redirect_to show_issue_path(@project, @issue.serial_id)
|
2011-12-19 15:30:14 +00:00
|
|
|
else
|
|
|
|
flash[:error] = I18n.t("flash.issue.saved_error")
|
|
|
|
render :action => :new
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
@issue.destroy
|
|
|
|
|
|
|
|
flash[:notice] = t("flash.issue.destroyed")
|
|
|
|
redirect_to root_path
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def find_project
|
|
|
|
@project = Project.find(params[:project_id])
|
|
|
|
end
|
|
|
|
|
2011-12-21 14:48:16 +00:00
|
|
|
def find_issue_by_serial_id
|
|
|
|
@issue = @project.issues.where(:serial_id => params[:serial_id])[0]
|
2011-12-19 15:30:14 +00:00
|
|
|
end
|
|
|
|
end
|