- md5
- 556b1303091fbe8280a35208c48e85f7
- sha1
- 2e963109ae8a93ed0d18bb2e1d9be04634e258c1
- sha256
- 61e08b148c7e3e2975dc9fbfb78ef1d28baedc2539500933a8e37ec8ca9aac50
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
<?php
/**
* @package Joomla.Administrator
* @subpackage com_privacy
*
* @copyright Copyright (C) 2005 - 2018 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('_JEXEC') or die;
/**
* Request management controller class.
*
* @since 3.9.0
*/
class PrivacyControllerRequest extends JControllerForm
{
/**
* Method to complete a request.
*
* @param string $key The name of the primary key of the URL variable.
* @param string $urlVar The name of the URL variable if different from the primary key (sometimes required to avoid router collisions).
*
* @return boolean
*
* @since 3.9.0
*/
public function complete($key = null, $urlVar = null)
{
// Check for request forgeries.
JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
/** @var PrivacyModelRequest $model */
$model = $this->getModel();
/** @var PrivacyTableRequest $table */
$table = $model->getTable();
// Determine the name of the primary key for the data.
if (empty($key))
{
$key = $table->getKeyName();
}
// To avoid data collisions the urlVar may be different from the primary key.
if (empty($urlVar))
{
$urlVar = $key;
}
$recordId = $this->input->getInt($urlVar);
$item = $model->getItem($recordId);
// Ensure this record can transition to the requested state
if (!$this->canTransition($item, '2'))
{
$this->setError(\JText::_('COM_PRIVACY_ERROR_COMPLETE_TRANSITION_NOT_PERMITTED'));
$this->setMessage($this->getError(), 'error');
$this->setRedirect(
\JRoute::_(
'index.php?option=com_privacy&view=request&id=' . $recordId, false
)
);
return false;
}
// Build the data array for the update
$data = array(
$key => $recordId,
'status' => '2',
);
// Access check.
if (!$this->allowSave($data, $key))
{
$this->setError(\JText::_('JLIB_APPLICATION_ERROR_SAVE_NOT_PERMITTED'));
$this->setMessage($this->getError(), 'error');
$this->setRedirect(
\JRoute::_(
'index.php?option=com_privacy&view=request&id=' . $recordId, false
)
);
return false;
}
// Attempt to save the data.
if (!$model->save($data))
{
// Redirect back to the edit screen.
$this->setError(\JText::sprintf('JLIB_APPLICATION_ERROR_SAVE_FAILED', $model->getError()));
$this->setMessage($this->getError(), 'error');
$this->setRedirect(
\JRoute::_(
'index.php?option=com_privacy&view=request&id=' . $recordId, false
)
);
return false;
}
// Log the request completed
$model->logRequestCompleted($recordId);
$this->setMessage(\JText::_('COM_PRIVACY_REQUEST_COMPLETED'));
$url = 'index.php?option=com_privacy&view=requests';
// Check if there is a return value
$return = $this->input->get('return', null, 'base64');
if (!is_null($return) && \JUri::isInternal(base64_decode($return)))
{
$url = base64_decode($return);
}
// Redirect to the list screen.
$this->setRedirect(\JRoute::_($url, false));
return true;
}
/**
* Method to email the data export for a request.
*
* @return boolean
*
* @since 3.9.0
*/
public function emailexport()
{
/** @var PrivacyModelExport $model */
$model = $this->getModel('Export');
$recordId = $this->input->getUint('id');
if (!$model->emailDataExport($recordId))
{
// Redirect back to the edit screen.
$this->setError(\JText::sprintf('COM_PRIVACY_ERROR_EXPORT_EMAIL_FAILED', $model->getError()));
$this->setMessage($this->getError(), 'error');
}
else
{
$this->setMessage(\JText::_('COM_PRIVACY_EXPORT_EMAILED'));
}
$url = 'index.php?option=com_privacy&view=requests';
// Check if there is a return value
$return = $this->input->get('return', null, 'base64');
if (!is_null($return) && \JUri::isInternal(base64_decode($return)))
{
$url = base64_decode($return);
}
// Redirect to the list screen.
$this->setRedirect(\JRoute::_($url, false));
return true;
}
/**
* Method to invalidate a request.
*
* @param string $key The name of the primary key of the URL variable.
* @param string $urlVar The name of the URL variable if different from the primary key (sometimes required to avoid router collisions).
*
* @return boolean
*
* @since 3.9.0
*/
public function invalidate($key = null, $urlVar = null)
{
// Check for request forgeries.
JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
/** @var PrivacyModelRequest $model */
$model = $this->getModel();
/** @var PrivacyTableRequest $table */
$table = $model->getTable();
// Determine the name of the primary key for the data.
if (empty($key))
{
$key = $table->getKeyName();
}
// To avoid data collisions the urlVar may be different from the primary key.
if (empty($urlVar))
{
$urlVar = $key;
}
$recordId = $this->input->getInt($urlVar);
$item = $model->getItem($recordId);
// Ensure this record can transition to the requested state
if (!$this->canTransition($item, '-1'))
{
$this->setError(\JText::_('COM_PRIVACY_ERROR_INVALID_TRANSITION_NOT_PERMITTED'));
$this->setMessage($this->getError(), 'error');
$this->setRedirect(
\JRoute::_(
'index.php?option=com_privacy&view=request&id=' . $recordId, false
)
);
return false;
}
// Build the data array for the update
$data = array(
$key => $recordId,
'status' => '-1',
);
// Access check.
if (!$this->allowSave($data, $key))
{
$this->setError(\JText::_('JLIB_APPLICATION_ERROR_SAVE_NOT_PERMITTED'));
$this->setMessage($this->getError(), 'error');
$this->setRedirect(
\JRoute::_(
'index.php?option=com_privacy&view=request&id=' . $recordId, false
)
);
return false;
}
// Attempt to save the data.
if (!$model->save($data))
{
// Redirect back to the edit screen.
$this->setError(\JText::sprintf('JLIB_APPLICATION_ERROR_SAVE_FAILED', $model->getError()));
$this->setMessage($this->getError(), 'error');
$this->setRedirect(
\JRoute::_(
'index.php?option=com_privacy&view=request&id=' . $recordId, false
)
);
return false;
}
// Log the request invalidated
$model->logRequestInvalidated($recordId);
$this->setMessage(\JText::_('COM_PRIVACY_REQUEST_INVALIDATED'));
$url = 'index.php?option=com_privacy&view=requests';
// Check if there is a return value
$return = $this->input->get('return', null, 'base64');
if (!is_null($return) && \JUri::isInternal(base64_decode($return)))
{
$url = base64_decode($return);
}
// Redirect to the list screen.
$this->setRedirect(\JRoute::_($url, false));
return true;
}
/**
* Method to remove the user data for a privacy remove request.
*
* @return boolean
*
* @since 3.9.0
*/
public function remove()
{
/** @var PrivacyModelRemove $model */
$model = $this->getModel('Remove');
$recordId = $this->input->getUint('id');
if (!$model->removeDataForRequest($recordId))
{
// Redirect back to the edit screen.
$this->setError(\JText::sprintf('COM_PRIVACY_ERROR_REMOVE_DATA_FAILED', $model->getError()));
$this->setMessage($this->getError(), 'error');
$this->setRedirect(
\JRoute::_(
'index.php?option=com_privacy&view=request&id=' . $recordId, false
)
);
return false;
}
$this->setMessage(\JText::_('COM_PRIVACY_DATA_REMOVED'));
$url = 'index.php?option=com_privacy&view=requests';
// Check if there is a return value
$return = $this->input->get('return', null, 'base64');
if (!is_null($return) && \JUri::isInternal(base64_decode($return)))
{
$url = base64_decode($return);
}
// Redirect to the list screen.
$this->setRedirect(\JRoute::_($url, false));
return true;
}
/**
* Function that allows child controller access to model data after the data has been saved.
*
* @param \JModelLegacy $model The data model object.
* @param array $validData The validated data.
*
* @return void
*
* @since 3.9.0
*/
protected function postSaveHook(\JModelLegacy $model, $validData = array())
{
// This hook only processes new items
if (!$model->getState($model->getName() . '.new', false))
{
return;
}
if (!$model->logRequestCreated($model->getState($model->getName() . '.id')))
{
if ($error = $model->getError())
{
JFactory::getApplication()->enqueueMessage($error, 'warning');
}
}
if (!$model->notifyUserAdminCreatedRequest($model->getState($model->getName() . '.id')))
{
if ($error = $model->getError())
{
JFactory::getApplication()->enqueueMessage($error, 'warning');
}
}
else
{
JFactory::getApplication()->enqueueMessage(JText::_('COM_PRIVACY_MSG_CONFIRM_EMAIL_SENT_TO_USER'));
}
}
/**
* Method to determine if an item can transition to the specified status.
*
* @param object $item The item being updated.
* @param string $newStatus The new status of the item.
*
* @return boolean
*
* @since 3.9.0
*/
private function canTransition($item, $newStatus)
{
switch ($item->status)
{
case '0':
// A pending item can only move to invalid through this controller due to the requirement for a user to confirm the request
return $newStatus === '-1';
case '1':
// A confirmed item can be marked completed or invalid
return in_array($newStatus, array('-1', '2'), true);
// An item which is already in an invalid or complete state cannot transition, likewise if we don't know the state don't change anything
case '-1':
case '2':
default:
return false;
}
}
}
The same content is in 10 releases, Joomla 3.9.0-alpha to 3.9.1. See them all, or every version of this file.