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
7266140c
Commit
7266140c
authored
Feb 24, 2019
by
Florent Chehab
Browse files
Merge branch 'cleaning' into 'master'
Cleaning See merge request
rex-dri/rex-dri!50
parents
0e42118e
4fe1bdf2
Pipeline
#35396
passed with stages
in 4 minutes and 15 seconds
Changes
106
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
frontend/src/utils/dateToDateStr.js
View file @
7266140c
/**
* Converts a date object into a date string "yyyy-mm-dd"
*
* @export
* @param {Date} date
* @returns
*/
export
default
function
dateToDateStr
(
date
)
{
if
(
!
date
)
{
return
null
;
...
...
@@ -7,8 +14,9 @@ export default function dateToDateStr(date) {
mm
=
date
.
getMonth
()
+
1
,
dd
=
date
.
getDate
();
// add zero to the left if necessary
mm
=
mm
<
10
?
"
0
"
+
mm
:
mm
;
dd
=
dd
<
10
?
"
0
"
+
dd
:
dd
;
return
yyyy
+
"
-
"
+
mm
+
"
-
"
+
dd
;
}
\ No newline at end of file
return
`
${
yyyy
}
-
${
mm
}
-
${
dd
}
`
;
}
frontend/src/utils/getObjModerationLevels.js
View file @
7266140c
import
OBJ_MODERATION_PERMISSIONS
from
"
../../../shared/OBJ_MODERATION_PERMISSIONS.json
"
;
/**
* Function to get the moderation levels available
* if restrict is true then only the levels that are <= to the one of the user
* are returned
*
* @export
* @param {number} userLevel
* @param {boolean} [restrict=false]
* @returns {object}
*/
export
default
function
getObjModerationLevel
(
userLevel
,
restrict
=
false
)
{
let
out
=
Array
();
for
(
let
key
in
OBJ_MODERATION_PERMISSIONS
)
{
...
...
@@ -14,4 +24,4 @@ export default function getObjModerationLevel(userLevel, restrict = false) {
}
}
return
out
;
}
\ No newline at end of file
}
frontend/src/utils/isUrl.js
View file @
7266140c
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
);
/**
* Function to test if a string is a valid url
*
* @export
* @param {string} strUrl
* @returns
*/
export
default
function
isUrl
(
strUrl
)
{
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
*
)?
$/
;
return
regexp
.
test
(
strUrl
);
}
frontend/src/utils/range.js
0 → 100644
View file @
7266140c
/**
* Function to generate a range of numbers from 0 to n-1
*
* @export
* @param {number} n
* @returns
*/
export
default
function
range
(
n
)
{
return
[...
Array
(
n
).
keys
()];
}
frontend/src/utils/stringHasExtension.js
View file @
7266140c
/**
* Function to check if a string has an extension in one of the allowedExtensions list
*
* @export
* @param {string} str
* @param {Array} allowedExtensions
* @returns
*/
export
default
function
stringHasExtension
(
str
,
allowedExtensions
)
{
if
(
!
str
||
typeof
str
!=
"
string
"
)
{
if
(
typeof
str
!==
"
string
"
)
{
// eslint-disable-next-line no-console
console
.
error
(
"
The string provided to the the stringHasExtension function is not a string...
"
);
return
false
;
}
if
(
!
str
)
{
return
false
;
}
const
strExtension
=
str
.
split
(
"
.
"
).
slice
(
-
1
)[
0
].
toLowerCase
();
return
allowedExtensions
.
some
(
ext
=>
{
if
(
ext
.
toLowerCase
()
==
strExtension
)
{
return
true
;
}
else
{
return
false
;
}
});
return
allowedExtensions
.
some
(
ext
=>
ext
.
toLowerCase
()
==
strExtension
);
}
shared/api_config.yml
View file @
7266140c
# THIS FILE IS USED TO GENERATE OTHER VERY IMPORTANT FILES
# BOTH IN THE FRONTEND AND IN THE BACKEND !
# THIS FILE IS DYNAMICALLY USED FOR THE BACKEND AND THE FRONTEND
# TAKE CARE WHEN MODYFING IT ;)
# model : the model name (may be null) Model can't be present more than once.
...
...
@@ -12,6 +11,7 @@
# and used in the viewset
# requires_testing: boolean to tell if this viewset is only availble in
# a testing environment.
# ignore_in_admin: don't register the model in the admin
# Moderation levels are defined as follow :
# 0 : moderation will never be applied
...
...
@@ -19,12 +19,12 @@
# 2 : (default for security reasons) moderation will always be on no matter what
# It is to be noted that staff members, dri members and moderators won't be subject to moderation !
#
# When moderation_level > 0, someone may decide to enforce moderation on for the users with a lower
# status in the app. This is called object level moderation !
# staff ⊂ dri ⊂ moderators ⊂ authenficated_user
# When moderation_level > 0, someone may decide to enforce moderation on for the users with a lower
# status in the app. This is called object level moderation !
# staff ⊂ dri ⊂ moderators ⊂ authenficated_user
# For viewset permissions we have the followings
#
#
# By default, every viewset will have :
# - isAuthentificated : to use the API the client needs to be authentificated
# - noDeleteIsNotStaff : nothing can be deleted except if you are a staff member
...
...
@@ -32,9 +32,9 @@
# Some viewsets may have more presice permissions
# - IsStaff
# - IsStaffOrReadOnly
# - IsDriOrReadOnly
# - IsDriOrReadOnly
# - IsOwner : (or )
#
#
-
model
:
Country
viewset
:
CountryViewSet
...
...
Prev
1
2
3
4
5
6
Next
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