James Moger
2011-11-11 d65f712ea3d8941f4b9145c0630c30c20af80d13
src/com/gitblit/RpcServlet.java
@@ -68,9 +68,13 @@
      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)) {
@@ -91,28 +95,31 @@
         }
         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();
@@ -221,9 +228,19 @@
            // 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));