Skip to content

Commit 2b49d8a

Browse files
authored
Merge pull request #2087 from tf/user-attribute-table
Make user admin attributes table extensible
2 parents 6a78645 + e22e267 commit 2b49d8a

File tree

3 files changed

+30
-15
lines changed

3 files changed

+30
-15
lines changed

admins/pageflow/user.rb

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,7 @@ module Pageflow
3838

3939
show do |user|
4040
div do
41-
attributes_table_for user do
42-
row :last_name, class: 'last_name'
43-
row :first_name, class: 'first_name'
44-
row :email, class: 'email'
45-
46-
row :created_at
47-
row :last_sign_in_at
48-
boolean_status_tag_row :suspended?
49-
row :locale do
50-
I18n.t('language', locale: user.locale)
51-
end
52-
if authorized?(:see_admin_status, user)
53-
boolean_status_tag_row(:admin?, 'admin warning')
54-
end
55-
end
41+
render('attributes_table', user:)
5642

5743
para do
5844
link_to I18n.t('pageflow.admin.users.resend_invitation'),
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
extensible_attributes_table_for(user, Pageflow.config.admin_attributes_table_rows.for(:user)) do
2+
row :last_name, class: 'last_name'
3+
row :first_name, class: 'first_name'
4+
row :email, class: 'email'
5+
6+
row :created_at
7+
row :last_sign_in_at
8+
boolean_status_tag_row :suspended?
9+
row :locale do
10+
I18n.t('language', locale: user.locale)
11+
end
12+
boolean_status_tag_row(:admin?, 'admin warning') if authorized?(:see_admin_status, user)
13+
end

spec/controllers/admin/users_controller_spec.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,22 @@ def self.name
128128
end
129129
end
130130
end
131+
132+
describe 'additional attributes table rows' do
133+
it 'renders additional rows registered for user' do
134+
user = create(:user)
135+
create(:account, with_manager: user)
136+
137+
pageflow_configure do |config|
138+
config.admin_attributes_table_rows.register(:user, :custom) { 'custom attribute' }
139+
end
140+
141+
sign_in(user, scope: :user)
142+
get(:show, params: {id: user.id})
143+
144+
expect(response.body).to have_text('custom attribute')
145+
end
146+
end
131147
end
132148

133149
describe 'get #quota_state' do

0 commit comments

Comments
 (0)