1031 Commits

Author SHA1 Message Date
Edwin Kempin
50484b7b94 Merge changes Ie87c1c8e,I530116c8
* changes:
  Remove support for groups in ReviewDb
  Migrate groups to NoteDb
2018-03-28 06:17:45 +00:00
Patrick Hiesel
9104fa9ad9 Refactor Reachable to take Project.NameKey instead of ProjectState
This resolved a TODO I had put in code and makes the method more
light-weight.

Change-Id: I229b197d1e3798b409edaa409cb5ec4dedae2ccb
2018-03-27 18:44:35 +00:00
David Pursehouse
7769a2a437 Merge "Remove unused variables" 2018-03-27 16:32:55 +00:00
David Pursehouse
1aacb966ef Merge changes I8eace895,I3eafef10
* changes:
  Respect the configured server ID during in memory tests
  Make sure that footers in group config commit messages are sorted
2018-03-27 16:19:20 +00:00
Patrick Hiesel
4dcc9f36b3 Remove unused variables
These came out of a larger refactoring in I601ea1200a.

Change-Id: Ib3921d414bd26de5360b72ff709dd751382e8f18
2018-03-27 18:01:14 +02:00
Patrick Hiesel
ef17720a73 Merge "Remove PermissionBackend#user(Provider<CurrentUser>)" 2018-03-27 14:50:44 +00:00
Patrick Hiesel
4bdef6c030 Remove PermissionBackend#user(Provider<CurrentUser>)
Checking permissions of users that aren't the caller on the current request
can have implications on the security of the system. The most prominent
one is creating a group-oracle.

To limit the cases where we could potentially expose Gerrit to these
threats, PermissionBackend removes the method that was operating solely
on the provider of the current user.

Change-Id: I601ea1200a15a5f262ca0770b23cc1c7bee126b1
2018-03-27 15:57:45 +02:00
Edwin Kempin
9cae606cda Enable UI action to toggle WIP flag for admins
Change I4878f066b6 allowed administrators to toggle the WIP flag on any
change but the UI action was still disabled for admins.

Change-Id: I55dd6400dc07d57fe2aaaf3528ff429d5baf48ed
Signed-off-by: Edwin Kempin <ekempin@google.com>
2018-03-27 15:57:39 +02:00
Patrick Hiesel
659ea71969 Add currentUser() to PermissionBackend
Passing in a Provider<CurrentUser> into PermissionBackend is
boiler-platy. This change adds a convenience method to PermissionBackend
and DefaultPermissionBackend to limit this boiler-plate. Future commits
will remove #user(Provider<CurrentUser>) from PermissionBackend, once
all callers were moved.

Change-Id: Ifcd07fe2c7d2673a66b2b4f9eff06ee8a3b6b943
2018-03-27 10:58:37 +00:00
Edwin Kempin
95df75fae6 Remove support for groups in ReviewDb
Groups have been migrated to NoteDb. Hence we no longer need to be able
to read groups from ReviewDb.

Change-Id: Ie87c1c8e604cf1344af5291f0b369cd24af8387d
Signed-off-by: Edwin Kempin <ekempin@google.com>
2018-03-27 10:46:26 +02:00
Alice Kober-Sotzek
a9aabc879c Migrate groups to NoteDb
This change adds a schema migration that migrates Gerrit groups from
ReviewDb to NoteDb.

In NoteDb groups are stored in group refs in the All-Users repository.
When a group is migrated its group ref in NoteDb is overwritten if it
already exists.

If groups in ReviewDb have already been disabled (e.g. a new Gerrit
instance that directly used groups in NoteDb, or if groups have been
migrated differently) this schema migration does nothing, as we don't
want to overwrite group information in NoteDb with potentially outdated
ReviewDb content.

The commits in the group refs form the audit log of the group. This is
why the migration creates one commit per audit event in the group ref.

When members or subgroups are added or removed they are listed as
footers in the commit message. For subgroups this footer line contains
the group name and the group UUID. The schema migration can set the
proper group name only for Gerrit internal groups and system groups,
but not for external groups since the external group backends, which are
needed to resolve the UUID to the group name, are not available during
init. For groups which cannot be resolved during init the UUID is used
as group name. This is only a cosmetic issue with the commits of the
group refs that might affect human readers of the history. When Gerrit
is reading the audit log it doesn't rely on the group names in the
footers, but resolves the group UUIDs via the group backends.

After the migration has been done all groups are now fully in NoteDb.
The default values for the group migration configuration are changed so
that NoteDb is used as primary storage for groups and groups in ReviewDb
are disabled. Writing groups to NoteDb can no longer be disabled because
after this point there will be no further migration to copy group data
from ReviewDb to NoteDb.

GroupRebuilderIT is merged into the new
Schema_166_to_167_WithGroupsInReviewDbTest.

Change-Id: I530116c8c5a6a5c595d24ca2445ffa921c2d3eb0
Signed-off-by: Edwin Kempin <ekempin@google.com>
2018-03-27 10:46:20 +02:00
Patrick Hiesel
548d22f29b Merge "Add Java implementation of the label functions" 2018-03-27 08:43:44 +00:00
Maxime Guerreiro
c275089fc9 Add Java implementation of the label functions
Add unit tests for the labels functions.
Check if prolog rules are defined for this project or its parents, and
if not default to the added Java implementations of LabelFunctons.

Before this commit, the Prolog rules engine was always invoked to check
wether a change can be submitted or not, even if no prolog rules were
defined.
Doing so should also make it easier to extract Prolog as a plugin
without losing any of its currently offered features (label functions
and default rules implementation).

The LabelFunction code is inspired by Saša Živkov's change Iffe1567,
adjusted to live directly in the enum.

Change-Id: I5e18b0d494be3f0423bb533ed84a63ea4b8a31df
2018-03-27 09:47:23 +02:00
xchangcheng
5d5a21c8d9 Merge "CheckAccess: don't catch PermissionBackendException" 2018-03-27 07:16:19 +00:00
Edwin Kempin
ca90860ef4 Merge "GroupBundle: Fix reading visibleToAll from ReviewDb" 2018-03-27 07:14:45 +00:00
Edwin Kempin
4a55f249ff Respect the configured server ID during in memory tests
Some tests want to configure the server ID via the Gerrit config.
InMemoryModule should respect this setting if it is there and only
fallback to the hard-coded server ID if this config is missing.

Change-Id: I8eace895978d221b8d4e726a4c5428bc16f9e77b
Signed-off-by: Edwin Kempin <ekempin@google.com>
2018-03-27 09:01:30 +02:00
Edwin Kempin
99cdabf582 Make sure that footers in group config commit messages are sorted
E.g. GroupConfigCommitMessage#getFooters is using Sets for the footers
and hence the order was not guaranteed. As result of this tests checking
group audit logs could be flaky.

The AuditLogFormatter in AbstractGroupTest is now loading the real group
names instead of using 'Group <uuid>'. This is needed to control the
order of the subgroup modification footers from the AuditLogReaderTest.
If the real name is not included into these footers the sort order
depends on the generated UUIDs. Since the UUIDs are generated based on
the group name and the server ID they are stable for each run, but
relying on the order of the UUIDs makes the test at least less readable.

The AuditLogFormatter in AbstractGroupTest is loading the group from the
repo each time a group name is needed. Since it's an in memory
repository and there are only few tests using this AuditLogFormatter we
don't bother about caching here.

Reading footers from group config commit messages works regardless of
the order of the footers. This means this change doesn't require
rewriting already existing group refs.

Change-Id: I3eafef10e916890b90d9f9ac222595eaf2246e27
Signed-off-by: Edwin Kempin <ekempin@google.com>
2018-03-27 08:49:08 +02:00
Changcheng Xiao
a2ece68f1a DefaultRefFilter: log error for PermissionBackendException
This commit changes this class so that every PBE will be logged
out as an error. But another option is throwing out this
exception since it stands for an error on the server side.

Change-Id: I231ab13ebeb9e5b37788875355d675c17f68745b
2018-03-27 08:16:30 +02:00
Changcheng Xiao
6f7b253901 CheckAccess: don't catch PermissionBackendException
By design, PermissionBackendException stands for some error
in the permission backend. It doesn't mean the user doesn't
hold the checked/tested permission. Thus this endpoint should
not catch PBE and treat it the same with AuthException.

Change-Id: Ibbb99fb3648a1bfdbdea922cdb94a77f6824c141
2018-03-26 21:09:03 +02:00
Patrick Hiesel
059e7e7a33 Merge changes from topic "remove-project-ctl-isHidden"
* changes:
  ProjectControl: remove "isHidden" when checking "READ" permission
  UploadArchive: check ProjectState readable before checking "READ" permission
  ListProjects: check ProjectState readable before checking "READ" permission
  ProjectIsVisibleToPredicate: check ProjectState readable before checking "READ" permission
  DefaultRefFilter: check ProjectState readable before checking "READ" permission
  AsyncReceiveCommits: check ProjectState readable before checking "READ" permission
  GitWebServlet: check ProjectState readable before checking "READ" permission
2018-03-26 15:40:25 +00:00
Changcheng Xiao
3d002433fc ProjectControl: remove "isHidden" when checking "READ" permission
Change-Id: I687f2957135bfba3c3a66617828980ddc5b14c85
2018-03-26 13:12:45 +00:00
Changcheng Xiao
581dbf9f32 UploadArchive: check ProjectState readable before checking "READ" permission
Change-Id: I77756f59e60dba33fc6f3b659bebb0c1bbac2ea6
2018-03-26 13:12:39 +00:00
Changcheng Xiao
80e5273562 ListProjects: check ProjectState readable before checking "READ" permission
Change-Id: I7c3724927afe7427434e6ae84b33310491c3e098
2018-03-26 13:12:29 +00:00
Changcheng Xiao
0c4a378264 ProjectIsVisibleToPredicate: check ProjectState readable before checking "READ" permission
Change-Id: Ie6602e373f98d8bdf8c13cd4213145da88709afa
2018-03-26 15:11:53 +02:00
Edwin Kempin
4f908ced60 GroupBundle: Fix reading visibleToAll from ReviewDb
In ReviewDb visibleToAll is stored as 'Y'/'N'.

Change-Id: Ia7d7f8fecf3d076ec3e0449850a8bb6c276baac5
Signed-off-by: Edwin Kempin <ekempin@google.com>
2018-03-26 14:55:22 +02:00
Changcheng Xiao
179ce3726b DefaultRefFilter: check ProjectState readable before checking "READ" permission
Change-Id: I0a5f3dd5fb0bb2ddf47abc72a840c68ef088c60c
2018-03-26 11:21:29 +00:00
Changcheng Xiao
8d99576d47 AsyncReceiveCommits: check ProjectState readable before checking "READ" permission
Change-Id: I2958b75916886b047f778f38dac2fe6cdab9712e
2018-03-26 11:21:07 +00:00
Changcheng Xiao
a39176467a GitWebServlet: check ProjectState readable before checking "READ" permission
Change-Id: I20921ffaa5a9e49d80365a40dbd506957ea8cadf
2018-03-26 13:19:42 +02:00
Edwin Kempin
009ac5341e Merge "CreateProject: throw RuntimeException when creation failed" 2018-03-26 08:38:16 +00:00
Changcheng Xiao
8003295e22 CreateProject: throw RuntimeException when creation failed
Create project could fail when there are concurrent requests.
For example, in the test
CreateProjectIT#createSameProjectFromTwoConcurrentRequests.

Like other places, it's good to check whether ProjectState is
null before use.

Change-Id: I9dc590912f6ffa1878a3974991f78ccf51ca9ad1
2018-03-26 07:35:16 +00:00
xchangcheng
1f70c63694 Merge "Move AccessResource to "restapi.access" package" 2018-03-26 07:23:07 +00:00
Changcheng Xiao
5f8ce550bf Move AccessResource to "restapi.access" package
Change-Id: Iafbec48e2cf45fd0729296d2bacf6da1c09a6e0b
2018-03-26 06:40:00 +00:00
David Pursehouse
5c329be1b7 Merge "Remove unused class "ProjectRef"" 2018-03-25 08:52:38 +00:00
Changcheng Xiao
e31fc7d169 Remove unused class "ProjectRef"
Change-Id: I381fb854952a7354535e326fd64882603ff136a5
2018-03-23 15:08:02 +01:00
Hugo Arès
0894a276ae Merge "Allow admins to toggle the WIP flag on all changes" 2018-03-23 13:49:49 +00:00
Edwin Kempin
812bacc7b3 Allow admins to toggle the WIP flag on all changes
Sometimes this can be useful, e.g. if one developers starts a WIP
change, goes to vacation and another developer makes the change ready.
At the moment the WIP flag cannot be removed by anyone else than the
change owner.

Change-Id: I4878f066b633b349dbfe927480ebb143539bf4d3
Signed-off-by: Edwin Kempin <ekempin@google.com>
2018-03-23 07:41:14 +01:00
Maxime Guerreiro
8d129d41f5 Add Gerrit's instance name and reference it in notification emails
Gerrit users active on several Gerrit servers may find it hard to
determine the gerrit instance related to an email.
This commit fixes it by adding a Gerrit instance name to the email
titles, right before the project's short name.
For instance, for a Gerrit instance called "Pear" and the project
"website/forum", the notification email titles will contain "Pear/forum".

Also add configuration to disable this behavior.
Change-Id: I6c842f33ce605125ec64ca7d09643f59aa96a02d
2018-03-22 16:30:08 +01:00
Edwin Kempin
44cb0fd77a Move GroupRebuilder and GroupBundle into schema package
GroupRebuilder and GroupBundle are supposed to be only used by schema
migrations. Make sure that they are not used otherwise by moving them
into the schema package.

Change-Id: I094043259720edec9b60309f0ec0535bf0505d9e
Signed-off-by: Edwin Kempin <ekempin@google.com>
2018-03-22 08:27:09 +01:00
Edwin Kempin
e41ac7a198 AbstractGroupTest: Include UUID into group names
This is better than checking a constant group name that is the same for
all groups.

Change-Id: Ie92327bb1d5f285f3ef65fa229f1b3ee863cd8f6
Signed-off-by: Edwin Kempin <ekempin@google.com>
2018-03-22 08:27:09 +01:00
Edwin Kempin
1d31982d06 Make GroupRebuilder useable from schema migration
We want to use GroupRebuilder from a schema migration to migrate Gerrit
groups to NoteDb. For this GroupRebuilder must not depend on classes
which are not available during init:

- Don't use MetaDataUpdate.InternalFactory but instead instantiate
  MetaDataUpdate directly (it's okay to use GitReferenceUpdated.DISABLED
  since we don't fire events during init and init is the only place
  where GroupRebuilder is used).
- Don't create an AuditLogFormatter from account cache, group cache and
  server ID but instead require that the AuditLogFormatter is created
  and passed in by the caller.

Change-Id: Ib43e3121ec99c38ef4c1a1879c48d879118fb4c4
Signed-off-by: Edwin Kempin <ekempin@google.com>
2018-03-22 08:27:09 +01:00
Edwin Kempin
0ae2c32c17 GroupBundle.Factory#fromReviewDb: Require UUID as input instead of ID
This will make it easier to use this method from the schema migration
that implements the migration of Gerrit groups to NoteDb.

Change-Id: Ic15d54c240998796bb5e8ad91a8b8144674c8af0
Signed-off-by: Edwin Kempin <ekempin@google.com>
2018-03-22 08:27:09 +01:00
Edwin Kempin
53f55312bf GroupBundle.Factory: Make fromReviewDb method static
This will allow us to use this method from the schema migration that
implements the migration of Gerrit groups to NoteDb.

Change-Id: I12ba4a0217ae9479f32c6c5f3fc0a834fd127e30
Signed-off-by: Edwin Kempin <ekempin@google.com>
2018-03-22 08:27:09 +01:00
Edwin Kempin
0b992cc55e GroupBundle: Use SQL to read group data from ReviewDb
The Gerrit groups will be migrated to NoteDb. Once this is done reading
groups from ReviewDb will be no longer supported and the
AccountGroup*Access classes will be removed.

The GroupBundle class will be used by the schema migration that migrates
the Gerrit groups from ReviewDb to NoteDb and we need to keep this
migration running for some longer time to support Gerrit upgrades.

This means GroupBundle will still exist when the AccountGroup*Access
classes are already gone. Hence to read group data it cannot rely on the
AccountGroup*Access classes, but must use plain SQL to retrieve this
data from ReviewDb.

Change-Id: If4bc99191bc7cd0e713c9666c2d52b278fe3a246
Signed-off-by: Edwin Kempin <ekempin@google.com>
2018-03-22 08:27:09 +01:00
David Pursehouse
58e7335c59 CanSeeChangePredicate: Add missing license/copyright header
Change-Id: I942d3a06a1ef9f701427318a75a893c471e95305
2018-03-22 14:28:46 +09:00
Edwin Kempin
26e3c95c89 Merge "Revert "Add config option to prevent group updates while migrating groups"" 2018-03-21 09:20:01 +00:00
Edwin Kempin
6b458c6cd6 Merge "Remove REST endpoint to rebuild individual groups in NoteDb" 2018-03-21 09:19:20 +00:00
Dave Borowitz
af83e8cb57 Merge changes I53434efc,I21a889f2
* changes:
  SubmoduleOp: Don't require ProjectState.Factory
  Move ProjectLevelConfig to project package
2018-03-20 14:56:26 +00:00
Alice Kober-Sotzek
033b48c396 Revert "Add config option to prevent group updates while migrating groups"
This reverts commit 809de7e70c9a974df0a4c467ab731938c8b81d85.

Reason for revert: Groups are migrated offline with change I530116c8c5a.
Hence, we don't need to prevent any intermediate group updates.

Change-Id: I28113f8dbca7698a2335ae315405e7893636a745
2018-03-20 09:36:21 +01:00
Alice Kober-Sotzek
3afca9eb0d Remove REST endpoint to rebuild individual groups in NoteDb
This change partially reverts I84201c0c9d.

A follow-up change will migrate all groups from ReviewDb to NoteDb.
Further follow-up changes will remove all ReviewDb code for groups.
Hence, we don't need this REST endpoint anymore, which only existed
temporarily while implementing groups in NoteDb.

Change-Id: Ia2cf0c75a80e34ef9a8d8c8063b08388fa5fae9c
2018-03-20 08:58:16 +01:00
Edwin Kempin
191aaa7e24 Limit assignee suggestions to users that can see the change
Bug: Issue 5181
Change-Id: Ib64248a285e8feca1fd8f18e825f302d09d252ed
Signed-off-by: Edwin Kempin <ekempin@google.com>
2018-03-20 07:55:58 +00:00