On login we create a default calendar and a default addressbook for the user - fixes #22360

This commit is contained in:
Thomas Müller 2016-02-15 12:39:36 +01:00
parent 46b39c3465
commit 722809c2bd
2 changed files with 44 additions and 2 deletions

View File

@ -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')
);
});

View File

@ -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);
}
}
}
}