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

Fix Asset and Device creation from backend #252

Merged
merged 3 commits into from
Jan 19, 2023

Conversation

Aschen
Copy link
Contributor

@Aschen Aschen commented Jan 6, 2023

What does this PR do ?

Every modification of a Digital Twin (Asset or Device) through associated controllers is contextualized with the user who made the request to keep a trace in Kuzzle metadata.

This allows for example to know who has modified a metadata or link a new device to an asset by consulting history documents in assets-history collection.

When a request is made to those controllers from the backend, there is no user since it's the EmbeddedSDK executing the request and it was causing an error.

This PR fix that, when the EmbeddedSDK is used to execute one of those action, it will use the user if the sdk was contextualized with sdk.as method, otherwise the metadata will be set with the null user ID who represent the backend user.

@Aschen Aschen self-assigned this Jan 6, 2023
Comment on lines 44 to 52
private get impersonatedSdk() {
return (user: User) => this.sdk.as(user, { checkRights: false });
return (user: User) => {
if (user?._id) {
return this.sdk.as(user, { checkRights: false });
}

return this.sdk;
};
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is a very useful method should we provide it as well in the Framework?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well actually Kuzzle could just return the normal SDK if the user is null but I'm not sure about potential side effects for users who relied on the fact that the method will throw if an incorrect user is passed.

Also, I don't know where we could put this method in the framework. Let's see if we need it another time and talk about this

@Aschen Aschen changed the base branch from 2-dev to master January 19, 2023 08:53
@Aschen Aschen merged commit 12d14f0 into master Jan 19, 2023
@Aschen Aschen deleted the fix/asset-device-creation-from-backend branch January 19, 2023 08:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants