-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Asset and Device creation from backend (#252)
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.
- Loading branch information
Showing
6 changed files
with
70 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { Backend, Controller, KuzzleRequest } from "kuzzle"; | ||
import { ApiAssetCreateRequest, ApiAssetCreateResult } from "lib/modules/asset"; | ||
import { | ||
ApiDeviceCreateRequest, | ||
ApiDeviceCreateResult, | ||
} from "lib/modules/device"; | ||
|
||
export class TestsController extends Controller { | ||
constructor(app: Backend) { | ||
super(app); | ||
|
||
this.definition = { | ||
actions: { | ||
createDigitalTwinFromBackend: { | ||
handler: this.createDigitalTwinFromBackend, | ||
}, | ||
}, | ||
}; | ||
} | ||
|
||
async createDigitalTwinFromBackend(request: KuzzleRequest) { | ||
const engineId = request.getString("engineId"); | ||
const reference = request.getBodyString("reference"); | ||
|
||
await this.app.sdk.query<ApiAssetCreateRequest, ApiAssetCreateResult>({ | ||
controller: "device-manager/assets", | ||
action: "create", | ||
engineId, | ||
body: { | ||
model: "Container", | ||
reference, | ||
}, | ||
}); | ||
|
||
await this.app.sdk.query<ApiDeviceCreateRequest, ApiDeviceCreateResult>({ | ||
controller: "device-manager/devices", | ||
action: "create", | ||
engineId, | ||
body: { | ||
model: "DummyTemp", | ||
reference, | ||
}, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters