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
Rex Dri
Rex Dri
Commits
d5f79595
Commit
d5f79595
authored
Sep 13, 2018
by
Florent Chehab
Browse files
usefull links validation ok
parent
3945371a
Changes
4
Hide whitespace changes
Inline
Side-by-side
backend/validators/tag/tags_config/useful_links.py
View file @
d5f79595
...
...
@@ -5,13 +5,15 @@ USEFULL_LINKS_CONFIG = {
"url"
:
{
"type"
:
"url"
,
"required"
:
True
,
"validators"
:
{}
"validators"
:
{
"max_length"
:
300
}
},
"description"
:
{
"type"
:
"text"
,
"required"
:
True
,
"validators"
:
{
"max_length"
:
50
0
"max_length"
:
50
}
}
}
...
...
backend/validators/tag/url.py
View file @
d5f79595
...
...
@@ -23,6 +23,9 @@ def validate_url(config, string):
validator_content
=
validators
[
validator
]
if
validator
==
'extension'
:
validate_extension
(
validator_content
,
string
)
elif
validator
==
'max_length'
:
if
len
(
string
)
>
validator_content
:
raise
ValidationError
(
'Your url is too long !'
)
else
:
raise
Exception
(
"Dev, you have implement something here..."
)
...
...
frontend/src/components/university/modules/editors/fields/UsefulLinksField.js
View file @
d5f79595
...
...
@@ -15,6 +15,9 @@ import DeleteIcon from '@material-ui/icons/Delete';
import
KeyboardArrowDownIcon
from
'
@material-ui/icons/KeyboardArrowDown
'
;
import
KeyboardArrowUpIcon
from
'
@material-ui/icons/KeyboardArrowUp
'
;
import
Field
from
'
./Field
'
;
import
Typography
from
'
@material-ui/core/Typography
'
;
import
isUrl
from
'
../../../../../utils/isUrl
'
;
const
styles
=
theme
=>
({
container
:
{
...
...
@@ -33,8 +36,50 @@ class UsefulLinksField extends Field {
if
(
this
.
props
.
required
&&
usefulLinks
.
length
==
0
)
{
return
true
;
}
const
notEmpty
=
usefulLinks
.
every
(
el
=>
{
if
(
(
el
.
url
!=
''
&&
el
.
description
==
''
)
||
(
el
.
url
==
''
&&
el
.
description
!=
''
)
)
{
return
false
;
}
return
true
;
});
if
(
!
notEmpty
)
{
return
true
}
const
urlValid
=
usefulLinks
.
every
(
el
=>
{
if
(
!
isUrl
(
el
.
url
))
{
return
false
;
}
return
true
;
});
if
(
!
urlValid
)
{
return
true
}
const
lengthOk
=
usefulLinks
.
every
(
el
=>
{
if
((
el
.
url
&&
el
.
url
.
length
>
this
.
props
.
urlMaxLength
)
||
(
el
.
description
&&
el
.
description
.
length
>
this
.
props
.
descriptionMaxLength
)
)
{
return
false
;
}
return
true
;
});
if
(
!
lengthOk
)
{
return
true
}
return
false
;
// TODO MORE
}
getValue
()
{
console
.
log
(
"
Get value comme il faut !
"
)
const
usefulLinks
=
this
.
state
.
value
;
let
emptyIndexes
=
Array
();
usefulLinks
.
map
((
el
,
idx
)
=>
{
if
(
el
.
url
==
''
&&
el
.
description
==
''
)
{
emptyIndexes
.
push
(
idx
);
}
})
console
.
log
(
"
empty indexes
"
,
emptyIndexes
)
return
usefulLinks
.
filter
((
s
,
idx
)
=>
!
(
idx
in
emptyIndexes
));
}
updateUsefulLinks
(
newUsefulLinks
)
{
...
...
@@ -101,6 +146,7 @@ class UsefulLinksField extends Field {
hasError
=
{
this
.
state
.
hasError
}
label
=
{
this
.
props
.
label
}
>
<
Typography
variant
=
'
caption
'
>
Tous
les
champs
doivent
être
remplis
et
les
URLs
doivent
commencer
par
'
http
'
ou
'
https
'
ou
'
ftp
'
.
<
/Typography
>
<
Grid
container
spacing
=
{
16
}
...
...
@@ -180,13 +226,17 @@ class UsefulLinksField extends Field {
UsefulLinksField
.
defaultProps
=
{
value
:
Array
(),
urlMaxLength
:
300
,
descriptionMaxLength
:
50
,
}
UsefulLinksField
.
propTypes
=
{
UsefulLinksField
.
propTypes
=
{
value
:
PropTypes
.
arrayOf
(
PropTypes
.
shape
({
url
:
PropTypes
.
string
.
isRequired
,
description
:
PropTypes
.
string
.
isRequired
,
})),
urlMaxLength
:
PropTypes
.
number
.
isRequired
,
descriptionMaxLength
:
PropTypes
.
number
.
isRequired
};
export
default
compose
(
...
...
frontend/src/utils/isUrl.js
0 → 100644
View file @
d5f79595
const
regexp
=
/^
(?:(?:
https
?
|ftp
)
:
\/\/)(?:(?!(?:
10|127
)(?:\.\d{1,3}){3})(?!(?:
169
\.
254|192
\.
168
)(?:\.\d{1,3}){2})(?!
172
\.(?:
1
[
6-9
]
|2
\d
|3
[
0-1
])(?:\.\d{1,3}){2})(?:[
1-9
]\d?
|1
\d\d
|2
[
01
]\d
|22
[
0-3
])(?:\.(?:
1
?\d{1,2}
|2
[
0-4
]\d
|25
[
0-5
])){2}(?:\.(?:[
1-9
]\d?
|1
\d\d
|2
[
0-4
]\d
|25
[
0-4
]))
|
(?:(?:[
a-z
\u
00a1-
\u
ffff0-9
]
-*
)
*
[
a-z
\u
00a1-
\u
ffff0-9
]
+
)(?:\.(?:[
a-z
\u
00a1-
\u
ffff0-9
]
-*
)
*
[
a-z
\u
00a1-
\u
ffff0-9
]
+
)
*
(?:\.(?:[
a-z
\u
00a1-
\u
ffff
]{2,})))(?:
:
\d{2,5})?(?:\/\S
*
)?
$/
;
export
default
function
isUrl
(
str
)
{
return
regexp
.
test
(
str
);
}
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