Skip to content
Snippets Groups Projects
Commit 83efb08d authored by Fredrik Jonsson's avatar Fredrik Jonsson
Browse files

Addning new comment visibility options and renaming old ones.

parent 07bab6b5
No related branches found
No related tags found
No related merge requests found
...@@ -12,7 +12,7 @@ class CommentForm(forms.ModelForm): ...@@ -12,7 +12,7 @@ class CommentForm(forms.ModelForm):
model = Activity model = Activity
fields = ('message', 'visibility') fields = ('message', 'visibility')
labels = { labels = {
'visibility': '', 'visibility': 'Visible to',
'message': '', 'message': '',
} }
widgets = { widgets = {
......
# Generated by Django 2.0.13 on 2019-08-26 07:41
from django.db import migrations, models
from opentech.apply.activity.models import COMMENT, APPLICANT, TEAM, ALL
def update_visibility_options(apps, schema_editor):
Activity = apps.get_model('activity', 'Activity')
for comment in Activity.objects.filter(type=COMMENT):
updated = False
if comment.visibility == 'private':
comment.visibility = APPLICANT
updated = True
elif comment.visibility == 'internal':
comment.visibility = TEAM
updated = True
elif comment.visibility == 'public':
comment.visibility = ALL
updated = True
if updated:
comment.save()
class Migration(migrations.Migration):
dependencies = [
('activity', '0025_add_batch_lead_event'),
]
operations = [
migrations.AlterField(
model_name='activity',
name='visibility',
field=models.CharField(choices=[('applicant', 'Applicant(s)'), ('team', 'Team'), ('reviewers', 'Reviewers'), ('partners', 'Partners'), ('all', 'All')], default='applicant', max_length=30),
),
migrations.RunPython(update_visibility_options, migrations.RunPython.noop)
]
...@@ -15,25 +15,31 @@ ACTIVITY_TYPES = { ...@@ -15,25 +15,31 @@ ACTIVITY_TYPES = {
COMMENT: 'Comment', COMMENT: 'Comment',
ACTION: 'Action', ACTION: 'Action',
} }
PRIVATE = 'private'
PUBLIC = 'public' PUBLIC = 'public'
REVIEWER = 'reviewers'
INTERNAL = 'internal' INTERNAL = 'internal'
APPLICANT = 'applicant'
TEAM = 'team'
REVIEWER = 'reviewers'
PARTNER = 'partners'
ALL = 'all'
VISIBILILTY_HELP_TEXT = { VISIBILILTY_HELP_TEXT = {
PRIVATE: 'Visible to applicant and staff.', APPLICANT: 'Visible to applicant and team.',
REVIEWER: 'Visible to reviewers and staff.', TEAM: 'Visible only to team.',
INTERNAL: 'Visible only to staff.', REVIEWER: 'Visible to reviewers and team.',
PUBLIC: 'Visible to all users of the application system.', PARTNER: 'Visible to partners and team.',
ALL: 'Visible to any user who has access to the submission.',
} }
VISIBILITY = { VISIBILITY = {
PRIVATE: 'Private', APPLICANT: 'Applicant(s)',
REVIEWER: 'Reviewers and Staff', TEAM: 'Team',
INTERNAL: 'Internal', REVIEWER: 'Reviewers',
PUBLIC: 'Public', PARTNER: 'Partners',
ALL: 'All',
} }
...@@ -87,7 +93,7 @@ class Activity(models.Model): ...@@ -87,7 +93,7 @@ class Activity(models.Model):
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.PROTECT) user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.PROTECT)
submission = models.ForeignKey('funds.ApplicationSubmission', related_name='activities', on_delete=models.CASCADE) submission = models.ForeignKey('funds.ApplicationSubmission', related_name='activities', on_delete=models.CASCADE)
message = models.TextField() message = models.TextField()
visibility = models.CharField(choices=list(VISIBILITY.items()), default=PUBLIC, max_length=10) visibility = models.CharField(choices=list(VISIBILITY.items()), default=APPLICANT, max_length=30)
# Fields for handling versioning of the comment activity models # Fields for handling versioning of the comment activity models
edited = models.DateTimeField(default=None, null=True) edited = models.DateTimeField(default=None, null=True)
...@@ -110,12 +116,12 @@ class Activity(models.Model): ...@@ -110,12 +116,12 @@ class Activity(models.Model):
@property @property
def priviledged(self): def priviledged(self):
# Not visible to applicant # Not visible to applicant
return self.visibility not in [PUBLIC, PRIVATE] return self.visibility not in [APPLICANT, ALL]
@property @property
def private(self): def private(self):
# not visible to all # not visible to all
return self.visibility not in [PUBLIC] return self.visibility not in [ALL]
def __str__(self): def __str__(self):
return '{}: for "{}"'.format(self.get_type_display(), self.submission) return '{}: for "{}"'.format(self.get_type_display(), self.submission)
...@@ -123,10 +129,13 @@ class Activity(models.Model): ...@@ -123,10 +129,13 @@ class Activity(models.Model):
@classmethod @classmethod
def visibility_for(cls, user): def visibility_for(cls, user):
if user.is_apply_staff: if user.is_apply_staff:
return [PRIVATE, REVIEWER, INTERNAL, PUBLIC] return [APPLICANT, TEAM, REVIEWER, PARTNER, ALL]
if user.is_reviewer: if user.is_reviewer:
return [REVIEWER, PUBLIC] return [REVIEWER, ALL]
return [PRIVATE, PUBLIC] if user.is_partner:
return [PARTNER, ALL]
return [APPLICANT, ALL]
@classmethod @classmethod
def visibility_choices_for(cls, user): def visibility_choices_for(cls, user):
......
...@@ -5,7 +5,7 @@ from django import template ...@@ -5,7 +5,7 @@ from django import template
from opentech.apply.determinations.models import Determination from opentech.apply.determinations.models import Determination
from opentech.apply.review.models import Review from opentech.apply.review.models import Review
from ..models import INTERNAL, PUBLIC, REVIEWER from ..models import INTERNAL, TEAM, PUBLIC, REVIEWER
register = template.Library() register = template.Library()
...@@ -40,7 +40,7 @@ def display_for(activity, user): ...@@ -40,7 +40,7 @@ def display_for(activity, user):
visibile_for_user = activity.visibility_for(user) visibile_for_user = activity.visibility_for(user)
if set(visibile_for_user) & set([INTERNAL, REVIEWER]): if set(visibile_for_user) & set([TEAM, REVIEWER]):
return message_data[INTERNAL] return message_data[INTERNAL]
return message_data[PUBLIC] return message_data[PUBLIC]
from django.test import TestCase, override_settings from django.test import TestCase, override_settings
from django.urls import reverse_lazy from django.urls import reverse_lazy
from opentech.apply.activity.models import Activity, PUBLIC, PRIVATE from opentech.apply.activity.models import Activity, APPLICANT, ALL
from opentech.apply.activity.tests.factories import CommentFactory from opentech.apply.activity.tests.factories import CommentFactory
from opentech.apply.users.tests.factories import UserFactory from opentech.apply.users.tests.factories import UserFactory
...@@ -55,7 +55,7 @@ class TestCommentEdit(TestCase): ...@@ -55,7 +55,7 @@ class TestCommentEdit(TestCase):
def test_cant_change_visibility(self): def test_cant_change_visibility(self):
user = UserFactory() user = UserFactory()
comment = CommentFactory(user=user, visibility=PRIVATE) comment = CommentFactory(user=user, visibility=APPLICANT)
self.client.force_login(user) self.client.force_login(user)
response = self.client.post( response = self.client.post(
...@@ -63,12 +63,12 @@ class TestCommentEdit(TestCase): ...@@ -63,12 +63,12 @@ class TestCommentEdit(TestCase):
secure=True, secure=True,
data={ data={
'message': 'the new message', 'message': 'the new message',
'visibility': PUBLIC, 'visibility': ALL,
}, },
) )
self.assertEqual(response.status_code, 200, response.json()) self.assertEqual(response.status_code, 200, response.json())
self.assertEqual(response.json()['visibility'], PRIVATE) self.assertEqual(response.json()['visibility'], APPLICANT)
def test_out_of_order_does_nothing(self): def test_out_of_order_does_nothing(self):
user = UserFactory() user = UserFactory()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment