]> source.dussan.org Git - gitblit.git/commitdiff
Completed permissions UI, RPC, and Manager support (issue 36)
authorJames Moger <james.moger@gitblit.com>
Sat, 20 Oct 2012 01:32:57 +0000 (21:32 -0400)
committerJames Moger <james.moger@gitblit.com>
Sat, 20 Oct 2012 02:47:34 +0000 (22:47 -0400)
39 files changed:
docs/02_rpc.mkd
docs/04_releases.mkd
src/com/gitblit/ConfigUserService.java
src/com/gitblit/Constants.java
src/com/gitblit/FederationPullExecutor.java
src/com/gitblit/FileUserService.java
src/com/gitblit/GitBlit.java
src/com/gitblit/RpcServlet.java
src/com/gitblit/client/EditRepositoryDialog.java
src/com/gitblit/client/EditTeamDialog.java
src/com/gitblit/client/EditUserDialog.java
src/com/gitblit/client/GitblitClient.java
src/com/gitblit/client/RegistrantPermissionsPanel.java [new file with mode: 0644]
src/com/gitblit/client/RegistrantPermissionsTableModel.java [new file with mode: 0644]
src/com/gitblit/client/RepositoriesPanel.java
src/com/gitblit/client/TeamsPanel.java
src/com/gitblit/client/UsersPanel.java
src/com/gitblit/client/UsersTableModel.java
src/com/gitblit/models/RegistrantAccessPermission.java [new file with mode: 0644]
src/com/gitblit/models/RepositoryAccessPermission.java [deleted file]
src/com/gitblit/models/TeamAccessPermission.java [deleted file]
src/com/gitblit/models/TeamModel.java
src/com/gitblit/models/UserAccessPermission.java [deleted file]
src/com/gitblit/models/UserModel.java
src/com/gitblit/utils/RpcUtils.java
src/com/gitblit/wicket/GitBlitWebApp.properties
src/com/gitblit/wicket/pages/EditRepositoryPage.java
src/com/gitblit/wicket/pages/EditTeamPage.java
src/com/gitblit/wicket/pages/EditUserPage.java
src/com/gitblit/wicket/panels/RegistrantPermissionsPanel.html [new file with mode: 0644]
src/com/gitblit/wicket/panels/RegistrantPermissionsPanel.java [new file with mode: 0644]
src/com/gitblit/wicket/panels/RepositoryPermissionsPanel.html [deleted file]
src/com/gitblit/wicket/panels/RepositoryPermissionsPanel.java [deleted file]
src/com/gitblit/wicket/panels/TeamPermissionsPanel.html [deleted file]
src/com/gitblit/wicket/panels/TeamPermissionsPanel.java [deleted file]
src/com/gitblit/wicket/panels/UserPermissionsPanel.html [deleted file]
src/com/gitblit/wicket/panels/UserPermissionsPanel.java [deleted file]
src/com/gitblit/wicket/panels/UsersPanel.java
tests/com/gitblit/tests/RpcTests.java

index d05ca27f99737bbca5dd874668d33e9d4726a333..35528bfc41618567d2554594efd692dd4bf95b5d 100644 (file)
@@ -64,10 +64,18 @@ The Gitblit API includes methods for retrieving and interpreting RSS feeds.  The
 <tr><td>Gitblit v0.7.0</td><td>1 (inferred version)</td></tr>\r
 <tr><td>Gitblit v0.8.0</td><td>2</td></tr>\r
 <tr><td>Gitblit v0.9.0 - v1.0.0</td><td>3</td></tr>\r
-<tr><td>Gitblit v1.1.0+</td><td>4</td></tr>\r
+<tr><td>Gitblit v1.1.0</td><td>4</td></tr>\r
+<tr><td>Gitblit v1.2.0+</td><td>5</td></tr>\r
 </tbody>\r
 </table>\r
 \r
+#### Protocol Version 5\r
+\r
+- *SET_REPOSITORY_MEMBERS* will reject all calls because this would elevate all discrete permissions to RW+  \r
+Use *SET_REPOSITORY_MEMBER_PERMISSIONS* instead.\r
+- *SET_REPOSITORY_TEAMS* will reject all calls because this would elevate all discrete permissions to RW+  \r
+Use *SET_REPOSITORY_TEAM_PERMISSIONS* instead.\r
+\r
 ### RPC Request and Response Types\r
 <table class="table">\r
 <tr><th colspan='2'>url parameters</th><th rowspan='2'>required<br/>user<br/>permission</th><th rowspan='2'>protocol<br/>version</th><th colspan='2'>json</th></tr>\r
@@ -90,9 +98,13 @@ The Gitblit API includes methods for retrieving and interpreting RSS feeds.  The
 <tr><td>EDIT_TEAM</td><td>team name</td><td><em>admin</em></td><td>2</td><td>TeamModel</td><td>-</td></tr>\r
 <tr><td>DELETE_TEAM</td><td>team name</td><td><em>admin</em></td><td>2</td><td>-</td><td>-</td></tr>\r
 <tr><td>LIST_REPOSITORY_MEMBERS</td><td>repository name</td><td><em>admin</em></td><td>1</td><td>-</td><td>List&lt;String&gt;</td></tr>\r
-<tr><td>SET_REPOSITORY_MEMBERS</td><td>repository name</td><td><em>admin</em></td><td>1</td><td>List&lt;String&gt;</td><td>-</td></tr>\r
+<tr><td><s>SET_REPOSITORY_MEMBERS</s></td><td><s>repository name</s></td><td><em><s>admin</s></em></td><td><s>1</s></td><td><s>List&lt;String&gt;</s></td><td>-</td></tr>\r
+<tr><td>LIST_REPOSITORY_MEMBER_PERMISSIONS</td><td>repository name</td><td><em>admin</em></td><td>5</td><td>-</td><td>List&lt;String&gt;</td></tr>\r
+<tr><td>SET_REPOSITORY_MEMBER_PERMISSIONS</td><td>repository name</td><td><em>admin</em></td><td>5</td><td>List&lt;String&gt;</td><td>-</td></tr>\r
 <tr><td>LIST_REPOSITORY_TEAMS</td><td>repository name</td><td><em>admin</em></td><td>2</td><td>-</td><td>List&lt;String&gt;</td></tr>\r
-<tr><td>SET_REPOSITORY_TEAMS</td><td>repository name</td><td><em>admin</em></td><td>2</td><td>List&lt;String&gt;</td><td>-</td></tr>\r
+<tr><td><s>SET_REPOSITORY_TEAMS</s></td><td><s>repository name</s></td><td><em><s>admin</s></em></td><td><s>2</s></td><td><s>List&lt;String&gt;</s></td><td>-</td></tr>\r
+<tr><td>LIST_REPOSITORY_TEAM_PERMISSIONS</td><td>repository name</td><td><em>admin</em></td><td>5</td><td>-</td><td>List&lt;String&gt;</td></tr>\r
+<tr><td>SET_REPOSITORY_TEAM_PERMISSIONS</td><td>repository name</td><td><em>admin</em></td><td>5</td><td>List&lt;String&gt;</td><td>-</td></tr>\r
 <tr><td>LIST_SETTINGS</td><td>-</td><td><em>admin</em></td><td>1</td><td>-</td><td>ServerSettings (management keys)</td></tr>\r
 <tr><td>CLEAR_REPOSITORY_CACHE</td><td>-</td><td><em>-</em></td><td>4</td><td>-</td><td>-</td></tr>\r
 <tr><td colspan='6'><em>web.enableRpcAdministration=true</em></td></tr>\r
index 920ae386df9aebe61e32993804d164ccd271534b..70e0ad2f662d959766fcc7ba47d3240405df6998 100644 (file)
@@ -1,8 +1,10 @@
 ## Release History\r
 \r
-<div class="alert alert-error">\r
+<div class="alert alert-info">\r
 <h4>Update Note</h4>\r
-If you are updating from an earlier release AND you have indexed branches with the Lucene indexing feature, you need to be aware that this release will completely re-index your repositories.  Please be sure to provide ample heap resources as appropriate for your installation.\r
+The permissions model has changed in this release.\r
+<p>\r
+If you are updating your server, you must also update any Gitblit Manager and Federation Client installs to 1.2.0 as well.  The data model used by the RPC mechanism has changed slightly for the new permissions infrastructure.\r
 </div>\r
 \r
 ### Current Release\r
@@ -65,6 +67,11 @@ If *realm.ldap.maintainTeams==true* **AND** *realm.ldap.admins* is not empty, th
 \r
 ### Older Releases\r
 \r
+<div class="alert alert-error">\r
+<h4>Update Note</h4>\r
+If you are updating from an earlier release AND you have indexed branches with the Lucene indexing feature, you need to be aware that this release will completely re-index your repositories.  Please be sure to provide ample heap resources as appropriate for your installation.\r
+</div>\r
+\r
 **1.1.0** *released 2012-08-25*\r
 \r
 #### fixes\r
index 82cd33e33b8a2ab160f7529ec48e1f7bca1c143d..015cef762fbded8312da5641e204aa42744ad17b 100644 (file)
@@ -840,16 +840,8 @@ public class ConfigUserService implements IUserService {
                        }\r
                        config.setStringList(USER, model.username, ROLE, roles);\r
 \r
-                       // repository memberships\r
-                       if (model.permissions == null) {\r
-                               // null check on "final" repositories because JSON-sourced UserModel\r
-                               // can have a null repositories object\r
-                               if (!ArrayUtils.isEmpty(model.repositories)) {\r
-                                       config.setStringList(USER, model.username, REPOSITORY, new ArrayList<String>(\r
-                                                       model.repositories));\r
-                               }\r
-                       } else {\r
-                               // discrete repository permissions\r
+                       // discrete repository permissions\r
+                       if (model.permissions != null) {\r
                                List<String> permissions = new ArrayList<String>();\r
                                for (Map.Entry<String, AccessPermission> entry : model.permissions.entrySet()) {\r
                                        if (entry.getValue().exceeds(AccessPermission.NONE)) {\r
index 0e68355ea1073cfce95f5b5374fe9959951bc60b..970c3db51594c7054ba682c0f9b7249fa2e47118 100644 (file)
@@ -255,6 +255,7 @@ public class Constants {
                LIST_USERS, CREATE_USER, EDIT_USER, DELETE_USER, \r
                LIST_TEAMS, CREATE_TEAM, EDIT_TEAM, DELETE_TEAM,\r
                LIST_REPOSITORY_MEMBERS, SET_REPOSITORY_MEMBERS, LIST_REPOSITORY_TEAMS, SET_REPOSITORY_TEAMS, \r
+               LIST_REPOSITORY_MEMBER_PERMISSIONS, SET_REPOSITORY_MEMBER_PERMISSIONS, LIST_REPOSITORY_TEAM_PERMISSIONS, SET_REPOSITORY_TEAM_PERMISSIONS, \r
                LIST_FEDERATION_REGISTRATIONS, LIST_FEDERATION_RESULTS, LIST_FEDERATION_PROPOSALS, LIST_FEDERATION_SETS,\r
                EDIT_SETTINGS, LIST_STATUS;\r
 \r
@@ -379,6 +380,10 @@ public class Constants {
                }\r
        }\r
        \r
+       public static enum RegistrantType {\r
+               REPOSITORY, USER, TEAM;\r
+       }\r
+       \r
        @Documented\r
        @Retention(RetentionPolicy.RUNTIME)\r
        public @interface Unused {\r
index 03109dea01e1db0e621ddf94406f18aed84c06e7..19afacc7156ef2e46615c2949caf9fe7680c19c6 100644 (file)
@@ -335,7 +335,7 @@ public class FederationPullExecutor implements Runnable {
                                                // reparent all repository permissions if the local\r
                                                // repositories are stored within subfolders\r
                                                if (!StringUtils.isEmpty(registrationFolder)) {\r
-                                                       if (user.permissions != null && user.permissions.size() > 0) {\r
+                                                       if (user.permissions != null) {\r
                                                                // pulling from >= 1.2 version\r
                                                                Map<String, AccessPermission> copy = new HashMap<String, AccessPermission>(user.permissions);\r
                                                                user.permissions.clear();\r
@@ -359,7 +359,7 @@ public class FederationPullExecutor implements Runnable {
                                                        GitBlit.self().updateUserModel(user.username, user, true);\r
                                                } else {\r
                                                        // update repository permissions of local user\r
-                                                       if (user.permissions != null && user.permissions.size() > 0) {\r
+                                                       if (user.permissions != null) {\r
                                                                // pulling from >= 1.2 version\r
                                                                Map<String, AccessPermission> copy = new HashMap<String, AccessPermission>(user.permissions);\r
                                                                for (Map.Entry<String, AccessPermission> entry : copy.entrySet()) {\r
index d411b68f47895ddf28bf689b433d9e175af4a8fa..39c9a5dc8abe88bb0652312fc507db6f95b7437d 100644 (file)
@@ -329,8 +329,7 @@ public class FileUserService extends FileSettings implements IUserService {
                        UserModel oldUser = getUserModel(username);\r
                        List<String> roles;\r
                        if (model.permissions == null) {\r
-                               // legacy, use repository list\r
-                               roles = new ArrayList<String>(model.repositories);\r
+                               roles = new ArrayList<String>();\r
                        } else {\r
                                // discrete repository permissions\r
                                roles = new ArrayList<String>();\r
index af13e02ddc506a3074a4b4214fc32753cf227a32..ce556b6eb318b7730e2b7522907c838a0cf0e5cf 100644 (file)
@@ -78,20 +78,20 @@ import com.gitblit.Constants.AuthorizationControl;
 import com.gitblit.Constants.FederationRequest;\r
 import com.gitblit.Constants.FederationStrategy;\r
 import com.gitblit.Constants.FederationToken;\r
+import com.gitblit.Constants.RegistrantType;\r
 import com.gitblit.models.FederationModel;\r
 import com.gitblit.models.FederationProposal;\r
 import com.gitblit.models.FederationSet;\r
 import com.gitblit.models.ForkModel;\r
 import com.gitblit.models.Metric;\r
 import com.gitblit.models.ProjectModel;\r
+import com.gitblit.models.RegistrantAccessPermission;\r
 import com.gitblit.models.RepositoryModel;\r
 import com.gitblit.models.SearchResult;\r
 import com.gitblit.models.ServerSettings;\r
 import com.gitblit.models.ServerStatus;\r
 import com.gitblit.models.SettingModel;\r
-import com.gitblit.models.TeamAccessPermission;\r
 import com.gitblit.models.TeamModel;\r
-import com.gitblit.models.UserAccessPermission;\r
 import com.gitblit.models.UserModel;\r
 import com.gitblit.utils.ArrayUtils;\r
 import com.gitblit.utils.ByteFormat;\r
@@ -637,11 +637,11 @@ public class GitBlit implements ServletContextListener {
         * @param repository\r
         * @return a list of User-AccessPermission tuples\r
         */\r
-       public List<UserAccessPermission> getUserAccessPermissions(RepositoryModel repository) {\r
-               List<UserAccessPermission> permissions = new ArrayList<UserAccessPermission>();\r
+       public List<RegistrantAccessPermission> getUserAccessPermissions(RepositoryModel repository) {\r
+               List<RegistrantAccessPermission> permissions = new ArrayList<RegistrantAccessPermission>();\r
                for (String user : userService.getUsernamesForRepositoryRole(repository.name)) {\r
                        AccessPermission ap = userService.getUserModel(user).getRepositoryPermission(repository);\r
-                       permissions.add(new UserAccessPermission(user, ap));\r
+                       permissions.add(new RegistrantAccessPermission(user, ap, RegistrantType.USER));\r
                }\r
                return permissions;\r
        }\r
@@ -653,10 +653,10 @@ public class GitBlit implements ServletContextListener {
         * @param permissions\r
         * @return true if the user models have been updated\r
         */\r
-       public boolean setUserAccessPermissions(RepositoryModel repository, List<UserAccessPermission> permissions) {\r
+       public boolean setUserAccessPermissions(RepositoryModel repository, Collection<RegistrantAccessPermission> permissions) {\r
                List<UserModel> users = new ArrayList<UserModel>();\r
-               for (UserAccessPermission up : permissions) {\r
-                       UserModel user = userService.getUserModel(up.user);\r
+               for (RegistrantAccessPermission up : permissions) {\r
+                       UserModel user = userService.getUserModel(up.registrant);\r
                        user.setRepositoryPermission(repository.name, up.permission);\r
                        users.add(user);\r
                }\r
@@ -686,7 +686,9 @@ public class GitBlit implements ServletContextListener {
         */\r
        @Deprecated\r
        public boolean setRepositoryUsers(RepositoryModel repository, List<String> repositoryUsers) {\r
-               return userService.setUsernamesForRepositoryRole(repository.name, repositoryUsers);\r
+               // rejects all changes since 1.2.0 because this would elevate\r
+               // all discrete access permissions to RW+\r
+               return false;\r
        }\r
 \r
        /**\r
@@ -767,11 +769,11 @@ public class GitBlit implements ServletContextListener {
         * @param repository\r
         * @return a list of Team-AccessPermission tuples\r
         */\r
-       public List<TeamAccessPermission> getTeamAccessPermissions(RepositoryModel repository) {\r
-               List<TeamAccessPermission> permissions = new ArrayList<TeamAccessPermission>();\r
+       public List<RegistrantAccessPermission> getTeamAccessPermissions(RepositoryModel repository) {\r
+               List<RegistrantAccessPermission> permissions = new ArrayList<RegistrantAccessPermission>();\r
                for (String team : userService.getTeamnamesForRepositoryRole(repository.name)) {\r
                        AccessPermission ap = userService.getTeamModel(team).getRepositoryPermission(repository);\r
-                       permissions.add(new TeamAccessPermission(team, ap));\r
+                       permissions.add(new RegistrantAccessPermission(team, ap, RegistrantType.TEAM));\r
                }\r
                return permissions;\r
        }\r
@@ -783,10 +785,10 @@ public class GitBlit implements ServletContextListener {
         * @param permissions\r
         * @return true if the team models have been updated\r
         */\r
-       public boolean setTeamAccessPermissions(RepositoryModel repository, List<TeamAccessPermission> permissions) {\r
+       public boolean setTeamAccessPermissions(RepositoryModel repository, Collection<RegistrantAccessPermission> permissions) {\r
                List<TeamModel> teams = new ArrayList<TeamModel>();\r
-               for (TeamAccessPermission tp : permissions) {\r
-                       TeamModel team = userService.getTeamModel(tp.team);\r
+               for (RegistrantAccessPermission tp : permissions) {\r
+                       TeamModel team = userService.getTeamModel(tp.registrant);\r
                        team.setRepositoryPermission(repository.name, tp.permission);\r
                        teams.add(team);\r
                }\r
@@ -794,14 +796,13 @@ public class GitBlit implements ServletContextListener {
        }\r
        \r
        /**\r
-        * Returns the list of all teams who are allowed to bypass the access\r
-        * restriction placed on the specified repository.\r
+        * Returns the list of all teams who have an explicit access permission for\r
+        * the specified repository.\r
         * \r
         * @see IUserService.getTeamnamesForRepositoryRole(String)\r
         * @param repository\r
-        * @return list of all teamnames that can bypass the access restriction\r
+        * @return list of all teamnames with explicit access permissions to the repository\r
         */\r
-       @Deprecated\r
        public List<String> getRepositoryTeams(RepositoryModel repository) {\r
                return userService.getTeamnamesForRepositoryRole(repository.name);\r
        }\r
@@ -817,7 +818,9 @@ public class GitBlit implements ServletContextListener {
         */\r
        @Deprecated\r
        public boolean setRepositoryTeams(RepositoryModel repository, List<String> repositoryTeams) {\r
-               return userService.setTeamnamesForRepositoryRole(repository.name, repositoryTeams);\r
+               // rejects all changes since 1.2.0 because this would elevate\r
+               // all discrete access permissions to RW+\r
+               return false;\r
        }\r
 \r
        /**\r
index 2a6ba26c7819f7fc8bc1c6ecbbfd59f98e716711..0c9ac37994bdbdf6ca4b7e3db02f7895d63bf8cf 100644 (file)
@@ -30,6 +30,7 @@ import javax.servlet.http.HttpServletResponse;
 import org.eclipse.jgit.lib.Repository;\r
 \r
 import com.gitblit.Constants.RpcRequest;\r
+import com.gitblit.models.RegistrantAccessPermission;\r
 import com.gitblit.models.RefModel;\r
 import com.gitblit.models.RepositoryModel;\r
 import com.gitblit.models.ServerSettings;\r
@@ -49,7 +50,7 @@ public class RpcServlet extends JsonServlet {
 \r
        private static final long serialVersionUID = 1L;\r
 \r
-       public static final int PROTOCOL_VERSION = 4;\r
+       public static final int PROTOCOL_VERSION = 5;\r
 \r
        public RpcServlet() {\r
                super();\r
@@ -226,25 +227,33 @@ public class RpcServlet extends JsonServlet {
                        RepositoryModel model = GitBlit.self().getRepositoryModel(objectName);\r
                        result = GitBlit.self().getRepositoryUsers(model);\r
                } else if (RpcRequest.SET_REPOSITORY_MEMBERS.equals(reqType)) {\r
-                       // update repository access list\r
+                       // rejected since 1.2.0\r
+                       response.setStatus(failureCode);\r
+               } else if (RpcRequest.LIST_REPOSITORY_MEMBER_PERMISSIONS.equals(reqType)) {\r
+                       // get repository member permissions\r
                        RepositoryModel model = GitBlit.self().getRepositoryModel(objectName);\r
-                       Collection<String> names = deserialize(request, response, RpcUtils.NAMES_TYPE);\r
-                       List<String> users = new ArrayList<String>(names);\r
-                       if (!GitBlit.self().setRepositoryUsers(model, users)) {\r
-                               response.setStatus(failureCode);\r
-                       }\r
+                       result = GitBlit.self().getUserAccessPermissions(model);\r
+               } else if (RpcRequest.SET_REPOSITORY_MEMBER_PERMISSIONS.equals(reqType)) {\r
+                       // set the repository permissions for the specified users\r
+                       RepositoryModel model = GitBlit.self().getRepositoryModel(objectName);\r
+                       Collection<RegistrantAccessPermission> permissions = deserialize(request, response, RpcUtils.REGISTRANT_PERMISSIONS_TYPE);\r
+                       result = GitBlit.self().setUserAccessPermissions(model, permissions);\r
                } else if (RpcRequest.LIST_REPOSITORY_TEAMS.equals(reqType)) {\r
                        // get repository teams\r
                        RepositoryModel model = GitBlit.self().getRepositoryModel(objectName);\r
                        result = GitBlit.self().getRepositoryTeams(model);\r
                } else if (RpcRequest.SET_REPOSITORY_TEAMS.equals(reqType)) {\r
-                       // update repository team access list\r
+                       // rejected since 1.2.0\r
+                       response.setStatus(failureCode);\r
+               } else if (RpcRequest.LIST_REPOSITORY_TEAM_PERMISSIONS.equals(reqType)) {\r
+                       // get repository team permissions\r
                        RepositoryModel model = GitBlit.self().getRepositoryModel(objectName);\r
-                       Collection<String> names = deserialize(request, response, RpcUtils.NAMES_TYPE);\r
-                       List<String> teams = new ArrayList<String>(names);\r
-                       if (!GitBlit.self().setRepositoryTeams(model, teams)) {\r
-                               response.setStatus(failureCode);\r
-                       }\r
+                       result = GitBlit.self().getTeamAccessPermissions(model);\r
+               } else if (RpcRequest.SET_REPOSITORY_TEAM_PERMISSIONS.equals(reqType)) {\r
+                       // set the repository permissions for the specified teams\r
+                       RepositoryModel model = GitBlit.self().getRepositoryModel(objectName);\r
+                       Collection<RegistrantAccessPermission> permissions = deserialize(request, response, RpcUtils.REGISTRANT_PERMISSIONS_TYPE);\r
+                       result = GitBlit.self().setTeamAccessPermissions(model, permissions);\r
                } else if (RpcRequest.LIST_FEDERATION_REGISTRATIONS.equals(reqType)) {\r
                        // return the list of federation registrations\r
                        if (allowAdmin) {\r
index e15b1546d43135ce33568104f58260628baf9007..0adf8a8076eeacde9b494a6f1ccae003f9475c96 100644 (file)
@@ -59,6 +59,7 @@ import javax.swing.ScrollPaneConstants;
 import com.gitblit.Constants.AccessRestrictionType;\r
 import com.gitblit.Constants.AuthorizationControl;\r
 import com.gitblit.Constants.FederationStrategy;\r
+import com.gitblit.models.RegistrantAccessPermission;\r
 import com.gitblit.models.RepositoryModel;\r
 import com.gitblit.utils.ArrayUtils;\r
 import com.gitblit.utils.StringUtils;\r
@@ -116,11 +117,11 @@ public class EditRepositoryDialog extends JDialog {
 \r
        private JComboBox headRefField;\r
 \r
-       private JPalette<String> usersPalette;\r
+       private RegistrantPermissionsPanel usersPalette;\r
 \r
        private JPalette<String> setsPalette;\r
 \r
-       private JPalette<String> teamsPalette;\r
+       private RegistrantPermissionsPanel teamsPalette;\r
        \r
        private JPalette<String> indexedBranchesPalette;\r
 \r
@@ -280,7 +281,7 @@ public class EditRepositoryDialog extends JDialog {
                clonePushPanel\r
                .add(newFieldPanel(Translation.get("gb.verifyCommitter"), verifyCommitter));\r
 \r
-               usersPalette = new JPalette<String>();\r
+               usersPalette = new RegistrantPermissionsPanel();\r
                JPanel northAccessPanel = new JPanel(new BorderLayout(5, 5));\r
                northAccessPanel.add(newFieldPanel(Translation.get("gb.accessRestriction"),\r
                                accessRestriction), BorderLayout.NORTH);\r
@@ -290,13 +291,13 @@ public class EditRepositoryDialog extends JDialog {
 \r
                JPanel accessPanel = new JPanel(new BorderLayout(5, 5));\r
                accessPanel.add(northAccessPanel, BorderLayout.NORTH);\r
-               accessPanel.add(newFieldPanel(Translation.get("gb.permittedUsers"),\r
+               accessPanel.add(newFieldPanel(Translation.get("gb.userPermissions"),\r
                                                usersPalette), BorderLayout.CENTER);\r
 \r
-               teamsPalette = new JPalette<String>();\r
+               teamsPalette = new RegistrantPermissionsPanel();\r
                JPanel teamsPanel = new JPanel(new BorderLayout(5, 5));\r
                teamsPanel.add(\r
-                               newFieldPanel(Translation.get("gb.permittedTeams"),\r
+                               newFieldPanel(Translation.get("gb.teamPermissions"),\r
                                                teamsPalette), BorderLayout.CENTER);\r
 \r
                setsPalette = new JPalette<String>();\r
@@ -545,16 +546,16 @@ public class EditRepositoryDialog extends JDialog {
                this.allowNamed.setSelected(!authenticated);\r
        }\r
 \r
-       public void setUsers(String owner, List<String> all, List<String> selected) {\r
+       public void setUsers(String owner, List<String> all, List<RegistrantAccessPermission> permissions) {\r
                ownerField.setModel(new DefaultComboBoxModel(all.toArray()));\r
                if (!StringUtils.isEmpty(owner)) {\r
                        ownerField.setSelectedItem(owner);\r
                }\r
-               usersPalette.setObjects(all, selected);\r
+               usersPalette.setObjects(all, permissions);\r
        }\r
 \r
-       public void setTeams(List<String> all, List<String> selected) {\r
-               teamsPalette.setObjects(all, selected);\r
+       public void setTeams(List<String> all, List<RegistrantAccessPermission> permissions) {\r
+               teamsPalette.setObjects(all, permissions);\r
        }\r
 \r
        public void setRepositories(List<RepositoryModel> repositories) {\r
@@ -607,12 +608,12 @@ public class EditRepositoryDialog extends JDialog {
                return repository;\r
        }\r
 \r
-       public List<String> getPermittedUsers() {\r
-               return usersPalette.getSelections();\r
+       public List<RegistrantAccessPermission> getUserAccessPermissions() {\r
+               return usersPalette.getPermissions();\r
        }\r
 \r
-       public List<String> getPermittedTeams() {\r
-               return teamsPalette.getSelections();\r
+       public List<RegistrantAccessPermission> getTeamAccessPermissions() {\r
+               return teamsPalette.getPermissions();\r
        }\r
        \r
        public void setCustomFields(RepositoryModel repository, Map<String, String> customFields) {\r
index 57d6bcfbbaf5cea7f8f830268c86792eb938ca17..4eb07295055fe53773941d3e11dd30a0f8cd8540 100644 (file)
@@ -45,6 +45,7 @@ import javax.swing.JTextField;
 import javax.swing.KeyStroke;\r
 \r
 import com.gitblit.Constants.AccessRestrictionType;\r
+import com.gitblit.models.RegistrantAccessPermission;\r
 import com.gitblit.models.RepositoryModel;\r
 import com.gitblit.models.ServerSettings;\r
 import com.gitblit.models.TeamModel;\r
@@ -74,7 +75,7 @@ public class EditTeamDialog extends JDialog {
 \r
        private JTextField mailingListsField;\r
 \r
-       private JPalette<String> repositoryPalette;\r
+       private RegistrantPermissionsPanel repositoryPalette;\r
 \r
        private JPalette<String> userPalette;\r
 \r
@@ -138,7 +139,7 @@ public class EditTeamDialog extends JDialog {
                fieldsPanel.add(newFieldPanel(Translation.get("gb.mailingLists"), mailingListsField));\r
 \r
                final Insets _insets = new Insets(5, 5, 5, 5);\r
-               repositoryPalette = new JPalette<String>();\r
+               repositoryPalette = new RegistrantPermissionsPanel();\r
                userPalette = new JPalette<String>();\r
                userPalette.setEnabled(settings.supportsTeamMembershipChanges);\r
                \r
@@ -278,8 +279,9 @@ public class EditTeamDialog extends JDialog {
                        team.mailingLists.addAll(list);\r
                }\r
 \r
-               team.repositories.clear();\r
-               team.repositories.addAll(repositoryPalette.getSelections());\r
+               for (RegistrantAccessPermission rp : repositoryPalette.getPermissions()) {\r
+                       team.setRepositoryPermission(rp.registrant, rp.permission);\r
+               }\r
 \r
                team.users.clear();\r
                team.users.addAll(userPalette.getSelections());\r
@@ -305,18 +307,21 @@ public class EditTeamDialog extends JDialog {
                }\r
        }\r
 \r
-       public void setRepositories(List<RepositoryModel> repositories, List<String> selected) {\r
+       public void setRepositories(List<RepositoryModel> repositories, List<RegistrantAccessPermission> permissions) {\r
                List<String> restricted = new ArrayList<String>();\r
                for (RepositoryModel repo : repositories) {\r
                        if (repo.accessRestriction.exceeds(AccessRestrictionType.NONE)) {\r
                                restricted.add(repo.name);\r
                        }\r
                }\r
-               StringUtils.sortRepositorynames(restricted);\r
-               if (selected != null) {\r
-                       StringUtils.sortRepositorynames(selected);\r
+               \r
+               // remove repositories for which team already has a permission\r
+               for (RegistrantAccessPermission rp : permissions) {\r
+                       restricted.remove(rp.registrant);\r
                }\r
-               repositoryPalette.setObjects(restricted, selected);\r
+\r
+               StringUtils.sortRepositorynames(restricted);\r
+               repositoryPalette.setObjects(restricted, permissions);\r
        }\r
 \r
        public void setUsers(List<String> users, List<String> selected) {\r
index 4ef036e872688ce88465b1f685774f5341bb3bed..5b789da57df935cf52c7ac424a007455d564eb7d 100644 (file)
@@ -47,6 +47,7 @@ import javax.swing.KeyStroke;
 \r
 import com.gitblit.Constants.AccessRestrictionType;\r
 import com.gitblit.Keys;\r
+import com.gitblit.models.RegistrantAccessPermission;\r
 import com.gitblit.models.RepositoryModel;\r
 import com.gitblit.models.ServerSettings;\r
 import com.gitblit.models.TeamModel;\r
@@ -85,7 +86,7 @@ public class EditUserDialog extends JDialog {
 \r
        private JCheckBox notFederatedCheckbox;\r
 \r
-       private JPalette<String> repositoryPalette;\r
+       private RegistrantPermissionsPanel repositoryPalette;\r
 \r
        private JPalette<TeamModel> teamsPalette;\r
 \r
@@ -157,7 +158,7 @@ public class EditUserDialog extends JDialog {
                                notFederatedCheckbox));\r
 \r
                final Insets _insets = new Insets(5, 5, 5, 5);\r
-               repositoryPalette = new JPalette<String>();\r
+               repositoryPalette = new RegistrantPermissionsPanel();\r
                teamsPalette = new JPalette<TeamModel>();\r
                teamsPalette.setEnabled(settings.supportsTeamMembershipChanges);\r
 \r
@@ -318,8 +319,9 @@ public class EditUserDialog extends JDialog {
                user.canCreate = canCreateCheckbox.isSelected();\r
                user.excludeFromFederation = notFederatedCheckbox.isSelected();\r
 \r
-               user.repositories.clear();\r
-               user.repositories.addAll(repositoryPalette.getSelections());\r
+               for (RegistrantAccessPermission rp : repositoryPalette.getPermissions()) {\r
+                       user.setRepositoryPermission(rp.registrant, rp.permission);\r
+               }\r
 \r
                user.teams.clear();\r
                user.teams.addAll(teamsPalette.getSelections());\r
@@ -338,18 +340,20 @@ public class EditUserDialog extends JDialog {
                }\r
        }\r
 \r
-       public void setRepositories(List<RepositoryModel> repositories, List<String> selected) {\r
+       public void setRepositories(List<RepositoryModel> repositories, List<RegistrantAccessPermission> permissions) {\r
                List<String> restricted = new ArrayList<String>();\r
                for (RepositoryModel repo : repositories) {\r
                        if (repo.accessRestriction.exceeds(AccessRestrictionType.NONE)) {\r
                                restricted.add(repo.name);\r
                        }\r
                }\r
-               StringUtils.sortRepositorynames(restricted);\r
-               if (selected != null) {\r
-                       StringUtils.sortRepositorynames(selected);\r
+               // remove repositories for which user already has a permission\r
+               for (RegistrantAccessPermission rp : permissions) {\r
+                       restricted.remove(rp.registrant);\r
                }\r
-               repositoryPalette.setObjects(restricted, selected);\r
+               \r
+               StringUtils.sortRepositorynames(restricted);\r
+               repositoryPalette.setObjects(restricted, permissions);\r
        }\r
 \r
        public void setTeams(List<TeamModel> teams, List<TeamModel> selected) {\r
index 52d4e06dffe4945823e7745a7a69f026f88afc36..9815cbe88025fe3297d6ddb366ddefd09acd3a21 100644 (file)
@@ -35,6 +35,7 @@ import com.gitblit.GitBlitException.NotAllowedException;
 import com.gitblit.GitBlitException.UnauthorizedException;\r
 import com.gitblit.GitBlitException.UnknownRequestException;\r
 import com.gitblit.Keys;\r
+import com.gitblit.models.RegistrantAccessPermission;\r
 import com.gitblit.models.FederationModel;\r
 import com.gitblit.models.FeedEntryModel;\r
 import com.gitblit.models.FeedModel;\r
@@ -485,12 +486,20 @@ public class GitblitClient implements Serializable {
        public List<String> getPermittedUsernames(RepositoryModel repository) {\r
                List<String> usernames = new ArrayList<String>();\r
                for (UserModel user : this.allUsers) {\r
-                       if (user.repositories.contains(repository.name)) {\r
+                       if (user.hasRepositoryPermission(repository.name)) {\r
                                usernames.add(user.username);\r
                        }\r
                }\r
                return usernames;\r
        }\r
+       \r
+       public List<RegistrantAccessPermission> getUserAccessPermissions(RepositoryModel repository) throws IOException {\r
+               return RpcUtils.getRepositoryMemberPermissions(repository, url, account, password);\r
+       }\r
+\r
+       public boolean setUserAccessPermissions(RepositoryModel repository, List<RegistrantAccessPermission> permissions) throws IOException {\r
+               return RpcUtils.setRepositoryMemberPermissions(repository, permissions, url, account, password);\r
+       }\r
 \r
        public List<TeamModel> getTeams() {\r
                return allTeams;\r
@@ -508,12 +517,20 @@ public class GitblitClient implements Serializable {
        public List<String> getPermittedTeamnames(RepositoryModel repository) {\r
                List<String> teamnames = new ArrayList<String>();\r
                for (TeamModel team : this.allTeams) {\r
-                       if (team.repositories.contains(repository.name)) {\r
+                       if (team.hasRepositoryPermission(repository.name)) {\r
                                teamnames.add(team.name);\r
                        }\r
                }\r
                return teamnames;\r
        }\r
+       \r
+       public List<RegistrantAccessPermission> getTeamAccessPermissions(RepositoryModel repository) throws IOException {\r
+               return RpcUtils.getRepositoryTeamPermissions(repository, url, account, password);\r
+       }\r
+\r
+       public boolean setTeamAccessPermissions(RepositoryModel repository, List<RegistrantAccessPermission> permissions) throws IOException {\r
+               return RpcUtils.setRepositoryTeamPermissions(repository, permissions, url, account, password);\r
+       }\r
 \r
        public TeamModel getTeamModel(String name) {\r
                for (TeamModel team : allTeams) {\r
@@ -532,44 +549,44 @@ public class GitblitClient implements Serializable {
                return allRepositories;\r
        }\r
 \r
-       public boolean createRepository(RepositoryModel repository, List<String> permittedUsers)\r
+       public boolean createRepository(RepositoryModel repository, List<RegistrantAccessPermission> userPermissions)\r
                        throws IOException {\r
-               return createRepository(repository, permittedUsers, null);\r
+               return createRepository(repository, userPermissions, null);\r
        }\r
 \r
-       public boolean createRepository(RepositoryModel repository, List<String> permittedUsers,\r
-                       List<String> permittedTeams) throws IOException {\r
+       public boolean createRepository(RepositoryModel repository, List<RegistrantAccessPermission> userPermissions,\r
+                       List<RegistrantAccessPermission> teamPermissions) throws IOException {\r
                boolean success = true;\r
                success &= RpcUtils.createRepository(repository, url, account, password);\r
-               if (permittedUsers != null && permittedUsers.size() > 0) {\r
+               if (userPermissions != null && userPermissions.size() > 0) {\r
                        // if new repository has named members, set them\r
-                       success &= RpcUtils.setRepositoryMembers(repository, permittedUsers, url, account,\r
+                       success &= RpcUtils.setRepositoryMemberPermissions(repository, userPermissions, url, account,\r
                                        password);\r
                }\r
-               if (permittedTeams != null && permittedTeams.size() > 0) {\r
+               if (teamPermissions != null && teamPermissions.size() > 0) {\r
                        // if new repository has named teams, set them\r
-                       success &= RpcUtils.setRepositoryTeams(repository, permittedTeams, url, account,\r
+                       success &= RpcUtils.setRepositoryTeamPermissions(repository, teamPermissions, url, account,\r
                                        password);\r
                }\r
                return success;\r
        }\r
 \r
        public boolean updateRepository(String name, RepositoryModel repository,\r
-                       List<String> permittedUsers) throws IOException {\r
-               return updateRepository(name, repository, permittedUsers, null);\r
+                       List<RegistrantAccessPermission> userPermissions) throws IOException {\r
+               return updateRepository(name, repository, userPermissions, null);\r
        }\r
 \r
        public boolean updateRepository(String name, RepositoryModel repository,\r
-                       List<String> permittedUsers, List<String> permittedTeams) throws IOException {\r
+                       List<RegistrantAccessPermission> userPermissions,       List<RegistrantAccessPermission> teamPermissions) throws IOException {\r
                boolean success = true;\r
                success &= RpcUtils.updateRepository(name, repository, url, account, password);\r
                // set the repository members\r
-               if (permittedUsers != null) {\r
-                       success &= RpcUtils.setRepositoryMembers(repository, permittedUsers, url, account,\r
+               if (userPermissions != null) {\r
+                       success &= RpcUtils.setRepositoryMemberPermissions(repository, userPermissions, url, account,\r
                                        password);\r
                }\r
-               if (permittedTeams != null) {\r
-                       success &= RpcUtils.setRepositoryTeams(repository, permittedTeams, url, account,\r
+               if (teamPermissions != null) {\r
+                       success &= RpcUtils.setRepositoryTeamPermissions(repository, teamPermissions, url, account,\r
                                        password);\r
                }\r
                return success;\r
diff --git a/src/com/gitblit/client/RegistrantPermissionsPanel.java b/src/com/gitblit/client/RegistrantPermissionsPanel.java
new file mode 100644 (file)
index 0000000..fa7ff5a
--- /dev/null
@@ -0,0 +1,140 @@
+/*\r
+ * Copyright 2012 gitblit.com.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *     http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+package com.gitblit.client;\r
+\r
+import java.awt.BorderLayout;\r
+import java.awt.Dimension;\r
+import java.awt.event.ActionEvent;\r
+import java.awt.event.ActionListener;\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+\r
+import javax.swing.DefaultCellEditor;\r
+import javax.swing.DefaultComboBoxModel;\r
+import javax.swing.JButton;\r
+import javax.swing.JComboBox;\r
+import javax.swing.JPanel;\r
+import javax.swing.JScrollPane;\r
+import javax.swing.JTable;\r
+\r
+import com.gitblit.Constants.AccessPermission;\r
+import com.gitblit.models.RegistrantAccessPermission;\r
+\r
+public class RegistrantPermissionsPanel extends JPanel {\r
+\r
+       private static final long serialVersionUID = 1L;\r
+       \r
+       private JTable permissionsTable;\r
+\r
+       private RegistrantPermissionsTableModel tableModel;\r
+\r
+       private DefaultComboBoxModel registrantModel;\r
+\r
+       private JComboBox registrantSelector;\r
+\r
+       private JComboBox permissionSelector;\r
+\r
+       private JButton addButton;\r
+\r
+       private JPanel addPanel;\r
+\r
+       public RegistrantPermissionsPanel() {\r
+               super(new BorderLayout(5, 5));\r
+               tableModel = new RegistrantPermissionsTableModel();\r
+               permissionsTable = new JTable(tableModel);\r
+               permissionsTable.setPreferredScrollableViewportSize(new Dimension(400, 150));\r
+               JScrollPane jsp = new JScrollPane(permissionsTable);\r
+               add(jsp, BorderLayout.CENTER);\r
+               \r
+               permissionsTable.getColumnModel().getColumn(RegistrantPermissionsTableModel.Columns.Permission.ordinal())\r
+                               .setCellEditor(new AccessPermissionEditor());\r
+               \r
+               registrantModel = new DefaultComboBoxModel();\r
+               registrantSelector = new JComboBox(registrantModel);\r
+               permissionSelector = new JComboBox(AccessPermission.NEWPERMISSIONS);\r
+               addButton = new JButton(Translation.get("gb.add"));\r
+               addButton.addActionListener(new ActionListener() {\r
+                       public void actionPerformed(ActionEvent e) {\r
+                               if (registrantSelector.getSelectedIndex() < 0) {\r
+                                       return;\r
+                               }\r
+                               if (permissionSelector.getSelectedIndex() < 0) {\r
+                                       return;\r
+                               }\r
+                               \r
+                               RegistrantAccessPermission rp = new RegistrantAccessPermission();\r
+                               rp.registrant = registrantSelector.getSelectedItem().toString();\r
+                               rp.permission = (AccessPermission) permissionSelector.getSelectedItem();\r
+                               tableModel.permissions.add(rp);\r
+                               \r
+                               registrantModel.removeElement(rp.registrant);\r
+                               registrantSelector.setSelectedIndex(-1);\r
+                               registrantSelector.invalidate();\r
+                               addPanel.setVisible(registrantModel.getSize() > 0);\r
+                               \r
+                               tableModel.fireTableDataChanged();\r
+                       }\r
+               });\r
+               \r
+               addPanel = new JPanel();\r
+               addPanel.add(registrantSelector);\r
+               addPanel.add(permissionSelector);\r
+               addPanel.add(addButton);\r
+               add(addPanel, BorderLayout.SOUTH);\r
+       }\r
+\r
+       @Override\r
+       public void setEnabled(boolean enabled) {\r
+               super.setEnabled(enabled);\r
+               permissionsTable.setEnabled(false);\r
+       }\r
+\r
+       public void setObjects(List<String> registrants, List<RegistrantAccessPermission> permissions) {\r
+               List<String> filtered;\r
+               if (registrants == null) {\r
+                       filtered = new ArrayList<String>();\r
+               } else {\r
+                       filtered = new ArrayList<String>(registrants);\r
+               }\r
+               if (permissions == null) {\r
+                       permissions = new ArrayList<RegistrantAccessPermission>();\r
+               }\r
+               for (RegistrantAccessPermission rp : permissions) {\r
+                       filtered.remove(rp.registrant);\r
+               }\r
+               for (String registrant : filtered) {\r
+                       registrantModel.addElement(registrant);\r
+               }\r
+               tableModel.setPermissions(permissions);\r
+               \r
+               registrantSelector.setSelectedIndex(-1);\r
+               permissionSelector.setSelectedIndex(-1);\r
+               addPanel.setVisible(filtered.size() > 0);\r
+       }\r
+\r
+       public List<RegistrantAccessPermission> getPermissions() {\r
+               return tableModel.permissions;\r
+       }\r
+       \r
+       private class AccessPermissionEditor extends DefaultCellEditor {\r
+           \r
+               private static final long serialVersionUID = 1L;\r
+\r
+               public AccessPermissionEditor() {\r
+               super(new JComboBox(AccessPermission.values()));\r
+           }\r
+       }\r
+}\r
diff --git a/src/com/gitblit/client/RegistrantPermissionsTableModel.java b/src/com/gitblit/client/RegistrantPermissionsTableModel.java
new file mode 100644 (file)
index 0000000..91acec8
--- /dev/null
@@ -0,0 +1,120 @@
+/*\r
+ * Copyright 2012 gitblit.com.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ *     http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+package com.gitblit.client;\r
+\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+\r
+import javax.swing.table.AbstractTableModel;\r
+\r
+import com.gitblit.Constants.AccessPermission;\r
+import com.gitblit.models.RegistrantAccessPermission;\r
+\r
+/**\r
+ * Table model of a registrant permissions.\r
+ * \r
+ * @author James Moger\r
+ * \r
+ */\r
+public class RegistrantPermissionsTableModel extends AbstractTableModel {\r
+\r
+       private static final long serialVersionUID = 1L;\r
+\r
+       List<RegistrantAccessPermission> permissions;\r
+\r
+       enum Columns {\r
+               Registrant, Permission;\r
+\r
+               @Override\r
+               public String toString() {\r
+                       return name().replace('_', ' ');\r
+               }\r
+       }\r
+\r
+       public RegistrantPermissionsTableModel() {\r
+               this(new ArrayList<RegistrantAccessPermission>());\r
+       }\r
+\r
+       public RegistrantPermissionsTableModel(List<RegistrantAccessPermission> list) {\r
+               setPermissions(list);\r
+       }\r
+\r
+       public void setPermissions(List<RegistrantAccessPermission> list) {\r
+               this.permissions = list;\r
+       }\r
+\r
+       @Override\r
+       public int getRowCount() {\r
+               return permissions.size();\r
+       }\r
+\r
+       @Override\r
+       public int getColumnCount() {\r
+               return Columns.values().length;\r
+       }\r
+\r
+       @Override\r
+       public String getColumnName(int column) {\r
+               Columns col = Columns.values()[column];\r
+               switch (col) {\r
+               case Registrant:\r
+                       return Translation.get("gb.name");\r
+               case Permission:\r
+                       return Translation.get("gb.permission");\r
+               }\r
+               return "";\r
+       }\r
+\r
+       /**\r
+        * Returns <code>Object.class</code> regardless of <code>columnIndex</code>.\r
+        * \r
+        * @param columnIndex\r
+        *            the column being queried\r
+        * @return the Object.class\r
+        */\r
+       public Class<?> getColumnClass(int columnIndex) {\r
+               if (columnIndex == Columns.Permission.ordinal()) {\r
+                       return AccessPermission.class;\r
+               }\r
+               return String.class;\r
+       }\r
+       \r
+       @Override\r
+       public boolean isCellEditable(int rowIndex, int columnIndex) {\r
+               return columnIndex == Columns.Permission.ordinal();\r
+       }\r
+\r
+       @Override\r
+       public Object getValueAt(int rowIndex, int columnIndex) {\r
+               RegistrantAccessPermission rp = permissions.get(rowIndex);\r
+               Columns col = Columns.values()[columnIndex];\r
+               switch (col) {\r
+               case Registrant:\r
+                       return rp.registrant;\r
+               case Permission:\r
+                       return rp.permission;\r
+               }\r
+               return null;\r
+       }\r
+       \r
+       @Override\r
+       public void setValueAt(Object o, int rowIndex, int columnIndex) {\r
+               RegistrantAccessPermission rp = permissions.get(rowIndex);\r
+               if (columnIndex == Columns.Permission.ordinal()) {\r
+                       rp.permission = (AccessPermission) o;\r
+               }\r
+       }\r
+}\r
index 54158e8e90cf69ee581d9e2663573fe6f9fb8a6b..972dda19cf3f34e44ec2a437b21abfe4cf910550 100644 (file)
@@ -49,6 +49,7 @@ import javax.swing.table.TableRowSorter;
 import com.gitblit.Constants;\r
 import com.gitblit.Constants.RpcRequest;\r
 import com.gitblit.Keys;\r
+import com.gitblit.models.RegistrantAccessPermission;\r
 import com.gitblit.models.FeedModel;\r
 import com.gitblit.models.RepositoryModel;\r
 import com.gitblit.utils.StringUtils;\r
@@ -401,8 +402,8 @@ public abstract class RepositoriesPanel extends JPanel {
                                gitblit.getPostReceiveScriptsInherited(null), null);\r
                dialog.setVisible(true);\r
                final RepositoryModel newRepository = dialog.getRepository();\r
-               final List<String> permittedUsers = dialog.getPermittedUsers();\r
-               final List<String> permittedTeams = dialog.getPermittedTeams();\r
+               final List<RegistrantAccessPermission> permittedUsers = dialog.getUserAccessPermissions();\r
+               final List<RegistrantAccessPermission> permittedTeams = dialog.getTeamAccessPermissions();\r
                if (newRepository == null) {\r
                        return;\r
                }\r
@@ -452,10 +453,14 @@ public abstract class RepositoriesPanel extends JPanel {
                                repository);\r
                dialog.setLocationRelativeTo(RepositoriesPanel.this);\r
                List<String> usernames = gitblit.getUsernames();\r
-               List<String> members = gitblit.getPermittedUsernames(repository);\r
-               dialog.setUsers(repository.owner, usernames, members);\r
-               dialog.setTeams(gitblit.getTeamnames(), gitblit.getPermittedTeamnames(repository));\r
-               dialog.setRepositories(gitblit.getRepositories());\r
+               try {\r
+                       List<RegistrantAccessPermission> members = gitblit.getUserAccessPermissions(repository);\r
+                       dialog.setUsers(repository.owner, usernames, members);\r
+                       dialog.setTeams(gitblit.getTeamnames(), gitblit.getTeamAccessPermissions(repository));\r
+                       dialog.setRepositories(gitblit.getRepositories());\r
+               } catch (IOException e) {\r
+                       //  TODO\r
+               }\r
                dialog.setFederationSets(gitblit.getFederationSets(), repository.federationSets);\r
                List<String> allLocalBranches = new ArrayList<String>();\r
                allLocalBranches.add(Constants.DEFAULT_BRANCH);\r
@@ -471,8 +476,8 @@ public abstract class RepositoriesPanel extends JPanel {
                }\r
                dialog.setVisible(true);\r
                final RepositoryModel revisedRepository = dialog.getRepository();\r
-               final List<String> permittedUsers = dialog.getPermittedUsers();\r
-               final List<String> permittedTeams = dialog.getPermittedTeams();\r
+               final List<RegistrantAccessPermission> permittedUsers = dialog.getUserAccessPermissions();\r
+               final List<RegistrantAccessPermission> permittedTeams = dialog.getTeamAccessPermissions();\r
                if (revisedRepository == null) {\r
                        return;\r
                }\r
index 7182566539b9456feac50a11522ef869f4ebda5a..6539d1c582bb2e910ce9f8e12df265246860e68f 100644 (file)
@@ -305,7 +305,7 @@ public abstract class TeamsPanel extends JPanel {
                                gitblit.getSettings());\r
                dialog.setLocationRelativeTo(TeamsPanel.this);\r
                dialog.setTeams(gitblit.getTeams());\r
-               dialog.setRepositories(gitblit.getRepositories(), new ArrayList<String>(team.repositories));\r
+               dialog.setRepositories(gitblit.getRepositories(), team.getRepositoryPermissions());\r
                dialog.setUsers(gitblit.getUsernames(), team.users == null ? null : new ArrayList<String>(\r
                                team.users));\r
                dialog.setPreReceiveScripts(gitblit.getPreReceiveScriptsUnused(null),\r
index 0dfa0434dbe256200cdf72bad0904e4cbd8047a4..9fcad7bc22f8e5a7237fa3720ab6f1c95b913429 100644 (file)
@@ -309,7 +309,7 @@ public abstract class UsersPanel extends JPanel {
                                gitblit.getSettings());\r
                dialog.setLocationRelativeTo(UsersPanel.this);\r
                dialog.setUsers(gitblit.getUsers());\r
-               dialog.setRepositories(gitblit.getRepositories(), new ArrayList<String>(user.repositories));\r
+               dialog.setRepositories(gitblit.getRepositories(), user.getRepositoryPermissions());\r
                dialog.setTeams(gitblit.getTeams(), user.teams == null ? null : new ArrayList<TeamModel>(\r
                                user.teams));\r
                dialog.setVisible(true);\r
index f635f7e8338657a32da0aa2c66ea6a00ebb416ae..b8ce45d4a046bef2d7f02c115437389942a8c1da 100644 (file)
@@ -110,8 +110,8 @@ public class UsersTableModel extends AbstractTableModel {
                        return (model.teams == null || model.teams.size() == 0) ? "" : String\r
                                        .valueOf(model.teams.size());\r
                case Repositories:\r
-                       return (model.repositories == null || model.repositories.size() == 0) ? "" : String\r
-                                       .valueOf(model.repositories.size());\r
+                       return (model.permissions == null || model.permissions.size() == 0) ? "" : String\r
+                                       .valueOf(model.permissions.size());\r
                }\r
                return null;\r
        }\r
diff --git a/src/com/gitblit/models/RegistrantAccessPermission.java b/src/com/gitblit/models/RegistrantAccessPermission.java
new file mode 100644 (file)
index 0000000..9302745
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2012 gitblit.com.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.gitblit.models;
+
+import java.io.Serializable;
+
+import com.gitblit.Constants.AccessPermission;
+import com.gitblit.Constants.RegistrantType;
+import com.gitblit.utils.StringUtils;
+
+/**
+ * Represents a Registrant-AccessPermission tuple.
+ * 
+ * @author James Moger
+ */
+public class RegistrantAccessPermission implements Serializable, Comparable<RegistrantAccessPermission> {
+
+       private static final long serialVersionUID = 1L;
+
+       public String registrant;
+       public AccessPermission permission;
+       public RegistrantType type;
+
+       public RegistrantAccessPermission() {
+       }
+       
+       public RegistrantAccessPermission(String registrant, AccessPermission permission, RegistrantType type) {
+               this.registrant = registrant;
+               this.permission = permission;
+               this.type = type;
+       }
+       
+       @Override
+       public int compareTo(RegistrantAccessPermission p) {
+               switch (type) {
+               case REPOSITORY:
+                       return StringUtils.compareRepositoryNames(registrant, p.registrant);
+               default:
+                       return registrant.toLowerCase().compareTo(p.registrant.toLowerCase());          
+               }
+       }
+       
+       @Override
+       public String toString() {
+               return permission.asRole(registrant);
+       }
+}
\ No newline at end of file
diff --git a/src/com/gitblit/models/RepositoryAccessPermission.java b/src/com/gitblit/models/RepositoryAccessPermission.java
deleted file mode 100644 (file)
index 06f5c05..0000000
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Copyright 2012 gitblit.com.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.gitblit.models;
-
-import java.io.Serializable;
-
-import com.gitblit.Constants.AccessPermission;
-import com.gitblit.utils.StringUtils;
-
-/**
- * Represents a Repository-AccessPermission tuple.
- * 
- * @author James Moger
- */
-public class RepositoryAccessPermission implements Serializable, Comparable<RepositoryAccessPermission> {
-
-       private static final long serialVersionUID = 1L;
-
-       public String repository;
-       public AccessPermission permission;
-
-       public RepositoryAccessPermission() {
-       }
-       
-       public RepositoryAccessPermission(String repository, AccessPermission permission) {
-               this.repository = repository;
-               this.permission = permission;
-       }
-       
-       @Override
-       public int compareTo(RepositoryAccessPermission p) {
-               return StringUtils.compareRepositoryNames(repository, p.repository);
-       }
-       
-       @Override
-       public String toString() {
-               return permission.asRole(repository);
-       }
-}
\ No newline at end of file
diff --git a/src/com/gitblit/models/TeamAccessPermission.java b/src/com/gitblit/models/TeamAccessPermission.java
deleted file mode 100644 (file)
index 23468c6..0000000
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Copyright 2012 gitblit.com.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.gitblit.models;
-
-import java.io.Serializable;
-
-import com.gitblit.Constants.AccessPermission;
-
-/**
- * Represents a Team-AccessPermission tuple.
- * 
- * @author James Moger
- */
-public class TeamAccessPermission implements Serializable, Comparable<TeamAccessPermission> {
-
-       private static final long serialVersionUID = 1L;
-
-       public String team;
-       public AccessPermission permission;
-
-       public TeamAccessPermission() {
-       }
-       
-       public TeamAccessPermission(String team, AccessPermission permission) {
-               this.team = team;
-               this.permission = permission;
-       }
-       
-       @Override
-       public int compareTo(TeamAccessPermission p) {
-               return team.compareTo(p.team);
-       }
-       
-       @Override
-       public String toString() {
-               return permission.asRole("@" + team);
-       }
-}
\ No newline at end of file
index 95e6ef4e6d1cc3194c7852df79d375402ce7daee..4c3a842799bc07286aa40f45177387a812f22586 100644 (file)
@@ -27,6 +27,7 @@ import java.util.Set;
 \r
 import com.gitblit.Constants.AccessPermission;\r
 import com.gitblit.Constants.AccessRestrictionType;\r
+import com.gitblit.Constants.RegistrantType;\r
 import com.gitblit.Constants.Unused;\r
 \r
 /**\r
@@ -93,10 +94,10 @@ public class TeamModel implements Serializable, Comparable<TeamModel> {
         * \r
         * @return the team's list of permissions\r
         */\r
-       public List<RepositoryAccessPermission> getRepositoryPermissions() {\r
-               List<RepositoryAccessPermission> list = new ArrayList<RepositoryAccessPermission>();\r
+       public List<RegistrantAccessPermission> getRepositoryPermissions() {\r
+               List<RegistrantAccessPermission> list = new ArrayList<RegistrantAccessPermission>();\r
                for (Map.Entry<String, AccessPermission> entry : permissions.entrySet()) {\r
-                       list.add(new RepositoryAccessPermission(entry.getKey(), entry.getValue()));\r
+                       list.add(new RegistrantAccessPermission(entry.getKey(), entry.getValue(), RegistrantType.REPOSITORY));\r
                }\r
                Collections.sort(list);\r
                return list;\r
diff --git a/src/com/gitblit/models/UserAccessPermission.java b/src/com/gitblit/models/UserAccessPermission.java
deleted file mode 100644 (file)
index a77fff2..0000000
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Copyright 2012 gitblit.com.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.gitblit.models;
-
-import java.io.Serializable;
-
-import com.gitblit.Constants.AccessPermission;
-
-/**
- * Represents a User-AccessPermission tuple.
- * 
- * @author James Moger
- */
-public class UserAccessPermission implements Serializable, Comparable<UserAccessPermission> {
-
-       private static final long serialVersionUID = 1L;
-
-       public String user;
-       public AccessPermission permission;
-
-       public UserAccessPermission() {
-       }
-       
-       public UserAccessPermission(String user, AccessPermission permission) {
-               this.user = user;
-               this.permission = permission;
-       }
-       
-       @Override
-       public int compareTo(UserAccessPermission p) {
-               return user.compareTo(p.user);
-       }
-       
-       @Override
-       public String toString() {
-               return permission.asRole(user);
-       }
-}
\ No newline at end of file
index 38a7aaedefab7d5e4d9aa9550063bd303283df64..fc9cbfba54064c30ec6583d5e6c0d748dd0f3c8d 100644 (file)
@@ -28,6 +28,7 @@ import java.util.Set;
 import com.gitblit.Constants.AccessPermission;\r
 import com.gitblit.Constants.AccessRestrictionType;\r
 import com.gitblit.Constants.AuthorizationControl;\r
+import com.gitblit.Constants.RegistrantType;\r
 import com.gitblit.Constants.Unused;\r
 import com.gitblit.utils.ArrayUtils;\r
 import com.gitblit.utils.StringUtils;\r
@@ -133,10 +134,10 @@ public class UserModel implements Principal, Serializable, Comparable<UserModel>
         * \r
         * @return the user's list of permissions\r
         */\r
-       public List<RepositoryAccessPermission> getRepositoryPermissions() {\r
-               List<RepositoryAccessPermission> list = new ArrayList<RepositoryAccessPermission>();\r
+       public List<RegistrantAccessPermission> getRepositoryPermissions() {\r
+               List<RegistrantAccessPermission> list = new ArrayList<RegistrantAccessPermission>();\r
                for (Map.Entry<String, AccessPermission> entry : permissions.entrySet()) {\r
-                       list.add(new RepositoryAccessPermission(entry.getKey(), entry.getValue()));\r
+                       list.add(new RegistrantAccessPermission(entry.getKey(), entry.getValue(), RegistrantType.REPOSITORY));\r
                }\r
                Collections.sort(list);\r
                return list;\r
@@ -208,10 +209,10 @@ public class UserModel implements Principal, Serializable, Comparable<UserModel>
                // and the permissions of teams of which the user belongs\r
                AccessPermission permission = AccessPermission.NONE;\r
                if (permissions.containsKey(repository.name.toLowerCase())) {\r
-                       // exact repository permission specified\r
+                       // exact repository permission specified, use it\r
                        AccessPermission p = permissions.get(repository.name.toLowerCase());\r
                        if (p != null) {\r
-                               permission = p;\r
+                               return p;\r
                        }\r
                } else {\r
                        // search for regex permission match\r
index 2b80e2af1ec645f670af22a8195efd822cced679..ed23dab62ca06e93550966a54c1d6fbd7ad72380 100644 (file)
@@ -25,6 +25,7 @@ import java.util.Map;
 import com.gitblit.Constants;\r
 import com.gitblit.Constants.RpcRequest;\r
 import com.gitblit.GitBlitException.UnknownRequestException;\r
+import com.gitblit.models.RegistrantAccessPermission;\r
 import com.gitblit.models.FederationModel;\r
 import com.gitblit.models.FederationProposal;\r
 import com.gitblit.models.FederationSet;\r
@@ -71,6 +72,9 @@ public class RpcUtils {
        private static final Type BRANCHES_TYPE = new TypeToken<Map<String, Collection<String>>>() {\r
        }.getType();\r
 \r
+       public static final Type REGISTRANT_PERMISSIONS_TYPE = new TypeToken<Collection<RegistrantAccessPermission>>() {\r
+       }.getType();\r
+\r
        /**\r
         * \r
         * @param remoteURL\r
@@ -357,25 +361,42 @@ public class RpcUtils {
                Collection<String> list = JsonUtils.retrieveJson(url, NAMES_TYPE, account, password);\r
                return new ArrayList<String>(list);\r
        }\r
+       \r
+       /**\r
+        * Retrieves the list of user access permissions for the specified repository.\r
+        * \r
+        * @param repository\r
+        * @param serverUrl\r
+        * @param account\r
+        * @param password\r
+        * @return list of User-AccessPermission tuples\r
+        * @throws IOException\r
+        */\r
+       public static List<RegistrantAccessPermission> getRepositoryMemberPermissions(RepositoryModel repository, \r
+                       String serverUrl, String account, char [] password) throws IOException {\r
+               String url = asLink(serverUrl, RpcRequest.LIST_REPOSITORY_MEMBER_PERMISSIONS, repository.name);\r
+               Collection<RegistrantAccessPermission> list = JsonUtils.retrieveJson(url, REGISTRANT_PERMISSIONS_TYPE, account, password);\r
+               return new ArrayList<RegistrantAccessPermission>(list);\r
+       }\r
 \r
        /**\r
-        * Sets the repository user membership list.\r
+        * Sets the repository user access permissions\r
         * \r
         * @param repository\r
-        * @param memberships\r
+        * @param permissions\r
         * @param serverUrl\r
         * @param account\r
         * @param password\r
         * @return true if the action succeeded\r
         * @throws IOException\r
         */\r
-       public static boolean setRepositoryMembers(RepositoryModel repository,\r
-                       List<String> memberships, String serverUrl, String account, char[] password)\r
+       public static boolean setRepositoryMemberPermissions(RepositoryModel repository,\r
+                       List<RegistrantAccessPermission> permissions, String serverUrl, String account, char[] password)\r
                        throws IOException {\r
-               return doAction(RpcRequest.SET_REPOSITORY_MEMBERS, repository.name, memberships, serverUrl,\r
+               return doAction(RpcRequest.SET_REPOSITORY_MEMBER_PERMISSIONS, repository.name, permissions, serverUrl,\r
                                account, password);\r
        }\r
-\r
+       \r
        /**\r
         * Retrieves the list of teams that can access the specified repository.\r
         * \r
@@ -392,25 +413,42 @@ public class RpcUtils {
                Collection<String> list = JsonUtils.retrieveJson(url, NAMES_TYPE, account, password);\r
                return new ArrayList<String>(list);\r
        }\r
+       \r
+       /**\r
+        * Retrieves the list of team access permissions for the specified repository.\r
+        * \r
+        * @param repository\r
+        * @param serverUrl\r
+        * @param account\r
+        * @param password\r
+        * @return list of Team-AccessPermission tuples\r
+        * @throws IOException\r
+        */\r
+       public static List<RegistrantAccessPermission> getRepositoryTeamPermissions(RepositoryModel repository, \r
+                       String serverUrl, String account, char [] password) throws IOException {\r
+               String url = asLink(serverUrl, RpcRequest.LIST_REPOSITORY_TEAM_PERMISSIONS, repository.name);\r
+               Collection<RegistrantAccessPermission> list = JsonUtils.retrieveJson(url, REGISTRANT_PERMISSIONS_TYPE, account, password);\r
+               return new ArrayList<RegistrantAccessPermission>(list);\r
+       }\r
 \r
        /**\r
-        * Sets the repository team membership list.\r
+        * Sets the repository team access permissions\r
         * \r
         * @param repository\r
-        * @param teams\r
+        * @param permissions\r
         * @param serverUrl\r
         * @param account\r
         * @param password\r
         * @return true if the action succeeded\r
         * @throws IOException\r
         */\r
-       public static boolean setRepositoryTeams(RepositoryModel repository,\r
-                       List<String> teams, String serverUrl, String account, char[] password)\r
+       public static boolean setRepositoryTeamPermissions(RepositoryModel repository,\r
+                       List<RegistrantAccessPermission> permissions, String serverUrl, String account, char[] password)\r
                        throws IOException {\r
-               return doAction(RpcRequest.SET_REPOSITORY_TEAMS, repository.name, teams, serverUrl,\r
+               return doAction(RpcRequest.SET_REPOSITORY_TEAM_PERMISSIONS, repository.name, permissions, serverUrl,\r
                                account, password);\r
        }\r
-\r
+       \r
        /**\r
         * Retrieves the list of federation registrations. These are the list of\r
         * registrations that this Gitblit instance is pulling from.\r
index eb7d77257b347ac6667fb5aeec9a364b12dcf4d2..e46bb0edfbd7bae1f43c6431a53283606b7ab7ed 100644 (file)
@@ -353,4 +353,5 @@ gb.clonePermission = {0} (clone)
 gb.pushPermission = {0} (push)\r
 gb.createPermission = {0} (push, ref creation)\r
 gb.deletePermission = {0} (push, ref creation+deletion)\r
-gb.rewindPermission = {0} (push, ref creation+deletion+rewind)
\ No newline at end of file
+gb.rewindPermission = {0} (push, ref creation+deletion+rewind)\r
+gb.permission = permission\r
index 4e34d898a28eed768ee7b326c5bcd55a5e9eb8e4..200a50e07c14b8d69a27e90c4e6cf0c907b6cd50 100644 (file)
@@ -54,9 +54,8 @@ import com.gitblit.Constants.FederationStrategy;
 import com.gitblit.GitBlit;\r
 import com.gitblit.GitBlitException;\r
 import com.gitblit.Keys;\r
+import com.gitblit.models.RegistrantAccessPermission;\r
 import com.gitblit.models.RepositoryModel;\r
-import com.gitblit.models.TeamAccessPermission;\r
-import com.gitblit.models.UserAccessPermission;\r
 import com.gitblit.models.UserModel;\r
 import com.gitblit.utils.ArrayUtils;\r
 import com.gitblit.utils.StringUtils;\r
@@ -64,8 +63,7 @@ import com.gitblit.wicket.GitBlitWebSession;
 import com.gitblit.wicket.StringChoiceRenderer;\r
 import com.gitblit.wicket.WicketUtils;\r
 import com.gitblit.wicket.panels.BulletListPanel;\r
-import com.gitblit.wicket.panels.TeamPermissionsPanel;\r
-import com.gitblit.wicket.panels.UserPermissionsPanel;\r
+import com.gitblit.wicket.panels.RegistrantPermissionsPanel;\r
 \r
 public class EditRepositoryPage extends RootSubPage {\r
 \r
@@ -117,8 +115,8 @@ public class EditRepositoryPage extends RootSubPage {
 \r
                List<String> indexedBranches = new ArrayList<String>();\r
                List<String> federationSets = new ArrayList<String>();\r
-               final List<UserAccessPermission> repositoryUsers = new ArrayList<UserAccessPermission>();\r
-               final List<TeamAccessPermission> repositoryTeams = new ArrayList<TeamAccessPermission>();\r
+               final List<RegistrantAccessPermission> repositoryUsers = new ArrayList<RegistrantAccessPermission>();\r
+               final List<RegistrantAccessPermission> repositoryTeams = new ArrayList<RegistrantAccessPermission>();\r
                List<String> preReceiveScripts = new ArrayList<String>();\r
                List<String> postReceiveScripts = new ArrayList<String>();\r
 \r
@@ -146,8 +144,10 @@ public class EditRepositoryPage extends RootSubPage {
 \r
                final String oldName = repositoryModel.name;\r
 \r
-               UserPermissionsPanel usersPalette = new UserPermissionsPanel("users", repositoryUsers, getAccessPermissions());\r
-               TeamPermissionsPanel teamsPalette = new TeamPermissionsPanel("teams", repositoryTeams, getAccessPermissions());\r
+               RegistrantPermissionsPanel usersPalette = new RegistrantPermissionsPanel("users", \r
+                               GitBlit.self().getAllUsernames(), repositoryUsers, getAccessPermissions());\r
+               RegistrantPermissionsPanel teamsPalette = new RegistrantPermissionsPanel("teams", \r
+                               GitBlit.self().getAllTeamnames(), repositoryTeams, getAccessPermissions());\r
 \r
                // indexed local branches palette\r
                List<String> allLocalBranches = new ArrayList<String>();\r
index 05c91215ec3e2d1a703a58950c19719f9c2d6268..a4e2c5e21bee37a79e6978e41a821d4d1c2b180e 100644 (file)
@@ -39,15 +39,15 @@ import org.apache.wicket.model.util.ListModel;
 import com.gitblit.Constants.AccessRestrictionType;\r
 import com.gitblit.GitBlit;\r
 import com.gitblit.GitBlitException;\r
+import com.gitblit.models.RegistrantAccessPermission;\r
 import com.gitblit.models.RepositoryModel;\r
-import com.gitblit.models.RepositoryAccessPermission;\r
 import com.gitblit.models.TeamModel;\r
 import com.gitblit.utils.StringUtils;\r
 import com.gitblit.wicket.RequiresAdminRole;\r
 import com.gitblit.wicket.StringChoiceRenderer;\r
 import com.gitblit.wicket.WicketUtils;\r
 import com.gitblit.wicket.panels.BulletListPanel;\r
-import com.gitblit.wicket.panels.RepositoryPermissionsPanel;\r
+import com.gitblit.wicket.panels.RegistrantPermissionsPanel;\r
 \r
 @RequiresAdminRole\r
 public class EditTeamPage extends RootSubPage {\r
@@ -98,7 +98,7 @@ public class EditTeamPage extends RootSubPage {
                List<String> postReceiveScripts = new ArrayList<String>();\r
 \r
                final String oldName = teamModel.name;\r
-               final List<RepositoryAccessPermission> permissions = teamModel.getRepositoryPermissions();\r
+               final List<RegistrantAccessPermission> permissions = teamModel.getRepositoryPermissions();\r
 \r
                // users palette\r
                final Palette<String> users = new Palette<String>("users", new ListModel<String>(\r
@@ -147,8 +147,8 @@ public class EditTeamPage extends RootSubPage {
                                        }\r
                                }\r
                                // update team permissions\r
-                               for (RepositoryAccessPermission repositoryPermission : permissions) {\r
-                                       teamModel.setRepositoryPermission(repositoryPermission.repository, repositoryPermission.permission);\r
+                               for (RegistrantAccessPermission repositoryPermission : permissions) {\r
+                                       teamModel.setRepositoryPermission(repositoryPermission.registrant, repositoryPermission.permission);\r
                                }\r
 \r
                                Iterator<String> selectedUsers = users.getSelectedChoices();\r
@@ -224,7 +224,7 @@ public class EditTeamPage extends RootSubPage {
                                : StringUtils.flattenStrings(teamModel.mailingLists, " "));\r
                form.add(new TextField<String>("mailingLists", mailingLists));\r
 \r
-               form.add(new RepositoryPermissionsPanel("repositories", permissions, getAccessPermissions()));\r
+               form.add(new RegistrantPermissionsPanel("repositories", repos, permissions, getAccessPermissions()));\r
                form.add(preReceivePalette);\r
                form.add(new BulletListPanel("inheritedPreReceive", "inherited", GitBlit.self()\r
                                .getPreReceiveScriptsInherited(null)));\r
index 6e3535437a41249abd29b567c5fba31f798dafce..3fc1eab15d7a1e167b50acd5a67fae67ef45b941 100644 (file)
@@ -38,15 +38,15 @@ import com.gitblit.Constants.AccessRestrictionType;
 import com.gitblit.GitBlit;\r
 import com.gitblit.GitBlitException;\r
 import com.gitblit.Keys;\r
+import com.gitblit.models.RegistrantAccessPermission;\r
 import com.gitblit.models.RepositoryModel;\r
-import com.gitblit.models.RepositoryAccessPermission;\r
 import com.gitblit.models.TeamModel;\r
 import com.gitblit.models.UserModel;\r
 import com.gitblit.utils.StringUtils;\r
 import com.gitblit.wicket.RequiresAdminRole;\r
 import com.gitblit.wicket.StringChoiceRenderer;\r
 import com.gitblit.wicket.WicketUtils;\r
-import com.gitblit.wicket.panels.RepositoryPermissionsPanel;\r
+import com.gitblit.wicket.panels.RegistrantPermissionsPanel;\r
 \r
 @RequiresAdminRole\r
 public class EditUserPage extends RootSubPage {\r
@@ -93,6 +93,8 @@ public class EditUserPage extends RootSubPage {
                                repos.add(repo);\r
                        }\r
                }\r
+               StringUtils.sortRepositorynames(repos);\r
+               \r
                List<String> userTeams = new ArrayList<String>();\r
                for (TeamModel team : userModel.teams) {\r
                        userTeams.add(team.name);\r
@@ -100,7 +102,7 @@ public class EditUserPage extends RootSubPage {
                Collections.sort(userTeams);\r
                \r
                final String oldName = userModel.username;\r
-               final List<RepositoryAccessPermission> permissions = userModel.getRepositoryPermissions();\r
+               final List<RegistrantAccessPermission> permissions = userModel.getRepositoryPermissions();\r
 \r
                final Palette<String> teams = new Palette<String>("teams", new ListModel<String>(\r
                                new ArrayList<String>(userTeams)), new CollectionModel<String>(GitBlit.self()\r
@@ -171,8 +173,8 @@ public class EditUserPage extends RootSubPage {
                                }\r
 \r
                                // update user permissions\r
-                               for (RepositoryAccessPermission repositoryPermission : permissions) {\r
-                                       userModel.setRepositoryPermission(repositoryPermission.repository, repositoryPermission.permission);\r
+                               for (RegistrantAccessPermission repositoryPermission : permissions) {\r
+                                       userModel.setRepositoryPermission(repositoryPermission.registrant, repositoryPermission.permission);\r
                                }\r
 \r
                                Iterator<String> selectedTeams = teams.getSelectedChoices();\r
@@ -234,7 +236,7 @@ public class EditUserPage extends RootSubPage {
                form.add(new CheckBox("canFork"));\r
                form.add(new CheckBox("canCreate"));\r
                form.add(new CheckBox("excludeFromFederation"));\r
-               form.add(new RepositoryPermissionsPanel("repositories", permissions, getAccessPermissions()));\r
+               form.add(new RegistrantPermissionsPanel("repositories", repos, permissions, getAccessPermissions()));\r
                form.add(teams.setEnabled(editTeams));\r
 \r
                form.add(new Button("save"));\r
diff --git a/src/com/gitblit/wicket/panels/RegistrantPermissionsPanel.html b/src/com/gitblit/wicket/panels/RegistrantPermissionsPanel.html
new file mode 100644 (file)
index 0000000..dd76d9f
--- /dev/null
@@ -0,0 +1,24 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\r
+<html xmlns="http://www.w3.org/1999/xhtml"  \r
+      xmlns:wicket="http://wicket.apache.org/dtds.data/wicket-xhtml1.3-strict.dtd"  \r
+      xml:lang="en"  \r
+      lang="en"> \r
+\r
+<body>\r
+<wicket:panel>\r
+\r
+       <div wicket:id="permissionRow">\r
+               <div style="padding-top:10px" class="row-fluid">\r
+                       <span class="span8" wicket:id="registrant"></span> <select class="input-medium" wicket:id="permission"></select>\r
+               </div>\r
+       </div>\r
+\r
+       <div style="padding-top:15px;" class="row-fluid">\r
+               <form class="well form-inline" wicket:id="addPermissionForm">\r
+                       <select class="input-large" wicket:id="registrant"></select> <select class="input-medium" wicket:id="permission"></select> <input class="btn btn-success" type="submit" value="Add" wicket:message="value:gb.add" wicket:id="addPermissionButton"/>\r
+               </form>\r
+       </div>  \r
+       \r
+</wicket:panel>\r
+</body>\r
+</html>
\ No newline at end of file
diff --git a/src/com/gitblit/wicket/panels/RegistrantPermissionsPanel.java b/src/com/gitblit/wicket/panels/RegistrantPermissionsPanel.java
new file mode 100644 (file)
index 0000000..936659d
--- /dev/null
@@ -0,0 +1,157 @@
+/*
+ * Copyright 2012 gitblit.com.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.gitblit.wicket.panels;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.wicket.ajax.AjaxRequestTarget;
+import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior;
+import org.apache.wicket.ajax.markup.html.form.AjaxButton;
+import org.apache.wicket.markup.html.basic.Label;
+import org.apache.wicket.markup.html.form.DropDownChoice;
+import org.apache.wicket.markup.html.form.Form;
+import org.apache.wicket.markup.html.form.IChoiceRenderer;
+import org.apache.wicket.markup.repeater.Item;
+import org.apache.wicket.markup.repeater.OddEvenItem;
+import org.apache.wicket.markup.repeater.RefreshingView;
+import org.apache.wicket.markup.repeater.util.ModelIteratorAdapter;
+import org.apache.wicket.model.CompoundPropertyModel;
+import org.apache.wicket.model.IModel;
+
+import com.gitblit.Constants.AccessPermission;
+import com.gitblit.models.RegistrantAccessPermission;
+import com.gitblit.utils.DeepCopier;
+
+/**
+ * Allows user to manipulate registrant access permissions.
+ * 
+ * @author James Moger
+ *
+ */
+public class RegistrantPermissionsPanel extends BasePanel {
+
+       private static final long serialVersionUID = 1L;
+
+       public RegistrantPermissionsPanel(String wicketId, List<String> allRegistrants, final List<RegistrantAccessPermission> permissions, final Map<AccessPermission, String> translations) {
+               super(wicketId);
+               
+               // update existing permissions repeater
+               RefreshingView<RegistrantAccessPermission> dataView = new RefreshingView<RegistrantAccessPermission>("permissionRow") {
+                       private static final long serialVersionUID = 1L;
+               
+                       @Override
+            protected Iterator<IModel<RegistrantAccessPermission>> getItemModels() {
+                // the iterator returns RepositoryPermission objects, but we need it to
+                // return models
+                return new ModelIteratorAdapter<RegistrantAccessPermission>(permissions.iterator()) {
+                    @Override
+                    protected IModel<RegistrantAccessPermission> model(RegistrantAccessPermission permission) {
+                        return new CompoundPropertyModel<RegistrantAccessPermission>(permission);
+                    }
+                };
+            }
+
+            @Override
+            protected Item<RegistrantAccessPermission> newItem(String id, int index, IModel<RegistrantAccessPermission> model) {
+                // this item sets markup class attribute to either 'odd' or
+                // 'even' for decoration
+                return new OddEvenItem<RegistrantAccessPermission>(id, index, model);
+            }
+            
+                       public void populateItem(final Item<RegistrantAccessPermission> item) {
+                               final RegistrantAccessPermission entry = item.getModelObject();
+                               item.add(new Label("registrant", entry.registrant));
+
+                               // use ajax to get immediate update of permission level change
+                               // otherwise we can lose it if they change levels and then add
+                               // a new repository permission
+                               final DropDownChoice<AccessPermission> permissionChoice = new DropDownChoice<AccessPermission>(
+                                               "permission", Arrays.asList(AccessPermission.values()), new AccessPermissionRenderer(translations));
+                               permissionChoice.add(new AjaxFormComponentUpdatingBehavior("onchange") {
+                          
+                                       private static final long serialVersionUID = 1L;
+
+                                       protected void onUpdate(AjaxRequestTarget target) {
+                               target.addComponent(permissionChoice);
+                           }
+                       });
+
+                               item.add(permissionChoice);
+                       }
+               };
+               add(dataView);
+               setOutputMarkupId(true);
+
+               // filter out registrants we already have permissions for
+               final List<String> registrants = new ArrayList<String>(allRegistrants);
+               for (RegistrantAccessPermission rp : permissions) {
+                       registrants.remove(rp.registrant);
+               }
+
+               // add new permission form
+               IModel<RegistrantAccessPermission> addPermissionModel = new CompoundPropertyModel<RegistrantAccessPermission>(new RegistrantAccessPermission());
+               Form<RegistrantAccessPermission> addPermissionForm = new Form<RegistrantAccessPermission>("addPermissionForm", addPermissionModel);
+               addPermissionForm.add(new DropDownChoice<String>("registrant", registrants));
+               addPermissionForm.add(new DropDownChoice<AccessPermission>("permission", Arrays
+                               .asList(AccessPermission.NEWPERMISSIONS), new AccessPermissionRenderer(translations)));
+               AjaxButton button = new AjaxButton("addPermissionButton", addPermissionForm) {
+
+                       private static final long serialVersionUID = 1L;
+
+                       @Override
+                       protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
+                               // add permission to our list
+                               RegistrantAccessPermission rp = (RegistrantAccessPermission) form.getModel().getObject();
+                               permissions.add(DeepCopier.copy(rp));
+                               
+                               // remove registrant from available choices
+                               registrants.remove(rp.registrant);
+                               
+                               // force the panel to refresh
+                               target.addComponent(RegistrantPermissionsPanel.this);
+                       }
+               };
+               addPermissionForm.add(button);
+               
+               // only show add permission form if we have a registrant choice
+               add(addPermissionForm.setVisible(registrants.size() > 0));
+       }
+       
+       private class AccessPermissionRenderer implements IChoiceRenderer<AccessPermission> {
+
+               private static final long serialVersionUID = 1L;
+
+               private final Map<AccessPermission, String> map;
+
+               public AccessPermissionRenderer(Map<AccessPermission, String> map) {
+                       this.map = map;
+               }
+
+               @Override
+               public String getDisplayValue(AccessPermission type) {
+                       return map.get(type);
+               }
+
+               @Override
+               public String getIdValue(AccessPermission type, int index) {
+                       return Integer.toString(index);
+               }
+       }
+}
diff --git a/src/com/gitblit/wicket/panels/RepositoryPermissionsPanel.html b/src/com/gitblit/wicket/panels/RepositoryPermissionsPanel.html
deleted file mode 100644 (file)
index 1c7e44e..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\r
-<html xmlns="http://www.w3.org/1999/xhtml"  \r
-      xmlns:wicket="http://wicket.apache.org/dtds.data/wicket-xhtml1.3-strict.dtd"  \r
-      xml:lang="en"  \r
-      lang="en"> \r
-\r
-<body>\r
-<wicket:panel>\r
-\r
-       <div wicket:id="permissionRow">\r
-               <div style="padding-top:10px" class="row-fluid">\r
-                       <span class="span8" wicket:id="repository"></span> <select class="input-medium" wicket:id="permission"></select>\r
-               </div>\r
-       </div>\r
-\r
-       <div style="padding-top:15px;" class="row-fluid">\r
-               <form class="well form-inline" wicket:id="addPermissionForm">\r
-                       <select class="input-large" wicket:id="repository"></select> <select class="input-medium" wicket:id="permission"></select> <input class="btn btn-success" type="submit" value="Add" wicket:message="value:gb.add" wicket:id="addPermissionButton"/>\r
-               </form>\r
-       </div>  \r
-       \r
-</wicket:panel>\r
-</body>\r
-</html>
\ No newline at end of file
diff --git a/src/com/gitblit/wicket/panels/RepositoryPermissionsPanel.java b/src/com/gitblit/wicket/panels/RepositoryPermissionsPanel.java
deleted file mode 100644 (file)
index 3d967d3..0000000
+++ /dev/null
@@ -1,157 +0,0 @@
-/*
- * Copyright 2012 gitblit.com.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.gitblit.wicket.panels;
-
-import java.util.Arrays;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.wicket.ajax.AjaxRequestTarget;
-import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior;
-import org.apache.wicket.ajax.markup.html.form.AjaxButton;
-import org.apache.wicket.markup.html.basic.Label;
-import org.apache.wicket.markup.html.form.DropDownChoice;
-import org.apache.wicket.markup.html.form.Form;
-import org.apache.wicket.markup.html.form.IChoiceRenderer;
-import org.apache.wicket.markup.repeater.Item;
-import org.apache.wicket.markup.repeater.OddEvenItem;
-import org.apache.wicket.markup.repeater.RefreshingView;
-import org.apache.wicket.markup.repeater.util.ModelIteratorAdapter;
-import org.apache.wicket.model.CompoundPropertyModel;
-import org.apache.wicket.model.IModel;
-
-import com.gitblit.Constants.AccessPermission;
-import com.gitblit.GitBlit;
-import com.gitblit.models.RepositoryAccessPermission;
-import com.gitblit.utils.DeepCopier;
-
-/**
- * Allows user to manipulate repository access permissions.
- * 
- * @author James Moger
- *
- */
-public class RepositoryPermissionsPanel extends BasePanel {
-
-       private static final long serialVersionUID = 1L;
-
-       public RepositoryPermissionsPanel(String wicketId, final List<RepositoryAccessPermission> permissions, final Map<AccessPermission, String> translations) {
-               super(wicketId);
-               
-               // update existing permissions repeater
-               RefreshingView<RepositoryAccessPermission> dataView = new RefreshingView<RepositoryAccessPermission>("permissionRow") {
-                       private static final long serialVersionUID = 1L;
-               
-                       @Override
-            protected Iterator<IModel<RepositoryAccessPermission>> getItemModels() {
-                // the iterator returns RepositoryPermission objects, but we need it to
-                // return models
-                return new ModelIteratorAdapter<RepositoryAccessPermission>(permissions.iterator()) {
-                    @Override
-                    protected IModel<RepositoryAccessPermission> model(RepositoryAccessPermission permission) {
-                        return new CompoundPropertyModel<RepositoryAccessPermission>(permission);
-                    }
-                };
-            }
-
-            @Override
-            protected Item<RepositoryAccessPermission> newItem(String id, int index, IModel<RepositoryAccessPermission> model) {
-                // this item sets markup class attribute to either 'odd' or
-                // 'even' for decoration
-                return new OddEvenItem<RepositoryAccessPermission>(id, index, model);
-            }
-            
-                       public void populateItem(final Item<RepositoryAccessPermission> item) {
-                               final RepositoryAccessPermission entry = item.getModelObject();
-                               item.add(new Label("repository", entry.repository));
-
-                               // use ajax to get immediate update of permission level change
-                               // otherwise we can lose it if they change levels and then add
-                               // a new repository permission
-                               final DropDownChoice<AccessPermission> permissionChoice = new DropDownChoice<AccessPermission>(
-                                               "permission", Arrays.asList(AccessPermission.values()), new AccessPermissionRenderer(translations));
-                               permissionChoice.add(new AjaxFormComponentUpdatingBehavior("onchange") {
-                          
-                                       private static final long serialVersionUID = 1L;
-
-                                       protected void onUpdate(AjaxRequestTarget target) {
-                               target.addComponent(permissionChoice);
-                           }
-                       });
-
-                               item.add(permissionChoice);
-                       }
-               };
-               add(dataView);
-               setOutputMarkupId(true);
-
-               // filter out repositories we already have permissions for
-               final List<String> repositories = GitBlit.self().getRepositoryList();
-               for (RepositoryAccessPermission rp : permissions) {
-                       repositories.remove(rp.repository);
-               }
-
-               // add new permission form
-               IModel<RepositoryAccessPermission> addPermissionModel = new CompoundPropertyModel<RepositoryAccessPermission>(new RepositoryAccessPermission());
-               Form<RepositoryAccessPermission> addPermissionForm = new Form<RepositoryAccessPermission>("addPermissionForm", addPermissionModel);
-               addPermissionForm.add(new DropDownChoice<String>("repository", repositories));
-               addPermissionForm.add(new DropDownChoice<AccessPermission>("permission", Arrays
-                               .asList(AccessPermission.NEWPERMISSIONS), new AccessPermissionRenderer(translations)));
-               AjaxButton button = new AjaxButton("addPermissionButton", addPermissionForm) {
-
-                       private static final long serialVersionUID = 1L;
-
-                       @Override
-                       protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
-                               // add permission to our list
-                               RepositoryAccessPermission rp = (RepositoryAccessPermission) form.getModel().getObject();
-                               permissions.add(DeepCopier.copy(rp));
-                               
-                               // remove repository from available choices
-                               repositories.remove(rp.repository);
-                               
-                               // force the panel to refresh
-                               target.addComponent(RepositoryPermissionsPanel.this);
-                       }
-               };
-               addPermissionForm.add(button);
-               
-               // only show add permission form if we have a repository choice
-               add(addPermissionForm.setVisible(repositories.size() > 0));
-       }
-       
-       private class AccessPermissionRenderer implements IChoiceRenderer<AccessPermission> {
-
-               private static final long serialVersionUID = 1L;
-
-               private final Map<AccessPermission, String> map;
-
-               public AccessPermissionRenderer(Map<AccessPermission, String> map) {
-                       this.map = map;
-               }
-
-               @Override
-               public String getDisplayValue(AccessPermission type) {
-                       return map.get(type);
-               }
-
-               @Override
-               public String getIdValue(AccessPermission type, int index) {
-                       return Integer.toString(index);
-               }
-       }
-}
diff --git a/src/com/gitblit/wicket/panels/TeamPermissionsPanel.html b/src/com/gitblit/wicket/panels/TeamPermissionsPanel.html
deleted file mode 100644 (file)
index d728f65..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\r
-<html xmlns="http://www.w3.org/1999/xhtml"  \r
-      xmlns:wicket="http://wicket.apache.org/dtds.data/wicket-xhtml1.3-strict.dtd"  \r
-      xml:lang="en"  \r
-      lang="en"> \r
-\r
-<body>\r
-<wicket:panel>\r
-\r
-       <div wicket:id="permissionRow">\r
-               <div style="padding-top:10px" class="row-fluid">\r
-                       <span class="span8" wicket:id="team"></span> <select class="input-medium" wicket:id="permission"></select>\r
-               </div>\r
-       </div>\r
-\r
-       <div style="padding-top:15px;" class="row-fluid">\r
-               <form class="well form-inline" wicket:id="addPermissionForm">\r
-                       <select class="input-large" wicket:id="team"></select> <select class="input-medium" wicket:id="permission"></select> <input class="btn btn-success" type="submit" value="Add" wicket:message="value:gb.add" wicket:id="addPermissionButton"/>\r
-               </form>\r
-       </div>  \r
-       \r
-</wicket:panel>\r
-</body>\r
-</html>
\ No newline at end of file
diff --git a/src/com/gitblit/wicket/panels/TeamPermissionsPanel.java b/src/com/gitblit/wicket/panels/TeamPermissionsPanel.java
deleted file mode 100644 (file)
index e51aab4..0000000
+++ /dev/null
@@ -1,157 +0,0 @@
-/*
- * Copyright 2012 gitblit.com.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.gitblit.wicket.panels;
-
-import java.util.Arrays;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.wicket.ajax.AjaxRequestTarget;
-import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior;
-import org.apache.wicket.ajax.markup.html.form.AjaxButton;
-import org.apache.wicket.markup.html.basic.Label;
-import org.apache.wicket.markup.html.form.DropDownChoice;
-import org.apache.wicket.markup.html.form.Form;
-import org.apache.wicket.markup.html.form.IChoiceRenderer;
-import org.apache.wicket.markup.repeater.Item;
-import org.apache.wicket.markup.repeater.OddEvenItem;
-import org.apache.wicket.markup.repeater.RefreshingView;
-import org.apache.wicket.markup.repeater.util.ModelIteratorAdapter;
-import org.apache.wicket.model.CompoundPropertyModel;
-import org.apache.wicket.model.IModel;
-
-import com.gitblit.Constants.AccessPermission;
-import com.gitblit.GitBlit;
-import com.gitblit.models.TeamAccessPermission;
-import com.gitblit.utils.DeepCopier;
-
-/**
- * Allows user to manipulate user access permissions.
- * 
- * @author James Moger
- *
- */
-public class TeamPermissionsPanel extends BasePanel {
-
-       private static final long serialVersionUID = 1L;
-
-       public TeamPermissionsPanel(String wicketId, final List<TeamAccessPermission> permissions, final Map<AccessPermission, String> translations) {
-               super(wicketId);
-               
-               // update existing permissions repeater
-               RefreshingView<TeamAccessPermission> dataView = new RefreshingView<TeamAccessPermission>("permissionRow") {
-                       private static final long serialVersionUID = 1L;
-               
-                       @Override
-            protected Iterator<IModel<TeamAccessPermission>> getItemModels() {
-                // the iterator returns RepositoryPermission objects, but we need it to
-                // return models
-                return new ModelIteratorAdapter<TeamAccessPermission>(permissions.iterator()) {
-                    @Override
-                    protected IModel<TeamAccessPermission> model(TeamAccessPermission permission) {
-                        return new CompoundPropertyModel<TeamAccessPermission>(permission);
-                    }
-                };
-            }
-
-            @Override
-            protected Item<TeamAccessPermission> newItem(String id, int index, IModel<TeamAccessPermission> model) {
-                // this item sets markup class attribute to either 'odd' or
-                // 'even' for decoration
-                return new OddEvenItem<TeamAccessPermission>(id, index, model);
-            }
-            
-                       public void populateItem(final Item<TeamAccessPermission> item) {
-                               final TeamAccessPermission entry = item.getModelObject();
-                               item.add(new Label("team", entry.team));
-
-                               // use ajax to get immediate update of permission level change
-                               // otherwise we can lose it if they change levels and then add
-                               // a new repository permission
-                               final DropDownChoice<AccessPermission> permissionChoice = new DropDownChoice<AccessPermission>(
-                                               "permission", Arrays.asList(AccessPermission.values()), new AccessPermissionRenderer(translations));
-                               permissionChoice.add(new AjaxFormComponentUpdatingBehavior("onchange") {
-                          
-                                       private static final long serialVersionUID = 1L;
-
-                                       protected void onUpdate(AjaxRequestTarget target) {
-                               target.addComponent(permissionChoice);
-                           }
-                       });
-
-                               item.add(permissionChoice);
-                       }
-               };
-               add(dataView);
-               setOutputMarkupId(true);
-
-               // filter out teams we already have permissions for
-               final List<String> teams = GitBlit.self().getAllTeamnames();
-               for (TeamAccessPermission tp : permissions) {
-                       teams.remove(tp.team);
-               }
-
-               // add new permission form
-               IModel<TeamAccessPermission> addPermissionModel = new CompoundPropertyModel<TeamAccessPermission>(new TeamAccessPermission());
-               Form<TeamAccessPermission> addPermissionForm = new Form<TeamAccessPermission>("addPermissionForm", addPermissionModel);
-               addPermissionForm.add(new DropDownChoice<String>("team", teams));
-               addPermissionForm.add(new DropDownChoice<AccessPermission>("permission", Arrays
-                               .asList(AccessPermission.NEWPERMISSIONS), new AccessPermissionRenderer(translations)));
-               AjaxButton button = new AjaxButton("addPermissionButton", addPermissionForm) {
-
-                       private static final long serialVersionUID = 1L;
-
-                       @Override
-                       protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
-                               // add permission to our list
-                               TeamAccessPermission tp = (TeamAccessPermission) form.getModel().getObject();
-                               permissions.add(DeepCopier.copy(tp));
-                               
-                               // remove team from available choices
-                               teams.remove(tp.team);
-                               
-                               // force the panel to refresh
-                               target.addComponent(TeamPermissionsPanel.this);
-                       }
-               };
-               addPermissionForm.add(button);
-               
-               // only show add permission form if we have a team choice
-               add(addPermissionForm.setVisible(teams.size() > 0));
-       }
-       
-       private class AccessPermissionRenderer implements IChoiceRenderer<AccessPermission> {
-
-               private static final long serialVersionUID = 1L;
-
-               private final Map<AccessPermission, String> map;
-
-               public AccessPermissionRenderer(Map<AccessPermission, String> map) {
-                       this.map = map;
-               }
-
-               @Override
-               public String getDisplayValue(AccessPermission type) {
-                       return map.get(type);
-               }
-
-               @Override
-               public String getIdValue(AccessPermission type, int index) {
-                       return Integer.toString(index);
-               }
-       }
-}
diff --git a/src/com/gitblit/wicket/panels/UserPermissionsPanel.html b/src/com/gitblit/wicket/panels/UserPermissionsPanel.html
deleted file mode 100644 (file)
index 14d4305..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\r
-<html xmlns="http://www.w3.org/1999/xhtml"  \r
-      xmlns:wicket="http://wicket.apache.org/dtds.data/wicket-xhtml1.3-strict.dtd"  \r
-      xml:lang="en"  \r
-      lang="en"> \r
-\r
-<body>\r
-<wicket:panel>\r
-\r
-       <div wicket:id="permissionRow">\r
-               <div style="padding-top:10px" class="row-fluid">\r
-                       <span class="span8" wicket:id="user"></span> <select class="input-medium" wicket:id="permission"></select>\r
-               </div>\r
-       </div>\r
-\r
-       <div style="padding-top:15px;" class="row-fluid">\r
-               <form class="well form-inline" wicket:id="addPermissionForm">\r
-                       <select class="input-large" wicket:id="user"></select> <select class="input-medium" wicket:id="permission"></select> <input class="btn btn-success" type="submit" value="Add" wicket:message="value:gb.add" wicket:id="addPermissionButton"/>\r
-               </form>\r
-       </div>  \r
-       \r
-</wicket:panel>\r
-</body>\r
-</html>
\ No newline at end of file
diff --git a/src/com/gitblit/wicket/panels/UserPermissionsPanel.java b/src/com/gitblit/wicket/panels/UserPermissionsPanel.java
deleted file mode 100644 (file)
index 6d0ae58..0000000
+++ /dev/null
@@ -1,157 +0,0 @@
-/*
- * Copyright 2012 gitblit.com.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.gitblit.wicket.panels;
-
-import java.util.Arrays;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.wicket.ajax.AjaxRequestTarget;
-import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior;
-import org.apache.wicket.ajax.markup.html.form.AjaxButton;
-import org.apache.wicket.markup.html.basic.Label;
-import org.apache.wicket.markup.html.form.DropDownChoice;
-import org.apache.wicket.markup.html.form.Form;
-import org.apache.wicket.markup.html.form.IChoiceRenderer;
-import org.apache.wicket.markup.repeater.Item;
-import org.apache.wicket.markup.repeater.OddEvenItem;
-import org.apache.wicket.markup.repeater.RefreshingView;
-import org.apache.wicket.markup.repeater.util.ModelIteratorAdapter;
-import org.apache.wicket.model.CompoundPropertyModel;
-import org.apache.wicket.model.IModel;
-
-import com.gitblit.Constants.AccessPermission;
-import com.gitblit.GitBlit;
-import com.gitblit.models.UserAccessPermission;
-import com.gitblit.utils.DeepCopier;
-
-/**
- * Allows user to manipulate user access permissions.
- * 
- * @author James Moger
- *
- */
-public class UserPermissionsPanel extends BasePanel {
-
-       private static final long serialVersionUID = 1L;
-
-       public UserPermissionsPanel(String wicketId, final List<UserAccessPermission> permissions, final Map<AccessPermission, String> translations) {
-               super(wicketId);
-               
-               // update existing permissions repeater
-               RefreshingView<UserAccessPermission> dataView = new RefreshingView<UserAccessPermission>("permissionRow") {
-                       private static final long serialVersionUID = 1L;
-               
-                       @Override
-            protected Iterator<IModel<UserAccessPermission>> getItemModels() {
-                // the iterator returns RepositoryPermission objects, but we need it to
-                // return models
-                return new ModelIteratorAdapter<UserAccessPermission>(permissions.iterator()) {
-                    @Override
-                    protected IModel<UserAccessPermission> model(UserAccessPermission permission) {
-                        return new CompoundPropertyModel<UserAccessPermission>(permission);
-                    }
-                };
-            }
-
-            @Override
-            protected Item<UserAccessPermission> newItem(String id, int index, IModel<UserAccessPermission> model) {
-                // this item sets markup class attribute to either 'odd' or
-                // 'even' for decoration
-                return new OddEvenItem<UserAccessPermission>(id, index, model);
-            }
-            
-                       public void populateItem(final Item<UserAccessPermission> item) {
-                               final UserAccessPermission entry = item.getModelObject();
-                               item.add(new Label("user", entry.user));
-
-                               // use ajax to get immediate update of permission level change
-                               // otherwise we can lose it if they change levels and then add
-                               // a new repository permission
-                               final DropDownChoice<AccessPermission> permissionChoice = new DropDownChoice<AccessPermission>(
-                                               "permission", Arrays.asList(AccessPermission.values()), new AccessPermissionRenderer(translations));
-                               permissionChoice.add(new AjaxFormComponentUpdatingBehavior("onchange") {
-                          
-                                       private static final long serialVersionUID = 1L;
-
-                                       protected void onUpdate(AjaxRequestTarget target) {
-                               target.addComponent(permissionChoice);
-                           }
-                       });
-
-                               item.add(permissionChoice);
-                       }
-               };
-               add(dataView);
-               setOutputMarkupId(true);
-
-               // filter out users we already have permissions for
-               final List<String> users = GitBlit.self().getAllUsernames();
-               for (UserAccessPermission up : permissions) {
-                       users.remove(up.user);
-               }
-
-               // add new permission form
-               IModel<UserAccessPermission> addPermissionModel = new CompoundPropertyModel<UserAccessPermission>(new UserAccessPermission());
-               Form<UserAccessPermission> addPermissionForm = new Form<UserAccessPermission>("addPermissionForm", addPermissionModel);
-               addPermissionForm.add(new DropDownChoice<String>("user", users));
-               addPermissionForm.add(new DropDownChoice<AccessPermission>("permission", Arrays
-                               .asList(AccessPermission.NEWPERMISSIONS), new AccessPermissionRenderer(translations)));
-               AjaxButton button = new AjaxButton("addPermissionButton", addPermissionForm) {
-
-                       private static final long serialVersionUID = 1L;
-
-                       @Override
-                       protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
-                               // add permission to our list
-                               UserAccessPermission up = (UserAccessPermission) form.getModel().getObject();
-                               permissions.add(DeepCopier.copy(up));
-                               
-                               // remove user from available choices
-                               users.remove(up.user);
-                               
-                               // force the panel to refresh
-                               target.addComponent(UserPermissionsPanel.this);
-                       }
-               };
-               addPermissionForm.add(button);
-               
-               // only show add permission form if we have a user choice
-               add(addPermissionForm.setVisible(users.size() > 0));
-       }
-       
-       private class AccessPermissionRenderer implements IChoiceRenderer<AccessPermission> {
-
-               private static final long serialVersionUID = 1L;
-
-               private final Map<AccessPermission, String> map;
-
-               public AccessPermissionRenderer(Map<AccessPermission, String> map) {
-                       this.map = map;
-               }
-
-               @Override
-               public String getDisplayValue(AccessPermission type) {
-                       return map.get(type);
-               }
-
-               @Override
-               public String getIdValue(AccessPermission type, int index) {
-                       return Integer.toString(index);
-               }
-       }
-}
index c5dba847dfa0a8595a8c6d6d8808afa857e7136d..46c502e5749508ffb53a2c6371372c5efcc7fba0 100644 (file)
@@ -84,7 +84,7 @@ public class UsersPanel extends BasePanel {
                                item.add(new Label("accesslevel", entry.canAdmin() ? "administrator" : ""));\r
                                item.add(new Label("teams", entry.teams.size() > 0 ? ("" + entry.teams.size()) : ""));\r
                                item.add(new Label("repositories",\r
-                                               entry.repositories.size() > 0 ? ("" + entry.repositories.size()) : ""));\r
+                                               entry.permissions.size() > 0 ? ("" + entry.permissions.size()) : ""));\r
                                Fragment userLinks = new Fragment("userLinks", "userAdminLinks", this);\r
                                userLinks.add(new BookmarkablePageLink<Void>("editUser", EditUserPage.class,\r
                                                WicketUtils.newUsernameParameter(entry.username)));\r
index 3ad0ec591e2490088cbdd3b389a670a5748b1975..c739eba3038d8e4738a19b30b22dbfd58b1350e3 100644 (file)
@@ -32,11 +32,14 @@ import org.junit.AfterClass;
 import org.junit.BeforeClass;\r
 import org.junit.Test;\r
 \r
+import com.gitblit.Constants.AccessPermission;\r
 import com.gitblit.Constants.AccessRestrictionType;\r
 import com.gitblit.Constants.AuthorizationControl;\r
+import com.gitblit.Constants.RegistrantType;\r
 import com.gitblit.GitBlitException.UnauthorizedException;\r
 import com.gitblit.Keys;\r
 import com.gitblit.RpcServlet;\r
+import com.gitblit.models.RegistrantAccessPermission;\r
 import com.gitblit.models.FederationModel;\r
 import com.gitblit.models.FederationProposal;\r
 import com.gitblit.models.FederationSet;\r
@@ -180,6 +183,7 @@ public class RpcTests {
                String originalName = model.name;\r
                model.name = "garbagerepo2.git";\r
                model.accessRestriction = AccessRestrictionType.PUSH;\r
+               model.authorizationControl = AuthorizationControl.NAMED;\r
                assertTrue("Failed to update repository!", RpcUtils.updateRepository(originalName, model,\r
                                url, account, password.toCharArray()));\r
 \r
@@ -192,20 +196,21 @@ public class RpcTests {
                UserModel testMember = new UserModel("justadded");\r
                assertTrue(RpcUtils.createUser(testMember, url, account, password.toCharArray()));\r
 \r
-               List<String> members = RpcUtils.getRepositoryMembers(retrievedRepository, url, account,\r
+               List<RegistrantAccessPermission> permissions = RpcUtils.getRepositoryMemberPermissions(retrievedRepository, url, account,\r
                                password.toCharArray());\r
-               assertEquals("Membership roster is not empty!", 0, members.size());\r
-               members.add(testMember.username);\r
+               assertEquals("Membership permissions is not empty!", 0, permissions.size());\r
+               permissions.add(new RegistrantAccessPermission(testMember.username, AccessPermission.PUSH, RegistrantType.USER));\r
                assertTrue(\r
-                               "Failed to set memberships!",\r
-                               RpcUtils.setRepositoryMembers(retrievedRepository, members, url, account,\r
+                               "Failed to set member permissions!",\r
+                               RpcUtils.setRepositoryMemberPermissions(retrievedRepository, permissions, url, account,\r
                                                password.toCharArray()));\r
-               members = RpcUtils.getRepositoryMembers(retrievedRepository, url, account,\r
+               permissions = RpcUtils.getRepositoryMemberPermissions(retrievedRepository, url, account,\r
                                password.toCharArray());\r
                boolean foundMember = false;\r
-               for (String member : members) {\r
-                       if (member.equalsIgnoreCase(testMember.username)) {\r
+               for (RegistrantAccessPermission permission : permissions) {\r
+                       if (permission.registrant.equalsIgnoreCase(testMember.username)) {\r
                                foundMember = true;\r
+                               assertEquals(AccessPermission.PUSH, permission.permission);\r
                                break;\r
                        }\r
                }\r
@@ -281,7 +286,11 @@ public class RpcTests {
                assertTrue(helloworldTeams.contains(aTeam.name));\r
 \r
                // set no teams\r
-               assertTrue(RpcUtils.setRepositoryTeams(helloworld, new ArrayList<String>(), url, account,\r
+               List<RegistrantAccessPermission> permissions = new ArrayList<RegistrantAccessPermission>();\r
+               for (String team : helloworldTeams) {\r
+                       permissions.add(new RegistrantAccessPermission(team, AccessPermission.NONE, RegistrantType.TEAM));\r
+               }\r
+               assertTrue(RpcUtils.setRepositoryTeamPermissions(helloworld, permissions, url, account,\r
                                password.toCharArray()));\r
                helloworldTeams = RpcUtils.getRepositoryTeams(helloworld, url, account,\r
                                password.toCharArray());\r