Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix participants in project #217

Merged
merged 1 commit into from
Sep 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions app/models/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,18 @@ def should_generate_new_friendly_id?
end

def participants
users = statement_of_works.active_in_period(Time.zone.today,
Time.zone.today).map(&:requirements)
.flatten.map(&:assignments).flatten.map(&:user).flatten
User.where(id: users.map(&:id)).distinct
date = Time.zone.today

# Get the active statement of works in the given period
active_sows = statement_of_works.active_in_period(date, date)

# Find all the related requirements that are active in the period while keeping it as an ActiveRecord relation
active_requirements = Requirement.where(statement_of_work_id: active_sows.pluck(:id))
.active_in_period(date, date)

# Get the users related to assignments from the active requirements
User.joins(assignments: :requirement)
.where(assignments: { requirement_id: active_requirements.pluck(:id) })
.distinct
end
end
Loading