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

49 lines
1.2 KiB
TypeScript
Raw Normal View History

2017-07-04 01:17:49 +08:00
import {DirectoryDTO} from "./DirectoryDTO";
import {Utils} from "../Utils";
2018-02-04 08:50:42 +08:00
export enum UserRoles {
2017-07-09 18:03:17 +08:00
LimitedGuest = 0,
Guest = 1,
User = 2,
Admin = 3,
Developer = 4,
2016-12-27 23:09:47 +08:00
}
export interface UserDTO {
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
}
2017-07-09 18:03:17 +08:00
export module UserDTO {
2017-07-04 01:17:49 +08:00
export const isPathAvailable = (path: string, permissions: string[]): boolean => {
2018-02-04 08:50:42 +08:00
if (permissions == null || permissions.length == 0 || permissions[0] == "/*") {
2017-07-04 01:17:49 +08:00
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)) {
2018-02-04 08:50:42 +08:00
return true;
2017-07-04 01:17:49 +08:00
}
2018-02-04 08:50:42 +08:00
} else if (path == permission) {
return true;
} else if (path == "." && permission == "/") {
return true;
2017-07-04 01:17:49 +08:00
}
2018-02-04 08:50:42 +08:00
2017-07-04 01:17:49 +08:00
}
return false;
};
2018-02-04 08:50:42 +08:00
export const isDirectoryAvailable = (directory: DirectoryDTO, permissions: string[]): boolean => {
return isPathAvailable(Utils.concatUrls(directory.path, directory.name), permissions);
2017-07-04 01:17:49 +08:00
};
}