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

Make the widget_visible filter cleaner

Klaus Zanders43618a8e6c9e
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 282352e4518..b832abb46db 100644
--- a/modules/grids/app/representers/api/v3/grids/grid_representer.rb
+++ b/modules/grids/app/representers/api/v3/grids/grid_representer.rb
@@ -94,15 +94,9 @@ module API
getter: ->(*) do
represented
.widgets
- .select do |widget|
- ::Grids::Configuration.allowed_widget?(
- represented.class,
- widget.identifier,
- current_user,
- represented.project
- )
- end
- .sort_by { |w| w.id.to_i }.map do |widget|
+ .select { |widget| widget_visible?(widget) }
+ .sort_by { |w| w.id.to_i }
+ .map do |widget|
Widgets::WidgetRepresenter.new(widget, current_user:)
end
end,
@@ -128,6 +122,15 @@ module API
private
+ def widget_visible?(widget)
+ ::Grids::Configuration.allowed_widget?(
+ represented.class,
+ widget.identifier,
+ current_user,
+ represented.project
+ )
+ end
+
def delete_allowed?
represented.user_deletable? && write_allowed?
end