Skip to content

Commit

Permalink
Merge pull request #12964 from kaltura/Ursa-21.3.0-PLAT-24975
Browse files Browse the repository at this point in the history
PLAT-24975: Validate user when editing Annotation Cue Points on entries
  • Loading branch information
drorsou authored Nov 11, 2024
2 parents 14d49b7 + 56f1684 commit 894c860
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 31 deletions.
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'))
{
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

0 comments on commit 894c860

Please sign in to comment.