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

Fix specs

Klaus Zanderse3869783c866
diff --git a/modules/dashboards/spec/features/members_spec.rb b/modules/dashboards/spec/features/members_spec.rb
index 4e0d8828a65..5d067ff3766 100644
--- a/modules/dashboards/spec/features/members_spec.rb
+++ b/modules/dashboards/spec/features/members_spec.rb
@@ -30,7 +30,7 @@ require 'spec_helper'
require_relative '../support/pages/dashboard'
-RSpec.describe 'Members widget on dashboard', js: true do
+RSpec.describe 'Members widget on dashboard', :js do
let!(:project) { create(:project) }
let!(:other_project) { create(:project) }
@@ -128,25 +128,10 @@ RSpec.describe 'Members widget on dashboard', js: true do
.not_to have_link('Member')
end
- # A user without view permission will not see any members
+ # A user without view permission will not see the widget
login_as no_view_member_user
-
visit root_path
-
dashboard.visit!
-
- within members_area.area do
- expect(page)
- .to have_no_content manager_user.name
-
- expect(page)
- .to have_content('No visible members')
-
- expect(page)
- .not_to have_link('Member')
-
- expect(page)
- .not_to have_link('View all members')
- end
+ expect(page).not_to have_css('.grid--area.-widgeted:nth-of-type(1)')
end
end
diff --git a/modules/dashboards/spec/features/modifying_with_unallowed_spec.rb b/modules/dashboards/spec/features/modifying_with_unallowed_spec.rb
index 229b706eb57..f2a1ef92c09 100644
--- a/modules/dashboards/spec/features/modifying_with_unallowed_spec.rb
+++ b/modules/dashboards/spec/features/modifying_with_unallowed_spec.rb
@@ -30,7 +30,7 @@ require 'spec_helper'
require_relative '../support/pages/dashboard'
-RSpec.describe 'Modifying a dashboard which already has widgets for which permissions are lacking', js: true do
+RSpec.describe 'Modifying a dashboard which already has widgets for which permissions are lacking', :js do
let!(:project) do
create(:project)
end
@@ -65,7 +65,7 @@ RSpec.describe 'Modifying a dashboard which already has widgets for which permis
sleep(0.1)
- news_widget = Components::Grids::GridArea.new('.grid--area.-widgeted:nth-of-type(2)')
+ news_widget = Components::Grids::GridArea.new('.grid--area.-widgeted:nth-of-type(1)')
within news_widget.area do
expect(page)
@@ -76,7 +76,7 @@ RSpec.describe 'Modifying a dashboard which already has widgets for which permis
dashboard_page.visit!
- news_widget = Components::Grids::GridArea.new('.grid--area.-widgeted:nth-of-type(2)')
+ news_widget = Components::Grids::GridArea.new('.grid--area.-widgeted:nth-of-type(1)')
within news_widget.area do
expect(page)
@@ -90,6 +90,6 @@ RSpec.describe 'Modifying a dashboard which already has widgets for which permis
dashboard_page.visit!
expect(page)
- .not_to have_selector('.grid--area.-widgeted:nth-of-type(2)')
+ .not_to have_css('.grid--area.-widgeted:nth-of-type(2)')
end
end
diff --git a/modules/grids/app/representers/api/v3/grids/grid_representer.rb b/modules/grids/app/representers/api/v3/grids/grid_representer.rb
index a1e1160f0f7..c6695f8a5c7 100644
--- a/modules/grids/app/representers/api/v3/grids/grid_representer.rb
+++ b/modules/grids/app/representers/api/v3/grids/grid_representer.rb
@@ -36,7 +36,7 @@ module API
include ::API::V3::Attachments::AttachableRepresenterMixin
cached_representer key_parts: %i(widgets),
- dependencies: -> { User.current }
+ dependencies: -> { all_permissions_granted_to_user_under_project }
resource_link :scope,
getter: ->(*) {
@@ -165,6 +165,16 @@ module API
path_attributes.compact
end
+
+ def all_permissions_granted_to_user_under_project
+ Role
+ .joins(:members)
+ .where(members: { project_id: represented.project, principal: User.current })
+ .map(&:permissions)
+ .flatten
+ .uniq
+ .sort
+ end
end
end
end