-
Notifications
You must be signed in to change notification settings - Fork 228
LI module: Fixing permission logic #4389
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -44,6 +44,7 @@ | |
| import org.prebid.server.vertx.httpclient.HttpClient; | ||
| import org.prebid.server.vertx.httpclient.model.HttpClientResponse; | ||
|
|
||
| import java.util.Collections; | ||
| import java.util.List; | ||
| import java.util.Objects; | ||
| import java.util.Optional; | ||
|
|
@@ -58,6 +59,8 @@ public class LiveIntentOmniChannelIdentityProcessedAuctionRequestHook implements | |
|
|
||
| private static final String CODE = "liveintent-omni-channel-identity-enrichment-hook"; | ||
|
|
||
| private static final String INSERTER = "s2s.liveintent.com"; | ||
|
|
||
| private final LiveIntentOmniChannelProperties config; | ||
| private final JacksonMapper mapper; | ||
| private final HttpClient httpClient; | ||
|
|
@@ -161,7 +164,11 @@ private MultiMap headers() { | |
| } | ||
|
|
||
| private IdResResponse processResponse(HttpClientResponse response) { | ||
| return mapper.decodeValue(response.getBody(), IdResResponse.class); | ||
| final IdResResponse res = mapper.decodeValue(response.getBody(), IdResResponse.class); | ||
| final List<Eid> eids = res.getEids().stream() | ||
| .map(eid -> eid.toBuilder().inserter(INSERTER).build()) | ||
| .toList(); | ||
| return IdResResponse.of(eids); | ||
| } | ||
|
|
||
| private static Future<InvocationResult<AuctionRequestPayload>> noAction() { | ||
|
|
@@ -208,14 +215,6 @@ private BidRequest updateAllowedBidders(BidRequest bidRequest, List<Eid> resolve | |
| final ExtRequestPrebid extPrebid = ext != null ? ext.getPrebid() : null; | ||
| final ExtRequestPrebidData extPrebidData = extPrebid != null ? extPrebid.getData() : null; | ||
|
|
||
| final List<ExtRequestPrebidDataEidPermissions> existingPerms = extPrebidData != null | ||
| ? extPrebidData.getEidPermissions() | ||
| : null; | ||
|
|
||
| if (CollectionUtils.isEmpty(existingPerms)) { | ||
| return bidRequest; | ||
| } | ||
|
|
||
| final ExtRequestPrebid updatedExtPrebid = Optional.ofNullable(extPrebid) | ||
| .map(ExtRequestPrebid::toBuilder) | ||
| .orElseGet(ExtRequestPrebid::builder) | ||
|
|
@@ -237,7 +236,11 @@ private ExtRequestPrebidData updatePrebidData(ExtRequestPrebidData extPrebidData | |
| .map(Eid::getSource) | ||
| .collect(Collectors.toSet()); | ||
|
|
||
| final List<ExtRequestPrebidDataEidPermissions> updatedPermissions = extPrebidData.getEidPermissions().stream() | ||
| final List<ExtRequestPrebidDataEidPermissions> eidPermissions = extPrebidData != null | ||
| ? ListUtils.emptyIfNull(extPrebidData.getEidPermissions()) | ||
| : Collections.emptyList(); | ||
|
|
||
| final List<ExtRequestPrebidDataEidPermissions> updatedPermissions = eidPermissions.stream() | ||
| .map(permission -> restrictEidPermission(permission, resolvedSources)) | ||
| .filter(Objects::nonNull) | ||
| .toList(); | ||
|
|
@@ -252,16 +255,24 @@ private ExtRequestPrebidDataEidPermissions restrictEidPermission(ExtRequestPrebi | |
| return permission; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You added inserter into each EID your module inserts, but you didn't target it by rule. The idea is to use a combination of |
||
| } | ||
|
|
||
| final List<String> permittedBidders = ListUtils.emptyIfNull(permission.getBidders()); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need for |
||
|
|
||
| if (CollectionUtils.isEmpty(permittedBidders) || permittedBidders.contains("*")) { | ||
| return ExtRequestPrebidDataEidPermissions.builder() | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When updating existing permissions, its a bad idea to recreate them from scratch. Only replace the objects you have updated. |
||
| .source(permission.getSource()) | ||
| .bidders(targetBidders.stream().toList()) | ||
| .build(); | ||
| } | ||
|
|
||
| final List<String> finalBidders = ListUtils.emptyIfNull(permission.getBidders()).stream() | ||
| .filter(targetBidders::contains) | ||
| .toList(); | ||
|
|
||
| return CollectionUtils.isEmpty(finalBidders) | ||
| ? null | ||
| : ExtRequestPrebidDataEidPermissions | ||
| .builder() | ||
| .bidders(finalBidders) | ||
| : ExtRequestPrebidDataEidPermissions.builder() | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When updating existing permissions, its a bad idea to recreate them from scratch. Only replace the objects you have updated. |
||
| .source(permission.getSource()) | ||
| .bidders(finalBidders) | ||
| .build(); | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there are no incoming EID permissions, you will end up not defining any at all. You should have 2 logic branches:
To make things work right now, you can only stick to the first option for the time being: just always add a specific permission for a source + inserter combination with the allowed bidders if your module actually added new EIDs.