Merge pull request #6804 from opf/feature/28866/work-packages-read-only
Implement read-only work package attributes based on statuspull/6822/head
commit
1728da9d1f
@ -0,0 +1,47 @@ |
||||
module Statuses |
||||
class RowCell < ::RowCell |
||||
include ::IconsHelper |
||||
include ::ColorsHelper |
||||
include ReorderLinksHelper |
||||
|
||||
def status |
||||
model |
||||
end |
||||
|
||||
def name |
||||
link_to status.name, edit_status_path(status) |
||||
end |
||||
|
||||
def is_default |
||||
checkmark(status.is_default?) |
||||
end |
||||
|
||||
def is_closed |
||||
checkmark(status.is_closed?) |
||||
end |
||||
|
||||
def is_readonly |
||||
checkmark(status.is_readonly?) |
||||
end |
||||
|
||||
def color |
||||
icon_for_color status.color |
||||
end |
||||
|
||||
def done_ratio |
||||
h(status.default_done_ratio) |
||||
end |
||||
|
||||
def sort |
||||
reorder_links 'status', |
||||
{ action: 'update', id: status }, |
||||
method: :patch |
||||
end |
||||
|
||||
def button_links |
||||
[ |
||||
delete_link(status_path(status)) |
||||
] |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,50 @@ |
||||
require_dependency 'statuses/row_cell' |
||||
|
||||
module Statuses |
||||
class TableCell < ::TableCell |
||||
|
||||
def initial_sort |
||||
%i[id asc] |
||||
end |
||||
|
||||
def sortable? |
||||
false |
||||
end |
||||
|
||||
def columns |
||||
headers.map(&:first) |
||||
end |
||||
|
||||
def inline_create_link |
||||
link_to new_status_path, |
||||
aria: { label: t(:label_work_package_status_new) }, |
||||
class: 'wp-inline-create--add-link', |
||||
title: t(:label_work_package_status_new) do |
||||
op_icon('icon icon-add') |
||||
end |
||||
end |
||||
|
||||
def empty_row_message |
||||
I18n.t :no_results_title_text |
||||
end |
||||
|
||||
def row_class |
||||
::Statuses::RowCell |
||||
end |
||||
|
||||
def headers |
||||
[ |
||||
[:name, caption: Status.human_attribute_name(:name)], |
||||
[:color, caption: Status.human_attribute_name(:color)], |
||||
[:is_default, caption: Status.human_attribute_name(:is_default)], |
||||
[:is_closed, caption: Status.human_attribute_name(:is_closed)], |
||||
[:is_readonly, caption: Status.human_attribute_name(:is_readonly)], |
||||
[:sort, caption: I18n.t(:label_sort)] |
||||
].tap do |default| |
||||
if WorkPackage.use_status_for_done_ratio? |
||||
default.insert 2, [:done_ratio, caption: WorkPackage.human_attribute_name(:done_ratio)] |
||||
end |
||||
end |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,5 @@ |
||||
class AddReadOnlyToStatuses < ActiveRecord::Migration[5.1] |
||||
def change |
||||
add_column :statuses, :is_readonly, :boolean, default: false |
||||
end |
||||
end |
@ -0,0 +1,39 @@ |
||||
//-- copyright
|
||||
// OpenProject is a project management system.
|
||||
// Copyright (C) 2012-2015 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-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 doc/COPYRIGHT.rdoc for more details.
|
||||
//++
|
||||
|
||||
import {HalResource} from 'core-app/modules/hal/resources/hal-resource'; |
||||
import {CollectionResource} from 'core-app/modules/hal/resources/collection-resource'; |
||||
import {InputState} from 'reactivestates'; |
||||
|
||||
export class StatusResource extends HalResource { |
||||
|
||||
public get state():InputState<this> { |
||||
return this.states.statuses.get(this.href as string) as any; |
||||
} |
||||
} |
||||
|
@ -0,0 +1,98 @@ |
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2018 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 docs/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
require 'spec_helper' |
||||
|
||||
describe 'Read-only statuses affect work package editing', |
||||
with_ee: %i[readonly_work_packages], |
||||
type: :feature, |
||||
js: true do |
||||
let(:locked_status) { FactoryBot.create :status, name: 'Locked', is_readonly: true } |
||||
let(:unlocked_status) { FactoryBot.create :status, name: 'Unlocked', is_readonly: false } |
||||
|
||||
let(:type) { FactoryBot.create :type_bug } |
||||
let(:project) { FactoryBot.create :project, types: [type] } |
||||
let!(:work_package) do |
||||
FactoryBot.create :work_package, |
||||
project: project, |
||||
type: type, |
||||
status: unlocked_status |
||||
end |
||||
|
||||
let(:role) { FactoryBot.create :role, permissions: %i[edit_work_packages view_work_packages] } |
||||
let(:user) do |
||||
FactoryBot.create :user, |
||||
member_in_project: project, |
||||
member_through_role: role |
||||
end |
||||
|
||||
let!(:workflow1) do |
||||
FactoryBot.create :workflow, |
||||
type_id: type.id, |
||||
old_status: unlocked_status, |
||||
new_status: locked_status, |
||||
role: role |
||||
end |
||||
let!(:workflow2) do |
||||
FactoryBot.create :workflow, |
||||
type_id: type.id, |
||||
old_status: locked_status, |
||||
new_status: unlocked_status, |
||||
role: role |
||||
end |
||||
|
||||
let(:wp_page) { Pages::FullWorkPackage.new(work_package) } |
||||
|
||||
before do |
||||
login_as(user) |
||||
wp_page.visit! |
||||
end |
||||
|
||||
it 'locks the work package on a read only status' do |
||||
expect(page).to have_selector '.work-package--attachments--drop-box' |
||||
|
||||
subject_field = wp_page.edit_field :subject |
||||
subject_field.activate! |
||||
subject_field.cancel_by_escape |
||||
|
||||
status_field = wp_page.edit_field :status |
||||
status_field.expect_state_text 'Unlocked' |
||||
status_field.update 'Locked' |
||||
|
||||
wp_page.expect_and_dismiss_notification(message: 'Successful update.') |
||||
|
||||
status_field.expect_state_text 'Locked' |
||||
|
||||
subject_field = wp_page.edit_field :subject |
||||
subject_field.activate! expect_open: false |
||||
subject_field.expect_read_only |
||||
|
||||
# Expect attachments not available |
||||
expect(page).to have_no_selector '.work-package--attachments--drop-box' |
||||
end |
||||
end |
@ -0,0 +1,50 @@ |
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2018 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 docs/COPYRIGHT.rdoc for more details. |
||||
#++ |
||||
|
||||
require 'spec_helper' |
||||
|
||||
describe 'Statuses administration', type: :feature do |
||||
let(:admin) { FactoryBot.create :admin } |
||||
|
||||
before do |
||||
login_as(admin) |
||||
visit new_status_path |
||||
end |
||||
|
||||
describe 'with EE token', with_ee: %i[readonly_work_packages] do |
||||
it 'allows to set readonly status' do |
||||
expect(page).to have_field 'status[is_readonly]', disabled: false |
||||
end |
||||
end |
||||
|
||||
describe 'without EE token' do |
||||
it 'does not allow to set readonly status' do |
||||
expect(page).to have_field 'status[is_readonly]', disabled: true |
||||
end |
||||
end |
||||
end |
Loading…
Reference in new issue