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 "Accountable" to be a settable field via inbound mails
Aaron Contrerasb3e497d6a8dc
diff --git a/app/models/mail_handler.rb b/app/models/mail_handler.rbindex c404f5d4e23..3525d0d6ba2 100644--- a/app/models/mail_handler.rb+++ b/app/models/mail_handler.rb@@ -377,17 +377,18 @@ class MailHandler < ActionMailer::Base# Returns a Hash of issue attributes extracted from keywords in the email bodydef wp_attributes_from_keywords(work_package){- "type_id" => wp_type_from_keywords(work_package),- "status_id" => wp_status_from_keywords,- "parent_id" => wp_parent_from_keywords,- "priority_id" => wp_priority_from_keywords,- "category_id" => wp_category_from_keywords(work_package),"assigned_to_id" => wp_assignee_from_keywords(work_package),- "version_id" => wp_version_from_keywords(work_package),- "start_date" => wp_start_date_from_keywords,+ "category_id" => wp_category_from_keywords(work_package),"due_date" => wp_due_date_from_keywords,"estimated_hours" => wp_estimated_hours_from_keywords,- "remaining_hours" => wp_remaining_hours_from_keywords+ "parent_id" => wp_parent_from_keywords,+ "priority_id" => wp_priority_from_keywords,+ "remaining_hours" => wp_remaining_hours_from_keywords,+ "responsible_id" => wp_accountable_from_keywords(work_package),+ "start_date" => wp_start_date_from_keywords,+ "status_id" => wp_status_from_keywords,+ "type_id" => wp_type_from_keywords(work_package),+ "version_id" => wp_version_from_keywords(work_package)}.compact_blank!end@@ -541,8 +542,16 @@ class MailHandler < ActionMailer::Baselookup_case_insensitive_key(work_package.project.categories, :category)end+ def wp_accountable_from_keywords(work_package)+ get_assignable_principal_from_keywords(:responsible, work_package)+ end+def wp_assignee_from_keywords(work_package)- keyword = get_keyword(:assigned_to, override: true)+ get_assignable_principal_from_keywords(:assigned_to, work_package)+ end++ def get_assignable_principal_from_keywords(keyword, work_package)+ keyword = get_keyword(keyword, override: true)return nil if keyword.blank?diff --git a/spec/fixtures/mail_handler/wp_mention_reply_with_attributes.eml b/spec/fixtures/mail_handler/wp_mention_reply_with_attributes.emlindex 2dfa1098616..ec585e24d3b 100644--- a/spec/fixtures/mail_handler/wp_mention_reply_with_attributes.eml+++ b/spec/fixtures/mail_handler/wp_mention_reply_with_attributes.eml@@ -52,6 +52,7 @@ The text of the reply.Status: Resolveddue date: 2010-12-31Start Date:2010-01-01+Accountable: [email protected]Assigned to: [email protected]float field: 52.6diff --git a/spec/fixtures/mail_handler/wp_on_given_project.eml b/spec/fixtures/mail_handler/wp_on_given_project.emlindex 92e06b5fbf1..6802e2ca515 100644--- a/spec/fixtures/mail_handler/wp_on_given_project.eml+++ b/spec/fixtures/mail_handler/wp_on_given_project.eml@@ -53,6 +53,7 @@ Project: onlinestoreStatus: Resolveddue date: 2010-12-31Start Date:2010-01-01+Accountable: John SmithAssigned to: John SmithVersion: alphaestimated hours: 2.5diff --git a/spec/fixtures/mail_handler/wp_on_given_project_group_assignment.eml b/spec/fixtures/mail_handler/wp_on_given_project_group_assignment.emlindex 1a3b1be315a..34fc9753ffc 100644--- a/spec/fixtures/mail_handler/wp_on_given_project_group_assignment.eml+++ b/spec/fixtures/mail_handler/wp_on_given_project_group_assignment.eml@@ -53,6 +53,7 @@ Project: onlinestoreStatus: Resolveddue date: 2010-12-31Start Date:2010-01-01+Accountable: A-TeamAssigned to: A-TeamVersion: alphaestimated hours: 2.5diff --git a/spec/fixtures/mail_handler/wp_reply_with_quoted_reply_above.eml b/spec/fixtures/mail_handler/wp_reply_with_quoted_reply_above.emlindex 15a20bfe81c..6748f37c9b1 100644--- a/spec/fixtures/mail_handler/wp_reply_with_quoted_reply_above.eml+++ b/spec/fixtures/mail_handler/wp_reply_with_quoted_reply_above.eml@@ -39,6 +39,7 @@ platea dictumst.>> Subject changed from Projects with JSON to Project JSON API> Status changed from New to Assigned+> Accountable set to Jerry Smith> Assignee set to Eric Davis> Priority changed from Low to Normal> Estimated time deleted (1.00)diff --git a/spec/fixtures/mail_handler/wp_with_invalid_attributes.eml b/spec/fixtures/mail_handler/wp_with_invalid_attributes.emlindex 9c2b9363731..9a7802bc822 100644--- a/spec/fixtures/mail_handler/wp_with_invalid_attributes.eml+++ b/spec/fixtures/mail_handler/wp_with_invalid_attributes.eml@@ -40,6 +40,7 @@ pulvinar dui, a gravida orci mi eget odio. Nunc a lacus.Project: onlinestoreType: Feature requestcategory: Stock management+accountable: [email protected]assigned to: [email protected]priority: foostart date: some daydiff --git a/spec/models/mail_handler_spec.rb b/spec/models/mail_handler_spec.rbindex 49bc97a62f3..eb4b177667e 100644--- a/spec/models/mail_handler_spec.rb+++ b/spec/models/mail_handler_spec.rb@@ -557,6 +557,11 @@ RSpec.describe MailHandler do.to eql("2010-12-31")end+ it "sets the accountable" do+ expect(subject.responsible)+ .to eql(user)+ end+it "sets the assignee" doexpect(subject.assigned_to).to eql(user)@@ -652,6 +657,11 @@ RSpec.describe MailHandler doit_behaves_like "work package created"+ it "sets the accountable to the group" do+ expect(subject.responsible)+ .to eql(group)+ end+it "sets the assignee to the group" doexpect(subject.assigned_to).to eql(group)@@ -1078,6 +1088,9 @@ RSpec.describe MailHandler doit_behaves_like "work package created"it "ignores the invalid attributes and set default ones where possible" do+ expect(subject.responsible)+ .to be_nil+expect(subject.assigned_to).to be_nil@@ -1212,14 +1225,18 @@ RSpec.describe MailHandler domember_with_permissions: { project => %i(view_work_packages) },notification_settings: [build(:notification_setting, assignee: true, responsible: true)])+ responsible = create(:user,+ member_with_permissions: { project => %i(view_work_packages) },+ notification_settings: [build(:notification_setting, assignee: true, responsible: true)])work_package.update_column(:assigned_to_id, assignee.id)+ work_package.update_column(:responsible_id, responsible.id)# Sends notifications for the assignee and the author who is listening for all changes.expect doperform_enqueued_jobs dosubjectend- end.to change(Notification, :count).by(1)+ end.to change(Notification, :count).by(2)endend@@ -1269,6 +1286,7 @@ RSpec.describe MailHandler do.to eql("due_date" => [nil, Date.parse("Fri, 31 Dec 2010")],"status_id" => [original_status.id, resolved_status.id],+ "responsible_id" => [nil, other_user.id],"assigned_to_id" => [nil, other_user.id],"start_date" => [nil, Date.parse("Fri, 01 Jan 2010")],"duration" => [nil, 365],