Skip to content

Commit

Permalink
fix(client): add context to ClientCheckRequest
Browse files Browse the repository at this point in the history
  • Loading branch information
booniepepper committed Dec 28, 2023
1 parent dd53336 commit 97b840b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
11 changes: 1 addition & 10 deletions src/main/java/dev/openfga/sdk/api/client/OpenFgaClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -535,16 +535,7 @@ public CompletableFuture<ClientCheckResponse> check(ClientCheckRequest request,
configuration.assertValid();
String storeId = configuration.getStoreIdChecked();

CheckRequest body = new CheckRequest();

if (request != null) {
body.tupleKey(request.asCheckRequestTupleKey());

var contextualTuples = request.getContextualTuples();
if (contextualTuples != null && !contextualTuples.isEmpty()) {
body.contextualTuples(ClientTupleKey.asContextualTupleKeys(contextualTuples));
}
}
CheckRequest body = request.asCheckRequest();

if (options != null && !isNullOrWhitespace(options.getAuthorizationModelId())) {
body.authorizationModelId(options.getAuthorizationModelId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,26 @@

package dev.openfga.sdk.api.client.model;

import dev.openfga.sdk.api.model.CheckRequest;
import dev.openfga.sdk.api.model.CheckRequestTupleKey;
import java.util.List;

public class ClientCheckRequest {
private String user;
private String relation;
private String _object;
private Object context;
private List<ClientTupleKey> contextualTuples;

public CheckRequestTupleKey asCheckRequestTupleKey() {
return new CheckRequestTupleKey().user(user).relation(relation)._object(_object);
public CheckRequest asCheckRequest() {
var checkRequest = new CheckRequest()
.tupleKey(
new CheckRequestTupleKey().user(user).relation(relation)._object(_object))
.context(context);
if (contextualTuples != null && !contextualTuples.isEmpty()) {
checkRequest.contextualTuples(ClientTupleKey.asContextualTupleKeys(contextualTuples));
}
return checkRequest;
}

public ClientCheckRequest _object(String _object) {
Expand All @@ -43,6 +52,19 @@ public ClientCheckRequest relation(String relation) {
return this;
}

/**
* Get context
* @return context
**/
public Object getContext() {
return context;
}

public ClientCheckRequest context(Object context) {
this.context = context;
return this;
}

/**
* Get relation
* @return relation
Expand Down

0 comments on commit 97b840b

Please sign in to comment.