Commit b2bdeccb authored by Gabriel Guardincerri's avatar Gabriel Guardincerri Committed by gguardin

10018 [JM-1281] Fixed an exception using a user with a not visible email and...

10018 [JM-1281] Fixed an exception using a user with a not visible email and CS as a provider. And a problem with user search.

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/trunk@10022 b35dd754-fafc-0310-a699-88a17e54d16e
parent 5c9bed2d
...@@ -57,6 +57,11 @@ public class User implements Cacheable, Externalizable, Result { ...@@ -57,6 +57,11 @@ public class User implements Cacheable, Externalizable, Result {
private static final String INSERT_PROPERTY = private static final String INSERT_PROPERTY =
"INSERT INTO jiveUserProp (username, name, propValue) VALUES (?, ?, ?)"; "INSERT INTO jiveUserProp (username, name, propValue) VALUES (?, ?, ?)";
// The name of the name visible property
private static final String NAME_VISIBLE_PROPERTY = "name.visible";
// The name of the email visible property
private static final String EMAIL_VISIBLE_PROPERTY = "email.visible";
private String username; private String username;
private String name; private String name;
private String email; private String email;
...@@ -205,6 +210,24 @@ public class User implements Cacheable, Externalizable, Result { ...@@ -205,6 +210,24 @@ public class User implements Cacheable, Externalizable, Result {
} }
} }
/**
* Returns true if name is visible to everyone or not.
*
* @return true if name is visible to everyone, false if not.
*/
public boolean isNameVisible() {
return !getProperties().containsKey(NAME_VISIBLE_PROPERTY) || Boolean.valueOf(getProperties().get(NAME_VISIBLE_PROPERTY));
}
/**
* Sets if name is visible to everyone or not.
*
* @param visible true if name is visible, false if not.
*/
public void setNameVisible(boolean visible) {
getProperties().put(NAME_VISIBLE_PROPERTY, String.valueOf(visible));
}
/** /**
* Returns the email address of the user or <tt>null</tt> if none is defined. * Returns the email address of the user or <tt>null</tt> if none is defined.
* *
...@@ -239,6 +262,24 @@ public class User implements Cacheable, Externalizable, Result { ...@@ -239,6 +262,24 @@ public class User implements Cacheable, Externalizable, Result {
} }
} }
/**
* Returns true if email is visible to everyone or not.
*
* @return true if email is visible to everyone, false if not.
*/
public boolean isEmailVisible() {
return !getProperties().containsKey(EMAIL_VISIBLE_PROPERTY) || Boolean.valueOf(getProperties().get(EMAIL_VISIBLE_PROPERTY));
}
/**
* Sets if the email is visible to everyone or not.
*
* @param visible true if the email is visible, false if not.
*/
public void setEmailVisible(boolean visible) {
getProperties().put(EMAIL_VISIBLE_PROPERTY, String.valueOf(visible));
}
public Date getCreationDate() { public Date getCreationDate() {
return creationDate; return creationDate;
} }
......
...@@ -22,11 +22,11 @@ import java.util.concurrent.ConcurrentHashMap; ...@@ -22,11 +22,11 @@ import java.util.concurrent.ConcurrentHashMap;
* entities (i.e. users) the {@link User} name is used. For remote entities the following logic * entities (i.e. users) the {@link User} name is used. For remote entities the following logic
* is used: * is used:
* <ol> * <ol>
* <li>Check if a {@link UserNameProvider} is registered for the entity's domain. If a provider * <li>Check if a {@link UserNameProvider} is registered for the entity's domain. If a provider
* was found then use it to get the entity's name</li> * was found then use it to get the entity's name</li>
* <li>If no provider was found then retrieve the vCard of the entity and return the name as * <li>If no provider was found then retrieve the vCard of the entity and return the name as
* defined in the vCard. <i>This is not implemented yet.</i></li> * defined in the vCard. <i>This is not implemented yet.</i></li>
* <li>If no vCard was found then return the string representation of the entity's JID.</li> * <li>If no vCard was found then return the string representation of the entity's JID.</li>
* </ol> * </ol>
* *
* @author Gaston Dombiak * @author Gaston Dombiak
...@@ -72,7 +72,7 @@ public class UserNameManager { ...@@ -72,7 +72,7 @@ public class UserNameManager {
* @param entity the JID of the entity to get its name. * @param entity the JID of the entity to get its name.
* @return the name of the XMPP entity. * @return the name of the XMPP entity.
* @throws UserNotFoundException if the jid belongs to the local server but no user was * @throws UserNotFoundException if the jid belongs to the local server but no user was
* found for that jid. * found for that jid.
*/ */
public static String getUserName(JID entity) throws UserNotFoundException { public static String getUserName(JID entity) throws UserNotFoundException {
return getUserName(entity, entity.toString()); return getUserName(entity, entity.toString());
...@@ -85,19 +85,18 @@ public class UserNameManager { ...@@ -85,19 +85,18 @@ public class UserNameManager {
* the vCard of the entity might be requested and if none was found then a string * the vCard of the entity might be requested and if none was found then a string
* representation of the entity's JID will be returned. * representation of the entity's JID will be returned.
* *
* @param entity the JID of the entity to get its name. * @param entity the JID of the entity to get its name.
* @param defaultName default name to return when no name was found. * @param defaultName default name to return when no name was found.
* @return the name of the XMPP entity. * @return the name of the XMPP entity.
* @throws UserNotFoundException if the jid belongs to the local server but no user was * @throws UserNotFoundException if the jid belongs to the local server but no user was
* found for that jid. * found for that jid.
*/ */
public static String getUserName(JID entity, String defaultName) throws UserNotFoundException { public static String getUserName(JID entity, String defaultName) throws UserNotFoundException {
if (server.isLocal(entity)) { if (server.isLocal(entity)) {
// Contact is a local entity so search for his user name // Contact is a local entity so search for his user name
User localUser = UserManager.getInstance().getUser(entity.getNode()); User localUser = UserManager.getInstance().getUser(entity.getNode());
return "".equals(localUser.getName()) ? entity.getNode() : localUser.getName(); return !localUser.isNameVisible() || "".equals(localUser.getName()) ? entity.getNode() : localUser.getName();
} } else {
else {
UserNameProvider provider = providersByDomain.get(entity.getDomain()); UserNameProvider provider = providersByDomain.get(entity.getDomain());
if (provider != null) { if (provider != null) {
return provider.getUserName(entity); return provider.getUserName(entity);
......
...@@ -713,11 +713,11 @@ public class SearchPlugin implements Component, Plugin, PropertyEventListener { ...@@ -713,11 +713,11 @@ public class SearchPlugin implements Component, Plugin, PropertyEventListener {
items.add(fieldUsername); items.add(fieldUsername);
XFormFieldImpl fieldName = new XFormFieldImpl(LocaleUtils.getLocalizedString("advance.user.search.name", "search")); XFormFieldImpl fieldName = new XFormFieldImpl(LocaleUtils.getLocalizedString("advance.user.search.name", "search"));
fieldName.addValue(removeNull(user.getName())); fieldName.addValue((user.isNameVisible() ? removeNull(user.getName()) : ""));
items.add(fieldName); items.add(fieldName);
XFormFieldImpl fieldEmail = new XFormFieldImpl(LocaleUtils.getLocalizedString("advance.user.search.email", "search")); XFormFieldImpl fieldEmail = new XFormFieldImpl(LocaleUtils.getLocalizedString("advance.user.search.email", "search"));
fieldEmail.addValue(removeNull(user.getEmail())); fieldEmail.addValue((user.isEmailVisible() ? removeNull(user.getEmail()) : ""));
items.add(fieldEmail); items.add(fieldEmail);
searchResults.addItemFields(items); searchResults.addItemFields(items);
...@@ -759,13 +759,13 @@ public class SearchPlugin implements Component, Plugin, PropertyEventListener { ...@@ -759,13 +759,13 @@ public class SearchPlugin implements Component, Plugin, PropertyEventListener {
if ("Name".equals(field)) { if ("Name".equals(field)) {
Element element = item.addElement(reverseFieldLookup Element element = item.addElement(reverseFieldLookup
.get(field)); .get(field));
element.addText(removeNull(user.getName())); element.addText(user.isNameVisible() ? removeNull(user.getName()) : "");
} }
if ("Email".equals(field)) { if ("Email".equals(field)) {
Element element = item.addElement(reverseFieldLookup Element element = item.addElement(reverseFieldLookup
.get(field)); .get(field));
element.addText(removeNull(user.getEmail())); element.addText(user.isEmailVisible() ? removeNull(user.getEmail()) : "");
} }
} }
} }
...@@ -1006,12 +1006,13 @@ public class SearchPlugin implements Component, Plugin, PropertyEventListener { ...@@ -1006,12 +1006,13 @@ public class SearchPlugin implements Component, Plugin, PropertyEventListener {
} }
} }
else if (field.equals("Name")) { else if (field.equals("Name")) {
if (query.equalsIgnoreCase(user.getName())) { if (user.isNameVisible()) {
foundUsers.add(user); if (query.equalsIgnoreCase(user.getName())) {
foundUsers.add(user);
}
} }
} } else if (field.equals("Email")) {
else if (field.equals("Email")) { if (user.isEmailVisible() && user.getEmail() != null) {
if (user.getEmail() != null) {
if (query.equalsIgnoreCase(user.getEmail())) { if (query.equalsIgnoreCase(user.getEmail())) {
foundUsers.add(user); foundUsers.add(user);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment