Skip to content

Commit 139ccc4

Browse files
author
Rachel Macfarlane
committed
Disable sign out for account specified through embedder API
1 parent 2b5ac23 commit 139ccc4

1 file changed

Lines changed: 27 additions & 14 deletions

File tree

src/vs/workbench/browser/parts/activitybar/activitybarActions.ts

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ import { ActionViewItem, Separator } from 'vs/base/browser/ui/actionbar/actionba
3131
import { isMacintosh } from 'vs/base/common/platform';
3232
import { ContextSubMenu } from 'vs/base/browser/contextmenu';
3333
import { IAuthenticationService } from 'vs/workbench/services/authentication/browser/authenticationService';
34-
import { distinct } from 'vs/base/common/arrays';
34+
import { AuthenticationSession } from 'vs/editor/common/modes';
35+
import { IWorkbenchEnvironmentService } from 'vs/workbench/services/environment/common/environmentService';
3536

3637
export class ViewContainerActivityAction extends ActivityAction {
3738

@@ -105,7 +106,8 @@ export class AccountsActionViewItem extends ActivityActionViewItem {
105106
@IContextMenuService protected contextMenuService: IContextMenuService,
106107
@IMenuService protected menuService: IMenuService,
107108
@IContextKeyService private readonly contextKeyService: IContextKeyService,
108-
@IAuthenticationService private readonly authenticationService: IAuthenticationService
109+
@IAuthenticationService private readonly authenticationService: IAuthenticationService,
110+
@IWorkbenchEnvironmentService private readonly environmentService: IWorkbenchEnvironmentService
109111
) {
110112
super(action, { draggable: false, colors, icon: true }, themeService);
111113
}
@@ -140,27 +142,38 @@ export class AccountsActionViewItem extends ActivityActionViewItem {
140142
const providers = this.authenticationService.getProviderIds();
141143
const allSessions = providers.map(async id => {
142144
const sessions = await this.authenticationService.getSessions(id);
143-
const uniqueSessions = distinct(sessions, session => session.account.label);
145+
146+
const groupedSessions: { [label: string]: AuthenticationSession[] } = {};
147+
sessions.forEach(session => {
148+
if (groupedSessions[session.account.label]) {
149+
groupedSessions[session.account.label].push(session);
150+
} else {
151+
groupedSessions[session.account.label] = [session];
152+
}
153+
});
154+
144155
return {
145156
providerId: id,
146-
sessions: uniqueSessions
157+
sessions: groupedSessions
147158
};
148159
});
149160

150161
const result = await Promise.all(allSessions);
151162
let menus: (IAction | ContextSubMenu)[] = [];
152163
result.forEach(sessionInfo => {
153164
const providerDisplayName = this.authenticationService.getLabel(sessionInfo.providerId);
154-
sessionInfo.sessions.forEach(session => {
155-
const accountName = session.account.label;
156-
const menu = new ContextSubMenu(`${accountName} (${providerDisplayName})`, [
157-
new Action(`configureSessions${accountName}`, nls.localize('manageTrustedExtensions', "Manage Trusted Extensions"), '', true, _ => {
158-
return this.authenticationService.manageTrustedExtensionsForAccount(sessionInfo.providerId, accountName);
159-
}),
160-
new Action('signOut', nls.localize('signOut', "Sign Out"), '', true, _ => {
161-
return this.authenticationService.signOutOfAccount(sessionInfo.providerId, accountName);
162-
})
163-
]);
165+
Object.keys(sessionInfo.sessions).forEach(accountName => {
166+
const hasEmbedderAccountSession = sessionInfo.sessions[accountName].some(session => session.id === this.environmentService.options?.authenticationSessionId);
167+
const manageExtensionsAction = new Action(`configureSessions${accountName}`, nls.localize('manageTrustedExtensions', "Manage Trusted Extensions"), '', true, _ => {
168+
return this.authenticationService.manageTrustedExtensionsForAccount(sessionInfo.providerId, accountName);
169+
});
170+
const signOutAction = new Action('signOut', nls.localize('signOut', "Sign Out"), '', true, _ => {
171+
return this.authenticationService.signOutOfAccount(sessionInfo.providerId, accountName);
172+
});
173+
174+
const actions = hasEmbedderAccountSession ? [manageExtensionsAction] : [manageExtensionsAction, signOutAction];
175+
176+
const menu = new ContextSubMenu(`${accountName} (${providerDisplayName})`, actions);
164177
menus.push(menu);
165178
});
166179
});

0 commit comments

Comments
 (0)