Skip to content

Commit 9f3b9fd

Browse files
committed
fix sharing ownership
Signed-off-by: Robert Landers <landers.robert@gmail.com>
1 parent acadbd8 commit 9f3b9fd

4 files changed

Lines changed: 13 additions & 15 deletions

File tree

cli/lib/api.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -315,8 +315,8 @@ func Startup(ctx context.Context, js jetstream.JetStream, logger *zap.Logger, po
315315
}
316316
}
317317

318-
// POST /resource/{id}/share: share ownership of the resource with another user
319-
r.HandleFunc("/resource/{id}/share/{userid}", func(writer http.ResponseWriter, request *http.Request) {
318+
// POST /entity/{name}/{id}/share/{userid}: share ownership of the resource with another user
319+
r.HandleFunc("/entity/{name}/{id}/share/{userid}", func(writer http.ResponseWriter, request *http.Request) {
320320
if stop := handleCors(writer, request); stop {
321321
return
322322
}
@@ -330,17 +330,19 @@ func Startup(ctx context.Context, js jetstream.JetStream, logger *zap.Logger, po
330330
logRequest(logger, request, ctx)
331331

332332
vars := mux.Vars(request)
333-
id := &glue.StateId{
334-
Id: strings.TrimSpace(vars["id"]),
333+
id := &glue.EntityId{
334+
Name: strings.TrimSpace(vars["name"]),
335+
Id: strings.TrimSpace(vars["id"]),
335336
}
337+
stateId := id.ToStateId()
336338

337339
// verify the user is authorized to access the resource
338-
ctx, done := authorize(writer, request, config, ctx, rm, id, logger, true, auth.Owner)
340+
ctx, done := authorize(writer, request, config, ctx, rm, stateId, logger, true, auth.Owner)
339341
if done {
340342
return
341343
}
342344

343-
r, err := rm.DiscoverResource(ctx, id, logger, true)
345+
r, err := rm.DiscoverResource(ctx, stateId, logger, true)
344346
if err != nil {
345347
logger.Error("Failed to discover resource", zap.Error(err))
346348
http.Error(writer, "Not Found", http.StatusNotFound)

src/DurableClient.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,8 @@ public function deleteEntity(EntityId $entityId): void
143143
$this->entityClient->deleteEntity($entityId);
144144
}
145145

146-
public function shareOwnership(EntityId|OrchestrationInstance $resource, string $with): void
146+
public function shareEntityOwnership(EntityId $id, string $with): void
147147
{
148-
$this->entityClient->shareOwnership($resource, $with);
148+
$this->entityClient->shareEntityOwnership($id, $with);
149149
}
150150
}

src/EntityClientInterface.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
use Bottledcode\DurablePhp\Search\EntityFilter;
2828
use Bottledcode\DurablePhp\State\EntityId;
2929
use Bottledcode\DurablePhp\State\EntityState;
30-
use Bottledcode\DurablePhp\State\OrchestrationInstance;
3130
use Closure;
3231
use DateTimeImmutable;
3332
use Generator;
@@ -82,5 +81,5 @@ public function getEntitySnapshot(EntityId $entityId): ?EntityState;
8281
*/
8382
public function deleteEntity(EntityId $entityId): void;
8483

85-
public function shareOwnership(EntityId|OrchestrationInstance $resource, string $with): void;
84+
public function shareEntityOwnership(EntityId $id, string $with): void;
8685
}

src/RemoteEntityClient.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@
3131
use Bottledcode\DurablePhp\Search\EntityFilter;
3232
use Bottledcode\DurablePhp\State\EntityId;
3333
use Bottledcode\DurablePhp\State\EntityState;
34-
use Bottledcode\DurablePhp\State\Ids\StateId;
35-
use Bottledcode\DurablePhp\State\OrchestrationInstance;
3634
use Bottledcode\DurablePhp\State\Serializer;
3735
use Closure;
3836
use DateTimeImmutable;
@@ -166,10 +164,9 @@ public function deleteEntity(EntityId $entityId): void
166164
}
167165
}
168166

169-
public function shareOwnership(EntityId|OrchestrationInstance $resource, string $with): void
167+
public function shareEntityOwnership(EntityId $id, string $with): void
170168
{
171-
$id = $resource instanceof EntityId ? StateId::fromEntityId($resource) : StateId::fromInstance($resource);
172-
$req = new Request("{$this->apiHost}/resource/{$id}/share/{$with}", 'POST');
169+
$req = new Request("{$this->apiHost}/entity/{$id->name}/{$id->id}/share/{$with}", 'POST');
173170
if ($this->userToken) {
174171
$req->setHeader('Authorization', 'Bearer ' . $this->userToken);
175172
}

0 commit comments

Comments
 (0)