Class: Marty::Users::UserView
- Defined in:
- app/components/marty/users/user_view.rb
Constant Summary
Constants included from Permissions
Class Method Summary collapse
- .create_edit_user(data) ⇒ Object
- .set_roles(roles, user) ⇒ Object
-
.user_columns ⇒ Object
list of columns to be displayed in the grid view.
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
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'app/components/marty/users/user_view.rb', line 54 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
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'app/components/marty/users/user_view.rb', line 36 def self.set_roles(roles, user) roles = [] if roles.blank? 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_columns ⇒ Object
list of columns to be displayed in the grid view
10 11 12 13 14 15 16 17 18 |
# File 'app/components/marty/users/user_view.rb', line 10 def self.user_columns [ :login, :firstname, :lastname, :active, :user_roles, ] end |
Instance Method Details
#configure(c) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'app/components/marty/users/user_view.rb', line 20 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 if c.attributes.include?(:login) c.store_config[:sorters] = [{ property: :login, direction: 'ASC', }] end c.scope = ->(arel) { arel.includes(:user_roles) } end |
#default_context_menu ⇒ Object
125 126 127 |
# File 'app/components/marty/users/user_view.rb', line 125 def [] end |