commit
bdf3909fdf
@ -0,0 +1,31 @@ |
||||
#-- encoding: UTF-8 |
||||
|
||||
#-- 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. |
||||
#++ |
||||
|
||||
class Priority::InexistentPriority < IssuePriority; end |
@ -0,0 +1,31 @@ |
||||
#-- encoding: UTF-8 |
||||
|
||||
#-- 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. |
||||
#++ |
||||
|
||||
class Status::InexistentStatus < Status; end |
@ -0,0 +1,32 @@ |
||||
#-- encoding: UTF-8 |
||||
|
||||
#-- 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. |
||||
#++ |
||||
|
||||
class Type::InexistentType < Type |
||||
end |
@ -0,0 +1,31 @@ |
||||
#-- encoding: UTF-8 |
||||
|
||||
#-- 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. |
||||
#++ |
||||
|
||||
class User::InexistentUser < User; end |
@ -0,0 +1,5 @@ |
||||
class AddContentOrientationToCustomFields < ActiveRecord::Migration[6.0] |
||||
def change |
||||
add_column :custom_fields, :content_right_to_left, :boolean, default: false |
||||
end |
||||
end |
@ -0,0 +1,43 @@ |
||||
#-- 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. |
||||
#++ |
||||
|
||||
module Bcf::Issues |
||||
class BaseContract < ::ModelContract |
||||
attribute :uuid |
||||
attribute :work_package |
||||
attribute :index |
||||
|
||||
def validate |
||||
validate_user_allowed_to_manage |
||||
|
||||
super |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,39 @@ |
||||
#-- 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. |
||||
#++ |
||||
|
||||
module Bcf::Issues |
||||
class CreateContract < BaseContract |
||||
private |
||||
|
||||
def validate_user_allowed_to_manage |
||||
unless model.project && user.allowed_to?(:manage_bcf, model.project) |
||||
errors.add :base, :error_unauthorized |
||||
end |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,50 @@ |
||||
#-- encoding: UTF-8 |
||||
|
||||
#-- 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. |
||||
#++ |
||||
|
||||
module Bcf::API::V2_1::Endpoints |
||||
class Create < API::Utilities::Endpoints::Create |
||||
include ModifyMixin |
||||
|
||||
def present_success(_current_user, call) |
||||
render_representer |
||||
.new(call.result) |
||||
end |
||||
|
||||
def postprocess_errors(call) |
||||
Bcf::API::V2_1::Errors::ErrorMapper.map(super) |
||||
end |
||||
|
||||
private |
||||
|
||||
def deduce_process_service |
||||
"::Bcf::#{deduce_backend_namespace}::#{update_or_create}Service".constantize |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,46 @@ |
||||
#-- encoding: UTF-8 |
||||
|
||||
#-- 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. |
||||
#++ |
||||
|
||||
module Bcf::API::V2_1::Endpoints |
||||
module ModifyMixin |
||||
private |
||||
|
||||
def deduce_parse_service |
||||
Bcf::API::V2_1::ParseResourceParamsService |
||||
end |
||||
|
||||
def deduce_in_and_out_representer |
||||
"::Bcf::API::V2_1::#{deduce_api_namespace}::SingleRepresenter".constantize |
||||
end |
||||
|
||||
alias_method :deduce_parse_representer, :deduce_in_and_out_representer |
||||
alias_method :deduce_render_representer, :deduce_in_and_out_representer |
||||
end |
||||
end |
@ -0,0 +1,41 @@ |
||||
#-- encoding: UTF-8 |
||||
|
||||
#-- 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. |
||||
#++ |
||||
|
||||
module Bcf::API::V2_1 |
||||
module ProjectExtensions |
||||
class API < ::API::OpenProjectAPI |
||||
|
||||
get :extensions do |
||||
mapper = Definitions.new(project: @project, user: current_user) |
||||
Representer.new(mapper) |
||||
end |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,64 @@ |
||||
#-- encoding: UTF-8 |
||||
|
||||
#-- 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. |
||||
#++ |
||||
|
||||
module Bcf::API::V2_1::Errors |
||||
class ErrorMapper |
||||
extend ActiveModel::Naming |
||||
extend ActiveModel::Translation |
||||
|
||||
def read_attribute_for_validation(_attr) |
||||
nil |
||||
end |
||||
|
||||
def self.lookup_ancestors |
||||
[::Bcf::Issue] |
||||
end |
||||
|
||||
def self.map(original_errors) |
||||
mapped_errors = ActiveModel::Errors.new(new) |
||||
|
||||
original_errors.send(:error_symbols).each do |key, errors| |
||||
errors.map(&:first).each do |error| |
||||
mapped_errors.add(error_key_mapper(key), error) |
||||
end |
||||
end |
||||
|
||||
mapped_errors |
||||
end |
||||
|
||||
def self.i18n_scope |
||||
:activerecord |
||||
end |
||||
|
||||
def self.error_key_mapper(key) |
||||
{ subject: :title }[key] || key |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,110 @@ |
||||
#-- encoding: UTF-8 |
||||
|
||||
#-- 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. |
||||
#++ |
||||
|
||||
module Bcf::API::V2_1 |
||||
module ProjectExtensions |
||||
class Definitions |
||||
def initialize(project:, user:) |
||||
@project = project |
||||
@user = user |
||||
end |
||||
|
||||
def topic_type |
||||
project.types.pluck(:name) |
||||
end |
||||
|
||||
## |
||||
# We only return the default status for now |
||||
# since that can always be set to a new issue |
||||
def topic_status |
||||
Status |
||||
.where_default |
||||
.pluck(:name) |
||||
end |
||||
|
||||
def priority |
||||
OpenProject::Cache.fetch(IssuePriority.all.cache_key, 'names') do |
||||
IssuePriority.all.pluck(:name) |
||||
end |
||||
end |
||||
|
||||
def user_id_type |
||||
if allowed?(:view_members) |
||||
project.possible_assignees.pluck(:mail) |
||||
else |
||||
[] |
||||
end |
||||
end |
||||
|
||||
# TODO: Labels do not yet exist |
||||
def topic_label |
||||
[] |
||||
end |
||||
|
||||
# TODO: Stage do not yet exist |
||||
def stage |
||||
[] |
||||
end |
||||
|
||||
# TODO: Snippet types do not exist |
||||
def snippet_type |
||||
[] |
||||
end |
||||
|
||||
def project_actions |
||||
[].tap do |actions| |
||||
actions << 'update' if allowed?(:edit_project) |
||||
actions << 'createTopic' if allowed?(:manage_bcf) |
||||
end |
||||
end |
||||
|
||||
def topic_actions |
||||
if allowed?(:manage_bcf) |
||||
%w[update updateRelatedTopics updateFiles createViewpoint] |
||||
else |
||||
[] |
||||
end |
||||
end |
||||
|
||||
def comment_actions |
||||
[] |
||||
end |
||||
|
||||
private |
||||
|
||||
attr_reader :project, :user |
||||
|
||||
def allowed?(permission) |
||||
user.allowed_to?(permission, project) |
||||
end |
||||
end |
||||
end |
||||
end |
||||
|
@ -0,0 +1,44 @@ |
||||
#-- encoding: UTF-8 |
||||
|
||||
#-- 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. |
||||
#++ |
||||
|
||||
module Bcf::API::V2_1 |
||||
class ProjectExtensions::Representer < BaseRepresenter |
||||
property :topic_type |
||||
property :topic_status |
||||
property :topic_label |
||||
property :snippet_type |
||||
property :priority |
||||
property :user_id_type |
||||
property :stage |
||||
property :project_actions |
||||
property :topic_actions |
||||
property :comment_actions |
||||
end |
||||
end |
@ -0,0 +1,51 @@ |
||||
#-- encoding: UTF-8 |
||||
|
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2019 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. |
||||
#++ |
||||
|
||||
module Bcf::Issues |
||||
class CreateService < ::BaseServices::Create |
||||
private |
||||
|
||||
def before_perform(params) |
||||
wp_call = WorkPackages::CreateService |
||||
.new(user: user) |
||||
.call(params) |
||||
|
||||
if wp_call.success? |
||||
issue_params = { |
||||
work_package: wp_call.result |
||||
}.merge(params.slice(:stage, :labels, :index)) |
||||
|
||||
super(issue_params) |
||||
else |
||||
wp_call |
||||
end |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,34 @@ |
||||
#-- encoding: UTF-8 |
||||
|
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2019 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. |
||||
#++ |
||||
|
||||
module Bcf::Issues |
||||
class SetAttributesService < ::BaseServices::SetAttributes |
||||
end |
||||
end |
@ -0,0 +1,162 @@ |
||||
#-- encoding: UTF-8 |
||||
|
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2019 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. |
||||
#++ |
||||
|
||||
module Bcf::Issues |
||||
class TransformAttributesService |
||||
def call(attributes) |
||||
ServiceResult.new success: true, |
||||
result: work_package_attributes(attributes) |
||||
end |
||||
|
||||
private |
||||
|
||||
## |
||||
# BCF issues might have empty titles. OP needs one. |
||||
def title(attributes) |
||||
if attributes[:title] |
||||
attributes[:title] |
||||
elsif attributes[:import_options] |
||||
'(Imported BCF issue contained no title)' |
||||
end |
||||
end |
||||
|
||||
def author(project, attributes) |
||||
find_user_in_project(project, attributes[:author]) || User.system |
||||
end |
||||
|
||||
def assignee(project, attributes) |
||||
assignee = find_user_in_project(project, attributes[:assignee]) |
||||
|
||||
return assignee if assignee.present? |
||||
|
||||
missing_assignee(attributes[:assignee], attributes[:import_options] || {}) |
||||
end |
||||
|
||||
## |
||||
# Try to find the given user by mail in the project |
||||
def find_user_in_project(project, mail) |
||||
project.users.find_by(mail: mail) |
||||
end |
||||
|
||||
def type(project, attributes) |
||||
type_name = attributes[:type] |
||||
type = project.types.find_by(name: type_name) |
||||
|
||||
return type if type.present? |
||||
|
||||
missing_type(project, type_name, attributes[:import_options] || {}) |
||||
end |
||||
|
||||
## |
||||
# Handle unknown statuses during import |
||||
def status(attributes) |
||||
status_name = attributes[:status] |
||||
status = ::Status.find_by(name: status_name) |
||||
|
||||
return status if status.present? |
||||
|
||||
missing_status(status_name, attributes[:import_options] || {}) |
||||
end |
||||
|
||||
## |
||||
# Handle unknown priorities during import |
||||
def priority(attributes) |
||||
priority_name = attributes[:priority] |
||||
priority = ::IssuePriority.find_by(name: priority_name) |
||||
|
||||
return priority if priority.present? |
||||
|
||||
missing_priority(priority_name, attributes[:import_options] || {}) |
||||
end |
||||
|
||||
## |
||||
# Get mapped and raw attributes from MarkupExtractor |
||||
# and return all values that are non-nil |
||||
def work_package_attributes(attributes) |
||||
project = Project.find(attributes[:project_id]) |
||||
|
||||
{ |
||||
# Fixed attributes we know |
||||
project: project, |
||||
type: type(project, attributes), |
||||
|
||||
# Native attributes from the extractor |
||||
subject: title(attributes), |
||||
description: attributes[:description], |
||||
due_date: attributes[:due_date], |
||||
start_date: attributes[:start_date], |
||||
|
||||
# Mapped attributes |
||||
assigned_to: assignee(project, attributes), |
||||
status: status(attributes), |
||||
priority: priority(attributes) |
||||
}.compact |
||||
end |
||||
|
||||
def missing_status(status_name, import_options) |
||||
if import_options[:unknown_statuses_action] == 'use_default' |
||||
::Status.default |
||||
elsif import_options[:unknown_statuses_action] == 'chose' && |
||||
import_options[:unknown_statuses_chose_ids].any? |
||||
::Status.find_by(id: import_options[:unknown_statuses_chose_ids].first) |
||||
elsif status_name |
||||
Status::InexistentStatus.new |
||||
end |
||||
end |
||||
|
||||
def missing_priority(priority_name, import_options) |
||||
if import_options[:unknown_priorities_action] == 'use_default' |
||||
# NOP The 'use_default' case gets already covered by OP. |
||||
elsif import_options[:unknown_priorities_action] == 'chose' && |
||||
import_options[:unknown_priorities_chose_ids].any? |
||||
::IssuePriority.find_by(id: import_options[:unknown_priorities_chose_ids].first) |
||||
elsif priority_name |
||||
Priority::InexistentPriority.new |
||||
end |
||||
end |
||||
|
||||
def missing_type(project, type_name, import_options) |
||||
if import_options[:unknown_types_action] == 'use_default' |
||||
project.types.default&.first |
||||
elsif import_options[:unknown_types_action] == 'chose' && |
||||
import_options[:unknown_types_chose_ids].any? |
||||
project.types.find_by(id: import_options[:unknown_types_chose_ids].first) |
||||
elsif type_name |
||||
Type::InexistentType.new |
||||
end |
||||
end |
||||
|
||||
def missing_assignee(assignee_name, import_options) |
||||
if import_options[:invalid_people_action] != 'anonymize' && assignee_name |
||||
User::InexistentUser.new |
||||
end |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,9 @@ |
||||
class AddIssueColumns < ActiveRecord::Migration[6.0] |
||||
def change |
||||
change_table :bcf_issues do |i| |
||||
i.string :stage |
||||
i.integer :index |
||||
i.text :labels, array: true, default: [] |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,45 @@ |
||||
#-- 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' |
||||
require_relative './shared_contract_examples' |
||||
|
||||
describe Bcf::Issues::CreateContract do |
||||
it_behaves_like 'issues contract' do |
||||
let(:issue) do |
||||
Bcf::Issue.new(uuid: issue_uuid, |
||||
work_package: issue_work_package, |
||||
stage: issue_stage, |
||||
index: issue_index, |
||||
labels: issue_labels) |
||||
end |
||||
let(:permissions) { [:manage_bcf] } |
||||
|
||||
subject(:contract) { described_class.new(issue, current_user) } |
||||
end |
||||
end |
@ -0,0 +1,129 @@ |
||||
#-- 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' |
||||
|
||||
shared_examples_for 'issues contract' do |
||||
let(:current_user) do |
||||
FactoryBot.build_stubbed(:user) |
||||
end |
||||
let!(:allowed_to) do |
||||
allow(current_user) |
||||
.to receive(:allowed_to?) do |permission, permission_project| |
||||
permissions.include?(permission) && project == permission_project |
||||
end |
||||
end |
||||
let(:issue_uuid) { 'issue uuid' } |
||||
let(:project) { FactoryBot.build_stubbed(:project) } |
||||
let(:issue_work_package) { FactoryBot.build_stubbed(:stubbed_work_package, project: project) } |
||||
let(:issue_work_package_id) do |
||||
id = 5 |
||||
|
||||
allow(WorkPackage) |
||||
.to receive(:find) |
||||
.with(id) |
||||
.and_return(issue_work_package) |
||||
|
||||
id |
||||
end |
||||
let(:issue_stage) { nil } |
||||
let(:issue_labels) { [] } |
||||
let(:issue_index) { 8 } |
||||
|
||||
before do |
||||
allow(issue) |
||||
.to receive(:project) |
||||
.and_return(project) |
||||
end |
||||
|
||||
def expect_valid(valid, symbols = {}) |
||||
expect(contract.validate).to eq(valid) |
||||
|
||||
symbols.each do |key, arr| |
||||
expect(contract.errors.symbols_for(key)).to match_array arr |
||||
end |
||||
end |
||||
|
||||
shared_examples 'is valid' do |
||||
it 'is valid' do |
||||
expect_valid(true) |
||||
end |
||||
end |
||||
|
||||
it_behaves_like 'is valid' |
||||
|
||||
context 'if the uuid is nil' do |
||||
let(:issue_uuid) { nil } |
||||
|
||||
it_behaves_like 'is valid' # as the uuid will be set |
||||
end |
||||
|
||||
context 'if the work_package_id is nil' do |
||||
let(:issue_work_package) { nil } |
||||
|
||||
it 'is invalid' do |
||||
expect_valid(false, work_package: %i(blank)) |
||||
end |
||||
end |
||||
|
||||
context 'if the user lacks permission' do |
||||
let(:permissions) { [] } |
||||
|
||||
it 'is invalid' do |
||||
expect_valid(false, base: %i(error_unauthorized)) |
||||
end |
||||
end |
||||
|
||||
context 'if the stage is nil' do |
||||
let(:issue_stage) { nil } |
||||
|
||||
it_behaves_like 'is valid' |
||||
end |
||||
|
||||
context 'if the stage is written' do |
||||
let(:issue_stage) { 'some stage' } |
||||
|
||||
it 'is invalid' do |
||||
expect_valid(false, stage: %i(error_readonly)) |
||||
end |
||||
end |
||||
|
||||
context 'if labels is written' do |
||||
let(:issue_labels) { %w(some labels) } |
||||
|
||||
it 'is invalid' do |
||||
expect_valid(false, labels: %i(error_readonly)) |
||||
end |
||||
end |
||||
|
||||
context 'if index is nil' do |
||||
let(:issue_index) { nil } |
||||
|
||||
it_behaves_like 'is valid' |
||||
end |
||||
end |
@ -0,0 +1,135 @@ |
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2019 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' |
||||
|
||||
require_relative '../shared_examples' |
||||
|
||||
describe Bcf::API::V2_1::ProjectExtensions::Definitions, 'rendering' do |
||||
shared_let(:type_task) { FactoryBot.create :type_task, name: 'My BCF type' } |
||||
shared_let(:project) { FactoryBot.create(:project, types: [type_task]) } |
||||
let(:user) { FactoryBot.build_stubbed(:user) } |
||||
let(:instance) { described_class.new(project: project, user: user) } |
||||
|
||||
describe '#topic_type' do |
||||
subject { instance.topic_type } |
||||
|
||||
it 'returns the project type names' do |
||||
expect(subject).to eq ['My BCF type'] |
||||
end |
||||
end |
||||
|
||||
describe '#topic_status' do |
||||
let!(:default_status) { FactoryBot.create :default_status } |
||||
let!(:status) { FactoryBot.create :status } |
||||
subject { instance.topic_status } |
||||
|
||||
it 'returns default status only' do |
||||
expect(subject).to eq [default_status.name] |
||||
end |
||||
end |
||||
|
||||
describe '#priority' do |
||||
let!(:priority) { FactoryBot.create :default_priority } |
||||
subject { instance.priority } |
||||
|
||||
it 'returns statuses for the available types' do |
||||
expect(subject).to eq [priority.name] |
||||
end |
||||
end |
||||
|
||||
describe '#user_id_type' do |
||||
let!(:other_user) do |
||||
FactoryBot.create(:user, |
||||
member_in_project: project, |
||||
member_with_permissions: [:view_work_packages]) |
||||
end |
||||
subject { instance.user_id_type } |
||||
|
||||
before do |
||||
allow(user) |
||||
.to receive(:allowed_to?).with(:view_members, project) |
||||
.and_return is_permitted |
||||
end |
||||
|
||||
context 'with permissions' do |
||||
let(:is_permitted) { true } |
||||
|
||||
it 'returns the user as assignee' do |
||||
expect(subject).to eq [other_user.mail] |
||||
end |
||||
end |
||||
|
||||
context 'with no permissions' do |
||||
let(:is_permitted) { false } |
||||
|
||||
it 'returns nothing' do |
||||
expect(subject).to eq [] |
||||
end |
||||
end |
||||
end |
||||
|
||||
describe '#project_actions' do |
||||
subject { instance.project_actions } |
||||
|
||||
it 'includes nothing if not permitted' do |
||||
allow(user).to receive(:allowed_to?).and_return false |
||||
expect(subject).to be_empty |
||||
end |
||||
|
||||
it 'includes `update` if edit_project permission' do |
||||
allow(user).to receive(:allowed_to?).and_return false |
||||
allow(user).to receive(:allowed_to?).with(:edit_project, project).and_return true |
||||
|
||||
expect(subject).to include 'update' |
||||
end |
||||
|
||||
it 'includes `createTopic` if edit_project permission' do |
||||
allow(user).to receive(:allowed_to?).and_return false |
||||
allow(user).to receive(:allowed_to?).with(:manage_bcf, project).and_return true |
||||
|
||||
expect(subject).to include 'createTopic' |
||||
end |
||||
end |
||||
|
||||
describe '#topic_actions' do |
||||
subject { instance.topic_actions } |
||||
|
||||
it 'includes nothing if not permitted' do |
||||
allow(user).to receive(:allowed_to?).and_return false |
||||
expect(subject).to be_empty |
||||
end |
||||
|
||||
it 'includes `update` if manage_bcf permission' do |
||||
allow(user).to receive(:allowed_to?).and_return false |
||||
allow(user).to receive(:allowed_to?).with(:manage_bcf, project).and_return true |
||||
|
||||
expect(subject).to match_array %w[update updateRelatedTopics updateFiles createViewpoint] |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,116 @@ |
||||
#-- copyright |
||||
# OpenProject is a project management system. |
||||
# Copyright (C) 2012-2019 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' |
||||
require 'rack/test' |
||||
|
||||
require_relative './shared_responses' |
||||
|
||||
describe 'BCF 2.1 project extensions resource', type: :request, content_type: :json do |
||||
include Rack::Test::Methods |
||||
shared_let(:type_task) { FactoryBot.create :type_task } |
||||
shared_let(:status) { FactoryBot.create :default_status } |
||||
shared_let(:priority) { FactoryBot.create :default_priority } |
||||
shared_let(:project) { FactoryBot.create(:project, enabled_module_names: [:bcf], types: [type_task]) } |
||||
subject(:response) { last_response } |
||||
|
||||
let(:path) { "/api/bcf/2.1/projects/#{project.id}/extensions" } |
||||
|
||||
context 'with only view_project permissions' do |
||||
let(:current_user) do |
||||
FactoryBot.create(:user, |
||||
member_in_project: project, |
||||
member_with_permissions: [:view_project]) |
||||
end |
||||
|
||||
before do |
||||
login_as(current_user) |
||||
get path |
||||
end |
||||
|
||||
it_behaves_like 'bcf api successful response' do |
||||
let(:expected_body) do |
||||
{ |
||||
topic_type: [type_task.name], |
||||
topic_status: [status.name], |
||||
priority: [priority.name], |
||||
snippet_type: [], |
||||
stage: [], |
||||
topic_label: [], |
||||
user_id_type: [], |
||||
project_actions: [], |
||||
topic_actions: [], |
||||
comment_actions: [] |
||||
} |
||||
end |
||||
end |
||||
end |
||||
|
||||
context 'with edit permissions in project' do |
||||
let(:current_user) do |
||||
FactoryBot.create(:user, |
||||
member_in_project: project, |
||||
member_with_permissions: [:view_project, :edit_project, :manage_bcf, :view_members]) |
||||
end |
||||
|
||||
let(:other_user) { |
||||
FactoryBot.create(:user, |
||||
member_in_project: project, |
||||
member_with_permissions: [:view_project]) |
||||
} |
||||
|
||||
before do |
||||
other_user |
||||
login_as(current_user) |
||||
get path |
||||
end |
||||
|
||||
it_behaves_like 'bcf api successful response expectation' do |
||||
let(:expectations) do |
||||
->(body) { |
||||
hash = JSON.parse(body) |
||||
|
||||
expect(hash.keys).to match_array %w[ |
||||
topic_type topic_status user_id_type project_actions topic_actions comment_actions |
||||
stage snippet_type priority topic_label |
||||
] |
||||
|
||||
expect(hash['topic_type']).to include type_task.name |
||||
expect(hash['topic_status']).to include status.name |
||||
|
||||
expect(hash['user_id_type']).to include(other_user.mail, current_user.mail) |
||||
|
||||
expect(hash['project_actions']).to eq %w[update createTopic] |
||||
|
||||
expect(hash['topic_actions']).to eq %w[update updateRelatedTopics updateFiles createViewpoint] |
||||
expect(hash['comment_actions']).to eq [] |
||||
} |
||||
end |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,173 @@ |
||||
#-- encoding: UTF-8 |
||||
|
||||
#-- 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 Bcf::Issues::CreateService, type: :model do |
||||
let(:user) { FactoryBot.build_stubbed(:user) } |
||||
let(:contract_class) do |
||||
double('contract_class', '<=': true) |
||||
end |
||||
let(:issue_valid) { true } |
||||
let(:instance) do |
||||
described_class.new(user: user, |
||||
contract_class: contract_class) |
||||
end |
||||
let(:call_attributes) { { subject: 'Some name' } } |
||||
let(:set_attributes_success) do |
||||
true |
||||
end |
||||
let(:set_attributes_errors) do |
||||
double('set_attributes_errors') |
||||
end |
||||
let(:set_attributes_result) do |
||||
ServiceResult.new result: created_issue, |
||||
success: set_attributes_success, |
||||
errors: set_attributes_errors |
||||
end |
||||
let!(:created_work_package) do |
||||
FactoryBot.build_stubbed(:work_package) |
||||
end |
||||
let(:wp_create_errors) do |
||||
double('wp_create_errors') |
||||
end |
||||
let(:wp_create_result) do |
||||
ServiceResult.new result: created_work_package, |
||||
success: true, |
||||
errors: wp_create_errors |
||||
end |
||||
let!(:wp_create_service) do |
||||
wp_service = double('wp create service') |
||||
|
||||
allow(WorkPackages::CreateService) |
||||
.to receive(:new) |
||||
.with(user: user) |
||||
.and_return(wp_service) |
||||
|
||||
allow(wp_service) |
||||
.to receive(:call) |
||||
.and_return(wp_create_result) |
||||
|
||||
wp_service |
||||
end |
||||
let!(:created_issue) do |
||||
issue = FactoryBot.build_stubbed(:bcf_issue) |
||||
|
||||
allow(Bcf::Issue) |
||||
.to receive(:new) |
||||
.and_return(issue) |
||||
|
||||
allow(issue) |
||||
.to receive(:save) |
||||
.and_return(issue_valid) |
||||
|
||||
issue |
||||
end |
||||
let!(:set_attributes_service) do |
||||
service = double('set_attributes_service_instance') |
||||
|
||||
allow(Bcf::Issues::SetAttributesService) |
||||
.to receive(:new) |
||||
.with(user: user, |
||||
model: created_issue, |
||||
contract_class: contract_class) |
||||
.and_return(service) |
||||
|
||||
allow(service) |
||||
.to receive(:call) |
||||
.and_return(set_attributes_result) |
||||
end |
||||
|
||||
describe '#call' do |
||||
subject { instance.call(call_attributes) } |
||||
|
||||
it 'is successful' do |
||||
expect(subject.success?).to be_truthy |
||||
end |
||||
|
||||
it 'returns the result of the SetAttributesService' do |
||||
expect(subject) |
||||
.to eql set_attributes_result |
||||
end |
||||
|
||||
it 'persists the issue' do |
||||
expect(created_issue) |
||||
.to receive(:save) |
||||
.and_return(issue_valid) |
||||
|
||||
subject |
||||
end |
||||
|
||||
it 'creates a issue' do |
||||
expect(subject.result) |
||||
.to eql created_issue |
||||
end |
||||
|
||||
context 'if the SetAttributeService is unsuccessful' do |
||||
let(:set_attributes_success) { false } |
||||
|
||||
it 'is unsuccessful' do |
||||
expect(subject.success?).to be_falsey |
||||
end |
||||
|
||||
it 'returns the result of the SetAttributesService' do |
||||
expect(subject) |
||||
.to eql set_attributes_result |
||||
end |
||||
|
||||
it 'does not persist the changes' do |
||||
expect(created_issue) |
||||
.to_not receive(:save) |
||||
|
||||
subject |
||||
end |
||||
|
||||
it "exposes the contract's errors" do |
||||
subject |
||||
|
||||
expect(subject.errors).to eql set_attributes_errors |
||||
end |
||||
end |
||||
|
||||
context 'when the issue is invalid' do |
||||
let(:issue_valid) { false } |
||||
|
||||
it 'is unsuccessful' do |
||||
expect(subject.success?).to be_falsey |
||||
end |
||||
|
||||
it "exposes the issue's errors" do |
||||
subject |
||||
|
||||
expect(subject.errors).to eql created_issue.errors |
||||
end |
||||
end |
||||
end |
||||
end |
@ -1,5 +1,5 @@ |
||||
tr: |
||||
dashboards: |
||||
label: 'Gösterge tabloları' |
||||
label: 'Gösterge panosu' |
||||
menu_badge: 'Alfa' |
||||
project_module_dashboards: 'Gösterge tabloları' |
||||
project_module_dashboards: 'Gösterge panosu' |
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue