3060 Commits

Author SHA1 Message Date
Dave Borowitz
71073f4210 Rename AccountResolver#byId to accountCache
Change-Id: I5e609de45c2593ed9a547690f92f54dc49f20481
2019-02-05 12:14:44 -08:00
Dave Borowitz
78e943d14a Rename AccountResolver2 to AccountResolver
Change-Id: Idf4a3c542f979206121bb96bde5af605c77df070
2019-02-05 12:14:44 -08:00
Dave Borowitz
2a4d98a0ab Remove now-unused old AccountResolver implementation
Change-Id: Id93b22ac46940d1dcfc154f54bb1bea1c76b44c0
2019-02-05 12:14:44 -08:00
Dave Borowitz
edd6afcf66 Remove unnecessary explicit binding of AccountResolver
A just-in-time binding is fine.

Change-Id: I8f940bdcef84be7c73e705189b2a1e153ff73187
2019-02-05 12:14:44 -08:00
Dave Borowitz
b920f3f407 Use AccountResolver2 to resolve strings to IdentifiedUsers
In many callers, this allows us to remove special error handling code:
problems will propagate as UnprocessableEntityExceptions with helpful
messages. The main exception is in AccountsCollection, which is used to
parse users out of URLs (as opposed to, say, JSON inputs). In this case
the correct behavior is to wrap the exception in
ResourceNotFoundException, or AuthException in the case of "self".

The one place that gets more ugly is ReviewerAdder, where we need to
propagate the exception message for a NOT_FOUND result and combine that
with the hard-coded error message when a group is missing. This produces
a somewhat unnecessarily verbose message. The idea is that this
AccountResolver series is a prerequisite for rewriting ReviewerAdder,
which will reduce this ugliness.

Change-Id: I99c03df3da853cba7958bc027d0f67a0320c9e5a
2019-02-05 12:14:44 -08:00
Dave Borowitz
5b5ee594b8 AccountResolver2: Allow resolving "self" and "me"
In the old AccountResolver, the "parse" methods support "self", but the
"find" methods didn't. This meant that callers using "find" either
needed to remember to special case this string, as in
ChangeQueryBuilder, or else they wouldn't get the special behavior.
Consolidate this logic in one location instead.

The string "self" returns an empty Result set when the user is not
logged in. For callers that need to distinguish this case from other
empty results, add isSelf methods to both Result and
UnresolvableAccountException.

Reuse the resolver logic directly in ChangeQueryBuilder instead of
hand-rolling support for "self". This means we also need to support
"me". Again, the consistency here makes sense: it's odd that "me" was
a synonym for self in the change query syntax but not in the REST API.
(It's still not, yet, but it will be when we finish migrating callers to
AccountResolver2.)

Change-Id: I7113aa7a1e274d63826241757cad0aa10370d5c2
2019-02-05 12:14:44 -08:00
Dave Borowitz
28b0c557be AccountResolver2: Expose more useful exception information
Introduce a subclass of UnprocessableEntityException specific to this
resolver code. Flesh out the error message in the ambiguous and inactive
cases with the list of matching accounts, which is something end users
have wanted for a long time. One reason we weren't able to provide this
before was it was hard to reason about whether the multiple matching
accounts were visible to the calling user. Now that we have stricter
guarantees about visibility in the Result object, we know this is safe
to do.

Unfortunately, producing this exception message requires making Result
non-static so we can pass through the injected AnonymousCowardName. This
means we can't use AutoValue. However, neither downstream consumers nor
tests were depending on any of the niceties of AutoValue. Nor should
they be, really: AccountState is not immutable and doesn't implement
equals.

Rewriting the core search logic to keep track of inactive users makes it
a bit more complicated, and at this point it makes more sense to inline
the trySearch method. The complicated logic is hopefully balanced by
good test coverage.

Remove the Searcher field from Result. This wasn't providing much value
in tests, since the searcher that matched is pretty well identified by
the particular set of accounts that were returned. And now, with
inactive users being combined across searchers, there's not necessarily
a single searcher that identifies the result.

Change-Id: I500fe32ade899d991ade90f90eaf5b8b83224a0d
2019-02-05 12:14:44 -08:00
Dave Borowitz
9d59be3af0 AccountResolver: Mark more methods as private
Change-Id: Icc428855c156398bf58e6d81c3f1d13b42f43ac6
2019-02-05 12:14:44 -08:00
Dave Borowitz
5372d49b18 Implement new AccountResolver2#resolveByNameOrEmail
This method is used in exactly one case: MailUtil, for optionally
parsing accounts out of git identities in special commit footers. Out of
an abundance of caution (and because the new code structure makes it
easy), keep the behavior exactly the same.

However, the long term future of this code is unclear[1]: should we
remove it entirely? Or at least limit the format so it requires
something looking more like a git identity than a random bag of stuff we
pass to the index? It's not clear that this or other potential callers
resolveByNameOrEmail actually understand the current semantics. For that
reason, mark the new method as deprecated.

[1] https://groups.google.com/d/msg/repo-discuss/tIFxY7L4DXk/6wqTK5-UHQAJ

Change-Id: I33470221812e398e80b7265f5fe21e51203ed187
2019-02-05 12:14:44 -08:00
Dave Borowitz
c6d93b210f Rewrite AccountResolver with consistent interface and semantics
AccountResolver has a mishmash of methods with different resolution
semantics, different disambiguation semantics, and different return
types.

A short, non-exhaustive list of illustrative examples of confusing
things about this class:
 * find(String) returns null if there is not exactly one match;
   parse(String) throws UnprocessableEntityException.
 * The difference between parse(String) and parseId(String) doesn't have
   anything to do with IDs, it's that one of them respects account
   visibility and the other doesn't. (Pop quiz: which one is which?)
 * findAll(String) and findAllByNameOrEmail(String) don't in fact find
   *all* matching accounts: some paths short-circuit. For example, if
   the input is a number, it will return one result if the number is an
   existing account, and zero results otherwise, even though *all*
   accounts strictly speaking might include users whose full name
   happens to be a numeric string.
 * find(String) filters out inactive users, but findAll doesn't.

These issues at best lead to head-scratching and at worst to subtle but
potentially serious bugs like failing to respect account visibility.

What we really need is a more intentionally designed interface. This
change starts a new implementation, temporarily named AccountResolver2;
once it reaches parity with AccountResolver and all callers have been
migrated, it will be renamed.

The main benefit of the new implementation is that it separates the
_searching_ semantics from the _result_ semantics. For a given input, we
always produce a single Result object, which encapsulates zero or more
results. The Result class has several view methods which allow callers
to convert an arbitrarily sized list of AccountStates to another type
that they may find more useful, like a set of Account.Ids or a single,
unique account. This also provides us a single place to produce useful
exception messages when an account is not unique.

The other major change from AccountResolver is that the new
implementation consistently filters out invisible and inactive users.
We'll explain these one at a time.

First, AccountResolver2 never returns accounts that are not visible to
the calling user. The purpose of this class is to parse
end-user-provided strings to accounts in various contexts (REST API
URLs, REST API inputs, search queries). The search semantics are
intentionally somewhat fuzzy specifically because the input is
user-provided. Since it's user-provided, we can safely assume that there
is an end user on the other end for whom we can check visibility. It's
true that some Gerrit code needs to bypass account visibility, but that
code shouldn't use the AccountResolver interface; it should use a
lower-level interface like InternalAccountQuery.

Next, AccountResolver2 almost always filters out inactive users, except
in one specific case: when the input is a number. This reflects our
experience providing support for customers who are very confused when
their REST API operations fail because they specified some account
string that they thought was unique but that actually matched some
inactive accounts. The idea is that in normal usage, users should never
need to care about inactive accounts--it should be as if they don't
exist. In certain administrative contexts, it is necessary to care about
them, for example an admin re-enabling an account. In these contexts, an
admin can figure out the unambiguous account ID, for example by
searching with [-is:active]. This is a slightly backwards-incompatible
change (although the documentation was never clear on what type of
filtering could occur), but based on our experience, the expected
reduction in user confusion and consequent support costs makes the
change worth it. We should also be able to provide a useful exception
message listing inactive accounts, now that we have a common place to
put the logic.

Taken together, the filtering semantics mean that an end user can't
distinguish between the case where AccountResolver2 produces no results
and where it only produced inactive or invisible results. This is
considered a feature.

In terms of implementation, switch to a more declarative style of
defining the search semantics, based around the concept of a single
Searcher matching a single type of input. Searchers are then iterated
over in a loop, separating the definition of lookup semantics from the
precedence and short-circuiting behavior. This implementation allows us
to preserve the previous search implementation quite closely, while
making it crystal-clear what are the list of supported formats, and
where the intent is to short-circuit and where not. It additionally
makes it possible to write small tests of just the looping logic,
without having to build up all the dependencies required to do actual
account resolution.

Change-Id: I08e64c647378a9275e425b68c39122984ee37e77
2019-02-05 12:14:44 -08:00
Dave Borowitz
936fd00225 Merge "Fix some nits in JavaDoc of classes that implement group storage in NoteDb" 2019-02-05 19:25:34 +00:00
David Pursehouse
6632c0dca1 Merge branch 'stable-2.16'
* stable-2.16:
  Index groups with in-memory test
  Index projects with in-memory test
  Fix loading topics that have unusual characters

Change-Id: Iab74f0539842617c4aeac91dfc083ba620a7c06b
2019-02-05 23:17:19 +09:00
Patrick Hiesel
ca010de75e Merge "ListChangesOption: Remove @Deprecated annotation from SKIP_MERGEABLE" 2019-02-05 13:19:27 +00:00
Patrick Hiesel
e52b9b5f74 Use NoteDb for ref filtering when asking only for a single change ref
SearchingChangeCacheImpl only returns a fraction of all changes. This
fraction covers most recently modified changes. This is problematic when
users want to fetch a change that is older than what this set covers.

There are Gerrit instances with millions of changes and the concept of
index-backed evaluation doesn't scale to this size. Other concepts
failed and had to be reverted (I447eaeb).

If refs-in-wants on Protocol V2 is used, we can fix the shortcomming by
investigating only a single ref backed by NoteDb.

Change-Id: Ib01492ac58eda4a37086aa3e106be857cfb566e1
2019-02-05 13:29:21 +01:00
Luca Milanesio
73cbdac4d5 Index groups with in-memory test
Move the indexing of the initial groups when the
Gerrit server gets prepared and started.

Change-Id: Ida137c500426d6d5b32a938fcdfee947040f4a80
2019-02-05 11:57:56 +00:00
David Pursehouse
3953f4654c Merge "Add explicit factory methods to create AccountsUpdate/GroupsUpdate for serverIdent" 2019-02-05 11:05:44 +00:00
Changcheng Xiao
a4184ccf3d Mark #hasLegacyPermissions with @UsedAt google
This method is not used in upstream but it's used internally.

Change-Id: Ia9f55dcc5d3d901a3e26684eff6e3b942fbc9964
2019-02-05 11:14:38 +01:00
Patrick Hiesel
88e5bc74fe Merge changes I893e38ee,I3d55aa5e,I1a139f4c,Iea0227ff,I62ed7b18, ...
* changes:
  CreateChange: move code for create change to a method
  CreateChange: move code for creating commit message to a method
  CreateChange: move logic for getting parent commit to its own method
  CreateChange: move logic for getting base change to its own method
  CreateChange: move out checks for "merge" field of the ChangeInput
  CreateChange: move logic for "isWorkInProgress" to #checkAndSanitizeChangeInput
  CreateChange: move permission checks to its own method
  CreateChange: move logic for "isPrivate" to #checkAndSanitizeChangeInput
  CreateChange: move code for preprocess input to its own method
2019-02-05 10:10:35 +00:00
Edwin Kempin
4711820e88 Add explicit factory methods to create AccountsUpdate/GroupsUpdate for serverIdent
This is more readable and less error-prone than passing in null for the
IdentifiedUser if the server identity should be used.

This allows AccountsUpdate/GroupsUpdate to use Optional for the
IdentifiedUser internally which makes the internal code nicer.

Signed-off-by: Edwin Kempin <ekempin@google.com>
Change-Id: Ie8593b5194a48a21fa85857879197fd7ca9d5908
2019-02-05 10:50:57 +01:00
Luca Milanesio
baa9aeb0e6 Index projects with in-memory test
When running integration tests with in-memory repositories make
sure that they are all indexed in Lucene before starting the tests.
This enables the implementation of tests that can rely on a
consistent projects index to run.

Change-Id: I2e628e4555ed7faa24fff44a0d226b57b5ce9909
2019-02-05 07:49:38 +00:00
David Pursehouse
ec1769201b ListChangesOption: Remove @Deprecated annotation from SKIP_MERGEABLE
This option is used in several places, and deprecating it causes
warnings.

Because change.api.excludeMergeableInChangeInfo is configurable, callers
have no way to reliably request a change without computing mergeability
without specifying the SKIP_MERGEABLE option.

Remove the @Deprecated annotation, and clarify the documentation.

Change-Id: I20fdadbda12f3d7e434d2f61f5a93569a0df3674
2019-02-05 12:59:26 +09:00
David Pursehouse
b66c949d1f Merge branch 'stable-2.16'
* stable-2.16:
  ListChildProjects: Make settting recursive option chainable
  ListChildProjects: Add limit option
  ListChildProjects: Use parent predicate to find child projects
  QueryProjects: Make setter methods chainable
  Project index: Add parent predicate

ListChildProjectsIT#listChildrenWithLimit is adjusted to use the
ProjectOperations interface.

Change-Id: I185c204f6acbf542f7d80454fe67ce892147473a
2019-02-05 10:43:17 +09:00
Edwin Kempin
51b1b742d3 Fix some nits in JavaDoc of classes that implement group storage in NoteDb
Signed-off-by: Edwin Kempin <ekempin@google.com>
Change-Id: I77a2e97254077dfc5f6b77e9430df0d4f39507a2
2019-02-04 14:38:52 +01:00
David Ostrovsky
712f699db9 ListChildProjects: Make settting recursive option chainable
Change-Id: I4ffa174cd8ba2b062cd230a8e116f45c65f58693
2019-02-04 20:22:14 +09:00
David Ostrovsky
d3039e7143 ListChildProjects: Add limit option
Change-Id: Ied90e49cec5c9b658ad65e7a8ab45f2ec5e03948
2019-02-04 20:22:05 +09:00
David Ostrovsky
ddd38f36dc ListChildProjects: Use parent predicate to find child projects
Change-Id: I4c51f0c3826a71ad4aec9246e07883741b95b7ff
2019-02-04 20:21:46 +09:00
David Ostrovsky
f358a748bb QueryProjects: Make setter methods chainable
Change-Id: I8544af6114d554b39d11358971fed77c1b0b8f6b
2019-02-04 09:22:40 +01:00
David Ostrovsky
30b0a80290 Project index: Add parent predicate
Enabling the search by parent enables the rewrite
of the ListChildProjects REST-API that extracts the children
of a project. Using the Lucene index avoids the full scan
of the ProjectCache and thus speedup the extraction and
reduce the JVM heap consumption.

Bug: Issue 10401
Change-Id: I568d6ba0e5a0bff391f57e2357de6d059d77fe5d
2019-02-02 22:54:33 +00:00
David Pursehouse
1d531da9d8 Merge "Rename DisallowCreationAndDeletionOfUserBranches" 2019-02-02 14:35:50 +00:00
Jonathan Nieder
e6cf33d150 Cleanup: Use method references instead of lambdas
Just a small readability improvement.  No functional change intended.

The lambdas were found using

 git grep -Ovi -e '\([a-z0-9]\+\) -> \1\.[^.]*()[,);]'

Signed-off-by: Jonathan Nieder <jrn@google.com>
Change-Id: I6abc206d555e3215f80e45cdaf180cea0050fcd3
2019-02-01 18:43:28 -08:00
Edwin Kempin
8a5abacfd6 Rename DisallowCreationAndDeletionOfUserBranches
DisallowCreationAndDeletionOfUserBranches no longer applies to user
branches only, but also disallows the creation and deletion of group
branches. Give it a more generic name.

Signed-off-by: Edwin Kempin <ekempin@google.com>
Change-Id: I73d37a59b68d68c062376da114de3762bdd08461
2019-02-01 12:38:27 +01:00
Edwin Kempin
c95a285ec3 Schema versions: Pass arguments into upgrade method, not to the constructor
Schema migrations do all their work in the upgrade method. This is the
place where they need to access the arguments. If the arguments are
passed into the constructor, each schema migration must save the
arguments in a local member veriable to make them accessible from the
upgrade method. To save this boilerplate code we now directly pass the
arguments into the upgrade method. This means schema versions don't
need to define any constructor since the default constructor is all that
is needed.

Signed-off-by: Edwin Kempin <ekempin@google.com>
Change-Id: Ie35d088bde76c0d11440b073034ecdae8df59a2c
2019-02-01 11:46:37 +01:00
Paladox
0614869051 Merge branch 'stable-2.16'
* stable-2.16:
  Elasticsearch: Support and use v6.6.0 for testing
  Adds <noscript> to PolyGerritIndexHtml.soy

Change-Id: I916e1fdca110f0e958e05ea74e100c9883cc0d30
2019-01-31 13:57:01 +00:00
Paladox
22d300fc28 Merge branch 'stable-2.15' into stable-2.16
* stable-2.15:
  Elasticsearch: Support and use v6.6.0 for testing
  Adds <noscript> to PolyGerritIndexHtml.soy

Change-Id: I93e6121d3fbb97d3f6598131148d50c73db19704
2019-01-31 13:51:23 +00:00
Edwin Kempin
d41d9d4aa1 Merge "Add StoredValues.PLUGIN_CONFIG_FACTORY" 2019-01-31 07:41:30 +00:00
Chih-Hung Hsieh
b67992fa22 Add StoredValues.PLUGIN_CONFIG_FACTORY
First customer will be the find-owners plugin to get
plugin config parameters in project.config and gerrit.config.

Change-Id: I6bbc3cbad93b31aa8dc36b711ad6d74acef05424
2019-01-30 17:56:23 -08:00
Changcheng Xiao
bc166f79a1 CreateChange: move code for create change to a method
With this and previous commits, code in "CreateChange"
is reorganised for better readability. Each method is
relatively small and mainly serves for one
functionality.

Change-Id: I893e38ee726f245706a5bb266b7c291de40bfbf6
2019-01-30 16:49:35 +01:00
Changcheng Xiao
63dd3ef21c CreateChange: move code for creating commit message to a method
Change-Id: I3d55aa5efb5cfdc923e16f80680547b495e53c22
2019-01-30 16:48:47 +01:00
Changcheng Xiao
7d9a8ce557 CreateChange: move logic for getting parent commit to its own method
Change-Id: I1a139f4c98a0a6caaf6d4ab159924e60a6eb4281
2019-01-30 16:48:47 +01:00
Changcheng Xiao
959e7843c4 CreateChange: move logic for getting base change to its own method
Change-Id: Iea0227ff8206e46e909a3961542861fc3935d61e
2019-01-30 16:48:47 +01:00
Changcheng Xiao
de240acfb3 CreateChange: move out checks for "merge" field of the ChangeInput
This check is required for the input and can be done before
lots of the above code being executed. Moving it to
rejected early.

Change-Id: I62ed7b18bfa441dc6d7addb06a105069932acd9d
2019-01-30 16:47:49 +01:00
Changcheng Xiao
4a2e5eb0ec CreateChange: move logic for "isWorkInProgress" to #checkAndSanitizeChangeInput
Change-Id: Iac3991542fd4a20d1b443eae2ce322bd0ae37d59
2019-01-30 16:46:14 +01:00
Changcheng Xiao
bccf27e260 CreateChange: move permission checks to its own method
This commit groups those permission checks to a dedicated
method. It also renames "rsrc" to "projectResource" to make
it more readable.

Change-Id: I7b9ed0f9aa3d4af5e3fb1a9d0b9de96455d605a8
2019-01-30 16:45:44 +01:00
Changcheng Xiao
97ab6d8f7c CreateChange: move logic for "isPrivate" to #checkAndSanitizeChangeInput
Change-Id: Ia384c293c229c3d398c2bb68c64d434191a561db
2019-01-30 16:45:08 +01:00
Changcheng Xiao
a2fc847e73 CreateChange: move code for preprocess input to its own method
The existing #clean method is merged into this new method. More
code for preprocessing will be merged into this method in the
followup methods.

Change-Id: I943708898b2e47c62912fad739fefe8dccdd36fd
2019-01-30 16:33:48 +01:00
Patrick Hiesel
da7e0fa958 Remove 'filterTagsSeparately' option
filterTagsSeparately was an option to make refs computation faster. It
was used from parts in Gerrit that didn't need this option and wanted
a faster computation. Now that we have restricted tags to be reachable
from refs/heads/* we can remove that extra complexity.

I764e16d introduced this originally.

Change-Id: I6c4a01db77ff9dad93439788100e8a4b090d946a
2019-01-30 16:02:33 +01:00
Changcheng Xiao
1bec79f5bf Project: remove unused methods
Change-Id: Idc3f3300718fda42258c34ff19914bacb8956f1e
2019-01-29 17:09:41 +01:00
Ardo Septama
ce7fb0d05c Introduce sequential success commit messages
As of now, gerrit will display successfully pushed commits based on
change number.
When user rebased and reordered the commits, this sequence is no longer
correct.

Features in depth:
- Commits list is ordered based on git history.
- New commit is indicated using [NEW].
- Updated and newly created commit no longer grouped.

--------------------------------------------------------
Example of current message:
--------------------------------------------------------
remote: New Changes:
remote:   http://192.168.50.1:8080/c/test/+/41 C 5

remote: Updated Changes:
remote:   http://192.168.50.1:8080/c/test/+/1 C 2
remote:   http://192.168.50.1:8080/c/test/+/2 C 3
remote:   http://192.168.50.1:8080/c/test/+/3 C 1
remote:   http://192.168.50.1:8080/c/test/+/21 C 4
--------------------------------------------------------
Example of the new sequential message:
--------------------------------------------------------
remote:   http://192.168.50.1:8080/c/test/+/3 C 1
remote:   http://192.168.50.1:8080/c/test/+/1 C 2
remote:   http://192.168.50.1:8080/c/test/+/2 C 3
remote:   http://192.168.50.1:8080/c/test/+/21 C 4
remote:   http://192.168.50.1:8080/c/test/+/41 C 5 [NEW]
--------------------------------------------------------

Change-Id: I7add03f7990b7d187e89c93b0c76a43a767a7dab
2019-01-29 08:43:09 +00:00
Edwin Kempin
2b2f3897cf Support searching changes which only touch certain file extensions
With the current 'extension' search operator it's possible to find
a) changes that contain at least one file with the given extension,
   e.g.: extension:txt
b) changes that contain no file with the given extension,
   e.g.: -extension:txt

However sometimes you want to match changes which only contain files of
a given extension, e.g. changes that only touch txt files. This can now
be done with the new 'only_extensions' search operator, e.g.:
  only_extensions:txt

It is also possible to specify multiple file extensions. E.g. matching
changes that only touch txt and jpg files can be done by:
  only_extensions:jpg,txt

By reversing the 'only_extensions' search operator it is possible to
match changes that not only touch files with certain extensions, e.g.:
  -only_extensions:jpg,txt

The order and the case in which the extensions are provided to the
'only_extensions' operator don't matter.

Also extensions can be specified with or without leading '.' (same as
for the 'extension' search operator).

Changes that contain files without file extension can be matched by
including an empty file extension into the file extension list, e.g.:
* changes that only include txt files and files without extension:
  only_extensions:,txt
* changes that only contain files without extension:
  only_extensions:,
  only_extensions:""

Signed-off-by: Edwin Kempin <ekempin@google.com>
Change-Id: I3d2b978ed455f835d1dad2daa920be0b0ec2ae36
2019-01-29 08:54:42 +01:00
Dave Borowitz
684d68e8d0 Merge changes from topic "audit-test-flakiness"
* changes:
  Move GitOverHttpServletIT tests into HttpPushForReviewIT
  GitOverHttpServletIT: Don't sandbox tests
  Fix GitOverHttpServletIT flakiness
  FakeGroupAuditService: Extend AuditService
  GitOverHttpServletIT: Make FakeGroupAuditService a field
2019-01-28 16:04:57 +00:00