
/** List the operations to which the user has access
 *
 * @a userOrgs is the user's organisations
 * @a itemOrgs is the item's organisations
 *
 */
function operations (userOrgs = {}, itemOrgs = {}) {
	// console.log("userOrgs", userOrgs);
	// console.log("itemOrgs", itemOrgs);
	const ops = [];

	for (const userOrg in userOrgs) {
		for (const operation in userOrgs[userOrg]) {
			if (userOrg in itemOrgs) {
				// Found an organisation in common between user and project
				// (there might be many)
				if (itemOrgs[userOrg][operation] == true && userOrgs[userOrg][operation] == true) {
					ops.push[operation];
				}
			}
		}
	}
	if ("*" in userOrgs) {
		// Aha! A wildcard user
		// Return true if at least one organisation grants access
		// to this operation
		// console.log("Checking via wildcard");
		for (const operation in userOrgs["*"]) {
			if (Object.values(itemOrgs).some( org => org[operation] )) {
				ops.push(operation);
			}
		}
	}
	return ops;

}

if (typeof module !== 'undefined' && module.exports) {
    module.exports = operations; // CJS export
}

// ESM export
if (typeof exports !== 'undefined' && !exports.default) {
    exports.default = operations; // ESM export
}
