1020 Commits

Author SHA1 Message Date
Hector Oswaldo Caballero
6a23b311c9 RestApiServlet: Extract methods to find kind of request
As done with the GET and HEAD methods, extract to individual methods
checking if a request is of type DELETE, POST or PUT.

Change-Id: If159ea2aaaac32ac6747b1242cefbb6532dc63bc
2018-02-07 05:21:48 -05:00
Hector Oswaldo Caballero
0292e3ce75 RestApiServlet: Collapse identically handled exceptions
Change-Id: Id41beea30b266c4cadeeec9dd109306a8e04bbf0
2018-02-07 05:21:48 -05:00
Edwin Kempin
8330f32d21 Merge "Improve and document REST API errors on non-internal groups" 2018-02-07 09:18:26 +00:00
Edwin Kempin
d8808dccdb Merge "Remove unused InvalidUserNameException" 2018-02-07 09:11:09 +00:00
Edwin Kempin
8128e3f149 CurrentUser: Return Optional from methods that retrieve a property
Returning Optional makes it more explicit that callers must expect that
the return value is absent.

Change-Id: If739844482ac8966dbcdc2285869cfac7ab7e059
Signed-off-by: Edwin Kempin <ekempin@google.com>
2018-02-07 10:00:17 +01:00
xchangcheng
a0f7a2fece Merge changes from topic "group-audits"
* changes:
  Rename DbGroupMemberAuditListener to DbGroupAuditListener
  Send group audit events also when completely on NoteDb
  Redefine interface for group audit listeners
2018-02-06 19:02:04 +00:00
Dave Borowitz
5d90003964 Merge "ReplaceOp: Add more precise change kind messages" 2018-02-06 17:48:12 +00:00
Dave Borowitz
0211869220 ReplaceOp: Add more precise change kind messages
Using "Patch Set N was rebased" misleads the reader into thinking the
kind is TRIVIAL_REBASE, even though this message was previously used for
other types as well.

Change-Id: If4526c6ffae7d45b3ae16df9dc90bb4245906598
2018-02-06 12:37:39 -05:00
Dave Borowitz
bf5efd5e16 Improve and document REST API errors on non-internal groups
Many REST API endpoints require an internal group and return 405 if the
group is not an internal group. This is a non-obvious requirement and
contract of API, so make it explicit in the documentation.

Provide a more descriptive message in the error text, and add a new
subclass NotInternalGroupException to avoid the need to repeat ourselves
in each endpoint handler.

Change-Id: I993ebf98ce4eb565b9f98ff10742114d57ce6f9a
2018-02-06 12:22:42 -05:00
Han-Wen Nienhuys
c956776b92 Don't crash in GetAccess if refs/meta/config is missing
Change-Id: I6ad1b9802d104d2dac4fc4d20f9478bfde5bccdf
2018-02-06 18:07:48 +01:00
Edwin Kempin
f3d5600d0c Account: Remove @Column annotations and make members private
This class is no longer a ReviewDb class and hence these annotations are
no longer needed.

We cannot remove the @Column annotation from Account.Id. This because we
store a proto for changes in the change index which includes an account
ID and protobuf needs this annotation for encoding/decoding.

Change-Id: Id3ad4a3454b1fc84527bd3a578b9f8db85883cf8
Signed-off-by: Edwin Kempin <ekempin@google.com>
2018-02-06 14:17:53 +01:00
Changcheng Xiao
ef99d2abc1 Rename DbGroupMemberAuditListener to DbGroupAuditListener
Change-Id: I9a75a377d1118c9bc137a4d0055322a4d1a33fef
2018-02-06 12:46:27 +00:00
Changcheng Xiao
1f080ccf32 Send group audit events also when completely on NoteDb
This commit migrates the existing group audit listener from
the old GroupMemberAuditListener to the new GroupAuditListener
interface.

Before this commit, group audit events are dispatched only
for ReviewDb updates. After this, they will be dispatched for
both ReviewDb and NoteDb updates.

To make DbGroupMemberAuditListener easier for review, this commit
doesn't rename it. In the child change, it's renamed to
DbGroupAuditListener.

Change-Id: Ie9ad8ec3af0fb298556de677dcfcc0bf9f479a6c
2018-02-06 12:58:43 +01:00
Edwin Kempin
cb59a332a9 Remove unused InvalidUserNameException
Change-Id: I596ef0f427e7a31ebd36eece01dacf8194d194e2
Signed-off-by: Edwin Kempin <ekempin@google.com>
2018-02-06 10:38:49 +01:00
Edwin Kempin
783c5a5516 Slave mode: Pass error message about disabled SSH receive command to client
Gerrit slaves are read-only and hence pushing to them is disabled.
Pushes over SSH come in as git-receive-pack commands. For slaves this
command is mapped to an SSH Command class that fails immediately so that
pushes on slaves are disabled. This SSH Command class is also supposed
to provide a meaningful error message to the client (see change
Ia25012486b). However this didn't work:

1. A git-receive-pack command has the project name to which the push is
   done as argument:
   The SSH Command class that was bound for git-receive-pack commands on
   slaves didn't allow any argument. Hence the request already failed
   during the command parsing so that the bound SSH Command class was
   not executed.
2. When using JGit on client-side the exception message from the server
   didn't reach the client. On client side the error was always "Short
   read of block". Then the client checked whether the remote repository
   exists by fetching from it. For slaves this fetch works and then JGit
   returned "push not permitted" as error message to the callers.

To fix 1 the SSH Command class that is bound for git-receive-pack
commands on slaves now extends AbstractGitCommand which defines the
argument for the project name.

To fix 2 we write out a special ERR packet which allows to pass a
customized remote service error to the client.

The error message that we return from slaves when pushing is now
consistent between SSH and HTTP. In both cases we now throw a
ServiceNotEnabledException.

Change-Id: Id99e93d0127d58114b54b4deea7f5227b920c8e2
Signed-off-by: Edwin Kempin <ekempin@google.com>
2018-02-06 09:57:08 +01:00
David Pursehouse
6e78391950 Merge branch 'stable-2.15'
* stable-2.15:
  Reset state flags on loadData calls
  ReceiveCommits: Fix NEW_PATCHSET regex pattern
  CreateChangeIT#createNewChangeSignedOffByFooter: Remove unnecessary assume
  CommitValidators: Always check for Change-Id in subject line
  AbstractPushForReview: Factor repeated code to setRequireChangeId method
  Bazel: Use rules_closure from HEAD

Change-Id: Ifb35377d72c3f4bd085944f16a6a1264ecad2141
2018-02-06 08:45:03 +09:00
Dave Borowitz
83280ea879 Merge "Add Gerrit-Comment-In-Reply-To footer" 2018-02-05 19:16:32 +00:00
Dave Borowitz
a703d46418 Merge changes I070a28e1,I2856e04f
* changes:
  Add test for listing groups of a user in Gerrit slave mode
  Enable testing of Gerrit in slave mode
2018-02-05 19:13:11 +00:00
Edwin Kempin
a55c4396e8 AccountSshKey: Move from reviewdb.client package into server.account package
This class is no longer a ReviewDb class and shouldn't be used by the GWT UI.

Change-Id: I46b1b76c2375700ecaac5bc547e7507b11869d64
Signed-off-by: Edwin Kempin <ekempin@google.com>
2018-02-05 16:06:04 +01:00
Edwin Kempin
9640a61a84 AccountSshKey: Make members private and remove default constructor
The default constructor was needed for instantiated this class in the
GWT UI, but the GWT UI is no longer using this class.

Change-Id: I6ad28e50d2d617eb91fcff927ea77ac788d61833
Signed-off-by: Edwin Kempin <ekempin@google.com>
2018-02-05 15:43:49 +01:00
Edwin Kempin
8972f427fc Merge changes from topic "move-username-regexs-to-ExternalId"
* changes:
  AccountSshKey: Remove dependency to gwtorm
  Don't use Account class in GWT UI code
  Move regular expressions for user name from Account to ExternalId
  Account.Id: Return Optional from parse method
  ChangeField: Ignore invalid reviewer field values and log an error
  ChangeData: Expect that Account.Id.fromRefPart may return null
  AccountResolver: Inside of map methods use the id from the provided account
2018-02-05 14:43:22 +00:00
Changcheng Xiao
726c167ef1 Redefine interface for group audit listeners
We have migrated groups to NoteDb. But we didn't send audit events
to group audit listeners for NoteDb group updates. That means
existing listeners are broken. Instead of sending out NoteDb events
directly to fix them, we could take the chance to redefine a better
interface for those listeners. By doing this, we hope we don't need
to break them multiple times in the future.

This commit defines GroupAuditEvent interface which is implemented
by two group audit event, i.e. GroupMembersAuditEvent and
GroupSubgroupsAuditEvent. Hopefully, there will be
GroupRenameAuditEvent when we support renaming a group.

The follow-up commit will delete the old GroupMemberAuditLisenter
interface and migrate existing usages to the new interface.

Change-Id: I6d7d97e9cf5e4aae148d28e706b331163cf74d3e
2018-02-05 13:59:29 +01:00
Patrick Hiesel
dd8148165a Merge changes I25b301bb,Idc3308e3
* changes:
  Exclude cache-automerge refs from TagSet
  Exclude NoteDb meta refs from TagSet
2018-02-05 11:42:19 +00:00
David Pursehouse
017b222041 Merge changes I1f530f02,I66fb4509
* changes:
  Add @Nullable annotation to AccessSection
  Remove RefControl#isBlocked.
2018-02-05 10:54:51 +00:00
Edwin Kempin
87950e75cc AccountSshKey: Remove dependency to gwtorm
This class is no longer a ReviewDb class and should be moved out of the
reviewdb.client package. For this we must not depend on gwtorm classes
like IntKey.

Change-Id: I30181547b7ddf3d9d9cab53bdd12c4b9bb792ed5
Signed-off-by: Edwin Kempin <ekempin@google.com>
2018-02-05 11:40:21 +01:00
Edwin Kempin
c89f32404c Move regular expressions for user name from Account to ExternalId
User names are stored as external IDs, hence the regular expressions to
validate the format of a user name should be part of the ExternalId
class.

There is one place in the GWT UI where user names are validated. Since
the GWT UI doesn't have access to the ExternalId class it needs to copy
two of the regular expressions. This should be OK since the format of
user names is not expected to change and the GWT UI will be gone soon.
It's actually a goal to remove all dependencies from the GWT UI on the
Account class so that the Account class can be moved out of the
reviewdb.client package and be turned into an immutable AutoValue type.

Change-Id: I6ea7139019eb0e7f0e06efaf77ec4bd89d514006
Signed-off-by: Edwin Kempin <ekempin@google.com>
2018-02-05 11:13:44 +01:00
Patrick Hiesel
f9e3ef0b53 Exclude cache-automerge refs from TagSet
Similar to change refs, cache-automerge refs are not tag-able since
they are simply used for Gerrit-internal data representation. Excluding
them from the list of interesting refs in TagSet scales down on the
amount of work we have to do later on when calculating tags.

The fewer references we have prior to calculating the tags, the less
memory we'll need when using BitSets to deal with refs flags.

Change-Id: I25b301bba5f22e94c6339a6bf2e3b87a505202f3
2018-02-05 10:51:36 +01:00
Edwin Kempin
fb42262089 Account.Id: Return Optional from parse method
This is better than throwing a NumberFormatException as done before.
Callers can easily forget to handle NumberFormatException. It's better
to return an Optional so that it's obvious that callers must handle the
case where parsing didn't succeed.

Change-Id: I0bade70a31430674c739f7e1af51f71f22027c88
Signed-off-by: Edwin Kempin <ekempin@google.com>
2018-02-05 10:43:29 +01:00
Edwin Kempin
19d1baaa4f ChangeField: Ignore invalid reviewer field values and log an error
We didn't see any failures with this, but it's better to be able to
handle invalid data from the index.

Change-Id: I958ec9851337d9f76349e81c04ee2358a738dde5
Signed-off-by: Edwin Kempin <ekempin@google.com>
2018-02-05 10:43:12 +01:00
Edwin Kempin
a7c80b0003 ChangeData: Expect that Account.Id.fromRefPart may return null
In practice this should never happen since before calling
Account.Id.fromRefPart we verified that it's a change edit ref. Hence
this is not a bug-fix but rather improving readability.

We cannot annotate Account.Id.fromRefPart with @Nullable since the
Account class is used in the GWT UI where @Nullable is not available.
However the follow-up change modifies this method to return an Optional.

Change-Id: Iae9d34e4ee225decd6ab4367827c1505d18acbdb
Signed-off-by: Edwin Kempin <ekempin@google.com>
2018-02-05 10:43:06 +01:00
Edwin Kempin
827c755b75 AccountResolver: Inside of map methods use the id from the provided account
This should be always the same ID as 'id' but like this it's more
readable.

Change-Id: Ie7eed61baad09510ce98395ca1f5c672f08ea2b3
Signed-off-by: Edwin Kempin <ekempin@google.com>
2018-02-05 10:42:59 +01:00
Patrick Hiesel
545ce5b6e0 Exclude NoteDb meta refs from TagSet
Similar to normal change refs, meta refs are not tag-able. Excluding
them from the list of interesting refs in TagSet scales down on the
amount of work we have to do later on when calculating tags.

The fewer references we have prior to calculating the tags, the less
memory we'll need when using BitSets to deal with refs flags.

Change-Id: Idc3308e3378bfede57d95cd65457129484385794
2018-02-05 10:40:12 +01:00
Han-Wen Nienhuys
c4b4d96aff Add @Nullable annotation to AccessSection
Change-Id: I1f530f02840cffc6277c9d2a2235897c2b21e908
2018-02-05 10:15:07 +01:00
Han-Wen Nienhuys
ab3121d29c Remove RefControl#isBlocked.
This method is used only tests and in isOwner().

In isOwner, use the stronger canPerform() method.

Blocking a user is not a observable part of the permission system, so
it should not be tested. To check that a user is blocked, one should
grant permissions in a child project, and observe that the child
permission is ignored.

Change-Id: I66fb450901eec2169883724c55445fab8e5f7bfa
2018-02-05 10:15:03 +01:00
Edwin Kempin
5c676582ad AccountCache: Rename maybeGet to get
maybeGet is the method that most callers should use. Make this more
obvious by renaming it to get. Also the return type of Optional already
implies that there might not be a result, hence the method name doesn't
need to be explicit about this.

Change-Id: I571fa9989b2629d96f2238d4b8571d669a9bc89d
Signed-off-by: Edwin Kempin <ekempin@google.com>
2018-02-05 09:18:37 +01:00
Edwin Kempin
60951298e3 AccountCache: Rename get to getEvenIfMissing
AccountCache#get returns an empty AccountState to represent a missing
account, but most callers are not aware of this. Make this behavior
obvious by having an explicit name.

Most callers of AccountCache should use maybeGet and handle the missing
account case explicitly. A follow-up change can now rename maybeGet to
get to make it more obvious that this is the method that should be used
by default.

Within this series quite some callers of AccountCache#get have been
migrated to AccountCache#maybeGet. The remaining usages of
AccountCache#get (now AccountCache#getEvenIfMissing) cannot easily be
migrated to AccountCache#maybeGet, at least not without changing
behavior. Ideally we still want to migrate all callers to
AccountCache#maybeGet and then get rid of AccountCache#get (now
AccountCache#getEvenIfMissing), but this work is left for future
changes.

Change-Id: Ib993cb5ce9498ed52032ce9f7be0d314456ff20d
Signed-off-by: Edwin Kempin <ekempin@google.com>
2018-02-05 09:01:51 +01:00
David Ostrovsky
522a7b5d1b GroupReferenceSubject: Add GwtIncompatible annotation
This is needed to fix Super Dev mode, that is broken since: I5d19492102.

Change-Id: I03ab36ff2288efa530d4bd973d1fcb9189aeb005
2018-02-02 22:12:37 +01:00
Edwin Kempin
c3c9447470 ChangeNoteUtil: Use AccountCache#maybeGet instead of AccountCache#get
AccountCache#get returns an empty AccountState to represent a missing
account. Handle the missing account case explicitly instead of using an
empty AccountState.

Change-Id: I67a9309007c9946af8407258045aea11a49336ed
Signed-off-by: Edwin Kempin <ekempin@google.com>
2018-02-02 16:39:23 +01:00
Edwin Kempin
1c03fffbfe Merge changes I9369c39f,I03d7eeb4
* changes:
  ChangeNoteUtil: Support PersonIdent creation by account ID
  FromAddressGeneratorProvider: Use AccountCache#maybeGet instead of AccountCache#get
2018-02-02 15:10:48 +00:00
Edwin Kempin
d39f17e08e Merge changes I50d42d11,Ie7664e09,Ife28d99e,Ie206c53d
* changes:
  DbGroupMemberAuditListener: Use AccountCache#maybeGet instead of AccountCache#get
  AccountResolver: Use AccountCache#maybeGet instead of AccountCache#get
  ChangeResource: Use AccountCache#maybeGet instead of AccountCache#get
  SetMembersCommand: Use AccountCache#maybeGet instead of AccountCache#get
2018-02-02 15:04:21 +00:00
Edwin Kempin
34d63bba4f com.google.gerrit.server.account.AuthRequest: Initialize userName
Change Ia1fcdb3c9b made the getUserName() method return an Optional
and callers rely on this method to never return null. However when the
setUserName method was not invoked userName was still null. This
resulted in a NullPointerException when trying to create a new account
from the "New Account" button on the login page when using
DEVELOPMENT_BECOME_ANY_ACCOUNT [1]. Fix this by initializing userName
with Optional.empty().

[1]
com.google.gerrit.pgm.http.jetty.HiddenErrorHandler : Error in POST /login
java.lang.NullPointerException
        at com.google.gerrit.server.account.AccountManager.create(AccountManager.java:285)
        at com.google.gerrit.server.account.AccountManager.authenticate(AccountManager.java:147)
        at com.google.gerrit.httpd.auth.become.BecomeAnyAccountLoginServlet.create(BecomeAnyAccountLoginServlet.java:248)
        at com.google.gerrit.httpd.auth.become.BecomeAnyAccountLoginServlet.doPost(BecomeAnyAccountLoginServlet.java:100)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:661)
        ...

Change-Id: Ied5d6ec93e7e5d1b1f72106e2f28d0cd1c224c08
Signed-off-by: Edwin Kempin <ekempin@google.com>
2018-02-02 08:33:51 +01:00
Han-Wen Nienhuys
573706c324 Add more comments to PermissionCollection
Change-Id: I20bd619dd1d5eaba0d32308ba33b0728bdd48a17
2018-02-01 15:27:05 +01:00
Han-Wen Nienhuys
6af080d2b9 Separate part of PermissionCollection#filter into separate function
Change-Id: I486db4af7e10c2384e3c320a6d2b8c7d4f9f609d
2018-02-01 15:08:24 +01:00
Han-Wen Nienhuys
ac0191f607 Clarify the function of GroupMembership
Change-Id: I87b6feade47d940aef7468d0344242192aac3d01
2018-02-01 13:20:03 +01:00
David Pursehouse
a3090eed8b Merge branch 'stable-2.15'
* stable-2.15:
  Update git submodules
  Update git submodules
  Remove circular dependency between diff_summary and diff caches
  Fix build for bazel 0.9.0

Change-Id: Iaa995dad9962a1514aa5c201a464a28edc42f461
2018-02-01 13:43:51 +09:00
David Pursehouse
1c6b620bcc Merge "Clarify the per-userness of IncludingGroupMembership" 2018-02-01 01:44:04 +00:00
David Ostrovsky
ca8b39a981 Merge changes I9b6c165c,Iae24118a
* changes:
  Show project name in config push failure log 
  Further clarify the function of SectionSortCache
2018-01-31 19:32:34 +00:00
Han-Wen Nienhuys
ca632f9e4d Show project name in config push failure log
Change-Id: I9b6c165c3e1f5cb9ae2b4f23cbdbd421a08b7f1b
2018-01-31 17:24:06 +00:00
Han-Wen Nienhuys
7f54a2c63c Further clarify the function of SectionSortCache
Change-Id: Iae24118a0229bea1f9ea6800d75829d0d6a7387d
2018-01-31 18:23:48 +01:00
hanwen
08e8986fab Merge "Clarify use of PermissionCollection.Factory#filter." 2018-01-31 17:23:34 +00:00