@@ -29,6 +29,7 @@ r18: { | |||
- updated Brazilian Portuguese translation | |||
additions: | |||
- Added optional browser-side page caching using Last-Modified and Cache-Control for the dashboard, activity, project, and several repository pages | |||
- Added a GET_USER request type for the RPC mechanism (issue-275) | |||
dependencyChanges: ~ | |||
settings: | |||
- { name: 'web.pageCacheExpires', defaultValue: 0 } | |||
@@ -45,6 +46,7 @@ r18: { | |||
- Rafael Cavazin | |||
- Tamás Papp | |||
- Florian Zschocke | |||
- Amélie Benoit | |||
} | |||
# |
@@ -321,7 +321,7 @@ public class Constants { | |||
public static enum RpcRequest { | |||
// Order is important here. anything above LIST_SETTINGS requires | |||
// administrator privileges and web.allowRpcManagement. | |||
CLEAR_REPOSITORY_CACHE, GET_PROTOCOL, LIST_REPOSITORIES, LIST_BRANCHES, LIST_SETTINGS, | |||
CLEAR_REPOSITORY_CACHE, GET_PROTOCOL, LIST_REPOSITORIES, LIST_BRANCHES, GET_USER, LIST_SETTINGS, | |||
CREATE_REPOSITORY, EDIT_REPOSITORY, DELETE_REPOSITORY, | |||
LIST_USERS, CREATE_USER, EDIT_USER, DELETE_USER, | |||
LIST_TEAMS, CREATE_TEAM, EDIT_TEAM, DELETE_TEAM, |
@@ -36,9 +36,11 @@ 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; | |||
import com.gitblit.utils.RpcUtils; | |||
import com.gitblit.utils.StringUtils; | |||
/** | |||
* Handles remote procedure calls. | |||
@@ -50,7 +52,7 @@ public class RpcServlet extends JsonServlet { | |||
private static final long serialVersionUID = 1L; | |||
public static final int PROTOCOL_VERSION = 5; | |||
public static final int PROTOCOL_VERSION = 6; | |||
public RpcServlet() { | |||
super(); | |||
@@ -132,6 +134,28 @@ public class RpcServlet extends JsonServlet { | |||
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.self().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.self().getAllUsernames(); |
@@ -297,6 +297,24 @@ public class RpcUtils { | |||
char[] password) throws IOException { | |||
return doAction(RpcRequest.DELETE_USER, null, user, serverUrl, account, password); | |||
} | |||
/** | |||
* Tries to get the specified gitblit user account from the remote gitblit instance. | |||
* If the username is null or empty, the current user is returned. | |||
* | |||
* @param username | |||
* @param serverUrl | |||
* @param account | |||
* @param password | |||
* @return a UserModel or null | |||
* @throws IOException | |||
*/ | |||
public static UserModel getUser(String username, String serverUrl, String account, char[] password) | |||
throws IOException { | |||
String url = asLink(serverUrl, RpcRequest.GET_USER); | |||
UserModel model = JsonUtils.retrieveJson(url, UserModel.class, account, password); | |||
return model; | |||
} | |||
/** | |||
* Create a team on the Gitblit server. |
@@ -66,6 +66,7 @@ The Gitblit API includes methods for retrieving and interpreting RSS feeds. The | |||
<tr><td>Gitblit v0.9.0 - v1.0.0</td><td>3</td></tr> | |||
<tr><td>Gitblit v1.1.0</td><td>4</td></tr> | |||
<tr><td>Gitblit v1.2.0+</td><td>5</td></tr> | |||
<tr><td>Gitblit v1.3.1+</td><td>6</td></tr> | |||
</tbody> | |||
</table> | |||
@@ -85,6 +86,7 @@ Use *SET_REPOSITORY_TEAM_PERMISSIONS* instead. | |||
<tr><td>LIST_REPOSITORIES</td><td>-</td><td>-</td><td>1</td><td>-</td><td>Map<String, RepositoryModel></td></tr> | |||
<tr><td>LIST_BRANCHES</td><td>-</td><td>-</td><td>1</td><td>-</td><td>Map<String, List<String>></td></tr> | |||
<tr><td>LIST_SETTINGS</td><td>-</td><td><em>-</em></td><td>1</td><td>-</td><td>ServerSettings (basic keys)</td></tr> | |||
<tr><td>GET_USER</td><td>user name</td><td>-</td><td>6</td><td>-</td><td>UserModel</td></tr> | |||
<tr><td colspan='6'><em>web.enableRpcManagement=true</em></td></tr> | |||
<tr><td>CREATE_REPOSITORY</td><td>repository name</td><td><em>admin</em></td><td>1</td><td>RepositoryModel</td><td>-</td></tr> | |||
<tr><td>EDIT_REPOSITORY</td><td>repository name</td><td><em>admin</em></td><td>1</td><td>RepositoryModel</td><td>-</td></tr> |
@@ -37,6 +37,7 @@ import com.gitblit.Constants.AccessRestrictionType; | |||
import com.gitblit.Constants.AuthorizationControl; | |||
import com.gitblit.Constants.PermissionType; | |||
import com.gitblit.Constants.RegistrantType; | |||
import com.gitblit.GitBlitException.NotAllowedException; | |||
import com.gitblit.GitBlitException.UnauthorizedException; | |||
import com.gitblit.Keys; | |||
import com.gitblit.RpcServlet; | |||
@@ -102,6 +103,20 @@ public class RpcTests { | |||
list = RpcUtils.getUsers(url, "admin", "admin".toCharArray()); | |||
assertTrue("User list is empty!", list.size() > 0); | |||
} | |||
@Test | |||
public void testGetUser() throws IOException { | |||
UserModel user = null; | |||
try { | |||
user = RpcUtils.getUser("admin", url, null, null); | |||
} catch (NotAllowedException e) { | |||
} | |||
assertNull("Server allows anyone to get user!", user); | |||
user = RpcUtils.getUser("admin", url, "admin", "admin".toCharArray()); | |||
assertEquals("User is not the admin!", "admin", user.username); | |||
assertTrue("User is not an administrator!", user.canAdmin()); | |||
} | |||
@Test | |||
public void testListTeams() throws IOException { |