Class: GroupHistory
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- GroupHistory
- Defined in:
- app/models/group_history.rb
Class Method Summary collapse
Class Method Details
.actions ⇒ Object
12 13 14 15 16 17 18 19 20 21 |
# File 'app/models/group_history.rb', line 12 def self.actions @actions ||= Enum.new( change_group_setting: 1, add_user_to_group: 2, remove_user_from_group: 3, make_user_group_owner: 4, remove_user_as_group_owner: 5, ) end |
.filters ⇒ Object
23 24 25 |
# File 'app/models/group_history.rb', line 23 def self.filters %i[acting_user target_user action subject] end |
.with_filters(group, params = {}) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'app/models/group_history.rb', line 27 def self.with_filters(group, params = {}) records = self .includes(:acting_user, :target_user) .where(group_id: group.id) .order("group_histories.created_at DESC") if !params.blank? params = params.slice(*filters) records = records.where(action: self.actions[params[:action].to_sym]) if params[ :action ].present? records = records.where(subject: params[:subject]) if params[:subject].present? %i[acting_user target_user].each do |filter| if params[filter].present? id = User.where(username_lower: params[filter]).pluck(:id) records = records.where("#{filter}_id" => id) end end end records end |