MCPcopy Create free account
hub / github.com/error311/FileRise / computeGroupGrantMaskForUser

Function computeGroupGrantMaskForUser

public/js/adminFolderAccess.js:864–961  ·  view source on GitHub ↗
(username, folders = [], sourceId = null)

Source from the content-addressed store, hash-verified

862}
863
864function computeGroupGrantMaskForUser(username, folders = [], sourceId = null) {
865 const mask = {};
866 if (!username || !__groupsCache) return mask;
867 const sid = normalizeSourceId(sourceId == null ? getFolderAccessSourceId() : sourceId);
868 const uname = String(username).toLowerCase();
869
870 const userGroups = Object.keys(__groupsCache || {}).map(groupName => {
871 const g = __groupsCache[groupName] || {};
872 const members = Array.isArray(g.members) ? g.members : [];
873 const inGroup = members.some(m => String(m || "").toLowerCase() === uname);
874 if (!inGroup) return null;
875 return { name: groupName, grants: pickGroupGrantsForSource(g, sid) };
876 }).filter(Boolean);
877
878 if (!userGroups.length) return mask;
879
880 const folderList = Array.isArray(folders) && folders.length
881 ? folders.slice()
882 : Array.from(new Set(
883 userGroups.flatMap(g => Object.keys(g.grants || {}))
884 ));
885
886 const hasExplicit = (grants = {}) => {
887 if (grants.__explicit || grants.explicit) return true;
888 const caps = [
889 'view', 'viewOwn', 'manage', 'create', 'upload', 'edit', 'rename',
890 'copy', 'move', 'delete', 'extract', 'shareFile', 'shareFolder',
891 'write', 'share', 'share_file', 'share_folder', 'owners', 'read', 'read_own'
892 ];
893 return caps.some(k => !!grants[k]);
894 };
895
896 const expandCaps = (grants = {}) => {
897 const caps = {};
898 const shareFile = !!(grants.shareFile || grants.share_file || grants.share);
899 const shareFolder = !!(grants.shareFolder || grants.share_folder || grants.share);
900 const writeMeta = !!grants.write;
901
902 [
903 'view', 'viewOwn', 'manage', 'create', 'upload', 'edit',
904 'rename', 'copy', 'move', 'delete', 'extract'
905 ].forEach(k => { if (grants[k]) caps[k] = true; });
906
907 if (shareFile) caps.shareFile = true;
908 if (shareFolder) caps.shareFolder = true;
909 if (writeMeta) caps.write = true;
910 if (grants.share) caps.share = true;
911 if (grants.owners) caps.owners = true;
912 if (grants.read) caps.read = true;
913 if (grants.read_own) caps.read_own = true;
914
915 return caps;
916 };
917
918 const ancestors = (folder) => {
919 if (!folder || folder === 'root') return [];
920 const parts = folder.split('/').filter(Boolean);
921 const out = [];

Callers 2

ensureLoadedFunction · 0.85
ensureLoadedFunction · 0.85

Calls 6

getFolderAccessSourceIdFunction · 0.85
pickGroupGrantsForSourceFunction · 0.85
expandCapsFunction · 0.85
hasExplicitFunction · 0.85
ancestorsFunction · 0.85
normalizeSourceIdFunction · 0.70

Tested by

no test coverage detected