Commit c212a611 authored by Lin Jen-Shin's avatar Lin Jen-Shin Committed by Tiago Botelho

Move EE verification to EE module

parent 2fe01c8f
......@@ -26,6 +26,32 @@ module EE
projects
end
def verify_create_projects_attrs!(attrs)
super
verify_mirror_attrs!(attrs)
if attrs[:mirror]
attrs[:mirror_user_id] = current_user.id
end
end
def verify_update_project_attrs!(attrs)
super
verify_mirror_attrs!(attrs)
unless valid_mirror_user?(attrs)
render_api_error!("Invalid mirror user", 400)
end
end
def verify_mirror_attrs!(attrs)
if attrs[:mirror].present? && !mirroring_available?
render_api_error!("Pull mirroring is not available", 403)
end
end
end
end
......
......@@ -24,6 +24,12 @@ module API
projects
end
def verify_create_projects_attrs!(attrs)
end
def verify_update_project_attrs!(attrs)
end
end
prepend EE::API::Projects
......@@ -172,9 +178,7 @@ module API
attrs = declared_params(include_missing: false)
attrs = translate_params_for_compatibility(attrs)
break render_api_error!("Pull mirroring is not available", 403) if attrs[:mirror].present? && !mirroring_available?
attrs[:mirror_user_id] = current_user.id if attrs[:mirror]
verify_create_projects_attrs!(attrs)
project = ::Projects::CreateService.new(current_user, attrs).execute
......@@ -209,9 +213,7 @@ module API
attrs = declared_params(include_missing: false)
attrs = translate_params_for_compatibility(attrs)
break render_api_error!("Pull mirroring is not available", 403) if attrs[:mirror].present? && !mirroring_available?
attrs[:mirror_user_id] = user.id if attrs[:mirror]
verify_create_projects_attrs!(attrs)
project = ::Projects::CreateService.new(user, attrs).execute
......@@ -312,8 +314,7 @@ module API
attrs = translate_params_for_compatibility(attrs)
break render_api_error!("Pull mirroring is not available", 403) if attrs[:mirror].present? && !mirroring_available?
break render_api_error!("Invalid mirror user", 400) unless valid_mirror_user?(attrs)
verify_update_project_attrs!(attrs)
result = ::Projects::UpdateService.new(user_project, current_user, attrs).execute
......
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