teams.add(gitblit.getTeamModel(name));
}
result = teams;
} else if (RpcRequest.CREATE_REPOSITORY.equals(reqType)) {
// create repository
RepositoryModel model = deserialize(request, response, RepositoryModel.class);
try {
gitblit.updateRepositoryModel(model.name, model, true);
} catch (GitBlitException e) {
response.setStatus(failureCode);
}
} else if (RpcRequest.FORK_REPOSITORY.equals(reqType)) {
// fork repository
RepositoryModel origin = gitblit.getRepositoryModel(objectName);
if (origin == null) {
// failed to find repository, error is logged by the repository
// manager
response.setStatus(failureCode);
} else {
if (user == null || !user.canFork(origin)) {
logger.error("User {} is not permitted to fork '{}'!", user == null ? "anonymous" : user.username,
objectName);
response.setStatus(failureCode);
} else {
try {
// fork the origin
RepositoryModel fork = gitblit.fork(origin, user);
if (fork == null) {
logger.error("Failed to fork repository '{}'!", objectName);
response.setStatus(failureCode);
} else {
logger.info("User {} has forked '{}'!", user.username, objectName);
}
} catch (GitBlitException e) {
response.setStatus(failureCode);
}
}
}
} else if (RpcRequest.EDIT_REPOSITORY.equals(reqType)) {
// edit repository
RepositoryModel model = deserialize(request, response, RepositoryModel.class);
// name specifies original repository name in event of rename
String repoName = objectName;
if (repoName == null) {
repoName = model.name;
}
try {
gitblit.updateRepositoryModel(repoName, model, false);
} catch (GitBlitException e) {
response.setStatus(failureCode);
}
} else if (RpcRequest.DELETE_REPOSITORY.equals(reqType)) {
// delete repository
RepositoryModel model = deserialize(request, response, RepositoryModel.class);
gitblit.deleteRepositoryModel(model);
} else if (RpcRequest.CREATE_USER.equals(reqType)) {
// create user
UserModel model = deserialize(request, response, UserModel.class);
try {
gitblit.addUser(model);
} catch (GitBlitException e) {
response.setStatus(failureCode);
}
} else if (RpcRequest.EDIT_USER.equals(reqType)) {
// edit user
UserModel model = deserialize(request, response, UserModel.class);
// name parameter specifies original user name in event of rename
String username = objectName;
if (username == null) {
username = model.username;
}
try {
gitblit.reviseUser(username, model);
} catch (GitBlitException e) {
response.setStatus(failureCode);
}
} else if (RpcRequest.DELETE_USER.equals(reqType)) {
// delete user
UserModel model = deserialize(request, response, UserModel.class);
if (!gitblit.deleteUser(model.username)) {
response.setStatus(failureCode);
}
} else if (RpcRequest.CREATE_TEAM.equals(reqType)) {
// create team
TeamModel model = deserialize(request, response, TeamModel.class);
try {
gitblit.addTeam(model);
} catch (GitBlitException e) {
response.setStatus(failureCode);
}
} else if (RpcRequest.EDIT_TEAM.equals(reqType)) {
// edit team
TeamModel model = deserialize(request, response, TeamModel.class);
// name parameter specifies original team name in event of rename
String teamname = objectName;
if (teamname == null) {
teamname = model.name;
}
try {
gitblit.reviseTeam(teamname, model);
} catch (GitBlitException e) {
response.setStatus(failureCode);
}
} else if (RpcRequest.DELETE_TEAM.equals(reqType)) {
// delete team
TeamModel model = deserialize(request, response, TeamModel.class);
if (!gitblit.deleteTeam(model.name)) {
response.setStatus(failureCode);
}
} else if (RpcRequest.LIST_REPOSITORY_MEMBERS.equals(reqType)) {
// get repository members
RepositoryModel model = gitblit.getRepositoryModel(objectName);
result = gitblit.getRepositoryUsers(model);
} else if (RpcRequest.SET_REPOSITORY_MEMBERS.equals(reqType)) {
// rejected since 1.2.0
response.setStatus(failureCode);
} else if (RpcRequest.LIST_REPOSITORY_MEMBER_PERMISSIONS.equals(reqType)) {
// get repository member permissions
RepositoryModel model = gitblit.getRepositoryModel(objectName);
result = gitblit.getUserAccessPermissions(model);
} else if (RpcRequest.SET_REPOSITORY_MEMBER_PERMISSIONS.equals(reqType)) {
// set the repository permissions for the specified users
RepositoryModel model = gitblit.getRepositoryModel(objectName);
Collection<RegistrantAccessPermission> permissions = deserialize(request, response,
RpcUtils.REGISTRANT_PERMISSIONS_TYPE);
result = gitblit.setUserAccessPermissions(model, permissions);
} else if (RpcRequest.LIST_REPOSITORY_TEAMS.equals(reqType)) {
// get repository teams
RepositoryModel model = gitblit.getRepositoryModel(objectName);
result = gitblit.getRepositoryTeams(model);
} else if (RpcRequest.SET_REPOSITORY_TEAMS.equals(reqType)) {
// rejected since 1.2.0
response.setStatus(failureCode);
} else if (RpcRequest.LIST_REPOSITORY_TEAM_PERMISSIONS.equals(reqType)) {
// get repository team permissions
RepositoryModel model = gitblit.getRepositoryModel(objectName);
result = gitblit.getTeamAccessPermissions(model);
} else if (RpcRequest.SET_REPOSITORY_TEAM_PERMISSIONS.equals(reqType)) {
// set the repository permissions for the specified teams
RepositoryModel model = gitblit.getRepositoryModel(objectName);
Collection<RegistrantAccessPermission> permissions = deserialize(request, response,
RpcUtils.REGISTRANT_PERMISSIONS_TYPE);
result = gitblit.setTeamAccessPermissions(model, permissions);
} else if (RpcRequest.LIST_FEDERATION_REGISTRATIONS.equals(reqType)) {
// return the list of federation registrations
if (allowAdmin) {
result = gitblit.getFederationRegistrations();
} else {
response.sendError(notAllowedCode);
}
} else if (RpcRequest.LIST_FEDERATION_RESULTS.equals(reqType)) {
// return the list of federation result registrations
if (allowAdmin && gitblit.canFederate()) {
result = gitblit.getFederationResultRegistrations();
} else {
response.sendError(notAllowedCode);
}
} else if (RpcRequest.LIST_FEDERATION_PROPOSALS.equals(reqType)) {
// return the list of federation proposals
if (allowAdmin && gitblit.canFederate()) {
result = gitblit.getPendingFederationProposals();
} else {
response.sendError(notAllowedCode);
}
} else if (RpcRequest.LIST_FEDERATION_SETS.equals(reqType)) {
// return the list of federation sets
if (allowAdmin && gitblit.canFederate()) {
String gitblitUrl = settings.getString(Keys.web.canonicalUrl, null);
if (StringUtils.isEmpty(gitblitUrl)) {
gitblitUrl = HttpUtils.getGitblitURL(request);
}
result = gitblit.getFederationSets(gitblitUrl);
} else {
response.sendError(notAllowedCode);
}
} else if (RpcRequest.LIST_SETTINGS.equals(reqType)) {
// return the server's settings
ServerSettings serverSettings = gitblit.getSettingsModel();
if (allowAdmin) {
// return all settings
result = serverSettings;
} else {
// 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(serverSettings.get(key));
}
if (allowManagement) {
managementSettings.pushScripts = serverSettings.pushScripts;
}
result = managementSettings;
}
} else if (RpcRequest.EDIT_SETTINGS.equals(reqType)) {
// update settings on the server
if (allowAdmin) {
Map<String, String> map = deserialize(request, response, RpcUtils.SETTINGS_TYPE);
gitblit.updateSettings(map);
} else {
response.sendError(notAllowedCode);
}
} else if (RpcRequest.LIST_STATUS.equals(reqType)) {
// return the server's status information
if (allowAdmin) {
result = gitblit.getStatus();
} else {
response.sendError(notAllowedCode);
}
} else if (RpcRequest.CLEAR_REPOSITORY_CACHE.equals(reqType)) {
// clear the repository list cache
if (allowManagement) {
gitblit.resetRepositoryListCache();
} else {
response.sendError(notAllowedCode);
}
} else if (RpcRequest.REINDEX_TICKETS.equals(reqType)) {
if (allowManagement) {
if (StringUtils.isEmpty(objectName)) {
// reindex all tickets
gitblit.getTicketService().reindex();
} else {
// reindex tickets in a specific repository
RepositoryModel model = gitblit.getRepositoryModel(objectName);
gitblit.getTicketService().reindex(model);
}
} else {
response.sendError(notAllowedCode);
}