From fa5e6f97aab0faca8e11ab8a264b0190c145b07f Mon Sep 17 00:00:00 2001
From: James Moger <james.moger@gitblit.com>
Date: Fri, 04 Nov 2011 17:25:00 -0400
Subject: [PATCH] Documentation.
---
src/com/gitblit/RpcServlet.java | 39 ++++++++++++++++++++++++++++-----------
1 files changed, 28 insertions(+), 11 deletions(-)
diff --git a/src/com/gitblit/RpcServlet.java b/src/com/gitblit/RpcServlet.java
index b068a39..068562e 100644
--- a/src/com/gitblit/RpcServlet.java
+++ b/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));
--
Gitblit v1.9.1