use of com.gitblit.models.RegistrantAccessPermission 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.RegistrantAccessPermission in project gitblit by gitblit.
the class EditTeamDialog method validateFields.
private boolean validateFields() {
String tname = teamnameField.getText();
if (StringUtils.isEmpty(tname)) {
error("Please enter a team name!");
return false;
}
boolean rename = false;
// verify teamname uniqueness on create
if (isCreate) {
if (teamnames.contains(tname.toLowerCase())) {
error(MessageFormat.format("Team name ''{0}'' is unavailable.", tname));
return false;
}
} else {
// check rename collision
rename = !StringUtils.isEmpty(teamname) && !teamname.equalsIgnoreCase(tname);
if (rename) {
if (teamnames.contains(tname.toLowerCase())) {
error(MessageFormat.format("Failed to rename ''{0}'' because ''{1}'' already exists.", teamname, tname));
return false;
}
}
}
team.name = tname;
team.canAdmin = canAdminCheckbox.isSelected();
team.canFork = canForkCheckbox.isSelected();
team.canCreate = canCreateCheckbox.isSelected();
String ml = mailingListsField.getText();
if (!StringUtils.isEmpty(ml)) {
Set<String> list = new HashSet<String>();
for (String address : ml.split("(,|\\s)")) {
if (StringUtils.isEmpty(address)) {
continue;
}
list.add(address.toLowerCase());
}
team.mailingLists.clear();
team.mailingLists.addAll(list);
}
for (RegistrantAccessPermission rp : repositoryPalette.getPermissions()) {
team.setRepositoryPermission(rp.registrant, rp.permission);
}
team.users.clear();
team.users.addAll(userPalette.getSelections());
team.preReceiveScripts.clear();
team.preReceiveScripts.addAll(preReceivePalette.getSelections());
team.postReceiveScripts.clear();
team.postReceiveScripts.addAll(postReceivePalette.getSelections());
return true;
}
use of com.gitblit.models.RegistrantAccessPermission in project gitblit by gitblit.
the class EditTeamDialog method setRepositories.
public void setRepositories(List<RepositoryModel> repositories, List<RegistrantAccessPermission> permissions) {
List<String> restricted = new ArrayList<String>();
for (RepositoryModel repo : repositories) {
if (repo.accessRestriction.exceeds(AccessRestrictionType.NONE) && repo.authorizationControl.equals(AuthorizationControl.NAMED)) {
restricted.add(repo.name);
}
}
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);
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);
}
}
repositoryPalette.setObjects(list, permissions);
}
use of com.gitblit.models.RegistrantAccessPermission 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.RegistrantAccessPermission in project gitblit by gitblit.
the class RepositoriesPanel method createRepository.
/**
* Displays the create repository dialog and fires a SwingWorker to update
* the server, if appropriate.
*
*/
protected void createRepository() {
EditRepositoryDialog dialog = new EditRepositoryDialog(gitblit.getProtocolVersion());
dialog.setLocationRelativeTo(RepositoriesPanel.this);
dialog.setAccessRestriction(gitblit.getDefaultAccessRestriction());
dialog.setAuthorizationControl(gitblit.getDefaultAuthorizationControl());
dialog.setUsers(null, gitblit.getUsernames(), null);
dialog.setTeams(gitblit.getTeamnames(), null);
dialog.setRepositories(gitblit.getRepositories());
dialog.setFederationSets(gitblit.getFederationSets(), null);
dialog.setIndexedBranches(new ArrayList<String>(Arrays.asList(Constants.DEFAULT_BRANCH)), null);
dialog.setPreReceiveScripts(gitblit.getPreReceiveScriptsUnused(null), gitblit.getPreReceiveScriptsInherited(null), null);
dialog.setPostReceiveScripts(gitblit.getPostReceiveScriptsUnused(null), gitblit.getPostReceiveScriptsInherited(null), null);
dialog.setVisible(true);
final RepositoryModel newRepository = dialog.getRepository();
final List<RegistrantAccessPermission> permittedUsers = dialog.getUserAccessPermissions();
final List<RegistrantAccessPermission> permittedTeams = dialog.getTeamAccessPermissions();
if (newRepository == null) {
return;
}
GitblitWorker worker = new GitblitWorker(this, RpcRequest.CREATE_REPOSITORY) {
@Override
protected Boolean doRequest() throws IOException {
boolean success = gitblit.createRepository(newRepository, permittedUsers, permittedTeams);
if (success) {
gitblit.refreshRepositories();
if (permittedUsers.size() > 0) {
gitblit.refreshUsers();
}
if (permittedTeams.size() > 0) {
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(), newRepository.name);
}
};
worker.execute();
}
Aggregations