Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support CalDAV for birthdays and tasks #2304

Merged
merged 49 commits into from
Jan 23, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
80f4a36
Support CalDAV to export the collection of birthdays
asbiin Jan 14, 2019
79c9623
Apply fixes from StyleCI
asbiin Jan 14, 2019
230f18e
update
asbiin Jan 16, 2019
6bfa94a
Merge branch 'feat/caldav-2019-01-14' of github.com:monicahq/monica i…
asbiin Jan 16, 2019
66d18a1
Apply fixes from StyleCI
asbiin Jan 16, 2019
b6f5bd7
chore(assets): Update assets
MonicaBot Jan 16, 2019
4deb7b7
Update url of DAVs protocols
asbiin Jan 17, 2019
ef3d54e
Apply fixes from StyleCI
asbiin Jan 17, 2019
8712637
use special dates
asbiin Jan 18, 2019
36ba5d0
Apply fixes from StyleCI
asbiin Jan 19, 2019
fe1189e
Merge remote-tracking branch 'origin/master' into feat/caldav-2019-01-14
asbiin Jan 19, 2019
086ee33
some factorisation
asbiin Jan 19, 2019
c725a17
Apply fixes from StyleCI
asbiin Jan 19, 2019
5943401
add tasks calendar
asbiin Jan 19, 2019
6c199aa
Apply fixes from StyleCI
asbiin Jan 19, 2019
fa62f6c
update
asbiin Jan 19, 2019
0169b6f
Merge branch 'feat/caldav-2019-01-14' of github.com:monicahq/monica i…
asbiin Jan 19, 2019
f2f645d
Apply fixes from StyleCI
asbiin Jan 19, 2019
1f385c2
update
asbiin Jan 19, 2019
887cf76
Merge branch 'feat/caldav-2019-01-14' of github.com:monicahq/monica i…
asbiin Jan 19, 2019
b3770f6
Apply fixes from StyleCI
asbiin Jan 19, 2019
a2b8146
update synctoken usage
asbiin Jan 20, 2019
657a804
Apply fixes from StyleCI
asbiin Jan 20, 2019
6a3cad2
update
asbiin Jan 20, 2019
82465d3
Apply fixes from StyleCI
asbiin Jan 20, 2019
9c28e3e
fix psalm
asbiin Jan 20, 2019
f99b245
Apply fixes from StyleCI
asbiin Jan 20, 2019
100948f
Fix sonar
asbiin Jan 20, 2019
71a73c9
Apply fixes from StyleCI
asbiin Jan 20, 2019
596be97
fix styleci
asbiin Jan 20, 2019
faf5464
simplify some code
asbiin Jan 20, 2019
70a9423
Apply fixes from StyleCI
asbiin Jan 20, 2019
3473bbf
Add AbstractCalDAVBackend
asbiin Jan 20, 2019
00c7631
Apply fixes from StyleCI
asbiin Jan 20, 2019
bb12571
write a lot of tests
asbiin Jan 21, 2019
82d430d
Apply fixes from StyleCI
asbiin Jan 21, 2019
a2315b9
Fix getEtag
asbiin Jan 21, 2019
adeaaf1
Merge remote-tracking branch 'origin/master' into feat/caldav-2019-01-14
asbiin Jan 21, 2019
9a5fd8d
update open file limits
asbiin Jan 21, 2019
a3388f9
Merge remote-tracking branch 'origin/master' into feat/caldav-2019-01-14
asbiin Jan 22, 2019
7b354f8
Cache route
asbiin Jan 22, 2019
100d8cf
Really cache route
asbiin Jan 22, 2019
2223d61
Enable DAV on tests
asbiin Jan 22, 2019
032b538
with the right test it's better
asbiin Jan 22, 2019
8b2cbb0
remove route cache from dusk tests
asbiin Jan 22, 2019
eefa00a
Merge remote-tracking branch 'origin/master' into feat/caldav-2019-01-14
asbiin Jan 23, 2019
025b465
Move classes
asbiin Jan 23, 2019
8beb835
Apply fixes from StyleCI
asbiin Jan 23, 2019
71d2da7
fix SESSION_DRIVER
asbiin Jan 23, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update url of DAVs protocols
  • Loading branch information
asbiin committed Jan 17, 2019
commit 4deb7b7a5305cbdc84ea11a4bcd4e426b4562ef9
4 changes: 2 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ AWS_SERVER=
# Allow Two Factor Authentication feature on your instance
MFA_ENABLED=false

# Enable CardDAV support (beta feature)
CARDDAV_ENABLED=false
# Enable DAV support (beta feature)
DAV_ENABLED=false

# CLIENT ID and SECRET used for the official mobile application
# This is to make sure that only the mobile application that you approve can
Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ UNRELEASED CHANGES:

New features:

* Support CalDAV to export the collection of birthdays
* Support CalDAV to export the collection of birthdays (breaking change: url of CardDAV is '/dav' now)
* Add ability to name u2f security keys and to delete register ones
* Add ability to add a comment when rating your day in the journal
* Add API methods to manage genders
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace App\Http\Controllers\CardDAV;
namespace App\Http\Controllers\DAV;

use Illuminate\Http\Request;
use Sabre\CalDAV\CalendarRoot;
Expand All @@ -15,17 +15,15 @@
use Sabre\DAV\Sync\Plugin as SyncPlugin;
use Barryvdh\Debugbar\Facade as Debugbar;
use Sabre\CardDAV\Plugin as CardDAVPlugin;
use App\Models\CardDAV\MonicaAddressBookRoot;
use Sabre\DAV\Browser\Plugin as BrowserPlugin;
use App\Models\CardDAV\Backends\MonicaAuthBackend;
use App\Models\CardDAV\Backends\MonicaCalDAVBackend;
use App\Models\CardDAV\Backends\MonicaCardDAVBackend;
use App\Models\CardDAV\Backends\MonicaPrincipalBackend;
use App\Models\DAV\AddressBookRoot;
use App\Models\DAV\Backends\AuthBackend;
use App\Models\DAV\Backends\CalDAVBackend;
use App\Models\DAV\Backends\CardDAVBackend;
use App\Models\DAV\Backends\PrincipalBackend;

class CardDAVController extends Controller
class DAVController extends Controller
{
private const BASE_URI = '/carddav/';

/**
* Display the specified resource.
*/
Expand All @@ -46,13 +44,13 @@ public function init(Request $request)
private function getNodes() : array
{
// Initiate custom backends for link between Sabre and Monica
$principalBackend = new MonicaPrincipalBackend(); // User rights
$carddavBackend = new MonicaCardDAVBackend(); // Contacts
$caldavBackend = new MonicaCalDAVBackend(); // Calendar
$principalBackend = new PrincipalBackend(); // User rights
$carddavBackend = new CardDAVBackend(); // Contacts
$caldavBackend = new CalDAVBackend(); // Calendar

return [
new PrincipalCollection($principalBackend),
new MonicaAddressBookRoot($principalBackend, $carddavBackend),
new AddressBookRoot($principalBackend, $carddavBackend),
new CalendarRoot($principalBackend, $caldavBackend),
];
}
Expand All @@ -66,7 +64,7 @@ private function getServer(Request $request)
$server->sapi = new SapiServerMock();

// Base Uri of carddav
$server->setBaseUri(self::BASE_URI);
$server->setBaseUri($this->getBaseUri());
// Set Url with trailing slash
$server->httpRequest->setUrl($this->fullUrl($request));

Expand Down Expand Up @@ -103,7 +101,7 @@ public function fullUrl(Request $request)
private function addPlugins(SabreServer $server)
{
// Authentication backend
$authBackend = new MonicaAuthBackend();
$authBackend = new AuthBackend();
$server->addPlugin(new AuthPlugin($authBackend, 'SabreDAV'));

// CardDAV plugin
Expand Down Expand Up @@ -143,4 +141,9 @@ private function server(SabreServer $server)
return response($content, $status)
->withHeaders($headers);
}

private function getBaseUri()
{
return str_start(str_finish(config('dav.path'), '/'), '/');
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace App\Http\Controllers\CardDAV;
namespace App\Http\Controllers\DAV;

use Sabre\HTTP\Sapi;
use Sabre\HTTP\ResponseInterface;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php

namespace App\Models\CardDAV;
namespace App\Models\DAV;

use Sabre\CardDAV\AddressBook;
use App\Models\CardDAV\Backends\MonicaCardDAVBackend;
use Sabre\CardDAV\AddressBook as BaseAddressBook;
use App\Models\DAV\Backends\CardDAVBackend;

class MonicaAddressBook extends AddressBook
class AddressBook extends BaseAddressBook
{
/**
* Returns a list of ACE's for this node.
Expand Down Expand Up @@ -64,7 +64,7 @@ public function getChildACL()
*/
public function getLastModified()
{
if ($this->carddavBackend instanceof MonicaCardDAVBackend) {
if ($this->carddavBackend instanceof CardDAVBackend) {
return $this->carddavBackend->getLastModified();
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php

namespace App\Models\CardDAV;
namespace App\Models\DAV;

use Sabre\CardDAV\AddressBookHome;
use Sabre\CardDAV\AddressBookHome as BaseAddressBookHome;

class MonicaAddressBookHome extends AddressBookHome
class AddressBookHome extends BaseAddressBookHome
{
/**
* Returns a list of ACE's for this node.
Expand Down Expand Up @@ -39,7 +39,7 @@ public function getChildren()
$addressbooks = $this->carddavBackend->getAddressBooksForUser($this->principalUri);

return collect($addressbooks)->map(function ($addressbook) {
return new MonicaAddressBook($this->carddavBackend, $addressbook);
return new AddressBook($this->carddavBackend, $addressbook);
});
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php

namespace App\Models\CardDAV;
namespace App\Models\DAV;

use Sabre\DAVACL\IACL;
use Sabre\DAVACL\ACLTrait;
use Sabre\CardDAV\AddressBookRoot;
use Sabre\CardDAV\AddressBookRoot as BaseAddressBookRoot;

class MonicaAddressBookRoot extends AddressBookRoot implements IACL
class AddressBookRoot extends BaseAddressBookRoot implements IACL
{
use ACLTrait;

Expand Down Expand Up @@ -45,6 +45,6 @@ public function getACL()
*/
public function getChildForPrincipal(array $principal)
{
return new MonicaAddressBookHome($this->carddavBackend, $principal['uri']);
return new AddressBookHome($this->carddavBackend, $principal['uri']);
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php

namespace App\Models\CardDAV\Backends;
namespace App\Models\DAV\Backends;

use Sabre\HTTP\RequestInterface;
use Sabre\HTTP\ResponseInterface;
use Illuminate\Support\Facades\Auth;
use Sabre\DAV\Auth\Backend\BackendInterface;

class MonicaAuthBackend implements BackendInterface
class AuthBackend implements BackendInterface
{
/**
* Authentication Realm.
Expand Down Expand Up @@ -43,7 +43,7 @@ public function check(RequestInterface $request, ResponseInterface $response)
return [false, 'User is not authenticated'];
}

return [true, MonicaPrincipalBackend::getPrincipalUser()];
return [true, PrincipalBackend::getPrincipalUser()];
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace App\Models\CardDAV\Backends;
namespace App\Models\DAV\Backends;

use Sabre\DAV;
use App\Models\Contact\Contact;
Expand All @@ -10,7 +10,7 @@
use Sabre\CalDAV\Backend\AbstractBackend;
use App\Services\VCalendar\ExportVCalendar;

class MonicaCalDAVBackend extends AbstractBackend
class CalDAVBackend extends AbstractBackend
{
/**
* Extension for Calendar objects.
Expand Down Expand Up @@ -52,7 +52,7 @@ public function getCalendarsForUser($principalUri)
[
'id' => '0',
'uri' => 'calendar',
'principaluri' => MonicaPrincipalBackend::getPrincipalUser(),
'principaluri' => PrincipalBackend::getPrincipalUser(),
'{DAV:}displayname' => $name,
'{'.SabreServer::NS_SABREDAV.'}read-only' => 1,
'{urn:ietf:params:xml:ns:caldav}calendar-description' => 'Birthdays',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace App\Models\CardDAV\Backends;
namespace App\Models\DAV\Backends;

use Sabre\DAV;
use App\Models\User\SyncToken;
Expand All @@ -15,7 +15,7 @@
use Sabre\CardDAV\Backend\AbstractBackend;
use Sabre\CardDAV\Plugin as CardDAVPlugin;

class MonicaCardDAVBackend extends AbstractBackend implements SyncSupport
class CardDAVBackend extends AbstractBackend implements SyncSupport
{
/**
* Extension for Card objects.
Expand Down Expand Up @@ -50,7 +50,7 @@ public function getAddressBooksForUser($principalUri)
[
'id' => '0',
'uri' => 'contacts',
'principaluri' => MonicaPrincipalBackend::getPrincipalUser(),
'principaluri' => PrincipalBackend::getPrincipalUser(),
'{DAV:}sync-token' => $token->id,
'{DAV:}displayname' => $name,
'{'.SabreServer::NS_SABREDAV.'}sync-token' => $token->id,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php

namespace App\Models\CardDAV\Backends;
namespace App\Models\DAV\Backends;

use Sabre\DAV;
use Illuminate\Support\Facades\Auth;
use Sabre\DAV\Server as SabreServer;
use Sabre\DAVACL\PrincipalBackend\AbstractBackend;

class MonicaPrincipalBackend extends AbstractBackend
class PrincipalBackend extends AbstractBackend
{
/**
* This is the prefix that will be used to generate principal urls.
Expand Down
12 changes: 6 additions & 6 deletions app/Providers/RouteServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ public function map(Router $router)

$this->mapOAuthRoutes($router);

if (config('carddav.enabled')) {
$this->mapCardDAVRoutes($router);
if (config('dav.enabled')) {
$this->mapDAVRoutes($router);
}

$this->mapSpecialRoutes($router);
Expand Down Expand Up @@ -134,20 +134,20 @@ protected function mapApiRoutes(Router $router)
}

/**
* Define the "carddav" routes for the application.
* Define the DAV routes for the application.
*
* These routes are typically stateless.
*
* @return void
*/
protected function mapCardDAVRoutes(Router $router)
protected function mapDAVRoutes(Router $router)
{
$router->group([
'prefix' => 'carddav',
'prefix' => config('dav.path'),
'middleware' => 'api',
'namespace' => $this->namespace,
], function () {
require base_path('routes/carddav.php');
require base_path('routes/dav.php');
});
}

Expand Down
11 changes: 0 additions & 11 deletions config/carddav.php

This file was deleted.

25 changes: 25 additions & 0 deletions config/dav.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

return [

/*
|--------------------------------------------------------------------------
| Enable DAV feature
|--------------------------------------------------------------------------
|
| Enable or disable DAV completely.
|
*/
'enabled' => (bool) env('DAV_ENABLED', (bool) env('CARDDAV_ENABLED', false)),

/*
|--------------------------------------------------------------------------
| DAV Path
|--------------------------------------------------------------------------
|
| Path for all DAV requests.
|
*/
'path' => 'dav',

];
6 changes: 5 additions & 1 deletion nginx_app.conf
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ location / {

location @rewriteapp {
# Redirect .well-known urls (https://en.wikipedia.org/wiki/List_of_/.well-known/_services_offered_by_webservers)
rewrite .well-known/carddav /carddav/ permanent;
rewrite .well-known/carddav /dav/ permanent;
rewrite .well-known/caldav /dav/ permanent;
rewrite .well-known/security.txt$ /security.txt permanent;

# Old carddav url
rewrite carddav/(.*) /dav/$1 permanent;

# rewrite all to app.php
rewrite ^(.*)$ /index.php/$1 last;
}
Expand Down
8 changes: 6 additions & 2 deletions public/.htaccess
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,17 @@

# Redirect .well-known urls (https://en.wikipedia.org/wiki/List_of_/.well-known/_services_offered_by_webservers)
RewriteCond %{REQUEST_URI} .well-known/carddav
RewriteRule ^ /carddav/ [L,R=301]
RewriteCond %{REQUEST_URI} .well-known/caldav
RewriteRule ^ /dav/ [L,R=301]
RewriteCond %{REQUEST_URI} .well-known/security.txt
RewriteRule ^ /security.txt [L,R=301]
# old carddav url
RewriteCond %{REQUEST_URI} /carddav/(.+)
RewriteRule ^ /dav/%1 [L,R=301]

# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !carddav/*
RewriteCond %{REQUEST_FILENAME} !dav/*
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]

Expand Down
2 changes: 1 addition & 1 deletion routes/carddav.php → routes/dav.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@
Illuminate\Routing\Router::$verbs = $verbs;

Route::group(['middleware' => ['auth.tokenonbasic', 'limitations']], function () use ($verbs) {
Route::match($verbs, '{path?}', 'CardDAV\\CardDAVController@init')->where('path', '(.)*');
Route::match($verbs, '{path?}', 'DAV\\DAVController@init')->where('path', '(.)*');
});
Loading