2018-05-13 00:19:51 +08:00
|
|
|
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 {
|
2017-06-11 04:32:56 +08:00
|
|
|
id: number;
|
|
|
|
name: string;
|
|
|
|
password: string;
|
|
|
|
role: UserRoles;
|
2019-02-23 06:39:01 +08:00
|
|
|
usedSharingKey?: string;
|
2018-05-13 00:19:51 +08:00
|
|
|
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
|
|
|
|
2019-02-23 06:39:01 +08:00
|
|
|
export const isDirectoryPathAvailable = (path: string, permissions: string[], separator = '/'): boolean => {
|
|
|
|
if (permissions == null || permissions.length === 0 || permissions[0] === separator + '*') {
|
2017-07-04 01:17:49 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
for (let i = 0; i < permissions.length; i++) {
|
|
|
|
let permission = permissions[i];
|
2019-02-23 07:12:59 +08:00
|
|
|
if (permissions[i] === separator + '*') {
|
|
|
|
return true;
|
|
|
|
}
|
2018-05-13 00:19:51 +08:00
|
|
|
if (permission[permission.length - 1] === '*') {
|
2017-07-04 01:17:49 +08:00
|
|
|
permission = permission.slice(0, -1);
|
2019-02-23 06:39:01 +08:00
|
|
|
if (path.startsWith(permission) && (!path[permission.length] || path[permission.length] === separator)) {
|
2018-02-04 08:50:42 +08:00
|
|
|
return true;
|
2017-07-04 01:17:49 +08:00
|
|
|
}
|
2018-05-13 00:19:51 +08:00
|
|
|
} else if (path === permission) {
|
2018-02-04 08:50:42 +08:00
|
|
|
return true;
|
2019-02-23 06:39:01 +08:00
|
|
|
} else if (path === '.' && permission === separator) {
|
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 => {
|
2019-02-23 06:39:01 +08:00
|
|
|
return isDirectoryPathAvailable(Utils.concatUrls(directory.path, directory.name), permissions);
|
2017-07-04 01:17:49 +08:00
|
|
|
};
|
2017-06-11 04:32:56 +08:00
|
|
|
}
|