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-active-or-build-new.
-
#committee_member(committee:) ⇒ Object
Returns the user’s currently-active term on this committee, or nil.
- #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-active-or-build-new. If the user has no active term, build a fresh row (expired terms are history and are not edited in place through this helper).
43 44 45 |
# File 'app/models/concerns/effective_committees_user.rb', line 43 def build_committee_member(committee:) committee_member(committee: committee) || committee_members.build(committee: committee) end |
#committee_member(committee:) ⇒ Object
Returns the user’s currently-active term on this committee, or nil. A user may hold multiple terms on the same committee (history of past roles).
37 38 39 |
# File 'app/models/concerns/effective_committees_user.rb', line 37 def committee_member(committee:) committee_members.select(&:active?).find { |cm| cm.committee_id == committee.id } end |
#committees ⇒ Object
47 48 49 |
# File 'app/models/concerns/effective_committees_user.rb', line 47 def committees committee_members.select(&:active?).map { |cm| cm.committee }.uniq 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”
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'app/models/concerns/effective_committees_user.rb', line 52 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 |