feat(system): user companyId, kept on update when the request omits it
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
This commit is contained in:
1 parent
42071a850f
commit
72b724f468
4 files changed
+60
-1
No files matched your search
@@ -9,7 +9,7 @@ Babyboo source: `~/Projects/babyboo` (read only). All tasks run serially; most t
|
||||
|
||||
## 2. services-system
|
||||
|
||||
- [ ] 2.1 Add `companyId` to `services-system` `User` (column `company_id`) and make `/user/save` keep it. Test first: saving a user with `companyId` 1 and reading it back returns 1; saving an existing user without `companyId` does not clear it. Verify: `mvn -T 1C -pl solvway-services-system -am verify`.
|
||||
- [x] 2.1 Add `companyId` to `services-system` `User` (column `company_id`) and make `/user/save` keep it. Test first: saving a user with `companyId` 1 and reading it back returns 1; saving an existing user without `companyId` does not clear it. Verify: `mvn -T 1C -pl solvway-services-system -am verify`.
|
||||
- Scope: `solvway-services-system/src/**`
|
||||
|
||||
## 3. mobile-api admin guard
|
||||
|
||||
+3
@@ -302,6 +302,9 @@ public class UserController {
|
||||
if(user.getId()!=null) {
|
||||
User persistedUser = findByIdWithPassword(user.getId());
|
||||
user.setPassword(persistedUser.getPassword());
|
||||
if(user.getCompanyId() == null) {
|
||||
user.setCompanyId(persistedUser.getCompanyId());
|
||||
}
|
||||
}
|
||||
if(user.getLogin() != null) {
|
||||
user.setLogin(user.getLogin());
|
||||
|
||||
@@ -129,6 +129,8 @@ public class User {
|
||||
|
||||
private String master;
|
||||
|
||||
private Long companyId;
|
||||
|
||||
|
||||
@Transient
|
||||
private List<String> linkedAccounts;
|
||||
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
package com.solvway.services.system.controller;
|
||||
|
||||
import com.solvway.services.system.model.User;
|
||||
import com.solvway.services.system.service.UserService;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class UserControllerCompanyTest {
|
||||
|
||||
@Mock
|
||||
private UserService userService;
|
||||
@InjectMocks
|
||||
private UserController controller;
|
||||
|
||||
@Test
|
||||
void newUserKeepsCompanyFromRequest() {
|
||||
User user = new User();
|
||||
user.setCompanyId(1L);
|
||||
when(userService.save(any(User.class))).thenAnswer(i -> i.getArgument(0));
|
||||
|
||||
User saved = controller.save(user);
|
||||
|
||||
assertThat(saved.getCompanyId()).isEqualTo(1L);
|
||||
}
|
||||
|
||||
@Test
|
||||
void updateWithoutCompanyKeepsPersistedCompany() {
|
||||
User persisted = new User();
|
||||
persisted.setId(7L);
|
||||
persisted.setCompanyId(1L);
|
||||
when(userService.findById(7L)).thenReturn(Optional.of(persisted));
|
||||
when(userService.save(any(User.class))).thenAnswer(i -> i.getArgument(0));
|
||||
|
||||
User update = new User();
|
||||
update.setId(7L);
|
||||
controller.save(update);
|
||||
|
||||
ArgumentCaptor<User> saved = ArgumentCaptor.forClass(User.class);
|
||||
verify(userService).save(saved.capture());
|
||||
assertThat(saved.getValue().getCompanyId()).isEqualTo(1L);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user