use of com.zimbra.cs.mailbox.Mountpoint in project zm-mailbox by Zimbra.
the class CalendarProxyReadFor method toElement.
@Override
public Element toElement(DavContext ctxt, Element parent, boolean nameOnly) {
Element proxy = super.toElement(ctxt, parent, true);
if (nameOnly) {
return proxy;
}
ArrayList<Pair<Mountpoint, ZFolder>> mps = getMountpoints(ctxt);
HashSet<Account> writeProxies = new HashSet<Account>();
HashMap<Account, Element> proxies = new HashMap<Account, Element>();
for (Pair<Mountpoint, ZFolder> folder : mps) {
try {
short rights = ACL.stringToRights(folder.getSecond().getEffectivePerms());
Account owner = Provisioning.getInstance().get(AccountBy.id, folder.getFirst().getOwnerId());
if (owner == null) {
continue;
}
if ((rights & ACL.RIGHT_WRITE) > 0) {
writeProxies.add(owner);
proxies.remove(owner);
}
if ((rights & ACL.RIGHT_WRITE) == 0 && (rights & ACL.RIGHT_READ) > 0) {
if (!writeProxies.contains(owner) && !proxies.containsKey(owner)) {
Element e = DocumentHelper.createElement(DavElements.E_HREF);
e.setText(UrlNamespace.getPrincipalUrl(account, owner));
proxies.put(owner, e);
}
}
} catch (ServiceException se) {
ZimbraLog.dav.warn("can't convert rights", se);
}
}
for (Element e : proxies.values()) {
proxy.add(e);
}
return proxy;
}
use of com.zimbra.cs.mailbox.Mountpoint in project zm-mailbox by Zimbra.
the class CalendarProxyWriteFor method toElement.
@Override
public Element toElement(DavContext ctxt, Element parent, boolean nameOnly) {
Element proxy = super.toElement(ctxt, parent, true);
if (nameOnly) {
return proxy;
}
ArrayList<Pair<Mountpoint, ZFolder>> mps = getMountpoints(ctxt);
HashSet<Account> proxies = new HashSet<Account>();
for (Pair<Mountpoint, ZFolder> folder : mps) {
try {
short rights = ACL.stringToRights(folder.getSecond().getEffectivePerms());
if ((rights & ACL.RIGHT_WRITE) > 0) {
Account owner = Provisioning.getInstance().get(AccountBy.id, folder.getFirst().getOwnerId());
if (owner == null) {
continue;
}
if (!proxies.contains(owner)) {
proxy.addElement(DavElements.E_HREF).setText(UrlNamespace.getPrincipalUrl(account, owner));
proxies.add(owner);
}
}
} catch (ServiceException se) {
ZimbraLog.dav.warn("can't convert rights", se);
}
}
return proxy;
}
use of com.zimbra.cs.mailbox.Mountpoint in project zm-mailbox by Zimbra.
the class DefaultCalendarIdCallback method preModify.
@SuppressWarnings("rawtypes")
@Override
public void preModify(CallbackContext context, String attrName, Object attrValue, Map attrsToModify, Entry entry) throws ServiceException {
// validate new value 1st
if (attrValue == null) {
throw ServiceException.INVALID_REQUEST("Invalid value received for " + attrName, null);
}
Integer value = 0;
try {
if (attrValue instanceof String[]) {
String[] arr = (String[]) attrValue;
if (arr.length < 1) {
throw ServiceException.INVALID_REQUEST("Invalid value received for " + attrName, null);
}
String temp = arr[0];
if (StringUtil.isNullOrEmpty(temp)) {
throw ServiceException.INVALID_REQUEST("Invalid value received for " + attrName, null);
}
value = Integer.valueOf(temp);
} else if (attrValue instanceof String) {
String temp = (String) attrValue;
if (StringUtil.isNullOrEmpty(temp)) {
throw ServiceException.INVALID_REQUEST("Invalid value received for " + attrName, null);
}
value = Integer.valueOf(temp);
} else {
throw ServiceException.INVALID_REQUEST("Invalid value received for " + attrName, null);
}
} catch (NumberFormatException nfe) {
throw ServiceException.INVALID_REQUEST("Value for " + attrName + " must be valid integer", null);
}
if (value == 0) {
throw ServiceException.INVALID_REQUEST("Invalid value received for " + attrName, null);
}
if (entry instanceof Account) {
Account account = (Account) entry;
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
OperationContext octxt = new OperationContext(mbox);
Folder folder = mbox.getFolderById(octxt, value);
// validate if the folder exist or not
if (folder == null) {
throw ServiceException.NOT_FOUND("Folder not found for id " + value + ". Please provide valid folder id.", null);
}
// check if folder is calendar or not
if (folder.getDefaultView() != MailItem.Type.APPOINTMENT) {
throw ServiceException.INVALID_REQUEST("Folder must be a calendar folder.", null);
}
// check for permissions if it's shared calendar
if (folder.getType() == MailItem.Type.MOUNTPOINT) {
Mountpoint mp = mbox.getMountpointById(octxt, folder.getId());
String ownerId = mp.getOwnerId();
int ownerItemId = mp.getRemoteId();
FolderACL facl = new FolderACL(octxt, ownerId, ownerItemId);
boolean writeAccess = facl.canAccess(ACL.RIGHT_WRITE);
if (!writeAccess) {
throw ServiceException.PERM_DENIED(account.getMail() + " do not have enough permissions on " + folder.getName() + " to set default.");
}
}
} else if (entry instanceof Cos) {
throw ServiceException.INVALID_REQUEST("Changing value for " + attrName + " on COS is not allowed.", null);
} else if (entry != null) {
throw ServiceException.INVALID_REQUEST("Invalid entry received.", null);
}
}
use of com.zimbra.cs.mailbox.Mountpoint in project zm-mailbox by Zimbra.
the class GetFolder method handle.
@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
ZimbraSoapContext zsc = getZimbraSoapContext(context);
Mailbox mbox = getRequestedMailbox(zsc);
OperationContext octxt = getOperationContext(zsc, context);
ItemIdFormatter ifmt = new ItemIdFormatter(zsc);
ItemId iid;
Element eFolder = request.getOptionalElement(MailConstants.E_FOLDER);
if (eFolder != null) {
String uuid = eFolder.getAttribute(MailConstants.A_UUID, null);
if (uuid != null) {
Folder folder = mbox.getFolderByUuid(octxt, uuid);
iid = new ItemId(folder);
} else {
iid = new ItemId(eFolder.getAttribute(MailConstants.A_FOLDER, DEFAULT_FOLDER_ID), zsc);
}
String path = eFolder.getAttribute(MailConstants.A_PATH, null);
if (path != null) {
Pair<Folder, String> resolved = mbox.getFolderByPathLongestMatch(octxt, iid.getId(), path);
Folder folder = resolved.getFirst();
String overflow = resolved.getSecond();
if (overflow == null) {
iid = new ItemId(folder);
} else if (folder instanceof Mountpoint) {
// path crosses a mountpoint; update request and proxy to target mailbox
ItemId iidTarget = ((Mountpoint) folder).getTarget();
eFolder.addAttribute(MailConstants.A_FOLDER, iidTarget.toString()).addAttribute(MailConstants.A_PATH, overflow);
return proxyRequest(request, context, new ItemId(folder), iidTarget);
} else {
throw MailServiceException.NO_SUCH_FOLDER(path);
}
}
} else {
iid = new ItemId(DEFAULT_FOLDER_ID, zsc);
}
int depth = (int) request.getAttributeLong(MailConstants.A_FOLDER_DEPTH, -1);
boolean traverse = request.getAttributeBool(MailConstants.A_TRAVERSE, false);
boolean visible = request.getAttributeBool(MailConstants.A_VISIBLE, false);
boolean needGranteeName = request.getAttributeBool(MailConstants.A_NEED_GRANTEE_NAME, true);
String v = request.getAttribute(MailConstants.A_DEFAULT_VIEW, null);
MailItem.Type view = v == null ? null : MailItem.Type.of(v);
FolderNode rootnode = filterByView(mbox.getFolderTree(octxt, iid, visible), view);
Element response = zsc.createElement(MailConstants.GET_FOLDER_RESPONSE);
if (rootnode != null) {
if (needGranteeName) {
OperationContextData.addGranteeNames(octxt, rootnode);
} else {
OperationContextData.setNeedGranteeName(octxt, false);
}
List<ExpandableMountpoint> mounts = Lists.newArrayList();
Element folderRoot = encodeFolderNode(rootnode, response, ifmt, octxt, true, depth, view, traverse, mounts);
if (rootnode.mFolder != null && rootnode.mFolder instanceof Mountpoint) {
mounts.add(new ExpandableMountpoint(folderRoot, (Mountpoint) rootnode.mFolder, depth));
}
for (ExpandableMountpoint empt : mounts) {
expandMountpoint(empt, request, context);
}
}
return response;
}
use of com.zimbra.cs.mailbox.Mountpoint in project zm-mailbox by Zimbra.
the class GetItem method handle.
@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
ZimbraSoapContext zsc = getZimbraSoapContext(context);
Mailbox mbox = getRequestedMailbox(zsc);
OperationContext octxt = getOperationContext(zsc, context);
ItemIdFormatter ifmt = new ItemIdFormatter(zsc);
Element target = request.getElement(MailConstants.E_ITEM);
String id = target.getAttribute(MailConstants.A_ID, null);
String folderStr = target.getAttribute(MailConstants.A_FOLDER, null);
String path = target.getAttribute(MailConstants.A_PATH, target.getAttribute(MailConstants.A_NAME, null));
if (folderStr != null && path == null)
throw ServiceException.INVALID_REQUEST("missing required attribute: " + MailConstants.A_PATH, null);
MailItem item;
if (id != null) {
// get item by id
item = mbox.getItemById(octxt, new ItemId(id, zsc).getId(), MailItem.Type.UNKNOWN);
} else if (path != null) {
// get item by name within containing folder id (from root by default)
int folderId = folderStr == null ? Mailbox.ID_FOLDER_USER_ROOT : new ItemId(folderStr, zsc).getId();
try {
item = mbox.getItemByPath(octxt, path, folderId);
} catch (MailServiceException.NoSuchItemException nsie) {
Pair<Folder, String> match = mbox.getFolderByPathLongestMatch(octxt, folderId, path);
if (match.getFirst() instanceof Mountpoint) {
Mountpoint mpt = (Mountpoint) match.getFirst();
target.addAttribute(MailConstants.A_FOLDER, mpt.getRemoteId()).addAttribute(MailConstants.A_PATH, match.getSecond());
return proxyRequest(request, context, mpt.getOwnerId());
}
throw nsie;
}
} else {
throw ServiceException.INVALID_REQUEST("must specify 'id' or 'path'", null);
}
Element response = zsc.createElement(MailConstants.GET_ITEM_RESPONSE);
ToXML.encodeItem(response, ifmt, octxt, item, ToXML.NOTIFY_FIELDS);
return response;
}
Aggregations