continuum-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From car...@apache.org
Subject svn commit: r442161 - in /maven/continuum/branches/continuum-acegi/continuum-webapp/src/main: java/org/apache/maven/continuum/web/action/ProjectGroupPermissionsAction.java webapp/projectGroupPermissions.jsp
Date Mon, 11 Sep 2006 10:10:16 GMT
Author: carlos
Date: Mon Sep 11 03:10:15 2006
New Revision: 442161

URL: http://svn.apache.org/viewvc?view=rev&rev=442161
Log:
More work on project group permissions

Modified:
    maven/continuum/branches/continuum-acegi/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/ProjectGroupPermissionsAction.java
    maven/continuum/branches/continuum-acegi/continuum-webapp/src/main/webapp/projectGroupPermissions.jsp

Modified: maven/continuum/branches/continuum-acegi/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/ProjectGroupPermissionsAction.java
URL: http://svn.apache.org/viewvc/maven/continuum/branches/continuum-acegi/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/ProjectGroupPermissionsAction.java?view=diff&rev=442161&r1=442160&r2=442161
==============================================================================
--- maven/continuum/branches/continuum-acegi/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/ProjectGroupPermissionsAction.java
(original)
+++ maven/continuum/branches/continuum-acegi/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/ProjectGroupPermissionsAction.java
Mon Sep 11 03:10:15 2006
@@ -16,14 +16,14 @@
  * limitations under the License.
  */
 
-import java.util.HashMap;
-import java.util.Iterator;
+import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
 
 import org.apache.maven.continuum.ContinuumException;
 import org.apache.maven.continuum.model.project.ProjectGroup;
 import org.apache.maven.user.model.InstancePermissions;
+import org.apache.maven.user.model.User;
 import org.apache.maven.user.model.UserManager;
 
 /**
@@ -50,7 +50,9 @@
 
     private InstancePermissions[] userPermissions;
 
-    private Map map = new HashMap();
+    private String[] userNames;
+
+    private Map map;
 
     public void setProjectGroup( ProjectGroup projectGroup )
     {
@@ -92,6 +94,16 @@
         this.map = map;
     }
 
+    public void setUserNames( String[] userNames )
+    {
+        this.userNames = userNames;
+    }
+
+    public String[] getUserNames()
+    {
+        return userNames;
+    }
+
     public String execute()
         throws ContinuumException
     {
@@ -100,38 +112,56 @@
 
         setUserPermissions( (InstancePermissions[]) userPermissionsAsList.toArray( new InstancePermissions[0]
) );
 
-//        getUserPermissions()[0].setBuild( true );
-//        getUserPermissions()[1].setDelete( true );
-        
         setProjectGroup( getContinuum().getProjectGroup( projectGroupId ) );
 
-        getLogger().info( "ProjectGroupName = " + getProjectGroup().getName() );
-
         return INPUT;
     }
 
     public String save()
         throws ContinuumException
     {
-        for ( Iterator i = map.keySet().iterator(); i.hasNext(); )
+        List instancePermissions = new ArrayList( userNames.length );
+        for ( int i = 0; i < userNames.length; i++ )
         {
-            String id = (String) i.next();
-            getLogger().info( "key value == " + id );
+            User u = new User();
+            u.setUsername( userNames[i] );
+
+            InstancePermissions p = parsePermissions( map, u.getUsername() );
+            p.setUser( u );
+            p.setId( new Integer( projectGroupId ) );
+            p.setInstanceClass( ProjectGroup.class );
+            instancePermissions.add( p );
+
+            // TODO validate that the permissions dont conflict each other, set the error
msg if they do
         }
-        for ( Iterator i = map.values().iterator(); i.hasNext(); )
-        {
-            String[] id = (String[]) i.next();
-            for ( int y = 0; y < id.length; y++ )
-            {
-                getLogger().info( "class name == " + id[y].getClass().getSimpleName() );
-                getLogger().info( "value == " + id[y] );
-            }
-        }
-        // TODO - compare the values from the map to userManager.getUsersInstancePermissions()
then save the differences
-        // NOTE: only the checkboxes that are checked are saved on the map.
-        //       each user has 4 possible checkboxes and all of them are saved into an array
of String.
-        //       so to determine each checkbox(view) from the others(edit/delete/build),
we need a special notation. see below...
-        // KEY FORMAT: username + view/edit/delete or build. sample would be adminbuild or
guestview
+        userManager.setUsersInstancePermissions( instancePermissions );
+
         return SUCCESS;
+    }
+
+    private InstancePermissions parsePermissions( Map map, String username )
+    {
+        InstancePermissions p = new InstancePermissions();
+        if ( map.get( username + ".execute" ) != null )
+        {
+            p.setExecute( true );
+        }
+        if ( map.get( username + ".delete" ) != null )
+        {
+            p.setDelete( true );
+        }
+        if ( map.get( username + ".write" ) != null )
+        {
+            p.setWrite( true );
+        }
+        if ( map.get( username + ".read" ) != null )
+        {
+            p.setRead( true );
+        }
+        if ( map.get( username + ".administer" ) != null )
+        {
+            p.setAdminister( true );
+        }
+        return p;
     }
 }

Modified: maven/continuum/branches/continuum-acegi/continuum-webapp/src/main/webapp/projectGroupPermissions.jsp
URL: http://svn.apache.org/viewvc/maven/continuum/branches/continuum-acegi/continuum-webapp/src/main/webapp/projectGroupPermissions.jsp?view=diff&rev=442161&r1=442160&r2=442161
==============================================================================
--- maven/continuum/branches/continuum-acegi/continuum-webapp/src/main/webapp/projectGroupPermissions.jsp
(original)
+++ maven/continuum/branches/continuum-acegi/continuum-webapp/src/main/webapp/projectGroupPermissions.jsp
Mon Sep 11 03:10:15 2006
@@ -18,38 +18,50 @@
         <h3>Users</h3>
         <form action="projectGroupPermissions!save.action">
 
+          username - view - edit - delete - build - admin<br/>
+
           <ww:iterator value="userPermissions" id="permission">
 
-            <ww:property value="user.username"/>
+            <ww:property value='user.username'/>
+            <ww:hidden name="userNames" value="%{user.username}"/>
 
-            <ww:set name="view" value="<ww:property value='view'/>"/>
-            <ww:set name="edit" value="<ww:property value='edit'/>"/>
+            <ww:set name="read" value="<ww:property value='read'/>"/>
+            <ww:set name="write" value="<ww:property value='write'/>"/>
             <ww:set name="delete" value="<ww:property value='delete'/>"/>
-            <ww:set name="build" value="<ww:property value='build'/>"/>
-            <ww:if test="view == true">
-              <input type="checkbox" name="map['<ww:property value="user.username"/>view']"
checked="true">
+            <ww:set name="execute" value="<ww:property value='execute'/>"/>
+            <ww:set name="administer" value="<ww:property value='administer'/>"/>
+
+            <ww:if test="read == true">
+              <input type="checkbox" name="map['<ww:property value="user.username"/>.read']"
checked="true">
             </ww:if>
             <ww:else>
-              <input type="checkbox" name="map['<ww:property value="user.username"/>view']">
+              <input type="checkbox" name="map['<ww:property value="user.username"/>.read']">
             </ww:else>
-            <ww:if test="edit == true">
-              <input type="checkbox" name="map['<ww:property value="user.username"/>edit']"
checked="true">
+            <ww:if test="write == true">
+              <input type="checkbox" name="map['<ww:property value="user.username"/>.write']"
checked="true">
             </ww:if>
             <ww:else>
-              <input type="checkbox" name="map['<ww:property value="user.username"/>edit']">
+              <input type="checkbox" name="map['<ww:property value="user.username"/>.write']">
             </ww:else>
             <ww:if test="delete == true">
-              <input type="checkbox" name="map['<ww:property value="user.username"/>delete']"
checked="true">
+              <input type="checkbox" name="map['<ww:property value="user.username"/>.delete']"
checked="true">
+            </ww:if>
+            <ww:else>
+              <input type="checkbox" name="map['<ww:property value="user.username"/>.delete']">
+            </ww:else>
+            <ww:if test="execute == true">
+              <input type="checkbox" name="map['<ww:property value="user.username"/>.execute']"
checked="true">
             </ww:if>
             <ww:else>
-              <input type="checkbox" name="map['<ww:property value="user.username"/>delete']">
+              <input type="checkbox" name="map['<ww:property value="user.username"/>.execute']">
             </ww:else>
-            <ww:if test="build == true">
-              <input type="checkbox" name="map['<ww:property value="user.username"/>build']"
checked="true">
+            <ww:if test="administer == true">
+              <input type="checkbox" name="map['<ww:property value="user.username"/>.administer']"
checked="true">
             </ww:if>
             <ww:else>
-              <input type="checkbox" name="map['<ww:property value="user.username"/>build']">
+              <input type="checkbox" name="map['<ww:property value="user.username"/>.administer']">
             </ww:else>
+
             <br/>
           </ww:iterator>
 



Mime
View raw message