Search in sources :

Example 1 with UserType

use of org.bedework.caldav.util.sharing.UserType 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 UserType

use of org.bedework.caldav.util.sharing.UserType 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 UserType

use of org.bedework.caldav.util.sharing.UserType 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 UserType

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

the class Sharing method doSet.

private InviteNotificationType doSet(final BwCalendar col, final SetType s, final List<AddPrincipal> addPrincipals, final String calAddr, final InviteType invite) throws CalFacadeException {
    final Sharee sh = getSharee(s.getHref());
    if ((sh.pr != null) && sh.pr.equals(getPrincipal())) {
        // Inviting ourself
        return null;
    }
    /*
       pr != null means this is potentially one of our users.

       If the principal doesn't exist and we handle outbound
       notifications then we should drop a notification into the
       global notification collection. Eventually the user will log in
       we hope - we can then turn that invite into a real local user
       invite,
     */
    UserType uentry = invite.finduser(sh.href);
    if (uentry != null) {
        if (uentry.getInviteStatus().equals(Parser.inviteNoresponseTag)) {
            // Already an outstanding invitation
            final NotificationType n = findInvite(sh.pr, col.getPath());
            if (n != null) {
                final InviteNotificationType in = (InviteNotificationType) n.getNotification();
                if (in.getAccess().equals(s.getAccess())) {
                    // In their collection - no need to resend.
                    return null;
                }
                /* Delete the old notification - we're changing the access */
                deleteInvite(sh.pr, n);
            }
        }
    }
    final InviteNotificationType in = new InviteNotificationType();
    in.setSharedType(InviteNotificationType.sharedTypeCalendar);
    in.setUid(Uid.getUid());
    in.setHref(sh.href);
    in.setInviteStatus(Parser.inviteNoresponseTag);
    in.setAccess(s.getAccess());
    in.setHostUrl(col.getPath());
    in.setSummary(s.getSummary());
    final OrganizerType org = new OrganizerType();
    org.setHref(calAddr);
    in.setOrganizer(org);
    in.getSupportedComponents().addAll(col.getSupportedComponents());
    // Update the collection sharing status
    if (uentry != null) {
        uentry.setInviteStatus(in.getInviteStatus());
        uentry.setAccess(in.getAccess());
    } else {
        uentry = new UserType();
        uentry.setHref(sh.href);
        uentry.setInviteStatus(in.getInviteStatus());
        uentry.setCommonName(s.getCommonName());
        uentry.setAccess(in.getAccess());
        uentry.setSummary(s.getSummary());
        invite.getUsers().add(uentry);
    }
    uentry.setExternalUser(!sh.external);
    if (!sh.external) {
        addPrincipals.add(new AddPrincipal(sh.pr, s.getAccess().testRead()));
    }
    return in;
}
Also used : InviteNotificationType(org.bedework.caldav.util.sharing.InviteNotificationType) NotificationType(org.bedework.caldav.util.notifications.NotificationType) InviteNotificationType(org.bedework.caldav.util.sharing.InviteNotificationType) OrganizerType(org.bedework.caldav.util.sharing.OrganizerType) UserType(org.bedework.caldav.util.sharing.UserType)

Example 5 with UserType

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

the class Sharing method doRemove.

/**
 * Remove a principal from the list of sharers
 */
private InviteNotificationType doRemove(final BwCalendar col, final RemoveType rem, final String calAddr, final InviteType invite) throws CalFacadeException {
    final String href = getSvc().getDirectories().normalizeCua(rem.getHref());
    final UserType uentry = invite.finduser(href);
    if (uentry == null) {
        // Not in list of sharers
        return null;
    }
    invite.getUsers().remove(uentry);
    final InviteNotificationType note = deletedNotification(col.getPath(), href, calAddr, col.getSummary(), uentry.getAccess());
    note.setPreviousStatus(uentry.getInviteStatus());
    removeAlias(col, uentry.getHref(), false);
    return note;
}
Also used : InviteNotificationType(org.bedework.caldav.util.sharing.InviteNotificationType) UserType(org.bedework.caldav.util.sharing.UserType)

Aggregations

UserType (org.bedework.caldav.util.sharing.UserType)7 InviteType (org.bedework.caldav.util.sharing.InviteType)5 InviteNotificationType (org.bedework.caldav.util.sharing.InviteNotificationType)4 BwCalendar (org.bedework.calfacade.BwCalendar)4 NotificationType (org.bedework.caldav.util.notifications.NotificationType)3 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)3 DateTime (net.fortuna.ical4j.model.DateTime)2 DtStamp (net.fortuna.ical4j.model.property.DtStamp)2 InviteReplyType (org.bedework.caldav.util.sharing.InviteReplyType)2 BwPrincipal (org.bedework.calfacade.BwPrincipal)2 CalFacadeForbidden (org.bedework.calfacade.exc.CalFacadeForbidden)2 TreeSet (java.util.TreeSet)1 QName (javax.xml.namespace.QName)1 OrganizerType (org.bedework.caldav.util.sharing.OrganizerType)1 AliasesInfo (org.bedework.calfacade.AliasesInfo)1 CalFacadeAccessException (org.bedework.calfacade.exc.CalFacadeAccessException)1 UrlHandler (org.bedework.webdav.servlet.shared.UrlHandler)1 WebdavException (org.bedework.webdav.servlet.shared.WebdavException)1 WebdavForbidden (org.bedework.webdav.servlet.shared.WebdavForbidden)1