@@ -254,7 +254,8 @@ def create_user_provided(message)
254254
255255 def create_managed ( message , space :)
256256 service_plan = ServicePlan . first ( guid : message . service_plan_guid )
257- unprocessable_service_plan! unless service_plan_valid? ( service_plan , space )
257+ unprocessable_service_plan! unless service_plan_valid? ( service_plan )
258+ service_plan_not_visible_in_space! unless resource_exists_in_space? ( service_plan , space )
258259
259260 action = V3 ::ServiceInstanceCreateManaged . new ( user_audit_info , message . audit_hash )
260261 VCAP ::CloudController ::ManagedServiceInstance . db . transaction do
@@ -394,17 +395,21 @@ def admin?
394395 permission_queryer . can_write_globally?
395396 end
396397
397- def service_plan_valid? ( service_plan , space )
398+ def service_plan_valid? ( service_plan )
398399 service_plan &&
399- visible_to_current_user? ( plan : service_plan ) &&
400- service_plan . visible_in_space? ( space )
400+ visible_to_current_user? ( plan : service_plan )
401+ end
402+
403+ def resource_exists_in_space? ( service_plan , space )
404+ service_plan . visible_in_space? ( space )
401405 end
402406
403407 def raise_if_invalid_service_plan! ( service_instance , message )
404408 return unless message . service_plan_guid
405409
406410 service_plan = ServicePlan . first ( guid : message . service_plan_guid )
407- unprocessable_service_plan! unless service_plan_valid? ( service_plan , service_instance . space )
411+ unprocessable_service_plan! unless service_plan_valid? ( service_plan )
412+ service_plan_not_visible_in_space! unless resource_exists_in_space? ( service_plan , service_instance . space )
408413 invalid_service_plan_relation! unless service_plan . service == service_instance . service
409414 end
410415
@@ -424,6 +429,10 @@ def unprocessable_service_plan!
424429 unprocessable! ( 'Invalid service plan. Ensure that the service plan exists, is available, and you have access to it.' )
425430 end
426431
432+ def service_plan_not_visible_in_space!
433+ unprocessable! ( 'Invalid service plan. Ensure that the service plan is visible in your current space.' )
434+ end
435+
427436 def invalid_service_plan_relation!
428437 raise CloudController ::Errors ::ApiError . new_from_details ( 'InvalidRelation' , 'service plan relates to a different service offering' )
429438 end
0 commit comments