2012-09-27 20:59:42 +02:00
|
|
|
class MilestonesController < ProjectResourceController
|
2012-04-08 23:28:58 +02:00
|
|
|
before_filter :module_enabled
|
2012-08-11 00:07:50 +02:00
|
|
|
before_filter :milestone, only: [:edit, :update, :destroy, :show]
|
2012-04-08 23:28:58 +02:00
|
|
|
|
|
|
|
# Allow read any milestone
|
|
|
|
before_filter :authorize_read_milestone!
|
|
|
|
|
|
|
|
# Allow admin milestone
|
2012-08-11 00:07:50 +02:00
|
|
|
before_filter :authorize_admin_milestone!, except: [:index, :show]
|
2012-04-08 23:28:58 +02:00
|
|
|
|
|
|
|
respond_to :html
|
|
|
|
|
|
|
|
def index
|
2012-08-30 21:15:34 +02:00
|
|
|
@milestones = case params[:f]
|
2013-02-18 10:10:09 +01:00
|
|
|
when 'all'; @project.milestones.order("state, due_date DESC")
|
2012-12-14 06:34:05 +01:00
|
|
|
when 'closed'; @project.milestones.closed.order("due_date DESC")
|
|
|
|
else @project.milestones.active.order("due_date ASC")
|
2012-04-08 23:28:58 +02:00
|
|
|
end
|
|
|
|
|
2012-12-14 06:34:05 +01:00
|
|
|
@milestones = @milestones.includes(:project)
|
2012-04-08 23:28:58 +02:00
|
|
|
@milestones = @milestones.page(params[:page]).per(20)
|
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
|
|
|
@milestone = @project.milestones.new
|
|
|
|
respond_with(@milestone)
|
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
|
|
|
respond_with(@milestone)
|
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
2012-09-04 10:13:56 +02:00
|
|
|
@issues = @milestone.issues
|
2013-03-02 12:23:30 +01:00
|
|
|
@users = UserDecorator.decorate_collection(@milestone.participants)
|
2012-10-26 15:53:45 +02:00
|
|
|
@merge_requests = @milestone.merge_requests
|
2012-04-24 20:49:34 +02:00
|
|
|
|
2012-04-08 23:28:58 +02:00
|
|
|
respond_to do |format|
|
|
|
|
format.html
|
|
|
|
format.js
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
|
|
@milestone = @project.milestones.new(params[:milestone])
|
2012-12-14 20:39:55 +01:00
|
|
|
@milestone.author_id_of_changes = current_user.id
|
2012-04-08 23:28:58 +02:00
|
|
|
|
|
|
|
if @milestone.save
|
|
|
|
redirect_to project_milestone_path(@project, @milestone)
|
|
|
|
else
|
|
|
|
render "new"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2012-12-14 20:39:55 +01:00
|
|
|
@milestone.update_attributes(params[:milestone].merge(author_id_of_changes: current_user.id))
|
2012-04-08 23:28:58 +02:00
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.js
|
2012-10-09 21:09:46 +02:00
|
|
|
format.html do
|
2012-04-08 23:28:58 +02:00
|
|
|
if @milestone.valid?
|
|
|
|
redirect_to [@project, @milestone]
|
|
|
|
else
|
|
|
|
render :edit
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
return access_denied! unless can?(current_user, :admin_milestone, @milestone)
|
|
|
|
|
|
|
|
@milestone.destroy
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.html { redirect_to project_milestones_path }
|
2012-08-11 00:07:50 +02:00
|
|
|
format.js { render nothing: true }
|
2012-04-08 23:28:58 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
def milestone
|
|
|
|
@milestone ||= @project.milestones.find(params[:id])
|
|
|
|
end
|
|
|
|
|
|
|
|
def authorize_admin_milestone!
|
|
|
|
return render_404 unless can?(current_user, :admin_milestone, @project)
|
|
|
|
end
|
|
|
|
|
|
|
|
def module_enabled
|
|
|
|
return render_404 unless @project.issues_enabled
|
|
|
|
end
|
|
|
|
end
|