use of uk.gov.pay.adminusers.persistence.entity.ServiceRoleEntity in project pay-adminusers by alphagov.
the class ServiceRoleDaoIT method shouldRemoveAServiceRoleOfAUserSuccessfully.
@Test
public void shouldRemoveAServiceRoleOfAUserSuccessfully() {
Service service = ServiceDbFixture.serviceDbFixture(databaseHelper).insertService();
int roleId = RoleDbFixture.roleDbFixture(databaseHelper).insertRole().getId();
String username = randomUuid();
String email = username + "@example.com";
User user = UserDbFixture.userDbFixture(databaseHelper).withServiceRole(service, roleId).withUsername(username).withEmail(email).insertUser();
UserServiceId userServiceId = new UserServiceId();
userServiceId.setServiceId(user.getServiceRoles().get(0).getService().getId());
userServiceId.setUserId(user.getId());
List<Map<String, Object>> serviceRoles = databaseHelper.findServiceRoleForUser(user.getId());
assertThat(serviceRoles.size(), is(1));
ServiceRoleEntity serviceRoleOfUser = serviceRoleDao.findById(userServiceId).get();
serviceRoleDao.remove(serviceRoleOfUser);
List<Map<String, Object>> serviceRolesAfterRemove = databaseHelper.findServiceRoleForUser(user.getId());
assertThat(serviceRolesAfterRemove.size(), is(0));
}
use of uk.gov.pay.adminusers.persistence.entity.ServiceRoleEntity in project pay-adminusers by alphagov.
the class ServiceUserRemover method removeWithoutAdminCheck.
public void removeWithoutAdminCheck(String userExternalId, String serviceExternalId) {
LOGGER.info("User remove from toolbox requested - serviceId={}, userId={}", serviceExternalId, userExternalId);
ServiceRoleEntity userServiceRoleToRemove = getServiceRoleEntityOf(userExternalId, serviceExternalId);
serviceRoleDao.remove(userServiceRoleToRemove);
}
use of uk.gov.pay.adminusers.persistence.entity.ServiceRoleEntity in project pay-adminusers by alphagov.
the class UserCreator method addServiceRoleToUser.
private void addServiceRoleToUser(UserEntity user, RoleEntity role, List<String> serviceExternalIds) {
serviceExternalIds.forEach(serviceExternalId -> serviceDao.findByExternalId(serviceExternalId).map(serviceEntity -> {
ServiceRoleEntity serviceRole = new ServiceRoleEntity(serviceEntity, role);
serviceRole.setUser(user);
user.addServiceRole(serviceRole);
return null;
}).orElseGet(() -> {
LOGGER.error("Unable to assign service with external id {} to user, as it does not exist", serviceExternalId);
return null;
}));
}
use of uk.gov.pay.adminusers.persistence.entity.ServiceRoleEntity in project pay-adminusers by alphagov.
the class UserCreator method addServiceFromGatewayAccountsToUser.
private void addServiceFromGatewayAccountsToUser(UserEntity user, RoleEntity role, List<String> gatewayAccountIds) {
ServiceRoleEntity serviceRole = getServiceAssignedTo(gatewayAccountIds).map(serviceEntity -> new ServiceRoleEntity(serviceEntity, role)).orElseGet(() -> {
ServiceEntity service = new ServiceEntity(gatewayAccountIds);
service.addOrUpdateServiceName(ServiceNameEntity.from(SupportedLanguage.ENGLISH, Service.DEFAULT_NAME_VALUE));
serviceDao.persist(service);
return new ServiceRoleEntity(service, role);
});
serviceRole.setUser(user);
user.addServiceRole(serviceRole);
}
use of uk.gov.pay.adminusers.persistence.entity.ServiceRoleEntity in project pay-adminusers by alphagov.
the class UserEntityTest method creatingAUser_shouldSetGatewayAccountAndRole_whenServiceRoleIsSet.
@Test
void creatingAUser_shouldSetGatewayAccountAndRole_whenServiceRoleIsSet() {
UserEntity userEntity = new UserEntity();
String gatewayAccountId = "1";
ServiceEntity service = new ServiceEntity(List.of(gatewayAccountId));
Role role = role(1, "role", "hey");
role.setPermissions(Set.of(permission(1, "perm1", "perm1 desc"), permission(2, "perm2", "perm2 desc")));
RoleEntity roleEntity = new RoleEntity(role);
ServiceRoleEntity serviceRole = new ServiceRoleEntity(service, roleEntity);
userEntity.addServiceRole(serviceRole);
assertThat(userEntity.getRoles().size(), is(1));
assertThat(userEntity.getRoles().get(0).getId(), is(1));
assertThat(userEntity.getGatewayAccountId(), is(gatewayAccountId));
}
Aggregations