| | |
| | |
|
| | | import com.gitblit.Constants.AccessPermission;
|
| | | import com.gitblit.Constants.AccessRestrictionType;
|
| | | import com.gitblit.Constants.AccountType;
|
| | | import com.gitblit.Constants.PermissionType;
|
| | | import com.gitblit.Constants.RegistrantType;
|
| | | import com.gitblit.Constants.Unused;
|
| | | import com.gitblit.utils.StringUtils;
|
| | |
|
| | | /**
|
| | | * TeamModel is a serializable model class that represents a group of users and
|
| | | * a list of accessible repositories.
|
| | | * |
| | | *
|
| | | * @author James Moger
|
| | | * |
| | | *
|
| | | */
|
| | | public class TeamModel implements Serializable, Comparable<TeamModel> {
|
| | |
|
| | |
| | | public boolean canAdmin;
|
| | | public boolean canFork;
|
| | | public boolean canCreate;
|
| | | public AccountType accountType;
|
| | | public final Set<String> users = new HashSet<String>();
|
| | | // retained for backwards-compatibility with RPC clients
|
| | | @Deprecated
|
| | |
| | |
|
| | | public TeamModel(String name) {
|
| | | this.name = name;
|
| | | this.accountType = AccountType.LOCAL;
|
| | | }
|
| | |
|
| | | /**
|
| | | * @use hasRepositoryPermission
|
| | | * @param name
|
| | | * @return
|
| | | */
|
| | | @Deprecated
|
| | | @Unused
|
| | | public boolean hasRepository(String name) {
|
| | | return hasRepositoryPermission(name);
|
| | | }
|
| | |
|
| | | @Deprecated
|
| | | @Unused
|
| | | public void addRepository(String name) {
|
| | | addRepositoryPermission(name);
|
| | | }
|
| | | |
| | | @Deprecated
|
| | | @Unused
|
| | | public void addRepositories(Collection<String> names) {
|
| | | addRepositoryPermissions(names);
|
| | | }
|
| | |
|
| | | @Deprecated
|
| | | @Unused
|
| | | public void removeRepository(String name) {
|
| | | removeRepositoryPermission(name);
|
| | | }
|
| | |
|
| | | |
| | | /**
|
| | | * Returns a list of repository permissions for this team.
|
| | | * |
| | | *
|
| | | * @return the team's list of permissions
|
| | | */
|
| | | public List<RegistrantAccessPermission> getRepositoryPermissions() {
|
| | |
| | | Collections.sort(list);
|
| | | return list;
|
| | | }
|
| | | |
| | |
|
| | | /**
|
| | | * Returns true if the team has any type of specified access permission for
|
| | | * this repository.
|
| | | * |
| | | *
|
| | | * @param name
|
| | | * @return true if team has a specified access permission for the repository
|
| | | */
|
| | |
| | | }
|
| | | return false;
|
| | | }
|
| | | |
| | |
|
| | | /**
|
| | | * Returns true if the team has an explicitly specified access permission for
|
| | | * this repository.
|
| | | * |
| | | *
|
| | | * @param name
|
| | | * @return if the team has an explicitly specified access permission
|
| | | */
|
| | |
| | | String repository = AccessPermission.repositoryFromRole(name).toLowerCase();
|
| | | return permissions.containsKey(repository);
|
| | | }
|
| | | |
| | |
|
| | | /**
|
| | | * Adds a repository permission to the team.
|
| | | * <p>
|
| | |
| | | addRepositoryPermission(role);
|
| | | }
|
| | | }
|
| | | |
| | |
|
| | | public AccessPermission removeRepositoryPermission(String name) {
|
| | | String repository = AccessPermission.repositoryFromRole(name).toLowerCase();
|
| | | repositories.remove(repository);
|
| | | return permissions.remove(repository);
|
| | | }
|
| | | |
| | |
|
| | | public void setRepositoryPermission(String repository, AccessPermission permission) {
|
| | | permissions.put(repository.toLowerCase(), permission);
|
| | | repositories.add(repository.toLowerCase());
|
| | | if (permission == null) {
|
| | | // remove the permission
|
| | | permissions.remove(repository.toLowerCase());
|
| | | repositories.remove(repository.toLowerCase());
|
| | | } else {
|
| | | // set the new permission
|
| | | permissions.put(repository.toLowerCase(), permission);
|
| | | repositories.add(repository.toLowerCase());
|
| | | }
|
| | | }
|
| | | |
| | |
|
| | | public RegistrantAccessPermission getRepositoryPermission(RepositoryModel repository) {
|
| | | RegistrantAccessPermission ap = new RegistrantAccessPermission();
|
| | | ap.registrant = name;
|
| | | ap.registrantType = RegistrantType.TEAM;
|
| | | ap.permission = AccessPermission.NONE;
|
| | | ap.mutable = false;
|
| | | |
| | |
|
| | | // determine maximum permission for the repository
|
| | | final AccessPermission maxPermission = |
| | | (repository.isFrozen || !repository.isBare) ?
|
| | | final AccessPermission maxPermission =
|
| | | (repository.isFrozen || !repository.isBare || repository.isMirror) ?
|
| | | AccessPermission.CLONE : AccessPermission.REWIND;
|
| | |
|
| | | if (AccessRestrictionType.NONE.equals(repository.accessRestriction)) {
|
| | |
| | | }
|
| | | return ap;
|
| | | }
|
| | | |
| | |
|
| | | if (canAdmin) {
|
| | | ap.permissionType = PermissionType.ADMINISTRATOR;
|
| | | if (AccessPermission.REWIND.atMost(maxPermission)) {
|
| | |
| | | }
|
| | | return ap;
|
| | | }
|
| | | |
| | |
|
| | | if (permissions.containsKey(repository.name.toLowerCase())) {
|
| | | // exact repository permission specified
|
| | | AccessPermission p = permissions.get(repository.name.toLowerCase());
|
| | |
| | | }
|
| | | }
|
| | | }
|
| | | |
| | |
|
| | | // still no explicit or regex, check for implicit permissions
|
| | | if (AccessPermission.NONE == ap.permission) {
|
| | | switch (repository.accessRestriction) {
|
| | |
| | |
|
| | | return ap;
|
| | | }
|
| | | |
| | |
|
| | | protected boolean canAccess(RepositoryModel repository, AccessRestrictionType ifRestriction, AccessPermission requirePermission) {
|
| | | if (repository.accessRestriction.atLeast(ifRestriction)) {
|
| | | RegistrantAccessPermission ap = getRepositoryPermission(repository);
|
| | |
| | | }
|
| | | return true;
|
| | | }
|
| | | |
| | |
|
| | | public boolean canView(RepositoryModel repository) {
|
| | | return canAccess(repository, AccessRestrictionType.VIEW, AccessPermission.VIEW);
|
| | | }
|
| | |
| | | }
|
| | | }
|
| | |
|
| | | public boolean isLocalTeam() {
|
| | | return accountType.isLocal();
|
| | | }
|
| | |
|
| | | @Override
|
| | | public String toString() {
|
| | | return name;
|