Skip to content

Commit 92a19d0

Browse files
authored
Fix org sync cache on refresh and signout-signin (#4398)
* Clears organization settings when user signs out (#4300, #4398) * Updates organization permissions on manual sync (#4300, #4398)
1 parent 7e24da7 commit 92a19d0

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

src/plus/gk/organizationService.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export class OrganizationService implements Disposable {
3434
const orgId = await this.getActiveOrganizationId();
3535
void this.updateOrganizationPermissions(orgId);
3636
}),
37+
container.subscription.onDidCheckIn(this.onUserCheckedIn, this),
3738
container.subscription.onDidChange(this.onSubscriptionChanged, this),
3839
);
3940
}
@@ -128,11 +129,19 @@ export class OrganizationService implements Disposable {
128129
});
129130
}
130131

132+
private async onUserCheckedIn(): Promise<void> {
133+
const orgId = await this.getActiveOrganizationId();
134+
if (orgId == null) return;
135+
136+
await this.updateOrganizationPermissions(orgId, { force: true });
137+
}
138+
131139
private async onSubscriptionChanged(e: SubscriptionChangeEvent): Promise<void> {
132140
if (e.current?.account?.id == null) {
133141
this.updateOrganizations(undefined);
142+
this._organizationSettings = undefined;
143+
await this.clearAllStoredOrganizationsSettings();
134144
}
135-
await this.clearAllStoredOrganizationsSettings();
136145
await this.updateOrganizationPermissions(e.current?.activeOrganization?.id);
137146
}
138147

@@ -141,8 +150,11 @@ export class OrganizationService implements Disposable {
141150
void setContext('gitlens:gk:hasOrganizations', (organizations ?? []).length > 1);
142151
}
143152

144-
private async updateOrganizationPermissions(orgId: string | undefined): Promise<void> {
145-
const settings = orgId != null ? await this.getOrganizationSettings(orgId) : undefined;
153+
private async updateOrganizationPermissions(
154+
orgId: string | undefined,
155+
options?: { force?: boolean },
156+
): Promise<void> {
157+
const settings = orgId != null ? await this.getOrganizationSettings(orgId, options) : undefined;
146158
let aiProviders;
147159
try {
148160
aiProviders = fromGKDevAIProviders(settings?.aiProviders);
@@ -274,7 +286,7 @@ export class OrganizationService implements Disposable {
274286
}
275287

276288
private async clearAllStoredOrganizationsSettings(): Promise<void> {
277-
return this.container.storage.deleteWithPrefix(`plus:organization:`);
289+
return this.container.storage.deleteWithPrefix(`plus:organization`);
278290
}
279291

280292
private async deleteStoredOrganizationSettings(id: string): Promise<void> {

0 commit comments

Comments
 (0)