allow responsible to receive notifications

pull/5108/head
Jens Ulferts 8 years ago
parent 3e4f465528
commit defe6e75a8
No known key found for this signature in database
GPG Key ID: 3CAA4B1182CF5308
  1. 35
      app/models/work_package.rb
  2. 34
      spec/models/user_spec.rb
  3. 33
      spec/models/work_package_spec.rb

@ -432,30 +432,21 @@ class WorkPackage < ActiveRecord::Base
# >>> issues.rb >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
# Returns users that should be notified
def recipients
notified = project.notified_users
# Author and assignee are always notified unless they have been
# locked or don't want to be notified
notified << author if author && author.notify_about?(self)
if assigned_to
if assigned_to.is_a?(Group)
notified += assigned_to.users.select { |u| u.notify_about?(self) }
else
notified << assigned_to if assigned_to.notify_about?(self)
end
end
notified = project.notified_users + attribute_users.select { |u| u.notify_about?(self) }
notified.uniq!
# Remove users that can not view the issue
notified.select { |user| visible?(user) }
# Remove users that can not view the work package
notified & User.allowed(:view_work_packages, project)
end
def notify?(user)
case user.mail_notification
when 'selected', 'only_my_events'
author == user || user.is_or_belongs_to?(assigned_to)
author == user || user.is_or_belongs_to?(assigned_to) || user.is_or_belongs_to?(responsible)
when 'none'
false
when 'only_assigned'
user.is_or_belongs_to?(assigned_to)
user.is_or_belongs_to?(assigned_to) || user.is_or_belongs_to?(responsible)
when 'only_owner'
author == user
else
@ -951,4 +942,18 @@ class WorkPackage < ActiveRecord::Base
.pluck('SUM(hours)')
.first
end
def attribute_users
related = [author]
[responsible, assigned_to].each do |user|
if user.is_a?(Group)
related += user.users
else
related << user
end
end
related.select(&:present?)
end
end

@ -539,6 +539,7 @@ describe User, type: :model do
let(:work_package) do
FactoryGirl.build_stubbed(:work_package,
assigned_to: assignee,
responsible: responsible,
author: author)
end
let(:author) do
@ -547,6 +548,9 @@ describe User, type: :model do
let(:assignee) do
FactoryGirl.build_stubbed(:user)
end
let(:responsible) do
FactoryGirl.build_stubbed(:user)
end
let(:project) do
work_package.project
end
@ -571,7 +575,7 @@ describe User, type: :model do
expect(author.notify_about?(work_package)).to be_falsey
end
it "is false for a user with :only_my_events and isn't an author, creator, or assignee" do
it "is false for a user with :only_my_events who has no relation to the work package" do
user = FactoryGirl.build_stubbed(:user, mail_notification: 'only_my_events')
(Member.new.tap do |m|
m.attributes = { user: user, project: project, role_ids: [role.id] }
@ -579,47 +583,57 @@ describe User, type: :model do
expect(user.notify_about?(work_package)).to be_falsey
end
it 'is true for a user with :only_my_events and is the author' do
it 'is true for a user with :only_my_events who is the author' do
author.mail_notification = 'only_my_events'
expect(author.notify_about?(work_package)).to be_truthy
end
it 'is true for a user with :only_my_events and is the assignee' do
it 'is true for a user with :only_my_events who is the assignee' do
assignee.mail_notification = 'only_my_events'
expect(assignee.notify_about?(work_package)).to be_truthy
end
it 'is true for a user with :only_assigned and is the assignee' do
it 'is true for a user with :only_assigned who is the assignee' do
assignee.mail_notification = 'only_assigned'
expect(assignee.notify_about?(work_package)).to be_truthy
end
it 'is false for a user with :only_assigned and is not the assignee' do
it 'is true for a user with :only_assigned who is the responsible' do
responsible.mail_notification = 'only_assigned'
expect(responsible.notify_about?(work_package)).to be_truthy
end
it 'is false for a user with :only_assigned who is neither assignee nor responsible' do
author.mail_notification = 'only_assigned'
expect(author.notify_about?(work_package)).to be_falsey
end
it 'is true for a user with :only_owner and is the author' do
it 'is true for a user with :only_owner who is the author' do
author.mail_notification = 'only_owner'
expect(author.notify_about?(work_package)).to be_truthy
end
it 'is false for a user with :only_owner and is not the author' do
it 'is false for a user with :only_owner who is not the author' do
assignee.mail_notification = 'only_owner'
expect(assignee.notify_about?(work_package)).to be_falsey
end
it 'is true for a user with :selected and is the author' do
it 'is true for a user with :selected who is the author' do
author.mail_notification = 'selected'
expect(author.notify_about?(work_package)).to be_truthy
end
it 'is true for a user with :selected and is the assignee' do
it 'is true for a user with :selected who is the assignee' do
assignee.mail_notification = 'selected'
expect(assignee.notify_about?(work_package)).to be_truthy
end
it 'is false for a user with :selected and is not the author or assignee' do
it 'is true for a user with :selected who is the responsible' do
responsible.mail_notification = 'selected'
expect(responsible.notify_about?(work_package)).to be_truthy
end
it "is false for a user with :only_my_events who has no relation to the work package" do
user = FactoryGirl.build(:user, mail_notification: 'selected')
(Member.new.tap do |m|
m.attributes = { user: user, project: project, role_ids: [role.id] }

@ -918,12 +918,10 @@ describe WorkPackage, type: :model do
describe '#recipients' do
let(:project) { FactoryGirl.create(:project) }
let(:member) { FactoryGirl.create(:user) }
let(:author) { FactoryGirl.create(:user) }
let(:assignee) { FactoryGirl.create(:user) }
let(:role) {
FactoryGirl.create(:role,
permissions: [:view_work_packages])
}
let(:author) { FactoryGirl.create(:user, mail_notification: 'only_owner') }
let(:assignee) { FactoryGirl.create(:user, mail_notification: 'only_assigned') }
let(:responsible) { FactoryGirl.create(:user, mail_notification: 'only_assigned') }
let(:role) { FactoryGirl.create(:role, permissions: [:view_work_packages]) }
let(:project_member) {
FactoryGirl.create(:member,
user: member,
@ -942,10 +940,17 @@ describe WorkPackage, type: :model do
project: project,
roles: [role])
}
let(:project_responsible) {
FactoryGirl.create(:member,
user: responsible,
project: project,
roles: [role])
}
let(:work_package) {
FactoryGirl.create(:work_package,
author: author,
assigned_to: assignee,
responsible: responsible,
project: project)
}
@ -1003,6 +1008,22 @@ describe WorkPackage, type: :model do
it_behaves_like 'includes expected users'
end
describe 'includes work package responsible' do
before do
project_responsible
end
context 'pre-condition' do
subject { work_package.responsible }
it { is_expected.not_to be_nil }
end
let(:expected_users) { work_package.responsible }
it_behaves_like 'includes expected users'
end
context 'mail notification settings' do
before do
project_author

Loading…
Cancel
Save