use of com.zimbra.cs.account.Group in project zm-mailbox by Zimbra.
the class TestDelegatedDL method getDistributionListAdmin.
/*
* Test the owners element in zimbraAdmin:GetDistributionList
*/
@Test
public void getDistributionListAdmin() throws Exception {
SoapTransport transport = authAdmin(ADMIN);
com.zimbra.soap.admin.message.GetDistributionListRequest req = new com.zimbra.soap.admin.message.GetDistributionListRequest(com.zimbra.soap.admin.type.DistributionListSelector.fromName(DL_NAME));
com.zimbra.soap.admin.message.GetDistributionListResponse resp = invokeJaxb(transport, req);
com.zimbra.soap.admin.type.DistributionListInfo dlInfo = resp.getDl();
String dlId = dlInfo.getId();
Group group = prov.getGroup(Key.DistributionListBy.name, DL_NAME);
assertNotNull(group);
assertEquals(group.getId(), dlId);
/*
System.out.println("\nAttrs:");
List<com.zimbra.soap.admin.type.Attr> attrs = dlInfo.getAttrList();
for (com.zimbra.soap.admin.type.Attr attr : attrs) {
System.out.println(attr.getN() + ", " + attr.getValue());
}
*/
List<GranteeInfo> dlOwners = dlInfo.getOwners();
assertEquals(1, dlOwners.size());
for (GranteeInfo owner : dlOwners) {
com.zimbra.soap.type.GranteeType type = owner.getType();
String id = owner.getId();
String name = owner.getName();
assertEquals(com.zimbra.soap.type.GranteeType.usr, type);
assertEquals(USER_OWNER, name);
}
}
use of com.zimbra.cs.account.Group in project zm-mailbox by Zimbra.
the class TestDiscoverRights method displayName.
/*
* verify display name is returned in DiscoverRights and discovered targets
* are sorted by displayName
*/
@Test
@Bug(bug = 68225)
public void displayName() throws Exception {
Account acct = provUtil.createAccount(genAcctNameLocalPart(), domain);
String GROUP_1_NAME = getAddress(genGroupNameLocalPart("1"));
String GROUP_1_DISPLAY_NAME = "third";
String GROUP_2_NAME = getAddress(genGroupNameLocalPart("2"));
String GROUP_2_DISPLAY_NAME = "first";
String GROUP_3_NAME = getAddress(genGroupNameLocalPart("3"));
String GROUP_3_DISPLAY_NAME = "first";
Group group1 = provUtil.createGroup(GROUP_1_NAME, Collections.singletonMap(Provisioning.A_displayName, (Object) GROUP_1_DISPLAY_NAME), false);
Group group2 = provUtil.createGroup(GROUP_2_NAME, Collections.singletonMap(Provisioning.A_displayName, (Object) GROUP_2_DISPLAY_NAME), false);
Group group3 = provUtil.createGroup(GROUP_3_NAME, Collections.singletonMap(Provisioning.A_displayName, (Object) GROUP_3_DISPLAY_NAME), false);
String RIGHT_NAME = User.R_ownDistList.getName();
prov.grantRight(TargetType.dl.getCode(), TargetBy.name, group1.getName(), GranteeType.GT_USER.getCode(), GranteeBy.name, acct.getName(), null, RIGHT_NAME, null);
prov.grantRight(TargetType.dl.getCode(), TargetBy.name, group2.getName(), GranteeType.GT_USER.getCode(), GranteeBy.name, acct.getName(), null, RIGHT_NAME, null);
prov.grantRight(TargetType.dl.getCode(), TargetBy.name, group3.getName(), GranteeType.GT_USER.getCode(), GranteeBy.name, acct.getName(), null, RIGHT_NAME, null);
SoapTransport transport = authUser(acct.getName());
DiscoverRightsRequest req = new DiscoverRightsRequest(Collections.singletonList(RIGHT_NAME));
DiscoverRightsResponse resp = invokeJaxb(transport, req);
List<DiscoverRightsInfo> rightsInfo = resp.getDiscoveredRights();
assertEquals(1, rightsInfo.size());
List<String> result = Lists.newArrayList();
for (DiscoverRightsInfo rightInfo : rightsInfo) {
List<DiscoverRightsTarget> targets = rightInfo.getTargets();
for (DiscoverRightsTarget target : targets) {
String id = target.getId();
String name = target.getName();
String displayName = target.getDisplayName();
result.add(Verify.makeResultStr(id, name, displayName));
}
}
// result should be sorted by displayName.
// If displayName are the same, sorted by entry.getLabel()
Verify.verifyEquals(Lists.newArrayList(Verify.makeResultStr(group2.getId(), group2.getName(), group2.getDisplayName()), Verify.makeResultStr(group3.getId(), group3.getName(), group3.getDisplayName()), Verify.makeResultStr(group1.getId(), group1.getName(), group1.getDisplayName())), result);
}
use of com.zimbra.cs.account.Group in project zm-mailbox by Zimbra.
the class TestDelegatedDL method distributionListActionAddRemoveMembers.
@Test
public void distributionListActionAddRemoveMembers() throws Exception {
SoapTransport transport = authUser(USER_OWNER);
// addMembers
DistributionListAction action = new DistributionListAction(Operation.addMembers);
DistributionListActionRequest req = new DistributionListActionRequest(DistributionListSelector.fromName(DL_NAME), action);
Account member1 = provUtil.createAccount(genAcctNameLocalPart("member1"), domain);
Account member2 = provUtil.createAccount(genAcctNameLocalPart("member2"), domain);
String MEMBER1 = member1.getName();
String MEMBER2 = member2.getName();
action.addMember(MEMBER1);
action.addMember(MEMBER2);
DistributionListActionResponse resp = invokeJaxb(transport, req);
Group group = prov.getGroup(Key.DistributionListBy.name, DL_NAME);
Set<String> members = group.getAllMembersSet();
Verify.verifyEquals(Sets.newHashSet(MEMBER1, MEMBER2), members);
// removeMembers
action = new DistributionListAction(Operation.removeMembers);
req = new DistributionListActionRequest(DistributionListSelector.fromName(DL_NAME), action);
action.addMember(MEMBER1);
action.addMember(MEMBER2);
resp = invokeJaxb(transport, req);
group = prov.getGroup(Key.DistributionListBy.name, DL_NAME);
members = group.getAllMembersSet();
assertEquals(0, members.size());
}
use of com.zimbra.cs.account.Group in project zm-mailbox by Zimbra.
the class TestDelegatedDL method distributionListActionAddRemoveOwners.
@Test
public void distributionListActionAddRemoveOwners() throws Exception {
String GROUP_NAME = getAddress(genGroupNameLocalPart("group"));
Group group = createGroupAndAddOwner(GROUP_NAME);
Account owner1 = provUtil.createAccount(genAcctNameLocalPart("1"), domain);
Account owner2 = provUtil.createAccount(genAcctNameLocalPart("2"), domain);
SoapTransport transport = authUser(USER_OWNER);
//
// addOwners
//
DistributionListAction action = new DistributionListAction(Operation.addOwners);
DistributionListActionRequest req = new DistributionListActionRequest(DistributionListSelector.fromName(GROUP_NAME), action);
action.addOwner(new DistributionListGranteeSelector(com.zimbra.soap.type.GranteeType.usr, DistributionListGranteeBy.name, USER_OWNER));
action.addOwner(new DistributionListGranteeSelector(com.zimbra.soap.type.GranteeType.usr, DistributionListGranteeBy.name, owner1.getName()));
action.addOwner(new DistributionListGranteeSelector(com.zimbra.soap.type.GranteeType.usr, DistributionListGranteeBy.name, owner2.getName()));
DistributionListActionResponse resp = invokeJaxb(transport, req);
//
// verify owners are added
//
GetDistributionListRequest getDLReq = new GetDistributionListRequest(DistributionListSelector.fromName(GROUP_NAME), Boolean.TRUE);
GetDistributionListResponse getDLResp = invokeJaxb(transport, getDLReq);
DistributionListInfo dlInfo = getDLResp.getDl();
List<? extends DistributionListGranteeInfoInterface> owners = dlInfo.getOwners();
Set<String> ownerNames = Sets.newHashSet();
for (DistributionListGranteeInfoInterface owner : owners) {
if (owner.getType() == com.zimbra.soap.type.GranteeType.usr) {
ownerNames.add(owner.getName());
}
}
assertEquals(3, owners.size());
Verify.verifyEquals(Sets.newHashSet(USER_OWNER, owner1.getName(), owner2.getName()), ownerNames);
//
// removeOwners
//
action = new DistributionListAction(Operation.removeOwners);
req = new DistributionListActionRequest(DistributionListSelector.fromName(GROUP_NAME), action);
action.addOwner(new DistributionListGranteeSelector(com.zimbra.soap.type.GranteeType.usr, DistributionListGranteeBy.name, owner1.getName()));
action.addOwner(new DistributionListGranteeSelector(com.zimbra.soap.type.GranteeType.usr, DistributionListGranteeBy.name, owner2.getName()));
resp = invokeJaxb(transport, req);
//
// verify owners are removed
//
getDLReq = new GetDistributionListRequest(DistributionListSelector.fromName(GROUP_NAME), Boolean.TRUE);
getDLResp = invokeJaxb(transport, getDLReq);
dlInfo = getDLResp.getDl();
owners = dlInfo.getOwners();
ownerNames = Sets.newHashSet();
for (DistributionListGranteeInfoInterface owner : owners) {
if (owner.getType() == com.zimbra.soap.type.GranteeType.usr) {
ownerNames.add(owner.getName());
}
}
assertEquals(1, owners.size());
Verify.verifyEquals(Sets.newHashSet(USER_OWNER), ownerNames);
}
use of com.zimbra.cs.account.Group in project zm-mailbox by Zimbra.
the class DistributionListAction method handle.
@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
ZimbraSoapContext zsc = getZimbraSoapContext(context);
Provisioning prov = Provisioning.getInstance();
Account acct = getAuthenticatedAccount(zsc);
Group group = getGroupBasic(request, prov);
DistributionListActionHandler handler = new DistributionListActionHandler(group, request, prov, acct);
handler.handle();
Element response = zsc.createElement(AccountConstants.DISTRIBUTION_LIST_ACTION_RESPONSE);
return response;
}
Aggregations