| | |
| | | import java.text.MessageFormat;
|
| | | import java.util.ArrayList;
|
| | | import java.util.Collections;
|
| | | import java.util.HashMap;
|
| | | import java.util.HashSet;
|
| | | import java.util.List;
|
| | | import java.util.Map;
|
| | | import java.util.Set;
|
| | |
|
| | | import javax.swing.ImageIcon;
|
| | |
| | | import javax.swing.KeyStroke;
|
| | |
|
| | | import com.gitblit.Constants.AccessRestrictionType;
|
| | | import com.gitblit.Constants.AuthorizationControl;
|
| | | import com.gitblit.Constants.PermissionType;
|
| | | import com.gitblit.Constants.RegistrantType;
|
| | | import com.gitblit.Keys;
|
| | | import com.gitblit.models.RegistrantAccessPermission;
|
| | | import com.gitblit.models.RepositoryModel;
|
| | |
| | | notFederatedCheckbox));
|
| | |
|
| | | final Insets _insets = new Insets(5, 5, 5, 5);
|
| | | repositoryPalette = new RegistrantPermissionsPanel();
|
| | | repositoryPalette = new RegistrantPermissionsPanel(RegistrantType.REPOSITORY);
|
| | | teamsPalette = new JPalette<TeamModel>();
|
| | | teamsPalette.setEnabled(settings.supportsTeamMembershipChanges);
|
| | |
|
| | |
| | | }
|
| | |
|
| | | 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) {
|
| | | if (repo.accessRestriction.exceeds(AccessRestrictionType.NONE)) {
|
| | | restricted.add(repo.name);
|
| | | // 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.add("[^~].*");
|
| | | String lastProject = null;
|
| | | for (String repo : restricted) {
|
| | | String projectPath = StringUtils.getFirstPathElement(repo);
|
| | | 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);
|
| | | }
|
| | | list.add(repo);
|
| | | }
|
| | |
|
| | | // remove repositories for which user already has a permission
|
| | |
| | | permissions = new ArrayList<RegistrantAccessPermission>();
|
| | | } else {
|
| | | for (RegistrantAccessPermission rp : permissions) {
|
| | | list.remove(rp.registrant);
|
| | | 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);
|
| | | }
|
| | |
|