Module: EffectiveCommitteesUser
- Extended by:
- ActiveSupport::Concern
- Defined in:
- app/models/concerns/effective_committees_user.rb
Overview
EffectiveCommitteesUser
Mark your user model with effective_committees_user to get all the includes
Defined Under Namespace
Modules: Base, ClassMethods
Instance Method Summary collapse
-
#build_committee_member(committee:) ⇒ Object
Find or build.
-
#committee_member(committee:) ⇒ Object
Instance Methods.
- #committees ⇒ Object
-
#committees_recent_activity(limit: 100) ⇒ Object
When activity is for sequential uploaded files, group them together like: “12 files were added to Board of Directors - April 2025 Meeting”.
Instance Method Details
#build_committee_member(committee:) ⇒ Object
Find or build
40 41 42 |
# File 'app/models/concerns/effective_committees_user.rb', line 40 def build_committee_member(committee:) committee_member(committee: committee) || committee_members.build(committee: committee) end |
#committee_member(committee:) ⇒ Object
Instance Methods
35 36 37 |
# File 'app/models/concerns/effective_committees_user.rb', line 35 def committee_member(committee:) committee_members.find { |rep| rep.committee_id == committee.id } end |
#committees ⇒ Object
44 45 46 |
# File 'app/models/concerns/effective_committees_user.rb', line 44 def committees committee_members.select { |cm| cm.active? && !cm.marked_for_destruction? }.map { |cm| cm.committee } end |
#committees_recent_activity(limit: 100) ⇒ Object
When activity is for sequential uploaded files, group them together like: “12 files were added to Board of Directors - April 2025 Meeting”
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'app/models/concerns/effective_committees_user.rb', line 49 def committees_recent_activity(limit: 100) logs = EffectiveLogging.Log.logged_changes.deep .where(changes_to_type: 'Effective::Committee', changes_to_id: committees.map(&:id)) .order(created_at: :desc) # Recent activity should be for folders being created and files being uploaded/replaced logs = logs.select do |log| folder_created = (log.associated_type == 'Effective::CommitteeFolder' && log. == 'Created') file_changed = (log.associated_type == 'Effective::CommitteeFile' && (log. == 'Created' || log.details.dig(:changes, 'File').present?)) folder_created || file_changed end # Returns an Array of Arrays where some are 1 length groups # Others are multiple length groups of file changes to one folder logs = logs.slice_when do |a, b| (a.changes_to_id != b.changes_to_id) || (a.associated_type != b.associated_type) || (b.associated_type == "Effective::CommitteeFolder") || (a.associated.try(:committee_folder_id) != b.associated.try(:committee_folder_id)) end logs.take(limit) end |