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 `calendars#index` route

Aaron Contreras8608e1429cf9
diff --git a/.rubocop.yml b/.rubocop.yml
index b93cdc1295a..f53ac4aad3c 100644
--- a/.rubocop.yml
+++ b/.rubocop.yml
@@ -242,6 +242,7 @@ RSpec/ContextWording:
- unless
- when
- with
+ - within
- without
Style/Alias:
diff --git a/modules/calendar/app/controllers/calendar/calendars_controller.rb b/modules/calendar/app/controllers/calendar/calendars_controller.rb
index cb0d7df5b8b..934cdd07439 100644
--- a/modules/calendar/app/controllers/calendar/calendars_controller.rb
+++ b/modules/calendar/app/controllers/calendar/calendars_controller.rb
@@ -54,6 +54,15 @@ module ::Calendar
private
+ def find_optional_project
+ return unless params[:project_id]
+
+ @project = Project.find(params[:project_id])
+ authorize
+ rescue ActiveRecord::RecordNotFound
+ render_404
+ end
+
def visible_views
Query
.visible(current_user)
diff --git a/modules/calendar/config/routes.rb b/modules/calendar/config/routes.rb
index 7a3fb244028..993b095367b 100644
--- a/modules/calendar/config/routes.rb
+++ b/modules/calendar/config/routes.rb
@@ -9,4 +9,6 @@ OpenProject::Application.routes.draw do
get '(/*state)' => 'calendar/calendars#show', on: :member, as: ''
end
end
+
+ resources :calendars, only: :index, controller: 'calendar/calendars'
end
diff --git a/modules/calendar/spec/controllers/calendar_controller_spec.rb b/modules/calendar/spec/controllers/calendar_controller_spec.rb
index 834510f4843..5f76af84c4c 100644
--- a/modules/calendar/spec/controllers/calendar_controller_spec.rb
+++ b/modules/calendar/spec/controllers/calendar_controller_spec.rb
@@ -50,7 +50,7 @@ RSpec.describe Calendar::CalendarsController do
end
end
- before { login_as(user) }
+ before { login_as user }
describe '#index' do
shared_examples_for 'calendar#index' do
@@ -61,12 +61,20 @@ RSpec.describe Calendar::CalendarsController do
it { is_expected.to render_template('calendar/calendars/index') }
end
- context 'with project' do
+ context 'within a project context' do
before do
get :index, params: { project_id: project.id }
end
it_behaves_like 'calendar#index'
end
+
+ context 'within a global context' do
+ before do
+ get :index
+ end
+
+ it_behaves_like 'calendar#index'
+ end
end
end
diff --git a/modules/calendar/spec/routing/calendar_routing_spec.rb b/modules/calendar/spec/routing/calendar_routing_spec.rb
index 6dff3cf7e3a..3bbd6347ee9 100644
--- a/modules/calendar/spec/routing/calendar_routing_spec.rb
+++ b/modules/calendar/spec/routing/calendar_routing_spec.rb
@@ -29,6 +29,11 @@
require 'spec_helper'
RSpec.describe Calendar::CalendarsController do
+ it do
+ expect(get('calendars')).to route_to(controller: 'calendar/calendars',
+ action: 'index')
+ end
+
it do
expect(get('/projects/1/calendars')).to route_to(controller: 'calendar/calendars',
action: 'index',