Merge pull request #920 from taigaio/attachments-on-comment
Add from_comment field to attachments and allow attach files from commentsremotes/origin/github-import
commit
1303a4622f
|
@ -0,0 +1,20 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Generated by Django 1.10.4 on 2017-01-17 07:45
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('attachments', '0006_auto_20160617_1233'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='attachment',
|
||||||
|
name='from_comment',
|
||||||
|
field=models.BooleanField(default=False, verbose_name='from_comment'),
|
||||||
|
),
|
||||||
|
]
|
|
@ -58,6 +58,7 @@ class Attachment(models.Model):
|
||||||
sha1 = models.CharField(default="", max_length=40, verbose_name=_("sha1"), blank=True)
|
sha1 = models.CharField(default="", max_length=40, verbose_name=_("sha1"), blank=True)
|
||||||
|
|
||||||
is_deprecated = models.BooleanField(default=False, verbose_name=_("is deprecated"))
|
is_deprecated = models.BooleanField(default=False, verbose_name=_("is deprecated"))
|
||||||
|
from_comment = models.BooleanField(default=False, verbose_name=_("from_comment"))
|
||||||
description = models.TextField(null=False, blank=True, verbose_name=_("description"))
|
description = models.TextField(null=False, blank=True, verbose_name=_("description"))
|
||||||
order = models.IntegerField(default=0, null=False, blank=False, verbose_name=_("order"))
|
order = models.IntegerField(default=0, null=False, blank=False, verbose_name=_("order"))
|
||||||
|
|
||||||
|
|
|
@ -27,10 +27,16 @@ class IsAttachmentOwnerPerm(PermissionComponent):
|
||||||
return request.user == obj.owner
|
return request.user == obj.owner
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
class CommentAttachmentPerm(PermissionComponent):
|
||||||
|
def check_permissions(self, request, view, obj=None):
|
||||||
|
if obj.from_comment:
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
class EpicAttachmentPermission(TaigaResourcePermission):
|
class EpicAttachmentPermission(TaigaResourcePermission):
|
||||||
retrieve_perms = HasProjectPerm('view_epics') | IsAttachmentOwnerPerm()
|
retrieve_perms = HasProjectPerm('view_epics') | IsAttachmentOwnerPerm()
|
||||||
create_perms = HasProjectPerm('modify_epic')
|
create_perms = HasProjectPerm('modify_epic') | (CommentAttachmentPerm() & HasProjectPerm('comment_epic'))
|
||||||
update_perms = HasProjectPerm('modify_epic') | IsAttachmentOwnerPerm()
|
update_perms = HasProjectPerm('modify_epic') | IsAttachmentOwnerPerm()
|
||||||
partial_update_perms = HasProjectPerm('modify_epic') | IsAttachmentOwnerPerm()
|
partial_update_perms = HasProjectPerm('modify_epic') | IsAttachmentOwnerPerm()
|
||||||
destroy_perms = HasProjectPerm('modify_epic') | IsAttachmentOwnerPerm()
|
destroy_perms = HasProjectPerm('modify_epic') | IsAttachmentOwnerPerm()
|
||||||
|
@ -39,7 +45,7 @@ class EpicAttachmentPermission(TaigaResourcePermission):
|
||||||
|
|
||||||
class UserStoryAttachmentPermission(TaigaResourcePermission):
|
class UserStoryAttachmentPermission(TaigaResourcePermission):
|
||||||
retrieve_perms = HasProjectPerm('view_us') | IsAttachmentOwnerPerm()
|
retrieve_perms = HasProjectPerm('view_us') | IsAttachmentOwnerPerm()
|
||||||
create_perms = HasProjectPerm('modify_us')
|
create_perms = HasProjectPerm('modify_us') | (CommentAttachmentPerm() & HasProjectPerm('comment_us'))
|
||||||
update_perms = HasProjectPerm('modify_us') | IsAttachmentOwnerPerm()
|
update_perms = HasProjectPerm('modify_us') | IsAttachmentOwnerPerm()
|
||||||
partial_update_perms = HasProjectPerm('modify_us') | IsAttachmentOwnerPerm()
|
partial_update_perms = HasProjectPerm('modify_us') | IsAttachmentOwnerPerm()
|
||||||
destroy_perms = HasProjectPerm('modify_us') | IsAttachmentOwnerPerm()
|
destroy_perms = HasProjectPerm('modify_us') | IsAttachmentOwnerPerm()
|
||||||
|
@ -48,7 +54,7 @@ class UserStoryAttachmentPermission(TaigaResourcePermission):
|
||||||
|
|
||||||
class TaskAttachmentPermission(TaigaResourcePermission):
|
class TaskAttachmentPermission(TaigaResourcePermission):
|
||||||
retrieve_perms = HasProjectPerm('view_tasks') | IsAttachmentOwnerPerm()
|
retrieve_perms = HasProjectPerm('view_tasks') | IsAttachmentOwnerPerm()
|
||||||
create_perms = HasProjectPerm('modify_task')
|
create_perms = HasProjectPerm('modify_task') | (CommentAttachmentPerm() & HasProjectPerm('comment_task'))
|
||||||
update_perms = HasProjectPerm('modify_task') | IsAttachmentOwnerPerm()
|
update_perms = HasProjectPerm('modify_task') | IsAttachmentOwnerPerm()
|
||||||
partial_update_perms = HasProjectPerm('modify_task') | IsAttachmentOwnerPerm()
|
partial_update_perms = HasProjectPerm('modify_task') | IsAttachmentOwnerPerm()
|
||||||
destroy_perms = HasProjectPerm('modify_task') | IsAttachmentOwnerPerm()
|
destroy_perms = HasProjectPerm('modify_task') | IsAttachmentOwnerPerm()
|
||||||
|
@ -57,7 +63,7 @@ class TaskAttachmentPermission(TaigaResourcePermission):
|
||||||
|
|
||||||
class IssueAttachmentPermission(TaigaResourcePermission):
|
class IssueAttachmentPermission(TaigaResourcePermission):
|
||||||
retrieve_perms = HasProjectPerm('view_issues') | IsAttachmentOwnerPerm()
|
retrieve_perms = HasProjectPerm('view_issues') | IsAttachmentOwnerPerm()
|
||||||
create_perms = HasProjectPerm('modify_issue')
|
create_perms = HasProjectPerm('modify_issue') | (CommentAttachmentPerm() & HasProjectPerm('comment_issue'))
|
||||||
update_perms = HasProjectPerm('modify_issue') | IsAttachmentOwnerPerm()
|
update_perms = HasProjectPerm('modify_issue') | IsAttachmentOwnerPerm()
|
||||||
partial_update_perms = HasProjectPerm('modify_issue') | IsAttachmentOwnerPerm()
|
partial_update_perms = HasProjectPerm('modify_issue') | IsAttachmentOwnerPerm()
|
||||||
destroy_perms = HasProjectPerm('modify_issue') | IsAttachmentOwnerPerm()
|
destroy_perms = HasProjectPerm('modify_issue') | IsAttachmentOwnerPerm()
|
||||||
|
@ -66,7 +72,7 @@ class IssueAttachmentPermission(TaigaResourcePermission):
|
||||||
|
|
||||||
class WikiAttachmentPermission(TaigaResourcePermission):
|
class WikiAttachmentPermission(TaigaResourcePermission):
|
||||||
retrieve_perms = HasProjectPerm('view_wiki_pages') | IsAttachmentOwnerPerm()
|
retrieve_perms = HasProjectPerm('view_wiki_pages') | IsAttachmentOwnerPerm()
|
||||||
create_perms = HasProjectPerm('modify_wiki_page')
|
create_perms = HasProjectPerm('modify_wiki_page') | (CommentAttachmentPerm() & HasProjectPerm('comment_wiki_page'))
|
||||||
update_perms = HasProjectPerm('modify_wiki_page') | IsAttachmentOwnerPerm()
|
update_perms = HasProjectPerm('modify_wiki_page') | IsAttachmentOwnerPerm()
|
||||||
partial_update_perms = HasProjectPerm('modify_wiki_page') | IsAttachmentOwnerPerm()
|
partial_update_perms = HasProjectPerm('modify_wiki_page') | IsAttachmentOwnerPerm()
|
||||||
destroy_perms = HasProjectPerm('modify_wiki_page') | IsAttachmentOwnerPerm()
|
destroy_perms = HasProjectPerm('modify_wiki_page') | IsAttachmentOwnerPerm()
|
||||||
|
|
|
@ -35,6 +35,7 @@ class AttachmentSerializer(serializers.LightSerializer):
|
||||||
url = Field()
|
url = Field()
|
||||||
description = Field()
|
description = Field()
|
||||||
is_deprecated = Field()
|
is_deprecated = Field()
|
||||||
|
from_comment = Field()
|
||||||
created_date = Field()
|
created_date = Field()
|
||||||
modified_date = Field()
|
modified_date = Field()
|
||||||
object_id = Field()
|
object_id = Field()
|
||||||
|
|
|
@ -29,5 +29,5 @@ class AttachmentValidator(validators.ModelValidator):
|
||||||
model = models.Attachment
|
model = models.Attachment
|
||||||
fields = ("id", "project", "owner", "name", "attached_file", "size",
|
fields = ("id", "project", "owner", "name", "attached_file", "size",
|
||||||
"description", "is_deprecated", "created_date",
|
"description", "is_deprecated", "created_date",
|
||||||
"modified_date", "object_id", "order", "sha1")
|
"modified_date", "object_id", "order", "sha1", "from_comment")
|
||||||
read_only_fields = ("owner", "created_date", "modified_date", "sha1")
|
read_only_fields = ("owner", "created_date", "modified_date", "sha1")
|
||||||
|
|
|
@ -1027,3 +1027,67 @@ def test_wiki_attachment_list(client, data, data_wiki):
|
||||||
|
|
||||||
results = helper_test_http_method_and_count(client, 'get', url, None, users)
|
results = helper_test_http_method_and_count(client, 'get', url, None, users)
|
||||||
assert results == [(200, 2), (200, 2), (200, 2), (200, 4), (200, 4)]
|
assert results == [(200, 2), (200, 2), (200, 2), (200, 4), (200, 4)]
|
||||||
|
|
||||||
|
|
||||||
|
def test_create_attachment_by_external_user_without_comment_permission(client):
|
||||||
|
issue = f.create_issue()
|
||||||
|
user = f.UserFactory()
|
||||||
|
|
||||||
|
assert issue.owner != user
|
||||||
|
assert issue.project.owner != user
|
||||||
|
|
||||||
|
url = reverse("issue-attachments-list")
|
||||||
|
|
||||||
|
data = {"description": "test",
|
||||||
|
"object_id": issue.pk,
|
||||||
|
"project": issue.project.id,
|
||||||
|
"attached_file": SimpleUploadedFile("test.txt", b"test"),
|
||||||
|
"from_comment": True}
|
||||||
|
|
||||||
|
client.login(user)
|
||||||
|
response = client.post(url, data)
|
||||||
|
assert response.status_code == 403
|
||||||
|
|
||||||
|
|
||||||
|
def test_create_attachment_by_external_user_with_comment_permission_but_without_from_comment_flag(client):
|
||||||
|
project = f.ProjectFactory(public_permissions=['comment_issue'])
|
||||||
|
issue = f.create_issue(project=project)
|
||||||
|
|
||||||
|
user = f.UserFactory()
|
||||||
|
|
||||||
|
assert issue.owner != user
|
||||||
|
assert issue.project.owner != user
|
||||||
|
|
||||||
|
url = reverse("issue-attachments-list")
|
||||||
|
|
||||||
|
data = {"description": "test",
|
||||||
|
"object_id": issue.pk,
|
||||||
|
"project": issue.project.id,
|
||||||
|
"attached_file": SimpleUploadedFile("test.txt", b"test"),
|
||||||
|
"from_comment": False}
|
||||||
|
|
||||||
|
client.login(user)
|
||||||
|
response = client.post(url, data)
|
||||||
|
assert response.status_code == 403
|
||||||
|
|
||||||
|
|
||||||
|
def test_create_attachment_by_external_user_with_comment_permission_and_with_from_comment_flag(client):
|
||||||
|
project = f.ProjectFactory(public_permissions=['comment_issue'])
|
||||||
|
issue = f.create_issue(project=project)
|
||||||
|
|
||||||
|
user = f.UserFactory()
|
||||||
|
|
||||||
|
assert issue.owner != user
|
||||||
|
assert issue.project.owner != user
|
||||||
|
|
||||||
|
url = reverse("issue-attachments-list")
|
||||||
|
|
||||||
|
data = {"description": "test",
|
||||||
|
"object_id": issue.pk,
|
||||||
|
"project": issue.project.id,
|
||||||
|
"attached_file": SimpleUploadedFile("test.txt", b"test"),
|
||||||
|
"from_comment": True}
|
||||||
|
|
||||||
|
client.login(user)
|
||||||
|
response = client.post(url, data)
|
||||||
|
assert response.status_code == 201
|
||||||
|
|
Loading…
Reference in New Issue