Commit e1a499ca authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gato

1) Users are not being loaded when using public shared groups. JM-222

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/trunk@3742 b35dd754-fafc-0310-a699-88a17e54d16e
parent b717415f
......@@ -6,8 +6,6 @@ import org.jivesoftware.wildfire.XMPPServer;
import org.jivesoftware.wildfire.auth.UnauthorizedException;
import org.jivesoftware.wildfire.group.Group;
import org.jivesoftware.wildfire.roster.RosterManager;
import org.jivesoftware.wildfire.user.UserManager;
import org.jivesoftware.wildfire.user.UserNotFoundException;
import org.xmpp.packet.IQ;
import org.xmpp.packet.PacketError;
......@@ -24,7 +22,6 @@ public class IQSharedGroupHandler extends IQHandler {
private IQHandlerInfo info;
private String serverName;
private UserManager userManager;
private RosterManager rosterManager;
public IQSharedGroupHandler() {
......@@ -44,22 +41,15 @@ public class IQSharedGroupHandler extends IQHandler {
return result;
}
try {
Collection<Group> groups = rosterManager.getSharedGroups(userManager.getUser(username));
Element sharedGroups = result.setChildElement("sharedgroup",
"http://www.jivesoftware.org/protocol/sharedgroup");
for (Group sharedGroup : groups) {
String displayName = sharedGroup.getProperties().get("sharedRoster.displayName");
if (displayName != null) {
sharedGroups.addElement("group").setText(displayName);
}
Collection<Group> groups = rosterManager.getSharedGroups(username);
Element sharedGroups = result.setChildElement("sharedgroup",
"http://www.jivesoftware.org/protocol/sharedgroup");
for (Group sharedGroup : groups) {
String displayName = sharedGroup.getProperties().get("sharedRoster.displayName");
if (displayName != null) {
sharedGroups.addElement("group").setText(displayName);
}
}
catch (UserNotFoundException e) {
// User not found return an error. This case should never happen.
result.setChildElement(packet.getChildElement().createCopy());
result.setError(PacketError.Condition.not_allowed);
}
return result;
}
......@@ -70,7 +60,6 @@ public class IQSharedGroupHandler extends IQHandler {
public void initialize(XMPPServer server) {
super.initialize(server);
serverName = server.getServerInfo().getName();
userManager = server.getUserManager();
rosterManager = server.getRosterManager();
}
}
......@@ -25,7 +25,6 @@ import org.jivesoftware.wildfire.event.GroupEventListener;
import org.jivesoftware.wildfire.group.Group;
import org.jivesoftware.wildfire.group.GroupManager;
import org.jivesoftware.wildfire.group.GroupNotFoundException;
import org.jivesoftware.wildfire.user.User;
import org.jivesoftware.wildfire.user.UserManager;
import org.jivesoftware.wildfire.user.UserNotFoundException;
import org.xmpp.packet.JID;
......@@ -162,16 +161,16 @@ public class RosterManager extends BasicModule implements GroupEventListener {
* belongs to a Group that may see a Group that whose members may include the Group in their
* rosters.
*
* @param user the user to return his shared groups.
* @param username the username of the user to return his shared groups.
* @return a collection with all the groups that the user may include in his roster.
*/
public Collection<Group> getSharedGroups(User user) {
public Collection<Group> getSharedGroups(String username) {
Collection<Group> answer = new HashSet<Group>();
Collection<Group> groups = GroupManager.getInstance().getSharedGroups();
for (Group group : groups) {
String showInRoster = group.getProperties().get("sharedRoster.showInRoster");
if ("onlyGroup".equals(showInRoster)) {
if (group.isUser(user.getUsername())) {
if (group.isUser(username)) {
// The user belongs to the group so add the group to the answer
answer.add(group);
}
......@@ -179,7 +178,7 @@ public class RosterManager extends BasicModule implements GroupEventListener {
// Check if the user belongs to a group that may see this group
Collection<Group> groupList = parseGroups(group.getProperties().get("sharedRoster.groupList"));
for (Group groupInList : groupList) {
if (groupInList.isUser(user.getUsername())) {
if (groupInList.isUser(username)) {
answer.add(group);
}
}
......@@ -334,6 +333,42 @@ public class RosterManager extends BasicModule implements GroupEventListener {
return false;
}
/**
* Returns true if the specified Group may be seen by all users in the system. The decision
* is made based on the group properties that are configurable through the Admin Console.
*
* @param group the group to check if it may be seen by all users in the system.
* @return true if the specified Group may be seen by all users in the system.
*/
public boolean isPulicSharedGroup(Group group) {
String showInRoster = group.getProperties().get("sharedRoster.showInRoster");
if ("everybody".equals(showInRoster)) {
return true;
}
return false;
}
/**
* Returns true if a shared group may be seen by any of the specified groups. The groups
* contained in the collection may or may not be a shared groups.
*
* @param sharedGroup the shared group to check its visibility.
* @param groups the groups to check if any of them can see the shared group.
* @return true if any of the specified groups can see the shared group.
*/
public boolean isSharedGroupVisible(Group sharedGroup, Collection<Group> groups) {
Map<String, String> properties = sharedGroup.getProperties();
String showInRoster = properties.get("sharedRoster.showInRoster");
if ("everybody".equals(showInRoster)) {
return true;
}
if ("onlyGroup".equals(showInRoster) ) {
Collection<Group> visibleGroups = parseGroups(properties.get("sharedRoster.groupList"));
return !Collections.disjoint(visibleGroups, groups);
}
return false;
}
public void memberAdded(Group group, Map params) {
JID addedUser = new JID((String) params.get("member"));
// Do nothing if the user was an admin that became a member
......@@ -661,8 +696,8 @@ public class RosterManager extends BasicModule implements GroupEventListener {
// Check if anyone can see this shared group
if ("everybody".equals(showInRoster)) {
// Add all users in the system
for (User user : UserManager.getInstance().getUsers()) {
users.add(server.createJID(user.getUsername(), null));
for (String username : UserManager.getInstance().getUsernames()) {
users.add(server.createJID(username, null));
}
// Add all logged users. We don't need to add all users in the system since only the
// logged ones will be affected.
......@@ -698,8 +733,8 @@ public class RosterManager extends BasicModule implements GroupEventListener {
// in the system since they all need to be in the roster with subscription "from"
if (group.isUser(roster.getUsername())) {
// Add all users in the system
for (User user : UserManager.getInstance().getUsers()) {
users.add(server.createJID(user.getUsername(),null));
for (String username : UserManager.getInstance().getUsernames()) {
users.add(server.createJID(username, null));
}
}
}
......
......@@ -194,6 +194,15 @@ public class UserManager implements IQResultListener {
return provider.getUsers();
}
/**
* Returns an unmodifiable Collection of usernames of all users in the system.
*
* @return an unmodifiable Collection of all usernames in the system.
*/
public Collection<String> getUsernames() {
return provider.getUsernames();
}
/**
* Returns an unmodifiable Collection of all users starting at <tt>startIndex</tt>
* with the given number of results. This is useful to support pagination in a GUI
......
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