Skip to content

Commit

Permalink
Merge pull request #25 from permitio/gidi/per-10718-update-schema-of-…
Browse files Browse the repository at this point in the history
…java-sdk

update create user schema ti support new paramets - role_assigmetns list
  • Loading branch information
gideonsmila authored Sep 15, 2024
2 parents f596662 + d447b81 commit 4a46933
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
12 changes: 11 additions & 1 deletion src/main/java/io/permit/sdk/enforcement/User.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
package io.permit.sdk.enforcement;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import io.permit.sdk.openapi.models.UserRoleCreate;

public class User {
private String key;
private String firstName = null;
private String lastName = null;
private String email = null;
private HashMap<String, Object> attributes = null;
private List<UserRoleCreate> roleAssignments = null;

public User(Builder builder) {
this.key = builder.key;
this.firstName = builder.firstName;
this.lastName = builder.lastName;
this.email = builder.email;
this.attributes = builder.attributes;
this.roleAssignments = builder.roleAssignments;
}

public String getKey() {
Expand Down Expand Up @@ -52,6 +56,7 @@ public static class Builder {
private String lastName = null;
private String email = null;
private HashMap<String, Object> attributes = null;
private List<UserRoleCreate> roleAssignments;

public Builder(String userKey) {
this.key = userKey;
Expand All @@ -77,6 +82,11 @@ public Builder withAttributes(HashMap<String, Object> attributes) {
return this;
}

public Builder withRoleAssignments(List<UserRoleCreate> roleAssignments) {
this.roleAssignments = roleAssignments;
return this;
}

public User build() {
return new User(this);
}
Expand Down
19 changes: 18 additions & 1 deletion src/main/java/io/permit/sdk/openapi/models/UserCreate.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
package io.permit.sdk.openapi.models;

import java.util.HashMap;
import java.util.List;

import javax.annotation.Generated;

import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;

Expand Down Expand Up @@ -62,7 +65,16 @@ public class UserCreate {
@SerializedName("attributes")
@Expose
public HashMap<String, Object> attributes;

/**
* Role Assignments
* <p>
* List of roles to assign to the user in the environment.
*
*/
@SerializedName("role_assignments")
@Expose
public List<UserRoleCreate> roleAssignments;

/**
* No args constructor for use in serialization
*
Expand Down Expand Up @@ -104,4 +116,9 @@ public UserCreate withAttributes(HashMap<String, Object> attributes) {
return this;
}

public UserCreate withRoleAssignments(List<UserRoleCreate> roleAssignments) {
this.roleAssignments = roleAssignments;
return this;
}

}
7 changes: 7 additions & 0 deletions src/test/java/io/permit/sdk/e2e/RebacE2ETest.java
Original file line number Diff line number Diff line change
Expand Up @@ -179,14 +179,21 @@ public class RebacE2ETest extends PermitE2ETestBase {
new ShortDerivation("folder#commenter", "document#commenter", "parent"),
new ShortDerivation("folder#editor", "document#editor", "parent")
);

final List<UserRoleCreate> roleAssignments = Arrays.asList(
new UserRoleCreate("editor", "default")
);

final UserCreate USER_PERMIT = new UserCreate()
.withKey("[email protected]")
.withEmail("[email protected]")
.withFirstName("Asaf")
.withLastName("Cohen")
.withRoleAssignments(roleAssignments)
.withAttributes(new HashMap<String, Object>() {{
put("age", 35);
}});

final UserCreate USER_CC = new UserCreate()
.withKey("auth0|john")
.withEmail("[email protected]")
Expand Down

0 comments on commit 4a46933

Please sign in to comment.