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
@@ -51,7 +51,7 @@ See proposal.md for why.
|
||||
| 40500000 | `BO_LEADS_EDIT` | Edit leads | `M` | NULL | NULL |
|
||||
| 40600000 | `BO_LEADS_EXPORT` | Export leads | `M` | NULL | NULL |
|
||||
|
||||
**Edit and Export modules:** these are url-less `M` modules, so they can be granted and never show in the sidebar. A first draft used type `A`, which the Roles screen cannot grant.
|
||||
**Edit and Export modules:** these are url-less `M` modules, so they can be granted and never show in the sidebar. A first draft used type `A`, which the Roles screen cannot grant. The ACL menu that `/api/admin/me` returns (`ModuleService.findAllUrlByArea` in `services-system`) used to keep only modules with a url or type `A` modules, so these two never reached the portal's `hasModule`. The menu now also keeps a type `M` module that has a parent. Found in the browser check (task 4.3).
|
||||
|
||||
**Placement:** the two modules sit directly under the root, not under `BO_LEADS`. That way a role with only `BO_EVENT_LEADS` can still be given export.
|
||||
|
||||
|
||||
@@ -53,4 +53,5 @@ None. The Event Leads Listing (`event-lead-capture`) keeps its requirements; the
|
||||
- a "View lead" link on the event lead edit page.
|
||||
- Database: one new index on `service-counter`.`event_lead`, and three `service-system`.`module` rows. Additive only.
|
||||
- `local/seed/03-colite.sql` mirrors the index and the module rows.
|
||||
- `solvway-services-system`: the ACL menu keeps url-less `M` modules that have a parent, so `BO_LEADS_EDIT` and `BO_LEADS_EXPORT` reach the portal.
|
||||
- No change to the gateway, existing tables or existing endpoints.
|
||||
@@ -90,9 +90,15 @@ Design: `design.md` (decision numbers below refer to it). All tasks run serially
|
||||
- Scope: `solvway-admin-portal/app/api/**/export/**`, `solvway-admin-portal/app/lib/**`, `solvway-admin-portal/app/leads/page*`, `solvway-admin-portal/app/event-leads/[eventUuid]/page*`
|
||||
- Verify: as 4.1.
|
||||
|
||||
- [x] 4.3 Make the ACL menu carry url-less `M` modules (found in the browser check). `ModuleService.findAllUrlByArea` kept only modules with a url or type `A`, so `BO_LEADS_EDIT` and `BO_LEADS_EXPORT` never reached `hasModule` and the edit form and Export button never showed. Keep a type `M` module with a parent too.
|
||||
|
||||
Tests first: a granted url-less `M` module is in the menu, one not granted is not, and super admin gets it.
|
||||
- Scope: `solvway-services-system/src/**/service/ModuleService*`
|
||||
- Verify: `mvn -T 1C -B -q -pl solvway-services-system -am verify`.
|
||||
|
||||
## 5. Browser check
|
||||
|
||||
- [ ] 5.1 Rebuild the changed services and drive the portal with Playwright, using only local dev data and made-up test leads.
|
||||
- [x] 5.1 Rebuild the changed services and drive the portal with Playwright, using only local dev data and made-up test leads.
|
||||
- **Desktop:**
|
||||
- Grant the three modules to a role.
|
||||
- On Leads, check the counts, last event and latest salesperson of a lead captured at two events.
|
||||
|
||||
+2
-1
@@ -51,7 +51,8 @@ public class ModuleService {
|
||||
public List<Module> findAllUrlByArea(Area area) {
|
||||
List<Module> list = moduleRepository.findAllUrlByArea(area);
|
||||
list = list.stream().filter(m-> StringUtils.hasLength(m.getUrl()) ||
|
||||
(m.getType().equals(ModuleType.A) && m.getParent()!=null && m.getParent().getId()!=null)
|
||||
// A url-less M (e.g. BO_LEADS_EXPORT) is a grantable permission the portal checks with hasModule.
|
||||
((m.getType() == ModuleType.A || m.getType() == ModuleType.M) && m.getParent()!=null && m.getParent().getId()!=null)
|
||||
)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
|
||||
+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