Search in sources :

Example 1 with InviteType

use of org.bedework.caldav.util.sharing.InviteType in project bw-calendar-engine by Bedework.

the class Calendars method findAliases.

private void findAliases(final BwCalendar col, final AliasesInfo rootAi) throws CalFacadeException {
    final String collectionHref = col.getPath();
    final boolean defaultEnabled = !Boolean.valueOf(System.getProperty("org.bedework.nochangenote", "false")) && getAuthpars().getDefaultChangesNotifications();
    if (notificationsEnabled(col, defaultEnabled)) {
        rootAi.setNotificationsEnabled(true);
    }
    /* Handle aliases that are not a result of calendar sharing.  These could be public or private.
     */
    for (final BwCalendar alias : findAlias(collectionHref)) {
        final AliasesInfo ai = new AliasesInfo(getPrincipal().getPrincipalRef(), alias, null);
        rootAi.addSharee(ai);
        findAliases(alias, ai);
    }
    /* for each sharee in the list find user collection(s) pointing to this
     * collection and add the sharee if any are enabled for notifications.
     */
    final InviteType invite = getSvc().getSharingHandler().getInviteStatus(col);
    if (invite == null) {
        // No sharees
        return;
    }
    /* for sharees - it's the alias which points at this collection
     * which holds the status.
     */
    for (final UserType u : invite.getUsers()) {
        final BwPrincipal principal = caladdrToPrincipal(u.getHref());
        if (principal == null) {
            final AliasesInfo ai = new AliasesInfo(u.getHref(), col, null);
            ai.setExternalCua(true);
            rootAi.addSharee(ai);
            continue;
        }
        try {
            pushPrincipal(principal);
            for (final BwCalendar alias : findAlias(collectionHref)) {
                if (!notificationsEnabled(alias, defaultEnabled)) {
                    continue;
                }
                final AliasesInfo ai = new AliasesInfo(principal.getPrincipalRef(), alias, null);
                rootAi.addSharee(ai);
                findAliases(alias, ai);
            }
        } finally {
            popPrincipal();
        }
    }
}
Also used : AliasesInfo(org.bedework.calfacade.AliasesInfo) BwPrincipal(org.bedework.calfacade.BwPrincipal) InviteType(org.bedework.caldav.util.sharing.InviteType) BwCalendar(org.bedework.calfacade.BwCalendar) UserType(org.bedework.caldav.util.sharing.UserType)

Example 2 with InviteType

use of org.bedework.caldav.util.sharing.InviteType in project bw-calendar-engine by Bedework.

the class RestoreImpl method fixSharee.

@Override
public FixAliasResult fixSharee(final BwCalendar col, final String shareeHref, final AccessType a) throws CalFacadeException {
    /* First ensure this alias is not circular */
    final Set<String> paths = new TreeSet<>();
    BwCalendar curCol = col;
    while (curCol.getInternalAlias()) {
        if (paths.contains(curCol.getPath())) {
            return FixAliasResult.circular;
        }
        paths.add(curCol.getPath());
        try {
            curCol = getCols().resolveAliasIdx(curCol, false, false);
        } catch (final CalFacadeAccessException ignored) {
            // but we can still check for circularity and broken aliases.
            break;
        }
        if (curCol == null) {
            return FixAliasResult.broken;
        }
    }
    // See if we are in the invite list
    final InviteType invite = getSvc().getSharingHandler().getInviteStatus(col);
    final String shareeCua = getSvc().getDirectories().userToCaladdr(shareeHref);
    UserType uentry = invite.finduser(shareeCua);
    if (uentry != null) {
        // Already in list of sharers
        return FixAliasResult.ok;
    }
    /* Now fix the sharing invite info */
    uentry = new UserType();
    uentry.setHref(shareeCua);
    uentry.setInviteStatus(AppleServerTags.inviteAccepted);
    // uentry.setCommonName(...);
    uentry.setAccess(a);
    // uentry.setSummary(s.getSummary());
    invite.getUsers().add(uentry);
    try {
        col.setQproperty(AppleServerTags.invite, invite.toXml());
        getCols().update(col);
    } catch (final CalFacadeException cfe) {
        throw cfe;
    } catch (final Throwable t) {
        throw new CalFacadeException(t);
    }
    return FixAliasResult.reshared;
}
Also used : TreeSet(java.util.TreeSet) InviteType(org.bedework.caldav.util.sharing.InviteType) BwCalendar(org.bedework.calfacade.BwCalendar) CalFacadeAccessException(org.bedework.calfacade.exc.CalFacadeAccessException) UserType(org.bedework.caldav.util.sharing.UserType) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 3 with InviteType

use of org.bedework.caldav.util.sharing.InviteType in project bw-calendar-engine by Bedework.

the class Sharing method unsubscribe.

@Override
public void unsubscribe(final BwCalendar col) throws CalFacadeException {
    if (!col.getInternalAlias()) {
        return;
    }
    final BwCalendar shared = getCols().resolveAlias(col, true, false);
    if (shared == null) {
        // Gone or no access - nothing to do now.
        return;
    }
    final String sharerHref = shared.getOwnerHref();
    final BwPrincipal sharee = getSvc().getPrincipal();
    pushPrincipal(sharerHref);
    try {
        /* Get the invite property and locate and update this sharee */
        final InviteType invite = getInviteStatus(shared);
        UserType uentry = null;
        final String invitee = principalToCaladdr(sharee);
        if (invite != null) {
            uentry = invite.finduser(invitee);
        }
        if (uentry == null) {
            if (debug) {
                trace("Cannot find invitee: " + invitee);
            }
            return;
        }
        uentry.setInviteStatus(AppleServerTags.inviteDeclined);
        shared.setProperty(NamespaceAbbrevs.prefixed(AppleServerTags.invite), invite.toXml());
        getCols().update(shared);
        /* At this stage we need a message to notify the sharer -
         change notification.
         The name of the alias is the uid of the original invite
         */
        final NotificationType note = new NotificationType();
        note.setDtstamp(new DtStamp(new DateTime(true)).getValue());
        // Create a reply object.
        final InviteReplyType reply = new InviteReplyType();
        reply.setHref(principalToCaladdr(sharee));
        reply.setAccepted(false);
        reply.setHostUrl(shared.getPath());
        reply.setInReplyTo(col.getName());
        reply.setSummary(col.getSummary());
        note.setNotification(reply);
        getSvc().getNotificationsHandler().add(note);
    } catch (final CalFacadeException cfe) {
        throw cfe;
    } catch (final Throwable t) {
        throw new CalFacadeException(t);
    } finally {
        popPrincipal();
    }
/*
    final BwPrincipal pr = caladdrToPrincipal(getPrincipalHref());

    if (pr != null) {
      pushPrincipal(shared.getOwnerHref());
      NotificationType n = null;
      try {
        n = findInvite(pr, shared.getPath());
      } finally {
        popPrincipal();
      }
      if (n != null) {
        InviteNotificationType in = (InviteNotificationType)n.getNotification();
        Holder<AccessType> access = new Holder<AccessType>();

        // Create a dummy reply object.
        InviteReplyType reply = new InviteReplyType();
        reply.setHref(getPrincipalHref());
        reply.setAccepted(false);
        reply.setHostUrl(shared.getPath());
        reply.setInReplyTo(in.getUid());

        updateSharingStatus(shared.getOwnerHref(), shared.getPath(), reply, access);
      }
    }
    */
}
Also used : DtStamp(net.fortuna.ical4j.model.property.DtStamp) BwPrincipal(org.bedework.calfacade.BwPrincipal) NotificationType(org.bedework.caldav.util.notifications.NotificationType) InviteNotificationType(org.bedework.caldav.util.sharing.InviteNotificationType) InviteType(org.bedework.caldav.util.sharing.InviteType) InviteReplyType(org.bedework.caldav.util.sharing.InviteReplyType) BwCalendar(org.bedework.calfacade.BwCalendar) UserType(org.bedework.caldav.util.sharing.UserType) DateTime(net.fortuna.ical4j.model.DateTime) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 4 with InviteType

use of org.bedework.caldav.util.sharing.InviteType in project bw-calendar-engine by Bedework.

the class BwSysIntfImpl method getInviteStatus.

@Override
public InviteType getInviteStatus(final CalDAVCollection col) throws WebdavException {
    try {
        InviteType inv = svci.getSharingHandler().getInviteStatus(unwrap(col));
        if (inv == null) {
            return null;
        }
        UrlHandler uh = getUrlHandler();
        for (UserType u : inv.getUsers()) {
            u.setHref(uh.prefix(u.getHref()));
        }
        return inv;
    } catch (CalFacadeForbidden cf) {
        throw new WebdavForbidden(cf.getMessage());
    } catch (WebdavException we) {
        throw we;
    } catch (Throwable t) {
        throw new WebdavException(t);
    }
}
Also used : UrlHandler(org.bedework.webdav.servlet.shared.UrlHandler) WebdavForbidden(org.bedework.webdav.servlet.shared.WebdavForbidden) InviteType(org.bedework.caldav.util.sharing.InviteType) WebdavException(org.bedework.webdav.servlet.shared.WebdavException) CalFacadeForbidden(org.bedework.calfacade.exc.CalFacadeForbidden) UserType(org.bedework.caldav.util.sharing.UserType)

Example 5 with InviteType

use of org.bedework.caldav.util.sharing.InviteType in project bw-calendar-engine by Bedework.

the class Sharing method share.

@Override
public ShareResultType share(final BwCalendar col, final ShareType share) throws CalFacadeException {
    if (!col.getCanAlias()) {
        throw new CalFacadeForbidden("Cannot share");
    }
    final ShareResultType sr = new ShareResultType();
    final List<String> removePrincipalHrefs = new ArrayList<>();
    final List<AddPrincipal> addPrincipals = new ArrayList<>();
    final String calAddr = principalToCaladdr(getPrincipal());
    final InviteType invite = getInviteStatus(col);
    if (invite.getOrganizer() == null) {
        final OrganizerType org = new OrganizerType();
        org.setHref(calAddr);
        invite.setOrganizer(org);
    }
    final List<InviteNotificationType> notifications = new ArrayList<>();
    boolean addedSharee = false;
    boolean removedSharee = false;
    /* If there are any removal elements in the invite, remove those
     * sharees. We'll flag hrefs as bad if they are not actually sharees.
     *
     * If we do remove a sharee we'll add notifications to the list
     * to send later.
     */
    for (final RemoveType rem : share.getRemove()) {
        final InviteNotificationType n = doRemove(col, rem, calAddr, invite);
        if (n != null) {
            removedSharee = true;
            if ((n.getPreviousStatus() != null) && !n.getPreviousStatus().equals(declineStatus)) {
                // We don't notify if the user had declined
                notifications.add(n);
            }
            sr.addGood(rem.getHref());
            removePrincipalHrefs.add(rem.getHref());
        } else {
            sr.addBad(rem.getHref());
        }
    }
    /* Now deal with the added sharees if there are any.
     */
    for (final SetType set : share.getSet()) {
        final InviteNotificationType n = doSet(col, set, addPrincipals, calAddr, invite);
        if (n != null) {
            addedSharee = true;
            notifications.add(n);
            sr.addGood(set.getHref());
        } else {
            sr.addBad(set.getHref());
        }
    }
    if (!addedSharee && !removedSharee) {
        // Nothing changed
        return sr;
    }
    /* Send any invitations and update the sharing status.
     * If it's a removal and the current status is not
     * accepted then just delete the current invitation
     */
    final Notifications notify = (Notifications) getSvc().getNotificationsHandler();
    sendNotifications: for (final InviteNotificationType in : notifications) {
        final Sharee sh = getSharee(in.getHref());
        final boolean remove = in.getInviteStatus().equals(removeStatus);
        final List<NotificationType> notes = notify.getMatching(in.getHref(), AppleServerTags.inviteNotification);
        if (!Util.isEmpty(notes)) {
            for (final NotificationType n : notes) {
                final InviteNotificationType nin = (InviteNotificationType) n.getNotification();
                if (!nin.getHostUrl().equals(in.getHostUrl())) {
                    continue;
                }
                if (remove) {
                    if (nin.getInviteStatus().equals(noresponseStatus)) {
                        notify.remove(sh.pr, n);
                        continue sendNotifications;
                    }
                } else {
                    notify.remove(sh.pr, n);
                }
            }
        }
        final NotificationType note = new NotificationType();
        note.setDtstamp(new DtStamp(new DateTime(true)).getValue());
        note.setNotification(in);
        notify.send(sh.pr, note);
        /* Add the invite to the set of properties associated with this collection
       * We give it a name consisting of the inviteNotification tag + uid.
       */
        final QName qn = new QName(AppleServerTags.inviteNotification.getNamespaceURI(), AppleServerTags.inviteNotification.getLocalPart() + in.getUid());
        try {
            col.setProperty(NamespaceAbbrevs.prefixed(qn), in.toXml());
        } catch (final CalFacadeException cfe) {
            throw cfe;
        } catch (final Throwable t) {
            throw new CalFacadeException(t);
        }
    }
    if (addedSharee && !col.getShared()) {
        // Mark the collection as shared
        col.setShared(true);
    }
    try {
        col.setQproperty(AppleServerTags.invite, invite.toXml());
        getCols().update(col);
        for (final String principalHref : removePrincipalHrefs) {
            removeAccess(col, principalHref);
        }
        for (final AddPrincipal ap : addPrincipals) {
            setAccess(col, ap);
        }
    } catch (final CalFacadeException cfe) {
        throw cfe;
    } catch (final Throwable t) {
        throw new CalFacadeException(t);
    }
    return sr;
}
Also used : ShareResultType(org.bedework.caldav.util.sharing.ShareResultType) InviteNotificationType(org.bedework.caldav.util.sharing.InviteNotificationType) QName(javax.xml.namespace.QName) ArrayList(java.util.ArrayList) CalFacadeForbidden(org.bedework.calfacade.exc.CalFacadeForbidden) OrganizerType(org.bedework.caldav.util.sharing.OrganizerType) DateTime(net.fortuna.ical4j.model.DateTime) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException) RemoveType(org.bedework.caldav.util.sharing.RemoveType) DtStamp(net.fortuna.ical4j.model.property.DtStamp) SetType(org.bedework.caldav.util.sharing.SetType) NotificationType(org.bedework.caldav.util.notifications.NotificationType) InviteNotificationType(org.bedework.caldav.util.sharing.InviteNotificationType) InviteType(org.bedework.caldav.util.sharing.InviteType) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

InviteType (org.bedework.caldav.util.sharing.InviteType)6 UserType (org.bedework.caldav.util.sharing.UserType)5 BwCalendar (org.bedework.calfacade.BwCalendar)4 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)4 DateTime (net.fortuna.ical4j.model.DateTime)3 DtStamp (net.fortuna.ical4j.model.property.DtStamp)3 NotificationType (org.bedework.caldav.util.notifications.NotificationType)3 InviteNotificationType (org.bedework.caldav.util.sharing.InviteNotificationType)3 CalFacadeForbidden (org.bedework.calfacade.exc.CalFacadeForbidden)3 QName (javax.xml.namespace.QName)2 InviteReplyType (org.bedework.caldav.util.sharing.InviteReplyType)2 BwPrincipal (org.bedework.calfacade.BwPrincipal)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 TreeSet (java.util.TreeSet)1 OrganizerType (org.bedework.caldav.util.sharing.OrganizerType)1 RemoveType (org.bedework.caldav.util.sharing.RemoveType)1 SetType (org.bedework.caldav.util.sharing.SetType)1 ShareResultType (org.bedework.caldav.util.sharing.ShareResultType)1 AliasesInfo (org.bedework.calfacade.AliasesInfo)1