mirror of
https://github.com/mickael-kerjean/filestash.git
synced 2025-11-03 13:11:46 +08:00
we used to have the readonly attribute but somehow it's not supported by all fields, eg: select. As such when something is read only we disable the field
30 lines
917 B
JavaScript
30 lines
917 B
JavaScript
import rxjs from "../../lib/rx.js";
|
|
|
|
const perms$ = new rxjs.BehaviorSubject({});
|
|
|
|
export function setPermissions(path, value = {}) {
|
|
if (JSON.stringify(value) === JSON.stringify(perms$.value[path])) return;
|
|
perms$.next({
|
|
...perms$.value,
|
|
[path]: value,
|
|
});
|
|
}
|
|
|
|
export function calculatePermission(path, action) {
|
|
const toBool = (n) => n === undefined ? true : n;
|
|
if (!perms$.value[path]) return false;
|
|
switch (action) {
|
|
case "new-file": return toBool(perms$.value[path]["can_create_file"]);
|
|
case "new-folder": return toBool(perms$.value[path]["can_create_directory"]);
|
|
case "delete": return toBool(perms$.value[path]["can_delete"]);
|
|
case "rename": return toBool(perms$.value[path]["can_rename"]);
|
|
default: return false;
|
|
}
|
|
}
|
|
|
|
export function getPermission(path) {
|
|
return perms$.asObservable().pipe(
|
|
rxjs.map((perms) => perms[path]),
|
|
);
|
|
}
|