Fix resolve endpoint to work with epics
parent
5d5a42a077
commit
0d3de76c8e
|
@ -88,7 +88,6 @@ class Epic(OCCModelMixin, WatchedModelMixin, BlockedMixin, TaggedMixin, models.M
|
|||
return "<Epic %s>" % (self.id)
|
||||
|
||||
|
||||
|
||||
class RelatedUserStory(models.Model):
|
||||
user_story = models.ForeignKey("userstories.UserStory", on_delete=models.CASCADE)
|
||||
epic = models.ForeignKey("epics.Epic", on_delete=models.CASCADE)
|
||||
|
|
|
@ -45,6 +45,9 @@ class ResolverViewSet(viewsets.ViewSet):
|
|||
|
||||
result = {"project": project.pk}
|
||||
|
||||
if data["epic"] and user_has_perm(request.user, "view_epics", project):
|
||||
result["epic"] = get_object_or_404(project.epics.all(),
|
||||
ref=data["epic"]).pk
|
||||
if data["us"] and user_has_perm(request.user, "view_us", project):
|
||||
result["us"] = get_object_or_404(project.user_stories.all(),
|
||||
ref=data["us"]).pk
|
||||
|
@ -63,6 +66,11 @@ class ResolverViewSet(viewsets.ViewSet):
|
|||
|
||||
if data["ref"]:
|
||||
ref_found = False # No need to continue once one ref is found
|
||||
if ref_found is False and user_has_perm(request.user, "view_epics", project):
|
||||
epic = project.epics.filter(ref=data["ref"]).first()
|
||||
if epic:
|
||||
result["epic"] = epic.pk
|
||||
ref_found = True
|
||||
if user_has_perm(request.user, "view_us", project):
|
||||
us = project.user_stories.filter(ref=data["ref"]).first()
|
||||
if us:
|
||||
|
|
|
@ -24,6 +24,7 @@ from taiga.base.exceptions import ValidationError
|
|||
class ResolverValidator(validators.Validator):
|
||||
project = serializers.CharField(max_length=512, required=True)
|
||||
milestone = serializers.CharField(max_length=512, required=False)
|
||||
epic = serializers.IntegerField(required=False)
|
||||
us = serializers.IntegerField(required=False)
|
||||
task = serializers.IntegerField(required=False)
|
||||
issue = serializers.IntegerField(required=False)
|
||||
|
@ -32,6 +33,8 @@ class ResolverValidator(validators.Validator):
|
|||
|
||||
def validate(self, attrs):
|
||||
if "ref" in attrs:
|
||||
if "epic" in attrs:
|
||||
raise ValidationError("'epic' param is incompatible with 'ref' in the same request")
|
||||
if "us" in attrs:
|
||||
raise ValidationError("'us' param is incompatible with 'ref' in the same request")
|
||||
if "task" in attrs:
|
||||
|
|
Loading…
Reference in New Issue