Skip to content

Commit

Permalink
add named parameters on check_publisher_restriction method
Browse files Browse the repository at this point in the history
  • Loading branch information
peczenyj committed Dec 17, 2023
1 parent 7f191b7 commit 41eed4a
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 17 deletions.
35 changes: 27 additions & 8 deletions lib/GDPR/IAB/TCFv2.pm
Original file line number Diff line number Diff line change
Expand Up @@ -333,10 +333,22 @@ sub vendor_legitimate_interest {
}

sub check_publisher_restriction {
my ( $self, $purpose_id, $restrict_type, $vendor ) = @_;
my $self = shift;

my ( $purpose_id, $restriction_type, $vendor_id );

if ( scalar(@_) == 6 ) {
my (%opts) = @_;

$purpose_id = $opts{purpose_id};
$restriction_type = $opts{restriction_type};
$vendor_id = $opts{vendor_id};
}

( $purpose_id, $restriction_type, $vendor_id ) = @_;

return $self->{publisher}
->check_restriction( $purpose_id, $restrict_type, $vendor );
->check_restriction( $purpose_id, $restriction_type, $vendor_id );
}

sub publisher_tc {
Expand Down Expand Up @@ -501,10 +513,10 @@ sub _parse_vendor_section {

# parse vendor legitimate interest

my $pub_restrict_offset =
my $pub_restriction_offset =
$self->_parse_vendor_legitimate_interests($legitimate_interest_offset);

return $pub_restrict_offset;
return $pub_restriction_offset;
}

sub _parse_vendor_consents {
Expand All @@ -523,22 +535,22 @@ sub _parse_vendor_consents {
sub _parse_vendor_legitimate_interests {
my ( $self, $legitimate_interest_offset ) = @_;

my ( $vendor_legitimate_interests, $pub_restrict_offset ) =
my ( $vendor_legitimate_interests, $pub_restriction_offset ) =
$self->_parse_bitfield_or_range(
$legitimate_interest_offset,
);

$self->{vendor_legitimate_interests} = $vendor_legitimate_interests;

return $pub_restrict_offset;
return $pub_restriction_offset;
}

sub _parse_publisher_section {
my ( $self, $pub_restrict_offset ) = @_;
my ( $self, $pub_restriction_offset ) = @_;

# parse public restrictions

my $core_data = substr( $self->{core_data}, $pub_restrict_offset );
my $core_data = substr( $self->{core_data}, $pub_restriction_offset );
my $core_data_size = length( $self->{core_data} );

my $publisher = GDPR::IAB::TCFv2::Publisher->Parse(
Expand Down Expand Up @@ -959,6 +971,13 @@ It true, there is a publisher restriction of certain type, for a given purpose i
# with restriction type 0 'Purpose Flatly Not Allowed by Publisher'
my $ok = $instance->check_publisher_restriction(1, 0, 284);
or
my $ok = $instance->check_publisher_restriction(
purpose_id => 1,
restriction_type => 0,
vendor_id => 284);
Version 2.0 of the Framework introduced the ability for publishers to signal restrictions on how vendors may process personal data. Restrictions can be of two types:
=over
Expand Down
25 changes: 17 additions & 8 deletions lib/GDPR/IAB/TCFv2/PublisherRestrictions.pm
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,22 @@ sub Parse {
}

sub check_restriction {
my ( $self, $purpose_id, $restrict_type, $vendor ) = @_;
my $self = shift;

my $nargs = scalar(@_);

croak "missing arguments: purpose id, restriction type and vendor id"
if $nargs == 0;
croak "missing arguments: restriction type and vendor id" if $nargs == 1;
croak "missing argument: vendor id" if $nargs == 2;

my ( $purpose_id, $restriction_type, $vendor_id ) = @_;

return 0
unless exists $self->{restrictions}->{$purpose_id}->{$restrict_type};
unless exists $self->{restrictions}->{$purpose_id}->{$restriction_type};

return $self->{restrictions}->{$purpose_id}->{$restrict_type}
->contains($vendor);
return $self->{restrictions}->{$purpose_id}->{$restriction_type}
->contains($vendor_id);
}

sub TO_JSON {
Expand All @@ -86,11 +95,11 @@ sub TO_JSON {

my %purpose_restrictions;

foreach my $restrict_type ( keys %{$restriction_map} ) {
my $vendors = $restriction_map->{$restrict_type}->all;
foreach my $restriction_type ( keys %{$restriction_map} ) {
my $vendors = $restriction_map->{$restriction_type}->all;

foreach my $vendor ( @{$vendors} ) {
$purpose_restrictions{$vendor} = int($restrict_type);
$purpose_restrictions{$vendor} = int($restriction_type);
}
}

Expand Down Expand Up @@ -147,7 +156,7 @@ Return true for a given combination of purpose id, restriction type and vendor
my $purpose_id = 1;
my $restriction_type = 0;
my $vendor = 284;
$ok = $range->check_restriction($purpose_id, $restriction_type, $vendor);
my $ok = $range->check_restriction($purpose_id, $restriction_type, $vendor);
=head2 TO_JSON
Expand Down
6 changes: 5 additions & 1 deletion t/01-parse.t
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,11 @@ subtest "bitfield" => sub {
};

ok !$consent->check_publisher_restriction( 1, 0, 284 ),
"should have no publisher restriction to vendor 284 regarding purpose id 1 of type 0 'Purpose Flatly Not Allowed by Publisher'";
"should have no publisher restriction to vendor 284 regarding purpose id 1 of type 0 'Purpose Flatly Not Allowed by Publisher' when called with positional parameters";

ok !$consent->check_publisher_restriction( purpose_id => 1,
restriction_type => 0, vendor_id => 284 ),
"should have no publisher restriction to vendor 284 regarding purpose id 1 of type 0 'Purpose Flatly Not Allowed by Publisher' when called with named parameters";

my $publisher_tc = $consent->publisher_tc;

Expand Down

0 comments on commit 41eed4a

Please sign in to comment.