checks.js
function(request, response, next) {
		var apptkn;
		if (!utils.Misc.isNullOrUndefined(request.get(X_BOLT_APP_TOKEN))) {
			apptkn = request.get(X_BOLT_APP_TOKEN);
		}
		else {
			var error = new Error(errors['110']);
			response.end(utils.Misc.createResponse(null, error, 110));
			return;
		}

		var name = __getAppFromAppToken(apptkn, request);
		if (utils.Misc.isNullOrUndefined(name)) {
			var error = new Error(errors['113']);
			response.end(utils.Misc.createResponse(null, error, 113));
			return;
		}
		var appnm = utils.String.trim(name.toLowerCase());
		var dbOwner = request.body.db || request.body.app || appnm;

		models.collection.findOne({ name: request.params.collection, app: dbOwner }, function(collError, collection){
			if (!utils.Misc.isNullOrUndefined(collError)){
				response.end(utils.Misc.createResponse(null, collError));
			}
			else if(utils.Misc.isNullOrUndefined(collection)){
				var errColl = new Error(errors['703']);
				response.end(utils.Misc.createResponse(null, errColl, 703));
			}
			else {
				//allow the owner to pass
				if (appnm == collection.app.toLowerCase()) {
					next();
					return;
				}

				if (!utils.Misc.isNullOrUndefined(collection.tenants)) { //tenants allowed
					if ("*" == collection.tenants) { //every body is allowed
						next();
						return;
					}
					//there is a tenant list; are u listed?
					else if (collection.tenants.map(function(value){ return value.toLowerCase(); }).indexOf(appnm) > -1) {
						next();
						return;
					}
				}

				//no guests allowed

				var error = new Error(errors['704']);
				response.end(utils.Misc.createResponse(null, error, 704));
			}
		});
	}
function(request, response, next) {
		var apptkn;
		if (!utils.Misc.isNullOrUndefined(request.get(X_BOLT_APP_TOKEN))) {
			apptkn = request.get(X_BOLT_APP_TOKEN);
		}
		else {
			var error = new Error(errors['110']);
			response.end(utils.Misc.createResponse(null, error, 110));
			return;
		}

		var name = __getAppFromAppToken(apptkn, request);
		if (utils.Misc.isNullOrUndefined(name)) {
			var error = new Error(errors['113']);
			response.end(utils.Misc.createResponse(null, error, 113));
			return;
		}
		var appnm = utils.String.trim(name.toLowerCase());
		var dbOwner = request.body.db || request.body.app || appnm;

		models.collection.findOne({ name: request.params.collection, app: dbOwner }, function(collError, collection){
			if (!utils.Misc.isNullOrUndefined(collError)){
				response.end(utils.Misc.createResponse(null, collError));
			}
			else if(utils.Misc.isNullOrUndefined(collection)){
				var errColl = new Error(errors['703']);
				response.end(utils.Misc.createResponse(null, errColl, 703));
			}
			else {
				//allow the owner to pass
				if (appnm == collection.app.toLowerCase()) {
					next();
					return;
				}

				if (!utils.Misc.isNullOrUndefined(collection.tenants)) { //tenants allowed
					if ("*" == collection.tenants) { //every body is allowed
						next();
						return;
					}
					//there is a tenant list; are u listed?
					else if (collection.tenants.map(function(value){ return value.toLowerCase(); }).indexOf(appnm) > -1) {
						next();
						return;
					}
				}

				//no guests allowed

				var error = new Error(errors['704']);
				response.end(utils.Misc.createResponse(null, error, 704));
			}
		});
	}
function ( request , response , next ) { var apptkn ; if ( ! utils . Misc . isNullOrUndefined ( request . get ( X_BOLT_APP_TOKEN ) ) ) { apptkn = request . get ( X_BOLT_APP_TOKEN ) ; } else { var error = new Error ( errors [ '110' ] ) ; response . end ( utils . Misc . createResponse ( null , error , 110 ) ) ; return ; } var name = __getAppFromAppToken ( apptkn , request ) ; if ( utils . Misc . isNullOrUndefined ( name ) ) { var error = new Error ( errors [ '113' ] ) ; response . end ( utils . Misc . createResponse ( null , error , 113 ) ) ; return ; } var appnm = utils . String . trim ( name . toLowerCase ( ) ) ; var dbOwner = request . body . db || request . body . app || appnm ; models . collection . findOne ( { name : request . params . collection , app : dbOwner } , function ( collError , collection ) { if ( ! utils . Misc . isNullOrUndefined ( collError ) ) { response . end ( utils . Misc . createResponse ( null , collError ) ) ; } else if ( utils . Misc . isNullOrUndefined ( collection ) ) { var errColl = new Error ( errors [ '703' ] ) ; response . end ( utils . Misc . createResponse ( null , errColl , 703 ) ) ; } else { //allow the owner to pass if ( appnm == collection . app . toLowerCase ( ) ) { next ( ) ; return ; } if ( ! utils . Misc . isNullOrUndefined ( collection . tenants ) ) { //tenants allowed if ( "*" == collection . tenants ) { //every body is allowed next ( ) ; return ; } //there is a tenant list; are u listed? else if ( collection . tenants . map ( function ( value ) { return value . toLowerCase ( ) ; } ) . indexOf ( appnm ) > - 1 ) { next ( ) ; return ; } } //no guests allowed var error = new Error ( errors [ '704' ] ) ; response . end ( utils . Misc . createResponse ( null , error , 704 ) ) ; } } ) ; }
checks if this app has the right to write to the collection in the database
checks if this app has the right to write to the collection in the database