2020-04-08 14:13:33 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Projects
|
|
|
|
module Import
|
|
|
|
class JiraController < Projects::ApplicationController
|
2020-04-22 19:07:51 +05:30
|
|
|
before_action :authenticate_user!
|
|
|
|
before_action :check_issues_available!
|
|
|
|
before_action :authorize_read_project!
|
2020-04-08 14:13:33 +05:30
|
|
|
before_action :jira_import_enabled?
|
|
|
|
before_action :jira_integration_configured?
|
2020-04-22 19:07:51 +05:30
|
|
|
before_action :authorize_admin_project!, only: [:import]
|
2020-04-08 14:13:33 +05:30
|
|
|
|
|
|
|
def show
|
2020-04-22 19:07:51 +05:30
|
|
|
jira_service = @project.jira_service
|
|
|
|
|
|
|
|
if jira_service.present? && !@project.latest_jira_import&.in_progress? && current_user&.can?(:admin_project, @project)
|
|
|
|
jira_client = jira_service.client
|
|
|
|
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
|
2020-04-08 14:13:33 +05:30
|
|
|
end
|
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
unless Feature.enabled?(:jira_issue_import_vue, @project, default_enabled: true)
|
|
|
|
flash[:notice] = _("Import %{status}") % { status: @project.jira_import_status } unless @project.latest_jira_import&.initial?
|
|
|
|
end
|
2020-04-08 14:13:33 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def import
|
2020-04-22 19:07:51 +05:30
|
|
|
jira_project_key = jira_import_params[:jira_project_key]
|
2020-04-08 14:13:33 +05:30
|
|
|
|
2020-04-22 19:07:51 +05:30
|
|
|
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
|
2020-04-08 14:13:33 +05:30
|
|
|
|
|
|
|
redirect_to project_import_jira_path(@project)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def jira_import_enabled?
|
2020-04-22 19:07:51 +05:30
|
|
|
return if @project.jira_issues_import_feature_flag_enabled?
|
2020-04-08 14:13:33 +05:30
|
|
|
|
|
|
|
redirect_to project_issues_path(@project)
|
|
|
|
end
|
|
|
|
|
|
|
|
def jira_integration_configured?
|
2020-04-22 19:07:51 +05:30
|
|
|
return if Feature.enabled?(:jira_issue_import_vue, @project, default_enabled: true)
|
2020-04-08 14:13:33 +05:30
|
|
|
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
|