MDL-75333 reportbuilder: report audience type for site admins.
[moodle.git] / reportbuilder / tests / behat / audience.feature
blob4614c95323bacdd651a324e378ba8437a9d9ab78
1 @core_reportbuilder @javascript
2 Feature: Configure access to reports based on intended audience
3   As an admin
4   I want to restrict which users have access to a report
6   Background:
7     Given the following "custom profile fields" exist:
8       | datatype | shortname | name  |
9       | text     | fruit     | Fruit |
10     And the following "users" exist:
11       | username  | firstname | lastname | email             | profile_field_fruit |
12       | user1     | User      | 1        | user1@example.com | Apple               |
13       | user2     | User      | 2        | user2@example.com | Banana              |
14       | user3     | User      | 3        | user3@example.com | Banana              |
15     And the following "core_reportbuilder > Reports" exist:
16       | name      | source                                   | default |
17       | My report | core_user\reportbuilder\datasource\users | 1       |
19   Scenario: Configure report audience with manually added users audience type
20     When I log in as "user1"
21     And I follow "Reports" in the user menu
22     And I should see "Nothing to display"
23     And I log out
24     And I am on the "My report" "reportbuilder > Editor" page logged in as "admin"
25     And I click on the "Access" dynamic tab
26     And I should see "Nothing to display"
27     And I click on the "Audience" dynamic tab
28     And I should see "There are no audiences for this report"
29     And I click on "Add audience 'Manually added users'" "link"
30     And I should see "Added audience 'Manually added users'"
31     And I set the field "Add users manually" to "User 1,User 3"
32     And I press "Save changes"
33     And I should see "Audience saved"
34     And I should see "User 1"
35     And I should not see "User 2"
36     And I should see "User 3"
37     And I should not see "There are no audiences for this report"
38     And I click on the "Access" dynamic tab
39     And I should see "User 1" in the "reportbuilder-table" "table"
40     And I should not see "User 2" in the "reportbuilder-table" "table"
41     And I should see "User 3" in the "reportbuilder-table" "table"
42     And I log out
43     And I log in as "user1"
44     And I follow "Reports" in the user menu
45     Then I should see "My report" in the "reportbuilder-table" "table"
46     And I click on "My report" "link" in the "My report" "table_row"
47     And I should see "User 1" in the "reportbuilder-table" "table"
49   Scenario: Configure report audience with administrator audience type
50     Given I am on the "My report" "reportbuilder > Editor" page logged in as "admin"
51     And I click on the "Audience" dynamic tab
52     When I click on "Add audience 'Site administrators'" "link"
53     And I press "Save changes"
54     Then I should see "Audience saved"
55     And I click on the "Access" dynamic tab
56     And I should see "Admin User" in the "reportbuilder-table" "table"
57     And I should not see "User 1" in the "reportbuilder-table" "table"
58     And I should not see "User 2" in the "reportbuilder-table" "table"
59     And I should not see "User 3" in the "reportbuilder-table" "table"
61   Scenario: Configure report audience with has system role audience type
62     Given the following "roles" exist:
63       | shortname | name      | archetype |
64       | testrole  | Test role |            |
65     And the following "role assigns" exist:
66       | user    | role     | contextlevel | reference |
67       | user2   | testrole | System       |          |
68     And I am on the "My report" "reportbuilder > Editor" page logged in as "admin"
69     And I click on the "Audience" dynamic tab
70     When I click on "Add audience 'Assigned system role'" "link"
71     And I should see "Added audience 'Assigned system role'"
72     And I set the field "Select a role" to "Test role"
73     And I press "Save changes"
74     Then I should see "Audience saved"
75     And I should see "Test role"
76     And I should not see "There are no audiences for this report"
77     And I click on the "Access" dynamic tab
78     And I should not see "User 1" in the "reportbuilder-table" "table"
79     And I should see "User 2" in the "reportbuilder-table" "table"
80     And I should not see "User 3" in the "reportbuilder-table" "table"
81     And I log out
82     And I am on the "My report" "reportbuilder > View" page logged in as "user2"
83     And I should see "User 1" in the "reportbuilder-table" "table"
85   Scenario: Configure report audience with Member of cohort audience type
86     Given the following "cohorts" exist:
87       | name    | idnumber |
88       | Cohort1 | cohort1  |
89     And the following "cohort members" exist:
90       | cohort  | user  |
91       | cohort1 | user3 |
92     And I am on the "My report" "reportbuilder > Editor" page logged in as "admin"
93     And I click on the "Audience" dynamic tab
94     When I click on "Add audience 'Member of cohort'" "link"
95     And I should see "Added audience 'Member of cohort'"
96     And I set the field "Select members from cohort" to "Cohort1"
97     And I press "Save changes"
98     Then I should see "Audience saved"
99     And I should see "Cohort1"
100     And I should not see "There are no audiences for this report"
101     And I click on the "Access" dynamic tab
102     And I should not see "User 1" in the "reportbuilder-table" "table"
103     And I should not see "User 2" in the "reportbuilder-table" "table"
104     And I should see "User 3" in the "reportbuilder-table" "table"
105     And I log out
106     And I am on the "My report" "reportbuilder > View" page logged in as "user3"
107     And I should see "User 1" in the "reportbuilder-table" "table"
109   Scenario: Configure report audience with Member of cohort audience type with no cohorts available
110     Given I am on the "My report" "reportbuilder > Editor" page logged in as "admin"
111     When I click on the "Audience" dynamic tab
112     Then "Add audience 'All users'" "link" should exist
113     # This audience type should be disabled because there are no cohorts available.
114     And "Add audience 'Member of cohort'" "link" should not exist
115     And the "title" attribute of "//div[@data-region='sidebar-menu']/descendant::div[normalize-space(.)='Member of cohort']" "xpath_element" should contain "Not available"
117   Scenario: Configure report audience as user who cannot use specific audience
118     Given the following "users" exist:
119       | username  | firstname | lastname |
120       | manager1  | Manager   | 1        |
121     And the following "role assigns" exist:
122       | user     | role    | contextlevel   | reference |
123       | manager1 | manager | System         |           |
124     And the following "permission overrides" exist:
125       | capability                   | permission | role    | contextlevel | reference |
126       | moodle/reportbuilder:editall | Allow      | manager | System       |           |
127       | moodle/cohort:view           | Prohibit   | manager | System       |           |
128     And I am on the "My report" "reportbuilder > Editor" page logged in as "manager1"
129     When I click on the "Audience" dynamic tab
130     Then I should not see "Member of cohort" in the "[data-region='sidebar-menu']" "css_element"
132   Scenario: Search for and add audience to report
133     Given I am on the "My report" "reportbuilder > Editor" page logged in as "admin"
134     And I click on the "Audience" dynamic tab
135     When I set the field "Search" in the "[data-region=sidebar-menu]" "css_element" to "All users"
136     Then I should see "All users" in the "[data-region=sidebar-menu]" "css_element"
137     And I should not see "Member of cohort" in the "[data-region=sidebar-menu]" "css_element"
138     And I click on "Add audience 'All users'" "link"
139     And I should see "Added audience 'All users'"
140     And I press "Save changes"
141     And I should see "Audience saved"
143   Scenario: Rename report audience
144     Given I am on the "My report" "reportbuilder > Editor" page logged in as "admin"
145     And I click on the "Audience" dynamic tab
146     And I click on "Add audience 'All users'" "link"
147     And I press "Save changes"
148     When I set the field "Rename audience 'All users'" to "All my lovely users"
149     And I reload the page
150     Then I should see "All my lovely users" in the "[data-region='audience-card']" "css_element"
152   Scenario: Rename report audience using filters
153     Given the "multilang" filter is "on"
154     And the "multilang" filter applies to "content and headings"
155     And I am on the "My report" "reportbuilder > Editor" page logged in as "admin"
156     And I click on the "Audience" dynamic tab
157     And I click on "Add audience 'All users'" "link"
158     And I press "Save changes"
159     When I set the field "Rename audience 'All users'" to "<span class=\"multilang\" lang=\"en\">English</span><span class=\"multilang\" lang=\"es\">Spanish</span>"
160     And I reload the page
161     Then I should see "English" in the "[data-region='audience-card']" "css_element"
162     And I should not see "Spanish" in the "[data-region='audience-card']" "css_element"
164   Scenario: Delete report audience
165     Given I am on the "My report" "reportbuilder > Editor" page logged in as "admin"
166     And I click on the "Audience" dynamic tab
167     And I click on "Add audience 'All users'" "link"
168     And I press "Save changes"
169     When I click on "Delete audience 'All users'" "button"
170     And I click on "Delete" "button" in the "Delete audience 'All users'" "dialogue"
171     Then I should see "Deleted audience 'All users'"
172     And I should see "There are no audiences for this report"
174   Scenario: Edit report audience with manually added users audience type
175     Given I am on the "My report" "reportbuilder > Editor" page logged in as "admin"
176     And I click on the "Access" dynamic tab
177     And I should see "Nothing to display"
178     And I click on the "Audience" dynamic tab
179     And I should see "There are no audiences for this report"
180     And I click on "Add audience 'Manually added users'" "link"
181     And I set the field "Add users manually" to "User 1,User 3"
182     And I press "Save changes"
183     When I press "Edit audience 'Manually added users'"
184     And I set the field "Add users manually" to "User 2"
185     And I press "Save changes"
186     Then I should see "Audience saved"
187     And I should not see "User 1"
188     And I should see "User 2"
189     And I should not see "User 3"
190     And I click on the "Access" dynamic tab
191     And I should not see "User 1" in the "reportbuilder-table" "table"
192     And I should see "User 2" in the "reportbuilder-table" "table"
193     And I should not see "User 3" in the "reportbuilder-table" "table"
195   Scenario: View configured user identity fields on the access tab
196     Given the following config values are set as admin:
197       | showuseridentity | email,profile_field_fruit |
198     And the following "core_reportbuilder > Audiences" exist:
199       | report    | configdata |
200       | My report |            |
201     And I am on the "My report" "reportbuilder > Editor" page logged in as "admin"
202     When I click on the "Access" dynamic tab
203     Then the following should exist in the "reportbuilder-table" table:
204       | -0-    | Email address     | Fruit  |
205       | User 1 | user1@example.com | Apple  |
206       | User 2 | user2@example.com | Banana |
207       | User 3 | user3@example.com | Banana |
208     # Now let's filter them.
209     And I click on "Filters" "button"
210     And I set the following fields in the "Fruit" "core_reportbuilder > Filter" to these values:
211       | Fruit operator | Is equal to |
212       | Fruit value    | Banana      |
213     And I click on "Apply" "button" in the "[data-region='report-filters']" "css_element"
214     And I should not see "User 1" in the "reportbuilder-table" "table"
215     And I should see "User 2" in the "reportbuilder-table" "table"
216     And I should see "User 3" in the "reportbuilder-table" "table"
217     And I set the following fields in the "Email address" "core_reportbuilder > Filter" to these values:
218       | Email address operator | Contains |
219       | Email address value    | user2 |
220     And I click on "Apply" "button" in the "[data-region='report-filters']" "css_element"
221     And I should not see "User 1" in the "reportbuilder-table" "table"
222     And I should see "User 2" in the "reportbuilder-table" "table"
223     And I should not see "User 3" in the "reportbuilder-table" "table"
225   Scenario: View report as a user with edit capability
226     Given the following "roles" exist:
227       | shortname       | name      | archetype |
228       | viewreportsrole | Test role |           |
229     And the following "role assigns" exist:
230       | user     | role             | contextlevel | reference |
231       | user1    | viewreportsrole  | System       |           |
232     And the following "permission overrides" exist:
233       | capability                    | permission  | role            | contextlevel | reference |
234       | moodle/reportbuilder:editall  | Prohibit    | viewreportsrole | System       |           |
235       | moodle/reportbuilder:edit     | Allow       | viewreportsrole | System       |           |
236       | moodle/reportbuilder:view     | Prohibit    | viewreportsrole | System       |           |
237     When I log in as "user1"
238     And I follow "Reports" in the user menu
239     And I should see "Nothing to display"
240     And I click on "New report" "button"
241     And I set the following fields in the "New report" "dialogue" to these values:
242       | Name                  | My user1 report |
243       | Report source         | Users           |
244       | Include default setup | 1               |
245     And I click on "Save" "button" in the "New report" "dialogue"
246     And I click on "Close 'My user1 report' editor" "button"
247     And I should see "My user1 report" in the "reportbuilder-table" "table"
248     And I press "View report" action in the "My user1 report" report row
249     And I should see "User 1" in the "reportbuilder-table" "table"
251   Scenario: View report as a user with editall capability
252     Given the following "roles" exist:
253       | shortname       | name      | archetype |
254       | viewreportsrole | Test role |           |
255     And the following "role assigns" exist:
256       | user     | role             | contextlevel | reference |
257       | user1    | viewreportsrole  | System       |           |
258     And the following "permission overrides" exist:
259       | capability                    | permission  | role            | contextlevel | reference |
260       | moodle/reportbuilder:editall  | Allow       | viewreportsrole | System       |           |
261       | moodle/reportbuilder:edit     | Prohibit    | viewreportsrole | System       |           |
262       | moodle/reportbuilder:view     | Prohibit    | viewreportsrole | System       |           |
263     When I log in as "user1"
264     And I follow "Reports" in the user menu
265     Then I should see "My report" in the "reportbuilder-table" "table"
266     And I press "View report" action in the "My report" report row
267     And I should see "User 1" in the "reportbuilder-table" "table"