[#38833] BCF API Comments Service
- https://community.openproject.org/work_packages/38833 - added requests tests - added check for expected body length - added representer and api for bcf_comments - added create and set attributes service for bcf_comments - added migration for comment hierarchy - added create and update service for journalspull/9684/head
parent
23a8bef352
commit
d6b87a2210
@ -0,0 +1,43 @@ |
||||
#-- 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 Journals |
||||
class UpdateContract < BaseContract |
||||
attribute :notes |
||||
|
||||
validate :user_allowed_to_edit |
||||
|
||||
private |
||||
|
||||
def user_allowed_to_edit |
||||
errors.add(:base, :error_unauthorized) unless model.editable_by?(user) |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,33 @@ |
||||
#-- 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 Journals |
||||
class SetAttributesService < ::BaseServices::SetAttributes; end |
||||
end |
@ -0,0 +1,33 @@ |
||||
#-- 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 Journals |
||||
class UpdateService < ::BaseServices::Update; end |
||||
end |
@ -0,0 +1,6 @@ |
||||
class AddBcfCommentHierarchy < ActiveRecord::Migration[6.1] |
||||
def change |
||||
add_column :bcf_comments, :reply_to, :bigint, default: nil, null: true |
||||
add_foreign_key :bcf_comments, :bcf_comments, column: :reply_to, on_delete: :nullify |
||||
end |
||||
end |
@ -0,0 +1,39 @@ |
||||
#-- 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 API |
||||
module V3 |
||||
module Activities |
||||
class ActivityPayloadRepresenter < ::API::V3::Activities::ActivityRepresenter |
||||
include API::Utilities::PayloadRepresenter |
||||
end |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,61 @@ |
||||
#-- 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 Bim::Bcf |
||||
module Comments |
||||
class CreateContract < BaseContract |
||||
attribute :journal |
||||
attribute :issue |
||||
attribute :viewpoint |
||||
attribute :reply_to |
||||
|
||||
validate :user_allowed_to_create |
||||
validate :validate_journal |
||||
validate :validate_viewpoint_reference |
||||
validate :validate_reply_to_comment |
||||
|
||||
private |
||||
|
||||
def user_allowed_to_create |
||||
errors.add :base, :error_unauthorized unless @user.allowed_to?(:manage_bcf, model.issue.work_package.project) |
||||
end |
||||
|
||||
def validate_journal |
||||
errors.add(:base, :invalid) if model.journal.journable != model.issue.work_package |
||||
end |
||||
|
||||
def validate_viewpoint_reference |
||||
errors.add(:viewpoint, :does_not_exist) if model.viewpoint.is_a?(::Bim::Bcf::NonExistentViewpoint) |
||||
end |
||||
|
||||
def validate_reply_to_comment |
||||
errors.add(:bcf_comment, :does_not_exist) if model.reply_to.is_a?(::Bim::Bcf::NonExistentComment) |
||||
end |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,54 @@ |
||||
#-- 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 Bim::Bcf |
||||
module Comments |
||||
class UpdateContract < BaseContract |
||||
attribute :viewpoint |
||||
attribute :reply_to |
||||
|
||||
validate :user_allowed_to_update |
||||
validate :validate_viewpoint_reference |
||||
validate :validate_reply_to_comment |
||||
|
||||
private |
||||
|
||||
def user_allowed_to_update |
||||
errors.add :base, :error_unauthorized unless @user.allowed_to?(:manage_bcf, model.issue.work_package.project) |
||||
end |
||||
|
||||
def validate_viewpoint_reference |
||||
errors.add(:viewpoint, :does_not_exist) if model.viewpoint.is_a?(::Bim::Bcf::NonExistentViewpoint) |
||||
end |
||||
|
||||
def validate_reply_to_comment |
||||
errors.add(:bcf_comment, :does_not_exist) if model.reply_to.is_a?(::Bim::Bcf::NonExistentComment) |
||||
end |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,102 @@ |
||||
#-- 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 Bim::Bcf::API::V2_1 |
||||
module Comments |
||||
class API < ::API::OpenProjectAPI |
||||
resources :comments do |
||||
helpers do |
||||
def all_comments |
||||
@issue.comments.includes(:journal, :issue, :viewpoint) |
||||
end |
||||
|
||||
def transform_create_parameter(params) |
||||
viewpoint = if params[:viewpoint_guid] == nil |
||||
nil |
||||
else |
||||
@issue.viewpoints |
||||
.find_by(uuid: params[:viewpoint_guid]) || ::Bim::Bcf::NonExistentViewpoint.new |
||||
end |
||||
replied_comment = if params[:reply_to_comment_guid] == nil |
||||
nil |
||||
else |
||||
@issue.comments |
||||
.find_by(uuid: params[:reply_to_comment_guid]) || ::Bim::Bcf::NonExistentComment.new |
||||
end |
||||
{ |
||||
issue: @issue, |
||||
viewpoint: viewpoint, |
||||
reply_to: replied_comment |
||||
} |
||||
end |
||||
|
||||
def transform_update_parameter(params) |
||||
viewpoint = if params[:viewpoint_guid] == nil |
||||
nil |
||||
else |
||||
@issue.viewpoints |
||||
.find_by(uuid: params[:viewpoint_guid]) || ::Bim::Bcf::NonExistentViewpoint.new |
||||
end |
||||
replied_comment = if params[:reply_to_comment_guid] == nil |
||||
nil |
||||
else |
||||
@issue.comments |
||||
.find_by(uuid: params[:reply_to_comment_guid]) || ::Bim::Bcf::NonExistentComment.new |
||||
end |
||||
|
||||
{ |
||||
original_comment: @comment, |
||||
viewpoint: viewpoint, |
||||
reply_to: replied_comment |
||||
} |
||||
end |
||||
end |
||||
|
||||
get &::Bim::Bcf::API::V2_1::Endpoints::Index.new(model: Bim::Bcf::Comment, scope: -> { all_comments }).mount |
||||
|
||||
post &::Bim::Bcf::API::V2_1::Endpoints::Create |
||||
.new(model: Bim::Bcf::Comment, |
||||
params_modifier: ->(params) { transform_create_parameter(params).merge(params) }) |
||||
.mount |
||||
|
||||
route_param :comment_guid, regexp: /\A[a-f0-9\-]+\z/ do |
||||
after_validation do |
||||
@comment = all_comments.find_by!(uuid: params[:comment_guid]) |
||||
end |
||||
|
||||
get &::Bim::Bcf::API::V2_1::Endpoints::Show.new(model: Bim::Bcf::Comment).mount |
||||
|
||||
put &::Bim::Bcf::API::V2_1::Endpoints::Update |
||||
.new(model: Bim::Bcf::Comment, |
||||
params_modifier: ->(params) { transform_update_parameter(params).merge(params) }) |
||||
.mount |
||||
end |
||||
end |
||||
end |
||||
end |
||||
end |
@ -1,18 +1,50 @@ |
||||
#-- 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 Bim::Bcf |
||||
class Comment < ActiveRecord::Base |
||||
self.table_name = :bcf_comments |
||||
|
||||
include InitializeWithUuid |
||||
|
||||
CREATE_ATTRIBUTES = %i[journal issue viewpoint reply_to].freeze |
||||
UPDATE_ATTRIBUTES = %i[viewpoint reply_to].freeze |
||||
|
||||
belongs_to :journal |
||||
belongs_to :issue, foreign_key: :issue_id, class_name: "Bim::Bcf::Issue" |
||||
belongs_to :viewpoint, foreign_key: :viewpoint_id, class_name: "Bim::Bcf::Viewpoint", optional: true |
||||
belongs_to :reply_to, foreign_key: :reply_to, class_name: "Bim::Bcf::Comment", optional: true |
||||
|
||||
validates_presence_of :uuid |
||||
validates_uniqueness_of :uuid, scope: [:issue_id] |
||||
|
||||
def self.has_uuid?(uuid, issue_id) |
||||
where(uuid: uuid, issue_id: issue_id).exists? |
||||
exists?(uuid: uuid, issue_id: issue_id) |
||||
end |
||||
end |
||||
end |
||||
|
@ -0,0 +1,4 @@ |
||||
module Bim::Bcf |
||||
class NonExistentComment < Comment |
||||
end |
||||
end |
@ -0,0 +1,4 @@ |
||||
module Bim::Bcf |
||||
class NonExistentViewpoint < Viewpoint |
||||
end |
||||
end |
@ -0,0 +1,46 @@ |
||||
#-- 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. |
||||
#++ |
||||
|
||||
# rubocop:disable Naming/ClassAndModuleCamelCase |
||||
module Bim::Bcf::API::V2_1 |
||||
# rubocop:enable Naming/ClassAndModuleCamelCase |
||||
class Comments::AuthorizationRepresenter < BaseRepresenter |
||||
property :comment_actions, |
||||
getter: ->(decorator:, **) { |
||||
if decorator.manage_bcf_allowed? |
||||
%w[update] |
||||
else |
||||
[] |
||||
end |
||||
} |
||||
|
||||
def manage_bcf_allowed? |
||||
represented.user.allowed_to?(:manage_bcf, represented.model.project) |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,88 @@ |
||||
#-- 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. |
||||
#++ |
||||
|
||||
# rubocop:disable Naming/ClassAndModuleCamelCase |
||||
module Bim::Bcf::API::V2_1 |
||||
# rubocop:enable Naming/ClassAndModuleCamelCase |
||||
class Comments::SingleRepresenter < BaseRepresenter |
||||
include API::Decorators::DateProperty |
||||
|
||||
property :uuid, |
||||
as: :guid |
||||
|
||||
property :date, |
||||
getter: ->(represented:, decorator:, **) { |
||||
decorator.datetime_formatter.format_datetime(represented.journal.created_at, allow_nil: true) |
||||
} |
||||
|
||||
property :author, |
||||
getter: ->(represented:, **) { |
||||
represented.journal.user.mail |
||||
} |
||||
|
||||
property :comment, |
||||
getter: ->(represented:, **) { |
||||
represented.journal.notes |
||||
} |
||||
|
||||
property :topic_guid, |
||||
getter: ->(represented:, **) { |
||||
represented.issue.uuid |
||||
} |
||||
|
||||
# not required properties |
||||
property :viewpoint_guid, |
||||
getter: ->(represented:, **) { |
||||
represented.viewpoint&.uuid |
||||
} |
||||
|
||||
property :reply_to_comment_guid, |
||||
getter: ->(represented:, **) { |
||||
represented.reply_to&.uuid |
||||
} |
||||
|
||||
property :modified_date, |
||||
getter: ->(represented:, decorator:, **) { |
||||
decorator.datetime_formatter.format_datetime(represented.journal.updated_at, allow_nil: true) |
||||
} |
||||
|
||||
# we do not store the author when editing a journal, hence the "modified author" is the same as the creator |
||||
property :modified_author, |
||||
getter: ->(represented:, **) { |
||||
represented.journal.user.mail |
||||
} |
||||
|
||||
property :authorization, |
||||
getter: ->(represented:, **) { |
||||
contract = WorkPackages::UpdateContract.new(represented.issue.work_package, User.current) |
||||
Comments::AuthorizationRepresenter.new(contract) |
||||
} |
||||
end |
||||
end |
@ -0,0 +1,52 @@ |
||||
#-- 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 Bim::Bcf |
||||
module Comments |
||||
class CreateService < ::BaseServices::Create |
||||
private |
||||
|
||||
def before_perform(params) |
||||
journal_call = create_journal(params[:issue].work_package, |
||||
params[:comment]) |
||||
return journal_call if journal_call.failure? |
||||
|
||||
input = { journal: journal_call.result } |
||||
.merge(params) |
||||
.slice(*::Bim::Bcf::Comment::CREATE_ATTRIBUTES) |
||||
super input |
||||
end |
||||
|
||||
def create_journal(work_package, comment) |
||||
::Journals::CreateService.new(work_package, user).call(notes: comment) |
||||
end |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,36 @@ |
||||
#-- 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 Bim::Bcf |
||||
module Comments |
||||
class SetAttributesService < ::BaseServices::SetAttributes |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,49 @@ |
||||
#-- 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 Bim::Bcf |
||||
module Comments |
||||
class UpdateService < ::BaseServices::Update |
||||
private |
||||
|
||||
def before_perform(params) |
||||
journal_call = update_journal(params[:original_comment].journal, params[:comment]) |
||||
return journal_call if journal_call.failure? |
||||
|
||||
super params.slice(*::Bim::Bcf::Comment::UPDATE_ATTRIBUTES) |
||||
end |
||||
|
||||
def update_journal(journal, comment) |
||||
::Journals::UpdateService.new(user: user, |
||||
model: journal, |
||||
contract_class: ::EmptyContract) |
||||
.call(notes: comment) |
||||
end |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,611 @@ |
||||
#-- 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' |
||||
require 'rack/test' |
||||
|
||||
require_relative './shared_responses' |
||||
|
||||
describe 'BCF 2.1 comments resource', type: :request, content_type: :json, with_mail: false do |
||||
include Rack::Test::Methods |
||||
include API::V3::Utilities::PathHelper |
||||
|
||||
let(:project) do |
||||
FactoryBot.create(:project, enabled_module_names: %i[bim work_package_tracking]) |
||||
end |
||||
|
||||
let(:view_only_user) do |
||||
FactoryBot.create(:user, |
||||
member_in_project: project, |
||||
member_with_permissions: %i[view_linked_issues view_work_packages]) |
||||
end |
||||
|
||||
let(:edit_user) do |
||||
FactoryBot.create(:user, |
||||
member_in_project: project, |
||||
member_with_permissions: %i[view_linked_issues view_work_packages manage_bcf]) |
||||
end |
||||
|
||||
let(:user_without_permission) { FactoryBot.create(:user, member_in_project: project) } |
||||
|
||||
let(:assignee) { FactoryBot.create(:user) } |
||||
|
||||
let(:work_package) do |
||||
FactoryBot.create(:work_package, assigned_to: assignee, due_date: Date.today, project: project) |
||||
end |
||||
|
||||
let(:bcf_issue) { FactoryBot.create(:bcf_issue_with_viewpoint, work_package: work_package) } |
||||
let(:viewpoint) { bcf_issue.viewpoints.first } |
||||
|
||||
let(:bcf_comment) { FactoryBot.create(:bcf_comment, issue: bcf_issue, author: view_only_user) } |
||||
let(:bcf_answer) { FactoryBot.create(:bcf_comment, issue: bcf_issue, reply_to: bcf_comment, author: assignee) } |
||||
let(:bcf_comment_to_viewpoint) do |
||||
FactoryBot.create(:bcf_comment, issue: bcf_issue, viewpoint: viewpoint, author: edit_user) |
||||
end |
||||
|
||||
subject(:response) { last_response } |
||||
|
||||
describe 'GET /api/bcf/2.1/projects/:project_id/topics/:topic_guid/comments' do |
||||
let(:path) { "/api/bcf/2.1/projects/#{project.id}/topics/#{bcf_issue.uuid}/comments" } |
||||
let(:current_user) { view_only_user } |
||||
let(:comments) { bcf_comment } |
||||
|
||||
before do |
||||
login_as(current_user) |
||||
comments |
||||
get path |
||||
end |
||||
|
||||
it_behaves_like 'bcf api successful response' do |
||||
let(:comments) { [bcf_comment, bcf_answer, bcf_comment_to_viewpoint] } |
||||
|
||||
let(:expected_body) do |
||||
[ |
||||
{ |
||||
guid: bcf_comment.uuid, |
||||
date: bcf_comment.journal.created_at, |
||||
author: view_only_user.mail, |
||||
comment: bcf_comment.journal.notes, |
||||
modified_date: bcf_comment.journal.updated_at, |
||||
modified_author: view_only_user.mail, |
||||
topic_guid: bcf_issue.uuid, |
||||
reply_to_comment_guid: nil, |
||||
viewpoint_guid: nil, |
||||
authorization: { |
||||
comment_actions: [] |
||||
} |
||||
}, |
||||
{ |
||||
guid: bcf_answer.uuid, |
||||
date: bcf_answer.journal.created_at, |
||||
author: assignee.mail, |
||||
comment: bcf_answer.journal.notes, |
||||
modified_date: bcf_answer.journal.updated_at, |
||||
modified_author: assignee.mail, |
||||
topic_guid: bcf_issue.uuid, |
||||
reply_to_comment_guid: bcf_comment.uuid, |
||||
viewpoint_guid: nil, |
||||
authorization: { |
||||
comment_actions: [] |
||||
} |
||||
}, |
||||
{ |
||||
guid: bcf_comment_to_viewpoint.uuid, |
||||
date: bcf_comment_to_viewpoint.journal.created_at, |
||||
author: edit_user.mail, |
||||
comment: bcf_comment_to_viewpoint.journal.notes, |
||||
modified_date: bcf_comment_to_viewpoint.journal.updated_at, |
||||
modified_author: edit_user.mail, |
||||
topic_guid: bcf_issue.uuid, |
||||
reply_to_comment_guid: nil, |
||||
viewpoint_guid: viewpoint.uuid, |
||||
authorization: { |
||||
comment_actions: [] |
||||
} |
||||
} |
||||
] |
||||
end |
||||
end |
||||
|
||||
context 'with edit comments permission' do |
||||
let(:current_user) { edit_user } |
||||
|
||||
it_behaves_like 'bcf api successful response' do |
||||
let(:expected_body) do |
||||
[ |
||||
{ |
||||
guid: bcf_comment.uuid, |
||||
date: bcf_comment.journal.created_at, |
||||
author: view_only_user.mail, |
||||
comment: bcf_comment.journal.notes, |
||||
modified_date: bcf_comment.journal.updated_at, |
||||
modified_author: view_only_user.mail, |
||||
topic_guid: bcf_issue.uuid, |
||||
reply_to_comment_guid: nil, |
||||
viewpoint_guid: nil, |
||||
authorization: { |
||||
comment_actions: [ |
||||
"update" |
||||
] |
||||
} |
||||
} |
||||
] |
||||
end |
||||
end |
||||
end |
||||
|
||||
context 'without view permissions' do |
||||
let(:current_user) { user_without_permission } |
||||
|
||||
it_behaves_like 'bcf api not allowed response' |
||||
end |
||||
end |
||||
|
||||
describe 'POST /api/bcf/2.1/projects/:project_id/topics/:topic_guid/comments' do |
||||
let(:path) { "/api/bcf/2.1/projects/#{project.id}/topics/#{bcf_issue.uuid}/comments" } |
||||
let(:current_user) { edit_user } |
||||
let(:params) do |
||||
{ |
||||
comment: "this is a new bcf comment" |
||||
} |
||||
end |
||||
|
||||
before do |
||||
login_as(current_user) |
||||
post path, params.to_json |
||||
end |
||||
|
||||
it_behaves_like 'bcf api successful response' do |
||||
let(:expected_status) { 201 } |
||||
let(:expected_body) do |
||||
comment = Bim::Bcf::Comment.last.reload |
||||
creation_date = comment&.journal&.created_at&.iso8601 |
||||
|
||||
{ |
||||
guid: comment&.uuid, |
||||
date: creation_date, |
||||
author: edit_user.mail, |
||||
comment: "this is a new bcf comment", |
||||
modified_date: creation_date, |
||||
modified_author: edit_user.mail, |
||||
topic_guid: bcf_issue.uuid, |
||||
reply_to_comment_guid: nil, |
||||
viewpoint_guid: nil, |
||||
authorization: { |
||||
comment_actions: [ |
||||
"update" |
||||
] |
||||
} |
||||
} |
||||
end |
||||
end |
||||
|
||||
context 'if user has no permission to write comments' do |
||||
let(:current_user) { view_only_user } |
||||
|
||||
it_behaves_like 'bcf api not allowed response' |
||||
end |
||||
|
||||
context 'if request contains viewpoint guid' do |
||||
let(:params) do |
||||
{ |
||||
comment: "this is a comment to a specific viewpoint", |
||||
viewpoint_guid: viewpoint.uuid |
||||
} |
||||
end |
||||
|
||||
it_behaves_like 'bcf api successful response' do |
||||
let(:expected_status) { 201 } |
||||
let(:expected_body) do |
||||
comment = Bim::Bcf::Comment.last.reload |
||||
creation_date = comment&.journal&.created_at&.iso8601 |
||||
|
||||
{ |
||||
guid: comment&.uuid, |
||||
date: creation_date, |
||||
author: edit_user.mail, |
||||
comment: "this is a comment to a specific viewpoint", |
||||
modified_date: creation_date, |
||||
modified_author: edit_user.mail, |
||||
topic_guid: bcf_issue.uuid, |
||||
reply_to_comment_guid: nil, |
||||
viewpoint_guid: viewpoint.uuid, |
||||
authorization: { |
||||
comment_actions: [ |
||||
"update" |
||||
] |
||||
} |
||||
} |
||||
end |
||||
end |
||||
|
||||
context 'if the viewpoint guid does not exist' do |
||||
let(:params) do |
||||
{ |
||||
comment: "this is a comment to a specific viewpoint", |
||||
viewpoint_guid: "00000000-0000-0000-0000-000000000000" |
||||
} |
||||
end |
||||
|
||||
it_behaves_like 'bcf api unprocessable response' do |
||||
let(:message) { 'Viewpoint does not exist.' } |
||||
end |
||||
end |
||||
end |
||||
|
||||
context 'if request contains reply comment' do |
||||
let(:params) do |
||||
{ |
||||
comment: "this is a reply comment to another comment", |
||||
reply_to_comment_guid: bcf_comment.uuid |
||||
} |
||||
end |
||||
|
||||
it_behaves_like 'bcf api successful response' do |
||||
let(:expected_status) { 201 } |
||||
let(:expected_body) do |
||||
comment = Bim::Bcf::Comment.last.reload |
||||
creation_date = comment&.journal&.created_at&.iso8601 |
||||
|
||||
{ |
||||
guid: comment&.uuid, |
||||
date: creation_date, |
||||
author: edit_user.mail, |
||||
comment: "this is a reply comment to another comment", |
||||
modified_date: creation_date, |
||||
modified_author: edit_user.mail, |
||||
topic_guid: bcf_issue.uuid, |
||||
reply_to_comment_guid: bcf_comment.uuid, |
||||
viewpoint_guid: nil, |
||||
authorization: { |
||||
comment_actions: [ |
||||
"update" |
||||
] |
||||
} |
||||
} |
||||
end |
||||
end |
||||
|
||||
context 'if the comment guid does not exist' do |
||||
let(:params) do |
||||
{ |
||||
comment: "this is a reply comment to another comment", |
||||
reply_to_comment_guid: "00000000-0000-0000-0000-000000000000" |
||||
} |
||||
end |
||||
|
||||
it_behaves_like 'bcf api unprocessable response' do |
||||
let(:message) { 'Bcf comment does not exist.' } |
||||
end |
||||
end |
||||
end |
||||
|
||||
context 'if request contains reply comment and viewpoint reference' do |
||||
let(:params) do |
||||
{ |
||||
comment: "this is a reply comment to another comment with a specific reference to a viewpoint", |
||||
reply_to_comment_guid: bcf_comment.uuid, |
||||
viewpoint_guid: viewpoint.uuid |
||||
} |
||||
end |
||||
|
||||
it_behaves_like 'bcf api successful response' do |
||||
let(:expected_status) { 201 } |
||||
let(:expected_body) do |
||||
comment = Bim::Bcf::Comment.last.reload |
||||
creation_date = comment&.journal&.created_at&.iso8601 |
||||
|
||||
{ |
||||
guid: comment&.uuid, |
||||
date: creation_date, |
||||
author: edit_user.mail, |
||||
comment: "this is a reply comment to another comment with a specific reference to a viewpoint", |
||||
modified_date: creation_date, |
||||
modified_author: edit_user.mail, |
||||
topic_guid: bcf_issue.uuid, |
||||
reply_to_comment_guid: bcf_comment.uuid, |
||||
viewpoint_guid: viewpoint.uuid, |
||||
authorization: { |
||||
comment_actions: [ |
||||
"update" |
||||
] |
||||
} |
||||
} |
||||
end |
||||
end |
||||
|
||||
context 'if the comment guid does not exist' do |
||||
let(:params) do |
||||
{ |
||||
comment: "this is a reply comment to another comment", |
||||
reply_to_comment_guid: "00000000-0000-0000-0000-000000000000", |
||||
viewpoint_guid: viewpoint.uuid |
||||
} |
||||
end |
||||
|
||||
it_behaves_like 'bcf api unprocessable response' do |
||||
let(:message) { 'Bcf comment does not exist.' } |
||||
end |
||||
end |
||||
|
||||
context 'if the viewpoint guid does not exist' do |
||||
let(:params) do |
||||
{ |
||||
comment: "this is a reply comment to another comment", |
||||
viewpoint_guid: "00000000-0000-0000-0000-000000000000", |
||||
reply_to_comment_guid: bcf_comment.uuid |
||||
} |
||||
end |
||||
|
||||
it_behaves_like 'bcf api unprocessable response' do |
||||
let(:message) { 'Viewpoint does not exist.' } |
||||
end |
||||
end |
||||
|
||||
context 'if the comment and viewpoint guid does not exist' do |
||||
let(:params) do |
||||
{ |
||||
comment: "this is a reply comment to another comment", |
||||
reply_to_comment_guid: "00000000-0000-0000-0000-000000000000", |
||||
viewpoint_guid: "00000000-0000-0000-0000-000000000000" |
||||
} |
||||
end |
||||
|
||||
it_behaves_like 'bcf api unprocessable response' do |
||||
let(:message) { 'Multiple field constraints have been violated. Viewpoint does not exist. Bcf comment does not exist.' } |
||||
end |
||||
end |
||||
end |
||||
end |
||||
|
||||
describe 'PUT /api/bcf/2.1/projects/:project_id/topics/:topic_guid/comments' do |
||||
let(:path) { "/api/bcf/2.1/projects/#{project.id}/topics/#{bcf_issue.uuid}/comments" } |
||||
let(:current_user) { edit_user } |
||||
let(:params) { { comment: "This is a bad comment update ... " } } |
||||
|
||||
before do |
||||
login_as(current_user) |
||||
put path, params.to_json |
||||
end |
||||
|
||||
it_behaves_like 'bcf api method not allowed response' |
||||
end |
||||
|
||||
describe 'GET /api/bcf/2.1/projects/:project_id/topics/:topic_guid/comments/:comment_guid' do |
||||
let(:path) { "/api/bcf/2.1/projects/#{project.id}/topics/#{bcf_issue.uuid}/comments/#{bcf_comment.uuid}" } |
||||
let(:current_user) { view_only_user } |
||||
let(:comments) { [bcf_comment, bcf_answer, bcf_comment_to_viewpoint] } |
||||
|
||||
before do |
||||
login_as(current_user) |
||||
comments |
||||
get path |
||||
end |
||||
|
||||
it_behaves_like 'bcf api successful response' do |
||||
let(:expected_body) do |
||||
{ |
||||
guid: bcf_comment.uuid, |
||||
date: bcf_comment.journal.created_at, |
||||
author: view_only_user.mail, |
||||
comment: bcf_comment.journal.notes, |
||||
modified_date: bcf_comment.journal.updated_at, |
||||
modified_author: view_only_user.mail, |
||||
topic_guid: bcf_issue.uuid, |
||||
reply_to_comment_guid: nil, |
||||
viewpoint_guid: nil, |
||||
authorization: { comment_actions: [] } |
||||
} |
||||
end |
||||
end |
||||
|
||||
context 'if user has editing permissions' do |
||||
let(:current_user) { edit_user } |
||||
|
||||
it_behaves_like 'bcf api successful response' do |
||||
let(:expected_body) do |
||||
{ |
||||
guid: bcf_comment.uuid, |
||||
date: bcf_comment.journal.created_at, |
||||
author: view_only_user.mail, |
||||
comment: bcf_comment.journal.notes, |
||||
modified_date: bcf_comment.journal.updated_at, |
||||
modified_author: view_only_user.mail, |
||||
topic_guid: bcf_issue.uuid, |
||||
reply_to_comment_guid: nil, |
||||
viewpoint_guid: nil, |
||||
authorization: { |
||||
comment_actions: [ |
||||
"update" |
||||
] |
||||
} |
||||
} |
||||
end |
||||
end |
||||
end |
||||
|
||||
context 'if comment id does not exist' do |
||||
let(:invalid_id) { "1337" } |
||||
let(:path) { "/api/bcf/2.1/projects/#{project.id}/topics/#{bcf_issue.uuid}/comments/#{invalid_id}" } |
||||
|
||||
it_behaves_like 'bcf api not found response' |
||||
end |
||||
|
||||
context 'without view permissions' do |
||||
let(:current_user) { user_without_permission } |
||||
|
||||
it_behaves_like 'bcf api not allowed response' |
||||
end |
||||
end |
||||
|
||||
describe 'PUT /api/bcf/2.1/projects/:project_id/topics/:topic_guid/comments/:comment_guid' do |
||||
let(:updated_comment) { bcf_comment } |
||||
let(:path) { "/api/bcf/2.1/projects/#{project.id}/topics/#{bcf_issue.uuid}/comments/#{updated_comment.uuid}" } |
||||
let(:current_user) { edit_user } |
||||
let(:params) { { comment: "Update comment to this elaborate text." } } |
||||
|
||||
before do |
||||
login_as(current_user) |
||||
put path, params.to_json |
||||
end |
||||
|
||||
it_behaves_like 'bcf api successful response' do |
||||
let(:expected_body) do |
||||
{ |
||||
guid: updated_comment.uuid, |
||||
date: updated_comment.journal.created_at, |
||||
author: view_only_user.mail, |
||||
comment: "Update comment to this elaborate text.", |
||||
modified_date: updated_comment.journal.updated_at, |
||||
# we cannot store another author then the journal creator |
||||
modified_author: view_only_user.mail, |
||||
topic_guid: bcf_issue.uuid, |
||||
reply_to_comment_guid: nil, |
||||
viewpoint_guid: nil, |
||||
authorization: { |
||||
comment_actions: [ |
||||
"update" |
||||
] |
||||
} |
||||
} |
||||
end |
||||
end |
||||
|
||||
context 'if user has no edit permissions' do |
||||
let(:current_user) { view_only_user } |
||||
|
||||
it_behaves_like 'bcf api not allowed response' |
||||
end |
||||
|
||||
context 'if viewpoint reference and reply to is changed' do |
||||
let(:params) do |
||||
{ |
||||
comment: "A new updated text", |
||||
viewpoint_guid: viewpoint.uuid, |
||||
reply_to_comment_guid: bcf_comment_to_viewpoint.uuid |
||||
} |
||||
end |
||||
|
||||
it_behaves_like 'bcf api successful response' do |
||||
let(:expected_body) do |
||||
{ |
||||
guid: updated_comment.uuid, |
||||
date: updated_comment.journal.created_at, |
||||
author: view_only_user.mail, |
||||
comment: "A new updated text", |
||||
modified_date: updated_comment.journal.updated_at, |
||||
# we cannot store another author then the journal creator |
||||
modified_author: view_only_user.mail, |
||||
topic_guid: bcf_issue.uuid, |
||||
reply_to_comment_guid: bcf_comment_to_viewpoint.uuid, |
||||
viewpoint_guid: viewpoint.uuid, |
||||
authorization: { |
||||
comment_actions: [ |
||||
"update" |
||||
] |
||||
} |
||||
} |
||||
end |
||||
end |
||||
end |
||||
|
||||
context 'if an invalid viewpoint guid is given' do |
||||
let(:params) do |
||||
{ |
||||
comment: "A new updated text", |
||||
viewpoint_guid: "00000000-0000-0000-0000-000000000000" |
||||
} |
||||
end |
||||
|
||||
it_behaves_like 'bcf api unprocessable response' do |
||||
let(:message) { 'Viewpoint does not exist.' } |
||||
end |
||||
end |
||||
|
||||
context 'if an invalid comment guid is given' do |
||||
let(:params) do |
||||
{ |
||||
comment: "A new updated text", |
||||
reply_to_comment_guid: "00000000-0000-0000-0000-000000000000" |
||||
} |
||||
end |
||||
|
||||
it_behaves_like 'bcf api unprocessable response' do |
||||
let(:message) { 'Bcf comment does not exist.' } |
||||
end |
||||
end |
||||
|
||||
context 'if the updated comment contains viewpoint reference and is a reply, but update does not set those attributes' do |
||||
let(:updated_comment) do |
||||
FactoryBot.create(:bcf_comment, |
||||
issue: bcf_issue, |
||||
viewpoint: viewpoint, |
||||
reply_to: bcf_comment, |
||||
author: edit_user) |
||||
end |
||||
|
||||
let(:params) { { comment: "Only change the comment text and leave the reply and viewpoint guid empty." } } |
||||
|
||||
it_behaves_like 'bcf api successful response' do |
||||
let(:expected_body) do |
||||
{ |
||||
guid: updated_comment.uuid, |
||||
date: updated_comment.journal.created_at, |
||||
author: edit_user.mail, |
||||
comment: "Only change the comment text and leave the reply and viewpoint guid empty.", |
||||
modified_date: updated_comment.journal.updated_at, |
||||
# we cannot store another author then the journal creator |
||||
modified_author: edit_user.mail, |
||||
topic_guid: bcf_issue.uuid, |
||||
reply_to_comment_guid: nil, |
||||
viewpoint_guid: nil, |
||||
authorization: { |
||||
comment_actions: [ |
||||
"update" |
||||
] |
||||
} |
||||
} |
||||
end |
||||
end |
||||
|
||||
end |
||||
end |
||||
|
||||
describe 'POST /api/bcf/2.1/projects/:project_id/topics/:topic_guid/comments/:comment_guid' do |
||||
let(:path) { "/api/bcf/2.1/projects/#{project.id}/topics/#{bcf_issue.uuid}/comments/#{bcf_comment.uuid}" } |
||||
let(:current_user) { edit_user } |
||||
let(:params) { { comment: "This is an invalid try to create a comment ..." } } |
||||
|
||||
before do |
||||
login_as(current_user) |
||||
post path, params.to_json |
||||
end |
||||
|
||||
it_behaves_like 'bcf api method not allowed response' |
||||
end |
||||
end |
Loading…
Reference in new issue