Search | Sailfish OS | Running | PineTime | All Posts

Sharing calendars with Baikal

April 21, 2023 — Nico Cartron

A short how-to more for me, but could be useful to others


Basic, right?

Sharing a calendar through a CalDAV server should be easy, and achievable straight from either the server side, or the client side, right?

Well, turns out that's not the case: Baikal does indeed support calendar sharing, but this is a rather manual (and a bit painful) process.

Baikal Config

Enabling in the configuration

You need to enable it in the configuration.
On my FreeBSD installation, the file is located in Core/Frameworks/Baikal/Core/.

You need to edit Server.php and add a specific instruction:

$server->addPlugin(new Sabre\\DAV\\Sharing\\Plugin());

Allowing CalDAV clients to manipulate who has access to a share

This is needed for "less compatible" clients, such as MacOS X Calendar and BusyCal.
This time, you need to add:

$server->addPlugin(new Sabre\CalDAV\SharingPlugin());

Prerequisites and principles

This is where things get a bit more messy interesting :)

Actually giving share permissions to another user cannot be done through the Admin web UI, nor the Baikal config; you have to manually add entries in the database.

You need to:

  1. have created 2 users, and each user must have at least one calendar,
  2. add an entry in the principals table to specify read-only or read-write permissions,
  3. add an entry in the groupmembers table to specify which user can access which principal/calendars.

Manipulating the database

1. Getting the principal_id of the users

You need to get the principal_id of the 2 users (the one sharing and the one you're sharing with) - this is done from the groupmembers table:

> select id, uri, displayname from principals;
+----+-----------------------------+-------------+
| id | uri                         | displayname +
+----+-----------------------------+-------------+
|  1 | principals/nc               | Nico        +
|  2 | principals/test             | Test        +
+----+-----------------------------+-------------+

OK, my user is "Nico" (so id 1) and I want to get access to "Test" (id 2).

2. Create entries for read-only or read-write

You then need to create an entry in the same principals table, with read-write access:

> insert into principals (uri,email,displayname) values ('principals/test/calendar-proxy-write',null,null);

If you wanted to only give read-only access, you'd use instead:

> insert into principals (uri,email,displayname) values ('principals/test/calendar-proxy-read',null,null);

A select request will now show:

> select id, uri, displayname from principals;
+----+--------------------------------------+-------------+
| id | uri                                  | displayname +
+----+--------------------------------------+-------------+
|  1 | principals/nc                        | Nico        +
|  2 | principals/test                      | Test        +
|  3 | principals/test/calendar-proxy-read  | NULL        +
|  4 | principals/test/calendar-proxy-write | NULL        +
+----+--------------------------------------+-------------+

=> Write down the ID that you want to use (in the above example, 3 for read and 4 for read-write).
=> Do not use the "normal" ID (2 in my case) as it's useless.

3. Giving access

You'll update the groupmembers table with respectively the target principal_id and the principal_id who will get access.

In the above example, I want id 1 to have access to id 4 (since I want read-write access):

> insert into groupmembers (principal_id,member_id) values (4,1);

which I can confirm has been updated with:

> select * from groupmembers; 
+----+--------------+-----------+ 
| id | principal_id | member_id |
+----+--------------+-----------+
|  1 |            4 |         1 |
+----+--------------+-----------+

Calendar configuration

You can now configure your CalDAV client, by using your regular username and password (the one from your account, not the account that shares with you) and you should see a new calendar appearing :)

e.g.:

https://<YOUR_SERVER>/cal.php/calendars/test/default

Wrap Up

I hope this article was useful; I wrote it because I struggled to do that when I started using Baikal a few years back, and the article I used to do it seems not to be online anymore.


Tags: IT, Misc


I don't have any commenting system, but email me (nicolas at ncartron dot org) your comments!
If you like my work, you can buy me a coffee!