Merge pull request #10220 from opf/feature/41278/index-action-calendar
[41278] Add index action for calendarspull/10230/head
commit
22da742051
@ -0,0 +1,70 @@ |
|||||||
|
#-- encoding: UTF-8 |
||||||
|
|
||||||
|
#-- copyright |
||||||
|
# OpenProject is an open source project management software. |
||||||
|
# Copyright (C) 2012-2020 the OpenProject GmbH |
||||||
|
# |
||||||
|
# This program is free software; you can redistribute it and/or |
||||||
|
# modify it under the terms of the GNU General Public License version 3. |
||||||
|
# |
||||||
|
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: |
||||||
|
# Copyright (C) 2006-2017 Jean-Philippe Lang |
||||||
|
# Copyright (C) 2010-2013 the ChiliProject Team |
||||||
|
# |
||||||
|
# This program is free software; you can redistribute it and/or |
||||||
|
# modify it under the terms of the GNU General Public License |
||||||
|
# as published by the Free Software Foundation; either version 2 |
||||||
|
# of the License, or (at your option) any later version. |
||||||
|
# |
||||||
|
# This program is distributed in the hope that it will be useful, |
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||||
|
# GNU General Public License for more details. |
||||||
|
# |
||||||
|
# You should have received a copy of the GNU General Public License |
||||||
|
# along with this program; if not, write to the Free Software |
||||||
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
||||||
|
# |
||||||
|
# See COPYRIGHT and LICENSE files for more details. |
||||||
|
#++ |
||||||
|
|
||||||
|
module Calendar |
||||||
|
class RowCell < ::RowCell |
||||||
|
include ApplicationHelper |
||||||
|
include ::Redmine::I18n |
||||||
|
|
||||||
|
def query |
||||||
|
model |
||||||
|
end |
||||||
|
|
||||||
|
delegate :project, to: :query |
||||||
|
|
||||||
|
def name |
||||||
|
link_to query.name, project_calendar_path(project, query.id) |
||||||
|
end |
||||||
|
|
||||||
|
def created_at |
||||||
|
format_time(query.created_at) |
||||||
|
end |
||||||
|
|
||||||
|
def button_links |
||||||
|
[delete_link].compact |
||||||
|
end |
||||||
|
|
||||||
|
def delete_link |
||||||
|
if table.current_user.allowed_to?(:manage_calendars, project) |
||||||
|
link_to( |
||||||
|
'', |
||||||
|
project_calendar_path(project, query.id), |
||||||
|
method: :delete, |
||||||
|
class: 'icon icon-delete', |
||||||
|
data: { |
||||||
|
confirm: I18n.t(:text_are_you_sure), |
||||||
|
'qa-selector': "calendar-remove-#{query.id}" |
||||||
|
}, |
||||||
|
title: t(:button_delete) |
||||||
|
) |
||||||
|
end |
||||||
|
end |
||||||
|
end |
||||||
|
end |
@ -0,0 +1,76 @@ |
|||||||
|
#-- encoding: UTF-8 |
||||||
|
|
||||||
|
#-- copyright |
||||||
|
# OpenProject is an open source project management software. |
||||||
|
# Copyright (C) 2012-2021 the OpenProject GmbH |
||||||
|
# |
||||||
|
# This program is free software; you can redistribute it and/or |
||||||
|
# modify it under the terms of the GNU General Public License version 3. |
||||||
|
# |
||||||
|
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: |
||||||
|
# Copyright (C) 2006-2013 Jean-Philippe Lang |
||||||
|
# Copyright (C) 2010-2013 the ChiliProject Team |
||||||
|
# |
||||||
|
# This program is free software; you can redistribute it and/or |
||||||
|
# modify it under the terms of the GNU General Public License |
||||||
|
# as published by the Free Software Foundation; either version 2 |
||||||
|
# of the License, or (at your option) any later version. |
||||||
|
# |
||||||
|
# This program is distributed in the hope that it will be useful, |
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||||
|
# GNU General Public License for more details. |
||||||
|
# |
||||||
|
# You should have received a copy of the GNU General Public License |
||||||
|
# along with this program; if not, write to the Free Software |
||||||
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
||||||
|
# |
||||||
|
# See COPYRIGHT and LICENSE files for more details. |
||||||
|
#++ |
||||||
|
|
||||||
|
module ::Calendar |
||||||
|
class CalendarsController < ApplicationController |
||||||
|
before_action :find_optional_project |
||||||
|
before_action :authorize |
||||||
|
|
||||||
|
before_action :find_calendar, only: %i[destroy] |
||||||
|
menu_item :calendar_view |
||||||
|
|
||||||
|
def index |
||||||
|
@views = visible_views |
||||||
|
end |
||||||
|
|
||||||
|
def show |
||||||
|
render layout: 'angular/angular' |
||||||
|
end |
||||||
|
|
||||||
|
def destroy |
||||||
|
if @view.destroy |
||||||
|
flash[:notice] = t(:notice_successful_delete) |
||||||
|
else |
||||||
|
flash[:error] = t(:error_can_not_delete_entry) |
||||||
|
end |
||||||
|
|
||||||
|
redirect_to action: :index |
||||||
|
end |
||||||
|
|
||||||
|
private |
||||||
|
|
||||||
|
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') |
||||||
|
end |
||||||
|
|
||||||
|
def find_calendar |
||||||
|
@view = Query |
||||||
|
.visible(current_user) |
||||||
|
.find(params[:id]) |
||||||
|
rescue ActiveRecord::RecordNotFound |
||||||
|
render_404 |
||||||
|
end |
||||||
|
end |
||||||
|
end |
@ -0,0 +1,44 @@ |
|||||||
|
<%#-- copyright |
||||||
|
OpenProject is an open source project management software. |
||||||
|
Copyright (C) 2012-2021 the OpenProject GmbH |
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or |
||||||
|
modify it under the terms of the GNU General Public License version 3. |
||||||
|
|
||||||
|
OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: |
||||||
|
Copyright (C) 2006-2013 Jean-Philippe Lang |
||||||
|
Copyright (C) 2010-2013 the ChiliProject Team |
||||||
|
|
||||||
|
This program is free software; you can redistribute it and/or |
||||||
|
modify it under the terms of the GNU General Public License |
||||||
|
as published by the Free Software Foundation; either version 2 |
||||||
|
of the License, or (at your option) any later version. |
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful, |
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||||
|
GNU General Public License for more details. |
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License |
||||||
|
along with this program; if not, write to the Free Software |
||||||
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
||||||
|
|
||||||
|
See COPYRIGHT and LICENSE files for more details. |
||||||
|
|
||||||
|
++#%> |
||||||
|
|
||||||
|
<% html_title(t(:label_calendar_plural)) -%> |
||||||
|
<%= toolbar title: t(:label_calendar_plural) do %> |
||||||
|
<% if current_user.allowed_to?(:manage_calendars, @project) %> |
||||||
|
<li class="toolbar-item"> |
||||||
|
<%= link_to new_project_calendars_path(@project), |
||||||
|
class: 'button -alt-highlight', |
||||||
|
title: t(:button_create) do %> |
||||||
|
<%= op_icon('button--icon icon-add') %> |
||||||
|
<span class="button--text"><%= t(:button_create) %></span> |
||||||
|
<% end %> |
||||||
|
</li> |
||||||
|
<% end %> |
||||||
|
<% end %> |
||||||
|
|
||||||
|
<%= rails_cell ::Calendar::TableCell, @views, current_user: current_user %> |
@ -1,4 +1,6 @@ |
|||||||
# English strings go here |
# English strings go here |
||||||
en: |
en: |
||||||
permission_view_calendar: "View calendar" |
label_calendar_plural: "Calendars" |
||||||
|
permission_view_calendars: "View calendars" |
||||||
|
permission_manage_calendars: "Manage calendars" |
||||||
project_module_calendar_view: "Calendar" |
project_module_calendar_view: "Calendar" |
||||||
|
@ -1,7 +1,11 @@ |
|||||||
OpenProject::Application.routes.draw do |
OpenProject::Application.routes.draw do |
||||||
scope 'projects/:project_id', as: 'project' do |
scope 'projects/:project_id', as: 'project' do |
||||||
get '/calendar(/*state)', to: 'calendar/calendar#index', as: :calendar |
resources :calendars, |
||||||
|
controller: 'calendar/calendars', |
||||||
|
only: %i[index destroy], |
||||||
|
as: :calendars do |
||||||
|
get '/new' => 'calendar/calendars#show', on: :collection, as: 'new' |
||||||
|
get '(/*state)' => 'calendar/calendars#show', on: :member, as: '' |
||||||
|
end |
||||||
end |
end |
||||||
|
|
||||||
get '/calendar(/*state)', to: 'calendar/calendar#index', as: :calendar |
|
||||||
end |
end |
||||||
|
@ -0,0 +1,115 @@ |
|||||||
|
#-- encoding: UTF-8 |
||||||
|
|
||||||
|
#-- copyright |
||||||
|
# OpenProject is an open source project management software. |
||||||
|
# Copyright (C) 2012-2021 the OpenProject GmbH |
||||||
|
# |
||||||
|
# This program is free software; you can redistribute it and/or |
||||||
|
# modify it under the terms of the GNU General Public License version 3. |
||||||
|
# |
||||||
|
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: |
||||||
|
# Copyright (C) 2006-2013 Jean-Philippe Lang |
||||||
|
# Copyright (C) 2010-2013 the ChiliProject Team |
||||||
|
# |
||||||
|
# This program is free software; you can redistribute it and/or |
||||||
|
# modify it under the terms of the GNU General Public License |
||||||
|
# as published by the Free Software Foundation; either version 2 |
||||||
|
# of the License, or (at your option) any later version. |
||||||
|
# |
||||||
|
# This program is distributed in the hope that it will be useful, |
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||||
|
# GNU General Public License for more details. |
||||||
|
# |
||||||
|
# You should have received a copy of the GNU General Public License |
||||||
|
# along with this program; if not, write to the Free Software |
||||||
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
||||||
|
# |
||||||
|
# See COPYRIGHT and LICENSE files for more details. |
||||||
|
#++ |
||||||
|
|
||||||
|
require 'spec_helper' |
||||||
|
|
||||||
|
describe 'Team planner index', type: :feature, js: true, with_ee: %i[team_planner_view] do |
||||||
|
shared_let(: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_with_permissions: %w[ |
||||||
|
view_work_packages |
||||||
|
edit_work_packages |
||||||
|
save_queries |
||||||
|
save_public_queries |
||||||
|
view_calendar |
||||||
|
manage_calendars |
||||||
|
] |
||||||
|
end |
||||||
|
|
||||||
|
let(:query) do |
||||||
|
create(:query_with_view_work_packages_calendar, |
||||||
|
project: project, |
||||||
|
user: user, |
||||||
|
public: true) |
||||||
|
end |
||||||
|
|
||||||
|
let(:current_user) { user } |
||||||
|
|
||||||
|
before do |
||||||
|
login_as current_user |
||||||
|
query |
||||||
|
visit project_calendars_path(project) |
||||||
|
end |
||||||
|
|
||||||
|
context 'with no view' do |
||||||
|
let(:query) { nil } |
||||||
|
|
||||||
|
it 'shows an index action' do |
||||||
|
expect(page).to have_text 'There is currently nothing to display.' |
||||||
|
expect(page).to have_selector '.button', text: 'Create' |
||||||
|
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).to have_no_selector "[data-qa-selector='calendar-remove-#{query.id}']" |
||||||
|
|
||||||
|
# Does not show the create button |
||||||
|
expect(page).to have_no_selector '.button', text: 'Create' |
||||||
|
end |
||||||
|
|
||||||
|
context 'when the view is non-public' do |
||||||
|
let(:query) { create :query, user: user, project: 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).to have_no_selector 'td', text: query.name |
||||||
|
|
||||||
|
# Does not show the delete |
||||||
|
expect(page).to have_no_selector "[data-qa-selector='team-planner-remove-#{query.id}']" |
||||||
|
|
||||||
|
# Does not show the create button |
||||||
|
expect(page).to have_no_selector '.button', text: 'Create' |
||||||
|
end |
||||||
|
end |
||||||
|
end |
||||||
|
end |
||||||
|
end |
Loading…
Reference in new issue