Skip to content
GitLab
Menu
Why GitLab
Pricing
Contact Sales
Explore
Why GitLab
Pricing
Contact Sales
Explore
Sign in
Get free trial
Commits on Source (2)
(refactor): Never ignore ACL when reading boosted campaign entities
· 24bd6128
Emiliano Balbuena
authored
Jul 31, 2019
24bd6128
(chore): Code style
· 3f4e4d30
Emiliano Balbuena
authored
Jul 31, 2019
3f4e4d30
Hide whitespace changes
Inline
Side-by-side
Core/Boost/Campaigns/Iterator.php
View file @
3f4e4d30
...
...
@@ -130,7 +130,17 @@ class Iterator implements \Iterator
public
function
getList
()
{
$response
=
$this
->
manager
->
getList
([
'limit'
=>
$this
->
limit
,
'from'
=>
$this
->
from
,
'offset'
=>
$this
->
offset
,
'type'
=>
$this
->
type
,
'owner_guid'
=>
$this
->
ownerGuid
,
'state'
=>
$this
->
state
,
'rating'
=>
$this
->
rating
,
'quality'
=>
$this
->
quality
,]);
$response
=
$this
->
manager
->
getList
([
'limit'
=>
$this
->
limit
,
'from'
=>
$this
->
from
,
'offset'
=>
$this
->
offset
,
'type'
=>
$this
->
type
,
'owner_guid'
=>
$this
->
ownerGuid
,
'state'
=>
$this
->
state
,
'rating'
=>
$this
->
rating
,
'quality'
=>
$this
->
quality
,
]);
$this
->
offset
=
$response
->
getPagingToken
();
$this
->
list
=
$response
;
}
...
...
Core/Boost/Campaigns/Metrics.php
View file @
3f4e4d30
...
...
@@ -73,17 +73,19 @@ class Metrics
// NOTE: Campaigns have a _single_ entity, for now. Refactor this when we support multiple
// Ideally, we should use a composite URN, like: urn:campaign-entity:100000321:(urn:activity:100000500)
foreach
(
$this
->
campaign
->
getEntityUrns
()
as
$entityUrn
)
{
$entity
=
$this
->
resolver
->
setOpts
([
'ignoreAcl'
=>
true
])
->
single
(
new
Urn
(
$entityUrn
));
$this
->
counters
->
setEntityGuid
(
$entity
->
guid
)
->
setMetric
(
'impression'
)
->
increment
();
$this
->
counters
->
setEntityGuid
(
$entity
->
owner_guid
)
->
setMetric
(
'impression'
)
->
increment
();
$entity
=
$this
->
resolver
->
single
(
new
Urn
(
$entityUrn
));
if
(
$entity
)
{
$this
->
counters
->
setEntityGuid
(
$entity
->
guid
)
->
setMetric
(
'impression'
)
->
increment
();
$this
->
counters
->
setEntityGuid
(
$entity
->
owner_guid
)
->
setMetric
(
'impression'
)
->
increment
();
}
}
return
true
;
...
...
Core/Boost/Campaigns/Repository.php
View file @
3f4e4d30
...
...
@@ -83,27 +83,27 @@ class Repository
->
setOwnerGuid
(
$row
[
'owner_guid'
]
->
toInt
())
->
setType
(
$row
[
'type'
]);
$data
=
json_decode
(
$row
[
'json_data'
]
?:
'{}'
,
true
);
$
json_
data
=
json_decode
(
$row
[
'json_data'
]
?:
'{}'
,
true
);
$campaign
->
setName
(
$data
[
'name'
])
->
setEntityUrns
(
Text
::
buildArray
(
$data
[
'entity_urns'
]))
->
setHashtags
(
Text
::
buildArray
(
$data
[
'hashtags'
]))
->
setNsfw
(
Number
::
buildIntArray
(
$data
[
'nsfw'
]))
->
setStart
((
int
)
$data
[
'start'
])
->
setEnd
((
int
)
$data
[
'end'
])
->
setBudget
((
string
)
$data
[
'budget'
])
->
setBudgetType
(
$data
[
'budget_type'
])
->
setChecksum
(
$data
[
'checksum'
])
->
setImpressions
((
int
)
$data
[
'impressions'
])
->
setImpressionsMet
(
$data
[
'impressions_met'
])
->
setRating
(
$data
[
'rating'
])
->
setQuality
(
$data
[
'quality'
])
->
setCreatedTimestamp
(((
int
)
$data
[
'created_timestamp'
])
?:
null
)
->
setReviewedTimestamp
(((
int
)
$data
[
'reviewed_timestamp'
])
?:
null
)
->
setRejectedTimestamp
(((
int
)
$data
[
'rejected_timestamp'
])
?:
null
)
->
setRevokedTimestamp
(((
int
)
$data
[
'revoked_timestamp'
])
?:
null
)
->
setCompletedTimestamp
(((
int
)
$data
[
'completed_timestamp'
])
?:
null
);
->
setName
(
$
json_
data
[
'name'
])
->
setEntityUrns
(
Text
::
buildArray
(
$
json_
data
[
'entity_urns'
]))
->
setHashtags
(
Text
::
buildArray
(
$
json_
data
[
'hashtags'
]))
->
setNsfw
(
Number
::
buildIntArray
(
$
json_
data
[
'nsfw'
]))
->
setStart
((
int
)
$
json_
data
[
'start'
])
->
setEnd
((
int
)
$
json_
data
[
'end'
])
->
setBudget
((
string
)
$
json_
data
[
'budget'
])
->
setBudgetType
(
$
json_
data
[
'budget_type'
])
->
setChecksum
(
$
json_
data
[
'checksum'
])
->
setImpressions
((
int
)
$
json_
data
[
'impressions'
])
->
setImpressionsMet
(
$
json_
data
[
'impressions_met'
])
->
setRating
(
$
json_
data
[
'rating'
])
->
setQuality
(
$
json_
data
[
'quality'
])
->
setCreatedTimestamp
(((
int
)
$
json_
data
[
'created_timestamp'
])
?:
null
)
->
setReviewedTimestamp
(((
int
)
$
json_
data
[
'reviewed_timestamp'
])
?:
null
)
->
setRejectedTimestamp
(((
int
)
$
json_
data
[
'rejected_timestamp'
])
?:
null
)
->
setRevokedTimestamp
(((
int
)
$
json_
data
[
'revoked_timestamp'
])
?:
null
)
->
setCompletedTimestamp
(((
int
)
$
json_
data
[
'completed_timestamp'
])
?:
null
);
$response
[]
=
$campaign
;
}
...
...
@@ -126,33 +126,36 @@ class Repository
public
function
add
(
Campaign
$campaign
,
$async
=
true
)
{
$cql
=
"INSERT INTO boost_campaigns (type, guid, owner_guid, json_data, delivery_status) VALUES (?, ?, ?, ?, ?)"
;
$json_data
=
[
'urn'
=>
$campaign
->
getUrn
(),
'owner_guid'
=>
(
string
)
$campaign
->
getOwnerGuid
(),
'name'
=>
$campaign
->
getName
(),
'type'
=>
$campaign
->
getType
(),
'entity_urns'
=>
$campaign
->
getEntityUrns
(),
'hashtags'
=>
$campaign
->
getHashtags
(),
'nsfw'
=>
$campaign
->
getNsfw
(),
'start'
=>
$campaign
->
getStart
(),
'end'
=>
$campaign
->
getEnd
(),
'budget'
=>
$campaign
->
getBudget
(),
'budget_type'
=>
$campaign
->
getBudgetType
(),
'checksum'
=>
$campaign
->
getChecksum
(),
'impressions'
=>
$campaign
->
getImpressions
(),
'impressions_met'
=>
$campaign
->
getImpressionsMet
(),
'rating'
=>
$campaign
->
getRating
(),
'quality'
=>
$campaign
->
getQuality
(),
'created_timestamp'
=>
$campaign
->
getCreatedTimestamp
(),
'reviewed_timestamp'
=>
$campaign
->
getReviewedTimestamp
(),
'rejected_timestamp'
=>
$campaign
->
getRejectedTimestamp
(),
'revoked_timestamp'
=>
$campaign
->
getRevokedTimestamp
(),
'completed_timestamp'
=>
$campaign
->
getCompletedTimestamp
(),
];
$values
=
[
$campaign
->
getType
(),
new
Bigint
(
$campaign
->
getGuid
()),
new
Bigint
(
$campaign
->
getOwnerGuid
()),
json_encode
([
'urn'
=>
$campaign
->
getUrn
(),
'owner_guid'
=>
(
string
)
$campaign
->
getOwnerGuid
(),
'name'
=>
$campaign
->
getName
(),
'type'
=>
$campaign
->
getType
(),
'entity_urns'
=>
$campaign
->
getEntityUrns
(),
'hashtags'
=>
$campaign
->
getHashtags
(),
'nsfw'
=>
$campaign
->
getNsfw
(),
'start'
=>
$campaign
->
getStart
(),
'end'
=>
$campaign
->
getEnd
(),
'budget'
=>
$campaign
->
getBudget
(),
'budget_type'
=>
$campaign
->
getBudgetType
(),
'checksum'
=>
$campaign
->
getChecksum
(),
'impressions'
=>
$campaign
->
getImpressions
(),
'impressions_met'
=>
$campaign
->
getImpressionsMet
(),
'rating'
=>
$campaign
->
getRating
(),
'quality'
=>
$campaign
->
getQuality
(),
'created_timestamp'
=>
$campaign
->
getCreatedTimestamp
(),
'reviewed_timestamp'
=>
$campaign
->
getReviewedTimestamp
(),
'rejected_timestamp'
=>
$campaign
->
getRejectedTimestamp
(),
'revoked_timestamp'
=>
$campaign
->
getRevokedTimestamp
(),
'completed_timestamp'
=>
$campaign
->
getCompletedTimestamp
(),
]),
json_encode
(
$json_data
),
$campaign
->
getDeliveryStatus
(),
];
...
...
Core/Entities/Delegates/BoostCampaignResolverDelegate.php
View file @
3f4e4d30
...
...
@@ -79,11 +79,14 @@ class BoostCampaignResolverDelegate implements ResolverDelegate
return
null
;
}
$entity
=
$this
->
resolver
->
setOpts
([
'ignoreAcl'
=>
true
])
->
single
(
new
Urn
(
$campaign
->
getEntityUrns
()[
0
]));
$entity
->
boosted
=
true
;
$entity
->
boosted_guid
=
$campaign
->
getUrn
();
$entity
->
boosted_onchain
=
true
;
$entity
->
urn
=
$campaign
->
getUrn
();
$entity
=
$this
->
resolver
->
single
(
new
Urn
(
$campaign
->
getEntityUrns
()[
0
]));
if
(
$entity
)
{
$entity
->
boosted
=
true
;
$entity
->
boosted_guid
=
$campaign
->
getUrn
();
$entity
->
boosted_onchain
=
true
;
$entity
->
urn
=
$campaign
->
getUrn
();
}
return
$entity
;
}
...
...
Core/Entities/Resolver.php
View file @
3f4e4d30
...
...
@@ -131,16 +131,12 @@ class Resolver
$sorted
=
array_filter
(
$sorted
,
function
(
$entity
)
{
return
(
bool
)
$entity
;
});
// Filter out forbidden entities
, if not ignoring ACL
// Filter out forbidden entities
$ignoreAcl
=
$this
->
opts
[
'ignoreAcl'
]
??
false
;
if
(
!
$ignoreAcl
)
{
$sorted
=
array_filter
(
$sorted
,
function
(
$entity
)
{
return
$this
->
acl
->
read
(
$entity
,
$this
->
user
);
//&& !Flags::shouldFail($entity);
});
}
$sorted
=
array_filter
(
$sorted
,
function
(
$entity
)
{
return
$this
->
acl
->
read
(
$entity
,
$this
->
user
);
//&& !Flags::shouldFail($entity);
});
//
...
...