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