Search in sources :

Example 21 with CalendarResource

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

the class DeleteCalendarResource method handle.

/**
 * Deletes a calendar resource account and its mailbox.
 */
@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    Provisioning prov = Provisioning.getInstance();
    DeleteCalendarResourceRequest req = zsc.elementToJaxb(request);
    String id = req.getId();
    if (null == id) {
        throw ServiceException.INVALID_REQUEST("missing required attribute: " + AdminConstants.E_ID, null);
    }
    // Confirm that the account exists and that the mailbox is located on the current host
    CalendarResource resource = prov.get(CalendarResourceBy.id, id);
    defendAgainstCalResourceHarvesting(resource, CalendarResourceBy.id, id, zsc, Admin.R_deleteCalendarResource);
    if (!Provisioning.onLocalServer(resource)) {
        // the mailbox can be deleted
        throw ServiceException.WRONG_HOST(resource.getAttr(Provisioning.A_zimbraMailHost), null);
    }
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(resource);
    prov.deleteCalendarResource(id);
    mbox.deleteMailbox();
    ZimbraLog.security.info(ZimbraLog.encodeAttrs(new String[] { "cmd", "DeleteCalendarResource", "name", resource.getName(), "id", resource.getId() }));
    Element response = zsc.createElement(AdminConstants.DELETE_CALENDAR_RESOURCE_RESPONSE);
    return response;
}
Also used : DeleteCalendarResourceRequest(com.zimbra.soap.admin.message.DeleteCalendarResourceRequest) Mailbox(com.zimbra.cs.mailbox.Mailbox) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) Element(com.zimbra.common.soap.Element) CalendarResource(com.zimbra.cs.account.CalendarResource) Provisioning(com.zimbra.cs.account.Provisioning)

Example 22 with CalendarResource

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

the class CheckPasswordStrength method handle.

public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    Provisioning prov = Provisioning.getInstance();
    String id = request.getAttribute(AdminConstants.E_ID);
    String password = request.getAttribute(AdminConstants.E_PASSWORD);
    Account account = prov.get(AccountBy.id, id, zsc.getAuthToken());
    if (account == null)
        throw AccountServiceException.NO_SUCH_ACCOUNT(id);
    if (account.isCalendarResource()) {
        // need a CalendarResource instance for RightChecker
        CalendarResource resource = prov.get(Key.CalendarResourceBy.id, id);
        checkCalendarResourceRight(zsc, resource, Admin.R_checkCalendarResourcePasswordStrength);
    } else {
        checkAccountRight(zsc, account, Admin.R_checkPasswordStrength);
    }
    prov.checkPasswordStrength(account, password);
    ZimbraLog.security.info(ZimbraLog.encodeAttrs(new String[] { "cmd", "CheckPasswordStrength", "name", account.getName() }));
    Element response = zsc.createElement(AdminConstants.CHECK_PASSWORD_STRENGTH_RESPONSE);
    return response;
}
Also used : Account(com.zimbra.cs.account.Account) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) Element(com.zimbra.common.soap.Element) CalendarResource(com.zimbra.cs.account.CalendarResource) Provisioning(com.zimbra.cs.account.Provisioning)

Example 23 with CalendarResource

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

the class CreateCalendarResource method handle.

@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    Provisioning prov = Provisioning.getInstance();
    CreateCalendarResourceRequest req = zsc.elementToJaxb(request);
    String name = req.getName().toLowerCase();
    checkDomainRightByEmail(zsc, name, Admin.R_createCalendarResource);
    Map<String, Object> attrs = req.getAttrsAsOldMultimap(true);
    checkSetAttrsOnCreate(zsc, TargetType.calresource, name, attrs);
    String password = req.getPassword();
    CalendarResource resource = prov.createCalendarResource(name, password, attrs);
    ZimbraLog.security.info(ZimbraLog.encodeAttrs(new String[] { "cmd", "CreateCalendarResource", "name", name }, attrs));
    Element response = zsc.createElement(AdminConstants.CREATE_CALENDAR_RESOURCE_RESPONSE);
    ToXML.encodeCalendarResource(response, resource, true);
    return response;
}
Also used : ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) Element(com.zimbra.common.soap.Element) CalendarResource(com.zimbra.cs.account.CalendarResource) Provisioning(com.zimbra.cs.account.Provisioning) CreateCalendarResourceRequest(com.zimbra.soap.admin.message.CreateCalendarResourceRequest)

Example 24 with CalendarResource

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

the class CompactIndex method handle.

@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    String action = request.getAttribute(MailConstants.E_ACTION);
    Element mreq = request.getElement(AdminConstants.E_MAILBOX);
    String accountId = mreq.getAttribute(AdminConstants.A_ACCOUNTID);
    Provisioning prov = Provisioning.getInstance();
    Account account = prov.get(AccountBy.id, accountId, zsc.getAuthToken());
    if (account == null) {
        throw AccountServiceException.NO_SUCH_ACCOUNT(accountId);
    }
    if (account.isCalendarResource()) {
        // need a CalendarResource instance for RightChecker
        CalendarResource resource = prov.get(Key.CalendarResourceBy.id, account.getId());
        checkCalendarResourceRight(zsc, resource, Admin.R_reindexCalendarResourceMailbox);
    } else {
        checkAccountRight(zsc, account, Admin.R_reindexMailbox);
    }
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account, false);
    if (mbox == null) {
        throw ServiceException.FAILURE("mailbox not found for account " + accountId, null);
    }
    Element response = zsc.createElement(AdminConstants.COMPACT_INDEX_RESPONSE);
    if (ACTION_START.equalsIgnoreCase(action)) {
        if (mbox.index.isCompactIndexInProgress()) {
            response.addAttribute(AdminConstants.A_STATUS, STATUS_RUNNING);
        } else {
            mbox.index.startCompactIndex();
        }
        response.addAttribute(AdminConstants.A_STATUS, STATUS_STARTED);
    } else if (ACTION_STATUS.equalsIgnoreCase(action)) {
        if (mbox.index.isCompactIndexInProgress()) {
            response.addAttribute(AdminConstants.A_STATUS, STATUS_RUNNING);
        } else {
            response.addAttribute(AdminConstants.A_STATUS, STATUS_IDLE);
        }
    } else {
        throw ServiceException.INVALID_REQUEST("Unknown action: " + action, null);
    }
    return response;
}
Also used : Account(com.zimbra.cs.account.Account) Mailbox(com.zimbra.cs.mailbox.Mailbox) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) Element(com.zimbra.common.soap.Element) CalendarResource(com.zimbra.cs.account.CalendarResource) Provisioning(com.zimbra.cs.account.Provisioning)

Example 25 with CalendarResource

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

the class CalendarMailSender method createDefaultReply.

private static MimeMessage createDefaultReply(Account fromAccount, String fromIdentityId, Account authAccount, String authIdentityId, boolean asAdmin, boolean onBehalfOf, CalendarItem calItem, Invite inv, MimeMessage mmInv, String replySubject, Verb verb, boolean partialAccept, String additionalMsgBody, ZVCalendar iCal, boolean addSignature) throws ServiceException {
    Identity fromIdentity = null;
    if (fromIdentityId != null) {
        fromIdentity = fromAccount.getIdentityById(fromIdentityId);
        if (fromIdentity == null) {
            ZimbraLog.calendar.warn("No such identity " + fromIdentityId + " for account " + fromAccount.getName());
            fromIdentity = getTargetedIdentity(fromAccount, inv);
        }
    } else {
        fromIdentity = getTargetedIdentity(fromAccount, inv);
    }
    Identity authIdentity = null;
    if (authIdentityId != null) {
        authIdentity = authAccount.getIdentityById(authIdentityId);
        if (authIdentity == null) {
            ZimbraLog.calendar.warn("No such identity " + authIdentityId + " for account " + authAccount.getName());
            if (authAccount.equals(fromAccount))
                authIdentity = fromIdentity;
            else
                authIdentity = getTargetedIdentity(authAccount, inv);
        }
    } else {
        if (authAccount.equals(fromAccount))
            authIdentity = fromIdentity;
        else
            authIdentity = getTargetedIdentity(authAccount, inv);
    }
    Locale lc;
    InternetAddress organizerAddress;
    if (inv.hasOrganizer()) {
        ZOrganizer org = inv.getOrganizer();
        // organizer or sent-by
        organizerAddress = org.getReplyAddress();
        Account organizer = Provisioning.getInstance().get(AccountBy.name, organizerAddress.getAddress());
        lc = organizer != null ? organizer.getLocale() : authAccount.getLocale();
    } else {
        organizerAddress = null;
        lc = authAccount.getLocale();
    }
    String fromDisplayName = fromIdentity.getAttr(Provisioning.A_zimbraPrefFromDisplay);
    if (fromDisplayName == null) {
        fromDisplayName = fromAccount.getAttr(Provisioning.A_displayName, fromAccount.getName());
    }
    StringBuilder replyText = new StringBuilder();
    boolean isResourceAccount = fromAccount instanceof CalendarResource;
    MsgKey statusMsgKey;
    if (VERB_ACCEPT.equals(verb)) {
        if (isResourceAccount) {
            if (partialAccept)
                statusMsgKey = MsgKey.calendarResourceDefaultReplyPartiallyAccept;
            else
                statusMsgKey = MsgKey.calendarResourceDefaultReplyAccept;
        } else {
            statusMsgKey = MsgKey.calendarDefaultReplyAccept;
        }
    } else if (VERB_DECLINE.equals(verb)) {
        if (isResourceAccount) {
            if (partialAccept)
                statusMsgKey = MsgKey.calendarResourceDefaultReplyPartiallyDecline;
            else
                statusMsgKey = MsgKey.calendarResourceDefaultReplyDecline;
        } else {
            statusMsgKey = MsgKey.calendarDefaultReplyDecline;
        }
    } else if (VERB_TENTATIVE.equals(verb)) {
        if (isResourceAccount)
            statusMsgKey = MsgKey.calendarResourceDefaultReplyTentativelyAccept;
        else
            statusMsgKey = MsgKey.calendarDefaultReplyTentativelyAccept;
    } else {
        statusMsgKey = MsgKey.calendarDefaultReplyOther;
    }
    String statusMsg;
    if (!statusMsgKey.equals(MsgKey.calendarDefaultReplyOther))
        statusMsg = L10nUtil.getMessage(statusMsgKey, lc, fromDisplayName);
    else
        statusMsg = L10nUtil.getMessage(statusMsgKey, lc, fromDisplayName, verb.toString());
    replyText.append(statusMsg).append("\r\n\r\n");
    if (additionalMsgBody != null) {
        replyText.append(additionalMsgBody).append("\r\n");
    }
    // signature can come above or below original invite text
    boolean sigAboveOriginal = true;
    String sigText = null;
    if (addSignature) {
        String sigStyle = fromAccount.getAttr(Provisioning.A_zimbraPrefMailSignatureStyle, "outlook");
        sigAboveOriginal = sigStyle.equalsIgnoreCase("outlook");
        String sigKey;
        if (VERB_DECLINE.equals(verb))
            sigKey = Provisioning.A_zimbraPrefCalendarAutoDeclineSignatureId;
        else
            sigKey = Provisioning.A_zimbraPrefCalendarAutoAcceptSignatureId;
        sigText = getSignatureText(fromAccount, fromIdentity, sigKey);
        if (sigAboveOriginal && sigText != null && sigText.length() > 0) {
            replyText.append(sigText).append("\r\n");
        }
    }
    boolean allowPrivateAccess = calItem != null ? calItem.allowPrivateAccess(authAccount, asAdmin) : true;
    if (inv.isPublic() || allowPrivateAccess) {
        attachInviteSummary(replyText, inv, mmInv, lc);
    }
    if (addSignature && !sigAboveOriginal && sigText != null && sigText.length() > 0) {
        replyText.append("\r\n-------------------------\r\n\r\n");
        replyText.append(sigText).append("\r\n");
    }
    List<Address> toList = new ArrayList<Address>(1);
    if (organizerAddress != null)
        toList.add(organizerAddress);
    Address senderAddr = null;
    if (onBehalfOf)
        senderAddr = authIdentity.getFriendlyEmailAddress();
    return createCalendarMessage(authAccount, fromIdentity.getFriendlyEmailAddress(), senderAddr, toList, replySubject, replyText.toString(), null, inv.getUid(), iCal);
}
Also used : Locale(java.util.Locale) Account(com.zimbra.cs.account.Account) InternetAddress(javax.mail.internet.InternetAddress) JavaMailInternetAddress(com.zimbra.common.mime.shim.JavaMailInternetAddress) Address(javax.mail.Address) InternetAddress(javax.mail.internet.InternetAddress) JavaMailInternetAddress(com.zimbra.common.mime.shim.JavaMailInternetAddress) ArrayList(java.util.ArrayList) MsgKey(com.zimbra.common.util.L10nUtil.MsgKey) Identity(com.zimbra.cs.account.Identity) CalendarResource(com.zimbra.cs.account.CalendarResource)

Aggregations

CalendarResource (com.zimbra.cs.account.CalendarResource)40 Account (com.zimbra.cs.account.Account)23 Element (com.zimbra.common.soap.Element)12 Provisioning (com.zimbra.cs.account.Provisioning)11 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)11 Test (org.junit.Test)8 ProvTest (com.zimbra.qa.unittest.prov.ProvTest)7 NamedEntry (com.zimbra.cs.account.NamedEntry)6 ArrayList (java.util.ArrayList)6 ServiceException (com.zimbra.common.service.ServiceException)5 Server (com.zimbra.cs.account.Server)4 Mailbox (com.zimbra.cs.mailbox.Mailbox)4 Invite (com.zimbra.cs.mailbox.calendar.Invite)4 RecurId (com.zimbra.cs.mailbox.calendar.RecurId)4 ZAttendee (com.zimbra.cs.mailbox.calendar.ZAttendee)4 HashMap (java.util.HashMap)4 ICalTimeZone (com.zimbra.common.calendar.ICalTimeZone)3 ParsedDateTime (com.zimbra.common.calendar.ParsedDateTime)3 JavaMailInternetAddress (com.zimbra.common.mime.shim.JavaMailInternetAddress)3 SoapTransport (com.zimbra.common.soap.SoapTransport)3