Skip to content

Commit

Permalink
Merge pull request #2087 from tf/user-attribute-table
Browse files Browse the repository at this point in the history
Make user admin attributes table extensible
  • Loading branch information
tf authored Mar 7, 2024
2 parents 6a78645 + e22e267 commit 2b49d8a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 15 deletions.
16 changes: 1 addition & 15 deletions admins/pageflow/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,7 @@ module Pageflow

show do |user|
div do
attributes_table_for user do
row :last_name, class: 'last_name'
row :first_name, class: 'first_name'
row :email, class: 'email'

row :created_at
row :last_sign_in_at
boolean_status_tag_row :suspended?
row :locale do
I18n.t('language', locale: user.locale)
end
if authorized?(:see_admin_status, user)
boolean_status_tag_row(:admin?, 'admin warning')
end
end
render('attributes_table', user:)

para do
link_to I18n.t('pageflow.admin.users.resend_invitation'),
Expand Down
13 changes: 13 additions & 0 deletions app/views/admin/users/_attributes_table.html.arb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
extensible_attributes_table_for(user, Pageflow.config.admin_attributes_table_rows.for(:user)) do
row :last_name, class: 'last_name'
row :first_name, class: 'first_name'
row :email, class: 'email'

row :created_at
row :last_sign_in_at
boolean_status_tag_row :suspended?
row :locale do
I18n.t('language', locale: user.locale)
end
boolean_status_tag_row(:admin?, 'admin warning') if authorized?(:see_admin_status, user)
end
16 changes: 16 additions & 0 deletions spec/controllers/admin/users_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,22 @@ def self.name
end
end
end

describe 'additional attributes table rows' do
it 'renders additional rows registered for user' do
user = create(:user)
create(:account, with_manager: user)

pageflow_configure do |config|
config.admin_attributes_table_rows.register(:user, :custom) { 'custom attribute' }
end

sign_in(user, scope: :user)
get(:show, params: {id: user.id})

expect(response.body).to have_text('custom attribute')
end
end
end

describe 'get #quota_state' do
Expand Down

0 comments on commit 2b49d8a

Please sign in to comment.