Search in sources :

Example 1 with Presence

use of com.zimbra.cs.zimlet.ZimletPresence.Presence in project zm-mailbox by Zimbra.

the class ZimletUtil method migrateUserPrefIfNecessary.

public static void migrateUserPrefIfNecessary(Account acct) throws ServiceException {
    if (!DebugConfig.enableMigrateUserZimletPrefs) {
        return;
    }
    Set<String> wanted = acct.getMultiAttrSet(Provisioning.A_zimbraPrefZimlets);
    Set<String> unwanted = acct.getMultiAttrSet(Provisioning.A_zimbraPrefDisabledZimlets);
    // needs upgrade only if wanted is not empty and unwanted is empty, because
    // if wanted is empty: means use whatever zimbraZimletAvailableZimlets/zimbraZimletDomainAvailableZimlets says
    // if unwanted is not empty: already migrated or user has change it.
    boolean needsMigrate = (!wanted.isEmpty()) && unwanted.isEmpty();
    if (!needsMigrate) {
        return;
    }
    ZimletPresence availZimlets = getAvailableZimlets(acct);
    Map<String, Object> attrs = new HashMap<String, Object>();
    StringBuilder disabledZimletNamesForLogging = new StringBuilder();
    for (String zimletName : availZimlets.getZimletNames()) {
        Presence presence = availZimlets.getPresence(zimletName);
        if (presence == Presence.enabled && !wanted.contains(zimletName)) {
            disabledZimletNamesForLogging.append(zimletName + ", ");
            StringUtil.addToMultiMap(attrs, Provisioning.A_zimbraPrefDisabledZimlets, zimletName);
        }
    }
    // attrs will be empty => we've got nothing to do.
    if (attrs.isEmpty()) {
        ZimbraLog.account.info("Not migrating zimbraPrefDisabledZimlets for account " + acct.getName() + " because all zimlets are enabled");
        return;
    }
    ZimbraLog.account.info("Migrating zimbraPrefDisabledZimlets for account " + acct.getName() + " to " + disabledZimletNamesForLogging.toString());
    Provisioning prov = Provisioning.getInstance();
    prov.modifyAttrs(acct, attrs);
}
Also used : HashMap(java.util.HashMap) Presence(com.zimbra.cs.zimlet.ZimletPresence.Presence) Provisioning(com.zimbra.cs.account.Provisioning) SoapProvisioning(com.zimbra.cs.account.soap.SoapProvisioning)

Example 2 with Presence

use of com.zimbra.cs.zimlet.ZimletPresence.Presence in project zm-mailbox by Zimbra.

the class ZimletUtil method getUserZimlets.

public static ZimletPresence getUserZimlets(Account acct) throws ServiceException {
    ZimletPresence userZimlets = getAvailableZimlets(acct);
    // userZimlets now contains all allowed zimlets for the user
    // process user pref, which overrides cos/domain enabled/disabled by default
    // user pref cannot override cos/domain mandatory zimlets
    String[] userPrefEnabledZimlets = acct.getMultiAttr(Provisioning.A_zimbraPrefZimlets);
    for (String zimletName : userPrefEnabledZimlets) {
        Presence presence = userZimlets.getPresence(zimletName);
        if (// zimlet is allowed
        presence != null && // can't override mandatory
        presence != Presence.mandatory && presence != Presence.enabled) {
            // disabled by default, but user specifically enabled it
            userZimlets.put(zimletName, Presence.enabled);
        }
    }
    String[] userPrefDisabledZimlets = acct.getMultiAttr(Provisioning.A_zimbraPrefDisabledZimlets);
    for (String zimletName : userPrefDisabledZimlets) {
        Presence presence = userZimlets.getPresence(zimletName);
        if (// zimlet is allowed
        presence != null && // can't override mandatory
        presence != Presence.mandatory && presence != Presence.disabled) {
            // enabled by default, but user specifically disabled it
            userZimlets.put(zimletName, Presence.disabled);
        }
    }
    return userZimlets;
}
Also used : Presence(com.zimbra.cs.zimlet.ZimletPresence.Presence)

Example 3 with Presence

use of com.zimbra.cs.zimlet.ZimletPresence.Presence in project zm-mailbox by Zimbra.

the class ModifyZimletPrefs method handle.

@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    Account account = getRequestedAccount(zsc);
    if (!canModifyOptions(zsc, account))
        throw ServiceException.PERM_DENIED("can not modify options");
    Map<String, Object> attrs = new HashMap<String, Object>();
    ZimletPresence availZimlets = ZimletUtil.getAvailableZimlets(account);
    String addEnabled = "+" + Provisioning.A_zimbraPrefZimlets;
    String delEnabled = "-" + Provisioning.A_zimbraPrefZimlets;
    String addDisabled = "+" + Provisioning.A_zimbraPrefDisabledZimlets;
    String delDisabled = "-" + Provisioning.A_zimbraPrefDisabledZimlets;
    for (Element eZimlet : request.listElements(AccountConstants.E_ZIMLET)) {
        String zimletName = eZimlet.getAttribute(AccountConstants.A_NAME);
        String presense = eZimlet.getAttribute(AccountConstants.A_ZIMLET_PRESENCE);
        Presence userPrefPresence = Presence.fromString(presense);
        // user cannot make a zimlet mandatory
        if (userPrefPresence == Presence.mandatory)
            throw ServiceException.INVALID_REQUEST("invalid zimlet presence: " + presense, null);
        Presence defaultPresence = availZimlets.getPresence(zimletName);
        /*
             * if zimlet is not available to the user or is mandatory,
             * we don't want it to appear in either enabled/disabled prefs,
             * regardless what the user wants.
             * 
             * if default presence is the same as what user wants. it does not 
             * need to appear in the user pref.
             */
        if (// zimlet not available to the user
        defaultPresence == null || // zimlet is mandatory
        defaultPresence == Presence.mandatory || defaultPresence == userPrefPresence) {
            // default == what user wants
            StringUtil.addToMultiMap(attrs, delEnabled, zimletName);
            StringUtil.addToMultiMap(attrs, delDisabled, zimletName);
        } else {
            /*
                 * default != what user wants
                 */
            if (userPrefPresence == Presence.enabled) {
                // user wants the zimlet enabled
                StringUtil.addToMultiMap(attrs, addEnabled, zimletName);
                StringUtil.addToMultiMap(attrs, delDisabled, zimletName);
            } else {
                // user wants the zimlet disabled
                StringUtil.addToMultiMap(attrs, delEnabled, zimletName);
                StringUtil.addToMultiMap(attrs, addDisabled, zimletName);
            }
        }
    }
    Provisioning prov = Provisioning.getInstance();
    prov.modifyAttrs(account, attrs);
    Element response = zsc.createElement(AccountConstants.MODIFY_ZIMLET_PREFS_RESPONSE);
    doResponse(prov, response, account);
    return response;
}
Also used : Account(com.zimbra.cs.account.Account) HashMap(java.util.HashMap) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) Element(com.zimbra.common.soap.Element) Presence(com.zimbra.cs.zimlet.ZimletPresence.Presence) ZimletPresence(com.zimbra.cs.zimlet.ZimletPresence) ZimletPresence(com.zimbra.cs.zimlet.ZimletPresence) Provisioning(com.zimbra.cs.account.Provisioning)

Example 4 with Presence

use of com.zimbra.cs.zimlet.ZimletPresence.Presence in project zm-mailbox by Zimbra.

the class AvailableZimlets method preModify.

@Override
public void preModify(CallbackContext context, String attrName, Object value, Map attrsToModify, Entry entry) {
    Object replacing = attrsToModify.get(attrName);
    Object deleting = attrsToModify.get("-" + attrName);
    Object adding = attrsToModify.get("+" + attrName);
    ZimletPresence availZimlets;
    if (replacing != null)
        availZimlets = doReplacing(replacing);
    else
        availZimlets = doDeletingAdding(entry, attrName, deleting, adding);
    String[] zimlets = availZimlets.getZimletNamesAsArray();
    String[] newValues = new String[zimlets.length];
    for (int i = 0; i < zimlets.length; i++) {
        String zimletName = zimlets[i];
        Presence presence = availZimlets.getPresence(zimletName);
        newValues[i] = presence.prefix() + zimletName;
    }
    // do the update using our re-shuffled values
    attrsToModify.remove(attrName);
    attrsToModify.remove("-" + attrName);
    attrsToModify.remove("+" + attrName);
    attrsToModify.put(attrName, newValues);
}
Also used : ZimletPresence(com.zimbra.cs.zimlet.ZimletPresence) Presence(com.zimbra.cs.zimlet.ZimletPresence.Presence) ZimletPresence(com.zimbra.cs.zimlet.ZimletPresence)

Aggregations

Presence (com.zimbra.cs.zimlet.ZimletPresence.Presence)4 Provisioning (com.zimbra.cs.account.Provisioning)2 ZimletPresence (com.zimbra.cs.zimlet.ZimletPresence)2 HashMap (java.util.HashMap)2 Element (com.zimbra.common.soap.Element)1 Account (com.zimbra.cs.account.Account)1 SoapProvisioning (com.zimbra.cs.account.soap.SoapProvisioning)1 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)1