Class: Pageflow::Admin::UserEntriesTab

Inherits:
ViewComponent
  • Object
show all
Defined in:
app/views/components/pageflow/admin/user_entries_tab.rb

Overview

Since:

  • 12.2

Instance Method Summary collapse

Instance Method Details

#build(user) ⇒ Object

Since:

  • 12.2



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'app/views/components/pageflow/admin/user_entries_tab.rb', line 4

def build(user)
  embedded_index_table(user.memberships.on_entries
                         .includes(:entry, entry: :account).references(:pageflow_entries)
                         .accessible_by(current_ability, :index),
                       blank_slate_text: t('pageflow.admin.users.no_entries')) do
    table_for_collection class: 'memberships', sortable: true, i18n: Pageflow::Membership do
      column :entry, sortable: 'pageflow_entries.title' do |membership|
        link_to(membership.entry.title, admin_entry_path(membership.entry))
      end
      column :role, sortable: 'pageflow_memberships.role' do |membership|
        membership_role_with_tooltip(membership.role, scope: 'entries')
      end
      column :account, sortable: 'pageflow_accounts.name' do |membership|
        if authorized?(:read, membership.entry.)
          link_to(membership.entry..name,
                  (membership.entry.))
        else
          membership.entry..name
        end
      end
      column :created_at, sortable: 'pageflow_memberships.created_at'
      column do |membership|
        if authorized?(:update, membership)
          link_to(t('pageflow.admin.users.edit_role'),
                  edit_admin_user_membership_path(
                    user,
                    membership,
                    entity_type: 'Pageflow::Entry'
                  ),
                  data: {
                    rel: "edit_entry_role_#{membership.role}"
                  })
        end
      end
      column do |membership|
        if authorized?(:destroy, membership)
          link_to(t('pageflow.admin.users.delete'),
                  admin_user_membership_path(user, membership),
                  method: :delete,
                  data: {
                    confirm: t('pageflow.admin.users.delete_entry_membership_confirmation'),
                    rel: "delete_entry_membership_#{membership.role}"
                  })
        end
      end
    end
    add_membership_button(current_user, user, 'entry')
  end
end