diff --git a/rails/app/helpers/navigation_helper.rb b/rails/app/helpers/navigation_helper.rb index fe6738dd3..b3e9df8ce 100644 --- a/rails/app/helpers/navigation_helper.rb +++ b/rails/app/helpers/navigation_helper.rb @@ -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 @@ -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 @@ -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} diff --git a/rails/config/locales/en.yml b/rails/config/locales/en.yml index 96785dbd1..16dcd8a7e 100644 --- a/rails/config/locales/en.yml +++ b/rails/config/locales/en.yml @@ -167,6 +167,7 @@ en: full_status: Full Status links: Links switch_back: Switch back + researcher_projects: Researcher Projects 'en-HAS': activerecord: diff --git a/rails/spec/helpers/navigation_helper_spec.rb b/rails/spec/helpers/navigation_helper_spec.rb index b39efe8c9..20c1bc1a9 100644 --- a/rails/spec/helpers/navigation_helper_spec.rb +++ b/rails/spec/helpers/navigation_helper_spec.rb @@ -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) @@ -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