Implement FORK RPC request type
2 files added
5 files modified
| | |
| | | // 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,
|
New file |
| | |
| | | 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; |
| | | } |
| | | |
| | | } |
| | |
| | | import javax.servlet.http.HttpServletRequest;
|
| | | import javax.servlet.http.HttpServletResponse;
|
| | |
|
| | | import com.gitblit.models.*;
|
| | | import org.eclipse.jgit.lib.Repository;
|
| | |
|
| | | import com.gitblit.Constants;
|
| | |
| | | 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;
|
| | |
| | | * Handles remote procedure calls.
|
| | | *
|
| | | * @author James Moger
|
| | | *
|
| | | */
|
| | | public class RpcServlet extends JsonServlet {
|
| | |
|
| | |
| | | } 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);
|
| | | }
|
| | |
|
| | | } catch (GitBlitException e) {
|
| | | response.setStatus(failureCode);
|
| | | }
|
| | | } else if (RpcRequest.EDIT_REPOSITORY.equals(reqType)) {
|
| | | // edit repository
|
| | | RepositoryModel model = deserialize(request, response, RepositoryModel.class);
|
| | |
| | | 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;
|
| | |
|
| | | /**
|
| | |
| | | }
|
| | |
|
| | | /**
|
| | | * 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
|
| | |
| | | role = "#notfederated" |
| | | [user "sampleuser"] |
| | | password = sampleuser |
| | | cookie = 6e07ed42149fc166206319faffdfba2e2ec82e43 |
| | | accountType = LOCAL |
| | | role = "#none" |
| | | [team "admins"] |
| | |
| | | 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";
|
New file |
| | |
| | | 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 { |
| | | } |