]> source.dussan.org Git - gitblit.git/commitdiff
Tweak the receive pack push permission check to be a method
authorJames Moger <james.moger@gitblit.com>
Wed, 12 Mar 2014 21:21:12 +0000 (17:21 -0400)
committerJames Moger <james.moger@gitblit.com>
Wed, 12 Mar 2014 21:21:12 +0000 (17:21 -0400)
src/main/java/com/gitblit/git/GitblitReceivePack.java

index e3e2faeb58506b3065aa5d12ac11b8256a0e7b83..73da3d3e1d5f6b64712da546572e38d52f1ca539 100644 (file)
@@ -123,6 +123,32 @@ public class GitblitReceivePack extends ReceivePack implements PreReceiveHook, P
                setPostReceiveHook(this);\r
        }\r
 \r
+       /**\r
+        * Returns true if the user is permitted to apply the receive commands to\r
+        * the repository.\r
+        *\r
+        * @param commands\r
+        * @return true if the user may push these commands\r
+        */\r
+       protected boolean canPush(Collection<ReceiveCommand> commands) {\r
+               // TODO Consider supporting branch permissions here (issue-36)\r
+               // Not sure if that should be Gerrit-style, refs/meta/config, or\r
+               // gitolite-style, permissions in users.conf\r
+               //\r
+               // How could commands be empty?\r
+               //\r
+               // Because a subclass, like PatchsetReceivePack, filters receive\r
+               // commands before this method is called.  This makes it possible for\r
+               // this method to test an empty list.  In this case, we assume that the\r
+               // subclass receive pack properly enforces push restrictions. for the\r
+               // ref.\r
+               //\r
+               // The empty test is not explicitly required, it's written here to\r
+               // clarify special-case behavior.\r
+\r
+               return commands.isEmpty() ? true : user.canPush(repository);\r
+       }\r
+\r
        /**\r
         * Instrumentation point where the incoming push event has been parsed,\r
         * validated, objects created BUT refs have not been updated. You might\r
@@ -155,7 +181,7 @@ public class GitblitReceivePack extends ReceivePack implements PreReceiveHook, P
                        return;\r
                }\r
 \r
-               if (!user.canPush(repository)) {\r
+               if (!canPush(commands)) {\r
                        // user does not have push permissions\r
                        for (ReceiveCommand cmd : commands) {\r
                                sendRejection(cmd, "User \"{0}\" does not have push permissions for \"{1}\"!", user.username, repository.name);\r