Documentation: Add prolog submit-rule example Submit by Author
Issue 1631 has been filed to track the need of a way to query
if a certain user has Submit permissions.
Bug: Issue 891
Change-Id: I6f78343012fb0bbcdc7ed90fde1b4189dfcd28c7
diff --git a/Documentation/prolog-cookbook.txt b/Documentation/prolog-cookbook.txt
index c4a0589..e660067 100644
--- a/Documentation/prolog-cookbook.txt
+++ b/Documentation/prolog-cookbook.txt
@@ -721,6 +721,30 @@
add_apprentice_master(S, S).
====
+Example 14: Only allow Author to submit change
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+This example adds a new needed category `Patchset-Author` for any user that is
+not the author of the patch. This effectively blocks all users except the author
+from submitting the change. This could result in an impossible situation if the
+author does not have permissions for submitting the change.
+
+.rules.pl
+[caption=""]
+====
+ submit_rule(S) :-
+ gerrit:default_submit(In),
+ In =.. [submit | Ls],
+ only_allow_author_to_submit(Ls, R),
+ S =.. [submit | R].
+
+ only_allow_author_to_submit(S, S) :-
+ gerrit:commit_author(Id),
+ gerrit:current_user(Id),
+ !.
+
+ only_allow_author_to_submit(S1, [label('Patchset-Author', need(_)) | S1]).
+====
+
GERRIT
------
Part of link:index.html[Gerrit Code Review]