Module: TbCore::UserModel::ClassMethods
- Defined in:
- app/models/concerns/tb_core/user_model.rb
Overview
rubocop:enable Metrics/BlockLength
Instance Method Summary collapse
- #as_csv(column_names) ⇒ Object
-
#where_name_like(string) ⇒ Object
Returns an ActiveRecord::Relation performing a LIKE query against name columns.
-
#with_permission(tag, include_supers: true) ⇒ Object
Return an array of users who have the requested permission.
Instance Method Details
#as_csv(column_names) ⇒ Object
90 91 92 93 94 95 96 97 |
# File 'app/models/concerns/tb_core/user_model.rb', line 90 def as_csv(column_names) CSV.generate do |csv| csv << column_names all.find_each do |item| csv << item.attributes.values_at(*column_names) end end end |
#where_name_like(string) ⇒ Object
Returns an ActiveRecord::Relation performing a LIKE query against name columns
68 69 70 71 72 73 74 75 |
# File 'app/models/concerns/tb_core/user_model.rb', line 68 def where_name_like(string) full_name = Arel::Nodes::NamedFunction.new( 'concat', [arel_table[:first_name], Arel::Nodes.build_quoted(' '), arel_table[:last_name]] ) search = '%' + string + '%' where(full_name.matches(search)) end |
#with_permission(tag, include_supers: true) ⇒ Object
Return an array of users who have the requested permission
-
tag - Desired permission tag string (required)
-
include_supers - Whether to include super user (default: true)
81 82 83 84 85 86 87 88 |
# File 'app/models/concerns/tb_core/user_model.rb', line 81 def (tag, include_supers: true) role_ids = SpudRolePermission.where(spud_permission_tag: tag).pluck(:spud_role_id).uniq() if include_supers where(super_admin: true).or(where(spud_role_id: role_ids)) else where(spud_role_id: role_ids) end end |