Skip to content

Commit

Permalink
fix: user roles
Browse files Browse the repository at this point in the history
  • Loading branch information
sattvikc committed Feb 29, 2024
1 parent eb4496b commit d267312
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public String getPath() {

@Override
protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException {
// API is tenant specific
// API is tenant specific, but uses public tenant storage
JsonObject input = InputParser.parseJsonObjectOrThrowError(req);
String userId = InputParser.parseStringOrThrowError(input, "userId", false);
String role = InputParser.parseStringOrThrowError(input, "role", false);
Expand All @@ -61,7 +61,8 @@ protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws IO

try {
boolean didUserAlreadyHaveRole = !UserRoles.addRoleToUser(
this.getTenantStorage(req), userId, role);
this.getTenantStorage(req).withStorage(this.getPublicTenantStorage(req).getStorage()),
userId, role);
JsonObject response = new JsonObject();
response.addProperty("status", "OK");
response.addProperty("didUserAlreadyHaveRole", didUserAlreadyHaveRole);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ public String getPath() {

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException {
// API is tenant specific
// API is tenant specific, but using the public tenant storage
String userId = InputParser.getQueryParamOrThrowError(req, "userId", false);
try {

String[] userRoles = UserRoles.getRolesForUser(this.getTenantStorage(req),
String[] userRoles = UserRoles.getRolesForUser(
this.getTenantStorage(req).withStorage(this.getPublicTenantStorage(req).getStorage()),
userId);
JsonArray arr = new JsonArray();
for (String s : userRoles) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public String getPath() {

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException {
// API is tenant specific
// API is tenant specific, but uses public tenant storage
String role = InputParser.getQueryParamOrThrowError(req, "role", false);

// normalize roles
Expand All @@ -60,8 +60,9 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IO
}

try {

String[] roleUsers = UserRoles.getUsersForRole(this.getTenantStorage(req), role);
String[] roleUsers = UserRoles.getUsersForRole(
this.getTenantStorage(req).withStorage(this.getPublicTenantStorage(req).getStorage()),
role);
JsonArray arr = new JsonArray();

for (String s : roleUsers) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public String getPath() {

@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException {
// API is tenant specific
// API is tenant specific, but uses public tenant storage
JsonObject input = InputParser.parseJsonObjectOrThrowError(req);
String userId = InputParser.parseStringOrThrowError(input, "userId", false);
String role = InputParser.parseStringOrThrowError(input, "role", false);
Expand All @@ -60,7 +60,8 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws I
}

try {
boolean didUserHaveRole = UserRoles.removeUserRole(this.getTenantStorage(req),
boolean didUserHaveRole = UserRoles.removeUserRole(
this.getTenantStorage(req).withStorage(this.getPublicTenantStorage(req).getStorage()),
userId, role);

JsonObject response = new JsonObject();
Expand Down

0 comments on commit d267312

Please sign in to comment.