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