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

Assign mentor to club when joining team #5308

Merged
merged 6 commits into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
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
8 changes: 4 additions & 4 deletions app/controllers/mentor/mentor_invites_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ def update

invite.update(invite_params)

student_chapters = invite.team.students.flat_map { |s| s.account.current_chapter }.uniq
student_chapterables = invite.team.students.flat_map { |s| s.account.current_chapterable_assignment&.chapterable }.uniq

student_chapters.each do |chapter|
if chapter.present?
chapter.chapter_account_assignments.create(
student_chapterables.each do |chapterable|
if chapterable.present?
chapterable.chapterable_account_assignments.create(
profile: current_mentor,
account: current_mentor.account,
season: Season.current.year,
Expand Down
8 changes: 4 additions & 4 deletions app/controllers/mentor/team_member_invites_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ def update
)
invite.update(invite_params)

student_chapters = invite.team.students.flat_map { |s| s.account.current_chapter }.uniq
student_chapterables = invite.team.students.flat_map { |s| s.account.current_chapterable_assignment&.chapterable }.uniq

student_chapters.each do |chapter|
if chapter.present?
chapter.chapter_account_assignments.create(
student_chapterables.each do |chapterable|
if chapterable.present?
chapterable.chapterable_account_assignments.create(
profile: current_mentor,
account: current_mentor.account,
season: Season.current.year,
Expand Down
6 changes: 3 additions & 3 deletions app/models/chapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ class Chapter < ActiveRecord::Base
has_one :legal_contact, dependent: :destroy
has_one :chapter_program_information, dependent: :destroy

has_many :chapter_account_assignments, as: :chapterable, class_name: "ChapterableAccountAssignment"
has_many :accounts, through: :chapter_account_assignments
has_many :chapterable_account_assignments, as: :chapterable, class_name: "ChapterableAccountAssignment"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this was (or is going to be) updated in the refactor work. I updated this association to match the chapterable account assignment association in the club model

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, nice naming alignment! 👍

has_many :accounts, through: :chapterable_account_assignments
has_many :chapter_ambassadors, -> { where "profile_type = 'ChapterAmbassadorProfile'" },
through: :chapter_account_assignments,
through: :chapterable_account_assignments,
source: :account

has_many :chapter_links, dependent: :destroy
Expand Down
8 changes: 8 additions & 0 deletions app/null_objects/null_account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ def name
"null account"
end

def scope_name
nil
end

def mentor_profile
::NullProfile.new
end
Expand Down Expand Up @@ -37,6 +41,10 @@ def authenticated?
false
end

def profile_image_url
nil
end

def current_chapter
NullChapter.new
end
Expand Down
2 changes: 1 addition & 1 deletion app/null_objects/null_chapterable.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class NullChapterable < NullObject
def primary_contact
nil
NullAccount.new
end
end
8 changes: 4 additions & 4 deletions app/technovation/join_request_approved.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ def self.call(join_request)
TeamRosterManaging.add(join_request.team, join_request.requestor)

if join_request.requestor_scope_name == "mentor"
student_chapters = join_request.team.students.flat_map { |s| s.account.current_chapter }.uniq
student_chapterables = join_request.team.students.flat_map { |s| s.account.current_chapterable_assignment&.chapterable }.uniq

student_chapters.each do |chapter|
if chapter.present?
chapter.chapter_account_assignments.create(
student_chapterables.each do |chapterable|
if chapterable.present?
chapterable.chapterable_account_assignments.create(
profile: join_request.requestor,
account: join_request.requestor.account,
season: Season.current.year,
Expand Down
88 changes: 45 additions & 43 deletions spec/controllers/mentor/mentor_invites_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -151,54 +151,56 @@
end
end

describe "mentor chapter assignments" do
context "when two students from the same chapter are on a team" do
let(:team) { FactoryBot.create(:team) }
let(:mentor) { FactoryBot.create(:mentor, :onboarded) }
let(:chapter) { FactoryBot.create(:chapter) }
let(:student1) { FactoryBot.create(:student, :not_assigned_to_chapter) }
let(:student2) { FactoryBot.create(:student, :not_assigned_to_chapter) }
let!(:invite) { FactoryBot.create(:team_member_invite, invitee: mentor) }

before do
student1.chapterable_assignments.create(
chapterable: chapter,
account: student1.account,
season: Season.current.year,
primary: true
)

student2.chapterable_assignments.create(
chapterable: chapter,
account: student2.account,
season: Season.current.year,
primary: true
)

team.students << student1
team.students << student2
team.save

invite.team = team
invite.save
end
describe "mentor chapterable assignments" do
%w[club chapter].each do |chapterable_type|
context "when two students from the same #{chapterable_type} are on a team" do
let(:team) { FactoryBot.create(:team) }
let(:mentor) { FactoryBot.create(:mentor, :onboarded) }
let(:chapterable) { FactoryBot.create(chapterable_type.to_sym) }
let(:student1) { FactoryBot.create(:student, :not_assigned_to_chapter) }
let(:student2) { FactoryBot.create(:student, :not_assigned_to_chapter) }
let!(:invite) { FactoryBot.create(:team_member_invite, invitee: mentor) }

context "when the mentor invite request for this team is accepted" do
before do
sign_in(mentor)

put :update, params: {
id: invite.invite_token,
team_member_invite: {status: :accepted}
}
student1.chapterable_assignments.create(
chapterable: chapterable,
account: student1.account,
season: Season.current.year,
primary: true
)

student2.chapterable_assignments.create(
chapterable: chapterable,
account: student2.account,
season: Season.current.year,
primary: true
)

team.students << student1
team.students << student2
team.save

invite.team = team
invite.save
end

it "creates one non-primary chapter assignment (since both students belong to the same chapter)" do
expect(mentor.account.chapterable_assignments.where(chapterable: chapter, primary: false).count).to eq(1)
end
context "when the mentor invite request for this team is accepted" do
before do
sign_in(mentor)

put :update, params: {
id: invite.invite_token,
team_member_invite: {status: :accepted}
}
end

it "creates one non-primary chapterable assignment (since both students belong to the same #{chapterable_type})" do
expect(mentor.account.chapterable_assignments.where(chapterable: chapterable, primary: false).count).to eq(1)
end

it "assigns the mentor to the student's chapter" do
expect(mentor.account.current_chapters).to include(student1.account.current_chapter)
it "assigns the mentor to the student's #{chapterable_type}" do
expect(mentor.account.chapterable_assignments.map(&:chapterable)).to include(student1.account.current_primary_chapterable_assignment.chapterable)
end
end
end
end
Expand Down
88 changes: 45 additions & 43 deletions spec/controllers/mentor/team_member_invites_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,54 +75,56 @@
end
end

describe "mentor chapter assignments" do
context "when two students from the same chapter are on a team" do
let(:team) { FactoryBot.create(:team) }
let(:mentor) { FactoryBot.create(:mentor, :onboarded) }
let(:chapter) { FactoryBot.create(:chapter) }
let(:student1) { FactoryBot.create(:student, :not_assigned_to_chapter) }
let(:student2) { FactoryBot.create(:student, :not_assigned_to_chapter) }
let!(:invite) { FactoryBot.create(:team_member_invite, invitee: mentor) }

before do
student1.chapterable_assignments.create(
chapterable: chapter,
account: student1.account,
season: Season.current.year,
primary: true
)

student2.chapterable_assignments.create(
chapterable: chapter,
account: student2.account,
season: Season.current.year,
primary: true
)

team.students << student1
team.students << student2
team.save

invite.team = team
invite.save
end
describe "mentor chapterable assignments" do
%w[club chapter].each do |chapterable_type|
context "when two students from the same #{chapterable_type} are on a team" do
let(:team) { FactoryBot.create(:team) }
let(:mentor) { FactoryBot.create(:mentor, :onboarded) }
let(:chapterable) { FactoryBot.create(chapterable_type.to_sym) }
let(:student1) { FactoryBot.create(:student, :not_assigned_to_chapter) }
let(:student2) { FactoryBot.create(:student, :not_assigned_to_chapter) }
let!(:invite) { FactoryBot.create(:team_member_invite, invitee: mentor) }

context "when the mentor invite request for this team is accepted" do
before do
sign_in(mentor)

put :update, params: {
id: invite.invite_token,
team_member_invite: {status: :accepted}
}
student1.chapterable_assignments.create(
chapterable: chapterable,
account: student1.account,
season: Season.current.year,
primary: true
)

student2.chapterable_assignments.create(
chapterable: chapterable,
account: student2.account,
season: Season.current.year,
primary: true
)

team.students << student1
team.students << student2
team.save

invite.team = team
invite.save
end

it "creates one non-primary chapter assignment (since both students belong to the same chapter)" do
expect(mentor.account.chapterable_assignments.where(chapterable: chapter, primary: false).count).to eq(1)
end
context "when the mentor invite request for this team is accepted" do
before do
sign_in(mentor)

put :update, params: {
id: invite.invite_token,
team_member_invite: {status: :accepted}
}
end

it "creates one non-primary chapterable assignment (since both students belong to the same #{chapterable_type})" do
expect(mentor.account.chapterable_assignments.where(chapterable: chapterable, primary: false).count).to eq(1)
end

it "assigns the mentor to the student's chapter" do
expect(mentor.account.current_chapters).to include(student1.account.current_chapter)
it "assigns the mentor to the student's #{chapterable_type}" do
expect(mentor.account.chapterable_assignments.map(&:chapterable)).to include(student1.account.current_primary_chapterable_assignment.chapterable)
end
end
end
end
Expand Down
96 changes: 49 additions & 47 deletions spec/controllers/student/join_requests_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -248,59 +248,61 @@
end
end

describe "mentor chapter assignments" do
context "when two students from the same chapter are on a team" do
let(:team) { FactoryBot.create(:team) }
let(:mentor) { FactoryBot.create(:mentor, :onboarded) }
let(:chapter) { FactoryBot.create(:chapter) }
let(:student1) { FactoryBot.create(:student, :not_assigned_to_chapter) }
let(:student2) { FactoryBot.create(:student, :not_assigned_to_chapter) }
let(:join_request) {
FactoryBot.create(
:join_request,
team: team,
requestor: mentor
)
}

before do
student1.chapterable_assignments.create(
chapterable: chapter,
account: student1.account,
season: Season.current.year,
primary: true
)

student2.chapterable_assignments.create(
chapterable: chapter,
account: student2.account,
season: Season.current.year,
primary: true
)

team.students << student1
team.students << student2
team.save
end

before do
sign_in(student1)
end
describe "mentor chapterable assignments" do
%w[club chapter].each do |chapterable_type|
context "when two students from the same #{chapterable_type} are on a team" do
let(:team) { FactoryBot.create(:team) }
let(:mentor) { FactoryBot.create(:mentor, :onboarded) }
let(:chapterable) { FactoryBot.create(chapterable_type.to_sym) }
let(:student1) { FactoryBot.create(:student, :not_assigned_to_chapter) }
let(:student2) { FactoryBot.create(:student, :not_assigned_to_chapter) }
let(:join_request) {
FactoryBot.create(
:join_request,
team: team,
requestor: mentor
)
}

context "when the mentor join request for the team is accepted" do
before do
put :update, params: {
id: join_request.review_token,
join_request: {status: :approved}
}
student1.chapterable_assignments.create(
chapterable: chapterable,
account: student1.account,
season: Season.current.year,
primary: true
)

student2.chapterable_assignments.create(
chapterable: chapterable,
account: student2.account,
season: Season.current.year,
primary: true
)

team.students << student1
team.students << student2
team.save
end

it "creates one non-primary chapter assignment (since both students belong to the same chapter)" do
expect(mentor.account.chapterable_assignments.where(chapterable: chapter, primary: false).count).to eq(1)
before do
sign_in(student1)
end

it "assigns the mentor to the student's chapter" do
expect(mentor.account.current_chapters).to include(student1.account.current_chapter)
context "when the mentor join request for the team is accepted" do
before do
put :update, params: {
id: join_request.review_token,
join_request: {status: :approved}
}
end

it "creates one non-primary chapterable assignment (since both students belong to the same #{chapterable_type})" do
expect(mentor.account.chapterable_assignments.where(chapterable: chapterable, primary: false).count).to eq(1)
end

it "assigns the mentor to the student's #{chapterable_type}" do
expect(mentor.account.chapterable_assignments.map(&:chapterable)).to include(student1.account.current_primary_chapterable_assignment.chapterable)
end
end
end
end
Expand Down