Skip to content

Commit

Permalink
Moderated objects unavailable even with visible_until_rejected = True
Browse files Browse the repository at this point in the history
  • Loading branch information
dipen30 committed Oct 12, 2021
1 parent 6909b01 commit 4190488
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 4 deletions.
1 change: 1 addition & 0 deletions moderation/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
MODERATION_STATUS_REJECTED = 0
MODERATION_STATUS_APPROVED = 1
MODERATION_STATUS_PENDING = 2
MODERATION_STATUS_VISIBLE_UNTIL_REJECTED = 3
8 changes: 6 additions & 2 deletions moderation/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from django.db.models.manager import Manager

from . import moderation
from .constants import MODERATION_READY_STATE
from .constants import MODERATION_READY_STATE, MODERATION_STATUS_VISIBLE_UNTIL_REJECTED
from .queryset import ModeratedObjectQuerySet


Expand Down Expand Up @@ -45,7 +45,11 @@ def filter_moderated_objects(self, queryset):
only_ready = {
'_relation_object__state': MODERATION_READY_STATE,
}
return queryset.filter(Q(**only_no_relation_objects) | Q(**only_ready))
visible_until_rejected = {
'_relation_object__status': MODERATION_STATUS_VISIBLE_UNTIL_REJECTED,
}
return queryset.filter(Q(**only_no_relation_objects) | Q(**only_ready)
| Q(**visible_until_rejected))

def exclude_objs_by_visibility_col(self, query_set):
return query_set.exclude(**{self.moderator.visibility_column: False})
Expand Down
18 changes: 18 additions & 0 deletions moderation/migrations/0006_auto_20211012_1311.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 2.2.14 on 2021-10-12 10:11

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('moderation', '0005_auto_20190412_0442'),
]

operations = [
migrations.AlterField(
model_name='moderatedobject',
name='status',
field=models.SmallIntegerField(choices=[(0, 'Rejected'), (1, 'Approved'), (2, 'Pending'), (3, 'Visible until rejected')], default=2, editable=False),
),
]
14 changes: 12 additions & 2 deletions moderation/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@

from . import moderation
from .constants import (MODERATION_DRAFT_STATE, MODERATION_READY_STATE, MODERATION_STATUS_APPROVED,
MODERATION_STATUS_PENDING, MODERATION_STATUS_REJECTED)
MODERATION_STATUS_PENDING, MODERATION_STATUS_REJECTED,
MODERATION_STATUS_VISIBLE_UNTIL_REJECTED)
from .diff import get_changes_between_models
from .fields import SerializedObjectField
from .managers import ModeratedObjectManager
Expand All @@ -24,6 +25,7 @@
(MODERATION_STATUS_REJECTED, 'rejected', _('Rejected')),
(MODERATION_STATUS_APPROVED, 'approved', _('Approved')),
(MODERATION_STATUS_PENDING, 'pending', _('Pending')),
(MODERATION_STATUS_VISIBLE_UNTIL_REJECTED, 'visible_until_rejected', _('Visible until rejected')),
)


Expand Down Expand Up @@ -102,6 +104,8 @@ def automoderate(self, user=None):
self.reject(by=self.by, reason=reason)
elif status == MODERATION_STATUS_APPROVED:
self.approve(by=self.by, reason=reason)
elif self.moderator.visible_until_rejected:
self.visible_until_rejected(by=self.by, reason=reason)
else: # MODERATION_STATUS_PENDING
self.save()

Expand All @@ -119,6 +123,9 @@ def _get_moderation_status_and_reason(self, obj, user):
if reason:
return MODERATION_STATUS_APPROVED, reason

if self.moderator.visible_until_rejected:
return MODERATION_STATUS_VISIBLE_UNTIL_REJECTED, None

return MODERATION_STATUS_PENDING, None

def get_object_for_this_type(self):
Expand Down Expand Up @@ -207,7 +214,7 @@ def _moderate(self, new_status, by, reason):
# inherited visibility_column.
base_object._save_parents(base_object.__class__, None, None)

if self.changed_by:
if self.changed_by and self.status != MODERATION_STATUS_VISIBLE_UNTIL_REJECTED:
self.moderator.inform_user(self.content_object, self.changed_by)

def has_object_been_changed(self, original_obj, only_excluded=False):
Expand All @@ -234,3 +241,6 @@ def approve(self, by=None, reason=None):

def reject(self, by=None, reason=None):
self._send_signals_and_moderate(MODERATION_STATUS_REJECTED, by, reason)

def visible_until_rejected(self, by=None, reason=None):
self._send_signals_and_moderate(MODERATION_STATUS_VISIBLE_UNTIL_REJECTED, by, reason)

0 comments on commit 4190488

Please sign in to comment.