OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Add meeting contract permission specs
Oliver Güntherd003cc3784e1
diff --git a/modules/meeting/app/contracts/meeting_agenda_items/create_contract.rb b/modules/meeting/app/contracts/meeting_agenda_items/create_contract.rbindex b083853fbc5..03f44a47728 100644--- a/modules/meeting/app/contracts/meeting_agenda_items/create_contract.rb+++ b/modules/meeting/app/contracts/meeting_agenda_items/create_contract.rb@@ -28,5 +28,15 @@module MeetingAgendaItemsclass CreateContract < BaseContract+ validate :user_allowed_to_add++ ##+ # Meeting agenda items can currently be only created+ # through the project permission :edit_meetings+ def user_allowed_to_add+ unless user.allowed_to?(:edit_meetings, model.project)+ errors.add :base, :error_unauthorized+ end+ endendenddiff --git a/modules/meeting/app/contracts/meeting_agenda_items/update_contract.rb b/modules/meeting/app/contracts/meeting_agenda_items/update_contract.rbindex 39edd467484..daaaf403981 100644--- a/modules/meeting/app/contracts/meeting_agenda_items/update_contract.rb+++ b/modules/meeting/app/contracts/meeting_agenda_items/update_contract.rb@@ -28,5 +28,15 @@module MeetingAgendaItemsclass UpdateContract < BaseContract+ validate :user_allowed_to_edit++ ##+ # Meeting agenda items can currently be only edited+ # through the project permission :edit_meetings+ def user_allowed_to_edit+ unless user.allowed_to?(:edit_meetings, model.project)+ errors.add :base, :error_unauthorized+ end+ endendenddiff --git a/modules/meeting/app/models/meeting_agenda_item.rb b/modules/meeting/app/models/meeting_agenda_item.rbindex 9ab7be5bff8..c8cd0aa2385 100644--- a/modules/meeting/app/models/meeting_agenda_item.rb+++ b/modules/meeting/app/models/meeting_agenda_item.rb@@ -36,7 +36,6 @@ class MeetingAgendaItem < ApplicationRecordacts_as_list scope: :meetingdefault_scope { order(:position) }- validates :author_id, presence: truevalidates :meeting_id, presence: truevalidates :title, presence: true, if: Proc.new { |item| item.work_package_id.blank? }validates :work_package_id, presence: true, if: Proc.new { |item| item.title.blank? }diff --git a/modules/meeting/spec/contracts/meeting_agenda_items/create_contract_spec.rb b/modules/meeting/spec/contracts/meeting_agenda_items/create_contract_spec.rbindex a60a7b03974..9df042fb6d4 100644--- a/modules/meeting/spec/contracts/meeting_agenda_items/create_contract_spec.rb+++ b/modules/meeting/spec/contracts/meeting_agenda_items/create_contract_spec.rb@@ -30,9 +30,34 @@require 'spec_helper'require 'contracts/shared/model_contract_shared_context'-require_relative './shared_contract_examples'RSpec.describe MeetingAgendaItems::CreateContract doinclude_context 'ModelContract shared context'- include_examples 'meeting is not readable'++ shared_let(:project) { create(:project) }+ shared_let(:meeting) { create(:structured_meeting, project:) }+ let(:item) { build(:meeting_agenda_item, meeting:) }+ let(:contract) { described_class.new(item, user) }++ context 'with permission' do+ let(:user) do+ create(:user, member_in_project: project, member_with_permissions: [:edit_meetings])+ end++ it_behaves_like 'contract is valid'++ context 'when :meeting is not editable' do+ before do+ meeting.update_column(:state, :closed)+ end++ it_behaves_like 'contract is invalid', base: I18n.t(:text_meeting_not_editable_anymore)+ end+ end++ context 'without permission' do+ let(:user) { build_stubbed(:user) }++ it_behaves_like 'contract is invalid', base: :error_unauthorized+ endenddiff --git a/modules/meeting/spec/contracts/meeting_agenda_items/delete_contract_spec.rb b/modules/meeting/spec/contracts/meeting_agenda_items/delete_contract_spec.rbindex 6f38f9cb6bb..3b72e63df42 100644--- a/modules/meeting/spec/contracts/meeting_agenda_items/delete_contract_spec.rb+++ b/modules/meeting/spec/contracts/meeting_agenda_items/delete_contract_spec.rb@@ -30,14 +30,13 @@require 'spec_helper'require 'contracts/shared/model_contract_shared_context'-require_relative 'shared_contract_examples'RSpec.describe MeetingAgendaItems::DeleteContract doinclude_context 'ModelContract shared context'- let(:project) { create(:project) }- let(:meeting) { create(:structured_meeting, project:) }- let(:item) { create(:meeting_agenda_item, meeting:) }+ shared_let(:project) { create(:project) }+ shared_let(:meeting) { create(:structured_meeting, project:) }+ shared_let(:item) { create(:meeting_agenda_item, meeting:) }let(:contract) { described_class.new(item, user) }context 'with permission' do@@ -46,7 +45,14 @@ RSpec.describe MeetingAgendaItems::DeleteContract doendit_behaves_like 'contract is valid'- include_examples 'meeting is not readable'++ context 'when :meeting is not editable' do+ before do+ meeting.update_column(:state, :closed)+ end++ it_behaves_like 'contract is invalid', base: I18n.t(:text_meeting_not_editable_anymore)+ endendcontext 'without permission' dodiff --git a/modules/meeting/spec/contracts/meeting_agenda_items/shared_contract_examples.rb b/modules/meeting/spec/contracts/meeting_agenda_items/shared_contract_examples.rbdeleted file mode 100644index e1289c49e62..00000000000--- a/modules/meeting/spec/contracts/meeting_agenda_items/shared_contract_examples.rb+++ /dev/null@@ -1,45 +0,0 @@-# frozen_string_literal: true--#-- copyright-# OpenProject is an open source project management software.-# Copyright (C) 2012-2023 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 'contracts/shared/model_contract_shared_context'--RSpec.shared_examples_for 'meeting is not readable' do- let(:user) { build_stubbed(:user) }- let(:meeting) { build_stubbed(:structured_meeting) }- let(:item) { build_stubbed(:meeting_agenda_item, meeting:) }- let(:contract) { described_class.new(item, user) }-- context 'when :meeting is not editable' do- let(:meeting) { build_stubbed(:structured_meeting, state: :closed) }-- it_behaves_like 'contract is invalid', base: I18n.t(:text_meeting_not_editable_anymore)- end-enddiff --git a/modules/meeting/spec/contracts/meeting_agenda_items/update_contract_spec.rb b/modules/meeting/spec/contracts/meeting_agenda_items/update_contract_spec.rbindex 6bbf4850eb5..81156b7c913 100644--- a/modules/meeting/spec/contracts/meeting_agenda_items/update_contract_spec.rb+++ b/modules/meeting/spec/contracts/meeting_agenda_items/update_contract_spec.rb@@ -30,9 +30,34 @@require 'spec_helper'require 'contracts/shared/model_contract_shared_context'-require_relative './shared_contract_examples'RSpec.describe MeetingAgendaItems::UpdateContract doinclude_context 'ModelContract shared context'- include_examples 'meeting is not readable'++ shared_let(:project) { create(:project) }+ shared_let(:meeting) { create(:structured_meeting, project:) }+ shared_let(:item) { create(:meeting_agenda_item, meeting:) }+ let(:contract) { described_class.new(item, user) }++ context 'with permission' do+ let(:user) do+ create(:user, member_in_project: project, member_with_permissions: [:edit_meetings])+ end++ it_behaves_like 'contract is valid'++ context 'when :meeting is not editable' do+ before do+ meeting.update_column(:state, :closed)+ end++ it_behaves_like 'contract is invalid', base: I18n.t(:text_meeting_not_editable_anymore)+ end+ end++ context 'without permission' do+ let(:user) { build_stubbed(:user) }++ it_behaves_like 'contract is invalid', base: :error_unauthorized+ endend