Skip to content

Commit 34060c7

Browse files
committed
add disabled field to services and service links
1 parent f168653 commit 34060c7

File tree

6 files changed

+138
-16
lines changed

6 files changed

+138
-16
lines changed

src/main/java/com/uid2/admin/vertx/service/ServiceLinkService.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ private void handleServiceLinkUpdate(RoutingContext rc) {
162162
Integer siteId = body.getInteger("site_id");
163163
String name = body.getString("name");
164164
JsonArray rolesJson = body.getJsonArray("roles");
165+
Boolean disabled = body.getBoolean("disabled");
165166

166167
if (siteId == null || serviceId == null || linkId == null || linkId.isEmpty()) {
167168
ResponseUtil.error(rc, 400, "required parameters: site_id, service_id, link_id");
@@ -195,6 +196,10 @@ private void handleServiceLinkUpdate(RoutingContext rc) {
195196
serviceLink.setName(name);
196197
}
197198

199+
if (disabled != null) {
200+
serviceLink.setDisabled(disabled);
201+
}
202+
198203
if (rolesJson != null && !rolesJson.isEmpty()) {
199204
final Set<Role> roles;
200205
try {
@@ -259,6 +264,7 @@ private JsonObject toJson(ServiceLink s) {
259264
jsonObject.put("site_id", s.getSiteId());
260265
jsonObject.put("name", s.getName());
261266
jsonObject.put("roles", s.getRoles());
267+
jsonObject.put("disabled", s.isDisabled());
262268
return jsonObject;
263269
}
264270

src/main/java/com/uid2/admin/vertx/service/ServiceService.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ private void handleUpdate(RoutingContext rc) {
191191
Integer siteId = body.getInteger("site_id");
192192
String name = body.getString("name");
193193
String linkIdRegex = body.getString("link_id_regex");
194+
Boolean disabled = body.getBoolean("disabled");
194195

195196
JsonArray rolesSpec = null;
196197
if (body.getString("roles") != null && !body.getString("roles").isEmpty()) {
@@ -242,6 +243,10 @@ private void handleUpdate(RoutingContext rc) {
242243
service.setLinkIdRegex(linkIdRegex);
243244
}
244245

246+
if (disabled != null) {
247+
service.setDisabled(disabled);
248+
}
249+
245250
if (siteId != null && siteId != 0) {
246251
service.setSiteId(siteId);
247252
}
@@ -295,6 +300,7 @@ private JsonObject toJson(Service s) {
295300
jsonObject.put("name", s.getName());
296301
jsonObject.put("roles", s.getRoles());
297302
jsonObject.put("link_id_regex", s.getLinkIdRegex());
303+
jsonObject.put("disabled", s.isDisabled());
298304
return jsonObject;
299305
}
300306

src/test/java/com/uid2/admin/vertx/ServiceLinkServiceTest.java

Lines changed: 72 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import io.vertx.junit5.VertxTestContext;
1414
import org.junit.jupiter.api.Test;
1515
import org.junit.jupiter.params.ParameterizedTest;
16+
import org.junit.jupiter.params.provider.Arguments;
1617
import org.junit.jupiter.params.provider.MethodSource;
1718
import org.junit.jupiter.params.provider.ValueSource;
1819

@@ -387,6 +388,34 @@ void updateServiceLink_updateNameOnly_succeeds(Vertx vertx, VertxTestContext tes
387388
});
388389
}
389390

391+
@Test
392+
void updateServiceLink_updateDisabledOnly_succeeds(Vertx vertx, VertxTestContext testContext) {
393+
fakeAuth(Role.MAINTAINER);
394+
395+
setSites(new Site(123, "name1", false));
396+
setServices(new Service(1, 123, "name1", Set.of(Role.MAINTAINER, Role.MAPPER)));
397+
ServiceLink existingLink = new ServiceLink("link1", 1, 123, "name1", Set.of(Role.MAPPER));
398+
setServiceLinks(existingLink);
399+
400+
JsonObject jo = new JsonObject();
401+
jo.put("link_id", "link1");
402+
jo.put("service_id", 1);
403+
jo.put("site_id", 123);
404+
jo.put("disabled", true);
405+
406+
ServiceLink expected = new ServiceLink("link1", 1, 123, "name1", Set.of(Role.MAPPER));
407+
expected.setDisabled(true);
408+
409+
post(vertx, testContext, "api/service_link/update", jo.encode(), response -> {
410+
assertEquals(200, response.statusCode());
411+
checkServiceLinkJson(expected, response.bodyAsJsonObject());
412+
verify(serviceStoreWriter, never()).upload(null, null);
413+
verify(serviceLinkStoreWriter, times(1)).upload(List.of(expected), null);
414+
415+
testContext.completeNow();
416+
});
417+
}
418+
390419
@Test
391420
void updateServiceLink_updateRoleOnly_succeeds(Vertx vertx, VertxTestContext testContext) {
392421
fakeAuth(Role.MAINTAINER);
@@ -442,6 +471,35 @@ void updateServiceLink_updateRoleAndName_succeeds(Vertx vertx, VertxTestContext
442471
});
443472
}
444473

474+
@Test
475+
void updateServiceLink_updateRoleNameDisabled_succeeds(Vertx vertx, VertxTestContext testContext) {
476+
fakeAuth(Role.MAINTAINER);
477+
478+
setSites(new Site(123, "name1", false));
479+
setServices(new Service(1, 123, "name1", Set.of(Role.MAINTAINER, Role.MAPPER, Role.SHARER)));
480+
ServiceLink existingLink = new ServiceLink("link1", 1, 123, "name1", Set.of(Role.MAPPER));
481+
setServiceLinks(existingLink);
482+
483+
JsonObject jo = new JsonObject();
484+
jo.put("link_id", "link1");
485+
jo.put("service_id", 1);
486+
jo.put("site_id", 123);
487+
jo.put("name", "newname");
488+
jo.put("roles", JsonArray.of(Role.MAPPER, Role.SHARER));
489+
jo.put("disabled", true);
490+
491+
ServiceLink expected = new ServiceLink("link1", 1, 123, "newname", Set.of(Role.MAPPER, Role.SHARER), true);
492+
493+
post(vertx, testContext, "api/service_link/update", jo.encode(), response -> {
494+
assertEquals(200, response.statusCode());
495+
checkServiceLinkJson(expected, response.bodyAsJsonObject());
496+
verify(serviceStoreWriter, never()).upload(null, null);
497+
verify(serviceLinkStoreWriter, times(1)).upload(List.of(expected), null);
498+
499+
testContext.completeNow();
500+
});
501+
}
502+
445503
@Test
446504
void updateServiceLink_roleDoesNotExist_returnsError(Vertx vertx, VertxTestContext testContext) {
447505
fakeAuth(Role.MAINTAINER);
@@ -622,20 +680,20 @@ void addServiceLink_linkIdRegex_validation(String linkIdRegex, String linkId, bo
622680

623681
private static java.util.stream.Stream<org.junit.jupiter.params.provider.Arguments> linkIdRegexCases() {
624682
return java.util.stream.Stream.of(
625-
org.junit.jupiter.params.provider.Arguments.of("link[0-9]+", "invalidLink", false),
626-
org.junit.jupiter.params.provider.Arguments.of("link[0-9]+", "link42", true),
627-
org.junit.jupiter.params.provider.Arguments.of("^[A-Z0-9_]{1,256}$", "XY12345", true), // snowflake valid
628-
org.junit.jupiter.params.provider.Arguments.of("^[A-Z0-9_]{1,256}$", "UID2_ENVIRONMENT", true), // snowflake valid
629-
org.junit.jupiter.params.provider.Arguments.of("^[A-Z0-9_]{1,256}$", "xy12345", false), // snowflake invalid, lowercase
630-
org.junit.jupiter.params.provider.Arguments.of("^[A-Z0-9_]{1,256}$", "X", true), // snowflake valid, minimum length
631-
org.junit.jupiter.params.provider.Arguments.of("^[A-Z0-9_]{1,256}$", "X".repeat(256), true), // snowflake valid, maximum length
632-
org.junit.jupiter.params.provider.Arguments.of("^[A-Z0-9_]{1,256}$", "X".repeat(257), false), // snowflake invalid, exceeds maximum length
633-
org.junit.jupiter.params.provider.Arguments.of("^[A-Z0-9_]{1,256}$", " XY12345", false), // snowflake invalid, leading whitespace
634-
org.junit.jupiter.params.provider.Arguments.of("^[A-Z0-9_]{1,256}$", "XY12345 ", false), // snowflake invalid, trailing whitespace
635-
org.junit.jupiter.params.provider.Arguments.of("^[A-Z0-9_]{1,256}$", "XY 12345", false), // snowflake invalid, whitespace in the middle
636-
org.junit.jupiter.params.provider.Arguments.of("^[A-Z0-9_]{1,256}$", "", false), // snowflake invalid, empty
637-
org.junit.jupiter.params.provider.Arguments.of("^[A-Z0-9_]{1,256}$", " ", false), // snowflake invalid, just whitespace
638-
org.junit.jupiter.params.provider.Arguments.of("^[A-Z0-9_]{1,256}$", "XY_12345", true) // snowflake valid, used underscore
683+
Arguments.of("link[0-9]+", "invalidLink", false),
684+
Arguments.of("link[0-9]+", "link42", true),
685+
Arguments.of("^[A-Z0-9_]{1,256}$", "XY12345", true), // snowflake valid
686+
Arguments.of("^[A-Z0-9_]{1,256}$", "UID2_ENVIRONMENT", true), // snowflake valid
687+
Arguments.of("^[A-Z0-9_]{1,256}$", "xy12345", false), // snowflake invalid, lowercase
688+
Arguments.of("^[A-Z0-9_]{1,256}$", "X", true), // snowflake valid, minimum length
689+
Arguments.of("^[A-Z0-9_]{1,256}$", "X".repeat(256), true), // snowflake valid, maximum length
690+
Arguments.of("^[A-Z0-9_]{1,256}$", "X".repeat(257), false), // snowflake invalid, exceeds maximum length
691+
Arguments.of("^[A-Z0-9_]{1,256}$", " XY12345", false), // snowflake invalid, leading whitespace
692+
Arguments.of("^[A-Z0-9_]{1,256}$", "XY12345 ", false), // snowflake invalid, trailing whitespace
693+
Arguments.of("^[A-Z0-9_]{1,256}$", "XY 12345", false), // snowflake invalid, whitespace in the middle
694+
Arguments.of("^[A-Z0-9_]{1,256}$", "", false), // snowflake invalid, empty
695+
Arguments.of("^[A-Z0-9_]{1,256}$", " ", false), // snowflake invalid, just whitespace
696+
Arguments.of("^[A-Z0-9_]{1,256}$", "XY_12345", true) // snowflake valid, used underscore
639697
);
640698
}
641699
}

src/test/java/com/uid2/admin/vertx/ServiceServiceTest.java

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,26 @@ void updateName(Vertx vertx, VertxTestContext testContext) {
580580
});
581581
}
582582

583+
@Test
584+
void updateDisabled(Vertx vertx, VertxTestContext testContext) {
585+
fakeAuth(Role.PRIVILEGED);
586+
587+
Service existingService = new Service(1, 123, "name1", Set.of(Role.MAINTAINER));
588+
setServices(existingService);
589+
590+
JsonObject jo = new JsonObject();
591+
jo.put("service_id", 1);
592+
jo.put("disabled", true);
593+
594+
post(vertx, testContext, "api/service/update", jo.encode(), response -> {
595+
assertEquals(200, response.statusCode());
596+
existingService.setDisabled(true);
597+
checkServiceJson(existingService, response.bodyAsJsonObject());
598+
verify(serviceStoreWriter, times(1)).upload(List.of(existingService), null);
599+
testContext.completeNow();
600+
});
601+
}
602+
583603
@Test
584604
void updateSiteId(Vertx vertx, VertxTestContext testContext) {
585605
fakeAuth(Role.PRIVILEGED);
@@ -600,6 +620,32 @@ void updateSiteId(Vertx vertx, VertxTestContext testContext) {
600620
});
601621
}
602622

623+
@Test
624+
void updateNameDisabledSiteIdRoles(Vertx vertx, VertxTestContext testContext) {
625+
fakeAuth(Role.PRIVILEGED);
626+
627+
Service existingService = new Service(1, 123, "name1", Set.of(Role.MAINTAINER));
628+
setServices(existingService);
629+
630+
JsonObject jo = new JsonObject();
631+
jo.put("service_id", 1);
632+
jo.put("site_id", 456);
633+
jo.put("name", "newname");
634+
jo.put("disabled", true);
635+
jo.put("roles", JsonArray.of(Role.MAINTAINER, Role.MAPPER, Role.SHARER));
636+
637+
post(vertx, testContext, "api/service/update", jo.encode(), response -> {
638+
assertEquals(200, response.statusCode());
639+
existingService.setSiteId(456);
640+
existingService.setName("newname");
641+
existingService.setDisabled(true);
642+
existingService.setRoles(Set.of(Role.MAINTAINER, Role.MAPPER, Role.SHARER));
643+
checkServiceJson(existingService, response.bodyAsJsonObject());
644+
verify(serviceStoreWriter, times(1)).upload(List.of(existingService), null);
645+
testContext.completeNow();
646+
});
647+
}
648+
603649
@Test
604650
void updateWithEmptyValues(Vertx vertx, VertxTestContext testContext) {
605651
fakeAuth(Role.PRIVILEGED);

webroot/adm/service-link.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ <h3>Inputs</h3>
2424
<input type="text" id="linkName" name="linkName">
2525
<label for="roles">Roles:</label>
2626
<input type="text" id="roles" name="roles">
27+
<label for="disabled">Disable Service Link:</label>
28+
<input type="checkbox" id="disabled" name="disabled">
2729
</div>
2830

2931
<br>
@@ -95,7 +97,8 @@ <h3>Output</h3>
9597
return
9698
}
9799
const roles = ($('#roles').val()).replace(/\s+/g, '').split(',').filter( (value, _, __) => value !== "");
98-
doApiCall('POST', '/api/service_link/update', '#standardOutput', '#errorOutput', JSON.stringify({link_id: linkId, service_id: serviceId, site_id: siteId, name: linkName, roles: roles}));
100+
const disabled = $('#disabled').is(':checked')
101+
doApiCall('POST', '/api/service_link/update', '#standardOutput', '#errorOutput', JSON.stringify({link_id: linkId, service_id: serviceId, site_id: siteId, name: linkName, roles: roles, disabled: disabled}));
99102
});
100103

101104
$('#doDelete').on('click', function () {

webroot/adm/service.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ <h3>Inputs</h3>
2424
<input type="text" id="roles" name="roles">
2525
<label for="linkIdRegex">Link Id Regex:</label>
2626
<input type="text" id="linkIdRegex" name="linkIdRegex">
27+
<label for="disabled">Disable Service:</label>
28+
<input type="checkbox" id="disabled" name="disabled">
2729
</div>
2830

2931
<br>
@@ -106,8 +108,9 @@ <h3>Output</h3>
106108
let roles = ($('#roles').val()).replace(/\s+/g, '').split(',').filter( (value, _, __) => value !== "");
107109
roles = roles.length > 0 ? roles : null;
108110
const linkIdRegex = $('#linkIdRegex').val()
111+
const disabled = $('#disabled').is(':checked')
109112

110-
doApiCall('POST', '/api/service/update', '#standardOutput', '#errorOutput', JSON.stringify({service_id: serviceId, site_id: siteId, name: serviceName, roles: roles, link_id_regex: linkIdRegex}));
113+
doApiCall('POST', '/api/service/update', '#standardOutput', '#errorOutput', JSON.stringify({service_id: serviceId, site_id: siteId, name: serviceName, roles: roles, link_id_regex: linkIdRegex, disabled: disabled}));
111114
});
112115

113116
$('#doDelete').on('click', function () {

0 commit comments

Comments
 (0)