Class: Marty::UserView

Inherits:
Grid
  • Object
show all
Defined in:
app/components/marty/user_view.rb

Constant Summary

Constants included from Permissions

Permissions::NETZKE_ENDPOINTS

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Grid

#child_components, #class_can?, #configure_form_window, #get_json_sorter, #has_search_action?, #initialize, #linked_components

Methods included from Permissions

#can_call_endpoint?, #can_perform_action?, #can_perform_actions, #current_user_roles, extended, #has_any_perm?, #has_marty_permissions, #has_perm?

Constructor Details

This class inherits a constructor from Marty::Grid

Class Method Details

.create_edit_user(data) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'app/components/marty/user_view.rb', line 51

def self.create_edit_user(data)
  # Creates initial place-holder user object and validate
  user = data['id'].nil? ? User.new : User.find(data['id'])

  user_columns.each do |c|
    user.send("#{c}=", data[c.to_s]) unless c == :user_roles
  end

  if user.valid?
    user.save
    set_roles(data['user_roles'], user)
  end

  user
end

.set_roles(roles, user) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'app/components/marty/user_view.rb', line 33

def self.set_roles(roles, user)
  roles = [] unless roles.present?

  roles = ::Marty::RoleType.from_nice_names(roles)

  roles_in_user = user.user_roles.map(&:role)
  roles_to_delete = roles_in_user - roles
  roles_to_add = roles - roles_in_user

  Marty::User.transaction do
    user.user_roles.where(role: roles_to_delete).map(&:destroy!)

    roles_to_add.each do |role|
      user.user_roles.create!(role: role)
    end
  end
end

.user_columnsObject

list of columns to be displayed in the grid view



8
9
10
11
12
13
14
15
16
# File 'app/components/marty/user_view.rb', line 8

def self.user_columns
  [
    :login,
    :firstname,
    :lastname,
    :active,
    :user_roles,
  ]
end

Instance Method Details

#configure(c) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/components/marty/user_view.rb', line 18

def configure(c)
  super

  c.attributes   ||= self.class.user_columns
  c.title        ||= I18n.t('users', default: 'Users')
  c.model          = 'Marty::User'
  c.editing        = :in_form
  c.paging         = :pagination
  c.multi_select   = false
  c.store_config.merge!(sorters: [{ property: :login,
                                   direction: 'ASC',
                                  }]) if c.attributes.include?(:login)
  c.scope = ->(arel) { arel.includes(:user_roles) }
end

#default_context_menuObject



122
123
124
# File 'app/components/marty/user_view.rb', line 122

def default_context_menu
  []
end