On login we create a default calendar and a default addressbook for the user - fixes #22360
This commit is contained in:
parent
46b39c3465
commit
722809c2bd
|
@ -57,7 +57,9 @@ class Application extends App {
|
|||
/** @var IAppContainer $c */
|
||||
return new HookManager(
|
||||
$c->getServer()->getUserManager(),
|
||||
$c->query('SyncService')
|
||||
$c->query('SyncService'),
|
||||
$c->query('CalDavBackend'),
|
||||
$c->query('CardDavBackend')
|
||||
);
|
||||
});
|
||||
|
||||
|
|
|
@ -20,6 +20,8 @@
|
|||
*/
|
||||
namespace OCA\DAV;
|
||||
|
||||
use OCA\DAV\CalDAV\CalDavBackend;
|
||||
use OCA\DAV\CardDAV\CardDavBackend;
|
||||
use OCA\DAV\CardDAV\SyncService;
|
||||
use OCP\IUser;
|
||||
use OCP\IUserManager;
|
||||
|
@ -36,9 +38,20 @@ class HookManager {
|
|||
/** @var IUser[] */
|
||||
private $usersToDelete;
|
||||
|
||||
public function __construct(IUserManager $userManager, SyncService $syncService) {
|
||||
/** @var CalDavBackend */
|
||||
private $calDav;
|
||||
|
||||
/** @var CardDavBackend */
|
||||
private $cardDav;
|
||||
|
||||
public function __construct(IUserManager $userManager,
|
||||
SyncService $syncService,
|
||||
CalDavBackend $calDav,
|
||||
CardDavBackend $cardDav) {
|
||||
$this->userManager = $userManager;
|
||||
$this->syncService = $syncService;
|
||||
$this->calDav = $calDav;
|
||||
$this->cardDav = $cardDav;
|
||||
}
|
||||
|
||||
public function setup() {
|
||||
|
@ -58,6 +71,10 @@ class HookManager {
|
|||
'changeUser',
|
||||
$this,
|
||||
'changeUser');
|
||||
Util::connectHook('OC_User',
|
||||
'post_login',
|
||||
$this,
|
||||
'postLogin');
|
||||
}
|
||||
|
||||
public function postCreateUser($params) {
|
||||
|
@ -80,4 +97,27 @@ class HookManager {
|
|||
$user = $params['user'];
|
||||
$this->syncService->updateUser($user);
|
||||
}
|
||||
|
||||
public function postLogin($params) {
|
||||
$user = $this->userManager->get($params['uid']);
|
||||
|
||||
$principal = 'principals/users/' . $user->getUID();
|
||||
$calendars = $this->calDav->getCalendarsForUser($principal);
|
||||
if (empty($calendars)) {
|
||||
try {
|
||||
$this->calDav->createCalendar($principal, 'default', []);
|
||||
} catch (\Exception $ex) {
|
||||
\OC::$server->getLogger()->logException($ex);
|
||||
}
|
||||
}
|
||||
$books = $this->cardDav->getAddressBooksForUser($principal);
|
||||
if (empty($books)) {
|
||||
try {
|
||||
$this->cardDav->createAddressBook($principal, 'default', []);
|
||||
} catch (\Exception $ex) {
|
||||
\OC::$server->getLogger()->logException($ex);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue