From 587ed96a92deb9daf6ce4a40ba544e8b5ee06ae2 Mon Sep 17 00:00:00 2001 From: rodrigocam Date: Tue, 6 Nov 2018 22:01:21 -0200 Subject: [PATCH 01/29] Fix promoted conversations add route permission --- src/ej_conversations/routes/admin.py | 6 +++++- src/ej_conversations/rules.py | 6 +++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/ej_conversations/routes/admin.py b/src/ej_conversations/routes/admin.py index 826143c59..68994af74 100644 --- a/src/ej_conversations/routes/admin.py +++ b/src/ej_conversations/routes/admin.py @@ -10,8 +10,12 @@ log = getLogger('ej') -@urlpatterns.route('add/', login=True, perms=['ej.can_add_promoted_conversation']) +@urlpatterns.route('add/') def create(request): + #TODO: Fix this case of permission in django-boogie + if not request.user.has_perm('ej.can_add_promoted_conversation'): + raise Http404 + form = forms.ConversationForm(request.POST or None) if request.method == 'POST' and form.is_valid(): with transaction.atomic(): diff --git a/src/ej_conversations/rules.py b/src/ej_conversations/rules.py index 2b5878748..4c0fefa79 100644 --- a/src/ej_conversations/rules.py +++ b/src/ej_conversations/rules.py @@ -146,14 +146,14 @@ def can_comment(user, conversation): @rules.register_perm('ej.can_add_promoted_conversation') -def can_add_promoted_conversation(user, conversation): +def can_add_promoted_conversation(user): """ - Check if user can comment in conversation. + Check if user can add a promoted conversation * Has explicit 'ej_conversations.can_publish_promoted' permission stored in the db. """ - return user.has_perm('ej_conversations.can_publish_promoted', conversation) + return user.has_perm('ej_conversations.can_publish_promoted') @rules.register_perm('ej.can_edit_conversation') From 038adbffbf9c783051dd552362195d322d5d1499 Mon Sep 17 00:00:00 2001 From: rodrigocam Date: Tue, 6 Nov 2018 22:51:17 -0200 Subject: [PATCH 02/29] Fix broken tests --- src/ej_conversations/routes/admin.py | 4 ++-- src/ej_conversations/tests/conftest.py | 4 ++++ src/ej_conversations/tests/test_routes.py | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/ej_conversations/routes/admin.py b/src/ej_conversations/routes/admin.py index 68994af74..b899b3d72 100644 --- a/src/ej_conversations/routes/admin.py +++ b/src/ej_conversations/routes/admin.py @@ -10,9 +10,9 @@ log = getLogger('ej') -@urlpatterns.route('add/') +@urlpatterns.route('add/', login=True) def create(request): - #TODO: Fix this case of permission in django-boogie + # TODO: Fix this case of permission in django-boogie if not request.user.has_perm('ej.can_add_promoted_conversation'): raise Http404 diff --git a/src/ej_conversations/tests/conftest.py b/src/ej_conversations/tests/conftest.py index b543bd832..f8cceecbc 100644 --- a/src/ej_conversations/tests/conftest.py +++ b/src/ej_conversations/tests/conftest.py @@ -12,6 +12,10 @@ def user(db): user = User.objects.create_user('email@server.com', 'password') user.board_name = 'testboard' + + # TODO: Fix this dirty way to set user permissions + user.has_perm = lambda x, y=None: True + user.save() return user diff --git a/src/ej_conversations/tests/test_routes.py b/src/ej_conversations/tests/test_routes.py index caa3a809f..9e585c09a 100644 --- a/src/ej_conversations/tests/test_routes.py +++ b/src/ej_conversations/tests/test_routes.py @@ -9,7 +9,7 @@ class TestRoutes(UrlTester, ConversationRecipes): '/conversations/', '/conversations/conversation/', ] - login_urls = [ + admin_urls = [ '/conversations/add/', ] owner_urls = [ From bbeea65065d712d3cc4db2ae35072a27842da803 Mon Sep 17 00:00:00 2001 From: rodrigocam Date: Wed, 7 Nov 2018 11:55:03 -0200 Subject: [PATCH 03/29] Add is_hidden to field to conversation --- src/ej_boards/routes.py | 2 +- src/ej_conversations/admin.py | 8 ++++---- src/ej_conversations/models/conversation.py | 8 ++++++++ src/ej_conversations/routes/conversations.py | 2 +- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/ej_boards/routes.py b/src/ej_boards/routes.py index 4263759c9..847068af2 100644 --- a/src/ej_boards/routes.py +++ b/src/ej_boards/routes.py @@ -40,7 +40,7 @@ @urlpatterns.route('/conversations/') def conversation_list(request, board): user = request.user - conversations = board.conversations.all() + conversations = board.conversations.filter(is_hidden=False) board_user = board.owner boards = [] boards_count = 0 diff --git a/src/ej_conversations/admin.py b/src/ej_conversations/admin.py index 8fc920f22..037d19c39 100644 --- a/src/ej_conversations/admin.py +++ b/src/ej_conversations/admin.py @@ -36,7 +36,7 @@ class CommentAdmin(AuthorIsUserMixin, admin.ModelAdmin): @admin.register(models.Conversation) class ConversationAdmin(AuthorIsUserMixin, admin.ModelAdmin): - fields = ['title', 'text', 'is_promoted'] - list_display = ['title', 'slug', 'author', 'created', 'is_promoted'] - list_filter = ['created', 'is_promoted'] - list_editable = ['is_promoted'] + fields = ['title', 'text', 'is_promoted', 'is_hidden'] + list_display = ['title', 'slug', 'author', 'created', 'is_promoted', 'is_hidden'] + list_filter = ['created', 'is_promoted', 'is_hidden'] + list_editable = ['is_promoted', 'is_hidden'] diff --git a/src/ej_conversations/models/conversation.py b/src/ej_conversations/models/conversation.py index a2e067c1c..50df59f19 100644 --- a/src/ej_conversations/models/conversation.py +++ b/src/ej_conversations/models/conversation.py @@ -67,6 +67,14 @@ class Conversation(TimeStampedModel): 'endpoint.' ), ) + is_hidden = models.BooleanField( + _('hidden?'), + default=False, + help_text=_( + 'Hidden conversations does not appears in boards or in the main /conversations/ ' + 'endpoint.' + ), + ) objects = ConversationManager() tags = TaggableManager(through='ConversationTag') diff --git a/src/ej_conversations/routes/conversations.py b/src/ej_conversations/routes/conversations.py index 58025a9f0..65292c340 100644 --- a/src/ej_conversations/routes/conversations.py +++ b/src/ej_conversations/routes/conversations.py @@ -17,7 +17,7 @@ @urlpatterns.route('', name='list') def conversation_list(request): return { - 'conversations': Conversation.objects.filter(is_promoted=True), + 'conversations': Conversation.objects.filter(is_promoted=True, is_hidden=False), 'can_add_conversation': request.user.has_perm('ej.can_add_promoted_conversation'), 'create_url': reverse('conversation:create'), 'topic': _('A space for adolescents to discuss actions that promote, guarantee and defend their rights'), From b869de3b8174bb431cbdff7f78439ad4b41d98f1 Mon Sep 17 00:00:00 2001 From: pablodiegoss Date: Wed, 7 Nov 2018 12:18:35 -0200 Subject: [PATCH 04/29] Create migration to update conversation fields --- .../migrations/0004_update_fields.py | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/ej_conversations/migrations/0004_update_fields.py diff --git a/src/ej_conversations/migrations/0004_update_fields.py b/src/ej_conversations/migrations/0004_update_fields.py new file mode 100644 index 000000000..2afaef2f2 --- /dev/null +++ b/src/ej_conversations/migrations/0004_update_fields.py @@ -0,0 +1,40 @@ +# Generated by Django 2.1.2 on 2018-11-07 14:03 + +import django.core.validators +from django.db import migrations, models +import ej_conversations.validators + + +class Migration(migrations.Migration): + + dependencies = [ + ('ej_conversations', '0003_conversation_hidden'), + ] + + operations = [ + migrations.RemoveField( + model_name='taggedconversation', + name='content_object', + ), + migrations.RemoveField( + model_name='taggedconversation', + name='tag', + ), + migrations.RemoveField( + model_name='conversation', + name='hidden', + ), + migrations.AddField( + model_name='conversation', + name='is_hidden', + field=models.BooleanField(default=False, help_text='Hidden conversations does not appears in boards or in the main /conversations/ endpoint.', verbose_name='hidden?'), + ), + migrations.AlterField( + model_name='comment', + name='content', + field=models.TextField(help_text='Body of text for the comment', max_length=252, validators=[django.core.validators.MinLengthValidator(2), ej_conversations.validators.is_not_empty], verbose_name='Content'), + ), + migrations.DeleteModel( + name='TaggedConversation', + ), + ] From 67084f2d3e247edd827f7c16caafeb28e0ad63d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fab=C3=ADola=20Fleury?= Date: Wed, 7 Nov 2018 19:57:30 -0200 Subject: [PATCH 05/29] Adding return link to board from any conversation --- .../jinja2/components/generic/page_header.jinja2 | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/ej/templates/jinja2/components/generic/page_header.jinja2 b/src/ej/templates/jinja2/components/generic/page_header.jinja2 index 7785c6f1f..bf84f1081 100644 --- a/src/ej/templates/jinja2/components/generic/page_header.jinja2 +++ b/src/ej/templates/jinja2/components/generic/page_header.jinja2 @@ -61,10 +61,15 @@ {% endblock %}