use of com.gitblit.models.RepositoryModel in project gitblit by gitblit.
the class EditTeamDialog method setRepositories.
public void setRepositories(List<RepositoryModel> repositories, List<RegistrantAccessPermission> permissions) {
List<String> restricted = new ArrayList<String>();
for (RepositoryModel repo : repositories) {
if (repo.accessRestriction.exceeds(AccessRestrictionType.NONE) && repo.authorizationControl.equals(AuthorizationControl.NAMED)) {
restricted.add(repo.name);
}
}
StringUtils.sortRepositorynames(restricted);
List<String> list = new ArrayList<String>();
// repositories
list.add(".*");
String prefix;
if (settings.hasKey(Keys.git.userRepositoryPrefix)) {
prefix = settings.get(Keys.git.userRepositoryPrefix).currentValue;
if (StringUtils.isEmpty(prefix)) {
prefix = Constants.DEFAULT_USER_REPOSITORY_PREFIX;
}
} else {
prefix = Constants.DEFAULT_USER_REPOSITORY_PREFIX;
}
if (prefix.length() == 1) {
// all repositories excluding personal repositories
list.add("[^" + prefix + "].*");
}
String lastProject = null;
for (String repo : restricted) {
String projectPath = StringUtils.getFirstPathElement(repo);
if (lastProject == null || !lastProject.equalsIgnoreCase(projectPath)) {
lastProject = projectPath;
if (!StringUtils.isEmpty(projectPath)) {
// regex for all repositories within a project
list.add(projectPath + "/.*");
}
list.add(repo);
}
}
// remove repositories for which user already has a permission
if (permissions == null) {
permissions = new ArrayList<RegistrantAccessPermission>();
} else {
for (RegistrantAccessPermission rp : permissions) {
list.remove(rp.registrant);
}
}
repositoryPalette.setObjects(list, permissions);
}
use of com.gitblit.models.RepositoryModel in project gitblit by gitblit.
the class RepositoriesTableModel method getValueAt.
@Override
public Object getValueAt(int rowIndex, int columnIndex) {
RepositoryModel model = list.get(rowIndex);
Columns col = Columns.values()[columnIndex];
switch(col) {
case Name:
return model;
case Description:
return model.description;
case Owner:
return ArrayUtils.toString(model.owners);
case Indicators:
return model;
case Last_Change:
return model.lastChange;
case Size:
if (model.hasCommits) {
return model.size;
}
return "(empty)";
}
return null;
}
use of com.gitblit.models.RepositoryModel in project gitblit by gitblit.
the class UserServiceTest method testTeams.
protected void testTeams(IUserService service) {
// confirm we have 1 team (admins)
assertEquals(1, service.getAllTeamNames().size());
assertEquals("admins", service.getAllTeamNames().get(0));
RepositoryModel newrepo1 = new RepositoryModel("newrepo1", null, null, null);
newrepo1.accessRestriction = AccessRestrictionType.VIEW;
RepositoryModel NEWREPO1 = new RepositoryModel("NEWREPO1", null, null, null);
NEWREPO1.accessRestriction = AccessRestrictionType.VIEW;
// remove newrepo1 from test user
// now test user has no repositories
UserModel user = service.getUserModel("test");
user.permissions.clear();
service.updateUserModel(user);
user = service.getUserModel("test");
assertEquals(0, user.permissions.size());
assertFalse(user.canView(newrepo1));
assertFalse(user.canView(NEWREPO1));
// create test team and add test user and newrepo1
TeamModel team = new TeamModel("testteam");
team.addUser("test");
team.addRepositoryPermission(newrepo1.name);
service.updateTeamModel(team);
// confirm 1 user and 1 repo
team = service.getTeamModel("testteam");
assertEquals(1, team.permissions.size());
assertEquals(1, team.users.size());
// confirm team membership
user = service.getUserModel("test");
assertEquals(0, user.permissions.size());
assertEquals(1, user.teams.size());
// confirm team access
assertTrue(team.hasRepositoryPermission(newrepo1.name));
assertTrue(user.canView(newrepo1));
assertTrue(team.hasRepositoryPermission(NEWREPO1.name));
assertTrue(user.canView(NEWREPO1));
// rename the team and add new repository
RepositoryModel newrepo2 = new RepositoryModel("newrepo2", null, null, null);
newrepo2.accessRestriction = AccessRestrictionType.VIEW;
RepositoryModel NEWREPO2 = new RepositoryModel("NEWREPO2", null, null, null);
NEWREPO2.accessRestriction = AccessRestrictionType.VIEW;
team.addRepositoryPermission(newrepo2.name);
team.name = "testteam2";
service.updateTeamModel("testteam", team);
team = service.getTeamModel("testteam2");
user = service.getUserModel("test");
// confirm user and team can access newrepo2
assertEquals(2, team.permissions.size());
assertTrue(team.hasRepositoryPermission(newrepo2.name));
assertTrue(user.canView(newrepo2));
assertTrue(team.hasRepositoryPermission(NEWREPO2.name));
assertTrue(user.canView(NEWREPO2));
// delete testteam2
service.deleteTeam("testteam2");
team = service.getTeamModel("testteam2");
user = service.getUserModel("test");
// confirm team does not exist and user can not access newrepo1 and 2
assertEquals(null, team);
assertFalse(user.canView(newrepo1));
assertFalse(user.canView(newrepo2));
// create new team and add it to user
// this tests the inverse team creation/team addition
team = new TeamModel("testteam");
team.addRepositoryPermission(NEWREPO1.name);
team.addRepositoryPermission(NEWREPO2.name);
user.teams.add(team);
service.updateUserModel(user);
// confirm the inverted team addition
user = service.getUserModel("test");
team = service.getTeamModel("testteam");
assertTrue(user.canView(newrepo1));
assertTrue(user.canView(newrepo2));
assertTrue(team.hasUser("test"));
// drop testteam from user and add nextteam to user
team = new TeamModel("nextteam");
team.addRepositoryPermission(NEWREPO1.name);
team.addRepositoryPermission(NEWREPO2.name);
user.teams.clear();
user.teams.add(team);
service.updateUserModel(user);
// confirm implicit drop
user = service.getUserModel("test");
team = service.getTeamModel("testteam");
assertTrue(user.canView(newrepo1));
assertTrue(user.canView(newrepo2));
assertFalse(team.hasUser("test"));
team = service.getTeamModel("nextteam");
assertTrue(team.hasUser("test"));
// delete the user and confirm team no longer has user
service.deleteUser("test");
team = service.getTeamModel("testteam");
assertFalse(team.hasUser("test"));
// delete both teams
service.deleteTeam("testteam");
service.deleteTeam("nextteam");
// assert we still have the admins team
assertEquals(1, service.getAllTeamNames().size());
assertEquals("admins", service.getAllTeamNames().get(0));
team = service.getTeamModel("admins");
assertEquals(1, team.mailingLists.size());
assertTrue(team.mailingLists.contains("admins@localhost.com"));
}
use of com.gitblit.models.RepositoryModel in project gitblit by gitblit.
the class RepositoryModelTest method testGetCustomProperty.
@Test
public void testGetCustomProperty() throws Exception {
RepositoryModel model = repositories().getRepositoryModel(GitBlitSuite.getHelloworldRepository().getDirectory().getName());
assertEquals("\\d", model.customFields.get("commitMessageRegEx"));
assertEquals("Hello", model.customFields.get("anotherProperty"));
}
use of com.gitblit.models.RepositoryModel in project gitblit by gitblit.
the class SshDaemonTest method testCloneCommand.
@Test
public void testCloneCommand() throws Exception {
if (ticgitFolder.exists()) {
GitBlitSuite.close(ticgitFolder);
FileUtils.delete(ticgitFolder, FileUtils.RECURSIVE);
}
// set clone restriction
RepositoryModel model = repositories().getRepositoryModel("ticgit.git");
assertNotNull("Could not get repository modle for ticgit.git", model);
model.accessRestriction = AccessRestrictionType.CLONE;
model.authorizationControl = AuthorizationControl.NAMED;
repositories().updateRepositoryModel(model.name, model, false);
JschConfigTestSessionFactory sessionFactory = new JschConfigTestSessionFactory(roKeyPair);
SshSessionFactory.setInstance(sessionFactory);
CloneCommand clone = Git.cloneRepository();
clone.setCredentialsProvider(new UsernamePasswordCredentialsProvider(username, password));
clone.setURI(MessageFormat.format("{0}/ticgit.git", url));
clone.setDirectory(ticgitFolder);
clone.setBare(false);
clone.setCloneAllBranches(true);
Git git = clone.call();
List<RevCommit> commits = JGitUtils.getRevLog(git.getRepository(), 10);
GitBlitSuite.close(git);
assertEquals(10, commits.size());
// restore anonymous repository access
model.accessRestriction = AccessRestrictionType.NONE;
model.authorizationControl = AuthorizationControl.NAMED;
repositories().updateRepositoryModel(model.name, model, false);
}
Aggregations