Skip to content

Commit

Permalink
Merge pull request pencilblue#1081 from pencilblue/0.6.0
Browse files Browse the repository at this point in the history
0.6.0
  • Loading branch information
brianhyder authored Jul 5, 2016
2 parents 4ba1380 + 3095b4b commit 07f4f1e
Show file tree
Hide file tree
Showing 291 changed files with 7,603 additions and 3,505 deletions.
17 changes: 17 additions & 0 deletions .bithoundrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"ignore": [
"**/public/js/lib/**",
"**/public/css/lib/**",
"**/public/bower_components/**",
"**/public/localization/**",
"**/sample.config.js"
],
"test": [
"**/test/**"
],
"critics": {
"lint": {
"engine": "jshint"
}
}
}
7 changes: 0 additions & 7 deletions .codeclimate.yml

This file was deleted.

6 changes: 0 additions & 6 deletions .nodemonignore

This file was deleted.

2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ node_js:
- "0.11"
- "0.12"
- "4"
- "5"
- "6"
- "iojs"
after_script:
- cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![dependencies](https://david-dm.org/pencilblue/pencilblue.png)](https://david-dm.org/pencilblue/pencilblue) [![Coverage Status](https://coveralls.io/repos/pencilblue/pencilblue/badge.svg?branch=master)](https://coveralls.io/r/pencilblue/pencilblue?branch=master) [![Build Status](https://travis-ci.org/pencilblue/pencilblue.svg?branch=master)](https://travis-ci.org/pencilblue/pencilblue) [![Code Climate](https://codeclimate.com/github/pencilblue/pencilblue/badges/gpa.svg)](https://codeclimate.com/github/pencilblue/pencilblue) [![bitHound Overall Score](https://www.bithound.io/github/pencilblue/pencilblue/badges/score.svg)](https://www.bithound.io/github/pencilblue/pencilblue) [![Join the chat at https://gitter.im/pencilblue/pencilblue](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/pencilblue/pencilblue?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![dependencies](https://david-dm.org/pencilblue/pencilblue.png)](https://david-dm.org/pencilblue/pencilblue) [![Coverage Status](https://coveralls.io/repos/pencilblue/pencilblue/badge.svg?branch=master)](https://coveralls.io/r/pencilblue/pencilblue?branch=master) [![Build Status](https://travis-ci.org/pencilblue/pencilblue.svg?branch=master)](https://travis-ci.org/pencilblue/pencilblue) [![bitHound Overall Score](https://www.bithound.io/github/pencilblue/pencilblue/badges/score.svg)](https://www.bithound.io/github/pencilblue/pencilblue) [![Join the chat at https://gitter.im/pencilblue/pencilblue](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/pencilblue/pencilblue?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

[PencilBlue](http://pencilblue.org)
=====
Expand Down Expand Up @@ -26,7 +26,7 @@ Installation

[![LAUNCH ON OpenShift](http://launch-shifter.rhcloud.com/launch/LAUNCH ON.svg)](https://hub.openshift.com/quickstarts/deploy/159-pencilblue)

The instructions below assume that Node.js [0.11, 5) and MongoDB [2, 3) are installed on your machine. If they are not then please visit http://nodejs.org and http://www.mongodb.org to install them.
The instructions below assume that Node.js [0.11, 6] and MongoDB [2, 3) are installed on your machine. If they are not then please visit http://nodejs.org and http://www.mongodb.org to install them.

##### PencilBlue Command-line interface
1. Install the pencilblue-cli module: ```sudo npm install -g pencilblue-cli```
Expand Down
12 changes: 4 additions & 8 deletions controllers/api/base_api_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ module.exports = function(pb) {

//PB dependencies
var util = pb.util;
var BaseObjectService = pb.BaseObjectService;

/**
*
Expand Down Expand Up @@ -62,8 +63,7 @@ module.exports = function(pb) {
* @param {Function} cb
*/
BaseApiController.prototype.get = function(cb) {
var id = this.pathVars.id;
this.service.get(id, this.handleGet(cb));
this.service.get(this.pathVars.id, this.processQuery(), this.handleGet(cb));
};

/**
Expand Down Expand Up @@ -172,9 +172,7 @@ module.exports = function(pb) {
pb.ValidationService.isNonEmptyStr(statement[0], true) &&
pb.ValidationService.isInt(statement[1], true)) {

var ordering = {};
ordering[statement[0]] = parseInt(statement[1]) > 0 ? pb.DAO.ASC : pb.DAO.DESC;
order.push(ordering);
order.push( [ statement[0], parseInt(statement[1]) > 0 ? pb.DAO.ASC : pb.DAO.DESC ] );
}
else {

Expand Down Expand Up @@ -347,9 +345,7 @@ module.exports = function(pb) {
* @method notFound
*/
BaseApiController.prototype.notFound = function(cb) {
var error = new Error('NOT FOUND');
error.code = 404;
cb(error);
cb(BaseObjectService.notFound('NOT FOUND'));
};

//exports
Expand Down
120 changes: 99 additions & 21 deletions controllers/base_controller.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (C) 2015 PencilBlue, LLC
Copyright (C) 2016 PencilBlue, LLC
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand All @@ -14,6 +14,7 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
'use strict';

//dependencies
var url = require('url');
Expand Down Expand Up @@ -110,21 +111,88 @@ module.exports = function BaseControllerModule(pb) {
*/
BaseController.prototype.init = function(props, cb) {
var self = this;
this.reqHandler = props.request_handler;
this.req = props.request;
this.res = props.response;
this.session = props.session;
this.body = props.body;

/**
* The instance of the request handler that processed the request
* @property reqHandler
* @type {RequestHandler}
*/
this.reqHandler = props.request_handler;

/**
* The current request object
* @property req
* @type {Request}
*/
this.req = props.request;

/**
* The current response object
* @property res
* @type {Response}
*/
this.res = props.response;

/**
* The session object that represents the calling entity
* @property session
* @type {object}
*/
this.session = props.session;

/**
* The deserialized body of the request. This field is only ever populted if the executing route specifies the
* "request_body" attribute and provides valid MIME types that map to a registered body parser
* @property body
* @type {object|null}
*/
this.body = props.body;

/**
* @deprecated Use this.ls
* @property localizationService
* @type {Localization}
*/
this.localizationService = props.localization_service;
this.ls = this.localizationService;
this.pathVars = props.pathVars;
this.query = props.query;

/**
* @property ls
* @type {Localization}
*/
this.ls = props.localization_service;

/**
* The hash of key/value pairs that represent the variables passed in the route path
* @property pathVars
* @type {object}
*/
this.pathVars = props.pathVars;

/**
* The hash of key/value pairs that represent the variables passed as query string parameters
* @property query
* @type {object}
*/
this.query = props.query;

/**
* The title of the view to be rendered, if there is a view
* @property pageName
* @type {string}
*/
this.pageName = '';
this.siteObj = props.siteObj;
this.site = props.site;
this.siteName = props.siteName;
this.hostname = SiteService.getHostWithProtocol(self.siteObj.hostname) || pb.config.siteRoot;
this.referer = this.req.headers.referer;

/**
* The referring URL
* @deprecated
* @property referer
* @type {string}
*/
this.referer = this.req.headers.referer;

/**
* @property ts
Expand All @@ -140,6 +208,10 @@ module.exports = function BaseControllerModule(pb) {

//build out a base service context that can be cloned and passed to any
//service objects
/**
* @property context
* @type {{req: Request, session: object, ls: Localization, ts: TemplateService, site: string, hostname: string, activeTheme: string, onlyThisSite: boolean, siteObj: object}}
*/
this.context = {
req: this.req,
session: this.session,
Expand Down Expand Up @@ -177,7 +249,7 @@ module.exports = function BaseControllerModule(pb) {

//create options
var tsOpts = {
ls: this.localizationService,
ls: this.ls,
activeTheme: props.activeTheme,
site: this.site
};
Expand Down Expand Up @@ -323,12 +395,12 @@ module.exports = function BaseControllerModule(pb) {
if(this.session.error) {
var error = this.session.error;
delete this.session.error;
cb(null, new pb.TemplateValue(util.format(ALERT_PATTERN, 'alert-danger', this.localizationService.get(error)), false));
cb(null, new pb.TemplateValue(util.format(ALERT_PATTERN, 'alert-danger', this.ls.get(error)), false));
}
else if(this.session.success) {
var success = this.session.success;
delete this.session.success;
cb(null, new pb.TemplateValue(util.format(ALERT_PATTERN, 'alert-success', this.localizationService.get(success)), false));
cb(null, new pb.TemplateValue(util.format(ALERT_PATTERN, 'alert-success', this.ls.get(success)), false));
}
else {
cb(null, '');
Expand Down Expand Up @@ -375,6 +447,12 @@ module.exports = function BaseControllerModule(pb) {

//convert to string
var postParams = url.parse('?' + raw.toString(encoding), true).query;

//In Node v6 a breaking change was introduced into the "querystring" module to prevent reserved words from
// being passed in as query string parameters and overriding prototype functions.
// This fix allows for users to continue on with V6 until another viable option comes along
postParams.hawOwnProperty = Object.prototype.hasOwnProperty;

cb(null, postParams);
});
};
Expand Down Expand Up @@ -450,16 +528,16 @@ module.exports = function BaseControllerModule(pb) {
for (var i = 0; i < requiredParameters.length; i++) {

if (typeof queryObject[requiredParameters[i]] === 'undefined') {
return this.localizationService.get('FORM_INCOMPLETE');
return this.ls.get('FORM_INCOMPLETE');
}
else if (queryObject[requiredParameters[i]].length === 0) {
return this.localizationService.get('FORM_INCOMPLETE');
return this.ls.get('FORM_INCOMPLETE');
}
}

if(queryObject.password && queryObject.confirm_password) {
if(queryObject.password !== queryObject.confirm_password) {
return this.localizationService.get('PASSWORD_MISMATCH');
return this.ls.get('PASSWORD_MISMATCH');
}
}

Expand Down Expand Up @@ -510,13 +588,13 @@ module.exports = function BaseControllerModule(pb) {
}

var rules = this.getSanitizationRules();
for(var prop in obj) {
Object.keys(obj).forEach(function(prop) {
if (util.isString(obj[prop])) {

var config = rules[prop];
obj[prop] = BaseController.sanitize(obj[prop], config);
obj[prop] = pb.BaseObjectService.sanitize(obj[prop], config);
}
}
});
};

/**
Expand Down Expand Up @@ -578,10 +656,10 @@ module.exports = function BaseControllerModule(pb) {
BaseController.apiResponse = function(cd, msg, dta) {
if(typeof msg === 'undefined') {
switch(cd) {
case BaseController.FAILURE:
case BaseController.API_FAILURE:
msg = 'FAILURE';
break;
case BaseController.SUCCESS:
case BaseController.API_SUCCESS:
msg = 'SUCCESS';
break;
default:
Expand Down
2 changes: 1 addition & 1 deletion controllers/delete_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ module.exports = function(pb) {
*
* @method getDataOnSuccess
* @param {Array} results
* @return {String}
* @return {object}
*/
DeleteController.prototype.getDataOnSuccess = function(/*results*/) {
return pb.RequestHandler.generateRedirect(this.getSuccessRedirect());
Expand Down
6 changes: 3 additions & 3 deletions controllers/form_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
var util = require('../include/util.js');

module.exports = function(pb) {

/**
* Provides the basic functionality for implementing a controller that
* needs access to a posted form.
Expand Down Expand Up @@ -77,7 +77,7 @@ module.exports = function(pb) {
* @param {Boolean} val
*/
FormController.prototype.setAutoSanitize = function(val) {
this.autoSanitize = val ? true : false;
this.autoSanitize = !!val;
};

/**
Expand All @@ -103,6 +103,6 @@ module.exports = function(pb) {
FormController.prototype.onPostParamsRetrieved = function(params, cb) {
cb({content: JSON.stringify(params), content_type:'application/json'});
};

return FormController;
};
Loading

0 comments on commit 07f4f1e

Please sign in to comment.