Skip to content

Commit

Permalink
[Backport] Fixing contact project
Browse files Browse the repository at this point in the history
  • Loading branch information
superalex authored and bameda committed Mar 13, 2017
1 parent eaf943c commit b579737
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion taiga/projects/contact/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def send_contact_email(contact_entry_id):
"user_profile_url": resolve_front_url("user", contact_entry.user.username),
"project_settings_url": resolve_front_url("project-admin", contact_entry.project.slug),
}
users = contact_entry.project.get_users().exclude(id=contact_entry.user_id)
users = contact_entry.project.get_users(with_admin_privileges=True).exclude(id=contact_entry.user_id)
addresses = ", ".join([u.email for u in users])
email = mail_builder.contact_notification(addresses, ctx)
email.extra_headers["Reply-To"] = ", ".join([contact_entry.user.email])
Expand Down
7 changes: 5 additions & 2 deletions taiga/projects/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,9 +382,12 @@ def cached_memberships_for_user(self, user):
def get_roles(self):
return self.roles.all()

def get_users(self):
def get_users(self, with_admin_privileges=None):
user_model = get_user_model()
members = self.memberships.values_list("user", flat=True)
members = self.memberships.all()
if with_admin_privileges is not None:
members = members.filter(Q(is_admin=True)|Q(user__id=self.owner.id))
members = members.values_list("user", flat=True)
return user_model.objects.filter(id__in=list(members))

def update_role_points(self, user_stories=None):
Expand Down
6 changes: 4 additions & 2 deletions tests/integration/test_contact.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@
def test_create_comment(client):
user = f.UserFactory.create()
project = f.ProjectFactory.create()
f.MembershipFactory(user=project.owner, project=project, is_admin=True)
m1 = f.MembershipFactory(user=project.owner, project=project)
m2 = f.MembershipFactory(project=project, is_admin=True)
m3 = f.MembershipFactory(project=project, is_admin=False)

url = reverse("contact-list")

Expand All @@ -46,7 +48,7 @@ def test_create_comment(client):
response = client.post(url, contact_data, content_type="application/json")
assert response.status_code == 201
assert len(mail.outbox) == 1
assert mail.outbox[0].to == [project.owner.email]
assert set(mail.outbox[0].to[0].split(", ")) == set([project.owner.email, m2.user.email])



Expand Down

0 comments on commit b579737

Please sign in to comment.