server/src/bl/thingsMngr.js
function getThingUserClaims(user, thing, isSuperAdministrator) {

	if (!thing)
		throw new utils.ErrorCustom(httpStatusCodes.INTERNAL_SERVER_ERROR, "Thing can't be null", 26);

	let thingUserClaimsAndRights = {
		read    : thing.publicReadClaims,
		change  : thing.publicChangeClaims
	};

	if (user) {
		thingUserClaimsAndRights.read   = thingUserClaimsAndRights.read   | thing.everyoneReadClaims;
		thingUserClaimsAndRights.change = thingUserClaimsAndRights.change | thing.everyoneChangeClaims;

		var thingUserRights = getThingUserRights(user._id, user.username, thing);
		if (thingUserRights)
		{
			thingUserClaimsAndRights.read   = thingUserClaimsAndRights.read   | thingUserRights.userReadClaims;
			thingUserClaimsAndRights.change = thingUserClaimsAndRights.change | thingUserRights.userChangeClaims;
		}

		if (isSuperAdministrator)
		{
			thingUserClaimsAndRights.read   = thConstants.ThingUserReadClaims.AllClaims;
			thingUserClaimsAndRights.change = thConstants.ThingUserChangeClaims.AllClaims;
		}
	}

	return thingUserClaimsAndRights;
}
function getThingUserClaims(user, thing, isSuperAdministrator) {

	if (!thing)
		throw new utils.ErrorCustom(httpStatusCodes.INTERNAL_SERVER_ERROR, "Thing can't be null", 26);

	let thingUserClaimsAndRights = {
		read    : thing.publicReadClaims,
		change  : thing.publicChangeClaims
	};

	if (user) {
		thingUserClaimsAndRights.read   = thingUserClaimsAndRights.read   | thing.everyoneReadClaims;
		thingUserClaimsAndRights.change = thingUserClaimsAndRights.change | thing.everyoneChangeClaims;

		var thingUserRights = getThingUserRights(user._id, user.username, thing);
		if (thingUserRights)
		{
			thingUserClaimsAndRights.read   = thingUserClaimsAndRights.read   | thingUserRights.userReadClaims;
			thingUserClaimsAndRights.change = thingUserClaimsAndRights.change | thingUserRights.userChangeClaims;
		}

		if (isSuperAdministrator)
		{
			thingUserClaimsAndRights.read   = thConstants.ThingUserReadClaims.AllClaims;
			thingUserClaimsAndRights.change = thConstants.ThingUserChangeClaims.AllClaims;
		}
	}

	return thingUserClaimsAndRights;
}
function getThingUserClaims ( user , thing , isSuperAdministrator ) { if ( ! thing ) throw new utils . ErrorCustom ( httpStatusCodes . INTERNAL_SERVER_ERROR , "Thing can't be null" , 26 ) ; let thingUserClaimsAndRights = { read : thing . publicReadClaims , change : thing . publicChangeClaims } ; if ( user ) { thingUserClaimsAndRights . read = thingUserClaimsAndRights . read | thing . everyoneReadClaims ; thingUserClaimsAndRights . change = thingUserClaimsAndRights . change | thing . everyoneChangeClaims ; var thingUserRights = getThingUserRights ( user . _id , user . username , thing ) ; if ( thingUserRights ) { thingUserClaimsAndRights . read = thingUserClaimsAndRights . read | thingUserRights . userReadClaims ; thingUserClaimsAndRights . change = thingUserClaimsAndRights . change | thingUserRights . userChangeClaims ; } if ( isSuperAdministrator ) { thingUserClaimsAndRights . read = thConstants . ThingUserReadClaims . AllClaims ; thingUserClaimsAndRights . change = thConstants . ThingUserChangeClaims . AllClaims ; } } return thingUserClaimsAndRights ; }
All paths return to something. It never returns null except for exceptions The User may be null as anonymous. If User is anonymous returns Thing's PublicClaims
All paths return to something . It never returns null except for exceptions The User may be null as anonymous . If User is anonymous returns Thing s PublicClaims