summaryrefslogtreecommitdiff
path: root/app/controllers/projects/releases_controller.rb
blob: 7ee5230de066e624b2d949ff0c9ec916ff30f1d4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# frozen_string_literal: true

class Projects::ReleasesController < Projects::ApplicationController
  # Authorize
  before_action :require_non_empty_project, except: [:index]
  before_action :release, only: %i[edit update]
  before_action :authorize_read_release!
  before_action do
    push_frontend_feature_flag(:release_edit_page, project)
    push_frontend_feature_flag(:release_issue_summary, project)
  end
  before_action :authorize_update_release!, only: %i[edit update]

  def index
    respond_to do |format|
      format.html do
        require_non_empty_project
      end
      format.json { render json: releases }
    end
  end

  protected

  def releases
    ReleasesFinder.new(@project, current_user).execute
  end

  def edit
    respond_to do |format|
      format.html { render 'edit' }
    end
  end

  private

  def authorize_update_release!
    access_denied! unless Feature.enabled?(:release_edit_page, project)
    access_denied! unless can?(current_user, :update_release, release)
  end

  def release
    @release ||= project.releases.find_by_tag!(sanitized_tag_name)
  end

  def sanitized_tag_name
    CGI.unescape(params[:tag])
  end
end