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

Add Global `meetings#index` page

Aaron Contrerasae90fb0bf73a
diff --git a/.rubocop.yml b/.rubocop.yml
index f53ac4aad3c..84c569581df 100644
--- a/.rubocop.yml
+++ b/.rubocop.yml
@@ -233,6 +233,7 @@ RSpec/NamedSubject:
RSpec/ContextWording:
Prefixes:
+ - and
- as
- for
- having
diff --git a/modules/calendar/app/components/calendar/row_component.rb b/modules/calendar/app/components/calendar/row_component.rb
index 0da2962cd43..269fb0a6452 100644
--- a/modules/calendar/app/components/calendar/row_component.rb
+++ b/modules/calendar/app/components/calendar/row_component.rb
@@ -38,6 +38,10 @@ module Calendar
link_to query.name, project_calendar_path(project, query.id)
end
+ def project_id
+ link_to project.name, project_path(project)
+ end
+
def created_at
helpers.format_time(query.created_at)
end
diff --git a/modules/calendar/app/components/calendar/table_component.rb b/modules/calendar/app/components/calendar/table_component.rb
index 54af89aa333..dfe47166c09 100644
--- a/modules/calendar/app/components/calendar/table_component.rb
+++ b/modules/calendar/app/components/calendar/table_component.rb
@@ -28,18 +28,28 @@
module Calendar
class TableComponent < ::TableComponent
- options :current_user
- columns :name, :created_at
+ options :current_project, :current_user
- def sortable?
- false
+ sortable_columns :name, :project_id, :created_at
+
+ def initial_sort
+ %i[name asc]
+ end
+
+ def paginated?
+ true
end
def headers
- [
+ @headers ||= [
['name', { caption: I18n.t(:label_name) }],
+ current_project.blank? ? ['project_id', { caption: I18n.t('attributes.project') }] : nil,
['created_at', { caption: I18n.t('attributes.created_at') }]
- ]
+ ].compact
+ end
+
+ def columns
+ @columns ||= headers.map(&:first)
end
end
end
diff --git a/modules/calendar/app/controllers/calendar/calendars_controller.rb b/modules/calendar/app/controllers/calendar/calendars_controller.rb
index 934cdd07439..5efe3490903 100644
--- a/modules/calendar/app/controllers/calendar/calendars_controller.rb
+++ b/modules/calendar/app/controllers/calendar/calendars_controller.rb
@@ -29,11 +29,15 @@
module ::Calendar
class CalendarsController < ApplicationController
before_action :find_optional_project
- before_action :authorize
+ before_action :authorize, except: %i[index]
+ before_action :authorize_global, only: %i[index]
before_action :find_calendar, only: %i[destroy]
menu_item :calendar_view
+ include PaginationHelper
+ include SortHelper
+
def index
@views = visible_views
end
@@ -64,12 +68,16 @@ module ::Calendar
end
def visible_views
- Query
- .visible(current_user)
- .joins(:views)
- .where('views.type' => 'work_packages_calendar')
- .where('queries.project_id' => @project.id)
- .order('queries.name ASC')
+ base_query = Query
+ .visible(current_user)
+ .joins(:views)
+ .where('views.type' => 'work_packages_calendar')
+
+ if @project
+ base_query = base_query.where('queries.project_id' => @project.id)
+ end
+
+ base_query.order('queries.name ASC')
end
def find_calendar
diff --git a/modules/calendar/app/views/calendar/calendars/index.html.erb b/modules/calendar/app/views/calendar/calendars/index.html.erb
index 040722f265f..9d7acbaa005 100644
--- a/modules/calendar/app/views/calendar/calendars/index.html.erb
+++ b/modules/calendar/app/views/calendar/calendars/index.html.erb
@@ -41,4 +41,4 @@ See COPYRIGHT and LICENSE files for more details.
<% end %>
<% end %>
-<%= render ::Calendar::TableComponent.new(rows: @views, current_user: current_user) %>
+<%= render ::Calendar::TableComponent.new(rows: @views, current_project: @project, current_user: current_user) %>
diff --git a/modules/calendar/spec/features/calendars_index_spec.rb b/modules/calendar/spec/features/calendars_index_spec.rb
index 3efd4d99d66..c286360085c 100644
--- a/modules/calendar/spec/features/calendars_index_spec.rb
+++ b/modules/calendar/spec/features/calendars_index_spec.rb
@@ -28,14 +28,18 @@
require 'spec_helper'
-RSpec.describe 'Team planner index', js: true, with_ee: %i[team_planner_view] do
+RSpec.describe 'Calendars', 'index', :js, :with_cuprite do
shared_let(:project) do
create(:project, enabled_module_names: %w[work_package_tracking calendar_view])
end
+ shared_let(:other_project) do
+ create(:project, enabled_module_names: %w[work_package_tracking calendar_view])
+ end
+
shared_let(:user) do
create(:user,
- member_in_project: project,
+ member_in_projects: [project, other_project],
member_with_permissions: %w[
view_work_packages
edit_work_packages
@@ -52,28 +56,45 @@ RSpec.describe 'Team planner index', js: true, with_ee: %i[team_planner_view] do
user:,
public: true)
end
+ let(:other_query) do
+ create(:query_with_view_work_packages_calendar,
+ project: other_project,
+ user:,
+ public: true)
+ end
let(:current_user) { user }
- before do
- login_as current_user
- query
- visit project_calendars_path(project)
- end
+ context 'when visiting from a global context' do
+ let(:queries) { [query, other_query] }
- context 'with no view' do
- let(:query) { nil }
+ before do
+ login_as current_user
+ queries
+ visit calendars_path
+ end
- it 'shows an index action' do
- expect(page).to have_text 'There is currently nothing to display.'
- expect(page).to have_selector '.button', text: 'Calendar'
+ context 'with permissions to globally manage calendars' do
+ it 'shows no create button' do
+ expect(page).not_to have_selector '.button', text: 'Calendar'
+ end
end
- end
- context 'with an existing view' do
- it 'shows that view' do
- expect(page).to have_selector 'td', text: query.name
- expect(page).to have_selector "[data-qa-selector='calendar-remove-#{query.id}']"
+ context 'with no views' do
+ let(:queries) { [] }
+
+ it 'shows an empty index page' do
+ expect(page).to have_text 'There is currently nothing to display.'
+ end
+ end
+
+ context 'with existing views' do
+ it 'shows those views', :aggregate_failures do
+ queries.each do |q|
+ expect(page).to have_selector 'td', text: q.name
+ expect(page).to have_selector "[data-qa-selector='calendar-remove-#{q.id}']"
+ end
+ end
end
context 'with another user with limited access' do
@@ -84,17 +105,7 @@ RSpec.describe 'Team planner index', js: true, with_ee: %i[team_planner_view] do
member_with_permissions: %w[view_work_packages view_calendar])
end
- it 'does not show the create button' do
- expect(page).to have_selector 'td', text: query.name
-
- # Does not show the delete
- expect(page).not_to have_selector "[data-qa-selector='calendar-remove-#{query.id}']"
-
- # Does not show the create button
- expect(page).not_to have_selector '.button', text: 'Calendar'
- end
-
- context 'when the view is non-public' do
+ context 'and the view is non-public' do
let(:query) { create(:query, user:, project:, public: false) }
it 'does not show a non-public view' do
@@ -103,10 +114,65 @@ RSpec.describe 'Team planner index', js: true, with_ee: %i[team_planner_view] do
# Does not show the delete
expect(page).not_to have_selector "[data-qa-selector='team-planner-remove-#{query.id}']"
+ end
+ end
+ end
+ end
+
+ context 'when visiting from a project-specific context' do
+ before do
+ login_as current_user
+ query
+ visit project_calendars_path(project)
+ end
+
+ context 'with no views' do
+ let(:query) { nil }
+
+ it 'shows an empty index page' do
+ expect(page).to have_text 'There is currently nothing to display.'
+ expect(page).to have_selector '.button', text: 'Calendar'
+ end
+ end
+
+ context 'with an existing view' do
+ it 'shows that view' do
+ expect(page).to have_selector 'td', text: query.name
+ expect(page).to have_selector "[data-qa-selector='calendar-remove-#{query.id}']"
+ end
+
+ context 'with another user with limited access' do
+ let(:current_user) do
+ create(:user,
+ firstname: 'Bernd',
+ member_in_project: project,
+ member_with_permissions: %w[view_work_packages view_calendar])
+ end
+
+ it 'does not show the create button' do
+ expect(page).to have_selector 'td', text: query.name
+
+ # Does not show the delete
+ expect(page).not_to have_selector "[data-qa-selector='calendar-remove-#{query.id}']"
# Does not show the create button
expect(page).not_to have_selector '.button', text: 'Calendar'
end
+
+ context 'when the view is non-public' do
+ let(:query) { create(:query, user:, project:, public: false) }
+
+ it 'does not show a non-public view' do
+ expect(page).to have_text 'There is currently nothing to display.'
+ expect(page).not_to have_selector 'td', text: query.name
+
+ # Does not show the delete
+ expect(page).not_to have_selector "[data-qa-selector='team-planner-remove-#{query.id}']"
+
+ # Does not show the create button
+ expect(page).not_to have_selector '.button', text: 'Calendar'
+ end
+ end
end
end
end