Fix cannot delete expired invitation
Signed-off-by: Émile Ré <emile@getprobo.com>
This commit is contained in:
@@ -119,7 +119,8 @@ export function InvitationListItem(props: {
|
|||||||
{isDeleting ? (
|
{isDeleting ? (
|
||||||
<Spinner size={16} />
|
<Spinner size={16} />
|
||||||
) : (
|
) : (
|
||||||
invitation.canDelete && (
|
invitation.canDelete &&
|
||||||
|
invitation.status !== "ACCEPTED" && (
|
||||||
<Button
|
<Button
|
||||||
variant="danger"
|
variant="danger"
|
||||||
onClick={handleDelete}
|
onClick={handleDelete}
|
||||||
|
|||||||
@@ -273,14 +273,17 @@ func (e ErrInvalidCredentials) Error() string {
|
|||||||
return e.message
|
return e.message
|
||||||
}
|
}
|
||||||
|
|
||||||
type ErrInvitationNotPending struct{ InvitationID gid.GID }
|
type ErrInvitationNotDeleted struct {
|
||||||
|
InvitationID gid.GID
|
||||||
func NewInvitationNotPendingError(invitationID gid.GID) error {
|
Status string
|
||||||
return &ErrInvitationNotPending{InvitationID: invitationID}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e ErrInvitationNotPending) Error() string {
|
func NewInvitationNotDeletedError(invitationID gid.GID, status string) error {
|
||||||
return fmt.Sprintf("invitation %q is not pending", e.InvitationID)
|
return &ErrInvitationNotDeleted{InvitationID: invitationID, Status: status}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e ErrInvitationNotDeleted) Error() string {
|
||||||
|
return fmt.Sprintf("cannot delete invitation %q in %q status", e.InvitationID, e.Status)
|
||||||
}
|
}
|
||||||
|
|
||||||
type ErrPasswordRequired struct {
|
type ErrPasswordRequired struct {
|
||||||
|
|||||||
@@ -283,8 +283,10 @@ func (s *OrganizationService) DeleteInvitation(
|
|||||||
return fmt.Errorf("cannot load invitation: %w", err)
|
return fmt.Errorf("cannot load invitation: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if invitation.Status != coredata.InvitationStatusPending {
|
switch invitation.Status {
|
||||||
return NewInvitationNotPendingError(invitationID)
|
case coredata.InvitationStatusAccepted:
|
||||||
|
return NewInvitationNotDeletedError(invitationID, invitation.Status.String())
|
||||||
|
case coredata.InvitationStatusPending, coredata.InvitationStatusExpired:
|
||||||
}
|
}
|
||||||
|
|
||||||
err = invitation.Delete(ctx, tx, scope, invitationID)
|
err = invitation.Delete(ctx, tx, scope, invitationID)
|
||||||
|
|||||||
@@ -925,13 +925,13 @@ func (r *mutationResolver) DeleteInvitation(ctx context.Context, input types.Del
|
|||||||
err := r.iam.OrganizationService.DeleteInvitation(ctx, input.OrganizationID, input.InvitationID)
|
err := r.iam.OrganizationService.DeleteInvitation(ctx, input.OrganizationID, input.InvitationID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
var errInvitationNotFound *iam.ErrInvitationNotFound
|
var errInvitationNotFound *iam.ErrInvitationNotFound
|
||||||
var errInvitationNotPending *iam.ErrInvitationNotPending
|
var errInvitationNotDeleted *iam.ErrInvitationNotDeleted
|
||||||
|
|
||||||
if errors.As(err, &errInvitationNotFound) {
|
if errors.As(err, &errInvitationNotFound) {
|
||||||
return nil, gqlutils.NotFound(err)
|
return nil, gqlutils.NotFound(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if errors.As(err, &errInvitationNotPending) {
|
if errors.As(err, &errInvitationNotDeleted) {
|
||||||
return nil, gqlutils.Invalid(err, nil)
|
return nil, gqlutils.Invalid(err, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user