-
Notifications
You must be signed in to change notification settings - Fork 371
Add suspended state for spaces and deleting state for spaces and orgs #5206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
d570a50
ae47792
aaf9311
ac57f96
aa01995
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -76,7 +76,7 @@ def index_with_token?(_) | |
|
|
||
| def can_write_to_route(route, is_create=false) | ||
| return true if context.queryer.can_write_globally? | ||
| return false if route.in_suspended_org? | ||
| return false if route.in_suspended_or_deleting_org? || route.space.suspended_or_deleting? | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Helper method? Why not |
||
| return false if route.wildcard_host? && route.domain.shared? | ||
|
|
||
| FeatureFlag.raise_unless_enabled!(:route_creation) if is_create | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -56,14 +56,14 @@ def create?(service_instance, _params=nil) | |
| return true if admin_user? | ||
|
|
||
| FeatureFlag.raise_unless_enabled!(:service_instance_creation) | ||
| return false if service_instance.in_suspended_org? | ||
| return false if service_instance.in_suspended_or_deleting_org? || service_instance.space&.suspended_or_deleting? | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Helper method? |
||
|
|
||
| service_instance.space&.has_developer?(context.user) && allowed?(service_instance) | ||
| end | ||
|
|
||
| def read_for_update?(service_instance, _params=nil) | ||
| return true if admin_user? | ||
| return false if service_instance.in_suspended_org? | ||
| return false if service_instance.in_suspended_or_deleting_org? || service_instance.space&.suspended_or_deleting? | ||
|
|
||
| service_instance.space&.has_developer?(context.user) | ||
| end | ||
|
|
@@ -74,7 +74,7 @@ def update?(service_instance, params=nil) | |
|
|
||
| def delete?(service_instance) | ||
| return true if admin_user? | ||
| return false if service_instance.in_suspended_org? | ||
| return false if service_instance.in_suspended_or_deleting_org? || service_instance.space&.suspended_or_deleting? | ||
|
|
||
| service_instance.space&.has_developer?(context.user) | ||
| end | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,7 @@ def update(org, message) | |
| AnnotationsUpdate.update(org, message.annotations, OrganizationAnnotationModel) | ||
|
|
||
| if message.requested?(:suspended) | ||
| error!("Organization '#{org.name}' is being deleted and cannot be reactivated.") if org.deleting? && message.suspended == false | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is no check for setting a DELETING org to SUSPENDED. I think this should also be forbidden. |
||
| org.status = message.suspended ? Organization::SUSPENDED : Organization::ACTIVE | ||
| end | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,10 @@ def update(space, message) | |
| space.db.transaction do | ||
| space.lock! | ||
| space.name = message.name if message.requested?(:name) | ||
| if message.requested?(:suspended) | ||
| error!("Space '#{space.name}' is being deleted and cannot be reactivated.") if space.deleting? && message.suspended == false | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is no check for setting a DELETING space to SUSPENDED. I think this should also be forbidden. |
||
| space.status = message.suspended ? Space::SUSPENDED : Space::ACTIVE | ||
| end | ||
| MetadataUpdate.update(space, message) | ||
|
|
||
| space.save | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,7 +34,7 @@ def create | |
| raise CloudController::Errors::ApiError.new_from_details('RouteNotFound', request_attrs['route_guid']) unless route | ||
| raise CloudController::Errors::ApiError.new_from_details('AppNotFound', request_attrs['app_guid']) unless process | ||
| raise CloudController::Errors::ApiError.new_from_details('NotAuthorized') unless permissions.can_write_to_active_space?(process.space.id) | ||
| raise CloudController::Errors::ApiError.new_from_details('OrgSuspended') unless permissions.is_space_active?(process.space.id) | ||
| raise CloudController::Errors::ApiError.new_from_details('OrgSuspended') unless permissions.writable_space_state(process.space.id) == :active | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This raises |
||
|
|
||
| route_mapping = V2::RouteMappingCreate.new(UserAuditInfo.from_context(SecurityContext), route, process, request_attrs, logger).add | ||
|
|
||
|
|
@@ -61,7 +61,7 @@ def delete(guid) | |
|
|
||
| raise CloudController::Errors::ApiError.new_from_details('RouteMappingNotFound', guid) unless route_mapping | ||
| raise CloudController::Errors::ApiError.new_from_details('NotAuthorized') unless permissions.can_write_to_active_space?(route_mapping.space.id) | ||
| raise CloudController::Errors::ApiError.new_from_details('OrgSuspended') unless permissions.is_space_active?(route_mapping.space.id) | ||
| raise CloudController::Errors::ApiError.new_from_details('OrgSuspended') unless permissions.writable_space_state(route_mapping.space.id) == :active | ||
|
|
||
| RouteMappingDelete.new(UserAuditInfo.from_context(SecurityContext)).delete(route_mapping) | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,6 +26,14 @@ def suspended! | |
| raise CloudController::Errors::ApiError.new_from_details('OrgSuspended') | ||
| end | ||
|
|
||
| def space_suspended! | ||
| raise CloudController::Errors::ApiError.new_from_details('SpaceSuspended') | ||
| end | ||
|
|
||
| def resource_being_deleted!(resource_name) | ||
| raise CloudController::Errors::ApiError.new_from_details('ResourceBeingDeleted', resource_name) | ||
| end | ||
|
|
||
| def resource_not_found_with_message!(message) | ||
| raise CloudController::Errors::ApiError.new_from_details('ResourceNotFound', message) | ||
| end | ||
|
|
@@ -150,6 +158,33 @@ def permission_queryer | |
| @permission_queryer ||= VCAP::CloudController::Permissions.new(VCAP::CloudController::SecurityContext.current_user) | ||
| end | ||
|
|
||
| def require_writable_org!(org) | ||
| require_writable_org_id!(org.id) | ||
| end | ||
|
|
||
| def require_writable_org_id!(org_id) | ||
| case permission_queryer.writable_org_state(org_id) | ||
| when :active | ||
| nil | ||
| when :deleting | ||
| resource_being_deleted!('organization') | ||
| when :suspended | ||
| suspended! | ||
| end | ||
|
Comment on lines
+166
to
+173
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This would look more compact to me. Does Rubocop complain then? |
||
| end | ||
|
|
||
| def require_writable_space!(space) | ||
| org_state = permission_queryer.writable_org_state(space.organization_id) | ||
| return resource_being_deleted!('organization') if org_state == :deleting | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These |
||
|
|
||
| space_state = permission_queryer.writable_space_state(space.id) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pass |
||
| return resource_being_deleted!('space') if space_state == :deleting | ||
|
|
||
| return suspended! if org_state == :suspended | ||
|
|
||
| space_suspended! if space_state == :suspended | ||
| end | ||
|
|
||
| def add_warning_headers(warnings) | ||
| return if warnings.nil? | ||
| raise ArgumentError.new('warnings should be an array') unless warnings.is_a?(Array) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,8 +40,8 @@ def create | |
|
|
||
| package = PackageModel.where(guid: message.package_guid). | ||
| eager(:app, :space, space: :organization, app: %i[buildpack_lifecycle_data cnb_lifecycle_data]).first | ||
| unprocessable_package! unless package && | ||
| permission_queryer.can_manage_apps_in_active_space?(package.space.id) && permission_queryer.is_space_active?(package.space.id) | ||
| unprocessable_package! unless package && permission_queryer.can_manage_apps_in_active_space?(package.space.id) | ||
| require_writable_space!(package.space) if package | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| FeatureFlag.raise_unless_enabled!(:diego_docker) if package.type == PackageModel::DOCKER_TYPE | ||
|
|
||
|
|
@@ -98,7 +98,7 @@ def update | |
| unauthorized! unless permission_queryer.can_update_build_state? | ||
| else | ||
| unauthorized! unless permission_queryer.can_write_to_active_space?(space.id) | ||
| suspended! unless permission_queryer.is_space_active?(space.id) | ||
| require_writable_space!(space) | ||
| end | ||
|
|
||
| build = BuildUpdate.new.update(build, create_valid_update_message) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Helper method?
app.in_suspended_or_deleting_space?