debian-mirror-gitlab/app/helpers/learn_gitlab_helper.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

108 lines
3 KiB
Ruby
Raw Normal View History

2021-03-11 19:13:27 +05:30
# frozen_string_literal: true
module LearnGitlabHelper
2022-05-07 20:08:51 +05:30
IMAGE_PATH_PLAN = "learn_gitlab/section_plan.svg"
IMAGE_PATH_DEPLOY = "learn_gitlab/section_deploy.svg"
IMAGE_PATH_WORKSPACE = "learn_gitlab/section_workspace.svg"
2022-08-13 15:12:31 +05:30
LICENSE_SCANNING_RUN_URL = 'https://docs.gitlab.com/ee/user/compliance/license_compliance/index.html'
2022-05-07 20:08:51 +05:30
2021-11-11 11:23:49 +05:30
def learn_gitlab_enabled?(project)
2021-03-11 19:13:27 +05:30
return false unless current_user
learn_gitlab_onboarding_available?(project)
end
2021-12-11 22:18:48 +05:30
def learn_gitlab_data(project)
{
actions: onboarding_actions_data(project).to_json,
2022-01-26 12:08:38 +05:30
sections: onboarding_sections_data.to_json,
project: onboarding_project_data(project).to_json
2021-12-11 22:18:48 +05:30
}
end
def learn_gitlab_onboarding_available?(project)
2022-10-11 01:57:18 +05:30
Onboarding::Progress.onboarding?(project.namespace) &&
Onboarding::LearnGitlab.new(current_user).available?
2021-12-11 22:18:48 +05:30
end
private
2021-03-11 19:13:27 +05:30
def onboarding_actions_data(project)
attributes = onboarding_progress(project).attributes.symbolize_keys
2022-05-07 20:08:51 +05:30
action_urls(project).to_h do |action, url|
2021-03-11 19:13:27 +05:30
[
action,
2022-10-11 01:57:18 +05:30
{
url: url,
completed: attributes[Onboarding::Progress.column_name(action)].present?,
svg: image_path("learn_gitlab/#{action}.svg"),
enabled: true
}
2021-03-11 19:13:27 +05:30
]
2021-04-29 21:17:54 +05:30
end
2021-03-11 19:13:27 +05:30
end
2021-06-08 01:23:25 +05:30
def onboarding_sections_data
{
workspace: {
2022-05-07 20:08:51 +05:30
svg: image_path(IMAGE_PATH_WORKSPACE)
2021-06-08 01:23:25 +05:30
},
plan: {
2022-05-07 20:08:51 +05:30
svg: image_path(IMAGE_PATH_PLAN)
2021-06-08 01:23:25 +05:30
},
deploy: {
2022-05-07 20:08:51 +05:30
svg: image_path(IMAGE_PATH_DEPLOY)
2021-06-08 01:23:25 +05:30
}
}
end
2022-01-26 12:08:38 +05:30
def onboarding_project_data(project)
{ name: project.name }
end
2022-05-07 20:08:51 +05:30
def action_urls(project)
action_issue_urls.merge(
2021-12-11 22:18:48 +05:30
issue_created: project_issues_path(project),
git_write: project_path(project),
merge_request_created: project_merge_requests_path(project),
user_added: project_members_url(project),
2022-08-13 15:12:31 +05:30
**deploy_section_action_urls(project)
2021-12-11 22:18:48 +05:30
)
end
2022-05-07 20:08:51 +05:30
def action_issue_urls
2022-10-11 01:57:18 +05:30
Onboarding::Completion::ACTION_ISSUE_IDS.transform_values do |id|
project_issue_url(learn_gitlab_project, id)
end
2022-05-07 20:08:51 +05:30
end
2022-08-13 15:12:31 +05:30
def deploy_section_action_urls(project)
2022-10-11 01:57:18 +05:30
experiment(
:security_actions_continuous_onboarding,
2022-08-13 15:12:31 +05:30
namespace: project.namespace,
user: current_user,
sticky_to: current_user
) do |e|
e.control { { security_scan_enabled: project_security_configuration_path(project) } }
e.candidate do
{
license_scanning_run: LICENSE_SCANNING_RUN_URL,
secure_dependency_scanning_run: project_security_configuration_path(project, anchor: 'dependency-scanning'),
secure_dast_run: project_security_configuration_path(project, anchor: 'dast')
}
end
end.run
end
2021-03-11 19:13:27 +05:30
def learn_gitlab_project
2022-10-11 01:57:18 +05:30
@learn_gitlab_project ||= Onboarding::LearnGitlab.new(current_user).project
2021-03-11 19:13:27 +05:30
end
def onboarding_progress(project)
2022-10-11 01:57:18 +05:30
Onboarding::Progress.find_by(namespace: project.namespace) # rubocop: disable CodeReuse/ActiveRecord
2021-03-11 19:13:27 +05:30
end
end
2021-12-11 22:18:48 +05:30
LearnGitlabHelper.prepend_mod_with('LearnGitlabHelper')