Skip to content
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

feat: consume permissions in repository #3

Merged
merged 1 commit into from
Oct 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/core/server/saved_objects/service/lib/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ export class SavedObjectsRepository {
originId,
initialNamespaces,
version,
permissions,
} = options;
const namespace = normalizeNamespace(options.namespace);

Expand Down Expand Up @@ -289,6 +290,7 @@ export class SavedObjectsRepository {
migrationVersion,
updated_at: time,
...(Array.isArray(references) && { references }),
...(permissions && { permissions }),
});

const raw = this._serializer.savedObjectToRaw(migrated as SavedObjectSanitizedDoc);
Expand Down Expand Up @@ -976,7 +978,7 @@ export class SavedObjectsRepository {
throw SavedObjectsErrorHelpers.createGenericNotFoundError(type, id);
}

const { originId, updated_at: updatedAt } = body._source;
const { originId, updated_at: updatedAt, permissions } = body._source;

let namespaces: string[] = [];
if (!this._registry.isNamespaceAgnostic(type)) {
Expand All @@ -991,6 +993,7 @@ export class SavedObjectsRepository {
namespaces,
...(originId && { originId }),
...(updatedAt && { updated_at: updatedAt }),
...(permissions && { permissions }),
version: encodeHitVersion(body),
attributes: body._source[type],
references: body._source.references || [],
Expand Down Expand Up @@ -1019,7 +1022,7 @@ export class SavedObjectsRepository {
throw SavedObjectsErrorHelpers.createGenericNotFoundError(type, id);
}

const { version, references, refresh = DEFAULT_REFRESH_SETTING } = options;
const { version, references, refresh = DEFAULT_REFRESH_SETTING, permissions } = options;
const namespace = normalizeNamespace(options.namespace);

let preflightResult: SavedObjectsRawDoc | undefined;
Expand All @@ -1033,6 +1036,7 @@ export class SavedObjectsRepository {
[type]: attributes,
updated_at: time,
...(Array.isArray(references) && { references }),
...(permissions && { permissions }),
};

const { body, statusCode } = await this.client.update<SavedObjectsRawDocSource>(
Expand Down Expand Up @@ -1754,7 +1758,7 @@ function getSavedObjectFromSource<T>(
id: string,
doc: { _seq_no?: number; _primary_term?: number; _source: SavedObjectsRawDocSource }
): SavedObject<T> {
const { originId, updated_at: updatedAt } = doc._source;
const { originId, updated_at: updatedAt, permissions } = doc._source;

let namespaces: string[] = [];
if (!registry.isNamespaceAgnostic(type)) {
Expand All @@ -1773,6 +1777,7 @@ function getSavedObjectFromSource<T>(
attributes: doc._source[type],
references: doc._source.references || [],
migrationVersion: doc._source.migrationVersion,
permissions,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ export interface SavedObjectsCreateOptions extends SavedObjectsBaseOptions {
* Note: this can only be used for multi-namespace object types.
*/
initialNamespaces?: string[];
/** permission control describe by ACL object */
permissions?: Permissions;
}

/**
Expand Down Expand Up @@ -180,6 +182,8 @@ export interface SavedObjectsUpdateOptions extends SavedObjectsBaseOptions {
references?: SavedObjectReference[];
/** The OpenSearch Refresh setting for this operation */
refresh?: MutatingOperationRefreshSetting;
/** permission control describe by ACL object */
permissions?: Permissions;
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/core/types/saved_objects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
* specific language governing permissions and limitations
* under the License.
*/
import { Permissions } from '../server/saved_objects/permission_control/acl';

/**
* Don't use this type, it's simply a helper type for {@link SavedObjectAttribute}
Expand Down Expand Up @@ -113,6 +114,7 @@ export interface SavedObject<T = unknown> {
* space.
*/
originId?: string;
permissions?: Permissions;
}

export interface SavedObjectError {
Expand Down
Loading