mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-06 18:27:19 +00:00
fix: secret sharing view count
This commit is contained in:
@@ -178,33 +178,17 @@ export const secretSharingServiceFactory = ({
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
const $decrementSecretViewCount = async (sharedSecret: TSecretSharing, sharedSecretId: string) => {
|
const $decrementSecretViewCount = async (sharedSecret: TSecretSharing) => {
|
||||||
const { expiresAfterViews } = sharedSecret;
|
const { expiresAfterViews } = sharedSecret;
|
||||||
|
|
||||||
const isUuid = isUuidV4(sharedSecretId);
|
|
||||||
|
|
||||||
if (expiresAfterViews) {
|
if (expiresAfterViews) {
|
||||||
// decrement view count if view count expiry set
|
// decrement view count if view count expiry set
|
||||||
|
await secretSharingDAL.updateById(sharedSecret.id, { $decr: { expiresAfterViews: 1 } });
|
||||||
if (isUuid) {
|
|
||||||
await secretSharingDAL.updateById(sharedSecretId, { $decr: { expiresAfterViews: 1 } });
|
|
||||||
} else {
|
|
||||||
await secretSharingDAL.update({ identifier: sharedSecretId }, { $decr: { expiresAfterViews: 1 } });
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isUuid) {
|
await secretSharingDAL.updateById(sharedSecret.id, {
|
||||||
await secretSharingDAL.updateById(sharedSecretId, {
|
lastViewedAt: new Date()
|
||||||
lastViewedAt: new Date()
|
});
|
||||||
});
|
|
||||||
} else {
|
|
||||||
await secretSharingDAL.update(
|
|
||||||
{ identifier: sharedSecretId },
|
|
||||||
{
|
|
||||||
lastViewedAt: new Date()
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Get's password-less secret. validates all secret's requested (must be fresh). */
|
/** Get's password-less secret. validates all secret's requested (must be fresh). */
|
||||||
@@ -267,7 +251,7 @@ export const secretSharingServiceFactory = ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
// decrement when we are sure the user will view secret.
|
// decrement when we are sure the user will view secret.
|
||||||
await $decrementSecretViewCount(sharedSecret, sharedSecretId);
|
await $decrementSecretViewCount(sharedSecret);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
isPasswordProtected,
|
isPasswordProtected,
|
||||||
|
|||||||
Reference in New Issue
Block a user