Commit 7266140c authored by Florent Chehab's avatar 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
/**
* Converts a date object into a date string "yyyy-mm-dd"
*
* @export
* @param {Date} date
* @returns
*/
export default function dateToDateStr(date) { export default function dateToDateStr(date) {
if (!date) { if (!date) {
return null; return null;
...@@ -7,8 +14,9 @@ export default function dateToDateStr(date) { ...@@ -7,8 +14,9 @@ export default function dateToDateStr(date) {
mm = date.getMonth() + 1, mm = date.getMonth() + 1,
dd = date.getDate(); dd = date.getDate();
// add zero to the left if necessary
mm = mm < 10 ? "0" + mm : mm; mm = mm < 10 ? "0" + mm : mm;
dd = dd < 10 ? "0" + dd : dd; dd = dd < 10 ? "0" + dd : dd;
return yyyy + "-" + mm + "-" + dd; return `${yyyy}-${mm}-${dd}`;
} }
\ No newline at end of file
import OBJ_MODERATION_PERMISSIONS from "../../../shared/OBJ_MODERATION_PERMISSIONS.json"; 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) { export default function getObjModerationLevel(userLevel, restrict = false) {
let out = Array(); let out = Array();
for (let key in OBJ_MODERATION_PERMISSIONS) { for (let key in OBJ_MODERATION_PERMISSIONS) {
...@@ -14,4 +24,4 @@ export default function getObjModerationLevel(userLevel, restrict = false) { ...@@ -14,4 +24,4 @@ export default function getObjModerationLevel(userLevel, restrict = false) {
} }
} }
return out; return out;
} }
\ No newline at end of file
/**
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\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})))(?::\d{2,5})?(?:\/\S*)?$/; * Function to test if a string is a valid url
*
export default function isUrl(str) { * @export
return regexp.test(str); * @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\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})))(?::\d{2,5})?(?:\/\S*)?$/;
return regexp.test(strUrl);
} }
/**
* 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()];
}
/**
* 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) { 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; return false;
} }
if (!str) {
return false;
}
const strExtension = str.split(".").slice(-1)[0].toLowerCase(); const strExtension = str.split(".").slice(-1)[0].toLowerCase();
return allowedExtensions.some(ext => { return allowedExtensions.some(ext => ext.toLowerCase() == strExtension);
if (ext.toLowerCase() == strExtension) {
return true;
} else {
return false;
}
});
} }
# THIS FILE IS USED TO GENERATE OTHER VERY IMPORTANT FILES # THIS FILE IS DYNAMICALLY USED FOR THE BACKEND AND THE FRONTEND
# BOTH IN THE FRONTEND AND IN THE BACKEND !
# TAKE CARE WHEN MODYFING IT ;) # TAKE CARE WHEN MODYFING IT ;)
# model : the model name (may be null) Model can't be present more than once. # model : the model name (may be null) Model can't be present more than once.
...@@ -12,6 +11,7 @@ ...@@ -12,6 +11,7 @@
# and used in the viewset # and used in the viewset
# requires_testing: boolean to tell if this viewset is only availble in # requires_testing: boolean to tell if this viewset is only availble in
# a testing environment. # a testing environment.
# ignore_in_admin: don't register the model in the admin
# Moderation levels are defined as follow : # Moderation levels are defined as follow :
# 0 : moderation will never be applied # 0 : moderation will never be applied
...@@ -19,12 +19,12 @@ ...@@ -19,12 +19,12 @@
# 2 : (default for security reasons) moderation will always be on no matter what # 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 ! # 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 # 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 ! # status in the app. This is called object level moderation !
# staff ⊂ dri ⊂ moderators ⊂ authenficated_user # staff ⊂ dri ⊂ moderators ⊂ authenficated_user
# For viewset permissions we have the followings # For viewset permissions we have the followings
# #
# By default, every viewset will have : # By default, every viewset will have :
# - isAuthentificated : to use the API the client needs to be authentificated # - isAuthentificated : to use the API the client needs to be authentificated
# - noDeleteIsNotStaff : nothing can be deleted except if you are a staff member # - noDeleteIsNotStaff : nothing can be deleted except if you are a staff member
...@@ -32,9 +32,9 @@ ...@@ -32,9 +32,9 @@
# Some viewsets may have more presice permissions # Some viewsets may have more presice permissions
# - IsStaff # - IsStaff
# - IsStaffOrReadOnly # - IsStaffOrReadOnly
# - IsDriOrReadOnly # - IsDriOrReadOnly
# - IsOwner : (or ) # - IsOwner : (or )
# #
- model: Country - model: Country
viewset: CountryViewSet viewset: CountryViewSet
......
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