TYPO3 CMS  TYPO3_7-6
PermissionController.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
28 
33 {
37  const SESSION_PREFIX = 'tx_Beuser_';
38 
42  protected $id;
43 
47  protected $returnUrl = '';
48 
52  protected $depth;
53 
59  protected $getLevels = 10;
60 
64  protected $pageInfo = [];
65 
71  protected $defaultViewObjectName = BackendTemplateView::class;
72 
78  protected $view;
79 
85  protected function initializeAction()
86  {
87  // determine depth parameter
88  $this->depth = (int)GeneralUtility::_GP('depth') > 0
89  ? (int)GeneralUtility::_GP('depth')
90  : (int)$this->getBackendUser()->getSessionData(self::SESSION_PREFIX . 'depth');
91  if ($this->request->hasArgument('depth')) {
92  $this->depth = (int)$this->request->getArgument('depth');
93  }
94  $this->getBackendUser()->setAndSaveSessionData(self::SESSION_PREFIX . 'depth', $this->depth);
95 
96  // determine id parameter
97  $this->id = (int)GeneralUtility::_GP('id');
98  if ($this->request->hasArgument('id')) {
99  $this->id = (int)$this->request->getArgument('id');
100  }
101 
102  $this->returnUrl = GeneralUtility::_GP('returnUrl');
103  if ($this->request->hasArgument('returnUrl')) {
104  $this->returnUrl = $this->request->getArgument('returnUrl');
105  }
106 
107  $this->pageInfo = BackendUtility::readPageAccess($this->id, ' 1=1');
108  }
109 
116  protected function initializeView(ViewInterface $view)
117  {
118  parent::initializeView($view);
119  $view->assign(
120  'previewUrl',
121  BackendUtility::viewonclick(
122  $this->pageInfo['uid'], '',
123  BackendUtility::BEgetRootLine($this->pageInfo['uid'])
124  )
125  );
126 
127  // the view of the update action has a different view class
128  if ($view instanceof BackendTemplateView) {
129  $view->getModuleTemplate()->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Beuser/Permissions');
130  $view->getModuleTemplate()->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/Tooltip');
131  $view->getModuleTemplate()->addJavaScriptCode(
132  'jumpToUrl',
133  '
134  function jumpToUrl(URL) {
135  window.location.href = URL;
136  return false;
137  }
138  '
139  );
140  $this->registerDocHeaderButtons();
141  $this->view->getModuleTemplate()->getDocHeaderComponent()->setMetaInformation($this->pageInfo);
142  $this->view->getModuleTemplate()->setFlashMessageQueue($this->controllerContext->getFlashMessageQueue());
143  }
144  }
145 
152  protected function registerDocHeaderButtons()
153  {
155  $buttonBar = $this->view->getModuleTemplate()->getDocHeaderComponent()->getButtonBar();
156  $currentRequest = $this->request;
157  $moduleName = $currentRequest->getPluginName();
158  $getVars = $this->request->getArguments();
159  $lang = $this->getLanguageService();
160 
161  $extensionName = $currentRequest->getControllerExtensionName();
162  if (empty($getVars)) {
163  $modulePrefix = strtolower('tx_' . $extensionName . '_' . $moduleName);
164  $getVars = ['id', 'M', $modulePrefix];
165  }
166 
167  if ($currentRequest->getControllerActionName() === 'edit') {
168  // CLOSE button:
169  $closeButton = $buttonBar->makeLinkButton()
170  ->setHref($this->returnUrl)
171  ->setTitle($lang->sL('LLL:EXT:lang/locallang_core.xlf:rm.closeDoc'))
172  ->setIcon($this->view->getModuleTemplate()->getIconFactory()->getIcon(
173  'actions-document-close',
175  ));
176  $buttonBar->addButton($closeButton);
177 
178  // SAVE button:
179  $saveButton = $buttonBar->makeInputButton()
180  ->setTitle($lang->sL('LLL:EXT:lang/locallang_core.xlf:rm.saveCloseDoc'))
181  ->setName('tx_beuser_system_beusertxpermission[submit]')
182  ->setValue('Save')
183  ->setForm('PermissionControllerEdit')
184  ->setIcon($this->view->getModuleTemplate()->getIconFactory()->getIcon(
185  'actions-document-save',
187  ))
188  ->setShowLabelText(true);
189 
190  $buttonBar->addButton($saveButton);
191  }
192 
193  // SHORTCUT botton:
194  $shortcutButton = $buttonBar->makeShortcutButton()
195  ->setModuleName($moduleName)
196  ->setGetVariables($getVars);
197  $buttonBar->addButton($shortcutButton);
198 
199  if ($this->id > 0) {
200  $iconFactory = $this->view->getModuleTemplate()->getIconFactory();
201  $viewButton = $buttonBar->makeLinkButton()
202  ->setOnClick(BackendUtility::viewOnClick($this->pageInfo['uid'], '',
203  BackendUtility::BEgetRootLine($this->pageInfo['uid'])))
204  ->setTitle($this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:labels.showPage'))
205  ->setIcon($iconFactory->getIcon('actions-document-view', Icon::SIZE_SMALL))
206  ->setHref('#');
207 
208  $buttonBar->addButton($viewButton, ButtonBar::BUTTON_POSITION_LEFT, 3);
209  }
210  }
211 
217  public function indexAction()
218  {
219  if (!$this->id) {
220  $this->pageInfo = ['title' => '[root-level]', 'uid' => 0, 'pid' => 0];
221  }
222 
223  if ($this->getBackendUser()->workspace != 0) {
224  // Adding section with the permission setting matrix:
225  $this->addFlashMessage(
226  LocalizationUtility::translate('LLL:EXT:beuser/Resources/Private/Language/locallang_mod_permission.xlf:WorkspaceWarningText', 'beuser'),
227  LocalizationUtility::translate('LLL:EXT:beuser/Resources/Private/Language/locallang_mod_permission.xlf:WorkspaceWarning', 'beuser'),
229  );
230  }
231 
232  // depth options
233  $depthOptions = [];
234  $url = $this->uriBuilder->reset()->setArguments([
235  'action' => 'index',
236  'depth' => '__DEPTH__',
237  'id' => $this->id
238  ])->buildBackendUri();
239  foreach ([1, 2, 3, 4, 10] as $depthLevel) {
240  $depthOptions[$depthLevel] = $depthLevel . ' ' . LocalizationUtility::translate('LLL:EXT:beuser/Resources/Private/Language/locallang_mod_permission.xlf:levels', 'beuser');
241  }
242  $this->view->assign('currentId', $this->id);
243  $this->view->assign('depthBaseUrl', $url);
244  $this->view->assign('depth', $this->depth);
245  $this->view->assign('depthOptions', $depthOptions);
246 
247  $beUserArray = BackendUtility::getUserNames();
248  $this->view->assign('beUsers', $beUserArray);
249  $beGroupArray = BackendUtility::getGroupNames();
250  $this->view->assign('beGroups', $beGroupArray);
251 
253  $tree = GeneralUtility::makeInstance(PageTreeView::class);
254  $tree->init();
255  $tree->addField('perms_user', true);
256  $tree->addField('perms_group', true);
257  $tree->addField('perms_everybody', true);
258  $tree->addField('perms_userid', true);
259  $tree->addField('perms_groupid', true);
260  $tree->addField('hidden');
261  $tree->addField('fe_group');
262  $tree->addField('starttime');
263  $tree->addField('endtime');
264  $tree->addField('editlock');
265 
266  // Create the tree from $this->id
267  if ($this->id) {
268  $tree->tree[] = ['row' => $this->pageInfo, 'HTML' => $tree->getIcon($this->id)];
269  } else {
270  $tree->tree[] = ['row' => $this->pageInfo, 'HTML' => $tree->getRootIcon($this->pageInfo)];
271  }
272  $tree->getTree($this->id, $this->depth);
273  $this->view->assign('viewTree', $tree->tree);
274 
275  // CSH for permissions setting
276  $this->view->assign('cshItem', BackendUtility::cshItem('xMOD_csh_corebe', 'perm_module', null, '<span class="btn btn-default btn-sm">|</span>'));
277  }
278 
284  public function editAction()
285  {
286  $this->view->assign('id', $this->id);
287  $this->view->assign('depth', $this->depth);
288 
289  if (!$this->id) {
290  $this->pageInfo = ['title' => '[root-level]', 'uid' => 0, 'pid' => 0];
291  }
292  if ($this->getBackendUser()->workspace != 0) {
293  // Adding FlashMessage with the permission setting matrix:
294  $this->addFlashMessage(
295  LocalizationUtility::translate('LLL:EXT:beuser/Resources/Private/Language/locallang_mod_permission.xlf:WorkspaceWarningText', 'beuser'),
296  LocalizationUtility::translate('LLL:EXT:beuser/Resources/Private/Language/locallang_mod_permission.xlf:WorkspaceWarning', 'beuser'),
298  );
299  }
300  // Get usernames and groupnames
301  $beGroupArray = BackendUtility::getListGroupNames('title,uid');
302  $beUserArray = BackendUtility::getUserNames();
303 
304  // Owner selector
305  $beUserDataArray = [0 => LocalizationUtility::translate('LLL:EXT:beuser/Resources/Private/Language/locallang_mod_permission.xlf:selectNone', 'beuser')];
306  foreach ($beUserArray as $uid => &$row) {
307  $beUserDataArray[$uid] = $row['username'];
308  }
309  $beUserDataArray[-1] = LocalizationUtility::translate('LLL:EXT:beuser/Resources/Private/Language/locallang_mod_permission.xlf:selectUnchanged', 'beuser');
310  $this->view->assign('currentBeUser', $this->pageInfo['perms_userid']);
311  $this->view->assign('beUserData', $beUserDataArray);
312 
313  // Group selector
314  $beGroupDataArray = [0 => LocalizationUtility::translate('LLL:EXT:beuser/Resources/Private/Language/locallang_mod_permission.xlf:selectNone', 'beuser')];
315  foreach ($beGroupArray as $uid => $row) {
316  $beGroupDataArray[$uid] = $row['title'];
317  }
318  $beGroupDataArray[-1] = LocalizationUtility::translate('LLL:EXT:beuser/Resources/Private/Language/locallang_mod_permission.xlf:selectUnchanged', 'beuser');
319  $this->view->assign('currentBeGroup', $this->pageInfo['perms_groupid']);
320  $this->view->assign('beGroupData', $beGroupDataArray);
321  $this->view->assign('pageInfo', $this->pageInfo);
322  $this->view->assign('returnUrl', $this->returnUrl);
323  $this->view->assign('recursiveSelectOptions', $this->getRecursiveSelectOptions());
324  }
325 
333  protected function updateAction(array $data, array $mirror)
334  {
335  if (!empty($data['pages'])) {
336  foreach ($data['pages'] as $pageUid => $properties) {
337  // if the owner and group field shouldn't be touched, unset the option
338  if ((int)$properties['perms_userid'] === -1) {
339  unset($properties['perms_userid']);
340  }
341  if ((int)$properties['perms_groupid'] === -1) {
342  unset($properties['perms_groupid']);
343  }
344  $this->getDatabaseConnection()->exec_UPDATEquery(
345  'pages',
346  'uid = ' . (int)$pageUid,
347  $properties
348  );
349  if (!empty($mirror['pages'][$pageUid])) {
350  $mirrorPages = GeneralUtility::trimExplode(',', $mirror['pages'][$pageUid]);
351  foreach ($mirrorPages as $mirrorPageUid) {
352  $this->getDatabaseConnection()->exec_UPDATEquery(
353  'pages',
354  'uid = ' . (int)$mirrorPageUid,
355  $properties
356  );
357  }
358  }
359  }
360  }
361  $this->redirectToUri($this->returnUrl);
362  }
363 
367  protected function getBackendUser()
368  {
369  return $GLOBALS['BE_USER'];
370  }
371 
375  protected function getDatabaseConnection()
376  {
377  return $GLOBALS['TYPO3_DB'];
378  }
379 
385  protected function getRecursiveSelectOptions()
386  {
387  // Initialize tree object:
388  $tree = GeneralUtility::makeInstance(PageTreeView::class);
389  $tree->init();
390  $tree->addField('perms_userid', true);
391  $tree->makeHTML = 0;
392  $tree->setRecs = 1;
393  // Make tree:
394  $tree->getTree($this->id, $this->getLevels, '');
395  $options = [];
396  $options[''] = '';
397  // If there are a hierarchy of page ids, then...
398  if ($this->getBackendUser()->user['uid'] && !empty($tree->orig_ids_hierarchy)) {
399  // Init:
400  $labelRecursive = LocalizationUtility::translate('LLL:EXT:beuser/Resources/Private/Language/locallang_mod_permission.xlf:recursive', 'beuser');
401  $labelLevels = LocalizationUtility::translate('LLL:EXT:beuser/Resources/Private/Language/locallang_mod_permission.xlf:levels', 'beuser');
402  $labelPagesAffected = LocalizationUtility::translate('LLL:EXT:beuser/Resources/Private/Language/locallang_mod_permission.xlf:pages_affected', 'beuser');
403  $theIdListArr = [];
404  // Traverse the number of levels we want to allow recursive
405  // setting of permissions for:
406  for ($a = $this->getLevels; $a > 0; $a--) {
407  if (is_array($tree->orig_ids_hierarchy[$a])) {
408  foreach ($tree->orig_ids_hierarchy[$a] as $theId) {
409  $theIdListArr[] = $theId;
410  }
411  $lKey = $this->getLevels - $a + 1;
412  $options[implode(',', $theIdListArr)] = $labelRecursive . ' ' . $lKey . ' ' . $labelLevels .
413  ' (' . count($theIdListArr) . ' ' . $labelPagesAffected . ')';
414  }
415  }
416  }
417  return $options;
418  }
419 
425  protected function getLanguageService()
426  {
427  return $GLOBALS['LANG'];
428  }
429 }
static translate($key, $extensionName, $arguments=null)
static readPageAccess($id, $perms_clause)
static BEgetRootLine($uid, $clause='', $workspaceOL=false)
static getGroupNames($fields='title, uid', $where='')
static trimExplode($delim, $string, $removeEmptyValues=false, $limit=0)
static getUserNames($fields='username, usergroup, usergroup_cached_list, uid', $where='')
static cshItem($table, $field, $_='', $wrap='')
static viewOnClick($pageUid, $backPath='', $rootLine=null, $anchorSection='', $alternativeUrl='', $additionalGetVars='', $switchFocus=true)
$uid
Definition: server.php:38
static getListGroupNames($fields='title, uid')
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']
addFlashMessage($messageBody, $messageTitle='', $severity=\TYPO3\CMS\Core\Messaging\AbstractMessage::OK, $storeInSession=true)