use of org.bedework.calfacade.svc.BwAdminGroup in project bw-calendar-engine by Bedework.
the class MemberRule method end.
@Override
public void end(final String ns, final String name) throws Exception {
/* Top should be the principal info, underneath is the actual entity -
*/
PrincipalHref oi = (PrincipalHref) pop();
try {
if (oi.prefix == null) {
error("Unable to handle principal type " + oi.getKind());
}
oi.href = Util.buildPath(false, oi.prefix, "/", oi.account);
} catch (Throwable t) {
error("Unable to get user principal root", t);
return;
}
BwPrincipal pr = globals.principalsTbl.get(oi);
if (top() instanceof BwGroup) {
BwGroup gr = (BwGroup) top();
if (pr == null) {
if (gr instanceof BwAdminGroup) {
ArrayList<PrincipalHref> m = globals.adminGroupMembers.get(gr.getAccount());
if (m == null) {
m = new ArrayList<PrincipalHref>();
globals.adminGroupMembers.put(gr.getAccount(), m);
}
m.add(oi);
} else {
error("Cannot handle group " + gr);
}
return;
}
gr.addGroupMember(pr);
return;
}
error("Unknown class for member " + top());
}
use of org.bedework.calfacade.svc.BwAdminGroup in project bw-calendar-engine by Bedework.
the class OwnerRule method end.
@Override
public void end(final String ns, final String name) throws Exception {
error("OwnerRule called");
BwPrincipal p = doPrincipal();
if (top() instanceof OwnerUidKey) {
OwnerUidKey key = (OwnerUidKey) top();
key.setOwnerHref(p.getPrincipalRef());
globals.inOwnerKey = false;
return;
}
if (top() instanceof BwAdminGroup) {
BwAdminGroup ag = (BwAdminGroup) top();
if (name.equals("owner")) {
ag.setOwnerHref(p.getPrincipalRef());
} else if (name.equals("owner-key")) {
// PRE3.5
ag.setOwnerHref(p.getPrincipalRef());
} else {
ag.setGroupOwnerHref(p.getPrincipalRef());
}
globals.inOwnerKey = false;
return;
}
BwOwnedDbentity o = null;
if (top() == null) {
error("Null stack top when setting owner. Match: " + getDigester().getMatch());
return;
}
if (top() instanceof EventInfo) {
o = ((EventInfo) top()).getEvent();
} else if (!(top() instanceof BwOwnedDbentity)) {
if (top() instanceof BwOrganizer) {
// No owner now
} else if (top() instanceof BwView) {
// No owner now
} else if (top() instanceof SkipThis) {
} else {
// We expect organizer in old data
warn("top() is not BwOwnedDbentity:" + top().getClass().getCanonicalName());
warn(" match: " + getDigester().getMatch());
}
globals.inOwnerKey = false;
return;
} else {
o = (BwOwnedDbentity) top();
}
o.setOwnerHref(p.getPrincipalRef());
globals.inOwnerKey = false;
}
use of org.bedework.calfacade.svc.BwAdminGroup in project bw-calendar-engine by Bedework.
the class CalSuites method wrap.
private BwCalSuiteWrapper wrap(final BwCalSuite cs, final boolean alwaysReturn) throws CalFacadeException {
final CurrentAccess ca = checkAccess(cs, PrivilegeDefs.privAny, alwaysReturn);
if ((ca == null) || !ca.getAccessAllowed()) {
return null;
}
final BwCalSuiteWrapper w = new BwCalSuiteWrapper(cs, ca);
final BwAdminGroup agrp = cs.getGroup();
if (agrp == null) {
return w;
}
final BwPrincipal eventsOwner = getSvc().getUsersHandler().getPrincipal(agrp.getOwnerHref());
if (eventsOwner == null) {
return w;
}
final BwCalendar home = getCols().getHome(eventsOwner, false);
if (home == null) {
return w;
}
w.setResourcesHome(home.getPath());
return w;
}
use of org.bedework.calfacade.svc.BwAdminGroup 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();
}
}
use of org.bedework.calfacade.svc.BwAdminGroup 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;
}
Aggregations