Skip to content

Commit c113627

Browse files
committed
rename label to "Profiles with users", add test to restrict access to admins
1 parent 0887eec commit c113627

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

app/controllers/admin_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ def get_user_stats
513513
partial = 'user_stats_list'
514514
collection = Person.pals
515515
title = 'List of PALs'
516-
when 'registered_users'
516+
when 'profiles_with_users'
517517
partial = 'user_stats_list'
518518
collection = Person.registered
519519
title = 'All Profiles'

app/views/admin/_stats.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
["Non-#{t('project')} Members","non_project_members"],
1616
["PALs","pals"],
1717
["Profiles without users","profiles_without_users"],
18-
["Registered users", "registered_users"]]
18+
["Profiles with users", "profiles_with_users"]]
1919

2020
grouped_options = [['Status', status_options], ['Statistics', statistics_options], ['User Information', user_options]]
2121
%>

test/functional/admin_controller_test.rb

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,16 +198,26 @@ def setup
198198
assert User.current_user.person.is_admin?
199199
end
200200

201-
test 'get registered users' do
202-
user = FactoryBot.create(:user, email: '[email protected]')
201+
test 'admin can get profiles with users stats' do
202+
user = FactoryBot.create(:admin)
203+
login_as(user)
203204
person_with_user = user.person
204205
person_without_user = FactoryBot.create(:person, user: nil)
205-
get :get_stats, xhr: true, params: { page: 'registered_users' }
206+
get :get_stats, xhr: true, params: { page: 'profiles_with_users' }
206207
assert_response :success
207208
assert_match person_with_user.name, response.body
208209
refute_match person_without_user.name, response.body
209210
end
210211

212+
test 'non-admin cannot access profiles with users stats' do
213+
user = FactoryBot.create(:user)
214+
login_as(user)
215+
get :get_stats, xhr: true, params: { page: 'profiles_with_users' }
216+
assert_response :redirect
217+
assert_redirected_to root_path
218+
refute_nil flash[:error]
219+
end
220+
211221
test 'get project content stats' do
212222
get :get_stats, xhr: true, params: { page: 'content_stats' }
213223
assert_response :success

0 commit comments

Comments
 (0)