jira_controller.rb 2.07 KB
Newer Older
1
2
3
4
5
6
7
8
9
# frozen_string_literal: true

module Projects
  module Import
    class JiraController < Projects::ApplicationController
      before_action :jira_import_enabled?
      before_action :jira_integration_configured?

      def show
10
        @is_jira_configured = @project.jira_service.present?
11
12
        return if Feature.enabled?(:jira_issue_import_vue, @project)

13
        unless @project.latest_jira_import&.in_progress?
14
          jira_client = @project.jira_service.client
15
16
17
18
19
20
21
          jira_projects = jira_client.Project.all

          if jira_projects.present?
            @jira_projects = jira_projects.map { |p| ["#{p.name} (#{p.key})", p.key] }
          else
            flash[:alert] = 'No projects have been returned from Jira. Please check your Jira configuration.'
          end
22
23
        end

24
        flash[:notice] = _("Import %{status}") % { status: @project.jira_import_status } unless @project.latest_jira_import&.initial?
25
26
27
      end

      def import
28
29
30
31
32
33
34
35
        jira_project_key = jira_import_params[:jira_project_key]

        if jira_project_key.present?
          response = ::JiraImport::StartImportService.new(current_user, @project, jira_project_key).execute
          flash[:notice] = response.message if response.message.present?
        else
          flash[:alert] = 'No jira project key has been provided.'
        end
36
37
38
39
40
41
42

        redirect_to project_import_jira_path(@project)
      end

      private

      def jira_import_enabled?
43
        return if @project.jira_issues_import_feature_flag_enabled?
44
45
46
47
48

        redirect_to project_issues_path(@project)
      end

      def jira_integration_configured?
49
        return if Feature.enabled?(:jira_issue_import_vue, @project)
50
51
52
53
54
55
56
57
58
59
60
61
62
        return if @project.jira_service

        flash[:notice] = _("Configure the Jira integration first on your project's %{strong_start} Settings > Integrations > Jira%{strong_end} page." %
           { strong_start: '<strong>'.html_safe, strong_end: '</strong>'.html_safe })
        redirect_to project_issues_path(@project)
      end

      def jira_import_params
        params.permit(:jira_project_key)
      end
    end
  end
end