2017-07-04 01:17:49 +08:00
|
|
|
import {DirectoryDTO} from "./DirectoryDTO";
|
|
|
|
import {Utils} from "../Utils";
|
2016-12-27 23:09:47 +08:00
|
|
|
export enum UserRoles{
|
2017-07-04 01:17:49 +08:00
|
|
|
Guest = 0,
|
|
|
|
TrustedGuest = 1,
|
2017-06-11 04:32:56 +08:00
|
|
|
User = 2,
|
|
|
|
Admin = 3,
|
|
|
|
Developer = 4,
|
2016-12-27 23:09:47 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface UserDTO {
|
2017-06-11 04:32:56 +08:00
|
|
|
id: number;
|
|
|
|
name: string;
|
|
|
|
password: string;
|
|
|
|
role: UserRoles;
|
2017-07-04 01:17:49 +08:00
|
|
|
permissions: string[]; //user can only see these permissions. if ends with *, its recursive
|
|
|
|
}
|
|
|
|
|
|
|
|
export module UserUtil {
|
|
|
|
|
|
|
|
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);
|
|
|
|
};
|
2017-06-11 04:32:56 +08:00
|
|
|
}
|