use of org.bedework.calfacade.exc.CalFacadeForbidden 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);
}
}
use of org.bedework.calfacade.exc.CalFacadeForbidden in project bw-calendar-engine by Bedework.
the class BwSysIntfImpl method updateEvent.
@Override
public void updateEvent(final CalDAVEvent event) throws WebdavException {
try {
EventInfo ei = getEvinfo(event);
getSvci().getEventsHandler().update(ei, false);
} 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);
}
}
use of org.bedework.calfacade.exc.CalFacadeForbidden in project bw-calendar-engine by Bedework.
the class Calendars method add.
@Override
public BwCalendar add(BwCalendar val, final String parentPath) throws CalFacadeException {
if (getPrincipalInfo().getSubscriptionsOnly()) {
// Only allow the creation of an alias
if (val.getCalType() != BwCalendar.calTypeAlias) {
throw new CalFacadeForbidden("User has read only access");
}
}
updateOK(val);
setupSharableEntity(val, getPrincipal().getPrincipalRef());
if (val.getPwNeedsEncrypt() || (val.getExternalSub() && val.getRemotePw() != null)) {
encryptPw(val);
}
val = getCal().add(val, parentPath);
((Preferences) getSvc().getPrefsHandler()).updateAdminPrefs(false, val, null, null, null);
final SynchI synch = getSvc().getSynch();
if (val.getExternalSub()) {
if (!synch.subscribe(val)) {
throw new CalFacadeException(CalFacadeException.subscriptionFailed);
}
}
return val;
}
use of org.bedework.calfacade.exc.CalFacadeForbidden in project bw-calendar-engine by Bedework.
the class Events method checkChanges.
@SuppressWarnings("unchecked")
private boolean checkChanges(final EventInfo ei, final boolean organizerSchedulingObject, final boolean attendeeSchedulingObject) throws CalFacadeException {
final UpdateResult updResult = ei.getUpdResult();
if (ei.getChangeset(getPrincipalHref()).isEmpty()) {
// Forced update?
updResult.hasChanged = true;
if (attendeeSchedulingObject) {
// Attendee replying?
/* XXX We should really check to see if the value changed here -
*/
updResult.reply = true;
}
return true;
}
if (debug) {
ei.getChangeset(getPrincipalHref()).dumpEntries();
}
final ChangeTable ct = ei.getChangeset(getPrincipalHref());
final Collection<ChangeTableEntry> ctes = ct.getEntries();
updResult.sequenceChange = ct.getSequenceChangeNeeded();
for (final ChangeTableEntry cte : ctes) {
if (!cte.getChanged()) {
continue;
}
updResult.hasChanged = true;
final PropertyInfoIndex pi = cte.getIndex();
if (!organizerSchedulingObject && pi.equals(PropertyInfoIndex.ORGANIZER)) {
final BwOrganizer oldOrg = (BwOrganizer) cte.getOldVal();
final BwOrganizer newOrg = (BwOrganizer) cte.getNewVal();
if ((oldOrg == null) || (newOrg == null) || !oldOrg.getOrganizerUri().equals(newOrg.getOrganizerUri())) {
// Never valid
throw new CalFacadeForbidden(CaldavTags.attendeeAllowed, "Cannot change organizer");
}
}
if (pi.equals(PropertyInfoIndex.ATTENDEE) || pi.equals(PropertyInfoIndex.VOTER)) {
updResult.addedAttendees = cte.getAddedValues();
updResult.deletedAttendees = cte.getRemovedValues();
if (attendeeSchedulingObject) {
// Attendee replying?
/* XXX We should really check to see if the value changed here -
*/
updResult.reply = true;
} else {
if (!Util.isEmpty(updResult.deletedAttendees)) {
// Bump sequence as we are sending out cancels
updResult.sequenceChange = true;
}
}
}
if (pi.equals(PropertyInfoIndex.POLL_WINNER)) {
if (!attendeeSchedulingObject) {
// Attendee replying?
/* XXX We should really check to see if the value changed here -
*/
updResult.pollWinner = ei.getEvent().getPollWinner();
}
}
if (pi.equals(PropertyInfoIndex.POLL_ITEM)) {
if (attendeeSchedulingObject) {
// Attendee replying?
/* XXX We should really check to see if the value changed here -
*/
updResult.reply = true;
}
}
if (organizerSchedulingObject) {
final BwIcalPropertyInfoEntry pie = BwIcalPropertyInfo.getPinfo(cte.getIndex());
if (pie.getReschedule()) {
updResult.doReschedule = true;
}
}
}
return updResult.hasChanged;
}
use of org.bedework.calfacade.exc.CalFacadeForbidden 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;
}
Aggregations