Read about our upcoming Code of Conduct on this issue

tags_controller.rb 2.31 KB
Newer Older
1
2
# frozen_string_literal: true

3
class Projects::TagsController < Projects::ApplicationController
tiagonbotelho's avatar
tiagonbotelho committed
4
  include SortingHelper
tiagonbotelho's avatar
tiagonbotelho committed
5

6
7
  prepend_before_action(only: [:index]) { authenticate_sessionless_user!(:rss) }

8
  # Authorize
9
10
  before_action :require_non_empty_project
  before_action :authorize_download_code!
11
  before_action :authorize_push_code!, only: [:new, :create]
12
  before_action :authorize_admin_project!, only: [:destroy]
13

14
  # rubocop: disable CodeReuse/ActiveRecord
15
  def index
16
    params[:sort] = params[:sort].presence || sort_value_recently_updated
tiagonbotelho's avatar
tiagonbotelho committed
17
18

    @sort = params[:sort]
tiagonbotelho's avatar
tiagonbotelho committed
19
    @tags = TagsFinder.new(@repository, params).execute
20
21
    @tags = Kaminari.paginate_array(@tags).page(params[:page])

22
    tag_names = @tags.map(&:name)
23
    @tags_pipelines = @project.ci_pipelines.latest_successful_for_refs(tag_names)
24
    @releases = project.releases.where(tag: tag_names)
25
26
27
28
29

    respond_to do |format|
      format.html
      format.atom { render layout: 'xml.atom' }
    end
30
  end
31
  # rubocop: enable CodeReuse/ActiveRecord
32

33
  # rubocop: disable CodeReuse/ActiveRecord
34
35
  def show
    @tag = @repository.find_tag(params[:id])
Sean McGivern's avatar
Sean McGivern committed
36

37
    return render_404 unless @tag
38

39
    @release = @project.releases.find_or_initialize_by(tag: @tag.name)
40
    @commit = @repository.commit(@tag.dereferenced_target)
41
  end
42
  # rubocop: enable CodeReuse/ActiveRecord
43
44

  def create
45
46
    result = Tags::CreateService.new(@project, current_user)
      .execute(params[:tag_name], params[:ref], params[:message], params[:release_description])
47

48
49
    if result[:status] == :success
      @tag = result[:tag]
50

51
      redirect_to project_tag_path(@project, @tag.name)
52
53
    else
      @error = result[:message]
54
55
      @message = params[:message]
      @release_description = params[:release_description]
56
57
      render action: 'new'
    end
58
59
60
  end

  def destroy
61
    result = Tags::DestroyService.new(project, current_user).execute(params[:id])
62

63
    respond_to do |format|
64
65
      if result[:status] == :success
        format.html do
Lin Jen-Shin's avatar
Lin Jen-Shin committed
66
          redirect_to project_tags_path(@project), status: :see_other
67
68
69
70
71
72
73
        end

        format.js
      else
        @error = result[:message]

        format.html do
74
          redirect_to project_tags_path(@project),
75
            alert: @error, status: 303
76
77
78
79
80
        end

        format.js do
          render status: :unprocessable_entity
        end
81
82
      end
    end
83
84
  end
end