| | |
| | | import com.gitblit.Constants.AccessPermission;
|
| | | import com.gitblit.Constants.AccessRestrictionType;
|
| | | import com.gitblit.Constants.AuthorizationControl;
|
| | | import com.gitblit.Constants.PermissionType;
|
| | | import com.gitblit.Constants.RegistrantType;
|
| | | import com.gitblit.GitBlitException.ForbiddenException;
|
| | | import com.gitblit.GitBlitException.NotAllowedException;
|
| | | import com.gitblit.GitBlitException.UnauthorizedException;
|
| | |
| | | return usernames;
|
| | | }
|
| | |
|
| | | /**
|
| | | * 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;
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | // TODO reconsider ownership as a user property
|
| | | // 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;
|
| | | }
|
| | | |
| | | public List<RegistrantAccessPermission> getUserAccessPermissions(RepositoryModel repository) {
|
| | | List<RegistrantAccessPermission> list = new ArrayList<RegistrantAccessPermission>(); |
| | | for (UserModel user : getUsers()) {
|
| | | List<RegistrantAccessPermission> list = new ArrayList<RegistrantAccessPermission>();
|
| | | if (AccessRestrictionType.NONE.equals(repository.accessRestriction)) {
|
| | | // no permissions needed, REWIND for everyone!
|
| | | return list;
|
| | | }
|
| | | if (AuthorizationControl.AUTHENTICATED.equals(repository.authorizationControl)) {
|
| | | // no permissions needed, REWIND for authenticated!
|
| | | return list;
|
| | | }
|
| | | // NAMED users and teams
|
| | | for (UserModel user : allUsers) {
|
| | | RegistrantAccessPermission ap = user.getRepositoryPermission(repository);
|
| | | if (ap.permission.exceeds(AccessPermission.NONE)) {
|
| | | list.add(ap);
|
| | | }
|
| | | }
|
| | | Collections.sort(list);
|
| | | return list;
|
| | | }
|
| | |
|