add custom_actions controller & routes

The models are only stubbed
pull/6140/head
Jens Ulferts 7 years ago
parent a0b822d50b
commit 126d2baf00
No known key found for this signature in database
GPG Key ID: 3CAA4B1182CF5308
  1. 42
      app/controllers/custom_actions_controller.rb
  2. 3
      app/views/custom_actions/_form.html.erb
  3. 12
      app/views/custom_actions/index.html.erb
  4. 38
      app/views/custom_actions/new.html.erb
  5. 2
      config/routes.rb
  6. 130
      spec/controllers/custom_actions_controller_spec.rb
  7. 27
      spec/features/work_packages/workflow_buttons_spec.rb
  8. 52
      spec/routing/custom_actions_spec.rb

@ -0,0 +1,42 @@
#-- encoding: UTF-8
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2017 the OpenProject Foundation (OPF)
#
# 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 doc/COPYRIGHT.rdoc for more details.
#++
class CustomActionsController < ApplicationController
before_action :require_admin
def index; end
def new
@custom_action = OpenStruct.new name: ''
end
def create
redirect_to custom_actions_path
end
end

@ -0,0 +1,3 @@
<div class="form--field">
<%= f.text_field :name, required: true, container_class: '-middle', label: 'Name' %>
</div>

@ -0,0 +1,12 @@
<% html_title l(:label_administration), 'Custom actions (placeholder)' -%>
<%= toolbar title: 'Custom actions (placeholder)' do %>
<li class="toolbar-item">
<%= link_to new_custom_action_path,
{ class: 'button -alt-highlight',
aria: { label: 'Custom action (placeholder)' },
title: 'Custom action (placeholder)' } do %>
<%= op_icon('button--icon icon-add') %>
<span class="button--text"><%= t('Custom action (placeholer)') %></span>
<% end %>
</li>
<% end %>

@ -0,0 +1,38 @@
<%#-- copyright
OpenProject is a project management system.
Copyright (C) 2012-2017 the OpenProject Foundation (OPF)
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 doc/COPYRIGHT.rdoc for more details.
++#%>
<% html_title l(:label_administration), t('custom_actions.new') %>
<% local_assigns[:additional_breadcrumb] = t('custom_actions.new') %>
<%= breadcrumb_toolbar t('custom_actions.new') %>
<%= labelled_tabular_form_for @custom_action, as: :custom_action, url: custom_actions_path do |f| %>
<%= render partial: 'form', locals: { f: f } %>
<%= styled_button_tag l(:button_create), class: '-highlight -with-icon icon-checkmark' %>
<% end %>

@ -353,6 +353,8 @@ OpenProject::Application.routes.draw do
get :test_connection
end
end
resources :custom_actions, only: %i(index new create)
end
# We should fix this crappy routing (split up and rename controller methods)

@ -0,0 +1,130 @@
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2017 the OpenProject Foundation (OPF)
#
# 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 doc/COPYRIGHT.rdoc for more details.
#++
require 'spec_helper'
describe CustomActionsController, type: :controller do
let(:admin) { FactoryGirl.build(:admin) }
let(:non_admin) { FactoryGirl.build(:user) }
describe '#index' do
context 'for admins' do
before do
login_as(admin)
get :index
end
it 'returns 200' do
expect(response.response_code)
.to eql 200
end
it 'renders index template' do
expect(response)
.to render_template('index')
end
end
context 'for non admins' do
before do
login_as(non_admin)
get :index
end
it 'returns 403' do
expect(response.response_code)
.to eql 403
end
end
end
describe '#new' do
context 'for admins' do
before do
login_as(admin)
get :new
end
it 'returns 200' do
expect(response.response_code)
.to eql 200
end
it 'renders new template' do
expect(response)
.to render_template('new')
end
it 'assigns custom_action' do
expect(assigns(:custom_action))
.not_to be_nil
end
end
context 'for non admins' do
before do
login_as(non_admin)
get :new
end
it 'returns 403' do
expect(response.response_code)
.to eql 403
end
end
end
describe '#create' do
context 'for admins' do
before do
login_as(admin)
post :create
end
it 'redirects to index' do
expect(response)
.to redirect_to(custom_actions_path)
end
end
context 'for non admins' do
before do
login_as(non_admin)
get :new
end
it 'returns 403' do
expect(response.response_code)
.to eql 403
end
end
end
end

@ -31,6 +31,7 @@ require 'spec_helper'
describe 'Workflow buttons', type: :feature, js: true do
let(:permissions) { %i(view_work_packages edit_work_packages) }
let(:role) { FactoryGirl.create(:role, permissions: permissions )}
let(:admin) { FactoryGirl.create(:admin) }
let(:user) do
FactoryGirl.create(:user,
member_through_role: role,
@ -73,16 +74,36 @@ describe 'Workflow buttons', type: :feature, js: true do
end
before do
login_as(user)
login_as(admin)
work_package
immediate_priority
workflows
wp_page.visit!
end
scenario 'viewing workflow buttons' do
# create custom actions
visit custom_actions_path
within '.toolbar-items' do
click_link 'Custom action'
end
fill_in 'Name', with: 'Unassign'
click_button 'Create'
expect(page)
.to have_current_path(custom_actions_path)
expect(page)
.to have_content 'Unassign'
# use custom actions
login_as(user)
wp_page.visit!
expect(page)
.to have_selector('.workflow-button', text: 'Unassign')
expect(page)

@ -0,0 +1,52 @@
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2017 the OpenProject Foundation (OPF)
#
# 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 doc/COPYRIGHT.rdoc for more details.
#++
require 'spec_helper'
describe 'custom_actions routes', type: :routing do
describe 'index' do
it 'links GET /admin/custom_actions' do
expect(get('/admin/custom_actions'))
.to route_to('custom_actions#index')
end
end
describe 'new' do
it 'links GET /admin/custom_actions/new' do
expect(get('/admin/custom_actions/new'))
.to route_to('custom_actions#new')
end
end
describe 'create' do
it 'links POST /admin/custom_actions' do
expect(post('/admin/custom_actions'))
.to route_to('custom_actions#create')
end
end
end
Loading…
Cancel
Save