Search in sources :

Example 41 with Mountpoint

use of com.zimbra.cs.mailbox.Mountpoint in project zm-mailbox by Zimbra.

the class SendShareNotification method getMatchingGrantLocal.

private MatchingGrant getMatchingGrantLocal(OperationContext octxt, MailItem item, byte granteeType, String granteeId, Account ownerAcct) throws ServiceException {
    if (item instanceof Mountpoint) {
        Mailbox ownerMbox = MailboxManager.getInstance().getMailboxByAccount(ownerAcct, false);
        if (ownerMbox == null) {
            throw ServiceException.FAILURE("mailbox not found for account " + ownerAcct.getId(), null);
        }
        item = ownerMbox.getItemById(octxt, ((Mountpoint) item).getRemoteId(), MailItem.Type.UNKNOWN);
    }
    ACL acl = item.getEffectiveACL();
    if (acl == null) {
        return null;
    }
    for (ACL.Grant grant : acl.getGrants()) {
        if (grant.getGranteeType() == granteeType && grant.getGranteeId().equals(granteeId)) {
            return new MatchingGrant(grant);
        }
    }
    return null;
}
Also used : Mailbox(com.zimbra.cs.mailbox.Mailbox) ACL(com.zimbra.cs.mailbox.ACL) Mountpoint(com.zimbra.cs.mailbox.Mountpoint)

Example 42 with Mountpoint

use of com.zimbra.cs.mailbox.Mountpoint in project zm-mailbox by Zimbra.

the class SendShareNotification method validateShareRecipient.

@Deprecated
private ShareInfoData validateShareRecipient(ZimbraSoapContext zsc, Map<String, Object> context, OperationContext octxt, Mailbox mbox, Element eShare) throws ServiceException {
    Provisioning prov = Provisioning.getInstance();
    // 
    // grantee
    // 
    byte granteeType = ACL.stringToType(eShare.getAttribute(MailConstants.A_GRANT_TYPE));
    String granteeId = eShare.getAttribute(MailConstants.A_ZIMBRA_ID, null);
    String granteeName = eShare.getAttribute(MailConstants.A_DISPLAY, null);
    // grantee id to match grant
    String matchingId;
    // email of the grantee, will be he recipient or the share notif message
    String granteeEmail;
    // display name, if set, of the grantee
    String granteeDisplayName;
    if (granteeType == ACL.GRANTEE_GUEST) {
        if (granteeName == null) {
            throw ServiceException.INVALID_REQUEST("must specify grantee name for guest grantee type", null);
        }
        // if guest, matchingId is the same as granteeEmail
        matchingId = granteeName;
        granteeEmail = granteeName;
        granteeDisplayName = granteeEmail;
    } else {
        Pair<NamedEntry, String> grantee;
        try {
            grantee = getGrantee(zsc, granteeType, granteeId, granteeName);
        } catch (ServiceException e) {
            if (e.getCode().equals(MailServiceException.NO_SUCH_GRANTEE)) {
                throw ServiceException.INVALID_REQUEST("no such grantee", e);
            }
            throw e;
        }
        NamedEntry granteeEntry = grantee.getFirst();
        matchingId = granteeEntry.getId();
        granteeEmail = granteeEntry.getName();
        granteeDisplayName = grantee.getSecond();
    }
    // 
    // folder
    // 
    Account account = getRequestedAccount(zsc);
    Folder folder = getFolder(octxt, account, mbox, eShare);
    Account ownerAcct = account;
    // if the folder is a mountpoint, set correct ownerAcct and the folder id in the owner's mailbox
    if (folder instanceof Mountpoint) {
        Mountpoint mp = (Mountpoint) folder;
        ownerAcct = prov.get(AccountBy.id, mp.getOwnerId());
        folder = mp;
    }
    return getShareInfoData(zsc, context, ownerAcct, octxt, granteeType, granteeEmail, matchingId, granteeDisplayName, folder, false);
}
Also used : NamedEntry(com.zimbra.cs.account.NamedEntry) Account(com.zimbra.cs.account.Account) ServiceException(com.zimbra.common.service.ServiceException) MailServiceException(com.zimbra.cs.mailbox.MailServiceException) Folder(com.zimbra.cs.mailbox.Folder) Mountpoint(com.zimbra.cs.mailbox.Mountpoint) Provisioning(com.zimbra.cs.account.Provisioning)

Example 43 with Mountpoint

use of com.zimbra.cs.mailbox.Mountpoint in project zm-mailbox by Zimbra.

the class SendShareNotification method validateRequest.

private Collection<ShareInfoData> validateRequest(ZimbraSoapContext zsc, Map<String, Object> context, OperationContext octxt, Mailbox mbox, Element request) throws ServiceException {
    Element eShare = request.getOptionalElement(MailConstants.E_SHARE);
    if (eShare != null) {
        return Arrays.asList(validateShareRecipient(zsc, context, octxt, mbox, eShare));
    }
    String action = request.getAttribute(MailConstants.A_ACTION, null);
    ArrayList<ShareInfoData> shareInfos = new ArrayList<ShareInfoData>();
    SendShareNotificationRequest req = zsc.elementToJaxb(request);
    ItemId iid = new ItemId(req.getItem().getId(), zsc);
    MailItem item = mbox.getItemById(octxt, iid.getId(), MailItem.Type.UNKNOWN);
    Provisioning prov = Provisioning.getInstance();
    Account account = getRequestedAccount(zsc);
    if (item instanceof Mountpoint) {
        Mountpoint mp = (Mountpoint) item;
        account = prov.get(AccountBy.id, mp.getOwnerId());
    }
    for (EmailAddrInfo email : req.getEmailAddresses()) {
        // add the non-existing grantee as type GRANTEE_GUEST for share notification.
        // for revoke notifications return the non-existing grantees only
        Pair<NamedEntry, String> grantee;
        boolean guestGrantee = false;
        byte granteeType = ACL.GRANTEE_USER;
        String granteeId = null;
        String granteeEmail = email.getAddress();
        String granteeDisplayName = null;
        try {
            grantee = getGrantee(zsc, granteeType, granteeId, granteeEmail);
            NamedEntry entry = grantee.getFirst();
            if (entry instanceof MailTarget) {
                Domain domain = prov.getDomain(account);
                String granteeDomainName = ((MailTarget) entry).getDomainName();
                if (domain.isInternalSharingCrossDomainEnabled() || domain.getName().equals(granteeDomainName) || Sets.newHashSet(domain.getInternalSharingDomain()).contains(granteeDomainName)) {
                    if (entry instanceof Group) {
                        granteeType = ACL.GRANTEE_GROUP;
                    }
                    granteeId = entry.getId();
                    granteeDisplayName = grantee.getSecond();
                } else {
                    guestGrantee = true;
                }
            }
        } catch (ServiceException e) {
            if (!e.getCode().equals(MailServiceException.NO_SUCH_GRANTEE)) {
                throw e;
            }
            guestGrantee = true;
        }
        if (guestGrantee) {
            granteeType = ACL.GRANTEE_GUEST;
            // if guest, granteeId is the same as granteeEmail
            granteeId = granteeEmail;
        }
        shareInfos.add(getShareInfoData(zsc, context, account, octxt, granteeType, granteeEmail, granteeId, granteeDisplayName, item, REVOKE.equals(action)));
    }
    return shareInfos;
}
Also used : Account(com.zimbra.cs.account.Account) Group(com.zimbra.cs.account.Group) Element(com.zimbra.common.soap.Element) ShareInfoData(com.zimbra.cs.account.ShareInfoData) ArrayList(java.util.ArrayList) MailTarget(com.zimbra.cs.account.MailTarget) ItemId(com.zimbra.cs.service.util.ItemId) Provisioning(com.zimbra.cs.account.Provisioning) NamedEntry(com.zimbra.cs.account.NamedEntry) MailItem(com.zimbra.cs.mailbox.MailItem) ServiceException(com.zimbra.common.service.ServiceException) MailServiceException(com.zimbra.cs.mailbox.MailServiceException) EmailAddrInfo(com.zimbra.soap.mail.type.EmailAddrInfo) SendShareNotificationRequest(com.zimbra.soap.mail.message.SendShareNotificationRequest) Domain(com.zimbra.cs.account.Domain) Mountpoint(com.zimbra.cs.mailbox.Mountpoint)

Aggregations

Mountpoint (com.zimbra.cs.mailbox.Mountpoint)43 Folder (com.zimbra.cs.mailbox.Folder)30 ServiceException (com.zimbra.common.service.ServiceException)23 Mailbox (com.zimbra.cs.mailbox.Mailbox)18 Account (com.zimbra.cs.account.Account)17 MailItem (com.zimbra.cs.mailbox.MailItem)14 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)14 ZFolder (com.zimbra.client.ZFolder)11 ItemId (com.zimbra.cs.service.util.ItemId)11 ZMailbox (com.zimbra.client.ZMailbox)8 Element (com.zimbra.common.soap.Element)8 OperationContext (com.zimbra.cs.mailbox.OperationContext)8 IOException (java.io.IOException)8 HashMap (java.util.HashMap)8 Provisioning (com.zimbra.cs.account.Provisioning)6 SearchFolder (com.zimbra.cs.mailbox.SearchFolder)6 ZMountpoint (com.zimbra.client.ZMountpoint)5 Pair (com.zimbra.common.util.Pair)5 NoSuchItemException (com.zimbra.cs.mailbox.MailServiceException.NoSuchItemException)5 ItemIdFormatter (com.zimbra.cs.service.util.ItemIdFormatter)5