Commit 21aabf98 authored by Etienne Baqué's avatar Etienne Baqué

Refactored Project presenter methods

parent ff937a0a
...@@ -23,6 +23,7 @@ class Projects::EnvironmentsController < Projects::ApplicationController ...@@ -23,6 +23,7 @@ class Projects::EnvironmentsController < Projects::ApplicationController
def index def index
@environments = project.environments @environments = project.environments
.with_state(params[:scope] || :available) .with_state(params[:scope] || :available)
@project = ProjectPresenter.new(project, current_user: current_user)
respond_to do |format| respond_to do |format|
format.html format.html
......
...@@ -276,8 +276,7 @@ class ProjectPresenter < Gitlab::View::Presenter::Delegated ...@@ -276,8 +276,7 @@ class ProjectPresenter < Gitlab::View::Presenter::Delegated
end end
def kubernetes_cluster_anchor_data def kubernetes_cluster_anchor_data
if current_user && can?(current_user, :create_cluster, project) if can_cluster_be_created?
if clusters.empty? if clusters.empty?
AnchorData.new(false, AnchorData.new(false,
statistic_icon + _('Add Kubernetes cluster'), statistic_icon + _('Add Kubernetes cluster'),
...@@ -294,7 +293,7 @@ class ProjectPresenter < Gitlab::View::Presenter::Delegated ...@@ -294,7 +293,7 @@ class ProjectPresenter < Gitlab::View::Presenter::Delegated
end end
def gitlab_ci_anchor_data def gitlab_ci_anchor_data
if current_user && can_current_user_push_code? && repository.gitlab_ci_yml.blank? && !auto_devops_enabled? if can_cicd_be_set_up?
AnchorData.new(false, AnchorData.new(false,
statistic_icon + _('Set up CI/CD'), statistic_icon + _('Set up CI/CD'),
add_ci_yml_path) add_ci_yml_path)
...@@ -306,6 +305,18 @@ class ProjectPresenter < Gitlab::View::Presenter::Delegated ...@@ -306,6 +305,18 @@ class ProjectPresenter < Gitlab::View::Presenter::Delegated
end end
end end
def can_setup_review_app?
can_cicd_be_set_up? || can_cluster_be_created?
end
def can_cicd_be_set_up?
current_user && can_current_user_push_code? && repository.gitlab_ci_yml.blank? && !auto_devops_enabled?
end
def can_cluster_be_created?
current_user && can?(current_user, :create_cluster, project)
end
def topics_to_show def topics_to_show
project.tag_list.take(MAX_TOPICS_TO_SHOW) # rubocop: disable CodeReuse/ActiveRecord project.tag_list.take(MAX_TOPICS_TO_SHOW) # rubocop: disable CodeReuse/ActiveRecord
end end
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#environments-list-view{ data: { environments_data: environments_list_data, #environments-list-view{ data: { environments_data: environments_list_data,
"can-read-environment" => can?(current_user, :read_environment, @project).to_s, "can-read-environment" => can?(current_user, :read_environment, @project).to_s,
"can-create-environment" => can?(current_user, :create_environment, @project).to_s, "can-create-environment" => can?(current_user, :create_environment, @project).to_s,
"can-setup-review-app" => @project.can_setup_review_app?,
"new-environment-path" => new_project_environment_path(@project), "new-environment-path" => new_project_environment_path(@project),
"help-page-path" => help_page_path("ci/environments"), "help-page-path" => help_page_path("ci/environments"),
"deploy-boards-help-path" => help_page_path("user/project/deploy_boards", anchor: "enabling-deploy-boards") } } "deploy-boards-help-path" => help_page_path("user/project/deploy_boards", anchor: "enabling-deploy-boards") } }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment