continuum-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From eveni...@apache.org
Subject svn commit: r494361 - /maven/continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/GroupSummaryAction.java
Date Tue, 09 Jan 2007 10:33:47 GMT
Author: evenisse
Date: Tue Jan  9 02:33:46 2007
New Revision: 494361

URL: http://svn.apache.org/viewvc?view=rev&rev=494361
Log:
[CONTINUUM-1126] Remove project groups from group summary when user doesn't a role on them
Submitted by: Lester Ecarma

Modified:
    maven/continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/GroupSummaryAction.java

Modified: maven/continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/GroupSummaryAction.java
URL: http://svn.apache.org/viewvc/maven/continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/GroupSummaryAction.java?view=diff&rev=494361&r1=494360&r2=494361
==============================================================================
--- maven/continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/GroupSummaryAction.java
(original)
+++ maven/continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/GroupSummaryAction.java
Tue Jan  9 02:33:46 2007
@@ -23,8 +23,17 @@
 import org.apache.maven.continuum.model.project.BuildResult;
 import org.apache.maven.continuum.model.project.Project;
 import org.apache.maven.continuum.model.project.ProjectGroup;
+import org.apache.maven.continuum.security.ContinuumRoleConstants;
 import org.apache.maven.continuum.web.model.GroupSummary;
 import org.apache.maven.continuum.web.model.ProjectSummary;
+import org.codehaus.plexus.security.authorization.AuthorizationDataSource;
+import org.codehaus.plexus.security.authorization.AuthorizationException;
+import org.codehaus.plexus.security.authorization.Authorizer;
+import org.codehaus.plexus.security.system.SecuritySession;
+import org.codehaus.plexus.security.system.SecuritySystemConstants;
+import org.codehaus.plexus.security.user.User;
+
+import com.opensymphony.xwork.ActionContext;
 
 import java.util.ArrayList;
 import java.util.Collection;
@@ -41,6 +50,11 @@
 public class GroupSummaryAction
     extends ContinuumActionSupport
 {
+    /**
+     * @plexus.requirement role-hint="rbac"
+     */
+    private Authorizer authorizer;
+
     private String infoMessage;
 
     private List groups;
@@ -49,123 +63,143 @@
         throws ContinuumException
     {
         groups = new ArrayList();
-
+        
         Collection projectGroups = getContinuum().getAllProjectGroupsWithProjects();
-
-        for ( Iterator j = projectGroups.iterator(); j.hasNext(); )
+        ActionContext context = ActionContext.getContext();
+        SecuritySession securitySession = (SecuritySession)context.getSession().get( SecuritySystemConstants.SECURITY_SESSION_KEY
);
+        
+        if ( securitySession != null )
         {
-            ProjectGroup projectGroup = (ProjectGroup) j.next();
-
-            getLogger().debug( "GroupSummaryAction: building group " + projectGroup.getName()
);
-
-            GroupSummary groupModel = new GroupSummary();
-            groupModel.setId( projectGroup.getId() );
-            groupModel.setGroupId( projectGroup.getGroupId() );
-            groupModel.setName( projectGroup.getName() );
-            groupModel.setDescription( projectGroup.getDescription() );
-
-            //TODO: Create a summary jpox request so code will be more simple and performance
will be better
-            Collection projects = projectGroup.getProjects();
-
-            groupModel.setNumProjects( projects.size() );
-
-            Map buildResults = getContinuum().getLatestBuildResults();
-
-            Map buildResultsInSuccess = getContinuum().getBuildResultsInSuccess();
-
-            List projectModels = new ArrayList();
-            int numSuccesses = 0;
-            int numFailures = 0;
-            int numErrors = 0;
-
-            for ( Iterator i = projects.iterator(); i.hasNext(); )
+            User user = securitySession.getUser();
+            AuthorizationDataSource authSource = new AuthorizationDataSource(user.getUsername(),
user, ContinuumRoleConstants.CONTINUUM_VIEW_GROUP_OPERATION);
+            
+            for ( Iterator j = projectGroups.iterator(); j.hasNext(); )
             {
-                Project project = (Project) i.next();
-
-                if ( groupModel.getProjectType() == null )
-                {
-                    groupModel.setProjectType( project.getExecutorId() );
-                }
-
-                ProjectSummary model = new ProjectSummary();
-
-                getLogger().debug( "GroupSummaryAction: building project model " + project.getName()
);
-
-                model.setId( project.getId() );
-
-                model.setName( project.getName() );
-
-                model.setVersion( project.getVersion() );
-
-                model.setProjectGroupId( project.getProjectGroup().getId() );
-
-                model.setProjectGroupName( project.getProjectGroup().getName() );
-
-                if ( getContinuum().isInBuildingQueue( project.getId() ) )
+                ProjectGroup projectGroup = (ProjectGroup) j.next();
+                
+                authSource.setResource( projectGroup.getName() );
+                
+                try
                 {
-                    model.setInBuildingQueue( true );
-                }
-                else if ( getContinuum().isInCheckoutQueue( project.getId() ) )
-                {
-                    model.setInCheckoutQueue( true );
-                }
-                else
-                {
-                    model.setInBuildingQueue( false );
-                    model.setInCheckoutQueue( false );
-                }
-
-                model.setState( project.getState() );
-
-                if ( project.getState() == 2 )
-                {
-                    numSuccesses++;
-                }
-                else if ( project.getState() == 3 )
-                {
-                    numFailures++;
-                }
-                else if ( project.getState() == 4 )
-                {
-                    numErrors++;
-                }
-
-                model.setBuildNumber( project.getBuildNumber() );
-
-                if ( buildResultsInSuccess != null )
-                {
-                    BuildResult buildInSuccess =
-                        (BuildResult) buildResultsInSuccess.get( new Integer( project.getId()
) );
-
-                    if ( buildInSuccess != null )
+                    if ( authorizer.isAuthorized( authSource ).isAuthorized() )
                     {
-                        model.setBuildInSuccessId( buildInSuccess.getId() );
+                        getLogger().debug( "GroupSummaryAction: building group " + projectGroup.getName()
);
+                        
+                        GroupSummary groupModel = new GroupSummary();
+                        groupModel.setId( projectGroup.getId() );
+                        groupModel.setGroupId( projectGroup.getGroupId() );
+                        groupModel.setName( projectGroup.getName() );
+                        groupModel.setDescription( projectGroup.getDescription() );
+    
+                        //TODO: Create a summary jpox request so code will be more simple
and performance will be better
+                        Collection projects = projectGroup.getProjects();
+    
+                        groupModel.setNumProjects( projects.size() );
+    
+                        Map buildResults = getContinuum().getLatestBuildResults();
+    
+                        Map buildResultsInSuccess = getContinuum().getBuildResultsInSuccess();
+    
+                        List projectModels = new ArrayList();
+                        int numSuccesses = 0;
+                        int numFailures = 0;
+                        int numErrors = 0;
+    
+                        for ( Iterator i = projects.iterator(); i.hasNext(); )
+                        {
+                            Project project = (Project) i.next();
+    
+                            if ( groupModel.getProjectType() == null )
+                            {
+                                groupModel.setProjectType( project.getExecutorId() );
+                            }
+    
+                            ProjectSummary model = new ProjectSummary();
+    
+                            getLogger().debug( "GroupSummaryAction: building project model
" + project.getName() );
+    
+                            model.setId( project.getId() );
+    
+                            model.setName( project.getName() );
+    
+                            model.setVersion( project.getVersion() );
+    
+                            model.setProjectGroupId( project.getProjectGroup().getId() );
+    
+                            model.setProjectGroupName( project.getProjectGroup().getName()
);
+    
+                            if ( getContinuum().isInBuildingQueue( project.getId() ) )
+                            {
+                                model.setInBuildingQueue( true );
+                            }
+                            else if ( getContinuum().isInCheckoutQueue( project.getId() )
)
+                            {
+                                model.setInCheckoutQueue( true );
+                            }
+                            else
+                            {
+                                model.setInBuildingQueue( false );
+                                model.setInCheckoutQueue( false );
+                            }
+    
+                            model.setState( project.getState() );
+    
+                            if ( project.getState() == 2 )
+                            {
+                                numSuccesses++;
+                            }
+                            else if ( project.getState() == 3 )
+                            {
+                                numFailures++;
+                            }
+                            else if ( project.getState() == 4 )
+                            {
+                                numErrors++;
+                            }
+    
+                            model.setBuildNumber( project.getBuildNumber() );
+    
+                            if ( buildResultsInSuccess != null )
+                            {
+                                BuildResult buildInSuccess =
+                                    (BuildResult) buildResultsInSuccess.get( new Integer(
project.getId() ) );
+    
+                                if ( buildInSuccess != null )
+                                {
+                                    model.setBuildInSuccessId( buildInSuccess.getId() );
+                                }
+                            }
+    
+                            if ( buildResults != null )
+                            {
+                                BuildResult latestBuild = (BuildResult) buildResults.get(
new Integer( project.getId() ) );
+    
+                                if ( latestBuild != null )
+                                {
+                                    model.setLatestBuildId( latestBuild.getId() );
+                                }
+                            }
+                            getLogger().debug( "GroupSummaryAction: adding model to group
" + model.getName() );
+                            projectModels.add( model );
+                        }
+    
+                        //todo wire in the next scheduled build for the project group and
a meaningful status message
+                        //groupModel.setNextScheduledBuild( "unknown" );
+                        //groupModel.setStatusMessage( "none" );
+    
+                        groupModel.setNumSuccesses( numSuccesses );
+                        groupModel.setNumFailures( numFailures );
+                        groupModel.setNumErrors( numErrors );
+                        groupModel.setProjects( projectModels );
+                        getLogger().debug( "GroupSummaryAction: adding group to groups list
" + groupModel.getName() );
+                        groups.add( groupModel );
                     }
                 }
-
-                if ( buildResults != null )
+                catch ( AuthorizationException e )
                 {
-                    BuildResult latestBuild = (BuildResult) buildResults.get( new Integer(
project.getId() ) );
-
-                    if ( latestBuild != null )
-                    {
-                        model.setLatestBuildId( latestBuild.getId() );
-                    }
+                    //Do nothing, just skip the current project group and continue processing
the next
                 }
-                getLogger().debug( "GroupSummaryAction: adding model to group " + model.getName()
);
-                projectModels.add( model );
             }
-
-            //todo wire in the next scheduled build for the project group and a meaningful
status message
-            //groupModel.setNextScheduledBuild( "unknown" );
-            //groupModel.setStatusMessage( "none" );
-
-            groupModel.setNumSuccesses( numSuccesses );
-            groupModel.setNumFailures( numFailures );
-            groupModel.setNumErrors( numErrors );
-            groupModel.setProjects( projectModels );
-            getLogger().debug( "GroupSummaryAction: adding group to groups list " + groupModel.getName()
);
-            groups.add( groupModel );
         }
 
         return SUCCESS;



Mime
View raw message