mirror of
https://github.com/willchen96/mike.git
synced 2026-06-14 20:55:13 +02:00
feat: prevent users from sharing projects and reviews with themselves
This commit is contained in:
parent
9e7046d4aa
commit
87e55d6046
4 changed files with 60 additions and 4 deletions
|
|
@ -136,13 +136,22 @@ export function PeopleModal({
|
|||
}
|
||||
|
||||
const trimmedNewEmail = newEmail.trim().toLowerCase();
|
||||
const normalizedCurrentUserEmail =
|
||||
currentUserEmail?.trim().toLowerCase() ?? null;
|
||||
const isValidEmail = EMAIL_RE.test(trimmedNewEmail);
|
||||
const sharedLower = sharedWith.map((e) => e.toLowerCase());
|
||||
const alreadyShared = sharedLower.includes(trimmedNewEmail);
|
||||
const isOwnerEmail =
|
||||
!!ownerEmail && trimmedNewEmail === ownerEmail.toLowerCase();
|
||||
const isSelfEmail =
|
||||
!!normalizedCurrentUserEmail &&
|
||||
trimmedNewEmail === normalizedCurrentUserEmail;
|
||||
const canAdd =
|
||||
isValidEmail && !alreadyShared && !isOwnerEmail && busy === null;
|
||||
isValidEmail &&
|
||||
!alreadyShared &&
|
||||
!isOwnerEmail &&
|
||||
!isSelfEmail &&
|
||||
busy === null;
|
||||
|
||||
async function handleAdd() {
|
||||
if (!canAdd || !onSharedWithChange) return;
|
||||
|
|
@ -249,10 +258,16 @@ export function PeopleModal({
|
|||
{trimmedNewEmail} is the owner.
|
||||
</p>
|
||||
)}
|
||||
{isSelfEmail && !isOwnerEmail && trimmedNewEmail && (
|
||||
<p className="mt-1.5 text-xs text-gray-400">
|
||||
You cannot share this with yourself.
|
||||
</p>
|
||||
)}
|
||||
{trimmedNewEmail &&
|
||||
!isValidEmail &&
|
||||
!alreadyShared &&
|
||||
!isOwnerEmail && (
|
||||
!isOwnerEmail &&
|
||||
!isSelfEmail && (
|
||||
<p className="mt-1.5 text-xs text-gray-400">
|
||||
Enter a valid email.
|
||||
</p>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue