diff --git a/application/src/main/java/org/thingsboard/server/controller/UserController.java b/application/src/main/java/org/thingsboard/server/controller/UserController.java index 626f326ae6..d6fda64d31 100644 --- a/application/src/main/java/org/thingsboard/server/controller/UserController.java +++ b/application/src/main/java/org/thingsboard/server/controller/UserController.java @@ -189,9 +189,7 @@ public class UserController extends BaseController { user.setTenantId(getCurrentUser().getTenantId()); } checkEntity(user.getId(), user, Resource.USER); - user.setTenantId(getTenantId()); - user.setCustomerId(getCurrentUser().getCustomerId()); - return tbUserService.save(user, sendActivationMail, request, getCurrentUser()); + return tbUserService.save(getTenantId(), getCurrentUser().getCustomerId(), user, sendActivationMail, request, getCurrentUser()); } @ApiOperation(value = "Send or re-send the activation email", @@ -267,7 +265,7 @@ public class UserController extends BaseController { if (user.getAuthority() == Authority.SYS_ADMIN && getCurrentUser().getId().equals(userId)) { throw new ThingsboardException("Sysadmin is not allowed to delete himself", ThingsboardErrorCode.PERMISSION_DENIED); } - tbUserService.delete(user, getCurrentUser()); + tbUserService.delete(getTenantId(), getCurrentUser().getCustomerId(), user, getCurrentUser()); } @ApiOperation(value = "Get Users (getUsers)", diff --git a/application/src/main/java/org/thingsboard/server/service/entitiy/user/DefaultUserService.java b/application/src/main/java/org/thingsboard/server/service/entitiy/user/DefaultUserService.java index 4443fed709..592496e6f8 100644 --- a/application/src/main/java/org/thingsboard/server/service/entitiy/user/DefaultUserService.java +++ b/application/src/main/java/org/thingsboard/server/service/entitiy/user/DefaultUserService.java @@ -48,17 +48,14 @@ public class DefaultUserService extends AbstractTbEntityService implements TbUse private final SystemSecurityService systemSecurityService; @Override - public User save(User tbUser, boolean sendActivationMail, + public User save(TenantId tenantId, CustomerId customerId, User tbUser, boolean sendActivationMail, HttpServletRequest request, SecurityUser user) throws ThingsboardException { ActionType actionType = tbUser.getId() == null ? ActionType.ADDED : ActionType.UPDATED; - TenantId tenantId = tbUser.getTenantId(); - CustomerId customerId = tbUser.getCustomerId(); try { boolean sendEmail = tbUser.getId() == null && sendActivationMail; User savedUser = checkNotNull(userService.saveUser(tbUser)); if (sendEmail) { - SecurityUser authUser = user; - UserCredentials userCredentials = userService.findUserCredentialsByUserId(authUser.getTenantId(), savedUser.getId()); + UserCredentials userCredentials = userService.findUserCredentialsByUserId(tenantId, savedUser.getId()); String baseUrl = systemSecurityService.getBaseUrl(tenantId, customerId, request); String activateUrl = String.format(ACTIVATE_URL_PATTERN, baseUrl, userCredentials.getActivateToken()); @@ -66,7 +63,7 @@ public class DefaultUserService extends AbstractTbEntityService implements TbUse try { mailService.sendActivationEmail(activateUrl, email); } catch (ThingsboardException e) { - userService.deleteUser(authUser.getTenantId(), savedUser.getId()); + userService.deleteUser(tenantId, savedUser.getId()); throw e; } } @@ -81,20 +78,17 @@ public class DefaultUserService extends AbstractTbEntityService implements TbUse } @Override - public void delete(User tbUser, SecurityUser user) throws ThingsboardException { - TenantId tenantId = tbUser.getTenantId(); + public void delete(TenantId tenantId, CustomerId customerId, User tbUser, SecurityUser user) throws ThingsboardException { UserId userId = tbUser.getId(); try { - - List relatedEdgeIds = findRelatedEdgeIds(tenantId, userId); userService.deleteUser(tenantId, userId); - notificationEntityService.notifyDeleteEntity(tenantId, userId, tbUser, tbUser.getCustomerId(), + notificationEntityService.notifyDeleteEntity(tenantId, userId, tbUser, customerId, ActionType.DELETED, relatedEdgeIds, user, userId.toString()); } catch (Exception e) { notificationEntityService.notifyCreateOrUpdateOrDelete(tenantId, null, emptyId(EntityType.USER), - null, user, ActionType.DELETED, false, e); + null, user, ActionType.DELETED, false, e, userId.toString()); throw handleException(e); } } diff --git a/application/src/main/java/org/thingsboard/server/service/entitiy/user/TbUserService.java b/application/src/main/java/org/thingsboard/server/service/entitiy/user/TbUserService.java index e6e0c0e658..177aad17cc 100644 --- a/application/src/main/java/org/thingsboard/server/service/entitiy/user/TbUserService.java +++ b/application/src/main/java/org/thingsboard/server/service/entitiy/user/TbUserService.java @@ -17,12 +17,14 @@ package org.thingsboard.server.service.entitiy.user; import org.thingsboard.server.common.data.User; import org.thingsboard.server.common.data.exception.ThingsboardException; +import org.thingsboard.server.common.data.id.CustomerId; +import org.thingsboard.server.common.data.id.TenantId; import org.thingsboard.server.service.security.model.SecurityUser; import javax.servlet.http.HttpServletRequest; public interface TbUserService { - User save(User tbUser, boolean sendActivationMail, HttpServletRequest request, SecurityUser user) throws ThingsboardException; + User save(TenantId tenantId, CustomerId customerId, User tbUser, boolean sendActivationMail, HttpServletRequest request, SecurityUser user) throws ThingsboardException; - void delete (User tbUser, SecurityUser user) throws ThingsboardException; + void delete (TenantId tenantId, CustomerId customerId, User tbUser, SecurityUser user) throws ThingsboardException; }