Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.deftdevs.bootstrapi.commons.model;

import com.deftdevs.bootstrapi.commons.constants.BootstrAPI;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
Expand Down Expand Up @@ -44,6 +45,9 @@ public class UserModel {
private String password;

@XmlElement
@Schema(description = "Group memberships keyed by group name. true ensures the user is a member, " +
"false ensures the user is not a member, null is a no-op (leaves the membership untouched). " +
"Group lifecycle is managed via the top-level groups map; referenced groups must already exist.")
private Map<String, Boolean> groups;

// Example instances for documentation and tests
Expand Down
2 changes: 1 addition & 1 deletion confluence/Models/UserModel.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
| **email** | **String** | | [optional] [default to null] |
| **active** | **Boolean** | | [optional] [default to null] |
| **password** | **String** | | [optional] [default to null] |
| **groups** | **Map** | | [optional] [default to null] |
| **groups** | **Map** | Group memberships keyed by group name. true ensures the user is a member, false ensures the user is not a member, null is a no-op (leaves the membership untouched). Group lifecycle is managed via the top-level groups map; referenced groups must already exist. | [optional] [default to null] |

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

2 changes: 1 addition & 1 deletion crowd/Models/UserModel.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
| **email** | **String** | | [optional] [default to null] |
| **active** | **Boolean** | | [optional] [default to null] |
| **password** | **String** | | [optional] [default to null] |
| **groups** | **Map** | | [optional] [default to null] |
| **groups** | **Map** | Group memberships keyed by group name. true ensures the user is a member, false ensures the user is not a member, null is a no-op (leaves the membership untouched). Group lifecycle is managed via the top-level groups map; referenced groups must already exist. | [optional] [default to null] |

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

Original file line number Diff line number Diff line change
Expand Up @@ -448,8 +448,12 @@ Map<String, Boolean> setUserGroups(
}
} catch (DirectoryPermissionException | ReadOnlyGroupException e) {
throw new BadRequestException(e);
} catch (GroupNotFoundException e) {
// the referenced group does not exist - group lifecycle is managed via the top-level
// groups map, so a non-existent group here is a client error (404)
throw new com.deftdevs.bootstrapi.commons.exception.GroupNotFoundException(groupName);
} catch (com.atlassian.crowd.exception.DirectoryNotFoundException |
com.atlassian.crowd.exception.UserNotFoundException | GroupNotFoundException |
com.atlassian.crowd.exception.UserNotFoundException |
OperationFailedException e) {
throw new InternalServerErrorException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,21 @@ public void testAddUserWithGroupsRemoveNotMember() throws CrowdException, Direct
assertEquals(false, result.getGroups().get("some-group"));
}

@Test
public void testAddUserWithGroupsUnknownGroupThrowsNotFound() throws CrowdException, DirectoryPermissionException {
// return the same user as the one we are adding
doAnswer(invocation -> invocation.getArguments()[1]).when(directoryManager).addUser(anyLong(), any(), any());
doThrow(new GroupNotFoundException("unknown-group"))
.when(directoryManager).addUserToGroup(anyLong(), anyString(), anyString());

final UserModel userModel = UserModelUtil.toUserModel(getTestUser());
userModel.setPassword("12345");
userModel.setGroups(Collections.singletonMap("unknown-group", true));

assertThrows(com.deftdevs.bootstrapi.commons.exception.GroupNotFoundException.class,
() -> usersService.addUser(1L, userModel));
}

@Test
public void testAddUserAlreadyExists() throws CrowdException {
final User user = getTestUser();
Expand Down
2 changes: 1 addition & 1 deletion jira/Models/UserModel.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
| **email** | **String** | | [optional] [default to null] |
| **active** | **Boolean** | | [optional] [default to null] |
| **password** | **String** | | [optional] [default to null] |
| **groups** | **Map** | | [optional] [default to null] |
| **groups** | **Map** | Group memberships keyed by group name. true ensures the user is a member, false ensures the user is not a member, null is a no-op (leaves the membership untouched). Group lifecycle is managed via the top-level groups map; referenced groups must already exist. | [optional] [default to null] |

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)