Merge "One-off request context on behalf of a user"
This commit is contained in:
@@ -14,7 +14,9 @@
|
|||||||
|
|
||||||
package com.google.gerrit.server.util;
|
package com.google.gerrit.server.util;
|
||||||
|
|
||||||
|
import com.google.gerrit.reviewdb.client.Account;
|
||||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||||
|
import com.google.gerrit.server.IdentifiedUser;
|
||||||
import com.google.gerrit.server.InternalUser;
|
import com.google.gerrit.server.InternalUser;
|
||||||
import com.google.gwtorm.server.OrmException;
|
import com.google.gwtorm.server.OrmException;
|
||||||
import com.google.gwtorm.server.SchemaFactory;
|
import com.google.gwtorm.server.SchemaFactory;
|
||||||
@@ -27,25 +29,34 @@ import com.google.inject.Singleton;
|
|||||||
* Each call to {@link #open()} opens a new {@link ReviewDb}, so this class
|
* Each call to {@link #open()} opens a new {@link ReviewDb}, so this class
|
||||||
* should only be used in a bounded try/finally block.
|
* should only be used in a bounded try/finally block.
|
||||||
* <p>
|
* <p>
|
||||||
* The user in the request context is {@link InternalUser}.
|
* The user in the request context is {@link InternalUser} or the
|
||||||
|
* {@link IdentifiedUser} associated to the userId passed as parameter.
|
||||||
*/
|
*/
|
||||||
@Singleton
|
@Singleton
|
||||||
public class OneOffRequestContext {
|
public class OneOffRequestContext {
|
||||||
private final InternalUser.Factory userFactory;
|
private final InternalUser.Factory userFactory;
|
||||||
private final SchemaFactory<ReviewDb> schemaFactory;
|
private final SchemaFactory<ReviewDb> schemaFactory;
|
||||||
private final ThreadLocalRequestContext requestContext;
|
private final ThreadLocalRequestContext requestContext;
|
||||||
|
private final IdentifiedUser.GenericFactory identifiedUserFactory;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
OneOffRequestContext(InternalUser.Factory userFactory,
|
OneOffRequestContext(InternalUser.Factory userFactory,
|
||||||
SchemaFactory<ReviewDb> schemaFactory,
|
SchemaFactory<ReviewDb> schemaFactory,
|
||||||
ThreadLocalRequestContext requestContext) {
|
ThreadLocalRequestContext requestContext,
|
||||||
|
IdentifiedUser.GenericFactory identifiedUserFactory) {
|
||||||
this.userFactory = userFactory;
|
this.userFactory = userFactory;
|
||||||
this.schemaFactory = schemaFactory;
|
this.schemaFactory = schemaFactory;
|
||||||
this.requestContext = requestContext;
|
this.requestContext = requestContext;
|
||||||
|
this.identifiedUserFactory = identifiedUserFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ManualRequestContext open() throws OrmException {
|
public ManualRequestContext open() throws OrmException {
|
||||||
return new ManualRequestContext(userFactory.create(),
|
return new ManualRequestContext(userFactory.create(),
|
||||||
schemaFactory, requestContext);
|
schemaFactory, requestContext);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ManualRequestContext openAs(Account.Id userId) throws OrmException {
|
||||||
|
return new ManualRequestContext(identifiedUserFactory.create(userId),
|
||||||
|
schemaFactory, requestContext);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user