Search in sources :

Example 56 with BwPrincipal

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

the class InProcessor method pendingToInbox.

/**
 * Update the inbox according to it's owners wishes (what if owner and proxy
 * have different wishes)
 *
 * @param ei - the pending inbox event
 * @param inboxOwnerHref href of
 * @param attendeeAccepting - is this the result of a REPLY with PARTSTAT accept?
 * @param forceDelete - it's inbox noise, delete it
 * @throws CalFacadeException
 */
public void pendingToInbox(final EventInfo ei, final String inboxOwnerHref, final boolean attendeeAccepting, final boolean forceDelete) throws CalFacadeException {
    boolean delete = forceDelete;
    if (!delete) {
        final BwPrincipal principal = getSvc().getUsersHandler().getPrincipal(inboxOwnerHref);
        if (principal == null) {
            delete = true;
        } else {
            final BwPreferences prefs = getSvc().getPrefsHandler().get(principal);
            final int sapr = prefs.getScheduleAutoProcessResponses();
            if (sapr == BwPreferences.scheduleAutoProcessResponsesNoNotify) {
                delete = true;
            } else if (sapr == BwPreferences.scheduleAutoProcessResponsesNoAcceptNotify) {
                delete = attendeeAccepting;
            }
        }
    }
    final BwEvent ev = ei.getEvent();
    final boolean vpoll = ev.getEntityType() == IcalDefs.entityTypeVpoll;
    if (delete) {
        getSvc().getEventsHandler().delete(ei, false);
    } else {
        final BwCalendar inbox = getSvc().getCalendarsHandler().getSpecial(BwCalendar.calTypeInbox, false);
        if (inbox == null) {
            return;
        }
        // if (vpoll) {
        /* Delete other notifications for the same event
         * NOTE: DON'T for non-vpoll - this was deleting changes that had to
         * be processed. Still an opportunity to improve this though.
         */
        final Collection<EventInfo> inevs = getEventsByUid(inbox.getPath(), ev.getUid());
        for (final EventInfo inei : inevs) {
            final BwEvent inev = inei.getEvent();
            if (inev.getScheduleState() != BwEvent.scheduleStateProcessed) {
                continue;
            }
            if (debug) {
                trace("delete earlier? event from inbox: " + inev.getName());
            }
            deleteEvent(inei, true, false);
        }
        if (debug) {
            trace("set event to scheduleStateProcessed: " + ev.getName());
        }
        final ChangeTable chg = ei.getChangeset(inboxOwnerHref);
        chg.changed(PropertyIndex.PropertyInfoIndex.SCHEDULE_STATE, ev.getScheduleState(), BwEvent.scheduleStateProcessed);
        ev.setScheduleState(BwEvent.scheduleStateProcessed);
        chg.changed(PropertyIndex.PropertyInfoIndex.COLPATH, ev.getColPath(), inbox.getPath());
        ev.setColPath(inbox.getPath());
        getSvc().getEventsHandler().update(ei, true, null);
    }
}
Also used : BwPrincipal(org.bedework.calfacade.BwPrincipal) BwPreferences(org.bedework.calfacade.svc.BwPreferences) EventInfo(org.bedework.calfacade.svc.EventInfo) ChangeTable(org.bedework.calfacade.util.ChangeTable) BwEvent(org.bedework.calfacade.BwEvent) BwCalendar(org.bedework.calfacade.BwCalendar)

Example 57 with BwPrincipal

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

the class ProcessAdd method addToAdminGroup.

private boolean addToAdminGroup(final String account) throws Throwable {
    if (debug) {
        debug("About to add member " + account + " to a group");
    }
    if (account == null) {
        pstate.addError("Must supply account");
        return false;
    }
    final String kind = word();
    final boolean group;
    if ("group".equals(kind)) {
        group = true;
    } else if ("user".equals(kind)) {
        group = false;
    } else {
        pstate.addError("Invalid kind: " + kind);
        return false;
    }
    if (!"to".equals(word())) {
        pstate.addError("Invalid syntax - expected 'to'");
        return false;
    }
    final String toGrp = wordOrQuotedVal();
    try {
        open();
        final BwAdminGroup grp = (BwAdminGroup) getSvci().getAdminDirectories().findGroup(toGrp);
        if (grp == null) {
            pstate.addError("Unknown group " + toGrp);
            return false;
        }
        if (grp.isMember(account, "group".equals(kind))) {
            pstate.addError("Already a member: " + account);
            return false;
        }
        final BwPrincipal nmbr = newMember(account, !group);
        getSvci().getAdminDirectories().addMember(grp, nmbr);
        getSvci().getAdminDirectories().updateGroup(grp);
        return true;
    } finally {
        close();
    }
}
Also used : BwPrincipal(org.bedework.calfacade.BwPrincipal) BwAdminGroup(org.bedework.calfacade.svc.BwAdminGroup)

Example 58 with BwPrincipal

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

the class ProcessCalsuite method process.

@Override
boolean process() throws Throwable {
    final String wd = word();
    if (wd == null) {
        return false;
    }
    if ("help".equals(wd)) {
        pstate.addInfo("calsuite <name>\n" + "   switch to event owner for calsuite\n" + "calsuite <name> addapprover <account>\n" + "   add an approver\n" + "calsuite <name> remapprover <account>\n" + "   remove an approver");
        return true;
    }
    final String account;
    try {
        open();
        final BwCalSuite cs = getSvci().getCalSuitesHandler().get(wd);
        if (cs == null) {
            error("No calsuite with name " + wd);
            return true;
        }
        final BwAdminGroup adminGrp = cs.getGroup();
        if (adminGrp == null) {
            error("No admin group for calsuite " + wd);
            return true;
        }
        final String ownerHref = adminGrp.getOwnerHref();
        if (ownerHref == null) {
            error("No owner href in admin group " + adminGrp + " for calsuite " + wd);
            return true;
        }
        final BwPrincipal ownerPr = getSvci().getPrincipal(ownerHref);
        if (ownerPr == null) {
            error("No user with owner href " + ownerHref + " in admin group " + adminGrp + " for calsuite " + wd);
            return true;
        }
        final String action = word();
        account = ownerPr.getAccount();
        if (action == null) {
            pstate.setCalsuite(cs);
            return true;
        }
        final boolean addAppprover = "addapprover".equals(action);
        if (!addAppprover && !"remapprover".equals(action)) {
            error("Expected addapprover or remapprover");
            return false;
        }
        final String appAccount = word();
        if (appAccount == null) {
            error("Expected an account");
        }
        final BwPreferences prefs = getSvci().getPrefsHandler().get(ownerPr);
        final List<String> approvers = prefs.getCalsuiteApproversList();
        if (Util.isEmpty(approvers)) {
            if (addAppprover) {
                prefs.setCalsuiteApprovers(appAccount);
            }
        } else {
            if (addAppprover) {
                if (!approvers.contains(appAccount)) {
                    approvers.add(appAccount);
                }
            } else {
                approvers.remove(appAccount);
            }
            prefs.setCalsuiteApprovers(String.join(",", approvers));
        }
        getSvci().getPrefsHandler().update(prefs);
    } finally {
        close();
    }
    setUser(account, false);
    return true;
}
Also used : BwCalSuite(org.bedework.calfacade.svc.BwCalSuite) BwPrincipal(org.bedework.calfacade.BwPrincipal) BwPreferences(org.bedework.calfacade.svc.BwPreferences) BwAdminGroup(org.bedework.calfacade.svc.BwAdminGroup)

Example 59 with BwPrincipal

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

the class ProcessCreate method createAdminGroup.

private boolean createAdminGroup(final String account) throws Throwable {
    if (debug) {
        debug("About to create admin group " + account);
    }
    if (account == null) {
        addError("Must supply account");
        return false;
    }
    try {
        open();
        final BwAdminGroup grp = new BwAdminGroup();
        grp.setAccount(account);
        final DirectoryInfo di = getDirectoryInfo();
        String href = di.getBwadmingroupPrincipalRoot();
        if (!href.endsWith("/")) {
            href += "/";
        }
        grp.setPrincipalRef(href + account);
        grp.setDescription(quotedVal());
        if (grp.getDescription() == null) {
            addError("Must supply admin group description");
            return false;
        }
        final String adgGroupOwner = word();
        if (adgGroupOwner == null) {
            addError("Must supply admin group owner");
            return false;
        }
        final BwPrincipal adgPr = getUserAlways(adgGroupOwner);
        if (adgPr == null) {
            return false;
        }
        grp.setGroupOwnerHref(adgPr.getPrincipalRef());
        String adgEventOwner = word();
        if (adgEventOwner == null) {
            adgEventOwner = "agrp_" + account;
        }
        final BwPrincipal adePr = getUserAlways(adgEventOwner);
        if (adePr == null) {
            return false;
        }
        grp.setOwnerHref(adePr.getPrincipalRef());
        getSvci().getAdminDirectories().addGroup(grp);
        return true;
    } finally {
        close();
    }
}
Also used : BwPrincipal(org.bedework.calfacade.BwPrincipal) DirectoryInfo(org.bedework.calfacade.DirectoryInfo) BwAdminGroup(org.bedework.calfacade.svc.BwAdminGroup)

Aggregations

BwPrincipal (org.bedework.calfacade.BwPrincipal)59 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)22 BwCalendar (org.bedework.calfacade.BwCalendar)16 BwAdminGroup (org.bedework.calfacade.svc.BwAdminGroup)10 EventInfo (org.bedework.calfacade.svc.EventInfo)9 BwEvent (org.bedework.calfacade.BwEvent)7 ArrayList (java.util.ArrayList)6 BwPreferences (org.bedework.calfacade.svc.BwPreferences)6 Acl (org.bedework.access.Acl)5 BwGroup (org.bedework.calfacade.BwGroup)4 Component (net.fortuna.ical4j.model.Component)3 AccessException (org.bedework.access.AccessException)3 Ace (org.bedework.access.Ace)3 Privilege (org.bedework.access.Privilege)3 BwOrganizer (org.bedework.calfacade.BwOrganizer)3 WebdavException (org.bedework.webdav.servlet.shared.WebdavException)3 File (java.io.File)2 Collection (java.util.Collection)2 NamingEnumeration (javax.naming.NamingEnumeration)2 Attribute (javax.naming.directory.Attribute)2