use of com.zimbra.cs.account.Signature in project zm-mailbox by Zimbra.
the class TestLdapProvSignature method getAllSignatures.
@Test
public void getAllSignatures() throws Exception {
String ACCT_NAME_LOCALPART = Names.makeAccountNameLocalPart(genAcctNameLocalPart());
String SIGNATURE_NAME_1 = Names.makeSignatureName(genSignatureName("1"));
String SIGNATURE_NAME_2 = Names.makeSignatureName(genSignatureName("2"));
String SIGNATURE_NAME_3 = Names.makeSignatureName(genSignatureName("3"));
Account acct = createAccount(ACCT_NAME_LOCALPART);
Signature signature1 = createSignature(acct, SIGNATURE_NAME_1);
Signature signature2 = createSignature(acct, SIGNATURE_NAME_2);
Signature signature3 = createSignature(acct, SIGNATURE_NAME_3);
acct = getFresh(acct);
List<Signature> allSignatures = prov.getAllSignatures(acct);
assertEquals(3, allSignatures.size());
Set<String> allSignatureIds = new HashSet<String>();
for (Signature signature : allSignatures) {
allSignatureIds.add(signature.getId());
}
assertTrue(allSignatureIds.contains(signature1.getId()));
assertTrue(allSignatureIds.contains(signature2.getId()));
assertTrue(allSignatureIds.contains(signature3.getId()));
deleteSignature(acct, signature1);
deleteSignature(acct, signature2);
deleteSignature(acct, signature3);
deleteAccount(acct);
}
use of com.zimbra.cs.account.Signature in project zm-mailbox by Zimbra.
the class CreateSignature method handle.
public Element handle(Element request, Map<String, Object> context) throws ServiceException, SoapFaultException {
ZimbraSoapContext zsc = getZimbraSoapContext(context);
Account account = getRequestedAccount(zsc);
if (!canModifyOptions(zsc, account))
throw ServiceException.PERM_DENIED("can not modify options");
Element eReqSignature = request.getElement(AccountConstants.E_SIGNATURE);
String name = eReqSignature.getAttribute(AccountConstants.A_NAME);
String id = eReqSignature.getAttribute(AccountConstants.A_ID, null);
List<Element> contents = eReqSignature.listElements(AccountConstants.E_CONTENT);
Map<String, Object> attrs = new HashMap<String, Object>();
for (Element eContent : contents) {
String type = eContent.getAttribute(AccountConstants.A_TYPE);
String attr = SignatureUtil.mimeTypeToAttrName(type);
if (attr == null)
throw ServiceException.INVALID_REQUEST("invalid type " + type, null);
if (attrs.get(attr) != null)
throw ServiceException.INVALID_REQUEST("only one " + type + " content is allowed", null);
String content = eContent.getText();
if (!StringUtil.isNullOrEmpty(content))
attrs.put(attr, content);
}
if (id != null)
attrs.put(Provisioning.A_zimbraSignatureId, id);
Element eContactId = eReqSignature.getOptionalElement(AccountConstants.E_CONTACT_ID);
if (eContactId != null)
attrs.put(Provisioning.A_zimbraPrefMailSignatureContactId, eContactId.getText());
Signature signature = Provisioning.getInstance().createSignature(account, name, attrs);
Element response = zsc.createElement(AccountConstants.CREATE_SIGNATURE_RESPONSE);
Element eRespSignature = response.addElement(AccountConstants.E_SIGNATURE);
eRespSignature.addAttribute(AccountConstants.A_ID, signature.getId());
eRespSignature.addAttribute(AccountConstants.A_NAME, signature.getName());
return response;
}
use of com.zimbra.cs.account.Signature in project zm-mailbox by Zimbra.
the class DeleteSignature method handle.
public Element handle(Element request, Map<String, Object> context) throws ServiceException, SoapFaultException {
ZimbraSoapContext zsc = getZimbraSoapContext(context);
Account account = getRequestedAccount(zsc);
if (!canModifyOptions(zsc, account))
throw ServiceException.PERM_DENIED("can not modify options");
Provisioning prov = Provisioning.getInstance();
Element eSignature = request.getElement(AccountConstants.E_SIGNATURE);
// signature can be specified by name or by ID
Signature signature = null;
String sigStr = eSignature.getAttribute(AccountConstants.A_ID, null);
if (sigStr != null) {
signature = prov.get(account, Key.SignatureBy.id, sigStr);
} else {
sigStr = eSignature.getAttribute(AccountConstants.A_NAME);
signature = prov.get(account, Key.SignatureBy.name, sigStr);
}
if (signature != null)
Provisioning.getInstance().deleteSignature(account, signature.getId());
else
throw AccountServiceException.NO_SUCH_SIGNATURE(sigStr);
Element response = zsc.createElement(AccountConstants.DELETE_SIGNATURE_RESPONSE);
return response;
}
use of com.zimbra.cs.account.Signature in project zm-mailbox by Zimbra.
the class TestAccess method ModifySignature.
public void ModifySignature(Role role, Perm perm) throws Exception {
String signatureName = "signature-modify-" + random();
Signature signature = mProvAdmin.createSignature(mProvAdmin.get(Key.AccountBy.id, ACCT_1_ID), signatureName, new HashMap<String, Object>());
XMLElement req = new XMLElement(AccountConstants.MODIFY_SIGNATURE_REQUEST);
Element identity = req.addElement(AccountConstants.E_SIGNATURE);
identity.addAttribute(AccountConstants.A_ID, signature.getId());
accessTest(role, perm, req);
}
use of com.zimbra.cs.account.Signature in project zm-mailbox by Zimbra.
the class TestAccess method DeleteSignature.
public void DeleteSignature(Role role, Perm perm) throws Exception {
String signatureName = "signature-delete-" + random();
Signature signature = mProvAdmin.createSignature(mProvAdmin.get(Key.AccountBy.id, ACCT_1_ID), signatureName, new HashMap<String, Object>());
XMLElement req = new XMLElement(AccountConstants.DELETE_SIGNATURE_REQUEST);
Element identity = req.addElement(AccountConstants.E_SIGNATURE);
identity.addAttribute(AccountConstants.A_ID, signature.getId());
accessTest(role, perm, req);
}
Aggregations