Skip to content

Commit

Permalink
Merge pull request #174 from IABTechLab/cbc-UID2-2219-client-roles-wr…
Browse files Browse the repository at this point in the history
…ong-admin

Adding fix for the site service
  • Loading branch information
cody-constine-ttd authored Nov 6, 2023
2 parents 1b9a6fe + 53fb88f commit c863526
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/uid2/admin/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ public void run() {
new ServiceLinkService(auth, writeLock, serviceLinkStoreWriter, serviceLinkProvider, serviceProvider, siteProvider),
new OperatorKeyService(config, auth, writeLock, operatorKeyStoreWriter, operatorKeyProvider, siteProvider, keyGenerator, keyHasher),
new SaltService(auth, writeLock, saltStoreWriter, saltProvider, saltRotation),
new SiteService(auth, writeLock, siteStoreWriter, siteProvider, clientKeyProvider),
new SiteService(auth, writeLock, siteStoreWriter, siteProvider, legacyClientKeyProvider),
new PartnerConfigService(auth, writeLock, partnerStoreWriter, partnerConfigProvider),
new PrivateSiteDataRefreshService(auth, jobDispatcher, writeLock, config),
new JobDispatcherService(auth, jobDispatcher),
Expand Down
19 changes: 11 additions & 8 deletions src/main/java/com/uid2/admin/vertx/service/SiteService.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.uid2.admin.vertx.service;

import com.fasterxml.jackson.databind.ObjectWriter;
import com.uid2.admin.legacy.ILegacyClientKeyProvider;
import com.uid2.admin.legacy.LegacyClientKey;
import com.uid2.shared.model.ClientType;
import com.google.common.net.InternetDomainName;
import com.uid2.admin.store.writer.StoreWriter;
Expand Down Expand Up @@ -35,20 +37,20 @@ public class SiteService implements IService {
private final WriteLock writeLock;
private final StoreWriter<Collection<Site>> storeWriter;
private final RotatingSiteStore siteProvider;
private final IClientKeyProvider clientKeyProvider;
private final ILegacyClientKeyProvider legacyClientKeyProvider;
private final ObjectWriter jsonWriter = JsonUtil.createJsonWriter();
private static final Logger LOGGER = LoggerFactory.getLogger(SiteService.class);

public SiteService(AuthMiddleware auth,
WriteLock writeLock,
StoreWriter<Collection<Site>> storeWriter,
RotatingSiteStore siteProvider,
IClientKeyProvider clientKeyProvider) {
ILegacyClientKeyProvider legacyClientKeyProvider) {
this.auth = auth;
this.writeLock = writeLock;
this.storeWriter = storeWriter;
this.siteProvider = siteProvider;
this.clientKeyProvider = clientKeyProvider;
this.legacyClientKeyProvider = legacyClientKeyProvider;
}

@Override
Expand Down Expand Up @@ -99,9 +101,10 @@ private void handleSiteList(RoutingContext rc) {
final Collection<Site> sites = this.siteProvider.getAllSites().stream()
.sorted(Comparator.comparing(Site::getName))
.collect(Collectors.toList());
final Map<Integer, List<ClientKey>> clientKeys = this.clientKeyProvider.getAll().stream()
.collect(Collectors.groupingBy(ClientKey::getSiteId));
final Map<Integer, List<LegacyClientKey>> legacyClientKeys = this.legacyClientKeyProvider.getAll().stream()
.collect(Collectors.groupingBy(LegacyClientKey::getSiteId));
final List<ClientKey> emptySiteKeys = new ArrayList<>();
final List<LegacyClientKey> emptySiteLegacyKeys = new ArrayList<>();
for (Site site : sites) {
JsonObject jo = new JsonObject();
ja.add(jo);
Expand All @@ -116,14 +119,14 @@ private void handleSiteList(RoutingContext rc) {
jo.put("domain_names", domainNamesJa);
jo.put("created", site.getCreated());

List<ClientKey> clients = clientKeys.getOrDefault(site.getId(), emptySiteKeys);
JsonArray jr = new JsonArray();
clients.stream()
List<LegacyClientKey> legacyClients = legacyClientKeys.getOrDefault(site.getId(), emptySiteLegacyKeys);
legacyClients.stream()
.map(c -> c.getRoles()).flatMap(Set::stream).collect(Collectors.toSet())
.forEach(r -> jr.add(r));

jo.put("roles", jr);
jo.put("client_count", clients.size());
jo.put("client_count", legacyClients.size());
}

rc.response()
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/com/uid2/admin/vertx/SiteServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
public class SiteServiceTest extends ServiceTestBase {
@Override
protected IService createService() {
return new SiteService(auth, writeLock, storeWriter, siteProvider, clientKeyProvider);
return new SiteService(auth, writeLock, storeWriter, siteProvider, legacyClientKeyProvider);
}

private void checkSiteResponse(Site[] expectedSites, Object[] actualSites) {
Expand Down

0 comments on commit c863526

Please sign in to comment.