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

		// Permissions
		if (!\is_array($this->User->fop))
		{
			$this->User->fop = array();
		}

		$canUpload = $this->User->hasAccess('f1', 'fop');
		$canEdit = $this->User->hasAccess('f2', 'fop');
		$canDeleteOne = $this->User->hasAccess('f3', 'fop');
		$canDeleteRecursive = $this->User->hasAccess('f4', 'fop');

		// Set the filemounts
		$GLOBALS['TL_DCA']['tl_files']['list']['sorting']['root'] = $this->User->filemounts;

		// Disable the upload button if uploads are not allowed
		if (!$canUpload)
		{
			$GLOBALS['TL_DCA']['tl_files']['config']['closed'] = true;
		}

		// Disable the edit_all button
		if (!$canEdit)
		{
			$GLOBALS['TL_DCA']['tl_files']['config']['notEditable'] = true;
		}

		// Disable the delete_all button
		if (!$canDeleteOne && !$canDeleteRecursive)
		{
			$GLOBALS['TL_DCA']['tl_files']['config']['notDeletable'] = true;
		}

		$container = Contao\System::getContainer();
		$rootDir = $container->getParameter('kernel.project_dir');
		$objSession = $container->get('session');

		$session = $objSession->all();

		// Set allowed page IDs (edit multiple)
		if (\is_array($session['CURRENT']['IDS']))
		{
			if (Contao\Input::get('act') == 'editAll')
			{
				if (!$canEdit)
				{
					$session['CURRENT']['IDS'] = array();
				}
			}

			// Check delete permissions
			else
			{
				$folders = array();
				$delete_all = array();

				foreach ($session['CURRENT']['IDS'] as $id)
				{
					if (is_dir($rootDir . '/' . $id))
					{
						$folders[] = $id;

						if ($canDeleteRecursive || ($canDeleteOne && \count(scan($rootDir . '/' . $id)) < 1))
						{
							$delete_all[] = $id;
						}
					}
					else
					{
						if (($canDeleteOne || $canDeleteRecursive) && !\in_array(\dirname($id), $folders))
						{
							$delete_all[] = $id;
						}
					}
				}

				$session['CURRENT']['IDS'] = $delete_all;
			}
		}

		// Set allowed clipboard IDs
		if (isset($session['CLIPBOARD']['tl_files']) && !$canEdit)
		{
			$session['CLIPBOARD']['tl_files'] = array();
		}

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

		// Check current action
		if (Contao\Input::get('act') && Contao\Input::get('act') != 'paste')
		{
			switch (Contao\Input::get('act'))
			{
				case 'move':
					if (!$canUpload)
					{
						throw new Contao\CoreBundle\Exception\AccessDeniedException('No permission to upload files.');
					}
					break;

				case 'edit':
				case 'create':
				case 'copy':
				case 'copyAll':
				case 'cut':
				case 'cutAll':
					if (!$canEdit)
					{
						throw new Contao\CoreBundle\Exception\AccessDeniedException('No permission to create, edit, copy or move files.');
					}
					break;

				case 'delete':
					$strFile = Contao\Input::get('id', true);

					if (is_dir($rootDir . '/' . $strFile))
					{
						$finder = Symfony\Component\Finder\Finder::create()->in($rootDir . '/' . $strFile);

						if ($finder->count() > 0 && !$canDeleteRecursive)
						{
							throw new Contao\CoreBundle\Exception\AccessDeniedException('No permission to delete folder "' . $strFile . '" recursively.');
						}
						elseif (!$canDeleteOne)
						{
							throw new Contao\CoreBundle\Exception\AccessDeniedException('No permission to delete folder "' . $strFile . '".');
						}
					}
					elseif (!$canDeleteOne)
					{
						throw new Contao\CoreBundle\Exception\AccessDeniedException('No permission to delete file "' . $strFile . '".');
					}
					break;

				case 'source':
					if (!$this->User->hasAccess('f5', 'fop'))
					{
						throw new Contao\CoreBundle\Exception\AccessDeniedException('Not enough permissions to edit the source of file "' . Contao\Input::get('id', true) . '".');
					}
					break;

				case 'sync':
					if (!$this->User->hasAccess('f6', 'fop'))
					{
						throw new Contao\CoreBundle\Exception\AccessDeniedException('No permission to synchronize the file system with the database.');
					}
					break;

				default:
					if (empty($this->User->fop))
					{
						throw new Contao\CoreBundle\Exception\AccessDeniedException('No permission to manipulate files.');
					}
					break;
			}
		}
	}
public function checkPermission()
	{
		if ($this->User->isAdmin)
		{
			return;
		}

		
		if (!\is_array($this->User->fop))
		{
			$this->User->fop = array();
		}

		$canUpload = $this->User->hasAccess('f1', 'fop');
		$canEdit = $this->User->hasAccess('f2', 'fop');
		$canDeleteOne = $this->User->hasAccess('f3', 'fop');
		$canDeleteRecursive = $this->User->hasAccess('f4', 'fop');

		
		$GLOBALS['TL_DCA']['tl_files']['list']['sorting']['root'] = $this->User->filemounts;

		
		if (!$canUpload)
		{
			$GLOBALS['TL_DCA']['tl_files']['config']['closed'] = true;
		}

		
		if (!$canEdit)
		{
			$GLOBALS['TL_DCA']['tl_files']['config']['notEditable'] = true;
		}

		
		if (!$canDeleteOne && !$canDeleteRecursive)
		{
			$GLOBALS['TL_DCA']['tl_files']['config']['notDeletable'] = true;
		}

		$container = Contao\System::getContainer();
		$rootDir = $container->getParameter('kernel.project_dir');
		$objSession = $container->get('session');

		$session = $objSession->all();

		
		if (\is_array($session['CURRENT']['IDS']))
		{
			if (Contao\Input::get('act') == 'editAll')
			{
				if (!$canEdit)
				{
					$session['CURRENT']['IDS'] = array();
				}
			}

			
			else
			{
				$folders = array();
				$delete_all = array();

				foreach ($session['CURRENT']['IDS'] as $id)
				{
					if (is_dir($rootDir . '/' . $id))
					{
						$folders[] = $id;

						if ($canDeleteRecursive || ($canDeleteOne && \count(scan($rootDir . '/' . $id)) < 1))
						{
							$delete_all[] = $id;
						}
					}
					else
					{
						if (($canDeleteOne || $canDeleteRecursive) && !\in_array(\dirname($id), $folders))
						{
							$delete_all[] = $id;
						}
					}
				}

				$session['CURRENT']['IDS'] = $delete_all;
			}
		}

		
		if (isset($session['CLIPBOARD']['tl_files']) && !$canEdit)
		{
			$session['CLIPBOARD']['tl_files'] = array();
		}

		
		$objSession->replace($session);

		
		if (Contao\Input::get('act') && Contao\Input::get('act') != 'paste')
		{
			switch (Contao\Input::get('act'))
			{
				case 'move':
					if (!$canUpload)
					{
						throw new Contao\CoreBundle\Exception\AccessDeniedException('No permission to upload files.');
					}
					break;

				case 'edit':
				case 'create':
				case 'copy':
				case 'copyAll':
				case 'cut':
				case 'cutAll':
					if (!$canEdit)
					{
						throw new Contao\CoreBundle\Exception\AccessDeniedException('No permission to create, edit, copy or move files.');
					}
					break;

				case 'delete':
					$strFile = Contao\Input::get('id', true);

					if (is_dir($rootDir . '/' . $strFile))
					{
						$finder = Symfony\Component\Finder\Finder::create()->in($rootDir . '/' . $strFile);

						if ($finder->count() > 0 && !$canDeleteRecursive)
						{
							throw new Contao\CoreBundle\Exception\AccessDeniedException('No permission to delete folder "' . $strFile . '" recursively.');
						}
						elseif (!$canDeleteOne)
						{
							throw new Contao\CoreBundle\Exception\AccessDeniedException('No permission to delete folder "' . $strFile . '".');
						}
					}
					elseif (!$canDeleteOne)
					{
						throw new Contao\CoreBundle\Exception\AccessDeniedException('No permission to delete file "' . $strFile . '".');
					}
					break;

				case 'source':
					if (!$this->User->hasAccess('f5', 'fop'))
					{
						throw new Contao\CoreBundle\Exception\AccessDeniedException('Not enough permissions to edit the source of file "' . Contao\Input::get('id', true) . '".');
					}
					break;

				case 'sync':
					if (!$this->User->hasAccess('f6', 'fop'))
					{
						throw new Contao\CoreBundle\Exception\AccessDeniedException('No permission to synchronize the file system with the database.');
					}
					break;

				default:
					if (empty($this->User->fop))
					{
						throw new Contao\CoreBundle\Exception\AccessDeniedException('No permission to manipulate files.');
					}
					break;
			}
		}
	}
public function checkPermission ( ) { if ( $ this -> User -> isAdmin ) { return ; } // Permissions if ( ! \ is_array ( $ this -> User -> fop ) ) { $ this -> User -> fop = array ( ) ; } $ canUpload = $ this -> User -> hasAccess ( 'f1' , 'fop' ) ; $ canEdit = $ this -> User -> hasAccess ( 'f2' , 'fop' ) ; $ canDeleteOne = $ this -> User -> hasAccess ( 'f3' , 'fop' ) ; $ canDeleteRecursive = $ this -> User -> hasAccess ( 'f4' , 'fop' ) ; // Set the filemounts $ GLOBALS [ 'TL_DCA' ] [ 'tl_files' ] [ 'list' ] [ 'sorting' ] [ 'root' ] = $ this -> User -> filemounts ; // Disable the upload button if uploads are not allowed if ( ! $ canUpload ) { $ GLOBALS [ 'TL_DCA' ] [ 'tl_files' ] [ 'config' ] [ 'closed' ] = true ; } // Disable the edit_all button if ( ! $ canEdit ) { $ GLOBALS [ 'TL_DCA' ] [ 'tl_files' ] [ 'config' ] [ 'notEditable' ] = true ; } // Disable the delete_all button if ( ! $ canDeleteOne && ! $ canDeleteRecursive ) { $ GLOBALS [ 'TL_DCA' ] [ 'tl_files' ] [ 'config' ] [ 'notDeletable' ] = true ; } $ container = Contao \ System :: getContainer ( ) ; $ rootDir = $ container -> getParameter ( 'kernel.project_dir' ) ; $ objSession = $ container -> get ( 'session' ) ; $ session = $ objSession -> all ( ) ; // Set allowed page IDs (edit multiple) if ( \ is_array ( $ session [ 'CURRENT' ] [ 'IDS' ] ) ) { if ( Contao \ Input :: get ( 'act' ) == 'editAll' ) { if ( ! $ canEdit ) { $ session [ 'CURRENT' ] [ 'IDS' ] = array ( ) ; } } // Check delete permissions else { $ folders = array ( ) ; $ delete_all = array ( ) ; foreach ( $ session [ 'CURRENT' ] [ 'IDS' ] as $ id ) { if ( is_dir ( $ rootDir . '/' . $ id ) ) { $ folders [ ] = $ id ; if ( $ canDeleteRecursive || ( $ canDeleteOne && \ count ( scan ( $ rootDir . '/' . $ id ) ) < 1 ) ) { $ delete_all [ ] = $ id ; } } else { if ( ( $ canDeleteOne || $ canDeleteRecursive ) && ! \ in_array ( \ dirname ( $ id ) , $ folders ) ) { $ delete_all [ ] = $ id ; } } } $ session [ 'CURRENT' ] [ 'IDS' ] = $ delete_all ; } } // Set allowed clipboard IDs if ( isset ( $ session [ 'CLIPBOARD' ] [ 'tl_files' ] ) && ! $ canEdit ) { $ session [ 'CLIPBOARD' ] [ 'tl_files' ] = array ( ) ; } // Overwrite session $ objSession -> replace ( $ session ) ; // Check current action if ( Contao \ Input :: get ( 'act' ) && Contao \ Input :: get ( 'act' ) != 'paste' ) { switch ( Contao \ Input :: get ( 'act' ) ) { case 'move' : if ( ! $ canUpload ) { throw new Contao \ CoreBundle \ Exception \ AccessDeniedException ( 'No permission to upload files.' ) ; } break ; case 'edit' : case 'create' : case 'copy' : case 'copyAll' : case 'cut' : case 'cutAll' : if ( ! $ canEdit ) { throw new Contao \ CoreBundle \ Exception \ AccessDeniedException ( 'No permission to create, edit, copy or move files.' ) ; } break ; case 'delete' : $ strFile = Contao \ Input :: get ( 'id' , true ) ; if ( is_dir ( $ rootDir . '/' . $ strFile ) ) { $ finder = Symfony \ Component \ Finder \ Finder :: create ( ) -> in ( $ rootDir . '/' . $ strFile ) ; if ( $ finder -> count ( ) > 0 && ! $ canDeleteRecursive ) { throw new Contao \ CoreBundle \ Exception \ AccessDeniedException ( 'No permission to delete folder "' . $ strFile . '" recursively.' ) ; } elseif ( ! $ canDeleteOne ) { throw new Contao \ CoreBundle \ Exception \ AccessDeniedException ( 'No permission to delete folder "' . $ strFile . '".' ) ; } } elseif ( ! $ canDeleteOne ) { throw new Contao \ CoreBundle \ Exception \ AccessDeniedException ( 'No permission to delete file "' . $ strFile . '".' ) ; } break ; case 'source' : if ( ! $ this -> User -> hasAccess ( 'f5' , 'fop' ) ) { throw new Contao \ CoreBundle \ Exception \ AccessDeniedException ( 'Not enough permissions to edit the source of file "' . Contao \ Input :: get ( 'id' , true ) . '".' ) ; } break ; case 'sync' : if ( ! $ this -> User -> hasAccess ( 'f6' , 'fop' ) ) { throw new Contao \ CoreBundle \ Exception \ AccessDeniedException ( 'No permission to synchronize the file system with the database.' ) ; } break ; default : if ( empty ( $ this -> User -> fop ) ) { throw new Contao \ CoreBundle \ Exception \ AccessDeniedException ( 'No permission to manipulate files.' ) ; } break ; } } }
Check permissions to edit the file system

@throws Contao\CoreBundle\Exception\AccessDeniedException
Check permissions to edit the file system