Search in sources :

Example 46 with RepositoryModel

use of com.gitblit.models.RepositoryModel in project gitblit by gitblit.

the class ITicketService method deleteAll.

/**
	 * Deletes all tickets in every repository.
	 *
	 * @return true if successful
	 * @since 1.4.0
	 */
public boolean deleteAll() {
    List<String> repositories = repositoryManager.getRepositoryList();
    BitSet bitset = new BitSet(repositories.size());
    for (int i = 0; i < repositories.size(); i++) {
        String name = repositories.get(i);
        RepositoryModel repository = repositoryManager.getRepositoryModel(name);
        boolean success = deleteAll(repository);
        bitset.set(i, success);
    }
    boolean success = bitset.cardinality() == repositories.size();
    if (success) {
        indexer.deleteAll();
        resetCaches();
    }
    return success;
}
Also used : BitSet(java.util.BitSet) RepositoryModel(com.gitblit.models.RepositoryModel)

Example 47 with RepositoryModel

use of com.gitblit.models.RepositoryModel in project gitblit by gitblit.

the class ITicketService method updateComment.

/**
	 * Updates the text of an ticket comment.
	 *
	 * @param ticket
	 * @param commentId
	 *            the id of the comment to revise
	 * @param updatedBy
	 *            the author of the updated comment
	 * @param comment
	 *            the revised comment
	 * @return the revised ticket if the change was successful
	 * @since 1.4.0
	 */
public final TicketModel updateComment(TicketModel ticket, String commentId, String updatedBy, String comment) {
    Change revision = new Change(updatedBy);
    revision.comment(comment);
    revision.comment.id = commentId;
    RepositoryModel repository = repositoryManager.getRepositoryModel(ticket.repository);
    TicketModel revisedTicket = updateTicket(repository, ticket.number, revision);
    return revisedTicket;
}
Also used : TicketModel(com.gitblit.models.TicketModel) Change(com.gitblit.models.TicketModel.Change) RepositoryModel(com.gitblit.models.RepositoryModel)

Example 48 with RepositoryModel

use of com.gitblit.models.RepositoryModel in project gitblit by gitblit.

the class Issue0259Test method testFile.

/**
	 * Test the provided users.conf file for expected access permissions.
	 *
	 * @throws Exception
	 */
@Test
public void testFile() throws Exception {
    File realmFile = new File("src/test/resources/issue0259.conf");
    ConfigUserService service = new ConfigUserService(realmFile);
    RepositoryModel test = repo("test.git", AccessRestrictionType.VIEW);
    RepositoryModel projects_test = repo("projects/test.git", AccessRestrictionType.VIEW);
    UserModel a = service.getUserModel("a");
    UserModel b = service.getUserModel("b");
    UserModel c = service.getUserModel("c");
    // assert RWD or RW+ for projects/test.git
    assertEquals(AccessPermission.DELETE, a.getRepositoryPermission(projects_test).permission);
    assertEquals(AccessPermission.DELETE, b.getRepositoryPermission(projects_test).permission);
    assertEquals(AccessPermission.REWIND, c.getRepositoryPermission(projects_test).permission);
    assertTrue(a.canPush(projects_test));
    assertTrue(b.canPush(projects_test));
    assertTrue(c.canPush(projects_test));
    assertTrue(a.canDeleteRef(projects_test));
    assertTrue(b.canDeleteRef(projects_test));
    assertTrue(c.canDeleteRef(projects_test));
    assertFalse(a.canRewindRef(projects_test));
    assertFalse(b.canRewindRef(projects_test));
    assertTrue(c.canRewindRef(projects_test));
    // assert R for test.git
    assertEquals(AccessPermission.CLONE, a.getRepositoryPermission(test).permission);
    assertEquals(AccessPermission.CLONE, b.getRepositoryPermission(test).permission);
    assertEquals(AccessPermission.REWIND, c.getRepositoryPermission(test).permission);
    assertTrue(a.canClone(test));
    assertTrue(b.canClone(test));
    assertFalse(a.canPush(test));
    assertFalse(b.canPush(test));
    assertTrue(c.canPush(test));
}
Also used : UserModel(com.gitblit.models.UserModel) ConfigUserService(com.gitblit.ConfigUserService) RepositoryModel(com.gitblit.models.RepositoryModel) File(java.io.File) Test(org.junit.Test)

Example 49 with RepositoryModel

use of com.gitblit.models.RepositoryModel in project gitblit by gitblit.

the class Issue0259Test method testTeam.

/**
	 * Test a single team that has multiple repository permissions that all match.
	 * Here defined order IS important.  The first permission match wins so it is
	 * important to define permissions from most-specific match to least-specific
	 * match.
	 *
	 * If the defined permissions are:
	 *   R:.*
	 *   RWD:projects/.*
	 * then the expected result is R for all repositories because it is first.
	 *
	 * But if the defined permissions are:
	 *   RWD:projects/.*
	 *   R:.*
	 * then the expected result is RWD for projects/test.git and R for test.git
	 *
	 * @param reverseOrder
	 * @throws Exception
	 */
private void testTeam(boolean reverseOrder) throws Exception {
    RepositoryModel test = repo("test.git", AccessRestrictionType.VIEW);
    RepositoryModel projects_test = repo("projects/test.git", AccessRestrictionType.VIEW);
    TeamModel t1 = new TeamModel("t1");
    if (reverseOrder) {
        t1.setRepositoryPermission("projects/.*", AccessPermission.DELETE);
        t1.setRepositoryPermission(".*", AccessPermission.CLONE);
    } else {
        t1.setRepositoryPermission(".*", AccessPermission.CLONE);
        t1.setRepositoryPermission("projects/.*", AccessPermission.DELETE);
    }
    UserModel a = new UserModel("a");
    a.teams.add(t1);
    // simulate a repository rename
    a.setRepositoryPermission("projects/renamed.git", null);
    t1.setRepositoryPermission("projects/renamed.git", null);
    assertEquals(AccessPermission.CLONE, a.getRepositoryPermission(test).permission);
    assertTrue(a.canClone(test));
    assertFalse(a.canDeleteRef(test));
    assertTrue(a.canClone(projects_test));
    if (reverseOrder) {
        // RWD permission is found first
        assertEquals(AccessPermission.DELETE, a.getRepositoryPermission(projects_test).permission);
        assertTrue(a.canDeleteRef(projects_test));
    } else {
        // R permission is found first
        assertEquals(AccessPermission.CLONE, a.getRepositoryPermission(projects_test).permission);
        assertFalse(a.canDeleteRef(projects_test));
    }
}
Also used : UserModel(com.gitblit.models.UserModel) TeamModel(com.gitblit.models.TeamModel) RepositoryModel(com.gitblit.models.RepositoryModel)

Example 50 with RepositoryModel

use of com.gitblit.models.RepositoryModel in project gitblit by gitblit.

the class Issue0259Test method testTeams.

/**
	 * Tests multiple teams each with a regex permisson that will match.  The
	 * highest matching permission should be used.  Order should be irrelevant.
	 *
	 * @param reverseOrder
	 * @throws Exception
	 */
private void testTeams(boolean reverseOrder) throws Exception {
    RepositoryModel test = repo("test.git", AccessRestrictionType.VIEW);
    RepositoryModel projects_test = repo("projects/test.git", AccessRestrictionType.VIEW);
    TeamModel t1 = new TeamModel("t1");
    t1.setRepositoryPermission(".*", AccessPermission.CLONE);
    TeamModel t2 = new TeamModel("t2");
    t2.setRepositoryPermission("projects/.*", AccessPermission.DELETE);
    UserModel a = new UserModel("a");
    if (reverseOrder) {
        a.teams.add(t2);
        a.teams.add(t1);
    } else {
        a.teams.add(t1);
        a.teams.add(t2);
    }
    // simulate a repository rename
    a.setRepositoryPermission("projects/renamed.git", null);
    t1.setRepositoryPermission("projects/renamed.git", null);
    t2.setRepositoryPermission("projects/renamed.git", null);
    assertEquals(AccessPermission.CLONE, a.getRepositoryPermission(test).permission);
    assertEquals(AccessPermission.DELETE, a.getRepositoryPermission(projects_test).permission);
    assertTrue(a.canClone(test));
    assertTrue(a.canClone(projects_test));
    assertFalse(a.canDeleteRef(test));
    assertTrue(a.canDeleteRef(projects_test));
}
Also used : UserModel(com.gitblit.models.UserModel) TeamModel(com.gitblit.models.TeamModel) RepositoryModel(com.gitblit.models.RepositoryModel)

Aggregations

RepositoryModel (com.gitblit.models.RepositoryModel)234 Test (org.junit.Test)145 Date (java.util.Date)135 UserModel (com.gitblit.models.UserModel)116 TeamModel (com.gitblit.models.TeamModel)68 ArrayList (java.util.ArrayList)39 File (java.io.File)20 Repository (org.eclipse.jgit.lib.Repository)20 CloneCommand (org.eclipse.jgit.api.CloneCommand)16 Git (org.eclipse.jgit.api.Git)13 ReceiveCommand (org.eclipse.jgit.transport.ReceiveCommand)13 GitBlitException (com.gitblit.GitBlitException)11 Label (org.apache.wicket.markup.html.basic.Label)11 UsernamePasswordCredentialsProvider (org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider)11 PushResult (org.eclipse.jgit.transport.PushResult)10 RemoteRefUpdate (org.eclipse.jgit.transport.RemoteRefUpdate)10 RegistrantAccessPermission (com.gitblit.models.RegistrantAccessPermission)9 BufferedWriter (java.io.BufferedWriter)9 FileOutputStream (java.io.FileOutputStream)9 RevCommit (org.eclipse.jgit.revwalk.RevCommit)9