Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃悰 Bug Report: When trying to resend email in Organization tab it throws AppwriteException #5901

Open
2 tasks done
ZachHandley opened this issue Jul 28, 2023 · 2 comments 路 Fixed by #7790 路 May be fixed by #8157
Open
2 tasks done

馃悰 Bug Report: When trying to resend email in Organization tab it throws AppwriteException #5901

ZachHandley opened this issue Jul 28, 2023 · 2 comments 路 Fixed by #7790 路 May be fixed by #8157
Assignees
Labels
bug Something isn't working

Comments

@ZachHandley
Copy link

馃憻 Reproduction steps

Try to hit resend on an unclaimed email invite

馃憤 Expected behavior

resend the email

馃憥 Actual Behavior

Appwrite Exception
image

馃幉 Appwrite version

Version 1.3.x

馃捇 Operating system

Linux

馃П Your Environment

1.3.8, Cloudflare, Appwrite is self hosted as a reverse proxy using Nginx

馃憖 Have you spent some time to check if this issue has been raised before?

  • I checked and didn't find similar issue

馃彚 Have you read the Code of Conduct?

@ZachHandley ZachHandley added the bug Something isn't working label Jul 28, 2023
@joeyouss joeyouss self-assigned this Jul 31, 2023
@safwanyp
Copy link
Contributor

safwanyp commented Aug 5, 2023

On the backend, the endpoint controller tries to create a whole new membership, which is expected from it:

if ($isPrivilegedUser || $isAppUser) { // Allow admin to create membership
try {
$membership = Authorization::skip(fn() => $dbForProject->createDocument('memberships', $membership));
} catch (Duplicate $th) {
throw new Exception(Exception::TEAM_INVITE_ALREADY_EXISTS);
}
$team->setAttribute('total', $team->getAttribute('total', 0) + 1);
$team = Authorization::skip(fn() => $dbForProject->updateDocument('teams', $team->getId(), $team));
$dbForProject->deleteCachedDocument('users', $invitee->getId());
} else {

Considering the fact that the email delivery is in the same endpoint, can't we do something like:

  • Try to create a new membership
  • If membership exists for given user, resend invite instead of throwing TEAM_INVITE_ALREADY_EXISTS exception.

Looking at the console API calls, this endpoint would be called only when a brand new membership is being created and when trying to resend an email, so this should be a viable fix. What do you think?

Edit: I would love to work on this issue 馃榿

@safwanyp
Copy link
Contributor

safwanyp commented Aug 5, 2023

I've seen the code and it seems like letting the code keep running on catching a Duplicate exception works.

Changed the code from this:

try { 
   $membership = Authorization::skip(fn() => $dbForProject->createDocument('memberships', $membership)); 
} catch (Duplicate $th) { 
   throw new Exception(Exception::TEAM_INVITE_ALREADY_EXISTS); 
} 

to this:

try {
    $membership = Authorization::skip(fn() => $dbForProject->createDocument('memberships', $membership));
} catch (Duplicate $th) {
    null;
} catch (Exception $th) {
    throw new Exception($th->getMessage());
}

I haven't been able to generate a case where an error actually gets thrown, so would appreciate feedback on the above approach!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: In Progress
4 participants