Commit 4ff26df1 authored by Dave Cridland's avatar Dave Cridland

Merge pull request #102 from Redor/openfire

OF-250: Allow to configure the groups of a user from the user profile
parents d34229d5 6bcf79ee
......@@ -537,13 +537,11 @@
## Added key: 'server.properties.encrypt_confirm'
##
## 3.10.0
## Added key: 'user.properties.additional_propertie'
## Added key: 'user.properties.additional_properties'
## Added key: 'user.groups.title'
## Added key: 'user.groups.info'
## Added key: 'user.groups.member.info'
## Added key: 'user.groups.name'
## Added key: 'user.groups.none'
## Added key: 'user.groups.member'
## Added key: 'user.groups.admin'
## Added key: 'user.groups.form.update'
# Openfire
......@@ -2578,10 +2576,8 @@ user.lockout.time.minutes=minutes
user.groups.title=User Groups
user.groups.info=Below is a list of groups available for the user
user.groups.member.info=Below is a list of groups for user
user.groups.name=Group Name
user.groups.none=None
user.groups.member=Member
user.groups.admin=Admin
user.groups.form.update=User groups edited successfully.
# Plugins Admin Page
......
......@@ -21,6 +21,7 @@
import="org.jivesoftware.openfire.PresenceManager,
org.jivesoftware.openfire.group.Group,
org.jivesoftware.openfire.group.GroupManager,
org.jivesoftware.openfire.group.GroupNotFoundException,
org.jivesoftware.openfire.security.SecurityAuditManager,
org.jivesoftware.openfire.user.User,
org.jivesoftware.openfire.user.UserManager,
......@@ -47,84 +48,246 @@
<%
// Get parameters
boolean cancel = request.getParameter("cancel") != null;
boolean update = request.getParameter("update") != null;
String add = StringUtils.escapeHTMLTags(ParamUtils.getParameter(request, "add"));
String delete = StringUtils.escapeHTMLTags(ParamUtils.getParameter(request, "delete"));
boolean success = ParamUtils.getBooleanParameter(request,"updatesuccess");
String username = ParamUtils.getParameter(request, "username");
Map<String, String> errors = new HashMap<String, String>();
String username = StringUtils.escapeHTMLTags(ParamUtils.getParameter(request, "username"));
JID jid = webManager.getXMPPServer().createJID(username, null);
GroupManager groupManager = webManager.getGroupManager();
Collection<Group> groups = webManager.getGroupManager().getGroups();
// Handle a cancel
if (cancel) {
response.sendRedirect("user-properties.jsp?username=" + URLEncoder.encode(username, "UTF-8"));
if(add != null) {
try {
Group group = webManager.getGroupManager().getGroup(add);
group.getMembers().add(jid);
response.sendRedirect("user-groups.jsp?username=" + URLEncoder.encode(username, "UTF-8") + "&updatesuccess=true");
} catch (GroupNotFoundException exp) {
return;
}
}
if(success) { %>
<div class="jive-success">
<table cellpadding="0" cellspacing="0" border="0">
<tbody>
<tr><td class="jive-icon"><img src="images/success-16x16.gif" width="16" height="16" border="0" alt=""></td>
<td class="jive-icon-label">
<fmt:message key="user.groups.form.update" />
</td></tr>
</tbody>
</table>
</div><br> <%
if(delete != null) {
try {
Group group = webManager.getGroupManager().getGroup(delete);
group.getMembers().remove(jid);
response.sendRedirect("user-groups.jsp?username=" + URLEncoder.encode(username, "UTF-8") + "&updatesuccess=true");
} catch (GroupNotFoundException exp) {
return;
}
}
// Handle a save/update
if(update) {
for (Group group : groups) {
String role = ParamUtils.getParameter(request, URLEncoder.encode(group.getName(), "UTF-8"));
if("admin".equals(role)) {
if(!group.getAdmins().contains(jid)) {
group.getAdmins().add(jid);
// Load the user object
User user = null;
try {
user = webManager.getUserManager().getUser(username);
}
} else if("member".equals(role)) {
if(!group.getMembers().contains(jid)) {
group.getMembers().add(jid);
catch (UserNotFoundException unfe) {
}
} else {
if(group.getMembers().contains(jid)) {
group.getMembers().remove(jid);
Collection<Group> userGroups = webManager.getGroupManager().getGroups(user);
int start = ParamUtils.getIntParameter(request,"start",0);
int range = ParamUtils.getIntParameter(request,"range",15);
if (request.getParameter("range") != null) {
webManager.setRowsPerPage("group-summary", range);
}
if(group.getAdmins().contains(jid)) {
group.getAdmins().remove(jid);
ArrayList<Group> groups = new ArrayList<Group>(webManager.getGroupManager().getGroups());
// Remove already joined groups
groups.removeAll(userGroups);
int groupCount = groups.size();
int groupIndex = start + range;
String search = null;
if (webManager.getGroupManager().isSearchSupported() && request.getParameter("search") != null
&& !request.getParameter("search").trim().equals("")) {
search = request.getParameter("search");
search = StringUtils.escapeHTMLTags(search);
// Use the search terms to get the list of groups.
groups = new ArrayList<Group>(webManager.getGroupManager().search(search));
// Count already joined groups in the search result
int userGroupCount = 0;
for(Group group : groups) {
if(userGroups.contains(group)) {
userGroupCount++;
}
}
groups.removeAll(userGroups);
groupCount = groups.size() - userGroupCount;
}
response.sendRedirect("user-groups.jsp?username=" + URLEncoder.encode(username, "UTF-8") + "&updatesuccess=true");
return;
if(groupIndex >= groupCount) {
groupIndex = groupCount;
}
// paginator vars
int numPages = (int)Math.ceil((double)groupCount/(double)range);
int curPage = (start/range) + 1;
if(success) {
%>
<div class="jive-success">
<table cellpadding="0" cellspacing="0" border="0">
<tbody>
<tr>
<td class="jive-icon"><img src="images/success-16x16.gif"
width="16" height="16" border="0" alt=""></td>
<td class="jive-icon-label"><fmt:message
key="user.groups.form.update" /></td>
</tr>
</tbody>
</table>
</div>
<br>
<%
}
%>
<html>
<head>
<title><fmt:message key="user.groups.title" /></title>
<meta name="subPageID" content="user-groups" />
<meta name="extraParams" content="<%= "username="+URLEncoder.encode(username, "UTF-8") %>"/>
<title><fmt:message key="user.groups.title" /></title>
<meta name="subPageID" content="user-groups" />
<meta name="extraParams"
content="<%="username="+URLEncoder.encode(username, "UTF-8")%>" />
</head>
<body>
<p>
<fmt:message key="user.groups.member.info" />
<b><%=username%>.</b>
</p>
<div class="jive-table">
<table cellpadding="0" cellspacing="0" border="0" width="100%">
<thead>
<tr>
<th>&nbsp;</th>
<th><fmt:message key="user.groups.name" /></th>
<th><fmt:message key="global.delete" /></th>
</tr>
</thead>
<tbody>
<%
// Print the list of groups
if (userGroups.isEmpty()) {
%>
<tr>
<td align="center" colspan="6"><fmt:message
key="group.summary.no_groups" /></td>
</tr>
<%
}
int x = 0;
for (Group group : userGroups) {
String groupName = URLEncoder.encode(group.getName(), "UTF-8");
x++;
%>
<tr class="jive-<%=(((x % 2) == 0) ? "even" : "odd")%>">
<td width="1%" valign="top"><%=x%></td>
<td><a href="group-edit.jsp?group=<%=groupName%>"><%=StringUtils.escapeHTMLTags(group.getName())%></a>
<%
if (group.getDescription() != null) {
%> <br> <span class="jive-description"> <%=StringUtils.escapeHTMLTags(group.getDescription())%>
</span> <%
}
%></td>
<td width="5%"><a
href="user-groups.jsp?username=<%=URLEncoder.encode(user.getUsername(), "UTF-8")%>&delete=<%=groupName%>"
title="<fmt:message key="global.click_delete" />"><img
src="images/delete-16x16.gif" width="16" height="16" border="0"
alt="<fmt:message key="global.click_delete" />"></a></td>
</tr>
<%
}
%>
</tbody>
</table>
</div>
<br />
<p>
<fmt:message key="user.groups.info" />
<b><%=username%>.</b>
</p>
<%
if (webManager.getGroupManager().isSearchSupported()) {
%>
<form action="user-groups.jsp" method="get" name="searchForm">
<table border="0" width="100%" cellpadding="0" cellspacing="0">
<tr>
<td valign="bottom"><fmt:message
key="group.summary.total_group" /> <b><%=groupCount%></b></td>
<td align="right" valign="bottom"><fmt:message
key="group.summary.search" />: <input type="text" size="30"
maxlength="150" name="search"
value="<%=((search!=null) ? search : "")%>"></td>
</tr>
</table>
<input type="hidden" name="username"
value="<%=StringUtils.escapeForXML(user.getUsername())%>">
</form>
<script language="JavaScript" type="text/javascript">
document.searchForm.search.focus();
</script>
<%
}
// Otherwise, searching is not supported.
else {
%>
<p>
<fmt:message key="user.groups.info" /> <b><%= username %>.</b>
<fmt:message key="group.summary.total_group" />
<b><%=groupCount%></b>
<%
if (numPages > 1) {
%>
,
<fmt:message key="global.showing" />
<%=(start + 1)%>-<%=(start + range)%>
<%
}
%>
</p>
<%
}
%>
<%
if (numPages > 1) {
%>
<p>
<fmt:message key="global.pages" />
[
<%
for (int i = 0; i < numPages; i++) {
String sep = ((i + 1) < numPages) ? " " : "";
boolean isCurrent = (i + 1) == curPage;
%>
<a
href="user-groups.jsp?username=<%=StringUtils.escapeForXML(user.getUsername())%>&start=<%=(i * range)%><%=search != null ? "&search=" + URLEncoder.encode(search, "UTF-8") : ""%>"
class="<%=((isCurrent) ? "jive-current" : "")%>"><%=(i + 1)%></a><%=sep%>
<%
}
%>
]
</p>
<%
}
%>
<form action="user-groups.jsp" method="post" name="main">
<div class="jive-table">
<table cellpadding="0" cellspacing="0" border="0" width="100%">
<thead>
<tr>
<th>&nbsp;</th>
<th nowrap><fmt:message key="user.groups.name" /></th>
<th nowrap><fmt:message key="user.groups.none" /></th>
<th nowrap><fmt:message key="user.groups.member" /></th>
<th nowrap><fmt:message key="user.groups.admin" /></th>
<th nowrap><fmt:message key="global.add" /></th>
</tr>
</thead>
<tbody>
......@@ -134,19 +297,20 @@
if (groups.isEmpty()) {
%>
<tr>
<td align="center" colspan="6"><fmt:message key="group.summary.no_groups" /></td>
<td align="center" colspan="6"><fmt:message
key="group.summary.no_groups" /></td>
</tr>
<%
}
int i = 0;
for (Group group : groups) {
for (Group group : groups.subList(start, groupIndex)) {
String groupName = URLEncoder.encode(group.getName(), "UTF-8");
i++;
%>
<tr class="jive-<%=(((i % 2) == 0) ? "even" : "odd")%>">
<td width="1%" valign="top"><%=i%></td>
<td width="40%"><a href="group-edit.jsp?group=<%=groupName%>"><%=StringUtils.escapeHTMLTags(group.getName())%></a>
<td><a href="group-edit.jsp?group=<%=groupName%>"><%=StringUtils.escapeHTMLTags(group.getName())%></a>
<%
if (group.getDescription() != null) {
%> <br> <span class="jive-description"> <%=StringUtils.escapeHTMLTags(group.getDescription())%>
......@@ -154,18 +318,11 @@
}
%></td>
<td width="10%"><input type="radio"
name="<%= groupName %>" value="none"
<% if (!group.isUser(jid)) { %> checked <% } %>>
</td>
<td width="10%"><input type="radio"
name="<%= groupName %>" value="member"
<% if (group.getMembers().contains(jid)) { %> checked <% } %>>
</td>
<td width="10%"><input type="radio"
name="<%= groupName %>" value="admin"
<% if (group.getAdmins().contains(jid)) { %> checked <% } %>>
</td>
<td width="5%"><a
href="user-groups.jsp?username=<%=URLEncoder.encode(user.getUsername(), "UTF-8")%>&add=<%=groupName%>"
title="<fmt:message key="global.click_add" />"> <img
src="images/add-16x16.gif" width="16" height="16" border="0"
alt="<fmt:message key="global.click_add" />"></a></td>
</tr>
<%
}
......@@ -173,11 +330,32 @@
</tbody>
</table>
</div>
<br />
<input type="hidden" name="username" value="<%= StringUtils.escapeForXML(username) %>">
<input type="submit" name="update" value="<fmt:message key="global.save_changes" />">
<input type="submit" name="cancel" value="<fmt:message key="global.cancel" />">
</form>
<%
if (numPages > 1) {
%>
<br>
<p>
<fmt:message key="global.pages" />
[
<%
for (i = 0; i < numPages; i++) {
String sep = ((i + 1) < numPages) ? " " : "";
boolean isCurrent = (i + 1) == curPage;
%>
<a
href="user-groups.jsp?username=<%=StringUtils.escapeForXML(user.getUsername())%>&start=<%=(i * range)%><%=search != null ? "&search=" + URLEncoder.encode(search, "UTF-8") : ""%>"
class="<%=((isCurrent) ? "jive-current" : "")%>"><%=(i + 1)%></a><%=sep%>
<%
}
%>
]
</p>
<%
}
%>
</body>
</html>
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