Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ks 2021 add classification when report is sent #91

Merged
merged 2 commits into from
Apr 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion adhocracy-plus/config/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
from adhocracy4.comments_async.api import CommentViewSet
from adhocracy4.follows.api import FollowViewSet
from adhocracy4.ratings.api import RatingViewSet
from adhocracy4.reports.api import ReportViewSet
from apps.contrib import views as contrib_views
from apps.contrib.sitemaps import static_sitemap_index
from apps.documents.api import DocumentViewSet
Expand All @@ -34,6 +33,7 @@
from apps.polls.api import VoteViewSet
from apps.polls.routers import QuestionDefaultRouter
from apps.projects.api import ProjectViewSet
from apps.reports.api import ReportViewSet
from apps.users.decorators import user_is_project_admin

router = routers.DefaultRouter()
Expand Down
2 changes: 1 addition & 1 deletion apps/classifications/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

from . import models

# admin.site.register(models.UserClassification)
admin.site.register(models.UserClassification)
admin.site.register(models.AIClassification)
34 changes: 34 additions & 0 deletions apps/classifications/migrations/0002_userclassification.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Generated by Django 2.2.19 on 2021-04-07 13:41

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
import django.utils.timezone


class Migration(migrations.Migration):

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('a4comments', '0007_comment_is_moderator_marked'),
('a4_candy_classifications', '0001_initial'),
]

operations = [
migrations.CreateModel(
name='UserClassification',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('created', models.DateTimeField(default=django.utils.timezone.now, editable=False)),
('modified', models.DateTimeField(blank=True, editable=False, null=True)),
('classification', models.CharField(choices=[('OFFENSIVE', 'Offensive'), ('OTHER', 'Other')], max_length=50)),
('comment_text', models.TextField(max_length=4000)),
('user_message', models.TextField(max_length=1024)),
('comment', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='a4comments.Comment')),
('creator', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
options={
'abstract': False,
},
),
]
12 changes: 0 additions & 12 deletions apps/classifications/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,9 @@ def save(self, *args, **kwargs):
super().save(*args, **kwargs)


"""
We use the a4 reports for user classifications for now
until we decided on a final reporting/classification procedure.
Since we would have to disconnect reports and instead connect
UserClassification to the comments, this seemed too complicated
without a clear goal.
The reports can then be shown in moderation dashboard without
a classification.
"""

"""
class UserClassification(Classification, base.UserGeneratedContentModel):

user_message = models.TextField(max_length=1024)
"""


class AIClassification(Classification, base.TimeStampedModel):
Expand Down
38 changes: 38 additions & 0 deletions apps/reports/api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from django.contrib.contenttypes.models import ContentType
from rest_framework import mixins
from rest_framework import permissions
from rest_framework import viewsets

from adhocracy4.comments.models import Comment
from adhocracy4.reports import emails
from adhocracy4.reports.models import Report
from adhocracy4.reports.serializers import ReportSerializer
from apps.classifications.models import UserClassification

'''
overwrites ReportViewSet from adhocracy4 in order to
save a UserClassification object every time a comment is
reported
'''


class ReportViewSet(mixins.CreateModelMixin,
viewsets.GenericViewSet):

serializer_class = ReportSerializer
queryset = Report.objects.all()
permission_classes = (permissions.IsAuthenticated,)

def perform_create(self, serializer):
report = serializer.save(creator=self.request.user)
emails.ReportModeratorEmail.send(report)
if serializer.data['content_type'] == \
ContentType.objects.get(app_label='a4comments',
model='comment').pk:

classification = UserClassification(
creator=self.request.user,
comment=Comment.objects.get(pk=serializer.data['object_pk']),
classification='OFFENSIVE',
user_message=serializer.data['description'])
classification.save()