@sync-in/server
Version:
The secure, open-source platform for file storage, sharing, collaboration, and sync
88 lines (87 loc) • 3.48 kB
JavaScript
/*
* Copyright (C) 2012-2025 Johan Legrand <johan.legrand@sync-in.com>
* This file is part of Sync-in | The open source file sync and share solution
* See the LICENSE file for licensing details
*/ "use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
function _export(target, all) {
for(var name in all)Object.defineProperty(target, name, {
enumerable: true,
get: Object.getOwnPropertyDescriptor(all, name).get
});
}
_export(exports, {
get canAccessToSpace () {
return canAccessToSpace;
},
get canAccessToSpaceUrl () {
return canAccessToSpaceUrl;
},
get getEnvPermissions () {
return getEnvPermissions;
},
get havePermission () {
return havePermission;
},
get haveSpaceEnvPermissions () {
return haveSpaceEnvPermissions;
},
get haveSpacePermission () {
return haveSpacePermission;
},
get removePermissions () {
return removePermissions;
}
});
const _functions = require("../../../common/functions");
const _user = require("../../users/constants/user");
const _spaces = require("../constants/spaces");
function havePermission(currentPermissions, mustHavePermission) {
return currentPermissions.indexOf(mustHavePermission) > -1;
}
function haveSpaceEnvPermissions(space, permission) {
if (permission) {
return havePermission(space.envPermissions, permission);
}
return true;
}
function haveSpacePermission(space, permission) {
return havePermission(space.permissions, permission);
}
function getEnvPermissions(space, root) {
/* In a root space, we have to intersect the space & the root permissions */ if (root?.id && typeof root?.permissions === 'string') {
return (0, _functions.intersectPermissions)(space.permissions, root.permissions);
} else {
return space.permissions;
}
}
function removePermissions(permissions, rmPermissions) {
return permissions.split(_spaces.SPACE_PERMS_SEP).filter((p)=>rmPermissions.indexOf(p) === -1).sort().join(_spaces.SPACE_PERMS_SEP);
}
function canAccessToSpaceUrl(user, urlSegments) {
if (urlSegments[1] === _spaces.SPACE_ALIAS.PERSONAL && (urlSegments[0] === _spaces.SPACE_REPOSITORY.FILES || urlSegments[0] === _spaces.SPACE_REPOSITORY.TRASH)) {
return user.havePermission(_user.USER_PERMISSION.PERSONAL_SPACE);
} else if (urlSegments[0] === _spaces.SPACE_REPOSITORY.FILES) {
return user.havePermission(_user.USER_PERMISSION.SPACES);
} else if (urlSegments[0] === _spaces.SPACE_REPOSITORY.SHARES) {
return user.havePermission(_user.USER_PERMISSION.SHARES);
} else if (urlSegments[0] === _spaces.SPACE_REPOSITORY.TRASH) {
return user.havePermission(_user.USER_PERMISSION.SPACES) || user.havePermission(_user.USER_PERMISSION.PERSONAL_SPACE);
}
return false;
}
function canAccessToSpace(user, space) {
if (space.inPersonalSpace) {
return user.havePermission(_user.USER_PERMISSION.PERSONAL_SPACE);
} else if (space.inFilesRepository) {
return user.havePermission(_user.USER_PERMISSION.SPACES);
} else if (space.inSharesRepository) {
return user.havePermission(_user.USER_PERMISSION.SHARES);
} else if (space.inTrashRepository) {
return user.havePermission(_user.USER_PERMISSION.SPACES) || user.havePermission(_user.USER_PERMISSION.PERSONAL_SPACE);
}
return false;
}
//# sourceMappingURL=permissions.js.map