/** * zobrazi zoznam vsetkych * @global array $ALIEN */ public static function showPermissionsList() { if (!Authorization::getCurrentUser()->hasPermission(38)) { new Notification("Prístup zamietnutý.", "error"); header("Location: ?page=home", false, 301); ob_end_flush(); exit; } global $ALIEN; $ALIEN['HEADER'] = 'Zoznam existujúcich oprávnení'; $limit = sizeof(Authorization::$Permissions); for ($i = 1; $i <= $limit; $i++) { $permission = new Permission(Authorization::$Permissions[$i]['label']); echo '<div class="item"><img src="images/icons/shield.png"> ID: ' . $permission->getId() . ' | <strong>' . $permission->getLabel() . '</strong> | ' . $permission->getDescription() . '</div>'; } }
/** * Adds an object to the instance pool. * * Propel keeps cached copies of objects in an instance pool when they are retrieved * from the database. In some cases -- especially when you override doSelect*() * methods in your stub classes -- you may need to explicitly add objects * to the cache in order to ensure that the same objects are always returned by doSelect*() * and retrieveByPK*() calls. * * @param Permission $value A Permission object. * @param string $key (optional) key to use for instance map (for performance boost if key was already calculated externally). */ public static function addInstanceToPool(Permission $obj, $key = null) { if (Propel::isInstancePoolingEnabled()) { if ($key === null) { $key = (string) $obj->getId(); } // if key === null self::$instances[$key] = $obj; } }
function addPermissionToPartner($permissionCfg, $partnerId = null) { // init new db permission object if (is_null($partnerId)) { $partnerId = $permissionCfg->partnerId; } PermissionPeer::setUseCriteriaFilter(false); $permission = PermissionPeer::getByNameAndPartner($permissionCfg->name, $partnerId); PermissionPeer::setUseCriteriaFilter(true); if (!$permission) { $permission = new Permission(); } foreach ($permissionCfg as $key => $value) { if ($key == 'partnerPackages') { continue; } $setterCallback = array($permission, "set{$key}"); call_user_func_array($setterCallback, array($value)); } if (!$permission->getFriendlyName()) { $permission->setFriendlyName($permission->getName()); } if ($partnerId != null) { $permission->setPartnerId($partnerId); } $permission->setStatus(PermissionStatus::ACTIVE); // add to database KalturaLog::log('Adding new permission with name [' . $permission->getName() . '] to partner id [' . $permission->getPartnerId() . ']'); try { if ($permission->getId()) { $permission->save(); } else { PermissionPeer::addToPartner($permission, $permission->getPartnerId()); } } catch (kPermissionException $e) { if ($e->getCode() === kPermissionException::PERMISSION_ALREADY_EXISTS) { KalturaLog::log('Permission name [' . $permission->getName() . '] already exists for partner id [' . $permission->getPartnerId() . ']'); } else { throw $e; } } }
/** * Adds an object to the instance pool. * * Propel keeps cached copies of objects in an instance pool when they are retrieved * from the database. In some cases -- especially when you override doSelect*() * methods in your stub classes -- you may need to explicitly add objects * to the cache in order to ensure that the same objects are always returned by doSelect*() * and retrieveByPK*() calls. * * @param Permission $value A Permission object. * @param string $key (optional) key to use for instance map (for performance boost if key was already calculated externally). */ public static function addInstanceToPool(Permission $obj, $key = null) { if (Propel::isInstancePoolingEnabled()) { if ($key === null) { $key = (string) $obj->getId(); } if (isset(self::$instances[$key]) || count(self::$instances) < kConf::get('max_num_instances_in_pool')) { self::$instances[$key] = $obj; kMemoryManager::registerPeer('PermissionPeer'); } } }
/** * Add a partner group permission to the local map for the given action * @param array $map map to fill * @param Permission $permission partner group permission object */ private static function addPartnerGroupAction(array &$map, Permission $permission) { $partnerGroup = $permission->getPartnerGroup(); if (!$permission->getPartnerGroup()) { KalturaLog::notice('No partner group defined for permission id [' . $permission->getId() . '] with type partner group [' . $permission->getType() . ']'); return; } $partnerGroup = explode(',', trim($partnerGroup, ',')); $permissionItems = $permission->getPermissionItems(); foreach ($permissionItems as $item) { if ($item->getType() != PermissionItemType::API_ACTION_ITEM) { KalturaLog::notice('Permission item id [' . $item->getId() . '] is not of type PermissionItemType::API_ACTION_ITEM but still defined in partner group permission id [' . $permission->getId() . ']'); continue; } $service = strtolower($item->getService()); $action = strtolower($item->getAction()); if (!isset($map[self::PARTNER_GROUP_ARRAY_NAME][$service])) { $map[self::PARTNER_GROUP_ARRAY_NAME][$service] = array(); $map[self::PARTNER_GROUP_ARRAY_NAME][$service][$action] = array(); } else { if (!isset($map[self::PARTNER_GROUP_ARRAY_NAME][$service][$action])) { $map[self::PARTNER_GROUP_ARRAY_NAME][$service][$action] = array(); } } $map[self::PARTNER_GROUP_ARRAY_NAME][$service][$action] = array_merge($map[self::PARTNER_GROUP_ARRAY_NAME][$service][$action], $partnerGroup); } }
public static function getObjectsWithPermission(Permission $permission, $user = null) { $retval = array(); if (!$user) { $user = User::getCurrentUser(); } if ($user) { $db = AbstractDb::getObject(); $object_class = $permission->getTargetObjectClass(); $table = strtolower($object_class) . '_stakeholders'; $permissionIdStr = $db->escapeString($permission->getId()); $sql = "SELECT DISTINCT object_id FROM {$table} JOIN role_has_permissions USING (role_id) WHERE user_id='{$user->getId()}' AND permission_id = '{$permissionIdStr}'"; $db->execSql($sql, $rows, false); if ($rows) { foreach ($rows as $row) { $retval[$row['object_id']] = call_user_func(array($object_class, 'getObject'), $row['object_id']); } } } return $retval; }
/** * Create a special partner group permission for given partner id, or get an existing one * @param int $partnerId * @param string $partnerGroup */ function getOrCreatePartnerGroupPermission($partnerId, $partnerGroup) { $permissionName = 'PARTNER_' . $partnerId . '_GROUP_' . $partnerGroup . '_PERMISSION'; PermissionPeer::clearInstancePool(); $c = new Criteria(); $c->addAnd(PermissionPeer::PARTNER_ID, $partnerId, Criteria::EQUAL); $c->addAnd(PermissionPeer::NAME, $permissionName, Criteria::EQUAL); $c->addAnd(PermissionPeer::TYPE, PermissionType::PARTNER_GROUP, Criteria::EQUAL); $permission = PermissionPeer::doSelectOne($c); if (!$permission) { // create permission if not yet created $permission = new Permission(); $permission->setPartnerId($partnerId); $permission->setName($permissionName); $permission->setFriendlyName('Partner ' . $partnerId . ' permission for group ' . $partnerGroup); $permission->setDescription('Partner ' . $partnerId . ' permission for group ' . $partnerGroup); $permission->setType(PermissionType::PARTNER_GROUP); $permission->setPartnerGroup($partnerGroup); $permission->setStatus(PermissionStatus::ACTIVE); $permission->save(); } else { if ($permission->getPartnerGroup() != $partnerGroup) { $msg = '***** ERROR - Permission id [' . $permission->getId() . '] partner group [' . $permission->getPartnerGroup() . '] is different from the required partner group [' . $partnerGroup . ']'; KalturaLog::alert($msg); echo $msg . PHP_EOL; } } return $permission; }
/** * Declares an association between this object and a Permission object. * * @param Permission $v * @return PermissionToPermissionItem The current object (for fluent API support) * @throws PropelException */ public function setPermission(Permission $v = null) { if ($v === null) { $this->setPermissionId(NULL); } else { $this->setPermissionId($v->getId()); } $this->aPermission = $v; // Add binding for other direction of this n:n relationship. // If this object has already been added to the Permission object, it will not be re-added. if ($v !== null) { $v->addPermissionToPermissionItem($this); } return $this; }