use of com.nike.cerberus.record.UserGroupRecord in project cerberus by Nike-Inc.
the class UserGroupPermissionServiceTest method testUpdateUserGroupPermissionWhenGroupRecordIsPresentForGivenName.
@Test
public void testUpdateUserGroupPermissionWhenGroupRecordIsPresentForGivenName() {
UserGroupPermission userGroupPermission = mockUserGroupPermissionWithNameAndRoleId("name", "roleId");
Optional<UserGroupRecord> userGroupRecord = getUserGroup();
Mockito.when(userGroupDao.getUserGroupByName("name")).thenReturn(userGroupRecord);
userGroupPermissionService.updateUserGroupPermission("safeBoId", userGroupPermission, "user", OffsetDateTime.MAX);
Mockito.verify(userGroupDao).updateUserGroupPermission(Mockito.any(UserGroupPermissionRecord.class));
}
use of com.nike.cerberus.record.UserGroupRecord in project cerberus by Nike-Inc.
the class UserGroupPermissionServiceTest method testGrantUserGroupPermissionWhenUserGroupRecordIsPresentForGivenName.
@Test
public void testGrantUserGroupPermissionWhenUserGroupRecordIsPresentForGivenName() {
UserGroupPermission userGroupPermission = mockUserGroupPermissionWithNameAndRoleId("name", "roleId");
Role role = Mockito.mock(Role.class);
Mockito.when(roleService.getRoleById("roleId")).thenReturn(Optional.of(role));
Optional<UserGroupRecord> userGroupRecord = getUserGroup();
Mockito.when(userGroupDao.getUserGroupByName("name")).thenReturn(userGroupRecord);
userGroupPermissionService.grantUserGroupPermission("safeBoxId", userGroupPermission, "user", OffsetDateTime.MAX);
Mockito.verify(userGroupDao).createUserGroupPermission(Mockito.any(UserGroupPermissionRecord.class));
}
use of com.nike.cerberus.record.UserGroupRecord in project cerberus by Nike-Inc.
the class UserGroupPermissionServiceTest method testUpdateUserGroupPermissionsWhenGroupRecordIsPresentForGivenName.
@Test
public void testUpdateUserGroupPermissionsWhenGroupRecordIsPresentForGivenName() {
UserGroupPermission userGroupPermission = mockUserGroupPermissionWithNameAndRoleId("name", "roleId");
Set<UserGroupPermission> userGroupPermissions = new HashSet<>();
userGroupPermissions.add(userGroupPermission);
Optional<UserGroupRecord> userGroupRecord = getUserGroup();
Mockito.when(userGroupDao.getUserGroupByName("name")).thenReturn(userGroupRecord);
userGroupPermissionService.updateUserGroupPermissions("safeBoId", userGroupPermissions, "user", OffsetDateTime.MAX);
Mockito.verify(userGroupDao).updateUserGroupPermission(Mockito.any(UserGroupPermissionRecord.class));
}
use of com.nike.cerberus.record.UserGroupRecord in project cerberus by Nike-Inc.
the class UserGroupPermissionService method updateUserGroupPermission.
/**
* Updates a user group permission.
*
* @param safeDepositBoxId The safe deposit box id
* @param userGroupPermission The user group permission
* @param user The user making the changes
* @param dateTime The time of the changes
*/
@Transactional
public void updateUserGroupPermission(final String safeDepositBoxId, final UserGroupPermission userGroupPermission, final String user, final OffsetDateTime dateTime) {
final Optional<UserGroupRecord> possibleUserGroupRecord = userGroupDao.getUserGroupByName(userGroupPermission.getName());
if (possibleUserGroupRecord.isEmpty()) {
String msg = "Unable to update permissions for user group name that doesn't exist.";
throw ApiException.newBuilder().withApiErrors(CustomApiError.createCustomApiError(DefaultApiError.ENTITY_NOT_FOUND, msg)).withExceptionMessage(msg).build();
}
UserGroupPermissionRecord record = new UserGroupPermissionRecord();
record.setSdboxId(safeDepositBoxId);
record.setUserGroupId(possibleUserGroupRecord.get().getId());
record.setRoleId(userGroupPermission.getRoleId());
record.setLastUpdatedBy(user);
record.setLastUpdatedTs(dateTime);
userGroupDao.updateUserGroupPermission(record);
}
use of com.nike.cerberus.record.UserGroupRecord in project cerberus by Nike-Inc.
the class UserGroupPermissionService method grantUserGroupPermission.
/**
* Grants a user group permission.
*
* @param safeDepositBoxId The safe deposit box id
* @param userGroupPermission The user group permission
* @param user The user making the changes
* @param dateTime The time of the changes
*/
@Transactional
public void grantUserGroupPermission(final String safeDepositBoxId, final UserGroupPermission userGroupPermission, final String user, final OffsetDateTime dateTime) {
final Optional<UserGroupRecord> possibleUserGroupRecord = userGroupDao.getUserGroupByName(userGroupPermission.getName());
final Optional<Role> role = roleService.getRoleById(userGroupPermission.getRoleId());
if (role.isEmpty()) {
throw ApiException.newBuilder().withApiErrors(DefaultApiError.USER_GROUP_ROLE_ID_INVALID).build();
}
String userGroupId;
if (possibleUserGroupRecord.isPresent()) {
userGroupId = possibleUserGroupRecord.get().getId();
} else {
userGroupId = uuidSupplier.get();
UserGroupRecord userGroupRecord = new UserGroupRecord();
userGroupRecord.setId(userGroupId);
userGroupRecord.setName(userGroupPermission.getName());
userGroupRecord.setCreatedBy(user);
userGroupRecord.setLastUpdatedBy(user);
userGroupRecord.setCreatedTs(dateTime);
userGroupRecord.setLastUpdatedTs(dateTime);
userGroupDao.createUserGroup(userGroupRecord);
}
UserGroupPermissionRecord permissionsRecord = new UserGroupPermissionRecord();
permissionsRecord.setId(uuidSupplier.get());
permissionsRecord.setUserGroupId(userGroupId);
permissionsRecord.setRoleId(userGroupPermission.getRoleId());
permissionsRecord.setSdboxId(safeDepositBoxId);
permissionsRecord.setCreatedBy(user);
permissionsRecord.setLastUpdatedBy(user);
permissionsRecord.setCreatedTs(dateTime);
permissionsRecord.setLastUpdatedTs(dateTime);
userGroupDao.createUserGroupPermission(permissionsRecord);
}
Aggregations