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

import {DirectoryDTO} from './DirectoryDTO';
import {Utils} from '../Utils';
2018-02-04 08:50:42 +08:00
export enum UserRoles {
2018-05-29 02:03:12 +08:00
LimitedGuest = 1,
Guest = 2,
User = 3,
Admin = 4,
Developer = 5,
2016-12-27 23:09:47 +08:00
}
export interface UserDTO {
id: number;
name: string;
password: string;
role: UserRoles;
permissions: string[]; // user can only see these permissions. if ends with *, its recursive
2017-07-04 01:17:49 +08:00
}
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 => {
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] === '*') {
2017-07-04 01:17:49 +08:00
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
}
} else if (path === permission) {
2018-02-04 08:50:42 +08:00
return true;
} else if (path === '.' && 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
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
};
}