CreateMergePatchSet: Implement 'author' to tweak Git commit author
This change implements the same functionality as I54b98be6 but for CreateMergePatchSet. Setting the newly exposed 'author' field requires the caller to have 'forgeAuthor' permission. Change-Id: Ia434ed0ed11489296d8c2aa9f8208faac293b563
This commit is contained in:
		| @@ -14,9 +14,12 @@ | ||||
|  | ||||
| package com.google.gerrit.extensions.common; | ||||
|  | ||||
| import com.google.gerrit.extensions.api.accounts.AccountInput; | ||||
|  | ||||
| public class MergePatchSetInput { | ||||
|   public String subject; | ||||
|   public boolean inheritParent; | ||||
|   public String baseChange; | ||||
|   public MergeInput merge; | ||||
|   public AccountInput author; | ||||
| } | ||||
|   | ||||
| @@ -55,6 +55,7 @@ import com.google.gerrit.server.notedb.ChangeNotes; | ||||
| import com.google.gerrit.server.permissions.ChangePermission; | ||||
| import com.google.gerrit.server.permissions.PermissionBackend; | ||||
| import com.google.gerrit.server.permissions.PermissionBackendException; | ||||
| import com.google.gerrit.server.permissions.RefPermission; | ||||
| import com.google.gerrit.server.project.ProjectCache; | ||||
| import com.google.gerrit.server.project.ProjectState; | ||||
| import com.google.gerrit.server.restapi.project.CommitsCollection; | ||||
| @@ -128,6 +129,13 @@ public class CreateMergePatchSet implements RestModifyView<ChangeResource, Merge | ||||
|     psUtil.checkPatchSetNotLocked(rsrc.getNotes()); | ||||
|  | ||||
|     rsrc.permissions().check(ChangePermission.ADD_PATCH_SET); | ||||
|     if (in.author != null) { | ||||
|       permissionBackend | ||||
|           .currentUser() | ||||
|           .project(rsrc.getProject()) | ||||
|           .ref(rsrc.getChange().getDest().branch()) | ||||
|           .check(RefPermission.FORGE_AUTHOR); | ||||
|     } | ||||
|  | ||||
|     ProjectState projectState = | ||||
|         projectCache.get(rsrc.getProject()).orElseThrow(illegalState(rsrc.getProject())); | ||||
| @@ -137,6 +145,10 @@ public class CreateMergePatchSet implements RestModifyView<ChangeResource, Merge | ||||
|     if (merge == null || Strings.isNullOrEmpty(merge.source)) { | ||||
|       throw new BadRequestException("merge.source must be non-empty"); | ||||
|     } | ||||
|     if (in.author != null | ||||
|         && (Strings.isNullOrEmpty(in.author.email) || Strings.isNullOrEmpty(in.author.name))) { | ||||
|       throw new BadRequestException("Author must specify name and email"); | ||||
|     } | ||||
|     in.baseChange = Strings.nullToEmpty(in.baseChange).trim(); | ||||
|  | ||||
|     PatchSet ps = psUtil.current(rsrc.getNotes()); | ||||
| @@ -166,7 +178,10 @@ public class CreateMergePatchSet implements RestModifyView<ChangeResource, Merge | ||||
|  | ||||
|       Timestamp now = TimeUtil.nowTs(); | ||||
|       IdentifiedUser me = user.get().asIdentifiedUser(); | ||||
|       PersonIdent author = me.newCommitterIdent(now, serverTimeZone); | ||||
|       PersonIdent author = | ||||
|           in.author == null | ||||
|               ? me.newCommitterIdent(now, serverTimeZone) | ||||
|               : new PersonIdent(in.author.name, in.author.email, now, serverTimeZone); | ||||
|       CodeReviewCommit newCommit = | ||||
|           createMergeCommit( | ||||
|               in, | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Patrick Hiesel
					Patrick Hiesel