Adding support for extra text in invitation
parent
06d4ef0188
commit
8593b82f8b
|
@ -193,6 +193,7 @@ class MembershipViewSet(ModelCrudViewSet):
|
|||
|
||||
data = serializer.data
|
||||
project = models.Project.objects.get(id=data["project_id"])
|
||||
invitation_extra_text = data.get("invitation_extra_text", None)
|
||||
self.check_permissions(request, 'bulk_create', project)
|
||||
|
||||
# TODO: this should be moved to main exception handler instead
|
||||
|
@ -201,6 +202,7 @@ class MembershipViewSet(ModelCrudViewSet):
|
|||
try:
|
||||
members = services.create_members_in_bulk(data["bulk_memberships"],
|
||||
project=project,
|
||||
invitation_extra_text=invitation_extra_text,
|
||||
callback=self.post_save,
|
||||
precall=self.pre_save)
|
||||
except ValidationError as err:
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import models, migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('projects', '0004_auto_20141002_2337'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='membership',
|
||||
name='invitation_extra_text',
|
||||
field=models.TextField(null=True, verbose_name='invitation extra text', blank=True),
|
||||
preserve_default=True,
|
||||
),
|
||||
]
|
|
@ -70,6 +70,9 @@ class Membership(models.Model):
|
|||
invited_by = models.ForeignKey(settings.AUTH_USER_MODEL, related_name="ihaveinvited+",
|
||||
null=True, blank=True)
|
||||
|
||||
invitation_extra_text = models.TextField(null=True, blank=True,
|
||||
verbose_name=_("invitation extra text"))
|
||||
|
||||
def clean(self):
|
||||
# TODO: Review and do it more robust
|
||||
memberships = Membership.objects.filter(user=self.user, project=self.project)
|
||||
|
|
|
@ -251,3 +251,4 @@ class MemberBulkSerializer(RoleExistsValidator, serializers.Serializer):
|
|||
class MembersBulkSerializer(ProjectExistsValidator, serializers.Serializer):
|
||||
project_id = serializers.IntegerField()
|
||||
bulk_memberships = MemberBulkSerializer(many=True)
|
||||
invitation_extra_text = serializers.CharField(required=False, max_length=255)
|
||||
|
|
|
@ -11,6 +11,7 @@ def send_invitation(invitation):
|
|||
template = mbuilder.membership_notification
|
||||
else:
|
||||
template = mbuilder.membership_invitation
|
||||
|
||||
email = template(invitation.email, {"membership": invitation})
|
||||
email.send()
|
||||
|
||||
|
|
|
@ -11,6 +11,14 @@
|
|||
<p>you have been invited to the project '{{ membership.project }}'.</p>
|
||||
<p>If you want to join to this project go to <a href="{{ final_url }}">this link</a>
|
||||
for accept this invitation.</p>
|
||||
|
||||
{% if membership.invitation_extra_text %}
|
||||
<p>
|
||||
Some words from your Taiga Ambassador:<br/>
|
||||
{{ membership.invitation_extra_text }}
|
||||
</p>
|
||||
{% endif %}
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
|
|
@ -7,5 +7,12 @@ you have been invited to the project '{{ membership.project }}'.
|
|||
|
||||
If you want to join to this project go to {{ final_url }} for accept this invitation.
|
||||
|
||||
{% if membership.invitation_extra_text %}
|
||||
|
||||
Some words from your Taiga Ambassador:
|
||||
|
||||
{{ membership.invitation_extra_text }}
|
||||
|
||||
{% endif %}
|
||||
|
||||
** More info at ({{ final_url }}) **
|
||||
|
|
|
@ -51,6 +51,29 @@ def test_api_create_bulk_members(client):
|
|||
assert response.data[0]["email"] == john.email
|
||||
assert response.data[1]["email"] == joseph.email
|
||||
|
||||
def test_api_create_bulk_members_with_extra_text(client, outbox):
|
||||
project = f.ProjectFactory()
|
||||
tester = f.RoleFactory(project=project, name="Tester")
|
||||
url = reverse("memberships-bulk-create")
|
||||
|
||||
invitation_extra_text = "this is a not so random invitation text"
|
||||
data = {
|
||||
"project_id": project.id,
|
||||
"bulk_memberships": [
|
||||
{"role_id": tester.pk, "email": "john@email.com"},
|
||||
],
|
||||
"invitation_extra_text": invitation_extra_text
|
||||
}
|
||||
client.login(project.owner)
|
||||
response = client.json.post(url, json.dumps(data))
|
||||
|
||||
assert response.status_code == 200
|
||||
assert response.data[0]["email"] == "john@email.com"
|
||||
|
||||
message = outbox[0]
|
||||
assert len(outbox) == 1
|
||||
assert message.to == ["john@email.com"]
|
||||
assert "this is a not so random invitation text" in message.body
|
||||
|
||||
def test_api_resend_invitation(client, outbox):
|
||||
invitation = f.create_invitation()
|
||||
|
|
Loading…
Reference in New Issue