Commit cf049ae5 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Move feature expose logic from serializer to the model

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent ca179bdc
......@@ -63,5 +63,25 @@ module EE
def has_dast_data?
dast_artifact&.success?
end
def expose_performance_data?
project.feature_available?(:merge_request_performance_metrics) &&
has_performance_data?
end
def expose_sast_data?
project.feature_available?(:sast) &&
has_sast_data?
end
def expose_dast_data?
project.feature_available?(:dast) &&
has_dast_data?
end
def expose_sast_container_data?
project.feature_available?(:sast_container) &&
has_sast_container_data?
end
end
end
......@@ -27,7 +27,7 @@ module EE
end
end
expose :performance, if: -> (mr, _) { expose_performance_data?(mr) } do
expose :performance, if: -> (mr, _) { mr.expose_performance_data? } do
expose :head_path, if: -> (mr, _) { can?(current_user, :read_build, mr.head_performance_artifact) } do |merge_request|
raw_project_build_artifacts_url(merge_request.source_project,
merge_request.head_performance_artifact,
......@@ -41,60 +41,35 @@ module EE
end
end
expose :sast, if: -> (mr, _) { expose_sast_data?(mr, current_user) } do
expose :head_path do |merge_request|
expose :sast, if: -> (mr, _) { mr.expose_sast_data? } do
expose :head_path, if: -> (mr, _) { can?(current_user, :read_build, mr.head_sast_artifact) } do |merge_request|
raw_project_build_artifacts_url(merge_request.source_project,
merge_request.head_sast_artifact,
path: Ci::Build::SAST_FILE)
end
expose :base_path, if: -> (mr, _) { mr.has_base_sast_data? } do |merge_request|
expose :base_path, if: -> (mr, _) { mr.has_base_sast_data? && can?(current_user, :read_build, mr.base_sast_artifact)} do |merge_request|
raw_project_build_artifacts_url(merge_request.target_project,
merge_request.base_sast_artifact,
path: Ci::Build::SAST_FILE)
end
end
expose :sast_container, if: -> (mr, _) { expose_sast_container_data?(mr, current_user) } do
expose :path do |merge_request|
expose :sast_container, if: -> (mr, _) { mr.expose_sast_container_data? } do
expose :path, if: -> (mr, _) { can?(current_user, :read_build, mr.sast_container_artifact) } do |merge_request|
raw_project_build_artifacts_url(merge_request.source_project,
merge_request.sast_container_artifact,
path: Ci::Build::SAST_CONTAINER_FILE)
end
end
expose :dast, if: -> (mr, _) { expose_dast_data?(mr, current_user) } do
expose :path do |merge_request|
expose :dast, if: -> (mr, _) { mr.expose_dast_data? } do
expose :path, if: -> (mr, _) { can?(current_user, :read_build, mr.dast_artifact) } do |merge_request|
raw_project_build_artifacts_url(merge_request.source_project,
merge_request.dast_artifact,
path: Ci::Build::DAST_FILE)
end
end
end
private
def expose_sast_data?(mr, current_user)
mr.project.feature_available?(:sast) &&
mr.has_sast_data? &&
can?(current_user, :read_build, mr.head_sast_artifact)
end
def expose_performance_data?(mr)
mr.project.feature_available?(:merge_request_performance_metrics) &&
mr.has_performance_data?
end
def expose_sast_container_data?(mr, current_user)
mr.project.feature_available?(:sast_container) &&
mr.has_sast_container_data? &&
can?(current_user, :read_build, mr.sast_container_artifact)
end
def expose_dast_data?(mr, current_user)
mr.project.feature_available?(:dast) &&
mr.has_dast_data? &&
can?(current_user, :read_build, mr.dast_artifact)
end
end
end
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