-
Notifications
You must be signed in to change notification settings - Fork 11
[#69] Add approval flow for new customers #90
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
[#69] Add approval flow for new customers #90
Conversation
| @@ -0,0 +1,9 @@ | |||
| # Preview all emails at http://localhost:3000/rails/mailers/admin_mailer | |||
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.
Is this comment here needed?
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.
This was autogenerated by rails generate, I thought it would be nice to keep it.
But thinking about it now, it may be better to include this information in the README.md or in the setup docs instead.
| def send_user_self_registration_notification_email | ||
| return unless resource.persisted? | ||
|
|
||
| AdminMailer.user_self_registration_notification(admins: User.admins.to_a, user: resource).deliver_later |
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.
Here you don't need to call .to_a on User.admins
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.
Unfortunately, for this case it is necessary to specify the to_a option for the admins. If this option is omitted, ActiveJob raises an exception:
ActiveJob::SerializationError:
Unsupported argument type: ActiveRecord::RelationThere 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.
What do you think about sending only the emails themselves? It seems to me you don't need the entire admin and by doing that you'll simplify the serialization and make the mailer know only what it needs to know to complete its job.
6a0a7e9 to
7cae99d
Compare
RodrigoVitiello
left a comment
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.
🚀
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.
It looks awesome, thanks for this pr! 🥇
Just left a comment telling you about our request helpers, but it will be merged very soon! 🚀
Also, it has a few rubocop offenses, can you please take a look?
spec/requests/registrations_spec.rb
Outdated
| describe 'POST /signup' do | ||
| subject(:request) { post signup_path, params: params, as: :json } | ||
|
|
||
| let(:response_body) { JSON.parse(response.body).deep_symbolize_keys } |
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.
| PERMITTED_PARAMS = %i[email full_name cellphone cpf address].freeze | ||
|
|
||
| before_action :configure_permitted_parameters | ||
| after_action :send_user_self_registration_notification_email, only: %i[create] # rubocop:disable Rails/LexicallyScopedActionFilter |
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.
@m-pereira I disabled this Rubocop rule for this case, is this ok?
The reason is that, at first Rubocop pointed out that create is not defined in the class, but if I explicitly add the method, like so:
def create
super
endRubocop complains about an useless method:
app/controllers/registrations_controller.rb:10:3: W: [Correctable] Lint/UselessMethodDefinition: Useless method definition detected.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.
I think that's ok commenting as you did, in this case, the method is inherited from the Devise gem. And it's easy to find why, on the rubocop docs
7ee29f9 to
b17de60
Compare
mauricio-prl
left a comment
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.
Nice! Thanks @rhian-cs 🚀
|
@allcontributors add @rhian-cs for code |
|
I've put up a pull request to add @rhian-cs! 🎉 |
|
@allcontributors add @wenderjean and @RodrigoVitiello for review |
|
I've put up a pull request to add @wenderjean! 🎉 |
|
@allcontributors add @RodrigoVitiello for review |
|
I've put up a pull request to add @RodrigoVitiello! 🎉 |
Closes: #69
What?
userstable:self_registeredself_registered: trueandactive: falseand need to be enabled manually by an adminWhy?
With these changes, admins no longer need to manually add each user to the platform, they only need to approve their entry.
How to test it?
Open up the application and create a new user via the JSON request
POST /signupwith the body:{ "user": { "full_name": "John Doe", "email": "[email protected]", "password": "12345678", "address": "Test Street, 123", "cpf": "12345670088", "cellphone": "123456789012345" } }Example cURL request:
It should return status
201 Createdand a body containing the created user:{ "id": 5, "full_name": "John Doe", "email": "[email protected]", "cpf": "12345670088", "address": "Test Street, 123", "cellphone": "123456789012345", "picture_url": null, "admin": false, "active": false, "self_registered": true, "created_at": "2022-03-23T17:10:05.768Z", "updated_at": "2022-03-23T17:10:05.768Z", "companies": [] }If something is wrong, it will return
422 Unprocessable Entitywith the errors inside the body:{ "errors": { "email": [ "já está em uso" ], "cpf": [ "já está em uso" ] } }Mailer Preview Screenshot