fix(services-system): keep url-less M modules in the ACL menu
BO_LEADS_EDIT and BO_LEADS_EXPORT are grantable url-less M modules, but the ACL menu kept only modules with a url or type A, so the portal's hasModule never saw them and the edit form and Export button never showed. Found in the browser check. 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
5f4f2705e8
commit
0593b5379c
5 files changed
+121
-3
No files matched your search
+110
@@ -0,0 +1,110 @@
|
||||
package com.solvway.services.system.service;
|
||||
|
||||
import com.solvway.services.system.constant.SystemConstants.Area;
|
||||
import com.solvway.services.system.model.Module;
|
||||
import com.solvway.services.system.model.Module.ModuleType;
|
||||
import com.solvway.services.system.model.ModuleSub;
|
||||
import com.solvway.services.system.model.Role;
|
||||
import com.solvway.services.system.repo.ModuleRepository;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class ModuleServiceTest {
|
||||
|
||||
@Mock
|
||||
private ModuleRepository moduleRepository;
|
||||
|
||||
private ModuleService service;
|
||||
|
||||
private Module root;
|
||||
private Module leads;
|
||||
private Module leadsExport;
|
||||
private Module legacyAction;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
service = new ModuleService();
|
||||
ReflectionTestUtils.setField(service, "moduleRepository", moduleRepository);
|
||||
// Mirrors local/seed/03-colite.sql: the lead modules hang directly off BO_ROOT.
|
||||
root = module(40000000L, "BO_ROOT", ModuleType.R, null, null);
|
||||
leads = module(40400000L, "BO_LEADS", ModuleType.M, "/leads", root);
|
||||
leadsExport = module(40600000L, "BO_LEADS_EXPORT", ModuleType.M, null, root);
|
||||
legacyAction = module(40900000L, "LEGACY_ACTION", ModuleType.A, null, root);
|
||||
}
|
||||
|
||||
private static Module module(long id, String name, ModuleType type, String url, Module parent) {
|
||||
Module m = new Module();
|
||||
m.setId(id);
|
||||
m.setName(name);
|
||||
m.setType(type);
|
||||
m.setUrl(url);
|
||||
m.setArea(Area.BO);
|
||||
if (parent != null) {
|
||||
ModuleSub p = new ModuleSub();
|
||||
p.setId(parent.getId());
|
||||
m.setParent(p);
|
||||
}
|
||||
return m;
|
||||
}
|
||||
|
||||
private static Role role(long id, Module... granted) {
|
||||
Role r = new Role();
|
||||
r.setId(id);
|
||||
for (Module m : granted) m.getRoles().add(r);
|
||||
return r;
|
||||
}
|
||||
|
||||
private static List<String> names(Module node) {
|
||||
List<String> out = new ArrayList<>();
|
||||
out.add(node.getName());
|
||||
if (node.getChildren() != null) for (Module c : node.getChildren()) out.addAll(names(c));
|
||||
return out;
|
||||
}
|
||||
|
||||
private void stubArea() {
|
||||
List<Module> all = List.of(root, leads, leadsExport, legacyAction);
|
||||
when(moduleRepository.findRootByArea(Area.BO)).thenReturn(root);
|
||||
when(moduleRepository.findAllByArea(Area.BO)).thenReturn(all);
|
||||
when(moduleRepository.findAllUrlByArea(Area.BO)).thenReturn(all);
|
||||
}
|
||||
|
||||
@Test
|
||||
void aclMenu_keepsAGrantedUrlLessModule() {
|
||||
stubArea();
|
||||
Role sales = role(5L, leads, leadsExport);
|
||||
|
||||
Module menu = service.getACLMenu(Area.BO, List.of(sales)).orElseThrow();
|
||||
|
||||
assertThat(names(menu)).contains("BO_LEADS", "BO_LEADS_EXPORT");
|
||||
}
|
||||
|
||||
@Test
|
||||
void aclMenu_leavesOutAUrlLessModuleTheRoleWasNotGranted() {
|
||||
stubArea();
|
||||
Role sales = role(5L, leads);
|
||||
|
||||
Module menu = service.getACLMenu(Area.BO, List.of(sales)).orElseThrow();
|
||||
|
||||
assertThat(names(menu)).contains("BO_LEADS").doesNotContain("BO_LEADS_EXPORT");
|
||||
}
|
||||
|
||||
@Test
|
||||
void aclMenu_superAdminGetsUrlLessModules() {
|
||||
stubArea();
|
||||
|
||||
Module menu = service.getACLMenu(Area.BO, List.of(role(1L))).orElseThrow();
|
||||
|
||||
assertThat(names(menu)).contains("BO_LEADS", "BO_LEADS_EXPORT", "LEGACY_ACTION");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user