1
0
mirror of https://github.com/xuthus83/pigallery2.git synced 2024-11-03 21:04:03 +08:00
pigallery2/common/entities/UserDTO.ts
2017-07-09 12:03:17 +02:00

47 lines
1.1 KiB
TypeScript

import {DirectoryDTO} from "./DirectoryDTO";
import {Utils} from "../Utils";
export enum UserRoles{
LimitedGuest = 0,
Guest = 1,
User = 2,
Admin = 3,
Developer = 4,
}
export interface UserDTO {
id: number;
name: string;
password: string;
role: UserRoles;
permissions: string[]; //user can only see these permissions. if ends with *, its recursive
}
export module UserDTO {
export const isPathAvailable = (path: string, permissions: string[]): boolean => {
if (permissions == null || permissions.length == 0 || permissions[0] == "/") {
return true;
}
for (let i = 0; i < permissions.length; i++) {
let permission = permissions[i];
if (permission[permission.length - 1] == "*") {
permission = permission.slice(0, -1);
if (path.startsWith(permission)) {
return true
}
} else {
if (path == permission) {
return true
}
}
}
return false;
};
export const isDirectoryAvailable = (direcotry: DirectoryDTO, permissions: string[]): boolean => {
return isPathAvailable(Utils.concatUrls(direcotry.path, direcotry.name), permissions);
};
}