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-25073: Added bit mask for UserEntry PermissionLevel #13080

Open
wants to merge 4 commits into
base: Ursa-21.8.0
Choose a base branch
from
Open
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,6 +28,7 @@ protected function init()
"_eq_extended_status",
"_in_extended_status",
"_notin_extended_status",
'_bitor_extended_status',
"_eq_privacy_context",
"_in_privacy_context",
"_eq_partner_id",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,64 @@
*/
class KalturaPermissionLevelUserEntryFilter extends KalturaUserEntryFilter
{
/**
* @var KalturaPermissionLevelArray
*/
public $permissionLevels;

/**
* @var int
*/
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;
}

protected function setPermissionLevelsBitmask()
{
if (!$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,
];

$newBitmask = 0;
foreach ($this->permissionLevels as $permissionLevel)
{
/** @var KalturaPermissionLevel $permissionLevel */
$val = $permissionLevel->permissionLevel;
$newBitmask += $permissionBitmask[intval($val)];
}

if ($newBitmask)
{
$this->permissionLevelsBitmask = $newBitmask;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,70 @@ class PermissionLevelUserEntry extends UserEntry

const CUSTOM_DATA_PERMISSION_ORDER = 'permission_order';

const PERMISSION_BIT_MASK = [
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()
{
$this->setType(EntryPermissionLevelPlugin::getPermissionLevelUserEntryTypeCoreValue(PermissionLevelUserEntryType::PERMISSION_LEVEL));
parent::__construct();
}

public function getPermissionLevels ()
public function getPermissionLevels()
{
$permissionLevels = $this->decodePermissionLevels(($this->getExtendedStatus()));

return array_map( function($permissionLevel)
{
$permissionLevelObject = new PermissionLevel();
$permissionLevelObject->setPermissionLevel($permissionLevel);
return $permissionLevelObject;
}, $permissionLevels);
}

protected function decodePermissionLevels($encodedPermissionLevels)
{
$serialized = $this->getFromCustomData(self::CUSTOM_DATA_PERMISSION_LEVELS);
return unserialize($serialized);
$permissionLevels = array();
foreach (self::PERMISSION_BIT_MASK as $permission => $permissionBitmask)
{
if ($encodedPermissionLevels & $permissionBitmask)
{
$permissionLevels[] = $permission;
}
}

return $permissionLevels;
}

public function setPermissionLevels ($permissionLevels)
public function setPermissionLevels($permissionLevels)
{
if(!count($permissionLevels))
if (!count($permissionLevels))
{
return;

$serialized = serialize($permissionLevels);
return $this->putInCustomData(self::CUSTOM_DATA_PERMISSION_LEVELS, $serialized);
}

$encodedPermissions = $this->encodePermissionLevels($permissionLevels);
$this->setExtendedStatus($encodedPermissions);
}

protected function encodePermissionLevels($permissionLevels)
{
$encodedPermissionLevels = 0;
foreach ($permissionLevels as $permissionLevel)
{
/** @var PermissionLevel $permissionLevel */
$bitmask = self::PERMISSION_BIT_MASK[$permissionLevel->getPermissionLevel()];
$encodedPermissionLevels = $encodedPermissionLevels | $bitmask;
}

return $encodedPermissionLevels;
}

public function getPermissionOrder()
Expand Down