summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYash Chaturvedi <yash.chaturvedi@linaro.org>2023-10-12 14:38:47 +0530
committerYash Chaturvedi <yash.chaturvedi@linaro.org>2023-10-12 22:05:47 +0530
commit3e4d612b8b7ead85bfcb86e029b013b6758203b7 (patch)
treec7a239bfb1cde75d4e205b03cea62eb6e2392c9f
parentfe271837a9e7f78494db8b3169824656248eaac1 (diff)
parente56d2c66234225094a2b322b8e6b606ad42598b8 (diff)
Merge branch 'stable-3.5' into stable-3.6
* stable-3.5: Fix bug where changing preferred email results in duplicate emails Fix the warning to not appear while loading a plugin Change-Id: If2f6fdc23c1b8537423136fa3cf51dde32c393b9 Release-Notes: skip
-rw-r--r--java/com/google/gerrit/sshd/SshPluginStarterCallback.java20
-rw-r--r--polygerrit-ui/app/services/gr-rest-api/gr-rest-api-impl.ts4
-rw-r--r--polygerrit-ui/app/services/gr-rest-api/gr-rest-api-impl_test.js25
3 files changed, 45 insertions, 4 deletions
diff --git a/java/com/google/gerrit/sshd/SshPluginStarterCallback.java b/java/com/google/gerrit/sshd/SshPluginStarterCallback.java
index 6e8590c888..55ecdfeecf 100644
--- a/java/com/google/gerrit/sshd/SshPluginStarterCallback.java
+++ b/java/com/google/gerrit/sshd/SshPluginStarterCallback.java
@@ -24,6 +24,10 @@ import com.google.inject.Inject;
import com.google.inject.Key;
import com.google.inject.Provider;
import com.google.inject.Singleton;
+import com.google.inject.TypeLiteral;
+import com.google.inject.internal.MoreTypes;
+import java.util.ArrayList;
+import java.util.List;
import org.apache.sshd.server.command.Command;
@Singleton
@@ -63,9 +67,9 @@ class SshPluginStarterCallback implements StartPluginListener, ReloadPluginListe
try {
return plugin.getSshInjector().getProvider(key);
} catch (RuntimeException err) {
- if (!providesDynamicOptions(plugin)) {
+ if (!providesDynamicOptions(plugin) && !providesCommandInterceptor(plugin)) {
logger.atWarning().withCause(err).log(
- "Plugin %s did not define its top-level command nor any DynamicOptions",
+ "Plugin %s did not define its top-level command, any DynamicOptions, nor any Ssh*CommandInterceptors",
plugin.getName());
}
}
@@ -76,4 +80,16 @@ class SshPluginStarterCallback implements StartPluginListener, ReloadPluginListe
private boolean providesDynamicOptions(Plugin plugin) {
return dynamicBeans.plugins().contains(plugin.getName());
}
+
+ private boolean providesCommandInterceptor(Plugin plugin) {
+ List<TypeLiteral<?>> typeLiterals = new ArrayList<>(2);
+ typeLiterals.add(
+ MoreTypes.canonicalizeForKey(
+ (TypeLiteral<?>) TypeLiteral.get(SshExecuteCommandInterceptor.class)));
+ typeLiterals.add(
+ MoreTypes.canonicalizeForKey(
+ (TypeLiteral<?>) TypeLiteral.get(SshCreateCommandInterceptor.class)));
+ return plugin.getSshInjector().getAllBindings().keySet().stream()
+ .anyMatch(key -> typeLiterals.contains(key.getTypeLiteral()));
+ }
}
diff --git a/polygerrit-ui/app/services/gr-rest-api/gr-rest-api-impl.ts b/polygerrit-ui/app/services/gr-rest-api/gr-rest-api-impl.ts
index 2729e6926f..567045dc31 100644
--- a/polygerrit-ui/app/services/gr-rest-api/gr-rest-api-impl.ts
+++ b/polygerrit-ui/app/services/gr-rest-api/gr-rest-api-impl.ts
@@ -819,9 +819,9 @@ export class GrRestApiServiceImpl implements RestApiService, Finalizable {
if (cachedEmails) {
const emails = cachedEmails.map(entry => {
if (entry.email === email) {
- return {email, preferred: true};
+ return {email: entry.email, preferred: true};
} else {
- return {email};
+ return {email: entry.email, preferred: false};
}
});
this._cache.set('/accounts/self/emails', emails);
diff --git a/polygerrit-ui/app/services/gr-rest-api/gr-rest-api-impl_test.js b/polygerrit-ui/app/services/gr-rest-api/gr-rest-api-impl_test.js
index d8c3ff274f..b4defb50c0 100644
--- a/polygerrit-ui/app/services/gr-rest-api/gr-rest-api-impl_test.js
+++ b/polygerrit-ui/app/services/gr-rest-api/gr-rest-api-impl_test.js
@@ -459,6 +459,31 @@ suite('gr-rest-api-service-impl tests', () => {
assert.deepEqual(sendStub.lastCall.args[0].body, {token: 'foo'});
});
+ test('setPreferredAccountEmail', () => {
+ const email1 = 'email1@example.com';
+ const email2 = 'email2@example.com';
+ const encodedEmail = encodeURIComponent(email2);
+ const sendStub = sinon.stub(element._restApiHelper, 'send').resolves();
+ element._cache.set('/accounts/self/emails', [
+ {email: email1, preferred: true},
+ {email: email2, preferred: false},
+ ]);
+
+ return element.setPreferredAccountEmail(email2).then(() => {
+ assert.isTrue(sendStub.calledOnce);
+ assert.equal(sendStub.lastCall.args[0].method, 'PUT');
+ assert.equal(sendStub.lastCall.args[0].url,
+ `/accounts/self/emails/${encodedEmail}/preferred`
+ );
+ assert.deepEqual(
+ element._restApiHelper._cache.get('/accounts/self/emails'), [
+ {email: email1, preferred: false},
+ {email: email2, preferred: true},
+ ]
+ );
+ });
+ });
+
test('setAccountStatus', () => {
const sendStub = sinon.stub(element._restApiHelper, 'send')
.returns(Promise.resolve('OOO'));