Search in sources :

Example 1 with CalFacadeForbidden

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

the class Events method add.

@Override
public UpdateResult add(final EventInfo ei, final boolean noInvites, final boolean schedulingInbox, final boolean autoCreateCollection, final boolean rollbackOnError) throws CalFacadeException {
    try {
        if (getPrincipalInfo().getSubscriptionsOnly()) {
            throw new CalFacadeForbidden("User has read only access");
        }
        final UpdateResult updResult = ei.getUpdResult();
        updResult.adding = true;
        updResult.hasChanged = true;
        final BwEvent event = ei.getEvent();
        adjustEntities(ei);
        final BwPreferences prefs = getSvc().getPrefsHandler().get();
        if (prefs != null) {
            final Collection<BwCategory> cats = getSvc().getCategoriesHandler().get(prefs.getDefaultCategoryUids());
            for (final BwCategory cat : cats) {
                event.addCategory(cat);
            }
        }
        final RealiasResult raResp = reAlias(event);
        if (raResp.getStatus() != ok) {
            throw new CalFacadeException(CalFacadeException.badRequest, "Status: " + raResp.getStatus() + " message: " + raResp.getMessage());
        }
        // Or just validate?
        assignGuid(event);
        updateEntities(updResult, event);
        BwCalendar cal = validate(event, true, schedulingInbox, autoCreateCollection);
        BwEventProxy proxy = null;
        BwEvent override = null;
        if (event instanceof BwEventProxy) {
            proxy = (BwEventProxy) event;
            override = proxy.getRef();
            setupSharableEntity(override, getPrincipal().getPrincipalRef());
        } else {
            setupSharableEntity(event, getPrincipal().getPrincipalRef());
            if (ei.getNumContainedItems() > 0) {
                for (final EventInfo aei : ei.getContainedItems()) {
                    final BwEvent av = aei.getEvent();
                    av.setParent(event);
                    setupSharableEntity(av, getPrincipal().getPrincipalRef());
                }
            }
        }
        final BwCalendar undereffedCal = cal;
        if (cal.getInternalAlias()) {
            /* Resolve the alias and put the event in it's proper place */
            // XXX This is probably OK for non-public admin
            final boolean setCats = getSvc().getPars().getPublicAdmin();
            if (!setCats) {
                cal = getCols().resolveAlias(cal, true, false);
            } else {
                while (true) {
                    final Set<BwCategory> cats = cal.getCategories();
                    for (final BwCategory cat : cats) {
                        event.addCategory(cat);
                    }
                    if (!cal.getInternalAlias()) {
                        break;
                    }
                    cal = getCols().resolveAlias(cal, false, false);
                }
            }
            event.setColPath(cal.getPath());
        }
        if (!cal.getCalendarCollection()) {
            throw new CalFacadeAccessException();
        }
        if (!event.getPublick() && Util.isEmpty(event.getAlarms())) {
            setDefaultAlarms(ei, undereffedCal);
        }
        boolean schedulingObject = false;
        if (cal.getCollectionInfo().scheduling && (event.getOrganizerSchedulingObject() || event.getAttendeeSchedulingObject())) {
            schedulingObject = true;
        }
        final Integer maxAttendees = getSvc().getAuthProperties().getMaxAttendeesPerInstance();
        if ((maxAttendees != null) && !Util.isEmpty(event.getAttendees()) && (event.getAttendees().size() > maxAttendees)) {
            throw new CalFacadeException(CalFacadeException.schedulingTooManyAttendees);
        }
        event.setDtstamps(getCurrentTimestamp());
        if (schedulingObject) {
            event.updateStag(getCurrentTimestamp());
        }
        /* All Overrides go in same calendar and have same name */
        final Collection<BwEventProxy> overrides = ei.getOverrideProxies();
        if (overrides != null) {
            for (final BwEventProxy ovei : overrides) {
                setScheduleState(ovei, true, schedulingInbox);
                if ((maxAttendees != null) && !Util.isEmpty(ovei.getAttendees()) && (ovei.getAttendees().size() > maxAttendees)) {
                    throw new CalFacadeException(CalFacadeException.schedulingTooManyAttendees);
                }
                ovei.setDtstamps(getCurrentTimestamp());
                if (cal.getCollectionInfo().scheduling && (ovei.getOrganizerSchedulingObject() || ovei.getAttendeeSchedulingObject())) {
                    schedulingObject = true;
                }
                if (schedulingObject) {
                    ovei.updateStag(getCurrentTimestamp());
                }
                final BwEventAnnotation ann = ovei.getRef();
                ann.setColPath(event.getColPath());
                ann.setName(event.getName());
            }
        }
        if (event.getOrganizerSchedulingObject()) {
            // Set RSVP on all attendees with PARTSTAT = NEEDS_ACTION
            for (final BwAttendee att : event.getAttendees()) {
                if (att.getPartstat() == IcalDefs.partstatValNeedsAction) {
                    att.setRsvp(true);
                }
            }
        }
        UpdateEventResult uer = getCal().addEvent(ei, schedulingInbox, rollbackOnError);
        if (ei.getNumContainedItems() > 0) {
            for (final EventInfo oei : ei.getContainedItems()) {
                oei.getEvent().setName(event.getName());
                final UpdateEventResult auer = getCal().addEvent(oei, schedulingInbox, rollbackOnError);
                if (auer.errorCode != null) {
                // ?
                }
            }
        }
        updResult.failedOverrides = uer.failedOverrides;
        if (!noInvites) {
            if (event.getAttendeeSchedulingObject()) {
                // Attendee replying?
                updResult.reply = true;
            }
            if (cal.getCollectionInfo().scheduling && schedulingObject) {
                final SchedulingIntf sched = (SchedulingIntf) getSvc().getScheduler();
                sched.implicitSchedule(ei, false);
            /* We assume we don't need to update again to set attendee status
           * Trying to do an update results in duplicate key errors.
           *
           * If it turns out the scgedule status is not getting persisted in the
           * calendar entry then we need to find a way to set just that value in
           * already persisted entity.
           */
            }
        }
        return updResult;
    } catch (final Throwable t) {
        if (debug) {
            error(t);
        }
        getSvc().rollbackTransaction();
        if (t instanceof CalFacadeException) {
            throw (CalFacadeException) t;
        }
        throw new CalFacadeException(t);
    }
}
Also used : BwPreferences(org.bedework.calfacade.svc.BwPreferences) CoreEventInfo(org.bedework.calcorei.CoreEventInfo) EventInfo(org.bedework.calfacade.svc.EventInfo) BwCategory(org.bedework.calfacade.BwCategory) CalFacadeForbidden(org.bedework.calfacade.exc.CalFacadeForbidden) BwEvent(org.bedework.calfacade.BwEvent) SchedulingIntf(org.bedework.calsvc.scheduling.SchedulingIntf) BwCalendar(org.bedework.calfacade.BwCalendar) BwEventProxy(org.bedework.calfacade.BwEventProxy) CalFacadeAccessException(org.bedework.calfacade.exc.CalFacadeAccessException) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException) BwEventAnnotation(org.bedework.calfacade.BwEventAnnotation) BwAttendee(org.bedework.calfacade.BwAttendee) UpdateResult(org.bedework.calfacade.svc.EventInfo.UpdateResult) UpdateEventResult(org.bedework.calcorei.CoreEventsI.UpdateEventResult)

Example 2 with CalFacadeForbidden

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

the class ResourcesImpl method save.

private boolean save(final String path, final BwResource val, final boolean forNotification, final boolean returnIfExists) throws CalFacadeException {
    try {
        final BwCalendar coll = getCols().get(path);
        if (coll == null) {
            throw new CalFacadeException(CalFacadeException.collectionNotFound, path);
        }
        if (forNotification) {
            // We allow this for subscription only
            if (coll.getCalType() != BwCalendar.calTypeNotifications) {
                throw new CalFacadeException(CalFacadeException.badRequest, path);
            }
        } else if (getPrincipalInfo().getSubscriptionsOnly()) {
            throw new CalFacadeForbidden("User has read only access");
        }
        final BwResource r = getCal().getResource(val.getName(), coll, PrivilegeDefs.privAny);
        if (r != null) {
            if (returnIfExists) {
                return false;
            }
            throw new CalFacadeException(CalFacadeException.duplicateResource, val.getName());
        }
        final BwResourceContent rc = val.getContent();
        if (rc == null) {
            throw new CalFacadeException(CalFacadeException.missingResourceContent);
        }
        setupSharableEntity(val, getPrincipal().getPrincipalRef());
        val.setColPath(path);
        if ((coll.getCalType() == BwCalendar.calTypeCalendarCollection) || (coll.getCalType() == BwCalendar.calTypeExtSub)) {
            throw new CalFacadeException(CalFacadeException.badRequest, path);
        }
        checkAccess(coll, PrivilegeDefs.privBind, false);
        val.updateLastmod(getCurrentTimestamp());
        getCal().add(val);
        rc.setColPath(val.getColPath());
        rc.setName(val.getName());
        getCal().add(rc);
        touchCalendar(coll);
        return true;
    } catch (final CalFacadeException cfe) {
        getSvc().rollbackTransaction();
        throw cfe;
    }
}
Also used : BwResource(org.bedework.calfacade.BwResource) CalFacadeForbidden(org.bedework.calfacade.exc.CalFacadeForbidden) BwResourceContent(org.bedework.calfacade.BwResourceContent) BwCalendar(org.bedework.calfacade.BwCalendar) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 3 with CalFacadeForbidden

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

the class Sharing method unpublish.

@Override
public void unpublish(final BwCalendar col) throws CalFacadeException {
    if (col.getPublick() || (col.getQproperty(AppleServerTags.publishUrl) == null)) {
        throw new CalFacadeForbidden("Not published");
    }
    /* Remove access to all */
    final Acl acl = removeAccess(col.getCurrentAccess().getAcl(), null, WhoDefs.whoTypeAll);
    // Mark the collection as published
    col.removeQproperty(AppleServerTags.publishUrl);
    try {
        getCols().update(col);
        if (acl != null) {
            getSvc().changeAccess(col, acl.getAces(), true);
        }
    } catch (final CalFacadeException cfe) {
        throw cfe;
    } catch (final Throwable t) {
        throw new CalFacadeException(t);
    }
}
Also used : CalFacadeForbidden(org.bedework.calfacade.exc.CalFacadeForbidden) Acl(org.bedework.access.Acl) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 4 with CalFacadeForbidden

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

the class Sharing method subscribe.

@Override
public SubscribeResult subscribe(final String colPath, final String subscribedName) throws CalFacadeException {
    /* We must have at least read access to the published collection */
    final BwCalendar publishedCol = getCols().get(colPath);
    final SubscribeResult sr = new SubscribeResult();
    if (publishedCol == null) {
        // Bad url?
        throw new CalFacadeForbidden("Bad url or no access");
    }
    if (!publishedCol.getPublick() && (publishedCol.getQproperty(AppleServerTags.publishUrl) == null)) {
        throw new CalFacadeForbidden("Not published");
    }
    /* We may already be subscribed. If so we're done.
     * Otherwise we need to create an alias in the calendar home using the
     * reply summary as the display name */
    final List<BwCalendar> aliases = findAlias(colPath);
    if (!Util.isEmpty(aliases)) {
        sr.path = aliases.get(0).getPath();
        sr.alreadySubscribed = true;
        return sr;
    }
    final BwCalendar alias = new BwCalendar();
    String summary = subscribedName;
    if ((summary == null) || (summary.length() == 0)) {
        summary = "Published Calendar";
    }
    alias.setName(getEncodedUuid());
    alias.setSummary(summary);
    alias.setCalType(BwCalendar.calTypeAlias);
    // alias.setPath(home.getPath() + "/" + UUID.randomUUID().toString());
    alias.setAliasUri("bwcal://" + colPath);
    alias.setShared(true);
    alias.setSharedWritable(false);
    sr.path = getCols().add(alias, getCols().getHome().getPath()).getPath();
    return sr;
}
Also used : CalFacadeForbidden(org.bedework.calfacade.exc.CalFacadeForbidden) BwCalendar(org.bedework.calfacade.BwCalendar)

Example 5 with CalFacadeForbidden

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

the class BwSysIntfImpl method updateEvent.

@Override
public UpdateResult updateEvent(final CalDAVEvent event, final List<ComponentSelectionType> updates) throws WebdavException {
    try {
        EventInfo ei = getEvinfo(event);
        if (updates == null) {
            return new UpdateResult("No updates");
        }
        UpdateResult ur = new BwUpdates(getPrincipal().getPrincipalRef()).updateEvent(ei, updates, getSvci().getIcalCallback());
        if (!ur.getOk()) {
            getSvci().rollbackTransaction();
            return ur;
        }
        getSvci().getEventsHandler().update(ei, false);
        return ur;
    } catch (CalFacadeAccessException cfae) {
        throw new WebdavForbidden();
    } catch (CalFacadeForbidden cff) {
        throw new WebdavForbidden(cff.getQname(), cff.getMessage());
    } catch (CalFacadeException cfe) {
        if (CalFacadeException.duplicateGuid.equals(cfe.getMessage())) {
            throw new WebdavBadRequest("Duplicate-guid");
        }
        throw new WebdavException(cfe);
    } catch (Throwable t) {
        throw new WebdavException(t);
    }
}
Also used : WebdavBadRequest(org.bedework.webdav.servlet.shared.WebdavBadRequest) EventInfo(org.bedework.calfacade.svc.EventInfo) WebdavForbidden(org.bedework.webdav.servlet.shared.WebdavForbidden) WebdavException(org.bedework.webdav.servlet.shared.WebdavException) CalFacadeForbidden(org.bedework.calfacade.exc.CalFacadeForbidden) CalFacadeAccessException(org.bedework.calfacade.exc.CalFacadeAccessException) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Aggregations

CalFacadeForbidden (org.bedework.calfacade.exc.CalFacadeForbidden)14 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)9 BwCalendar (org.bedework.calfacade.BwCalendar)5 EventInfo (org.bedework.calfacade.svc.EventInfo)4 InviteType (org.bedework.caldav.util.sharing.InviteType)3 CalFacadeAccessException (org.bedework.calfacade.exc.CalFacadeAccessException)3 WebdavException (org.bedework.webdav.servlet.shared.WebdavException)3 QName (javax.xml.namespace.QName)2 DateTime (net.fortuna.ical4j.model.DateTime)2 DtStamp (net.fortuna.ical4j.model.property.DtStamp)2 NotificationType (org.bedework.caldav.util.notifications.NotificationType)2 InviteNotificationType (org.bedework.caldav.util.sharing.InviteNotificationType)2 UserType (org.bedework.caldav.util.sharing.UserType)2 BwEvent (org.bedework.calfacade.BwEvent)2 BwPreferences (org.bedework.calfacade.svc.BwPreferences)2 UpdateResult (org.bedework.calfacade.svc.EventInfo.UpdateResult)2 WebdavBadRequest (org.bedework.webdav.servlet.shared.WebdavBadRequest)2 WebdavForbidden (org.bedework.webdav.servlet.shared.WebdavForbidden)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1