mirror of
https://gitlab.com/comunic/comunicapiv2
synced 2025-06-20 16:45:16 +00:00
Can update group settings
This commit is contained in:
24
src/utils/ArrayUtils.ts
Normal file
24
src/utils/ArrayUtils.ts
Normal file
@ -0,0 +1,24 @@
|
||||
/**
|
||||
* Array utilities
|
||||
*
|
||||
* @author Pierre HUBERT
|
||||
*/
|
||||
|
||||
/**
|
||||
* Find the key matching a given value in an object
|
||||
*
|
||||
* @param object Object to search in
|
||||
* @param value The value to search for
|
||||
* @returns Matching key, or null if not found
|
||||
*/
|
||||
export function findKey(object: Object, value: any): string {
|
||||
for (const key in object) {
|
||||
if (!object.hasOwnProperty(key))
|
||||
continue;
|
||||
|
||||
if(object[key] == value)
|
||||
return key;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
@ -14,6 +14,20 @@ export function checkMail(emailAddress: string): boolean {
|
||||
return (emailAddress.match(/^[a-zA-Z0-9_.]+@[a-zA-Z0-9-.]{1,}[.][a-zA-Z]{2,8}$/) === null ? false : true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check a URL validity
|
||||
*
|
||||
* Source: https://gist.github.com/729294
|
||||
*
|
||||
* @param {string} url The URL to check
|
||||
* @return {boolean} TRUE if the URL is valid
|
||||
*/
|
||||
export function checkURL(url: string) : boolean {
|
||||
const regex = /^(?:(?:https?|ftp):\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?: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*)?$/i
|
||||
|
||||
return url.match(regex) == null ? false : true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fix text encoding
|
||||
*
|
||||
|
49
src/utils/VirtualDirsUtils.ts
Normal file
49
src/utils/VirtualDirsUtils.ts
Normal file
@ -0,0 +1,49 @@
|
||||
import { AccountHelper } from "../helpers/AccountHelper";
|
||||
import { GroupsHelper } from "../helpers/GroupsHelper";
|
||||
|
||||
/**
|
||||
* Virtual directories utilities
|
||||
*
|
||||
* @author Pierre HUBERT
|
||||
*/
|
||||
|
||||
export enum VirtualDirType {
|
||||
USER,
|
||||
GROUP
|
||||
}
|
||||
|
||||
/**
|
||||
* Check out whether a virtual directory is valid or not
|
||||
*
|
||||
* @param dir The virtual directory to check
|
||||
*/
|
||||
export function checkVirtualDirectory(dir: string) : boolean {
|
||||
if(dir.length < 4) return false;
|
||||
|
||||
for(let el of [".html", ".txt", ".php", "à", "â", "é", "ê", "@", "/", "\"", "'", '"', "<", ">", "?", "&", "#"])
|
||||
if(dir.includes(el))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the availability of a virtual directory
|
||||
*
|
||||
* @param dir Directory to check
|
||||
* @param id The ID of the element to check
|
||||
* @param type The type of the element
|
||||
*/
|
||||
export async function checkVirtualDirectoryAvailability(dir: string, id: number, type: VirtualDirType) : Promise<boolean> {
|
||||
if(!checkVirtualDirectory(dir)) return false;
|
||||
|
||||
if(type == VirtualDirType.USER) {
|
||||
return await AccountHelper.CheckUserDirectoryAvailability(dir, id)
|
||||
&& await GroupsHelper.CheckDirectoryAvailability(dir);
|
||||
}
|
||||
|
||||
else {
|
||||
return await AccountHelper.CheckUserDirectoryAvailability(dir)
|
||||
&& await GroupsHelper.CheckDirectoryAvailability(dir, id);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user