Skip to content

Commit

Permalink
Merge pull request #1245 from concord-consortium/187153689-researcher…
Browse files Browse the repository at this point in the history
…-classes

Add "Researcher Projects" to sidebar
  • Loading branch information
pjanik committed Mar 20, 2024
2 parents 8ebc487 + fd1ce82 commit 0e5f4ad
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
33 changes: 33 additions & 0 deletions rails/app/helpers/navigation_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ def show_admin_links
current_visitor.is_project_researcher?
end

def show_researcher_projects_links
current_visitor.is_project_researcher?
end

def show_switch_user_link
@original_user && @original_user != current_visitor
end
Expand Down Expand Up @@ -241,6 +245,31 @@ def project_link(project_link_spec)
}
end

def researcher_project_links
if current_visitor.researcher_for_projects.empty?
return []
end

links = [{
id: '/researcher_projects',
label: nav_label('researcher_projects'),
type: NavigationService::SECTION_TYPE,
sort: 4
}]

projects = current_visitor.researcher_for_projects

projects.each do |project|
links << {
id: "/researcher_projects/#{project.id}",
label: project.name,
url: url_for(project),
}
end

links
end

def project_links
links = []
if current_visitor.has_role?('admin', 'manager', 'researcher') || current_visitor.portal_teacher
Expand Down Expand Up @@ -292,6 +321,10 @@ def navigation_service(params={})
service.add_item switch_user_link
end

if show_researcher_projects_links
researcher_project_links.each {|clazz_link| service.add_item clazz_link}
end

clazz_links.each {|clazz_link| service.add_item clazz_link}
project_links.each { |link| service.add_item link}

Expand Down
1 change: 1 addition & 0 deletions rails/config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ en:
full_status: Full Status
links: Links
switch_back: Switch back
researcher_projects: Researcher Projects

'en-HAS':
activerecord:
Expand Down
18 changes: 18 additions & 0 deletions rails/spec/helpers/navigation_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@
let(:fake_clazzes) { FactoryBot.create_list(:portal_clazz, 3)}
let(:fake_inactive_clazz) { FactoryBot.create(:portal_clazz, is_archived: true)}
let(:fake_student) { FactoryBot.create(:full_portal_student, clazzes: fake_clazzes) }
let(:fake_researcher) {
researcher = FactoryBot.generate(:researcher_user)
researcher.researcher_for_projects << FactoryBot.create(:project)
researcher
}
let(:fake_teacher) {
teacher = FactoryBot.create(:portal_teacher, clazzes: fake_clazzes)
teacher.teacher_clazzes.create(clazz: fake_inactive_clazz)
Expand Down Expand Up @@ -120,6 +125,19 @@
it "should not include favorites links" do
expect(subject).not_to match %r{"label": "Favorites"}
end

it "should not include researcher project links" do
expect(subject).not_to match %r{"label": "Researcher Projects"}
end
end

describe "researcher links" do
let(:fake_visitor) { fake_researcher }
subject { JSON.pretty_generate(helper.navigation_service(params).to_hash) }

it "should include researcher project links" do
expect(subject).to match %r{"label": "Researcher Projects"}
end
end

describe "selections" do
Expand Down

0 comments on commit 0e5f4ad

Please sign in to comment.