-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
1 parent
3d42db1
commit 2b7d7ef
Showing
11 changed files
with
446 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
store/src/main/java/com/zimbra/cs/service/account/GetAllLocales.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
120 changes: 120 additions & 0 deletions
120
store/src/main/java/com/zimbra/cs/service/account/GetAvailableLocales.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
store/src/main/java/com/zimbra/cs/service/admin/GetAllLocales.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
} |
Oops, something went wrong.