use of io.datarouter.web.user.databean.DatarouterUser in project datarouter by hotpads.
the class DatarouterAuthConfigScanner method checkForDefaultUserId.
public ConfigScanDto checkForDefaultUserId() {
Long defaultAdminId = DatarouterUserCreationService.ADMIN_ID;
Optional<DatarouterUser> defaultUser = datarouterUserDao.find(new DatarouterUserKey(defaultAdminId));
if (defaultUser.isEmpty()) {
return ConfigScanResponseTool.buildEmptyResponse();
}
String userName = defaultUser.get().getUsername();
return ConfigScanResponseTool.buildResponse("Found a user with the default admin id=" + defaultAdminId + " and username=" + userName);
}
use of io.datarouter.web.user.databean.DatarouterUser in project datarouter by hotpads.
the class DatarouterUserEditService method handleAccountChanges.
private Optional<String> handleAccountChanges(DatarouterUser user, Set<DatarouterAccountKey> requestedAccounts) {
Set<DatarouterUserAccountMapKey> currentAccounts = datarouterUserAccountMapDao.scanKeysWithPrefix(new DatarouterUserAccountMapKey(user.getId(), null)).collect(HashSet::new);
Set<DatarouterUserAccountMapKey> accountsToDelete = currentAccounts.stream().filter(currentAccountKey -> !requestedAccounts.contains(currentAccountKey.getDatarouterAccountKey())).collect(Collectors.toSet());
Set<DatarouterUserAccountMap> accountsToAdd = requestedAccounts.stream().map(accountKey -> new DatarouterUserAccountMap(user.getId(), accountKey.getAccountName())).filter(requestedAccount -> !currentAccounts.contains(requestedAccount.getKey())).collect(Collectors.toSet());
if (!accountsToDelete.isEmpty() || !accountsToAdd.isEmpty()) {
if (!accountsToDelete.isEmpty()) {
datarouterUserAccountMapDao.deleteMulti(accountsToDelete);
}
if (!accountsToAdd.isEmpty()) {
datarouterUserAccountMapDao.putMulti(accountsToAdd);
}
String original = currentAccounts.stream().map(DatarouterUserAccountMapKey::getDatarouterAccountKey).map(DatarouterAccountKey::getAccountName).sorted(String.CASE_INSENSITIVE_ORDER).collect(Collectors.joining(","));
String current = requestedAccounts.stream().map(DatarouterAccountKey::getAccountName).sorted(String.CASE_INSENSITIVE_ORDER).collect(Collectors.joining(","));
return Optional.of(change("accounts", original, current));
}
return Optional.empty();
}
use of io.datarouter.web.user.databean.DatarouterUser in project datarouter by hotpads.
the class DatarouterUserHistoryService method sendRoleEditEmail.
private void sendRoleEditEmail(DatarouterUser user, DatarouterUserHistory history, String signInUrl) {
DatarouterUser editor = datarouterUserService.getUserById(history.getEditor());
var p1 = p(String.format("%s permissions have been edited by %s", user.getUsername(), editor.getUsername()));
var p2 = p("Changes: " + history.getChanges());
var content = div(p1, p2, makeSignInParagraph(signInUrl));
var emailBuilder = htmlEmailService.startEmailBuilder().withSubject(userEditService.getPermissionRequestEmailSubject(user)).withTitle("Permissions Changed").withTitleHref(signInUrl).withContent(content).from(user.getUsername()).to(user.getUsername()).to(editor.getUsername()).to(permissionRequestEmailType, serverTypeDetector.mightBeProduction()).toSubscribers(serverTypeDetector.mightBeProduction()).toAdmin(serverTypeDetector.mightBeDevelopment());
htmlEmailService.trySendJ2Html(emailBuilder);
}
use of io.datarouter.web.user.databean.DatarouterUser in project datarouter by hotpads.
the class DatarouterUserService method assertUserDoesNotExist.
public void assertUserDoesNotExist(Long id, String userToken, String username) {
DatarouterUser userWithId = getUserById(id);
if (userWithId != null) {
throw new IllegalArgumentException("DatarouterUser already exists with id=" + id);
}
DatarouterUser userWithUserToken = nodes.getByUserToken(new DatarouterUserByUserTokenLookup(userToken));
if (userWithUserToken != null) {
throw new IllegalArgumentException("DatarouterUser already exists with userToken=" + userToken);
}
DatarouterUser userWithEmail = nodes.getByUsername(new DatarouterUserByUsernameLookup(username));
if (userWithEmail != null) {
throw new IllegalArgumentException("DatarouterUser already exists with username=" + username);
}
}
use of io.datarouter.web.user.databean.DatarouterUser in project datarouter by hotpads.
the class AdminEditUserHandler method updateUserDetails.
// TODO DATAROUTER-2759 make this work without DatarouterUser
@Handler
private EditUserDetailsDto updateUserDetails(@RequestBody EditUserDetailsDto dto) {
if (dto == null || StringTool.isNullOrEmptyOrWhitespace(dto.username) || dto.currentAccounts == null || dto.currentRoles == null) {
return new EditUserDetailsDto("Invalid request.");
}
DatarouterUser currentUser = getCurrentUser();
DatarouterUser userToEdit = datarouterUserDao.getByUsername(new DatarouterUserByUsernameLookup(dto.username));
if (!userToEdit.isEnabled()) {
return new EditUserDetailsDto("This user is not editable.");
}
if (!checkEditPermission(currentUser, userToEdit, datarouterUserService::canEditUser)) {
return null;
}
Set<Role> requestedUserRoles = Scanner.of(dto.currentRoles.entrySet()).include(Entry::getValue).map(Entry::getKey).map(roleManager::getRoleFromPersistentString).collect(HashSet::new);
Set<DatarouterAccountKey> requestedAccounts = Scanner.of(dto.currentAccounts.entrySet()).include(Entry::getValue).map(Entry::getKey).map(DatarouterAccountKey::new).collect(HashSet::new);
datarouterUserEditService.editUser(userToEdit, currentUser, requestedUserRoles, null, getSigninUrl(), requestedAccounts, Optional.ofNullable(dto.currentZoneId).map(ZoneId::of), Optional.empty());
return getEditUserDetailsDto(dto.username);
}
Aggregations