Refactoring update order in bulk user-stories
parent
b567a55598
commit
7944c36e6b
|
@ -80,27 +80,16 @@ class UserStoryViewSet(OCCResourceMixin, HistoryResourceMixin, WatchedResourceMi
|
||||||
|
|
||||||
@list_route(methods=["POST"])
|
@list_route(methods=["POST"])
|
||||||
def bulk_update_order(self, request, **kwargs):
|
def bulk_update_order(self, request, **kwargs):
|
||||||
# bulkStories should be:
|
serializer = serializers.UpdateUserStoriesBulkSerializer(data=request.DATA)
|
||||||
# [[1,1],[23, 2], ...]
|
if serializer.is_valid():
|
||||||
|
data = serializer.data
|
||||||
|
project = Project.objects.get(id=data["project_id"])
|
||||||
|
self.check_permissions(request, 'bulk_update_order', project)
|
||||||
|
# services.update_userstories_order_in_bulk(data["bulk_stories"])
|
||||||
|
|
||||||
# TODO: Generate the histoy snaptshot when change the uss order in the backlog.
|
return response.NoContent()
|
||||||
# Implement order with linked lists \o/.
|
|
||||||
bulk_stories = request.DATA.get("bulkStories", None)
|
|
||||||
|
|
||||||
if bulk_stories is None:
|
return response.BadRequest(serializer.errors)
|
||||||
raise exc.BadRequest(_("bulkStories parameter is mandatory"))
|
|
||||||
|
|
||||||
project_id = request.DATA.get('projectId', None)
|
|
||||||
if project_id is None:
|
|
||||||
raise exc.BadRequest(_("projectId parameter ir mandatory"))
|
|
||||||
|
|
||||||
project = get_object_or_404(Project, id=project_id)
|
|
||||||
|
|
||||||
self.check_permissions(request, 'bulk_update_order', project)
|
|
||||||
|
|
||||||
services.update_userstories_order_in_bulk(bulk_stories)
|
|
||||||
|
|
||||||
return Response(data=None, status=status.HTTP_204_NO_CONTENT)
|
|
||||||
|
|
||||||
@transaction.atomic
|
@transaction.atomic
|
||||||
def create(self, *args, **kwargs):
|
def create(self, *args, **kwargs):
|
||||||
|
|
|
@ -21,6 +21,7 @@ from rest_framework import serializers
|
||||||
from taiga.base.serializers import Serializer, PickleField, NeighborsSerializerMixin
|
from taiga.base.serializers import Serializer, PickleField, NeighborsSerializerMixin
|
||||||
from taiga.mdrender.service import render as mdrender
|
from taiga.mdrender.service import render as mdrender
|
||||||
from taiga.projects.validators import ProjectExistsValidator, UserStoryStatusExistsValidator
|
from taiga.projects.validators import ProjectExistsValidator, UserStoryStatusExistsValidator
|
||||||
|
from taiga.projects.userstories.validators import UserStoryExistsValidator
|
||||||
|
|
||||||
from . import models
|
from . import models
|
||||||
|
|
||||||
|
@ -116,3 +117,14 @@ class UserStoriesBulkSerializer(ProjectExistsValidator, UserStoryStatusExistsVal
|
||||||
project_id = serializers.IntegerField()
|
project_id = serializers.IntegerField()
|
||||||
status_id = serializers.IntegerField(required=False)
|
status_id = serializers.IntegerField(required=False)
|
||||||
bulk_stories = serializers.CharField()
|
bulk_stories = serializers.CharField()
|
||||||
|
|
||||||
|
|
||||||
|
class UserStoryOrderBulkSerializer(UserStoryExistsValidator, Serializer):
|
||||||
|
us_id = serializers.IntegerField()
|
||||||
|
order = serializers.IntegerField()
|
||||||
|
|
||||||
|
|
||||||
|
class UpdateUserStoriesBulkSerializer(ProjectExistsValidator, UserStoryStatusExistsValidator,
|
||||||
|
Serializer):
|
||||||
|
project_id = serializers.IntegerField()
|
||||||
|
bulk_stories = UserStoryOrderBulkSerializer(many=True)
|
||||||
|
|
|
@ -6,7 +6,7 @@ from . import models
|
||||||
|
|
||||||
|
|
||||||
class UserStoryExistsValidator:
|
class UserStoryExistsValidator:
|
||||||
def validate_project_id(self, attrs, source):
|
def validate_us_id(self, attrs, source):
|
||||||
value = attrs[source]
|
value = attrs[source]
|
||||||
if not models.UserStory.objects.filter(pk=value).exists():
|
if not models.UserStory.objects.filter(pk=value).exists():
|
||||||
msg = _("There's no user story with that id")
|
msg = _("There's no user story with that id")
|
||||||
|
|
|
@ -250,15 +250,15 @@ def test_user_story_action_bulk_create(client, data):
|
||||||
data.project_owner
|
data.project_owner
|
||||||
]
|
]
|
||||||
|
|
||||||
bulk_data = json.dumps({"bulkStories": "test1\ntest2", "projectId": data.public_user_story.project.pk})
|
bulk_data = json.dumps({"bulk_stories": "test1\ntest2", "projectId": data.public_user_story.project.pk})
|
||||||
results = helper_test_http_method(client, 'post', url, bulk_data, users)
|
results = helper_test_http_method(client, 'post', url, bulk_data, users)
|
||||||
assert results == [401, 200, 200, 200, 200]
|
assert results == [401, 200, 200, 200, 200]
|
||||||
|
|
||||||
bulk_data = json.dumps({"bulkStories": "test1\ntest2", "projectId": data.private_user_story1.project.pk})
|
bulk_data = json.dumps({"bulk_stories": "test1\ntest2", "projectId": data.private_user_story1.project.pk})
|
||||||
results = helper_test_http_method(client, 'post', url, bulk_data, users)
|
results = helper_test_http_method(client, 'post', url, bulk_data, users)
|
||||||
assert results == [401, 200, 200, 200, 200]
|
assert results == [401, 200, 200, 200, 200]
|
||||||
|
|
||||||
bulk_data = json.dumps({"bulkStories": "test1\ntest2", "projectId": data.private_user_story2.project.pk})
|
bulk_data = json.dumps({"bulk_stories": "test1\ntest2", "projectId": data.private_user_story2.project.pk})
|
||||||
results = helper_test_http_method(client, 'post', url, bulk_data, users)
|
results = helper_test_http_method(client, 'post', url, bulk_data, users)
|
||||||
assert results == [401, 403, 403, 200, 200]
|
assert results == [401, 403, 403, 200, 200]
|
||||||
|
|
||||||
|
@ -275,22 +275,22 @@ def test_user_story_action_bulk_update_order(client, data):
|
||||||
]
|
]
|
||||||
|
|
||||||
post_data = json.dumps({
|
post_data = json.dumps({
|
||||||
"bulkStories": [(1,2)],
|
"bulk_stories": [{"us_id": 1, "order": 2}],
|
||||||
"projectId": data.public_project.pk
|
"project_id": data.public_project.pk
|
||||||
})
|
})
|
||||||
results = helper_test_http_method(client, 'post', url, post_data, users)
|
results = helper_test_http_method(client, 'post', url, post_data, users)
|
||||||
assert results == [401, 403, 403, 204, 204]
|
assert results == [401, 403, 403, 204, 204]
|
||||||
|
|
||||||
post_data = json.dumps({
|
post_data = json.dumps({
|
||||||
"bulkStories": [(1,2)],
|
"bulk_stories": [{"id": 1, "order": 2}],
|
||||||
"projectId": data.private_project1.pk
|
"project_id": data.private_project1.pk
|
||||||
})
|
})
|
||||||
results = helper_test_http_method(client, 'post', url, post_data, users)
|
results = helper_test_http_method(client, 'post', url, post_data, users)
|
||||||
assert results == [401, 403, 403, 204, 204]
|
assert results == [401, 403, 403, 204, 204]
|
||||||
|
|
||||||
post_data = json.dumps({
|
post_data = json.dumps({
|
||||||
"bulkStories": [(1,2)],
|
"bulk_stories": [{"id": 1, "order": 2}],
|
||||||
"projectId": data.private_project2.pk
|
"project_id": data.private_project2.pk
|
||||||
})
|
})
|
||||||
results = helper_test_http_method(client, 'post', url, post_data, users)
|
results = helper_test_http_method(client, 'post', url, post_data, users)
|
||||||
assert results == [401, 403, 403, 204, 204]
|
assert results == [401, 403, 403, 204, 204]
|
||||||
|
|
|
@ -80,3 +80,20 @@ def test_api_create_in_bulk_with_status(client):
|
||||||
|
|
||||||
assert response.status_code == 200, response.data
|
assert response.status_code == 200, response.data
|
||||||
assert response.data[0]["status"] == project.default_us_status.id
|
assert response.data[0]["status"] == project.default_us_status.id
|
||||||
|
|
||||||
|
|
||||||
|
def test_api_update_order_in_bulk(client):
|
||||||
|
project = f.create_project()
|
||||||
|
us1 = f.create_userstory(project=project)
|
||||||
|
us2 = f.create_userstory(project=project)
|
||||||
|
url = reverse("userstories-bulk-update-order")
|
||||||
|
data = {
|
||||||
|
"project_id": project.id,
|
||||||
|
"bulk_stories": [{"us_id": us1.id, "order": 1},
|
||||||
|
{"us_id": us2.id, "order": 2}]
|
||||||
|
}
|
||||||
|
|
||||||
|
client.login(project.owner)
|
||||||
|
response = client.json.post(url, data)
|
||||||
|
|
||||||
|
assert response.status_code == 204, response.data
|
||||||
|
|
Loading…
Reference in New Issue