2018-09-25 23:45:43 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-11-05 05:16:41 -05:00
|
|
|
class Projects::ReleasesController < Projects::ApplicationController
|
|
|
|
# Authorize
|
|
|
|
before_action :require_non_empty_project
|
|
|
|
before_action :authorize_download_code!
|
|
|
|
before_action :authorize_push_code!
|
|
|
|
before_action :tag
|
|
|
|
before_action :release
|
|
|
|
|
|
|
|
def edit
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2016-12-08 15:32:08 -05:00
|
|
|
# Release belongs to Tag which is not active record object,
|
|
|
|
# it exists only to save a description to each Tag.
|
|
|
|
# If description is empty we should destroy the existing record.
|
|
|
|
if release_params[:description].present?
|
2018-07-02 06:43:06 -04:00
|
|
|
release.update(release_params)
|
2016-12-08 15:32:08 -05:00
|
|
|
else
|
|
|
|
release.destroy
|
|
|
|
end
|
2015-11-05 05:16:41 -05:00
|
|
|
|
2017-06-29 13:06:35 -04:00
|
|
|
redirect_to project_tag_path(@project, @tag.name)
|
2015-11-05 05:16:41 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def tag
|
|
|
|
@tag ||= @repository.find_tag(params[:tag_id])
|
|
|
|
end
|
|
|
|
|
2018-08-27 11:31:01 -04:00
|
|
|
# rubocop: disable CodeReuse/ActiveRecord
|
2015-11-05 05:16:41 -05:00
|
|
|
def release
|
|
|
|
@release ||= @project.releases.find_or_initialize_by(tag: @tag.name)
|
|
|
|
end
|
2018-08-27 11:31:01 -04:00
|
|
|
# rubocop: enable CodeReuse/ActiveRecord
|
2015-11-09 09:30:50 -05:00
|
|
|
|
|
|
|
def release_params
|
|
|
|
params.require(:release).permit(:description)
|
|
|
|
end
|
2015-11-05 05:16:41 -05:00
|
|
|
end
|