Skip to content

Conversation

devdattatalele
Copy link

Summary

Fixes user invitation issues described in #2473 by adding proper backend validation for disabled users.

Changes Made

  • Backend Validation: Added check in helpdesk/api/agent.py to detect disabled users before creating invitations
  • Clear Error Messages: Users now receive specific feedback when attempting to invite disabled users
  • Prevention of Errors: Stops the system from creating invalid invitation states

Problem Solved

Before: Inviting a disabled user would cause unclear errors or system issues
After: Clear validation message: "User {email} is disabled. Please enable the user first to invite them."

Testing

  • Tested with disabled user accounts
  • Verified error message displays correctly
  • Confirmed no invitation records created for disabled users
  • Validated existing enabled user invitations still work

Related Issues

Addresses part 1 of issue #2473

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature
  • Breaking change
  • Documentation update

Additional Notes

This change focuses on the invitation validation issue. The user deletion and password reset issues mentioned in #2473 may require separate PRs for targeted fixes.

Copy link
Author

@devdattatalele devdattatalele left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import frappe
+from frappe import _

@frappe.whitelist()
def sent_invites(emails, send_welcome_mail_to_user=True):
    for email in emails:
        if frappe.db.exists("User", email):
            user = frappe.get_doc("User", email)
+            if not user.enabled:
+                frappe.throw(
+                    _("User with email {0} is disabled. Please enable the user first to invite them.").format(email),
+                    frappe.ValidationError
+                )
        else:
            user = frappe.get_doc(
                {"doctype": "User", "email": email, "first_name": email.split("@")[0]}
            ).insert()

            if send_welcome_mail_to_user:
                user.send_welcome_mail_to_user()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant