|
|
@@ -24,7 +24,7 @@ class WarningScopeMapperTest {
|
|
|
new XMLMapperBuilder(input, configuration, resource, configuration.getSqlFragments()).parse();
|
|
|
}
|
|
|
Map<String, Object> params = new HashMap<>(extra);
|
|
|
- params.put("scope", new WarningAccessScope("current", true, true, true, parentTypes));
|
|
|
+ params.put("scope", WarningAccessScope.restricted("current", true, true, true, parentTypes));
|
|
|
params.putIfAbsent("q", Collections.emptyMap());
|
|
|
params.putIfAbsent("releaseOrder", false);
|
|
|
params.putIfAbsent("pendingOnly", false);
|
|
|
@@ -47,18 +47,53 @@ class WarningScopeMapperTest {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- @Test void missingCompanyOnlyAllowsExplicitSharedDeviceAssignees() throws Exception {
|
|
|
+ @Test void missingCompanyFailsClosedWithoutSharedDeviceException() throws Exception {
|
|
|
for (String query : List.of("selectMobileWarnings", "countVisibleWarning", "countCompanyDevice")) {
|
|
|
String sql = sql(statement(query, Collections.emptySet(), Collections.emptyMap()));
|
|
|
- if (query.equals("countCompanyDevice")) assertTrue(sql.contains("AND 1 = 0"));
|
|
|
- else {
|
|
|
- assertTrue(sql.contains("1 = 0 OR (et.parent_id = 4 AND (w.handler = ? OR w.reviewer = ?))"));
|
|
|
- assertTrue(sql.contains("eb.equipment_code = w.device_code"));
|
|
|
- }
|
|
|
- assertFalse(sql.contains("IN ( )"));
|
|
|
+ assertTrue(sql.contains("1 = 0"), query);
|
|
|
+ assertFalse(sql.contains("et.parent_id = 4"), query);
|
|
|
+ assertFalse(sql.contains("IN ( )"), query);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Test void drainageCompanyKeepsSharedDeviceAssigneeException() throws Exception {
|
|
|
+ String sql = sql(statement("selectMobileWarnings", Set.of(2, 4), Collections.emptyMap()));
|
|
|
+ assertTrue(sql.contains("OR (et.parent_id = 4 AND (w.handler = ? OR w.reviewer = ?))"));
|
|
|
+ assertTrue(sql.contains("et.parent_id IN"));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test void waterAndGasCompaniesHaveNoSharedDeviceException() throws Exception {
|
|
|
+ for (Set<Integer> types : List.of(Set.of(1), Set.of(3))) {
|
|
|
+ String sql = sql(statement("selectMobileWarnings", types, Collections.emptyMap()));
|
|
|
+ assertFalse(sql.contains("et.parent_id = 4 AND"), String.valueOf(types));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test void unrestrictedScopeSkipsAllVisibilityFilters() throws Exception {
|
|
|
+ Configuration configuration = new Configuration();
|
|
|
+ String resource = "mapper/warning/EarlyWarningMapper.xml";
|
|
|
+ try (InputStream input = Resources.getResourceAsStream(resource)) {
|
|
|
+ new XMLMapperBuilder(input, configuration, resource, configuration.getSqlFragments()).parse();
|
|
|
+ }
|
|
|
+ for (String query : List.of("selectWarningList", "searchWarnings", "selectMobileWarnings", "selectMyTasks",
|
|
|
+ "countVisibleWarning", "selectProcessingWarnings", "selectCompletedWarnings", "selectVisibleArchives")) {
|
|
|
+ Map<String, Object> params = new HashMap<>();
|
|
|
+ params.put("scope", WarningAccessScope.unrestricted("admin"));
|
|
|
+ params.putIfAbsent("q", Collections.emptyMap());
|
|
|
+ params.putIfAbsent("releaseOrder", false);
|
|
|
+ params.putIfAbsent("pendingOnly", false);
|
|
|
+ String text = sql(configuration.getMappedStatement(NS + query).getBoundSql(params));
|
|
|
+ assertFalse(text.contains("eb.equipment_code = w.device_code"), query);
|
|
|
+ assertFalse(text.contains("et.parent_id IN"), query);
|
|
|
+ }
|
|
|
+ Map<String, Object> deviceParams = new HashMap<>();
|
|
|
+ deviceParams.put("scope", WarningAccessScope.unrestricted("admin"));
|
|
|
+ deviceParams.put("deviceCode", "any");
|
|
|
+ String deviceSql = sql(configuration.getMappedStatement(NS + "countCompanyDevice").getBoundSql(deviceParams));
|
|
|
+ assertFalse(deviceSql.contains("1 = 0"));
|
|
|
+ assertFalse(deviceSql.contains("et.parent_id IN"));
|
|
|
+ }
|
|
|
+
|
|
|
@Test void pcAndMobileTodoUseSameAssigneePermissionStateRulesWithoutRequiringTodoRows() throws Exception {
|
|
|
String pc = sql(statement("selectMyTasks", Set.of(2, 4), Map.of("q", Map.of("todoType", "TODO"))));
|
|
|
String mobile = sql(statement("selectMobileWarnings", Set.of(2, 4), Map.of("pendingOnly", true)));
|