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
Admin, Enterprise Settings, Users tabs: remove tooltips directives + use reflex to invite user to be managers #9729
Admin, Enterprise Settings, Users tabs: remove tooltips directives + use reflex to invite user to be managers #9729
Conversation
b2bb865
to
8ff1a08
Compare
6cff836
to
2f68529
Compare
0bac855
to
22926b9
Compare
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 found the commit history wasn't straightforward, but they are small enough to understand. I understand this hasn't been easy to pick up :)
I have a few suggestions, can you please take a look?
app/views/admin/enterprises/form/_add_new_unregistered_manager.html.haml
Show resolved
Hide resolved
app/views/admin/enterprises/form/_add_new_unregistered_manager.html.haml
Outdated
Show resolved
Hide resolved
begin | ||
new_user = create_new_manager(email, enterprise) | ||
locals[:success] = true | ||
locals[:email] = new_user.email | ||
rescue StandardError => e | ||
@error = e.message | ||
locals[:error] = @error || I18n.t('admin.enterprises.invite_manager.error') | ||
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.
I remember discussing this with Maikel a while back, and agreeing that we shouldn't have a "catch-all" (rescue StandardError
), and should rescue only expected errors. Any unexpected errors should be treated as bugs (logged in bugsnag) so we can improve them.
I can see that the old controller had a problem: create_new_manager
could raise an exception (from new_user.save!
), but it wasn't being caught.
Handling exceptions in this way is generally a good idea, but for controllers we more commonly use the if/else
pattern. So I'd recommend we use that. What do others think?
Otherwise, it should be renamed create_new_manager!
and we should only catch expected errors like ActiveRecord::RecordInvalid
.
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.
My suggestion (untested):
begin | |
new_user = create_new_manager(email, enterprise) | |
locals[:success] = true | |
locals[:email] = new_user.email | |
rescue StandardError => e | |
@error = e.message | |
locals[:error] = @error || I18n.t('admin.enterprises.invite_manager.error') | |
end | |
new_user = create_new_manager(email, enterprise) | |
if new_user | |
locals[:success] = true | |
else | |
locals[:error] = new_user.errors.full_messages.to_sentence || I18n.t('admin.enterprises.invite_manager.error') | |
end |
- This requires that
create_new_manager
is changed fromsave!
tosave
- From what I could see
new_user.email
should be the same as local varemail
, so I simplified that too. - I don't see the need for class var
@error
, so I removed it
update: I noticed in this PR the use of to_sentence
so have incorporated that too.
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 requires that create_new_manager is changed from save! to save
Not only, since EnterpriseMailer.manager_invitation(@enterprise, new_user).deliver_later
seems to throw exception as well. That's why I've added:
return new_user unless new_user.valid? # Return early if user is invalid.
after new_user.save
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.
Commit: b17d3e4
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.
Great work, thanks for picking that up and making it work.
0cf743c
to
b17d3e4
Compare
Thanks for those meaningful suggestions! 👍 🙏 I've done, I think, the job, feel free to review. As said on delivery circle meeting, it's not about removing all angular on that panel but only removing some tooltip directives + add manager invitation as reflex. |
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.
👍 Agreed, it will be good to have the work from this PR merged.
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.
Great work. I would just like to see one little cleanup to make the code more robust.
296c529
to
24a009f
Compare
There are tooltips here that don't have a what's this? There are many angular directives/methods being used that I haven't looked into Every select box is using select2
Actually the `config()` method of `admin_ofn` file did not run on `/admin/enterprises/*` pages for an unknown reason Now those two files have the same configuration
24a009f
to
31d8ac0
Compare
I agree. Thanks for that! |
end | ||
end | ||
end | ||
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.
Thanks for this!
👏 👏 👏
EDIT: maybe we could update the spec to enqueue two emails jobs?
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.
maybe we could update the spec to enqueue two emails jobs?
expect do
...
end.to enqueue_job(ActionMailer::MailDeliveryJob).exactly(:twice)
I did not understand your point ;)
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.
Ahh right - I've missed it, we do enqueue it twice. All good! 👍
They are enqueued but, not delivered. And the spec does cover for this...
Hey @binarygit and @jibees , Before this PR, the invitation form looks like this: Sending an invitation delivers two emails - see Wiki on Emails:
After this PR Sending an invitation triggers this error:
From bugsnag:
And indeed, only one email arrives - the account confirmation. So, the missing email is actual invitation email (email i.) I think this will need another look, for now as it introduces a regression. Moving to in dev. |
Can be used elsewhere Update manager_invitations.rb
…rprise Co-Authored-By: David Cook <david@redcliffs.net>
and then expect the right values.
Co-Authored-By: Maikel <maikel@email.org.au>
31d8ac0
to
29cdadd
Compare
Oh yes, there were a copy/paste error ( |
This PR openfoodfoundation#9729 remove #! from url. But unfortunately, AngularJs rewrite "example.com#panel" as "example.com#/panel" thus breaking the original implementation.
This PR openfoodfoundation#9729 remove #! from url. But unfortunately, AngularJs rewrite "example.com#panel" as "example.com#/panel" thus breaking the original implementation.
What? Why?
Part of #9491
This basically add a reflex for adding a user as manager of an enterprise.
To be more precise:
#!#
from URLs as they aren't valid. Commit cherry picked from Admin: Remove#!#
anchor from enterprise preferences page #10541. Could be merged before.What should we test?
/admin/enterprises/ENTERPRISE/edit#/users_panel
Release notes
Changelog Category: Technical changes
The title of the pull request will be included in the release notes.
Dependencies
Documentation updates