2012-01-30 20:39:34 +00:00
|
|
|
# -*- encoding : utf-8 -*-
|
2012-05-02 10:18:07 +01:00
|
|
|
class Projects::IssuesController < Projects::BaseController
|
2012-08-20 18:37:22 +01:00
|
|
|
NON_RESTFUL_ACTION = [:create_label, :update_label, :destroy_label]
|
2011-12-19 15:30:14 +00:00
|
|
|
before_filter :authenticate_user!
|
2012-03-31 00:37:54 +01:00
|
|
|
skip_before_filter :authenticate_user!, :only => [:index, :show] if APP_CONFIG['anonymous_access']
|
2012-03-02 17:38:00 +00:00
|
|
|
load_resource :project
|
2012-05-30 17:03:07 +01:00
|
|
|
load_and_authorize_resource :issue, :through => :project, :find_by => :serial_id, :only => [:show, :edit, :update, :destroy, :new, :create, :index]
|
2012-02-27 16:10:12 +00:00
|
|
|
before_filter :load_and_authorize_label, :only => NON_RESTFUL_ACTION
|
2013-03-21 21:20:36 +00:00
|
|
|
before_filter :find_collaborators, :only => [:new, :create, :show, :search_collaborators]
|
2011-12-19 15:30:14 +00:00
|
|
|
|
2012-08-25 17:01:49 +01:00
|
|
|
layout false, :only => [:update, :search_collaborators]
|
2011-12-19 15:30:14 +00:00
|
|
|
|
2012-02-23 14:48:31 +00:00
|
|
|
def index(status = 200)
|
|
|
|
@labels = params[:labels] || []
|
2012-09-26 12:46:23 +01:00
|
|
|
@issues = @project.issues.without_pull_requests
|
2013-04-29 19:13:45 +01:00
|
|
|
@issues = @issues.where(:assignee_id => current_user.id) if @is_assigned_to_me = params[:filter] == 'assigned'
|
2012-02-23 14:48:31 +00:00
|
|
|
@issues = @issues.joins(:labels).where(:labels => {:name => @labels}) unless @labels == []
|
2012-08-27 10:43:44 +01:00
|
|
|
# Using mb_chars for correct transform to lowercase ('Русский Текст'.downcase => "Русский Текст")
|
2013-03-19 15:30:50 +00:00
|
|
|
@issues = @issues.search(params[:search_issue]) if params[:search_issue] !~ /#{t('layout.issues.search')}/
|
2012-02-20 16:54:45 +00:00
|
|
|
|
2013-03-19 12:11:02 +00:00
|
|
|
@opened_issues, @closed_issues = @issues.not_closed_or_merged.count, @issues.closed_or_merged.count
|
2013-03-19 11:57:01 +00:00
|
|
|
@status = params[:status] == 'closed' ? :closed : :open
|
|
|
|
@issues = @issues.send( (@status == :closed) ? :closed_or_merged : :not_closed_or_merged )
|
2012-02-28 14:28:11 +00:00
|
|
|
|
2013-03-19 11:57:01 +00:00
|
|
|
@sort = params[:sort] == 'updated' ? :updated : :created
|
|
|
|
@direction = params[:direction] == 'asc' ? :asc : :desc
|
|
|
|
@issues = @issues.order("issues.#{@sort}_at #{@direction}")
|
|
|
|
@issues = @issues.includes(:assignee, :user, :pull_request).uniq
|
2013-03-19 21:30:35 +00:00
|
|
|
.paginate :per_page => 20, :page => params[:page]
|
2012-02-23 14:48:31 +00:00
|
|
|
if status == 200
|
2012-09-26 12:46:23 +01:00
|
|
|
render 'index', :layout => request.xhr? ? 'with_sidebar' : 'application'
|
2012-02-23 14:48:31 +00:00
|
|
|
else
|
|
|
|
render :status => status, :nothing => true
|
|
|
|
end
|
2011-12-19 15:30:14 +00:00
|
|
|
end
|
|
|
|
|
2011-12-28 02:57:42 +00:00
|
|
|
def new
|
|
|
|
end
|
|
|
|
|
2011-12-19 15:30:14 +00:00
|
|
|
def create
|
2012-04-13 20:44:04 +01:00
|
|
|
@issue.user_id = current_user.id
|
2012-01-13 15:07:01 +00:00
|
|
|
|
2013-04-03 10:59:34 +01:00
|
|
|
unless can?(:write, @project)
|
|
|
|
@issue.assignee_id = nil
|
|
|
|
@issue.labelings = []
|
|
|
|
end
|
2011-12-28 02:57:42 +00:00
|
|
|
if @issue.save
|
2012-01-13 15:07:01 +00:00
|
|
|
@issue.subscribe_creator(current_user.id)
|
2011-12-19 15:30:14 +00:00
|
|
|
flash[:notice] = I18n.t("flash.issue.saved")
|
|
|
|
redirect_to project_issues_path(@project)
|
|
|
|
else
|
2011-12-28 02:57:42 +00:00
|
|
|
flash[:error] = I18n.t("flash.issue.save_error")
|
2011-12-19 15:30:14 +00:00
|
|
|
render :action => :new
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-06-05 13:08:52 +01:00
|
|
|
def show
|
|
|
|
redirect_to project_pull_request_path(@project, @issue.pull_request) if @issue.pull_request
|
|
|
|
end
|
|
|
|
|
2011-12-19 15:30:14 +00:00
|
|
|
def update
|
2013-04-03 10:59:34 +01:00
|
|
|
unless can?(:write, @project)
|
|
|
|
params.delete :update_labels
|
|
|
|
[:assignee_id, :labelings, :labelings_attributes].each do |k|
|
|
|
|
params[:issue].delete k
|
|
|
|
end if params[:issue]
|
|
|
|
end
|
|
|
|
@issue.labelings.destroy_all if params[:update_labels]
|
2012-03-06 15:20:29 +00:00
|
|
|
if params[:issue] && status = params[:issue][:status]
|
2012-02-28 14:05:18 +00:00
|
|
|
@issue.set_close(current_user) if status == 'closed'
|
|
|
|
@issue.set_open if status == 'open'
|
2012-09-24 18:34:14 +01:00
|
|
|
render :partial => 'status', :status => (@issue.save ? 200 : 400)
|
2012-03-06 15:20:29 +00:00
|
|
|
elsif params[:issue]
|
2012-09-24 18:34:14 +01:00
|
|
|
status, message = if @issue.update_attributes(params[:issue])
|
|
|
|
[200, view_context.markdown(@issue.body)]
|
|
|
|
else
|
|
|
|
[400, view_context.local_alert(@issue.errors.full_messages.join('. '))]
|
|
|
|
end
|
|
|
|
render :inline => message, :status => status
|
2012-03-06 15:20:29 +00:00
|
|
|
else
|
2012-08-25 17:01:49 +01:00
|
|
|
render :nothing => true, :status => 200
|
2011-12-19 15:30:14 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
@issue.destroy
|
|
|
|
flash[:notice] = t("flash.issue.destroyed")
|
|
|
|
redirect_to root_path
|
|
|
|
end
|
|
|
|
|
2012-02-23 14:48:31 +00:00
|
|
|
def create_label
|
2012-08-25 17:01:49 +01:00
|
|
|
index(@project.labels.create!(:name => params[:name], :color => params[:color]) ? 200 : 500)
|
2012-02-23 14:48:31 +00:00
|
|
|
end
|
2011-12-19 15:30:14 +00:00
|
|
|
|
2012-02-23 14:48:31 +00:00
|
|
|
def update_label
|
2012-08-25 17:01:49 +01:00
|
|
|
index(@label.update_attributes(:name => params[:name], :color => params[:color]) ? 200 : 500)
|
2012-02-23 14:48:31 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def destroy_label
|
2012-08-25 17:01:49 +01:00
|
|
|
index((@label && @label_destroy) ? 200 : 500)
|
2011-12-19 15:30:14 +00:00
|
|
|
end
|
|
|
|
|
2012-02-27 16:10:12 +00:00
|
|
|
def search_collaborators
|
2012-08-25 17:01:49 +01:00
|
|
|
render :partial => 'search_collaborators'
|
2012-02-27 16:10:12 +00:00
|
|
|
end
|
|
|
|
|
2012-02-23 14:48:31 +00:00
|
|
|
private
|
|
|
|
|
|
|
|
def load_and_authorize_label
|
|
|
|
@label = Label.find(params[:label_id]) if params[:label_id]
|
|
|
|
authorize! :write, @project
|
2011-12-19 15:30:14 +00:00
|
|
|
end
|
|
|
|
end
|