Skip to content

Role-targeted broadcast messages

Eugie Limpin requested to merge role-targeted-broadcast into master

What does this MR do and why?

Issue: gitlab-org/growth/team-tasks#461 (closed)

This MR implements role-targeted broadcast messages. It allows admins to create broadcast messages that will be shown only to users with the selected role(s) in group/sub-group/project pages.

Role-targeted broadcast messages will be shown in all pages where we can infer a project, group or sub-group from the URL using namespace_id, id, project_id, or group_id params. For example, assuming the current user has the target role, the following table shows some examples of where the broadcast message will be displayed/not displayed.

Page URL Display role-targeted broadcast message?
Project page /my-group/my-project Yes
Project members page /my-group/my-project/-/project_members Yes
Group page /my-group Yes
Sub-group page /my-group/my-subgroup Yes
Groups list page /dashboard/groups No

Database

rails db:migrate

$ rails db:migrate
== 20220128081329 AddTargetAccessLevelsToBroadcastMessages: migrating =========
-- add_column(:broadcast_messages, :target_access_levels, :integer, {:array=>true, :null=>false, :default=>[]})
   -> 0.0049s
== 20220128081329 AddTargetAccessLevelsToBroadcastMessages: migrated (0.0050s)

rails db:rollback

$ rails db:rollback
== 20220128081329 AddTargetAccessLevelsToBroadcastMessages: reverting =========
-- remove_column(:broadcast_messages, :target_access_levels, :integer, {:array=>true, :null=>false, :default=>[]})
   -> 0.0060s
== 20220128081329 AddTargetAccessLevelsToBroadcastMessages: reverted (0.0120s)

Screenshots or screen recordings

Demo

https://www.youtube.com/watch?v=2Sj_i1aJ8x8

Updates on the form

Screen_Shot_2022-02-02_at_4.11.07_PM

Created role-targeted broadcast message

Screen_Shot_2022-02-02_at_4.12.21_PM

How to set up and validate locally

Setup

  1. Enable the feature
    Feature.enable(:role_targeted_broadcast_messages)
  2. Login as admin (GDK root user)
  3. Go to http://127.0.0.1:3000/admin/broadcast_messages and create a broadcast message with Target Role(s)
    Form Screen_Shot_2022-02-02_at_4.11.07_PM
    Created broadcast message in the table Screen_Shot_2022-02-02_at_4.12.21_PM

Validate

  1. Login with a non-admin user
  2. Go to a project/group/sub-group page where the role of the currently logged-in user matches one of the roles you set when you created the broadcast message
  3. Validate that the broadcast message is displayed
    Project members page where current user is a developer Screen_Shot_2022-02-02_at_4.22.09_PM

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Eugie Limpin

Merge request reports