Skip to content
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
35 changes: 11 additions & 24 deletions administrator/components/com_content/controllers/article.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,45 +84,32 @@ protected function allowEdit($data = array(), $key = 'id')
{
$recordId = (int) isset($data[$key]) ? $data[$key] : 0;
$user = JFactory::getUser();
$userId = $user->get('id');

// If we get a deny at the component level, we cannot override here.
if (!parent::allowEdit($data, $key))
// Zero record (id:0), return component edit permission by calling parent controller method
if (!$recordId)
{
return false;
return parent::allowEdit($data, $key);
}

// Check general edit permission first.
// Check edit on the record asset (explicit or inherited)
if ($user->authorise('core.edit', 'com_content.article.' . $recordId))
{
return true;
}

// Fallback on edit.own.
// First test if the permission is available.
// Check edit own on the record asset (explicit or inherited)
if ($user->authorise('core.edit.own', 'com_content.article.' . $recordId))
{
// Now test the owner is the user.
$ownerId = (int) isset($data['created_by']) ? $data['created_by'] : 0;
// Existing record already has an owner, get it
$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_by;
return false;
}

// If the owner matches 'me' then permission is granted.
if ($ownerId == $userId)
{
return true;
}
// Grant if current user is owner of the record
return $user->get('id') == $record->created_by;
}

return false;
Expand Down
45 changes: 18 additions & 27 deletions components/com_content/controllers/article.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,45 +103,36 @@ protected function allowAdd($data = array())
protected function allowEdit($data = array(), $key = 'id')
{
$recordId = (int) isset($data[$key]) ? $data[$key] : 0;
$user = JFactory::getUser();
$userId = $user->get('id');
$asset = 'com_content.article.' . $recordId;
$user = JFactory::getUser();

// Check general edit permission first.
if ($user->authorise('core.edit', $asset))
// Zero record (id:0), return component edit permission by calling parent controller method
if (!$recordId)
{
return parent::allowEdit($data, $key);
}

// Check edit on the record asset (explicit or inherited)
if ($user->authorise('core.edit', 'com_content.article.' . $recordId))
{
return true;
}

// Fallback on edit.own.
// First test if the permission is available.
if ($user->authorise('core.edit.own', $asset))
// Check edit own on the record asset (explicit or inherited)
if ($user->authorise('core.edit.own', 'com_content.article.' . $recordId))
{
// Now test the owner is the user.
$ownerId = (int) isset($data['created_by']) ? $data['created_by'] : 0;
// Existing record already has an owner, get it
$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_by;
return false;
}

// If the owner matches 'me' then do the test.
if ($ownerId == $userId)
{
return true;
}
// Grant if current user is owner of the record
return $user->get('id') == $record->created_by;
}

// Since there is no asset tracking, revert to the component permissions.
return parent::allowEdit($data, $key);
return false;
}

/**
Expand Down