1023 Commits

Author SHA1 Message Date
Patrick Hiesel
21ef5af63b Adapt JavaDoc of PermissionBackend to 'Returns' instead of @return
This is preferred in case there is no summary fragment:
https://google.github.io/styleguide/javaguide.html#s7.2-summary-fragment

Change-Id: Ieeda088f22d3707a1efd627501f6d3c0f4b1a743
2018-03-27 17:39:00 +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
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
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
Edwin Kempin
f4f0f8a222 Merge "Add account predicate that checks if user can see a certain change" 2018-03-20 07:17:21 +00:00
Dave Borowitz
87df97aa95 SubmoduleOp: Don't require ProjectState.Factory
The only usage of this class is to create a ProjectState from a
ProjectConfig acquired from a ProjectState returned by the ProjectCache.
No need for this indirection; just use the original ProjectState.

Change-Id: I53434efc3c59bb2992f54ef262076030db55badd
2018-03-19 17:09:56 -04:00
Dave Borowitz
7928861637 Move ProjectLevelConfig to project package
This class is tightly related to ProjectState, which lives in this
package.

Change-Id: I21a889f23d95eaf4af40f47b2569550d7d53ea8d
2018-03-19 14:57:13 -04:00
Dave Borowitz
abafb7c1ae Move non-Gerrit-specific project index code to new package
This is similar to the split between index and server.index: these
pieces of the index code do not depend on Gerrit internals and may be
used to implement a project index in non-Gerrit servers. In other words,
this is the logical continuation of the work started in I07beec95.

Change-Id: Ic56eb46a5386cdd72f62117ad36b24ca85659809
2018-03-19 16:26:22 +00:00
David Pursehouse
e9dac39d6b Merge branch 'stable-2.15'
* stable-2.15:
  Fix formatting in MergeInput documentation
  Fix assertions on iterable size in tests
  Fix example ref in 'Create Merge Patch Set For Change' documentation
  Fix documentation for CreateMergePatchSetForChange REST API endpoint.
  LightweightPluginDaemonTest: Expose plugin guice injectors

Change-Id: Ief9930217e4769aac629b076316cdb3b47edfd11
2018-03-19 08:45:01 +09:00
David Pursehouse
5a459ca62a Merge branch 'stable-2.15'
* stable-2.15:
  Fix logic in NoteDbMigrator#canSkipPrimaryStorageMigration

Change-Id: Ib6642b8b38556ab2f5d906bac25d2160dedd2522
2018-03-18 12:34:53 +09:00
David Pursehouse
3c62aa0d0b Merge branch 'stable-2.15'
* stable-2.15:
  Skip migrating inline comments on missing patch set parents
  Temporarily increase heap size of NoteDb migration tests
  Log the reason why a project cannot be found
  Change kind cache: short-circuit on root commits
  Document that gitweb.type must be set
  Tidy up config-gitweb
  Change kind cache: short-circuit on root commits
  Do not abort indexing if < 50% projects failed
  Improve documentation of `index.maxLimit` for Elasticsearch
  InitIndex: Set Elasticsearch index config under elasticsearch section
  Link to hashtag intro docs from more places
  user-upload.txt: Document setting hashtags on push
  intro-user.txt: Document hashtags
  user-search.txt: Document hashtag operator
  intro-user.txt: Mention that topics may affect submission
  Add NoteDb migration test for change with no patch set refs
  NoteDbMigrator: Totally skip changes with no patch sets
  Add more tests for rebuilding changes missing some entities
  Fix Change-Id in revert email
  Widen set of My Drafts menus that are automatically removed
  Migrate old My Drafts menus in refs/users/default

This partially reverts commit e518d9dacc9d4cc547cb5935101859e36072ccb0
because Schema_159_to_160_Test references PREFERENCES which was made
private, and uses the forDefault method which was removed. This commit
makes PREFERENCES package visible and re-adds the forDefault method as
a package visible method.

Change-Id: Ifba662a47197b3a5f17988fc69896cdca1ff853b
2018-03-17 10:08:39 +09:00
Alice Kober-Sotzek
02c1c05b28 Merge changes I43df0fa0,I8eba8b0c
* changes:
  AccountIndexer: Remove reindex if stale after original index update
  Make sure to never use cached values when indexing accounts
2018-03-16 15:24:41 +00:00