| | |
| | | import java.util.Collections;
|
| | | import java.util.Date;
|
| | | import java.util.HashSet;
|
| | | import java.util.LinkedHashSet;
|
| | | import java.util.List;
|
| | | import java.util.Map;
|
| | | import java.util.Set;
|
| | | import java.util.TreeSet;
|
| | |
|
| | | import com.gitblit.Constants;
|
| | | import com.gitblit.Constants.AccessRestrictionType;
|
| | | import com.gitblit.Constants.AuthorizationControl;
|
| | | import com.gitblit.GitBlitException.ForbiddenException;
|
| | | import com.gitblit.GitBlitException.NotAllowedException;
|
| | | import com.gitblit.GitBlitException.UnauthorizedException;
|
| | |
| | | import com.gitblit.models.ServerStatus;
|
| | | import com.gitblit.models.TeamModel;
|
| | | import com.gitblit.models.UserModel;
|
| | | import com.gitblit.utils.ArrayUtils;
|
| | | import com.gitblit.utils.RpcUtils;
|
| | | import com.gitblit.utils.StringUtils;
|
| | | import com.gitblit.utils.SyndicationUtils;
|
| | |
| | | }
|
| | | return sb.toString();
|
| | | }
|
| | | }
|
| | | |
| | | public AccessRestrictionType getDefaultAccessRestriction() {
|
| | | String restriction = null;
|
| | | if (settings.hasKey(Keys.git.defaultAccessRestriction)) {
|
| | | restriction = settings.get(Keys.git.defaultAccessRestriction).currentValue;
|
| | | }
|
| | | return AccessRestrictionType.fromName(restriction);
|
| | | }
|
| | |
|
| | | public AuthorizationControl getDefaultAuthorizationControl() {
|
| | | String authorization = null;
|
| | | if (settings.hasKey(Keys.git.defaultAuthorizationControl)) {
|
| | | authorization = settings.get(Keys.git.defaultAuthorizationControl).currentValue;
|
| | | }
|
| | | return AuthorizationControl.fromName(authorization);
|
| | | }
|
| | |
|
| | | /**
|
| | | * Returns the list of pre-receive scripts the repository inherited from the
|
| | | * global settings and team affiliations.
|
| | | * |
| | | * @param repository
|
| | | * if null only the globally specified scripts are returned
|
| | | * @return a list of scripts
|
| | | */
|
| | | public List<String> getPreReceiveScriptsInherited(RepositoryModel repository) {
|
| | | Set<String> scripts = new LinkedHashSet<String>();
|
| | | // Globals
|
| | | for (String script : settings.get(Keys.groovy.preReceiveScripts).getStrings()) {
|
| | | if (script.endsWith(".groovy")) {
|
| | | scripts.add(script.substring(0, script.lastIndexOf('.')));
|
| | | } else {
|
| | | scripts.add(script);
|
| | | }
|
| | | }
|
| | |
|
| | | // Team Scripts
|
| | | if (repository != null) {
|
| | | for (String teamname : getPermittedTeamnames(repository)) {
|
| | | TeamModel team = getTeamModel(teamname);
|
| | | if (!ArrayUtils.isEmpty(team.preReceiveScripts)) {
|
| | | scripts.addAll(team.preReceiveScripts);
|
| | | }
|
| | | }
|
| | | }
|
| | | return new ArrayList<String>(scripts);
|
| | | }
|
| | |
|
| | | /**
|
| | | * Returns the list of all available Groovy pre-receive push hook scripts
|
| | | * that are not already inherited by the repository. Script files must have
|
| | | * .groovy extension
|
| | | * |
| | | * @param repository
|
| | | * optional parameter
|
| | | * @return list of available hook scripts
|
| | | */
|
| | | public List<String> getPreReceiveScriptsUnused(RepositoryModel repository) {
|
| | | Set<String> inherited = new TreeSet<String>(getPreReceiveScriptsInherited(repository));
|
| | |
|
| | | // create list of available scripts by excluding inherited scripts
|
| | | List<String> scripts = new ArrayList<String>();
|
| | | for (String script : settings.pushScripts) {
|
| | | if (!inherited.contains(script)) {
|
| | | scripts.add(script);
|
| | | }
|
| | | }
|
| | | return scripts;
|
| | | }
|
| | |
|
| | | /**
|
| | | * Returns the list of post-receive scripts the repository inherited from
|
| | | * the global settings and team affiliations.
|
| | | * |
| | | * @param repository
|
| | | * if null only the globally specified scripts are returned
|
| | | * @return a list of scripts
|
| | | */
|
| | | public List<String> getPostReceiveScriptsInherited(RepositoryModel repository) {
|
| | | Set<String> scripts = new LinkedHashSet<String>();
|
| | | // Global Scripts
|
| | | for (String script : settings.get(Keys.groovy.postReceiveScripts).getStrings()) {
|
| | | if (script.endsWith(".groovy")) {
|
| | | scripts.add(script.substring(0, script.lastIndexOf('.')));
|
| | | } else {
|
| | | scripts.add(script);
|
| | | }
|
| | | }
|
| | | // Team Scripts
|
| | | if (repository != null) {
|
| | | for (String teamname : getPermittedTeamnames(repository)) {
|
| | | TeamModel team = getTeamModel(teamname);
|
| | | if (!ArrayUtils.isEmpty(team.postReceiveScripts)) {
|
| | | scripts.addAll(team.postReceiveScripts);
|
| | | }
|
| | | }
|
| | | }
|
| | | return new ArrayList<String>(scripts);
|
| | | }
|
| | |
|
| | | /**
|
| | | * Returns the list of unused Groovy post-receive push hook scripts that are
|
| | | * not already inherited by the repository. Script files must have .groovy
|
| | | * extension
|
| | | * |
| | | * @param repository
|
| | | * optional parameter
|
| | | * @return list of available hook scripts
|
| | | */
|
| | | public List<String> getPostReceiveScriptsUnused(RepositoryModel repository) {
|
| | | Set<String> inherited = new TreeSet<String>(getPostReceiveScriptsInherited(repository));
|
| | |
|
| | | // create list of available scripts by excluding inherited scripts
|
| | | List<String> scripts = new ArrayList<String>();
|
| | | if (!ArrayUtils.isEmpty(settings.pushScripts)) { |
| | | for (String script : settings.pushScripts) {
|
| | | if (!inherited.contains(script)) {
|
| | | scripts.add(script);
|
| | | }
|
| | | }
|
| | | }
|
| | | return scripts;
|
| | | }
|
| | |
|
| | | public ServerSettings getSettings() {
|
| | |
| | | return teamnames;
|
| | | }
|
| | |
|
| | | public TeamModel getTeamModel(String name) {
|
| | | for (TeamModel team : allTeams) {
|
| | | if (team.name.equalsIgnoreCase(name)) {
|
| | | return team;
|
| | | }
|
| | | }
|
| | | return null;
|
| | | }
|
| | |
|
| | | public List<String> getFederationSets() {
|
| | | return settings.get(Keys.federation.sets).getStrings();
|
| | | }
|
| | |
| | | public boolean deleteRepository(RepositoryModel repository) throws IOException {
|
| | | return RpcUtils.deleteRepository(repository, url, account, password);
|
| | | }
|
| | | |
| | | public boolean clearRepositoryCache() throws IOException {
|
| | | return RpcUtils.clearRepositoryCache(url, account, password);
|
| | | }
|
| | |
|
| | | public boolean createUser(UserModel user) throws IOException {
|
| | | return RpcUtils.createUser(user, url, account, password);
|