Skip to content

Commit

Permalink
ZCS-15079 POC | Hide alias in GAL
Browse files Browse the repository at this point in the history
  • Loading branch information
rendurama committed Jul 5, 2024
1 parent 1a419ea commit d905cee
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 32 deletions.
14 changes: 11 additions & 3 deletions common/src/java/com/zimbra/common/account/ZAttrProvisioning.java
Original file line number Diff line number Diff line change
Expand Up @@ -7508,9 +7508,9 @@ public static TwoFactorAuthSecretEncoding fromString(String s) throws ServiceExc
public static final String A_zimbraFeatureSearchHistoryEnabled = "zimbraFeatureSearchHistoryEnabled";

/**
* Feature to enable/disable the mobile sync for shared folders. Default
* value is TRUE. The option to sync the shared folders to the Mobile
* will be enabled for the users in the webclient. The option will only
* Feature to enable/disable the mobile sync for shared folders. Default
* value is TRUE. The option to sync the shared folders to the Mobile
* will be enabled for the users in the webclient. The option will only
* be enabled for shared folders having Admin or Manager permission
*
* @since ZCS 10.1.0
Expand Down Expand Up @@ -8586,6 +8586,14 @@ public static TwoFactorAuthSecretEncoding fromString(String s) throws ServiceExc
@ZAttr(id=4116)
public static final String A_zimbraHideAliasesInGal = "zimbraHideAliasesInGal";

/**
* Option to hide/show alias in GAL
*
* @since ZCS 10.1.1
*/
@ZAttr(id=4135)
public static final String A_zimbraHideAliasInGal = "zimbraHideAliasInGal";

/**
* hide entry in Global Address List
*/
Expand Down
5 changes: 3 additions & 2 deletions store/conf/attrs/zimbra-attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10556,7 +10556,8 @@ TODO: delete them permanently from here
<desc>Feature to enable/disable the mobile sync for shared folders. Default value is TRUE. The option to sync the shared folders to the Mobile will be enabled for the users in the webclient. The option will only be enabled for shared folders having Admin or Manager permission</desc>
</attr>

<attr id="4135" name="zimbraHideAliasInGal" type="boolean" cardinality="single" requiredIn="alias" since="10.1.1">
<desc>Option to hide/show alias in GAL</desc>
<attr id="4135" name="zimbraHideAliasInGal" type="boolean" cardinality="single" requiredIn="alias" since="10.1.1">
<desc> Option to hide/show alias in GAL</desc>

</attr>
</attrs>
Original file line number Diff line number Diff line change
Expand Up @@ -970,4 +970,9 @@ public void resetPassword(Account acct, String newPassword, boolean dryRun) thro
public String sendMdmEmail(String status, String timeInterval) throws ServiceException {
return null;
}

@Override
public void checkIsAliasToBeHidden(NamedEntry entry, List<String> email) throws ServiceException {
//Not yet implemenmted
}
}
3 changes: 3 additions & 0 deletions store/src/java/com/zimbra/cs/account/Provisioning.java
Original file line number Diff line number Diff line change
Expand Up @@ -2795,4 +2795,7 @@ public String createAddressList(Domain domain, String name, String desc, Map<Str
}

public abstract String sendMdmEmail(String status, String timeInterval) throws ServiceException;

public abstract void checkIsAliasToBeHidden(NamedEntry entry, List<String> email) throws ServiceException;

}
40 changes: 40 additions & 0 deletions store/src/java/com/zimbra/cs/account/ldap/LdapProvisioning.java
Original file line number Diff line number Diff line change
Expand Up @@ -11726,4 +11726,44 @@ public void modifyAddressList(AddressList addressList, String name, Map<String,
public String sendMdmEmail(String status, String timeInterval) throws ServiceException {
return L10nUtil.getMessage(L10nUtil.MsgKey.sendMDMNotificationEmailFailure);
}


@Override
public void checkIsAliasToBeHidden(NamedEntry entry, List<String> aliases) throws ServiceException {
ZimbraLog.mailbox.debug("checkIsAliasToBeHidden %s ", aliases);

LdapUsage ldapUsage = LdapUsage.ADD_ALIAS_ACCOUNT;

ZLdapContext zlc = LdapClient.getContext(LdapServerType.MASTER, ldapUsage);

for (String alias : new ArrayList<String>(aliases)) {
if (null != alias) {
String parts[] = alias.split("@");
String aliasName = parts[0];
String aliasDomain = parts[1];

ZimbraLog.mailbox.debug("checkIsAliasToBeHidden2 %s ", alias);

String targetDomainName = ((Account) entry).getDomainName();

String aliasDn = mDIT.aliasDN(((LdapEntry) entry).getDN(), targetDomainName, aliasName, aliasDomain);

ZAttributes attrs = helper.getAttributes(zlc, aliasDn);

Alias aliasEntryLocal = makeAlias(aliasDn, attrs);

NamedEntry targetEntry = searchAliasTarget(aliasEntryLocal, false);

boolean isSame = (entry.getId().equals(targetEntry.getId()));

if ("TRUE".equalsIgnoreCase(aliasEntryLocal.getAttr(Provisioning.A_zimbraHideAliasInGal))) {
aliases.remove(alias);
}
ZimbraLog.mailbox.info("alias attribute for %s is %s and isSame %s ", alias,
aliasEntryLocal.getAttr(Provisioning.A_zimbraHideAliasInGal), isSame);
}
}

}
}

Original file line number Diff line number Diff line change
Expand Up @@ -3312,4 +3312,8 @@ public String sendMdmEmail(String status, String timeInterval) throws ServiceExc

return L10nUtil.getMessage(L10nUtil.MsgKey.sendMDMNotificationEmailSuccess);
}

@Override public void checkIsAliasToBeHidden(NamedEntry entry, List<String> email) throws ServiceException {

}
}
77 changes: 50 additions & 27 deletions store/src/java/com/zimbra/cs/mailbox/ContactAutoComplete.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import com.zimbra.cs.account.Account;
import com.zimbra.cs.account.GalContact;
import com.zimbra.cs.account.Provisioning;
import com.zimbra.cs.account.ldap.LdapProvisioning;
import com.zimbra.cs.gal.GalGroup;
import com.zimbra.cs.gal.GalGroupInfoProvider;
import com.zimbra.cs.gal.GalSearchControl;
Expand Down Expand Up @@ -397,17 +398,17 @@ public void setSearchType(GalSearchType type) {
}

public AutoCompleteResult resolveEmailAddr(String str) throws ServiceException {
AutoCompleteResult result = new AutoCompleteResult(1);
result.rankings = new ContactRankings(getRequestedAcctId());
for (String addr : mRequestedAcct.getAllAddrsSet()) {
if (addr.equals(str)) {
ContactEntry entry = new ContactEntry();
entry.mEmail = addr;
result.addEntry(entry);
break;
}
}
return result;
AutoCompleteResult result = new AutoCompleteResult(1);
result.rankings = new ContactRankings(getRequestedAcctId());
for (String addr : mRequestedAcct.getAllAddrsSet()) {
if (addr.equals(str)) {
ContactEntry entry = new ContactEntry();
entry.mEmail = addr;
result.addEntry(entry);
break;
}
}
return result;
}
public AutoCompleteResult query(String str, Collection<Integer> folders, int limit) throws ServiceException {
ZimbraLog.gal.debug("AutoComplete querying: %s", str);
Expand Down Expand Up @@ -470,7 +471,7 @@ private void resolveGroupInfo(ContactEntry entry, String email) {
}

private void queryGal(String str, AutoCompleteResult result) {
ZimbraLog.gal.debug("querying gal");
ZimbraLog.gal.info("querying gal");
GalSearchParams params = new GalSearchParams(mRequestedAcct, mZsc);
params.setQuery(str);
params.setType(mSearchType);
Expand Down Expand Up @@ -504,7 +505,7 @@ public AutoCompleteCallback(String str, AutoCompleteResult result, GalSearchPara
this.str = str;
}

public void handleContactAttrs(Map<String, ? extends Object> attrs) {
public void handleContactAttrs(Map<String, ? extends Object> attrs) throws ServiceException {
addMatchedContacts(str, attrs, FOLDER_ID_GAL, null, result);
}

Expand Down Expand Up @@ -600,8 +601,7 @@ private boolean matchesName(List<String> tokens, Map<String, ? extends Object> a
String fullName = getFieldAsString(attrs, ContactConstants.A_fullName);
if (!Strings.isNullOrEmpty(fullName)) {
for (String fullNameToken : TOKEN_SPLITTER.split(fullName)) {
if (!Strings.isNullOrEmpty(fullNameToken) &&
fullNameToken.toLowerCase().startsWith(token)) {
if (!Strings.isNullOrEmpty(fullNameToken) && fullNameToken.toLowerCase().startsWith(token)) {
return true;
}
}
Expand Down Expand Up @@ -634,8 +634,8 @@ private boolean matchesName(List<String> tokens, Map<String, ? extends Object> a
if (pattern.matcher(Joiner.on(' ').skipNulls().join(lastName, firstName, middleName)).matches()) {
return true;
}


String fullName = getFieldAsString(attrs, ContactConstants.A_fullName);
if (!Strings.isNullOrEmpty(fullName) && pattern.matcher(fullName).matches()) {
return true;
Expand Down Expand Up @@ -669,7 +669,7 @@ private Pattern toPattern(List<String> tokens) {
}

public void addMatchedContacts(String query, Map<String, ? extends Object> attrs, int folderId, ItemId id,
AutoCompleteResult result) {
AutoCompleteResult result) throws ServiceException {
if (!result.canBeCached) {
return;
}
Expand All @@ -680,10 +680,10 @@ public void addMatchedContacts(String query, Map<String, ? extends Object> attrs
}

if (!Contact.isGroup(attrs) || folderId == FOLDER_ID_GAL) {
//
//
// either a GAL entry or a non-contact-group contact entry
//

boolean nameMatches = matchesName(tokens, attrs);

// matching algorithm is slightly different between matching
Expand All @@ -704,25 +704,47 @@ public void addMatchedContacts(String query, Map<String, ? extends Object> attrs
String company = getFieldAsString(attrs, ContactConstants.A_company);
String fileas = getFieldAsString(attrs, ContactConstants.A_fileAs);
String displayName = fullName;
Account account = Provisioning.getInstance().get(Key.AccountBy.name, fullName);

if (Strings.isNullOrEmpty(displayName)) {
displayName = Joiner.on(' ').skipNulls().join(first, middle, last);
}

for (String emailKey : mEmailKeys) {
String email = getFieldAsString(attrs, emailKey);
List<String> allowedEmailsList = new ArrayList<>();
for(String emailKey: mEmailKeys) {
if (!emailKey.equals("email")) {
if (account.isHideAliasesInGal()) {
//condition for allowing primary email address only
break;
}
}
allowedEmailsList.add(getFieldAsString(attrs, emailKey));
}
ZimbraLog.mailbox.info("allowed list 1 is %s", allowedEmailsList);

try {
Provisioning.getInstance().checkIsAliasToBeHidden(account, allowedEmailsList.subList( 1, allowedEmailsList.size()));
} catch (ServiceException e) {
throw new RuntimeException(e);
}

ZimbraLog.mailbox.info("allowed list 2 is %s", allowedEmailsList);


for (String email : allowedEmailsList) {
if (email != null && (nameMatches || matchesEmail(tokens, email))) {
ContactEntry entry = new ContactEntry();
entry.mEmail = email;
entry.setName(displayName);
entry.mId = id;
entry.mFolderId = folderId;
entry.mFirstName = first;
entry.mFirstName = first;
entry.mMiddleName = middle;
entry.mLastName = last;
entry.mFullName = fullName;
entry.mNickname = nick;
entry.mCompany = company;
entry.mFileAs = fileas;
entry.mCompany = company;
entry.mFileAs = fileas;
if (Contact.isGroup(attrs)) {
entry.setIsGalGroup(email, attrs, mAuthedAcct, mNeedCanExpand);
} else if (entry.mFolderId != FOLDER_ID_GAL) {
Expand All @@ -734,10 +756,11 @@ public void addMatchedContacts(String query, Map<String, ? extends Object> attrs
if (returnFullContactData) {
entry.mAttrs = attrs;
}

addEntry(entry, result);
ZimbraLog.gal.debug("adding %s", entry.getEmail());
/*
Previously stopped at first matching email address for GAL contact.
Previously stopped at first matching email address for GAL contact.
See ZBUG-1838.
*/
}
Expand Down Expand Up @@ -931,4 +954,4 @@ private void addExistingContactsFromRankingTable(String str, String folderBasicQ
queryFolders(str, queryRanking, mountpoints, limit, result);
}
}
}
}

0 comments on commit d905cee

Please sign in to comment.