import java.util.Locale;\r
import java.util.Map;\r
import java.util.Set;\r
+import java.util.TreeSet;\r
import java.util.concurrent.ConcurrentHashMap;\r
\r
import org.eclipse.jgit.lib.StoredConfig;\r
\r
private static final String STARRED = "starred";\r
\r
+ private static final String OWNS = "owns";\r
+\r
private static final String LOCALE = "locale";\r
\r
private static final String EMAILONMYTICKETCHANGES = "emailMeOnMyTicketChanges";\r
AccessPermission permission = model.removeRepositoryPermission(oldRole);\r
model.setRepositoryPermission(newRole, permission);\r
}\r
+\r
+ if (model.isOwner(oldRole)) {\r
+ model.disown(oldRole);\r
+ model.own(newRole);\r
+ }\r
}\r
\r
// identify teams which require role rename\r
config.setStringList(USER, model.username, REPOSITORY, permissions);\r
}\r
\r
+ // project and repository ownership\r
+ if (model.ownedPaths != null) {\r
+ config.setStringList(USER, model.username, OWNS, new ArrayList<String>(model.ownedPaths));\r
+ }\r
+\r
// user preferences\r
if (model.getPreferences() != null) {\r
List<String> starred = model.getPreferences().getStarredRepositories();\r
}\r
\r
// starred repositories\r
- Set<String> starred = new HashSet<String>(Arrays.asList(config\r
+ Set<String> starred = new TreeSet<String>(Arrays.asList(config\r
.getStringList(USER, username, STARRED)));\r
for (String repository : starred) {\r
UserRepositoryPreferences prefs = user.getPreferences().getRepositoryPreferences(repository);\r
prefs.starred = true;\r
}\r
\r
+ // repository ownership\r
+ Set<String> ownerOf = new TreeSet<String>(Arrays.asList(config.getStringList(USER, username, OWNS)));\r
+ for (String path : ownerOf) {\r
+ user.own(path);\r
+ }\r
+\r
// update cache\r
users.put(user.username, user);\r
if (!StringUtils.isEmpty(user.cookie)) {\r
CREATE_REPOSITORY, EDIT_REPOSITORY, DELETE_REPOSITORY,\r
LIST_USERS, CREATE_USER, EDIT_USER, DELETE_USER,\r
LIST_TEAMS, CREATE_TEAM, EDIT_TEAM, DELETE_TEAM,\r
+ LIST_REPOSITORY_OWNERS, SET_REPOSITORY_OWNERS,\r
LIST_REPOSITORY_MEMBERS, SET_REPOSITORY_MEMBERS, LIST_REPOSITORY_TEAMS, SET_REPOSITORY_TEAMS,\r
LIST_REPOSITORY_MEMBER_PERMISSIONS, SET_REPOSITORY_MEMBER_PERMISSIONS, LIST_REPOSITORY_TEAM_PERMISSIONS, SET_REPOSITORY_TEAM_PERMISSIONS,\r
LIST_FEDERATION_REGISTRATIONS, LIST_FEDERATION_RESULTS, LIST_FEDERATION_PROPOSALS, LIST_FEDERATION_SETS,\r
\r
repository.name = rname;\r
repository.description = descriptionField.getText();\r
- repository.owners.clear();\r
- repository.owners.addAll(ownersPalette.getSelections());\r
repository.HEAD = headRefField.getSelectedItem() == null ? null\r
: headRefField.getSelectedItem().toString();\r
repository.gcPeriod = (Integer) gcPeriod.getSelectedItem();\r
return teamsPalette.getPermissions();\r
}\r
\r
+ public List<String> getOwners() {\r
+ return ownersPalette.getSelections();\r
+ }\r
+\r
public void setCustomFields(RepositoryModel repository, Map<String, String> customFields) {\r
customFieldsPanel.removeAll();\r
customTextfields = new ArrayList<JTextField>();\r
List<String> restricted = new ArrayList<String>();\r
for (RepositoryModel repo : repositories) {\r
// exclude Owner or personal repositories\r
- if (!repo.isOwner(username) && !repo.isUsersPersonalRepository(username)) {\r
+ if (!user.isOwner(repo)) {\r
if (repo.accessRestriction.exceeds(AccessRestrictionType.NONE)\r
&& repo.authorizationControl.equals(AuthorizationControl.NAMED)) {\r
restricted.add(repo.name);\r
permission.mutable = false;\r
continue;\r
}\r
- boolean isOwner = rm.isOwner(username);\r
+ boolean isOwner = user.isOwner(rm);\r
if (isOwner) {\r
permission.permissionType = PermissionType.OWNER;\r
permission.mutable = false;\r
}\r
\r
public boolean isOwner(RepositoryModel model) {\r
- return model.isOwner(account);\r
+ return getUser(account).isOwner(model);\r
+ }\r
+\r
+ public List<String> getOwners(RepositoryModel model) {\r
+ List<String> list = new ArrayList<String>();\r
+ for (UserModel user : allUsers) {\r
+ if (user.isOwner(model)) {\r
+ list.add(user.username);\r
+ }\r
+ }\r
+ return list;\r
}\r
\r
public String getURL(String action, String repository, String objectId) {\r
}\r
}\r
\r
- // TODO reconsider ownership as a user property\r
// manually specify personal repository ownerships\r
for (RepositoryModel rm : allRepositories) {\r
- if (rm.isUsersPersonalRepository(user.username) || rm.isOwner(user.username)) {\r
+ if (user.isOwner(rm)) {\r
RegistrantAccessPermission rp = new RegistrantAccessPermission(rm.name, AccessPermission.REWIND,\r
PermissionType.OWNER, RegistrantType.REPOSITORY, null, false);\r
// user may be owner of a repository to which they've inherited\r
\r
public boolean updateRepository(String name, RepositoryModel repository,\r
List<RegistrantAccessPermission> userPermissions) throws IOException {\r
- return updateRepository(name, repository, userPermissions, null);\r
+ return updateRepository(name, repository, null, userPermissions, null);\r
}\r
\r
- public boolean updateRepository(String name, RepositoryModel repository,\r
+ public boolean updateRepository(String name, RepositoryModel repository, List<String> owners,\r
List<RegistrantAccessPermission> userPermissions, List<RegistrantAccessPermission> teamPermissions) throws IOException {\r
boolean success = true;\r
success &= RpcUtils.updateRepository(name, repository, url, account, password);\r
+ // set the repository owners\r
+ if (owners != null) {\r
+ success &= RpcUtils.setRepositoryOwners(repository, owners, url, account, password);\r
+ }\r
+\r
// set the repository members\r
if (userPermissions != null) {\r
success &= RpcUtils.setRepositoryMemberPermissions(repository, userPermissions, url, account,\r
\r
setRepositoryRenderer(RepositoriesTableModel.Columns.Name, nameRenderer, -1);\r
setRepositoryRenderer(RepositoriesTableModel.Columns.Indicators, typeRenderer, 100);\r
- setRepositoryRenderer(RepositoriesTableModel.Columns.Owner, ownerRenderer, -1);\r
setRepositoryRenderer(RepositoriesTableModel.Columns.Size, sizeRenderer, 60);\r
\r
table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {\r
dialog.setLocationRelativeTo(RepositoriesPanel.this);\r
List<String> usernames = gitblit.getUsernames();\r
List<RegistrantAccessPermission> members = gitblit.getUserAccessPermissions(repository);\r
- dialog.setUsers(new ArrayList<String>(repository.owners), usernames, members);\r
+ List<String> owners = gitblit.getOwners(repository);\r
+ dialog.setUsers(owners, usernames, members);\r
dialog.setTeams(gitblit.getTeamnames(), gitblit.getTeamAccessPermissions(repository));\r
dialog.setRepositories(gitblit.getRepositories());\r
dialog.setFederationSets(gitblit.getFederationSets(), repository.federationSets);\r
final RepositoryModel revisedRepository = dialog.getRepository();\r
final List<RegistrantAccessPermission> permittedUsers = dialog.getUserAccessPermissions();\r
final List<RegistrantAccessPermission> permittedTeams = dialog.getTeamAccessPermissions();\r
+ final List<String> newOwners = dialog.getOwners();\r
if (revisedRepository == null) {\r
return;\r
}\r
\r
@Override\r
protected Boolean doRequest() throws IOException {\r
- boolean success = gitblit.updateRepository(repository.name, revisedRepository,\r
+ boolean success = gitblit.updateRepository(repository.name, revisedRepository, newOwners,\r
permittedUsers, permittedTeams);\r
if (success) {\r
gitblit.refreshRepositories();\r
import javax.swing.table.AbstractTableModel;\r
\r
import com.gitblit.models.RepositoryModel;\r
-import com.gitblit.utils.ArrayUtils;\r
\r
/**\r
* Table model of a list of repositories.\r
List<RepositoryModel> list;\r
\r
enum Columns {\r
- Name, Description, Owner, Indicators, Last_Change, Size;\r
+ Name, Description, Indicators, Last_Change, Size;\r
\r
@Override\r
public String toString() {\r
return Translation.get("gb.name");\r
case Description:\r
return Translation.get("gb.description");\r
- case Owner:\r
- return Translation.get("gb.owner");\r
case Last_Change:\r
return Translation.get("gb.lastChange");\r
case Size:\r
return model;\r
case Description:\r
return model.description;\r
- case Owner:\r
- return ArrayUtils.toString(model.owners);\r
case Indicators:\r
return model;\r
case Last_Change:\r
} else if (ref.equals(BranchTicketService.BRANCH)) {\r
// ensure pushing user is an administrator OR an owner\r
// i.e. prevent ticket tampering\r
- boolean permitted = user.canAdmin() || repository.isOwner(user.username);\r
+ boolean permitted = user.canAdmin() || user.isOwner(repository);\r
if (!permitted) {\r
sendRejection(cmd, "{0} is not permitted to push to {1}", user.username, ref);\r
}\r
import com.gitblit.models.GitClientApplication;
import com.gitblit.models.Mailing;
import com.gitblit.models.Metric;
+import com.gitblit.models.Owner;
import com.gitblit.models.PluginRegistry.InstallState;
import com.gitblit.models.PluginRegistry.PluginRegistration;
import com.gitblit.models.PluginRegistry.PluginRelease;
import com.gitblit.tickets.ITicketService;
import com.gitblit.transport.ssh.IPublicKeyManager;
import com.gitblit.transport.ssh.SshKey;
-import com.gitblit.utils.ArrayUtils;
import com.gitblit.utils.HttpUtils;
import com.gitblit.utils.JsonUtils;
import com.gitblit.utils.ObjectCache;
*/
@Override
public RepositoryModel fork(RepositoryModel repository, UserModel user) throws GitBlitException {
- String cloneName = MessageFormat.format("{0}/{1}.git", user.getPersonalPath(), StringUtils.stripDotGit(StringUtils.getLastPathElement(repository.name)));
+ String cloneName = MessageFormat.format("{0}{1}.git", user.getPersonalPath(), StringUtils.stripDotGit(StringUtils.getLastPathElement(repository.name)));
String fromUrl = MessageFormat.format("file://{0}/{1}", repositoryManager.getRepositoriesFolder().getAbsolutePath(), repository.name);
// clone the repository
// create a Gitblit repository model for the clone
RepositoryModel cloneModel = repository.cloneAs(cloneName);
- // owner has REWIND/RW+ permissions
- cloneModel.addOwner(user.username);
repositoryManager.updateRepositoryModel(cloneName, cloneModel, false);
- // add the owner of the source repository to the clone's access list
- if (!ArrayUtils.isEmpty(repository.owners)) {
- for (String owner : repository.owners) {
- UserModel originOwner = userManager.getUserModel(owner);
- if (originOwner != null && !originOwner.canClone(cloneModel)) {
+ // owner has REWIND/RW+ permissions
+ user.own(cloneModel);
+ reviseUser(user.username, user);
+
+ // add the owners of the source repository to the clone's access list
+ for (Owner owner : getOwners(repository)) {
+ if (owner instanceof UserModel) {
+ UserModel userOwner = (UserModel) owner;
+ if (!userOwner.canClone(cloneModel)) {
// origin owner can't yet clone fork, grant explicit clone access
- originOwner.setRepositoryPermission(cloneName, AccessPermission.CLONE);
- reviseUser(originOwner.username, originOwner);
+ userOwner.setRepositoryPermission(cloneName, AccessPermission.CLONE);
+ reviseUser(userOwner.username, userOwner);
}
}
}
user.username));
}
- // rename repositories and owner fields for all repositories
- for (RepositoryModel model : repositoryManager.getRepositoryModels(user)) {
- if (model.isUsersPersonalRepository(username)) {
- // personal repository
- model.addOwner(user.username);
- String oldRepositoryName = model.name;
- model.name = user.getPersonalPath() + model.name.substring(model.projectPath.length());
- model.projectPath = user.getPersonalPath();
- repositoryManager.updateRepositoryModel(oldRepositoryName, model, false);
- } else if (model.isOwner(username)) {
- // common/shared repo
- model.addOwner(user.username);
- repositoryManager.updateRepositoryModel(model.name, model, false);
- }
- }
-
// rename the user's ssh public keystore
getPublicKeyManager().renameUser(username, user.username);
}
return userManager.deleteTeam(teamname);
}
+ @Override
+ public List<Owner> getOwners(RepositoryModel repository) {
+ return userManager.getOwners(repository);
+ }
+
+ @Override
+ public boolean setOwners(RepositoryModel repository, List<Owner> owners) {
+ return userManager.setOwners(repository, owners);
+ }
+
/*
* REPOSITORY MANAGER
*/
*/
package com.gitblit.manager;
+import java.util.List;
+
import com.gitblit.IUserService;
+import com.gitblit.models.Owner;
+import com.gitblit.models.RepositoryModel;
public interface IUserManager extends IManager, IUserService {
*/
boolean isInternalAccount(String username);
+ /**
+ * Returns the list of repository owners.
+ *
+ * @param repository
+ * @return a list of owners
+ * @since 1.6.0
+ */
+ List<Owner> getOwners(RepositoryModel repository);
+
+ /**
+ * Sets the repository owners.
+ *
+ * @param repository
+ * @param a list of owners
+ * @return true if successful
+ * @since 1.6.0
+ */
+ boolean setOwners(RepositoryModel repository, List<Owner> owners);
+
+// /**
+// * Returns the list of project owners.
+// *
+// * @param project
+// * @return a list of owners
+// * @since 1.6.0
+// */
+// List<RepositoryOwner> getOwners(ProjectModel project);
+//
}
\ No newline at end of file
// exclude personal repositories
continue;
}
- if (!projects.containsKey(repository.projectPath)) {
- ProjectModel project = getProjectModel(repository.projectPath);
+ if (!projects.containsKey(repository.getProject())) {
+ ProjectModel project = getProjectModel(repository.getProject());
if (project == null) {
logger.warn(MessageFormat.format("excluding project \"{0}\" from project list because it is empty!",
- repository.projectPath));
+ repository.getProject()));
continue;
}
- projects.put(repository.projectPath, project);
+ projects.put(repository.getProject(), project);
// clear the repo list in the project because that is the system
// list, not the user-accessible list and start building the
// user-accessible list
} else {
// update the user-accessible list
// this is used for repository count
- ProjectModel project = projects.get(repository.projectPath);
+ ProjectModel project = projects.get(repository.getProject());
project.repositories.add(repository.name);
if (project.lastChange.before(repository.lastChange)) {
project.lastChange = repository.lastChange;
}
}
- // TODO reconsider ownership as a user property
// manually specify personal repository ownerships
for (RepositoryModel rm : repositoryListCache.values()) {
- if (rm.isUsersPersonalRepository(user.username) || rm.isOwner(user.username)) {
+ if (user.isOwner(rm)) {
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
if (r == null) {
return null;
}
- RepositoryModel model = new RepositoryModel();
- model.isBare = r.isBare();
+
+ String name;
File basePath = getRepositoriesFolder();
- if (model.isBare) {
- model.name = com.gitblit.utils.FileUtils.getRelativePath(basePath, r.getDirectory());
+ if (r.isBare()) {
+ name = com.gitblit.utils.FileUtils.getRelativePath(basePath, r.getDirectory());
} else {
- model.name = com.gitblit.utils.FileUtils.getRelativePath(basePath, r.getDirectory().getParentFile());
+ name = com.gitblit.utils.FileUtils.getRelativePath(basePath, r.getDirectory().getParentFile());
}
- if (StringUtils.isEmpty(model.name)) {
+
+ if (StringUtils.isEmpty(name)) {
// Repository is NOT located relative to the base folder because it
// is symlinked. Use the provided repository name.
- model.name = repositoryName;
+ name = repositoryName;
}
- model.projectPath = StringUtils.getFirstPathElement(repositoryName);
+
+ RepositoryModel model = new RepositoryModel(name);
+ model.isBare = r.isBare();
StoredConfig config = r.getConfig();
boolean hasOrigin = false;
}
model.description = getConfig(config, "description", "");
model.originRepository = getConfig(config, "originRepository", null);
- model.addOwners(ArrayUtils.fromString(getConfig(config, "owner", "")));
+// model.addOwners(ArrayUtils.fromString(getConfig(config, "owner", "")));
model.acceptNewPatchsets = getConfig(config, "acceptNewPatchsets", true);
model.acceptNewTickets = getConfig(config, "acceptNewTickets", true);
model.requireApproval = getConfig(config, "requireApproval", settings.getBoolean(Keys.tickets.requireApproval, false));
if (StringUtils.isEmpty(origin)) {
return null;
}
- String userProject = ModelUtils.getPersonalPath(username);
+ String userPath = ModelUtils.getPersonalPath(username);
if (settings.getBoolean(Keys.git.cacheRepositoryList, true)) {
String originKey = origin.toLowerCase();
- String userPath = userProject + "/";
// collect all origin nodes in fork network
Set<String> roots = new HashSet<String>();
}
} else {
// not caching
+ String userProject = ModelUtils.getPersonalProject(username);
File subfolder = new File(getRepositoriesFolder(), userProject);
List<String> repositories = JGitUtils.getRepositoryList(subfolder,
settings.getBoolean(Keys.git.onlyAccessBareRepositories, false),
settings.getInteger(Keys.git.searchRecursionDepth, -1),
settings.getStrings(Keys.git.searchExclusions));
for (String repository : repositories) {
- RepositoryModel model = getRepositoryModel(userProject + "/" + repository);
+ RepositoryModel model = getRepositoryModel(userPath + repository);
if (model.originRepository != null && model.originRepository.equalsIgnoreCase(origin)) {
// user has a fork
return model.name;
StoredConfig config = r.getConfig();
config.setString(Constants.CONFIG_GITBLIT, null, "description", repository.description);
config.setString(Constants.CONFIG_GITBLIT, null, "originRepository", repository.originRepository);
- config.setString(Constants.CONFIG_GITBLIT, null, "owner", ArrayUtils.toString(repository.owners));
+// config.setString(Constants.CONFIG_GITBLIT, null, "owner", ArrayUtils.toString(repository.owners));
config.setBoolean(Constants.CONFIG_GITBLIT, null, "acceptNewPatchsets", repository.acceptNewPatchsets);
config.setBoolean(Constants.CONFIG_GITBLIT, null, "acceptNewTickets", repository.acceptNewTickets);
if (settings.getBoolean(Keys.tickets.requireApproval, false) == repository.requireApproval) {
import com.gitblit.IUserService;
import com.gitblit.Keys;
import com.gitblit.extensions.UserTeamLifeCycleListener;
+import com.gitblit.models.Owner;
+import com.gitblit.models.RepositoryModel;
import com.gitblit.models.TeamModel;
import com.gitblit.models.UserModel;
import com.gitblit.utils.StringUtils;
return userService.deleteRepositoryRole(role);
}
+ /**
+ * Returns the list of owners for the repository.
+ *
+ * @param repository
+ * @return a list of owners
+ */
+ @Override
+ public List<Owner> getOwners(RepositoryModel repository) {
+ List<Owner> list = new ArrayList<>();
+ for (UserModel user : getAllUsers()) {
+ if (user.isOwner(repository)) {
+ list.add(user);
+ }
+ }
+ return list;
+ }
+
+ /**
+ * Set the repository owners.
+ *
+ * @param repository
+ * @param a list of owners
+ * @return true if successful
+ */
+ @Override
+ public boolean setOwners(RepositoryModel repository, List<Owner> owners) {
+ List<Owner> oldOwners = getOwners(repository);
+ List<UserModel> users = new ArrayList<>();
+
+ // identify new owners and filter-out continued owners
+ for (Owner owner : owners) {
+ if (!oldOwners.remove(owner)) {
+ // new owner
+ owner.own(repository);
+ if (owner instanceof UserModel) {
+ users.add((UserModel) owner);
+ }
+ }
+ }
+
+ // the remaining oldOwners are now former owners
+ for (Owner formerOwner : oldOwners) {
+ formerOwner.disown(repository);
+
+ if (formerOwner instanceof UserModel) {
+ users.add((UserModel) formerOwner);
+ }
+ }
+
+ updateUserModels(users);
+
+ return true;
+ }
+
protected void callCreateUserListeners(UserModel user) {
if (pluginManager == null || user == null) {
return;
--- /dev/null
+/*
+ * Copyright 2014 gitblit.com.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.gitblit.models;
+
+import java.io.Serializable;
+import java.util.Set;
+import java.util.TreeSet;
+
+import com.gitblit.utils.StringUtils;
+
+/**
+ * The owner class defines the ownership method contract for an object.
+ *
+ * @author James Moger
+ *
+ */
+public abstract class Owner implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ public final Set<String> ownedPaths = new TreeSet<String>();
+
+ public abstract String getId();
+
+ public abstract String getDisplayName();
+
+ public abstract String getPersonalPath();
+
+ public boolean isOwner(String path) {
+ if (StringUtils.isEmpty(path)) {
+ return false;
+ }
+
+ String personalPath = getPersonalPath();
+ if (personalPath != null && path.startsWith(personalPath)) {
+ return true;
+ }
+
+ if (ownedPaths == null) {
+ return false;
+ }
+
+ if (ownedPaths.contains(path.toLowerCase())) {
+ // exact path match
+ return true;
+ }
+
+ for (String ownedPath : ownedPaths) {
+ if (StringUtils.matchesIgnoreCase(path, ownedPath)) {
+ // regex match
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ public void own(String path) {
+ ownedPaths.add(path.toLowerCase());
+ }
+
+ public void disown(String path) {
+ ownedPaths.remove(path.toLowerCase());
+ }
+
+ public boolean isOwner(RepositoryModel repository) {
+ return isOwner(repository.name);
+ }
+
+ public void own(RepositoryModel repository) {
+ own(repository.name);
+ }
+
+ public void disown(RepositoryModel repository) {
+ disown(repository.name);
+ }
+}
\r
import java.io.Serializable;\r
import java.util.ArrayList;\r
-import java.util.Collection;\r
import java.util.Date;\r
import java.util.List;\r
import java.util.Map;\r
// field names are reflectively mapped in EditRepository page\r
public String name;\r
public String description;\r
- public List<String> owners;\r
public Date lastChange;\r
public String lastChangeAuthor;\r
public boolean hasCommits;\r
public List<String> postReceiveScripts;\r
public List<String> mailingLists;\r
public Map<String, String> customFields;\r
- public String projectPath;\r
+ private String projectPath;\r
private String displayName;\r
public boolean allowForks;\r
public Set<String> forks;\r
public String sparkleshareId;\r
\r
public RepositoryModel() {\r
- this("", "", "", new Date(0));\r
+ this("", "", new Date(0));\r
}\r
\r
- public RepositoryModel(String name, String description, String owner, Date lastchange) {\r
+ public RepositoryModel(String name ) {\r
this.name = name;\r
+ this.projectPath = StringUtils.getFirstPathElement(name);\r
+ }\r
+\r
+ public RepositoryModel(String name, String description, Date lastchange) {\r
+ this.name = name;\r
+ this.projectPath = StringUtils.getFirstPathElement(name);\r
this.description = description;\r
this.lastChange = lastchange;\r
this.accessRestriction = AccessRestrictionType.NONE;\r
this.federationSets = new ArrayList<String>();\r
this.federationStrategy = FederationStrategy.FEDERATE_THIS;\r
this.projectPath = StringUtils.getFirstPathElement(name);\r
- this.owners = new ArrayList<String>();\r
this.isBare = true;\r
this.acceptNewTickets = true;\r
this.acceptNewPatchsets = true;\r
-\r
- addOwner(owner);\r
}\r
\r
public List<String> getLocalBranches() {\r
return !StringUtils.isEmpty(originRepository);\r
}\r
\r
- public boolean isOwner(String username) {\r
- if (StringUtils.isEmpty(username) || ArrayUtils.isEmpty(owners)) {\r
- return isUsersPersonalRepository(username);\r
- }\r
- return owners.contains(username.toLowerCase()) || isUsersPersonalRepository(username);\r
- }\r
-\r
public boolean isPersonalRepository() {\r
return !StringUtils.isEmpty(projectPath) && ModelUtils.isPersonalRepository(projectPath);\r
}\r
\r
- public boolean isUsersPersonalRepository(String username) {\r
- return !StringUtils.isEmpty(projectPath) && ModelUtils.isUsersPersonalRepository(username, projectPath);\r
+ public String getPersonalRepositoryOwner() {\r
+ return ModelUtils.getUserNameFromRepoPath(projectPath);\r
+ }\r
+\r
+ /**\r
+ * Returns the project name.\r
+ *\r
+ * @return project name\r
+ */\r
+ public String getProject() {\r
+ return projectPath;\r
+ }\r
+\r
+ /**\r
+ * Returns the first path element of the full repository path. This path will always end with\r
+ * a trailing '/'.\r
+ *\r
+ * @return the project path of the repository\r
+ */\r
+ public String getProjectPath() {\r
+ return StringUtils.isEmpty(projectPath) ? "/" : (projectPath + "/");\r
}\r
\r
public boolean allowAnonymousView() {\r
clone.sparkleshareId = sparkleshareId;\r
return clone;\r
}\r
-\r
- public void addOwner(String username) {\r
- if (!StringUtils.isEmpty(username)) {\r
- String name = username.toLowerCase();\r
- // a set would be more efficient, but this complicates JSON\r
- // deserialization so we enforce uniqueness with an arraylist\r
- if (!owners.contains(name)) {\r
- owners.add(name);\r
- }\r
- }\r
- }\r
-\r
- public void removeOwner(String username) {\r
- if (!StringUtils.isEmpty(username)) {\r
- owners.remove(username.toLowerCase());\r
- }\r
- }\r
-\r
- public void addOwners(Collection<String> usernames) {\r
- if (!ArrayUtils.isEmpty(usernames)) {\r
- for (String username : usernames) {\r
- addOwner(username);\r
- }\r
- }\r
- }\r
-\r
- public void removeOwners(Collection<String> usernames) {\r
- if (!ArrayUtils.isEmpty(owners)) {\r
- for (String username : usernames) {\r
- removeOwner(username);\r
- }\r
- }\r
- }\r
}
* @author James Moger\r
*\r
*/\r
-public class UserModel implements Principal, Serializable, Comparable<UserModel> {\r
+public class UserModel extends Owner implements Principal, Serializable, Comparable<UserModel> {\r
\r
private static final long serialVersionUID = 1L;\r
\r
this.userPreferences = new UserPreferences(this.username);\r
}\r
\r
+ @Override\r
+ public String getId() {\r
+ return username;\r
+ }\r
+\r
public boolean isLocalAccount() {\r
return !Constants.EXTERNAL_ACCOUNT.equals(password)\r
|| accountType == null\r
}\r
\r
// repository owner - either specified owner or personal repository\r
- if (repository.isOwner(username) || repository.isUsersPersonalRepository(username)) {\r
+ if (isOwner(repository)) {\r
ap.permissionType = PermissionType.OWNER;\r
if (AccessPermission.REWIND.atMost(maxPermission)) {\r
ap.permission = AccessPermission.REWIND;\r
}\r
\r
public boolean canFork(RepositoryModel repository) {\r
- if (repository.isUsersPersonalRepository(username)) {\r
+ if (isMyPersonalRepository(repository.name)) {\r
// can not fork your own repository\r
return false;\r
}\r
- if (canAdmin() || repository.isOwner(username)) {\r
+ if (canAdmin() || isOwner(repository)) {\r
return true;\r
}\r
if (!repository.allowForks) {\r
}\r
\r
public boolean canDelete(RepositoryModel model) {\r
- return canAdmin() || model.isUsersPersonalRepository(username);\r
+ return canAdmin()\r
+ || isMyPersonalRepository(model.name)\r
+ || (!model.isPersonalRepository() && isOwner(model));\r
}\r
\r
public boolean canEdit(RepositoryModel model) {\r
- return canAdmin() || model.isUsersPersonalRepository(username) || model.isOwner(username);\r
+ return canAdmin() || isOwner(model);\r
}\r
\r
public boolean canEdit(TicketModel ticket, RepositoryModel repository) {\r
return true;\r
}\r
if (canCreate()) {\r
- String projectPath = StringUtils.getFirstPathElement(repository);\r
- if (!StringUtils.isEmpty(projectPath) && projectPath.equalsIgnoreCase(getPersonalPath())) {\r
- // personal repository\r
- return true;\r
- }\r
+ String projectPath = StringUtils.getFirstPathElement(repository) + "/";\r
+ return isOwner(projectPath);\r
}\r
return false;\r
}\r
\r
+// /**\r
+// * Returns true if the user is allowed to administer the specified project\r
+// *\r
+// * @param project\r
+// * @return true if the user can administer the project\r
+// */\r
+// public boolean canAdmin(ProjectModel project) {\r
+// return canAdmin() || isOwner(project);\r
+// }\r
+//\r
/**\r
* Returns true if the user is allowed to administer the specified repository\r
*\r
* @return true if the user can administer the repository\r
*/\r
public boolean canAdmin(RepositoryModel repo) {\r
- return canAdmin() || repo.isOwner(username) || isMyPersonalRepository(repo.name);\r
+ return canAdmin() || isOwner(repo);\r
}\r
\r
public boolean isAuthenticated() {\r
return username;\r
}\r
\r
+ @Override\r
public String getDisplayName() {\r
if (StringUtils.isEmpty(displayName)) {\r
return username;\r
return displayName;\r
}\r
\r
+ @Override\r
public String getPersonalPath() {\r
return ModelUtils.getPersonalPath(username);\r
}\r
}\r
\r
public boolean isMyPersonalRepository(String repository) {\r
- String projectPath = StringUtils.getFirstPathElement(repository);\r
- return !StringUtils.isEmpty(projectPath) && projectPath.equalsIgnoreCase(getPersonalPath());\r
+ return repository.startsWith(getPersonalPath());\r
}\r
+\r
+ @Override\r
+ public boolean isOwner(RepositoryModel repository) {\r
+ return isMyPersonalRepository(repository.name)\r
+ || isOwner(repository.name);\r
+ }\r
+// public boolean isOwner(ProjectModel project) {\r
+// return isOwner(project.name + "/");\r
+//}\r
+//\r
+// public void own(ProjectModel project) {\r
+// if (StringUtils.isEmpty(project.name)) {\r
+// own("/");\r
+// } else {\r
+// own(project.name.toLowerCase() + "/");\r
+// }\r
+// }\r
+//\r
+// public void disown(ProjectModel project) {\r
+// if (StringUtils.isEmpty(project.name)) {\r
+// disown("/");\r
+// } else {\r
+// disown(project.name.toLowerCase() + "/");\r
+// }\r
+// }\r
}\r
import com.gitblit.IStoredSettings;\r
import com.gitblit.Keys;\r
import com.gitblit.manager.IFederationManager;\r
+import com.gitblit.manager.IUserManager;\r
import com.gitblit.models.RepositoryModel;\r
import com.gitblit.models.UserModel;\r
import com.gitblit.utils.StringUtils;\r
\r
private IStoredSettings settings;\r
\r
+ private IUserManager userManager;\r
+\r
private IFederationManager federationManager;\r
\r
@Override\r
protected void inject(ObjectGraph dagger, FilterConfig filterConfig) {\r
super.inject(dagger, filterConfig);\r
this.settings = dagger.get(IStoredSettings.class);\r
+ this.userManager = dagger.get(IUserManager.class);\r
this.federationManager = dagger.get(IFederationManager.class);\r
}\r
\r
}\r
\r
// create repository\r
- RepositoryModel model = new RepositoryModel();\r
- model.name = repository;\r
- model.addOwner(user.username);\r
- model.projectPath = StringUtils.getFirstPathElement(repository);\r
- if (model.isUsersPersonalRepository(user.username)) {\r
+ RepositoryModel model = new RepositoryModel(repository);\r
+ if (user.isMyPersonalRepository(model.name)) {\r
// personal repository, default to private for user\r
model.authorizationControl = AuthorizationControl.NAMED;\r
model.accessRestriction = AccessRestrictionType.VIEW;\r
// create the repository\r
try {\r
repositoryManager.updateRepositoryModel(model.name, model, true);\r
+ user.own(model);\r
+ userManager.updateUserModel(user.username, user);\r
logger.info(MessageFormat.format("{0} created {1} ON-PUSH", user.username, model.name));\r
return repositoryManager.getRepositoryModel(model.name);\r
} catch (GitBlitException e) {\r
import com.gitblit.models.RefModel;\r
import com.gitblit.models.RegistrantAccessPermission;\r
import com.gitblit.models.RepositoryModel;\r
+import com.gitblit.models.Owner;\r
import com.gitblit.models.ServerSettings;\r
import com.gitblit.models.TeamModel;\r
import com.gitblit.models.UserModel;\r
} else if (RpcRequest.SET_REPOSITORY_MEMBERS.equals(reqType)) {\r
// rejected since 1.2.0\r
response.setStatus(failureCode);\r
+ } else if (RpcRequest.LIST_REPOSITORY_OWNERS.equals(reqType)) {\r
+ // get repository owners\r
+ RepositoryModel model = gitblit.getRepositoryModel(objectName);\r
+ List<Owner> owners = gitblit.getOwners(model);\r
+ List<String> names = new ArrayList<>();\r
+ for (Owner owner : owners) {\r
+ if (owner instanceof UserModel) {\r
+ names.add(((UserModel) owner).username);\r
+ }\r
+ }\r
+ result = names;\r
+ } else if (RpcRequest.SET_REPOSITORY_OWNERS.equals(reqType)) {\r
+ // set the owners for the specified repository\r
+ RepositoryModel model = gitblit.getRepositoryModel(objectName);\r
+ Collection<String> names = deserialize(request, response, RpcUtils.NAMES_TYPE);\r
+ List<Owner> owners = new ArrayList<>();\r
+ for (String name : names) {\r
+ UserModel owner = gitblit.getUserModel(name);\r
+ if (owner != null) {\r
+ owners.add(owner);\r
+ }\r
+ }\r
+ result = gitblit.setOwners(model, owners);\r
} else if (RpcRequest.LIST_REPOSITORY_MEMBER_PERMISSIONS.equals(reqType)) {\r
// get repository member permissions\r
RepositoryModel model = gitblit.getRepositoryModel(objectName);\r
continue;
}
TicketModel ticket = TicketModel.buildTicket(changes);
- ticket.project = repository.projectPath;
+ ticket.project = repository.getProject();
ticket.repository = repository.name;
ticket.number = ticketId;
}
TicketModel ticket = TicketModel.buildTicket(changes);
if (ticket != null) {
- ticket.project = repository.projectPath;
+ ticket.project = repository.getProject();
ticket.repository = repository.name;
ticket.number = ticketId;
}
continue;
}
TicketModel ticket = TicketModel.buildTicket(changes);
- ticket.project = repository.projectPath;
+ ticket.project = repository.getProject();
ticket.repository = repository.name;
ticket.number = ticketId;
}
TicketModel ticket = TicketModel.buildTicket(changes);
if (ticket != null) {
- ticket.project = repository.projectPath;
+ ticket.project = repository.getProject();
ticket.repository = repository.name;
ticket.number = ticketId;
}
continue;
}
TicketModel ticket = TicketModel.buildTicket(changes);
- ticket.project = repository.projectPath;
+ ticket.project = repository.getProject();
ticket.repository = repository.name;
ticket.number = ticketId;
return null;
}
TicketModel ticket = TicketModel.buildTicket(changes);
- ticket.project = repository.projectPath;
+ ticket.project = repository.getProject();
ticket.repository = repository.name;
ticket.number = ticketId;
log.debug("rebuilt ticket {} from Redis @ {}", ticketId, getUrl());
import com.gitblit.manager.IRuntimeManager;
import com.gitblit.manager.IUserManager;
import com.gitblit.models.Mailing;
+import com.gitblit.models.Owner;
import com.gitblit.models.PathModel.PathChangeModel;
import com.gitblit.models.RepositoryModel;
import com.gitblit.models.TicketModel;
//
Set<String> ccs = new TreeSet<String>();
- // repository owners
- if (!ArrayUtils.isEmpty(repository.owners)) {
- ccs.addAll(repository.owners);
- }
-
// cc users mentioned in last comment
Change lastChange = ticket.changes.get(ticket.changes.size() - 1);
if (lastChange.hasComment()) {
// TODO cc users who are watching the repository
Set<String> ccAddresses = new TreeSet<String>();
+
for (String name : ccs) {
UserModel user = userManager.getUserModel(name);
if (user != null && !user.disabled) {
}
}
+ // repository owners
+ for (Owner owner : userManager.getOwners(repository)) {
+ if (owner instanceof UserModel) {
+ UserModel user = (UserModel) owner;
+ if (!StringUtils.isEmpty(user.emailAddress)) {
+ ccAddresses.add(user.emailAddress);
+ }
+ }
+ }
+
// cc repository mailing list addresses
if (!ArrayUtils.isEmpty(repository.mailingLists)) {
ccAddresses.addAll(repository.mailingLists);
return userRepoPrefix;
}
+ /**
+ * Get the user project name for a user.
+ *
+ * @param username name of user
+ * @return the active user repository project prefix concatenated with the user name
+ */
+ public static String getPersonalProject(String username)
+ {
+ return userRepoPrefix + username.toLowerCase();
+ }
/**
* Get the user project name for a user.
*/
public static String getPersonalPath(String username)
{
- return userRepoPrefix + username.toLowerCase();
+ return userRepoPrefix + username.toLowerCase() + "/";
}
account, password);\r
}\r
\r
+ /**\r
+ * Retrieves the list of owners for the specified repository.\r
+ *\r
+ * @param repository\r
+ * @param serverUrl\r
+ * @param account\r
+ * @param password\r
+ * @return list of owners\r
+ * @throws IOException\r
+ */\r
+ public static List<String> getRepositoryOwners(RepositoryModel repository,\r
+ String serverUrl, String account, char [] password) throws IOException {\r
+ String url = asLink(serverUrl, RpcRequest.LIST_REPOSITORY_OWNERS, repository.name);\r
+ Collection<String> list = JsonUtils.retrieveJson(url, NAMES_TYPE, account, password);\r
+ return new ArrayList<String>(list);\r
+ }\r
+\r
+ /**\r
+ * Sets the repository owners\r
+ *\r
+ * @param repository\r
+ * @param owners\r
+ * @param serverUrl\r
+ * @param account\r
+ * @param password\r
+ * @return true if the action succeeded\r
+ * @throws IOException\r
+ */\r
+ public static boolean setRepositoryOwners(RepositoryModel repository,\r
+ List<String> owners, String serverUrl, String account, char[] password)\r
+ throws IOException {\r
+ return doAction(RpcRequest.SET_REPOSITORY_OWNERS, repository.name, owners, serverUrl,\r
+ account, password);\r
+ }\r
+\r
/**\r
* Retrieves the list of teams that can access the specified repository.\r
*\r
import com.gitblit.Constants.RegistrantType;\r
import com.gitblit.GitBlitException;\r
import com.gitblit.Keys;\r
+import com.gitblit.models.Owner;\r
import com.gitblit.models.RegistrantAccessPermission;\r
import com.gitblit.models.RepositoryModel;\r
import com.gitblit.models.UserChoice;\r
UserModel user = session.getUser();\r
if (user != null && user.canCreate() && !user.canAdmin()) {\r
// personal create permissions, inject personal repository path\r
- model.name = user.getPersonalPath() + "/";\r
- model.projectPath = user.getPersonalPath();\r
- model.addOwner(user.username);\r
+ model.name = user.getPersonalPath();\r
+\r
// personal repositories are private by default\r
model.accessRestriction = AccessRestrictionType.VIEW;\r
model.authorizationControl = AuthorizationControl.NAMED;\r
\r
GitBlitWebSession session = GitBlitWebSession.get();\r
final UserModel user = session.getUser() == null ? UserModel.ANONYMOUS : session.getUser();\r
- final boolean allowEditName = isCreate || isAdmin || repositoryModel.isUsersPersonalRepository(user.username);\r
\r
if (isCreate) {\r
if (user.canAdmin()) {\r
\r
// owners palette\r
List<UserChoice> owners = new ArrayList<UserChoice>();\r
- for (String owner : repositoryModel.owners) {\r
- UserModel o = app().users().getUserModel(owner);\r
- if (o != null) {\r
- owners.add(new UserChoice(o.getDisplayName(), o.username, o.emailAddress));\r
- } else {\r
- owners.add(new UserChoice(owner));\r
+ for (Owner owner : app().users().getOwners(repositoryModel)) {\r
+ if (owner instanceof UserModel) {\r
+ UserModel userOwner = (UserModel) owner;\r
+ owners.add(new UserChoice(userOwner.getDisplayName(), userOwner.username, userOwner.emailAddress));\r
}\r
}\r
List<UserChoice> persons = new ArrayList<UserChoice>();\r
}\r
repositoryModel.indexedBranches = indexedBranches;\r
\r
- // owners\r
- repositoryModel.owners.clear();\r
- Iterator<UserChoice> owners = ownersPalette.getSelectedChoices();\r
- while (owners.hasNext()) {\r
- repositoryModel.addOwner(owners.next().getUserId());\r
- }\r
-\r
// pre-receive scripts\r
List<String> preReceiveScripts = new ArrayList<String>();\r
Iterator<String> pres = preReceivePalette.getSelectedChoices();\r
app().gitblit().setUserAccessPermissions(repositoryModel, repositoryUsers);\r
app().gitblit().setTeamAccessPermissions(repositoryModel, repositoryTeams);\r
}\r
+\r
+ //\r
+ // handle ownership changes\r
+ //\r
+\r
+ List<Owner> newOwners = new ArrayList<>();\r
+ Iterator<UserChoice> owners = ownersPalette.getSelectedChoices();\r
+ while (owners.hasNext()) {\r
+ String username = owners.next().getUserId();\r
+ UserModel owner = app().users().getUserModel(username);\r
+ newOwners.add(owner);\r
+ }\r
+\r
+ app().users().setOwners(repositoryModel, newOwners);\r
+\r
} catch (GitBlitException e) {\r
error(e.getMessage());\r
return;\r
// GENERAL\r
//\r
namePanel = new RepositoryNamePanel("namePanel", repositoryModel);\r
- namePanel.setEditable(allowEditName);\r
form.add(namePanel);\r
\r
// XXX AccessPolicyPanel is defined later.\r
// the user can delete if deletions are allowed AND the user is an admin or the personal owner\r
// assigned ownership is not sufficient to allow deletion\r
boolean canDelete = !isCreate && app().repositories().canDelete(repositoryModel)\r
- && (user.canAdmin() || user.isMyPersonalRepository(repositoryModel.name));\r
+ && user.canDelete(repositoryModel);\r
\r
Link<Void> delete = new Link<Void>("delete") {\r
\r
info(MessageFormat.format(getString("gb.repositoryDeleted"), latestModel));\r
if (latestModel.isPersonalRepository()) {\r
// redirect to user's profile page\r
- String prefix = app().settings().getString(Keys.git.userRepositoryPrefix, "~");\r
- String username = latestModel.projectPath.substring(prefix.length());\r
+ String username = latestModel.getPersonalRepositoryOwner();\r
setResponsePage(UserPage.class, WicketUtils.newUsernameParameter(username));\r
} else {\r
// redirect to server repositories page\r
isAdmin = true;\r
return;\r
} else {\r
- if (!model.isOwner(user.username)) {\r
+ if (!user.isOwner(model)) {\r
// User is not an Admin nor Owner\r
error(getString("gb.errorOnlyAdminOrOwnerMayEditRepository"), true);\r
}\r
import com.gitblit.models.ForkModel;\r
import com.gitblit.models.RepositoryModel;\r
import com.gitblit.models.UserModel;\r
+import com.gitblit.utils.ModelUtils;\r
import com.gitblit.utils.StringUtils;\r
import com.gitblit.wicket.GitBlitWebSession;\r
import com.gitblit.wicket.WicketUtils;\r
RepositoryModel repository = fork.repository;\r
\r
if (repository.isPersonalRepository()) {\r
- UserModel user = app().users().getUserModel(repository.projectPath.substring(1));\r
+ String name = ModelUtils.getUserNameFromRepoPath(repository.name);\r
+ UserModel user = app().users().getUserModel(name);\r
if (user == null) {\r
// user account no longer exists\r
- user = new UserModel(repository.projectPath.substring(1));\r
+ user = new UserModel(name);\r
}\r
PersonIdent ident = new PersonIdent(user.getDisplayName(), user.emailAddress == null ? user.getDisplayName() : user.emailAddress);\r
item.add(new GravatarImage("anAvatar", ident, 20));\r
WicketUtils.setCssClass(swatch, "repositorySwatch");\r
WicketUtils.setCssBackground(swatch, repository.toString());\r
item.add(swatch);\r
- String projectName = repository.projectPath;\r
+ String projectName = repository.getProject();\r
if (StringUtils.isEmpty(projectName)) {\r
projectName = app().settings().getString(Keys.web.repositoryRootGroupName, "main");\r
}\r
List<RepositoryModel> active = new ArrayList<RepositoryModel>();\r
\r
for (RepositoryModel model : getRepositoryModels()) {\r
- if (model.isUsersPersonalRepository(user.username) || model.isOwner(user.username)) {\r
+ if (user.isOwner(model)) {\r
owned.add(model);\r
}\r
\r
import java.io.IOException;\r
import java.io.UnsupportedEncodingException;\r
import java.util.ArrayList;\r
+import java.util.Arrays;\r
import java.util.Collections;\r
import java.util.List;\r
\r
import com.gitblit.Constants.AuthorizationControl;\r
import com.gitblit.GitBlitException;\r
import com.gitblit.Keys;\r
+import com.gitblit.models.Owner;\r
import com.gitblit.models.RepositoryModel;\r
import com.gitblit.models.UserModel;\r
import com.gitblit.utils.ArrayUtils;\r
}\r
accessPolicyPanel.updateModel(repositoryModel);\r
\r
- repositoryModel.owners = new ArrayList<String>();\r
- repositoryModel.owners.add(GitBlitWebSession.get().getUsername());\r
-\r
// setup branch defaults\r
boolean useGitFlow = addGitflowModel.getObject();\r
\r
// init the repository\r
app().gitblit().updateRepositoryModel(repositoryModel.name, repositoryModel, true);\r
\r
+ // save the owner change\r
+ List<Owner> owners = Arrays.asList((Owner) GitBlitWebSession.get().getUser());\r
+ app().gitblit().setOwners(repositoryModel, owners);\r
+\r
// optionally create an initial commit\r
initialCommit(repositoryModel, addReadme, gitignore, useGitFlow);\r
\r
package com.gitblit.wicket.pages;\r
\r
import java.text.MessageFormat;\r
-import java.util.ArrayList;\r
import java.util.List;\r
\r
import org.apache.wicket.PageParameters;\r
\r
import com.gitblit.Keys;\r
import com.gitblit.models.Metric;\r
+import com.gitblit.models.Owner;\r
import com.gitblit.models.RepositoryModel;\r
import com.gitblit.models.UserModel;\r
import com.gitblit.utils.JGitUtils;\r
add(new Label("repositoryDescription", getRepositoryModel().description));\r
\r
// owner links\r
- final List<String> owners = new ArrayList<String>(getRepositoryModel().owners);\r
- ListDataProvider<String> ownersDp = new ListDataProvider<String>(owners);\r
- DataView<String> ownersView = new DataView<String>("repositoryOwners", ownersDp) {\r
+ final List<Owner> owners = app().users().getOwners(getRepositoryModel());\r
+ ListDataProvider<Owner> ownersDp = new ListDataProvider<Owner>(owners);\r
+ DataView<Owner> ownersView = new DataView<Owner>("repositoryOwners", ownersDp) {\r
private static final long serialVersionUID = 1L;\r
int counter = 0;\r
@Override\r
- public void populateItem(final Item<String> item) {\r
- String ownername = item.getModelObject();\r
- UserModel ownerModel = app().users().getUserModel(ownername);\r
- if (ownerModel != null) {\r
- item.add(new LinkPanel("owner", null, ownerModel.getDisplayName(), UserPage.class,\r
- WicketUtils.newUsernameParameter(ownerModel.username)).setRenderBodyOnly(true));\r
- } else {\r
- Label owner = new Label("owner", ownername);\r
- WicketUtils.setCssStyle(owner, "text-decoration: line-through;");\r
- WicketUtils.setHtmlTooltip(owner, MessageFormat.format(getString("gb.failedToFindAccount"), ownername));\r
- item.add(owner);\r
+ public void populateItem(final Item<Owner> item) {\r
+ Owner owner = item.getModelObject();\r
+ if (owner instanceof UserModel) {\r
+ UserModel user = (UserModel) owner;\r
+ item.add(new LinkPanel("owner", null, user.getDisplayName(), UserPage.class,\r
+ WicketUtils.newUsernameParameter(user.username)).setRenderBodyOnly(true));\r
}\r
counter++;\r
item.add(new Label("comma", ",").setVisible(counter < owners.size()));\r
&& app().settings().getBoolean(Keys.web.generateActivityGraph, true)) {\r
\r
Charts charts = new Flotr2Charts();\r
- \r
+\r
// daily line chart\r
Chart chart = charts.createLineChart("chartDaily", "", "unit",\r
getString("gb.commits"));\r
showAdmin = app().settings().getBoolean(Keys.web.allowAdministration, false);\r
}\r
isOwner = GitBlitWebSession.get().isLoggedIn()\r
- && (getRepositoryModel().isOwner(GitBlitWebSession.get().getUsername()));\r
+ && (GitBlitWebSession.get().getUser().isOwner(getRepositoryModel()));\r
\r
// register the available navigation links for this page and user\r
List<NavLink> navLinks = registerNavLinks();\r
String userName = WicketUtils.getUsername(params);
if (StringUtils.isEmpty(projectName)) {
if (!StringUtils.isEmpty(userName)) {
- projectName = ModelUtils.getPersonalPath(userName);
+ projectName = ModelUtils.getPersonalProject(userName);
}
}
String repositoryName = WicketUtils.getRepositoryName(params);
RepositoryModel repositoryModel = app().repositories().getRepositoryModel(repo);\r
if (repositoryModel.accessRestriction.exceeds(AccessRestrictionType.NONE)\r
&& repositoryModel.authorizationControl.equals(AuthorizationControl.NAMED)) {\r
- if (user != null &&\r
- (repositoryModel.isOwner(user.username) || repositoryModel.isUsersPersonalRepository(user.username))) {\r
+ if (user != null && user.isOwner(repositoryModel)) {\r
// exclude Owner or personal repositories\r
continue;\r
}\r
if (includeWildcards) {\r
- if (lastProject == null || !lastProject.equalsIgnoreCase(repositoryModel.projectPath)) {\r
- lastProject = repositoryModel.projectPath.toLowerCase();\r
- if (!StringUtils.isEmpty(repositoryModel.projectPath)) {\r
+ if (lastProject == null || !lastProject.equalsIgnoreCase(repositoryModel.getProject())) {\r
+ lastProject = repositoryModel.getProject().toLowerCase();\r
+ if (!StringUtils.isEmpty(repositoryModel.getProject())) {\r
// regex for all repositories within a project\r
- repos.add(repositoryModel.projectPath + "/.*");\r
+ repos.add(repositoryModel.getProjectPath() + "/.*");\r
}\r
}\r
}\r
import java.text.MessageFormat;\r
import java.text.ParseException;\r
import java.text.SimpleDateFormat;\r
-import java.util.ArrayList;\r
import java.util.Date;\r
import java.util.List;\r
\r
\r
import com.gitblit.Keys;\r
import com.gitblit.models.Metric;\r
+import com.gitblit.models.Owner;\r
import com.gitblit.models.RepositoryModel;\r
import com.gitblit.models.UserModel;\r
import com.gitblit.utils.JGitUtils;\r
add(new Label("repositoryDescription", getRepositoryModel().description));\r
\r
// owner links\r
- final List<String> owners = new ArrayList<String>(getRepositoryModel().owners);\r
- ListDataProvider<String> ownersDp = new ListDataProvider<String>(owners);\r
- DataView<String> ownersView = new DataView<String>("repositoryOwners", ownersDp) {\r
+ final List<Owner> owners = app().users().getOwners(getRepositoryModel());\r
+ ListDataProvider<Owner> ownersDp = new ListDataProvider<>(owners);\r
+ DataView<Owner> ownersView = new DataView<Owner>("repositoryOwners", ownersDp) {\r
private static final long serialVersionUID = 1L;\r
int counter = 0;\r
@Override\r
- public void populateItem(final Item<String> item) {\r
- String ownername = item.getModelObject();\r
- UserModel ownerModel = app().users().getUserModel(ownername);\r
- if (ownerModel != null) {\r
+ public void populateItem(final Item<Owner> item) {\r
+ Owner owner = item.getModelObject();\r
+ if (owner instanceof UserModel) {\r
+ UserModel ownerModel = (UserModel) owner;\r
item.add(new LinkPanel("owner", null, ownerModel.getDisplayName(), UserPage.class,\r
WicketUtils.newUsernameParameter(ownerModel.username)).setRenderBodyOnly(true));\r
- } else {\r
- Label owner = new Label("owner", ownername);\r
- WicketUtils.setCssStyle(owner, "text-decoration: line-through;");\r
- WicketUtils.setHtmlTooltip(owner, MessageFormat.format(getString("gb.failedToFindAccount"), ownername));\r
- item.add(owner);\r
}\r
counter++;\r
item.add(new Label("comma", ",").setVisible(counter < owners.size()));\r
*/\r
package com.gitblit.wicket.panels;\r
\r
+import java.util.List;\r
import java.util.Map;\r
\r
import org.apache.wicket.Component;\r
\r
import com.gitblit.Constants.AccessRestrictionType;\r
import com.gitblit.Keys;\r
+import com.gitblit.models.Owner;\r
import com.gitblit.models.RepositoryModel;\r
import com.gitblit.models.UserModel;\r
import com.gitblit.servlet.SyndicationServlet;\r
swatch.setVisible(showSwatch);\r
\r
PageParameters pp = WicketUtils.newRepositoryParameter(entry.name);\r
- add(new LinkPanel("repositoryName", "list", StringUtils.getRelativePath(entry.projectPath,\r
+ add(new LinkPanel("repositoryName", "list", StringUtils.getRelativePath(entry.getProject(),\r
StringUtils.stripDotGit(entry.name)), SummaryPage.class, pp));\r
add(new Label("repositoryDescription", entry.description).setVisible(!StringUtils\r
.isEmpty(entry.description)));\r
add(WicketUtils.newClearPixel("federatedIcon").setVisible(false));\r
}\r
\r
- if (ArrayUtils.isEmpty(entry.owners)) {\r
+ List<Owner> owners = app().users().getOwners(entry);\r
+ if (ArrayUtils.isEmpty(owners)) {\r
add(new Label("repositoryOwner").setVisible(false));\r
} else {\r
- String owner = "";\r
- for (String username : entry.owners) {\r
- UserModel ownerModel = app().users().getUserModel(username);\r
-\r
- if (ownerModel != null) {\r
- owner = ownerModel.getDisplayName();\r
- }\r
- }\r
- if (entry.owners.size() > 1) {\r
+ String owner = owners.get(0).getDisplayName();\r
+ if (owners.size() > 1) {\r
owner += ", ...";\r
}\r
Label ownerLabel = (new Label("repositoryOwner", owner + " (" +\r
localizer.getString("gb.owner", parent) + ")"));\r
- WicketUtils.setHtmlTooltip(ownerLabel, ArrayUtils.toString(entry.owners));\r
+ WicketUtils.setHtmlTooltip(ownerLabel, ArrayUtils.toString(owners));\r
add(ownerLabel);\r
}\r
\r
\r
import com.gitblit.Constants.AccessRestrictionType;\r
import com.gitblit.Keys;\r
+import com.gitblit.models.Owner;\r
import com.gitblit.models.ProjectModel;\r
import com.gitblit.models.RepositoryModel;\r
import com.gitblit.models.UserModel;\r
row.add(WicketUtils.newBlankImage("accessRestrictionIcon"));\r
}\r
\r
+ List<Owner> owners = app().users().getOwners(entry);\r
+ // display first owner\r
String owner = "";\r
- if (!ArrayUtils.isEmpty(entry.owners)) {\r
- // display first owner\r
- for (String username : entry.owners) {\r
- UserModel ownerModel = app().users().getUserModel(username);\r
- if (ownerModel != null) {\r
- owner = ownerModel.getDisplayName();\r
- break;\r
- }\r
- }\r
- if (entry.owners.size() > 1) {\r
+ if (!owners.isEmpty()) {\r
+ owner = owners.get(0).getDisplayName();\r
+ if (owners.size() > 1) {\r
owner += ", ...";\r
}\r
}\r
Label ownerLabel = new Label("repositoryOwner", owner);\r
- WicketUtils.setHtmlTooltip(ownerLabel, ArrayUtils.toString(entry.owners));\r
+ WicketUtils.setHtmlTooltip(ownerLabel, ArrayUtils.toString(owners));\r
row.add(ownerLabel);\r
\r
String lastChange;\r
String title;\r
\r
GroupRepositoryModel(String name, int count) {\r
- super(name, "", "", new Date(0));\r
+ super(name, "", new Date(0));\r
this.count = count;\r
}\r
\r
return o2.name.compareTo(o1.name);\r
}\r
});\r
- } else if (prop.equals(SortBy.owner.name())) {\r
- Collections.sort(list, new Comparator<RepositoryModel>() {\r
- @Override\r
- public int compare(RepositoryModel o1, RepositoryModel o2) {\r
- String own1 = ArrayUtils.toString(o1.owners);\r
- String own2 = ArrayUtils.toString(o2.owners);\r
- if (asc) {\r
- return own1.compareTo(own2);\r
- }\r
- return own2.compareTo(own1);\r
- }\r
- });\r
} else if (prop.equals(SortBy.description.name())) {\r
Collections.sort(list, new Comparator<RepositoryModel>() {\r
@Override\r
-/*\r
- * Copyright 2014 gitblit.com.\r
- *\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-package com.gitblit.wicket.panels;\r
-\r
-import java.text.MessageFormat;\r
-import java.util.ArrayList;\r
-import java.util.Set;\r
-import java.util.TreeSet;\r
-\r
-import org.apache.wicket.markup.html.form.DropDownChoice;\r
-import org.apache.wicket.markup.html.form.TextField;\r
-import org.apache.wicket.model.IModel;\r
-import org.apache.wicket.model.Model;\r
-\r
-import com.gitblit.models.ProjectModel;\r
-import com.gitblit.models.RepositoryModel;\r
-import com.gitblit.models.UserModel;\r
-import com.gitblit.utils.StringUtils;\r
-import com.gitblit.wicket.GitBlitWebSession;\r
-\r
-/**\r
- * A panel for naming a repository, specifying it's project, and entering a description.\r
- *\r
- * @author James Moger\r
- *\r
- */\r
-public class RepositoryNamePanel extends BasePanel {\r
-\r
- private static final long serialVersionUID = 1L;\r
-\r
- private String fullName;\r
-\r
- private final IModel<String> projectPath;\r
-\r
- private DropDownChoice<String> pathChoice;\r
-\r
- private final IModel<String> repoName;\r
-\r
- private TextField<String> nameField;\r
-\r
- public RepositoryNamePanel(String wicketId, RepositoryModel repository) {\r
- super(wicketId);\r
-\r
- GitBlitWebSession session = GitBlitWebSession.get();\r
- UserModel user = session.getUser();\r
-\r
- // build project set for repository destination\r
- String defaultPath = null;\r
- String defaultName = null;\r
- Set<String> pathNames = new TreeSet<String>();\r
-\r
- // add the registered/known projects\r
- for (ProjectModel project : app().projects().getProjectModels(user, false)) {\r
- // TODO issue-351: user.canAdmin(project)\r
- if (user.canAdmin()) {\r
- if (project.isRoot) {\r
- pathNames.add("/");\r
- } else {\r
- pathNames.add(project.name + "/");\r
- }\r
- }\r
- }\r
-\r
- // add the user's personal project namespace\r
- if (user.canAdmin() || user.canCreate()) {\r
- pathNames.add(user.getPersonalPath() + "/");\r
- }\r
-\r
- if (!StringUtils.isEmpty(repository.name)) {\r
- // editing a repository name\r
- // set the defaultProject to the current repository project\r
- if (StringUtils.isEmpty(repository.projectPath)) {\r
- defaultPath = "/";\r
- defaultName = repository.name;\r
- } else {\r
- defaultPath = repository.projectPath + "/";\r
- defaultName = repository.name.substring(defaultPath.length());\r
- }\r
- pathNames.add(defaultPath);\r
- }\r
-\r
- // if default project is not already set, set preference based on the user permissions\r
- if (defaultPath == null) {\r
- if (user.canAdmin()) {\r
- defaultPath = "/";\r
- } else if (user.canCreate()) {\r
- defaultPath = user.getPersonalPath() + "/";\r
- }\r
- }\r
-\r
- projectPath = Model.of(defaultPath);\r
- pathChoice = new DropDownChoice<String>("projectPath", projectPath, new ArrayList<String>(pathNames));\r
- repoName = Model.of(defaultName);\r
- nameField = new TextField<String>("name", repoName);\r
-\r
- // only enable project selection if we actually have multiple choices\r
- add(pathChoice.setEnabled(pathNames.size() > 1));\r
- add(nameField);\r
- add(new TextField<String>("description"));\r
- }\r
-\r
- public void setEditable(boolean editable) {\r
- // only enable project selection if we actually have multiple choices\r
- pathChoice.setEnabled(pathChoice.getChoices().size() > 1 && editable);\r
- nameField.setEnabled(editable);\r
- }\r
-\r
- public boolean updateModel(RepositoryModel repositoryModel) {\r
- // confirm a project path was selected\r
- if (StringUtils.isEmpty(projectPath.getObject())) {\r
- error(getString("gb.pleaseSelectProject"));\r
- return false;\r
- }\r
-\r
- // confirm a repository name was entered\r
- if (StringUtils.isEmpty(repoName.getObject())) {\r
- error(getString("gb.pleaseSetRepositoryName"));\r
- return false;\r
- }\r
-\r
- String project = projectPath.getObject();\r
- String name = repoName.getObject();\r
-\r
- fullName = (project + name).trim();\r
- fullName = fullName.replace('\\', '/');\r
- fullName = fullName.replace("//", "/");\r
- if (fullName.charAt(0) == '/') {\r
- fullName = fullName.substring(1);\r
- }\r
- if (fullName.endsWith("/")) {\r
- fullName = fullName.substring(0, fullName.length() - 1);\r
- }\r
-\r
- if (fullName.contains("../")) {\r
- error(getString("gb.illegalRelativeSlash"));\r
- return false;\r
- }\r
- if (fullName.contains("/../")) {\r
- error(getString("gb.illegalRelativeSlash"));\r
- return false;\r
- }\r
-\r
- // confirm valid characters in repository name\r
- Character c = StringUtils.findInvalidCharacter(fullName);\r
- if (c != null) {\r
- error(MessageFormat.format(getString("gb.illegalCharacterRepositoryName"), c));\r
- return false;\r
- }\r
-\r
- repositoryModel.name = fullName;\r
-\r
- return true;\r
- }\r
-\r
- @Override\r
- protected boolean getStatelessHint() {\r
- return false;\r
- }\r
+/*
+ * Copyright 2014 gitblit.com.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.gitblit.wicket.panels;
+
+import java.text.MessageFormat;
+import java.util.ArrayList;
+import java.util.Set;
+import java.util.TreeSet;
+
+import org.apache.wicket.markup.html.form.DropDownChoice;
+import org.apache.wicket.markup.html.form.TextField;
+import org.apache.wicket.model.IModel;
+import org.apache.wicket.model.Model;
+
+import com.gitblit.models.ProjectModel;
+import com.gitblit.models.RepositoryModel;
+import com.gitblit.models.UserModel;
+import com.gitblit.utils.StringUtils;
+import com.gitblit.wicket.GitBlitWebSession;
+
+/**
+ * A panel for naming a repository, specifying it's project, and entering a description.
+ *
+ * @author James Moger
+ *
+ */
+public class RepositoryNamePanel extends BasePanel {
+
+ private static final long serialVersionUID = 1L;
+
+ private String fullName;
+
+ private final IModel<String> projectPath;
+
+ private DropDownChoice<String> pathChoice;
+
+ private final IModel<String> repoName;
+
+ private TextField<String> nameField;
+
+ public RepositoryNamePanel(String wicketId, RepositoryModel repository) {
+ super(wicketId);
+
+ GitBlitWebSession session = GitBlitWebSession.get();
+ UserModel user = session.getUser();
+
+ // build project set for repository destination
+ String defaultPath = null;
+ String defaultName = null;
+ Set<String> pathNames = new TreeSet<String>();
+
+// // add all specified project paths
+// if (user.ownerOf != null) {
+// for (String path : user.ownerOf) {
+// if (path.charAt(path.length() - 1) == '/') {
+// projectNames.add(path);
+// }
+// }
+// }
+//
+ // add the registered/known projects
+ for (ProjectModel project : app().projects().getProjectModels(user, false)) {
+ // TODO issue-351: user.canAdmin(project)
+ if (user.canAdmin()) {
+ if (project.isRoot) {
+ pathNames.add("/");
+ } else {
+ pathNames.add(project.name + "/");
+ }
+ }
+ }
+
+ // add the user's personal project namespace
+ if (user.canAdmin() || user.canCreate()) {
+ pathNames.add(user.getPersonalPath());
+ }
+
+ if (!StringUtils.isEmpty(repository.name)) {
+ // editing a repository name
+ // set the defaultProject to the current repository project
+ defaultPath = repository.getProjectPath();
+ defaultName = repository.name.substring(defaultPath.length());
+ pathNames.add(defaultPath);
+ }
+
+ // if default project is not already set, set preference based on the user permissions
+ if (defaultPath == null) {
+ if (user.canAdmin()) {
+ defaultPath = "/";
+ } else if (user.canCreate()) {
+ defaultPath = user.getPersonalPath();
+ }
+ }
+
+ projectPath = Model.of(defaultPath);
+ pathChoice = new DropDownChoice<String>("projectPath", projectPath, new ArrayList<String>(pathNames));
+ repoName = Model.of(defaultName);
+ nameField = new TextField<String>("name", repoName);
+
+ // only enable project selection if we actually have multiple choices
+ add(pathChoice.setEnabled(pathNames.size() > 1));
+ add(nameField);
+ add(new TextField<String>("description"));
+ }
+
+ public void setEditable(boolean editable) {
+ // only enable project selection if we actually have multiple choices
+ pathChoice.setEnabled(pathChoice.getChoices().size() > 1 && editable);
+ nameField.setEnabled(editable);
+ }
+
+ public boolean updateModel(RepositoryModel repositoryModel) {
+ // confirm a project path was selected
+ if (StringUtils.isEmpty(projectPath.getObject())) {
+ error(getString("gb.pleaseSelectProject"));
+ return false;
+ }
+
+ // confirm a repository name was entered
+ if (StringUtils.isEmpty(repoName.getObject())) {
+ error(getString("gb.pleaseSetRepositoryName"));
+ return false;
+ }
+
+ String project = projectPath.getObject();
+ String name = repoName.getObject();
+
+ fullName = (project + name).trim();
+ fullName = fullName.replace('\\', '/');
+ fullName = fullName.replace("//", "/");
+ if (fullName.charAt(0) == '/') {
+ fullName = fullName.substring(1);
+ }
+ if (fullName.endsWith("/")) {
+ fullName = fullName.substring(0, fullName.length() - 1);
+ }
+
+ if (fullName.contains("../")) {
+ error(getString("gb.illegalRelativeSlash"));
+ return false;
+ }
+ if (fullName.contains("/../")) {
+ error(getString("gb.illegalRelativeSlash"));
+ return false;
+ }
+
+ // confirm valid characters in repository name
+ Character c = StringUtils.findInvalidCharacter(fullName);
+ if (c != null) {
+ error(MessageFormat.format(getString("gb.illegalCharacterRepositoryName"), c));
+ return false;
+ }
+
+ repositoryModel.name = fullName;
+
+ return true;
+ }
+
+ @Override
+ protected boolean getStatelessHint() {
+ return false;
+ }
}
\ No newline at end of file
emailMeOnMyTicketChanges = true
role = "#admin"
role = "#notfederated"
+ owns = ~admin/helloworld.git
[team "admins"]
role = "#none"
accountType = LOCAL
*/
public class BranchTicketServiceTest extends TicketServiceTest {
- final RepositoryModel repo = new RepositoryModel("tickets/branch.git", null, null, null);
+ final RepositoryModel repo = new RepositoryModel("tickets/branch.git", null, null);
@Override
protected RepositoryModel getRepository() {
model.accessRestriction = AccessRestrictionType.VIEW;\r
model.description = "cloneable repository " + i;\r
model.lastChange = new Date();\r
- model.addOwner("adminuser");\r
model.name = "repo" + i + ".git";\r
model.size = "5 MB";\r
model.hasCommits = true;\r
*/
public class FileTicketServiceTest extends TicketServiceTest {
- final RepositoryModel repo = new RepositoryModel("tickets/file.git", null, null, null);
+ final RepositoryModel repo = new RepositoryModel("tickets/file.git", null, null);
@Override
protected RepositoryModel getRepository() {
import com.gitblit.models.RefLogEntry;\r
import com.gitblit.models.RepositoryModel;\r
import com.gitblit.models.UserModel;\r
-import com.gitblit.utils.ArrayUtils;\r
import com.gitblit.utils.JGitUtils;\r
import com.gitblit.utils.RefLogUtils;\r
\r
\r
// confirm default personal repository permissions\r
RepositoryModel model = repositories().getRepositoryModel(MessageFormat.format("~{0}/ticgit.git", user.username));\r
- assertEquals("Unexpected owner", user.username, ArrayUtils.toString(model.owners));\r
+ user = gitblit().getUserModel(user.username);\r
+ assertTrue("Unexpected owner", user.isOwner(model));\r
assertEquals("Unexpected authorization control", AuthorizationControl.NAMED, model.authorizationControl);\r
assertEquals("Unexpected access restriction", AccessRestrictionType.VIEW, model.accessRestriction);\r
\r
\r
// confirm default project repository permissions\r
RepositoryModel model = repositories().getRepositoryModel("project/ticgit.git");\r
- assertEquals("Unexpected owner", user.username, ArrayUtils.toString(model.owners));\r
+ user = gitblit().getUserModel(user.username);\r
+ assertTrue("Unexpected owner", user.isOwner(model));\r
assertEquals("Unexpected authorization control", AuthorizationControl.fromName(settings().getString(Keys.git.defaultAuthorizationControl, "NAMED")), model.authorizationControl);\r
assertEquals("Unexpected access restriction", AccessRestrictionType.fromName(settings().getString(Keys.git.defaultAccessRestriction, "NONE")), model.accessRestriction);\r
\r
commands.add(new ReceiveCommand(ObjectId.zeroId(), ObjectId\r
.fromString("3fa7c46d11b11d61f1cbadc6888be5d0eae21969"), "refs/heads/master"));\r
\r
- RepositoryModel repository = new RepositoryModel("ex@mple.git", "", "admin", new Date());\r
+ RepositoryModel repository = new RepositoryModel("ex@mple.git", "", new Date());\r
\r
test("protect-refs.groovy", gitblit, logger, clientLogger, commands, repository);\r
}\r
commands.add(new ReceiveCommand(ObjectId.zeroId(), ObjectId\r
.fromString("3fa7c46d11b11d61f1cbadc6888be5d0eae21969"), "refs/tags/v1.0"));\r
\r
- RepositoryModel repository = new RepositoryModel("ex@mple.git", "", "admin", new Date());\r
+ RepositoryModel repository = new RepositoryModel("ex@mple.git", "", new Date());\r
\r
test("protect-refs.groovy", gitblit, logger, clientLogger, commands, repository);\r
assertEquals(0, logger.messages.size());\r
.fromString("c18877690322dfc6ae3e37bb7f7085a24e94e887"), ObjectId\r
.fromString("3fa7c46d11b11d61f1cbadc6888be5d0eae21969"), "refs/heads/master"));\r
\r
- RepositoryModel repository = new RepositoryModel("ex@mple.git", "", "admin", new Date());\r
+ RepositoryModel repository = new RepositoryModel("ex@mple.git", "", new Date());\r
\r
test("protect-refs.groovy", gitblit, logger, clientLogger, commands, repository);\r
assertEquals(0, logger.messages.size());\r
"refs/heads/master");\r
commands.add(command);\r
\r
- RepositoryModel repository = new RepositoryModel("ex@mple.git", "", "admin", new Date());\r
+ RepositoryModel repository = new RepositoryModel("ex@mple.git", "", new Date());\r
\r
test("protect-refs.groovy", gitblit, logger, clientLogger, commands, repository);\r
assertEquals(ReceiveCommand.Result.REJECTED_NODELETE, command.getResult());\r
.fromString("3fa7c46d11b11d61f1cbadc6888be5d0eae21969"), ObjectId.zeroId(),\r
"refs/heads/other"));\r
\r
- RepositoryModel repository = new RepositoryModel("ex@mple.git", "", "admin", new Date());\r
+ RepositoryModel repository = new RepositoryModel("ex@mple.git", "", new Date());\r
\r
test("protect-refs.groovy", gitblit, logger, clientLogger, commands, repository);\r
assertEquals(0, logger.messages.size());\r
"refs/tags/v1.0");\r
commands.add(command);\r
\r
- RepositoryModel repository = new RepositoryModel("ex@mple.git", "", "admin", new Date());\r
+ RepositoryModel repository = new RepositoryModel("ex@mple.git", "", new Date());\r
\r
test("protect-refs.groovy", gitblit, logger, clientLogger, commands, repository);\r
assertEquals(ReceiveCommand.Result.REJECTED_NODELETE, command.getResult());\r
.fromString("c18877690322dfc6ae3e37bb7f7085a24e94e887"), ObjectId\r
.fromString("3fa7c46d11b11d61f1cbadc6888be5d0eae21969"), "refs/heads/master"));\r
\r
- RepositoryModel repository = new RepositoryModel("ex@mple.git", "", "admin", new Date());\r
+ RepositoryModel repository = new RepositoryModel("ex@mple.git", "", new Date());\r
\r
try {\r
test("blockpush.groovy", gitblit, logger, clientLogger, commands, repository);\r
.fromString("c18877690322dfc6ae3e37bb7f7085a24e94e887"), ObjectId\r
.fromString("3fa7c46d11b11d61f1cbadc6888be5d0eae21969"), "refs/heads/master"));\r
\r
- RepositoryModel repository = new RepositoryModel("ex@mple.git", "", "admin", new Date());\r
+ RepositoryModel repository = new RepositoryModel("ex@mple.git", "", new Date());\r
\r
File groovyDir = repositories().getHooksFolder();\r
File tempScript = File.createTempFile("testClientLogging", "groovy", groovyDir);\r
import org.junit.Test;
import com.gitblit.Constants;
+import com.gitblit.models.UserModel;
import com.gitblit.utils.ModelUtils;
public class ModelUtilsTest extends GitblitUnitTest {
}
+ @Test
+ public void testGetPersonalProject()
+ {
+ String username = "rob";
+ assertEquals(Constants.DEFAULT_USER_REPOSITORY_PREFIX+username.toLowerCase(), ModelUtils.getPersonalProject(username));
+
+ username = "James";
+ assertEquals(Constants.DEFAULT_USER_REPOSITORY_PREFIX+username.toLowerCase(), ModelUtils.getPersonalProject(username));
+
+ ModelUtils.setUserRepoPrefix("usr/");
+ username = "noMan";
+ assertEquals("usr/"+username.toLowerCase(), ModelUtils.getPersonalProject(username));
+ }
+
+
@Test
public void testGetPersonalPath()
{
String username = "rob";
- assertEquals(Constants.DEFAULT_USER_REPOSITORY_PREFIX+username.toLowerCase(), ModelUtils.getPersonalPath(username));
+ assertEquals(Constants.DEFAULT_USER_REPOSITORY_PREFIX+username.toLowerCase() + "/", ModelUtils.getPersonalPath(username));
username = "James";
- assertEquals(Constants.DEFAULT_USER_REPOSITORY_PREFIX+username.toLowerCase(), ModelUtils.getPersonalPath(username));
+ assertEquals(Constants.DEFAULT_USER_REPOSITORY_PREFIX+username.toLowerCase() + "/", ModelUtils.getPersonalPath(username));
ModelUtils.setUserRepoPrefix("usr/");
username = "noMan";
- assertEquals("usr/"+username.toLowerCase(), ModelUtils.getPersonalPath(username));
+ assertEquals("usr/"+username.toLowerCase() + "/", ModelUtils.getPersonalPath(username));
}
assertEquals("fee", ModelUtils.getUserNameFromRepoPath(reponame));
}
+ @Test
+ public void testUserOwnership() {
+ ModelUtils.setUserRepoPrefix(Constants.DEFAULT_USER_REPOSITORY_PREFIX);
+ UserModel user = new UserModel("james");
+ user.own("test.git");
+ user.own("newyork/.*");
+
+ assertFalse(user.isOwner("test"));
+ assertTrue(user.isOwner("test.git"));
+ assertFalse(user.isOwner("newyork"));
+ assertTrue(user.isOwner("newyork/"));
+ assertTrue(user.isOwner("newyork/abc"));
+ assertTrue(user.isOwner("~james/"));
+ assertTrue(user.isOwner("~james/abc/123"));
+ }
}
user.canAdmin = true;
for (AccessRestrictionType ar : AccessRestrictionType.values()) {
- RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
+ RepositoryModel repository = new RepositoryModel("myrepo.git", null, new Date());
repository.authorizationControl = AuthorizationControl.NAMED;
repository.accessRestriction = ar;
*/
@Test
public void testAnonymous_NONE() throws Exception {
- RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
+ RepositoryModel repository = new RepositoryModel("myrepo.git", null, new Date());
repository.authorizationControl = AuthorizationControl.NAMED;
repository.accessRestriction = AccessRestrictionType.NONE;
@Test
public void testAnonymous_PUSH() throws Exception {
- RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
+ RepositoryModel repository = new RepositoryModel("myrepo.git", null, new Date());
repository.authorizationControl = AuthorizationControl.NAMED;
repository.accessRestriction = AccessRestrictionType.PUSH;
@Test
public void testAnonymous_CLONE() throws Exception {
- RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
+ RepositoryModel repository = new RepositoryModel("myrepo.git", null, new Date());
repository.authorizationControl = AuthorizationControl.NAMED;
repository.accessRestriction = AccessRestrictionType.CLONE;
@Test
public void testAnonymous_VIEW() throws Exception {
- RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
+ RepositoryModel repository = new RepositoryModel("myrepo.git", null, new Date());
repository.authorizationControl = AuthorizationControl.NAMED;
repository.accessRestriction = AccessRestrictionType.VIEW;
*/
@Test
public void testAuthenticated_NONE() throws Exception {
- RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
+ RepositoryModel repository = new RepositoryModel("myrepo.git", null, new Date());
repository.authorizationControl = AuthorizationControl.AUTHENTICATED;
repository.accessRestriction = AccessRestrictionType.NONE;
@Test
public void testAuthenticated_PUSH() throws Exception {
- RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
+ RepositoryModel repository = new RepositoryModel("myrepo.git", null, new Date());
repository.authorizationControl = AuthorizationControl.AUTHENTICATED;
repository.accessRestriction = AccessRestrictionType.PUSH;
@Test
public void testAuthenticated_CLONE() throws Exception {
- RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
+ RepositoryModel repository = new RepositoryModel("myrepo.git", null, new Date());
repository.authorizationControl = AuthorizationControl.AUTHENTICATED;
repository.accessRestriction = AccessRestrictionType.CLONE;
@Test
public void testAuthenticated_VIEW() throws Exception {
- RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
+ RepositoryModel repository = new RepositoryModel("myrepo.git", null, new Date());
repository.authorizationControl = AuthorizationControl.AUTHENTICATED;
repository.accessRestriction = AccessRestrictionType.VIEW;
*/
@Test
public void testNamed_NONE_NONE() throws Exception {
- RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
+ RepositoryModel repository = new RepositoryModel("myrepo.git", null, new Date());
repository.authorizationControl = AuthorizationControl.NAMED;
repository.accessRestriction = AccessRestrictionType.NONE;
*/
@Test
public void testNamed_PUSH_NONE() throws Exception {
- RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
+ RepositoryModel repository = new RepositoryModel("myrepo.git", null, new Date());
repository.authorizationControl = AuthorizationControl.NAMED;
repository.accessRestriction = AccessRestrictionType.PUSH;
*/
@Test
public void testNamed_CLONE_NONE() throws Exception {
- RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
+ RepositoryModel repository = new RepositoryModel("myrepo.git", null, new Date());
repository.authorizationControl = AuthorizationControl.NAMED;
repository.accessRestriction = AccessRestrictionType.CLONE;
*/
@Test
public void testNamed_VIEW_NONE() throws Exception {
- RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
+ RepositoryModel repository = new RepositoryModel("myrepo.git", null, new Date());
repository.authorizationControl = AuthorizationControl.NAMED;
repository.accessRestriction = AccessRestrictionType.VIEW;
*/
@Test
public void testNamed_NONE_VIEW() throws Exception {
- RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
+ RepositoryModel repository = new RepositoryModel("myrepo.git", null, new Date());
repository.authorizationControl = AuthorizationControl.NAMED;
repository.accessRestriction = AccessRestrictionType.NONE;
*/
@Test
public void testNamed_PUSH_VIEW() throws Exception {
- RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
+ RepositoryModel repository = new RepositoryModel("myrepo.git", null, new Date());
repository.authorizationControl = AuthorizationControl.NAMED;
repository.accessRestriction = AccessRestrictionType.PUSH;
*/
@Test
public void testNamed_CLONE_VIEW() throws Exception {
- RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
+ RepositoryModel repository = new RepositoryModel("myrepo.git", null, new Date());
repository.authorizationControl = AuthorizationControl.NAMED;
repository.accessRestriction = AccessRestrictionType.CLONE;
*/
@Test
public void testNamed_VIEW_VIEW() throws Exception {
- RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
+ RepositoryModel repository = new RepositoryModel("myrepo.git", null, new Date());
repository.authorizationControl = AuthorizationControl.NAMED;
repository.accessRestriction = AccessRestrictionType.VIEW;
*/
@Test
public void testNamed_NONE_CLONE() throws Exception {
- RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
+ RepositoryModel repository = new RepositoryModel("myrepo.git", null, new Date());
repository.authorizationControl = AuthorizationControl.NAMED;
repository.accessRestriction = AccessRestrictionType.NONE;
*/
@Test
public void testNamed_PUSH_CLONE() throws Exception {
- RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
+ RepositoryModel repository = new RepositoryModel("myrepo.git", null, new Date());
repository.authorizationControl = AuthorizationControl.NAMED;
repository.accessRestriction = AccessRestrictionType.PUSH;
*/
@Test
public void testNamed_CLONE_CLONE() throws Exception {
- RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
+ RepositoryModel repository = new RepositoryModel("myrepo.git", null, new Date());
repository.authorizationControl = AuthorizationControl.NAMED;
repository.accessRestriction = AccessRestrictionType.CLONE;
*/
@Test
public void testNamed_VIEW_CLONE() throws Exception {
- RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
+ RepositoryModel repository = new RepositoryModel("myrepo.git", null, new Date());
repository.authorizationControl = AuthorizationControl.NAMED;
repository.accessRestriction = AccessRestrictionType.VIEW;
*/
@Test
public void testNamed_NONE_PUSH() throws Exception {
- RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
+ RepositoryModel repository = new RepositoryModel("myrepo.git", null, new Date());
repository.authorizationControl = AuthorizationControl.NAMED;
repository.accessRestriction = AccessRestrictionType.NONE;
*/
@Test
public void testNamed_PUSH_PUSH() throws Exception {
- RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
+ RepositoryModel repository = new RepositoryModel("myrepo.git", null, new Date());
repository.authorizationControl = AuthorizationControl.NAMED;
repository.accessRestriction = AccessRestrictionType.PUSH;
*/
@Test
public void testNamed_CLONE_PUSH() throws Exception {
- RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
+ RepositoryModel repository = new RepositoryModel("myrepo.git", null, new Date());
repository.authorizationControl = AuthorizationControl.NAMED;
repository.accessRestriction = AccessRestrictionType.CLONE;
*/
@Test
public void testNamed_VIEW_PUSH() throws Exception {
- RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
+ RepositoryModel repository = new RepositoryModel("myrepo.git", null, new Date());
repository.authorizationControl = AuthorizationControl.NAMED;
repository.accessRestriction = AccessRestrictionType.VIEW;
*/
@Test
public void testNamed_NONE_CREATE() throws Exception {
- RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
+ RepositoryModel repository = new RepositoryModel("myrepo.git", null, new Date());
repository.authorizationControl = AuthorizationControl.NAMED;
repository.accessRestriction = AccessRestrictionType.NONE;
*/
@Test
public void testNamed_PUSH_CREATE() throws Exception {
- RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
+ RepositoryModel repository = new RepositoryModel("myrepo.git", null, new Date());
repository.authorizationControl = AuthorizationControl.NAMED;
repository.accessRestriction = AccessRestrictionType.PUSH;
*/
@Test
public void testNamed_CLONE_CREATE() throws Exception {
- RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
+ RepositoryModel repository = new RepositoryModel("myrepo.git", null, new Date());
repository.authorizationControl = AuthorizationControl.NAMED;
repository.accessRestriction = AccessRestrictionType.CLONE;
*/
@Test
public void testNamed_VIEW_CREATE() throws Exception {
- RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
+ RepositoryModel repository = new RepositoryModel("myrepo.git", null, new Date());
repository.authorizationControl = AuthorizationControl.NAMED;
repository.accessRestriction = AccessRestrictionType.VIEW;
*/
@Test
public void testNamed_NONE_DELETE() throws Exception {
- RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
+ RepositoryModel repository = new RepositoryModel("myrepo.git", null, new Date());
repository.authorizationControl = AuthorizationControl.NAMED;
repository.accessRestriction = AccessRestrictionType.NONE;
*/
@Test
public void testNamed_PUSH_DELETE() throws Exception {
- RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
+ RepositoryModel repository = new RepositoryModel("myrepo.git", null, new Date());
repository.authorizationControl = AuthorizationControl.NAMED;
repository.accessRestriction = AccessRestrictionType.PUSH;
*/
@Test
public void testNamed_CLONE_DELETE() throws Exception {
- RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
+ RepositoryModel repository = new RepositoryModel("myrepo.git", null, new Date());
repository.authorizationControl = AuthorizationControl.NAMED;
repository.accessRestriction = AccessRestrictionType.CLONE;
*/
@Test
public void testNamed_VIEW_DELETE() throws Exception {
- RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
+ RepositoryModel repository = new RepositoryModel("myrepo.git", null, new Date());
repository.authorizationControl = AuthorizationControl.NAMED;
repository.accessRestriction = AccessRestrictionType.VIEW;
*/
@Test
public void testNamed_NONE_REWIND() throws Exception {
- RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
+ RepositoryModel repository = new RepositoryModel("myrepo.git", null, new Date());
repository.authorizationControl = AuthorizationControl.NAMED;
repository.accessRestriction = AccessRestrictionType.NONE;
*/
@Test
public void testNamed_PUSH_REWIND() throws Exception {
- RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
+ RepositoryModel repository = new RepositoryModel("myrepo.git", null, new Date());
repository.authorizationControl = AuthorizationControl.NAMED;
repository.accessRestriction = AccessRestrictionType.PUSH;
*/
@Test
public void testNamed_CLONE_REWIND() throws Exception {
- RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
+ RepositoryModel repository = new RepositoryModel("myrepo.git", null, new Date());
repository.authorizationControl = AuthorizationControl.NAMED;
repository.accessRestriction = AccessRestrictionType.CLONE;
*/
@Test
public void testNamed_VIEW_REWIND() throws Exception {
- RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
+ RepositoryModel repository = new RepositoryModel("myrepo.git", null, new Date());
repository.authorizationControl = AuthorizationControl.NAMED;
repository.accessRestriction = AccessRestrictionType.VIEW;
*/
@Test
public void testTeam_NONE_NONE() throws Exception {
- RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
+ RepositoryModel repository = new RepositoryModel("myrepo.git", null, new Date());
repository.authorizationControl = AuthorizationControl.NAMED;
repository.accessRestriction = AccessRestrictionType.NONE;
*/
@Test
public void testTeam_PUSH_NONE() throws Exception {
- RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
+ RepositoryModel repository = new RepositoryModel("myrepo.git", null, new Date());
repository.authorizationControl = AuthorizationControl.NAMED;
repository.accessRestriction = AccessRestrictionType.PUSH;
*/
@Test
public void testTeam_CLONE_NONE() throws Exception {
- RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
+ RepositoryModel repository = new RepositoryModel("myrepo.git", null, new Date());
repository.authorizationControl = AuthorizationControl.NAMED;
repository.accessRestriction = AccessRestrictionType.CLONE;
*/
@Test
public void testTeam_VIEW_NONE() throws Exception {
- RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
+ RepositoryModel repository = new RepositoryModel("myrepo.git", null, new Date());
repository.authorizationControl = AuthorizationControl.NAMED;
repository.accessRestriction = AccessRestrictionType.VIEW;
*/
@Test
public void testTeam_NONE_PUSH() throws Exception {
- RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
+ RepositoryModel repository = new RepositoryModel("myrepo.git", null, new Date());
repository.authorizationControl = AuthorizationControl.NAMED;
repository.accessRestriction = AccessRestrictionType.NONE;
*/
@Test
public void testTeam_PUSH_PUSH() throws Exception {
- RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
+ RepositoryModel repository = new RepositoryModel("myrepo.git", null, new Date());
repository.authorizationControl = AuthorizationControl.NAMED;
repository.accessRestriction = AccessRestrictionType.PUSH;
*/
@Test
public void testTeam_CLONE_PUSH() throws Exception {
- RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
+ RepositoryModel repository = new RepositoryModel("myrepo.git", null, new Date());
repository.authorizationControl = AuthorizationControl.NAMED;
repository.accessRestriction = AccessRestrictionType.CLONE;
*/
@Test
public void testTeam_VIEW_PUSH() throws Exception {
- RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
+ RepositoryModel repository = new RepositoryModel("myrepo.git", null, new Date());
repository.authorizationControl = AuthorizationControl.NAMED;
repository.accessRestriction = AccessRestrictionType.VIEW;
*/
@Test
public void testTeam_NONE_CREATE() throws Exception {
- RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
+ RepositoryModel repository = new RepositoryModel("myrepo.git", null, new Date());
repository.authorizationControl = AuthorizationControl.NAMED;
repository.accessRestriction = AccessRestrictionType.NONE;
*/
@Test
public void testTeam_PUSH_CREATE() throws Exception {
- RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
+ RepositoryModel repository = new RepositoryModel("myrepo.git", null, new Date());
repository.authorizationControl = AuthorizationControl.NAMED;
repository.accessRestriction = AccessRestrictionType.PUSH;
*/
@Test
public void testTeam_CLONE_CREATE() throws Exception {
- RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
+ RepositoryModel repository = new RepositoryModel("myrepo.git", null, new Date());
repository.authorizationControl = AuthorizationControl.NAMED;
repository.accessRestriction = AccessRestrictionType.CLONE;
*/
@Test
public void testTeam_VIEW_CREATE() throws Exception {
- RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
+ RepositoryModel repository = new RepositoryModel("myrepo.git", null, new Date());
repository.authorizationControl = AuthorizationControl.NAMED;
repository.accessRestriction = AccessRestrictionType.VIEW;
*/
@Test
public void testTeam_NONE_DELETE() throws Exception {
- RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
+ RepositoryModel repository = new RepositoryModel("myrepo.git", null, new Date());
repository.authorizationControl = AuthorizationControl.NAMED;
repository.accessRestriction = AccessRestrictionType.NONE;
*/
@Test
public void testTeam_PUSH_DELETE() throws Exception {
- RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
+ RepositoryModel repository = new RepositoryModel("myrepo.git", null, new Date());
repository.authorizationControl = AuthorizationControl.NAMED;
repository.accessRestriction = AccessRestrictionType.PUSH;
*/
@Test
public void testTeam_CLONE_DELETE() throws Exception {
- RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
+ RepositoryModel repository = new RepositoryModel("myrepo.git", null, new Date());
repository.authorizationControl = AuthorizationControl.NAMED;
repository.accessRestriction = AccessRestrictionType.CLONE;
*/
@Test
public void testTeam_VIEW_DELETE() throws Exception {
- RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
+ RepositoryModel repository = new RepositoryModel("myrepo.git", null, new Date());
repository.authorizationControl = AuthorizationControl.NAMED;
repository.accessRestriction = AccessRestrictionType.VIEW;
*/
@Test
public void testTeam_NONE_REWIND() throws Exception {
- RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
+ RepositoryModel repository = new RepositoryModel("myrepo.git", null, new Date());
repository.authorizationControl = AuthorizationControl.NAMED;
repository.accessRestriction = AccessRestrictionType.NONE;
*/
@Test
public void testTeam_PUSH_REWIND() throws Exception {
- RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
+ RepositoryModel repository = new RepositoryModel("myrepo.git", null, new Date());
repository.authorizationControl = AuthorizationControl.NAMED;
repository.accessRestriction = AccessRestrictionType.PUSH;
*/
@Test
public void testTeam_CLONE_REWIND() throws Exception {
- RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
+ RepositoryModel repository = new RepositoryModel("myrepo.git", null, new Date());
repository.authorizationControl = AuthorizationControl.NAMED;
repository.accessRestriction = AccessRestrictionType.CLONE;
*/
@Test
public void testTeam_VIEW_REWIND() throws Exception {
- RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
+ RepositoryModel repository = new RepositoryModel("myrepo.git", null, new Date());
repository.authorizationControl = AuthorizationControl.NAMED;
repository.accessRestriction = AccessRestrictionType.VIEW;
*/
@Test
public void testTeam_NONE_CLONE() throws Exception {
- RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
+ RepositoryModel repository = new RepositoryModel("myrepo.git", null, new Date());
repository.authorizationControl = AuthorizationControl.NAMED;
repository.accessRestriction = AccessRestrictionType.NONE;
*/
@Test
public void testTeam_PUSH_CLONE() throws Exception {
- RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
+ RepositoryModel repository = new RepositoryModel("myrepo.git", null, new Date());
repository.authorizationControl = AuthorizationControl.NAMED;
repository.accessRestriction = AccessRestrictionType.PUSH;
*/
@Test
public void testTeam_CLONE_CLONE() throws Exception {
- RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
+ RepositoryModel repository = new RepositoryModel("myrepo.git", null, new Date());
repository.authorizationControl = AuthorizationControl.NAMED;
repository.accessRestriction = AccessRestrictionType.CLONE;
*/
@Test
public void testTeam_VIEW_CLONE() throws Exception {
- RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
+ RepositoryModel repository = new RepositoryModel("myrepo.git", null, new Date());
repository.authorizationControl = AuthorizationControl.NAMED;
repository.accessRestriction = AccessRestrictionType.VIEW;
*/
@Test
public void testTeam_NONE_VIEW() throws Exception {
- RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
+ RepositoryModel repository = new RepositoryModel("myrepo.git", null, new Date());
repository.authorizationControl = AuthorizationControl.NAMED;
repository.accessRestriction = AccessRestrictionType.NONE;
*/
@Test
public void testTeam_PUSH_VIEW() throws Exception {
- RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
+ RepositoryModel repository = new RepositoryModel("myrepo.git", null, new Date());
repository.authorizationControl = AuthorizationControl.NAMED;
repository.accessRestriction = AccessRestrictionType.PUSH;
*/
@Test
public void testTeam_CLONE_VIEW() throws Exception {
- RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
+ RepositoryModel repository = new RepositoryModel("myrepo.git", null, new Date());
repository.authorizationControl = AuthorizationControl.NAMED;
repository.accessRestriction = AccessRestrictionType.CLONE;
*/
@Test
public void testTeam_VIEW_VIEW() throws Exception {
- RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
+ RepositoryModel repository = new RepositoryModel("myrepo.git", null, new Date());
repository.authorizationControl = AuthorizationControl.NAMED;
repository.accessRestriction = AccessRestrictionType.VIEW;
*/
@Test
public void testTeamMember_NONE_NONE() throws Exception {
- RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
+ RepositoryModel repository = new RepositoryModel("myrepo.git", null, new Date());
repository.authorizationControl = AuthorizationControl.NAMED;
repository.accessRestriction = AccessRestrictionType.NONE;
*/
@Test
public void testTeamMember_PUSH_NONE() throws Exception {
- RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
+ RepositoryModel repository = new RepositoryModel("myrepo.git", null, new Date());
repository.authorizationControl = AuthorizationControl.NAMED;
repository.accessRestriction = AccessRestrictionType.PUSH;
*/
@Test
public void testTeamMember_CLONE_NONE() throws Exception {
- RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
+ RepositoryModel repository = new RepositoryModel("myrepo.git", null, new Date());
repository.authorizationControl = AuthorizationControl.NAMED;
repository.accessRestriction = AccessRestrictionType.CLONE;
*/
@Test
public void testTeamMember_VIEW_NONE() throws Exception {
- RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
+ RepositoryModel repository = new RepositoryModel("myrepo.git", null, new Date());
repository.authorizationControl = AuthorizationControl.NAMED;
repository.accessRestriction = AccessRestrictionType.VIEW;
*/
@Test
public void testTeamMember_NONE_PUSH() throws Exception {
- RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
+ RepositoryModel repository = new RepositoryModel("myrepo.git", null, new Date());
repository.authorizationControl = AuthorizationControl.NAMED;
repository.accessRestriction = AccessRestrictionType.NONE;
*/
@Test
public void testTeamMember_PUSH_PUSH() throws Exception {
- RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
+ RepositoryModel repository = new RepositoryModel("myrepo.git", null, new Date());
repository.authorizationControl = AuthorizationControl.NAMED;
repository.accessRestriction = AccessRestrictionType.PUSH;
*/
@Test
public void testTeamMember_CLONE_PUSH() throws Exception {
- RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
+ RepositoryModel repository = new RepositoryModel("myrepo.git", null, new Date());
repository.authorizationControl = AuthorizationControl.NAMED;
repository.accessRestriction = AccessRestrictionType.CLONE;
*/
@Test
public void testTeamMember_VIEW_PUSH() throws Exception {
- RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
+ RepositoryModel repository = new RepositoryModel("myrepo.git", null, new Date());
repository.authorizationControl = AuthorizationControl.NAMED;
repository.accessRestriction = AccessRestrictionType.VIEW;
*/
@Test
public void testTeamMember_NONE_CREATE() throws Exception {
- RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
+ RepositoryModel repository = new RepositoryModel("myrepo.git", null, new Date());
repository.authorizationControl = AuthorizationControl.NAMED;
repository.accessRestriction = AccessRestrictionType.NONE;
*/
@Test
public void testTeamMember_PUSH_CREATE() throws Exception {
- RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
+ RepositoryModel repository = new RepositoryModel("myrepo.git", null, new Date());
repository.authorizationControl = AuthorizationControl.NAMED;
repository.accessRestriction = AccessRestrictionType.PUSH;
*/
@Test
public void testTeamMember_CLONE_CREATE() throws Exception {
- RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
+ RepositoryModel repository = new RepositoryModel("myrepo.git", null, new Date());
repository.authorizationControl = AuthorizationControl.NAMED;
repository.accessRestriction = AccessRestrictionType.CLONE;
*/
@Test
public void testTeamMember_VIEW_CREATE() throws Exception {
- RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
+ RepositoryModel repository = new RepositoryModel("myrepo.git", null, new Date());
repository.authorizationControl = AuthorizationControl.NAMED;
repository.accessRestriction = AccessRestrictionType.VIEW;
*/
@Test
public void testTeamMember_NONE_DELETE() throws Exception {
- RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
+ RepositoryModel repository = new RepositoryModel("myrepo.git", null, new Date());
repository.authorizationControl = AuthorizationControl.NAMED;
repository.accessRestriction = AccessRestrictionType.NONE;
*/
@Test
public void testTeamMember_PUSH_DELETE() throws Exception {
- RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
+ RepositoryModel repository = new RepositoryModel("myrepo.git", null, new Date());
repository.authorizationControl = AuthorizationControl.NAMED;
repository.accessRestriction = AccessRestrictionType.PUSH;
*/
@Test
public void testTeamMember_CLONE_DELETE() throws Exception {
- RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
+ RepositoryModel repository = new RepositoryModel("myrepo.git", null, new Date());
repository.authorizationControl = AuthorizationControl.NAMED;
repository.accessRestriction = AccessRestrictionType.CLONE;
*/
@Test
public void testTeamMember_VIEW_DELETE() throws Exception {
- RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
+ RepositoryModel repository = new RepositoryModel("myrepo.git", null, new Date());
repository.authorizationControl = AuthorizationControl.NAMED;
repository.accessRestriction = AccessRestrictionType.VIEW;
*/
@Test
public void testTeamMember_NONE_REWIND() throws Exception {
- RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
+ RepositoryModel repository = new RepositoryModel("myrepo.git", null, new Date());
repository.authorizationControl = AuthorizationControl.NAMED;
repository.accessRestriction = AccessRestrictionType.NONE;
*/
@Test
public void testTeamMember_PUSH_REWIND() throws Exception {
- RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
+ RepositoryModel repository = new RepositoryModel("myrepo.git", null, new Date());
repository.authorizationControl = AuthorizationControl.NAMED;
repository.accessRestriction = AccessRestrictionType.PUSH;
*/
@Test
public void testTeamMember_CLONE_REWIND() throws Exception {
- RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
+ RepositoryModel repository = new RepositoryModel("myrepo.git", null, new Date());
repository.authorizationControl = AuthorizationControl.NAMED;
repository.accessRestriction = AccessRestrictionType.CLONE;
*/
@Test
public void testTeamMember_VIEW_REWIND() throws Exception {
- RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
+ RepositoryModel repository = new RepositoryModel("myrepo.git", null, new Date());
repository.authorizationControl = AuthorizationControl.NAMED;
repository.accessRestriction = AccessRestrictionType.VIEW;
*/
@Test
public void testTeamMember_NONE_CLONE() throws Exception {
- RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
+ RepositoryModel repository = new RepositoryModel("myrepo.git", null, new Date());
repository.authorizationControl = AuthorizationControl.NAMED;
repository.accessRestriction = AccessRestrictionType.NONE;
*/
@Test
public void testTeamMember_PUSH_CLONE() throws Exception {
- RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
+ RepositoryModel repository = new RepositoryModel("myrepo.git", null, new Date());
repository.authorizationControl = AuthorizationControl.NAMED;
repository.accessRestriction = AccessRestrictionType.PUSH;
*/
@Test
public void testTeamMember_CLONE_CLONE() throws Exception {
- RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
+ RepositoryModel repository = new RepositoryModel("myrepo.git", null, new Date());
repository.authorizationControl = AuthorizationControl.NAMED;
repository.accessRestriction = AccessRestrictionType.CLONE;
*/
@Test
public void testTeamMember_VIEW_CLONE() throws Exception {
- RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
+ RepositoryModel repository = new RepositoryModel("myrepo.git", null, new Date());
repository.authorizationControl = AuthorizationControl.NAMED;
repository.accessRestriction = AccessRestrictionType.VIEW;
*/
@Test
public void testTeamMember_NONE_VIEW() throws Exception {
- RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
+ RepositoryModel repository = new RepositoryModel("myrepo.git", null, new Date());
repository.authorizationControl = AuthorizationControl.NAMED;
repository.accessRestriction = AccessRestrictionType.NONE;
*/
@Test
public void testTeamMember_PUSH_VIEW() throws Exception {
- RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
+ RepositoryModel repository = new RepositoryModel("myrepo.git", null, new Date());
repository.authorizationControl = AuthorizationControl.NAMED;
repository.accessRestriction = AccessRestrictionType.PUSH;
*/
@Test
public void testTeamMember_CLONE_VIEW() throws Exception {
- RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
+ RepositoryModel repository = new RepositoryModel("myrepo.git", null, new Date());
repository.authorizationControl = AuthorizationControl.NAMED;
repository.accessRestriction = AccessRestrictionType.CLONE;
*/
@Test
public void testTeamMember_VIEW_VIEW() throws Exception {
- RepositoryModel repository = new RepositoryModel("myrepo.git", null, null, new Date());
+ RepositoryModel repository = new RepositoryModel("myrepo.git", null, new Date());
repository.authorizationControl = AuthorizationControl.NAMED;
repository.accessRestriction = AccessRestrictionType.VIEW;
@Test
public void testOwner() throws Exception {
- RepositoryModel repository = new RepositoryModel("~jj/myrepo.git", null, null, new Date());
+ RepositoryModel repository = new RepositoryModel("~jj/myrepo.git", null, new Date());
repository.authorizationControl = AuthorizationControl.NAMED;
repository.accessRestriction = AccessRestrictionType.VIEW;
UserModel user = new UserModel("test");
- repository.addOwner(user.username);
+ user.own(repository);
assertFalse("user SHOULD NOT HAVE a repository permission!", user.hasRepositoryPermission(repository.name));
assertTrue("owner CAN NOT view!", user.canView(repository));
assertTrue("owner CAN NOT fork!", user.canFork(repository));
- assertFalse("owner CAN NOT delete!", user.canDelete(repository));
+ assertFalse("owner CAN delete someone elses personal repo!", user.canDelete(repository));
assertTrue("owner CAN NOT edit!", user.canEdit(repository));
// test personal repo owner
assertTrue("jj CAN NOT delete!", jj.canDelete(repository));
assertTrue("jj CAN NOT edit!", jj.canEdit(repository));
- assertTrue(repository.isOwner(jj.username));
+ assertTrue(jj.isOwner(repository));
}
@Test
public void testMultipleOwners() throws Exception {
- RepositoryModel repository = new RepositoryModel("~jj/myrepo.git", null, null, new Date());
+ RepositoryModel repository = new RepositoryModel("~jj/myrepo.git", null, new Date());
repository.authorizationControl = AuthorizationControl.NAMED;
repository.accessRestriction = AccessRestrictionType.VIEW;
UserModel user = new UserModel("test");
- repository.addOwner(user.username);
+ user.own(repository);
UserModel user2 = new UserModel("test2");
- repository.addOwner(user2.username);
+ user2.own(repository);
// first owner
assertFalse("user SHOULD NOT HAVE a repository permission!", user.hasRepositoryPermission(repository.name));
assertFalse("owner CAN NOT delete!", user2.canDelete(repository));
assertTrue("owner CAN NOT edit!", user2.canEdit(repository));
- assertTrue(repository.isOwner(user.username));
- assertTrue(repository.isOwner(user2.username));
+ assertTrue(user.isOwner(repository));
+ assertTrue(user2.isOwner(repository));
// test personal repo owner
UserModel jj = new UserModel("jj");
assertTrue("jj CAN NOT delete!", jj.canDelete(repository));
assertTrue("jj CAN NOT edit!", jj.canEdit(repository));
- assertTrue(repository.isOwner(jj.username));
+ assertTrue(jj.isOwner(repository));
}
@Test
public void testOwnerPersonalRepository() throws Exception {
- RepositoryModel repository = new RepositoryModel("~test/myrepo.git", null, null, new Date());
+ RepositoryModel repository = new RepositoryModel("~test/myrepo.git", null, new Date());
repository.authorizationControl = AuthorizationControl.NAMED;
repository.accessRestriction = AccessRestrictionType.VIEW;
UserModel user = new UserModel("test");
- repository.addOwner(user.username);
+ user.own(repository);
assertFalse("user SHOULD NOT HAVE a repository permission!", user.hasRepositoryPermission(repository.name));
assertTrue("user CAN NOT view!", user.canView(repository));
@Test
public void testVisitorPersonalRepository() throws Exception {
- RepositoryModel repository = new RepositoryModel("~test/myrepo.git", null, null, new Date());
+ RepositoryModel repository = new RepositoryModel("~test/myrepo.git", null, new Date());
repository.authorizationControl = AuthorizationControl.NAMED;
repository.accessRestriction = AccessRestrictionType.VIEW;
UserModel user = new UserModel("visitor");
- repository.addOwner("test");
assertFalse("user HAS a repository permission!", user.hasRepositoryPermission(repository.name));
assertFalse("user CAN view!", user.canView(repository));
@Test
public void testRegexMatching() throws Exception {
- RepositoryModel repository = new RepositoryModel("ubercool/_my-r/e~po.git", null, null, new Date());
+ RepositoryModel repository = new RepositoryModel("ubercool/_my-r/e~po.git", null, new Date());
repository.authorizationControl = AuthorizationControl.NAMED;
repository.accessRestriction = AccessRestrictionType.VIEW;
user.setRepositoryPermission("[^~].*", AccessPermission.CLONE);
// common
- RepositoryModel common = new RepositoryModel("ubercool/_my-r/e~po.git", null, null, new Date());
+ RepositoryModel common = new RepositoryModel("ubercool/_my-r/e~po.git", null, new Date());
common.authorizationControl = AuthorizationControl.NAMED;
common.accessRestriction = AccessRestrictionType.VIEW;
assertFalse("user CAN edit!", user.canEdit(common));
// personal
- RepositoryModel personal = new RepositoryModel("~ubercool/_my-r/e~po.git", null, null, new Date());
+ RepositoryModel personal = new RepositoryModel("~ubercool/_my-r/e~po.git", null, new Date());
personal.authorizationControl = AuthorizationControl.NAMED;
personal.accessRestriction = AccessRestrictionType.VIEW;
@Test
public void testRegexMatching2() throws Exception {
- RepositoryModel personal = new RepositoryModel("~ubercool/_my-r/e~po.git", null, null, new Date());
+ RepositoryModel personal = new RepositoryModel("~ubercool/_my-r/e~po.git", null, new Date());
personal.authorizationControl = AuthorizationControl.NAMED;
personal.accessRestriction = AccessRestrictionType.VIEW;
@Test
public void testRegexOrder() throws Exception {
- RepositoryModel personal = new RepositoryModel("~ubercool/_my-r/e~po.git", null, null, new Date());
+ RepositoryModel personal = new RepositoryModel("~ubercool/_my-r/e~po.git", null, new Date());
personal.authorizationControl = AuthorizationControl.NAMED;
personal.accessRestriction = AccessRestrictionType.VIEW;
@Test
public void testExclusion() throws Exception {
- RepositoryModel personal = new RepositoryModel("~ubercool/_my-r/e~po.git", null, null, new Date());
+ RepositoryModel personal = new RepositoryModel("~ubercool/_my-r/e~po.git", null, new Date());
personal.authorizationControl = AuthorizationControl.NAMED;
personal.accessRestriction = AccessRestrictionType.VIEW;
@Test
public void testIsFrozen() throws Exception {
- RepositoryModel repo = new RepositoryModel("somerepo.git", null, null, new Date());
+ RepositoryModel repo = new RepositoryModel("somerepo.git", null, new Date());
repo.authorizationControl = AuthorizationControl.NAMED;
repo.accessRestriction = AccessRestrictionType.NONE;
@Test
public void testIsBare() throws Exception {
- RepositoryModel repo = new RepositoryModel("somerepo.git", null, null, new Date());
+ RepositoryModel repo = new RepositoryModel("somerepo.git", null, new Date());
repo.authorizationControl = AuthorizationControl.NAMED;
repo.accessRestriction = AccessRestrictionType.NONE;
@Test
public void testIsMirror() throws Exception {
- RepositoryModel repo = new RepositoryModel("somerepo.git", null, null, new Date());
+ RepositoryModel repo = new RepositoryModel("somerepo.git", null, new Date());
repo.authorizationControl = AuthorizationControl.NAMED;
repo.accessRestriction = AccessRestrictionType.NONE;
*/
public class RedisTicketServiceTest extends TicketServiceTest {
- final RepositoryModel repo = new RepositoryModel("tickets/redis.git", null, null, null);
+ final RepositoryModel repo = new RepositoryModel("tickets/redis.git", null, null);
@Override
protected RepositoryModel getRepository() {
RepositoryModel model = new RepositoryModel();\r
model.name = "garbagerepo.git";\r
model.description = "created by RpcUtils";\r
- model.addOwner("garbage");\r
model.accessRestriction = AccessRestrictionType.VIEW;\r
model.authorizationControl = AuthorizationControl.AUTHENTICATED;\r
\r
assertEquals(1, service.getAllTeamNames().size());\r
assertEquals("admins", service.getAllTeamNames().get(0));\r
\r
- RepositoryModel newrepo1 = new RepositoryModel("newrepo1", null, null, null);\r
+ RepositoryModel newrepo1 = new RepositoryModel("newrepo1", null, null);\r
newrepo1.accessRestriction = AccessRestrictionType.VIEW;\r
- RepositoryModel NEWREPO1 = new RepositoryModel("NEWREPO1", null, null, null);\r
+ RepositoryModel NEWREPO1 = new RepositoryModel("NEWREPO1", null, null);\r
NEWREPO1.accessRestriction = AccessRestrictionType.VIEW;\r
\r
// remove newrepo1 from test user\r
assertTrue(user.canView(NEWREPO1));\r
\r
// rename the team and add new repository\r
- RepositoryModel newrepo2 = new RepositoryModel("newrepo2", null, null, null);\r
+ RepositoryModel newrepo2 = new RepositoryModel("newrepo2", null, null);\r
newrepo2.accessRestriction = AccessRestrictionType.VIEW;\r
- RepositoryModel NEWREPO2 = new RepositoryModel("NEWREPO2", null, null, null);\r
+ RepositoryModel NEWREPO2 = new RepositoryModel("NEWREPO2", null, null);\r
NEWREPO2.accessRestriction = AccessRestrictionType.VIEW;\r
\r
team.addRepositoryPermission(newrepo2.name);\r