java/code/src/com/redhat/rhn/frontend/action/groups/AdminListAction.java | 132 ++++++++++ java/code/src/com/redhat/rhn/frontend/strings/jsp/StringResource_en_US.xml | 9 java/code/src/com/redhat/rhn/manager/rhnset/RhnSetDecl.java | 10 java/code/src/com/redhat/rhn/manager/user/UserManager.java | 65 ++++ java/code/webapp/WEB-INF/nav/system_group_detail.xml | 2 java/code/webapp/WEB-INF/pages/groups/adminlist.jsp | 73 +++++ java/code/webapp/WEB-INF/pages/groups/detail.jsp | 2 java/code/webapp/WEB-INF/struts-config.xml | 15 + web/html/network/systems/groups/admin_list.pxt | 50 --- web/include/nav/system_group_detail.xml | 2 10 files changed, 299 insertions(+), 61 deletions(-)
New commits: commit 899ef200605f19e4dff0d6e5217b8c65e49f89d9 Author: Michael Mraka michael.mraka@redhat.com Date: Tue Dec 10 11:18:53 2013 +0100
System Group / Admins - updated links and removed old page
diff --git a/java/code/webapp/WEB-INF/nav/system_group_detail.xml b/java/code/webapp/WEB-INF/nav/system_group_detail.xml index 7671f0a..f6953e1 100644 --- a/java/code/webapp/WEB-INF/nav/system_group_detail.xml +++ b/java/code/webapp/WEB-INF/nav/system_group_detail.xml @@ -15,7 +15,7 @@ <rhn-tab-url>/network/systems/groups/apply_errata_confirm.pxt</rhn-tab-url> </rhn-tab>
- <rhn-tab name="Admins" url="/network/systems/groups/admin_list.pxt" acl="user_role(system_group_admin)" /> + <rhn-tab name="Admins" url="/rhn/groups/AdminList.do" acl="user_role(system_group_admin)" />
<rhn-tab name="Probes" url="/network/systems/groups/probe_list.pxt" acl="org_entitlement(rhn_monitor)" />
diff --git a/java/code/webapp/WEB-INF/pages/groups/detail.jsp b/java/code/webapp/WEB-INF/pages/groups/detail.jsp index 1064e6f..5b68d73 100644 --- a/java/code/webapp/WEB-INF/pages/groups/detail.jsp +++ b/java/code/webapp/WEB-INF/pages/groups/detail.jsp @@ -55,7 +55,7 @@
<rhn:require acl="user_role(org_admin) or user_role(system_group_admin)"> <br /> - <a href="/network/systems/groups/admin_list.pxt?sgid=${id}"><bean:message key="systemgroup.details.manageadmins"/></a> + <a href="/rhn/groups/AdminList.do?sgid=${id}"><bean:message key="systemgroup.details.manageadmins"/></a> </rhn:require> </td> </tr> diff --git a/web/html/network/systems/groups/admin_list.pxt b/web/html/network/systems/groups/admin_list.pxt deleted file mode 100644 index 218a83f..0000000 --- a/web/html/network/systems/groups/admin_list.pxt +++ /dev/null @@ -1,50 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<pxt-passthrough> - <pxt-use class="Grail::Frame" /> - <pxt-use class="Sniglets::Users" /> - <pxt-use class="Sniglets::ServerGroup" /> - <pxt-use class="Sniglets::Lists" /> - <pxt-use class="Sniglets::Navi" /> - <pxt-use class="Sniglets::HTML" /> - - <grail-canvas-template base="/templates/c.pxt" mode="main_canvas"> - -<pxt-include file="/network/components/system_groups/sgdc_header.pxi" /> - - <h2> - Group Administrators - </h2> - - <div class="page-summary"> - <p>Checked users may administer the systems in this group. Org Admins - may always administer all systems. System Group Admins are marked with - (*) and may modify all aspects of system groups assigned to them.</p> - </div> - -<pxt-include-late file="/network/components/message_queues/local.pxi" /> - -<rhn-listview class="Sniglets::ListView::UserList" mode="group_admins"> - <formvars> - <var name="sgid" /> - </formvars> - - <column name="Admin" label="group_admin_checkbox" width="5%" align="center" /> - - <column name="Username" label="login" align="left"> - <rhn-require acl="user_role(org_admin)"> - <url>/rhn/users/UserDetails.do?uid={column:id}</url> - </rhn-require> - </column> - - <column name="Full Name" label="full_name" /> - - <column name="Status" label="disabled" /> - - <action name="Update" label="update_system_group_membership" /> - - <empty_list_message>No Groups Available.</empty_list_message> -</rhn-listview> - - </grail-canvas-template> -</pxt-passthrough> - diff --git a/web/include/nav/system_group_detail.xml b/web/include/nav/system_group_detail.xml index 7671f0a..f6953e1 100644 --- a/web/include/nav/system_group_detail.xml +++ b/web/include/nav/system_group_detail.xml @@ -15,7 +15,7 @@ <rhn-tab-url>/network/systems/groups/apply_errata_confirm.pxt</rhn-tab-url> </rhn-tab>
- <rhn-tab name="Admins" url="/network/systems/groups/admin_list.pxt" acl="user_role(system_group_admin)" /> + <rhn-tab name="Admins" url="/rhn/groups/AdminList.do" acl="user_role(system_group_admin)" />
<rhn-tab name="Probes" url="/network/systems/groups/probe_list.pxt" acl="org_entitlement(rhn_monitor)" />
commit e17da982bd6c2676b721164eb5b3801fc5c0941f Author: Michael Mraka michael.mraka@redhat.com Date: Tue Dec 10 11:17:47 2013 +0100
ported System Group / Admins to java
diff --git a/java/code/src/com/redhat/rhn/frontend/action/groups/AdminListAction.java b/java/code/src/com/redhat/rhn/frontend/action/groups/AdminListAction.java new file mode 100644 index 0000000..e63a7da --- /dev/null +++ b/java/code/src/com/redhat/rhn/frontend/action/groups/AdminListAction.java @@ -0,0 +1,132 @@ +/** + * Copyright (c) 2013 Red Hat, Inc. + * + * This software is licensed to you under the GNU General Public License, + * version 2 (GPLv2). There is NO WARRANTY for this software, express or + * implied, including the implied warranties of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2 + * along with this software; if not, see + * http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt. + * + * Red Hat trademarks are not licensed under GPLv2. No permission is + * granted to use or replicate Red Hat trademarks that are incorporated + * in this software or its documentation. + */ +package com.redhat.rhn.frontend.action.groups; + +import com.redhat.rhn.domain.server.ManagedServerGroup; +import com.redhat.rhn.domain.server.ServerGroupFactory; +import com.redhat.rhn.domain.role.RoleFactory; +import com.redhat.rhn.domain.user.User; +import com.redhat.rhn.frontend.action.common.BadParameterException; +import com.redhat.rhn.frontend.dto.UserOverview; +import com.redhat.rhn.frontend.struts.RequestContext; +import com.redhat.rhn.frontend.struts.RhnAction; +import com.redhat.rhn.frontend.struts.StrutsDelegate; +import com.redhat.rhn.frontend.taglibs.list.helper.ListRhnSetHelper; +import com.redhat.rhn.frontend.taglibs.list.helper.Listable; +import com.redhat.rhn.frontend.xmlrpc.PermissionCheckFailureException; +import com.redhat.rhn.manager.rhnset.RhnSetDecl; +import com.redhat.rhn.manager.user.UserManager; + +import org.apache.struts.action.ActionForm; +import org.apache.struts.action.ActionForward; +import org.apache.struts.action.ActionMapping; + +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + + +/** + * AdminListAction + */ +public class AdminListAction extends RhnAction implements Listable { + + + /** {@inheritDoc} */ + public ActionForward execute(ActionMapping mapping, + ActionForm formIn, + HttpServletRequest request, + HttpServletResponse response) { + + RequestContext requestContext = new RequestContext(request); + ManagedServerGroup serverGroup = requestContext.lookupAndBindServerGroup(); + User user = requestContext.getCurrentUser(); + + if (serverGroup == null) { + throw new BadParameterException("Invalid " + RequestContext.SERVER_GROUP_ID + + " parameter:" + serverGroup.getId()); + } + + + ListRhnSetHelper helper = new ListRhnSetHelper(this, request, + RhnSetDecl.setForSystemGroupAdmins(serverGroup)); + Set<Long> preselected = new HashSet<Long>(); + for (User item : (List<User>) ServerGroupFactory.listAdministrators(serverGroup)) { + preselected.add(item.getId()); + } + helper.preSelect(preselected); + + Map params = makeParamMap(request); + params.put(RequestContext.SERVER_GROUP_ID, serverGroup.getId()); + + if (requestContext.isSubmitted()) { + // make sure the user has enough perms + if (!UserManager.canAdministerSystemGroup(user, serverGroup)) { + throw new PermissionCheckFailureException(); + } + + long updated = 0; + // remove admins + for (Iterator<Long> iter = helper.getRemovedKeys().iterator(); + iter.hasNext();) { + Long uid = iter.next(); + if (!UserManager.hasRole(uid, RoleFactory.ORG_ADMIN)) { + UserManager.revokeServerGroupPermission(uid, serverGroup.getId()); + } + updated++; + } + + // add group admins + for (Iterator<Long> iter = helper.getAddedKeys().iterator(); iter.hasNext();) { + Long uid = iter.next(); + if (!UserManager.hasRole(uid, RoleFactory.ORG_ADMIN)) { + UserManager.revokeServerGroupPermission(uid, serverGroup.getId()); + UserManager.grantServerGroupPermission(uid, serverGroup.getId()); + } + updated++; + } + if (updated > 0) { + createSuccessMessage(request, "systemgroup.admins.updated", + serverGroup.getName()); + } + return StrutsDelegate.getInstance().forwardParams( + mapping.findForward("submitted"), params); + } + + helper.execute(); + + return StrutsDelegate.getInstance().forwardParams( + mapping.findForward("default"), params); + } + + /** {@inheritDoc} */ + public List getResult(RequestContext context) { + User currentUser = context.getCurrentUser(); + List<UserOverview> userList = UserManager.activeInOrg2(currentUser); + for (UserOverview uo : userList) { + if (UserManager.hasRole(uo.getId(), RoleFactory.ORG_ADMIN)) { + uo.setDisabled(true); + } + else if (UserManager.hasRole(uo.getId(), RoleFactory.SYSTEM_GROUP_ADMIN)) { + uo.setLogin(uo.getLogin() + "*"); + } + } + return userList; + } +} diff --git a/java/code/src/com/redhat/rhn/frontend/strings/jsp/StringResource_en_US.xml b/java/code/src/com/redhat/rhn/frontend/strings/jsp/StringResource_en_US.xml index 3a04505..c83168e 100644 --- a/java/code/src/com/redhat/rhn/frontend/strings/jsp/StringResource_en_US.xml +++ b/java/code/src/com/redhat/rhn/frontend/strings/jsp/StringResource_en_US.xml @@ -5240,6 +5240,15 @@ value for this entitlement, excluding the default organization's consumption.</s <trans-unit id="systems.groups.jsp.add"> <source>Join Selected Groups</source> </trans-unit> + <trans-unit id="systemgroup.admins.title"> + <source>Group Administrators</source> + </trans-unit> + <trans-unit id="systemgroup.admins.summary"> + <source>Checked users may administer the systems in this group. Org Admins may always administer all systems. System Group Admins are marked with (*) and may modify all aspects of system groups assigned to them.</source> + </trans-unit> + <trans-unit id="systemgroup.admins.updated"> + <source>Admin list for system group <strong>{0}</strong> updated.</source> + </trans-unit> <trans-unit id="systemgroup.target-systems.summary"> <source>The following are systems that may be added to this group.</source> </trans-unit> diff --git a/java/code/src/com/redhat/rhn/manager/rhnset/RhnSetDecl.java b/java/code/src/com/redhat/rhn/manager/rhnset/RhnSetDecl.java index 3eb1775..1ebca1c 100644 --- a/java/code/src/com/redhat/rhn/manager/rhnset/RhnSetDecl.java +++ b/java/code/src/com/redhat/rhn/manager/rhnset/RhnSetDecl.java @@ -18,6 +18,7 @@ import com.redhat.rhn.common.util.Asserts; import com.redhat.rhn.domain.channel.Channel; import com.redhat.rhn.domain.rhnset.RhnSet; import com.redhat.rhn.domain.rhnset.SetCleanup; +import com.redhat.rhn.domain.server.ManagedServerGroup; import com.redhat.rhn.domain.server.Server; import com.redhat.rhn.domain.user.User; import com.redhat.rhn.frontend.action.SetLabels; @@ -549,6 +550,15 @@ public class RhnSetDecl { return make("managers_for_channel" + chan.getId(), SetCleanup.NOOP); }
+ /** + * get the set for system group admins + * @param sysgroup channel passed in + * @return the Set descl + */ + public static RhnSetDecl setForSystemGroupAdmins(ManagedServerGroup sysgroup) { + return make("system_group_admins" + sysgroup.getId(), SetCleanup.NOOP); + } + public static final RhnSetDecl SYSTEM_NOTES = make("systems_notes", SetCleanup.NOOP);
diff --git a/java/code/src/com/redhat/rhn/manager/user/UserManager.java b/java/code/src/com/redhat/rhn/manager/user/UserManager.java index c82cd2c..bf758fa 100644 --- a/java/code/src/com/redhat/rhn/manager/user/UserManager.java +++ b/java/code/src/com/redhat/rhn/manager/user/UserManager.java @@ -28,6 +28,7 @@ import com.redhat.rhn.domain.org.Org; import com.redhat.rhn.domain.org.OrgFactory; import com.redhat.rhn.domain.role.Role; import com.redhat.rhn.domain.role.RoleFactory; +import com.redhat.rhn.domain.server.ManagedServerGroup; import com.redhat.rhn.domain.server.Server; import com.redhat.rhn.domain.user.Address; import com.redhat.rhn.domain.user.RhnTimeZone; @@ -42,6 +43,7 @@ import com.redhat.rhn.frontend.listview.PageControl; import com.redhat.rhn.frontend.taglibs.list.decorators.PageSizeDecorator; import com.redhat.rhn.manager.BaseManager; import com.redhat.rhn.manager.SatManager; +import com.redhat.rhn.manager.system.ServerGroupManager;
import org.apache.log4j.Logger;
@@ -232,10 +234,10 @@ public class UserManager extends BaseManager {
/** * Revokes permission from the given User to the ServerGroup whose id is sgid. - * @param usr User who no longer needs permission + * @param uid Id of user who no longer needs permission * @param sgid ServerGroup ID */ - public static void revokeServerGroupPermission(final User usr, + public static void revokeServerGroupPermission(final Long uid, final long sgid) { SelectMode sm = ModeFactory.getMode("User_queries", "check_server_group_permissions_for_revoke"); @@ -243,25 +245,35 @@ public class UserManager extends BaseManager { "remove_server_group_permissions");
Map params = new HashMap(); - params.put("user_id", usr.getId()); + params.put("user_id", uid); params.put("server_group_id", new Long(sgid));
DataResult dr = sm.execute(params); for (Iterator itr = dr.iterator(); itr.hasNext();) { Map row = (Map)itr.next(); - long uid = ((Long)row.get("user_id")).longValue(); - if (uid == usr.getId().longValue()) { + long ruid = ((Long)row.get("user_id")).longValue(); + if (ruid == uid.longValue()) { m.execute(params, new HashMap()); } } }
/** + * Revokes permission from the given User to the ServerGroup whose id is sgid. + * @param usr User who no longer needs permission + * @param sgid ServerGroup ID + */ + public static void revokeServerGroupPermission(final User usr, + final long sgid) { + revokeServerGroupPermission(usr.getId(), sgid); + } + + /** * Grants the given User permission to the ServerGroup whose id is sgid. - * @param usr User who needs permission + * @param uid Id of user who needs permission * @param sgid ServerGroup ID */ - public static void grantServerGroupPermission(final User usr, + public static void grantServerGroupPermission(final Long uid, final long sgid) { SelectMode sm = ModeFactory.getMode("User_queries", "check_server_group_permissions"); @@ -269,7 +281,7 @@ public class UserManager extends BaseManager { "set_server_group_permissions");
Map params = new HashMap(); - params.put("user_id", usr.getId()); + params.put("user_id", uid); params.put("server_group_id", new Long(sgid));
DataResult dr = sm.execute(params); @@ -279,6 +291,16 @@ public class UserManager extends BaseManager { }
/** + * Grants the given User permission to the ServerGroup whose id is sgid. + * @param usr User who needs permission + * @param sgid ServerGroup ID + */ + public static void grantServerGroupPermission(final User usr, + final long sgid) { + grantServerGroupPermission(usr.getId(), sgid); + } + + /** * Add and remove the specified roles from the user. * * @param usr The User who's Roles you want to update @@ -515,6 +537,20 @@ public class UserManager extends BaseManager { }
/** + * Check role for the specified user. + * @param uid The id of the user to lookup. + * @param label Role to check. + * @return the specified user. + */ + public static boolean hasRole(Long uid, Role label) { + if (uid == null) { + return false; + } + + return UserFactory.lookupById(uid).hasRole(label); + } + + /** * Retrieve the specified user, assuming that the User making the request * has the required permissions. * @param user The user making the lookup request @@ -796,6 +832,19 @@ public class UserManager extends BaseManager { }
/** + * can a system group be administered by user? + * @param user User + * @param group SystemGroup + * @return true if user can administer system group + */ + public static boolean canAdministerSystemGroup(User user, ManagedServerGroup group) { + return (user != null && + group != null && + ServerGroupManager.getInstance().canAccess(user, group) && + user.hasRole(RoleFactory.SYSTEM_GROUP_ADMIN)); + } + + /** * Returns the System Groups associated with the given User * bounded by the values of the PageControl. * @param user User whose SystemGroups are sought. diff --git a/java/code/webapp/WEB-INF/pages/groups/adminlist.jsp b/java/code/webapp/WEB-INF/pages/groups/adminlist.jsp new file mode 100644 index 0000000..51d989e --- /dev/null +++ b/java/code/webapp/WEB-INF/pages/groups/adminlist.jsp @@ -0,0 +1,73 @@ +<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> +<%@ taglib uri="http://rhn.redhat.com/rhn" prefix="rhn" %> +<%@ taglib uri="http://rhn.redhat.com/tags/list" prefix="rl" %> +<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %> + +<html> +<head> + <meta name="page-decorator" content="none" /> +</head> +<body> + +<%@ include file="/WEB-INF/pages/common/fragments/groups/header.jspf" %> + +<h2> + <bean:message key="systemgroup.admins.title"/> +</h2> + +<div class="page-summary"> +<bean:message key="systemgroup.admins.summary"/> +</div> + +<rl:listset name="groupAdmins"> + <rhn:csrf /> + <input type="hidden" name="sgid" value="${systemgroup.id}" /> + + rl:list + + <rl:decorator name="SelectableDecorator"/> + <rl:decorator name="PageSizeDecorator"/> + + <rl:selectablecolumn value="${current.id}" + selected="${current.selected}" + disabled="${current.disabled}"> + </rl:selectablecolumn> + + <rl:column sortable="true" + bound="false" + headerkey="username.nopunc.displayname" + sortattr="login" + filterattr="name" + defaultsort="asc" > + + <a href="/rhn/users/UserDetails.do?uid=${current.id}"> + ${current.login} + </a> + </rl:column> + + <rl:column sortable="false" + bound="false" + headerkey="realname.displayname" > + ${current.userLastName}, ${current.userFirstName} + </rl:column> + + <rl:column sortable="true" + sortattr="status" + bound="false" + headerkey="userlist.jsp.status" > + ${current.status} + </rl:column> + + </rl:list> + + <div class="text-right"> + <hr /> + <input type="submit" name="confirm" + value="<bean:message key='message.Update'/>" /> + </div> + rhn:submitted/ + +</rl:listset> + +</body> +</html> diff --git a/java/code/webapp/WEB-INF/struts-config.xml b/java/code/webapp/WEB-INF/struts-config.xml index 48e51ee..6ce376e 100644 --- a/java/code/webapp/WEB-INF/struts-config.xml +++ b/java/code/webapp/WEB-INF/struts-config.xml @@ -3866,6 +3866,21 @@ redirect="true" /> </action>
+ + <action path="/groups/AdminList" + scope="request" + type="com.redhat.rhn.frontend.action.groups.AdminListAction" + className="com.redhat.rhn.frontend.struts.RhnActionMapping"> + <set-property property="postRequiredIfSubmitted" value="true" /> + <set-property property="acls" + value="user_role(system_group_admin)"/> + <forward name="default" + path="/WEB-INF/pages/groups/adminlist.jsp" /> + <forward name="submitted" + path="/groups/AdminList.do" + redirect="true" /> + </action> + <action path="/groups/AddSystems" scope="request" type="com.redhat.rhn.frontend.action.groups.AddSystemsAction"
spacewalk-commits@lists.fedorahosted.org