- md5
- 85378d9a4aef14b41c59a820841d4cbb
- sha1
- e1fded61efc69753eb2a6e3fd800df145112e6a3
- sha256
- df234463ae8f565684bfb7aa6778e4d24b669c2fa1a11c3fdc0df11ab1bc1511
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
<?php
/**
* @package Joomla.API
* @subpackage com_fields
*
* @copyright (C) 2019 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace Joomla\Component\Fields\Api\Controller;
use Joomla\CMS\MVC\Controller\ApiController;
use Joomla\String\Inflector;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
/**
* The groups controller
*
* @since 4.0.0
*/
class GroupsController extends ApiController
{
/**
* The content type of the item.
*
* @var string
* @since 4.0.0
*/
protected $contentType = 'groups';
/**
* The default view for the display method.
*
* @var string
* @since 3.0
*/
protected $default_view = 'groups';
/**
* Basic display of an item view
*
* @param integer $id The primary key to display. Leave empty if you want to retrieve data from the request
*
* @return static A \JControllerLegacy object to support chaining.
*
* @since 4.0.0
*/
public function displayItem($id = null)
{
$this->modelState->set('filter.context', $this->getContextFromInput());
return parent::displayItem($id);
}
/**
* Basic display of a list view
*
* @return static A \JControllerLegacy object to support chaining.
*
* @since 4.0.0
*/
public function displayList()
{
$this->modelState->set('filter.context', $this->getContextFromInput());
return parent::displayList();
}
/**
* Get extension from input
*
* @return string
*
* @since 4.0.0
*/
private function getContextFromInput()
{
return $this->input->exists('context') ?
$this->input->get('context') : $this->input->post->get('context');
}
/**
* Method to check if you can add a new record.
*
* We don't allow adding from API
*
* @param array $data An array of input data.
*
* @return boolean
*
* @since 5.4.7
*/
protected function allowAdd($data = [])
{
$user = $this->app->getIdentity();
[$option] = explode('.', $this->getContextFromInput());
if (!$user->authorise('core.manage', $option)) {
return false;
}
return $user->authorise('core.create', $option);
}
/**
* Method to check if you can edit an existing record.
*
* We don't allow editing from API (yet?)
*
* @param array $data An array of input data.
* @param string $key The name of the key for the primary key; default is id.
*
* @return boolean
*
* @since 5.4.7
*/
protected function allowEdit($data = [], $key = 'parent_id')
{
$recordId = isset($data[$key]) ? (int) $data[$key] : 0;
$user = $this->app->getIdentity();
[$option] = explode('.', $this->getContextFromInput());
// Require generic management permissions for the component
if (!$user->authorise('core.manage', $option)) {
return false;
}
// Zero record (id:0), return component edit permission by calling parent controller method
if (!$recordId) {
return $user->authorise('core.edit', $option);
}
// Get existing record
$record = $this->getModel(Inflector::singularize($this->contentType))->getItem($recordId);
if (empty($record)) {
return false;
}
[$recordOption] = explode('.', $record->context);
// Validate request context and field context match
if ($recordOption !== $option) {
return false;
}
// Check edit on the record asset (explicit or inherited)
if ($user->authorise('core.edit', $option . '.fieldgroup.' . $recordId)) {
return true;
}
// Check edit own on the record asset (explicit or inherited)
if ($user->authorise('core.edit.own', $option . '.fieldgroup.' . $recordId)) {
// Existing record already has an owner, get it
$record = $this->getModel()->getItem($recordId);
if (empty($record)) {
return false;
}
// Grant if current user is owner of the record
return $user->id == $record->created_user_id;
}
return false;
}
/**
* Method to check if it's allowed to delete a record
*
* @return boolean
*
* @since 5.4.8
*/
protected function allowDelete(): bool
{
[$option] = explode('.', $this->getContextFromInput());
$user = $this->app->getIdentity();
// Require generic management permissions for the component
if (!$user->authorise('core.manage', $option)) {
return false;
}
return $user->authorise('core.delete', $option);
}
}
The same content is in 5 releases, Joomla 5.4.8 to 5.4.10. See them all, or every version of this file.