| | |
| | | logger.info(MessageFormat.format("Rpc {0} request from {1}", reqType,
|
| | | request.getRemoteAddr()));
|
| | |
|
| | | boolean allowAdmin = GitBlit.getBoolean(Keys.web.enableRpcAdministration, false);
|
| | |
|
| | | UserModel user = (UserModel) request.getUserPrincipal();
|
| | |
|
| | | boolean allowManagement = user != null && user.canAdmin
|
| | | && GitBlit.getBoolean(Keys.web.enableRpcManagement, false);
|
| | |
|
| | | boolean allowAdmin = user != null && user.canAdmin
|
| | | && GitBlit.getBoolean(Keys.web.enableRpcAdministration, false);
|
| | |
|
| | | Object result = null;
|
| | | if (RpcRequest.LIST_REPOSITORIES.equals(reqType)) {
|
| | |
| | | }
|
| | | result = repositories;
|
| | | } else if (RpcRequest.LIST_BRANCHES.equals(reqType)) {
|
| | | // list all branches in all repositories accessible to user
|
| | | Map<String, List<String>> allBranches = new HashMap<String, List<String>>();
|
| | | // list all local branches in all repositories accessible to user
|
| | | Map<String, List<String>> localBranches = new HashMap<String, List<String>>();
|
| | | List<RepositoryModel> models = GitBlit.self().getRepositoryModels(user);
|
| | | for (RepositoryModel model : models) {
|
| | | if (!model.hasCommits) {
|
| | | // skip empty repository
|
| | | continue;
|
| | | }
|
| | | // get branches
|
| | | // get local branches
|
| | | Repository repository = GitBlit.self().getRepository(model.name);
|
| | | List<RefModel> refs = JGitUtils.getLocalBranches(repository, false, -1);
|
| | | refs.addAll(JGitUtils.getRemoteBranches(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());
|
| | | }
|
| | | allBranches.put(model.name, branches);
|
| | | localBranches.put(model.name, branches);
|
| | | }
|
| | | repository.close();
|
| | | }
|
| | | result = allBranches;
|
| | | result = localBranches;
|
| | | } else if (RpcRequest.LIST_USERS.equals(reqType)) {
|
| | | // list users
|
| | | List<String> names = GitBlit.self().getAllUsernames();
|
| | |
| | | // return all settings
|
| | | result = settings;
|
| | | } else {
|
| | | // return management settings only
|
| | | String[] keys = { Keys.realm.minPasswordLength, Keys.realm.passwordStorage,
|
| | | Keys.federation.sets };
|
| | | // 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(settings.get(key));
|