/** * Get permissions for given role * * @param string $role * * @return array * @throws \Exception */ protected function getPermissionsForRole($role) { // we expect role is a string - if not, we need to throw exception if (!is_string($role)) { throw new \InvalidArgumentException('Role has to be a string'); } if (!isset($this->permissions['roles'][$role])) { $this->log->critical("There are no permissions assigned to role {$role}"); return []; } $permissions = $this->permissions['roles'][$role]; // for some roles (probably admin) we allow to specify only asterisk as // permission and in this case we will use all available permissions if (count($permissions) == 1 && $permissions[0] == '*') { return $this->permissions['available']; } return $permissions; }
/** * Checks the installation directory to make sure it is ready. * * @throws InvalidInstallationDirectoryException * @throws PackageInstallationException * @param $directory */ private function checkInstallationDirectory($directory) { if ($this->installationAttempts >= $this->breakAtInstallationAttempt) { $this->log->error('Installation directory checks failed at max attempts', ['attempts' => $this->installationAttempts]); throw new PackageInstallationException(null, "The package template could not be installed."); } $files = $this->files->allFiles($directory); $directories = $this->files->directories($directory); if (count($files) == 0 && count($directories) == 0) { return; } $directoriesReadable = true; $filesReadable = true; foreach ($directories as $directory) { if (!$this->files->isReadable($directory)) { $this->log->error('Unreadable directory preventing Composer install', ['directory' => $directory]); $directoriesReadable = false; } } foreach ($files as $file) { if (!$this->files->isReadable($file->getPathname())) { $this->log->error('Unreadable file preventing Composer install', ['file' => $file]); $filesReadable = false; } } if (!$directoriesReadable || !$filesReadable) { $this->log->critical('Unreadable files/directories, cannot proceed with install.'); throw new InvalidInstallationDirectoryException(null, "The installation directory ({$directory}) is not empty and could not be cleared due to a permissions issue. Please manually remove all files from the directory and try again."); } if (!$this->files->isWritable($directory)) { $this->log->critical('Installation directory is not writeable by NewUp. Cannot proceed with install.', ['directory' => $directory, 'permissions' => fileperms($directory)]); throw new InvalidInstallationDirectoryException(null, "The installation directory ({$directory}) is not writeable by the NewUp process."); } // At this point, there is no clear reason why the preparation // did not succeed. Because of this, we will try again. $this->installationAttempts++; $this->log->debug('Installation attempt incremented', ['directory' => $directory, 'attempt' => $this->installationAttempts]); $this->prepareInstallationDirectory($directory); }