use of com.gitblit.models.RepositoryModel in project gitblit by gitblit.
the class RepositoriesPanel method editRepository.
/**
* Displays the edit repository dialog and fires a SwingWorker to update the
* server, if appropriate.
*
* @param repository
*/
protected void editRepository(final RepositoryModel repository) {
EditRepositoryDialog dialog = new EditRepositoryDialog(gitblit.getProtocolVersion(), repository);
dialog.setLocationRelativeTo(RepositoriesPanel.this);
List<String> usernames = gitblit.getUsernames();
List<RegistrantAccessPermission> members = gitblit.getUserAccessPermissions(repository);
dialog.setUsers(new ArrayList<String>(repository.owners), usernames, members);
dialog.setTeams(gitblit.getTeamnames(), gitblit.getTeamAccessPermissions(repository));
dialog.setRepositories(gitblit.getRepositories());
dialog.setFederationSets(gitblit.getFederationSets(), repository.federationSets);
List<String> allLocalBranches = new ArrayList<String>();
allLocalBranches.add(Constants.DEFAULT_BRANCH);
allLocalBranches.addAll(repository.getLocalBranches());
dialog.setIndexedBranches(allLocalBranches, repository.indexedBranches);
dialog.setPreReceiveScripts(gitblit.getPreReceiveScriptsUnused(repository), gitblit.getPreReceiveScriptsInherited(repository), repository.preReceiveScripts);
dialog.setPostReceiveScripts(gitblit.getPostReceiveScriptsUnused(repository), gitblit.getPostReceiveScriptsInherited(repository), repository.postReceiveScripts);
if (gitblit.getSettings().hasKey(Keys.groovy.customFields)) {
Map<String, String> map = gitblit.getSettings().get(Keys.groovy.customFields).getMap();
dialog.setCustomFields(repository, map);
}
dialog.setVisible(true);
final RepositoryModel revisedRepository = dialog.getRepository();
final List<RegistrantAccessPermission> permittedUsers = dialog.getUserAccessPermissions();
final List<RegistrantAccessPermission> permittedTeams = dialog.getTeamAccessPermissions();
if (revisedRepository == null) {
return;
}
GitblitWorker worker = new GitblitWorker(this, RpcRequest.EDIT_REPOSITORY) {
@Override
protected Boolean doRequest() throws IOException {
boolean success = gitblit.updateRepository(repository.name, revisedRepository, permittedUsers, permittedTeams);
if (success) {
gitblit.refreshRepositories();
gitblit.refreshUsers();
gitblit.refreshTeams();
}
return success;
}
@Override
protected void onSuccess() {
updateTable(false);
updateUsersTable();
updateTeamsTable();
}
@Override
protected void onFailure() {
showFailure("Failed to execute request \"{0}\" for repository \"{1}\".", getRequestType(), repository.name);
}
};
worker.execute();
}
use of com.gitblit.models.RepositoryModel in project gitblit by gitblit.
the class RepositoriesPanel method getSelectedRepositories.
private List<RepositoryModel> getSelectedRepositories() {
List<RepositoryModel> repositories = new ArrayList<RepositoryModel>();
for (int viewRow : table.getSelectedRows()) {
int modelRow = table.convertRowIndexToModel(viewRow);
RepositoryModel model = tableModel.list.get(modelRow);
repositories.add(model);
}
return repositories;
}
use of com.gitblit.models.RepositoryModel in project gitblit by gitblit.
the class EditUserDialog method setRepositories.
public void setRepositories(List<RepositoryModel> repositories, List<RegistrantAccessPermission> permissions) {
Map<String, RepositoryModel> repoMap = new HashMap<String, RepositoryModel>();
List<String> restricted = new ArrayList<String>();
for (RepositoryModel repo : repositories) {
// exclude Owner or personal repositories
if (!repo.isOwner(username) && !repo.isUsersPersonalRepository(username)) {
if (repo.accessRestriction.exceeds(AccessRestrictionType.NONE) && repo.authorizationControl.equals(AuthorizationControl.NAMED)) {
restricted.add(repo.name);
}
}
repoMap.put(repo.name.toLowerCase(), repo);
}
StringUtils.sortRepositorynames(restricted);
List<String> list = new ArrayList<String>();
// repositories
list.add(".*");
String prefix;
if (settings.hasKey(Keys.git.userRepositoryPrefix)) {
prefix = settings.get(Keys.git.userRepositoryPrefix).currentValue;
if (StringUtils.isEmpty(prefix)) {
prefix = Constants.DEFAULT_USER_REPOSITORY_PREFIX;
}
} else {
prefix = Constants.DEFAULT_USER_REPOSITORY_PREFIX;
}
if (prefix.length() == 1) {
// all repositories excluding personal repositories
list.add("[^" + prefix + "].*");
}
String lastProject = null;
for (String repo : restricted) {
String projectPath = StringUtils.getFirstPathElement(repo).toLowerCase();
if (lastProject == null || !lastProject.equalsIgnoreCase(projectPath)) {
lastProject = projectPath;
if (!StringUtils.isEmpty(projectPath)) {
// regex for all repositories within a project
list.add(projectPath + "/.*");
}
}
list.add(repo);
}
// remove repositories for which user already has a permission
if (permissions == null) {
permissions = new ArrayList<RegistrantAccessPermission>();
} else {
for (RegistrantAccessPermission rp : permissions) {
list.remove(rp.registrant.toLowerCase());
}
}
// update owner and missing permissions for editing
for (RegistrantAccessPermission permission : permissions) {
if (permission.mutable && PermissionType.EXPLICIT.equals(permission.permissionType)) {
// Ensure this is NOT an owner permission - which is non-editable
// We don't know this from within the usermodel, ownership is a
// property of a repository.
RepositoryModel rm = repoMap.get(permission.registrant.toLowerCase());
if (rm == null) {
permission.permissionType = PermissionType.MISSING;
permission.mutable = false;
continue;
}
boolean isOwner = rm.isOwner(username);
if (isOwner) {
permission.permissionType = PermissionType.OWNER;
permission.mutable = false;
}
}
}
repositoryPalette.setObjects(list, permissions);
}
use of com.gitblit.models.RepositoryModel in project gitblit by gitblit.
the class GitblitClient method getUserAccessPermissions.
/**
* Returns the effective list of permissions for this user, taking into account
* team memberships, ownerships.
*
* @param user
* @return the effective list of permissions for the user
*/
public List<RegistrantAccessPermission> getUserAccessPermissions(UserModel user) {
Set<RegistrantAccessPermission> set = new LinkedHashSet<RegistrantAccessPermission>();
set.addAll(user.getRepositoryPermissions());
// Flag missing repositories
for (RegistrantAccessPermission permission : set) {
if (permission.mutable && PermissionType.EXPLICIT.equals(permission.permissionType)) {
RepositoryModel rm = getRepository(permission.registrant);
if (rm == null) {
permission.permissionType = PermissionType.MISSING;
permission.mutable = false;
continue;
}
}
}
// manually specify personal repository ownerships
for (RepositoryModel rm : allRepositories) {
if (rm.isUsersPersonalRepository(user.username) || rm.isOwner(user.username)) {
RegistrantAccessPermission rp = new RegistrantAccessPermission(rm.name, AccessPermission.REWIND, PermissionType.OWNER, RegistrantType.REPOSITORY, null, false);
// user may be owner of a repository to which they've inherited
// a team permission, replace any existing perm with owner perm
set.remove(rp);
set.add(rp);
}
}
List<RegistrantAccessPermission> list = new ArrayList<RegistrantAccessPermission>(set);
Collections.sort(list);
return list;
}
use of com.gitblit.models.RepositoryModel in project gitblit by gitblit.
the class IndicatorsRenderer method getTableCellRendererComponent.
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
if (isSelected)
setBackground(table.getSelectionBackground());
else
setBackground(table.getBackground());
removeAll();
if (value instanceof RepositoryModel) {
StringBuilder tooltip = new StringBuilder();
RepositoryModel model = (RepositoryModel) value;
if (model.isSparkleshared()) {
JLabel icon = new JLabel(sparkleshareIcon);
tooltip.append(Translation.get("gb.isSparkleshared")).append("<br/>");
add(icon);
}
if (model.isMirror) {
JLabel icon = new JLabel(mirrorIcon);
tooltip.append(Translation.get("gb.isMirror")).append("<br/>");
add(icon);
}
if (model.isFork()) {
JLabel icon = new JLabel(forkIcon);
tooltip.append(Translation.get("gb.isFork")).append("<br/>");
add(icon);
}
if (model.isFrozen) {
JLabel icon = new JLabel(frozenIcon);
tooltip.append(Translation.get("gb.isFrozen")).append("<br/>");
add(icon);
}
if (model.isFederated) {
JLabel icon = new JLabel(federatedIcon);
tooltip.append(Translation.get("gb.isFederated")).append("<br/>");
add(icon);
}
switch(model.accessRestriction) {
case NONE:
{
add(new JLabel(blankIcon));
break;
}
case PUSH:
{
JLabel icon = new JLabel(pushIcon);
tooltip.append(Translation.get("gb.pushRestricted")).append("<br/>");
add(icon);
break;
}
case CLONE:
{
JLabel icon = new JLabel(pullIcon);
tooltip.append(Translation.get("gb.cloneRestricted")).append("<br/>");
add(icon);
break;
}
case VIEW:
{
JLabel icon = new JLabel(viewIcon);
tooltip.append(Translation.get("gb.viewRestricted")).append("<br/>");
add(icon);
break;
}
default:
add(new JLabel(blankIcon));
}
if (tooltip.length() > 0) {
tooltip.insert(0, "<html><body>");
setToolTipText(tooltip.toString().trim());
}
}
return this;
}
Aggregations