Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Julien Jerphanion
Rex Dri
Commits
2b4429c0
Commit
2b4429c0
authored
Sep 10, 2018
by
Florent Chehab
Browse files
Bug corrected when testing if moderation is required and validating tagged item data
parent
a938e15d
Changes
9
Hide whitespace changes
Inline
Side-by-side
backend/load_data/assets/tags.json
View file @
2b4429c0
...
...
@@ -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
backend/migrations/0002_auto_20180910_1700.py
0 → 100644
View file @
2b4429c0
# 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
),
),
]
backend/migrations/0003_auto_20180910_1731.py
0 → 100644
View file @
2b4429c0
# 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
=
''
),
),
]
backend/models/abstract/basic_module/basicModule.py
View file @
2b4429c0
...
...
@@ -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
,
...
...
backend/models/abstract/taggedItem/taggedItem.py
View file @
2b4429c0
...
...
@@ -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
:
...
...
backend/permissions/is_moderation_required.py
View file @
2b4429c0
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..."
)
backend/tests/test_is_moderation_required.py
0 → 100644
View file @
2b4429c0
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
))
backend/validators/tag/__init__.py
View file @
2b4429c0
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
backend/validators/tag/tagged_item_validation.py
View file @
2b4429c0
...
...
@@ -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
# }
# }
# }
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment