Skip to content

Commit d447b81

Browse files
committed
update create user schema ti support new paramets - role_assigmetns list
1 parent f596662 commit d447b81

3 files changed

Lines changed: 36 additions & 2 deletions

File tree

src/main/java/io/permit/sdk/enforcement/User.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,25 @@
11
package io.permit.sdk.enforcement;
2-
32
import java.util.ArrayList;
43
import java.util.HashMap;
4+
import java.util.List;
5+
6+
import io.permit.sdk.openapi.models.UserRoleCreate;
57

68
public class User {
79
private String key;
810
private String firstName = null;
911
private String lastName = null;
1012
private String email = null;
1113
private HashMap<String, Object> attributes = null;
14+
private List<UserRoleCreate> roleAssignments = null;
1215

1316
public User(Builder builder) {
1417
this.key = builder.key;
1518
this.firstName = builder.firstName;
1619
this.lastName = builder.lastName;
1720
this.email = builder.email;
1821
this.attributes = builder.attributes;
22+
this.roleAssignments = builder.roleAssignments;
1923
}
2024

2125
public String getKey() {
@@ -52,6 +56,7 @@ public static class Builder {
5256
private String lastName = null;
5357
private String email = null;
5458
private HashMap<String, Object> attributes = null;
59+
private List<UserRoleCreate> roleAssignments;
5560

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

85+
public Builder withRoleAssignments(List<UserRoleCreate> roleAssignments) {
86+
this.roleAssignments = roleAssignments;
87+
return this;
88+
}
89+
8090
public User build() {
8191
return new User(this);
8292
}

src/main/java/io/permit/sdk/openapi/models/UserCreate.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
package io.permit.sdk.openapi.models;
33

44
import java.util.HashMap;
5+
import java.util.List;
6+
57
import javax.annotation.Generated;
8+
69
import com.google.gson.annotations.Expose;
710
import com.google.gson.annotations.SerializedName;
811

@@ -62,7 +65,16 @@ public class UserCreate {
6265
@SerializedName("attributes")
6366
@Expose
6467
public HashMap<String, Object> attributes;
65-
68+
/**
69+
* Role Assignments
70+
* <p>
71+
* List of roles to assign to the user in the environment.
72+
*
73+
*/
74+
@SerializedName("role_assignments")
75+
@Expose
76+
public List<UserRoleCreate> roleAssignments;
77+
6678
/**
6779
* No args constructor for use in serialization
6880
*
@@ -104,4 +116,9 @@ public UserCreate withAttributes(HashMap<String, Object> attributes) {
104116
return this;
105117
}
106118

119+
public UserCreate withRoleAssignments(List<UserRoleCreate> roleAssignments) {
120+
this.roleAssignments = roleAssignments;
121+
return this;
122+
}
123+
107124
}

src/test/java/io/permit/sdk/e2e/RebacE2ETest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,14 +179,21 @@ public class RebacE2ETest extends PermitE2ETestBase {
179179
new ShortDerivation("folder#commenter", "document#commenter", "parent"),
180180
new ShortDerivation("folder#editor", "document#editor", "parent")
181181
);
182+
183+
final List<UserRoleCreate> roleAssignments = Arrays.asList(
184+
new UserRoleCreate("editor", "default")
185+
);
186+
182187
final UserCreate USER_PERMIT = new UserCreate()
183188
.withKey("asaf@permit.io")
184189
.withEmail("asaf@permit.io")
185190
.withFirstName("Asaf")
186191
.withLastName("Cohen")
192+
.withRoleAssignments(roleAssignments)
187193
.withAttributes(new HashMap<String, Object>() {{
188194
put("age", 35);
189195
}});
196+
190197
final UserCreate USER_CC = new UserCreate()
191198
.withKey("auth0|john")
192199
.withEmail("john@cocacola.com")

0 commit comments

Comments
 (0)