Search in sources :

Example 6 with BwCalendar

use of org.bedework.calfacade.BwCalendar in project bw-calendar-engine by Bedework.

the class CalSuites method validateGroup.

/**
 * Ensure the given group is valid for the given calendar suite
 *
 * @param cs
 * @param groupName
 * @return home for the group
 * @throws CalFacadeException
 */
private BwCalendar validateGroup(final BwCalSuite cs, final String groupName) throws CalFacadeException {
    if (groupName.length() > BwCalSuite.maxNameLength) {
        throw new CalFacadeException(CalFacadeException.calsuiteGroupNameTooLong);
    }
    BwAdminGroup agrp = (BwAdminGroup) getSvc().getAdminDirectories().findGroup(groupName);
    if (agrp == null) {
        throw new CalFacadeException(CalFacadeException.groupNotFound, groupName);
    }
    final BwCalSuiteWrapper csw = get(agrp);
    if ((csw != null) && !csw.equals(cs)) {
        // Group already assigned to another cal suite
        throw new CalFacadeException(CalFacadeException.calsuiteGroupAssigned, csw.getName());
    }
    final BwPrincipal eventsOwner = getPrincipal(agrp.getOwnerHref());
    if (eventsOwner == null) {
        throw new CalFacadeException(CalFacadeException.calsuiteBadowner);
    }
    final BwCalendar home = getCols().getHomeDb(eventsOwner, true);
    if (home == null) {
        throw new CalFacadeException(CalFacadeException.missingGroupOwnerHome);
    }
    cs.setGroup(agrp);
    /* Change access on the home for the events creator which is also the
     * owner of the calsuite resources.
     */
    final Collection<Privilege> allPrivs = new ArrayList<>();
    allPrivs.add(Access.all);
    final Collection<Privilege> readPrivs = new ArrayList<>();
    readPrivs.add(Access.read);
    final Collection<Ace> aces = new ArrayList<>();
    try {
        aces.add(Ace.makeAce(AceWho.owner, allPrivs, null));
        aces.add(Ace.makeAce(AceWho.getAceWho(eventsOwner.getAccount(), WhoDefs.whoTypeUser, false), allPrivs, null));
        aces.add(Ace.makeAce(AceWho.getAceWho(null, WhoDefs.whoTypeAuthenticated, false), readPrivs, null));
        aces.add(Ace.makeAce(AceWho.all, readPrivs, null));
        getSvc().changeAccess(home, aces, true);
        /* Same access to the calsuite itself */
        getSvc().changeAccess(cs, aces, true);
        /* Also set access so that categories, locations etc are readable */
        final String aclStr = new String(new Acl(aces).encode());
        eventsOwner.setCategoryAccess(aclStr);
        eventsOwner.setLocationAccess(aclStr);
        eventsOwner.setContactAccess(aclStr);
    } catch (final AccessException ae) {
        throw new CalFacadeException(ae);
    }
    getSvc().getUsersHandler().update(eventsOwner);
    return home;
}
Also used : Ace(org.bedework.access.Ace) ArrayList(java.util.ArrayList) BwCalSuiteWrapper(org.bedework.calfacade.svc.wrappers.BwCalSuiteWrapper) BwCalendar(org.bedework.calfacade.BwCalendar) Acl(org.bedework.access.Acl) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException) BwPrincipal(org.bedework.calfacade.BwPrincipal) AccessException(org.bedework.access.AccessException) BwAdminGroup(org.bedework.calfacade.svc.BwAdminGroup) Privilege(org.bedework.access.Privilege)

Example 7 with BwCalendar

use of org.bedework.calfacade.BwCalendar in project bw-calendar-engine by Bedework.

the class CalSuites method setRootCol.

/**
 * Set root collection if supplied
 *
 * @param cs
 * @param rootCollectionPath
 * @throws CalFacadeException
 */
private void setRootCol(final BwCalSuite cs, final String rootCollectionPath) throws CalFacadeException {
    if ((rootCollectionPath == null) || rootCollectionPath.equals(cs.getRootCollectionPath())) {
        return;
    }
    BwCalendar rootCol = getCols().get(rootCollectionPath);
    if (rootCol == null) {
        throw new CalFacadeException(CalFacadeException.calsuiteUnknownRootCollection, rootCollectionPath);
    }
    cs.setRootCollection(rootCol);
    cs.setRootCollectionPath(rootCol.getPath());
}
Also used : BwCalendar(org.bedework.calfacade.BwCalendar) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 8 with BwCalendar

use of org.bedework.calfacade.BwCalendar in project bw-calendar-engine by Bedework.

the class CalSvc method getSynchReport.

/* (non-Javadoc)
   * @see org.bedework.calsvci.CalSvcI#getSynchReport(java.lang.String, java.lang.String, int, boolean)
   */
@Override
public SynchReport getSynchReport(final String path, final String token, final int limit, final boolean recurse) throws CalFacadeException {
    final BwCalendar col = getCalendarsHandler().get(path);
    if (col == null) {
        return null;
    }
    Set<SynchReportItem> items = new TreeSet<SynchReportItem>();
    String resToken = getSynchItems(col, path, token, items, recurse);
    final SynchReport res = new SynchReport(items, resToken);
    if ((limit > 0) && (res.size() >= limit)) {
        if (res.size() == limit) {
            return res;
        }
        items = new TreeSet<>();
        resToken = "";
        for (final SynchReportItem item : res.getItems()) {
            if (item.getToken().compareTo(resToken) > 0) {
                resToken = item.getToken();
            }
            items.add(item);
            if (items.size() == limit) {
                break;
            }
        }
    }
    if (resToken.length() == 0) {
        resToken = Util.icalUTCTimestamp() + "-0000";
    }
    return new SynchReport(items, resToken);
}
Also used : SynchReport(org.bedework.calsvci.SynchReport) TreeSet(java.util.TreeSet) BwCalendar(org.bedework.calfacade.BwCalendar) BwString(org.bedework.calfacade.BwString) SynchReportItem(org.bedework.calsvci.SynchReportItem)

Example 9 with BwCalendar

use of org.bedework.calfacade.BwCalendar in project bw-calendar-engine by Bedework.

the class CalSvc method changeAccess.

/* ====================================================================
   *                   Access
   * ==================================================================== */
/* (non-Javadoc)
   * @see org.bedework.calsvci.CalSvcI#changeAccess(org.bedework.calfacade.base.BwShareableDbentity, java.util.Collection)
   */
@Override
public void changeAccess(BwShareableDbentity ent, final Collection<Ace> aces, final boolean replaceAll) throws CalFacadeException {
    if (ent instanceof BwCalSuiteWrapper) {
        ent = ((BwCalSuiteWrapper) ent).fetchEntity();
    }
    getCal().changeAccess(ent, aces, replaceAll);
    if (ent instanceof BwCalendar) {
        final BwCalendar col = (BwCalendar) ent;
        if (col.getCalType() == BwCalendar.calTypeInbox) {
            // Same access as inbox
            final BwCalendar pendingInbox = getCalendarsHandler().getSpecial(BwCalendar.calTypePendingInbox, true);
            if (pendingInbox == null) {
                warn("Unable to update pending inbox access");
            } else {
                getCal().changeAccess(pendingInbox, aces, replaceAll);
            }
        }
        ((Preferences) getPrefsHandler()).updateAdminPrefs(false, col, null, null, null);
    } else if (ent instanceof BwEventProperty) {
        ((Preferences) getPrefsHandler()).updateAdminPrefs(false, (BwEventProperty) ent);
    }
}
Also used : BwEventProperty(org.bedework.calfacade.BwEventProperty) BwCalSuiteWrapper(org.bedework.calfacade.svc.wrappers.BwCalSuiteWrapper) BwCalendar(org.bedework.calfacade.BwCalendar) BwPreferences(org.bedework.calfacade.svc.BwPreferences)

Example 10 with BwCalendar

use of org.bedework.calfacade.BwCalendar 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)

Aggregations

BwCalendar (org.bedework.calfacade.BwCalendar)134 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)46 EventInfo (org.bedework.calfacade.svc.EventInfo)23 BwEvent (org.bedework.calfacade.BwEvent)19 ArrayList (java.util.ArrayList)18 CalFacadeAccessException (org.bedework.calfacade.exc.CalFacadeAccessException)18 BwPrincipal (org.bedework.calfacade.BwPrincipal)15 TreeSet (java.util.TreeSet)10 CoreEventInfo (org.bedework.calcorei.CoreEventInfo)10 BwCategory (org.bedework.calfacade.BwCategory)10 BwResource (org.bedework.calfacade.BwResource)10 WebdavException (org.bedework.webdav.servlet.shared.WebdavException)9 FilterBase (org.bedework.caldav.util.filter.FilterBase)8 BwPreferences (org.bedework.calfacade.svc.BwPreferences)8 BwEventProxy (org.bedework.calfacade.BwEventProxy)7 CalendarWrapper (org.bedework.calfacade.wrappers.CalendarWrapper)7 CurrentAccess (org.bedework.access.Acl.CurrentAccess)6 CalendarsI (org.bedework.calsvci.CalendarsI)6 Acl (org.bedework.access.Acl)5 BwEventAnnotation (org.bedework.calfacade.BwEventAnnotation)5