mam-dev / cosmo

Cosmo Calendar Server implements the server side of the CalDAV protocol.
Apache License 2.0
77 stars 45 forks source link

Calendar sharing setup #40

Closed abrausch closed 3 years ago

abrausch commented 4 years ago

Hi, I have one question regarding the calendar sharing functionality. I already figured out that I should use the subscription stuff to share calendars. My question now is how to create such subscriptions. I did a basic setup on my machine with a "modified" demo application. So I switched the backend to a persistent mysql database. I still use the demo authentification stuff because I am still in evaluation phase for a project. Can you perhaps give me a hint how to create a subscription so userB can access the calendar of userA. If this is already possible with the cosmo-api

Best regards Alex

danielgrigore commented 4 years ago

Hi @abrausch Here's some sample code in which I try to explain the flow.

// First the sharer's part User sharer = ...; // Owner of the collection to be shared CollectionItem collection = ...; // Collection to be shared (or target collection)

// Then create the ticket that will allow access to the shared collection
Ticket ticket = new HibTicket(TicketType READ_ONLY); ticket.setKey(UuidSubscriptionGenerator.get().getNext()); ticket.setOwner(sharer); ticket.setTimeout(Ticket.TIMEOUT_INFINITE); ticket.setItem(collection); this.contentService.createTicket(collection, ticket);

// Next create the subscription object that will link the sharer's collection with sharee's collection.

User sharee = ...;

HibCollectionSubscription subscription = new HibCollectionSubscription(); subscription.setTargetCollection(collection); subscription.setTicket(ticket); subscripion.setOwner(sharee); this.subscriptionDao.addOrUpdate(subscription);

// Step 2. This could happen when an email is sent to the sharee and sharee clicks on the Accept button or the application could do this automatically. // Create the sharee's collection that will point to the sharer's collection. This is called the proxy collection. HibCollectionSubscriptionItem calendarItem = new HibCollectionSubscriptionItem(); calendarItem.setName(UuidSubscriptionGenerator.get().getNext()); calendarItem.setUid(UuidSubscriptionGenerator.get().getNext()); // Copy the name from target collection. calendarItem.setDisplayName(subscription.getTargetCollection().getDisplayName()); calendarItem.setOwner(sharee);

// Create the double link between subscription and sharee's collection calendarItem.setSubscription(subscription); subscription.setProxyCollection(calendarItem); this.subscriptionDao.addOrUpdate(subscription);

Cheers,

abrausch commented 4 years ago

Hi Thanks a lot. I created some entries directly inside my database but faced another problem. I try to explain my current workflow (and problem)

Is that perhaps because of the missing proxy collection?

Cheers Alex

danielgrigore commented 4 years ago

Hi @abrausch

Most probably you did not create the proxy collection for the sharee. The sharee will be able to access the shared collection only through the proxy collection (and this is the reason for which the ticket is created). The sharee should not try to access directly the shared collection. That won't work.

Cheers,

slincem commented 3 years ago

Hi @danielgrigore, in my team we've been working on some features for Cosmo.

Right now we are working on the sharing calendar with a specific user feature and we wonder why if you have the code for getting it done (The one you posted in the previous answer), this feature is not implemented yet?. We've seen that some classes related to susbscriptions like "CollectionSubscriptionDaoImpl" are not being used.

We are planning to add the subscription stuff in the "mkticket" service, receiving the user to be granted with the ticket in a header in this request in order to get this done. However, we want to make sure if this is correct or if you know which is the correct way to expose the service for sharing a calendar with a specific user.

danielgrigore commented 3 years ago

Hi @slincem

The reason for which you do not see that class used in cosmo is because some steps of the share process are application specific.

The sharing was thought as a two steps process:

The shared collection should not be automatically added to the sharee's list without his/her consent because it might create confusion to the sharee, not to mention that it may impact privacy rights.

Usually when the sharer decides to share a collection with someone then an email is sent to the sharee (or some other ways of notification might be used like SMS etc.). The email should contain information about the sharer, the collection and and a link containing the ticket value for accessing the shared collection.

Sharee should click on that link for the share request to be accepted. The servlet/controller that process the request will receive the ticket value and it will use the CollectionSubscriptionDao to identify the subscription and add the collection in sharee's list.

Because the communication by email, SMS etc. is application specific these steps were left outside cosmo and each application that extends cosmo should add its own implementation but most probably every implementation will need the methods in the class CollectionSubscriptionDao.

Cheers,