What is a
UserFilter is one of building blocks for Quality Gates. It is one of the SubmitRule filters that determines whether a change qualifies for submission or not. SubmitRule with matching filters (or with no filters at all) are evaluated for submission.
UserFilter has the following attributes:
For example, if you want to disable submit for a user, you can use a
UserFilter with the
ignoreAuthor attribute set to
true. In such a case, the SubmitRule would not be satisfied if the user who is viewing the code review is the author of the latest patch set of that code change. In this case, the code change is not submittable by that user and the Submit button is disabled. This SubmitRule holds good in all other cases.
What are the reasons to remove
UserFilter from the quality gates?
UserFilter removal is a direct outcome of the removal of the current_user predicate from the open source Gerrit. It is not possible to implement the
UserFilter without this predicate, as the quality gates would have no information about the current user any longer.
Why was the current user predicate removed from open source Gerrit?
The current user predicate is removed because of the fact that the result of a submittability check should not depend on the user who is asking for it. For more information, click here to follow the discussion on this topic.
Here are a few arguments that support the
- Using the current user predicate may produce some surprising results such as two different users being presented with completely different sets of required labels—or even different submit type. If user A clicks submit, it might be Always Merge, but if user B clicks submit, it might be Cherry-Pick.
- Support for the
is:submittablequery. If the
current_userpredicate is used in the prolog rules, the ‘
submittablefield could vary on a user-to-user basis. So, it needs to be re-evaluated for every new request. Re-evaluating this field for every new request is not a good idea as this operation is quite costly.
- You can achieve equivalent results without using the
How can I check if I am affected by the
Use this plugin to check if you are affected.
How to replace
UserFilter from my Quality Gates?
Let’s consider the SubmitRule that mandates a user to be both the author and submitter of the change, for example.
Here’s the SubmitRule rule:
<?xml version="1.0" encoding="UTF-8"?> <cn:GerritWorkflow enableVerification="true" enableCodeReview="true" description="Only the author can submit the change, others can still informally review and verify" name="Author only" <cn:SubmitRule displayName="Author-To-Submit" actionIfSatisfied="allow"> <cn:UserFilter ignoreNonAuthor="true" /> </cn:SubmitRule> </cn:GerritWorkflow>
As you can see, the above rule uses a
UserFilter with the
ignoreAuthor attribute. Let’s see how to have this done without the
Let’s first understand how the above rule works.
This rule allows only the author to submit the change. No review is required, so the rule will be submittable for the author but not submittable for anyone else independent from the voting. That means that author is the only one who can decide if the rule can be submitted.
You can achieve this by requiring the author to give his approval (Verify +1) to make change submittable:
<?xml version="1.0" encoding="UTF-8"?> <cn:GerritWorkflow enableVerification="true" enableCodeReview="true" description="The change can only be submitted if the author has verified it, others can still informally review and verify" name="Author only" version="1" xsi:schemaLocation="http://www.collab.net/gerritworkflow gerritworkflow.xsd" xmlns:cn="http://www.collab.net/gerritworkflow" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <cn:SubmitRule displayName="Author-Verify-To-Submit" actionIfSatisfied="allow"> <cn:VotingCondition value="1" votingCategory="Verified"> <cn:VoteAuthorFilter ignoreAuthorVotes="false" ignoreNonAuthorVotes="true" /> </cn:VotingCondition> </cn:SubmitRule> </cn:GerritWorkflow>
As you can see, the above rule mandates the approval, but the only person whose vote will be considered is the author. So, we now have replaced the
UserFilter with the
VoteAuthorFilter attributes. In other words, no one can submit without a vote from the author. Once the author gives a
Verified +1 vote, anyone who has the submit permission can submit the change.
On the other hand, what if you want only a specific person to submit? That’s also possible if you create a special Gerrit group and give only members of this group the right to submit.