Class: Marty::UserView
- Defined in:
- app/components/marty/user_view.rb
Constant Summary
Constants included from Permissions
Permissions::ALL_ROLES, Permissions::REQ_ROLES
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
#class_can?, #configure_form_window, #get_json_sorter, #has_search_action?
Methods included from Permissions
#can_perform_action?, #can_perform_actions, #current_user_roles, #has_any_perm?, #has_marty_permissions
Class Method Details
.create_edit_user(data) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'app/components/marty/user_view.rb', line 47 def self.create_edit_user(data) # Creates initial place-holder user object and validate user = data["id"].nil? ? User.new : User.find(data["id"]) self.user_columns.each { |c| user.send("#{c}=", data[c.to_s]) unless c == :roles } if user.valid? user.save set_roles(data["roles"], user) end user end |
.set_roles(roles, user) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'app/components/marty/user_view.rb', line 33 def self.set_roles(roles, user) roles ||= [] # Destroy old roles (must call destroy for auditing to work properly) user.user_roles.each do |ur| ur.destroy unless roles.include?(I18n.t("roles.#{ur.role.name}")) end # set new roles user.roles = Role.select { |r| roles.include? I18n.t("roles.#{r.name}") } end |
.user_columns ⇒ Object
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, :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(:roles) } end |
#default_context_menu ⇒ Object
118 119 120 |
# File 'app/components/marty/user_view.rb', line 118 def [] end |