]> source.dussan.org Git - gitblit.git/commitdiff
Implement FORK RPC request type
authormanisha <manisha@wso2.com>
Fri, 21 Mar 2014 08:57:02 +0000 (14:27 +0530)
committerJames Moger <james.moger@gitblit.com>
Thu, 8 May 2014 13:00:11 +0000 (09:00 -0400)
src/main/java/com/gitblit/Constants.java
src/main/java/com/gitblit/models/UserRepositoryCompositeModel.java [new file with mode: 0644]
src/main/java/com/gitblit/servlet/RpcServlet.java
src/main/java/com/gitblit/utils/RpcUtils.java
src/test/config/test-users.conf
src/test/java/com/gitblit/tests/RpcTests.java
src/test/java/com/gitblit/tests/Test.java [new file with mode: 0644]

index a5e76a515ba49998afef3fe135a50baa47886f85..cbbc0cacad95059217f70f35210cb55ed12fa1fd 100644 (file)
@@ -353,7 +353,7 @@ public class Constants {
                // Order is important here.  anything above LIST_SETTINGS requires\r
                // administrator privileges and web.allowRpcManagement.\r
                CLEAR_REPOSITORY_CACHE, REINDEX_TICKETS, GET_PROTOCOL, LIST_REPOSITORIES, LIST_BRANCHES, GET_USER, LIST_SETTINGS,\r
-               CREATE_REPOSITORY, EDIT_REPOSITORY, DELETE_REPOSITORY,\r
+               CREATE_REPOSITORY, FORK_REPOSITORY, EDIT_REPOSITORY, DELETE_REPOSITORY,\r
                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
diff --git a/src/main/java/com/gitblit/models/UserRepositoryCompositeModel.java b/src/main/java/com/gitblit/models/UserRepositoryCompositeModel.java
new file mode 100644 (file)
index 0000000..122bb3b
--- /dev/null
@@ -0,0 +1,47 @@
+package com.gitblit.models;
+
+/*
+ * Copyright 2011 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.
+ */
+
+
+import com.gitblit.utils.StringUtils;
+
+import java.io.Serializable;
+
+public class UserRepositoryCompositeModel implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    public UserModel userModel;
+    public RepositoryModel repositoryModel;
+
+    public UserModel getUserModel() {
+        return userModel;
+    }
+
+    public void setUserModel(UserModel userModel) {
+        this.userModel = userModel;
+    }
+
+    public RepositoryModel getRepositoryModel() {
+        return repositoryModel;
+    }
+
+    public void setRepositoryModel(RepositoryModel repositoryModel) {
+        this.repositoryModel = repositoryModel;
+    }
+
+}
\ No newline at end of file
index 2d59ebd7eada640432d2ae598d85183fc897ca14..80c50714c11922b7a82e1ca6a895400b9dba4a41 100644 (file)
@@ -27,6 +27,7 @@ import javax.servlet.ServletException;
 import javax.servlet.http.HttpServletRequest;\r
 import javax.servlet.http.HttpServletResponse;\r
 \r
+import com.gitblit.models.*;\r
 import org.eclipse.jgit.lib.Repository;\r
 \r
 import com.gitblit.Constants;\r
@@ -35,12 +36,6 @@ import com.gitblit.GitBlitException;
 import com.gitblit.IStoredSettings;\r
 import com.gitblit.Keys;\r
 import com.gitblit.manager.IGitblit;\r
-import com.gitblit.models.RefModel;\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
-import com.gitblit.models.UserModel;\r
 import com.gitblit.utils.DeepCopier;\r
 import com.gitblit.utils.HttpUtils;\r
 import com.gitblit.utils.JGitUtils;\r
@@ -53,352 +48,368 @@ import dagger.ObjectGraph;
  * Handles remote procedure calls.\r
  *\r
  * @author James Moger\r
- *\r
  */\r
 public class RpcServlet extends JsonServlet {\r
 \r
-       private static final long serialVersionUID = 1L;\r
+    private static final long serialVersionUID = 1L;\r
+\r
+    public static final int PROTOCOL_VERSION = 7;\r
 \r
-       public static final int PROTOCOL_VERSION = 7;\r
+    private IStoredSettings settings;\r
 \r
-       private IStoredSettings settings;\r
+    private IGitblit gitblit;\r
 \r
-       private IGitblit gitblit;\r
+    @Override\r
+    protected void inject(ObjectGraph dagger) {\r
+        this.settings = dagger.get(IStoredSettings.class);\r
+        this.gitblit = dagger.get(IGitblit.class);\r
+    }\r
 \r
-       @Override\r
-       protected void inject(ObjectGraph dagger) {\r
-               this.settings = dagger.get(IStoredSettings.class);\r
-               this.gitblit = dagger.get(IGitblit.class);\r
-       }\r
+    /**\r
+     * Processes an rpc request.\r
+     *\r
+     * @param request\r
+     * @param response\r
+     * @throws javax.servlet.ServletException\r
+     * @throws java.io.IOException\r
+     */\r
+    @Override\r
+    protected void processRequest(HttpServletRequest request, HttpServletResponse response)\r
+            throws ServletException, IOException {\r
+        RpcRequest reqType = RpcRequest.fromName(request.getParameter("req"));\r
+        String objectName = request.getParameter("name");\r
+        logger.info(MessageFormat.format("Rpc {0} request from {1}", reqType,\r
+                request.getRemoteAddr()));\r
 \r
-       /**\r
-        * Processes an rpc request.\r
-        *\r
-        * @param request\r
-        * @param response\r
-        * @throws javax.servlet.ServletException\r
-        * @throws java.io.IOException\r
-        */\r
-       @Override\r
-       protected void processRequest(HttpServletRequest request, HttpServletResponse response)\r
-                       throws ServletException, IOException {\r
-               RpcRequest reqType = RpcRequest.fromName(request.getParameter("req"));\r
-               String objectName = request.getParameter("name");\r
-               logger.info(MessageFormat.format("Rpc {0} request from {1}", reqType,\r
-                               request.getRemoteAddr()));\r
+        UserModel user = (UserModel) request.getUserPrincipal();\r
 \r
-               UserModel user = (UserModel) request.getUserPrincipal();\r
+        boolean allowManagement = user != null && user.canAdmin()\r
+                && settings.getBoolean(Keys.web.enableRpcManagement, false);\r
 \r
-               boolean allowManagement = user != null && user.canAdmin()\r
-                               && settings.getBoolean(Keys.web.enableRpcManagement, false);\r
+        boolean allowAdmin = user != null && user.canAdmin()\r
+                && settings.getBoolean(Keys.web.enableRpcAdministration, false);\r
 \r
-               boolean allowAdmin = user != null && user.canAdmin()\r
-                               && settings.getBoolean(Keys.web.enableRpcAdministration, false);\r
+        Object result = null;\r
+        if (RpcRequest.GET_PROTOCOL.equals(reqType)) {\r
+            // Return the protocol version\r
+            result = PROTOCOL_VERSION;\r
+        } else if (RpcRequest.LIST_REPOSITORIES.equals(reqType)) {\r
+            // Determine the Gitblit clone url\r
+            String gitblitUrl = settings.getString(Keys.web.canonicalUrl, null);\r
+            if (StringUtils.isEmpty(gitblitUrl)) {\r
+                gitblitUrl = HttpUtils.getGitblitURL(request);\r
+            }\r
+            StringBuilder sb = new StringBuilder();\r
+            sb.append(gitblitUrl);\r
+            sb.append(Constants.R_PATH);\r
+            sb.append("{0}");\r
+            String cloneUrl = sb.toString();\r
 \r
-               Object result = null;\r
-               if (RpcRequest.GET_PROTOCOL.equals(reqType)) {\r
-                       // Return the protocol version\r
-                       result = PROTOCOL_VERSION;\r
-               } else if (RpcRequest.LIST_REPOSITORIES.equals(reqType)) {\r
-                       // Determine the Gitblit clone url\r
-                       String gitblitUrl = settings.getString(Keys.web.canonicalUrl, null);\r
-                       if (StringUtils.isEmpty(gitblitUrl)) {\r
-                               gitblitUrl = HttpUtils.getGitblitURL(request);\r
-                       }\r
-                       StringBuilder sb = new StringBuilder();\r
-                       sb.append(gitblitUrl);\r
-                       sb.append(Constants.R_PATH);\r
-                       sb.append("{0}");\r
-                       String cloneUrl = sb.toString();\r
+            // list repositories\r
+            List<RepositoryModel> list = gitblit.getRepositoryModels(user);\r
+            Map<String, RepositoryModel> repositories = new HashMap<String, RepositoryModel>();\r
+            for (RepositoryModel model : list) {\r
+                String url = MessageFormat.format(cloneUrl, model.name);\r
+                repositories.put(url, model);\r
+            }\r
+            result = repositories;\r
+        } else if (RpcRequest.LIST_BRANCHES.equals(reqType)) {\r
+            // list all local branches in all repositories accessible to user\r
+            Map<String, List<String>> localBranches = new HashMap<String, List<String>>();\r
+            List<RepositoryModel> models = gitblit.getRepositoryModels(user);\r
+            for (RepositoryModel model : models) {\r
+                if (!model.hasCommits) {\r
+                    // skip empty repository\r
+                    continue;\r
+                }\r
+                if (model.isCollectingGarbage) {\r
+                    // skip garbage collecting repository\r
+                    logger.warn(MessageFormat.format("Temporarily excluding {0} from RPC, busy collecting garbage", model.name));\r
+                    continue;\r
+                }\r
+                // get local branches\r
+                Repository repository = gitblit.getRepository(model.name);\r
+                List<RefModel> refs = JGitUtils.getLocalBranches(repository, false, -1);\r
+                if (model.showRemoteBranches) {\r
+                    // add remote branches if repository displays them\r
+                    refs.addAll(JGitUtils.getRemoteBranches(repository, false, -1));\r
+                }\r
+                if (refs.size() > 0) {\r
+                    List<String> branches = new ArrayList<String>();\r
+                    for (RefModel ref : refs) {\r
+                        branches.add(ref.getName());\r
+                    }\r
+                    localBranches.put(model.name, branches);\r
+                }\r
+                repository.close();\r
+            }\r
+            result = localBranches;\r
+        } else if (RpcRequest.GET_USER.equals(reqType)) {\r
+            if (StringUtils.isEmpty(objectName)) {\r
+                if (UserModel.ANONYMOUS.equals(user)) {\r
+                    response.sendError(forbiddenCode);\r
+                } else {\r
+                    // return the current user, reset credentials\r
+                    UserModel requestedUser = DeepCopier.copy(user);\r
+                    result = requestedUser;\r
+                }\r
+            } else {\r
+                if (user.canAdmin() || objectName.equals(user.username)) {\r
+                    // return the specified user\r
+                    UserModel requestedUser = gitblit.getUserModel(objectName);\r
+                    if (requestedUser == null) {\r
+                        response.setStatus(failureCode);\r
+                    } else {\r
+                        result = requestedUser;\r
+                    }\r
+                } else {\r
+                    response.sendError(forbiddenCode);\r
+                }\r
+            }\r
+        } else if (RpcRequest.LIST_USERS.equals(reqType)) {\r
+            // list users\r
+            List<String> names = gitblit.getAllUsernames();\r
+            List<UserModel> users = new ArrayList<UserModel>();\r
+            for (String name : names) {\r
+                users.add(gitblit.getUserModel(name));\r
+            }\r
+            result = users;\r
+        } else if (RpcRequest.LIST_TEAMS.equals(reqType)) {\r
+            // list teams\r
+            List<String> names = gitblit.getAllTeamNames();\r
+            List<TeamModel> teams = new ArrayList<TeamModel>();\r
+            for (String name : names) {\r
+                teams.add(gitblit.getTeamModel(name));\r
+            }\r
+            result = teams;\r
+        } else if (RpcRequest.CREATE_REPOSITORY.equals(reqType)) {\r
+            // create repository\r
+            RepositoryModel model = deserialize(request, response, RepositoryModel.class);\r
+            try {\r
+                gitblit.updateRepositoryModel(model.name, model, true);\r
+            } catch (GitBlitException e) {\r
+                response.setStatus(failureCode);\r
+            }\r
+        } else if (RpcRequest.FORK_REPOSITORY.equals(reqType)) {\r
+            // fork repository\r
+            UserRepositoryCompositeModel userRepositoryCompositeModel = deserialize(request, response,\r
+                    UserRepositoryCompositeModel.class);\r
+            RepositoryModel repoModel = userRepositoryCompositeModel.getRepositoryModel();\r
+            UserModel userModel = userRepositoryCompositeModel.getUserModel();\r
+            try {\r
+                if (repoModel != null && userModel != null) {\r
+                    gitblit.fork(repoModel, userModel);\r
+                } else {\r
+                    System.out.println("Non existing user model or repo model");\r
+                    response.setStatus(failureCode);\r
+                }\r
 \r
-                       // list repositories\r
-                       List<RepositoryModel> list = gitblit.getRepositoryModels(user);\r
-                       Map<String, RepositoryModel> repositories = new HashMap<String, RepositoryModel>();\r
-                       for (RepositoryModel model : list) {\r
-                               String url = MessageFormat.format(cloneUrl, model.name);\r
-                               repositories.put(url, model);\r
-                       }\r
-                       result = repositories;\r
-               } else if (RpcRequest.LIST_BRANCHES.equals(reqType)) {\r
-                       // list all local branches in all repositories accessible to user\r
-                       Map<String, List<String>> localBranches = new HashMap<String, List<String>>();\r
-                       List<RepositoryModel> models = gitblit.getRepositoryModels(user);\r
-                       for (RepositoryModel model : models) {\r
-                               if (!model.hasCommits) {\r
-                                       // skip empty repository\r
-                                       continue;\r
-                               }\r
-                               if (model.isCollectingGarbage) {\r
-                                       // skip garbage collecting repository\r
-                                       logger.warn(MessageFormat.format("Temporarily excluding {0} from RPC, busy collecting garbage", model.name));\r
-                                       continue;\r
-                               }\r
-                               // get local branches\r
-                               Repository repository = gitblit.getRepository(model.name);\r
-                               List<RefModel> refs = JGitUtils.getLocalBranches(repository, false, -1);\r
-                               if (model.showRemoteBranches) {\r
-                                       // add remote branches if repository displays them\r
-                                       refs.addAll(JGitUtils.getRemoteBranches(repository, false, -1));\r
-                               }\r
-                               if (refs.size() > 0) {\r
-                                       List<String> branches = new ArrayList<String>();\r
-                                       for (RefModel ref : refs) {\r
-                                               branches.add(ref.getName());\r
-                                       }\r
-                                       localBranches.put(model.name, branches);\r
-                               }\r
-                               repository.close();\r
-                       }\r
-                       result = localBranches;\r
-               } else if (RpcRequest.GET_USER.equals(reqType)) {\r
-                       if (StringUtils.isEmpty(objectName)) {\r
-                               if (UserModel.ANONYMOUS.equals(user)) {\r
-                                       response.sendError(forbiddenCode);\r
-                               } else {\r
-                                       // return the current user, reset credentials\r
-                                       UserModel requestedUser = DeepCopier.copy(user);\r
-                                       result = requestedUser;\r
-                               }\r
-                       } else {\r
-                               if (user.canAdmin() || objectName.equals(user.username)) {\r
-                                       // return the specified user\r
-                                       UserModel requestedUser = gitblit.getUserModel(objectName);\r
-                                       if (requestedUser == null) {\r
-                                               response.setStatus(failureCode);\r
-                                       } else {\r
-                                               result = requestedUser;\r
-                                       }\r
-                               } else {\r
-                                       response.sendError(forbiddenCode);\r
-                               }\r
-                       }\r
-               } else if (RpcRequest.LIST_USERS.equals(reqType)) {\r
-                       // list users\r
-                       List<String> names = gitblit.getAllUsernames();\r
-                       List<UserModel> users = new ArrayList<UserModel>();\r
-                       for (String name : names) {\r
-                               users.add(gitblit.getUserModel(name));\r
-                       }\r
-                       result = users;\r
-               } else if (RpcRequest.LIST_TEAMS.equals(reqType)) {\r
-                       // list teams\r
-                       List<String> names = gitblit.getAllTeamNames();\r
-                       List<TeamModel> teams = new ArrayList<TeamModel>();\r
-                       for (String name : names) {\r
-                               teams.add(gitblit.getTeamModel(name));\r
-                       }\r
-                       result = teams;\r
-               } else if (RpcRequest.CREATE_REPOSITORY.equals(reqType)) {\r
-                       // create repository\r
-                       RepositoryModel model = deserialize(request, response, RepositoryModel.class);\r
-                       try {\r
-                               gitblit.updateRepositoryModel(model.name, model, true);\r
-                       } catch (GitBlitException e) {\r
-                               response.setStatus(failureCode);\r
-                       }\r
-               } else if (RpcRequest.EDIT_REPOSITORY.equals(reqType)) {\r
-                       // edit repository\r
-                       RepositoryModel model = deserialize(request, response, RepositoryModel.class);\r
-                       // name specifies original repository name in event of rename\r
-                       String repoName = objectName;\r
-                       if (repoName == null) {\r
-                               repoName = model.name;\r
-                       }\r
-                       try {\r
-                               gitblit.updateRepositoryModel(repoName, model, false);\r
-                       } catch (GitBlitException e) {\r
-                               response.setStatus(failureCode);\r
-                       }\r
-               } else if (RpcRequest.DELETE_REPOSITORY.equals(reqType)) {\r
-                       // delete repository\r
-                       RepositoryModel model = deserialize(request, response, RepositoryModel.class);\r
-                       gitblit.deleteRepositoryModel(model);\r
-               } else if (RpcRequest.CREATE_USER.equals(reqType)) {\r
-                       // create user\r
-                       UserModel model = deserialize(request, response, UserModel.class);\r
-                       try {\r
-                               gitblit.addUser(model);\r
-                       } catch (GitBlitException e) {\r
-                               response.setStatus(failureCode);\r
-                       }\r
-               } else if (RpcRequest.EDIT_USER.equals(reqType)) {\r
-                       // edit user\r
-                       UserModel model = deserialize(request, response, UserModel.class);\r
-                       // name parameter specifies original user name in event of rename\r
-                       String username = objectName;\r
-                       if (username == null) {\r
-                               username = model.username;\r
-                       }\r
-                       try {\r
-                               gitblit.reviseUser(username, model);\r
-                       } catch (GitBlitException e) {\r
-                               response.setStatus(failureCode);\r
-                       }\r
-               } else if (RpcRequest.DELETE_USER.equals(reqType)) {\r
-                       // delete user\r
-                       UserModel model = deserialize(request, response, UserModel.class);\r
-                       if (!gitblit.deleteUser(model.username)) {\r
-                               response.setStatus(failureCode);\r
-                       }\r
-               } else if (RpcRequest.CREATE_TEAM.equals(reqType)) {\r
-                       // create team\r
-                       TeamModel model = deserialize(request, response, TeamModel.class);\r
-                       try {\r
-                               gitblit.addTeam(model);\r
-                       } catch (GitBlitException e) {\r
-                               response.setStatus(failureCode);\r
-                       }\r
-               } else if (RpcRequest.EDIT_TEAM.equals(reqType)) {\r
-                       // edit team\r
-                       TeamModel model = deserialize(request, response, TeamModel.class);\r
-                       // name parameter specifies original team name in event of rename\r
-                       String teamname = objectName;\r
-                       if (teamname == null) {\r
-                               teamname = model.name;\r
-                       }\r
-                       try {\r
-                               gitblit.reviseTeam(teamname, model);\r
-                       } catch (GitBlitException e) {\r
-                               response.setStatus(failureCode);\r
-                       }\r
-               } else if (RpcRequest.DELETE_TEAM.equals(reqType)) {\r
-                       // delete team\r
-                       TeamModel model = deserialize(request, response, TeamModel.class);\r
-                       if (!gitblit.deleteTeam(model.name)) {\r
-                               response.setStatus(failureCode);\r
-                       }\r
-               } else if (RpcRequest.LIST_REPOSITORY_MEMBERS.equals(reqType)) {\r
-                       // get repository members\r
-                       RepositoryModel model = gitblit.getRepositoryModel(objectName);\r
-                       result = gitblit.getRepositoryUsers(model);\r
-               } else if (RpcRequest.SET_REPOSITORY_MEMBERS.equals(reqType)) {\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.getRepositoryModel(objectName);\r
-                       result = gitblit.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.getRepositoryModel(objectName);\r
-                       Collection<RegistrantAccessPermission> permissions = deserialize(request, response, RpcUtils.REGISTRANT_PERMISSIONS_TYPE);\r
-                       result = gitblit.setUserAccessPermissions(model, permissions);\r
-               } else if (RpcRequest.LIST_REPOSITORY_TEAMS.equals(reqType)) {\r
-                       // get repository teams\r
-                       RepositoryModel model = gitblit.getRepositoryModel(objectName);\r
-                       result = gitblit.getRepositoryTeams(model);\r
-               } else if (RpcRequest.SET_REPOSITORY_TEAMS.equals(reqType)) {\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.getRepositoryModel(objectName);\r
-                       result = gitblit.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.getRepositoryModel(objectName);\r
-                       Collection<RegistrantAccessPermission> permissions = deserialize(request, response, RpcUtils.REGISTRANT_PERMISSIONS_TYPE);\r
-                       result = gitblit.setTeamAccessPermissions(model, permissions);\r
-               } else if (RpcRequest.LIST_FEDERATION_REGISTRATIONS.equals(reqType)) {\r
-                       // return the list of federation registrations\r
-                       if (allowAdmin) {\r
-                               result = gitblit.getFederationRegistrations();\r
-                       } else {\r
-                               response.sendError(notAllowedCode);\r
-                       }\r
-               } else if (RpcRequest.LIST_FEDERATION_RESULTS.equals(reqType)) {\r
-                       // return the list of federation result registrations\r
-                       if (allowAdmin && gitblit.canFederate()) {\r
-                               result = gitblit.getFederationResultRegistrations();\r
-                       } else {\r
-                               response.sendError(notAllowedCode);\r
-                       }\r
-               } else if (RpcRequest.LIST_FEDERATION_PROPOSALS.equals(reqType)) {\r
-                       // return the list of federation proposals\r
-                       if (allowAdmin && gitblit.canFederate()) {\r
-                               result = gitblit.getPendingFederationProposals();\r
-                       } else {\r
-                               response.sendError(notAllowedCode);\r
-                       }\r
-               } else if (RpcRequest.LIST_FEDERATION_SETS.equals(reqType)) {\r
-                       // return the list of federation sets\r
-                       if (allowAdmin && gitblit.canFederate()) {\r
-                               String gitblitUrl = settings.getString(Keys.web.canonicalUrl, null);\r
-                               if (StringUtils.isEmpty(gitblitUrl)) {\r
-                                       gitblitUrl = HttpUtils.getGitblitURL(request);\r
-                               }\r
-                               result = gitblit.getFederationSets(gitblitUrl);\r
-                       } else {\r
-                               response.sendError(notAllowedCode);\r
-                       }\r
-               } else if (RpcRequest.LIST_SETTINGS.equals(reqType)) {\r
-                       // return the server's settings\r
-                       ServerSettings serverSettings = gitblit.getSettingsModel();\r
-                       if (allowAdmin) {\r
-                               // return all settings\r
-                               result = serverSettings;\r
-                       } else {\r
-                               // anonymous users get a few settings to allow browser launching\r
-                               List<String> keys = new ArrayList<String>();\r
-                               keys.add(Keys.web.siteName);\r
-                               keys.add(Keys.web.mountParameters);\r
-                               keys.add(Keys.web.syndicationEntries);\r
+            } catch (GitBlitException e) {\r
+                response.setStatus(failureCode);\r
+            }\r
+        } else if (RpcRequest.EDIT_REPOSITORY.equals(reqType)) {\r
+            // edit repository\r
+            RepositoryModel model = deserialize(request, response, RepositoryModel.class);\r
+            // name specifies original repository name in event of rename\r
+            String repoName = objectName;\r
+            if (repoName == null) {\r
+                repoName = model.name;\r
+            }\r
+            try {\r
+                gitblit.updateRepositoryModel(repoName, model, false);\r
+            } catch (GitBlitException e) {\r
+                response.setStatus(failureCode);\r
+            }\r
+        } else if (RpcRequest.DELETE_REPOSITORY.equals(reqType)) {\r
+            // delete repository\r
+            RepositoryModel model = deserialize(request, response, RepositoryModel.class);\r
+            gitblit.deleteRepositoryModel(model);\r
+        } else if (RpcRequest.CREATE_USER.equals(reqType)) {\r
+            // create user\r
+            UserModel model = deserialize(request, response, UserModel.class);\r
+            try {\r
+                gitblit.addUser(model);\r
+            } catch (GitBlitException e) {\r
+                response.setStatus(failureCode);\r
+            }\r
+        } else if (RpcRequest.EDIT_USER.equals(reqType)) {\r
+            // edit user\r
+            UserModel model = deserialize(request, response, UserModel.class);\r
+            // name parameter specifies original user name in event of rename\r
+            String username = objectName;\r
+            if (username == null) {\r
+                username = model.username;\r
+            }\r
+            try {\r
+                gitblit.reviseUser(username, model);\r
+            } catch (GitBlitException e) {\r
+                response.setStatus(failureCode);\r
+            }\r
+        } else if (RpcRequest.DELETE_USER.equals(reqType)) {\r
+            // delete user\r
+            UserModel model = deserialize(request, response, UserModel.class);\r
+            if (!gitblit.deleteUser(model.username)) {\r
+                response.setStatus(failureCode);\r
+            }\r
+        } else if (RpcRequest.CREATE_TEAM.equals(reqType)) {\r
+            // create team\r
+            TeamModel model = deserialize(request, response, TeamModel.class);\r
+            try {\r
+                gitblit.addTeam(model);\r
+            } catch (GitBlitException e) {\r
+                response.setStatus(failureCode);\r
+            }\r
+        } else if (RpcRequest.EDIT_TEAM.equals(reqType)) {\r
+            // edit team\r
+            TeamModel model = deserialize(request, response, TeamModel.class);\r
+            // name parameter specifies original team name in event of rename\r
+            String teamname = objectName;\r
+            if (teamname == null) {\r
+                teamname = model.name;\r
+            }\r
+            try {\r
+                gitblit.reviseTeam(teamname, model);\r
+            } catch (GitBlitException e) {\r
+                response.setStatus(failureCode);\r
+            }\r
+        } else if (RpcRequest.DELETE_TEAM.equals(reqType)) {\r
+            // delete team\r
+            TeamModel model = deserialize(request, response, TeamModel.class);\r
+            if (!gitblit.deleteTeam(model.name)) {\r
+                response.setStatus(failureCode);\r
+            }\r
+        } else if (RpcRequest.LIST_REPOSITORY_MEMBERS.equals(reqType)) {\r
+            // get repository members\r
+            RepositoryModel model = gitblit.getRepositoryModel(objectName);\r
+            result = gitblit.getRepositoryUsers(model);\r
+        } else if (RpcRequest.SET_REPOSITORY_MEMBERS.equals(reqType)) {\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.getRepositoryModel(objectName);\r
+            result = gitblit.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.getRepositoryModel(objectName);\r
+            Collection<RegistrantAccessPermission> permissions = deserialize(request, response, RpcUtils.REGISTRANT_PERMISSIONS_TYPE);\r
+            result = gitblit.setUserAccessPermissions(model, permissions);\r
+        } else if (RpcRequest.LIST_REPOSITORY_TEAMS.equals(reqType)) {\r
+            // get repository teams\r
+            RepositoryModel model = gitblit.getRepositoryModel(objectName);\r
+            result = gitblit.getRepositoryTeams(model);\r
+        } else if (RpcRequest.SET_REPOSITORY_TEAMS.equals(reqType)) {\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.getRepositoryModel(objectName);\r
+            result = gitblit.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.getRepositoryModel(objectName);\r
+            Collection<RegistrantAccessPermission> permissions = deserialize(request, response, RpcUtils.REGISTRANT_PERMISSIONS_TYPE);\r
+            result = gitblit.setTeamAccessPermissions(model, permissions);\r
+        } else if (RpcRequest.LIST_FEDERATION_REGISTRATIONS.equals(reqType)) {\r
+            // return the list of federation registrations\r
+            if (allowAdmin) {\r
+                result = gitblit.getFederationRegistrations();\r
+            } else {\r
+                response.sendError(notAllowedCode);\r
+            }\r
+        } else if (RpcRequest.LIST_FEDERATION_RESULTS.equals(reqType)) {\r
+            // return the list of federation result registrations\r
+            if (allowAdmin && gitblit.canFederate()) {\r
+                result = gitblit.getFederationResultRegistrations();\r
+            } else {\r
+                response.sendError(notAllowedCode);\r
+            }\r
+        } else if (RpcRequest.LIST_FEDERATION_PROPOSALS.equals(reqType)) {\r
+            // return the list of federation proposals\r
+            if (allowAdmin && gitblit.canFederate()) {\r
+                result = gitblit.getPendingFederationProposals();\r
+            } else {\r
+                response.sendError(notAllowedCode);\r
+            }\r
+        } else if (RpcRequest.LIST_FEDERATION_SETS.equals(reqType)) {\r
+            // return the list of federation sets\r
+            if (allowAdmin && gitblit.canFederate()) {\r
+                String gitblitUrl = settings.getString(Keys.web.canonicalUrl, null);\r
+                if (StringUtils.isEmpty(gitblitUrl)) {\r
+                    gitblitUrl = HttpUtils.getGitblitURL(request);\r
+                }\r
+                result = gitblit.getFederationSets(gitblitUrl);\r
+            } else {\r
+                response.sendError(notAllowedCode);\r
+            }\r
+        } else if (RpcRequest.LIST_SETTINGS.equals(reqType)) {\r
+            // return the server's settings\r
+            ServerSettings serverSettings = gitblit.getSettingsModel();\r
+            if (allowAdmin) {\r
+                // return all settings\r
+                result = serverSettings;\r
+            } else {\r
+                // anonymous users get a few settings to allow browser launching\r
+                List<String> keys = new ArrayList<String>();\r
+                keys.add(Keys.web.siteName);\r
+                keys.add(Keys.web.mountParameters);\r
+                keys.add(Keys.web.syndicationEntries);\r
 \r
-                               if (allowManagement) {\r
-                                       // keys necessary for repository and/or user management\r
-                                       keys.add(Keys.realm.minPasswordLength);\r
-                                       keys.add(Keys.realm.passwordStorage);\r
-                                       keys.add(Keys.federation.sets);\r
-                               }\r
-                               // build the settings\r
-                               ServerSettings managementSettings = new ServerSettings();\r
-                               for (String key : keys) {\r
-                                       managementSettings.add(serverSettings.get(key));\r
-                               }\r
-                               if (allowManagement) {\r
-                                       managementSettings.pushScripts = serverSettings.pushScripts;\r
-                               }\r
-                               result = managementSettings;\r
-                       }\r
-               } else if (RpcRequest.EDIT_SETTINGS.equals(reqType)) {\r
-                       // update settings on the server\r
-                       if (allowAdmin) {\r
-                               Map<String, String> map = deserialize(request, response,\r
-                                               RpcUtils.SETTINGS_TYPE);\r
-                               gitblit.updateSettings(map);\r
-                       } else {\r
-                               response.sendError(notAllowedCode);\r
-                       }\r
-               } else if (RpcRequest.LIST_STATUS.equals(reqType)) {\r
-                       // return the server's status information\r
-                       if (allowAdmin) {\r
-                               result = gitblit.getStatus();\r
-                       } else {\r
-                               response.sendError(notAllowedCode);\r
-                       }\r
-               } else if (RpcRequest.CLEAR_REPOSITORY_CACHE.equals(reqType)) {\r
-                       // clear the repository list cache\r
-                       if (allowManagement) {\r
-                               gitblit.resetRepositoryListCache();\r
-                       } else {\r
-                               response.sendError(notAllowedCode);\r
-                       }\r
-               } else if (RpcRequest.REINDEX_TICKETS.equals(reqType)) {\r
-                       if (allowManagement) {\r
-                               if (StringUtils.isEmpty(objectName)) {\r
-                                       // reindex all tickets\r
-                                       gitblit.getTicketService().reindex();\r
-                               } else {\r
-                                       // reindex tickets in a specific repository\r
-                                       RepositoryModel model = gitblit.getRepositoryModel(objectName);\r
-                                       gitblit.getTicketService().reindex(model);\r
-                               }\r
-                       } else {\r
-                               response.sendError(notAllowedCode);\r
-                       }\r
-               }\r
+                if (allowManagement) {\r
+                    // keys necessary for repository and/or user management\r
+                    keys.add(Keys.realm.minPasswordLength);\r
+                    keys.add(Keys.realm.passwordStorage);\r
+                    keys.add(Keys.federation.sets);\r
+                }\r
+                // build the settings\r
+                ServerSettings managementSettings = new ServerSettings();\r
+                for (String key : keys) {\r
+                    managementSettings.add(serverSettings.get(key));\r
+                }\r
+                if (allowManagement) {\r
+                    managementSettings.pushScripts = serverSettings.pushScripts;\r
+                }\r
+                result = managementSettings;\r
+            }\r
+        } else if (RpcRequest.EDIT_SETTINGS.equals(reqType)) {\r
+            // update settings on the server\r
+            if (allowAdmin) {\r
+                Map<String, String> map = deserialize(request, response,\r
+                        RpcUtils.SETTINGS_TYPE);\r
+                gitblit.updateSettings(map);\r
+            } else {\r
+                response.sendError(notAllowedCode);\r
+            }\r
+        } else if (RpcRequest.LIST_STATUS.equals(reqType)) {\r
+            // return the server's status information\r
+            if (allowAdmin) {\r
+                result = gitblit.getStatus();\r
+            } else {\r
+                response.sendError(notAllowedCode);\r
+            }\r
+        } else if (RpcRequest.CLEAR_REPOSITORY_CACHE.equals(reqType)) {\r
+            // clear the repository list cache\r
+            if (allowManagement) {\r
+                gitblit.resetRepositoryListCache();\r
+            } else {\r
+                response.sendError(notAllowedCode);\r
+            }\r
+        } else if (RpcRequest.REINDEX_TICKETS.equals(reqType)) {\r
+            if (allowManagement) {\r
+                if (StringUtils.isEmpty(objectName)) {\r
+                    // reindex all tickets\r
+                    gitblit.getTicketService().reindex();\r
+                } else {\r
+                    // reindex tickets in a specific repository\r
+                    RepositoryModel model = gitblit.getRepositoryModel(objectName);\r
+                    gitblit.getTicketService().reindex(model);\r
+                }\r
+            } else {\r
+                response.sendError(notAllowedCode);\r
+            }\r
+        }\r
 \r
-               // send the result of the request\r
-               serialize(response, result);\r
-       }\r
+        // send the result of the request\r
+        serialize(response, result);\r
+    }\r
 }\r
index 5e577fb68f6853eda35047ce7ab37efb48a44481..904461c81801c5e5af447d0dc74999de6c440fdb 100644 (file)
@@ -25,16 +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.FederationModel;\r
-import com.gitblit.models.FederationProposal;\r
-import com.gitblit.models.FederationSet;\r
-import com.gitblit.models.FeedModel;\r
-import com.gitblit.models.RegistrantAccessPermission;\r
-import com.gitblit.models.RepositoryModel;\r
-import com.gitblit.models.ServerSettings;\r
-import com.gitblit.models.ServerStatus;\r
-import com.gitblit.models.TeamModel;\r
-import com.gitblit.models.UserModel;\r
+import com.gitblit.models.*;\r
 import com.google.gson.reflect.TypeToken;\r
 \r
 /**\r
@@ -203,7 +194,25 @@ public class RpcUtils {
 \r
        }\r
 \r
-       /**\r
+    /**\r
+     * Create a fork of an already existing repo\r
+     *\r
+     * @param repository\r
+     * @param user\r
+\r
+     * @return true if the action succeeded\r
+     * @throws IOException\r
+     */\r
+    public static boolean forkRpository(RepositoryModel repository, UserModel user, String serverUrl,\r
+                                        String account, char[] password) throws IOException {\r
+        UserRepositoryCompositeModel userRepositoryCompositeModel = new UserRepositoryCompositeModel();\r
+        userRepositoryCompositeModel.setRepositoryModel(repository);\r
+        userRepositoryCompositeModel.setUserModel(user);\r
+        return doAction(RpcRequest.FORK_REPOSITORY, null, userRepositoryCompositeModel, serverUrl, account, password);\r
+    }\r
+\r
+\r
+    /**\r
         * Send a revised version of the repository model to the Gitblit server.\r
         *\r
         * @param repository\r
index 1d01f8460db66ab09c7c396d3544029dfc7e931d..4e00903b17c586e8d6b5f43136a509f019d318b2 100644 (file)
@@ -6,7 +6,6 @@
        role = "#notfederated"
 [user "sampleuser"]
        password = sampleuser
-       cookie = 6e07ed42149fc166206319faffdfba2e2ec82e43
        accountType = LOCAL
        role = "#none"
 [team "admins"]
index ced1a130c57627466ff16cd43c43d2fec8e4453d..943153ded5649d058a2ef86931d430d476f521f7 100644 (file)
@@ -191,6 +191,12 @@ public class RpcTests extends GitblitUnitTest {
                assertEquals(AccessRestrictionType.VIEW, retrievedRepository.accessRestriction);\r
                assertEquals(AuthorizationControl.AUTHENTICATED, retrievedRepository.authorizationControl);\r
 \r
+        //fork repo\r
+        UserModel userModel = new UserModel("garbageUser");\r
+        assertTrue("Failed to create Fork Repository!",\r
+                RpcUtils.forkRpository(model, userModel, url, account, password.toCharArray()));\r
+\r
+\r
                // rename and change access restriciton\r
                String originalName = model.name;\r
                model.name = "garbagerepo2.git";\r
diff --git a/src/test/java/com/gitblit/tests/Test.java b/src/test/java/com/gitblit/tests/Test.java
new file mode 100644 (file)
index 0000000..275c6b4
--- /dev/null
@@ -0,0 +1,11 @@
+package com.gitblit.tests;
+
+/**
+ * Created with IntelliJ IDEA.
+ * User: manisha
+ * Date: 3/21/14
+ * Time: 12:03 PM
+ * To change this template use File | Settings | File Templates.
+ */
+public @interface Test {
+}