Commit 2b4429c0 authored by Florent Chehab's avatar Florent Chehab

Bug corrected when testing if moderation is required and validating tagged item data

parent a938e15d
Pipeline #27146 passed with stages
in 2 minutes and 38 seconds
......@@ -7,5 +7,49 @@
"required": true
}
}
},
{
"name": "insurance",
"config": {}
},
{
"name": "transport",
"config": {}
},
{
"name": "accomodation",
"config": {}
},
{
"name": "student_life",
"config": {}
},
{
"name": "everyday_life",
"config": {}
},
{
"name": "other",
"config": {}
},
{
"name": "administrative",
"config": {}
},
{
"name": "culture",
"config": {}
},
{
"name": "tourism",
"config": {}
},
{
"name": "shared_comment",
"config": {}
},
{
"name": "specific_partnership",
"config": {}
}
]
\ No newline at end of file
# Generated by Django 2.0.3 on 2018-09-10 15:00
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('backend', '0001_initial'),
]
operations = [
migrations.AddField(
model_name='campustaggeditem',
name='title',
field=models.CharField(default='', max_length=150),
),
migrations.AddField(
model_name='citytaggeditem',
name='title',
field=models.CharField(default='', max_length=150),
),
migrations.AddField(
model_name='countrytaggeditem',
name='title',
field=models.CharField(default='', max_length=150),
),
migrations.AddField(
model_name='universitytaggeditem',
name='title',
field=models.CharField(default='', max_length=150),
),
]
# Generated by Django 2.0.3 on 2018-09-10 15:31
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('backend', '0002_auto_20180910_1700'),
]
operations = [
migrations.AlterField(
model_name='campustaggeditem',
name='comment',
field=models.TextField(blank=True, default=''),
),
migrations.AlterField(
model_name='citytaggeditem',
name='comment',
field=models.TextField(blank=True, default=''),
),
migrations.AlterField(
model_name='countrydri',
name='comment',
field=models.TextField(blank=True, default=''),
),
migrations.AlterField(
model_name='countryscholarship',
name='comment',
field=models.TextField(blank=True, default=''),
),
migrations.AlterField(
model_name='countrytaggeditem',
name='comment',
field=models.TextField(blank=True, default=''),
),
migrations.AlterField(
model_name='universitydri',
name='comment',
field=models.TextField(blank=True, default=''),
),
migrations.AlterField(
model_name='universityinfo',
name='comment',
field=models.TextField(blank=True, default=''),
),
migrations.AlterField(
model_name='universityscholarship',
name='comment',
field=models.TextField(blank=True, default=''),
),
migrations.AlterField(
model_name='universitysemestersdates',
name='comment',
field=models.TextField(blank=True, default=''),
),
migrations.AlterField(
model_name='universitytaggeditem',
name='comment',
field=models.TextField(blank=True, default=''),
),
]
......@@ -13,7 +13,7 @@ IMPORTANCE_LEVEL = (
class BasicModule(MyModelVersionned):
comment = models.TextField(blank=True)
comment = models.TextField(blank=True, default="")
usefull_links = JSONField(default=list)
importance_level = models.CharField(
max_length=2,
......
......@@ -7,6 +7,7 @@ from backend.fields import JSONField
class TaggedItem(BasicModule):
tag = models.ForeignKey(Tag, related_name='+', on_delete=models.PROTECT)
title = models.CharField(default="", max_length=150)
custom_content = JSONField(default=dict)
class Meta:
......
from backend.utils import get_user_level
from backend.utils.get_user_level import get_user_level
from django.conf import settings
from .obj_moderation_permission import OBJ_MODERATION_PERMISSIONS
......@@ -18,11 +18,11 @@ def is_moderation_required(model_moderation_level, obj_in_db, user, user_level=N
if model_moderation_level == 1:
if settings.MODERATION_ACTIVATED:
return user_level < OBJ_MODERATION_PERMISSIONS["moderator"]
return not user_level >= OBJ_MODERATION_PERMISSIONS["moderator"]
else:
return False
elif model_moderation_level == 2:
return not user_level < OBJ_MODERATION_PERMISSIONS["moderator"]
return not user_level >= OBJ_MODERATION_PERMISSIONS["moderator"]
else:
raise Exception(
"No other moderation level should be defined...")
from django.test import override_settings
from .withUserTestCase import WithUserTestCase
from backend.permissions import is_moderation_required
class IsModerationActivatedTestCase(WithUserTestCase):
@override_settings(MODERATION_ACTIVATED=True)
def test_is_moderation_1(self):
self.assertFalse(is_moderation_required(2, None, self.staff_user))
self.assertFalse(is_moderation_required(2, None, self.staff_user, 3))
@override_settings(MODERATION_ACTIVATED=False)
def test_is_moderation_2(self):
self.assertFalse(is_moderation_required(2, None, self.staff_user))
self.assertFalse(is_moderation_required(2, None, self.staff_user, 3))
from .url import validate_url # noqa: F401
from .text import validate_text # noqa: F401
from .tagged_item_validation import validate_content_against_config # noqa: F401
from .tagged_item_validation import validate_content_against_config, tagged_item_validation # noqa: F401
......@@ -8,7 +8,11 @@ from .tags_config import USEFULL_LINKS_CONFIG
def tagged_item_validation(attrs):
tag_config = attrs["tag"].config
sumbitted_content = attrs["custom_content"]
try:
sumbitted_content = attrs["custom_content"]
except KeyError:
assert len(tag_config.keys()) == 0
return True
validate_content_against_config(tag_config, sumbitted_content)
......@@ -42,35 +46,3 @@ def validate_content_against_config(config, content):
validate_content_against_config(field_config['content'], item)
else:
raise Exception("Dev, you have implement something here...")
# my_tag_config = {
# "url": {
# "type": "url",
# "required": True,
# "validators": {
# "extension": ["jpg", "jpeg", "png"]
# },
# },
# "title": {
# "type": "text",
# "required": True,
# "validators": {
# "max_length": 200
# }
# },
# "description": {
# "required": False,
# "type": "text",
# "validators": {
# "max_length": 500
# }
# },
# "licence": {
# "type": "text",
# "required": False,
# "validators": {
# "max_length": 200
# }
# }
# }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment