continuum-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From c...@apache.org
Subject svn commit: r1237517 - in /continuum/trunk/continuum-webapp/src: main/java/org/apache/maven/continuum/web/action/ main/java/org/apache/maven/continuum/web/bean/ test/java/org/apache/maven/continuum/web/action/ test/java/org/apache/maven/continuum/web/a...
Date Mon, 30 Jan 2012 00:49:26 GMT
Author: ctan
Date: Mon Jan 30 00:49:25 2012
New Revision: 1237517

URL: http://svn.apache.org/viewvc?rev=1237517&view=rev
Log:
[CONTINUUM-2672] correctly display the roles of members in a group

Added:
    continuum/trunk/continuum-webapp/src/test/java/org/apache/maven/continuum/web/action/ProjectGroupActionTest.java
    continuum/trunk/continuum-webapp/src/test/java/org/apache/maven/continuum/web/action/stub/ProjectGroupActionStub.java
Modified:
    continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/ContinuumActionSupport.java
    continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/ProjectGroupAction.java
    continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/bean/ProjectGroupUserBean.java

Modified: continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/ContinuumActionSupport.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/ContinuumActionSupport.java?rev=1237517&r1=1237516&r2=1237517&view=diff
==============================================================================
--- continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/ContinuumActionSupport.java
(original)
+++ continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/ContinuumActionSupport.java
Mon Jan 30 00:49:25 2012
@@ -33,6 +33,8 @@ import org.codehaus.plexus.redback.autho
 import org.codehaus.plexus.redback.system.SecuritySession;
 import org.codehaus.plexus.redback.system.SecuritySystem;
 import org.codehaus.plexus.redback.system.SecuritySystemConstants;
+import org.codehaus.plexus.redback.users.User;
+import org.codehaus.plexus.redback.users.UserNotFoundException;
 import org.codehaus.plexus.util.StringUtils;
 
 /**
@@ -568,4 +570,10 @@ public class ContinuumActionSupport
         }
         return principal;
     }
+
+    protected User getUser( String principal )
+        throws UserNotFoundException
+    {
+        return getSecuritySystem().getUserManager().findUser( principal );
+    }
 }

Modified: continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/ProjectGroupAction.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/ProjectGroupAction.java?rev=1237517&r1=1237516&r2=1237517&view=diff
==============================================================================
--- continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/ProjectGroupAction.java
(original)
+++ continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/ProjectGroupAction.java
Mon Jan 30 00:49:25 2012
@@ -727,7 +727,7 @@ public class ProjectGroupAction
             List<UserAssignment> userAssignments = rbac.getUserAssignmentsForRoles(
roleNames );
             for ( UserAssignment ua : userAssignments )
             {
-                User u = getSecuritySystem().getUserManager().findUser( ua.getPrincipal()
);
+                User u = getUser( ua.getPrincipal() );
                 if ( u != null )
                 {
                     users.add( u );
@@ -766,16 +766,21 @@ public class ProjectGroupAction
             try
             {
                 Collection<Role> effectiveRoles = rbac.getEffectivelyAssignedRoles(
user.getUsername() );
+                boolean isGroupUser = false;
 
                 for ( Role role : effectiveRoles )
                 {
                     if ( role.getName().indexOf( projectGroup.getName() ) > -1 )
                     {
-                        pgUser.setRoles( effectiveRoles );
-                        projectGroupUsers.add( pgUser );
-                        break;
+                        pgUser.addRole( role );
+                        isGroupUser = true;
                     }
                 }
+
+                if ( isGroupUser )
+                {
+                    projectGroupUsers.add( pgUser );
+                }
             }
             catch ( RbacObjectNotFoundException e )
             {
@@ -1118,4 +1123,10 @@ public class ProjectGroupAction
     {
         this.sorterProperty = sorterProperty;
     }
+
+    // for testing
+    public void setRbacManager( RBACManager rbac )
+    {
+        this.rbac = rbac;
+    }
 }

Modified: continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/bean/ProjectGroupUserBean.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/bean/ProjectGroupUserBean.java?rev=1237517&r1=1237516&r2=1237517&view=diff
==============================================================================
--- continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/bean/ProjectGroupUserBean.java
(original)
+++ continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/bean/ProjectGroupUserBean.java
Mon Jan 30 00:49:25 2012
@@ -23,6 +23,7 @@ import org.apache.maven.continuum.model.
 import org.codehaus.plexus.redback.rbac.Role;
 import org.codehaus.plexus.redback.users.User;
 
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Iterator;
 
@@ -73,21 +74,26 @@ public class ProjectGroupUserBean
         this.projectGroup = projectGroup;
     }
 
-    public void addRole( String role )
+    public void addRole( Role role )
     {
+        if ( roles == null )
+        {
+            roles = new ArrayList();
+        }
+
         roles.add( role );
 
-        if ( role.indexOf( ROLE_ADMINISTRATOR ) != -1 )
+        if ( role.getName().indexOf( ROLE_ADMINISTRATOR ) != -1 )
         {
             isAdministrator = true;
         }
 
-        if ( role.indexOf( ROLE_DEVELOPER ) != -1 )
+        if ( role.getName().indexOf( ROLE_DEVELOPER ) != -1 )
         {
             isDeveloper = true;
         }
 
-        if ( role.indexOf( ROLE_USER ) != -1 )
+        if ( role.getName().indexOf( ROLE_USER ) != -1 )
         {
             isUser = true;
         }

Added: continuum/trunk/continuum-webapp/src/test/java/org/apache/maven/continuum/web/action/ProjectGroupActionTest.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-webapp/src/test/java/org/apache/maven/continuum/web/action/ProjectGroupActionTest.java?rev=1237517&view=auto
==============================================================================
--- continuum/trunk/continuum-webapp/src/test/java/org/apache/maven/continuum/web/action/ProjectGroupActionTest.java
(added)
+++ continuum/trunk/continuum-webapp/src/test/java/org/apache/maven/continuum/web/action/ProjectGroupActionTest.java
Mon Jan 30 00:49:25 2012
@@ -0,0 +1,135 @@
+package org.apache.maven.continuum.web.action;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.continuum.web.action.AbstractActionTest;
+import org.apache.maven.continuum.Continuum;
+import org.apache.maven.continuum.model.project.ProjectGroup;
+import org.apache.maven.continuum.web.action.stub.ProjectGroupActionStub;
+import org.apache.maven.continuum.web.bean.ProjectGroupUserBean;
+import org.codehaus.plexus.redback.rbac.RBACManager;
+import org.codehaus.plexus.redback.rbac.Role;
+import org.codehaus.plexus.redback.rbac.UserAssignment;
+import org.codehaus.plexus.redback.rbac.jdo.JdoRole;
+import org.codehaus.plexus.redback.rbac.jdo.JdoUserAssignment;
+import org.jmock.Mock;
+
+public class ProjectGroupActionTest
+    extends AbstractActionTest
+{
+    private ProjectGroupActionStub action;
+
+    private Mock continuum;
+
+    private Mock rbac;
+
+    protected void setUp()
+        throws Exception
+    {
+        super.setUp();
+
+        action = new ProjectGroupActionStub();
+        continuum = mock( Continuum.class );
+        rbac = mock( RBACManager.class );
+
+        action.setContinuum( (Continuum) continuum.proxy() );
+        action.setRbacManager( (RBACManager) rbac.proxy() );
+    }
+
+    public void testViewMembersWithProjectAdminRole()
+        throws Exception
+    {
+        ProjectGroup group = new ProjectGroup();
+        group.setName( "test-group" );
+
+        List<Role> roles = new ArrayList<Role>();
+        Role role1 = new JdoRole();
+        role1.setName( "Project User - test-group" );
+        roles.add( role1 );
+
+        Role role2 = new JdoRole();
+        role2.setName( "Continuum Manage Scheduling" );
+        roles.add( role2 );
+        
+        Role role3 = new JdoRole();
+        role3.setName( "Project Developer - test-group" );
+        roles.add( role3 );
+
+        Role role4 = new JdoRole();
+        role4.setName( "Project Administrator - test-group" );
+        roles.add( role4 );
+
+        List<UserAssignment> userAssignments = new ArrayList<UserAssignment>();
+        UserAssignment ua1 = new JdoUserAssignment();
+        ua1.setPrincipal( "user1" );
+        userAssignments.add( ua1 );
+
+        List<Role> eRoles = roles;
+
+        continuum.expects( once() ).method( "getProjectGroupWithProjects" ).will( returnValue(
group ) );
+        rbac.expects( once() ).method( "getAllRoles" ).will( returnValue( roles ) );
+        rbac.expects( once() ).method( "getUserAssignmentsForRoles" ).will( returnValue(
userAssignments ) );
+        rbac.expects( once() ).method( "getEffectivelyAssignedRoles" ).will( returnValue(
eRoles ) );
+
+        action.members();
+
+        continuum.verify();
+        rbac.verify();
+
+        List<ProjectGroupUserBean> users = action.getProjectGroupUsers();
+        assertEquals( 1, users.size() );
+        assertTrue( users.get( 0 ).isAdministrator() );
+        assertTrue( users.get( 0 ).isDeveloper() );
+        assertTrue( users.get( 0 ).isUser() );
+    }
+
+    public void testViewMembersWithProjectUserRole()
+        throws Exception
+    {
+        ProjectGroup group = new ProjectGroup();
+        group.setName( "test-group" );
+
+        List<Role> roles = new ArrayList<Role>();
+        Role role1 = new JdoRole();
+        role1.setName( "Project User - test-group" );
+        roles.add( role1 );
+
+        Role role2 = new JdoRole();
+        role2.setName( "Continuum Manage Scheduling" );
+        roles.add( role2 );
+        
+        Role role3 = new JdoRole();
+        role3.setName( "Project Developer - test-group" );
+        roles.add( role3 );
+
+        Role role4 = new JdoRole();
+        role4.setName( "Project Administrator - test-group" );
+        roles.add( role4 );
+
+        List<UserAssignment> userAssignments = new ArrayList<UserAssignment>();
+        UserAssignment ua1 = new JdoUserAssignment();
+        ua1.setPrincipal( "user1" );
+        userAssignments.add( ua1 );
+
+        List<Role> eRoles = new ArrayList<Role>();
+        eRoles.add( role1 );
+        eRoles.add( role2 );
+
+        continuum.expects( once() ).method( "getProjectGroupWithProjects" ).will( returnValue(
group ) );
+        rbac.expects( once() ).method( "getAllRoles" ).will( returnValue( roles ) );
+        rbac.expects( once() ).method( "getUserAssignmentsForRoles" ).will( returnValue(
userAssignments ) );
+        rbac.expects( once() ).method( "getEffectivelyAssignedRoles" ).will( returnValue(
eRoles ) );
+
+        action.members();
+
+        continuum.verify();
+        rbac.verify();
+
+        List<ProjectGroupUserBean> users = action.getProjectGroupUsers();
+        assertEquals( 1, users.size() );
+        assertFalse( users.get( 0 ).isAdministrator() );
+        assertFalse( users.get( 0 ).isDeveloper() );
+        assertTrue( users.get( 0 ).isUser() );
+    }
+}

Added: continuum/trunk/continuum-webapp/src/test/java/org/apache/maven/continuum/web/action/stub/ProjectGroupActionStub.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-webapp/src/test/java/org/apache/maven/continuum/web/action/stub/ProjectGroupActionStub.java?rev=1237517&view=auto
==============================================================================
--- continuum/trunk/continuum-webapp/src/test/java/org/apache/maven/continuum/web/action/stub/ProjectGroupActionStub.java
(added)
+++ continuum/trunk/continuum-webapp/src/test/java/org/apache/maven/continuum/web/action/stub/ProjectGroupActionStub.java
Mon Jan 30 00:49:25 2012
@@ -0,0 +1,29 @@
+package org.apache.maven.continuum.web.action.stub;
+
+import org.apache.maven.continuum.web.action.ProjectGroupAction;
+import org.codehaus.plexus.redback.users.User;
+import org.codehaus.plexus.redback.users.UserNotFoundException;
+import org.codehaus.plexus.redback.users.jdo.JdoUser;
+
+public class ProjectGroupActionStub
+    extends ProjectGroupAction
+{
+    public String getProjectGroupName()
+    {
+        return "test-group";
+    }
+    
+    protected void checkViewProjectGroupAuthorization( String resource )
+    {
+        // skip authorization check
+    }
+
+    protected User getUser( String principal )
+        throws UserNotFoundException
+    {
+        User user = new JdoUser();
+        user.setUsername( principal );
+
+        return user;
+    }
+}



Mime
View raw message