mirror of
https://github.com/bitwarden/browser
synced 2025-12-11 13:53:34 +00:00
PM-20393 return only matching ciphers on type of change (#14392)
* PM-20393 return only matching ciphers on type of change * use type for change
This commit is contained in:
@@ -160,51 +160,42 @@ export default class NotificationBackground {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Gets the current active tab and retrieves all decrypted ciphers
|
* Gets the current active tab and retrieves the relevant decrypted cipher
|
||||||
* for the tab's URL. It constructs and returns an array of `NotificationCipherData` objects.
|
* for the tab's URL. It constructs and returns an array of `NotificationCipherData` objects or a singular object.
|
||||||
* If no active tab or URL is found, it returns an empty array.
|
* If no active tab or URL is found, it returns an empty array.
|
||||||
*
|
*
|
||||||
* @returns {Promise<NotificationCipherData[]>}
|
* @returns {Promise<NotificationCipherData[]>}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
async getNotificationCipherData(): Promise<NotificationCipherData[]> {
|
async getNotificationCipherData(): Promise<NotificationCipherData[]> {
|
||||||
const [currentTab, showFavicons, env] = await Promise.all([
|
const [currentTab, showFavicons, env, activeUserId] = await Promise.all([
|
||||||
BrowserApi.getTabFromCurrentWindow(),
|
BrowserApi.getTabFromCurrentWindow(),
|
||||||
firstValueFrom(this.domainSettingsService.showFavicons$),
|
firstValueFrom(this.domainSettingsService.showFavicons$),
|
||||||
firstValueFrom(this.environmentService.environment$),
|
firstValueFrom(this.environmentService.environment$),
|
||||||
|
firstValueFrom(this.accountService.activeAccount$.pipe(getOptionalUserId)),
|
||||||
|
]);
|
||||||
|
|
||||||
|
const [decryptedCiphers, organizations] = await Promise.all([
|
||||||
|
this.cipherService.getAllDecryptedForUrl(currentTab?.url, activeUserId),
|
||||||
|
firstValueFrom(this.organizationService.organizations$(activeUserId)),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const iconsServerUrl = env.getIconsUrl();
|
const iconsServerUrl = env.getIconsUrl();
|
||||||
const activeUserId = await firstValueFrom(
|
|
||||||
this.accountService.activeAccount$.pipe(getOptionalUserId),
|
|
||||||
);
|
|
||||||
|
|
||||||
const decryptedCiphers = await this.cipherService.getAllDecryptedForUrl(
|
const toNotificationData = (view: CipherView): NotificationCipherData => {
|
||||||
currentTab?.url,
|
|
||||||
activeUserId,
|
|
||||||
);
|
|
||||||
|
|
||||||
const organizations = await firstValueFrom(
|
|
||||||
this.organizationService.organizations$(activeUserId),
|
|
||||||
);
|
|
||||||
|
|
||||||
return decryptedCiphers.map((view) => {
|
|
||||||
const { id, name, reprompt, favorite, login, organizationId } = view;
|
const { id, name, reprompt, favorite, login, organizationId } = view;
|
||||||
|
|
||||||
const organizationType = organizationId
|
const type = organizations.find((org) => org.id === organizationId)?.productTierType;
|
||||||
? organizations.find((org) => org.id === organizationId)?.productTierType
|
|
||||||
: null;
|
|
||||||
|
|
||||||
const organizationCategories: OrganizationCategory[] = [];
|
const organizationCategories: OrganizationCategory[] = [];
|
||||||
|
|
||||||
if (
|
if (
|
||||||
[ProductTierType.Teams, ProductTierType.Enterprise, ProductTierType.TeamsStarter].includes(
|
[ProductTierType.Teams, ProductTierType.Enterprise, ProductTierType.TeamsStarter].includes(
|
||||||
organizationType,
|
type,
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
organizationCategories.push(OrganizationCategories.business);
|
organizationCategories.push(OrganizationCategories.business);
|
||||||
}
|
}
|
||||||
if ([ProductTierType.Families, ProductTierType.Free].includes(organizationType)) {
|
if ([ProductTierType.Families, ProductTierType.Free].includes(type)) {
|
||||||
organizationCategories.push(OrganizationCategories.family);
|
organizationCategories.push(OrganizationCategories.family);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -216,11 +207,21 @@ export default class NotificationBackground {
|
|||||||
favorite,
|
favorite,
|
||||||
...(organizationCategories.length ? { organizationCategories } : {}),
|
...(organizationCategories.length ? { organizationCategories } : {}),
|
||||||
icon: buildCipherIcon(iconsServerUrl, view, showFavicons),
|
icon: buildCipherIcon(iconsServerUrl, view, showFavicons),
|
||||||
login: login && {
|
login: login && { username: login.username },
|
||||||
username: login.username,
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
});
|
};
|
||||||
|
|
||||||
|
const changeItem = this.notificationQueue.find(
|
||||||
|
(message): message is AddChangePasswordQueueMessage =>
|
||||||
|
message.type === NotificationQueueMessageType.ChangePassword,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (changeItem) {
|
||||||
|
const cipherView = await this.getDecryptedCipherById(changeItem.cipherId, activeUserId);
|
||||||
|
return [toNotificationData(cipherView)];
|
||||||
|
}
|
||||||
|
|
||||||
|
return decryptedCiphers.map(toNotificationData);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user