Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Spaces] Space-Aware Saved Objects (#18862)
**This is an updated description that incorperates some of the discussions below** This PR introduces changes which allow the Spaces plugin to make saved objects "space aware". Effectively, this means wrapping the Saved Objects Client to alter or filter requests/responses. **Note** Advanced UI Settings (i.e., saved objects of type `config`) are not in scope for this PR, and will be addressed separately. ### Terminology: - SOC: Saved Objects Client ## Saved Objects Client ### `get` The response from the base SOC is checked to see if the object belongs to the current space. If not, a 404 is thrown to indicate the object does not exist. ### `bulk_get` The response from the base SOC is checked to see if each object belongs to the current space. For each object that does not belong, its contents are replaced with a 404 response, which looks identical to the base SOC's 404 response for a missing object. ### `create` The `spaceId` is appended to the create request, so the base SOC will write the new object into the correct space. ### `bulk_create` The `spaceId` is appended to each space-aware object in the request, so the base SOC will write the new objects into the correct space. ### `update` Before allowing an update to be processed by the base SOC, we check to ensure that it belongs to the current space. If not, a 404 is thrown. We also ensure that the `spaceId` is not changed as a result of an update. ### `delete` Before allowing a delete to be processed by the base SOC, we check to ensure that it belongs to the current space. If not, a 404 is thrown. ### `find` Searching is arguably the most complex case for this PR, and is responsible for a bulk of the LOC (other than tests). When performing a find, we augment the ES query to ensure that each object belongs to the current space. ## * Belonging to the current space To figure out if an object belongs to the current space, the following check is performed: ### 1. Is the object's type space-aware? Most saved object types are space-aware. There are a couple of exceptions as of this PR: space and config. If the type is not space-aware, then ✅ this object belongs to the current space. This implies that objects that are not space aware belong to every space. If the type is space-aware, then processing continues to step 2 ### 2. Check the object's `spaceId` Each saved object may have a `spaceId` assigned. This `spaceId` is compared against the `spaceId` that the user's request is executed within. If they match, then the object belongs to the current space. **caveat** The Default Space is a special-case space that does not assign a `spaceId` to its underlying objects. This is done to maintain backwards compatibility, and makes bootstrapping Spaces much easier for upgrading installations. Given this, there is logic in place which accounts for this special-case. The most interesting example is when we build the query for the SOC's `find` operation. Rather than checking that the object has a particular `spaceId`, we have to check that the object does not have a `spaceId` assigned.
- Loading branch information