Notify users when roles get assigned#5886
Conversation
Codecov Report
@@ Coverage Diff @@
## develop #5886 +/- ##
==========================================
Coverage ? 94.24%
==========================================
Files ? 1101
Lines ? 30086
Branches ? 0
==========================================
Hits ? 28355
Misses ? 1731
Partials ? 0Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Hi @anaghavl! Nice job, really!
There are some minor things related to i18n and some code style issues, but apart from that code looks good! I see there are not tests though, can you check those in #4636 as an example?
Also, for the PR description we usually link the issue this PR works on. In this case, it's #5733, so can you put it in the "Fixes #?" secction? This way when we merge this PR the issue will be closed automatically 😄
Also, don't forget to add a line on the CHANGELOG file! 😄
| module Admin | ||
| # A command to notify users when a role is assigned for a participatory process | ||
| class NotifyRoleAssignedAssembly < Rectify::Command | ||
| def send_notification user |
There was a problem hiding this comment.
Even though Ruby syntax allows this, we usually put parenthesis when defining a method:
| def send_notification user | |
| def send_notification(user) |
| resource_title: resource_title, | ||
| resource_url: resource_url, | ||
| scope: event_name, | ||
| role: extra["role"] |
There was a problem hiding this comment.
We're sending the raw value of the role to the event, and then use that value when showing the i18n string. This will result in an English mashup when using locales other than English. Maybe we could refactor this? I think it's fine sending the raw value, this way we can translate it here:
def i18n_role
I18n.t(extra["role"], "decidim.admin.models.assembly_user_role.roles", default: nil)
end
def i18n_options
{
...
role: i18n_role
}
end
def notification_title
return I18n.t("notification_title", i18n_options).html_safe if i18n_role
I18n.t("notification_title_general_role", i18n_options).html_safe
endAnd then add the notification_title_general_role with the string "You have been assigned a role to %{resource_title}" or something like that.
What do you think? 😄
This would need to be applied to all similar classes!
There was a problem hiding this comment.
Mmm, maybe the user would prefer to have the non-translated role name to don't have anything. We could do something like:
def i18n_role
I18n.t(extra["role"], "decidim.admin.models.assembly_user_role.roles", default: extra["role"])
end
def i18n_options
{
...
role: i18n_role
}
end
def notification_title
I18n.t("notification_title", i18n_options).html_safe
endWhat do you think?
| module Admin | ||
| # A command to notify users when a role is assigned for a Conference | ||
| class NotifyRoleAssignedConference < Rectify::Command | ||
| def send_notification user |
There was a problem hiding this comment.
| def send_notification user | |
| def send_notification(user) |
| # A command to notify users when a role is assigned for a Conference | ||
| class NotifyRoleAssignedConference < Rectify::Command | ||
| def send_notification user | ||
| Decidim::EventsManager.publish( |
There was a problem hiding this comment.
Something funny with the identation here!
There was a problem hiding this comment.
You can automatically run bundle exec rubocop -a <list of files you want to check>, or manually check the "Lint" job in the Checks section of this PR, it will tell you what's missing 😄
decidim-assemblies/app/commands/decidim/assemblies/admin/update_assembly_admin.rb
Outdated
Show resolved
Hide resolved
decidim-assemblies/app/controllers/decidim/assemblies/admin/assembly_user_roles_controller.rb
Outdated
Show resolved
Hide resolved
decidim-conferences/app/commands/decidim/conferences/admin/update_conference_admin.rb
Outdated
Show resolved
Hide resolved
...im-conferences/app/controllers/decidim/conferences/admin/conference_user_roles_controller.rb
Outdated
Show resolved
Hide resolved
...ses/app/commands/decidim/participatory_processes/admin/update_participatory_process_admin.rb
Outdated
Show resolved
Hide resolved
...rollers/decidim/participatory_processes/admin/participatory_process_user_roles_controller.rb
Outdated
Show resolved
Hide resolved
| resource_title: resource_title, | ||
| resource_url: resource_url, | ||
| scope: event_name, | ||
| role: extra["role"] |
There was a problem hiding this comment.
Mmm, maybe the user would prefer to have the non-translated role name to don't have anything. We could do something like:
def i18n_role
I18n.t(extra["role"], "decidim.admin.models.assembly_user_role.roles", default: extra["role"])
end
def i18n_options
{
...
role: i18n_role
}
end
def notification_title
I18n.t("notification_title", i18n_options).html_safe
endWhat do you think?
|
Hey @decidim/core this PR is failing due to codecov checks, but we’re not sure how to fix them, do you have any insight? |
agustibr
left a comment
There was a problem hiding this comment.
It seems that emails are not sent to users (if user has enabled "Send notifications by email"), can you check it? 😀
|
Hello @anaghavl, the Codecov failing checks mean that there is code not covered by tests. To see what parts are uncovered, you can click on Details and look at "COVERAGE REACH"; the red squares mean the file needs more coverage. If you can't see any red square, you can click on "Diff" tab, and the first column from the files indicates if it's covered (green) or not (red). |
70e0e90 to
e390914
Compare
|
@anaghavl there are some conflicts on the changelog, can you check them please? 😄 |
tramuntanal
left a comment
There was a problem hiding this comment.
Hi @anaghavl good job!
I've just suggested some renamigs for clarification 😄
| # frozen-string_literal: true | ||
|
|
||
| module Decidim | ||
| class AssemblyRoleAssignedEvent < Decidim::Events::SimpleEvent |
There was a problem hiding this comment.
| class AssemblyRoleAssignedEvent < Decidim::Events::SimpleEvent | |
| class RoleAssignedToAssemblyEvent < Decidim::Events::SimpleEvent |
| module Assemblies | ||
| module Admin | ||
| # A command to notify users when a role is assigned for a participatory process | ||
| class NotifyRoleAssignedAssembly < Rectify::Command |
There was a problem hiding this comment.
Let's add the preposition, this will affect the class and the file names:
| class NotifyRoleAssignedAssembly < Rectify::Command | |
| class NotifyRoleAssignedToAssembly < Rectify::Command |
also the documentation for this class uses "a participatory process" when it should say "an assembly", correct?
There was a problem hiding this comment.
nice catch, did not realise, fixed it :)
| module Conferences | ||
| module Admin | ||
| # A command to notify users when a role is assigned for a Conference | ||
| class NotifyRoleAssignedConference < Rectify::Command |
There was a problem hiding this comment.
| class NotifyRoleAssignedConference < Rectify::Command | |
| class NotifyRoleAssignedToConference < Rectify::Command |
| module ParticipatoryProcesses | ||
| module Admin | ||
| # A command to notify users when a role is assigned for a participatory process | ||
| class NotifyRoleAssignedParticipatoryProcess < Rectify::Command |
There was a problem hiding this comment.
| class NotifyRoleAssignedParticipatoryProcess < Rectify::Command | |
| class NotifyRoleAssignedToParticipatoryProcess < Rectify::Command |
|
Thanks for the refactoring @anaghavl . It seems that "[CI] Admin / Tests" tests got stuck, I've re-run them. |
|
@tramuntanal could we merge this anyway? Considering no permissions were modified, and no code from |
* develop: (29 commits) Update Conversations design with decidim-design UI (decidim#6008) Add counter of active users to admin dashboard (decidim#5907) Show activity graphs on admin dashboard (decidim#6030) Update sassc gem version (decidim#6062) Fix generator Gemfile after puma upgrade (decidim#6060) New Crowdin translations (decidim#6059) Add Slovak as a new language (decidim#6039) Remove all tests for i18n PRs (decidim#6061) Update move up and down buttons after dragging questions when managing questionnaire (decidim#5947) Fix using Decidim as a provider for omniauth authentication (decidim#6042) Add redesign for responsive public profile navigation tabs (decidim#6032) Add versioning pages to initiatives (decidim#5935) Notify users when roles get assigned (decidim#5886) Improve the budget page and the project card (decidim#5809) New Crowdin translations (decidim#6050) New Crowdin translations (decidim#6046) Ignore jobs on locales branches (decidim#6047) Automatic task for deleting Meeting Inscription data (decidim#5989) New Crowdin translations (decidim#5877) Ignore builds on Crowdin PRs (decidim#6037) ...

Notify users when roles get assigned
📌 Related Issues
📋 Subtasks
CHANGELOGentry📷 Screenshots (optional)