Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
33 changes: 10 additions & 23 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 false, if caller wants component permissions just get them directly
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So a method that is supposed to check the ACL now has a hardcoded deny rule in place when it should be using the ACL system? Am I the only one who sees an issue with this?

if (!$recordId)
{
return false;
}

// 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, note: zero id is guest
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 false, if caller wants component permissions just get them directly
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same issue here. This logic is massively flawed. We should NOT be introducing hard deny rules in ANY method which should be reading from the ACL system. The previous behavior of reverting to the component permissions in the case of not having a record ID should be restored.

if (!$recordId)
{
return false;
}

// 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, note: zero id is guest
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