PEAR is discontinued

This is a static archive preserving historical releases and metadata. No new packages or updates will be published. For updates to existing packages, or to publish new packages, please use Composer and Packagist.

Home » Authentication » LiveUser » Bug #416

Retrieval of implied rights

Details

Submitted2003-12-12 20:04 UTC
Fromkipaten21 at hotmail dot com
Assignedlsmith
StatusClosed
PackageLiveUser
PHP VersionIrrelevant
OSANY
Roadmaps(Not assigned)

Comments

[2003-12-12 20:04 UTC] kipaten21 at hotmail dot com

Description:
------------
There doesn't appear to be any methods for retrieving implied rights. I suggest that LiveUser_Admin_Perm_Container_DB_Complex::getRights() be created ( derived from LiveUser_Admin_Perm_DB_Common::getRights() ). This derived getRights() should implement a solution to retrieve implied rights similar to the way getGroups() retrieves subgroups.

I have implemeted a solution that is based off my revised getGroups() code to retrieve subgroups.

Here is the code....

function getRights($options = null, $hierarchy = false)
{
static $groups;
static $subgroups;

$query = 'SELECT
rights.right_id AS right_id,
rights.area_id AS area_id,
areas.application_id AS application_id,';

if (isset($options['where_user_id'])) {
$query .= ' userrights.perm_user_id AS user_id,';
}

if (isset($options['where_group_id'])
&& is_numeric($options['where_group_id'])) {
$query .= ' grouprights.group_id AS group_id,';
}

$query .= '
rights.right_define_name AS define_name,
rights.has_implied AS has_implied,
rights.has_level AS has_level,
rights.has_scope AS has_scope,
translations.name AS name,
translations.comments AS comments
FROM
' . $this->prefix . 'rights rights,
' . $this->prefix . 'areas areas,
' . $this->prefix . 'applications applications,';

if (isset($options['where_user_id'])) {
$query .= ' ' . $this->prefix . 'userrights userrights,';
}

if (isset($options['where_group_id'])
&& is_numeric($options['where_group_id'])) {
$query .= ' ' . $this->prefix . 'grouprights grouprights,';
}

$query .= ' ' . $this->prefix . 'translations translations
WHERE';

if (isset($options['where_right_id'])
&& is_numeric($options['where_right_id'])) {
$query .= ' rights.right_id = '
. (int)$options['where_right_id'] . ' AND';
};

if (isset($options['where_area_id'])
&& is_numeric($options['where_area_id'])) {
$query .= ' rights.area_id = '
. (int)$options['where_area_id'] . ' AND';
};

if (isset($options['where_application_id'])
&& is_numeric($options['where_application_id'])) {
$query .= ' areas.application_id = '
. (int)$options['where_application_id'] . ' AND';
};

if (isset($options['where_user_id'])) {
$query .= ' userrights.perm_user_id = '
. $this->_getPermUserId($options['where_user_id']) . ' AND
userrights.right_id = rights.right_id AND';
};

if (isset($options['where_group_id'])
&& is_numeric($options['where_group_id'])) {
$query .= ' grouprights.group_id = '
. (int)$options['where_group_id'] . ' AND
grouprights.right_id = rights.right_id AND';
};

$query .= ' rights.area_id = areas.area_id AND
rights.right_id = translations.section_id AND
translations.section_type = ' . LIVEUSER_SECTION_RIGHT . ' AND
translations.language_id = '
. (int)($this->_langs[$this->getCurrentLanguage()]) . '
GROUP BY
rights.right_id, rights.area_id, areas.application_id';

if (isset($options['where_user_id'])) {
$query .= ',userrights.perm_user_id';
}

if (isset($options['where_group_id'])
&& is_numeric($options['where_group_id'])) {
$query .= ',grouprights.group_id';
}

$query .= '
,rights.right_define_name, rights.has_implied,
rights.has_level, rights.has_scope,
translations.name, translations.comments
ORDER BY
rights.area_id ASC';

$rights = $this->dbc->getAll($query, null, DB_FETCHMODE_ASSOC);

if (DB::isError($rights)) {
return $rights;
};

$_rights = array();
if (is_array($rights)) {
foreach ($rights as $key => $value)
{
$id = $value['right_id'];
$_rights[$id] = $value;

if (isset($options['with_areas'])) {
// Add area
$_rights[$id]['area'] =
$this->getTranslation($value['area_id'], LIVEUSER_SECTION_AREA);

if (DB::isError($_rights[$id]['area'])) {
return $_rights[$id]['area'];
};

if (isset($options['with_applications'])) {
// Add application
$_rights[$id]['application'] =
$this->getTranslation(
$value['application_id'],
LIVEUSER_SECTION_APPLICATION
);

if (DB::isError($_rights[$id]['application'])) {
return $_rights[$id]['application'];
};
};
};
};
}

if ($options['with_implied_rights']) {
$query = 'SELECT
implied.right_id as right_id,
implied.implied_right_id as implied_right_id
FROM
' . $this->prefix . 'right_implied implied';

$implied_rights = $this->dbc->getAll($query, null, DB_FETCHMODE_ASSOC);

if (DB::isError($implied_rights)) {
return $implied_rights;
}

foreach($implied_rights as $implied) {
if ($_rights[$implied['right_id']]) {
$result = $this->getRights(
array(
'where_right_id' => $implied['implied_right_id'],
'with_areas' => true,
'with_applications' => true
)
);

$_rights[$implied['right_id']]['implied_rights'][$implied['implied_right_id']] = $result[$implied['implied_right_id']];

if ($hierarchy)
unset($_rights[$implied['implied_right_id']]);
}
}
}

return $_rights;
}