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

Refactor allowEdit of backend category controller #11547

Merged
merged 2 commits into from
Aug 26, 2016
Merged
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
31 changes: 9 additions & 22 deletions administrator/components/com_categories/controllers/category.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,38 +76,25 @@ protected function allowEdit($data = array(), $key = 'parent_id')
$recordId = (int) isset($data[$key]) ? $data[$key] : 0;
$user = JFactory::getUser();

// Check general edit permission first.
if ($user->authorise('core.edit', $this->extension))
{
return true;
}

// Check specific edit permission.
// Check "edit" permission on record asset (explicit or inherited)
if ($user->authorise('core.edit', $this->extension . '.category.' . $recordId))
{
return true;
}

// Fallback on edit.own.
// First test if the permission is available.
if ($user->authorise('core.edit.own', $this->extension . '.category.' . $recordId) || $user->authorise('core.edit.own', $this->extension))
// Check "edit own" permission on record asset (explicit or inherited)
if ($user->authorise('core.edit.own', $this->extension . '.category.' . $recordId))
{
// Now test the owner is the user.
$ownerId = (int) isset($data['created_user_id']) ? $data['created_user_id'] : 0;
// Need to do a lookup from the model to get the owner
$record = $this->getModel()->getItem($recordId);

if (empty($ownerId) && $recordId)
if (empty($record))
{
// Need to do a lookup from the model.
$record = $this->getModel()->getItem($recordId);

if (empty($record))
{
return false;
}

$ownerId = $record->created_user_id;
return false;
}

$ownerId = $record->created_user_id;

// If the owner matches 'me' then do the test.
if ($ownerId == $user->id)
{
Expand Down