Add assigned users to webhooks
parent
1d4c731624
commit
8fbf4b8068
|
@ -85,13 +85,6 @@ class UserStoryListSerializer(ProjectExtraInfoSerializerMixin,
|
||||||
|
|
||||||
assigned_users = MethodField()
|
assigned_users = MethodField()
|
||||||
|
|
||||||
# def get_assigned_users(self, obj):
|
|
||||||
# assert hasattr(obj, "assigned_users_attr"), "instance must have a assigned_users_attr attribute"
|
|
||||||
# if not obj.assigned_users_attr:
|
|
||||||
# return []
|
|
||||||
#
|
|
||||||
# return obj.assigned_users_attr
|
|
||||||
|
|
||||||
def get_assigned_users(self, obj):
|
def get_assigned_users(self, obj):
|
||||||
"""Get the assigned of an object.
|
"""Get the assigned of an object.
|
||||||
|
|
||||||
|
|
|
@ -157,7 +157,6 @@ def attach_extra_info(queryset, user=None, include_attachments=False, include_ta
|
||||||
queryset = attach_total_points(queryset)
|
queryset = attach_total_points(queryset)
|
||||||
queryset = attach_role_points(queryset)
|
queryset = attach_role_points(queryset)
|
||||||
queryset = attach_epics(queryset)
|
queryset = attach_epics(queryset)
|
||||||
# queryset = attach_assigned_users(queryset)
|
|
||||||
|
|
||||||
if include_attachments:
|
if include_attachments:
|
||||||
queryset = attach_basic_attachments(queryset)
|
queryset = attach_basic_attachments(queryset)
|
||||||
|
|
|
@ -359,6 +359,7 @@ class UserStorySerializer(CustomAttributesValuesWebhookSerializerMixin, serializ
|
||||||
permalink = serializers.SerializerMethodField("get_permalink")
|
permalink = serializers.SerializerMethodField("get_permalink")
|
||||||
owner = UserSerializer()
|
owner = UserSerializer()
|
||||||
assigned_to = UserSerializer()
|
assigned_to = UserSerializer()
|
||||||
|
assigned_users = MethodField()
|
||||||
points = MethodField()
|
points = MethodField()
|
||||||
status = UserStoryStatusSerializer()
|
status = UserStoryStatusSerializer()
|
||||||
milestone = MilestoneSerializer()
|
milestone = MilestoneSerializer()
|
||||||
|
@ -369,6 +370,13 @@ class UserStorySerializer(CustomAttributesValuesWebhookSerializerMixin, serializ
|
||||||
def custom_attributes_queryset(self, project):
|
def custom_attributes_queryset(self, project):
|
||||||
return project.userstorycustomattributes.all()
|
return project.userstorycustomattributes.all()
|
||||||
|
|
||||||
|
def get_assigned_users(self, obj):
|
||||||
|
"""Get the assigned of an object.
|
||||||
|
|
||||||
|
:return: User queryset object representing the assigned users
|
||||||
|
"""
|
||||||
|
return [user.id for user in obj.assigned_users.all()]
|
||||||
|
|
||||||
def get_watchers(self, obj):
|
def get_watchers(self, obj):
|
||||||
return list(obj.get_watchers().values_list("id", flat=True))
|
return list(obj.get_watchers().values_list("id", flat=True))
|
||||||
|
|
||||||
|
|
|
@ -82,6 +82,38 @@ def test_webhooks_when_update_user_story(settings):
|
||||||
assert data["change"]["diff"]["subject"]["from"] != data["data"]["subject"]
|
assert data["change"]["diff"]["subject"]["from"] != data["data"]["subject"]
|
||||||
|
|
||||||
|
|
||||||
|
def test_webhooks_when_update_assigned_users_user_story(settings):
|
||||||
|
settings.WEBHOOKS_ENABLED = True
|
||||||
|
project = f.ProjectFactory()
|
||||||
|
f.WebhookFactory.create(project=project)
|
||||||
|
f.WebhookFactory.create(project=project)
|
||||||
|
|
||||||
|
obj = f.UserStoryFactory.create(project=project)
|
||||||
|
|
||||||
|
with patch('taiga.webhooks.tasks._send_request') as send_request_mock:
|
||||||
|
services.take_snapshot(obj, user=obj.owner)
|
||||||
|
assert send_request_mock.call_count == 2
|
||||||
|
|
||||||
|
user = f.create_user()
|
||||||
|
obj.assigned_users.add(user)
|
||||||
|
obj.save()
|
||||||
|
|
||||||
|
with patch('taiga.webhooks.tasks._send_request') as send_request_mock:
|
||||||
|
services.take_snapshot(obj, user=obj.owner,)
|
||||||
|
assert send_request_mock.call_count == 2
|
||||||
|
|
||||||
|
(webhook_id, url, key, data) = send_request_mock.call_args[0]
|
||||||
|
|
||||||
|
assert data["action"] == "change"
|
||||||
|
assert data["type"] == "userstory"
|
||||||
|
assert data["by"]["id"] == obj.owner.id
|
||||||
|
assert len(data["data"]["assigned_users"]) == \
|
||||||
|
obj.assigned_users.count()
|
||||||
|
assert data["data"]["assigned_users"] == [user.id]
|
||||||
|
assert not data["change"]["diff"]["assigned_users"]["from"]
|
||||||
|
assert data["change"]["diff"]["assigned_users"]["to"] == user.username
|
||||||
|
|
||||||
|
|
||||||
def test_webhooks_when_delete_user_story(settings):
|
def test_webhooks_when_delete_user_story(settings):
|
||||||
settings.WEBHOOKS_ENABLED = True
|
settings.WEBHOOKS_ENABLED = True
|
||||||
project = f.ProjectFactory()
|
project = f.ProjectFactory()
|
||||||
|
|
Loading…
Reference in New Issue