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) {
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;
return `${yyyy}-${mm}-${dd}`;
}
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) {
......
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*)?$/;
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\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) {
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;
}
const strExtension = str.split(".").slice(-1)[0].toLowerCase();
return allowedExtensions.some(ext => {
if (ext.toLowerCase() == strExtension) {
return true;
} else {
if (!str) {
return false;
}
});
const strExtension = str.split(".").slice(-1)[0].toLowerCase();
return allowedExtensions.some(ext => ext.toLowerCase() == strExtension);
}
# 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
......
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