Search in sources :

Example 1 with SendShareNotificationRequest

use of com.zimbra.soap.mail.message.SendShareNotificationRequest in project zm-mailbox by Zimbra.

the class AbstractCalendarProxy method changeGroupMembership.

/**
     * Reflect changes in membership, i.e. invite new members and revoke access to people no longer in the group.
     * Note that we are only dealing with the default Calendar - the Apple model doesn't talk about things at
     * the calendar level - so for our purposes we shall assume it only applies to that calendar.
     */
private void changeGroupMembership(DavContext ctxt, Set<Account> invitees, Set<Account> revokees, short role) {
    try {
        Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(getAccount());
        ZMailbox zmbox = ctxt.getZMailbox(getAccount());
        List<EmailAddrInfo> emailAddresses = Lists.newArrayList();
        for (Account target : invitees) {
            mbox.grantAccess(ctxt.getOperationContext(), Mailbox.ID_FOLDER_CALENDAR, target.getId(), ACL.GRANTEE_USER, role, null);
            emailAddresses.add(new EmailAddrInfo(target.getName()));
        }
        SendShareNotificationRequest ssnreq;
        if (!emailAddresses.isEmpty()) {
            ssnreq = SendShareNotificationRequest.create(Mailbox.ID_FOLDER_CALENDAR, null, /* SendShareNotificationRequest.Action */
            null, /* notes */
            emailAddresses);
            zmbox.invokeJaxb(ssnreq);
        }
        emailAddresses = Lists.newArrayList();
        for (Account target : revokees) {
            mbox.revokeAccess(ctxt.getOperationContext(), Mailbox.ID_FOLDER_CALENDAR, target.getId());
            emailAddresses.add(new EmailAddrInfo(target.getName()));
        }
        if (!emailAddresses.isEmpty()) {
            ssnreq = SendShareNotificationRequest.create(Mailbox.ID_FOLDER_CALENDAR, SendShareNotificationRequest.Action.revoke, null, /* notes */
            emailAddresses);
            zmbox.invokeJaxb(ssnreq);
        }
    } catch (ServiceException se) {
        ZimbraLog.dav.warn("can't modify acl on %s for %s", getAccount().getName(), ctxt.getPath());
    }
}
Also used : Account(com.zimbra.cs.account.Account) ZMailbox(com.zimbra.client.ZMailbox) Mailbox(com.zimbra.cs.mailbox.Mailbox) ZMailbox(com.zimbra.client.ZMailbox) ServiceException(com.zimbra.common.service.ServiceException) EmailAddrInfo(com.zimbra.soap.mail.type.EmailAddrInfo) SendShareNotificationRequest(com.zimbra.soap.mail.message.SendShareNotificationRequest)

Example 2 with SendShareNotificationRequest

use of com.zimbra.soap.mail.message.SendShareNotificationRequest in project zm-mailbox by Zimbra.

the class TestShareNotifications method testMultipleCalendarShareNotifications.

public void testMultipleCalendarShareNotifications() throws Exception {
    Account senderAccount = TestUtil.createAccount(SENDER_NAME);
    Account recipientAccount = TestUtil.createAccount(RECIPIENT_NAME);
    ZMailbox mbox = TestUtil.getZMailbox(SENDER_NAME);
    // check that there are no share notifications in the recipient's mailbox
    ZMailbox recipientMbox = TestUtil.getZMailbox(RECIPIENT_NAME);
    List<ShareNotificationInfo> shares = waitForShareNotifications(recipientMbox, 0, 100);
    assertEquals("Recipient should have exactly 0 share notification", 0, shares.size());
    // create and share the first calendar
    ZFolder newCal = TestUtil.createFolder(mbox, CAL_NAME1, ZFolder.View.appointment);
    String calendarId = newCal.getId();
    FolderActionSelector action = new FolderActionSelector(calendarId, "grant");
    ActionGrantSelector grant = new ActionGrantSelector("r", "usr");
    grant.setDisplayName(recipientAccount.getName());
    grant.setPassword("");
    action.setGrant(grant);
    FolderActionRequest folderActionReq = new FolderActionRequest(action);
    FolderActionResponse folderActionResp = mbox.invokeJaxb(folderActionReq);
    assertNotNull("FolderActionResponse is null", folderActionResp);
    SendShareNotificationRequest shareNotificationReq = new SendShareNotificationRequest();
    shareNotificationReq.setItem(new com.zimbra.soap.type.Id(calendarId));
    shareNotificationReq.addEmailAddress(new EmailAddrInfo(recipientAccount.getMail()));
    SendShareNotificationResponse resp = mbox.invokeJaxb(shareNotificationReq);
    assertNotNull("ShareNotificationResponse is null", resp);
    // create and share the second calendar
    ZFolder newCal2 = TestUtil.createFolder(mbox, CAL_NAME2, ZFolder.View.appointment);
    String calendarId2 = newCal2.getId();
    action = new FolderActionSelector(calendarId2, "grant");
    grant = new ActionGrantSelector("r", "usr");
    grant.setDisplayName(recipientAccount.getName());
    grant.setPassword("");
    action.setGrant(grant);
    folderActionReq = new FolderActionRequest(action);
    folderActionResp = mbox.invokeJaxb(folderActionReq);
    assertNotNull("FolderActionResponse is null", folderActionResp);
    shareNotificationReq = new SendShareNotificationRequest();
    shareNotificationReq.setItem(new com.zimbra.soap.type.Id(calendarId2));
    shareNotificationReq.addEmailAddress(new EmailAddrInfo(recipientAccount.getMail()));
    resp = mbox.invokeJaxb(shareNotificationReq);
    assertNotNull("ShareNotificationResponse is null", resp);
    shares = waitForShareNotifications(recipientMbox, 2, 1000);
    assertEquals("should have exactly two share notification", 2, shares.size());
    assertNotNull("share grantor is null", shares.get(0).getGrantor());
    assertTrue("share grantor is not " + senderAccount.getMail(), senderAccount.getMail().equalsIgnoreCase(shares.get(0).getGrantor().getEmail()));
}
Also used : Account(com.zimbra.cs.account.Account) FolderActionResponse(com.zimbra.soap.mail.message.FolderActionResponse) SendShareNotificationResponse(com.zimbra.soap.mail.message.SendShareNotificationResponse) ActionGrantSelector(com.zimbra.soap.mail.type.ActionGrantSelector) FolderActionSelector(com.zimbra.soap.mail.type.FolderActionSelector) ZMailbox(com.zimbra.client.ZMailbox) ShareNotificationInfo(com.zimbra.soap.mail.type.ShareNotificationInfo) FolderActionRequest(com.zimbra.soap.mail.message.FolderActionRequest) EmailAddrInfo(com.zimbra.soap.mail.type.EmailAddrInfo) ZFolder(com.zimbra.client.ZFolder) SendShareNotificationRequest(com.zimbra.soap.mail.message.SendShareNotificationRequest)

Example 3 with SendShareNotificationRequest

use of com.zimbra.soap.mail.message.SendShareNotificationRequest in project zm-mailbox by Zimbra.

the class TestShareNotifications method testCalendarShareNotification.

public void testCalendarShareNotification() throws Exception {
    Account senderAccount = TestUtil.createAccount(SENDER_NAME);
    Account recipientAccount = TestUtil.createAccount(RECIPIENT_NAME);
    ZMailbox mbox = TestUtil.getZMailbox(SENDER_NAME);
    // check that there are no share notifications in the recipient's mailbox
    ZMailbox recipientMbox = TestUtil.getZMailbox(RECIPIENT_NAME);
    List<ShareNotificationInfo> shares = waitForShareNotifications(recipientMbox, 0, 100);
    assertEquals("Recipient should have exactly 0 share notification", 0, shares.size());
    ZFolder newCal = TestUtil.createFolder(mbox, CAL_NAME1, ZFolder.View.appointment);
    String calendarId = newCal.getId();
    FolderActionSelector action = new FolderActionSelector(calendarId, "grant");
    ActionGrantSelector grant = new ActionGrantSelector("r", "usr");
    grant.setDisplayName(recipientAccount.getName());
    grant.setPassword("");
    action.setGrant(grant);
    FolderActionRequest folderActionReq = new FolderActionRequest(action);
    FolderActionResponse folderActionResp = mbox.invokeJaxb(folderActionReq);
    assertNotNull("FolderActionResponse is null", folderActionResp);
    SendShareNotificationRequest shareNotificationReq = new SendShareNotificationRequest();
    shareNotificationReq.setItem(new com.zimbra.soap.type.Id(calendarId));
    shareNotificationReq.addEmailAddress(new EmailAddrInfo(recipientAccount.getMail()));
    SendShareNotificationResponse resp = mbox.invokeJaxb(shareNotificationReq);
    assertNotNull("ShareNotificationResponse is null", resp);
    shares = waitForShareNotifications(recipientMbox, 1, 1000);
    assertTrue("should have exactly one share notification", shares.size() == 1);
    assertNotNull("share grantor is null", shares.get(0).getGrantor());
    assertTrue("share grantor is not " + senderAccount.getMail(), senderAccount.getMail().equalsIgnoreCase(shares.get(0).getGrantor().getEmail()));
}
Also used : Account(com.zimbra.cs.account.Account) FolderActionResponse(com.zimbra.soap.mail.message.FolderActionResponse) SendShareNotificationResponse(com.zimbra.soap.mail.message.SendShareNotificationResponse) ActionGrantSelector(com.zimbra.soap.mail.type.ActionGrantSelector) FolderActionSelector(com.zimbra.soap.mail.type.FolderActionSelector) ZMailbox(com.zimbra.client.ZMailbox) ShareNotificationInfo(com.zimbra.soap.mail.type.ShareNotificationInfo) FolderActionRequest(com.zimbra.soap.mail.message.FolderActionRequest) EmailAddrInfo(com.zimbra.soap.mail.type.EmailAddrInfo) ZFolder(com.zimbra.client.ZFolder) SendShareNotificationRequest(com.zimbra.soap.mail.message.SendShareNotificationRequest)

Example 4 with SendShareNotificationRequest

use of com.zimbra.soap.mail.message.SendShareNotificationRequest 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 = JaxbUtil.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)

Example 5 with SendShareNotificationRequest

use of com.zimbra.soap.mail.message.SendShareNotificationRequest in project zm-mailbox by Zimbra.

the class TestShareNotifications method testContactShareNotification.

public void testContactShareNotification() throws Exception {
    Account senderAccount = TestUtil.createAccount(SENDER_NAME);
    Account recipientAccount = TestUtil.createAccount(RECIPIENT_NAME);
    ZMailbox mbox = TestUtil.getZMailbox(SENDER_NAME);
    // check that there are no share notifications in the recipient's mailbox
    ZMailbox recipientMbox = TestUtil.getZMailbox(RECIPIENT_NAME);
    List<ShareNotificationInfo> shares = waitForShareNotifications(recipientMbox, 0, 100);
    assertEquals("Recipient should have exactly 0 share notification", 0, shares.size());
    // create and share the first calendar
    ZFolder newContactsFolder = TestUtil.createFolder(mbox, CAL_NAME1, ZFolder.View.contact);
    String contactsFolderId = newContactsFolder.getId();
    FolderActionSelector action = new FolderActionSelector(contactsFolderId, "grant");
    ActionGrantSelector grant = new ActionGrantSelector("r", "usr");
    grant.setDisplayName(recipientAccount.getName());
    grant.setPassword("");
    action.setGrant(grant);
    FolderActionRequest folderActionReq = new FolderActionRequest(action);
    FolderActionResponse folderActionResp = mbox.invokeJaxb(folderActionReq);
    assertNotNull("FolderActionResponse is null", folderActionResp);
    SendShareNotificationRequest shareNotificationReq = new SendShareNotificationRequest();
    shareNotificationReq.setItem(new com.zimbra.soap.type.Id(contactsFolderId));
    shareNotificationReq.addEmailAddress(new EmailAddrInfo(recipientAccount.getMail()));
    SendShareNotificationResponse resp = mbox.invokeJaxb(shareNotificationReq);
    assertNotNull("ShareNotificationResponse is null", resp);
    shares = waitForShareNotifications(recipientMbox, 1, 1000);
    assertEquals("should have exactly one share notification", 1, shares.size());
    assertNotNull("share grantor is null", shares.get(0).getGrantor());
    assertTrue("share grantor is not " + senderAccount.getMail(), senderAccount.getMail().equalsIgnoreCase(shares.get(0).getGrantor().getEmail()));
}
Also used : Account(com.zimbra.cs.account.Account) FolderActionResponse(com.zimbra.soap.mail.message.FolderActionResponse) SendShareNotificationResponse(com.zimbra.soap.mail.message.SendShareNotificationResponse) ActionGrantSelector(com.zimbra.soap.mail.type.ActionGrantSelector) FolderActionSelector(com.zimbra.soap.mail.type.FolderActionSelector) ZMailbox(com.zimbra.client.ZMailbox) ShareNotificationInfo(com.zimbra.soap.mail.type.ShareNotificationInfo) FolderActionRequest(com.zimbra.soap.mail.message.FolderActionRequest) EmailAddrInfo(com.zimbra.soap.mail.type.EmailAddrInfo) ZFolder(com.zimbra.client.ZFolder) SendShareNotificationRequest(com.zimbra.soap.mail.message.SendShareNotificationRequest)

Aggregations

SendShareNotificationRequest (com.zimbra.soap.mail.message.SendShareNotificationRequest)7 EmailAddrInfo (com.zimbra.soap.mail.type.EmailAddrInfo)7 Account (com.zimbra.cs.account.Account)6 ZMailbox (com.zimbra.client.ZMailbox)5 ZFolder (com.zimbra.client.ZFolder)4 FolderActionRequest (com.zimbra.soap.mail.message.FolderActionRequest)4 FolderActionResponse (com.zimbra.soap.mail.message.FolderActionResponse)4 SendShareNotificationResponse (com.zimbra.soap.mail.message.SendShareNotificationResponse)4 ActionGrantSelector (com.zimbra.soap.mail.type.ActionGrantSelector)4 FolderActionSelector (com.zimbra.soap.mail.type.FolderActionSelector)4 ShareNotificationInfo (com.zimbra.soap.mail.type.ShareNotificationInfo)4 ServiceException (com.zimbra.common.service.ServiceException)2 Element (com.zimbra.common.soap.Element)1 Domain (com.zimbra.cs.account.Domain)1 Group (com.zimbra.cs.account.Group)1 MailTarget (com.zimbra.cs.account.MailTarget)1 NamedEntry (com.zimbra.cs.account.NamedEntry)1 Provisioning (com.zimbra.cs.account.Provisioning)1 ShareInfoData (com.zimbra.cs.account.ShareInfoData)1 MailItem (com.zimbra.cs.mailbox.MailItem)1