Skip to content

Notify users when roles get assigned#5886

Merged
tramuntanal merged 18 commits intodevelopfrom
5733
Apr 30, 2020
Merged

Notify users when roles get assigned#5886
tramuntanal merged 18 commits intodevelopfrom
5733

Conversation

@anaghavl
Copy link
Copy Markdown
Contributor

@anaghavl anaghavl commented Mar 20, 2020

Notify users when roles get assigned

📌 Related Issues

📋 Subtasks

  • Add CHANGELOG entry
  • Add documentation regarding the feature
  • Add/modify seeds
  • Add tests
  • Another subtask

📷 Screenshots (optional)

Description
Screenshot 2020-03-27 at 2 22 34 PM
Screenshot 2020-03-27 at 2 12 27 PM
Screenshot 2020-03-27 at 2 13 46 PM

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 20, 2020

Codecov Report

❗ No coverage uploaded for pull request base (develop@9c7b36e). Click here to learn what that means.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##             develop    #5886   +/-   ##
==========================================
  Coverage           ?   94.24%           
==========================================
  Files              ?     1101           
  Lines              ?    30086           
  Branches           ?        0           
==========================================
  Hits               ?    28355           
  Misses             ?     1731           
  Partials           ?        0

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9c7b36e...aa9029d. Read the comment docs.

@anaghavl
Copy link
Copy Markdown
Contributor Author

@mrcasals @leio10 @agustibr Please review :)

Copy link
Copy Markdown
Contributor

@mrcasals mrcasals left a comment

Choose a reason for hiding this comment

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

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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Even though Ruby syntax allows this, we usually put parenthesis when defining a method:

Suggested change
def send_notification user
def send_notification(user)

resource_title: resource_title,
resource_url: resource_url,
scope: event_name,
role: extra["role"]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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
end

And 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!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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
end

What do you think?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Sounds good to me!

module Admin
# A command to notify users when a role is assigned for a Conference
class NotifyRoleAssignedConference < Rectify::Command
def send_notification user
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
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(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Something funny with the identation here!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 😄

Copy link
Copy Markdown
Contributor

@agustibr agustibr left a comment

Choose a reason for hiding this comment

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

😄 Good work! Please, check that the participatory_space is present in the form object.

Copy link
Copy Markdown
Contributor

@leio10 leio10 left a comment

Choose a reason for hiding this comment

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

Nice work! 💯 👍
You may be a bit overwhelmed by the project size, the reviews, the linting tools, the tests, and so on, but don't worry that you are doing it great and you will get used to all of that very soon. 💪

Extra tip: you can request a review using the right sidebar 😃
imagen

resource_title: resource_title,
resource_url: resource_url,
scope: event_name,
role: extra["role"]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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
end

What do you think?

leio10
leio10 previously approved these changes Mar 27, 2020
Copy link
Copy Markdown
Contributor

@leio10 leio10 left a comment

Choose a reason for hiding this comment

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

Great work!

mrcasals
mrcasals previously approved these changes Mar 31, 2020
@anaghavl
Copy link
Copy Markdown
Contributor Author

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?

@andreslucena andreslucena changed the title 5733 - Notify users when roles get assigned Notify users when roles get assigned Mar 31, 2020
Copy link
Copy Markdown
Contributor

@agustibr agustibr left a comment

Choose a reason for hiding this comment

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

It seems that emails are not sent to users (if user has enabled "Send notifications by email"), can you check it? 😀

@jesusdb
Copy link
Copy Markdown
Contributor

jesusdb commented Apr 1, 2020

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).

agustibr
agustibr previously approved these changes Apr 13, 2020
leio10
leio10 previously approved these changes Apr 14, 2020
@mrcasals
Copy link
Copy Markdown
Contributor

@anaghavl there are some conflicts on the changelog, can you check them please? 😄

mrcasals
mrcasals previously approved these changes Apr 15, 2020
agustibr
agustibr previously approved these changes Apr 20, 2020
Copy link
Copy Markdown
Contributor

@tramuntanal tramuntanal left a comment

Choose a reason for hiding this comment

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

Hi @anaghavl good job!
I've just suggested some renamigs for clarification 😄

# frozen-string_literal: true

module Decidim
class AssemblyRoleAssignedEvent < Decidim::Events::SimpleEvent
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Let's add the preposition, this will affect the class and the file names:

Suggested change
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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
class NotifyRoleAssignedParticipatoryProcess < Rectify::Command
class NotifyRoleAssignedToParticipatoryProcess < Rectify::Command

@anaghavl anaghavl dismissed stale reviews from agustibr and mrcasals via 6fcd1cd April 27, 2020 18:56
@anaghavl anaghavl requested a review from tramuntanal April 27, 2020 18:57
@tramuntanal
Copy link
Copy Markdown
Contributor

Thanks for the refactoring @anaghavl . It seems that "[CI] Admin / Tests" tests got stuck, I've re-run them.

@mrcasals
Copy link
Copy Markdown
Contributor

@tramuntanal could we merge this anyway? Considering no permissions were modified, and no code from decidim-admin was modified, I think it would be safe... It's just that the CI is stuck again with locales 😞

@tramuntanal tramuntanal merged commit 1f7f7a3 into develop Apr 30, 2020
@tramuntanal tramuntanal deleted the 5733 branch April 30, 2020 06:55
ace pushed a commit to aspgems/decidim that referenced this pull request May 5, 2020
* 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)
  ...
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.

Receive notification of the role I have been assigned

6 participants