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
allow setting accountable to user clicking custom action
ulferts1d585c05e270
diff --git a/app/models/custom_actions/actions/responsible.rb b/app/models/custom_actions/actions/responsible.rbindex 334ab95da45..78c3efc83b1 100644--- a/app/models/custom_actions/actions/responsible.rb+++ b/app/models/custom_actions/actions/responsible.rb@@ -27,9 +27,9 @@#++class CustomActions::Actions::Responsible < CustomActions::Actions::Base- include CustomActions::Actions::Strategies::Associated+ include CustomActions::Actions::Strategies::MeAssociated- def associated+ def available_principlesUser.not_locked.select(:id, :firstname, :lastname, :type)@@ -37,6 +37,10 @@ class CustomActions::Actions::Responsible < CustomActions::Actions::Base.map { |u| [u.id, u.name] }end+ def apply(work_package)+ work_package.responsible_id = transformed_value(values.first)+ end+def required?falseenddiff --git a/spec/models/custom_actions/actions/responsible_spec.rb b/spec/models/custom_actions/actions/responsible_spec.rbindex a442fff08be..a13062b1e7e 100644--- a/spec/models/custom_actions/actions/responsible_spec.rb+++ b/spec/models/custom_actions/actions/responsible_spec.rb@@ -25,8 +25,8 @@## See COPYRIGHT and LICENSE files for more details.#++-require 'spec_helper'-require_relative '../shared_expectations'+require "spec_helper"+require_relative "../shared_expectations"RSpec.describe CustomActions::Actions::Responsible dolet(:key) { :responsible }@@ -39,15 +39,16 @@ RSpec.describe CustomActions::Actions::Responsible do.to receive_message_chain(:not_locked, :select, :ordered_by_name).and_return(principals)- [{ value: nil, label: '-' },+ [{ value: nil, label: "-" },+ { value: "current_user", label: "(Assign to executing user)" },{ value: principals.first.id, label: principals.first.name },{ value: principals.last.id, label: principals.last.name }]end- it_behaves_like 'base custom action'- it_behaves_like 'associated custom action' do- describe '#allowed_values' do- it 'is the list of all users and groups' do+ it_behaves_like "base custom action"+ it_behaves_like "associated custom action" do+ describe "#allowed_values" do+ it "is the list of all users and groups" doallowed_valuesexpect(instance.allowed_values)@@ -55,4 +56,54 @@ RSpec.describe CustomActions::Actions::Responsible doendendend++ describe "current_user special value" do+ let(:work_package) { build_stubbed(:work_package) }+ let(:user) { build_stubbed(:user) }++ subject { described_class.new }++ before do+ subject.values = ["current_user"]+ end++ it "can set the value" do+ expect(subject).to have_me_value+ end++ it "includes the value in available_values" do+ expect(subject.associated)+ .to include([subject.current_user_value_key, I18n.t("custom_actions.actions.assigned_to.executing_user_value")])+ end++ context "when logged in" do+ before do+ login_as user+ end++ it "returns nil for the current user id" do+ subject.apply work_package+ expect(work_package.responsible_id).to eq(user.id)+ end++ it "validates the me value when executing" do+ errors = ActiveModel::Errors.new(CustomAction.new)+ subject.validate errors+ expect(errors.symbols_for(:actions)).to be_empty+ end+ end++ context "when not logged in" do+ it "returns nil for the current user id" do+ subject.apply work_package+ expect(work_package.responsible_id).to be_nil+ end++ it "validates the me value when executing" do+ errors = ActiveModel::Errors.new(CustomAction.new)+ subject.validate errors+ expect(errors.symbols_for(:actions)).to include :not_logged_in+ end+ end+ endend