Use abstract subclass so members can be defined
Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
parent
762002ec2e
commit
348171f311
5 changed files with 63 additions and 54 deletions
|
@ -7,10 +7,10 @@ $baseDir = $vendorDir;
|
|||
|
||||
return array(
|
||||
'OCA\\Provisioning_API\\AppInfo\\Application' => $baseDir . '/../lib/AppInfo/Application.php',
|
||||
'OCA\\Provisioning_API\\Controller\\AUserData' => $baseDir . '/../lib/Controller/AUserData.php',
|
||||
'OCA\\Provisioning_API\\Controller\\AppConfigController' => $baseDir . '/../lib/Controller/AppConfigController.php',
|
||||
'OCA\\Provisioning_API\\Controller\\AppsController' => $baseDir . '/../lib/Controller/AppsController.php',
|
||||
'OCA\\Provisioning_API\\Controller\\GroupsController' => $baseDir . '/../lib/Controller/GroupsController.php',
|
||||
'OCA\\Provisioning_API\\Controller\\UserDataTrait' => $baseDir . '/../lib/Controller/UserDataTrait.php',
|
||||
'OCA\\Provisioning_API\\Controller\\UsersController' => $baseDir . '/../lib/Controller/UsersController.php',
|
||||
'OCA\\Provisioning_API\\FederatedFileSharingFactory' => $baseDir . '/../lib/FederatedFileSharingFactory.php',
|
||||
'OCA\\Provisioning_API\\Middleware\\Exceptions\\NotSubAdminException' => $baseDir . '/../lib/Middleware/Exceptions/NotSubAdminException.php',
|
||||
|
|
|
@ -22,10 +22,10 @@ class ComposerStaticInitProvisioning_API
|
|||
|
||||
public static $classMap = array (
|
||||
'OCA\\Provisioning_API\\AppInfo\\Application' => __DIR__ . '/..' . '/../lib/AppInfo/Application.php',
|
||||
'OCA\\Provisioning_API\\Controller\\AUserData' => __DIR__ . '/..' . '/../lib/Controller/AUserData.php',
|
||||
'OCA\\Provisioning_API\\Controller\\AppConfigController' => __DIR__ . '/..' . '/../lib/Controller/AppConfigController.php',
|
||||
'OCA\\Provisioning_API\\Controller\\AppsController' => __DIR__ . '/..' . '/../lib/Controller/AppsController.php',
|
||||
'OCA\\Provisioning_API\\Controller\\GroupsController' => __DIR__ . '/..' . '/../lib/Controller/GroupsController.php',
|
||||
'OCA\\Provisioning_API\\Controller\\UserDataTrait' => __DIR__ . '/..' . '/../lib/Controller/UserDataTrait.php',
|
||||
'OCA\\Provisioning_API\\Controller\\UsersController' => __DIR__ . '/..' . '/../lib/Controller/UsersController.php',
|
||||
'OCA\\Provisioning_API\\FederatedFileSharingFactory' => __DIR__ . '/..' . '/../lib/FederatedFileSharingFactory.php',
|
||||
'OCA\\Provisioning_API\\Middleware\\Exceptions\\NotSubAdminException' => __DIR__ . '/..' . '/../lib/Middleware/Exceptions/NotSubAdminException.php',
|
||||
|
|
|
@ -22,14 +22,54 @@ declare(strict_types=1);
|
|||
namespace OCA\Provisioning_API\Controller;
|
||||
|
||||
use OC\Accounts\AccountManager;
|
||||
use OCP\AppFramework\Http\DataResponse;
|
||||
use OCP\AppFramework\OCS\OCSException;
|
||||
use OCP\AppFramework\OCS\OCSNotFoundException;
|
||||
use OCP\AppFramework\OCS\OCSForbiddenException;
|
||||
use OCP\AppFramework\OCSController;
|
||||
use OCP\Files\NotFoundException;
|
||||
use OC_Helper;
|
||||
use OCP\IConfig;
|
||||
use OCP\IGroupManager;
|
||||
use OCP\IRequest;
|
||||
use OCP\IUserManager;
|
||||
use OCP\IUserSession;
|
||||
|
||||
trait UserDataTrait {
|
||||
abstract class AUserData extends OCSController {
|
||||
|
||||
/** @var IUserManager */
|
||||
protected $userManager;
|
||||
/** @var IConfig */
|
||||
protected $config;
|
||||
/** @var IGroupManager|\OC\Group\Manager */ // FIXME Requires a method that is not on the interface
|
||||
protected $groupManager;
|
||||
/** @var IUserSession */
|
||||
protected $userSession;
|
||||
/** @var AccountManager */
|
||||
protected $accountManager;
|
||||
|
||||
/**
|
||||
* @param string $appName
|
||||
* @param IRequest $request
|
||||
* @param IUserManager $userManager
|
||||
* @param IConfig $config
|
||||
* @param IGroupManager $groupManager
|
||||
* @param IUserSession $userSession
|
||||
* @param AccountManager $accountManager
|
||||
*/
|
||||
public function __construct(string $appName,
|
||||
IRequest $request,
|
||||
IUserManager $userManager,
|
||||
IConfig $config,
|
||||
IGroupManager $groupManager,
|
||||
IUserSession $userSession,
|
||||
AccountManager $accountManager) {
|
||||
parent::__construct($appName, $request);
|
||||
|
||||
$this->userManager = $userManager;
|
||||
$this->config = $config;
|
||||
$this->groupManager = $groupManager;
|
||||
$this->userSession = $userSession;
|
||||
$this->accountManager = $accountManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* creates a array with all user data
|
||||
|
@ -38,7 +78,7 @@ trait UserDataTrait {
|
|||
* @return array
|
||||
* @throws OCSException
|
||||
*/
|
||||
public function getUserData(string $userId): array {
|
||||
protected function getUserData(string $userId): array {
|
||||
$currentLoggedInUser = $this->userSession->getUser();
|
||||
|
||||
$data = [];
|
|
@ -33,7 +33,6 @@ use OCP\AppFramework\Http\DataResponse;
|
|||
use OCP\AppFramework\OCS\OCSException;
|
||||
use OCP\AppFramework\OCS\OCSNotFoundException;
|
||||
use OCP\AppFramework\OCS\OCSForbiddenException;
|
||||
use OCP\AppFramework\OCSController;
|
||||
use OCP\IConfig;
|
||||
use OCP\IGroup;
|
||||
use OCP\IGroupManager;
|
||||
|
@ -43,24 +42,7 @@ use OCP\IUserManager;
|
|||
use OCP\IUserSession;
|
||||
use OCP\IUser;
|
||||
|
||||
class GroupsController extends OCSController {
|
||||
|
||||
use UserDataTrait;
|
||||
|
||||
/** @var IUserManager */
|
||||
private $userManager;
|
||||
|
||||
/** @var IGroupManager */
|
||||
private $groupManager;
|
||||
|
||||
/** @var IUserSession */
|
||||
private $userSession;
|
||||
|
||||
/** @var IConfig */
|
||||
private $config;
|
||||
|
||||
/** @var AccountManager */
|
||||
private $accountManager;
|
||||
class GroupsController extends AUserData {
|
||||
|
||||
/** @var ILogger */
|
||||
private $logger;
|
||||
|
@ -84,13 +66,14 @@ class GroupsController extends OCSController {
|
|||
IUserSession $userSession,
|
||||
AccountManager $accountManager,
|
||||
ILogger $logger) {
|
||||
parent::__construct($appName, $request);
|
||||
parent::__construct($appName,
|
||||
$request,
|
||||
$userManager,
|
||||
$config,
|
||||
$groupManager,
|
||||
$userSession,
|
||||
$accountManager);
|
||||
|
||||
$this->groupManager = $groupManager;
|
||||
$this->userManager = $userManager;
|
||||
$this->config = $config;
|
||||
$this->userSession = $userSession;
|
||||
$this->accountManager = $accountManager;
|
||||
$this->logger = $logger;
|
||||
}
|
||||
|
||||
|
|
|
@ -35,14 +35,11 @@ namespace OCA\Provisioning_API\Controller;
|
|||
use OC\Accounts\AccountManager;
|
||||
use OC\HintException;
|
||||
use OC\Settings\Mailer\NewUserMailHelper;
|
||||
use OC_Helper;
|
||||
use OCA\Provisioning_API\FederatedFileSharingFactory;
|
||||
use OCP\App\IAppManager;
|
||||
use OCP\AppFramework\Http\DataResponse;
|
||||
use OCP\AppFramework\OCS\OCSException;
|
||||
use OCP\AppFramework\OCS\OCSForbiddenException;
|
||||
use OCP\AppFramework\OCSController;
|
||||
use OCP\Files\NotFoundException;
|
||||
use OCP\IConfig;
|
||||
use OCP\IGroup;
|
||||
use OCP\IGroupManager;
|
||||
|
@ -53,22 +50,10 @@ use OCP\IUserSession;
|
|||
use OCP\L10N\IFactory;
|
||||
use OCP\Security\ISecureRandom;
|
||||
|
||||
class UsersController extends OCSController {
|
||||
class UsersController extends AUserData {
|
||||
|
||||
use UserDataTrait;
|
||||
|
||||
/** @var IUserManager */
|
||||
private $userManager;
|
||||
/** @var IConfig */
|
||||
private $config;
|
||||
/** @var IAppManager */
|
||||
private $appManager;
|
||||
/** @var IGroupManager|\OC\Group\Manager */ // FIXME Requires a method that is not on the interface
|
||||
private $groupManager;
|
||||
/** @var IUserSession */
|
||||
private $userSession;
|
||||
/** @var AccountManager */
|
||||
private $accountManager;
|
||||
/** @var ILogger */
|
||||
private $logger;
|
||||
/** @var IFactory */
|
||||
|
@ -108,14 +93,15 @@ class UsersController extends OCSController {
|
|||
NewUserMailHelper $newUserMailHelper,
|
||||
FederatedFileSharingFactory $federatedFileSharingFactory,
|
||||
ISecureRandom $secureRandom) {
|
||||
parent::__construct($appName, $request);
|
||||
parent::__construct($appName,
|
||||
$request,
|
||||
$userManager,
|
||||
$config,
|
||||
$groupManager,
|
||||
$userSession,
|
||||
$accountManager);
|
||||
|
||||
$this->userManager = $userManager;
|
||||
$this->config = $config;
|
||||
$this->appManager = $appManager;
|
||||
$this->groupManager = $groupManager;
|
||||
$this->userSession = $userSession;
|
||||
$this->accountManager = $accountManager;
|
||||
$this->logger = $logger;
|
||||
$this->l10nFactory = $l10nFactory;
|
||||
$this->newUserMailHelper = $newUserMailHelper;
|
||||
|
|
Loading…
Reference in a new issue