Commit e6d3b1d3f69f9715bb26c04616a5142c3ee65192
Committed by
Andrew Shvayka
1 parent
e33420d3
Fix for getting user method when additionalInfo is null and refactoring
Showing
1 changed file
with
9 additions
and
15 deletions
@@ -32,6 +32,7 @@ import org.springframework.web.bind.annotation.RequestParam; | @@ -32,6 +32,7 @@ import org.springframework.web.bind.annotation.RequestParam; | ||
32 | import org.springframework.web.bind.annotation.ResponseBody; | 32 | import org.springframework.web.bind.annotation.ResponseBody; |
33 | import org.springframework.web.bind.annotation.ResponseStatus; | 33 | import org.springframework.web.bind.annotation.ResponseStatus; |
34 | import org.springframework.web.bind.annotation.RestController; | 34 | import org.springframework.web.bind.annotation.RestController; |
35 | +import org.thingsboard.common.util.JacksonUtil; | ||
35 | import org.thingsboard.rule.engine.api.MailService; | 36 | import org.thingsboard.rule.engine.api.MailService; |
36 | import org.thingsboard.server.common.data.EntityType; | 37 | import org.thingsboard.server.common.data.EntityType; |
37 | import org.thingsboard.server.common.data.User; | 38 | import org.thingsboard.server.common.data.User; |
@@ -89,13 +90,14 @@ public class UserController extends BaseController { | @@ -89,13 +90,14 @@ public class UserController extends BaseController { | ||
89 | try { | 90 | try { |
90 | UserId userId = new UserId(toUUID(strUserId)); | 91 | UserId userId = new UserId(toUUID(strUserId)); |
91 | User user = checkUserId(userId, Operation.READ); | 92 | User user = checkUserId(userId, Operation.READ); |
92 | - if(!user.getAdditionalInfo().isNull()) { | ||
93 | - processDashboardIdFromAdditionalInfo((ObjectNode) user.getAdditionalInfo(), DEFAULT_DASHBOARD); | ||
94 | - processDashboardIdFromAdditionalInfo((ObjectNode) user.getAdditionalInfo(), HOME_DASHBOARD); | ||
95 | - } | ||
96 | - UserCredentials userCredentials = userService.findUserCredentialsByUserId(user.getTenantId(), user.getId()); | ||
97 | - if(userCredentials.isEnabled()) { | ||
98 | - addUserCredentialsEnabled((ObjectNode) user.getAdditionalInfo()); | 93 | + if(user.getAdditionalInfo().isObject()) { |
94 | + ObjectNode additionalInfo = (ObjectNode) user.getAdditionalInfo(); | ||
95 | + processDashboardIdFromAdditionalInfo(additionalInfo, DEFAULT_DASHBOARD); | ||
96 | + processDashboardIdFromAdditionalInfo(additionalInfo, HOME_DASHBOARD); | ||
97 | + UserCredentials userCredentials = userService.findUserCredentialsByUserId(user.getTenantId(), user.getId()); | ||
98 | + if(userCredentials.isEnabled() && !additionalInfo.has("userCredentialsEnabled")) { | ||
99 | + additionalInfo.put("userCredentialsEnabled", true); | ||
100 | + } | ||
99 | } | 101 | } |
100 | return user; | 102 | return user; |
101 | } catch (Exception e) { | 103 | } catch (Exception e) { |
@@ -103,14 +105,6 @@ public class UserController extends BaseController { | @@ -103,14 +105,6 @@ public class UserController extends BaseController { | ||
103 | } | 105 | } |
104 | } | 106 | } |
105 | 107 | ||
106 | - private void addUserCredentialsEnabled(ObjectNode additionalInfo) { | ||
107 | - if(!additionalInfo.isNull()) { | ||
108 | - if(!additionalInfo.has("userCredentialsEnabled")) { | ||
109 | - additionalInfo.put("userCredentialsEnabled", true); | ||
110 | - } | ||
111 | - } | ||
112 | - } | ||
113 | - | ||
114 | @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')") | 108 | @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')") |
115 | @RequestMapping(value = "/user/tokenAccessEnabled", method = RequestMethod.GET) | 109 | @RequestMapping(value = "/user/tokenAccessEnabled", method = RequestMethod.GET) |
116 | @ResponseBody | 110 | @ResponseBody |