Skip to content

Commit

Permalink
Merge pull request #13120 from kaltura/Ursa-21.9.0-PLAT-25073-1
Browse files Browse the repository at this point in the history
Save extended status on user entry object + fix filtering logic to us…
  • Loading branch information
drorsou authored Feb 5, 2025
2 parents c529db2 + a2f31d4 commit 8f680fd
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ protected function init()
"_eq_extended_status",
"_in_extended_status",
"_notin_extended_status",
"_bitor_extended_status",
"_bitand_extended_status",
"_eq_privacy_context",
"_in_privacy_context",
"_eq_partner_id",
Expand All @@ -53,4 +53,9 @@ protected function getIdFromPeer ( )
{
return UserEntryPeer::ID;
}

public function setExtendedStatusBitAnd($value)
{
$this->set("_bitand_extended_status", $value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,56 +9,44 @@ class KalturaPermissionLevelUserEntryFilter extends KalturaUserEntryFilter
* @var KalturaPermissionLevelArray
*/
public $permissionLevels;

/**
* @var int
* @readonly
*/
public $permissionLevelsBitmask;

static private $map_between_objects = array
(
'permissionLevelsBitmask' => '_bitor_extended_status',
);

public function getMapBetweenObjects()
{
return array_merge(parent::getMapBetweenObjects(), self::$map_between_objects);
}


public function getListResponse(KalturaFilterPager $pager, KalturaDetachedResponseProfile $responseProfile = null)
{
$this->typeEqual = EntryPermissionLevelPlugin::getApiValue(PermissionLevelUserEntryType::PERMISSION_LEVEL);

$this->setPermissionLevelsBitmask();

$response = parent::getListResponse($pager, $responseProfile);
return $response;
}

public function toObject($object_to_fill = null, $props_to_skip = array())
{
$object = parent::toObject($object_to_fill, $props_to_skip);
$permissionLevelsBitmask = $this->getPermissionLevelsBitmask();
if($permissionLevelsBitmask)
{
$object->setExtendedStatusBitAnd($permissionLevelsBitmask);
}
return $object;
}

protected function setPermissionLevelsBitmask()
protected function getPermissionLevelsBitmask()
{
if (!$this->permissionLevels)
if (!$this->permissionLevels || !count($this->permissionLevels))
{
return;
}

$permissionBitmask = [
KalturaUserEntryPermissionLevel::SPEAKER => 1,
KalturaUserEntryPermissionLevel::ROOM_MODERATOR => 2,
KalturaUserEntryPermissionLevel::ATTENDEE => 4,
KalturaUserEntryPermissionLevel::ADMIN => 8,
KalturaUserEntryPermissionLevel::PREVIEW_ONLY => 16,
KalturaUserEntryPermissionLevel::CHAT_MODERATOR => 32,
KalturaUserEntryPermissionLevel::PANELIST => 64,
];

$this->permissionLevelsBitmask = 0;

$permissionLevelsBitmask = 0;
foreach ($this->permissionLevels as $permissionLevel)
{
/** @var KalturaPermissionLevel $permissionLevel */
$val = $permissionLevel->permissionLevel;
$this->permissionLevelsBitmask += $permissionBitmask[intval($val)];
if (isset(PermissionLevelUserEntry::$permissionLevelBitmask[intval($val)]))
{
$permissionLevelsBitmask += PermissionLevelUserEntry::$permissionLevelBitmask[intval($val)];
}
}

return $permissionLevelsBitmask;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @package plugins.entryPermissionLevel
* @subpackage model
*/
class PermissionLevel extends UserEntry
class PermissionLevel
{
protected $permissionLevel;

Expand All @@ -16,4 +16,4 @@ public function setPermissionLevel($permissionLevel)
{
$this->permissionLevel = $permissionLevel;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ class PermissionLevelUserEntry extends UserEntry
const CUSTOM_DATA_PERMISSION_LEVELS = 'permission_levels';

const CUSTOM_DATA_PERMISSION_ORDER = 'permission_order';

public static $permissionLevelBitmask = array(
UserEntryPermissionLevel::SPEAKER => 1,
UserEntryPermissionLevel::ROOM_MODERATOR => 2,
UserEntryPermissionLevel::ATTENDEE => 4,
UserEntryPermissionLevel::ADMIN => 8,
UserEntryPermissionLevel::PREVIEW_ONLY => 16,
UserEntryPermissionLevel::CHAT_MODERATOR => 32,
UserEntryPermissionLevel::PANELIST => 64,
);

public function __construct()
{
Expand All @@ -32,6 +42,7 @@ public function setPermissionLevels($permissionLevels)
if(!count($permissionLevels))
return;

$this->syncExtendedStatus($permissionLevels);
$serialized = serialize($permissionLevels);
return $this->putInCustomData(self::CUSTOM_DATA_PERMISSION_LEVELS, $serialized);
}
Expand All @@ -45,4 +56,17 @@ public function setPermissionOrder($permissionOrder)
{
$this->putInCustomData(self::CUSTOM_DATA_PERMISSION_ORDER, $permissionOrder);
}

protected function syncExtendedStatus($permissionLevels)
{
$permissionLevelsBitmask = 0;
foreach ($permissionLevels as $permissionLevel)
{
/** @var PermissionLevel $permissionLevel */
$val = $permissionLevel->getPermissionLevel();
$permissionLevelsBitmask += self::$permissionLevelBitmask[intval($val)];
}

$this->setExtendedStatus($permissionLevelsBitmask);
}
}

0 comments on commit 8f680fd

Please sign in to comment.