BigW Consortium Gitlab

releases_controller.rb 921 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
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
13 14 15 16 17 18 19 20
    # 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?
      release.update_attributes(release_params)
    else
      release.destroy
    end
21

22
    redirect_to project_tag_path(@project, @tag.name)
23 24 25 26 27 28 29 30 31 32 33
  end

  private

  def tag
    @tag ||= @repository.find_tag(params[:tag_id])
  end

  def release
    @release ||= @project.releases.find_or_initialize_by(tag: @tag.name)
  end
34 35 36 37

  def release_params
    params.require(:release).permit(:description)
  end
38
end