correct core.edit.own

This commit is contained in:
andrepereiradasilva 2016-08-07 02:08:21 +01:00
parent 36c813e759
commit 2b3ec8fdb3
4 changed files with 21 additions and 12 deletions

View File

@ -59,21 +59,29 @@ class WeblinksControllerWeblink extends JControllerForm
protected function allowEdit($data = array(), $key = 'id') protected function allowEdit($data = array(), $key = 'id')
{ {
$recordId = (int) isset($data[$key]) ? $data[$key] : 0; $recordId = (int) isset($data[$key]) ? $data[$key] : 0;
$categoryId = 0;
if ($recordId) // Since there is no asset tracking, fallback to the component permissions.
if (!$recordId)
{ {
$categoryId = (int) $this->getModel()->getItem($recordId)->catid; return parent::allowEdit($data, $key);
} }
if ($categoryId) // Get the item.
$item = $this->getModel()->getItem($recordId);
// Since there is no item, return false.
if (empty($item))
{ {
// The category has been set. Check the category permissions. return false;
return JFactory::getUser()->authorise('core.edit', $this->option . '.category.' . $categoryId);
} }
// Since there is no asset tracking, revert to the component permissions. $user = JFactory::getUser();
return parent::allowEdit($data, $key);
// Check if can edit own core.edit.own.
$canEditOwn = $user->authorise('core.edit.own', $this->option . '.category.' . (int) $record->catid) && $item->created_by == $user->id;
// Check the category core.edit permissions.
return $canEditOwn || $user->authorise('core.edit', $this->option . '.category.' . (int) $record->catid);
} }
/** /**

View File

@ -132,7 +132,7 @@ class WeblinksModelWeblinks extends JModelList
$query->select( $query->select(
$this->getState( $this->getState(
'list.select', 'list.select',
'a.id, a.title, a.alias, a.checked_out, a.checked_out_time, a.catid,' . 'a.id, a.title, a.alias, a.checked_out, a.checked_out_time, a.catid, a.created_by ' .
'a.hits, a.state, a.access, a.ordering, a.language, a.publish_up, a.publish_down' 'a.hits, a.state, a.access, a.ordering, a.language, a.publish_up, a.publish_down'
) )
); );

View File

@ -132,7 +132,8 @@ JFactory::getDocument()->addScriptDeclaration('
$item->cat_link = JRoute::_('index.php?option=com_categories&extension=com_weblinks&task=edit&type=other&cid[]='. $item->catid); $item->cat_link = JRoute::_('index.php?option=com_categories&extension=com_weblinks&task=edit&type=other&cid[]='. $item->catid);
$canCreate = $user->authorise('core.create', 'com_weblinks.category.' . $item->catid); $canCreate = $user->authorise('core.create', 'com_weblinks.category.' . $item->catid);
$canEdit = $user->authorise('core.edit', 'com_weblinks.category.' . $item->catid); $canEdit = $user->authorise('core.edit', 'com_weblinks.category.' . $item->catid);
$canCheckin = $user->authorise('core.manage', 'com_checkin') || $item->checked_out == $user->get('id') || $item->checked_out == 0; $canCheckin = $user->authorise('core.manage', 'com_checkin') || $item->checked_out == $user->id || $item->checked_out == 0;
$canEditOwn = $user->authorise('core.edit.own', 'com_weblinks.category.' . $item->catid) && $item->created_by == $user->id;
$canChange = $user->authorise('core.edit.state', 'com_weblinks.category.' . $item->catid) && $canCheckin; $canChange = $user->authorise('core.edit.state', 'com_weblinks.category.' . $item->catid) && $canCheckin;
?> ?>
<tr class="row<?php echo $i % 2; ?>" sortable-group-id="<?php echo $item->catid?>"> <tr class="row<?php echo $i % 2; ?>" sortable-group-id="<?php echo $item->catid?>">
@ -165,7 +166,7 @@ JFactory::getDocument()->addScriptDeclaration('
<?php if ($item->checked_out) : ?> <?php if ($item->checked_out) : ?>
<?php echo JHtml::_('jgrid.checkedout', $i, $item->editor, $item->checked_out_time, 'weblinks.', $canCheckin); ?> <?php echo JHtml::_('jgrid.checkedout', $i, $item->editor, $item->checked_out_time, 'weblinks.', $canCheckin); ?>
<?php endif; ?> <?php endif; ?>
<?php if ($canEdit) : ?> <?php if ($canEdit || $canEditOwn) : ?>
<a href="<?php echo JRoute::_('index.php?option=com_weblinks&task=weblink.edit&id='.(int) $item->id); ?>"> <a href="<?php echo JRoute::_('index.php?option=com_weblinks&task=weblink.edit&id='.(int) $item->id); ?>">
<?php echo $this->escape($item->title); ?></a> <?php echo $this->escape($item->title); ?></a>
<?php else : ?> <?php else : ?>

View File

@ -70,7 +70,7 @@ class WeblinksViewWeblinks extends JViewLegacy
JToolbarHelper::addNew('weblink.add'); JToolbarHelper::addNew('weblink.add');
} }
if ($canDo->get('core.edit')) if ($canDo->get('core.edit') || $canDo->get('core.edit.own'))
{ {
JToolbarHelper::editList('weblink.edit'); JToolbarHelper::editList('weblink.edit');
} }