-
Notifications
You must be signed in to change notification settings - Fork 0
Add comprehensive email validation for blocked users #8
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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: blocked-email-validation-pre
Are you sure you want to change the base?
Add comprehensive email validation for blocked users #8
Conversation
… many times each email address is blocked, and last time it was blocked. Move email validation out of User model and into EmailValidator. Signup form remembers which email addresses have failed and shows validation error on email field.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.
Greptile OverviewConfidence Score: 2/5
Important Files ChangedFile Analysis
Sequence DiagramsequenceDiagram
participant Client as Browser/Client
participant Controller as UsersController
participant User as User Model
participant Validator as EmailValidator
participant Blocked as BlockedEmail
participant DB as Database
Client->>Controller: POST /users/create (email, username, password)
Controller->>User: User.new_from_params(params)
Controller->>User: user.save
User->>User: validate :email, presence: true, uniqueness: true
User->>Validator: validates :email, email: true
Validator->>Validator: Check whitelist/blacklist settings
alt Email passes whitelist/blacklist
Validator->>Blocked: BlockedEmail.should_block?(email)
Blocked->>DB: WHERE email = ?
alt Email found in blocked_emails
Blocked->>DB: UPDATE match_count, last_match_at
Blocked->>DB: save()
Blocked-->>Validator: true/false (based on action_type)
else Email not found
Blocked-->>Validator: false
end
alt Email is blocked
Validator->>User: errors.add(:email, "blocked")
end
else Email fails whitelist/blacklist
Validator->>User: errors.add(:email, "not_allowed")
end
User-->>Controller: validation result
alt Validation failed
Controller->>Client: JSON {success: false, errors: {...}, values: {...}}
Client->>Client: rejectedEmails.pushObject(email)
Client->>Client: Re-validate email field
Client->>Client: Show error on form
else Validation passed
Controller->>Client: JSON {success: true, message: ...}
end
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
10 files reviewed, 2 comments
| def self.should_block?(email) | ||
| record = BlockedEmail.where(email: email).first | ||
| if record | ||
| record.match_count += 1 | ||
| record.last_match_at = Time.zone.now | ||
| record.save | ||
| end | ||
| record && record.action_type == actions[:block] | ||
| end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: Modifying database state during validation is problematic. This method writes to the database (record.save) even during read-only validation checks, which can cause issues with transaction rollbacks and violates Rails conventions where validations should be side-effect free.
Prompt To Fix With AI
This is a comment left during a code review.
Path: app/models/blocked_email.rb
Line: 11:19
Comment:
**logic:** Modifying database state during validation is problematic. This method writes to the database (`record.save`) even during read-only validation checks, which can cause issues with transaction rollbacks and violates Rails conventions where validations should be side-effect free.
How can I resolve this? If you propose a fix, please make it concise.| value =~ regexp | ||
| end | ||
|
|
||
| end No newline at end of file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
syntax: Missing newline at end of file
| end | |
| end |
Prompt To Fix With AI
This is a comment left during a code review.
Path: lib/validators/email_validator.rb
Line: 24:24
Comment:
**syntax:** Missing newline at end of file
```suggestion
end
```
How can I resolve this? If you propose a fix, please make it concise.
Test 3
Replicated from ai-code-review-evaluation/discourse-greptile#3