Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

remove my specific links from project list sidebar

ulferts2459ca92909a
diff --git a/app/menus/projects/menu.rb b/app/menus/projects/menu.rb
index df94d327b01..f2c4a7c5ae2 100644
--- a/app/menus/projects/menu.rb
+++ b/app/menus/projects/menu.rb
@@ -81,8 +81,8 @@ module Projects
def main_static_filters
static_filters [
ProjectQueries::Static::ACTIVE,
- ProjectQueries::Static::MY,
- ProjectQueries::Static::FAVORED,
+ current_user.logged? ? ProjectQueries::Static::MY : nil,
+ current_user.logged? ? ProjectQueries::Static::FAVORED : nil,
current_user.admin? ? ProjectQueries::Static::ARCHIVED : nil
].compact
end
diff --git a/spec/menus/projects/menu_spec.rb b/spec/menus/projects/menu_spec.rb
index 0e916a730b5..1d393ee460d 100644
--- a/spec/menus/projects/menu_spec.rb
+++ b/spec/menus/projects/menu_spec.rb
@@ -32,14 +32,13 @@ require "spec_helper"
RSpec.describe Projects::Menu do
let(:instance) { described_class.new(controller_path:, params:, current_user:) }
+ let!(:current_user_query) { ProjectQuery.create!(name: "Current user query", user:) }
let(:controller_path) { "foo" }
let(:params) { {} }
- shared_let(:current_user) { build(:user) }
+ let(:current_user) { user }
- shared_let(:current_user_query) do
- ProjectQuery.create!(name: "Current user query", user: current_user)
- end
+ shared_let(:user) { create(:user) }
shared_let(:other_user_query) do
ProjectQuery.create!(name: "Other user query", user: build(:user))
@@ -53,7 +52,7 @@ RSpec.describe Projects::Menu do
shared_let(:shared_query) do
ProjectQuery.create!(name: "Shared query", user: build(:user)).tap do |query|
- create(:project_query_member, entity: query, user: current_user, roles: [view_project_query_role])
+ create(:project_query_member, entity: query, user:, roles: [view_project_query_role])
end
end
@@ -67,9 +66,19 @@ RSpec.describe Projects::Menu do
describe "children items" do
subject(:children_menu_items) { menu_items.flat_map(&:children) }
- context "when the current user is an admin" do
- before do
- allow(current_user).to receive(:admin?).and_return(true)
+ context "when the current user is logged in (admin)" do
+ let(:current_user) { build(:admin) }
+
+ it "has the active projects item" do
+ expect(children_menu_items).to include(have_attributes(title: I18n.t("projects.lists.active")))
+ end
+
+ it "has the my projects item" do
+ expect(children_menu_items).to include(have_attributes(title: I18n.t("projects.lists.my")))
+ end
+
+ it "has the favorite projects item" do
+ expect(children_menu_items).to include(have_attributes(title: I18n.t("projects.lists.favored")))
end
it "has an archived projects item" do
@@ -77,34 +86,62 @@ RSpec.describe Projects::Menu do
end
end
- context "when the current user is not an admin" do
- before do
- allow(current_user).to receive(:admin?).and_return(false)
+ context "when the current user is logged in (no admin)" do
+ it "has the active projects item" do
+ expect(children_menu_items).to include(have_attributes(title: I18n.t("projects.lists.active")))
end
- it "has an archived projects item" do
+ it "has the my projects item" do
+ expect(children_menu_items).to include(have_attributes(title: I18n.t("projects.lists.my")))
+ end
+
+ it "has the favorite projects item" do
+ expect(children_menu_items).to include(have_attributes(title: I18n.t("projects.lists.favored")))
+ end
+
+ it "has no archived projects item" do
expect(children_menu_items).not_to include(have_attributes(title: I18n.t("projects.lists.archived")))
end
- end
- it "contains menu items" do
- expect(children_menu_items).to all(be_a(OpenProject::Menu::MenuItem))
- end
+ it "contains menu items" do
+ expect(children_menu_items).to all(be_a(OpenProject::Menu::MenuItem))
+ end
- it "contains item for current user query" do
- expect(children_menu_items).to include(have_attributes(title: "Current user query"))
- end
+ it "contains item for current user query" do
+ expect(children_menu_items).to include(have_attributes(title: "Current user query"))
+ end
- it "doesn't contain item for other user query" do
- expect(children_menu_items).not_to include(have_attributes(title: "Other user query"))
- end
+ it "doesn't contain item for other user query" do
+ expect(children_menu_items).not_to include(have_attributes(title: "Other user query"))
+ end
+
+ it "contains item for public query" do
+ expect(children_menu_items).to include(have_attributes(title: "Public query"))
+ end
- it "contains item for public query" do
- expect(children_menu_items).to include(have_attributes(title: "Public query"))
+ it "contains item for shared query" do
+ expect(children_menu_items).to include(have_attributes(title: "Shared query"))
+ end
end
- it "contains item for shared query" do
- expect(children_menu_items).to include(have_attributes(title: "Shared query"))
+ context "when the current user is not logged in" do
+ let(:current_user) { build(:anonymous) }
+
+ it "has the active projects item" do
+ expect(children_menu_items).to include(have_attributes(title: I18n.t("projects.lists.active")))
+ end
+
+ it "has no my projects item" do
+ expect(children_menu_items).not_to include(have_attributes(title: I18n.t("projects.lists.my")))
+ end
+
+ it "has no favorite projects item" do
+ expect(children_menu_items).not_to include(have_attributes(title: I18n.t("projects.lists.favored")))
+ end
+
+ it "has no archived projects item" do
+ expect(children_menu_items).not_to include(have_attributes(title: I18n.t("projects.lists.archived")))
+ end
end
end
@@ -112,7 +149,7 @@ RSpec.describe Projects::Menu do
subject(:titles) { menu_items.map { it.children.map(&:title) } }
shared_let(:another_current_user_query) do
- ProjectQuery.create!(name: "Another current user query", user: current_user)
+ ProjectQuery.create!(name: "Another current user query", user:)
end
shared_let(:another_public_query) do
@@ -121,7 +158,7 @@ RSpec.describe Projects::Menu do
shared_let(:another_shared_query) do
ProjectQuery.create!(name: "Another shared query", user: build(:user)).tap do |query|
- create(:project_query_member, entity: query, user: current_user, roles: [view_project_query_role])
+ create(:project_query_member, entity: query, user:, roles: [view_project_query_role])
end
end