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

Save extended status on user entry object + fix filtering logic to us… #13120

Merged
merged 2 commits into from
Feb 5, 2025
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
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);
}
}