Skip to content

Commit

Permalink
Revert "refactor: remove mailboxd_directory (#549)" (#554)
Browse files Browse the repository at this point in the history
* Revert "refactor: remove mailboxd_directory (#549)"

This reverts commit 7dcd419.

* chore: align PKGs version
  • Loading branch information
frisonisland authored Jul 18, 2024
1 parent 3d42db1 commit 2b7d7ef
Show file tree
Hide file tree
Showing 11 changed files with 446 additions and 6 deletions.
20 changes: 17 additions & 3 deletions common/src/main/java/com/zimbra/common/localconfig/LC.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,14 @@ public final class LC {
public static final KnownKey localized_msgs_directory =
KnownKey.newKey("${zimbra_home}/conf/msgs");

@Supported
public static final KnownKey localized_client_msgs_directory =
KnownKey.newKey("${mailboxd_directory}/webapps/zimbraAdmin/WEB-INF/classes/messages");

@Supported
public static final KnownKey skins_directory =
KnownKey.newKey("${mailboxd_directory}/webapps/zimbra/skins");

public static final KnownKey zimbra_disk_cache_servlet_flush = KnownKey.newKey(true);
public static final KnownKey zimbra_disk_cache_servlet_size = KnownKey.newKey(1000);

Expand Down Expand Up @@ -466,7 +474,9 @@ public final class LC {
public static final KnownKey sqlite_page_size = KnownKey.newKey(4096);
public static final KnownKey sqlite_sync_mode = KnownKey.newKey("NORMAL");

public static final KnownKey create_db_sql_file = KnownKey.newKey("${zimbra_home}/db/create_database.sql");
@Supported
public static final KnownKey mailboxd_directory = KnownKey.newKey("${zimbra_home}/mailboxd");
public static final KnownKey create_db_sql_file = KnownKey.newKey("${mailboxd_directory}/../db/create_database.sql");

@Supported public static final KnownKey mailboxd_java_heap_size = KnownKey.newKey(null);

Expand Down Expand Up @@ -494,7 +504,7 @@ public final class LC {

@Supported
public static final KnownKey mailboxd_keystore =
KnownKey.newKey("${zimbra_home}/conf/keystore");
KnownKey.newKey("${mailboxd_directory}/etc/keystore");

@Supported public static final KnownKey mailboxd_keystore_password = KnownKey.newKey("zimbra");

Expand Down Expand Up @@ -577,6 +587,11 @@ public final class LC {
public static final KnownKey calendar_item_get_max_retries = KnownKey.newKey(100);
public static final KnownKey zimbraPrefCalenderScaling = KnownKey.newKey(false);

public static final KnownKey spnego_java_options =
KnownKey.newKey(
"-Djava.security.krb5.conf=${mailboxd_directory}/etc/krb5.ini "
+ "-Djava.security.auth.login.config=${mailboxd_directory}/etc/spnego.conf "
+ "-Djavax.security.auth.useSubjectCredsOnly=false");

public static final KnownKey text_attachments_base64 = KnownKey.newKey(true);

Expand Down Expand Up @@ -1443,5 +1458,4 @@ public enum PUBLIC_SHARE_VISIBILITY {
@Target({ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
public @interface Supported {}

}
2 changes: 1 addition & 1 deletion packages/mailbox-jar/PKGBUILD
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pkgname="carbonio-mailbox-jar"
pkgver="4.16.0"
pkgver="4.16.2"
pkgrel="1"
pkgdesc="Carbonio Mailbox Jars"
arch=('x86_64')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ public void registerHandlers(DocumentDispatcher dispatcher) {
dispatcher.registerHandler(AccountConstants.MODIFY_PROPERTIES_REQUEST, new ModifyProperties());
dispatcher.registerHandler(
AccountConstants.MODIFY_ZIMLET_PREFS_REQUEST, new ModifyZimletPrefs());

dispatcher.registerHandler(AccountConstants.GET_ALL_LOCALES_REQUEST, new GetAllLocales());
dispatcher.registerHandler(
AccountConstants.GET_AVAILABLE_LOCALES_REQUEST, new GetAvailableLocales());
dispatcher.registerHandler(
AccountConstants.GET_AVAILABLE_CSV_FORMATS_REQUEST, new GetAvailableCsvFormats());

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// SPDX-FileCopyrightText: 2022 Synacor, Inc.
// SPDX-FileCopyrightText: 2022 Zextras <https://www.zextras.com>
//
// SPDX-License-Identifier: GPL-2.0-only

package com.zimbra.cs.service.account;

import java.util.Locale;
import java.util.Map;

import com.zimbra.common.soap.AccountConstants;
import com.zimbra.common.soap.Element;
import com.zimbra.cs.util.WebClientL10nUtil;
import com.zimbra.soap.ZimbraSoapContext;

public class GetAllLocales extends AccountDocumentHandler {

@Override
public Element handle(Element request, Map<String, Object> context) {
ZimbraSoapContext zsc = getZimbraSoapContext(context);

Locale[] locales = WebClientL10nUtil.getAllLocalesSorted();
Element response = zsc.createElement(AccountConstants.GET_ALL_LOCALES_RESPONSE);
for (Locale locale : locales) {
ToXML.encodeLocale(response, locale, Locale.US);
}
return response;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
// SPDX-FileCopyrightText: 2022 Synacor, Inc.
// SPDX-FileCopyrightText: 2022 Zextras <https://www.zextras.com>
//
// SPDX-License-Identifier: GPL-2.0-only

package com.zimbra.cs.service.account;

import java.util.Locale;
import java.util.Map;
import java.util.Set;

import javax.servlet.http.HttpServletRequest;

import com.zimbra.common.service.ServiceException;
import com.zimbra.common.soap.AccountConstants;
import com.zimbra.common.soap.Element;
import com.zimbra.common.util.L10nUtil;
import com.zimbra.common.util.StringUtil;
import com.zimbra.cs.account.Account;
import com.zimbra.cs.account.Provisioning;
import com.zimbra.cs.util.WebClientL10nUtil;
import com.zimbra.soap.SoapServlet;
import com.zimbra.soap.ZimbraSoapContext;

public class GetAvailableLocales extends AccountDocumentHandler {

@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
ZimbraSoapContext zsc = getZimbraSoapContext(context);
Account account = getRequestedAccount(zsc);

if (!canAccessAccount(zsc, account)) {
throw ServiceException.PERM_DENIED("can not access account");
}

Locale displayLocale = getDisplayLocale(account, context);

// get installed locales, sorted
Locale[] installedLocales = WebClientL10nUtil.getLocales(displayLocale);

// get avail locales for this account/COS
Set<String> allowedLocales = account.getMultiAttrSet(Provisioning.A_zimbraAvailableLocale);

Locale[] availLocales = null;
if (allowedLocales.size() > 0) {
availLocales = computeAvailLocales(installedLocales, allowedLocales);
} else {
availLocales = installedLocales;
}

Element response = zsc.createElement(AccountConstants.GET_AVAILABLE_LOCALES_RESPONSE);
for (Locale locale : availLocales) {
if (locale != null) {
ToXML.encodeLocale(response, locale, displayLocale);
} else {
break;
}
}
return response;
}

private Locale getDisplayLocale(Account acct, Map<String, Object> context) throws ServiceException {
// use zimbraPrefLocale is it is present
String locale = acct.getAttr(Provisioning.A_zimbraPrefLocale, false);

// otherwise use Accept-Language header
if (StringUtil.isNullOrEmpty(locale)) {
HttpServletRequest req = (HttpServletRequest)context.get(SoapServlet.SERVLET_REQUEST);
if (req != null) {
locale = req.getHeader("Accept-Language");
//TODO need to handle multiple languages with quality value and use the one with the highest quality value
}
}

// otherwise use Provisioning.getLocale();
if (StringUtil.isNullOrEmpty(locale)) {
return Provisioning.getInstance().getLocale(acct);
} else {
return L10nUtil.lookupLocale(locale);
}
}

private Locale[] computeAvailLocales(Locale[] installedLocales, Set<String> allowedLocales) {
/*
* available locales is the intersection of installedLocales and allowedLocales
*
* for a locale in allowedLocales, we include all the sub locales, but not the more "generic" locales in the family
* e.g. - if allowedLocales is fr, all the fr_* in installedLocales will be included
* - if allowedLocales is fr_CA, all the fr_CA_* in installedLocales will be included,
* but not any of the fr_[non CA] or fr.
*/

Locale[] availLocales = new Locale[installedLocales.length];
int i = 0;
for (Locale locale : installedLocales) {
// locale ids are in language[_country[_variant]] format
// include it if it allows a more generic locale in the family
String localeId = locale.toString();
String language = locale.getLanguage();
String country = locale.getCountry();
String variant = locale.getVariant();

if (!StringUtil.isNullOrEmpty(variant)) {
if (allowedLocales.contains(language) || allowedLocales.contains(language+"_"+country) || allowedLocales.contains(localeId)) {
availLocales[i++] = locale;
}
} else if (!StringUtil.isNullOrEmpty(country)) {
if (allowedLocales.contains(language) || allowedLocales.contains(localeId)) {
availLocales[i++] = locale;
}
} else {
if (allowedLocales.contains(localeId)) {
availLocales[i++] = locale;
}
}
}

return availLocales;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class AdminService implements DocumentService {
public void registerHandlers(DocumentDispatcher dispatcher) throws ServiceException {
dispatcher.registerHandler(AdminConstants.PING_REQUEST, new Ping());
dispatcher.registerHandler(AdminConstants.CHECK_HEALTH_REQUEST, new CheckHealth());
dispatcher.registerHandler(AdminConstants.GET_ALL_LOCALES_REQUEST, new GetAllLocales());

dispatcher.registerHandler(AdminConstants.AUTH_REQUEST, new Auth());
dispatcher.registerHandler(AdminConstants.CREATE_ACCOUNT_REQUEST, new CreateAccount());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.zimbra.cs.account.accesscontrol.Rights.Admin;
import com.zimbra.cs.gal.GalGroup;
import com.zimbra.cs.httpclient.URLUtil;
import com.zimbra.cs.util.WebClientL10nUtil;
import com.zimbra.cs.util.WebClientServiceUtil;
import com.zimbra.cs.zimlet.ZimletUtil;
import com.zimbra.soap.SoapServlet;
Expand Down Expand Up @@ -114,6 +115,7 @@ public static void doFlush(
}
break;
case locale:
WebClientL10nUtil.flushCache();
break;
case license:
flushLdapCache(
Expand Down
41 changes: 41 additions & 0 deletions store/src/main/java/com/zimbra/cs/service/admin/GetAllLocales.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// SPDX-FileCopyrightText: 2022 Synacor, Inc.
// SPDX-FileCopyrightText: 2022 Zextras <https://www.zextras.com>
//
// SPDX-License-Identifier: GPL-2.0-only

package com.zimbra.cs.service.admin;

import java.util.List;
import java.util.Locale;
import java.util.Map;

import com.zimbra.common.soap.AdminConstants;
import com.zimbra.common.soap.Element;
import com.zimbra.cs.account.accesscontrol.AdminRight;
import com.zimbra.cs.util.WebClientL10nUtil;
import com.zimbra.soap.ZimbraSoapContext;

public class GetAllLocales extends AdminDocumentHandler {

@Override
public boolean domainAuthSufficient(Map<String, Object> context) {
return true;
}

@Override
public Element handle(Element request, Map<String, Object> context) {
ZimbraSoapContext zsc = getZimbraSoapContext(context);

Locale[] locales = WebClientL10nUtil.getAllLocalesSorted();
Element response = zsc.createElement(AdminConstants.GET_ALL_LOCALES_RESPONSE);
for (Locale locale : locales) {
com.zimbra.cs.service.account.ToXML.encodeLocale(response, locale, Locale.US);
}
return response;
}

@Override
public void docRights(List<AdminRight> relatedRights, List<String> notes) {
notes.add("Allow all admins");
}
}
Loading

0 comments on commit 2b7d7ef

Please sign in to comment.