public function checkPermission()
	{
		if ($this->User->isAdmin)
		{
			return;
		}

		/** @var Symfony\Component\HttpFoundation\Session\SessionInterface $objSession */
		$objSession = Contao\System::getContainer()->get('session');

		$session = $objSession->all();

		// Set the default page user and group
		$GLOBALS['TL_DCA']['tl_page']['fields']['cuser']['default'] = (int) Contao\Config::get('defaultUser') ?: $this->User->id;
		$GLOBALS['TL_DCA']['tl_page']['fields']['cgroup']['default'] = (int) Contao\Config::get('defaultGroup') ?: (int) $this->User->groups[0];

		// Restrict the page tree
		if (empty($this->User->pagemounts) || !\is_array($this->User->pagemounts))
		{
			$root = array(0);
		}
		else
		{
			$root = $this->User->pagemounts;
		}

		$GLOBALS['TL_DCA']['tl_page']['list']['sorting']['root'] = $root;

		// Set allowed page IDs (edit multiple)
		if (\is_array($session['CURRENT']['IDS']))
		{
			$edit_all = array();
			$delete_all = array();

			foreach ($session['CURRENT']['IDS'] as $id)
			{
				$objPage = $this->Database->prepare("SELECT id, pid, type, includeChmod, chmod, cuser, cgroup FROM tl_page WHERE id=?")
										  ->limit(1)
										  ->execute($id);

				if ($objPage->numRows < 1 || !$this->User->hasAccess($objPage->type, 'alpty'))
				{
					continue;
				}

				$row = $objPage->row();

				if ($this->User->isAllowed(Contao\BackendUser::CAN_EDIT_PAGE, $row))
				{
					$edit_all[] = $id;
				}

				// Mounted pages cannot be deleted
				if ($this->User->isAllowed(Contao\BackendUser::CAN_DELETE_PAGE, $row) && !$this->User->hasAccess($id, 'pagemounts'))
				{
					$delete_all[] = $id;
				}
			}

			$session['CURRENT']['IDS'] = (Contao\Input::get('act') == 'deleteAll') ? $delete_all : $edit_all;
		}

		// Set allowed clipboard IDs
		if (isset($session['CLIPBOARD']['tl_page']) && \is_array($session['CLIPBOARD']['tl_page']['id']))
		{
			$clipboard = array();

			foreach ($session['CLIPBOARD']['tl_page']['id'] as $id)
			{
				$objPage = $this->Database->prepare("SELECT id, pid, type, includeChmod, chmod, cuser, cgroup FROM tl_page WHERE id=?")
										  ->limit(1)
										  ->execute($id);

				if ($objPage->numRows < 1 || !$this->User->hasAccess($objPage->type, 'alpty'))
				{
					continue;
				}

				if ($this->User->isAllowed(Contao\BackendUser::CAN_EDIT_PAGE_HIERARCHY, $objPage->row()))
				{
					$clipboard[] = $id;
				}
			}

			$session['CLIPBOARD']['tl_page']['id'] = $clipboard;
		}

		// Overwrite session
		$objSession->replace($session);

		// Check permissions to save and create new
		if (Contao\Input::get('act') == 'edit')
		{
			$objPage = $this->Database->prepare("SELECT * FROM tl_page WHERE id=(SELECT pid FROM tl_page WHERE id=?)")
									  ->limit(1)
									  ->execute(Contao\Input::get('id'));

			if ($objPage->numRows && !$this->User->isAllowed(Contao\BackendUser::CAN_EDIT_PAGE_HIERARCHY, $objPage->row()))
			{
				$GLOBALS['TL_DCA']['tl_page']['config']['closed'] = true;
			}
		}

		// Check current action
		if (Contao\Input::get('act') && Contao\Input::get('act') != 'paste')
		{
			$permission = 0;
			$cid = CURRENT_ID ?: Contao\Input::get('id');
			$ids = ($cid != '') ? array($cid) : array();

			// Set permission
			switch (Contao\Input::get('act'))
			{
				case 'edit':
				case 'toggle':
					$permission = Contao\BackendUser::CAN_EDIT_PAGE;
					break;

				case 'move':
					$permission = Contao\BackendUser::CAN_EDIT_PAGE_HIERARCHY;
					$ids[] = Contao\Input::get('sid');
					break;

				case 'create':
				case 'copy':
				case 'copyAll':
				case 'cut':
				case 'cutAll':
					$permission = Contao\BackendUser::CAN_EDIT_PAGE_HIERARCHY;

					// Check the parent page in "paste into" mode
					if (Contao\Input::get('mode') == 2)
					{
						$ids[] = Contao\Input::get('pid');
					}
					// Check the parent's parent page in "paste after" mode
					else
					{
						$objPage = $this->Database->prepare("SELECT pid FROM tl_page WHERE id=?")
												  ->limit(1)
												  ->execute(Contao\Input::get('pid'));

						$ids[] = $objPage->pid;
					}
					break;

				case 'delete':
					$permission = Contao\BackendUser::CAN_DELETE_PAGE;
					break;
			}

			// Check user permissions
			if (Contao\Input::get('act') != 'show')
			{
				$pagemounts = array();

				// Get all allowed pages for the current user
				foreach ($this->User->pagemounts as $root)
				{
					if (Contao\Input::get('act') != 'delete')
					{
						$pagemounts[] = array($root);
					}

					$pagemounts[] = $this->Database->getChildRecords($root, 'tl_page');
				}

				if (!empty($pagemounts))
				{
					$pagemounts = array_merge(...$pagemounts);
				}

				$pagemounts = array_unique($pagemounts);

				// Do not allow to paste after pages on the root level (pagemounts)
				if ((Contao\Input::get('act') == 'cut' || Contao\Input::get('act') == 'cutAll') && Contao\Input::get('mode') == 1 && \in_array(Contao\Input::get('pid'), $this->eliminateNestedPages($this->User->pagemounts)))
				{
					throw new Contao\CoreBundle\Exception\AccessDeniedException('Not enough permissions to paste page ID ' . Contao\Input::get('id') . ' after mounted page ID ' . Contao\Input::get('pid') . ' (root level).');
				}

				$error = false;

				// Check each page
				foreach ($ids as $i=>$id)
				{
					if (!\in_array($id, $pagemounts))
					{
						$this->log('Page ID '. $id .' was not mounted', __METHOD__, TL_ERROR);

						$error = true;
						break;
					}

					// Get the page object
					$objPage = Contao\PageModel::findById($id);

					if ($objPage === null)
					{
						continue;
					}

					// Check whether the current user is allowed to access the current page
					if (!$this->User->isAllowed($permission, $objPage->row()))
					{
						$error = true;
						break;
					}

					// Check the type of the first page (not the following parent pages)
					// In "edit multiple" mode, $ids contains only the parent ID, therefore check $id != $_GET['pid'] (see #5620)
					if ($i == 0 && $id != Contao\Input::get('pid') && Contao\Input::get('act') != 'create' && !$this->User->hasAccess($objPage->type, 'alpty'))
					{
						$this->log('Not enough permissions to  '. Contao\Input::get('act') .' '. $objPage->type .' pages', __METHOD__, TL_ERROR);

						$error = true;
						break;
					}
				}

				// Redirect if there is an error
				if ($error)
				{
					throw new Contao\CoreBundle\Exception\AccessDeniedException('Not enough permissions to ' . Contao\Input::get('act') . ' page ID ' . $cid . ' or paste after/into page ID ' . Contao\Input::get('pid') . '.');
				}
			}
		}
	}
public function checkPermission()
	{
		if ($this->User->isAdmin)
		{
			return;
		}

		
		$objSession = Contao\System::getContainer()->get('session');

		$session = $objSession->all();

		
		$GLOBALS['TL_DCA']['tl_page']['fields']['cuser']['default'] = (int) Contao\Config::get('defaultUser') ?: $this->User->id;
		$GLOBALS['TL_DCA']['tl_page']['fields']['cgroup']['default'] = (int) Contao\Config::get('defaultGroup') ?: (int) $this->User->groups[0];

		
		if (empty($this->User->pagemounts) || !\is_array($this->User->pagemounts))
		{
			$root = array(0);
		}
		else
		{
			$root = $this->User->pagemounts;
		}

		$GLOBALS['TL_DCA']['tl_page']['list']['sorting']['root'] = $root;

		
		if (\is_array($session['CURRENT']['IDS']))
		{
			$edit_all = array();
			$delete_all = array();

			foreach ($session['CURRENT']['IDS'] as $id)
			{
				$objPage = $this->Database->prepare("SELECT id, pid, type, includeChmod, chmod, cuser, cgroup FROM tl_page WHERE id=?")
										  ->limit(1)
										  ->execute($id);

				if ($objPage->numRows < 1 || !$this->User->hasAccess($objPage->type, 'alpty'))
				{
					continue;
				}

				$row = $objPage->row();

				if ($this->User->isAllowed(Contao\BackendUser::CAN_EDIT_PAGE, $row))
				{
					$edit_all[] = $id;
				}

				
				if ($this->User->isAllowed(Contao\BackendUser::CAN_DELETE_PAGE, $row) && !$this->User->hasAccess($id, 'pagemounts'))
				{
					$delete_all[] = $id;
				}
			}

			$session['CURRENT']['IDS'] = (Contao\Input::get('act') == 'deleteAll') ? $delete_all : $edit_all;
		}

		
		if (isset($session['CLIPBOARD']['tl_page']) && \is_array($session['CLIPBOARD']['tl_page']['id']))
		{
			$clipboard = array();

			foreach ($session['CLIPBOARD']['tl_page']['id'] as $id)
			{
				$objPage = $this->Database->prepare("SELECT id, pid, type, includeChmod, chmod, cuser, cgroup FROM tl_page WHERE id=?")
										  ->limit(1)
										  ->execute($id);

				if ($objPage->numRows < 1 || !$this->User->hasAccess($objPage->type, 'alpty'))
				{
					continue;
				}

				if ($this->User->isAllowed(Contao\BackendUser::CAN_EDIT_PAGE_HIERARCHY, $objPage->row()))
				{
					$clipboard[] = $id;
				}
			}

			$session['CLIPBOARD']['tl_page']['id'] = $clipboard;
		}

		
		$objSession->replace($session);

		
		if (Contao\Input::get('act') == 'edit')
		{
			$objPage = $this->Database->prepare("SELECT * FROM tl_page WHERE id=(SELECT pid FROM tl_page WHERE id=?)")
									  ->limit(1)
									  ->execute(Contao\Input::get('id'));

			if ($objPage->numRows && !$this->User->isAllowed(Contao\BackendUser::CAN_EDIT_PAGE_HIERARCHY, $objPage->row()))
			{
				$GLOBALS['TL_DCA']['tl_page']['config']['closed'] = true;
			}
		}

		
		if (Contao\Input::get('act') && Contao\Input::get('act') != 'paste')
		{
			$permission = 0;
			$cid = CURRENT_ID ?: Contao\Input::get('id');
			$ids = ($cid != '') ? array($cid) : array();

			
			switch (Contao\Input::get('act'))
			{
				case 'edit':
				case 'toggle':
					$permission = Contao\BackendUser::CAN_EDIT_PAGE;
					break;

				case 'move':
					$permission = Contao\BackendUser::CAN_EDIT_PAGE_HIERARCHY;
					$ids[] = Contao\Input::get('sid');
					break;

				case 'create':
				case 'copy':
				case 'copyAll':
				case 'cut':
				case 'cutAll':
					$permission = Contao\BackendUser::CAN_EDIT_PAGE_HIERARCHY;

					
					if (Contao\Input::get('mode') == 2)
					{
						$ids[] = Contao\Input::get('pid');
					}
					
					else
					{
						$objPage = $this->Database->prepare("SELECT pid FROM tl_page WHERE id=?")
												  ->limit(1)
												  ->execute(Contao\Input::get('pid'));

						$ids[] = $objPage->pid;
					}
					break;

				case 'delete':
					$permission = Contao\BackendUser::CAN_DELETE_PAGE;
					break;
			}

			
			if (Contao\Input::get('act') != 'show')
			{
				$pagemounts = array();

				
				foreach ($this->User->pagemounts as $root)
				{
					if (Contao\Input::get('act') != 'delete')
					{
						$pagemounts[] = array($root);
					}

					$pagemounts[] = $this->Database->getChildRecords($root, 'tl_page');
				}

				if (!empty($pagemounts))
				{
					$pagemounts = array_merge(...$pagemounts);
				}

				$pagemounts = array_unique($pagemounts);

				
				if ((Contao\Input::get('act') == 'cut' || Contao\Input::get('act') == 'cutAll') && Contao\Input::get('mode') == 1 && \in_array(Contao\Input::get('pid'), $this->eliminateNestedPages($this->User->pagemounts)))
				{
					throw new Contao\CoreBundle\Exception\AccessDeniedException('Not enough permissions to paste page ID ' . Contao\Input::get('id') . ' after mounted page ID ' . Contao\Input::get('pid') . ' (root level).');
				}

				$error = false;

				
				foreach ($ids as $i=>$id)
				{
					if (!\in_array($id, $pagemounts))
					{
						$this->log('Page ID '. $id .' was not mounted', __METHOD__, TL_ERROR);

						$error = true;
						break;
					}

					
					$objPage = Contao\PageModel::findById($id);

					if ($objPage === null)
					{
						continue;
					}

					
					if (!$this->User->isAllowed($permission, $objPage->row()))
					{
						$error = true;
						break;
					}

					
					
					if ($i == 0 && $id != Contao\Input::get('pid') && Contao\Input::get('act') != 'create' && !$this->User->hasAccess($objPage->type, 'alpty'))
					{
						$this->log('Not enough permissions to  '. Contao\Input::get('act') .' '. $objPage->type .' pages', __METHOD__, TL_ERROR);

						$error = true;
						break;
					}
				}

				
				if ($error)
				{
					throw new Contao\CoreBundle\Exception\AccessDeniedException('Not enough permissions to ' . Contao\Input::get('act') . ' page ID ' . $cid . ' or paste after/into page ID ' . Contao\Input::get('pid') . '.');
				}
			}
		}
	}
public function checkPermission ( ) { if ( $ this -> User -> isAdmin ) { return ; } /** @var Symfony\Component\HttpFoundation\Session\SessionInterface $objSession */ $ objSession = Contao \ System :: getContainer ( ) -> get ( 'session' ) ; $ session = $ objSession -> all ( ) ; // Set the default page user and group $ GLOBALS [ 'TL_DCA' ] [ 'tl_page' ] [ 'fields' ] [ 'cuser' ] [ 'default' ] = ( int ) Contao \ Config :: get ( 'defaultUser' ) ? : $ this -> User -> id ; $ GLOBALS [ 'TL_DCA' ] [ 'tl_page' ] [ 'fields' ] [ 'cgroup' ] [ 'default' ] = ( int ) Contao \ Config :: get ( 'defaultGroup' ) ? : ( int ) $ this -> User -> groups [ 0 ] ; // Restrict the page tree if ( empty ( $ this -> User -> pagemounts ) || ! \ is_array ( $ this -> User -> pagemounts ) ) { $ root = array ( 0 ) ; } else { $ root = $ this -> User -> pagemounts ; } $ GLOBALS [ 'TL_DCA' ] [ 'tl_page' ] [ 'list' ] [ 'sorting' ] [ 'root' ] = $ root ; // Set allowed page IDs (edit multiple) if ( \ is_array ( $ session [ 'CURRENT' ] [ 'IDS' ] ) ) { $ edit_all = array ( ) ; $ delete_all = array ( ) ; foreach ( $ session [ 'CURRENT' ] [ 'IDS' ] as $ id ) { $ objPage = $ this -> Database -> prepare ( "SELECT id, pid, type, includeChmod, chmod, cuser, cgroup FROM tl_page WHERE id=?" ) -> limit ( 1 ) -> execute ( $ id ) ; if ( $ objPage -> numRows < 1 || ! $ this -> User -> hasAccess ( $ objPage -> type , 'alpty' ) ) { continue ; } $ row = $ objPage -> row ( ) ; if ( $ this -> User -> isAllowed ( Contao \ BackendUser :: CAN_EDIT_PAGE , $ row ) ) { $ edit_all [ ] = $ id ; } // Mounted pages cannot be deleted if ( $ this -> User -> isAllowed ( Contao \ BackendUser :: CAN_DELETE_PAGE , $ row ) && ! $ this -> User -> hasAccess ( $ id , 'pagemounts' ) ) { $ delete_all [ ] = $ id ; } } $ session [ 'CURRENT' ] [ 'IDS' ] = ( Contao \ Input :: get ( 'act' ) == 'deleteAll' ) ? $ delete_all : $ edit_all ; } // Set allowed clipboard IDs if ( isset ( $ session [ 'CLIPBOARD' ] [ 'tl_page' ] ) && \ is_array ( $ session [ 'CLIPBOARD' ] [ 'tl_page' ] [ 'id' ] ) ) { $ clipboard = array ( ) ; foreach ( $ session [ 'CLIPBOARD' ] [ 'tl_page' ] [ 'id' ] as $ id ) { $ objPage = $ this -> Database -> prepare ( "SELECT id, pid, type, includeChmod, chmod, cuser, cgroup FROM tl_page WHERE id=?" ) -> limit ( 1 ) -> execute ( $ id ) ; if ( $ objPage -> numRows < 1 || ! $ this -> User -> hasAccess ( $ objPage -> type , 'alpty' ) ) { continue ; } if ( $ this -> User -> isAllowed ( Contao \ BackendUser :: CAN_EDIT_PAGE_HIERARCHY , $ objPage -> row ( ) ) ) { $ clipboard [ ] = $ id ; } } $ session [ 'CLIPBOARD' ] [ 'tl_page' ] [ 'id' ] = $ clipboard ; } // Overwrite session $ objSession -> replace ( $ session ) ; // Check permissions to save and create new if ( Contao \ Input :: get ( 'act' ) == 'edit' ) { $ objPage = $ this -> Database -> prepare ( "SELECT * FROM tl_page WHERE id=(SELECT pid FROM tl_page WHERE id=?)" ) -> limit ( 1 ) -> execute ( Contao \ Input :: get ( 'id' ) ) ; if ( $ objPage -> numRows && ! $ this -> User -> isAllowed ( Contao \ BackendUser :: CAN_EDIT_PAGE_HIERARCHY , $ objPage -> row ( ) ) ) { $ GLOBALS [ 'TL_DCA' ] [ 'tl_page' ] [ 'config' ] [ 'closed' ] = true ; } } // Check current action if ( Contao \ Input :: get ( 'act' ) && Contao \ Input :: get ( 'act' ) != 'paste' ) { $ permission = 0 ; $ cid = CURRENT_ID ? : Contao \ Input :: get ( 'id' ) ; $ ids = ( $ cid != '' ) ? array ( $ cid ) : array ( ) ; // Set permission switch ( Contao \ Input :: get ( 'act' ) ) { case 'edit' : case 'toggle' : $ permission = Contao \ BackendUser :: CAN_EDIT_PAGE ; break ; case 'move' : $ permission = Contao \ BackendUser :: CAN_EDIT_PAGE_HIERARCHY ; $ ids [ ] = Contao \ Input :: get ( 'sid' ) ; break ; case 'create' : case 'copy' : case 'copyAll' : case 'cut' : case 'cutAll' : $ permission = Contao \ BackendUser :: CAN_EDIT_PAGE_HIERARCHY ; // Check the parent page in "paste into" mode if ( Contao \ Input :: get ( 'mode' ) == 2 ) { $ ids [ ] = Contao \ Input :: get ( 'pid' ) ; } // Check the parent's parent page in "paste after" mode else { $ objPage = $ this -> Database -> prepare ( "SELECT pid FROM tl_page WHERE id=?" ) -> limit ( 1 ) -> execute ( Contao \ Input :: get ( 'pid' ) ) ; $ ids [ ] = $ objPage -> pid ; } break ; case 'delete' : $ permission = Contao \ BackendUser :: CAN_DELETE_PAGE ; break ; } // Check user permissions if ( Contao \ Input :: get ( 'act' ) != 'show' ) { $ pagemounts = array ( ) ; // Get all allowed pages for the current user foreach ( $ this -> User -> pagemounts as $ root ) { if ( Contao \ Input :: get ( 'act' ) != 'delete' ) { $ pagemounts [ ] = array ( $ root ) ; } $ pagemounts [ ] = $ this -> Database -> getChildRecords ( $ root , 'tl_page' ) ; } if ( ! empty ( $ pagemounts ) ) { $ pagemounts = array_merge ( ... $ pagemounts ) ; } $ pagemounts = array_unique ( $ pagemounts ) ; // Do not allow to paste after pages on the root level (pagemounts) if ( ( Contao \ Input :: get ( 'act' ) == 'cut' || Contao \ Input :: get ( 'act' ) == 'cutAll' ) && Contao \ Input :: get ( 'mode' ) == 1 && \ in_array ( Contao \ Input :: get ( 'pid' ) , $ this -> eliminateNestedPages ( $ this -> User -> pagemounts ) ) ) { throw new Contao \ CoreBundle \ Exception \ AccessDeniedException ( 'Not enough permissions to paste page ID ' . Contao \ Input :: get ( 'id' ) . ' after mounted page ID ' . Contao \ Input :: get ( 'pid' ) . ' (root level).' ) ; } $ error = false ; // Check each page foreach ( $ ids as $ i => $ id ) { if ( ! \ in_array ( $ id , $ pagemounts ) ) { $ this -> log ( 'Page ID ' . $ id . ' was not mounted' , __METHOD__ , TL_ERROR ) ; $ error = true ; break ; } // Get the page object $ objPage = Contao \ PageModel :: findById ( $ id ) ; if ( $ objPage === null ) { continue ; } // Check whether the current user is allowed to access the current page if ( ! $ this -> User -> isAllowed ( $ permission , $ objPage -> row ( ) ) ) { $ error = true ; break ; } // Check the type of the first page (not the following parent pages) // In "edit multiple" mode, $ids contains only the parent ID, therefore check $id != $_GET['pid'] (see #5620) if ( $ i == 0 && $ id != Contao \ Input :: get ( 'pid' ) && Contao \ Input :: get ( 'act' ) != 'create' && ! $ this -> User -> hasAccess ( $ objPage -> type , 'alpty' ) ) { $ this -> log ( 'Not enough permissions to  ' . Contao \ Input :: get ( 'act' ) . ' ' . $ objPage -> type . ' pages' , __METHOD__ , TL_ERROR ) ; $ error = true ; break ; } } // Redirect if there is an error if ( $ error ) { throw new Contao \ CoreBundle \ Exception \ AccessDeniedException ( 'Not enough permissions to ' . Contao \ Input :: get ( 'act' ) . ' page ID ' . $ cid . ' or paste after/into page ID ' . Contao \ Input :: get ( 'pid' ) . '.' ) ; } } } }
Check permissions to edit table tl_page

@throws Contao\CoreBundle\Exception\AccessDeniedException
Check permissions to edit table tl_page