Skip to content
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

PLAT-24975: Validate user when editing Annotation Cue Points on entries #12964

Merged
merged 2 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 36 additions & 26 deletions plugins/cue_points/annotation/lib/api/KalturaAnnotation.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,37 +197,47 @@ public function updateEndTimeAndDuration($cuePoint)
}

/*
* @param string $cuePointId
* @throw KalturaAPIException - when parent annotation doesn't belong to the same entry
*/
public function validateParentId($cuePointId = null)
{
* @param string $cuePointId
* @throw KalturaAPIException - when parent annotation doesn't belong to the same entry
*/
public function validateParentId($cuePointId = null)
{
//Backward compatibility patch
if ($this->isNull('parentId'))
$this->parentId = 0;

if ($this->parentId)
{
$dbParentCuePoint = CuePointPeer::retrieveByPK($this->parentId);
if (!$dbParentCuePoint)
throw new KalturaAPIException(KalturaCuePointErrors::PARENT_ANNOTATION_NOT_FOUND, $this->parentId);
if ($this->parentId)
{
$dbParentCuePoint = CuePointPeer::retrieveByPK($this->parentId);
if (!$dbParentCuePoint)
throw new KalturaAPIException(KalturaCuePointErrors::PARENT_ANNOTATION_NOT_FOUND, $this->parentId);

if($cuePointId !== null){// update
$dbCuePoint = CuePointPeer::retrieveByPK($cuePointId);
if(!$dbCuePoint)
throw new KalturaAPIException(KalturaCuePointErrors::INVALID_OBJECT_ID, $cuePointId);
if($cuePointId !== null)
{// update
$dbCuePoint = CuePointPeer::retrieveByPK($cuePointId);
if(!$dbCuePoint)
throw new KalturaAPIException(KalturaCuePointErrors::INVALID_OBJECT_ID, $cuePointId);

if($dbCuePoint->isDescendant($this->parentId))
throw new KalturaAPIException(KalturaCuePointErrors::PARENT_ANNOTATION_IS_DESCENDANT, $this->parentId, $dbCuePoint->getId());
if($dbCuePoint->isDescendant($this->parentId))
throw new KalturaAPIException(KalturaCuePointErrors::PARENT_ANNOTATION_IS_DESCENDANT, $this->parentId, $dbCuePoint->getId());

if ($dbParentCuePoint->getEntryId() != $dbCuePoint->getEntryId())
throw new KalturaAPIException(KalturaCuePointErrors::PARENT_ANNOTATION_DO_NOT_BELONG_TO_THE_SAME_ENTRY);
}
else
{
if ($dbParentCuePoint->getEntryId() != $this->entryId)
throw new KalturaAPIException(KalturaCuePointErrors::PARENT_ANNOTATION_DO_NOT_BELONG_TO_THE_SAME_ENTRY);
}
}
}

if ($dbParentCuePoint->getEntryId() != $dbCuePoint->getEntryId())
throw new KalturaAPIException(KalturaCuePointErrors::PARENT_ANNOTATION_DO_NOT_BELONG_TO_THE_SAME_ENTRY);
}
else
{
if ($dbParentCuePoint->getEntryId() != $this->entryId)
throw new KalturaAPIException(KalturaCuePointErrors::PARENT_ANNOTATION_DO_NOT_BELONG_TO_THE_SAME_ENTRY);
}
}
}
protected function validateEntryEntitlement(entry $dbEntry, $tags)
{
if (!kEntitlementUtils::isEntryEntitled($dbEntry) && str_contains($tags, 'hotspots'))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I have a cue-point with the following tags:

  • coolhotspots
  • tag2
  • tag3

which translates into coolhotspots,tag2,tag3 in the DB (and in the API entry object) - this restriction will apply there, which is unexpected.
I think that you should do something like

$tags = explode(',', $tags);
if (in_array('hotspots', $tags) && !kEntitlementUtils::isEntryEntitled($dbEntry)) {
    // throw error
}

Also notice the order of the conditions - isEntryEntitled will not execute if hotspots isn't one of the tags, which might be performance improvement.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opened a new PR #12969

{
KalturaLog::debug("User is not allowed to edit " . get_class($this) . " on entry [$this->entryId]");
throw new KalturaAPIException(KalturaErrors::INVALID_USER_ID);
}
}
}
30 changes: 25 additions & 5 deletions plugins/cue_points/base/lib/api/KalturaCuePoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,13 @@ public function validateEntryId($cuePointId = null)
if($this->entryId !== null && $this->entryId != $dbCuePoint->getEntryId())
throw new KalturaAPIException(KalturaCuePointErrors::CANNOT_UPDATE_ENTRY_ID);
}

$this->validateEntryEntitlement($dbEntry, $this->tags);
}

protected function validateEntryEntitlement(entry $dbEntry, $tags)
{

}

/**
Expand Down Expand Up @@ -314,15 +321,28 @@ public function validateForInsert($propertiesToSkip = array())

public function validateForUpdate($sourceObject, $propertiesToSkip = array())
{
if($this->tags !== null)
if ($this->tags !== null)
{
$this->validatePropertyMaxLength("tags", CuePointPeer::MAX_TAGS_LENGTH);

if($this->entryId !== null)
}

if ($this->entryId !== null)
{
$this->validateEntryId($sourceObject->getId());
}
else
{
$cuePoint = CuePointPeer::retrieveByPK($sourceObject->getId());
$dbEntry = entryPeer::retrieveByPK($cuePoint->getEntryId());
$tags = $this->tags ?? $sourceObject->getTags();
$this->validateEntryEntitlement($dbEntry, $tags);
}

if($this->startTime !== null)
if ($this->startTime !== null)
{
$this->validateStartTime($sourceObject->getId());

}

$propertiesToSkip[] = 'cuePointType';
return parent::validateForUpdate($sourceObject, $propertiesToSkip);
}
Expand Down