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());
}
}
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()));
}
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()));
}
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;
}
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()));
}
Aggregations