James Moger
2014-03-12 b8e1fa94f3f28a94b466c79b1a4b24c6fd755df1
src/main/java/com/gitblit/git/GitblitReceivePack.java
@@ -51,7 +51,6 @@
import com.gitblit.models.RepositoryModel;
import com.gitblit.models.UserModel;
import com.gitblit.tickets.BranchTicketService;
import com.gitblit.tickets.BranchTicketService.TicketsBranchUpdated;
import com.gitblit.utils.ArrayUtils;
import com.gitblit.utils.ClientLogger;
import com.gitblit.utils.CommitCache;
@@ -125,6 +124,32 @@
   }
   /**
    * Returns true if the user is permitted to apply the receive commands to
    * the repository.
    *
    * @param commands
    * @return true if the user may push these commands
    */
   protected boolean canPush(Collection<ReceiveCommand> commands) {
      // TODO Consider supporting branch permissions here (issue-36)
      // Not sure if that should be Gerrit-style, refs/meta/config, or
      // gitolite-style, permissions in users.conf
      //
      // How could commands be empty?
      //
      // Because a subclass, like PatchsetReceivePack, filters receive
      // commands before this method is called.  This makes it possible for
      // this method to test an empty list.  In this case, we assume that the
      // subclass receive pack properly enforces push restrictions. for the
      // ref.
      //
      // The empty test is not explicitly required, it's written here to
      // clarify special-case behavior.
      return commands.isEmpty() ? true : user.canPush(repository);
   }
   /**
    * Instrumentation point where the incoming push event has been parsed,
    * validated, objects created BUT refs have not been updated. You might
    * use this to enforce a branch-write permissions model.
@@ -156,7 +181,7 @@
         return;
      }
      if (!user.canPush(repository)) {
      if (!canPush(commands)) {
         // user does not have push permissions
         for (ReceiveCommand cmd : commands) {
            sendRejection(cmd, "User \"{0}\" does not have push permissions for \"{1}\"!", user.username, repository.name);
@@ -344,12 +369,13 @@
      } catch (Exception e) {
         LOGGER.error(MessageFormat.format("Failed to update {0} pushlog", repository.name), e);
      }
      // check for updates pushed to the BranchTicketService branch
      // if the BranchTicketService is active it will reindex, as appropriate
      for (ReceiveCommand cmd : commands) {
         if (Result.OK.equals(cmd.getResult())
               && BranchTicketService.BRANCH.equals(cmd.getRefName())) {
            rp.getRepository().fireEvent(new TicketsBranchUpdated(repository));
            rp.getRepository().fireEvent(new ReceiveCommandEvent(repository, cmd));
         }
      }