use of com.gitblit.models.TeamModel in project gitblit by gitblit.
the class BasePage method getProjects.
protected List<ProjectModel> getProjects(PageParameters params) {
if (params == null) {
return getProjectModels();
}
boolean hasParameter = false;
String regex = WicketUtils.getRegEx(params);
String team = WicketUtils.getTeam(params);
int daysBack = params.getInt("db", 0);
int maxDaysBack = app().settings().getInteger(Keys.web.activityDurationMaximum, 30);
List<ProjectModel> availableModels = getProjectModels();
Set<ProjectModel> models = new HashSet<ProjectModel>();
if (!StringUtils.isEmpty(regex)) {
// filter the projects by the regex
hasParameter = true;
Pattern pattern = Pattern.compile(regex);
for (ProjectModel model : availableModels) {
if (pattern.matcher(model.name).find()) {
models.add(model);
}
}
}
if (!StringUtils.isEmpty(team)) {
// filter the projects by the specified teams
hasParameter = true;
List<String> teams = StringUtils.getStringsFromValue(team, ",");
// need TeamModels first
List<TeamModel> teamModels = new ArrayList<TeamModel>();
for (String name : teams) {
TeamModel teamModel = app().users().getTeamModel(name);
if (teamModel != null) {
teamModels.add(teamModel);
}
}
// brute-force our way through finding the matching models
for (ProjectModel projectModel : availableModels) {
for (String repositoryName : projectModel.repositories) {
for (TeamModel teamModel : teamModels) {
if (teamModel.hasRepositoryPermission(repositoryName)) {
models.add(projectModel);
}
}
}
}
}
if (!hasParameter) {
models.addAll(availableModels);
}
// time-filter the list
if (daysBack > 0) {
if (maxDaysBack > 0 && daysBack > maxDaysBack) {
daysBack = maxDaysBack;
}
Calendar cal = Calendar.getInstance();
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
cal.add(Calendar.DATE, -1 * daysBack);
Date threshold = cal.getTime();
Set<ProjectModel> timeFiltered = new HashSet<ProjectModel>();
for (ProjectModel model : models) {
if (model.lastChange.after(threshold)) {
timeFiltered.add(model);
}
}
models = timeFiltered;
}
List<ProjectModel> list = new ArrayList<ProjectModel>(models);
Collections.sort(list);
return list;
}
use of com.gitblit.models.TeamModel in project gitblit by gitblit.
the class TeamsPanel method editTeam.
/**
* Displays the edit team dialog and fires a SwingWorker to update the
* server, if appropriate.
*
* @param user
*/
protected void editTeam(final TeamModel team) {
EditTeamDialog dialog = new EditTeamDialog(gitblit.getProtocolVersion(), team, gitblit.getSettings());
dialog.setLocationRelativeTo(TeamsPanel.this);
dialog.setTeams(gitblit.getTeams());
dialog.setRepositories(gitblit.getRepositories(), team.getRepositoryPermissions());
dialog.setUsers(gitblit.getUsernames(), team.users == null ? null : new ArrayList<String>(team.users));
dialog.setPreReceiveScripts(gitblit.getPreReceiveScriptsUnused(null), gitblit.getPreReceiveScriptsInherited(null), team.preReceiveScripts);
dialog.setPostReceiveScripts(gitblit.getPostReceiveScriptsUnused(null), gitblit.getPostReceiveScriptsInherited(null), team.postReceiveScripts);
dialog.setVisible(true);
final TeamModel revisedTeam = dialog.getTeam();
if (revisedTeam == null) {
return;
}
GitblitWorker worker = new GitblitWorker(this, RpcRequest.EDIT_TEAM) {
@Override
protected Boolean doRequest() throws IOException {
boolean success = gitblit.updateTeam(team.name, revisedTeam);
if (success) {
gitblit.refreshTeams();
gitblit.refreshUsers();
}
return success;
}
@Override
protected void onSuccess() {
updateTable(false);
updateUsersTable();
}
@Override
protected void onFailure() {
showFailure("Failed to execute request \"{0}\" for team \"{1}\".", getRequestType(), team.name);
}
};
worker.execute();
}
use of com.gitblit.models.TeamModel in project gitblit by gitblit.
the class TeamsPanel method deleteTeams.
protected void deleteTeams(final List<TeamModel> teams) {
if (teams == null || teams.size() == 0) {
return;
}
StringBuilder message = new StringBuilder("Delete the following teams?\n\n");
for (TeamModel team : teams) {
message.append(team.name).append("\n");
}
int result = JOptionPane.showConfirmDialog(TeamsPanel.this, message.toString(), "Delete Teams?", JOptionPane.YES_NO_OPTION);
if (result == JOptionPane.YES_OPTION) {
GitblitWorker worker = new GitblitWorker(this, RpcRequest.DELETE_TEAM) {
@Override
protected Boolean doRequest() throws IOException {
boolean success = true;
for (TeamModel team : teams) {
success &= gitblit.deleteTeam(team);
}
if (success) {
gitblit.refreshTeams();
gitblit.refreshUsers();
}
return success;
}
@Override
protected void onSuccess() {
updateTable(false);
updateUsersTable();
}
@Override
protected void onFailure() {
showFailure("Failed to delete specified teams!");
}
};
worker.execute();
}
}
use of com.gitblit.models.TeamModel in project gitblit by gitblit.
the class GitblitClient method getTeamAccessPermissions.
public List<RegistrantAccessPermission> getTeamAccessPermissions(RepositoryModel repository) {
List<RegistrantAccessPermission> list = new ArrayList<RegistrantAccessPermission>();
for (TeamModel team : allTeams) {
RegistrantAccessPermission ap = team.getRepositoryPermission(repository);
if (ap.permission.exceeds(AccessPermission.NONE)) {
list.add(ap);
}
}
Collections.sort(list);
return list;
}
use of com.gitblit.models.TeamModel in project gitblit by gitblit.
the class FederationServlet method processRequest.
/**
* Processes a federation request.
*
* @param request
* @param response
* @throws javax.servlet.ServletException
* @throws java.io.IOException
*/
@Override
protected void processRequest(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, java.io.IOException {
FederationRequest reqType = FederationRequest.fromName(request.getParameter("req"));
logger.info(MessageFormat.format("Federation {0} request from {1}", reqType, request.getRemoteAddr()));
if (FederationRequest.POKE.equals(reqType)) {
// Gitblit always responds to POKE requests to verify a connection
logger.info("Received federation POKE from " + request.getRemoteAddr());
return;
}
if (!settings.getBoolean(Keys.git.enableGitServlet, true)) {
logger.warn(Keys.git.enableGitServlet + " must be set TRUE for federation requests.");
response.sendError(HttpServletResponse.SC_FORBIDDEN);
return;
}
String uuid = settings.getString(Keys.federation.passphrase, "");
if (StringUtils.isEmpty(uuid)) {
logger.warn(Keys.federation.passphrase + " is not properly set! Federation request denied.");
response.sendError(HttpServletResponse.SC_FORBIDDEN);
return;
}
if (FederationRequest.PROPOSAL.equals(reqType)) {
// Receive a gitblit federation proposal
FederationProposal proposal = deserialize(request, response, FederationProposal.class);
if (proposal == null) {
return;
}
// reject proposal, if not receipt prohibited
if (!settings.getBoolean(Keys.federation.allowProposals, false)) {
logger.error(MessageFormat.format("Rejected {0} federation proposal from {1}", proposal.tokenType.name(), proposal.url));
response.setStatus(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
return;
}
// poke the origin Gitblit instance that is proposing federation
boolean poked = false;
try {
poked = FederationUtils.poke(proposal.url);
} catch (Exception e) {
logger.error("Failed to poke origin", e);
}
if (!poked) {
logger.error(MessageFormat.format("Failed to send federation poke to {0}", proposal.url));
response.setStatus(HttpServletResponse.SC_NOT_ACCEPTABLE);
return;
}
String gitblitUrl = settings.getString(Keys.web.canonicalUrl, null);
if (StringUtils.isEmpty(gitblitUrl)) {
gitblitUrl = HttpUtils.getGitblitURL(request);
}
federationManager.submitFederationProposal(proposal, gitblitUrl);
logger.info(MessageFormat.format("Submitted {0} federation proposal to pull {1} repositories from {2}", proposal.tokenType.name(), proposal.repositories.size(), proposal.url));
response.setStatus(HttpServletResponse.SC_OK);
return;
}
if (FederationRequest.STATUS.equals(reqType)) {
// Receive a gitblit federation status acknowledgment
String remoteId = StringUtils.decodeFromHtml(request.getParameter("url"));
String identification = MessageFormat.format("{0} ({1})", remoteId, request.getRemoteAddr());
// deserialize the status data
FederationModel results = deserialize(request, response, FederationModel.class);
if (results == null) {
return;
}
// setup the last and netx pull dates
results.lastPull = new Date();
int mins = TimeUtils.convertFrequencyToMinutes(results.frequency, 5);
results.nextPull = new Date(System.currentTimeMillis() + (mins * 60 * 1000L));
// acknowledge the receipt of status
federationManager.acknowledgeFederationStatus(identification, results);
logger.info(MessageFormat.format("Received status of {0} federated repositories from {1}", results.getStatusList().size(), identification));
response.setStatus(HttpServletResponse.SC_OK);
return;
}
// Determine the federation tokens for this gitblit instance
String token = request.getParameter("token");
List<String> tokens = federationManager.getFederationTokens();
if (!tokens.contains(token)) {
logger.warn(MessageFormat.format("Received Federation token ''{0}'' does not match the server tokens", token));
response.sendError(HttpServletResponse.SC_FORBIDDEN);
return;
}
Object result = null;
if (FederationRequest.PULL_REPOSITORIES.equals(reqType)) {
String gitblitUrl = settings.getString(Keys.web.canonicalUrl, null);
if (StringUtils.isEmpty(gitblitUrl)) {
gitblitUrl = HttpUtils.getGitblitURL(request);
}
result = federationManager.getRepositories(gitblitUrl, token);
} else {
if (FederationRequest.PULL_SETTINGS.equals(reqType)) {
// pull settings
if (!federationManager.validateFederationRequest(reqType, token)) {
// invalid token to pull users or settings
logger.warn(MessageFormat.format("Federation token from {0} not authorized to pull SETTINGS", request.getRemoteAddr()));
response.sendError(HttpServletResponse.SC_FORBIDDEN);
return;
}
Map<String, String> map = new HashMap<String, String>();
List<String> keys = settings.getAllKeys(null);
for (String key : keys) {
map.put(key, settings.getString(key, ""));
}
result = map;
} else if (FederationRequest.PULL_USERS.equals(reqType)) {
// pull users
if (!federationManager.validateFederationRequest(reqType, token)) {
// invalid token to pull users or settings
logger.warn(MessageFormat.format("Federation token from {0} not authorized to pull USERS", request.getRemoteAddr()));
response.sendError(HttpServletResponse.SC_FORBIDDEN);
return;
}
List<String> usernames = userManager.getAllUsernames();
List<UserModel> users = new ArrayList<UserModel>();
for (String username : usernames) {
UserModel user = userManager.getUserModel(username);
if (!user.excludeFromFederation) {
users.add(user);
}
}
result = users;
} else if (FederationRequest.PULL_TEAMS.equals(reqType)) {
// pull teams
if (!federationManager.validateFederationRequest(reqType, token)) {
// invalid token to pull teams
logger.warn(MessageFormat.format("Federation token from {0} not authorized to pull TEAMS", request.getRemoteAddr()));
response.sendError(HttpServletResponse.SC_FORBIDDEN);
return;
}
List<String> teamnames = userManager.getAllTeamNames();
List<TeamModel> teams = new ArrayList<TeamModel>();
for (String teamname : teamnames) {
TeamModel user = userManager.getTeamModel(teamname);
teams.add(user);
}
result = teams;
} else if (FederationRequest.PULL_SCRIPTS.equals(reqType)) {
// pull scripts
if (!federationManager.validateFederationRequest(reqType, token)) {
// invalid token to pull script
logger.warn(MessageFormat.format("Federation token from {0} not authorized to pull SCRIPTS", request.getRemoteAddr()));
response.sendError(HttpServletResponse.SC_FORBIDDEN);
return;
}
Map<String, String> scripts = new HashMap<String, String>();
Set<String> names = new HashSet<String>();
names.addAll(settings.getStrings(Keys.groovy.preReceiveScripts));
names.addAll(settings.getStrings(Keys.groovy.postReceiveScripts));
for (TeamModel team : userManager.getAllTeams()) {
names.addAll(team.preReceiveScripts);
names.addAll(team.postReceiveScripts);
}
File scriptsFolder = repositoryManager.getHooksFolder();
for (String name : names) {
File file = new File(scriptsFolder, name);
if (!file.exists() && !file.getName().endsWith(".groovy")) {
file = new File(scriptsFolder, name + ".groovy");
}
if (file.exists()) {
// read the script
String content = FileUtils.readContent(file, "\n");
scripts.put(name, content);
} else {
// missing script?!
logger.warn(MessageFormat.format("Failed to find push script \"{0}\"", name));
}
}
result = scripts;
}
}
// send the result of the request
serialize(response, result);
}
Aggregations