From ca24aeee0732153a5c33e60de83e218f2bcf78c0 Mon Sep 17 00:00:00 2001 From: Andrew Monroe Date: Thu, 9 Apr 2015 10:13:45 -0400 Subject: [PATCH 001/790] set up site object and add an admin page to create sites --- include/admin_navigation.js | 18 +++ include/config.js | 3 + include/requirements.js | 4 + include/service/entities/site_service.js | 103 ++++++++++++++++++ .../actions/admin/sites/activate_site.js | 39 +++++++ .../actions/admin/sites/deactivate_site.js | 39 +++++++ .../actions/admin/sites/new_site.js | 82 ++++++++++++++ .../controllers/admin/sites/manage.js | 36 ++++++ plugins/pencilblue/include/routes.js | 29 +++++ .../templates/admin/sites/manage.html | 70 ++++++++++++ .../templates/angular/admin/sites/manage.html | 60 ++++++++++ public/localization/en-us.js | 6 + 12 files changed, 489 insertions(+) create mode 100644 include/service/entities/site_service.js create mode 100644 plugins/pencilblue/controllers/actions/admin/sites/activate_site.js create mode 100644 plugins/pencilblue/controllers/actions/admin/sites/deactivate_site.js create mode 100644 plugins/pencilblue/controllers/actions/admin/sites/new_site.js create mode 100644 plugins/pencilblue/controllers/admin/sites/manage.js create mode 100644 plugins/pencilblue/templates/admin/sites/manage.html create mode 100644 plugins/pencilblue/templates/angular/admin/sites/manage.html diff --git a/include/admin_navigation.js b/include/admin_navigation.js index d779dd6ba..6cbc10fcf 100755 --- a/include/admin_navigation.js +++ b/include/admin_navigation.js @@ -217,6 +217,16 @@ module.exports = function AdminNavigationModule(pb) { } ]); + var MULTISITE_NAV = Object.freeze([ + { + id: 'site_entity', + title: 'MANAGE_SITES', + icon: 'cogs', + href: '/admin/sites', + access: SecurityService.ACCESS_ADMINISTRATOR + + } + ]); /** * * @private @@ -228,6 +238,10 @@ module.exports = function AdminNavigationModule(pb) { return util.clone(DEFAULT_NAV); } + function getMultiSiteNavigation() { + return util.clone(MULTISITE_NAV); + } + /** * * @private @@ -262,10 +276,14 @@ module.exports = function AdminNavigationModule(pb) { var navigation = []; var defaultNavigation = getDefaultNavigation(); var additions = getAdditions(); + var multiSiteAdditions = getMultiSiteNavigation(); var childrenAdditions = getChildrenAdditions(); util.arrayPushAll(defaultNavigation, navigation); util.arrayPushAll(additions, navigation); + if(pb.config.multisite) { + util.arrayPushAll(multiSiteAdditions, navigation); + } //retrieve the nav items to iterate over var ids = Object.keys(childrenAdditions); diff --git a/include/config.js b/include/config.js index e73e93eb6..0068bab19 100755 --- a/include/config.js +++ b/include/config.js @@ -142,6 +142,9 @@ var BASE_CONFIG = { //the absolute file path to the directory where installation lives docRoot: Configuration.DOCUMENT_ROOT, + //enables/disables multiple sites in a single pencilblue instance (multitenancy) + multisite: false, + //provides a configuration for connecting to persistent storage. The //default configuration is meant for mongodb. db: { diff --git a/include/requirements.js b/include/requirements.js index f792ae578..2de6cda46 100755 --- a/include/requirements.js +++ b/include/requirements.js @@ -96,6 +96,10 @@ module.exports = function PB(config) { pb.UserService = require(path.join(config.docRoot, '/include/service/entities/user_service.js'))(pb); pb.users = new pb.UserService(); + //setup site service + pb.SiteService = require(path.join(config.docRoot, '/include/service/entities/site_service.js'))(pb); + pb.sites = new pb.SiteService(); + //setup request handling var BodyParsers = require(path.join(config.docRoot, 'include/http/parsers'))(pb); pb.BaseBodyParser = BodyParsers.BaseBodyParser; diff --git a/include/service/entities/site_service.js b/include/service/entities/site_service.js new file mode 100644 index 000000000..0e97b8b24 --- /dev/null +++ b/include/service/entities/site_service.js @@ -0,0 +1,103 @@ +var async = require('async'); +var util = require('../../util.js'); + +module.exports = function SiteServiceModule(pb) { + + var SITE_COLL = 'site' + + /** + * Service for performing site specific operations. + * + * @module Services + * @submodule Entities + * @class SiteService + * @constructor + */ + function SiteService(){} + + SiteService.prototype.getActiveSites = function(cb) { + var dao = new pb.DAO(); + dao.q(SITE_COLL, { select: pb.DAO.SELECT_ALL, where: {active: true} }, cb); + } + + SiteService.prototype.getInactiveSites = function(cb) { + var dao = new pb.DAO(); + dao.q(SITE_COLL, {where: {active: false}}, cb); + } + + SiteService.prototype.getSiteMap = function(cb) { + var self = this; + var tasks = { + + active: function(callback) { + self.getActiveSites(callback); + }, + + inactive: function(callback) { + self.getInactiveSites(callback); + } + }; + async.series(tasks, function(err, results) { + cb(err, results); + }); + }; + + /** + * Checks to see if a proposed site display name or hostname is already in the system + * + * @method isDisplayNameOrHostnameTaken + * @param {String} displayName + * @param {String} hostname + * @param {String} id Site object Id to exclude from the search + * @param {Function} cb Callback function + */ + SiteService.prototype.isDisplayNameOrHostnameTaken = function(displayName, hostname, id, cb) { + this.getExistingDisplayNameHostnameCounts(displayName, hostname, id, function(err, results) { + + var result = results === null; + if (!result) { + for(var key in results) { + result |= results[key] > 0; + } + } + cb(err, result); + }); + }; + + + /** + * Gets the total counts of a display name and hostname in the site collection + * + * @method getExistingDisplayNameHostnameCounts + * @param {String} displayName + * @param {String} hostname + * @param {String} id Site object Id to exclude from the search + * @param {Function} cb Callback function + */ + SiteService.prototype.getExistingDisplayNameHostnameCounts = function(displayName, hostname, id, cb) { + if (util.isFunction(id)) { + cb = id; + id = null; + } + + var getWhere = function(where) { + if (id) { + where[pb.DAO.getIdField()] = pb.DAO.getNotIDField(id); + } + return where; + }; + var dao = new pb.DAO(); + var tasks = { + displayName: function(callback) { + var expStr = util.escapeRegExp(displayName.toLowerCase) + '$'; + dao.count('site', getWhere({displayName: new RegExp(expStr, 'i')}), callback); + }, + hostname: function(callback) { + dao.count('site', getWhere({hostname: hostname.toLowerCase()}), callback); + } + }; + async.series(tasks, cb); + }; + + return SiteService; +}; diff --git a/plugins/pencilblue/controllers/actions/admin/sites/activate_site.js b/plugins/pencilblue/controllers/actions/admin/sites/activate_site.js new file mode 100644 index 000000000..c47875a00 --- /dev/null +++ b/plugins/pencilblue/controllers/actions/admin/sites/activate_site.js @@ -0,0 +1,39 @@ +module.exports = function(pb) { + + //pb dependencies + var util = pb.util; + + function ActivateSite(){} + util.inherits(ActivateSite, pb.BaseController); + + ActivateSite.prototype.render = function(cb) + { + var self = this; + var vars = this.pathVars; + + var message = this.hasRequiredParams(vars, ['id']); + if(message) { + self.formError(message, '/admin/sites', cb); + return; + } + + var dao = new pb.DAO(); + dao.loadByValue('uid', vars.id, 'site', function(err, site) { + if(util.isError(err) || site === null) { + self.formError(self.ls.get('ERROR_LOADING'), '/admin/sites/' + vars.id, cb); + return; + } + site.active = true; + dao.save(site, function(err, result) { + if(util.isError(err)) { + return self.formError(self.ls.get('ERROR_SAVING'), '/admin/sites/' + vars.id, cb); + } + + cb({content: pb.BaseController.apiResponse(pb.BaseController.API_SUCCESS, self.ls.get('SITE_ACTIVATED'), result)}); + }); + }); + } + + //exports + return ActivateSite; +}; \ No newline at end of file diff --git a/plugins/pencilblue/controllers/actions/admin/sites/deactivate_site.js b/plugins/pencilblue/controllers/actions/admin/sites/deactivate_site.js new file mode 100644 index 000000000..ba3bb45b7 --- /dev/null +++ b/plugins/pencilblue/controllers/actions/admin/sites/deactivate_site.js @@ -0,0 +1,39 @@ +module.exports = function(pb) { + + //pb dependencies + var util = pb.util; + + function DeactivateSite(){} + util.inherits(DeactivateSite, pb.BaseController); + + DeactivateSite.prototype.render = function(cb) + { + var self = this; + var vars = this.pathVars; + + var message = this.hasRequiredParams(vars, ['id']); + if(message) { + self.formError(message, '/admin/sites', cb); + return; + } + + var dao = new pb.DAO(); + dao.loadByValue('uid', vars.id, 'site', function(err, site) { + if(util.isError(err) || site === null) { + self.formError(self.ls.get('ERROR_LOADING'), '/admin/sites/' + vars.id, cb); + return; + } + site.active = false; + dao.save(site, function(err, result) { + if(util.isError(err)) { + return self.formError(self.ls.get('ERROR_SAVING'), '/admin/sites/' + vars.id, cb); + } + + cb({content: pb.BaseController.apiResponse(pb.BaseController.API_SUCCESS, self.ls.get('SITE_ACTIVATED'), result)}); + }); + }); + } + + //exports + return DeactivateSite; +}; \ No newline at end of file diff --git a/plugins/pencilblue/controllers/actions/admin/sites/new_site.js b/plugins/pencilblue/controllers/actions/admin/sites/new_site.js new file mode 100644 index 000000000..d4985699a --- /dev/null +++ b/plugins/pencilblue/controllers/actions/admin/sites/new_site.js @@ -0,0 +1,82 @@ +module.exports = function(pb) { + + //pb dependencies + var util = pb.util; + + /** + * Creates a new site + */ + function NewSite(){} + util.inherits(NewSite, pb.BaseController); + + NewSite.prototype.render = function(cb) + { + var self = this; + + this.getJSONPostParams(function(err, post) { + var message = self.hasRequiredParams(post, self.getRequiredFields()); + if(message) { + cb({ + code: 400, + content: pb.BaseController.apiResponse(pb.BaseController.API_ERROR, message) + }); + return; + } + + if(!pb.security.isAuthorized(self.session, {admin_level: post.admin})) { + cb({ + code: 400, + content: pb.BaseController.apiResponse(pb.BaseController.API_ERROR, self.ls.get('INSUFFICIENT_CREDENTIALS')) + }); + return; + } + + var site = pb.DocumentCreator.create('site', post); + site.active = false; + site.uid = getUid(); + pb.sites.isDisplayNameOrHostnameTaken(site.displayName, site.hostname, post.id, function(err, isTaken, field) { + if(util.isError(err) || isTaken) { + if(field === 'hostname') { + cb({ + code: 400, + content: pb.BaseController.apiResponse(pb.BaseController.API_ERROR, self.ls.get('EXISTING_HOSTNAME')) + }); + } else { + cb({ + code: 400, + content: pb.BaseController.apiResponse(pb.BaseController.API_ERROR, self.ls.get('EXISTING_DISPLAYNAME')) + }); + } + + return; + } + + var dao = new pb.DAO(); + dao.save(site, function(err, result) { + if(util.isError(err)) { + cb({ + code: 500, + content: pb.BaseController.apiResponse(pb.BaseController.API_ERROR, self.ls.get('ERROR_SAVING')) + }); + return; + } + + cb({content: pb.BaseController.apiResponse(pb.BaseController.API_SUCCESS, self.ls.get('SITE_CREATED'), result)}); + }); + }); + }); + + } + + NewSite.prototype.getRequiredFields = function() { + return ['displayName', 'hostname']; + }; + + function getUid() + { + return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {var r = Math.random()*16|0,v=c=='x'?r:r&0x3|0x8;return v.toString(16);}); + } + + //exports + return NewSite; +}; \ No newline at end of file diff --git a/plugins/pencilblue/controllers/admin/sites/manage.js b/plugins/pencilblue/controllers/admin/sites/manage.js new file mode 100644 index 000000000..5932d684b --- /dev/null +++ b/plugins/pencilblue/controllers/admin/sites/manage.js @@ -0,0 +1,36 @@ +module.exports = function(pb) { + + var util = pb.util; + + function Manage(){} + util.inherits(Manage, pb.BaseController); + + var SUB_NAV_KEY = 'sites_manage'; + + Manage.prototype.render = function(cb) { + var self = this; + + + + var siteService = new pb.SiteService(); + siteService.getSiteMap(function(err, map) { + var angularObjects = pb.ClientJs.getAngularObjects({ + navigation: pb.AdminNavigation.get(self.session, ['site_entity'], self.ls), + activeSites: map.active, + inactiveSites: map.inactive + }); + self.ts.registerLocal('angular_objects', new pb.TemplateValue(angularObjects, false)); + self.ts.load('admin/sites/manage', function(err,result) { + cb({content: result}); + }); + }); + } + + Manage.getSubNavItems = function(key, ls, data) { + return []; + } + + pb.AdminSubnavService.registerFor(SUB_NAV_KEY, Manage.getSubNavItems); + + return Manage; +} \ No newline at end of file diff --git a/plugins/pencilblue/include/routes.js b/plugins/pencilblue/include/routes.js index 8c4a06f68..88044670e 100644 --- a/plugins/pencilblue/include/routes.js +++ b/plugins/pencilblue/include/routes.js @@ -973,6 +973,35 @@ module.exports = function Routes(pb){ auth_required: false, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'api', 'localization_controller.js'), content_type: 'text/javascript' + }, + { + method: 'get', + path: "/admin/sites", + access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, + auth_required: true, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'sites', 'manage.js'), + content_type: 'text/html' + }, + { + method: 'post', + path: "/actions/admin/site", + access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, + auth_required: true, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'sites', 'new_site.js') + }, + { + method: 'post', + path: "/actions/admin/site/activate/:id", + access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, + auth_required: true, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'sites', 'activate_site.js') + }, + { + method: 'post', + path: "/actions/admin/site/deactivate/:id", + access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, + auth_required: true, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'sites', 'deactivate_site.js') } ]; }; diff --git a/plugins/pencilblue/templates/admin/sites/manage.html b/plugins/pencilblue/templates/admin/sites/manage.html new file mode 100644 index 000000000..54ec2e0a2 --- /dev/null +++ b/plugins/pencilblue/templates/admin/sites/manage.html @@ -0,0 +1,70 @@ +^tmp_admin=head^ +
+ ^tmp_admin=elements=error_success^ + ^tmp_admin=elements=sub_nav^ +
+
+
+
+ Active Sites +
+
+ No Active Sites +
+ + + + + + + + + + + + + +
Site NameHostnameDate Added
+
+ +
+
+
+
+
+ Inactive Sites +
+
+ No Inactive Sites +
+ + + + + + + + + + + + + +
Site NameHostnameDate Added
+
+ +
+
+
+
+
+ +
+
+ +
+ +
+
+^tmp_angular=admin=sites=manage^ +^tmp_admin=footer^ diff --git a/plugins/pencilblue/templates/angular/admin/sites/manage.html b/plugins/pencilblue/templates/angular/admin/sites/manage.html new file mode 100644 index 000000000..ae68fae09 --- /dev/null +++ b/plugins/pencilblue/templates/angular/admin/sites/manage.html @@ -0,0 +1,60 @@ + + diff --git a/public/localization/en-us.js b/public/localization/en-us.js index 666af6494..94dc458c2 100755 --- a/public/localization/en-us.js +++ b/public/localization/en-us.js @@ -221,6 +221,7 @@ var loc = SETTINGS: 'Settings', VIEW_SITE: 'View site', SITE_SETTINGS: 'Site settings', + MANAGE_SITES: 'Manage Sites', SITE_LOGO: 'Site logo', AUTHOR: 'Author', ACCOUNT: 'Account', @@ -425,6 +426,11 @@ var loc = VERIFY: 'Verify', VERIFIED: 'was verified' }, + sites: { + EXISTING_HOSTNAME: 'That hostname is already in use', + EXISTING_DISPLAYNAME: 'There is already a site with that displayname', + SITE_CREATED: 'The site was successfully created' + }, plugins: { MANAGE_PLUGINS: 'Manage plugins', From 9ee0765e90704c5214d8db29a6f1ff86bf91a5ab Mon Sep 17 00:00:00 2001 From: Andrew Monroe Date: Thu, 9 Apr 2015 11:02:35 -0400 Subject: [PATCH 002/790] add basic mechanism for handling sites in requesthandler --- include/http/request_handler.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/include/http/request_handler.js b/include/http/request_handler.js index 3e11b6311..d538c3c48 100755 --- a/include/http/request_handler.js +++ b/include/http/request_handler.js @@ -75,7 +75,8 @@ module.exports = function RequestHandlerModule(pb) { */ RequestHandler.storage = []; RequestHandler.index = {}; - + RequestHandler.sites = {}; + /** * The internal storage of static routes after they are validated and processed. * @private @@ -137,6 +138,14 @@ module.exports = function RequestHandlerModule(pb) { }; }; + RequestHandler.loadSite = function(site) { + RequestHandler.sites[site.hostname] = site.uid; + }; + + RequestHandler.unloadSite = function(site) { + RequestHandler.sites[site.hostname] = undefined; + }; + /** * Validates a route descriptor. The specified object must have a "controller" * property that points to a valid file and the "path" property must specify a @@ -551,6 +560,9 @@ module.exports = function RequestHandlerModule(pb) { //set the session this.session = session; + //set the site + var site = RequestHandler.sites[this.url.hostname]; + //find the controller to hand off to var route = this.getRoute(this.url.pathname); if (route == null) { From fd0754949846433004a5c2f0bf4df5d1b76f0b9e Mon Sep 17 00:00:00 2001 From: Eugene Chang Date: Thu, 9 Apr 2015 11:19:24 -0400 Subject: [PATCH 003/790] On activate/deactivate site, keep RequestHandler.sites up to date. --- include/http/request_handler.js | 2 +- .../pencilblue/controllers/actions/admin/sites/activate_site.js | 1 + .../controllers/actions/admin/sites/deactivate_site.js | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/include/http/request_handler.js b/include/http/request_handler.js index d538c3c48..2df19bae2 100755 --- a/include/http/request_handler.js +++ b/include/http/request_handler.js @@ -143,7 +143,7 @@ module.exports = function RequestHandlerModule(pb) { }; RequestHandler.unloadSite = function(site) { - RequestHandler.sites[site.hostname] = undefined; + delete RequestHandler.sites[site.hostname]; }; /** diff --git a/plugins/pencilblue/controllers/actions/admin/sites/activate_site.js b/plugins/pencilblue/controllers/actions/admin/sites/activate_site.js index c47875a00..60942576d 100644 --- a/plugins/pencilblue/controllers/actions/admin/sites/activate_site.js +++ b/plugins/pencilblue/controllers/actions/admin/sites/activate_site.js @@ -29,6 +29,7 @@ module.exports = function(pb) { return self.formError(self.ls.get('ERROR_SAVING'), '/admin/sites/' + vars.id, cb); } + pb.RequestHandler.loadSite(site); cb({content: pb.BaseController.apiResponse(pb.BaseController.API_SUCCESS, self.ls.get('SITE_ACTIVATED'), result)}); }); }); diff --git a/plugins/pencilblue/controllers/actions/admin/sites/deactivate_site.js b/plugins/pencilblue/controllers/actions/admin/sites/deactivate_site.js index ba3bb45b7..4bc4304cf 100644 --- a/plugins/pencilblue/controllers/actions/admin/sites/deactivate_site.js +++ b/plugins/pencilblue/controllers/actions/admin/sites/deactivate_site.js @@ -29,6 +29,7 @@ module.exports = function(pb) { return self.formError(self.ls.get('ERROR_SAVING'), '/admin/sites/' + vars.id, cb); } + pb.RequestHandler.unloadSite(site); cb({content: pb.BaseController.apiResponse(pb.BaseController.API_SUCCESS, self.ls.get('SITE_ACTIVATED'), result)}); }); }); From 5e8ab6d9d65fab36d260116a13ca3011ed80fe9d Mon Sep 17 00:00:00 2001 From: Andrew Monroe Date: Thu, 9 Apr 2015 11:19:43 -0400 Subject: [PATCH 004/790] load sites int req handler on pb startup --- include/service/entities/site_service.js | 13 +++++++++++++ pencilblue.js | 10 ++++++++++ 2 files changed, 23 insertions(+) diff --git a/include/service/entities/site_service.js b/include/service/entities/site_service.js index 0e97b8b24..29105fa04 100644 --- a/include/service/entities/site_service.js +++ b/include/service/entities/site_service.js @@ -99,5 +99,18 @@ module.exports = function SiteServiceModule(pb) { async.series(tasks, cb); }; + SiteService.prototype.initSites = function(cb) { + this.getActiveSites(function(err, results) { + if(err) { + cb(err); + } else { + util.forEach(results, function(site) { + pb.RequestHandler.loadSite(site); + }) + cb(err,true); + } + }); + }; + return SiteService; }; diff --git a/pencilblue.js b/pencilblue.js index bcb860228..c889d92a0 100755 --- a/pencilblue.js +++ b/pencilblue.js @@ -60,6 +60,7 @@ function PencilBlue(config){ util.wrapTask(this, this.initServer), this.initSessions, this.initPlugins, + this.initSites, this.initServerRegistration, this.initCommandService, this.initLibraries @@ -128,6 +129,15 @@ function PencilBlue(config){ pluginService.initPlugins(cb); }; + /** + * + */ + this.initSites = function(cb) + { + var siteService = new pb.SiteService(); + siteService.initSites(cb); + } + /** * Attempts to initialize a connection pool to the core database * @static From 00497e7bbcc352b0c812f4a3ca2b1e237aa0d17a Mon Sep 17 00:00:00 2001 From: Andrew Monroe Date: Mon, 13 Apr 2015 10:33:57 -0400 Subject: [PATCH 005/790] allow site injection in plugin service --- include/service/entities/plugin_service.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/include/service/entities/plugin_service.js b/include/service/entities/plugin_service.js index 6b51ddce4..9cba8f15f 100755 --- a/include/service/entities/plugin_service.js +++ b/include/service/entities/plugin_service.js @@ -36,11 +36,19 @@ module.exports = function PluginServiceModule(pb) { * @module Services * @submodule Entities */ - function PluginService(){ + function PluginService(siteUID){ //construct settings services var caching = pb.config.plugins.caching; + + if(pb.config.multisite && siteUID) + { + this.site = siteUID; + } else { + this.site = 'global'; + } + /** * A setting service that sets and retrieves the settings for plugins * @property pluginSettingsService From 0f5d99954e35de8a097fc67a580565987136f328 Mon Sep 17 00:00:00 2001 From: Andrew Monroe Date: Tue, 14 Apr 2015 13:49:13 -0400 Subject: [PATCH 006/790] make initial attempt at making settings and surrounding services site aware --- include/config.js | 8 +-- include/dao/dao.js | 42 ++++++++++++ include/service/cache_entity_service.js | 53 ++++++++++----- include/service/db_entity_service.js | 19 ++++-- include/service/entities/plugin_service.js | 4 +- include/service/memory_entity_service.js | 75 +++++++++++++++++----- 6 files changed, 158 insertions(+), 43 deletions(-) diff --git a/include/config.js b/include/config.js index 0068bab19..f6dfbbc6b 100755 --- a/include/config.js +++ b/include/config.js @@ -240,19 +240,19 @@ var BASE_CONFIG = { //plugin settings { collection: 'plugin_settings', - spec: {plugin_uid: ASC}, + spec: {plugin_uid: ASC, site: ASC}, options: {unique: true} }, { collection: 'plugin_settings', - spec: {plugin_id: ASC}, + spec: {plugin_id: ASC, site: ASC}, options: {unique: true} }, //settings { collection: 'setting', - spec: {key: ASC}, + spec: {key: ASC, site: ASC}, options: {unique: true} }, @@ -271,7 +271,7 @@ var BASE_CONFIG = { //plugin { collection: 'plugin', - spec: {uid: ASC}, + spec: {uid: ASC, site: ASC}, options: {unique: true} }, { diff --git a/include/dao/dao.js b/include/dao/dao.js index 5aec014da..c3d0f2d36 100755 --- a/include/dao/dao.js +++ b/include/dao/dao.js @@ -85,6 +85,9 @@ module.exports = function DAOModule(pb) { */ DAO.DESC = -1; + var GLOBAL_PREFIX = 'global'; + var SITE_COLL = 'site'; + /** * Retrieves an object by ID * @@ -114,6 +117,40 @@ module.exports = function DAOModule(pb) { this.loadByValues(where, collection, opts, cb); }; + DAO.prototype.loadByValueAvailableToSite = function(key, val, site, collection, opts, cb) { + var self = this; + this.loadByValueForOneSite(key, val, site, collection, opts, function(err, result) { + if (util.isError(err)) { + return cb(err); + } + + //ensure setting exists + if (!result){ + self.loadByValueFromGlobal(key, val, collection, opts, cb); + return; + } else { + cb(null, result); + } + }); + }; + + DAO.prototype.loadByValueForOneSite = function(key, val, site, collection, opts, cb) { + var where = {}; + where[key] = val; + where[SITE_COLL] = site; + this.loadByValues(where, collection, opts, cb); + }; + + DAO.prototype.loadByValueFromGlobal = function(key, val, collection, opts, cb) { + var where = {}; + where[key] = val; + where['$or'] = [ + { SITE_COLL: { $exists : false }}, + { SITE_COLL: GLOBAL_PREFIX } + ]; + this.loadByValues(where, collection, opts, cb); + } + /** * Retrieves object matching several key value pairs * @@ -406,6 +443,11 @@ module.exports = function DAOModule(pb) { }); }; + DAO.prototype.saveToSite = function(dbObj, site, options, cb) { + dbObj[SITE_COLL] = site || GLOBAL_PREFIX; + this.save(dbObj, options, cb); + }; + /** * Provides a mechanism to save an array of objects all from the same * collection. The function handles updates and inserts. The difference is diff --git a/include/service/cache_entity_service.js b/include/service/cache_entity_service.js index 11305e9b9..79223e1fb 100755 --- a/include/service/cache_entity_service.js +++ b/include/service/cache_entity_service.js @@ -35,13 +35,16 @@ module.exports = function CacheEntityServiceModule(pb) { * @param {String} valueField * @param {String} keyField */ - function CacheEntityService(objType, valueField, keyField){ + function CacheEntityService(objType, valueField, keyField, site){ this.type = 'Cache'; this.objType = objType; this.keyField = keyField; this.valueField = valueField ? valueField : null; + this.site = site || GLOBAL_PREFIX; } + var GLOBAL_PREFIX = 'global'; + /** * Retrieve a value from the cache * @@ -52,30 +55,46 @@ module.exports = function CacheEntityServiceModule(pb) { CacheEntityService.prototype.get = function(key, cb){ var self = this; - pb.cache.get(key, function(err, result){ + pb.cache.get(keyValue(key, this.site), function(err, result){ if (util.isError(err)) { cb(err, null); return; } - //value doesn't exist in cache - if (result == null) { - cb(null, null); - return; - } + //site specific value doesn't exist in cache + if (result == null && self.site !== GLOBAL_PREFIX) { + pb.cache.get(keyValue(key, GLOBAL_PREFIX), function(err, result){ + if (util.isError(err)) { + cb(err, null); + return; + } + + //value doesn't exist in cache + if (result == null) { + cb(null, null); + return; + } - //value exists - var val = result; - if (self.valueField != null){ - var rawVal = JSON.parse(result); - val = rawVal[self.valueField]; + //make call back + cb(null, getRightFieldFromValue(result, self.valueField)); + }); + return; } //make call back - cb(null, val); + cb(null, getRightFieldFromValue(result, self.valueField)); }); }; + function getRightFieldFromValue(result, valueField) { + var val = result; + if (valueField != null){ + var rawVal = JSON.parse(result); + val = rawVal[valueField]; + } + return val; + } + /** * Set a value in the cache * @@ -86,7 +105,7 @@ module.exports = function CacheEntityServiceModule(pb) { */ CacheEntityService.prototype.set = function(key, value, cb) { var self = this; - pb.cache.get(key, function(err, result){ + pb.cache.get(keyValue(key, this.site), function(err, result){ if (util.isError(err)) { cb(err, null); return; @@ -117,6 +136,10 @@ module.exports = function CacheEntityServiceModule(pb) { }); }; + function keyValue(key, site) { + return site + '_' + key; + } + /** * Purge the cache of a value * @@ -125,7 +148,7 @@ module.exports = function CacheEntityServiceModule(pb) { * @param {Function} cb Callback function */ CacheEntityService.prototype.purge = function(key, cb) { - pb.cache.del(key, cb); + pb.cache.del(keyValue(key, this.site), cb); }; return CacheEntityService; diff --git a/include/service/db_entity_service.js b/include/service/db_entity_service.js index 689cea17c..63300f992 100755 --- a/include/service/db_entity_service.js +++ b/include/service/db_entity_service.js @@ -31,13 +31,16 @@ module.exports = function DbEntityServiceModule(pb) { * @param {String} valueField * @param {String} keyField */ - function DbEntityService(objType, valueField, keyField){ + function DbEntityService(objType, valueField, keyField, site){ this.type = 'DB'; this.objType = objType; this.keyField = keyField; this.valueField = valueField ? valueField : null; + this.site = site || GLOBAL_PREFIX; } + var GLOBAL_PREFIX = 'global'; + var SITE_COLL = 'site'; /** * Retrieve a value from the database * @@ -51,7 +54,7 @@ module.exports = function DbEntityServiceModule(pb) { where[this.keyField] = key; var self = this; - dao.loadByValue(this.keyField, key, this.objType, function(err, entity){ + dao.loadByValueAvailableToSite(this.keyField, key, this.site, this.objType, function(err, entity){ if (util.isError(err)) { return cb(err); } @@ -83,7 +86,7 @@ module.exports = function DbEntityServiceModule(pb) { where[this.keyField] = key; var self = this; - dao.loadByValue(this.keyField, key, this.objType, function(err, result){ + dao.loadByValueForOneSite(this.keyField, key, this.site, this.objType, function(err, result){ if (util.isError(err)) { return cb(err); } @@ -109,7 +112,7 @@ module.exports = function DbEntityServiceModule(pb) { } //set into cache - dao.save(val, cb); + dao.saveToSite(val, self.site, cb); }); }; @@ -124,6 +127,14 @@ module.exports = function DbEntityServiceModule(pb) { var dao = new pb.DAO(); var where = {}; where[this.keyField] = key; + if(!this.site || this.site === GLOBAL_PREFIX) { + where['$or'] = [ + { SITE_COLL: { $exists : false }}, + { SITE_COLL: GLOBAL_PREFIX } + ]; + } else { + where[SITE_COLL] = this.site; + } dao.delete(where, this.objType, cb); }; diff --git a/include/service/entities/plugin_service.js b/include/service/entities/plugin_service.js index 9cba8f15f..bc1c0def1 100755 --- a/include/service/entities/plugin_service.js +++ b/include/service/entities/plugin_service.js @@ -41,9 +41,7 @@ module.exports = function PluginServiceModule(pb) { //construct settings services var caching = pb.config.plugins.caching; - - if(pb.config.multisite && siteUID) - { + if(pb.config.multisite && siteUID) { this.site = siteUID; } else { this.site = 'global'; diff --git a/include/service/memory_entity_service.js b/include/service/memory_entity_service.js index 41093b7c2..b891f4aed 100755 --- a/include/service/memory_entity_service.js +++ b/include/service/memory_entity_service.js @@ -40,11 +40,15 @@ module.exports = function MemoryEntityServiceModule(pb) { this.timers = {}; this.timeout = options.timeout || 0; this.changeHandler = MemoryEntityService.createChangeHandler(this); + this.site = options.site || 'global'; //register change handler pb.CommandService.getInstance().registerForType(MemoryEntityService.getOnChangeType(this.objType), this.changeHandler); } + + var GLOBAL_PREFIX = 'global'; + /** * The type string that describes the storage medium for the service * @private @@ -63,26 +67,56 @@ module.exports = function MemoryEntityServiceModule(pb) { * @param {Function} cb Callback function */ MemoryEntityService.prototype.get = function(key, cb){ + var value = null; + if(this.site) { + value = getSiteValue(this, key, this.site); + } + if(value == null && this.site !== GLOBAL_PREFIX) { + value = getGlobalValue(this, key); + } + cb(null, value); + }; + + function getSiteValue(self, key, site) + { var rawVal = null; - if (this.storage.hasOwnProperty(key)) { - rawVal = this.storage[key]; + if (self.storage.hasOwnProperty(site) && self.storage[site].hasOwnProperty(key)) { + rawVal = self.storage[site][key]; } //value not found if (rawVal == null) { - cb(null, null); - return; + return null; + } + + return getCorrectValueField(rawVal, self.ValueField); + } + + function getGlobalValue(self, key) + { + var rawVal = null; + if (self.storage.hasOwnProperty(GLOBAL_PREFIX) && self.storage[GLOBAL_PREFIX].hasOwnProperty(key)) { + rawVal = self.storage[GLOBAL_PREFIX][key]; + } + + //value not found + if (rawVal == null) { + return null; } + return getCorrectValueField(rawVal, self.ValueField); + } + + function getCorrectValueField(rawVal, valueField) { var value = null; - if (this.valueField == null) { + if (valueField == null) { value = rawVal; } else { - value = rawVal[this.valueField]; + value = rawVal[valueField]; } - cb(null, value); - }; + return value; + } /** * Set a value in memory. Triggers a command to be sent to the cluster to @@ -112,8 +146,11 @@ module.exports = function MemoryEntityServiceModule(pb) { */ MemoryEntityService.prototype._set = function(key, value, cb) { var rawValue = null; - if (this.storage.hasOwnProperty(key)) { - rawValue = this.storage[key]; + if(!this.site) { + this.site = GLOBAL_PREFIX; + } + if (this.storage.hasOwnProperty(this.site) && this.storage[this.site].hasOwnProperty(key)) { + rawValue = this.storage[this.site][key]; if (this.valueField == null) { rawValue = value; } @@ -131,7 +168,8 @@ module.exports = function MemoryEntityServiceModule(pb) { rawValue[this.keyField] = key; rawValue[this.valueField] = value; } - this.storage[key] = rawValue; + this.storage[this.site] = {}; + this.storage[this.site][key] = rawValue; //check for existing timeout this.setKeyExpiration(key); @@ -148,6 +186,7 @@ module.exports = function MemoryEntityServiceModule(pb) { var command = { key: key, value: value, + site: this.site, ignoreme: true }; pb.CommandService.getInstance() @@ -173,7 +212,7 @@ module.exports = function MemoryEntityServiceModule(pb) { //now set the timeout if configured to do so var self = this; - this.timers[key] = setTimeout(function() { + this.timers[this.site][key] = setTimeout(function() { self.purge(key, util.cb) }, this.timeout); }; @@ -186,9 +225,9 @@ module.exports = function MemoryEntityServiceModule(pb) { * @param {Function} cb Callback function */ MemoryEntityService.prototype.purge = function(key, cb) { - var exists = this.storage.hasOwnProperty(key); + var exists = this.storage.hasOwnProperty(this.site) && this.storage[this.site].hasOwnProperty(key); if(exists) { - delete this.storage[key]; + delete this.storage[this.site][key]; } cb(null, exists); }; @@ -202,8 +241,10 @@ module.exports = function MemoryEntityServiceModule(pb) { this.storage = null; var self = this; - Object.keys(this.timers).forEach(function(key) { - clearTimeout(self.timers[key]); + Object.keys(this.timers).forEach(function(site) { + Object.keys(this.timers[site]).forEach(function(key){ + clearTimeout(self.timers[key]); + }); }); this.timers = null; @@ -232,7 +273,7 @@ module.exports = function MemoryEntityServiceModule(pb) { */ MemoryEntityService.createChangeHandler = function(memoryEntityService) { return function(command) { - memoryEntityService._set(command.key, command.value, util.cb); + memoryEntityService._set(command.key, command.value, command.site, util.cb); }; }; From 7947189d1942e12d4ce1de6bdb0390e15e5fd839 Mon Sep 17 00:00:00 2001 From: Andrew Monroe Date: Wed, 15 Apr 2015 11:44:51 -0400 Subject: [PATCH 007/790] add site based routing support --- include/http/request_handler.js | 107 +++++++++++++++------ include/service/entities/plugin_service.js | 24 +++-- include/system/settings.js | 9 +- 3 files changed, 100 insertions(+), 40 deletions(-) diff --git a/include/http/request_handler.js b/include/http/request_handler.js index 2df19bae2..10e6f9c64 100755 --- a/include/http/request_handler.js +++ b/include/http/request_handler.js @@ -76,7 +76,7 @@ module.exports = function RequestHandlerModule(pb) { RequestHandler.storage = []; RequestHandler.index = {}; RequestHandler.sites = {}; - + var GLOBAL_PREFIX = 'global'; /** * The internal storage of static routes after they are validated and processed. * @private @@ -189,7 +189,13 @@ module.exports = function RequestHandlerModule(pb) { * @param {String} The theme that owns the route * @return {Boolean} TRUE if the route was found and removed, FALSE if not */ - RequestHandler.unregisterRoute = function(path, theme) { + RequestHandler.unregisterRoute = function(path, theme, site) { + //resolve the site + if(!site) + { + site = GLOBAL_PREFIX; + } + //get the pattern to check for var pattern = null; @@ -208,12 +214,19 @@ module.exports = function RequestHandlerModule(pb) { //check for theme var descriptor = RequestHandler.storage[RequestHandler.index[pattern]]; - if (!descriptor.themes[theme]) { + + //return false if specified site has no themes registered on that descriptor + //return false if theme doesnt exist on descriptor for that site + if (!descriptor.themes[site] || !descriptor.themes[site][theme]) { return false; } //remove from service - delete descriptor.themes[theme]; + delete descriptor.themes[site][theme]; + descriptor.themes[site].size--; + if(descriptor.themes[site].size < 1) { + delete descriptor.themes[site]; + } return true; }; @@ -238,7 +251,13 @@ module.exports = function RequestHandlerModule(pb) { * @param {String} theme The plugin/theme UID * @return {Boolean} TRUE if the route was registered, FALSE if not */ - RequestHandler.registerRoute = function(descriptor, theme){ + RequestHandler.registerRoute = function(descriptor, theme, site){ + //resolve empty site to global + if(!site) + { + site = GLOBAL_PREFIX; + } + //validate route if (!RequestHandler.isValidRoute(descriptor)) { pb.log.error("Route Validation Failed for: "+JSON.stringify(descriptor)); @@ -287,12 +306,20 @@ module.exports = function RequestHandlerModule(pb) { }; } + //if the site has no themes on this route, add it + if(!routeDescriptor.themes[site]) + { + routeDescriptor.themes[site] = {}; + routeDescriptor.themes[site].size = 0; + } + //set the descriptor for the theme and load the controller type - if (!routeDescriptor.themes[theme]) { - routeDescriptor.themes[theme] = {}; + if (!routeDescriptor.themes[site][theme]) { + routeDescriptor.themes[site][theme] = {}; + routeDescriptor.themes[site].size++; } - routeDescriptor.themes[theme][descriptor.method] = descriptor; - routeDescriptor.themes[theme][descriptor.method].controller = require(descriptor.controller)(pb); + routeDescriptor.themes[site][theme][descriptor.method] = descriptor; + routeDescriptor.themes[site][theme][descriptor.method].controller = require(descriptor.controller)(pb); //only add the descriptor it is new. We do it here because we need to //know that the controller is good. @@ -560,8 +587,8 @@ module.exports = function RequestHandlerModule(pb) { //set the session this.session = session; - //set the site - var site = RequestHandler.sites[this.url.hostname]; + //set the site -- how do we handle improper sites here? + this.site = RequestHandler.sites[this.url.hostname] || GLOBAL_PREFIX; //find the controller to hand off to var route = this.getRoute(this.url.pathname); @@ -573,7 +600,8 @@ module.exports = function RequestHandlerModule(pb) { //get active theme var self = this; - pb.settings.get('active_theme', function(err, activeTheme){ + var settings = pb.SettingServiceFactory.getService(pb.config.settings.use_memory, pb.config.settings.use_cache, this.site); + settings.get('active_theme', function(err, activeTheme){ if (!activeTheme) { pb.log.warn("RequestHandler: The active theme is not set. Defaulting to '%s'", RequestHandler.DEFAULT_THEME); activeTheme = RequestHandler.DEFAULT_THEME; @@ -595,10 +623,12 @@ module.exports = function RequestHandlerModule(pb) { var isSilly = pb.log.isSilly(); var route = RequestHandler.staticRoutes[path]; if (!util.isNullOrUndefined(route)) { - if (isSilly) { - pb.log.silly('RequestHandler: Found static route [%s]', path); + if(route.themes[this.site] || route.themes[GLOBAL_PREFIX]) { + if (isSilly) { + pb.log.silly('RequestHandler: Found static route [%s]', path); + } + return route; } - return route; } //now do the hard work. Iterate over the available patterns until a @@ -612,14 +642,16 @@ module.exports = function RequestHandlerModule(pb) { pb.log.silly('RequestHandler: Comparing Path [%s] to Pattern [%s] Result [%s]', path, curr.pattern, result); } if (result) { - route = curr; + if(curr.themes[this.site] || curr.themes[GLOBAL_PREFIX]) { + return curr; + } break; } } //ensures we return null when route is not found for backward //compatibility. - return route || null; + return null; }; /** @@ -642,10 +674,17 @@ module.exports = function RequestHandlerModule(pb) { * @param {Object} route * @param {String} theme The theme * @param {String} method HTTP method + * @param {string} site current site * @return {Boolean} */ - RequestHandler.routeSupportsTheme = function(route, theme, method) { - return !util.isNullOrUndefined(route.themes[theme]) && RequestHandler.routeSupportsMethod(route.themes[theme], method); + RequestHandler.routeSupportsSiteTheme = function(route, theme, method, site) { + return !util.isNullOrUndefined(route.themes[site]) + && !util.isNullOrUndefined(route.themes[site][theme]) + && RequestHandler.routeSupportsMethod(route.themes[site][theme], method); + }; + + RequestHandler.routeSupportsGlobalTheme = function(route, theme, method) { + return RequestHandler.routeSupportsSiteTheme(route, theme, method, GLOBAL_PREFIX); }; /** @@ -658,7 +697,7 @@ module.exports = function RequestHandlerModule(pb) { * @return {Object} An object with two properties: theme and method */ RequestHandler.prototype.getRouteTheme = function(activeTheme, route) { - var obj = {theme: null, method: null}; + var obj = {theme: null, method: null, site: null}; var methods = [this.req.method, 'ALL']; for (var i = 0; i < methods.length; i++) { @@ -669,10 +708,15 @@ module.exports = function RequestHandlerModule(pb) { for (var j = 0; j < themesToCheck.length; j++) { //see if theme supports method and provides support - if (RequestHandler.routeSupportsTheme(route, themesToCheck[j], methods[i])) { + if (RequestHandler.routeSupportsSiteTheme(route, themesToCheck[j], methods[i], this.site)) { obj.theme = themesToCheck[j]; obj.method = methods[i]; + obj.site = this.site; return obj; + } else if (RequestHandler.routeSupportsGlobalTheme(route, themesToCheck[j], methods[i])) { + obj.theme = themesToCheck[j]; + obj.method = methods[i]; + obj.site = GLOBAL_PREFIX; } } } @@ -696,13 +740,13 @@ module.exports = function RequestHandlerModule(pb) { } //sanity check - if (rt.theme === null || rt.method === null) { + if (rt.theme === null || rt.method === null || rt.site === null) { this.serve404(); return; } //do security checks - this.checkSecurity(rt.theme, rt.method, function(err, result) { + this.checkSecurity(rt.theme, rt.method, rt.site, function(err, result) { if (pb.log.isSilly()) { pb.log.silly("RequestHandler: Security Result=[%s]", result.success); for (var key in result.results) { @@ -711,7 +755,7 @@ module.exports = function RequestHandlerModule(pb) { } //all good if (result.success) { - return self.onSecurityChecksPassed(rt.theme, rt.method, route); + return self.onSecurityChecksPassed(rt.theme, rt.method, rt.site, route); } //handle failures through bypassing other processing and doing output @@ -724,9 +768,10 @@ module.exports = function RequestHandlerModule(pb) { * @method onSecurityChecksPassed * @param {String} activeTheme * @param {String} method + * @param {String} site * @param {Object} route */ - RequestHandler.prototype.onSecurityChecksPassed = function(activeTheme, method, route) { + RequestHandler.prototype.onSecurityChecksPassed = function(activeTheme, method, site, route) { //extract path variables var pathVars = {}; @@ -736,9 +781,9 @@ module.exports = function RequestHandlerModule(pb) { } //execute controller - var ControllerType = route.themes[activeTheme][method].controller; + var ControllerType = route.themes[site][activeTheme][method].controller; var cInstance = new ControllerType(); - this.doRender(pathVars, cInstance, route.themes[activeTheme][method]); + this.doRender(pathVars, cInstance, route.themes[site][activeTheme][method]); }; /** @@ -767,7 +812,8 @@ module.exports = function RequestHandlerModule(pb) { localization_service: self.localizationService, path_vars: pathVars, query: self.url.query, - body: body + body: body, + site: this.site }; cInstance.init(props, function(){ self.onControllerInitialized(cInstance, themeRoute); @@ -961,11 +1007,12 @@ module.exports = function RequestHandlerModule(pb) { * @method checkSecurity * @param {String} activeTheme * @param {String} method + * @param {String} site * @param {Function} cb */ - RequestHandler.prototype.checkSecurity = function(activeTheme, method, cb){ + RequestHandler.prototype.checkSecurity = function(activeTheme, method, site, cb){ var self = this; - this.themeRoute = this.route.themes[activeTheme][method]; + this.themeRoute = this.route.themes[site][activeTheme][method]; //verify if setup is needed var checkSystemSetup = function(callback) { diff --git a/include/service/entities/plugin_service.js b/include/service/entities/plugin_service.js index bc1c0def1..858ab2051 100755 --- a/include/service/entities/plugin_service.js +++ b/include/service/entities/plugin_service.js @@ -27,6 +27,8 @@ var util = require('../../util.js'); module.exports = function PluginServiceModule(pb) { + var GLOBAL_PREFIX = 'global'; + /** * PluginService - Provides functions for interacting with plugins. * Install/uninstall, setting retrieval, plugin retrieval, etc. @@ -44,7 +46,7 @@ module.exports = function PluginServiceModule(pb) { if(pb.config.multisite && siteUID) { this.site = siteUID; } else { - this.site = 'global'; + this.site = GLOBAL_PREFIX; } /** @@ -92,6 +94,15 @@ module.exports = function PluginServiceModule(pb) { */ var ACTIVE_PLUGINS = {}; + function getThemeForSite(theme, site) { + if (ACTIVE_PLUGINS[this.site] && ACTIVE_PLUGINS[this.site][theme]) { + return ACTIVE_PLUGINS[this.site][theme]; + } else if (ACTIVE_PLUGINS[GLOBAL_PREFIX] && ACTIVE_PLUGINS[GLOBAL_PREFIX][theme]) { + return ACTIVE_PLUGINS[GLOBAL_PREFIX][theme]; + } + return null; + } + /** * The name of the collection where plugin descriptors are stored * @private @@ -108,11 +119,12 @@ module.exports = function PluginServiceModule(pb) { * @param {Function} cb A callback that provides two parameters: cb(Error, URL_PATH_TO_ICON) */ PluginService.prototype.getActiveIcon = function(cb) { - pb.settings.get('active_theme', function(err, theme) { - if (ACTIVE_PLUGINS[theme] && ACTIVE_PLUGINS[theme].icon) { - cb(err, ACTIVE_PLUGINS[theme].icon); - } - else { + var settings = pb.SettingServiceFactory.getService(pb.config.settings.use_memory, pb.config.settings.use_cache, this.site); + settings.get('active_theme', function(err, theme) { + var active_theme = getThemeForSite(this.site, theme); + if(active_theme && active_theme.icon) { + cb(err, active_theme.icon); + } else { cb(err, '/favicon.ico'); } }); diff --git a/include/system/settings.js b/include/system/settings.js index 51ad841fb..6f019c7f6 100755 --- a/include/system/settings.js +++ b/include/system/settings.js @@ -44,7 +44,7 @@ module.exports = function SettingsModule(pb) { * @param {Boolean} useCache * @return {SimpleLayeredService} */ - SettingServiceFactory.getService = function(useMemory, useCache) { + SettingServiceFactory.getService = function(useMemory, useCache, site) { var objType = 'setting'; var keyField = 'key'; var valueField = 'value'; @@ -56,18 +56,19 @@ module.exports = function SettingsModule(pb) { objType: objType, valueField: valueField, keyField: keyField, - timeout: pb.config.settings.memory_timeout + timeout: pb.config.settings.memory_timeout, + site: site }; services.push(new pb.MemoryEntityService(options)); } //add cache service if (useCache) { - services.push(new pb.CacheEntityService(objType, valueField, keyField)); + services.push(new pb.CacheEntityService(objType, valueField, keyField, site)); } //always add db service - services.push(new pb.DBEntityService(objType, valueField, keyField)); + services.push(new pb.DBEntityService(objType, valueField, keyField, site)); return new pb.SimpleLayeredService(services, 'SettingService' + count++); }; From 89e1d75fef1bddfd9eef22838b2125ad2a4ad6fc Mon Sep 17 00:00:00 2001 From: Andrew Monroe Date: Fri, 17 Apr 2015 13:56:05 -0400 Subject: [PATCH 008/790] checkpoint converting plugin_service --- include/dao/dao.js | 21 +- include/http/request_handler.js | 9 +- include/requirements.js | 3 + include/service/cache_entity_service.js | 39 +- include/service/db_entity_service.js | 23 +- include/service/entities/plugin_service.js | 470 ++++++----------- .../entities/plugin_setting_service.js | 485 ++++++++++++++++++ .../jobs/plugins/plugin_initialize_job.js | 8 +- .../service/jobs/plugins/plugin_job_runner.js | 10 + .../jobs/plugins/plugin_uninstall_job.js | 40 +- include/service/memory_entity_service.js | 15 +- include/system/server_registration.js | 2 +- include/util.js | 12 + 13 files changed, 782 insertions(+), 355 deletions(-) create mode 100644 include/service/entities/plugin_setting_service.js diff --git a/include/dao/dao.js b/include/dao/dao.js index c3d0f2d36..db37e27d2 100755 --- a/include/dao/dao.js +++ b/include/dao/dao.js @@ -135,18 +135,26 @@ module.exports = function DAOModule(pb) { }; DAO.prototype.loadByValueForOneSite = function(key, val, site, collection, opts, cb) { - var where = {}; - where[key] = val; - where[SITE_COLL] = site; - this.loadByValues(where, collection, opts, cb); + if(!site || site === GLOBAL_PREFIX) { + this.loadByValueFromGlobal(key,val,collection,opts,cb); + } else { + var where = {}; + where[key] = val; + where[SITE_COLL] = site; + this.loadByValues(where, collection, opts, cb); + } }; DAO.prototype.loadByValueFromGlobal = function(key, val, collection, opts, cb) { var where = {}; + var hasNoSite = {}; + hasNoSite[SITE_COLL] = { $exists : false }; + var siteIsGlobal = {}; + siteIsGlobal[SITE_COLL] = GLOBAL_PREFIX; where[key] = val; where['$or'] = [ - { SITE_COLL: { $exists : false }}, - { SITE_COLL: GLOBAL_PREFIX } + hasNoSite, + siteIsGlobal ]; this.loadByValues(where, collection, opts, cb); } @@ -175,6 +183,7 @@ module.exports = function DAOModule(pb) { order: opts.order || DAO.NATURAL_ORDER, limit: 1 }; + this.q(collection, options, function(err, result){ cb(err, util.isArray(result) && result.length > 0 ? result[0] : null); }); diff --git a/include/http/request_handler.js b/include/http/request_handler.js index 10e6f9c64..b35e9e21f 100755 --- a/include/http/request_handler.js +++ b/include/http/request_handler.js @@ -168,12 +168,17 @@ module.exports = function RequestHandlerModule(pb) { * @param {String} theme The plugin/theme uid * @return {Integer} The number of routes removed */ - RequestHandler.unregisterThemeRoutes = function(theme) { + RequestHandler.unregisterThemeRoutes = function(theme, site) { + //resolve the site + if(!site) + { + site = GLOBAL_PREFIX; + } var routesRemoved = 0; for (var i = 0; i < RequestHandler.storage.length; i++) { var path = RequestHandler.storage[i].path; - var result = RequestHandler.unregisterRoute(path, theme); + var result = RequestHandler.unregisterRoute(path, theme, site); if (result) { routesRemoved++; } diff --git a/include/requirements.js b/include/requirements.js index 2de6cda46..e0c3a0e85 100755 --- a/include/requirements.js +++ b/include/requirements.js @@ -186,6 +186,9 @@ module.exports = function PB(config) { } }); + //create plugin setting service + pb.PluginSettingService = require(path.join(config.docRoot, '/include/service/entities/plugin_setting_service.js'))(pb); + //media renderers pb.media = { renderers: { diff --git a/include/service/cache_entity_service.js b/include/service/cache_entity_service.js index 79223e1fb..1e7ad2cb9 100755 --- a/include/service/cache_entity_service.js +++ b/include/service/cache_entity_service.js @@ -35,12 +35,13 @@ module.exports = function CacheEntityServiceModule(pb) { * @param {String} valueField * @param {String} keyField */ - function CacheEntityService(objType, valueField, keyField, site){ + function CacheEntityService(objType, valueField, keyField, site, onlyThisSite){ this.type = 'Cache'; this.objType = objType; this.keyField = keyField; this.valueField = valueField ? valueField : null; this.site = site || GLOBAL_PREFIX; + this.onlyThisSite = onlyThisSite ? true : false; } var GLOBAL_PREFIX = 'global'; @@ -62,22 +63,26 @@ module.exports = function CacheEntityServiceModule(pb) { } //site specific value doesn't exist in cache - if (result == null && self.site !== GLOBAL_PREFIX) { - pb.cache.get(keyValue(key, GLOBAL_PREFIX), function(err, result){ - if (util.isError(err)) { - cb(err, null); - return; - } - - //value doesn't exist in cache - if (result == null) { - cb(null, null); - return; - } - - //make call back - cb(null, getRightFieldFromValue(result, self.valueField)); - }); + if (result == null) { + if(self.site !== GLOBAL_PREFIX && !self.onlyThisSite) { + pb.cache.get(keyValue(key, GLOBAL_PREFIX), function(err, result){ + if (util.isError(err)) { + cb(err, null); + return; + } + + //value doesn't exist in cache + if (result == null) { + cb(null, null); + return; + } + + //make call back + cb(null, getRightFieldFromValue(result, self.valueField)); + }); + } else { + cb(null, null); + } return; } diff --git a/include/service/db_entity_service.js b/include/service/db_entity_service.js index 63300f992..576f126de 100755 --- a/include/service/db_entity_service.js +++ b/include/service/db_entity_service.js @@ -31,12 +31,13 @@ module.exports = function DbEntityServiceModule(pb) { * @param {String} valueField * @param {String} keyField */ - function DbEntityService(objType, valueField, keyField, site){ + function DbEntityService(objType, valueField, keyField, site, onlyThisSite){ this.type = 'DB'; this.objType = objType; this.keyField = keyField; this.valueField = valueField ? valueField : null; this.site = site || GLOBAL_PREFIX; + this.onlyThisSite = onlyThisSite ? true : false; } var GLOBAL_PREFIX = 'global'; @@ -54,7 +55,7 @@ module.exports = function DbEntityServiceModule(pb) { where[this.keyField] = key; var self = this; - dao.loadByValueAvailableToSite(this.keyField, key, this.site, this.objType, function(err, entity){ + var callback = function(err, entity){ if (util.isError(err)) { return cb(err); } @@ -69,7 +70,12 @@ module.exports = function DbEntityServiceModule(pb) { //callback with the result cb(null, val); - }); + }; + if(this.onlyThisSite) { + dao.loadByValueForOneSite(this.keyField, key, this.site, this.objType, callback); + } else { + dao.loadByValueAvailableToSite(this.keyField, key, this.site, this.objType, callback); + } }; /** @@ -127,10 +133,17 @@ module.exports = function DbEntityServiceModule(pb) { var dao = new pb.DAO(); var where = {}; where[this.keyField] = key; + + var hasNoSite = {}; + hasNoSite[SITE_COLL] = { $exists : false}; + + var siteIsGlobal = {}; + siteIsGlobal[SITE_COLL] = GLOBAL_PREFIX; + if(!this.site || this.site === GLOBAL_PREFIX) { where['$or'] = [ - { SITE_COLL: { $exists : false }}, - { SITE_COLL: GLOBAL_PREFIX } + hasNoSite, + siteIsGlobal ]; } else { where[SITE_COLL] = this.site; diff --git a/include/service/entities/plugin_service.js b/include/service/entities/plugin_service.js index 858ab2051..f60682f47 100755 --- a/include/service/entities/plugin_service.js +++ b/include/service/entities/plugin_service.js @@ -28,7 +28,7 @@ var util = require('../../util.js'); module.exports = function PluginServiceModule(pb) { var GLOBAL_PREFIX = 'global'; - + var SITE_COLL = 'site'; /** * PluginService - Provides functions for interacting with plugins. * Install/uninstall, setting retrieval, plugin retrieval, etc. @@ -39,29 +39,11 @@ module.exports = function PluginServiceModule(pb) { * @submodule Entities */ function PluginService(siteUID){ - - //construct settings services - var caching = pb.config.plugins.caching; - if(pb.config.multisite && siteUID) { this.site = siteUID; } else { this.site = GLOBAL_PREFIX; } - - /** - * A setting service that sets and retrieves the settings for plugins - * @property pluginSettingsService - * @type {SimpleLayeredService} - */ - this.pluginSettingsService = PluginService.genSettingsService('plugin_settings', caching.useMemory, caching.useCache, 'PluginSettingService'); - - /** - * A setting service that sets and retrieves the settings for plugins - * @property pluginSettingsService - * @type {SimpleLayeredService} - */ - this.themeSettingsService = PluginService.genSettingsService('theme_settings', caching.useMemory, caching.useCache, 'ThemeSettingService'); } //constants @@ -94,7 +76,7 @@ module.exports = function PluginServiceModule(pb) { */ var ACTIVE_PLUGINS = {}; - function getThemeForSite(theme, site) { + function getPluginForSite(theme, site) { if (ACTIVE_PLUGINS[this.site] && ACTIVE_PLUGINS[this.site][theme]) { return ACTIVE_PLUGINS[this.site][theme]; } else if (ACTIVE_PLUGINS[GLOBAL_PREFIX] && ACTIVE_PLUGINS[GLOBAL_PREFIX][theme]) { @@ -121,7 +103,7 @@ module.exports = function PluginServiceModule(pb) { PluginService.prototype.getActiveIcon = function(cb) { var settings = pb.SettingServiceFactory.getService(pb.config.settings.use_memory, pb.config.settings.use_cache, this.site); settings.get('active_theme', function(err, theme) { - var active_theme = getThemeForSite(this.site, theme); + var active_theme = getPluginForSite(this.site, theme); if(active_theme && active_theme.icon) { cb(err, active_theme.icon); } else { @@ -138,14 +120,17 @@ module.exports = function PluginServiceModule(pb) { * @param {String} pluginUid * @return {Boolean} */ - PluginService.deactivatePlugin = function(pluginUid) { + PluginService.deactivatePlugin = function(pluginUid, site) { if (!pb.validation.validateNonEmptyStr(pluginUid)) { throw new Error('A non-existent or empty plugin UID was passed'); } - if (ACTIVE_PLUGINS[pluginUid]) { + if(!site) { + site = GLOBAL_PREFIX; + } - delete ACTIVE_PLUGINS[pluginUid]; + if (ACTIVE_PLUGINS[site] && ACTIVE_PLUGINS[site][pluginUid]) { + delete ACTIVE_PLUGINS[site][pluginUid]; return true; } return false; @@ -158,8 +143,11 @@ module.exports = function PluginServiceModule(pb) { * @param {String} pluginUid * @return {Function} The prototype that is the plugin's main module. */ - PluginService.getActiveMainModule = function(pluginUid) { - return ACTIVE_PLUGINS[pluginUid] ? ACTIVE_PLUGINS[pluginUid].main_module : null; + PluginService.getActiveMainModule = function(pluginUid, site) { + if(!site) { + site = GLOBAL_PREFIX; + } + return (ACTIVE_PLUGINS[site] && ACTIVE_PLUGINS[site][pluginUid]) ? ACTIVE_PLUGINS[site][pluginUid].main_module : null; }; /** @@ -169,7 +157,35 @@ module.exports = function PluginServiceModule(pb) { * initialized successfully within this instance. */ PluginService.prototype.getActivePluginNames = function() { - return Object.keys(ACTIVE_PLUGINS); + var globalPlugins = []; + if(ACTIVE_PLUGINS[GLOBAL_PREFIX]) { + globalPlugins = Object.keys(ACTIVE_PLUGINS[GLOBAL_PREFIX]); + } + var sitePlugins = []; + if(ACTIVE_PLUGINS[this.site]) { + sitePlugins = Object.keys(ACTIVE_PLUGINS[this.site]); + } + var merged = util.dedupeArray(sitePlugins.concat(globalPlugins)); + return merged; + }; + + PluginService.prototype.getAllActivePluginNames = function() { + var pluginNames = []; + var siteNames = Object.keys(ACTIVE_PLUGINS); + for( var i = 0; i < siteNames.length; i++ ) { + var sitePluginNames = Object.keys(ACTIVE_PLUGINS[siteNames[i]]); + for ( var j = 0; j < sitePluginNames.length; j++ ) { + pluginNames.push(siteNames[i] + '_' + sitePluginNames[j]); + } + } + }; + + PluginService.prototype.getActivePluginNamesBySite = function() { + var result = []; + if(ACTIVE_PLUGINS[this.site]) { + result = Object.keys(ACTIVE_PLUGINS[this.site]); + } + return result; }; /** @@ -183,23 +199,8 @@ module.exports = function PluginServiceModule(pb) { * installed. */ PluginService.prototype.getSetting = function(settingName, pluginName, cb) { - this.getSettings(pluginName, function(err, settings) { - if (util.isError(err)) { - cb(err, null); - return; - } - - var val = null; - if (util.isArray(settings)) { - for (var i = 0; i < settings.length; i++) { - if (settingName === settings[i].name) { - val = settings[i].value; - break; - } - } - } - cb(err, val); - }); + settingService = getPluginSettingService(this); + settingService.getSetting(settingName, pluginName, cb); }; /** @@ -211,7 +212,8 @@ module.exports = function PluginServiceModule(pb) { * Null is provided in the event that the plugin is not installed. */ PluginService.prototype.getSettings = function(pluginName, cb) { - this.pluginSettingsService.get(pluginName, cb); + settingService = getPluginSettingService(this); + settingService.getSettings(pluginName, cb); }; /** @@ -228,16 +230,8 @@ module.exports = function PluginServiceModule(pb) { * exists, and a hash of of the plugin's settings' names/values. */ PluginService.prototype.getSettingsKV = function(pluginName, cb) { - this.pluginSettingsService.get(pluginName, function(err, settings) { - if (util.isError(err)) { - return cb(err); - } - else if (!util.isArray(settings)) { - return cb(null, null); - } - - cb(null, util.arrayToObj(settings, 'name', 'value')); - }); + settingService = getPluginSettingService(this); + settingService.getSettingsKV(pluginName, cb); }; /** @@ -251,39 +245,8 @@ module.exports = function PluginServiceModule(pb) { * TRUE if the setting was persisted successfully, FALSE if not. */ PluginService.prototype.setSetting = function(name, value, pluginName, cb) { - var self = this; - - //error checking - if (!PluginService.validateSettingValue(value)) { - cb(new Error("PluginService: The setting value is required when modifing a theme setting"), false); - } - if (!pb.validation.validateNonEmptyStr(name, true)) { - cb(new Error("PluginService: The setting name is required when modifing a theme setting"), false); - } - - //retrieve the settings to modify - this.getSettings(pluginName, function(err, settings) { - if (util.isError(err) || !settings) { - cb(err, false); - return; - } - - var wasFound = false; - for (var i = 0; i < settings.length; i++) { - if (name === settings[i].name) { - settings[i].value = value; - wasFound = true; - break; - } - } - if (!wasFound) { - settings.push({ - name: name, - value: value - }); - } - self.setSettings(settings, pluginName, cb); - }); + settingService = getPluginSettingService(this); + settingService.setSetting(name, value, pluginName, cb); }; /** @@ -296,28 +259,8 @@ module.exports = function PluginServiceModule(pb) { * TRUE if the settings were persisted successfully, FALSE if not. */ PluginService.prototype.setSettings = function(settings, pluginName, cb) { - var self = this; - - //error checking - if (!settings) { - cb(new Error("PluginService: The settings object is required when making changes to plugin settings"), false); - return; - } - if (!pluginName) { - cb(new Error("PluginService: The plugin name is required when making changes to plugin settings"), false); - return; - } - - this.isInstalled(pluginName, function(err, isInstalled) { - if (util.isError(err) || !isInstalled) { - cb(err, false); - return; - } - - self.pluginSettingsService.set(pluginName, settings, function(err, result) { - cb(err, !util.isError(err) && result); - }); - }); + settingService = getPluginSettingService(this); + settingService.setSettings(settings, pluginName, cb); }; /** @@ -331,39 +274,8 @@ module.exports = function PluginServiceModule(pb) { * TRUE if the setting was persisted successfully, FALSE if not. */ PluginService.prototype.setThemeSetting = function(name, value, pluginName, cb) { - var self = this; - - //error checking - if (!PluginService.validateSettingValue(value)) { - cb(new Error("PluginService: The setting value is required when modifing a theme setting"), false); - } - if (!pb.validation.validateNonEmptyStr(name, true)) { - cb(new Error("PluginService: The setting name is required when modifing a theme setting"), false); - } - - //retrieve the settings to modify - this.getThemeSettings(pluginName, function(err, settings) { - if (util.isError(err) || !settings) { - cb(err, false); - return; - } - - var wasFound = false; - for (var i = 0; i < settings.length; i++) { - if (name === settings[i].name) { - settings[i].value = value; - wasFound = true; - break; - } - } - if (!wasFound) { - settings.push({ - name: name, - value: value - }); - } - self.setThemeSettings(settings, pluginName, cb); - }); + settingService = getPluginSettingService(this); + settingService.setThemeSetting(name, value, pluginName, cb); }; /** @@ -376,28 +288,8 @@ module.exports = function PluginServiceModule(pb) { * TRUE if the settings were persisted successfully, FALSE if not. */ PluginService.prototype.setThemeSettings = function(settings, pluginName, cb) { - var self = this; - - //error checking - if (!settings) { - cb(new Error("PluginService: The settings object is required when making changes to theme settings"), false); - return; - } - if (!pluginName) { - cb(new Error("PluginService: The plugin name is required when making changes to theme settings"), false); - return; - } - - this.isInstalled(pluginName, function(err, isInstalled) { - if (util.isError(err) || !isInstalled) { - cb(err, false); - return; - } - - self.themeSettingsService.set(pluginName, settings, function(err, result) { - cb(err, !util.isError(err) && result); - }); - }); + settingService = getPluginSettingService(this); + settingService.setThemeSettings(settings, pluginName, cb); }; /** @@ -409,23 +301,8 @@ module.exports = function PluginServiceModule(pb) { * @param cb A callback that provides two parameters: cb(error, settingValue) */ PluginService.prototype.getThemeSetting = function(settingName, pluginName, cb) { - this.getThemeSettings(pluginName, function(err, settings) { - if (util.isError(err)) { - cb(err, null); - return; - } - - var val = null; - if (util.isArray(settings)) { - for (var i = 0; i < settings.length; i++) { - if (settingName === settings[i].name) { - val = settings[i].value; - break; - } - } - } - cb(err, val); - }); + settingService = getPluginSettingService(this); + settingService.getThemeSetting(settingName, pluginName, cb); }; /** @@ -436,7 +313,8 @@ module.exports = function PluginServiceModule(pb) { * @param cb A callback that provides two parameters: cb(err, settingsObject) */ PluginService.prototype.getThemeSettings = function(pluginName, cb) { - this.themeSettingsService.get(pluginName, cb); + settingService = getPluginSettingService(this); + settingService.getThemeSettings(pluginName, cb); }; /** @@ -453,18 +331,49 @@ module.exports = function PluginServiceModule(pb) { * exists, and a hash of of the plugin's settings' names/values. */ PluginService.prototype.getThemeSettingsKV = function(pluginName, cb) { - this.themeSettingsService.get(pluginName, function(err, settings) { - if (util.isError(err)) { - return cb(err); - } - else if (!util.isArray(settings)) { - return cb(null, null); - } + settingService = getPluginSettingService(this); + settingService.getThemeSettingsKV(pluginName, cb); + }; - cb(null, util.arrayToObj(settings, 'name', 'value')); - }); + + /** + * Loads the settings from a details object and persists them in the DB. Any + * existing settings for the plugin are deleted before the new settings are + * persisted. + * + * @method resetSettings + * @param details The details object to extract the settings from + * @param cb A callback that provides two parameters: cb(error, TRUE/FALSE). + * TRUE if the settings were successfully cleared and reloaded. FALSE if not. + */ + PluginService.prototype.resetSettings = function(details, cb) { + settingService = getPluginSettingService(this); + settingService.resetSettings(details, cb); + }; + + /** + * Loads the Theme settings from a details object and persists them in the DB. Any + * existing theme settings for the plugin are deleted before the new settings + * are persisted. If the plugin does not have a theme then false is provided in + * the callback. + * + * @method resetThemeSettings + * @param details The details object to extract the settings from + * @param cb A callback that provides two parameters: cb(error, TRUE/FALSE). + * TRUE if the settings were successfully cleared and reloaded. FALSE if not. + */ + PluginService.prototype.resetThemeSettings = function(details, cb) { + settingService = getPluginSettingService(this); + settingService.resetThemeSettings(details, cb); }; + function getPluginSettingService(self) { + if(!self.pluginSettingService) { + self.pluginSettingService = new pb.PluginSettingService(self.site); + } + return self.pluginSettingService; + } + /** * Indicates if a plugin by the specified identifier is installed. * @@ -503,6 +412,40 @@ module.exports = function PluginServiceModule(pb) { dao.loadByValues(where, PLUGIN_COLL, cb); }; + PluginService.prototype.getPluginBySite = function(pluginIdentifier, site, cb) { + var hasCorrectIdentifier = { $or: [ + {}, + { + uid: pluginIdentifier + } + ]}; + hasCorrectIdentifier['$or'][0][pb.DAO.getIdField()] = pluginIdentifier; + + var belongsToThisSite = {}; + if(!site || site === GLOBAL_PREFIX) { + var hasNoSite = {}; + hasNoSite[SITE_COLL] = { $exists : false}; + + var siteIsGlobal = {}; + siteIsGlobal[SITE_COLL] = GLOBAL_PREFIX; + + belongsToThisSite = { $or: [ + hasNoSite, + siteIsGlobal + ]}; + } else { + belongsToThisSite = {}; + belongsToThisSite[SITE_COLL] = site; + } + + var where = { + $and: [ hasCorrectIdentifier, belongsToThisSite] + }; + + var dao = new pb.DAO(); + dao.loadByValues(where, PLUGIN_COLL, cb); + } + /** * Retrieves the plugins that have themes associated with them * @method getPluginsWithThemes @@ -527,125 +470,29 @@ module.exports = function PluginServiceModule(pb) { * @param serviceName The name of the service * @return {SimpleLayeredService} */ - PluginService.genSettingsService = function(objType, useMemory, useCache, serviceName) { + PluginService.genSettingsService = function(objType, useMemory, useCache, serviceName, site) { //add in-memory service var services = []; if (useMemory){ var options = { objType: objType, - timeout: pb.config.plugins.caching.memory_timeout + timeout: pb.config.plugins.caching.memory_timeout, + site: site }; services.push(new pb.MemoryEntityService(options)); } //add cache service if (useCache) { - services.push(new pb.CacheEntityService(objType)); + services.push(new pb.CacheEntityService(objType, null, null, site)); } //always add DB - services.push(new pb.DBEntityService(objType, 'settings', 'plugin_uid')); + services.push(new pb.DBEntityService(objType, 'settings', 'plugin_uid', site)); return new pb.SimpleLayeredService(services, serviceName); }; - /** - * Loads the settings from a details object and persists them in the DB. Any - * existing settings for the plugin are deleted before the new settings are - * persisted. - * - * @method resetSettings - * @param details The details object to extract the settings from - * @param cb A callback that provides two parameters: cb(error, TRUE/FALSE). - * TRUE if the settings were successfully cleared and reloaded. FALSE if not. - */ - PluginService.prototype.resetSettings = function(details, cb) { - var self = this; - - //retrieve plugin to prove it exists (plus we need the id) - var pluginName = details.uid; - this.getPlugin(pluginName, function(err, plugin) { - if (util.isError(err) || !plugin) { - return cb(err ? err : new Error("The plugin "+pluginName+" is not installed"), false); - } - - //remove any existing settings - self.pluginSettingsService.purge(pluginName, function (err, result) { - if (util.isError(err) || !result) { - return cb(err, false); - } - - //build the object to persist - var baseDoc = { - plugin_name: plugin.name, - plugin_uid: plugin.uid, - plugin_id: plugin[pb.DAO.getIdField()].toString(), - settings: details.settings - }; - var settings = pb.DocumentCreator.create('plugin_settings', baseDoc); - - //save it - var dao = new pb.DAO(); - dao.save(settings, function(err, result) { - cb(err, !util.isError(err)); - }); - }); - }); - }; - - /** - * Loads the Theme settings from a details object and persists them in the DB. Any - * existing theme settings for the plugin are deleted before the new settings - * are persisted. If the plugin does not have a theme then false is provided in - * the callback. - * - * @method resetThemeSettings - * @param details The details object to extract the settings from - * @param cb A callback that provides two parameters: cb(error, TRUE/FALSE). - * TRUE if the settings were successfully cleared and reloaded. FALSE if not. - */ - PluginService.prototype.resetThemeSettings = function(details, cb) { - var self = this; - - //error checking - var pluginName = details.uid; - if (!details.theme || !details.theme.settings) { - cb(new Error("PluginService: Settings are required when attempting to reset a plugin's theme settings"), false); - return; - } - - //retrieve plugin to prove it exists (plus we need the id) - this.getPlugin(pluginName, function(err, plugin) { - if (util.isError(err) || !plugin) { - cb(err, false); - return; - } - - //remove any existing settings - self.themeSettingsService.purge(pluginName, function (err, result) { - if (util.isError(err) || !result) { - cb(err, false); - return; - } - - //build the object to persist - var baseDoc = { - plugin_name: plugin.name, - plugin_uid: plugin.uid, - plugin_id: plugin[pb.DAO.getIdField()].toString(), - settings: details.theme.settings - }; - var settings = pb.DocumentCreator.create('theme_settings', baseDoc); - - //save it - var dao = new pb.DAO(); - dao.save(settings, function(err, result) { - cb(err, !util.isError(err)); - }); - }); - }); - }; - /** * Retrieves the permission set for a given role. All active plugins are * inspected. @@ -695,8 +542,29 @@ module.exports = function PluginServiceModule(pb) { * @param {String} uid The unique identifier for a plugin * @return {Boolean} TRUE if the plugin is active, FALSE if not */ - PluginService.isActivePlugin = function(uid) { - return ACTIVE_PLUGINS[uid] !== undefined; + PluginService.isActivePlugin = function(uid, site) { + if(!site) { + site = GLOBAL_PREFIX; + } + var plugin = getPluginForSite(uid, site); + if(plugin) { + return true; + } else { + return false; + } + + }; + + PluginService.isPluginActiveBySite = function(uid, site) { + if(!site) { + site = GLOBAL_PREFIX; + } + if(ACTIVE_PLUGINS[site] && ACTIVE_PLUGINS[site][uid]) { + return true; + } else { + return false; + } + }; /** @@ -916,9 +784,11 @@ module.exports = function PluginServiceModule(pb) { var name = util.format('UNINSTALL_PLUGIN_%s', pluginUid); var jobId = options.jobId; + var site = options.site; var job = new pb.PluginUninstallJob(); job.init(name, jobId); job.setPluginUid(pluginUid); + job.setSite(site); job.setRunAsInitiator(options.forCluster === false ? false : true); job.run(cb); return job.getId(); @@ -1134,7 +1004,7 @@ module.exports = function PluginServiceModule(pb) { return cb(new Error('Failed to load main module for plugin '+plugin.uid)); } - ACTIVE_PLUGINS[details.uid] = { + ACTIVE_PLUGINS[self.site][details.uid] = { main_module: mainModule, public_dir: PluginService.getPublicPath(plugin.dirName), permissions: map, @@ -1143,7 +1013,7 @@ module.exports = function PluginServiceModule(pb) { //set icon url (if exists) if (details.icon) { - ACTIVE_PLUGINS[details.uid].icon = PluginService.genPublicPath(details.uid, details.icon); + ACTIVE_PLUGINS[self.site][details.uid].icon = PluginService.genPublicPath(details.uid, details.icon); } process.nextTick(function() {callback(null, true);}); }, @@ -2161,10 +2031,11 @@ module.exports = function PluginServiceModule(pb) { var options = { forCluster: false, - jobId: command.jobId + jobId: command.jobId, + site: command.site } - var pluginService = new PluginService(); + var pluginService = new PluginService(command.site); pluginService.uninstallPlugin(command.pluginUid, options, function(err, result) { var response = { @@ -2262,6 +2133,7 @@ module.exports = function PluginServiceModule(pb) { job.setRunAsInitiator(false) .init(name, command.jobId) .setPluginUid(command.pluginUid) + .setSite(command.site) .run(function(err, result) { var response = { diff --git a/include/service/entities/plugin_setting_service.js b/include/service/entities/plugin_setting_service.js new file mode 100644 index 000000000..2d602f101 --- /dev/null +++ b/include/service/entities/plugin_setting_service.js @@ -0,0 +1,485 @@ +module.exports = function PluginSettingServiceModule(pb) { + + var GLOBAL_PREFIX = 'global'; + + function PluginSettingService(siteUID){ + //construct settings services + this.caching = pb.config.plugins.caching; + + if(pb.config.multisite && siteUID) { + this.site = siteUID; + } else { + this.site = GLOBAL_PREFIX; + } + + this.pluginService = new pb.PluginService(this.site); + + /** + * A setting service that sets and retrieves the settings for plugins + * @property pluginSettingsService + * @type {SimpleLayeredService} + */ + this.pluginSettingsService = genSettingsService('plugin_settings', this.caching.useMemory, this.caching.useCache, 'PluginSettingService', this.site); + + /** + * A setting service that sets and retrieves the settings for plugins + * @property pluginSettingsService + * @type {SimpleLayeredService} + */ + this.themeSettingsService = genSettingsService('theme_settings', this.caching.useMemory, this.caching.useCache, 'ThemeSettingService', this.site); + } + + /** + * Retrieves a single setting for the specified plugin. + * + * @method getSetting + * @param {string} settingName The name of the setting to retrieve + * @param {string} pluginName The name of the plugin who owns the setting + * @param {function} cb A callback that provides two parameters: cb(error, settingValue). + * Null is returned if the setting does not exist or the specified plugin is not + * installed. + */ + PluginSettingService.prototype.getSetting = function(settingName, pluginName, cb) { + this.getSettings(pluginName, function(err, settings) { + if (util.isError(err)) { + cb(err, null); + return; + } + + var val = null; + if (util.isArray(settings)) { + for (var i = 0; i < settings.length; i++) { + if (settingName === settings[i].name) { + val = settings[i].value; + break; + } + } + } + cb(err, val); + }); + }; + + /** + * Retrieves all of the settings for the specfied plugin. + * + * @method getSettings + * @param pluginName The name of the plugin who's settings are being requested + * @param cb A callback that provides two parameters: cb(error, settings). + * Null is provided in the event that the plugin is not installed. + */ + PluginSettingService.prototype.getSettings = function(pluginName, cb) { + this.pluginSettingsService.get(pluginName, cb); + }; + + PluginSettingService.prototype.getSettingsBySite = function(pluginName, cb) { + var settings = getAdminPluginSettingsService(this); + settings.get(pluginName, cb); + } + + /** + * Retrieves the settings for a plugin as hash of key/value pairs. This + * differs from the getSettings function because the getSettings function + * provides the settings in their raw form as an array of objects containing + * multiple properties. In most circumstances just the k/v pair is needed and + * not any additional information about the property. The function takes the + * raw settings array and transforms it into an object where the setting name + * is the property and the setting value is the value. + * @method getSettingsKV + * @param {String} pluginName The unique ID of the plugin who settings are to be retrieved + * @param {Function} cb A callback that takes two parameters. A error, if + * exists, and a hash of of the plugin's settings' names/values. + */ + PluginSettingService.prototype.getSettingsKV = function(pluginName, cb) { + this.pluginSettingsService.get(pluginName, function(err, settings) { + if (util.isError(err)) { + return cb(err); + } + else if (!util.isArray(settings)) { + return cb(null, null); + } + + cb(null, util.arrayToObj(settings, 'name', 'value')); + }); + }; + + /** + * Replaces a single setting for the specified plugin + * + * @method setSetting + * @param name The name of the setting to change + * @param value The new value for the setting + * @param pluginName The plugin who's setting is being changed. + * @param cb A callback that provides two parameters: cb(error, TRUE/FALSE). + * TRUE if the setting was persisted successfully, FALSE if not. + */ + PluginSettingService.prototype.setSetting = function(name, value, pluginName, cb) { + var self = this; + + //error checking + if (!pb.PluginService.validateSettingValue(value)) { + cb(new Error("PluginService: The setting value is required when modifing a theme setting"), false); + } + if (!pb.validation.validateNonEmptyStr(name, true)) { + cb(new Error("PluginService: The setting name is required when modifing a theme setting"), false); + } + + //retrieve the settings to modify + this.getSettings(pluginName, function(err, settings) { + if (util.isError(err) || !settings) { + cb(err, false); + return; + } + + var wasFound = false; + for (var i = 0; i < settings.length; i++) { + if (name === settings[i].name) { + settings[i].value = value; + wasFound = true; + break; + } + } + if (!wasFound) { + settings.push({ + name: name, + value: value + }); + } + self.setSettings(settings, pluginName, cb); + }); + }; + + /** + * Replaces the settings for the specified plugin. + * + * @method setSettings + * @param settings The settings object to be validated and persisted + * @param pluginName The name of the plugin who's settings are being represented + * @param cb A callback that provides two parameters: cb(error, TRUE/FALSE). + * TRUE if the settings were persisted successfully, FALSE if not. + */ + PluginSettingService.prototype.setSettings = function(settings, pluginName, cb) { + var self = this; + + //error checking + if (!settings) { + cb(new Error("PluginSettingService: The settings object is required when making changes to plugin settings"), false); + return; + } + if (!pluginName) { + cb(new Error("PluginSettingService: The plugin name is required when making changes to plugin settings"), false); + return; + } + + this.pluginService.isInstalled(pluginName, function(err, isInstalled) { + if (util.isError(err) || !isInstalled) { + cb(err, false); + return; + } + + self.pluginSettingsService.set(pluginName, settings, function(err, result) { + cb(err, !util.isError(err) && result); + }); + }); + }; + + /** + * Replaces a single theme setting for the specified plugin + * + * @method setThemeSetting + * @param name The name of the setting to change + * @param value The new value for the setting + * @param pluginName The plugin who's setting is being changed. + * @param cb A callback that provides two parameters: cb(error, TRUE/FALSE). + * TRUE if the setting was persisted successfully, FALSE if not. + */ + PluginSettingService.prototype.setThemeSetting = function(name, value, pluginName, cb) { + var self = this; + + //error checking + if (!pb.PluginService.validateSettingValue(value)) { + cb(new Error("PluginService: The setting value is required when modifing a theme setting"), false); + } + if (!pb.validation.validateNonEmptyStr(name, true)) { + cb(new Error("PluginService: The setting name is required when modifing a theme setting"), false); + } + + //retrieve the settings to modify + this.getThemeSettings(pluginName, function(err, settings) { + if (util.isError(err) || !settings) { + cb(err, false); + return; + } + + var wasFound = false; + for (var i = 0; i < settings.length; i++) { + if (name === settings[i].name) { + settings[i].value = value; + wasFound = true; + break; + } + } + if (!wasFound) { + settings.push({ + name: name, + value: value + }); + } + self.setThemeSettings(settings, pluginName, cb); + }); + }; + + /** + * Replaces the theme settings for the specified plugin. + * + * @method setThemeSettings + * @param settings The settings object to be validated and persisted + * @param pluginName The uid of the plugin who's settings are being represented + * @param cb A callback that provides two parameters: cb(error, TRUE/FALSE). + * TRUE if the settings were persisted successfully, FALSE if not. + */ + PluginSettingService.prototype.setThemeSettings = function(settings, pluginName, cb) { + var self = this; + + //error checking + if (!settings) { + cb(new Error("PluginSettingService: The settings object is required when making changes to theme settings"), false); + return; + } + if (!pluginName) { + cb(new Error("PluginSettingService: The plugin name is required when making changes to theme settings"), false); + return; + } + + this.pluginService.isInstalled(pluginName, function(err, isInstalled) { + if (util.isError(err) || !isInstalled) { + cb(err, false); + return; + } + + self.themeSettingsService.set(pluginName, settings, function(err, result) { + cb(err, !util.isError(err) && result); + }); + }); + }; + + /** + * Retrieves a single theme setting value. + * + * @method getThemeSetting + * @param settingName The uid of the setting + * @param pluginName The plugin to retrieve the setting from + * @param cb A callback that provides two parameters: cb(error, settingValue) + */ + PluginSettingService.prototype.getThemeSetting = function(settingName, pluginName, cb) { + this.getThemeSettings(pluginName, function(err, settings) { + if (util.isError(err)) { + cb(err, null); + return; + } + + var val = null; + if (util.isArray(settings)) { + for (var i = 0; i < settings.length; i++) { + if (settingName === settings[i].name) { + val = settings[i].value; + break; + } + } + } + cb(err, val); + }); + }; + + /** + * Retrieves the theme settings for the specified plugin + * + * @method getThemeSettings + * @param pluginName The uid of the plugin + * @param cb A callback that provides two parameters: cb(err, settingsObject) + */ + PluginSettingService.prototype.getThemeSettings = function(pluginName, cb) { + this.themeSettingsService.get(pluginName, cb); + }; + + PluginSettingService.prototype.getThemeSettingsBySite = function(pluginName, cb) { + var settings = getAdminThemeSettingsService(this); + settings.get(pluginName, cb); + } + + /** + * Retrieves the theme settings for a plugin as hash of key/value pairs. This + * differs from the getThemeSettings function because the getThemeSettings function + * provides the settings in their raw form as an array of objects containing + * multiple properties. In most circumstances just the k/v pair is needed and + * not any additional information about the property. The function takes the + * raw settings array and transforms it into an object where the setting name + * is the property and the setting value is the value. + * @method getThemeSettingsKV + * @param {String} pluginName The unique ID of the plugin who settings are to be retrieved + * @param {Function} cb A callback that takes two parameters. A error, if + * exists, and a hash of of the plugin's settings' names/values. + */ + PluginSettingService.prototype.getThemeSettingsKV = function(pluginName, cb) { + this.themeSettingsService.get(pluginName, function(err, settings) { + if (util.isError(err)) { + return cb(err); + } + else if (!util.isArray(settings)) { + return cb(null, null); + } + + cb(null, util.arrayToObj(settings, 'name', 'value')); + }); + }; + + + /** + * Loads the settings from a details object and persists them in the DB. Any + * existing settings for the plugin are deleted before the new settings are + * persisted. + * + * @method resetSettings + * @param details The details object to extract the settings from + * @param cb A callback that provides two parameters: cb(error, TRUE/FALSE). + * TRUE if the settings were successfully cleared and reloaded. FALSE if not. + */ + PluginSettingService.prototype.resetSettings = function(details, cb) { + var self = this; + + //retrieve plugin to prove it exists (plus we need the id) + var pluginName = details.uid; + this.pluginService.getPlugin(pluginName, function(err, plugin) { + if (util.isError(err) || !plugin) { + return cb(err ? err : new Error("The plugin "+pluginName+" is not installed"), false); + } + + //remove any existing settings + self.pluginSettingsService.purge(pluginName, function (err, result) { + if (util.isError(err) || !result) { + return cb(err, false); + } + + //build the object to persist + var baseDoc = { + plugin_name: plugin.name, + plugin_uid: plugin.uid, + plugin_id: plugin[pb.DAO.getIdField()].toString(), + settings: details.settings + }; + var settings = pb.DocumentCreator.create('plugin_settings', baseDoc); + + //save it + var dao = new pb.DAO(); + dao.save(settings, function(err, result) { + cb(err, !util.isError(err)); + }); + }); + }); + }; + + /** + * Loads the Theme settings from a details object and persists them in the DB. Any + * existing theme settings for the plugin are deleted before the new settings + * are persisted. If the plugin does not have a theme then false is provided in + * the callback. + * + * @method resetThemeSettings + * @param details The details object to extract the settings from + * @param cb A callback that provides two parameters: cb(error, TRUE/FALSE). + * TRUE if the settings were successfully cleared and reloaded. FALSE if not. + */ + PluginSettingService.prototype.resetThemeSettings = function(details, cb) { + var self = this; + + //error checking + var pluginName = details.uid; + if (!details.theme || !details.theme.settings) { + cb(new Error("PluginService: Settings are required when attempting to reset a plugin's theme settings"), false); + return; + } + + //retrieve plugin to prove it exists (plus we need the id) + this.pluginService.getPlugin(pluginName, function(err, plugin) { + if (util.isError(err) || !plugin) { + cb(err, false); + return; + } + + //remove any existing settings + self.themeSettingsService.purge(pluginName, function (err, result) { + if (util.isError(err) || !result) { + cb(err, false); + return; + } + + //build the object to persist + var baseDoc = { + plugin_name: plugin.name, + plugin_uid: plugin.uid, + plugin_id: plugin[pb.DAO.getIdField()].toString(), + settings: details.theme.settings + }; + var settings = pb.DocumentCreator.create('theme_settings', baseDoc); + + //save it + var dao = new pb.DAO(); + dao.save(settings, function(err, result) { + cb(err, !util.isError(err)); + }); + }); + }); + }; + + /** + * Convenience function to generate a service to handle settings for a plugin. + * + * @static + * @method genSettingsService + * @param objType The type of object that will be dealt with. (plugin_settings, + * theme_settings) + * @param useMemory {Boolean} Indicates if the generated layered service should + * use an in memory service. + * @param useCache {Boolean} Indicates if the generated layered service should + * use a cache service. + * @param serviceName The name of the service + * @return {SimpleLayeredService} + */ + function genSettingsService(objType, useMemory, useCache, serviceName, site, onlyThisSite) { + + //add in-memory service + var services = []; + if (useMemory){ + var options = { + objType: objType, + timeout: pb.config.plugins.caching.memory_timeout, + site: site, + onlyThisSite: onlyThisSite + }; + services.push(new pb.MemoryEntityService(options)); + } + + //add cache service + if (useCache) { + services.push(new pb.CacheEntityService(objType, null, null, site, onlyThisSite)); + } + + //always add DB + services.push(new pb.DBEntityService(objType, 'settings', 'plugin_uid', site, onlyThisSite)); + return new pb.SimpleLayeredService(services, serviceName); + }; + + function getAdminPluginSettingsService(self) { + if(!self.adminPluginSettingsService) { + self.adminPluginSettingsService = genSettingsService('plugin_settings', this.caching.useMemory, this.caching.useCache, 'PluginSettingService', this.site, true); + } + return self.adminPluginSettingsService; + } + + function getAdminThemeSettingsService(self) { + if(!self.adminThemeSettingsService) { + self.adminThemeSettingsService = genSettingsService('theme_settings', this.caching.useMemory, this.caching.useCache, 'ThemeSettingService', this.site); + } + return self.adminThemeSettingsService; + } + return PluginSettingService; +} \ No newline at end of file diff --git a/include/service/jobs/plugins/plugin_initialize_job.js b/include/service/jobs/plugins/plugin_initialize_job.js index b9c16dbdc..f75ad8803 100644 --- a/include/service/jobs/plugins/plugin_initialize_job.js +++ b/include/service/jobs/plugins/plugin_initialize_job.js @@ -55,6 +55,7 @@ module.exports = function PluginInitializeJobModule(pb) { var validateCommand = { jobId: this.getId(), pluginUid: this.getPluginUid(), + site: this.getSite(), progress: progress }; @@ -76,18 +77,19 @@ module.exports = function PluginInitializeJobModule(pb) { var self = this; var pluginUid = this.getPluginUid(); + var site = this.getSite(); var tasks = [ //initialize the plugin if not already function(callback) { - if (pb.PluginService.isActivePlugin(pluginUid)) { + if (pb.PluginService.isPluginActiveBySite(pluginUid, site)) { self.log('Plugin %s is already active!', pluginUid); callback(null, true); return; } //load the plugin from persistence then initialize it on the server - pb.plugins.getPlugin(pluginUid, function(err, plugin) { + self.pluginService.getPluginBySite(pluginUid, function(err, plugin) { if (util.isError(err)) { callback(err); return; @@ -99,7 +101,7 @@ module.exports = function PluginInitializeJobModule(pb) { } self.log('Initializing plugin %s', pluginUid); - pb.plugins.initPlugin(plugin, function(err, result) { + self.pluginService.initPlugin(plugin, function(err, result) { self.log('Completed initialization RESULT=[%s] ERROR=[%s]', result, err ? err.message : 'n/a'); callback(err, result); }); diff --git a/include/service/jobs/plugins/plugin_job_runner.js b/include/service/jobs/plugins/plugin_job_runner.js index ea6e41696..8b2ff3f9d 100644 --- a/include/service/jobs/plugins/plugin_job_runner.js +++ b/include/service/jobs/plugins/plugin_job_runner.js @@ -65,6 +65,16 @@ module.exports = function PluginJobRunnerModule(pb) { return this.pluginUid; }; + PluginJobRunner.prototype.setSite = function(site) { + this.site = site; + this.pluginService = new pb.PluginService(site); + return this; + } + + PluginJobRunner.prototype.getSite = function() { + return this.site; + } + /** * Called when the tasks have completed execution and isInitiator = FALSE. The * function ispects the results of each processes' execution and attempts to diff --git a/include/service/jobs/plugins/plugin_uninstall_job.js b/include/service/jobs/plugins/plugin_uninstall_job.js index a2418d401..ad921550c 100644 --- a/include/service/jobs/plugins/plugin_uninstall_job.js +++ b/include/service/jobs/plugins/plugin_uninstall_job.js @@ -56,6 +56,9 @@ module.exports = function PluginUninstallJobModule(pb) { */ PluginUninstallJob.UNINSTALL_PLUGIN_COMMAND = 'uninstall_plugin'; + var GLOBAL_PREFIX = 'global'; + var SITE_COLL = 'site'; + /** * Retrieves the tasks needed to contact each process in the cluster to * uninstall the plugin. @@ -68,7 +71,7 @@ module.exports = function PluginUninstallJobModule(pb) { var command = { pluginUid: self.getPluginUid(), jobId: self.getId(), - + site: self.getSite(), //we provide a progress function to update the job listing progress: function(indexOfExecutingTask, totalTasks) { @@ -101,17 +104,18 @@ module.exports = function PluginUninstallJobModule(pb) { var self = this; var pluginUid = this.getPluginUid(); + var site = this.getSite(); var tasks = [ //call onUninstall function(callback) { - if (!pb.PluginService.isActivePlugin(pluginUid)) { + if (!pb.PluginService.isPluginActiveBySite(pluginUid, site)) { self.log("Skipping call to plugin's onUninstall function. Main module was not active."); callback(null, true); return; } - var mm = pb.PluginService.getActiveMainModule(pluginUid); + var mm = pb.PluginService.getActiveMainModule(pluginUid, site); if (util.isFunction(mm.onUninstall)) { self.log('Calling plugin onUnstall', pluginUid); @@ -129,7 +133,7 @@ module.exports = function PluginUninstallJobModule(pb) { //unregister routes function(callback) { - var routesRemoved = pb.RequestHandler.unregisterThemeRoutes(pluginUid); + var routesRemoved = pb.RequestHandler.unregisterThemeRoutes(pluginUid, site); self.log('Unregistered %d routes', routesRemoved); process.nextTick(function(){callback(null, true);}); }, @@ -148,7 +152,7 @@ module.exports = function PluginUninstallJobModule(pb) { function(callback) { self.log('Attemping to remove plugin settings'); - pb.plugins.pluginSettingsService.purge(pluginUid, function (err, result) { + this.pluginService.pluginSettingsService.purge(pluginUid, function (err, result) { callback(err, !util.isError(err) && result); }); }, @@ -157,7 +161,7 @@ module.exports = function PluginUninstallJobModule(pb) { function(callback) { self.log('Attemping to remove theme settings'); - pb.plugins.themeSettingsService.purge(pluginUid, function (err, result) { + this.pluginService.themeSettingsService.purge(pluginUid, function (err, result) { callback(err, !util.isError(err) && result); }); }, @@ -169,6 +173,22 @@ module.exports = function PluginUninstallJobModule(pb) { var where = { uid: pluginUid }; + + var hasNoSite = {}; + hasNoSite[SITE_COLL] = { $exists : false}; + + var siteIsGlobal = {}; + siteIsGlobal[SITE_COLL] = GLOBAL_PREFIX; + + if(!site || site === GLOBAL_PREFIX) { + where['$or'] = [ + hasNoSite, + siteIsGlobal + ]; + } else { + where[SITE_COLL] = site; + } + var dao = new pb.DAO(); dao.delete(where, 'plugin', function(err, result) { callback(err, !util.isError(err)); @@ -181,7 +201,8 @@ module.exports = function PluginUninstallJobModule(pb) { //retrieve the plugin so we can see if the value matches what we //are uninstalling - pb.settings.get('active_theme', function(err, activeTheme) { + var settings = pb.SettingServiceFactory.getService(pb.config.settings.use_memory, pb.config.settings.use_cache, site); + settings.get('active_theme', function(err, activeTheme) { if (util.isError(err)) { return callback(err, false); } @@ -189,8 +210,7 @@ module.exports = function PluginUninstallJobModule(pb) { //check if we need to reset the active theme if (activeTheme === pluginUid) { self.log('Uninstalling the active theme. Switching to pencilblue'); - - pb.settings.set('active_theme', 'pencilblue', function(err, result) { + settings.set('active_theme', 'pencilblue', function(err, result) { callback(err, result ? true : false); }); } @@ -202,7 +222,7 @@ module.exports = function PluginUninstallJobModule(pb) { //remove from ACTIVE_PLUGINS//unregister services function(callback) { - var result = pb.PluginService.deactivatePlugin(pluginUid); + var result = pb.PluginService.deactivatePlugin(pluginUid, site); process.nextTick(function(){callback(null, result);}); } ]; diff --git a/include/service/memory_entity_service.js b/include/service/memory_entity_service.js index b891f4aed..6f86b4114 100755 --- a/include/service/memory_entity_service.js +++ b/include/service/memory_entity_service.js @@ -41,6 +41,7 @@ module.exports = function MemoryEntityServiceModule(pb) { this.timeout = options.timeout || 0; this.changeHandler = MemoryEntityService.createChangeHandler(this); this.site = options.site || 'global'; + this.onlyThisSite = options.onlyThisSite ? true : false; //register change handler pb.CommandService.getInstance().registerForType(MemoryEntityService.getOnChangeType(this.objType), this.changeHandler); @@ -71,7 +72,7 @@ module.exports = function MemoryEntityServiceModule(pb) { if(this.site) { value = getSiteValue(this, key, this.site); } - if(value == null && this.site !== GLOBAL_PREFIX) { + if(value == null && this.site !== GLOBAL_PREFIX && !this.onlyThisSite) { value = getGlobalValue(this, key); } cb(null, value); @@ -94,17 +95,7 @@ module.exports = function MemoryEntityServiceModule(pb) { function getGlobalValue(self, key) { - var rawVal = null; - if (self.storage.hasOwnProperty(GLOBAL_PREFIX) && self.storage[GLOBAL_PREFIX].hasOwnProperty(key)) { - rawVal = self.storage[GLOBAL_PREFIX][key]; - } - - //value not found - if (rawVal == null) { - return null; - } - - return getCorrectValueField(rawVal, self.ValueField); + return getSiteValue(self, key, GLOBAL_PREFIX); } function getCorrectValueField(rawVal, valueField) { diff --git a/include/system/server_registration.js b/include/system/server_registration.js index 704a15601..7ec32ae68 100755 --- a/include/system/server_registration.js +++ b/include/system/server_registration.js @@ -92,7 +92,7 @@ module.exports = function ServerRegistrationModule(pb) { active_plugins: function(cb) { var pluginService = new pb.PluginService(); - cb(null, pluginService.getActivePluginNames()); + cb(null, pluginService.getAllActivePluginNames()); }, uptime: function(cb) { diff --git a/include/util.js b/include/util.js index 6dffb2ed7..d9910ec3f 100755 --- a/include/util.js +++ b/include/util.js @@ -384,6 +384,18 @@ Util.copyArray = function(array) { return clone; }; +Util.dedupeArray = function(array) { + var a = array.concat(); + for(var i = 0; i < a.length; ++i) { + for(var j=i+1; j Date: Tue, 21 Apr 2015 11:09:19 -0400 Subject: [PATCH 009/790] add new plugin repository and continue converting plugin service --- controllers/base_controller.js | 1 + include/repository/plugin_repository.js | 161 ++++++++++++++++++ include/requirements.js | 1 + include/service/entities/plugin_service.js | 80 +++------ .../entities/plugin_setting_service.js | 8 +- 5 files changed, 192 insertions(+), 59 deletions(-) create mode 100644 include/repository/plugin_repository.js diff --git a/controllers/base_controller.js b/controllers/base_controller.js index 38f2fd5a4..4e0089814 100755 --- a/controllers/base_controller.js +++ b/controllers/base_controller.js @@ -102,6 +102,7 @@ module.exports = function BaseControllerModule(pb) { this.pathVars = props.path_vars; this.query = props.query; this.pageName = ''; + this.site = props.site; var self = this; this.templateService = new pb.TemplateService(this.localizationService); diff --git a/include/repository/plugin_repository.js b/include/repository/plugin_repository.js new file mode 100644 index 000000000..9b0c4f5ce --- /dev/null +++ b/include/repository/plugin_repository.js @@ -0,0 +1,161 @@ +var async = require('async'); + +module.exports = function PluginRepositoryModule(pb) { + + var PLUGIN_COLL = 'plugin' + var GLOBAL_PREFIX = 'global'; + var SITE_COLL = 'site'; + + var publicAPI = {}; + + publicAPI.loadPluginsWithThemesAvailableToThisSite = function(site, cb) { + var dao = new pb.DAO(); + var hasATheme = getHasThemeQuery(); + var belongsToSite = getBelongsToSiteQuery(site); + var belongsToGlobal = getBelongsToSiteQuery(GLOBAL_PREFIX); + var siteWhere = { + $and: [ hasATheme, belongsToSite ] + }; + var globalWhere = { + $and: [ hasATheme, belongsToSite ] + }; + var tasks = { + sitePlugins: function(callback) { + dao.q(PLUGIN_COLL, siteWhere, callback); + }, + globalPlugins: function(callback) { + dao.q(PLUGIN_COLL, globalWhere, callback); + } + }; + async.parallel(tasks, function(err, results) { + if(err) { + cb(err, null); + } else { + var sitePlugins = results.sitePlugins || []; + var globalPlugins = results.globalPlugins || []; + var resultArray = mergeSitePluginsWithGlobalPlugins(sitePlugins, globalPlugins); + cb(null, resultArray); + } + }); + }; + + publicAPI.loadPluginsWithThemesOwnedByThisSite = function(site, cb) { + var dao = new pb.DAO(); + var hasATheme = getHasThemeQuery(); + var belongsToSite = getBelongsToSiteQuery(site); + var where = { + $and: [ hasATheme, belongsToSite ] + }; + dao.q(PLUGIN_COLL, where, cb); + }; + + publicAPI.loadPluginOwnedByThisSite = function(pluginID, site, cb) { + var hasCorrectIdentifier = getCorrectIdQuery(pluginID); + var belongsToSite = getBelongsToSiteQuery(site); + + var where = { + $and: [ hasCorrectIdentifier, belongsToThisSite] + }; + + var dao = new pb.DAO(); + dao.loadByValues(where, PLUGIN_COLL, cb); + }; + + publicAPI.loadPluginAvailableToThisSite = function(pluginID, site, cb) { + loadPluginOwnedByThisSite(pluginID, site, function(err, plugin){ + if (util.isError(err)) { + cb(err, null); + return; + } + + if(!plugin) { + if(site && site !== GLOBAL_PREFIX) { + loadPluginOwnedByThisSite(pluginID, GLOBAL_PREFIX, cb); + return; + } + cb(err, null); + } + + cb(err, plugin); + }); + }; + + publicAPI.loadPluginsWithTheseIds = function(pluginIDs, site, cb) { + + }; + + publicAPI.loadPluginsWithoutTheseIds = function(pluginIDs, site, cb) { + + }; + + publicAPI.loadPluginsAcrossAllSites = function(cb) { + + }; + + function getHasThemeQuery() { + var hasATheme = {theme: {$exists: true}}; + return hasATheme; + } + + function getCorrectIdQuery(pluginID){ + var hasCorrectIdentifier = { $or: [ + {}, + { + uid: pluginID + } + ]}; + hasCorrectIdentifier['$or'][0][pb.DAO.getIdField()] = pluginID; + return hasCorrectIdentifier; + } + + function getBelongsToSiteQuery(site) { + var belongsToThisSite = {}; + if(!site || site === GLOBAL_PREFIX) { + var hasNoSite = {}; + hasNoSite[SITE_COLL] = { $exists : false}; + + var siteIsGlobal = {}; + siteIsGlobal[SITE_COLL] = GLOBAL_PREFIX; + + belongsToThisSite = { $or: [ + hasNoSite, + siteIsGlobal + ]}; + } else { + belongsToThisSite = {}; + belongsToThisSite[SITE_COLL] = site; + } + } + + function mergeSitePluginsWithGlobalPlugins(sitePlugins, globalPlugins) { + var resultArray = [].concat(sitePlugins); + + for( var j = 0; j < globalPlugins.length; j++) { + var exists = false; + for( var i = 0; i < sitePlugins.length; i++) { + if(pluginsHaveSameID(globalPlugins[j], sitePlugins[i])) { + exists = true; + } + } + if(!exists) { + resultArray.push(globalPlugins[j]); + } + } + return resultArray; + } + + function pluginsHaveSameID (pluginOne, pluginTwo) { + var otherIDField = pb.DAO.getIdField(); + if(pluginOne.uid && pluginTwo.uid) { + if(pluginOne.uid === pluginTwo.uid) { + return true; + } + } + if(pluginOne[otherIDField] && pluginTwo[otherIDField]) { + if(pluginOne[otherIDField] === pluginTwo[otherIDField]) { + return true; + } + } + return false; + } +}; \ No newline at end of file diff --git a/include/requirements.js b/include/requirements.js index e0c3a0e85..f9cf73e63 100755 --- a/include/requirements.js +++ b/include/requirements.js @@ -188,6 +188,7 @@ module.exports = function PB(config) { //create plugin setting service pb.PluginSettingService = require(path.join(config.docRoot, '/include/service/entities/plugin_setting_service.js'))(pb); + pb.PluginRepository = require(path.join(config.docRoot, '/include/repository/plugin_repository.js'))(pb); //media renderers pb.media = { diff --git a/include/service/entities/plugin_service.js b/include/service/entities/plugin_service.js index f60682f47..a93f6c246 100755 --- a/include/service/entities/plugin_service.js +++ b/include/service/entities/plugin_service.js @@ -44,6 +44,9 @@ module.exports = function PluginServiceModule(pb) { } else { this.site = GLOBAL_PREFIX; } + + this._pluginRepository = pb.PluginRepository; + } //constants @@ -384,7 +387,7 @@ module.exports = function PluginServiceModule(pb) { * TRUE if the plugin is installed, FALSE if not. */ PluginService.prototype.isInstalled = function(pluginIdentifier, cb) { - this.getPlugin(pluginIdentifier, function(err, plugin) { + this.getPluginBySite(pluginIdentifier, function(err, plugin) { cb(err, plugin ? true : false); }); }; @@ -399,51 +402,11 @@ module.exports = function PluginServiceModule(pb) { * plugin does exist null is provided. */ PluginService.prototype.getPlugin = function(pluginIdentifier, cb) { - var where = { - $or: [ - {}, - { - uid: pluginIdentifier - } - ] - }; - where['$or'][0][pb.DAO.getIdField()] = pluginIdentifier; - var dao = new pb.DAO(); - dao.loadByValues(where, PLUGIN_COLL, cb); + _pluginRepository.loadPluginAvailableToThisSite(pluginIdentifier, this.site, cb); }; - PluginService.prototype.getPluginBySite = function(pluginIdentifier, site, cb) { - var hasCorrectIdentifier = { $or: [ - {}, - { - uid: pluginIdentifier - } - ]}; - hasCorrectIdentifier['$or'][0][pb.DAO.getIdField()] = pluginIdentifier; - - var belongsToThisSite = {}; - if(!site || site === GLOBAL_PREFIX) { - var hasNoSite = {}; - hasNoSite[SITE_COLL] = { $exists : false}; - - var siteIsGlobal = {}; - siteIsGlobal[SITE_COLL] = GLOBAL_PREFIX; - - belongsToThisSite = { $or: [ - hasNoSite, - siteIsGlobal - ]}; - } else { - belongsToThisSite = {}; - belongsToThisSite[SITE_COLL] = site; - } - - var where = { - $and: [ hasCorrectIdentifier, belongsToThisSite] - }; - - var dao = new pb.DAO(); - dao.loadByValues(where, PLUGIN_COLL, cb); + PluginService.prototype.getPluginBySite = function(pluginIdentifier, cb) { + _pluginRepository.loadPluginOwnedByThisSite(pluginIdentifier, this.site, cb); } /** @@ -452,10 +415,13 @@ module.exports = function PluginServiceModule(pb) { * @param {Function} cb Provides two parameters: Error, Array */ PluginService.prototype.getPluginsWithThemes = function(cb) { - var dao = new pb.DAO(); - dao.q(PLUGIN_COLL, {where: {theme: {$exists: true}}}, cb); + _pluginRepository.loadPluginsWithThemesAvailableToThisSite(this.site, cb); }; + PluginService.prototype.getPluginsWithThemesBySite = function(cb) { + _pluginRepository.loadPluginsWithThemesOwnedByThisSite(this.site, cb); + } + /** * Convenience function to generate a service to handle settings for a plugin. * @@ -507,13 +473,15 @@ module.exports = function PluginServiceModule(pb) { } var perms = {}; - for(var pluginUid in ACTIVE_PLUGINS) { - var permissions = ACTIVE_PLUGINS[pluginUid].permissions; - if (permissions) { - - var permsAtLevel = permissions[role]; - if (permsAtLevel) { - util.merge(permsAtLevel, perms); + for(var site in ACTIVE_PLUGINS) { + for(var pluginUid in ACTIVE_PLUGINS[site]) { + var permissions = ACTIVE_PLUGINS[site][pluginUid].permissions; + if (permissions) { + + var permsAtLevel = permissions[role]; + if (permsAtLevel) { + util.merge(permsAtLevel, perms); + } } } } @@ -529,8 +497,10 @@ module.exports = function PluginServiceModule(pb) { */ PluginService.getActivePluginPublicDir = function(pluginUid) { var publicPath = null; - if (ACTIVE_PLUGINS[pluginUid]) { - publicPath = ACTIVE_PLUGINS[pluginUid].public_dir; + for(var site in ACTIVE_PLUGINS) { + if (ACTIVE_PLUGINS[site][pluginUid]) { + publicPath = ACTIVE_PLUGINS[site][pluginUid].public_dir; + } } return publicPath; }; diff --git a/include/service/entities/plugin_setting_service.js b/include/service/entities/plugin_setting_service.js index 2d602f101..d06324b4c 100644 --- a/include/service/entities/plugin_setting_service.js +++ b/include/service/entities/plugin_setting_service.js @@ -124,7 +124,7 @@ module.exports = function PluginSettingServiceModule(pb) { } //retrieve the settings to modify - this.getSettings(pluginName, function(err, settings) { + this.getSettingsBySite(pluginName, function(err, settings) { if (util.isError(err) || !settings) { cb(err, false); return; @@ -204,7 +204,7 @@ module.exports = function PluginSettingServiceModule(pb) { } //retrieve the settings to modify - this.getThemeSettings(pluginName, function(err, settings) { + this.getThemeSettingsBySite(pluginName, function(err, settings) { if (util.isError(err) || !settings) { cb(err, false); return; @@ -348,7 +348,7 @@ module.exports = function PluginSettingServiceModule(pb) { //retrieve plugin to prove it exists (plus we need the id) var pluginName = details.uid; - this.pluginService.getPlugin(pluginName, function(err, plugin) { + this.pluginService.getPluginBySite(pluginName, function(err, plugin) { if (util.isError(err) || !plugin) { return cb(err ? err : new Error("The plugin "+pluginName+" is not installed"), false); } @@ -399,7 +399,7 @@ module.exports = function PluginSettingServiceModule(pb) { } //retrieve plugin to prove it exists (plus we need the id) - this.pluginService.getPlugin(pluginName, function(err, plugin) { + this.pluginService.getPluginBySite(pluginName, function(err, plugin) { if (util.isError(err) || !plugin) { cb(err, false); return; From 82c1c1f2d6161ac1d4d99d3ebba6b2c7195eaf1c Mon Sep 17 00:00:00 2001 From: Andrew Monroe Date: Wed, 22 Apr 2015 11:37:37 -0400 Subject: [PATCH 010/790] tentatively finished with plugin_service --- include/repository/plugin_repository.js | 45 +++++++++++-- include/service/entities/plugin_service.js | 67 +++++++++---------- .../jobs/plugins/plugin_install_job.js | 13 +++- 3 files changed, 81 insertions(+), 44 deletions(-) diff --git a/include/repository/plugin_repository.js b/include/repository/plugin_repository.js index 9b0c4f5ce..acb6a5f01 100644 --- a/include/repository/plugin_repository.js +++ b/include/repository/plugin_repository.js @@ -80,18 +80,51 @@ module.exports = function PluginRepositoryModule(pb) { }); }; - publicAPI.loadPluginsWithTheseIds = function(pluginIDs, site, cb) { - + publicAPI.loadIncludedPluginsOwnedByThisSite = function(pluginIDs, site, cb) { + var idIsInTheList = getIdsInListQuery(pluginIDs); + var belongsToThisSite = getBelongsToSiteQuery(site); + var where = { + $and: [idIsInTheList, belongsToThisSite] + } + var opts = { + select: pb.DAO.SELECT_ALL, + where: where, + order: {created: pb.DAO.ASC} + }; + var dao = new pb.DAO(); + dao.q(PLUGIN_COLL, opts, cb); }; - publicAPI.loadPluginsWithoutTheseIds = function(pluginIDs, site, cb) { - + publicAPI.loadPluginsNotIncludedOwnedByThisSite = function(pluginIDs, site, cb) { + var idIsNotInTheList = getIdsNotInListQuery(pluginIDs); + var belongsToThisSite = getBelongsToSiteQuery(site); + var where = { + $and: [idIsNotInTheList, belongsToThisSite] + } + var opts = { + select: pb.DAO.SELECT_ALL, + where: where, + order: {created: pb.DAO.ASC} + }; + var dao = new pb.DAO(); + dao.q(PLUGIN_COLL, opts, cb); }; publicAPI.loadPluginsAcrossAllSites = function(cb) { - + var dao = new pb.DAO(); + dao.q(PLUGIN_COLL, cb); }; + function getIdsNotInListQuery(pluginIDs) { + var idIsInTheList = {uid: {'$nin': pluginIDs}}; + return idIsInTheList; + } + + function getIdsInListQuery(pluginIDs) { + var idIsInTheList = {uid: {'$in': pluginIDs}}; + return idIsInTheList; + } + function getHasThemeQuery() { var hasATheme = {theme: {$exists: true}}; return hasATheme; @@ -158,4 +191,6 @@ module.exports = function PluginRepositoryModule(pb) { } return false; } + + return publicAPI; }; \ No newline at end of file diff --git a/include/service/entities/plugin_service.js b/include/service/entities/plugin_service.js index a93f6c246..a8a4df599 100755 --- a/include/service/entities/plugin_service.js +++ b/include/service/entities/plugin_service.js @@ -402,11 +402,11 @@ module.exports = function PluginServiceModule(pb) { * plugin does exist null is provided. */ PluginService.prototype.getPlugin = function(pluginIdentifier, cb) { - _pluginRepository.loadPluginAvailableToThisSite(pluginIdentifier, this.site, cb); + this._pluginRepository.loadPluginAvailableToThisSite(pluginIdentifier, this.site, cb); }; PluginService.prototype.getPluginBySite = function(pluginIdentifier, cb) { - _pluginRepository.loadPluginOwnedByThisSite(pluginIdentifier, this.site, cb); + this._pluginRepository.loadPluginOwnedByThisSite(pluginIdentifier, this.site, cb); } /** @@ -415,11 +415,11 @@ module.exports = function PluginServiceModule(pb) { * @param {Function} cb Provides two parameters: Error, Array */ PluginService.prototype.getPluginsWithThemes = function(cb) { - _pluginRepository.loadPluginsWithThemesAvailableToThisSite(this.site, cb); + this._pluginRepository.loadPluginsWithThemesAvailableToThisSite(this.site, cb); }; PluginService.prototype.getPluginsWithThemesBySite = function(cb) { - _pluginRepository.loadPluginsWithThemesOwnedByThisSite(this.site, cb); + this._pluginRepository.loadPluginsWithThemesOwnedByThisSite(this.site, cb); } /** @@ -559,14 +559,7 @@ module.exports = function PluginServiceModule(pb) { * @param {Function} cb A callback that provides two parameters: cb(Error, Array) */ PluginService.prototype.getActivePlugins = function(cb) { - - var opts = { - select: pb.DAO.SELECT_ALL, - where: {uid: {'$in': this.getActivePluginNames()}}, - order: {created: pb.DAO.ASC} - }; - var dao = new pb.DAO(); - dao.q(PLUGIN_COLL, opts, cb); + this._pluginRepository.loadIncludedPluginsOwnedByThisSite(this.getActivePluginNames(), this.site, cb); }; /** @@ -599,13 +592,7 @@ module.exports = function PluginServiceModule(pb) { * @param {Function} cb A callback that provides two parameters: cb(Error, Array) */ PluginService.prototype.getInactivePlugins = function(cb) { - var opts = { - select: pb.DAO.SELECT_ALL, - where: {uid: {'$nin': this.getActivePluginNames()}}, - order: {created: pb.DAO.ASC} - }; - var dao = new pb.DAO(); - dao.q(PLUGIN_COLL, opts, cb); + this._pluginRepository.loadPluginsNotIncludedOwnedByThisSite(this.getActivePluginNames(), this.site, cb); }; /** @@ -791,6 +778,7 @@ module.exports = function PluginServiceModule(pb) { var job = new pb.PluginInstallJob(); job.init(name); job.setRunAsInitiator(true); + job.setSite(site); job.setPluginUid(pluginDirName); job.run(cb); return job.getId(); @@ -805,8 +793,7 @@ module.exports = function PluginServiceModule(pb) { pb.log.debug('PluginService: Beginning plugin initilization...'); var self = this; - var dao = new pb.DAO(); - dao.q(PLUGIN_COLL, function(err, plugins) { + self._pluginRepository.loadPluginsAcrossAllSites(function(err, plugins) { if (util.isError(err)) { return cb(err); } @@ -879,6 +866,7 @@ module.exports = function PluginServiceModule(pb) { pb.log.debug("PluginService:[INIT] Beginning initialization of %s (%s)", plugin.name, plugin.uid); var details = null; + var site = plugin.site || GLOBAL_PREFIX; var tasks = [ //load the details file @@ -974,7 +962,7 @@ module.exports = function PluginServiceModule(pb) { return cb(new Error('Failed to load main module for plugin '+plugin.uid)); } - ACTIVE_PLUGINS[self.site][details.uid] = { + ACTIVE_PLUGINS[plugin.site][details.uid] = { main_module: mainModule, public_dir: PluginService.getPublicPath(plugin.dirName), permissions: map, @@ -983,7 +971,7 @@ module.exports = function PluginServiceModule(pb) { //set icon url (if exists) if (details.icon) { - ACTIVE_PLUGINS[self.site][details.uid].icon = PluginService.genPublicPath(details.uid, details.icon); + ACTIVE_PLUGINS[site][details.uid].icon = PluginService.genPublicPath(details.uid, details.icon); } process.nextTick(function() {callback(null, true);}); }, @@ -992,7 +980,7 @@ module.exports = function PluginServiceModule(pb) { function(callback) { pb.log.debug('PluginService:[INIT] Attempting to call onStartup function for %s.', details.uid); - var mainModule = ACTIVE_PLUGINS[details.uid].main_module; + var mainModule = ACTIVE_PLUGINS[site][details.uid].main_module; if (util.isFunction(mainModule.onStartup)) { var timeoutProtect = setTimeout(function() { @@ -1045,14 +1033,14 @@ module.exports = function PluginServiceModule(pb) { pb.log.debug("PluginService[INIT]: No services were found for %s", details.uid); services = {}; } - ACTIVE_PLUGINS[details.uid].services = services; + ACTIVE_PLUGINS[site][details.uid].services = services; callback(null, !util.isError(err)); }); }, //process routes function(callback) { - PluginService.loadControllers(path.join(PLUGINS_DIR, plugin.dirName), details.uid, callback); + PluginService.loadControllers(path.join(PLUGINS_DIR, plugin.dirName), details.uid, site, callback); }, //process localization @@ -1327,10 +1315,10 @@ module.exports = function PluginServiceModule(pb) { * @param {String} pluginUid The unique plugin identifier * @return {Object} Service prototype */ - PluginService.prototype.getService = function(serviceName, pluginUid) { + PluginService.prototype.getService = function(serviceName, pluginUid, site) { pb.log.warn('PluginService: Instance function getService is deprecated. Use pb.PluginService.getService intead'); try{ - return PluginService.getService(serviceName, pluginUid); + return PluginService.getService(serviceName, pluginUid, site); } catch(e) { //for backward compatibility until the function is removed @@ -1349,10 +1337,17 @@ module.exports = function PluginServiceModule(pb) { * @param {String} pluginUid The unique plugin identifier * @return {Object} Service prototype */ - PluginService.getService = function(serviceName, pluginUid) { - if (ACTIVE_PLUGINS[pluginUid]) { - if (ACTIVE_PLUGINS[pluginUid].services && ACTIVE_PLUGINS[pluginUid].services[serviceName]) { - return ACTIVE_PLUGINS[pluginUid].services[serviceName]; + PluginService.getService = function(serviceName, pluginUid, site) { + if(!site) { + site = GLOBAL_PREFIX; + } + if (ACTIVE_PLUGINS[site] && ACTIVE_PLUGINS[site][pluginUid]) { + if (ACTIVE_PLUGINS[site][pluginUid].services && ACTIVE_PLUGINS[site][pluginUid].services[serviceName]) { + return ACTIVE_PLUGINS[site][pluginUid].services[serviceName]; + } + } else if (ACTIVE_PLUGINS[GLOBAL_PREFIX] && ACTIVE_PLUGINS[GLOBAL_PREFIX][pluginUid]) { + if (ACTIVE_PLUGINS[GLOBAL_PREFIX][pluginUid].services && ACTIVE_PLUGINS[GLOBAL_PREFIX][pluginUid].services[serviceName]) { + return ACTIVE_PLUGINS[GLOBAL_PREFIX][pluginUid].services[serviceName]; } } throw new Error('Either plugin ['+pluginUid+'] or the service ['+serviceName+'] does not exist'); @@ -1867,7 +1862,7 @@ module.exports = function PluginServiceModule(pb) { * @param {String} pluginUid The unique identifier for the plugin * @param {Function} cb A callback that provides two parameters: cb(Error, Array) */ - PluginService.loadControllers = function(pathToPlugin, pluginUid, cb) { + PluginService.loadControllers = function(pathToPlugin, pluginUid, site, cb) { var controllersDir = path.join(pathToPlugin, 'controllers'); var options = { @@ -1888,7 +1883,7 @@ module.exports = function PluginServiceModule(pb) { return function(callback) { var pathToController = files[index]; - PluginService.loadController(pathToController, pluginUid, function(err, service) { + PluginService.loadController(pathToController, pluginUid, site, function(err, service) { if (util.isError(err)) { pb.log.warn('PluginService: Failed to load controller at [%s]: %s', pathToController, err.stack); } @@ -1911,7 +1906,7 @@ module.exports = function PluginServiceModule(pb) { * @param {String} pluginUid The unique identifier for the plugin * @param {Function} cb A callback that provides two parameters: cb(Error, Boolean) */ - PluginService.loadController = function(pathToController, pluginUid, cb) { + PluginService.loadController = function(pathToController, pluginUid, site, cb) { try { //load the controller type @@ -1937,7 +1932,7 @@ module.exports = function PluginServiceModule(pb) { for(var i = 0; i < routes.length; i++) { var route = routes[i]; route.controller = pathToController; - var result = pb.RequestHandler.registerRoute(route, pluginUid); + var result = pb.RequestHandler.registerRoute(route, pluginUid, site); //verify registration if (!result) { diff --git a/include/service/jobs/plugins/plugin_install_job.js b/include/service/jobs/plugins/plugin_install_job.js index 11244939b..318c86d3d 100644 --- a/include/service/jobs/plugins/plugin_install_job.js +++ b/include/service/jobs/plugins/plugin_install_job.js @@ -20,6 +20,7 @@ var async = require('async'); var util = require('../../../util.js'); module.exports = function PluginInstallJobModule(pb) { + var GLOBAL_PREFIX = 'global'; /** * A system job that coordinates the uninstall of a plugin across the cluster. @@ -59,13 +60,14 @@ module.exports = function PluginInstallJobModule(pb) { //progress function var jobId = self.getId(); var pluginUid = self.getPluginUid(); + var site = self.getSite(); var tasks = [ //verify that the plugin is not already installed function(callback) { self.log("Verifying that plugin %s is not already installed", pluginUid); - pb.plugins.isInstalled(pluginUid, function(err, isInstalled){ + self.pluginService.isInstalled(pluginUid, function(err, isInstalled){ if (util.isError(err)) { callback(err, !isInstalled); } @@ -84,6 +86,7 @@ module.exports = function PluginInstallJobModule(pb) { job.setRunAsInitiator(true) .init(name, jobId) .setPluginUid(pluginUid) + .setSite(site) .setChunkOfWorkPercentage(1/3) .run(callback); }, @@ -96,6 +99,7 @@ module.exports = function PluginInstallJobModule(pb) { job.setRunAsInitiator(true) .init(name, jobId) .setPluginUid(pluginUid) + .setSite(site) .setChunkOfWorkPercentage(1/3) .run(callback); }, @@ -119,6 +123,7 @@ module.exports = function PluginInstallJobModule(pb) { job.setRunAsInitiator(true) .init(name, jobId) .setPluginUid(pluginUid) + .setSite(site) .setChunkOfWorkPercentage(1/3) .run(callback); } @@ -144,6 +149,7 @@ module.exports = function PluginInstallJobModule(pb) { var self = this; var pluginUid = this.getPluginUid(); + var site = this.getSite(); var details = null; var tasks = [ @@ -166,13 +172,14 @@ module.exports = function PluginInstallJobModule(pb) { clone.dirName = pluginUid; var pluginDescriptor = pb.DocumentCreator.create('plugin', clone); + pluginDescriptor.site = site || GLOBAL_PREFIX; self.dao.save(pluginDescriptor, callback); }, //load plugin settings function(callback) { self.log("Adding settings for %s", details.uid); - pb.plugins.resetSettings(details, callback); + self.pluginService.resetSettings(details, callback); }, //load theme settings @@ -180,7 +187,7 @@ module.exports = function PluginInstallJobModule(pb) { if (details.theme && details.theme.settings) { self.log("Adding theme settings for %s", details.uid); - pb.plugins.resetThemeSettings(details, callback); + self.pluginService.resetThemeSettings(details, callback); } else { callback(null, true); From 76d7ee5de3374dbe5b9a196a639681990cd78289 Mon Sep 17 00:00:00 2001 From: Andrew Monroe Date: Wed, 22 Apr 2015 12:38:07 -0400 Subject: [PATCH 011/790] make plugin api accept site --- include/service/entities/plugin_service.js | 7 +++---- .../controllers/api/plugins/plugin_api.js | 15 ++++++++++----- plugins/pencilblue/include/routes.js | 8 ++++++++ 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/include/service/entities/plugin_service.js b/include/service/entities/plugin_service.js index a8a4df599..16576ee55 100755 --- a/include/service/entities/plugin_service.js +++ b/include/service/entities/plugin_service.js @@ -741,7 +741,7 @@ module.exports = function PluginServiceModule(pb) { var name = util.format('UNINSTALL_PLUGIN_%s', pluginUid); var jobId = options.jobId; - var site = options.site; + var site = this.site; var job = new pb.PluginUninstallJob(); job.init(name, jobId); job.setPluginUid(pluginUid); @@ -778,7 +778,7 @@ module.exports = function PluginServiceModule(pb) { var job = new pb.PluginInstallJob(); job.init(name); job.setRunAsInitiator(true); - job.setSite(site); + job.setSite(this.site); job.setPluginUid(pluginDirName); job.run(cb); return job.getId(); @@ -1996,8 +1996,7 @@ module.exports = function PluginServiceModule(pb) { var options = { forCluster: false, - jobId: command.jobId, - site: command.site + jobId: command.jobId } var pluginService = new PluginService(command.site); diff --git a/plugins/pencilblue/controllers/api/plugins/plugin_api.js b/plugins/pencilblue/controllers/api/plugins/plugin_api.js index d7e2f804d..b99b58b95 100755 --- a/plugins/pencilblue/controllers/api/plugins/plugin_api.js +++ b/plugins/pencilblue/controllers/api/plugins/plugin_api.js @@ -27,6 +27,8 @@ module.exports = function(pb) { var PluginService = pb.PluginService; var RequestHandler = pb.RequestHandler; + var GLOBAL_PREFIX = 'global'; + /** * Controller to properly route and handle remote calls to interact with * the PluginService @@ -72,6 +74,8 @@ module.exports = function(pb) { PluginApiController.prototype.render = function(cb) { var action = this.pathVars.action; var identifier = this.pathVars.id; + this.site = this.pathVars.site || GLOBAL_PREFIX; + this.pluginService = new pb.PluginService(this.site); //validate action var errors = []; @@ -91,7 +95,7 @@ module.exports = function(pb) { return; } //route to handler - this[action](identifier, cb); + this[action](identifier, site, cb); }; /** @@ -134,7 +138,7 @@ module.exports = function(pb) { //load plugin function(callback) { - self.pluginService.getPlugin(uid, function(err, plugin) { + self.pluginService.getPluginBySite(uid, function(err, plugin) { if (!plugin) { callback(new Error(util.format(self.ls.get('PLUGIN_NOT_FOUND'), uid)), false); return; @@ -194,7 +198,7 @@ module.exports = function(pb) { PluginApiController.prototype.initialize = function(uid, cb) { var self = this; - this.pluginService.getPlugin(uid, function(err, plugin) { + this.pluginService.getPluginBySite(uid, function(err, plugin) { if (util.isError(err)) { var content = BaseController.apiResponse(BaseController.API_FAILURE, util.format(self.ls.get('INITIALIZATION_FAILED'), uid), [err.message]); cb({content: content, code: 500}); @@ -224,7 +228,7 @@ module.exports = function(pb) { var self = this; //retrieve plugin - this.pluginService.getPlugin(uid, function(err, plugin) { + this.pluginService.getPluginBySite(uid, function(err, plugin) { if (uid !== RequestHandler.DEFAULT_THEME && util.isError(err)) { var content = BaseController.apiResponse(BaseController.API_FAILURE, util.format(self.ls.get('SET_THEME_FAILED'), uid), [err.message]); cb({content: content, code: 500}); @@ -238,7 +242,8 @@ module.exports = function(pb) { } var theme = plugin ? plugin.uid : uid; - pb.settings.set('active_theme', theme, function(err, result) { + var settings = pb.SettingServiceFactory.getService(pb.config.settings.use_memory, pb.config.settings.use_cache, self.site); + settings.set('active_theme', theme, function(err, result) { if (util.isError(err)) { var content = BaseController.apiResponse(BaseController.API_FAILURE, util.format(self.ls.get('SET_THEME_FAILED'), uid), [err.message]); cb({content: content, code: 500}); diff --git a/plugins/pencilblue/include/routes.js b/plugins/pencilblue/include/routes.js index 88044670e..f52429034 100644 --- a/plugins/pencilblue/include/routes.js +++ b/plugins/pencilblue/include/routes.js @@ -782,6 +782,14 @@ module.exports = function Routes(pb){ controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'api', 'plugins', 'plugin_api.js'), content_type: 'application/json' }, + { + method: 'post', + path: "/api/plugins/:action/:id/:site", + auth_required: true, + access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'api', 'plugins', 'plugin_api.js'), + content_type: 'application/json' + }, // THEMES { From 5a129e7c931b3bd345f5b0c75477274d55d44b75 Mon Sep 17 00:00:00 2001 From: Andrew Monroe Date: Fri, 24 Apr 2015 14:45:48 -0400 Subject: [PATCH 012/790] use correct host for site matching --- include/http/request_handler.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/include/http/request_handler.js b/include/http/request_handler.js index 1fcb56a1a..855234710 100755 --- a/include/http/request_handler.js +++ b/include/http/request_handler.js @@ -41,6 +41,7 @@ module.exports = function RequestHandlerModule(pb) { this.req = req; this.resp = resp; this.url = url.parse(req.url, true); + this.hostname = req.headers.host; } /** @@ -593,7 +594,7 @@ module.exports = function RequestHandlerModule(pb) { this.session = session; //set the site -- how do we handle improper sites here? - this.site = RequestHandler.sites[this.url.hostname] || GLOBAL_PREFIX; + this.site = RequestHandler.sites[this.hostname] || GLOBAL_PREFIX; //find the controller to hand off to var route = this.getRoute(this.url.pathname); From 7df94b01c924d5754f9435d22ee5efad011cb89a Mon Sep 17 00:00:00 2001 From: Andrew Monroe Date: Tue, 28 Apr 2015 11:31:11 -0400 Subject: [PATCH 013/790] dont try and delete non existent sites --- include/http/request_handler.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/include/http/request_handler.js b/include/http/request_handler.js index 855234710..5bc66e584 100755 --- a/include/http/request_handler.js +++ b/include/http/request_handler.js @@ -144,7 +144,9 @@ module.exports = function RequestHandlerModule(pb) { }; RequestHandler.unloadSite = function(site) { - delete RequestHandler.sites[site.hostname]; + if(RequestHandler.sites[site.hostname]) { + delete RequestHandler.sites[site.hostname]; + } }; /** From 02a9ae9202a6c0df2fd8261e01401e2e495e7bd7 Mon Sep 17 00:00:00 2001 From: andparker Date: Tue, 28 Apr 2015 16:26:42 -0400 Subject: [PATCH 014/790] Add deployment scripts and config loader. --- .gitignore | 1 - config.js | 2 ++ deploy/before_restart.rb | 70 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 config.js create mode 100644 deploy/before_restart.rb diff --git a/.gitignore b/.gitignore index ef3924db2..55b825eba 100755 --- a/.gitignore +++ b/.gitignore @@ -19,7 +19,6 @@ plugins/* !plugins/wp_import/** **/node_modules **/node_modules/** -config.js config.json **/.DS_Store **/dump.rdb diff --git a/config.js b/config.js new file mode 100644 index 000000000..ea52a1d45 --- /dev/null +++ b/config.js @@ -0,0 +1,2 @@ +var fs = require('fs'); +module.exports = JSON.parse(fs.readFileSync('config.json')); \ No newline at end of file diff --git a/deploy/before_restart.rb b/deploy/before_restart.rb new file mode 100644 index 000000000..115bbc3cd --- /dev/null +++ b/deploy/before_restart.rb @@ -0,0 +1,70 @@ +node[:deploy].each do |application, deploy| + if application.to_s == 'tecpencilblue' + + release_dir = ::File.expand_path(__FILE__).sub('deploy/before_restart.rb', '') + user, group = deploy[:user], deploy[:group] + + Chef::Log.info("Renaming pencilblue.js to server.js") + pencilblue_file = ::File.join(release_dir, 'pencilblue.js') + + server_file = ::File.join(release_dir, 'server.js') + + file server_file do + action :delete + end + + file server_file do + owner user + group group + mode 00755 + content ::File.open(pencilblue_file).read + action :create + end + + file pencilblue_file do + action :delete + end + + Chef::Log.info("Importing config.json for application: #{application}") + config_json = deploy[:config_json].to_s.gsub('=>', ':') + Chef::Log.info("release_dir: #{release_dir}") + + config_file = ::File.join(release_dir, 'config.json') + Chef::Log.info("config.json path: #{config_file}") + + file config_file do + action :delete + end + Chef::Log.info("#{config_file} deleted") + + file config_file do + owner user + group group + mode 00755 + content config_json + action :create + end + Chef::Log.info("#{config_file} created") + + execute "npm install -g bower" do + cwd release_dir + end + + execute "bower install" do + command "bower install --allow-root" + cwd "#{deploy[:deploy_to]}/current" + end + + Chef::Log.info("Killing java process that is AppDynamics agent") + execute "Stopping AppDynamics Agent" do + command "killall java" + returns [0,1] + end + + Chef::Log.info("Executing chmod -R a+rw /tmp/appd") + execute "chmod appd logs" do + command "sudo chmod -R a+rw /tmp/appd" + only_if { ::File.exists?("/tmp/appd") } + end + end +end From 616dde095312003f8c3e72d9cd17e742ac77191c Mon Sep 17 00:00:00 2001 From: btidwell Date: Tue, 28 Apr 2015 17:02:24 -0400 Subject: [PATCH 015/790] add coverage to gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 55b825eba..caed79130 100755 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ public/media/ public/docs/ public/bower_components/ log/ +coverage/ out plugins/* !plugins/pencilblue From d5691acfca852df2c91d5eaaefcaa0a75d19fc15 Mon Sep 17 00:00:00 2001 From: andparker Date: Tue, 28 Apr 2015 17:29:12 -0400 Subject: [PATCH 016/790] Add test deployment script. --- testdeploy.js | 135 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 135 insertions(+) create mode 100644 testdeploy.js diff --git a/testdeploy.js b/testdeploy.js new file mode 100644 index 000000000..00372ec79 --- /dev/null +++ b/testdeploy.js @@ -0,0 +1,135 @@ +var AWS = require('aws-sdk'); +var LINQ = require('node-linq').LINQ; + +//deploy to east region on test stack +AWS.config.region = 'us-east-1'; + +//OpsWorks Parameters for deployment +var StackId = process.env.AWS_StackId; +var AppId = process.env.AWS_AppId; +var LayerId = process.env.AWS_LayerId; + +var opsWorks = new AWS.OpsWorks(); + +getInstanceIds(function(instanceIds){ + if(instanceIds.length < 1){ + throw new NoEC2InstanceAvailableError("No instances are online for deployment"); + } + else{ + var deployParams = { + Command:{ + Name: 'deploy' + }, + StackId: StackId, + AppId: AppId, + InstanceIds: instanceIds + }; + createDeployment(deployParams); + } +}); + +//Get Instance IDs from stack matching desired LayerId +function getInstanceIds(cb){ + opsWorks.describeInstances({LayerId: LayerId}, function(err, data){ + if(err){ + console.log(StackId + ' ' + LayerId); + console.log(err, err.stack); + } + else{ + var instanceIds = new LINQ(data.Instances).Select(function(instance){ + return instance.InstanceId; + }).ToArray(); + console.log('Deploying to these instances: ' + instanceIds); + cb(instanceIds); + } + }); +} + +//Run the deloyment +function createDeployment(deployParams){ + opsWorks.createDeployment(deployParams, function(err, data){ + if(err){ + console.log(err, err.stack); + } + else{ + console.log("Deployment Id: " + data.DeploymentId); + watchDeployment(data.DeploymentId); + } + }); +} +//Hold the thread until deployment is finished. +function watchDeployment(deploymentId){ + opsWorks.describeDeployments({DeploymentIds: [deploymentId]}, function(err, data){ + if(err){ + console.log(err, err.stack); + } + else{ + console.log(data); + if(data.Deployments[0].Status.toLowerCase() === 'running'){ + var timeout = 60000; + console.log('Deployment in progress, waiting for ' + timeout + ' ms.'); + setTimeout(function(){ + watchDeployment(deploymentId); + }, timeout); + } + else{ + console.log('Deployment Finished. Status: ' + data.Deployments[0].Status); + if(data.Deployments[0].Status.toLowerCase() === 'failed'){ + throw new DeploymentFailedException("Deployment failed"); + } + else{ + healthCheck(); + } + } + } + }); +} + +//Hold the thread until load balancer reports healthy instances (will check 2 times in 15 second intervals) +var healthChecksRemaining = 10; +function healthCheck(){ + var elb = new AWS.ELB(); + setTimeout(function(){ + elb.describeInstanceHealth({LoadBalancerName: 'pencilblue-test'}, function(err, data){ + if (err){ + console.log(err, err.stack); // an error occurred + } + else{ + var unhealthyInstances = new LINQ(data.InstanceStates).Where(function(instanceState){ + return instanceState.State === 'OutOfService' || instanceState.State === 'Unknown'; + }).ToArray(); + if(unhealthyInstances && unhealthyInstances.length > 0){ + healthChecksRemaining --; + console.log('Unhealthy Instance Count: ' + unhealthyInstances.length); + if(healthChecksRemaining < 1){ + throw new UnhealthyEC2InstanceError("Instance Unhealthy after 5 consecutive health checks"); + } + else{ + healthCheck(); + } + } + else{ + console.log('Instance is healthy, moving on to nightwatch.'); + } + } + }); + }, 30000); +} + +//Exception for when no ec2 instances are available +function NoEC2InstanceAvailableError(message){ + this.message = message; + this.name = "NoEC2InstanceAvailableError"; +} + +//Exceptions for when deployment fails +function DeploymentFailedException(message){ + this.message = message; + this.name = "DeploymentFailedException"; +} + +//Exception for unhealthy EC2 Instances after deployment +function UnhealthyEC2InstanceError(message){ + this.message = message; + this.name = "UnhealthyEC2InstanceError"; +} \ No newline at end of file From 1f1704e6bf7f7eae9713a9e15dbf194e5cd3e939 Mon Sep 17 00:00:00 2001 From: andparker Date: Wed, 29 Apr 2015 10:47:10 -0400 Subject: [PATCH 017/790] Update load-balancer name to pull from codeship environment variable. --- testdeploy.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testdeploy.js b/testdeploy.js index 00372ec79..c415da618 100644 --- a/testdeploy.js +++ b/testdeploy.js @@ -90,7 +90,7 @@ var healthChecksRemaining = 10; function healthCheck(){ var elb = new AWS.ELB(); setTimeout(function(){ - elb.describeInstanceHealth({LoadBalancerName: 'pencilblue-test'}, function(err, data){ + elb.describeInstanceHealth({LoadBalancerName: env.AWS_ELB_NAME}, function(err, data){ if (err){ console.log(err, err.stack); // an error occurred } From 9acb17a23d04269c59ad032a64d52e2991dbb986 Mon Sep 17 00:00:00 2001 From: andparker Date: Wed, 29 Apr 2015 11:04:48 -0400 Subject: [PATCH 018/790] Fix: A codeship environment variable should be referenced from the process object. --- testdeploy.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/testdeploy.js b/testdeploy.js index c415da618..cadc09128 100644 --- a/testdeploy.js +++ b/testdeploy.js @@ -90,7 +90,7 @@ var healthChecksRemaining = 10; function healthCheck(){ var elb = new AWS.ELB(); setTimeout(function(){ - elb.describeInstanceHealth({LoadBalancerName: env.AWS_ELB_NAME}, function(err, data){ + elb.describeInstanceHealth({LoadBalancerName: process.env.AWS_ELB_NAME}, function(err, data){ if (err){ console.log(err, err.stack); // an error occurred } From ef988f207cbf97b0b39090ff6e81bbb1c528fe67 Mon Sep 17 00:00:00 2001 From: Andrew Monroe Date: Wed, 29 Apr 2015 11:20:00 -0400 Subject: [PATCH 019/790] add clusterified site activation deactivation and add modifications to management page --- include/requirements.js | 3 + include/service/entities/site_service.js | 132 ++++++++++++++++++ .../service/jobs/sites/site_activate_job.js | 105 ++++++++++++++ .../service/jobs/sites/site_deactivate_job.js | 102 ++++++++++++++ include/service/jobs/sites/site_job_runner.js | 58 ++++++++ pencilblue.js | 2 + .../actions/admin/sites/activate_site.js | 22 +-- .../actions/admin/sites/deactivate_site.js | 20 +-- .../actions/admin/sites/new_site.js | 53 +++---- .../templates/admin/sites/manage.html | 1 + .../templates/angular/admin/sites/manage.html | 107 +++++++++++++- public/localization/en-us.js | 6 +- 12 files changed, 539 insertions(+), 72 deletions(-) create mode 100644 include/service/jobs/sites/site_activate_job.js create mode 100644 include/service/jobs/sites/site_deactivate_job.js create mode 100644 include/service/jobs/sites/site_job_runner.js diff --git a/include/requirements.js b/include/requirements.js index 6294beeed..aff24a8c4 100755 --- a/include/requirements.js +++ b/include/requirements.js @@ -152,6 +152,9 @@ module.exports = function PB(config) { pb.PluginDependenciesJob = require(path.join(config.docRoot, '/include/service/jobs/plugins/plugin_dependencies_job.js'))(pb); pb.PluginInitializeJob = require(path.join(config.docRoot, '/include/service/jobs/plugins/plugin_initialize_job.js'))(pb); pb.PluginInstallJob = require(path.join(config.docRoot, '/include/service/jobs/plugins/plugin_install_job.js'))(pb); + pb.SiteJobRunner = require(path.join(config.docRoot, '/include/service/jobs/sites/site_job_runner.js'))(pb); + pb.SiteActivateJob = require(path.join(config.docRoot, '/include/service/jobs/sites/site_activate_job.js'))(pb); + pb.SiteDeactivateJob = require(path.join(config.docRoot, '/include/service/jobs/sites/site_deactivate_job.js'))(pb); //Email settings and functions pb.EmailService = require(path.join(config.docRoot, '/include/email'))(pb); diff --git a/include/service/entities/site_service.js b/include/service/entities/site_service.js index 29105fa04..a71ae7e4a 100644 --- a/include/service/entities/site_service.js +++ b/include/service/entities/site_service.js @@ -99,6 +99,81 @@ module.exports = function SiteServiceModule(pb) { async.series(tasks, cb); }; + SiteService.prototype.activateSite = function(siteUid, cb) { + cb = cb || util.cb; + var name = util.format("ACTIVATE_SITE_%s", siteUid); + var job = new pb.SiteActivateJob(); + job.setRunAsInitiator(true); + job.init(name); + job.setSite(siteUid); + job.run(cb); + return job.getId(); + }; + + SiteService.prototype.deactivateSite = function(siteUid, cb) { + cb = cb || util.cb; + var name = util.format("DEACTIVATE_SITE_%s", siteUid); + var job = new pb.SiteDeactivateJob(); + job.setRunAsInitiator(true); + job.init(name); + job.setSite(siteUid); + job.run(cb); + return job.getId(); + }; + + SiteService.prototype.createSite = function(site, id, cb) { + site.active = false; + site.uid = getUid(); + this.isDisplayNameOrHostnameTaken(site.displayName, site.hostname, id, function(err, isTaken, field) { + if(util.isError(err) || isTaken) { + cb(err, isTaken, field, null); + return; + } + + var dao = new pb.DAO(); + dao.save(site, function(err, result) { + if(util.isError(err)) { + cb(err, false, null, null); + return; + } + + cb(null, false, null, result); + }); + }); + }; + + SiteService.prototype.startAcceptingSiteTraffic = function(siteUid, cb) { + var dao = new pb.DAO(); + dao.loadByValue('uid', siteUid, 'site', function(err, site) { + if(util.isError(err)) { + cb(err, null) + } else if (!site) { + cb(new Error('Site not found'), null); + } else if (!site.active) { + cb(new Error('Site not active'), null); + } else { + pb.RequestHandler.loadSite(site); + cb(err, result) + } + }); + }; + + SiteService.prototype.stopAcceptingSiteTraffic = function(siteUid, cb) { + var dao = new pb.DAO(); + dao.loadByValue('uid', siteUid, 'site', function(err, site) { + if(util.isError(err)) { + cb(err, null) + } else if (!site) { + cb(new Error('Site not found'), null); + } else if (site.active) { + cb(new Error('Site not deactivated'), null); + } else { + pb.RequestHandler.unloadSite(site); + cb(err, result) + } + }); + }; + SiteService.prototype.initSites = function(cb) { this.getActiveSites(function(err, results) { if(err) { @@ -112,5 +187,62 @@ module.exports = function SiteServiceModule(pb) { }); }; + function getUid() + { + return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {var r = Math.random()*16|0,v=c=='x'?r:r&0x3|0x8;return v.toString(16);}); + } + + SiteService.onActivateSiteCommandReceived = function(command) { + if (!util.isObject(command)) { + pb.log.error('SiteService: an invalid activate_site command object was passed. %s', util.inspect(command)); + return; + } + + var name = util.format("ACTIVATE_SITE_%s", command.site); + var job = new pb.SiteActivateJob(); + job.setRunAsInitiator(false); + job.init(name, command.jobId); + job.setSite(command.site); + job.run(function(err, result) { + var response = { + error: err ? err.stack : undefined, + result: result ? true : false + }; + pb.CommandService.getInstance().sendInResponseTo(command, response); + }); + }; + + SiteService.onDeactivateSiteCommandReceived = function(command) { + if (!util.isObject(command)) { + pb.log.error('SiteService: an invalid deactivate_site command object was passed. %s', util.inspect(command)); + return; + } + + var name = util.format("DEACTIVATE_SITE_%s", command.site); + var job = new pb.SiteDeactivateJob(); + job.setRunAsInitiator(false); + job.init(name, command.jobId); + job.setSite(command.site); + job.run(function(err, result) { + var response = { + error: err ? err.stack : undefined, + result: result ? true : false + }; + pb.CommandService.getInstance().sendInResponseTo(command, response); + }); + }; + + /** + * + * @static + * @method init + */ + SiteService.init = function() { + //register for commands + var commandService = pb.CommandService.getInstance(); + commandService.registerForType('deactivate_site', SiteService.onActivateSiteCommandReceived); + commandService.registerForType('activate_site' , SiteService.onDeactivateSiteCommandReceived); + }; + return SiteService; }; diff --git a/include/service/jobs/sites/site_activate_job.js b/include/service/jobs/sites/site_activate_job.js new file mode 100644 index 000000000..f99391501 --- /dev/null +++ b/include/service/jobs/sites/site_activate_job.js @@ -0,0 +1,105 @@ + +//dependencies +var async = require('async'); +var util = require('../../../util.js'); + +module.exports = function SiteActivateJobModule(pb) { + var GLOBAL_PREFIX = 'global'; + + function SiteActivateJob(){ + SiteActivateJob.super_.call(this); + + //initialize + this.init(); + this.setParallelLimit(1); + }; + util.inherits(SiteActivateJob, pb.SiteJobRunner); + + SiteActivateJob.prototype.getInitiatorTasks = function(cb) { + var self = this; + //progress function + var jobId = self.getId(); + var site = self.getSite(); + + var activateCommand = { + jobId: jobId, + site: site + }; + + var tasks = [ + //activate site in mongo + function(callback) { + self.doPersistenceTasks(function(err, results) { + self.onUpdate(100 / tasks.length); + if (util.isError(err)) { + self.log(err.stack); + } + callback(err, results); + }); + }, + + //add site to request handler site collection across cluster + self.createCommandTask('activate_site', activateCommand) + ]; + cb(null, tasks); + }; + + SiteActivateJob.prototype.getWorkerTasks = function(cb) { + var self = this; + + var pluginUid = this.getPluginUid(); + var site = this.getSite(); + var tasks = [ + + //allow traffic to start routing for site + function(callback) { + self.siteService.startAcceptingSiteTraffic(site, callback); + } + ]; + cb(null, tasks); + }; + + /** + * + * @method doPersistenceTasks + */ + SiteActivateJob.prototype.doPersistenceTasks = function(cb) { + var self = this; + + var siteUid = this.getSite(); + var tasks = [ + //set site to active in mongo + function(callback) { + var dao = new pb.DAO(); + dao.loadByValue('uid', siteUid, 'site', function(err, site) { + if(util.isError(err)) { + callback(err, null) + } else if (!site) { + callback(new Error('Site not found'), null); + } else { + site.active = true; + dao.save(site, function(err, result) { + if(util.isError(err)) { + cb(err, null); + return; + } + + pb.RequestHandler.loadSite(site); + callback(err, result) + }); + } + }); + } + ]; + async.series(tasks, function(err, results) { + if(util.isError(err)) { + cb(err); + return; + } + cb(null, true); + }); + }; + + //exports + return SiteActivateJob; +}; diff --git a/include/service/jobs/sites/site_deactivate_job.js b/include/service/jobs/sites/site_deactivate_job.js new file mode 100644 index 000000000..c499a528d --- /dev/null +++ b/include/service/jobs/sites/site_deactivate_job.js @@ -0,0 +1,102 @@ + +//dependencies +var async = require('async'); +var util = require('../../../util.js'); + +module.exports = function SiteDeactivateJobModule(pb) { + var GLOBAL_PREFIX = 'global'; + + function SiteDeactivateJob(){ + SiteDeactivateJob.super_.call(this); + + //initialize + this.init(); + this.setParallelLimit(1); + }; + util.inherits(SiteDeactivateJob, pb.SiteJobRunner); + + SiteDeactivateJob.prototype.getInitiatorTasks = function(cb) { + var self = this; + + var activateCommand = {}; + + //progress function + var jobId = self.getId(); + var site = self.getSite(); + var tasks = [ + //activate site in mongo + function(callback) { + self.doPersistenceTasks(function(err, results) { + self.onUpdate(100 / tasks.length); + if (util.isError(err)) { + self.log(err.stack); + } + callback(err, results); + }); + }, + + //add site to request handler site collection across cluster + self.createCommandTask('deactivate_site', activateCommand) + ]; + cb(null, tasks); + }; + + SiteDeactivateJob.prototype.getWorkerTasks = function(cb) { + var self = this; + + var pluginUid = this.getPluginUid(); + var site = this.getSite(); + var tasks = [ + + //allow traffic to start routing for site + function(callback) { + self.siteService.stopAcceptingSiteTraffic(site, callback); + } + ]; + cb(null, tasks); + }; + + /** + * + * @method doPersistenceTasks + */ + SiteDeactivateJob.prototype.doPersistenceTasks = function(cb) { + var self = this; + + var siteUid = this.getSite(); + var tasks = [ + //set site to active in mongo + function(callback) { + var dao = new pb.DAO(); + dao.loadByValue('uid', siteUid, 'site', function(err, site) { + if(util.isError(err)) { + callback(err, null) + } else if (!site) { + callback(new Error('Site not found'), null); + } else { + site.active = false; + dao.save(site, function(err, result) { + if(util.isError(err)) { + cb(err, null); + return; + } + + pb.RequestHandler.unloadSite(site); + callback(err, result); + }); + } + }); + } + ]; + async.series(tasks, function(err, results) { + if(util.isError(err)) { + cb(err); + return; + } + cb(null, true); + }); + }; + + //exports + return SiteDeactivateJob; +}; diff --git a/include/service/jobs/sites/site_job_runner.js b/include/service/jobs/sites/site_job_runner.js new file mode 100644 index 000000000..8e6b9e4d2 --- /dev/null +++ b/include/service/jobs/sites/site_job_runner.js @@ -0,0 +1,58 @@ +var util = require('../../../util.js'); + +module.exports = function SiteJobRunnerModule(pb) { + + function SiteJobRunner() { + SiteJobRunner.super_.call(this); + + this.siteService = new pb.SiteService(); + }; + util.inherits(SiteJobRunner, pb.ClusterJobRunner); + + SiteJobRunner.prototype.site = ''; + + SiteJobRunner.prototype.setSite = function(site) { + this.site = site; + return this; + } + + SiteJobRunner.prototype.getSite = function() { + return this.site; + } + + SiteJobRunner.prototype.processClusterResults = function(err, results, cb) { + if (util.isError(err)) { + this.log(err.stack); + cb(err, results); + return; + } + + var firstErr = undefined; + var success = true; + for (var i = 0; i < results.length; i++) { + if (!results[i]) { + firstErr = util.format('An error occurred while attempting to execute the job for site [%s]. RESULT=[%s] TASK=[%d]', this.getSite(), util.inspect(results[i]), i); + success = false; + break; + } + } + + //log any errors + if (firstErr) { + this.log(firstErr); + } + + //callback with result + var result = { + success: success, + id: this.getId(), + site: this.getSite(), + error: firstErr, + results: results + }; + cb(err, result); + }; + + //exports + return SiteJobRunner; +}; \ No newline at end of file diff --git a/pencilblue.js b/pencilblue.js index c889d92a0..e0ca62f8e 100755 --- a/pencilblue.js +++ b/pencilblue.js @@ -134,6 +134,8 @@ function PencilBlue(config){ */ this.initSites = function(cb) { + pb.SiteService.init(); + var siteService = new pb.SiteService(); siteService.initSites(cb); } diff --git a/plugins/pencilblue/controllers/actions/admin/sites/activate_site.js b/plugins/pencilblue/controllers/actions/admin/sites/activate_site.js index 60942576d..b6ef73885 100644 --- a/plugins/pencilblue/controllers/actions/admin/sites/activate_site.js +++ b/plugins/pencilblue/controllers/actions/admin/sites/activate_site.js @@ -17,23 +17,11 @@ module.exports = function(pb) { return; } - var dao = new pb.DAO(); - dao.loadByValue('uid', vars.id, 'site', function(err, site) { - if(util.isError(err) || site === null) { - self.formError(self.ls.get('ERROR_LOADING'), '/admin/sites/' + vars.id, cb); - return; - } - site.active = true; - dao.save(site, function(err, result) { - if(util.isError(err)) { - return self.formError(self.ls.get('ERROR_SAVING'), '/admin/sites/' + vars.id, cb); - } - - pb.RequestHandler.loadSite(site); - cb({content: pb.BaseController.apiResponse(pb.BaseController.API_SUCCESS, self.ls.get('SITE_ACTIVATED'), result)}); - }); - }); - } + var siteService = new pb.SiteService(); + var jobId = siteService.activateSite(vars.id); + var content = pb.BaseController.apiResponse(pb.BaseController.API_SUCCESS, '', jobId); + cb({content: content}); + }; //exports return ActivateSite; diff --git a/plugins/pencilblue/controllers/actions/admin/sites/deactivate_site.js b/plugins/pencilblue/controllers/actions/admin/sites/deactivate_site.js index 4bc4304cf..c508a2a70 100644 --- a/plugins/pencilblue/controllers/actions/admin/sites/deactivate_site.js +++ b/plugins/pencilblue/controllers/actions/admin/sites/deactivate_site.js @@ -17,22 +17,10 @@ module.exports = function(pb) { return; } - var dao = new pb.DAO(); - dao.loadByValue('uid', vars.id, 'site', function(err, site) { - if(util.isError(err) || site === null) { - self.formError(self.ls.get('ERROR_LOADING'), '/admin/sites/' + vars.id, cb); - return; - } - site.active = false; - dao.save(site, function(err, result) { - if(util.isError(err)) { - return self.formError(self.ls.get('ERROR_SAVING'), '/admin/sites/' + vars.id, cb); - } - - pb.RequestHandler.unloadSite(site); - cb({content: pb.BaseController.apiResponse(pb.BaseController.API_SUCCESS, self.ls.get('SITE_ACTIVATED'), result)}); - }); - }); + var siteService = new pb.SiteService(); + var jobId = siteService.deactivateSite(vars.id); + var content = pb.BaseController.apiResponse(pb.BaseController.API_SUCCESS, '', jobId); + cb({content: content}); } //exports diff --git a/plugins/pencilblue/controllers/actions/admin/sites/new_site.js b/plugins/pencilblue/controllers/actions/admin/sites/new_site.js index d4985699a..cab36fe5b 100644 --- a/plugins/pencilblue/controllers/actions/admin/sites/new_site.js +++ b/plugins/pencilblue/controllers/actions/admin/sites/new_site.js @@ -31,52 +31,41 @@ module.exports = function(pb) { return; } + var siteService = new pb.SiteService(); var site = pb.DocumentCreator.create('site', post); - site.active = false; - site.uid = getUid(); - pb.sites.isDisplayNameOrHostnameTaken(site.displayName, site.hostname, post.id, function(err, isTaken, field) { - if(util.isError(err) || isTaken) { - if(field === 'hostname') { - cb({ - code: 400, - content: pb.BaseController.apiResponse(pb.BaseController.API_ERROR, self.ls.get('EXISTING_HOSTNAME')) - }); - } else { - cb({ - code: 400, - content: pb.BaseController.apiResponse(pb.BaseController.API_ERROR, self.ls.get('EXISTING_DISPLAYNAME')) - }); - } - return; - } - - var dao = new pb.DAO(); - dao.save(site, function(err, result) { - if(util.isError(err)) { + siteService.createSite(site, post.id, function(err, isTaken, field, result) { + if(isTaken) { + if(field === 'hostname') { cb({ - code: 500, - content: pb.BaseController.apiResponse(pb.BaseController.API_ERROR, self.ls.get('ERROR_SAVING')) + code: 400, + content: pb.BaseController.apiResponse(pb.BaseController.API_ERROR, self.ls.get('EXISTING_HOSTNAME')) + }); + } else { + cb({ + code: 400, + content: pb.BaseController.apiResponse(pb.BaseController.API_ERROR, self.ls.get('EXISTING_DISPLAYNAME')) }); - return; } + } + if(util.isError(err)) { + cb({ + code: 500, + content: pb.BaseController.apiResponse(pb.BaseController.API_ERROR, self.ls.get('ERROR_SAVING')) + }); + return; + } - cb({content: pb.BaseController.apiResponse(pb.BaseController.API_SUCCESS, self.ls.get('SITE_CREATED'), result)}); - }); + cb({content: pb.BaseController.apiResponse(pb.BaseController.API_SUCCESS, self.ls.get('SITE_CREATED'), result)}); }); }); - } + }; NewSite.prototype.getRequiredFields = function() { return ['displayName', 'hostname']; }; - function getUid() - { - return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {var r = Math.random()*16|0,v=c=='x'?r:r&0x3|0x8;return v.toString(16);}); - } - //exports return NewSite; }; \ No newline at end of file diff --git a/plugins/pencilblue/templates/admin/sites/manage.html b/plugins/pencilblue/templates/admin/sites/manage.html index 54ec2e0a2..eb2bf701f 100644 --- a/plugins/pencilblue/templates/admin/sites/manage.html +++ b/plugins/pencilblue/templates/admin/sites/manage.html @@ -65,6 +65,7 @@ + ^tmp_admin=elements=progress_console_modal^ ^tmp_angular=admin=sites=manage^ ^tmp_admin=footer^ diff --git a/plugins/pencilblue/templates/angular/admin/sites/manage.html b/plugins/pencilblue/templates/angular/admin/sites/manage.html index ae68fae09..a87067988 100644 --- a/plugins/pencilblue/templates/angular/admin/sites/manage.html +++ b/plugins/pencilblue/templates/angular/admin/sites/manage.html @@ -28,31 +28,126 @@ }; $scope.activateSite = function(site) { + site.name = site.displayName; + $scope.actionPlugin = site; + $scope.actionProgress = '0'; + $scope.consoleOutput = ''; + $('#progress_modal').modal({}); + $http.post('/actions/admin/site/activate/' + site.uid) .success(function(result) { - $scope.onActionSuccess(); - $scope.$apply(); + $scope.onActivateOrDeactivateComplete(result); }) .error(function(error, status) { - $scope.errorMessage = error.message; + $scope.onActionFailure(error); }); }; $scope.deactivateSite = function(site) { + site.name = site.displayName; + $scope.actionPlugin = site; + $scope.actionProgress = '0'; + $scope.consoleOutput = ''; + $('#progress_modal').modal({}); + $http.post('/actions/admin/site/deactivate/' + site.uid) .success(function(result) { - $scope.onActionSuccess(); - $scope.$apply(); + $scope.onActivateOrDeactivateComplete(result); }) .error(function(error, status) { - $scope.errorMessage = error.message; + $scope.onActionFailure(error); + }); + }; + + $scope.jobAction = function(actionType, identifier, data, cb) { + $http.post("/api/jobs/" + actionType + "/" + encodeURIComponent(identifier), data) + .success(function(result) { + cb(result); + }) + .error(function(error, status) { + $scope.onActionFailure(error); }); }; + $scope.onActivateOrDeactivateComplete = function(result) { + var jobId = result.data; + + //poll for logs + var logHandle = null; + var starting = 0; + var doLogRetrieve = function() { + $scope.jobAction('getLogs', jobId, {starting: starting}, function(result) { + if (!result || !result.data || !result.data.length) { + return; + } + + var nextStarting = starting; + for(var i = 0; i < result.data.length; i++) { + var item = result.data[i]; + $scope.consoleOutput += ($scope.consoleOutput.length ? '\n' : '') + item.created + ':[' + item.worker_id + '] ' + item.message; + + var date = new Date(item.created).getTime(); + if(date > nextStarting) { + nextStarting = date; + } + } + + //offset so we don't get repeats + starting = nextStarting + 1; + + //check for more log entries + logHandle = setTimeout(doLogRetrieve, 2000); + }); + }; + doLogRetrieve(); + + //check for job completion + var retrieveHandle = null; + var doJobRetrieve = function() { + $scope.jobAction('get', jobId, {}, function(result) { + if(!result || !result.data) { + return; + } + + //set progress bar + if(!isNaN(result.data.progress)) { + $scope.actionProgress = result.data.progress.toString(); + } + + //verify status + if(result.data.status === 'RUNNING') { + retrieveHandle = setTimeout(doJobRetrieve, 1000); + } + else { + //allow any trailing logs to come in + setTimeout(function() { + clearTimeout(logHandle); + + var line = result.data.status; + if (result.data.error) { + line += ': ' + result.data.error; + } + $scope.consoleOutput += ($scope.consoleOutput.length ? '\n' : '') + line; + $scope.onActionSuccess(); + $scope.$apply(); + }, 1500); + } + }); + }; + doJobRetrieve(); + }; + + $scope.onActionSuccess = function() { + $scope.actionIsComplete = true; $scope.refreshPage(); } + $scope.onActionFailure = function(error) { + $scope.actionIsComplete = true; + $scope.actionError = error.message; + } + $scope.refreshPage = function() { $window.location.reload(); } diff --git a/public/localization/en-us.js b/public/localization/en-us.js index 86d6a263a..5058999f0 100755 --- a/public/localization/en-us.js +++ b/public/localization/en-us.js @@ -430,7 +430,11 @@ var loc = sites: { EXISTING_HOSTNAME: 'That hostname is already in use', EXISTING_DISPLAYNAME: 'There is already a site with that displayname', - SITE_CREATED: 'The site was successfully created' + SITE_CREATED: 'The site was successfully created', + ERROR_ACTIVATING: 'There was an error activating', + ERROR_DEACTIVATING: 'There was an error deactivating', + SITE_ACTIVATED: 'Site activated', + SITE_DEACTIVATED: 'Site deactivated' }, plugins: { From 8b00499b73160638b51abe00f853a2f8ef49ecc9 Mon Sep 17 00:00:00 2001 From: Andrew Monroe Date: Wed, 29 Apr 2015 15:54:28 -0400 Subject: [PATCH 020/790] centralize some site related constants where possible --- include/dao/dao.js | 14 ++++----- include/http/request_handler.js | 18 +++++------ include/repository/plugin_repository.js | 18 +++++------ include/requirements.js | 8 ++--- include/service/cache_entity_service.js | 8 ++--- include/service/db_entity_service.js | 14 ++++----- include/service/entities/plugin_service.js | 31 +++++++++---------- .../entities/plugin_setting_service.js | 4 +-- include/service/entities/site_service.js | 6 +++- .../jobs/plugins/plugin_install_job.js | 4 +-- .../jobs/plugins/plugin_uninstall_job.js | 8 ++--- include/service/memory_entity_service.js | 8 ++--- .../controllers/api/plugins/plugin_api.js | 4 +-- 13 files changed, 74 insertions(+), 71 deletions(-) diff --git a/include/dao/dao.js b/include/dao/dao.js index 8c288bab8..923b4ca6e 100755 --- a/include/dao/dao.js +++ b/include/dao/dao.js @@ -85,8 +85,8 @@ module.exports = function DAOModule(pb) { */ DAO.DESC = -1; - var GLOBAL_PREFIX = 'global'; - var SITE_COLL = 'site'; + var GLOBAL_SITE = 'global'; + var SITE_FIELD = 'site'; /** * Retrieves an object by ID @@ -135,12 +135,12 @@ module.exports = function DAOModule(pb) { }; DAO.prototype.loadByValueForOneSite = function(key, val, site, collection, opts, cb) { - if(!site || site === GLOBAL_PREFIX) { + if(!site || site === GLOBAL_SITE) { this.loadByValueFromGlobal(key,val,collection,opts,cb); } else { var where = {}; where[key] = val; - where[SITE_COLL] = site; + where[SITE_FIELD] = site; this.loadByValues(where, collection, opts, cb); } }; @@ -148,9 +148,9 @@ module.exports = function DAOModule(pb) { DAO.prototype.loadByValueFromGlobal = function(key, val, collection, opts, cb) { var where = {}; var hasNoSite = {}; - hasNoSite[SITE_COLL] = { $exists : false }; + hasNoSite[SITE_FIELD] = { $exists : false }; var siteIsGlobal = {}; - siteIsGlobal[SITE_COLL] = GLOBAL_PREFIX; + siteIsGlobal[SITE_FIELD] = GLOBAL_SITE; where[key] = val; where['$or'] = [ hasNoSite, @@ -459,7 +459,7 @@ module.exports = function DAOModule(pb) { }; DAO.prototype.saveToSite = function(dbObj, site, options, cb) { - dbObj[SITE_COLL] = site || GLOBAL_PREFIX; + dbObj[SITE_FIELD] = site || GLOBAL_SITE; this.save(dbObj, options, cb); }; diff --git a/include/http/request_handler.js b/include/http/request_handler.js index 855234710..5f447ac3c 100755 --- a/include/http/request_handler.js +++ b/include/http/request_handler.js @@ -77,7 +77,7 @@ module.exports = function RequestHandlerModule(pb) { RequestHandler.storage = []; RequestHandler.index = {}; RequestHandler.sites = {}; - var GLOBAL_PREFIX = 'global'; + var GLOBAL_SITE = pb.SiteService.GLOBAL_SITE; /** * The internal storage of static routes after they are validated and processed. * @private @@ -173,7 +173,7 @@ module.exports = function RequestHandlerModule(pb) { //resolve the site if(!site) { - site = GLOBAL_PREFIX; + site = GLOBAL_SITE; } var routesRemoved = 0; @@ -199,7 +199,7 @@ module.exports = function RequestHandlerModule(pb) { //resolve the site if(!site) { - site = GLOBAL_PREFIX; + site = GLOBAL_SITE; } @@ -261,7 +261,7 @@ module.exports = function RequestHandlerModule(pb) { //resolve empty site to global if(!site) { - site = GLOBAL_PREFIX; + site = GLOBAL_SITE; } //validate route @@ -594,7 +594,7 @@ module.exports = function RequestHandlerModule(pb) { this.session = session; //set the site -- how do we handle improper sites here? - this.site = RequestHandler.sites[this.hostname] || GLOBAL_PREFIX; + this.site = RequestHandler.sites[this.hostname] || GLOBAL_SITE; //find the controller to hand off to var route = this.getRoute(this.url.pathname); @@ -629,7 +629,7 @@ module.exports = function RequestHandlerModule(pb) { var isSilly = pb.log.isSilly(); var route = RequestHandler.staticRoutes[path]; if (!util.isNullOrUndefined(route)) { - if(route.themes[this.site] || route.themes[GLOBAL_PREFIX]) { + if(route.themes[this.site] || route.themes[GLOBAL_SITE]) { if (isSilly) { pb.log.silly('RequestHandler: Found static route [%s]', path); } @@ -648,7 +648,7 @@ module.exports = function RequestHandlerModule(pb) { pb.log.silly('RequestHandler: Comparing Path [%s] to Pattern [%s] Result [%s]', path, curr.pattern, result); } if (result) { - if(curr.themes[this.site] || curr.themes[GLOBAL_PREFIX]) { + if(curr.themes[this.site] || curr.themes[GLOBAL_SITE]) { return curr; } break; @@ -690,7 +690,7 @@ module.exports = function RequestHandlerModule(pb) { }; RequestHandler.routeSupportsGlobalTheme = function(route, theme, method) { - return RequestHandler.routeSupportsSiteTheme(route, theme, method, GLOBAL_PREFIX); + return RequestHandler.routeSupportsSiteTheme(route, theme, method, GLOBAL_SITE); }; /** @@ -722,7 +722,7 @@ module.exports = function RequestHandlerModule(pb) { } else if (RequestHandler.routeSupportsGlobalTheme(route, themesToCheck[j], methods[i])) { obj.theme = themesToCheck[j]; obj.method = methods[i]; - obj.site = GLOBAL_PREFIX; + obj.site = GLOBAL_SITE; } } } diff --git a/include/repository/plugin_repository.js b/include/repository/plugin_repository.js index acb6a5f01..34fe281b5 100644 --- a/include/repository/plugin_repository.js +++ b/include/repository/plugin_repository.js @@ -3,8 +3,8 @@ var async = require('async'); module.exports = function PluginRepositoryModule(pb) { var PLUGIN_COLL = 'plugin' - var GLOBAL_PREFIX = 'global'; - var SITE_COLL = 'site'; + var GLOBAL_SITE = pb.SiteService.GLOBAL_SITE; + var SITE_FIELD = pb.SiteService.SITE_FIELD; var publicAPI = {}; @@ -12,7 +12,7 @@ module.exports = function PluginRepositoryModule(pb) { var dao = new pb.DAO(); var hasATheme = getHasThemeQuery(); var belongsToSite = getBelongsToSiteQuery(site); - var belongsToGlobal = getBelongsToSiteQuery(GLOBAL_PREFIX); + var belongsToGlobal = getBelongsToSiteQuery(GLOBAL_SITE); var siteWhere = { $and: [ hasATheme, belongsToSite ] }; @@ -69,8 +69,8 @@ module.exports = function PluginRepositoryModule(pb) { } if(!plugin) { - if(site && site !== GLOBAL_PREFIX) { - loadPluginOwnedByThisSite(pluginID, GLOBAL_PREFIX, cb); + if(site && site !== GLOBAL_SITE) { + loadPluginOwnedByThisSite(pluginID, GLOBAL_SITE, cb); return; } cb(err, null); @@ -143,12 +143,12 @@ module.exports = function PluginRepositoryModule(pb) { function getBelongsToSiteQuery(site) { var belongsToThisSite = {}; - if(!site || site === GLOBAL_PREFIX) { + if(!site || site === GLOBAL_SITE) { var hasNoSite = {}; - hasNoSite[SITE_COLL] = { $exists : false}; + hasNoSite[SITE_FIELD] = { $exists : false}; var siteIsGlobal = {}; - siteIsGlobal[SITE_COLL] = GLOBAL_PREFIX; + siteIsGlobal[SITE_FIELD] = GLOBAL_SITE; belongsToThisSite = { $or: [ hasNoSite, @@ -156,7 +156,7 @@ module.exports = function PluginRepositoryModule(pb) { ]}; } else { belongsToThisSite = {}; - belongsToThisSite[SITE_COLL] = site; + belongsToThisSite[SITE_FIELD] = site; } } diff --git a/include/requirements.js b/include/requirements.js index 6294beeed..5eef1b492 100755 --- a/include/requirements.js +++ b/include/requirements.js @@ -78,6 +78,10 @@ module.exports = function PB(config) { pb.SessionHandler = SessionModule(pb); pb.session = new pb.SessionHandler(pb.SessionHandler.getSessionStoreInstance()); + //setup site service + pb.SiteService = require(path.join(config.docRoot, '/include/service/entities/site_service.js'))(pb); + pb.sites = new pb.SiteService(); + //setup object services pb.SimpleLayeredService = require(path.join(config.docRoot, '/include/service/simple_layered_service.js'))(pb); pb.MemoryEntityService = require(path.join(config.docRoot, '/include/service/memory_entity_service.js'))(pb); @@ -105,10 +109,6 @@ module.exports = function PB(config) { pb.UserService = require(path.join(config.docRoot, '/include/service/entities/user_service.js'))(pb); pb.users = new pb.UserService(); - //setup site service - pb.SiteService = require(path.join(config.docRoot, '/include/service/entities/site_service.js'))(pb); - pb.sites = new pb.SiteService(); - //setup request handling var BodyParsers = require(path.join(config.docRoot, 'include/http/parsers'))(pb); pb.BaseBodyParser = BodyParsers.BaseBodyParser; diff --git a/include/service/cache_entity_service.js b/include/service/cache_entity_service.js index 1e7ad2cb9..1befe55dc 100755 --- a/include/service/cache_entity_service.js +++ b/include/service/cache_entity_service.js @@ -40,11 +40,11 @@ module.exports = function CacheEntityServiceModule(pb) { this.objType = objType; this.keyField = keyField; this.valueField = valueField ? valueField : null; - this.site = site || GLOBAL_PREFIX; + this.site = site || GLOBAL_SITE; this.onlyThisSite = onlyThisSite ? true : false; } - var GLOBAL_PREFIX = 'global'; + var GLOBAL_SITE = pb.SiteService.GLOBAL_SITE; /** * Retrieve a value from the cache @@ -64,8 +64,8 @@ module.exports = function CacheEntityServiceModule(pb) { //site specific value doesn't exist in cache if (result == null) { - if(self.site !== GLOBAL_PREFIX && !self.onlyThisSite) { - pb.cache.get(keyValue(key, GLOBAL_PREFIX), function(err, result){ + if(self.site !== GLOBAL_SITE && !self.onlyThisSite) { + pb.cache.get(keyValue(key, GLOBAL_SITE), function(err, result){ if (util.isError(err)) { cb(err, null); return; diff --git a/include/service/db_entity_service.js b/include/service/db_entity_service.js index 576f126de..5f57ab356 100755 --- a/include/service/db_entity_service.js +++ b/include/service/db_entity_service.js @@ -36,12 +36,12 @@ module.exports = function DbEntityServiceModule(pb) { this.objType = objType; this.keyField = keyField; this.valueField = valueField ? valueField : null; - this.site = site || GLOBAL_PREFIX; + this.site = site || GLOBAL_SITE; this.onlyThisSite = onlyThisSite ? true : false; } - var GLOBAL_PREFIX = 'global'; - var SITE_COLL = 'site'; + var GLOBAL_SITE = pb.SiteService.GLOBAL_SITE; + var SITE_FIELD = pb.SiteService.SITE_FIELD; /** * Retrieve a value from the database * @@ -135,18 +135,18 @@ module.exports = function DbEntityServiceModule(pb) { where[this.keyField] = key; var hasNoSite = {}; - hasNoSite[SITE_COLL] = { $exists : false}; + hasNoSite[SITE_FIELD] = { $exists : false}; var siteIsGlobal = {}; - siteIsGlobal[SITE_COLL] = GLOBAL_PREFIX; + siteIsGlobal[SITE_FIELD] = GLOBAL_SITE; - if(!this.site || this.site === GLOBAL_PREFIX) { + if(!this.site || this.site === GLOBAL_SITE) { where['$or'] = [ hasNoSite, siteIsGlobal ]; } else { - where[SITE_COLL] = this.site; + where[SITE_FIELD] = this.site; } dao.delete(where, this.objType, cb); }; diff --git a/include/service/entities/plugin_service.js b/include/service/entities/plugin_service.js index 42f023ac4..96bc6c473 100755 --- a/include/service/entities/plugin_service.js +++ b/include/service/entities/plugin_service.js @@ -27,8 +27,7 @@ var util = require('../../util.js'); module.exports = function PluginServiceModule(pb) { - var GLOBAL_PREFIX = 'global'; - var SITE_COLL = 'site'; + var GLOBAL_SITE = pb.SiteService.GLOBAL_SITE; /** * PluginService - Provides functions for interacting with plugins. * Install/uninstall, setting retrieval, plugin retrieval, etc. @@ -42,7 +41,7 @@ module.exports = function PluginServiceModule(pb) { if(pb.config.multisite && siteUID) { this.site = siteUID; } else { - this.site = GLOBAL_PREFIX; + this.site = GLOBAL_SITE; } this._pluginRepository = pb.PluginRepository; @@ -82,8 +81,8 @@ module.exports = function PluginServiceModule(pb) { function getPluginForSite(theme, site) { if (ACTIVE_PLUGINS[this.site] && ACTIVE_PLUGINS[this.site][theme]) { return ACTIVE_PLUGINS[this.site][theme]; - } else if (ACTIVE_PLUGINS[GLOBAL_PREFIX] && ACTIVE_PLUGINS[GLOBAL_PREFIX][theme]) { - return ACTIVE_PLUGINS[GLOBAL_PREFIX][theme]; + } else if (ACTIVE_PLUGINS[GLOBAL_SITE] && ACTIVE_PLUGINS[GLOBAL_SITE][theme]) { + return ACTIVE_PLUGINS[GLOBAL_SITE][theme]; } return null; } @@ -139,7 +138,7 @@ module.exports = function PluginServiceModule(pb) { } if(!site) { - site = GLOBAL_PREFIX; + site = GLOBAL_SITE; } if (ACTIVE_PLUGINS[site] && ACTIVE_PLUGINS[site][pluginUid]) { @@ -158,7 +157,7 @@ module.exports = function PluginServiceModule(pb) { */ PluginService.getActiveMainModule = function(pluginUid, site) { if(!site) { - site = GLOBAL_PREFIX; + site = GLOBAL_SITE; } return (ACTIVE_PLUGINS[site] && ACTIVE_PLUGINS[site][pluginUid]) ? ACTIVE_PLUGINS[site][pluginUid].main_module : null; }; @@ -171,8 +170,8 @@ module.exports = function PluginServiceModule(pb) { */ PluginService.prototype.getActivePluginNames = function() { var globalPlugins = []; - if(ACTIVE_PLUGINS[GLOBAL_PREFIX]) { - globalPlugins = Object.keys(ACTIVE_PLUGINS[GLOBAL_PREFIX]); + if(ACTIVE_PLUGINS[GLOBAL_SITE]) { + globalPlugins = Object.keys(ACTIVE_PLUGINS[GLOBAL_SITE]); } var sitePlugins = []; if(ACTIVE_PLUGINS[this.site]) { @@ -524,7 +523,7 @@ module.exports = function PluginServiceModule(pb) { */ PluginService.isActivePlugin = function(uid, site) { if(!site) { - site = GLOBAL_PREFIX; + site = GLOBAL_SITE; } var plugin = getPluginForSite(uid, site); if(plugin) { @@ -537,7 +536,7 @@ module.exports = function PluginServiceModule(pb) { PluginService.isPluginActiveBySite = function(uid, site) { if(!site) { - site = GLOBAL_PREFIX; + site = GLOBAL_SITE; } if(ACTIVE_PLUGINS[site] && ACTIVE_PLUGINS[site][uid]) { return true; @@ -876,7 +875,7 @@ module.exports = function PluginServiceModule(pb) { pb.log.debug("PluginService:[INIT] Beginning initialization of %s (%s)", plugin.name, plugin.uid); var details = null; - var site = plugin.site || GLOBAL_PREFIX; + var site = plugin.site || GLOBAL_SITE; var tasks = [ //load the details file @@ -1361,15 +1360,15 @@ module.exports = function PluginServiceModule(pb) { */ PluginService.getService = function(serviceName, pluginUid, site) { if(!site) { - site = GLOBAL_PREFIX; + site = GLOBAL_SITE; } if (ACTIVE_PLUGINS[site] && ACTIVE_PLUGINS[site][pluginUid]) { if (ACTIVE_PLUGINS[site][pluginUid].services && ACTIVE_PLUGINS[site][pluginUid].services[serviceName]) { return ACTIVE_PLUGINS[site][pluginUid].services[serviceName]; } - } else if (ACTIVE_PLUGINS[GLOBAL_PREFIX] && ACTIVE_PLUGINS[GLOBAL_PREFIX][pluginUid]) { - if (ACTIVE_PLUGINS[GLOBAL_PREFIX][pluginUid].services && ACTIVE_PLUGINS[GLOBAL_PREFIX][pluginUid].services[serviceName]) { - return ACTIVE_PLUGINS[GLOBAL_PREFIX][pluginUid].services[serviceName]; + } else if (ACTIVE_PLUGINS[GLOBAL_SITE] && ACTIVE_PLUGINS[GLOBAL_SITE][pluginUid]) { + if (ACTIVE_PLUGINS[GLOBAL_SITE][pluginUid].services && ACTIVE_PLUGINS[GLOBAL_SITE][pluginUid].services[serviceName]) { + return ACTIVE_PLUGINS[GLOBAL_SITE][pluginUid].services[serviceName]; } } throw new Error('Either plugin ['+pluginUid+'] or the service ['+serviceName+'] does not exist'); diff --git a/include/service/entities/plugin_setting_service.js b/include/service/entities/plugin_setting_service.js index d06324b4c..58e237bd4 100644 --- a/include/service/entities/plugin_setting_service.js +++ b/include/service/entities/plugin_setting_service.js @@ -1,6 +1,6 @@ module.exports = function PluginSettingServiceModule(pb) { - var GLOBAL_PREFIX = 'global'; + var GLOBAL_SITE = pb.SiteService.GLOBAL_SITE; function PluginSettingService(siteUID){ //construct settings services @@ -9,7 +9,7 @@ module.exports = function PluginSettingServiceModule(pb) { if(pb.config.multisite && siteUID) { this.site = siteUID; } else { - this.site = GLOBAL_PREFIX; + this.site = GLOBAL_SITE; } this.pluginService = new pb.PluginService(this.site); diff --git a/include/service/entities/site_service.js b/include/service/entities/site_service.js index 29105fa04..2e0c99287 100644 --- a/include/service/entities/site_service.js +++ b/include/service/entities/site_service.js @@ -3,7 +3,6 @@ var util = require('../../util.js'); module.exports = function SiteServiceModule(pb) { - var SITE_COLL = 'site' /** * Service for performing site specific operations. @@ -15,6 +14,11 @@ module.exports = function SiteServiceModule(pb) { */ function SiteService(){} + SiteService.GLOBAL_SITE = 'global'; + SiteService.SITE_FIELD = 'site'; + SiteService.SITE_COLLECTION = 'site'; + var SITE_COLL = SiteService.SITE_COLLECTION; + SiteService.prototype.getActiveSites = function(cb) { var dao = new pb.DAO(); dao.q(SITE_COLL, { select: pb.DAO.SELECT_ALL, where: {active: true} }, cb); diff --git a/include/service/jobs/plugins/plugin_install_job.js b/include/service/jobs/plugins/plugin_install_job.js index 318c86d3d..83456c147 100644 --- a/include/service/jobs/plugins/plugin_install_job.js +++ b/include/service/jobs/plugins/plugin_install_job.js @@ -20,7 +20,7 @@ var async = require('async'); var util = require('../../../util.js'); module.exports = function PluginInstallJobModule(pb) { - var GLOBAL_PREFIX = 'global'; + var GLOBAL_SITE = pb.SiteService.GLOBAL_SITE; /** * A system job that coordinates the uninstall of a plugin across the cluster. @@ -172,7 +172,7 @@ module.exports = function PluginInstallJobModule(pb) { clone.dirName = pluginUid; var pluginDescriptor = pb.DocumentCreator.create('plugin', clone); - pluginDescriptor.site = site || GLOBAL_PREFIX; + pluginDescriptor.site = site || GLOBAL_SITE; self.dao.save(pluginDescriptor, callback); }, diff --git a/include/service/jobs/plugins/plugin_uninstall_job.js b/include/service/jobs/plugins/plugin_uninstall_job.js index ad921550c..186644f3e 100644 --- a/include/service/jobs/plugins/plugin_uninstall_job.js +++ b/include/service/jobs/plugins/plugin_uninstall_job.js @@ -57,7 +57,7 @@ module.exports = function PluginUninstallJobModule(pb) { PluginUninstallJob.UNINSTALL_PLUGIN_COMMAND = 'uninstall_plugin'; var GLOBAL_PREFIX = 'global'; - var SITE_COLL = 'site'; + var SITE_FIELD = pb.SiteService.SITE_FIELD; /** * Retrieves the tasks needed to contact each process in the cluster to @@ -175,10 +175,10 @@ module.exports = function PluginUninstallJobModule(pb) { }; var hasNoSite = {}; - hasNoSite[SITE_COLL] = { $exists : false}; + hasNoSite[SITE_FIELD] = { $exists : false}; var siteIsGlobal = {}; - siteIsGlobal[SITE_COLL] = GLOBAL_PREFIX; + siteIsGlobal[SITE_FIELD] = GLOBAL_PREFIX; if(!site || site === GLOBAL_PREFIX) { where['$or'] = [ @@ -186,7 +186,7 @@ module.exports = function PluginUninstallJobModule(pb) { siteIsGlobal ]; } else { - where[SITE_COLL] = site; + where[SITE_FIELD] = site; } var dao = new pb.DAO(); diff --git a/include/service/memory_entity_service.js b/include/service/memory_entity_service.js index 6f86b4114..fb2f90585 100755 --- a/include/service/memory_entity_service.js +++ b/include/service/memory_entity_service.js @@ -48,7 +48,7 @@ module.exports = function MemoryEntityServiceModule(pb) { } - var GLOBAL_PREFIX = 'global'; + var GLOBAL_SITE = pb.SiteService.GLOBAL_SITE; /** * The type string that describes the storage medium for the service @@ -72,7 +72,7 @@ module.exports = function MemoryEntityServiceModule(pb) { if(this.site) { value = getSiteValue(this, key, this.site); } - if(value == null && this.site !== GLOBAL_PREFIX && !this.onlyThisSite) { + if(value == null && this.site !== GLOBAL_SITE && !this.onlyThisSite) { value = getGlobalValue(this, key); } cb(null, value); @@ -95,7 +95,7 @@ module.exports = function MemoryEntityServiceModule(pb) { function getGlobalValue(self, key) { - return getSiteValue(self, key, GLOBAL_PREFIX); + return getSiteValue(self, key, GLOBAL_SITE); } function getCorrectValueField(rawVal, valueField) { @@ -138,7 +138,7 @@ module.exports = function MemoryEntityServiceModule(pb) { MemoryEntityService.prototype._set = function(key, value, cb) { var rawValue = null; if(!this.site) { - this.site = GLOBAL_PREFIX; + this.site = GLOBAL_SITE; } if (this.storage.hasOwnProperty(this.site) && this.storage[this.site].hasOwnProperty(key)) { rawValue = this.storage[this.site][key]; diff --git a/plugins/pencilblue/controllers/api/plugins/plugin_api.js b/plugins/pencilblue/controllers/api/plugins/plugin_api.js index b99b58b95..08fca3325 100755 --- a/plugins/pencilblue/controllers/api/plugins/plugin_api.js +++ b/plugins/pencilblue/controllers/api/plugins/plugin_api.js @@ -27,7 +27,7 @@ module.exports = function(pb) { var PluginService = pb.PluginService; var RequestHandler = pb.RequestHandler; - var GLOBAL_PREFIX = 'global'; + var GLOBAL_SITE = pb.SiteService.GLOBAL_SITE; /** * Controller to properly route and handle remote calls to interact with @@ -74,7 +74,7 @@ module.exports = function(pb) { PluginApiController.prototype.render = function(cb) { var action = this.pathVars.action; var identifier = this.pathVars.id; - this.site = this.pathVars.site || GLOBAL_PREFIX; + this.site = this.pathVars.site || GLOBAL_SITE; this.pluginService = new pb.PluginService(this.site); //validate action From f1df92ac53c2e2285f7b68fb6808d81c116dcb5c Mon Sep 17 00:00:00 2001 From: Andrew Monroe Date: Wed, 29 Apr 2015 16:16:39 -0400 Subject: [PATCH 021/790] fix careless mistake breaking plugin admin page --- include/repository/plugin_repository.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/include/repository/plugin_repository.js b/include/repository/plugin_repository.js index acb6a5f01..9a43369d1 100644 --- a/include/repository/plugin_repository.js +++ b/include/repository/plugin_repository.js @@ -81,6 +81,9 @@ module.exports = function PluginRepositoryModule(pb) { }; publicAPI.loadIncludedPluginsOwnedByThisSite = function(pluginIDs, site, cb) { + if(!pluginIDs || !pluginIDs.length) { + pluginIDs = []; + } var idIsInTheList = getIdsInListQuery(pluginIDs); var belongsToThisSite = getBelongsToSiteQuery(site); var where = { @@ -96,6 +99,9 @@ module.exports = function PluginRepositoryModule(pb) { }; publicAPI.loadPluginsNotIncludedOwnedByThisSite = function(pluginIDs, site, cb) { + if(!pluginIDs || !pluginIDs.length) { + pluginIDs = []; + } var idIsNotInTheList = getIdsNotInListQuery(pluginIDs); var belongsToThisSite = getBelongsToSiteQuery(site); var where = { @@ -158,6 +164,7 @@ module.exports = function PluginRepositoryModule(pb) { belongsToThisSite = {}; belongsToThisSite[SITE_COLL] = site; } + return belongsToThisSite; } function mergeSitePluginsWithGlobalPlugins(sitePlugins, globalPlugins) { From 9e2f4736b4495f991f623cde98d5be179622862a Mon Sep 17 00:00:00 2001 From: btidwell Date: Wed, 29 Apr 2015 17:14:06 -0400 Subject: [PATCH 022/790] remove test deploy script --- testdeploy.js | 135 -------------------------------------------------- 1 file changed, 135 deletions(-) delete mode 100644 testdeploy.js diff --git a/testdeploy.js b/testdeploy.js deleted file mode 100644 index cadc09128..000000000 --- a/testdeploy.js +++ /dev/null @@ -1,135 +0,0 @@ -var AWS = require('aws-sdk'); -var LINQ = require('node-linq').LINQ; - -//deploy to east region on test stack -AWS.config.region = 'us-east-1'; - -//OpsWorks Parameters for deployment -var StackId = process.env.AWS_StackId; -var AppId = process.env.AWS_AppId; -var LayerId = process.env.AWS_LayerId; - -var opsWorks = new AWS.OpsWorks(); - -getInstanceIds(function(instanceIds){ - if(instanceIds.length < 1){ - throw new NoEC2InstanceAvailableError("No instances are online for deployment"); - } - else{ - var deployParams = { - Command:{ - Name: 'deploy' - }, - StackId: StackId, - AppId: AppId, - InstanceIds: instanceIds - }; - createDeployment(deployParams); - } -}); - -//Get Instance IDs from stack matching desired LayerId -function getInstanceIds(cb){ - opsWorks.describeInstances({LayerId: LayerId}, function(err, data){ - if(err){ - console.log(StackId + ' ' + LayerId); - console.log(err, err.stack); - } - else{ - var instanceIds = new LINQ(data.Instances).Select(function(instance){ - return instance.InstanceId; - }).ToArray(); - console.log('Deploying to these instances: ' + instanceIds); - cb(instanceIds); - } - }); -} - -//Run the deloyment -function createDeployment(deployParams){ - opsWorks.createDeployment(deployParams, function(err, data){ - if(err){ - console.log(err, err.stack); - } - else{ - console.log("Deployment Id: " + data.DeploymentId); - watchDeployment(data.DeploymentId); - } - }); -} -//Hold the thread until deployment is finished. -function watchDeployment(deploymentId){ - opsWorks.describeDeployments({DeploymentIds: [deploymentId]}, function(err, data){ - if(err){ - console.log(err, err.stack); - } - else{ - console.log(data); - if(data.Deployments[0].Status.toLowerCase() === 'running'){ - var timeout = 60000; - console.log('Deployment in progress, waiting for ' + timeout + ' ms.'); - setTimeout(function(){ - watchDeployment(deploymentId); - }, timeout); - } - else{ - console.log('Deployment Finished. Status: ' + data.Deployments[0].Status); - if(data.Deployments[0].Status.toLowerCase() === 'failed'){ - throw new DeploymentFailedException("Deployment failed"); - } - else{ - healthCheck(); - } - } - } - }); -} - -//Hold the thread until load balancer reports healthy instances (will check 2 times in 15 second intervals) -var healthChecksRemaining = 10; -function healthCheck(){ - var elb = new AWS.ELB(); - setTimeout(function(){ - elb.describeInstanceHealth({LoadBalancerName: process.env.AWS_ELB_NAME}, function(err, data){ - if (err){ - console.log(err, err.stack); // an error occurred - } - else{ - var unhealthyInstances = new LINQ(data.InstanceStates).Where(function(instanceState){ - return instanceState.State === 'OutOfService' || instanceState.State === 'Unknown'; - }).ToArray(); - if(unhealthyInstances && unhealthyInstances.length > 0){ - healthChecksRemaining --; - console.log('Unhealthy Instance Count: ' + unhealthyInstances.length); - if(healthChecksRemaining < 1){ - throw new UnhealthyEC2InstanceError("Instance Unhealthy after 5 consecutive health checks"); - } - else{ - healthCheck(); - } - } - else{ - console.log('Instance is healthy, moving on to nightwatch.'); - } - } - }); - }, 30000); -} - -//Exception for when no ec2 instances are available -function NoEC2InstanceAvailableError(message){ - this.message = message; - this.name = "NoEC2InstanceAvailableError"; -} - -//Exceptions for when deployment fails -function DeploymentFailedException(message){ - this.message = message; - this.name = "DeploymentFailedException"; -} - -//Exception for unhealthy EC2 Instances after deployment -function UnhealthyEC2InstanceError(message){ - this.message = message; - this.name = "UnhealthyEC2InstanceError"; -} \ No newline at end of file From 2d1745f53527718f03eb07e09fbe9cc6cbbf9e3d Mon Sep 17 00:00:00 2001 From: Andrew Monroe Date: Thu, 30 Apr 2015 10:07:14 -0400 Subject: [PATCH 023/790] fix bugs in install/uninstall plugin path --- include/repository/plugin_repository.js | 2 +- include/service/entities/plugin_service.js | 14 +++++++++++++- include/service/entities/plugin_setting_service.js | 12 ++++++++++++ .../service/jobs/plugins/plugin_uninstall_job.js | 4 ++-- .../controllers/api/plugins/plugin_api.js | 2 +- 5 files changed, 29 insertions(+), 5 deletions(-) diff --git a/include/repository/plugin_repository.js b/include/repository/plugin_repository.js index 9a43369d1..a82be4e5f 100644 --- a/include/repository/plugin_repository.js +++ b/include/repository/plugin_repository.js @@ -51,7 +51,7 @@ module.exports = function PluginRepositoryModule(pb) { publicAPI.loadPluginOwnedByThisSite = function(pluginID, site, cb) { var hasCorrectIdentifier = getCorrectIdQuery(pluginID); - var belongsToSite = getBelongsToSiteQuery(site); + var belongsToThisSite = getBelongsToSiteQuery(site); var where = { $and: [ hasCorrectIdentifier, belongsToThisSite] diff --git a/include/service/entities/plugin_service.js b/include/service/entities/plugin_service.js index 42f023ac4..74574dbd3 100755 --- a/include/service/entities/plugin_service.js +++ b/include/service/entities/plugin_service.js @@ -380,6 +380,16 @@ module.exports = function PluginServiceModule(pb) { settingService.resetThemeSettings(details, cb); }; + PluginService.prototype.purgePluginSettings = function(pluginUid, cb) { + settingService = getPluginSettingService(this); + settingService.purgePluginSettings(pluginUid, cb); + }; + + PluginService.prototype.purgeThemeSettings = function(pluginUid, cb) { + settingService = getPluginSettingService(this); + settingService.purgeThemeSettings(pluginUid, cb); + } + function getPluginSettingService(self) { if(!self.pluginSettingService) { self.pluginSettingService = new pb.PluginSettingService(self.site); @@ -971,7 +981,9 @@ module.exports = function PluginServiceModule(pb) { if (!mainModule) { return cb(new Error('Failed to load main module for plugin '+plugin.uid)); } - + if(!ACTIVE_PLUGINS[plugin.site]) { + ACTIVE_PLUGINS[plugin.site] = {}; + } ACTIVE_PLUGINS[plugin.site][details.uid] = { main_module: mainModule, public_dir: PluginService.getPublicPath(plugin.dirName), diff --git a/include/service/entities/plugin_setting_service.js b/include/service/entities/plugin_setting_service.js index d06324b4c..151ec51a5 100644 --- a/include/service/entities/plugin_setting_service.js +++ b/include/service/entities/plugin_setting_service.js @@ -1,3 +1,6 @@ +var util = require('../../util.js'); + + module.exports = function PluginSettingServiceModule(pb) { var GLOBAL_PREFIX = 'global'; @@ -430,6 +433,15 @@ module.exports = function PluginSettingServiceModule(pb) { }); }; + PluginSettingService.prototype.purgePluginSettings = function(pluginUid, cb) { + this.pluginSettingsService.purge(pluginUid, cb); + }; + + PluginSettingService.prototype.purgeThemeSettings = function(pluginUid, cb) { + this.themeSettingsService.purge(pluginUid, cb); + }; + + /** * Convenience function to generate a service to handle settings for a plugin. * diff --git a/include/service/jobs/plugins/plugin_uninstall_job.js b/include/service/jobs/plugins/plugin_uninstall_job.js index ad921550c..4ab47fda3 100644 --- a/include/service/jobs/plugins/plugin_uninstall_job.js +++ b/include/service/jobs/plugins/plugin_uninstall_job.js @@ -152,7 +152,7 @@ module.exports = function PluginUninstallJobModule(pb) { function(callback) { self.log('Attemping to remove plugin settings'); - this.pluginService.pluginSettingsService.purge(pluginUid, function (err, result) { + self.pluginService.purgePluginSettings(pluginUid, function (err, result) { callback(err, !util.isError(err) && result); }); }, @@ -161,7 +161,7 @@ module.exports = function PluginUninstallJobModule(pb) { function(callback) { self.log('Attemping to remove theme settings'); - this.pluginService.themeSettingsService.purge(pluginUid, function (err, result) { + self.pluginService.purgeThemeSettings(pluginUid, function (err, result) { callback(err, !util.isError(err) && result); }); }, diff --git a/plugins/pencilblue/controllers/api/plugins/plugin_api.js b/plugins/pencilblue/controllers/api/plugins/plugin_api.js index b99b58b95..54dc15c28 100755 --- a/plugins/pencilblue/controllers/api/plugins/plugin_api.js +++ b/plugins/pencilblue/controllers/api/plugins/plugin_api.js @@ -95,7 +95,7 @@ module.exports = function(pb) { return; } //route to handler - this[action](identifier, site, cb); + this[action](identifier, cb); }; /** From 99ff3ed4d14f0314c37d67493813c93cd92514ed Mon Sep 17 00:00:00 2001 From: Andrew Monroe Date: Thu, 30 Apr 2015 13:58:46 -0400 Subject: [PATCH 024/790] fixing reference error in plugin repo --- include/repository/plugin_repository.js | 7 +++--- include/service/entities/plugin_service.js | 28 +++++++++++----------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/include/repository/plugin_repository.js b/include/repository/plugin_repository.js index a82be4e5f..065458d1c 100644 --- a/include/repository/plugin_repository.js +++ b/include/repository/plugin_repository.js @@ -1,4 +1,5 @@ var async = require('async'); +var util = require('../util.js'); module.exports = function PluginRepositoryModule(pb) { @@ -17,7 +18,7 @@ module.exports = function PluginRepositoryModule(pb) { $and: [ hasATheme, belongsToSite ] }; var globalWhere = { - $and: [ hasATheme, belongsToSite ] + $and: [ hasATheme, belongsToGlobal ] }; var tasks = { sitePlugins: function(callback) { @@ -62,7 +63,7 @@ module.exports = function PluginRepositoryModule(pb) { }; publicAPI.loadPluginAvailableToThisSite = function(pluginID, site, cb) { - loadPluginOwnedByThisSite(pluginID, site, function(err, plugin){ + publicAPI.loadPluginOwnedByThisSite(pluginID, site, function(err, plugin){ if (util.isError(err)) { cb(err, null); return; @@ -70,7 +71,7 @@ module.exports = function PluginRepositoryModule(pb) { if(!plugin) { if(site && site !== GLOBAL_PREFIX) { - loadPluginOwnedByThisSite(pluginID, GLOBAL_PREFIX, cb); + publicAPI.loadPluginOwnedByThisSite(pluginID, GLOBAL_PREFIX, cb); return; } cb(err, null); diff --git a/include/service/entities/plugin_service.js b/include/service/entities/plugin_service.js index 74574dbd3..3aad13f76 100755 --- a/include/service/entities/plugin_service.js +++ b/include/service/entities/plugin_service.js @@ -212,7 +212,7 @@ module.exports = function PluginServiceModule(pb) { * installed. */ PluginService.prototype.getSetting = function(settingName, pluginName, cb) { - settingService = getPluginSettingService(this); + var settingService = getPluginSettingService(this); settingService.getSetting(settingName, pluginName, cb); }; @@ -225,7 +225,7 @@ module.exports = function PluginServiceModule(pb) { * Null is provided in the event that the plugin is not installed. */ PluginService.prototype.getSettings = function(pluginName, cb) { - settingService = getPluginSettingService(this); + var settingService = getPluginSettingService(this); settingService.getSettings(pluginName, cb); }; @@ -243,7 +243,7 @@ module.exports = function PluginServiceModule(pb) { * exists, and a hash of of the plugin's settings' names/values. */ PluginService.prototype.getSettingsKV = function(pluginName, cb) { - settingService = getPluginSettingService(this); + var settingService = getPluginSettingService(this); settingService.getSettingsKV(pluginName, cb); }; @@ -258,7 +258,7 @@ module.exports = function PluginServiceModule(pb) { * TRUE if the setting was persisted successfully, FALSE if not. */ PluginService.prototype.setSetting = function(name, value, pluginName, cb) { - settingService = getPluginSettingService(this); + var settingService = getPluginSettingService(this); settingService.setSetting(name, value, pluginName, cb); }; @@ -272,7 +272,7 @@ module.exports = function PluginServiceModule(pb) { * TRUE if the settings were persisted successfully, FALSE if not. */ PluginService.prototype.setSettings = function(settings, pluginName, cb) { - settingService = getPluginSettingService(this); + var settingService = getPluginSettingService(this); settingService.setSettings(settings, pluginName, cb); }; @@ -287,7 +287,7 @@ module.exports = function PluginServiceModule(pb) { * TRUE if the setting was persisted successfully, FALSE if not. */ PluginService.prototype.setThemeSetting = function(name, value, pluginName, cb) { - settingService = getPluginSettingService(this); + var settingService = getPluginSettingService(this); settingService.setThemeSetting(name, value, pluginName, cb); }; @@ -301,7 +301,7 @@ module.exports = function PluginServiceModule(pb) { * TRUE if the settings were persisted successfully, FALSE if not. */ PluginService.prototype.setThemeSettings = function(settings, pluginName, cb) { - settingService = getPluginSettingService(this); + var settingService = getPluginSettingService(this); settingService.setThemeSettings(settings, pluginName, cb); }; @@ -314,7 +314,7 @@ module.exports = function PluginServiceModule(pb) { * @param cb A callback that provides two parameters: cb(error, settingValue) */ PluginService.prototype.getThemeSetting = function(settingName, pluginName, cb) { - settingService = getPluginSettingService(this); + var settingService = getPluginSettingService(this); settingService.getThemeSetting(settingName, pluginName, cb); }; @@ -326,7 +326,7 @@ module.exports = function PluginServiceModule(pb) { * @param cb A callback that provides two parameters: cb(err, settingsObject) */ PluginService.prototype.getThemeSettings = function(pluginName, cb) { - settingService = getPluginSettingService(this); + var settingService = getPluginSettingService(this); settingService.getThemeSettings(pluginName, cb); }; @@ -344,7 +344,7 @@ module.exports = function PluginServiceModule(pb) { * exists, and a hash of of the plugin's settings' names/values. */ PluginService.prototype.getThemeSettingsKV = function(pluginName, cb) { - settingService = getPluginSettingService(this); + var settingService = getPluginSettingService(this); settingService.getThemeSettingsKV(pluginName, cb); }; @@ -360,7 +360,7 @@ module.exports = function PluginServiceModule(pb) { * TRUE if the settings were successfully cleared and reloaded. FALSE if not. */ PluginService.prototype.resetSettings = function(details, cb) { - settingService = getPluginSettingService(this); + var settingService = getPluginSettingService(this); settingService.resetSettings(details, cb); }; @@ -376,17 +376,17 @@ module.exports = function PluginServiceModule(pb) { * TRUE if the settings were successfully cleared and reloaded. FALSE if not. */ PluginService.prototype.resetThemeSettings = function(details, cb) { - settingService = getPluginSettingService(this); + var settingService = getPluginSettingService(this); settingService.resetThemeSettings(details, cb); }; PluginService.prototype.purgePluginSettings = function(pluginUid, cb) { - settingService = getPluginSettingService(this); + var settingService = getPluginSettingService(this); settingService.purgePluginSettings(pluginUid, cb); }; PluginService.prototype.purgeThemeSettings = function(pluginUid, cb) { - settingService = getPluginSettingService(this); + var settingService = getPluginSettingService(this); settingService.purgeThemeSettings(pluginUid, cb); } From 64a0c100c119f917e65226855d9696d9ea310f8d Mon Sep 17 00:00:00 2001 From: Andrew Monroe Date: Thu, 30 Apr 2015 14:00:59 -0400 Subject: [PATCH 025/790] fix syntax errors in plugin repository --- include/repository/plugin_repository.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/repository/plugin_repository.js b/include/repository/plugin_repository.js index 065458d1c..7b1a8f58a 100644 --- a/include/repository/plugin_repository.js +++ b/include/repository/plugin_repository.js @@ -3,7 +3,7 @@ var util = require('../util.js'); module.exports = function PluginRepositoryModule(pb) { - var PLUGIN_COLL = 'plugin' + var PLUGIN_COLL = 'plugin'; var GLOBAL_PREFIX = 'global'; var SITE_COLL = 'site'; @@ -89,7 +89,7 @@ module.exports = function PluginRepositoryModule(pb) { var belongsToThisSite = getBelongsToSiteQuery(site); var where = { $and: [idIsInTheList, belongsToThisSite] - } + }; var opts = { select: pb.DAO.SELECT_ALL, where: where, @@ -107,7 +107,7 @@ module.exports = function PluginRepositoryModule(pb) { var belongsToThisSite = getBelongsToSiteQuery(site); var where = { $and: [idIsNotInTheList, belongsToThisSite] - } + }; var opts = { select: pb.DAO.SELECT_ALL, where: where, From 0da0375f5b26ac578897aec5997fa5b79a84d82a Mon Sep 17 00:00:00 2001 From: btidwell Date: Fri, 1 May 2015 13:00:58 -0400 Subject: [PATCH 026/790] Add site_id routes and link in manage_sites page --- .../controllers/admin/sites/manage.js | 3 - .../include/multisite_admin_routes.js | 751 ++++++++++++++++++ plugins/pencilblue/include/routes.js | 7 +- .../templates/admin/sites/manage.html | 4 +- 4 files changed, 759 insertions(+), 6 deletions(-) create mode 100644 plugins/pencilblue/include/multisite_admin_routes.js diff --git a/plugins/pencilblue/controllers/admin/sites/manage.js b/plugins/pencilblue/controllers/admin/sites/manage.js index 5932d684b..b9894b865 100644 --- a/plugins/pencilblue/controllers/admin/sites/manage.js +++ b/plugins/pencilblue/controllers/admin/sites/manage.js @@ -9,9 +9,6 @@ module.exports = function(pb) { Manage.prototype.render = function(cb) { var self = this; - - - var siteService = new pb.SiteService(); siteService.getSiteMap(function(err, map) { var angularObjects = pb.ClientJs.getAngularObjects({ diff --git a/plugins/pencilblue/include/multisite_admin_routes.js b/plugins/pencilblue/include/multisite_admin_routes.js new file mode 100644 index 000000000..df361563a --- /dev/null +++ b/plugins/pencilblue/include/multisite_admin_routes.js @@ -0,0 +1,751 @@ +/* + Copyright (C) 2015 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ + +//dependencies +var path = require('path'); + +//exports +module.exports = function Routes(pb){ + return [ + { + method: 'get', + path: "/admin/:siteid", + access_level: pb.SecurityService.ACCESS_WRITER, + auth_required: true, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'index.js'), + content_type: 'text/html' + }, + // NAVIGATION + { + method: 'get', + path: "/admin/:siteid/content/navigation", + access_level: pb.SecurityService.ACCESS_EDITOR, + auth_required: true, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'content', 'navigation', 'nav_map.js'), + content_type: 'text/html' + }, + { + method: 'get', + path: "/admin/:siteid/content/navigation/new", + access_level: pb.SecurityService.ACCESS_EDITOR, + auth_required: true, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'content', 'navigation', 'nav_item_form.js'), + content_type: 'text/html' + }, + { + method: 'get', + path: "/admin/:siteid/content/navigation/:id", + access_level: pb.SecurityService.ACCESS_EDITOR, + auth_required: true, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'content', 'navigation', 'nav_item_form.js'), + content_type: 'text/html' + }, + { + method: 'post', + path: "/actions/admin/:siteid/content/navigation/map", + access_level: pb.SecurityService.ACCESS_EDITOR, + auth_required: true, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'content', 'navigation', 'nav_map.js'), + content_type: 'text/html' + }, + { + method: 'post', + path: "/actions/admin/:siteid/content/navigation", + access_level: pb.SecurityService.ACCESS_EDITOR, + auth_required: true, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'content', 'navigation', 'new_nav_item.js'), + content_type: 'text/html' + }, + { + method: 'post', + path: "/actions/admin/:siteid/content/navigation/:id", + access_level: pb.SecurityService.ACCESS_EDITOR, + auth_required: true, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'content', 'navigation', 'edit_nav_item.js'), + content_type: 'text/html' + }, + { + method: 'delete', + path: "/actions/admin/:siteid/content/navigation/:id", + access_level: pb.SecurityService.ACCESS_EDITOR, + auth_required: true, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'content', 'navigation', 'delete_nav_item.js'), + content_type: 'text/html' + }, + + // TOPICS + { + method: 'get', + path: "/admin/:siteid/content/topics", + access_level: pb.SecurityService.ACCESS_EDITOR, + auth_required: true, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'content', 'topics', 'manage_topics.js'), + content_type: 'text/html' + }, + { + method: 'get', + path: "/admin/:siteid/content/topics/new", + access_level: pb.SecurityService.ACCESS_EDITOR, + auth_required: true, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'content', 'topics', 'topic_form.js'), + content_type: 'text/html' + }, + { + method: 'get', + path: "/admin/:siteid/content/topics/import", + access_level: pb.SecurityService.ACCESS_EDITOR, + auth_required: true, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'content', 'topics', 'import_topics.js'), + content_type: 'text/html' + }, + { + method: 'get', + path: "/admin/:siteid/content/topics/:id", + access_level: pb.SecurityService.ACCESS_EDITOR, + auth_required: true, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'content', 'topics', 'topic_form.js'), + content_type: 'text/html' + }, + { + method: 'post', + path: "/actions/admin/:siteid/content/topics", + access_level: pb.SecurityService.ACCESS_EDITOR, + auth_required: true, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'content', 'topics', 'new_topic.js'), + content_type: 'text/html' + }, + { + method: 'post', + path: "/actions/admin/:siteid/content/topics/import", + access_level: pb.SecurityService.ACCESS_EDITOR, + auth_required: true, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'content', 'topics', 'import_topics.js'), + content_type: 'text/html' + }, + { + method: 'post', + path: "/actions/admin/:siteid/content/topics/:id", + access_level: pb.SecurityService.ACCESS_EDITOR, + auth_required: true, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'content', 'topics', 'edit_topic.js'), + content_type: 'text/html' + }, + { + method: 'delete', + path: "/actions/admin/:siteid/content/topics/:id", + access_level: pb.SecurityService.ACCESS_EDITOR, + auth_required: true, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'content', 'topics', 'delete_topic.js'), + content_type: 'text/html' + }, + + // ARTICLES + { + method: 'get', + path: "/admin/:siteid/content/articles", + access_level: pb.SecurityService.ACCESS_WRITER, + auth_required: true, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'content', 'articles', 'manage_articles.js'), + content_type: 'text/html' + }, + { + method: 'get', + path: "/admin/:siteid/content/articles/new", + access_level: pb.SecurityService.ACCESS_WRITER, + auth_required: true, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'content', 'articles', 'article_form.js'), + content_type: 'text/html' + }, + { + method: 'get', + path: "/admin/:siteid/content/articles/:id", + access_level: pb.SecurityService.ACCESS_WRITER, + auth_required: true, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'content', 'articles', 'article_form.js'), + content_type: 'text/html' + }, + { + method: 'post', + path: "/actions/admin/:siteid/content/articles", + access_level: pb.SecurityService.ACCESS_WRITER, + auth_required: true, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'content', 'articles', 'new_article.js'), + content_type: 'text/html' + }, + { + method: 'post', + path: "/actions/admin/:siteid/content/articles/:id", + access_level: pb.SecurityService.ACCESS_WRITER, + auth_required: true, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'content', 'articles', 'edit_article.js'), + content_type: 'text/html' + }, + { + method: 'delete', + path: "/actions/admin/:siteid/content/articles/:id", + access_level: pb.SecurityService.ACCESS_EDITOR, + auth_required: true, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'content', 'articles', 'delete_article.js'), + }, + + // PAGES + { + method: 'get', + path: "/admin/:siteid/content/pages", + access_level: pb.SecurityService.ACCESS_EDITOR, + auth_required: true, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'content', 'pages', 'manage_pages.js'), + content_type: 'text/html' + }, + { + method: 'get', + path: "/admin/:siteid/content/pages/new", + access_level: pb.SecurityService.ACCESS_EDITOR, + auth_required: true, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'content', 'pages', 'page_form.js'), + content_type: 'text/html' + }, + { + method: 'get', + path: "/admin/:siteid/content/pages/:id", + access_level: pb.SecurityService.ACCESS_EDITOR, + auth_required: true, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'content', 'pages', 'page_form.js'), + content_type: 'text/html' + }, + { + method: 'post', + path: "/actions/admin/:siteid/content/pages", + access_level: pb.SecurityService.ACCESS_EDITOR, + auth_required: true, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'content', 'pages', 'new_page.js'), + content_type: 'text/html' + }, + { + method: 'post', + path: "/actions/admin/:siteid/content/pages/:id", + access_level: pb.SecurityService.ACCESS_EDITOR, + auth_required: true, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'content', 'pages', 'edit_page.js'), + content_type: 'text/html' + }, + { + method: 'delete', + path: "/actions/admin/:siteid/content/pages/:id", + access_level: pb.SecurityService.ACCESS_EDITOR, + auth_required: true, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'content', 'pages', 'delete_page.js'), + content_type: 'text/html' + }, + + // MEDIA + { + method: 'get', + path: "/admin/:siteid/content/media", + access_level: pb.SecurityService.ACCESS_WRITER, + auth_required: true, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'content', 'media', 'manage_media.js'), + content_type: 'text/html' + }, + { + method: 'get', + path: "/admin/:siteid/content/media/new", + access_level: pb.SecurityService.ACCESS_WRITER, + auth_required: true, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'content', 'media', 'media_form.js'), + content_type: 'text/html' + }, + { + method: 'get', + path: "/admin/:siteid/content/media/:id", + access_level: pb.SecurityService.ACCESS_WRITER, + auth_required: true, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'content', 'media', 'media_form.js'), + content_type: 'text/html' + }, + { + method: 'post', + path: "/actions/admin/:siteid/content/media", + access_level: pb.SecurityService.ACCESS_WRITER, + auth_required: true, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'content', 'media', 'new_media.js'), + content_type: 'text/html' + }, + { + method: 'post', + path: "/actions/admin/:siteid/content/media/:id", + access_level: pb.SecurityService.ACCESS_WRITER, + auth_required: true, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'content', 'media', 'edit_media.js'), + content_type: 'text/html' + }, + { + method: 'delete', + path: "/actions/admin/:siteid/content/media/:id", + access_level: pb.SecurityService.ACCESS_WRITER, + auth_required: true, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'content', 'media', 'delete_media.js'), + content_type: 'text/html' + }, + { + method: 'post', + path: "/api/admin/:siteid/content/media/upload_media", + access_level: pb.SecurityService.ACCESS_WRITER, + auth_required: true, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'api', 'admin', 'content', 'media', 'upload_media.js'), + content_type: 'text/html' + }, + { + method: 'get', + path: "/api/admin/:siteid/content/media/get_link", + access_level: pb.SecurityService.ACCESS_WRITER, + auth_required: true, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'api', 'admin', 'content', 'media', 'get_link.js'), + content_type: 'application/json' + }, + { + method: 'get', + path: "/api/admin/:siteid/content/media/get_preview", + access_level: pb.SecurityService.ACCESS_WRITER, + auth_required: true, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'api', 'admin', 'content', 'media', 'get_preview.js'), + content_type: 'application/json' + }, + + // COMMENTS + { + method: 'get', + path: "/admin/:siteid/content/comments", + auth_required: true, + access_level: pb.SecurityService.ACCESS_EDITOR, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'content', 'comments', 'manage_comments.js'), + content_type: 'text/html' + }, + { + method: 'delete', + path: "/actions/admin/:siteid/content/comments/:id", + access_level: pb.SecurityService.ACCESS_EDITOR, + auth_required: true, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'content', 'comments', 'delete_comment.js'), + content_type: 'text/html' + }, + + // CUSTOM OBJECT TYPES + { + method: 'get', + path: "/admin/:siteid/content/objects/types", + access_level: pb.SecurityService.ACCESS_EDITOR, + auth_required: true, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'content', 'objects', 'types', 'manage_types.js'), + content_type: 'text/html' + }, + { + method: 'get', + path: "/admin/:siteid/content/objects/types/new", + access_level: pb.SecurityService.ACCESS_EDITOR, + auth_required: true, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'content', 'objects', 'types', 'type_form.js'), + content_type: 'text/html' + }, + { + method: 'get', + path: "/admin/:siteid/content/objects/types/:id", + access_level: pb.SecurityService.ACCESS_EDITOR, + auth_required: true, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'content', 'objects', 'types', 'type_form.js'), + content_type: 'text/html' + }, + { + method: 'get', + path: "/api/admin/:siteid/content/objects/types/available", + access_level: pb.SecurityService.ACCESS_EDITOR, + auth_required: true, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'api', 'admin', 'content', 'objects', 'types', 'available.js'), + content_type: 'text/html' + }, + { + method: 'post', + path: "/actions/admin/:siteid/content/objects/types", + access_level: pb.SecurityService.ACCESS_EDITOR, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'content', 'objects', 'types', 'new_type.js'), + content_type: 'text/html', + request_body: ['application/json'] + }, + { + method: 'post', + path: "/actions/admin/:siteid/content/objects/types/:id", + access_level: pb.SecurityService.ACCESS_EDITOR, + auth_required: true, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'content', 'objects', 'types', 'edit_type.js'), + content_type: 'text/html', + request_body: ['application/json'] + }, + { + method: 'delete', + path: "/actions/admin/:siteid/content/objects/types/:id", + access_level: pb.SecurityService.ACCESS_EDITOR, + auth_required: true, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'content', 'objects', 'types', 'delete_type.js'), + content_type: 'text/html' + }, + + // CUSTOM OBJECTS + { + path: "/admin/:siteid/content/objects/:type_id", + access_level: pb.SecurityService.ACCESS_EDITOR, + auth_required: true, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'content', 'objects', 'manage_objects.js'), + content_type: 'text/html' + }, + { + path: "/admin/:siteid/content/objects/:type_id/sort", + access_level: pb.SecurityService.ACCESS_EDITOR, + auth_required: true, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'content', 'objects', 'sort_objects.js'), + content_type: 'text/html' + }, + { + method: 'get', + path: "/admin/:siteid/content/objects/:type_id/new", + access_level: pb.SecurityService.ACCESS_EDITOR, + auth_required: true, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'content', 'objects', 'object_form.js'), + content_type: 'text/html' + }, + { + method: 'get', + path: "/admin/:siteid/content/objects/:type_id/:id", + access_level: pb.SecurityService.ACCESS_EDITOR, + auth_required: true, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'content', 'objects', 'object_form.js'), + content_type: 'text/html' + }, + { + method: 'post', + path: "/actions/admin/:siteid/content/objects/:type_id/sort", + access_level: pb.SecurityService.ACCESS_EDITOR, + auth_required: true, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'content', 'objects', 'sort_objects.js'), + content_type: 'text/html', + request_body: ['application/json'] + }, + { + method: 'post', + path: "/actions/admin/:siteid/content/objects/:type_id", + access_level: pb.SecurityService.ACCESS_EDITOR, + auth_required: true, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'content', 'objects', 'new_object.js'), + content_type: 'text/html', + request_body: ['application/json'] + }, + { + method: 'post', + path: "/actions/admin/:siteid/content/objects/:type_id/:id", + access_level: pb.SecurityService.ACCESS_EDITOR, + auth_required: true, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'content', 'objects', 'edit_object.js'), + content_type: 'text/html', + request_body: ['application/json'] + }, + { + method: 'delete', + path: "/actions/admin/:siteid/content/objects/:id", + access_level: pb.SecurityService.ACCESS_EDITOR, + auth_required: true, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'content', 'objects', 'delete_object.js'), + content_type: 'text/html' + }, + + // PLUGINS + { + method: 'get', + path: "/admin/:siteid/plugins", + auth_required: true, + access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'plugins', 'manage_plugins.js'), + content_type: 'text/html' + }, + { + method: 'get', + path: "/admin/:siteid/plugins/:id", + auth_required: true, + access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'plugins', 'plugin_details.js'), + content_type: 'text/html' + }, + { + method: 'get', + path: "/admin/:siteid/plugins/:id/settings", + handler: 'get', + auth_required: true, + access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'plugins', 'plugin_settings.js'), + content_type: 'text/html' + }, + { + method: 'post', + path: "/admin/:siteid/plugins/:id/settings", + handler: 'post', + auth_required: true, + access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'plugins', 'plugin_settings.js'), + content_type: 'application/json', + request_body: ['application/json'] + }, + { + method: 'post', + path: "/api/plugins/:action/:id", + auth_required: true, + access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'api', 'plugins', 'plugin_api.js'), + content_type: 'application/json' + }, + { + method: 'post', + path: "/api/plugins/:action/:id/:site", + auth_required: true, + access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'api', 'plugins', 'plugin_api.js'), + content_type: 'application/json' + }, + + // THEMES + { + method: 'get', + path: "/admin/:siteid/themes", + auth_required: true, + access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'themes', 'manage_themes.js'), + content_type: 'text/html' + }, + { + method: 'get', + path: "/admin/:siteid/themes/:id/settings", + handler: 'get', + auth_required: true, + access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'themes', 'theme_settings.js'), + content_type: 'text/html' + }, + { + method: 'post', + path: "/admin/:siteid/themes/:id/settings", + handler: 'post', + auth_required: true, + access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'themes', 'theme_settings.js'), + content_type: 'application/json', + request_body: ['application/json'] + }, + { + method: 'post', + path: "/actions/admin/:siteid/themes/site_logo", + auth_required: true, + access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'themes', 'site_logo.js'), + }, + + // USERS + { + method: 'get', + path: "/admin/:siteid/users", + auth_required: true, + access_level: pb.SecurityService.ACCESS_EDITOR, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'users', 'manage_users.js'), + }, + { + method: 'get', + path: "/admin/:siteid/users/unverified", + auth_required: true, + access_level: pb.SecurityService.ACCESS_EDITOR, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'users', 'unverified_users.js'), + }, + { + method: 'get', + path: "/admin/:siteid/users/new", + auth_required: true, + access_level: pb.SecurityService.ACCESS_EDITOR, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'users', 'user_form.js'), + }, + { + method: 'get', + path: "/admin/:siteid/users/:id", + auth_required: true, + access_level: pb.SecurityService.ACCESS_EDITOR, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'users', 'user_form.js'), + }, + { + method: 'get', + path: "/admin/:siteid/users/password/:id", + auth_required: true, + access_level: pb.SecurityService.ACCESS_EDITOR, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'users', 'change_password.js'), + }, + { + method: 'post', + path: "/actions/admin/:siteid/users", + auth_required: true, + access_level: pb.SecurityService.ACCESS_EDITOR, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'users', 'new_user.js'), + }, + { + method: 'post', + path: "/actions/admin/:siteid/users/:id", + auth_required: true, + access_level: pb.SecurityService.ACCESS_EDITOR, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'users', 'edit_user.js'), + }, + { + method: 'delete', + path: "/actions/admin/:siteid/users/:id", + auth_required: true, + access_level: pb.SecurityService.ACCESS_EDITOR, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'users', 'delete_user.js'), + }, + { + method: 'delete', + path: "/actions/admin/:siteid/users/unverified/:id", + auth_required: true, + access_level: pb.SecurityService.ACCESS_EDITOR, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'users', 'delete_unverified_user.js'), + }, + { + method: 'get', + path: "/actions/admin/:siteid/users/verify/:id", + auth_required: true, + access_level: pb.SecurityService.ACCESS_EDITOR, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'users', 'verify_user.js'), + }, + + { + method: 'post', + path: "/actions/admin/:siteid/users/change_password/:id", + auth_required: true, + access_level: pb.SecurityService.ACCESS_EDITOR, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'users', 'change_password.js'), + }, + { + method: 'get', + path: "/actions/admin/:siteid/users/send_password_reset/:id", + auth_required: true, + access_level: pb.SecurityService.ACCESS_MANAGING_EDITOR, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'users', 'send_password_reset.js'), + }, + { + method: 'post', + path: "/actions/admin/:siteid/users/send_password_reset/:id", + auth_required: true, + access_level: pb.SecurityService.ACCESS_MANAGING_EDITOR, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'users', 'send_password_reset.js'), + }, + + // SITE SETTINGS + { + method: 'get', + path: "/admin/:siteid/site_settings", + access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, + auth_required: true, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'site_settings', 'configuration.js'), + content_type: 'text/html' + }, + { + method: 'post', + path: "/actions/admin/:siteid/site_settings", + access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, + auth_required: true, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'site_settings', 'configuration.js'), + content_type: 'text/html' + }, + { + method: 'get', + path: "/admin/:siteid/site_settings/content", + access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, + auth_required: true, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'site_settings', 'content.js'), + content_type: 'text/html' + }, + { + method: 'post', + path: "/actions/admin/:siteid/site_settings/content", + access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, + auth_required: true, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'site_settings', 'content.js'), + content_type: 'text/html' + }, + { + method: 'get', + path: "/admin/:siteid/site_settings/email", + access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, + auth_required: true, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'site_settings', 'email.js'), + content_type: 'text/html' + }, + { + method: 'post', + path: "/actions/admin/:siteid/site_settings/email", + access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, + auth_required: true, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'site_settings', 'email.js'), + content_type: 'text/html' + }, + { + method: 'get', + path: "/admin/:siteid/site_settings/libraries", + access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, + auth_required: true, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'site_settings', 'libraries.js'), + content_type: 'text/html' + }, + { + method: 'post', + path: "/actions/admin/:siteid/site_settings/libraries", + access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, + auth_required: true, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'site_settings', 'libraries.js'), + content_type: 'text/html' + }, + { + method: 'get', + path: "/admin/:siteid/sites", + access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, + auth_required: true, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'sites', 'manage.js'), + content_type: 'text/html' + }, + { + method: 'post', + path: "/actions/admin/:siteid/site", + access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, + auth_required: true, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'sites', 'new_site.js') + }, + { + method: 'post', + path: "/actions/admin/:siteid/site/activate/:id", + access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, + auth_required: true, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'sites', 'activate_site.js') + }, + { + method: 'post', + path: "/actions/admin/:siteid/site/deactivate/:id", + access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, + auth_required: true, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'sites', 'deactivate_site.js') + } + ]; +}; diff --git a/plugins/pencilblue/include/routes.js b/plugins/pencilblue/include/routes.js index 4d93036be..fa74d675e 100644 --- a/plugins/pencilblue/include/routes.js +++ b/plugins/pencilblue/include/routes.js @@ -17,10 +17,11 @@ //dependencies var path = require('path'); +var multiSiteAdminRoutes = require('./multisite_admin_routes'); //exports module.exports = function Routes(pb){ - return [ + var routes = [ { method: 'get', path: '/media/*', @@ -1036,4 +1037,8 @@ module.exports = function Routes(pb){ controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'sites', 'deactivate_site.js') } ]; + if(pb.config.multisite){ + routes = routes.concat(multiSiteAdminRoutes(pb)); + } + return routes; }; diff --git a/plugins/pencilblue/templates/admin/sites/manage.html b/plugins/pencilblue/templates/admin/sites/manage.html index eb2bf701f..1234f5246 100644 --- a/plugins/pencilblue/templates/admin/sites/manage.html +++ b/plugins/pencilblue/templates/admin/sites/manage.html @@ -19,7 +19,7 @@ - + @@ -45,7 +45,7 @@ - + From 478031957339abc6189b9f8d1d5f78f5545dc47b Mon Sep 17 00:00:00 2001 From: btidwell Date: Fri, 1 May 2015 14:56:38 -0400 Subject: [PATCH 027/790] add selected site id to session for admin and use 'uid' for site --- include/http/request_handler.js | 5 ++++- plugins/pencilblue/templates/admin/sites/manage.html | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/include/http/request_handler.js b/include/http/request_handler.js index f0df5b6f4..41cf729c0 100755 --- a/include/http/request_handler.js +++ b/include/http/request_handler.js @@ -811,7 +811,10 @@ module.exports = function RequestHandlerModule(pb) { if (util.isError(err)) { return self.serveError(err); } - + if(pathVars.siteid) { + self.session.adminSiteId = pathVars.siteid; + } + console.log(self.session); var props = { request_handler: self, request: self.req, diff --git a/plugins/pencilblue/templates/admin/sites/manage.html b/plugins/pencilblue/templates/admin/sites/manage.html index 1234f5246..ab69625d1 100644 --- a/plugins/pencilblue/templates/admin/sites/manage.html +++ b/plugins/pencilblue/templates/admin/sites/manage.html @@ -19,7 +19,7 @@ - + @@ -45,7 +45,7 @@ - + From 93cb8b298797840d886c0ad8a961362ab0987594 Mon Sep 17 00:00:00 2001 From: Andrew Monroe Date: Fri, 1 May 2015 16:19:46 -0400 Subject: [PATCH 028/790] make change to api route and use new route on the clientside when possible --- plugins/pencilblue/include/routes.js | 2 +- .../templates/angular/admin/plugins/manage_plugins.html | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/pencilblue/include/routes.js b/plugins/pencilblue/include/routes.js index 4d93036be..850c934c2 100644 --- a/plugins/pencilblue/include/routes.js +++ b/plugins/pencilblue/include/routes.js @@ -796,7 +796,7 @@ module.exports = function Routes(pb){ }, { method: 'post', - path: "/api/plugins/:action/:id/:site", + path: "/api/:site/plugins/:action/:id", auth_required: true, access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'api', 'plugins', 'plugin_api.js'), diff --git a/plugins/pencilblue/templates/angular/admin/plugins/manage_plugins.html b/plugins/pencilblue/templates/angular/admin/plugins/manage_plugins.html index caabf6da4..be7c9631b 100644 --- a/plugins/pencilblue/templates/angular/admin/plugins/manage_plugins.html +++ b/plugins/pencilblue/templates/angular/admin/plugins/manage_plugins.html @@ -17,8 +17,8 @@ successCb = $scope.onInstallOrUninstallComplete; break; } - - $http.post("/api/plugins/" + actionType + "/" + encodeURIComponent(plugin.uid)) + var prefix = $scope.siteUid ? "/api/" + $scope.siteUid : "/api"; + $http.post(prefix +"/plugins/" + actionType + "/" + encodeURIComponent(plugin.uid)) .success(function(result) { successCb(result); }) From 50747cd000cb9baba4afb7cae0e8776c32417689 Mon Sep 17 00:00:00 2001 From: Andrew Monroe Date: Fri, 1 May 2015 16:43:56 -0400 Subject: [PATCH 029/790] fix reference to plugin loader in plugin service --- include/service/entities/plugin_service.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/service/entities/plugin_service.js b/include/service/entities/plugin_service.js index 3d0b0ab96..1aec8cee3 100755 --- a/include/service/entities/plugin_service.js +++ b/include/service/entities/plugin_service.js @@ -79,8 +79,8 @@ module.exports = function PluginServiceModule(pb) { var ACTIVE_PLUGINS = {}; function getPluginForSite(theme, site) { - if (ACTIVE_PLUGINS[this.site] && ACTIVE_PLUGINS[this.site][theme]) { - return ACTIVE_PLUGINS[this.site][theme]; + if (ACTIVE_PLUGINS[site] && ACTIVE_PLUGINS[site][theme]) { + return ACTIVE_PLUGINS[site][theme]; } else if (ACTIVE_PLUGINS[GLOBAL_SITE] && ACTIVE_PLUGINS[GLOBAL_SITE][theme]) { return ACTIVE_PLUGINS[GLOBAL_SITE][theme]; } @@ -115,7 +115,7 @@ module.exports = function PluginServiceModule(pb) { PluginService.prototype.getActiveIcon = function(cb) { var settings = pb.SettingServiceFactory.getService(pb.config.settings.use_memory, pb.config.settings.use_cache, this.site); settings.get('active_theme', function(err, theme) { - var active_theme = getPluginForSite(this.site, theme); + var active_theme = getPluginForSite(theme, this.site); if(active_theme && active_theme.icon) { cb(err, active_theme.icon); } else { From 9c3a2ef3b69d900796623eebd37f3e951ec6ec01 Mon Sep 17 00:00:00 2001 From: andparker Date: Fri, 1 May 2015 17:23:15 -0400 Subject: [PATCH 030/790] Update plugin routes and controller to include site. --- .../controllers/admin/plugins/manage_plugins.js | 7 +++++-- plugins/pencilblue/include/routes.js | 8 ++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/plugins/pencilblue/controllers/admin/plugins/manage_plugins.js b/plugins/pencilblue/controllers/admin/plugins/manage_plugins.js index c08407a68..faae0ffab 100755 --- a/plugins/pencilblue/controllers/admin/plugins/manage_plugins.js +++ b/plugins/pencilblue/controllers/admin/plugins/manage_plugins.js @@ -38,8 +38,10 @@ module.exports = function(pb) { ManagePlugins.prototype.render = function(cb) { var self = this; + var site = self.pathVars.site; + //get the data - var pluginService = new pb.PluginService(); + var pluginService = new pb.PluginService(site); pluginService.getPluginMap(function(err, map) { if (util.isError(err)) { self.reqHandler.serveError(err); @@ -52,7 +54,8 @@ module.exports = function(pb) { pills: pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls), installedPlugins: map.active, inactivePlugins: map.inactive, - availablePlugins: map.available + availablePlugins: map.available, + siteUid: site }); //load the template diff --git a/plugins/pencilblue/include/routes.js b/plugins/pencilblue/include/routes.js index 850c934c2..b88083e08 100644 --- a/plugins/pencilblue/include/routes.js +++ b/plugins/pencilblue/include/routes.js @@ -759,6 +759,14 @@ module.exports = function Routes(pb){ controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'plugins', 'manage_plugins.js'), content_type: 'text/html' }, + { + method: 'get', + path: "/admin/:site/plugins", + auth_required: true, + access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'plugins', 'manage_plugins.js'), + content_type: 'text/html' + }, { method: 'get', path: "/admin/plugins/:id", From bf532100b207f33b438cb252d1e7e8e77756bfab Mon Sep 17 00:00:00 2001 From: btidwell Date: Mon, 4 May 2015 09:14:56 -0400 Subject: [PATCH 031/790] Admin navigation for multisite --- include/admin_navigation.js | 335 +++++++++--------- include/http/request_handler.js | 1 - .../admin/plugins/manage_plugins.js | 7 +- 3 files changed, 173 insertions(+), 170 deletions(-) diff --git a/include/admin_navigation.js b/include/admin_navigation.js index 6cbc10fcf..beed5804e 100755 --- a/include/admin_navigation.js +++ b/include/admin_navigation.js @@ -56,167 +56,9 @@ module.exports = function AdminNavigationModule(pb) { * * @private * @static - * @readonly - * @property DEFAULT_NAV - * @type {Array} + * @property MULTISITE_NAV + * @returns {Array} */ - var DEFAULT_NAV = Object.freeze([ - { - id: 'content', - title: 'CONTENT', - icon: 'quote-right', - href: '#', - access: SecurityService.ACCESS_WRITER, - children: [ - { - id: 'navigation', - title: 'NAVIGATION', - icon: 'th-large', - href: '/admin/content/navigation', - access: SecurityService.ACCESS_EDITOR - }, - { - id: 'topics', - title: 'TOPICS', - icon: 'tags', - href: '/admin/content/topics', - access: SecurityService.ACCESS_EDITOR - }, - { - id: 'pages', - title: 'PAGES', - icon: 'file-o', - href: '/admin/content/pages', - access: SecurityService.ACCESS_EDITOR - }, - { - id: 'articles', - title: 'ARTICLES', - icon: 'files-o', - href: '/admin/content/articles', - access: SecurityService.ACCESS_WRITER - }, - { - id: 'media', - title: 'MEDIA', - icon: 'camera', - href: '/admin/content/media', - access: SecurityService.ACCESS_WRITER - }, - { - id: 'comments', - title: 'COMMENTS', - icon: 'comments', - href: '/admin/content/comments', - access: SecurityService.ACCESS_EDITOR - }, - { - id: 'custom_objects', - title: 'CUSTOM_OBJECTS', - icon: 'sitemap', - href: '/admin/content/objects/types', - access: SecurityService.ACCESS_EDITOR - } - ] - }, - { - id: 'plugins', - title: 'PLUGINS', - icon: 'puzzle-piece', - href: '#', - access: SecurityService.ACCESS_ADMINISTRATOR, - children: [ - { - divider: true, - id: 'manage', - title: 'MANAGE', - icon: 'upload', - href: '/admin/plugins' - }, - { - id: 'themes', - title: 'THEMES', - icon: 'magic', - href: '/admin/themes' - } - ] - }, - { - id: 'users', - title: 'USERS', - icon: 'users', - href: '#', - access: SecurityService.ACCESS_EDITOR, - children: [ - { - id: 'manage', - title: 'MANAGE', - icon: 'users', - href: '/admin/users', - access: SecurityService.ACCESS_EDITOR - }, - { - id: 'permissions', - title: 'PERMISSIONS', - icon: 'lock', - href: '/admin/users/permissions', - access: SecurityService.ACCESS_ADMINISTRATOR - }, - ] - }, - { - id: 'settings', - title: 'SETTINGS', - icon: 'cogs', - href: '#', - access: SecurityService.ACCESS_WRITER, - children: [ - { - id: 'site_settings', - title: 'SITE_SETTINGS', - icon: 'cog', - href: '/admin/site_settings', - access: SecurityService.ACCESS_MANAGING_EDITOR - }, - { - id: 'content_settings', - title: 'CONTENT', - icon: 'quote-right', - href: '/admin/site_settings/content', - access: SecurityService.ACCESS_MANAGING_EDITOR - }, - { - id: 'email_settings', - title: 'EMAIL', - icon: 'envelope', - href: '/admin/site_settings/email', - access: SecurityService.ACCESS_MANAGING_EDITOR - }, - { - id: 'library_settings', - title: 'LIBRARIES', - icon: 'book', - href: '/admin/site_settings/libraries', - access: SecurityService.ACCESS_MANAGING_EDITOR - } - ] - }, - { - id: 'view_site', - title: 'VIEW_SITE', - icon: 'desktop', - href: '/', - access: SecurityService.ACCESS_WRITER - }, - { - id: 'logout', - title: 'LOGOUT', - icon: 'power-off', - href: '/actions/logout', - access: SecurityService.ACCESS_WRITER - } - ]); - var MULTISITE_NAV = Object.freeze([ { id: 'site_entity', @@ -227,15 +69,176 @@ module.exports = function AdminNavigationModule(pb) { } ]); + /** * * @private * @static * @method getDefaultNavigation + * @param adminsiteId {String} uid of site * @returns {Array} */ - function getDefaultNavigation() { - return util.clone(DEFAULT_NAV); + function getDefaultNavigation(adminSiteId) { + var adminPath = '/admin' + if(adminSiteId) { + adminPath = '/admin/' + adminSiteId; + } + return util.clone(Object.freeze([ + { + id: 'content', + title: 'CONTENT', + icon: 'quote-right', + href: '#', + access: SecurityService.ACCESS_WRITER, + children: [ + { + id: 'navigation', + title: 'NAVIGATION', + icon: 'th-large', + href: adminPath + '/content/navigation', + access: SecurityService.ACCESS_EDITOR + }, + { + id: 'topics', + title: 'TOPICS', + icon: 'tags', + href: adminPath + '/content/topics', + access: SecurityService.ACCESS_EDITOR + }, + { + id: 'pages', + title: 'PAGES', + icon: 'file-o', + href: adminPath + '/content/pages', + access: SecurityService.ACCESS_EDITOR + }, + { + id: 'articles', + title: 'ARTICLES', + icon: 'files-o', + href: adminPath + '/content/articles', + access: SecurityService.ACCESS_WRITER + }, + { + id: 'media', + title: 'MEDIA', + icon: 'camera', + href: adminPath + '/content/media', + access: SecurityService.ACCESS_WRITER + }, + { + id: 'comments', + title: 'COMMENTS', + icon: 'comments', + href: adminPath + '/content/comments', + access: SecurityService.ACCESS_EDITOR + }, + { + id: 'custom_objects', + title: 'CUSTOM_OBJECTS', + icon: 'sitemap', + href: adminPath + '/content/objects/types', + access: SecurityService.ACCESS_EDITOR + } + ] + }, + { + id: 'plugins', + title: 'PLUGINS', + icon: 'puzzle-piece', + href: '#', + access: SecurityService.ACCESS_ADMINISTRATOR, + children: [ + { + divider: true, + id: 'manage', + title: 'MANAGE', + icon: 'upload', + href: adminPath + '/plugins' + }, + { + id: 'themes', + title: 'THEMES', + icon: 'magic', + href: adminPath + '/themes' + } + ] + }, + { + id: 'users', + title: 'USERS', + icon: 'users', + href: '#', + access: SecurityService.ACCESS_EDITOR, + children: [ + { + id: 'manage', + title: 'MANAGE', + icon: 'users', + href: '/admin/users', + access: SecurityService.ACCESS_EDITOR + }, + { + id: 'permissions', + title: 'PERMISSIONS', + icon: 'lock', + href: '/admin/users/permissions', + access: SecurityService.ACCESS_ADMINISTRATOR + }, + ] + }, + { + id: 'settings', + title: 'SETTINGS', + icon: 'cogs', + href: '#', + access: SecurityService.ACCESS_WRITER, + children: [ + { + id: 'site_settings', + title: 'SITE_SETTINGS', + icon: 'cog', + href: '/admin/site_settings', + access: SecurityService.ACCESS_MANAGING_EDITOR + }, + { + id: 'content_settings', + title: 'CONTENT', + icon: 'quote-right', + href: '/admin/site_settings/content', + access: SecurityService.ACCESS_MANAGING_EDITOR + }, + { + id: 'email_settings', + title: 'EMAIL', + icon: 'envelope', + href: '/admin/site_settings/email', + access: SecurityService.ACCESS_MANAGING_EDITOR + }, + { + id: 'library_settings', + title: 'LIBRARIES', + icon: 'book', + href: '/admin/site_settings/libraries', + access: SecurityService.ACCESS_MANAGING_EDITOR + } + ] + }, + { + id: 'view_site', + title: 'VIEW_SITE', + icon: 'desktop', + href: '/', + access: SecurityService.ACCESS_WRITER + }, + { + id: 'logout', + title: 'LOGOUT', + icon: 'power-off', + href: '/actions/logout', + access: SecurityService.ACCESS_WRITER + } + ])); } function getMultiSiteNavigation() { @@ -271,12 +274,12 @@ module.exports = function AdminNavigationModule(pb) { * @method buildNavigation * @returns {Array} */ - function buildNavigation() { + function buildNavigation(session) { var i; var navigation = []; - var defaultNavigation = getDefaultNavigation(); - var additions = getAdditions(); var multiSiteAdditions = getMultiSiteNavigation(); + var defaultNavigation = getDefaultNavigation(session.adminSiteId); + var additions = getAdditions(); var childrenAdditions = getChildrenAdditions(); util.arrayPushAll(defaultNavigation, navigation); @@ -383,7 +386,7 @@ module.exports = function AdminNavigationModule(pb) { AdminNavigation.get = function (session, activeMenuItems, ls) { var navigation = AdminNavigation.removeUnauthorized( session, - buildNavigation(), + buildNavigation(session), activeMenuItems ); diff --git a/include/http/request_handler.js b/include/http/request_handler.js index 41cf729c0..ccaa96d7b 100755 --- a/include/http/request_handler.js +++ b/include/http/request_handler.js @@ -814,7 +814,6 @@ module.exports = function RequestHandlerModule(pb) { if(pathVars.siteid) { self.session.adminSiteId = pathVars.siteid; } - console.log(self.session); var props = { request_handler: self, request: self.req, diff --git a/plugins/pencilblue/controllers/admin/plugins/manage_plugins.js b/plugins/pencilblue/controllers/admin/plugins/manage_plugins.js index c08407a68..dbe1e286a 100755 --- a/plugins/pencilblue/controllers/admin/plugins/manage_plugins.js +++ b/plugins/pencilblue/controllers/admin/plugins/manage_plugins.js @@ -37,9 +37,9 @@ module.exports = function(pb) { ManagePlugins.prototype.render = function(cb) { var self = this; - + var adminSiteId = this.session.adminSiteId; //get the data - var pluginService = new pb.PluginService(); + var pluginService = new pb.PluginService(adminSiteId); pluginService.getPluginMap(function(err, map) { if (util.isError(err)) { self.reqHandler.serveError(err); @@ -52,7 +52,8 @@ module.exports = function(pb) { pills: pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls), installedPlugins: map.active, inactivePlugins: map.inactive, - availablePlugins: map.available + availablePlugins: map.available, + siteUid : adminSiteId }); //load the template From 1543be32df718539b1b124ff8f0a4b8f3db84890 Mon Sep 17 00:00:00 2001 From: btidwell Date: Mon, 4 May 2015 10:04:41 -0400 Subject: [PATCH 032/790] migrating andparker's changes to manag_plugins controller. --- .../controllers/admin/plugins/manage_plugins.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/plugins/pencilblue/controllers/admin/plugins/manage_plugins.js b/plugins/pencilblue/controllers/admin/plugins/manage_plugins.js index dbe1e286a..faae0ffab 100755 --- a/plugins/pencilblue/controllers/admin/plugins/manage_plugins.js +++ b/plugins/pencilblue/controllers/admin/plugins/manage_plugins.js @@ -37,9 +37,11 @@ module.exports = function(pb) { ManagePlugins.prototype.render = function(cb) { var self = this; - var adminSiteId = this.session.adminSiteId; + + var site = self.pathVars.site; + //get the data - var pluginService = new pb.PluginService(adminSiteId); + var pluginService = new pb.PluginService(site); pluginService.getPluginMap(function(err, map) { if (util.isError(err)) { self.reqHandler.serveError(err); @@ -53,7 +55,7 @@ module.exports = function(pb) { installedPlugins: map.active, inactivePlugins: map.inactive, availablePlugins: map.available, - siteUid : adminSiteId + siteUid: site }); //load the template From ab8a6e6a879e9de0017c220708bbcbade89d01a4 Mon Sep 17 00:00:00 2001 From: btidwell Date: Mon, 4 May 2015 10:09:42 -0400 Subject: [PATCH 033/790] Remove unnecessary routes for multisite --- .../include/multisite_admin_routes.js | 191 +----------------- 1 file changed, 1 insertion(+), 190 deletions(-) diff --git a/plugins/pencilblue/include/multisite_admin_routes.js b/plugins/pencilblue/include/multisite_admin_routes.js index df361563a..8248b270f 100644 --- a/plugins/pencilblue/include/multisite_admin_routes.js +++ b/plugins/pencilblue/include/multisite_admin_routes.js @@ -556,196 +556,7 @@ module.exports = function Routes(pb){ path: "/actions/admin/:siteid/themes/site_logo", auth_required: true, access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'themes', 'site_logo.js'), - }, - - // USERS - { - method: 'get', - path: "/admin/:siteid/users", - auth_required: true, - access_level: pb.SecurityService.ACCESS_EDITOR, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'users', 'manage_users.js'), - }, - { - method: 'get', - path: "/admin/:siteid/users/unverified", - auth_required: true, - access_level: pb.SecurityService.ACCESS_EDITOR, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'users', 'unverified_users.js'), - }, - { - method: 'get', - path: "/admin/:siteid/users/new", - auth_required: true, - access_level: pb.SecurityService.ACCESS_EDITOR, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'users', 'user_form.js'), - }, - { - method: 'get', - path: "/admin/:siteid/users/:id", - auth_required: true, - access_level: pb.SecurityService.ACCESS_EDITOR, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'users', 'user_form.js'), - }, - { - method: 'get', - path: "/admin/:siteid/users/password/:id", - auth_required: true, - access_level: pb.SecurityService.ACCESS_EDITOR, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'users', 'change_password.js'), - }, - { - method: 'post', - path: "/actions/admin/:siteid/users", - auth_required: true, - access_level: pb.SecurityService.ACCESS_EDITOR, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'users', 'new_user.js'), - }, - { - method: 'post', - path: "/actions/admin/:siteid/users/:id", - auth_required: true, - access_level: pb.SecurityService.ACCESS_EDITOR, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'users', 'edit_user.js'), - }, - { - method: 'delete', - path: "/actions/admin/:siteid/users/:id", - auth_required: true, - access_level: pb.SecurityService.ACCESS_EDITOR, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'users', 'delete_user.js'), - }, - { - method: 'delete', - path: "/actions/admin/:siteid/users/unverified/:id", - auth_required: true, - access_level: pb.SecurityService.ACCESS_EDITOR, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'users', 'delete_unverified_user.js'), - }, - { - method: 'get', - path: "/actions/admin/:siteid/users/verify/:id", - auth_required: true, - access_level: pb.SecurityService.ACCESS_EDITOR, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'users', 'verify_user.js'), - }, - - { - method: 'post', - path: "/actions/admin/:siteid/users/change_password/:id", - auth_required: true, - access_level: pb.SecurityService.ACCESS_EDITOR, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'users', 'change_password.js'), - }, - { - method: 'get', - path: "/actions/admin/:siteid/users/send_password_reset/:id", - auth_required: true, - access_level: pb.SecurityService.ACCESS_MANAGING_EDITOR, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'users', 'send_password_reset.js'), - }, - { - method: 'post', - path: "/actions/admin/:siteid/users/send_password_reset/:id", - auth_required: true, - access_level: pb.SecurityService.ACCESS_MANAGING_EDITOR, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'users', 'send_password_reset.js'), - }, - - // SITE SETTINGS - { - method: 'get', - path: "/admin/:siteid/site_settings", - access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, - auth_required: true, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'site_settings', 'configuration.js'), - content_type: 'text/html' - }, - { - method: 'post', - path: "/actions/admin/:siteid/site_settings", - access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, - auth_required: true, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'site_settings', 'configuration.js'), - content_type: 'text/html' - }, - { - method: 'get', - path: "/admin/:siteid/site_settings/content", - access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, - auth_required: true, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'site_settings', 'content.js'), - content_type: 'text/html' - }, - { - method: 'post', - path: "/actions/admin/:siteid/site_settings/content", - access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, - auth_required: true, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'site_settings', 'content.js'), - content_type: 'text/html' - }, - { - method: 'get', - path: "/admin/:siteid/site_settings/email", - access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, - auth_required: true, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'site_settings', 'email.js'), - content_type: 'text/html' - }, - { - method: 'post', - path: "/actions/admin/:siteid/site_settings/email", - access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, - auth_required: true, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'site_settings', 'email.js'), - content_type: 'text/html' - }, - { - method: 'get', - path: "/admin/:siteid/site_settings/libraries", - access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, - auth_required: true, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'site_settings', 'libraries.js'), - content_type: 'text/html' - }, - { - method: 'post', - path: "/actions/admin/:siteid/site_settings/libraries", - access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, - auth_required: true, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'site_settings', 'libraries.js'), - content_type: 'text/html' - }, - { - method: 'get', - path: "/admin/:siteid/sites", - access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, - auth_required: true, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'sites', 'manage.js'), - content_type: 'text/html' - }, - { - method: 'post', - path: "/actions/admin/:siteid/site", - access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, - auth_required: true, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'sites', 'new_site.js') - }, - { - method: 'post', - path: "/actions/admin/:siteid/site/activate/:id", - access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, - auth_required: true, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'sites', 'activate_site.js') - }, - { - method: 'post', - path: "/actions/admin/:siteid/site/deactivate/:id", - access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, - auth_required: true, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'sites', 'deactivate_site.js') + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'themes', 'site_logo.js') } ]; }; From 93775a6c22297cee5ee7bc826733194be86132af Mon Sep 17 00:00:00 2001 From: Eugene Chang Date: Mon, 4 May 2015 11:34:42 -0400 Subject: [PATCH 034/790] Allow site-aware plugin settings in Admin --- .../entities/plugin_setting_service.js | 4 +++- .../admin/plugins/plugin_settings.js | 14 ++++++++++++-- plugins/pencilblue/include/routes.js | 19 +++++++++++++++++++ .../admin/plugins/manage_plugins.html | 2 +- .../angular/admin/plugins/manage_plugins.html | 8 +++++++- .../admin/plugins/plugin_settings.html | 3 ++- 6 files changed, 44 insertions(+), 6 deletions(-) diff --git a/include/service/entities/plugin_setting_service.js b/include/service/entities/plugin_setting_service.js index ae8edd1e9..1089bc36f 100644 --- a/include/service/entities/plugin_setting_service.js +++ b/include/service/entities/plugin_setting_service.js @@ -4,6 +4,7 @@ var util = require('../../util.js'); module.exports = function PluginSettingServiceModule(pb) { var GLOBAL_SITE = pb.SiteService.GLOBAL_SITE; + var SITE_FIELD = pb.SiteService.SITE_FIELD; function PluginSettingService(siteUID){ //construct settings services @@ -367,8 +368,9 @@ module.exports = function PluginSettingServiceModule(pb) { plugin_name: plugin.name, plugin_uid: plugin.uid, plugin_id: plugin[pb.DAO.getIdField()].toString(), - settings: details.settings + settings: details.settings, }; + baseDoc[SITE_FIELD] = self.site; var settings = pb.DocumentCreator.create('plugin_settings', baseDoc); //save it diff --git a/plugins/pencilblue/controllers/admin/plugins/plugin_settings.js b/plugins/pencilblue/controllers/admin/plugins/plugin_settings.js index 8145fc9f5..752dd4536 100755 --- a/plugins/pencilblue/controllers/admin/plugins/plugin_settings.js +++ b/plugins/pencilblue/controllers/admin/plugins/plugin_settings.js @@ -41,12 +41,16 @@ module.exports = function(pb) { //statics var SUB_NAV_KEY = 'plugin_settings'; + PluginSettingsFormController.prototype.initialzePluginService = function initialzePluginService() { + this.pluginService = new pb.PluginService(this.getSite()); + }; PluginSettingsFormController.prototype.get = function(cb) { var self = this;console.log(this.constructor.name); + self.initialzePluginService(); var uid = this.pathVars.id; - this.pluginService.getPlugin(uid, function(err, plugin) { + this.pluginService.getPluginBySite(uid, function(err, plugin) { if (util.isError(err)) { throw err; } @@ -104,7 +108,8 @@ module.exports = function(pb) { navigation: pb.AdminNavigation.get(self.session, ['plugins', 'manage'], self.ls), settings: clone, pluginUID: uid, - type: data.settingType + type: data.settingType, + siteUid: self.getSite() }); //render page @@ -121,6 +126,7 @@ module.exports = function(pb) { var self = this;console.log(this.constructor.name); var post = this.body; + self.initialzePluginService(); //retrieve settings var uid = this.pathVars.id; self.getSettings(uid, function(err, settings) {console.log(settings); @@ -332,6 +338,10 @@ module.exports = function(pb) { return null; }; + PluginSettingsFormController.prototype.getSite = function () { + return this.pathVars.site; + }; + //register admin sub-nav pb.AdminSubnavService.registerFor(SUB_NAV_KEY, PluginSettingsFormController.geSubNavItems); diff --git a/plugins/pencilblue/include/routes.js b/plugins/pencilblue/include/routes.js index b88083e08..dc8953208 100644 --- a/plugins/pencilblue/include/routes.js +++ b/plugins/pencilblue/include/routes.js @@ -784,6 +784,15 @@ module.exports = function Routes(pb){ controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'plugins', 'plugin_settings.js'), content_type: 'text/html' }, + { + method: 'get', + path: "/admin/:site/plugins/:id/settings", + handler: 'get', + auth_required: true, + access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'plugins', 'plugin_settings.js'), + content_type: 'text/html' + }, { method: 'post', path: "/admin/plugins/:id/settings", @@ -794,6 +803,16 @@ module.exports = function Routes(pb){ content_type: 'application/json', request_body: ['application/json'] }, + { + method: 'post', + path: "/admin/:site/plugins/:id/settings", + handler: 'post', + auth_required: true, + access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'plugins', 'plugin_settings.js'), + content_type: 'application/json', + request_body: ['application/json'] + }, { method: 'post', path: "/api/plugins/:action/:id", diff --git a/plugins/pencilblue/templates/admin/plugins/manage_plugins.html b/plugins/pencilblue/templates/admin/plugins/manage_plugins.html index 1788ab014..9d9bfed2a 100755 --- a/plugins/pencilblue/templates/admin/plugins/manage_plugins.html +++ b/plugins/pencilblue/templates/admin/plugins/manage_plugins.html @@ -23,7 +23,7 @@
-  ^loc_SETTINGS^ +  ^loc_SETTINGS^ diff --git a/plugins/pencilblue/templates/angular/admin/plugins/manage_plugins.html b/plugins/pencilblue/templates/angular/admin/plugins/manage_plugins.html index be7c9631b..87bb1ae06 100644 --- a/plugins/pencilblue/templates/angular/admin/plugins/manage_plugins.html +++ b/plugins/pencilblue/templates/angular/admin/plugins/manage_plugins.html @@ -3,6 +3,12 @@ .controller('PencilBlueController', function($scope, $http, $window) { ^angular_objects^ + $scope.getSiteAwarePrefix = function (prefix) { + return $scope.siteUid ? '/' + prefix + '/' + $scope.siteUid : '/' + prefix; + }; + + $scope.adminPrefix = $scope.getSiteAwarePrefix('admin'); + $scope.pluginAction = function(actionType, plugin) { $scope.actionPlugin = plugin; $scope.actionType = actionType; @@ -17,7 +23,7 @@ successCb = $scope.onInstallOrUninstallComplete; break; } - var prefix = $scope.siteUid ? "/api/" + $scope.siteUid : "/api"; + var prefix = $scope.getSiteAwarePrefix('api'); $http.post(prefix +"/plugins/" + actionType + "/" + encodeURIComponent(plugin.uid)) .success(function(result) { successCb(result); diff --git a/plugins/pencilblue/templates/angular/admin/plugins/plugin_settings.html b/plugins/pencilblue/templates/angular/admin/plugins/plugin_settings.html index 73ae0f3de..b5844822b 100644 --- a/plugins/pencilblue/templates/angular/admin/plugins/plugin_settings.html +++ b/plugins/pencilblue/templates/angular/admin/plugins/plugin_settings.html @@ -11,7 +11,8 @@ settingsObject[$scope.settings[i].name] = $scope.settings[i].value; } - $http.post('/admin/' + $scope.type + '/' + $scope.pluginUID + '/settings', settingsObject) + var prefix = $scope.siteUid ? '/admin/' + $scope.siteUid + '/' : '/admin/'; + $http.post(prefix + $scope.type + '/' + $scope.pluginUID + '/settings', settingsObject) .success(function(result) { $scope.successMessage = result.message; $scope.saving = false; From 56686d3afda4bcde0694a0b87a8d37b1202f2350 Mon Sep 17 00:00:00 2001 From: Andrew Monroe Date: Mon, 4 May 2015 12:13:16 -0400 Subject: [PATCH 035/790] remove duplicate routes except api --- plugins/pencilblue/include/routes.js | 27 --------------------------- 1 file changed, 27 deletions(-) diff --git a/plugins/pencilblue/include/routes.js b/plugins/pencilblue/include/routes.js index 535a46f06..8cf15a912 100644 --- a/plugins/pencilblue/include/routes.js +++ b/plugins/pencilblue/include/routes.js @@ -760,14 +760,6 @@ module.exports = function Routes(pb){ controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'plugins', 'manage_plugins.js'), content_type: 'text/html' }, - { - method: 'get', - path: "/admin/:site/plugins", - auth_required: true, - access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'plugins', 'manage_plugins.js'), - content_type: 'text/html' - }, { method: 'get', path: "/admin/plugins/:id", @@ -785,15 +777,6 @@ module.exports = function Routes(pb){ controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'plugins', 'plugin_settings.js'), content_type: 'text/html' }, - { - method: 'get', - path: "/admin/:site/plugins/:id/settings", - handler: 'get', - auth_required: true, - access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'plugins', 'plugin_settings.js'), - content_type: 'text/html' - }, { method: 'post', path: "/admin/plugins/:id/settings", @@ -804,16 +787,6 @@ module.exports = function Routes(pb){ content_type: 'application/json', request_body: ['application/json'] }, - { - method: 'post', - path: "/admin/:site/plugins/:id/settings", - handler: 'post', - auth_required: true, - access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'plugins', 'plugin_settings.js'), - content_type: 'application/json', - request_body: ['application/json'] - }, { method: 'post', path: "/api/plugins/:action/:id", From a5e2c2282131d9c48dc2ef058e5cf96714e434a7 Mon Sep 17 00:00:00 2001 From: Andrew Monroe Date: Mon, 4 May 2015 12:21:19 -0400 Subject: [PATCH 036/790] change pathvars variable from site to siteid and make necessary changes in controller --- plugins/pencilblue/controllers/admin/plugins/manage_plugins.js | 2 +- plugins/pencilblue/controllers/admin/plugins/plugin_settings.js | 2 +- plugins/pencilblue/controllers/api/plugins/plugin_api.js | 2 +- plugins/pencilblue/include/routes.js | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/pencilblue/controllers/admin/plugins/manage_plugins.js b/plugins/pencilblue/controllers/admin/plugins/manage_plugins.js index faae0ffab..ea1badf79 100755 --- a/plugins/pencilblue/controllers/admin/plugins/manage_plugins.js +++ b/plugins/pencilblue/controllers/admin/plugins/manage_plugins.js @@ -38,7 +38,7 @@ module.exports = function(pb) { ManagePlugins.prototype.render = function(cb) { var self = this; - var site = self.pathVars.site; + var site = self.pathVars.siteid; //get the data var pluginService = new pb.PluginService(site); diff --git a/plugins/pencilblue/controllers/admin/plugins/plugin_settings.js b/plugins/pencilblue/controllers/admin/plugins/plugin_settings.js index 752dd4536..1d8d6d0a4 100755 --- a/plugins/pencilblue/controllers/admin/plugins/plugin_settings.js +++ b/plugins/pencilblue/controllers/admin/plugins/plugin_settings.js @@ -339,7 +339,7 @@ module.exports = function(pb) { }; PluginSettingsFormController.prototype.getSite = function () { - return this.pathVars.site; + return this.pathVars.siteid; }; //register admin sub-nav diff --git a/plugins/pencilblue/controllers/api/plugins/plugin_api.js b/plugins/pencilblue/controllers/api/plugins/plugin_api.js index 6414cfc90..f56271d4c 100755 --- a/plugins/pencilblue/controllers/api/plugins/plugin_api.js +++ b/plugins/pencilblue/controllers/api/plugins/plugin_api.js @@ -74,7 +74,7 @@ module.exports = function(pb) { PluginApiController.prototype.render = function(cb) { var action = this.pathVars.action; var identifier = this.pathVars.id; - this.site = this.pathVars.site || GLOBAL_SITE; + this.site = this.pathVars.siteid || GLOBAL_SITE; this.pluginService = new pb.PluginService(this.site); //validate action diff --git a/plugins/pencilblue/include/routes.js b/plugins/pencilblue/include/routes.js index 8cf15a912..ee00eabee 100644 --- a/plugins/pencilblue/include/routes.js +++ b/plugins/pencilblue/include/routes.js @@ -797,7 +797,7 @@ module.exports = function Routes(pb){ }, { method: 'post', - path: "/api/:site/plugins/:action/:id", + path: "/api/:siteid/plugins/:action/:id", auth_required: true, access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'api', 'plugins', 'plugin_api.js'), From c230b41367acc459657d06f36a89b21229b14082 Mon Sep 17 00:00:00 2001 From: Andrew Monroe Date: Mon, 4 May 2015 12:58:12 -0400 Subject: [PATCH 037/790] consolidate api routes --- plugins/pencilblue/include/multisite_admin_routes.js | 10 +--------- plugins/pencilblue/include/routes.js | 8 -------- 2 files changed, 1 insertion(+), 17 deletions(-) diff --git a/plugins/pencilblue/include/multisite_admin_routes.js b/plugins/pencilblue/include/multisite_admin_routes.js index 8248b270f..9813d51de 100644 --- a/plugins/pencilblue/include/multisite_admin_routes.js +++ b/plugins/pencilblue/include/multisite_admin_routes.js @@ -508,15 +508,7 @@ module.exports = function Routes(pb){ }, { method: 'post', - path: "/api/plugins/:action/:id", - auth_required: true, - access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'api', 'plugins', 'plugin_api.js'), - content_type: 'application/json' - }, - { - method: 'post', - path: "/api/plugins/:action/:id/:site", + path: "/api/:siteid/plugins/:action/:id/", auth_required: true, access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'api', 'plugins', 'plugin_api.js'), diff --git a/plugins/pencilblue/include/routes.js b/plugins/pencilblue/include/routes.js index ee00eabee..93a08850f 100644 --- a/plugins/pencilblue/include/routes.js +++ b/plugins/pencilblue/include/routes.js @@ -795,14 +795,6 @@ module.exports = function Routes(pb){ controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'api', 'plugins', 'plugin_api.js'), content_type: 'application/json' }, - { - method: 'post', - path: "/api/:siteid/plugins/:action/:id", - auth_required: true, - access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'api', 'plugins', 'plugin_api.js'), - content_type: 'application/json' - }, // THEMES { From 5224d498f9ca2796b42ff5e93ee2f28682995b20 Mon Sep 17 00:00:00 2001 From: Christina Chatham Date: Mon, 4 May 2015 13:36:50 -0400 Subject: [PATCH 038/790] Add site handling for the plugin details page. --- .../pencilblue/controllers/admin/plugins/plugin_details.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/plugins/pencilblue/controllers/admin/plugins/plugin_details.js b/plugins/pencilblue/controllers/admin/plugins/plugin_details.js index 5caead032..408f21d0d 100755 --- a/plugins/pencilblue/controllers/admin/plugins/plugin_details.js +++ b/plugins/pencilblue/controllers/admin/plugins/plugin_details.js @@ -78,15 +78,16 @@ module.exports = function(pb) { */ PluginDetailsViewController.prototype.getDetails = function(puid, cb) { var self = this; + var siteId = self.pathVars.siteid ? self.pathVars.siteid : pb.SiteService.GLOBAL_SITE; - var pluginService = new pb.PluginService(); - pluginService.getPlugin(puid, function(err, plugin) { + var pluginService = new pb.PluginService(siteId); + pluginService.getPluginBySite(puid, function(err, plugin) { if (util.isError(err)) { cb(err, plugin); return; } - if (plugin) { + if (plugin && plugin.site === siteId) { var obj = { details: plugin, status: self.ls.get(PluginService.isActivePlugin(plugin.uid) ? 'ACTIVE' : 'INACTIVE') From 5868192a82bad1be7c36f9e8a11e5a53e60ec6e0 Mon Sep 17 00:00:00 2001 From: Eugene Chang Date: Mon, 4 May 2015 13:37:39 -0400 Subject: [PATCH 039/790] Refactoring plugin MT to have a centralized place to get the site, making sure pb.config.multisite act like a master switch. --- include/service/entities/site_service.js | 20 +++++++++++++++++++ .../admin/plugins/manage_plugins.js | 5 +++-- .../admin/plugins/plugin_settings.js | 14 ++++++++----- .../controllers/api/plugins/plugin_api.js | 2 +- .../angular/admin/plugins/manage_plugins.html | 9 ++------- .../admin/plugins/plugin_settings.html | 4 ++-- 6 files changed, 37 insertions(+), 17 deletions(-) diff --git a/include/service/entities/site_service.js b/include/service/entities/site_service.js index 2889c5c9b..8409d3404 100644 --- a/include/service/entities/site_service.js +++ b/include/service/entities/site_service.js @@ -248,5 +248,25 @@ module.exports = function SiteServiceModule(pb) { commandService.registerForType('activate_site' , SiteService.onDeactivateSiteCommandReceived); }; + /** + * Central place to get the current site + * + * @param pathVars + * @returns {string} empty string if multisite is not enabled; SiteService.GLOBAL_SITE if not specified, or siteid otherwise + */ + SiteService.getCurrentSite = function(pathVars) { + return pb.config.multisite ? + (pathVars.siteid || SiteService.GLOBAL_SITE) + : ''; + }; + + /** + * Gets the current site prefix based on pathVars; this is equivalent to getCurrentSite with a leading slash + * @param pathVars + */ + SiteService.getCurrentSitePrefix = function(pathVars) { + return '/' + SiteService.getCurrentSite(pathVars); + }; + return SiteService; }; diff --git a/plugins/pencilblue/controllers/admin/plugins/manage_plugins.js b/plugins/pencilblue/controllers/admin/plugins/manage_plugins.js index ea1badf79..609b582eb 100755 --- a/plugins/pencilblue/controllers/admin/plugins/manage_plugins.js +++ b/plugins/pencilblue/controllers/admin/plugins/manage_plugins.js @@ -38,7 +38,8 @@ module.exports = function(pb) { ManagePlugins.prototype.render = function(cb) { var self = this; - var site = self.pathVars.siteid; + var site = pb.SiteService.getCurrentSite(self.pathVars); + var prefix = pb.SiteService.getCurrentSitePrefix(self.pathVars); //get the data var pluginService = new pb.PluginService(site); @@ -55,7 +56,7 @@ module.exports = function(pb) { installedPlugins: map.active, inactivePlugins: map.inactive, availablePlugins: map.available, - siteUid: site + sitePrefix: prefix }); //load the template diff --git a/plugins/pencilblue/controllers/admin/plugins/plugin_settings.js b/plugins/pencilblue/controllers/admin/plugins/plugin_settings.js index 1d8d6d0a4..6e2d0dfbd 100755 --- a/plugins/pencilblue/controllers/admin/plugins/plugin_settings.js +++ b/plugins/pencilblue/controllers/admin/plugins/plugin_settings.js @@ -41,13 +41,13 @@ module.exports = function(pb) { //statics var SUB_NAV_KEY = 'plugin_settings'; - PluginSettingsFormController.prototype.initialzePluginService = function initialzePluginService() { + PluginSettingsFormController.prototype.initializePluginService = function initializePluginService() { this.pluginService = new pb.PluginService(this.getSite()); }; PluginSettingsFormController.prototype.get = function(cb) { var self = this;console.log(this.constructor.name); - self.initialzePluginService(); + self.initializePluginService(); var uid = this.pathVars.id; this.pluginService.getPluginBySite(uid, function(err, plugin) { @@ -109,7 +109,7 @@ module.exports = function(pb) { settings: clone, pluginUID: uid, type: data.settingType, - siteUid: self.getSite() + sitePrefix: self.getSitePrefix() }); //render page @@ -126,7 +126,7 @@ module.exports = function(pb) { var self = this;console.log(this.constructor.name); var post = this.body; - self.initialzePluginService(); + self.initializePluginService(); //retrieve settings var uid = this.pathVars.id; self.getSettings(uid, function(err, settings) {console.log(settings); @@ -339,9 +339,13 @@ module.exports = function(pb) { }; PluginSettingsFormController.prototype.getSite = function () { - return this.pathVars.siteid; + return pb.SiteService.getCurrentSite(this.pathVars); }; + PluginSettingsFormController.prototype.getSitePrefix = function getSitePrefix() { + return pb.SiteService.getCurrentSitePrefix(this.pathVars); + }; + //register admin sub-nav pb.AdminSubnavService.registerFor(SUB_NAV_KEY, PluginSettingsFormController.geSubNavItems); diff --git a/plugins/pencilblue/controllers/api/plugins/plugin_api.js b/plugins/pencilblue/controllers/api/plugins/plugin_api.js index f56271d4c..bbf83a0bb 100755 --- a/plugins/pencilblue/controllers/api/plugins/plugin_api.js +++ b/plugins/pencilblue/controllers/api/plugins/plugin_api.js @@ -74,7 +74,7 @@ module.exports = function(pb) { PluginApiController.prototype.render = function(cb) { var action = this.pathVars.action; var identifier = this.pathVars.id; - this.site = this.pathVars.siteid || GLOBAL_SITE; + this.site = pb.SiteService.getCurrentSite(this.pathVars); this.pluginService = new pb.PluginService(this.site); //validate action diff --git a/plugins/pencilblue/templates/angular/admin/plugins/manage_plugins.html b/plugins/pencilblue/templates/angular/admin/plugins/manage_plugins.html index 87bb1ae06..e139609a0 100644 --- a/plugins/pencilblue/templates/angular/admin/plugins/manage_plugins.html +++ b/plugins/pencilblue/templates/angular/admin/plugins/manage_plugins.html @@ -3,11 +3,7 @@ .controller('PencilBlueController', function($scope, $http, $window) { ^angular_objects^ - $scope.getSiteAwarePrefix = function (prefix) { - return $scope.siteUid ? '/' + prefix + '/' + $scope.siteUid : '/' + prefix; - }; - - $scope.adminPrefix = $scope.getSiteAwarePrefix('admin'); + $scope.adminPrefix = '/admin' + $scope.sitePrefix; $scope.pluginAction = function(actionType, plugin) { $scope.actionPlugin = plugin; @@ -23,8 +19,7 @@ successCb = $scope.onInstallOrUninstallComplete; break; } - var prefix = $scope.getSiteAwarePrefix('api'); - $http.post(prefix +"/plugins/" + actionType + "/" + encodeURIComponent(plugin.uid)) + $http.post("/api" + $scope.sitePrefix +"/plugins/" + actionType + "/" + encodeURIComponent(plugin.uid)) .success(function(result) { successCb(result); }) diff --git a/plugins/pencilblue/templates/angular/admin/plugins/plugin_settings.html b/plugins/pencilblue/templates/angular/admin/plugins/plugin_settings.html index b5844822b..45281685d 100644 --- a/plugins/pencilblue/templates/angular/admin/plugins/plugin_settings.html +++ b/plugins/pencilblue/templates/angular/admin/plugins/plugin_settings.html @@ -11,8 +11,8 @@ settingsObject[$scope.settings[i].name] = $scope.settings[i].value; } - var prefix = $scope.siteUid ? '/admin/' + $scope.siteUid + '/' : '/admin/'; - $http.post(prefix + $scope.type + '/' + $scope.pluginUID + '/settings', settingsObject) + var prefix = '/admin' + $scope.sitePrefix; + $http.post(prefix + '/' + $scope.type + '/' + $scope.pluginUID + '/settings', settingsObject) .success(function(result) { $scope.successMessage = result.message; $scope.saving = false; From 7297bf83a04240b4d63c2b43a2482b284368afe2 Mon Sep 17 00:00:00 2001 From: Andrew Monroe Date: Mon, 4 May 2015 13:51:22 -0400 Subject: [PATCH 040/790] handle no session --- include/admin_navigation.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/admin_navigation.js b/include/admin_navigation.js index beed5804e..595dba9a6 100755 --- a/include/admin_navigation.js +++ b/include/admin_navigation.js @@ -278,7 +278,7 @@ module.exports = function AdminNavigationModule(pb) { var i; var navigation = []; var multiSiteAdditions = getMultiSiteNavigation(); - var defaultNavigation = getDefaultNavigation(session.adminSiteId); + var defaultNavigation = getDefaultNavigation(session ? session.adminSiteId : null); var additions = getAdditions(); var childrenAdditions = getChildrenAdditions(); From 5302f9ceca4fb889dbc18addc6773e0a4f5635aa Mon Sep 17 00:00:00 2001 From: Eugene Chang Date: Mon, 4 May 2015 13:51:38 -0400 Subject: [PATCH 041/790] Fixing prefix --- include/service/entities/site_service.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/include/service/entities/site_service.js b/include/service/entities/site_service.js index 8409d3404..e61f5cd46 100644 --- a/include/service/entities/site_service.js +++ b/include/service/entities/site_service.js @@ -261,11 +261,12 @@ module.exports = function SiteServiceModule(pb) { }; /** - * Gets the current site prefix based on pathVars; this is equivalent to getCurrentSite with a leading slash + * Gets the current site prefix based on pathVars; this is equivalent to getCurrentSite with a leading slash if site exists, or empty string if not * @param pathVars */ SiteService.getCurrentSitePrefix = function(pathVars) { - return '/' + SiteService.getCurrentSite(pathVars); + var site = SiteService.getCurrentSite(pathVars); + return site ? '/' + site : ''; }; return SiteService; From 49d39e95f4a4a8985fea284618fa37c2cf341b6d Mon Sep 17 00:00:00 2001 From: Eugene Chang Date: Mon, 4 May 2015 14:48:33 -0400 Subject: [PATCH 042/790] Updating SiteService to reduce coupling and conforming with how site is processed in PluginService --- include/service/entities/site_service.js | 28 +++++++++++-------- .../admin/plugins/manage_plugins.js | 4 +-- .../admin/plugins/plugin_settings.js | 8 +++--- .../controllers/api/plugins/plugin_api.js | 2 +- 4 files changed, 24 insertions(+), 18 deletions(-) diff --git a/include/service/entities/site_service.js b/include/service/entities/site_service.js index e61f5cd46..590ae215a 100644 --- a/include/service/entities/site_service.js +++ b/include/service/entities/site_service.js @@ -251,22 +251,28 @@ module.exports = function SiteServiceModule(pb) { /** * Central place to get the current site * - * @param pathVars - * @returns {string} empty string if multisite is not enabled; SiteService.GLOBAL_SITE if not specified, or siteid otherwise + * @param siteid + * @returns {string} SiteService.GLOBAL_SITE if not specified, or siteid otherwise */ - SiteService.getCurrentSite = function(pathVars) { - return pb.config.multisite ? - (pathVars.siteid || SiteService.GLOBAL_SITE) - : ''; + SiteService.getCurrentSite = function (siteid) { + return siteid || SiteService.GLOBAL_SITE; }; /** - * Gets the current site prefix based on pathVars; this is equivalent to getCurrentSite with a leading slash if site exists, or empty string if not - * @param pathVars + * Gets the current site prefix based on site (the return value of getCurrentSite) + * this is used as an url fragment, and equal to slash + site if multisite is on, or empty if it's off; + * used for '/admin' + prefix so controllers (both node and angular) can generate urls conforming to + * multitenant and single tenant setups + * @param site */ - SiteService.getCurrentSitePrefix = function(pathVars) { - var site = SiteService.getCurrentSite(pathVars); - return site ? '/' + site : ''; + SiteService.getCurrentSitePrefix = function (site) { + if (!pb.config.multisite) { + return ''; + } + if (!site) { + throw new Error("Site is empty in getCurrentSitePrefix when it never should be"); + } + return '/' + site; }; return SiteService; diff --git a/plugins/pencilblue/controllers/admin/plugins/manage_plugins.js b/plugins/pencilblue/controllers/admin/plugins/manage_plugins.js index 609b582eb..b5486c90d 100755 --- a/plugins/pencilblue/controllers/admin/plugins/manage_plugins.js +++ b/plugins/pencilblue/controllers/admin/plugins/manage_plugins.js @@ -38,8 +38,8 @@ module.exports = function(pb) { ManagePlugins.prototype.render = function(cb) { var self = this; - var site = pb.SiteService.getCurrentSite(self.pathVars); - var prefix = pb.SiteService.getCurrentSitePrefix(self.pathVars); + var site = pb.SiteService.getCurrentSite(self.pathVars.siteid); + var prefix = pb.SiteService.getCurrentSitePrefix(site); //get the data var pluginService = new pb.PluginService(site); diff --git a/plugins/pencilblue/controllers/admin/plugins/plugin_settings.js b/plugins/pencilblue/controllers/admin/plugins/plugin_settings.js index 6e2d0dfbd..564db5ae4 100755 --- a/plugins/pencilblue/controllers/admin/plugins/plugin_settings.js +++ b/plugins/pencilblue/controllers/admin/plugins/plugin_settings.js @@ -109,7 +109,7 @@ module.exports = function(pb) { settings: clone, pluginUID: uid, type: data.settingType, - sitePrefix: self.getSitePrefix() + sitePrefix: self.getSitePrefix(self.getSite()) }); //render page @@ -339,11 +339,11 @@ module.exports = function(pb) { }; PluginSettingsFormController.prototype.getSite = function () { - return pb.SiteService.getCurrentSite(this.pathVars); + return pb.SiteService.getCurrentSite(this.pathVars.siteid); }; - PluginSettingsFormController.prototype.getSitePrefix = function getSitePrefix() { - return pb.SiteService.getCurrentSitePrefix(this.pathVars); + PluginSettingsFormController.prototype.getSitePrefix = function getSitePrefix(site) { + return pb.SiteService.getCurrentSitePrefix(site); }; //register admin sub-nav diff --git a/plugins/pencilblue/controllers/api/plugins/plugin_api.js b/plugins/pencilblue/controllers/api/plugins/plugin_api.js index bbf83a0bb..963594548 100755 --- a/plugins/pencilblue/controllers/api/plugins/plugin_api.js +++ b/plugins/pencilblue/controllers/api/plugins/plugin_api.js @@ -74,7 +74,7 @@ module.exports = function(pb) { PluginApiController.prototype.render = function(cb) { var action = this.pathVars.action; var identifier = this.pathVars.id; - this.site = pb.SiteService.getCurrentSite(this.pathVars); + this.site = pb.SiteService.getCurrentSite(this.pathVars.siteid); this.pluginService = new pb.PluginService(this.site); //validate action From 8601e29e8f0e7a24c998275e9a77e96236d1959b Mon Sep 17 00:00:00 2001 From: btidwell Date: Mon, 4 May 2015 15:02:59 -0400 Subject: [PATCH 043/790] Add current site indicator button on manage plugins page --- include/service/entities/site_service.js | 13 ++++++- .../admin/plugins/manage_plugins.js | 36 ++++++++++--------- .../templates/admin/elements/sub_nav.html | 5 +++ 3 files changed, 36 insertions(+), 18 deletions(-) diff --git a/include/service/entities/site_service.js b/include/service/entities/site_service.js index 2889c5c9b..0de93fc77 100644 --- a/include/service/entities/site_service.js +++ b/include/service/entities/site_service.js @@ -46,6 +46,17 @@ module.exports = function SiteServiceModule(pb) { }); }; + SiteService.prototype.getSiteNameByUid = function(uid, cb) { + var dao = new pb.DAO(); + dao.q(SITE_COLL, {select: pb.DAO.SELECT_ALL, where: {uid: uid} }, function(err, result) { + var siteName = SiteService.GLOBAL_SITE; + if(result.length > 0) { + siteName = result[0].displayName; + } + cb(siteName); + }); + }; + /** * Checks to see if a proposed site display name or hostname is already in the system * @@ -185,7 +196,7 @@ module.exports = function SiteServiceModule(pb) { } else { util.forEach(results, function(site) { pb.RequestHandler.loadSite(site); - }) + }); cb(err,true); } }); diff --git a/plugins/pencilblue/controllers/admin/plugins/manage_plugins.js b/plugins/pencilblue/controllers/admin/plugins/manage_plugins.js index faae0ffab..5ecce907e 100755 --- a/plugins/pencilblue/controllers/admin/plugins/manage_plugins.js +++ b/plugins/pencilblue/controllers/admin/plugins/manage_plugins.js @@ -38,30 +38,32 @@ module.exports = function(pb) { ManagePlugins.prototype.render = function(cb) { var self = this; - var site = self.pathVars.site; + var siteid = self.pathVars.siteid; //get the data - var pluginService = new pb.PluginService(site); + var pluginService = new pb.PluginService(siteid); pluginService.getPluginMap(function(err, map) { if (util.isError(err)) { self.reqHandler.serveError(err); return; } - - //setup angular - var angularObjects = pb.ClientJs.getAngularObjects({ - navigation: pb.AdminNavigation.get(self.session, ['plugins', 'manage'], self.ls), - pills: pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls), - installedPlugins: map.active, - inactivePlugins: map.inactive, - availablePlugins: map.available, - siteUid: site - }); - - //load the template - self.ts.registerLocal('angular_objects', new pb.TemplateValue(angularObjects, false)); - self.ts.load('/admin/plugins/manage_plugins', function(err, result) { - cb({content: result}); + var siteService = new pb.SiteService(); + siteService.getSiteNameByUid(siteid, function(siteName) { + //setup angular + var angularObjects = pb.ClientJs.getAngularObjects({ + navigation: pb.AdminNavigation.get(self.session, ['plugins', 'manage'], self.ls), + pills: pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls), + installedPlugins: map.active, + inactivePlugins: map.inactive, + availablePlugins: map.available, + siteUid: siteid, + siteName: siteName + }); + //load the template + self.ts.registerLocal('angular_objects', new pb.TemplateValue(angularObjects, false)); + self.ts.load('/admin/plugins/manage_plugins', function(err, result) { + cb({content: result}); + }); }); }); }; diff --git a/plugins/pencilblue/templates/admin/elements/sub_nav.html b/plugins/pencilblue/templates/admin/elements/sub_nav.html index 893240184..904d106bf 100755 --- a/plugins/pencilblue/templates/admin/elements/sub_nav.html +++ b/plugins/pencilblue/templates/admin/elements/sub_nav.html @@ -4,4 +4,9 @@   + + +
From c23a7f61ad2d15af4317744c612ff233751c314f Mon Sep 17 00:00:00 2001 From: btidwell Date: Mon, 4 May 2015 15:07:39 -0400 Subject: [PATCH 044/790] add check for not undefined/null result --- include/service/entities/site_service.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/service/entities/site_service.js b/include/service/entities/site_service.js index 0de93fc77..923cdf494 100644 --- a/include/service/entities/site_service.js +++ b/include/service/entities/site_service.js @@ -50,7 +50,7 @@ module.exports = function SiteServiceModule(pb) { var dao = new pb.DAO(); dao.q(SITE_COLL, {select: pb.DAO.SELECT_ALL, where: {uid: uid} }, function(err, result) { var siteName = SiteService.GLOBAL_SITE; - if(result.length > 0) { + if(result && result.length > 0) { siteName = result[0].displayName; } cb(siteName); From bf0fcf997d4737450c6ecbbe0a5a9ec7dfb370bf Mon Sep 17 00:00:00 2001 From: btidwell Date: Mon, 4 May 2015 15:18:56 -0400 Subject: [PATCH 045/790] Default to empty string and hide indicator. Log error if query fails --- include/service/entities/site_service.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/include/service/entities/site_service.js b/include/service/entities/site_service.js index 923cdf494..52a541076 100644 --- a/include/service/entities/site_service.js +++ b/include/service/entities/site_service.js @@ -49,10 +49,14 @@ module.exports = function SiteServiceModule(pb) { SiteService.prototype.getSiteNameByUid = function(uid, cb) { var dao = new pb.DAO(); dao.q(SITE_COLL, {select: pb.DAO.SELECT_ALL, where: {uid: uid} }, function(err, result) { - var siteName = SiteService.GLOBAL_SITE; - if(result && result.length > 0) { + var siteName = ''; + + if(pb.util.isError(err)) { + pb.log.error(err); + }else if(result && result.length > 0) { siteName = result[0].displayName; } + cb(siteName); }); }; From 40d88958d9305ae525029744f3c5b96284680548 Mon Sep 17 00:00:00 2001 From: btidwell Date: Mon, 4 May 2015 15:34:18 -0400 Subject: [PATCH 046/790] Default to global if no 'uid' or if 'global' is provided in url. --- include/service/entities/site_service.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/service/entities/site_service.js b/include/service/entities/site_service.js index 52a541076..5637679af 100644 --- a/include/service/entities/site_service.js +++ b/include/service/entities/site_service.js @@ -49,14 +49,14 @@ module.exports = function SiteServiceModule(pb) { SiteService.prototype.getSiteNameByUid = function(uid, cb) { var dao = new pb.DAO(); dao.q(SITE_COLL, {select: pb.DAO.SELECT_ALL, where: {uid: uid} }, function(err, result) { - var siteName = ''; + var siteName = (!uid || uid === SiteService.GLOBAL_SITE) ? 'global' : ''; if(pb.util.isError(err)) { pb.log.error(err); }else if(result && result.length > 0) { siteName = result[0].displayName; } - + cb(siteName); }); }; From dfc20002f7d07abd17df0c2beba3f7b008132032 Mon Sep 17 00:00:00 2001 From: Eugene Chang Date: Mon, 4 May 2015 15:46:37 -0400 Subject: [PATCH 047/790] Updating nav for plugin settings. --- .../controllers/admin/plugins/plugin_settings.js | 12 ++++++------ .../templates/admin/plugins/plugin_settings.html | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/plugins/pencilblue/controllers/admin/plugins/plugin_settings.js b/plugins/pencilblue/controllers/admin/plugins/plugin_settings.js index 564db5ae4..5dc4e909b 100755 --- a/plugins/pencilblue/controllers/admin/plugins/plugin_settings.js +++ b/plugins/pencilblue/controllers/admin/plugins/plugin_settings.js @@ -100,7 +100,8 @@ module.exports = function(pb) { //setup angular var data = { plugin: plugin, - settingType: self.getType() + settingType: self.getType(), + sitePrefix: self.getSitePrefix(self.getSite()) }; var angularObjects = pb.ClientJs.getAngularObjects({ pills: pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, null, data), @@ -109,7 +110,7 @@ module.exports = function(pb) { settings: clone, pluginUID: uid, type: data.settingType, - sitePrefix: self.getSitePrefix(self.getSite()) + sitePrefix: data.sitePrefix }); //render page @@ -228,17 +229,16 @@ module.exports = function(pb) { }; /** - * @static * @method render * */ - PluginSettingsFormController.geSubNavItems = function(key, ls, data) { + PluginSettingsFormController.getSubNavItems = function(key, ls, data) { return [ { name: 'manage_plugins', title: data.plugin.name + ' ' + ls.get('SETTINGS'), icon: 'chevron-left', - href: '/admin/' + data.settingType + href: '/admin' + data.sitePrefix + '/' + data.settingType } ]; }; @@ -347,7 +347,7 @@ module.exports = function(pb) { }; //register admin sub-nav - pb.AdminSubnavService.registerFor(SUB_NAV_KEY, PluginSettingsFormController.geSubNavItems); + pb.AdminSubnavService.registerFor(SUB_NAV_KEY, PluginSettingsFormController.getSubNavItems); //exports return PluginSettingsFormController; diff --git a/plugins/pencilblue/templates/admin/plugins/plugin_settings.html b/plugins/pencilblue/templates/admin/plugins/plugin_settings.html index ba0535e7c..7c32dfd7d 100755 --- a/plugins/pencilblue/templates/admin/plugins/plugin_settings.html +++ b/plugins/pencilblue/templates/admin/plugins/plugin_settings.html @@ -17,7 +17,7 @@ - +  ^loc_CANCEL^ ^tmp_admin=elements=save_button^ From 6dda6a1f9015223832d918d7a9633093ee2aa477 Mon Sep 17 00:00:00 2001 From: Christina Chatham Date: Mon, 4 May 2015 15:57:16 -0400 Subject: [PATCH 048/790] Changes are less redundant now and added site id to active plugin. --- .../pencilblue/controllers/admin/plugins/plugin_details.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/pencilblue/controllers/admin/plugins/plugin_details.js b/plugins/pencilblue/controllers/admin/plugins/plugin_details.js index 408f21d0d..a0a285734 100755 --- a/plugins/pencilblue/controllers/admin/plugins/plugin_details.js +++ b/plugins/pencilblue/controllers/admin/plugins/plugin_details.js @@ -87,10 +87,10 @@ module.exports = function(pb) { return; } - if (plugin && plugin.site === siteId) { + if (plugin) { var obj = { details: plugin, - status: self.ls.get(PluginService.isActivePlugin(plugin.uid) ? 'ACTIVE' : 'INACTIVE') + status: self.ls.get(PluginService.isActivePlugin(plugin.uid, siteId) ? 'ACTIVE' : 'INACTIVE') }; cb(err, obj); return; From 334226cf547c3ef8d5e28eae6cb2785d596a07f7 Mon Sep 17 00:00:00 2001 From: btidwell Date: Mon, 4 May 2015 16:15:25 -0400 Subject: [PATCH 049/790] check for config.multisite when building admin nav --- include/admin_navigation.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/admin_navigation.js b/include/admin_navigation.js index 595dba9a6..f99b935ff 100755 --- a/include/admin_navigation.js +++ b/include/admin_navigation.js @@ -80,7 +80,7 @@ module.exports = function AdminNavigationModule(pb) { */ function getDefaultNavigation(adminSiteId) { var adminPath = '/admin' - if(adminSiteId) { + if(adminSiteId && pb.config.multisite) { adminPath = '/admin/' + adminSiteId; } return util.clone(Object.freeze([ From 4ad1bfd3e1439b1aa239793dcad1e373d7e0aaea Mon Sep 17 00:00:00 2001 From: Christina Chatham Date: Tue, 5 May 2015 11:08:44 -0400 Subject: [PATCH 050/790] Have plugin details links on manage plugin page use site id --- .../templates/admin/plugins/manage_plugins.html | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/pencilblue/templates/admin/plugins/manage_plugins.html b/plugins/pencilblue/templates/admin/plugins/manage_plugins.html index 9d9bfed2a..0abb10cd3 100755 --- a/plugins/pencilblue/templates/admin/plugins/manage_plugins.html +++ b/plugins/pencilblue/templates/admin/plugins/manage_plugins.html @@ -18,7 +18,7 @@ - + @@ -53,12 +53,12 @@ - +
-  ^loc_SETTINGS^ +  ^loc_SETTINGS^ @@ -91,7 +91,7 @@ - + From e54c78e8bed605ae680f3fd2cdd613dfe48bb7e9 Mon Sep 17 00:00:00 2001 From: Eugene Chang Date: Tue, 5 May 2015 11:56:25 -0400 Subject: [PATCH 051/790] Updating manage themes/theme settings to be site aware. --- include/repository/plugin_repository.js | 2 +- include/service/entities/plugin_service.js | 2 +- .../entities/plugin_setting_service.js | 5 +++-- .../controllers/admin/themes/manage_themes.js | 22 +++++++++++++------ .../admin/themes/theme_settings.js | 1 - .../templates/admin/themes/manage_themes.html | 4 ++-- .../angular/admin/themes/manage_themes.html | 2 +- 7 files changed, 23 insertions(+), 15 deletions(-) diff --git a/include/repository/plugin_repository.js b/include/repository/plugin_repository.js index afa1845b7..3f87b5c19 100644 --- a/include/repository/plugin_repository.js +++ b/include/repository/plugin_repository.js @@ -47,7 +47,7 @@ module.exports = function PluginRepositoryModule(pb) { var where = { $and: [ hasATheme, belongsToSite ] }; - dao.q(PLUGIN_COLL, where, cb); + dao.q(PLUGIN_COLL, {where: where}, cb); }; publicAPI.loadPluginOwnedByThisSite = function(pluginID, site, cb) { diff --git a/include/service/entities/plugin_service.js b/include/service/entities/plugin_service.js index 1aec8cee3..9fd58a096 100755 --- a/include/service/entities/plugin_service.js +++ b/include/service/entities/plugin_service.js @@ -326,7 +326,7 @@ module.exports = function PluginServiceModule(pb) { */ PluginService.prototype.getThemeSettings = function(pluginName, cb) { var settingService = getPluginSettingService(this); - settingService.getThemeSettings(pluginName, cb); + settingService.getThemeSettingsBySite(pluginName, cb); }; /** diff --git a/include/service/entities/plugin_setting_service.js b/include/service/entities/plugin_setting_service.js index 1089bc36f..62e687046 100644 --- a/include/service/entities/plugin_setting_service.js +++ b/include/service/entities/plugin_setting_service.js @@ -424,6 +424,7 @@ module.exports = function PluginSettingServiceModule(pb) { plugin_id: plugin[pb.DAO.getIdField()].toString(), settings: details.theme.settings }; + baseDoc[SITE_FIELD] = self.site; var settings = pb.DocumentCreator.create('theme_settings', baseDoc); //save it @@ -484,14 +485,14 @@ module.exports = function PluginSettingServiceModule(pb) { function getAdminPluginSettingsService(self) { if(!self.adminPluginSettingsService) { - self.adminPluginSettingsService = genSettingsService('plugin_settings', this.caching.useMemory, this.caching.useCache, 'PluginSettingService', this.site, true); + self.adminPluginSettingsService = genSettingsService('plugin_settings', self.caching.useMemory, self.caching.useCache, 'PluginSettingService', this.site, true); } return self.adminPluginSettingsService; } function getAdminThemeSettingsService(self) { if(!self.adminThemeSettingsService) { - self.adminThemeSettingsService = genSettingsService('theme_settings', this.caching.useMemory, this.caching.useCache, 'ThemeSettingService', this.site); + self.adminThemeSettingsService = genSettingsService('theme_settings', self.caching.useMemory, self.caching.useCache, 'ThemeSettingService', this.site); } return self.adminThemeSettingsService; } diff --git a/plugins/pencilblue/controllers/admin/themes/manage_themes.js b/plugins/pencilblue/controllers/admin/themes/manage_themes.js index 62de0c368..dd1da00e5 100755 --- a/plugins/pencilblue/controllers/admin/themes/manage_themes.js +++ b/plugins/pencilblue/controllers/admin/themes/manage_themes.js @@ -36,14 +36,17 @@ module.exports = function(pb) { var self = this; //get plugs with themes - var pluginService = new pb.PluginService(); - pluginService.getPluginsWithThemes(function(err, themes) { + var site = pb.SiteService.getCurrentSite(self.pathVars.siteid); + var sitePrefix = pb.SiteService.getCurrentSitePrefix(site); + var pluginService = new pb.PluginService(site); + pluginService.getPluginsWithThemesBySite(function (err, themes) { if (util.isError(err)) { throw result; } //get active theme - pb.settings.get('active_theme', function(err, activeTheme) { + var settings = pb.SettingServiceFactory.getService(pb.config.settings.use_memory, pb.config.settings.use_cache, this.site); + settings.get('active_theme', function(err, activeTheme) { if (util.isError(err)) { throw err; } @@ -56,7 +59,7 @@ module.exports = function(pb) { }); - pb.settings.get('site_logo', function(err, logo) { + settings.get('site_logo', function(err, logo) { if(util.isError(err)) { pb.log.error("ManageThemes: Failed to retrieve site logo: "+err.stack); } @@ -71,15 +74,20 @@ module.exports = function(pb) { } } + var subNavData = { + sitePrefix: sitePrefix + }; + //setup angular var angularObjects = pb.ClientJs.getAngularObjects({ navigation: pb.AdminNavigation.get(self.session, ['plugins', 'themes'], self.ls), - pills: pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls), + pills: pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, null, subNavData), tabs: self.getTabs(), themes: themes, options: options, siteLogo: siteLogo, - activeTheme: activeTheme + activeTheme: activeTheme, + sitePrefix: sitePrefix }); self.ts.registerLocal('image_title', ''); @@ -113,7 +121,7 @@ module.exports = function(pb) { name: 'manage_themes', title: ls.get('MANAGE_THEMES'), icon: 'refresh', - href: '/admin/themes' + href: '/admin' + data.sitePrefix + '/themes' } ]; }; diff --git a/plugins/pencilblue/controllers/admin/themes/theme_settings.js b/plugins/pencilblue/controllers/admin/themes/theme_settings.js index 761ba2dd5..ff7ef61d3 100755 --- a/plugins/pencilblue/controllers/admin/themes/theme_settings.js +++ b/plugins/pencilblue/controllers/admin/themes/theme_settings.js @@ -34,7 +34,6 @@ module.exports = function(pb) { * @property pluginService * @type {PluginService} */ - this.pluginService = new pb.PluginService(); } util.inherits(ThemeSettings, PluginSettingsFormController); diff --git a/plugins/pencilblue/templates/admin/themes/manage_themes.html b/plugins/pencilblue/templates/admin/themes/manage_themes.html index b674dfd0d..3f3ed0518 100755 --- a/plugins/pencilblue/templates/admin/themes/manage_themes.html +++ b/plugins/pencilblue/templates/admin/themes/manage_themes.html @@ -29,13 +29,13 @@ - +
-  ^loc_SETTINGS^ +  ^loc_SETTINGS^
diff --git a/plugins/pencilblue/templates/angular/admin/themes/manage_themes.html b/plugins/pencilblue/templates/angular/admin/themes/manage_themes.html index b395ba060..0366a9db4 100644 --- a/plugins/pencilblue/templates/angular/admin/themes/manage_themes.html +++ b/plugins/pencilblue/templates/angular/admin/themes/manage_themes.html @@ -21,7 +21,7 @@ $scope.consoleOutput = ''; $('#progress_modal').modal({}); - $http.post("/api/plugins/" + actionType + "/" + encodeURIComponent($scope.actionPlugin.uid)) + $http.post("/api" + $scope.sitePrefix + "/plugins/" + actionType + "/" + encodeURIComponent($scope.actionPlugin.uid)) .success(function(result) { $scope.onActionSuccess(result); }) From 9c78cd006452d7cb27efc0154636f9b53edb80fc Mon Sep 17 00:00:00 2001 From: Eugene Chang Date: Tue, 5 May 2015 12:35:43 -0400 Subject: [PATCH 052/790] Correcting the change made to getThemeSettings. Adding getThemeSettingsBySite to plugin service. --- include/service/entities/plugin_service.js | 11 +++++++++++ .../controllers/admin/themes/theme_settings.js | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/include/service/entities/plugin_service.js b/include/service/entities/plugin_service.js index 9fd58a096..1311a1cc2 100755 --- a/include/service/entities/plugin_service.js +++ b/include/service/entities/plugin_service.js @@ -325,6 +325,17 @@ module.exports = function PluginServiceModule(pb) { * @param cb A callback that provides two parameters: cb(err, settingsObject) */ PluginService.prototype.getThemeSettings = function(pluginName, cb) { + var settingService = getPluginSettingService(this); + settingService.getThemeSettings(pluginName, cb); + }; + + /** + * Retrieves the theme settings for the specified plugin only for the site set in the current plugin service + * + * @param pluginName + * @param cb + */ + PluginService.prototype.getThemeSettingsBySite = function (pluginName, cb) { var settingService = getPluginSettingService(this); settingService.getThemeSettingsBySite(pluginName, cb); }; diff --git a/plugins/pencilblue/controllers/admin/themes/theme_settings.js b/plugins/pencilblue/controllers/admin/themes/theme_settings.js index ff7ef61d3..29ec018aa 100755 --- a/plugins/pencilblue/controllers/admin/themes/theme_settings.js +++ b/plugins/pencilblue/controllers/admin/themes/theme_settings.js @@ -44,7 +44,7 @@ module.exports = function(pb) { * @param {Function} cb */ ThemeSettings.prototype.getSettings = function(uid, cb) { - this.pluginService.getThemeSettings(uid, cb); + this.pluginService.getThemeSettingsBySite(uid, cb); }; /** From fee1226f989f9f05efceec06212922d5c75700ef Mon Sep 17 00:00:00 2001 From: Eugene Chang Date: Tue, 5 May 2015 12:44:45 -0400 Subject: [PATCH 053/790] Specifying ng-href for the sitePrefix'd URL --- plugins/pencilblue/templates/admin/themes/manage_themes.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/pencilblue/templates/admin/themes/manage_themes.html b/plugins/pencilblue/templates/admin/themes/manage_themes.html index 3f3ed0518..4a9b55c84 100755 --- a/plugins/pencilblue/templates/admin/themes/manage_themes.html +++ b/plugins/pencilblue/templates/admin/themes/manage_themes.html @@ -35,7 +35,7 @@
-  ^loc_SETTINGS^ +  ^loc_SETTINGS^
From 70f67aa4765958abd0d292b33e681221519a4f59 Mon Sep 17 00:00:00 2001 From: Andrew Monroe Date: Tue, 5 May 2015 13:43:38 -0400 Subject: [PATCH 054/790] fix another where clause in plugin repository --- include/repository/plugin_repository.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/repository/plugin_repository.js b/include/repository/plugin_repository.js index 3f87b5c19..642ffc9a0 100644 --- a/include/repository/plugin_repository.js +++ b/include/repository/plugin_repository.js @@ -22,10 +22,10 @@ module.exports = function PluginRepositoryModule(pb) { }; var tasks = { sitePlugins: function(callback) { - dao.q(PLUGIN_COLL, siteWhere, callback); + dao.q(PLUGIN_COLL, {where: siteWhere}, callback); }, globalPlugins: function(callback) { - dao.q(PLUGIN_COLL, globalWhere, callback); + dao.q(PLUGIN_COLL, {where: globalWhere}, callback); } }; async.parallel(tasks, function(err, results) { From d8ba4d66d504ce374812023e32aa3049c196f918 Mon Sep 17 00:00:00 2001 From: andparker Date: Tue, 5 May 2015 13:47:37 -0400 Subject: [PATCH 055/790] Initial commit for site routing validation. --- include/service/entities/site_service.js | 29 +++++++++- .../admin/plugins/manage_plugins.js | 55 ++++++++++--------- 2 files changed, 56 insertions(+), 28 deletions(-) diff --git a/include/service/entities/site_service.js b/include/service/entities/site_service.js index b82a61eb1..e9b754812 100644 --- a/include/service/entities/site_service.js +++ b/include/service/entities/site_service.js @@ -22,12 +22,12 @@ module.exports = function SiteServiceModule(pb) { SiteService.prototype.getActiveSites = function(cb) { var dao = new pb.DAO(); dao.q(SITE_COLL, { select: pb.DAO.SELECT_ALL, where: {active: true} }, cb); - } + }; SiteService.prototype.getInactiveSites = function(cb) { var dao = new pb.DAO(); dao.q(SITE_COLL, {where: {active: false}}, cb); - } + }; SiteService.prototype.getSiteMap = function(cb) { var self = this; @@ -290,5 +290,30 @@ module.exports = function SiteServiceModule(pb) { return '/' + site; }; + /** + * Serves a 404 if the site in question does not exist + * @method error404IfSiteDoesNotExist + * @param {RequestHandler} requestHandler + * @param {String} uid + * @param {Function} cb Called if site does exist + */ + SiteService.error404IfSiteDoesNotExist = function(requestHandler, uid, cb) { + if (uid && !(uid === SiteService.GLOBAL_SITE)) { + var dao = new pb.DAO(); + dao.exists(SITE_COLL, {uid: uid}, function (err, exists) { + if (!exists || util.isError(err)) { + requestHandler.serve404(); + return; + } + else { + cb(); + } + }); + } + else { + cb(); + } + }; + return SiteService; }; diff --git a/plugins/pencilblue/controllers/admin/plugins/manage_plugins.js b/plugins/pencilblue/controllers/admin/plugins/manage_plugins.js index 7bae77fa1..9c25151a3 100755 --- a/plugins/pencilblue/controllers/admin/plugins/manage_plugins.js +++ b/plugins/pencilblue/controllers/admin/plugins/manage_plugins.js @@ -37,35 +37,38 @@ module.exports = function(pb) { ManagePlugins.prototype.render = function(cb) { var self = this; - var siteid = self.pathVars.siteid; var site = pb.SiteService.getCurrentSite(self.pathVars.siteid); - var prefix = pb.SiteService.getCurrentSitePrefix(site); - //get the data - var pluginService = new pb.PluginService(siteid); - pluginService.getPluginMap(function(err, map) { - if (util.isError(err)) { - self.reqHandler.serveError(err); - return; - } - var siteService = new pb.SiteService(); - siteService.getSiteNameByUid(siteid, function(siteName) { - //setup angular - var angularObjects = pb.ClientJs.getAngularObjects({ - navigation: pb.AdminNavigation.get(self.session, ['plugins', 'manage'], self.ls), - pills: pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls), - installedPlugins: map.active, - inactivePlugins: map.inactive, - availablePlugins: map.available, - sitePrefix: prefix, - siteUid: siteid, - siteName: siteName - }); - //load the template - self.ts.registerLocal('angular_objects', new pb.TemplateValue(angularObjects, false)); - self.ts.load('/admin/plugins/manage_plugins', function(err, result) { - cb({content: result}); + pb.SiteService.error404IfSiteDoesNotExist(self.reqHandler, site, function () { + + var prefix = pb.SiteService.getCurrentSitePrefix(site); + + //get the data + var pluginService = new pb.PluginService(siteid); + pluginService.getPluginMap(function(err, map) { + if (util.isError(err)) { + self.reqHandler.serveError(err); + return; + } + var siteService = new pb.SiteService(); + siteService.getSiteNameByUid(siteid, function(siteName) { + //setup angular + var angularObjects = pb.ClientJs.getAngularObjects({ + navigation: pb.AdminNavigation.get(self.session, ['plugins', 'manage'], self.ls), + pills: pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls), + installedPlugins: map.active, + inactivePlugins: map.inactive, + availablePlugins: map.available, + sitePrefix: prefix, + siteUid: siteid, + siteName: siteName + }); + //load the template + self.ts.registerLocal('angular_objects', new pb.TemplateValue(angularObjects, false)); + self.ts.load('/admin/plugins/manage_plugins', function(err, result) { + cb({content: result}); + }); }); }); }); From 33bc18e3e3339564296db6fcf3d32feb0dc6572c Mon Sep 17 00:00:00 2001 From: Andrew Monroe Date: Tue, 5 May 2015 13:50:25 -0400 Subject: [PATCH 056/790] changing this reference to self --- plugins/pencilblue/controllers/admin/themes/manage_themes.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/pencilblue/controllers/admin/themes/manage_themes.js b/plugins/pencilblue/controllers/admin/themes/manage_themes.js index dd1da00e5..8fae5330a 100755 --- a/plugins/pencilblue/controllers/admin/themes/manage_themes.js +++ b/plugins/pencilblue/controllers/admin/themes/manage_themes.js @@ -45,7 +45,7 @@ module.exports = function(pb) { } //get active theme - var settings = pb.SettingServiceFactory.getService(pb.config.settings.use_memory, pb.config.settings.use_cache, this.site); + var settings = pb.SettingServiceFactory.getService(pb.config.settings.use_memory, pb.config.settings.use_cache, self.site); settings.get('active_theme', function(err, activeTheme) { if (util.isError(err)) { throw err; From be3090e470a14dcf081d4230f9fe0e29e4b10d27 Mon Sep 17 00:00:00 2001 From: Eugene Chang Date: Tue, 5 May 2015 13:59:19 -0400 Subject: [PATCH 057/790] Adding @returns documentation --- include/service/entities/site_service.js | 1 + 1 file changed, 1 insertion(+) diff --git a/include/service/entities/site_service.js b/include/service/entities/site_service.js index b82a61eb1..a3c387e08 100644 --- a/include/service/entities/site_service.js +++ b/include/service/entities/site_service.js @@ -279,6 +279,7 @@ module.exports = function SiteServiceModule(pb) { * used for '/admin' + prefix so controllers (both node and angular) can generate urls conforming to * multitenant and single tenant setups * @param site + * @returns {string} /site if multisite is enabled, empty if not */ SiteService.getCurrentSitePrefix = function (site) { if (!pb.config.multisite) { From 46f5c7e89c3be441b5221e4516ca329a1ce6e1b2 Mon Sep 17 00:00:00 2001 From: btidwell Date: Tue, 5 May 2015 14:20:17 -0400 Subject: [PATCH 058/790] add site to pages and query pages by site --- .../controllers/admin/content/pages/manage_pages.js | 6 +++--- .../pencilblue/controllers/admin/content/pages/page_form.js | 3 +++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/plugins/pencilblue/controllers/admin/content/pages/manage_pages.js b/plugins/pencilblue/controllers/admin/content/pages/manage_pages.js index 27157726d..e2fc6ea4e 100755 --- a/plugins/pencilblue/controllers/admin/content/pages/manage_pages.js +++ b/plugins/pencilblue/controllers/admin/content/pages/manage_pages.js @@ -31,10 +31,10 @@ module.exports = function(pb) { ManagePages.prototype.render = function(cb) { var self = this; - + var siteid = pb.SiteService.getCurrentSite(self.pathVars.siteid); var opts = { select: pb.DAO.PROJECT_ALL, - where: pb.DAO.ANYWHERE, + where: {site: siteid}, order: {headline: pb.DAO.ASC} }; var dao = new pb.DAO(); @@ -43,7 +43,7 @@ module.exports = function(pb) { return self.reqHandler.serveError(err); } else if(pages.length === 0) { - return self.redirect('/admin/content/pages/new', cb); + return self.redirect('/admin' + pb.SiteService.getCurrentSitePrefix(siteid) + '/content/pages/new', cb); } pb.users.getAuthors(pages, function(err, pagesWithAuthor) { diff --git a/plugins/pencilblue/controllers/admin/content/pages/page_form.js b/plugins/pencilblue/controllers/admin/content/pages/page_form.js index 67ae7458f..3b4c937d7 100755 --- a/plugins/pencilblue/controllers/admin/content/pages/page_form.js +++ b/plugins/pencilblue/controllers/admin/content/pages/page_form.js @@ -84,6 +84,9 @@ module.exports = function(pb) { * */ PageFormController.prototype.getAngularObjects = function(tabs, data) { + if(pb.config.multisite && !data.page.site) { + data.page.site = this.pathVars.siteid || pb.SiteService.GLOBAL_SITE; + } if(data.page[pb.DAO.getIdField()]) { var media = []; var i, j; From 674344c567a2541beaddcaf59f1d3b0a5f0b159c Mon Sep 17 00:00:00 2001 From: btidwell Date: Tue, 5 May 2015 14:29:01 -0400 Subject: [PATCH 059/790] Use sanitization function for retrieving siteid on page_form --- plugins/pencilblue/controllers/admin/content/pages/page_form.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/pencilblue/controllers/admin/content/pages/page_form.js b/plugins/pencilblue/controllers/admin/content/pages/page_form.js index 3b4c937d7..0f2c4e182 100755 --- a/plugins/pencilblue/controllers/admin/content/pages/page_form.js +++ b/plugins/pencilblue/controllers/admin/content/pages/page_form.js @@ -85,7 +85,7 @@ module.exports = function(pb) { */ PageFormController.prototype.getAngularObjects = function(tabs, data) { if(pb.config.multisite && !data.page.site) { - data.page.site = this.pathVars.siteid || pb.SiteService.GLOBAL_SITE; + data.page.site = pb.SiteService.getCurrentSite(this.pathVars.siteid); } if(data.page[pb.DAO.getIdField()]) { var media = []; From 7c0d5b46a590e1c27f92014bacd1bcf4883a9794 Mon Sep 17 00:00:00 2001 From: btidwell Date: Tue, 5 May 2015 14:34:00 -0400 Subject: [PATCH 060/790] add site to article and query article by site --- .../controllers/admin/content/articles/article_form.js | 3 +++ .../controllers/admin/content/articles/manage_articles.js | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/plugins/pencilblue/controllers/admin/content/articles/article_form.js b/plugins/pencilblue/controllers/admin/content/articles/article_form.js index 43db9ed21..edfa75e58 100755 --- a/plugins/pencilblue/controllers/admin/content/articles/article_form.js +++ b/plugins/pencilblue/controllers/admin/content/articles/article_form.js @@ -86,6 +86,9 @@ module.exports = function(pb) { }; ArticleForm.prototype.getAngularObjects = function(tabs, data) { + if(pb.config.multisite && !data.article.site) { + data.article.site = pb.SiteService.getCurrentSite(this.pathVars.siteid); + } if(data.article[pb.DAO.getIdField()]) { var media = []; var i, j; diff --git a/plugins/pencilblue/controllers/admin/content/articles/manage_articles.js b/plugins/pencilblue/controllers/admin/content/articles/manage_articles.js index add975cdf..c1d668e27 100755 --- a/plugins/pencilblue/controllers/admin/content/articles/manage_articles.js +++ b/plugins/pencilblue/controllers/admin/content/articles/manage_articles.js @@ -32,8 +32,8 @@ module.exports = function(pb) { ManageArticles.prototype.render = function(cb) { var self = this; var dao = new pb.DAO(); - - var where = {}; + var siteid = pb.SiteService.getCurrentSite(self.pathVars.siteid); + var where = {site:siteid}; if(!pb.security.isAuthorized(this.session, {logged_in: true, admin_level: pb.SecurityService.ACCESS_EDITOR})) { where.author = this.session.authentication.user_id; } @@ -49,7 +49,7 @@ module.exports = function(pb) { return self.reqHandler.serveError(err); } else if (articles.length <= 0) { - return self.redirect('/admin/content/articles/new', cb); + return self.redirect('/admin' + pb.SiteService.getCurrentSitePrefix(siteid) + '/content/articles/new', cb); } pb.users.getAuthors(articles, function(err, articlesWithAuthorNames) { From f835815455fe2eff9ebcf9e8a5bc208acbc5d906 Mon Sep 17 00:00:00 2001 From: Christina Chatham Date: Tue, 5 May 2015 14:47:09 -0400 Subject: [PATCH 061/790] Change all links to include site id. --- .../controllers/admin/plugins/manage_plugins.js | 4 ++-- .../controllers/admin/plugins/plugin_details.js | 16 +++++++++++----- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/plugins/pencilblue/controllers/admin/plugins/manage_plugins.js b/plugins/pencilblue/controllers/admin/plugins/manage_plugins.js index 7bae77fa1..46ccaf7f2 100755 --- a/plugins/pencilblue/controllers/admin/plugins/manage_plugins.js +++ b/plugins/pencilblue/controllers/admin/plugins/manage_plugins.js @@ -54,7 +54,7 @@ module.exports = function(pb) { //setup angular var angularObjects = pb.ClientJs.getAngularObjects({ navigation: pb.AdminNavigation.get(self.session, ['plugins', 'manage'], self.ls), - pills: pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls), + pills: pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, null, { sitePrefix: prefix }), installedPlugins: map.active, inactivePlugins: map.inactive, availablePlugins: map.available, @@ -77,7 +77,7 @@ module.exports = function(pb) { name: 'manage_plugins', title: ls.get('MANAGE_PLUGINS'), icon: 'refresh', - href: '/admin/plugins' + href: '/admin' + data.sitePrefix + '/plugins' } ]; }; diff --git a/plugins/pencilblue/controllers/admin/plugins/plugin_details.js b/plugins/pencilblue/controllers/admin/plugins/plugin_details.js index a0a285734..3abddfde2 100755 --- a/plugins/pencilblue/controllers/admin/plugins/plugin_details.js +++ b/plugins/pencilblue/controllers/admin/plugins/plugin_details.js @@ -22,6 +22,8 @@ module.exports = function(pb) { var BaseController = pb.BaseController; var PluginService = pb.PluginService; var LocalizationService = pb.LocalizationService; + var SiteService = pb.SiteService; + /** * Interface for viewing plugin details @@ -59,7 +61,8 @@ module.exports = function(pb) { navigation: pb.AdminNavigation.get(self.session, ['plugins', 'manage'], self.ls), d: obj.details, status: obj.status, - is_active: PluginService.isActivePlugin(obj.details.uid) + is_active: PluginService.isActivePlugin(obj.details.uid), + sitePrefix: SiteService.getCurrentSitePrefix(SiteService.getCurrentSite(self.pathVars.siteid)) }); //render page @@ -78,7 +81,8 @@ module.exports = function(pb) { */ PluginDetailsViewController.prototype.getDetails = function(puid, cb) { var self = this; - var siteId = self.pathVars.siteid ? self.pathVars.siteid : pb.SiteService.GLOBAL_SITE; + var siteId = pb.SiteService.getCurrentSite(self.pathVars.siteid); + var sitePrefix = SiteService.getCurrentSitePrefix(siteId); var pluginService = new pb.PluginService(siteId); pluginService.getPluginBySite(puid, function(err, plugin) { @@ -90,7 +94,8 @@ module.exports = function(pb) { if (plugin) { var obj = { details: plugin, - status: self.ls.get(PluginService.isActivePlugin(plugin.uid, siteId) ? 'ACTIVE' : 'INACTIVE') + status: self.ls.get(PluginService.isActivePlugin(plugin.uid, siteId) ? 'ACTIVE' : 'INACTIVE'), + sitePrefix: sitePrefix }; cb(err, obj); return; @@ -101,7 +106,8 @@ module.exports = function(pb) { var detailsFile = PluginService.getDetailsPath(puid); PluginService.loadDetailsFile(detailsFile, function(err, details) { var obj = { - status: self.ls.get('ERRORED') + status: self.ls.get('ERRORED'), + sitePrefix: sitePrefix }; if (util.isError(err)) { obj.details = { @@ -139,7 +145,7 @@ module.exports = function(pb) { name: 'manage', title: data.details.name, icon: 'chevron-left', - href: '/admin/plugins' + href: '/admin' + data.sitePrefix + '/plugins' } ]; }; From a8ac3bc2b1cde111f8f1ca392c89b14f041dc2f5 Mon Sep 17 00:00:00 2001 From: Andrew Monroe Date: Tue, 5 May 2015 14:47:48 -0400 Subject: [PATCH 062/790] do a little refactoring on manage_plugins --- .../admin/plugins/manage_plugins.js | 71 ++++++++++--------- 1 file changed, 39 insertions(+), 32 deletions(-) diff --git a/plugins/pencilblue/controllers/admin/plugins/manage_plugins.js b/plugins/pencilblue/controllers/admin/plugins/manage_plugins.js index 9c25151a3..a30414e82 100755 --- a/plugins/pencilblue/controllers/admin/plugins/manage_plugins.js +++ b/plugins/pencilblue/controllers/admin/plugins/manage_plugins.js @@ -14,21 +14,19 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ +var async = require('async'); module.exports = function(pb) { - + //pb dependencies var util = pb.util; var BaseController = pb.BaseController; - + /** * Interface for managing plugins */ function ManagePlugins(){} - //dependencies - var BaseController = pb.BaseController; - //inheritance util.inherits(ManagePlugins, BaseController); @@ -37,39 +35,48 @@ module.exports = function(pb) { ManagePlugins.prototype.render = function(cb) { var self = this; - var siteid = self.pathVars.siteid; var site = pb.SiteService.getCurrentSite(self.pathVars.siteid); - pb.SiteService.error404IfSiteDoesNotExist(self.reqHandler, site, function () { + pb.SiteService.error404IfSiteDoesNotExist(self.reqHandler, site, function () { + //what happens if it doesnt? + self.onSiteValidated(site, cb); + }); + }; - var prefix = pb.SiteService.getCurrentSitePrefix(site); + ManagePlugins.prototype.onSiteValidated = function onSiteValidated(site, cb) { + var self = this; + var prefix = pb.SiteService.getCurrentSitePrefix(site); - //get the data - var pluginService = new pb.PluginService(siteid); - pluginService.getPluginMap(function(err, map) { - if (util.isError(err)) { - self.reqHandler.serveError(err); - return; - } + //get the data + var tasks = { + pluginMap: function(callback) { + var pluginService = new pb.PluginService(site); + pluginService.getPluginMap(callback); + }, + siteName: function(callback) { var siteService = new pb.SiteService(); - siteService.getSiteNameByUid(siteid, function(siteName) { - //setup angular - var angularObjects = pb.ClientJs.getAngularObjects({ - navigation: pb.AdminNavigation.get(self.session, ['plugins', 'manage'], self.ls), - pills: pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls), - installedPlugins: map.active, - inactivePlugins: map.inactive, - availablePlugins: map.available, - sitePrefix: prefix, - siteUid: siteid, - siteName: siteName - }); - //load the template - self.ts.registerLocal('angular_objects', new pb.TemplateValue(angularObjects, false)); - self.ts.load('/admin/plugins/manage_plugins', function(err, result) { - cb({content: result}); - }); + siteService.getSiteNameByUid(site, function(siteName) { + callback(null, siteName); }); + } + }; + + async.parallel(tasks, function(err, results) { + //setup angular + var angularObjects = pb.ClientJs.getAngularObjects({ + navigation: pb.AdminNavigation.get(self.session, ['plugins', 'manage'], self.ls), + pills: pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls), + installedPlugins: results.pluginMap.active, + inactivePlugins: results.pluginMap.inactive, + availablePlugins: results.pluginMap.available, + sitePrefix: prefix, + siteUid: site, + siteName: results.siteName + }); + //load the template + self.ts.registerLocal('angular_objects', new pb.TemplateValue(angularObjects, false)); + self.ts.load('/admin/plugins/manage_plugins', function(err, result) { + cb({content: result}); }); }); }; From 59a2278290f0b408e846275339a066bd6f3db7b7 Mon Sep 17 00:00:00 2001 From: btidwell Date: Tue, 5 May 2015 15:17:29 -0400 Subject: [PATCH 063/790] change handler site reference and query page by site for front-end MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit request handler was referencing site via “this” instead of “self” while inside of an anonymous callback. --- include/http/request_handler.js | 2 +- plugins/pencilblue/controllers/page.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/http/request_handler.js b/include/http/request_handler.js index 856626329..563869d96 100755 --- a/include/http/request_handler.js +++ b/include/http/request_handler.js @@ -837,7 +837,7 @@ module.exports = function RequestHandlerModule(pb) { path_vars: pathVars, query: self.url.query, body: body, - site: this.site + site: self.site }; cInstance.init(props, function(){ self.onControllerInitialized(cInstance, themeRoute); diff --git a/plugins/pencilblue/controllers/page.js b/plugins/pencilblue/controllers/page.js index 1f3025376..b5110fa21 100755 --- a/plugins/pencilblue/controllers/page.js +++ b/plugins/pencilblue/controllers/page.js @@ -49,7 +49,7 @@ module.exports = function PageModule(pb) { } } else { - where = {url: custUrl}; + where = {url: custUrl, site:self.site}; } var dao = new pb.DAO(); From a3a82347a1e5f2fc2e9ebf5c9f3257a087a3079e Mon Sep 17 00:00:00 2001 From: btidwell Date: Tue, 5 May 2015 15:41:55 -0400 Subject: [PATCH 064/790] query article by site --- plugins/pencilblue/controllers/article.js | 2 +- plugins/pencilblue/controllers/index.js | 2 +- plugins/pencilblue/controllers/page.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/pencilblue/controllers/article.js b/plugins/pencilblue/controllers/article.js index d7e604fec..a316e3933 100755 --- a/plugins/pencilblue/controllers/article.js +++ b/plugins/pencilblue/controllers/article.js @@ -41,7 +41,7 @@ module.exports = function ArticleModule(pb) { } } else { - where = {url: custUrl}; + where = {url: custUrl, site: self.site}; } // fall through to URL key diff --git a/plugins/pencilblue/controllers/index.js b/plugins/pencilblue/controllers/index.js index c6e2f65fc..169cc78d1 100755 --- a/plugins/pencilblue/controllers/index.js +++ b/plugins/pencilblue/controllers/index.js @@ -249,7 +249,7 @@ module.exports = function IndexModule(pb) { service.findById(page, articleCallback); } else{ - service.find({}, articleCallback); + service.find({site: this.site}, articleCallback); } }; diff --git a/plugins/pencilblue/controllers/page.js b/plugins/pencilblue/controllers/page.js index b5110fa21..3105fb47e 100755 --- a/plugins/pencilblue/controllers/page.js +++ b/plugins/pencilblue/controllers/page.js @@ -49,7 +49,7 @@ module.exports = function PageModule(pb) { } } else { - where = {url: custUrl, site:self.site}; + where = {url: custUrl, site: self.site}; } var dao = new pb.DAO(); From abace3049557db4dd3d92290b5cfb85bd8511016 Mon Sep 17 00:00:00 2001 From: Eugene Chang Date: Tue, 5 May 2015 15:42:30 -0400 Subject: [PATCH 065/790] Removing unnecessary prototype functions. --- .../controllers/admin/plugins/plugin_settings.js | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/plugins/pencilblue/controllers/admin/plugins/plugin_settings.js b/plugins/pencilblue/controllers/admin/plugins/plugin_settings.js index 5dc4e909b..0e58623e8 100755 --- a/plugins/pencilblue/controllers/admin/plugins/plugin_settings.js +++ b/plugins/pencilblue/controllers/admin/plugins/plugin_settings.js @@ -42,7 +42,8 @@ module.exports = function(pb) { var SUB_NAV_KEY = 'plugin_settings'; PluginSettingsFormController.prototype.initializePluginService = function initializePluginService() { - this.pluginService = new pb.PluginService(this.getSite()); + this.site = pb.SiteService.getCurrentSite(this.pathVars.siteid); + this.pluginService = new pb.PluginService(this.site); }; PluginSettingsFormController.prototype.get = function(cb) { @@ -97,11 +98,12 @@ module.exports = function(pb) { } ]; + var prefix = pb.SiteService.getCurrentSitePrefix(self.site); //setup angular var data = { plugin: plugin, settingType: self.getType(), - sitePrefix: self.getSitePrefix(self.getSite()) + sitePrefix: prefix }; var angularObjects = pb.ClientJs.getAngularObjects({ pills: pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, null, data), @@ -110,7 +112,7 @@ module.exports = function(pb) { settings: clone, pluginUID: uid, type: data.settingType, - sitePrefix: data.sitePrefix + sitePrefix: prefix }); //render page @@ -338,14 +340,6 @@ module.exports = function(pb) { return null; }; - PluginSettingsFormController.prototype.getSite = function () { - return pb.SiteService.getCurrentSite(this.pathVars.siteid); - }; - - PluginSettingsFormController.prototype.getSitePrefix = function getSitePrefix(site) { - return pb.SiteService.getCurrentSitePrefix(site); - }; - //register admin sub-nav pb.AdminSubnavService.registerFor(SUB_NAV_KEY, PluginSettingsFormController.getSubNavItems); From 9779dbf344ecb55417cc03022985062880ac677c Mon Sep 17 00:00:00 2001 From: andparker Date: Tue, 5 May 2015 16:05:39 -0400 Subject: [PATCH 066/790] Update error404IfSiteDoesNotExist method to just check if site exists. - Updated error404IfSiteDoesNotExist to only check if the site exists - The manage_plugins controller and any other controller is responsible for serving a 404 --- include/service/entities/site_service.js | 25 +++++++------------ .../admin/plugins/manage_plugins.js | 11 +++++--- 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/include/service/entities/site_service.js b/include/service/entities/site_service.js index e9b754812..56c831ed0 100644 --- a/include/service/entities/site_service.js +++ b/include/service/entities/site_service.js @@ -291,27 +291,20 @@ module.exports = function SiteServiceModule(pb) { }; /** - * Serves a 404 if the site in question does not exist - * @method error404IfSiteDoesNotExist - * @param {RequestHandler} requestHandler - * @param {String} uid - * @param {Function} cb Called if site does exist + * Determines if a site exists matching siteUid + * @method siteExists + * @param {String} siteUid + * @param {Function} cb */ - SiteService.error404IfSiteDoesNotExist = function(requestHandler, uid, cb) { - if (uid && !(uid === SiteService.GLOBAL_SITE)) { + SiteService.siteExists = function(siteUid, cb) { + if (pb.config.multisite && !(siteUid === SiteService.GLOBAL_SITE)) { var dao = new pb.DAO(); - dao.exists(SITE_COLL, {uid: uid}, function (err, exists) { - if (!exists || util.isError(err)) { - requestHandler.serve404(); - return; - } - else { - cb(); - } + dao.exists(SITE_COLL, {uid: siteUid}, function (err, exists) { + cb(err, exists); }); } else { - cb(); + cb(null, true); } }; diff --git a/plugins/pencilblue/controllers/admin/plugins/manage_plugins.js b/plugins/pencilblue/controllers/admin/plugins/manage_plugins.js index a30414e82..cc839c1a1 100755 --- a/plugins/pencilblue/controllers/admin/plugins/manage_plugins.js +++ b/plugins/pencilblue/controllers/admin/plugins/manage_plugins.js @@ -37,9 +37,14 @@ module.exports = function(pb) { var self = this; var site = pb.SiteService.getCurrentSite(self.pathVars.siteid); - pb.SiteService.error404IfSiteDoesNotExist(self.reqHandler, site, function () { - //what happens if it doesnt? - self.onSiteValidated(site, cb); + pb.SiteService.siteExists(site, function (err, siteExists) { + if (siteExists) { + self.onSiteValidated(site, cb); + } + else { + self.reqHandler.serve404(); + return; + } }); }; From 25adccff17c5d05f182b5552da8a4a8a59b5014f Mon Sep 17 00:00:00 2001 From: Andrew Monroe Date: Tue, 5 May 2015 16:22:42 -0400 Subject: [PATCH 067/790] fix this references and laod correct setting service for theme admin settings --- include/service/entities/plugin_setting_service.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/service/entities/plugin_setting_service.js b/include/service/entities/plugin_setting_service.js index 62e687046..05e024e5b 100644 --- a/include/service/entities/plugin_setting_service.js +++ b/include/service/entities/plugin_setting_service.js @@ -485,14 +485,14 @@ module.exports = function PluginSettingServiceModule(pb) { function getAdminPluginSettingsService(self) { if(!self.adminPluginSettingsService) { - self.adminPluginSettingsService = genSettingsService('plugin_settings', self.caching.useMemory, self.caching.useCache, 'PluginSettingService', this.site, true); + self.adminPluginSettingsService = genSettingsService('plugin_settings', self.caching.useMemory, self.caching.useCache, 'PluginSettingService', self.site, true); } return self.adminPluginSettingsService; } function getAdminThemeSettingsService(self) { if(!self.adminThemeSettingsService) { - self.adminThemeSettingsService = genSettingsService('theme_settings', self.caching.useMemory, self.caching.useCache, 'ThemeSettingService', this.site); + self.adminThemeSettingsService = genSettingsService('theme_settings', self.caching.useMemory, self.caching.useCache, 'ThemeSettingService', self.site, true); } return self.adminThemeSettingsService; } From 0d9058449da4d6b26507e3d2693299f7beef3ac5 Mon Sep 17 00:00:00 2001 From: Eugene Chang Date: Tue, 5 May 2015 16:29:17 -0400 Subject: [PATCH 068/790] Fixing plugin setting service. --- include/service/entities/plugin_setting_service.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/service/entities/plugin_setting_service.js b/include/service/entities/plugin_setting_service.js index 62e687046..05e024e5b 100644 --- a/include/service/entities/plugin_setting_service.js +++ b/include/service/entities/plugin_setting_service.js @@ -485,14 +485,14 @@ module.exports = function PluginSettingServiceModule(pb) { function getAdminPluginSettingsService(self) { if(!self.adminPluginSettingsService) { - self.adminPluginSettingsService = genSettingsService('plugin_settings', self.caching.useMemory, self.caching.useCache, 'PluginSettingService', this.site, true); + self.adminPluginSettingsService = genSettingsService('plugin_settings', self.caching.useMemory, self.caching.useCache, 'PluginSettingService', self.site, true); } return self.adminPluginSettingsService; } function getAdminThemeSettingsService(self) { if(!self.adminThemeSettingsService) { - self.adminThemeSettingsService = genSettingsService('theme_settings', self.caching.useMemory, self.caching.useCache, 'ThemeSettingService', this.site); + self.adminThemeSettingsService = genSettingsService('theme_settings', self.caching.useMemory, self.caching.useCache, 'ThemeSettingService', self.site, true); } return self.adminThemeSettingsService; } From 0ee82fc60c2f2a4b9df7dc6a0131fe20a6649396 Mon Sep 17 00:00:00 2001 From: andparker Date: Wed, 6 May 2015 09:47:44 -0400 Subject: [PATCH 069/790] Site routing validation added to these controllers. --- plugins/pencilblue/controllers/admin/index.js | 24 ++++++++++++- .../admin/plugins/plugin_details.js | 35 +++++++++++++++---- .../controllers/api/plugins/plugin_api.js | 24 +++++++++++-- 3 files changed, 73 insertions(+), 10 deletions(-) diff --git a/plugins/pencilblue/controllers/admin/index.js b/plugins/pencilblue/controllers/admin/index.js index 1909156df..98fb831b8 100755 --- a/plugins/pencilblue/controllers/admin/index.js +++ b/plugins/pencilblue/controllers/admin/index.js @@ -36,6 +36,28 @@ module.exports = function AdminIndexControllerModule(pb) { */ AdminIndexController.prototype.render = function(cb) { var self = this; + var site = pb.SiteService.getCurrentSite(self.pathVars.siteid); + + pb.SiteService.siteExists(site, function (err, siteExists) { + if (siteExists) { + self.onSiteValidated(cb); + } + else { + self.reqHandler.serve404(); + return; + } + }); + }; + + /** + * + * @method onSiteValidated + * @param site + * @param cb + * + */ + AdminIndexController.prototype.onSiteValidated = function onSiteValidated(cb) { + var self = this; //gather all the data this.gatherData(function(err, data) { @@ -48,7 +70,7 @@ module.exports = function AdminIndexControllerModule(pb) { { name: name, count: data.articleCount, - href: '/admin/content/articles', + href: '/admin/content/articles' }, ]; diff --git a/plugins/pencilblue/controllers/admin/plugins/plugin_details.js b/plugins/pencilblue/controllers/admin/plugins/plugin_details.js index 3abddfde2..f2284683a 100755 --- a/plugins/pencilblue/controllers/admin/plugins/plugin_details.js +++ b/plugins/pencilblue/controllers/admin/plugins/plugin_details.js @@ -16,7 +16,7 @@ */ module.exports = function(pb) { - + //pb dependencies var util = pb.util; var BaseController = pb.BaseController; @@ -44,8 +44,30 @@ module.exports = function(pb) { */ PluginDetailsViewController.prototype.render = function(cb) { var self = this; + var site = pb.SiteService.getCurrentSite(self.pathVars.siteid); + + pb.SiteService.siteExists(site, function (err, siteExists) { + if (siteExists) { + self.onSiteValidated(site, cb); + } + else { + self.reqHandler.serve404(); + return; + } + }); + }; + + /** + * + * @method onSiteValidated + * @param site + * @param cb + * + */ + PluginDetailsViewController.prototype.onSiteValidated = function onSiteValidated(site, cb) { + var self = this; - this.getDetails(this.pathVars.id, function(err, obj) { + this.getDetails(this.pathVars.id, site, function(err, obj) { if (util.isError(err)) { throw err; } @@ -79,12 +101,11 @@ module.exports = function(pb) { * @method getDetails * */ - PluginDetailsViewController.prototype.getDetails = function(puid, cb) { + PluginDetailsViewController.prototype.getDetails = function(puid, site, cb) { var self = this; - var siteId = pb.SiteService.getCurrentSite(self.pathVars.siteid); - var sitePrefix = SiteService.getCurrentSitePrefix(siteId); + var sitePrefix = SiteService.getCurrentSitePrefix(site); - var pluginService = new pb.PluginService(siteId); + var pluginService = new pb.PluginService(site); pluginService.getPluginBySite(puid, function(err, plugin) { if (util.isError(err)) { cb(err, plugin); @@ -94,7 +115,7 @@ module.exports = function(pb) { if (plugin) { var obj = { details: plugin, - status: self.ls.get(PluginService.isActivePlugin(plugin.uid, siteId) ? 'ACTIVE' : 'INACTIVE'), + status: self.ls.get(PluginService.isActivePlugin(plugin.uid, site) ? 'ACTIVE' : 'INACTIVE'), sitePrefix: sitePrefix }; cb(err, obj); diff --git a/plugins/pencilblue/controllers/api/plugins/plugin_api.js b/plugins/pencilblue/controllers/api/plugins/plugin_api.js index 963594548..5a659738e 100755 --- a/plugins/pencilblue/controllers/api/plugins/plugin_api.js +++ b/plugins/pencilblue/controllers/api/plugins/plugin_api.js @@ -62,7 +62,7 @@ module.exports = function(pb) { uninstall: true, reset_settings: true, initialize: true, - set_theme: true, + set_theme: true }; /** @@ -72,9 +72,29 @@ module.exports = function(pb) { * @param {Function} cb */ PluginApiController.prototype.render = function(cb) { + var self = this; + this.site = pb.SiteService.getCurrentSite(this.pathVars.siteid); + + pb.SiteService.siteExists(this.site, function (err, siteExists) { + if (siteExists) { + self.onSiteValidated(this.site, cb); + } + else { + self.reqHandler.serve404(); + return; + } + }); + }; + + /** + * Triggers after the site is validated + * @method onSiteValidated + * @param site + * @param cb + */ + PluginApiController.prototype.onSiteValidated = function onSiteValidated(site, cb) { var action = this.pathVars.action; var identifier = this.pathVars.id; - this.site = pb.SiteService.getCurrentSite(this.pathVars.siteid); this.pluginService = new pb.PluginService(this.site); //validate action From 8e7361289eb5b2a5ffd10aa23183636bed173fd6 Mon Sep 17 00:00:00 2001 From: andparker Date: Wed, 6 May 2015 10:14:41 -0400 Subject: [PATCH 070/790] Change "site" member to local variable that is passed through to the other methods. --- plugins/pencilblue/controllers/api/plugins/plugin_api.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/pencilblue/controllers/api/plugins/plugin_api.js b/plugins/pencilblue/controllers/api/plugins/plugin_api.js index 5a659738e..5c9900c4b 100755 --- a/plugins/pencilblue/controllers/api/plugins/plugin_api.js +++ b/plugins/pencilblue/controllers/api/plugins/plugin_api.js @@ -73,11 +73,11 @@ module.exports = function(pb) { */ PluginApiController.prototype.render = function(cb) { var self = this; - this.site = pb.SiteService.getCurrentSite(this.pathVars.siteid); + var site = pb.SiteService.getCurrentSite(this.pathVars.siteid); - pb.SiteService.siteExists(this.site, function (err, siteExists) { + pb.SiteService.siteExists(site, function (err, siteExists) { if (siteExists) { - self.onSiteValidated(this.site, cb); + self.onSiteValidated(site, cb); } else { self.reqHandler.serve404(); @@ -95,7 +95,7 @@ module.exports = function(pb) { PluginApiController.prototype.onSiteValidated = function onSiteValidated(site, cb) { var action = this.pathVars.action; var identifier = this.pathVars.id; - this.pluginService = new pb.PluginService(this.site); + this.pluginService = new pb.PluginService(site); //validate action var errors = []; From a221f3a04109106b52cb1cc5326b4675347e11f0 Mon Sep 17 00:00:00 2001 From: btidwell Date: Wed, 6 May 2015 10:33:32 -0400 Subject: [PATCH 071/790] Replace Url and Headline index with unique compound index Change request handler to optionally take in site for function urlExists --- include/config.js | 8 +++--- include/http/request_handler.js | 9 ++++++- .../actions/admin/content/pages/edit_page.js | 2 +- .../actions/admin/content/pages/new_page.js | 26 ++++++------------- .../api/admin/content/pages/save_draft.js | 2 +- 5 files changed, 22 insertions(+), 25 deletions(-) diff --git a/include/config.js b/include/config.js index 8d781accf..9578a9a5d 100755 --- a/include/config.js +++ b/include/config.js @@ -356,12 +356,12 @@ var BASE_CONFIG = { //article { collection: 'article', - spec: {url: ASC}, + spec: {url: ASC, site: ASC}, options: {unique: true} }, { collection: 'article', - spec: {headline: ASC}, + spec: {headline: ASC, site: ASC}, options: {unique: true} }, { @@ -420,12 +420,12 @@ var BASE_CONFIG = { //page { collection: 'page', - spec: {url: ASC}, + spec: {url: ASC, site: ASC}, options: {unique: true} }, { collection: 'page', - spec: {headline: ASC}, + spec: {headline: ASC, site: ASC}, options: {unique: true} }, { diff --git a/include/http/request_handler.js b/include/http/request_handler.js index 563869d96..51776d6d5 100755 --- a/include/http/request_handler.js +++ b/include/http/request_handler.js @@ -1195,11 +1195,18 @@ module.exports = function RequestHandlerModule(pb) { * @param {String} url * @param { */ - RequestHandler.urlExists = function(url, id, cb) { + RequestHandler.urlExists = function(url, id, site, cb) { var dao = new pb.DAO(); + if(typeof site === 'function') { + cb = site; + site = undefined; + } var getTask = function(collection) { return function (callback) { var where = {url: url}; + if(site) { + where.site = site; + } if (id) { where[pb.DAO.getIdField()] = pb.DAO.getNotIdField(id); } diff --git a/plugins/pencilblue/controllers/actions/admin/content/pages/edit_page.js b/plugins/pencilblue/controllers/actions/admin/content/pages/edit_page.js index efc62d5c7..d16f6769c 100755 --- a/plugins/pencilblue/controllers/actions/admin/content/pages/edit_page.js +++ b/plugins/pencilblue/controllers/actions/admin/content/pages/edit_page.js @@ -65,7 +65,7 @@ module.exports = function(pb) { self.setFormFieldValues(post); - pb.RequestHandler.urlExists(page.url, post.id, function(err, exists) { + pb.RequestHandler.urlExists(page.url, post.id, page.site, function(err, exists) { if(util.isError(err) || exists) { cb({ code: 400, diff --git a/plugins/pencilblue/controllers/actions/admin/content/pages/new_page.js b/plugins/pencilblue/controllers/actions/admin/content/pages/new_page.js index edc3012b3..b63e7423c 100755 --- a/plugins/pencilblue/controllers/actions/admin/content/pages/new_page.js +++ b/plugins/pencilblue/controllers/actions/admin/content/pages/new_page.js @@ -31,7 +31,7 @@ module.exports = function(pb) { NewPagePostController.prototype.render = function(cb) { var self = this; - + var site = pb.SiteService.getCurrentSite(this.pathVars.siteid); this.getJSONPostParams(function(err, post) { if(self.session.authentication.user.admin < pb.SecurityService.ACCESS_EDITOR || !post.author) { post.author = self.session.authentication.user[pb.DAO.getIdField()]; @@ -52,35 +52,25 @@ module.exports = function(pb) { post = pb.DocumentCreator.formatIntegerItems(post, ['draft']); var pageDocument = pb.DocumentCreator.create('page', post, ['meta_keywords']); var dao = new pb.DAO(); - dao.count('page', {url: pageDocument.url}, function(err, count) { - if(util.isError(err) || count > 0) { + pb.RequestHandler.urlExists(pageDocument.url, post.id, pageDocument.site, function(err, exists) { + if(util.isError(err) || exists) { cb({ code: 400, content: pb.BaseController.apiResponse(pb.BaseController.API_FAILURE, self.ls.get('EXISTING_URL')) }); return; } - - dao.count('article', {url: pageDocument.url}, function(err, count) { - if(util.isError(err) || count > 0) { + dao.save(pageDocument, function(err, result) { + if(util.isError(err)) { + pb.log.error(err); cb({ - code: 400, + code: 500, content: pb.BaseController.apiResponse(pb.BaseController.API_FAILURE, self.ls.get('ERROR_SAVING')) }); return; } - dao.save(pageDocument, function(err, result) { - if(util.isError(err)) { - cb({ - code: 500, - content: pb.BaseController.apiResponse(pb.BaseController.API_FAILURE, self.ls.get('ERROR_SAVING')) - }); - return; - } - - cb({content: pb.BaseController.apiResponse(pb.BaseController.API_SUCCESS, pageDocument.headline + ' ' + self.ls.get('CREATED'), result)}); - }); + cb({content: pb.BaseController.apiResponse(pb.BaseController.API_SUCCESS, pageDocument.headline + ' ' + self.ls.get('CREATED'), result)}); }); }); }); diff --git a/plugins/pencilblue/controllers/api/admin/content/pages/save_draft.js b/plugins/pencilblue/controllers/api/admin/content/pages/save_draft.js index 83d94f6ca..ea8f34232 100755 --- a/plugins/pencilblue/controllers/api/admin/content/pages/save_draft.js +++ b/plugins/pencilblue/controllers/api/admin/content/pages/save_draft.js @@ -72,7 +72,7 @@ SavePageDraftController.prototype.onPostParamsRetrieved = function(post, cb) { post = pb.DocumentCreator.formatIntegerItems(post, ['draft']); pb.DocumentCreator.update(post, page, ['meta_keywords', 'page_topics', 'page_media']); - pb.RequestHandler.urlExists(page.url, post.id, function(error, exists) { + pb.RequestHandler.urlExists(page.url, post.id, page.site, function(error, exists) { if(error != null || exists || page.url.indexOf('/admin') == 0) { cb({content: pb.BaseController.apiResponse(pb.BaseController.API_FAILURE, 'existing page url')}); return; From dfa6536745bd7bea383a8385770e9984867618bb Mon Sep 17 00:00:00 2001 From: btidwell Date: Wed, 6 May 2015 11:23:09 -0400 Subject: [PATCH 072/790] Add site to subnav for pages and articles --- .../controllers/admin/content/articles/article_form.js | 8 ++++++-- .../admin/content/articles/manage_articles.js | 10 +++++++--- .../controllers/admin/content/pages/manage_pages.js | 10 +++++++--- .../controllers/admin/content/pages/page_form.js | 8 ++++++-- 4 files changed, 26 insertions(+), 10 deletions(-) diff --git a/plugins/pencilblue/controllers/admin/content/articles/article_form.js b/plugins/pencilblue/controllers/admin/content/articles/article_form.js index edfa75e58..b2a9bfc7b 100755 --- a/plugins/pencilblue/controllers/admin/content/articles/article_form.js +++ b/plugins/pencilblue/controllers/admin/content/articles/article_form.js @@ -146,16 +146,20 @@ module.exports = function(pb) { }; ArticleForm.getSubNavItems = function(key, ls, data) { + var adminPrefix = '/admin'; + if(data.article.site) { + adminPrefix += pb.SiteService.getCurrentSitePrefix(data.article.site); + } return [{ name: 'manage_articles', title: data.article[pb.DAO.getIdField()] ? ls.get('EDIT') + ' ' + data.article.headline : ls.get('NEW_ARTICLE'), icon: 'chevron-left', - href: '/admin/content/articles' + href: adminPrefix + '/content/articles' }, { name: 'new_article', title: '', icon: 'plus', - href: '/admin/content/articles/new' + href: adminPrefix + '/content/articles/new' }]; }; diff --git a/plugins/pencilblue/controllers/admin/content/articles/manage_articles.js b/plugins/pencilblue/controllers/admin/content/articles/manage_articles.js index c1d668e27..f1dd02b3f 100755 --- a/plugins/pencilblue/controllers/admin/content/articles/manage_articles.js +++ b/plugins/pencilblue/controllers/admin/content/articles/manage_articles.js @@ -57,7 +57,7 @@ module.exports = function(pb) { var angularObjects = pb.ClientJs.getAngularObjects( { navigation: pb.AdminNavigation.get(self.session, ['content', 'articles'], self.ls), - pills: pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, SUB_NAV_KEY), + pills: pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, SUB_NAV_KEY, {site: siteid}), articles: articles }); @@ -90,16 +90,20 @@ module.exports = function(pb) { }; ManageArticles.getSubNavItems = function(key, ls, data) { + var adminPrefix = '/admin'; + if(data.site) { + adminPrefix += pb.SiteService.getCurrentSitePrefix(data.site); + } return [{ name: 'manage_articles', title: ls.get('MANAGE_ARTICLES'), icon: 'refresh', - href: '/admin/content/articles' + href: adminPrefix + '/content/articles' }, { name: 'new_article', title: '', icon: 'plus', - href: '/admin/content/articles/new' + href: adminPrefix + '/content/articles/new' }]; }; diff --git a/plugins/pencilblue/controllers/admin/content/pages/manage_pages.js b/plugins/pencilblue/controllers/admin/content/pages/manage_pages.js index e2fc6ea4e..4977666f8 100755 --- a/plugins/pencilblue/controllers/admin/content/pages/manage_pages.js +++ b/plugins/pencilblue/controllers/admin/content/pages/manage_pages.js @@ -50,7 +50,7 @@ module.exports = function(pb) { var angularObjects = pb.ClientJs.getAngularObjects( { navigation: pb.AdminNavigation.get(self.session, ['content', 'pages'], self.ls), - pills: pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, 'manage_pages'), + pills: pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, 'manage_pages', {site: siteid}), pages: self.getPageStatuses(pagesWithAuthor) }); @@ -83,16 +83,20 @@ module.exports = function(pb) { }; ManagePages.getSubNavItems = function(key, ls, data) { + var adminPrefix = '/admin'; + if(data.site) { + adminPrefix += pb.SiteService.getCurrentSitePrefix(data.site); + } return [{ name: 'manage_pages', title: ls.get('MANAGE_PAGES'), icon: 'refresh', - href: '/admin/content/pages' + href: adminPrefix + '/content/pages' }, { name: 'new_page', title: '' , icon: 'plus', - href: '/admin/content/pages/new' + href: adminPrefix + '/content/pages/new' }]; }; diff --git a/plugins/pencilblue/controllers/admin/content/pages/page_form.js b/plugins/pencilblue/controllers/admin/content/pages/page_form.js index 0f2c4e182..a333c6ac4 100755 --- a/plugins/pencilblue/controllers/admin/content/pages/page_form.js +++ b/plugins/pencilblue/controllers/admin/content/pages/page_form.js @@ -137,16 +137,20 @@ module.exports = function(pb) { * */ PageFormController.getSubNavItems = function(key, ls, data) { + var adminPrefix = '/admin'; + if(data.page.site) { + adminPrefix += pb.SiteService.getCurrentSitePrefix(data.page.site); + } return [{ name: 'manage_pages', title: data.page[pb.DAO.getIdField()] ? ls.get('EDIT') + ' ' + data.page.headline : ls.get('NEW_PAGE'), icon: 'chevron-left', - href: '/admin/content/pages' + href: adminPrefix + '/content/pages' }, { name: 'new_page', title: '', icon: 'plus', - href: '/admin/content/pages/new' + href: adminPrefix + '/content/pages/new' }]; }; From fcf636aeee0e2bcd3e611d82d30e8cfd62b4dc7e Mon Sep 17 00:00:00 2001 From: Eugene Chang Date: Wed, 6 May 2015 11:26:53 -0400 Subject: [PATCH 073/790] Fixing theme setting/plugin API. --- .../jobs/plugins/plugin_uninstall_job.js | 2 +- include/system/settings.js | 11 +++++++---- .../controllers/admin/themes/manage_themes.js | 2 +- .../controllers/api/plugins/plugin_api.js | 18 ++++++++++++++---- 4 files changed, 23 insertions(+), 10 deletions(-) diff --git a/include/service/jobs/plugins/plugin_uninstall_job.js b/include/service/jobs/plugins/plugin_uninstall_job.js index 39ae847b9..3e87752a4 100644 --- a/include/service/jobs/plugins/plugin_uninstall_job.js +++ b/include/service/jobs/plugins/plugin_uninstall_job.js @@ -201,7 +201,7 @@ module.exports = function PluginUninstallJobModule(pb) { //retrieve the plugin so we can see if the value matches what we //are uninstalling - var settings = pb.SettingServiceFactory.getService(pb.config.settings.use_memory, pb.config.settings.use_cache, site); + var settings = pb.SettingServiceFactory.getService(pb.config.settings.use_memory, pb.config.settings.use_cache, site, true); settings.get('active_theme', function(err, activeTheme) { if (util.isError(err)) { return callback(err, false); diff --git a/include/system/settings.js b/include/system/settings.js index 6f019c7f6..9f368bb33 100755 --- a/include/system/settings.js +++ b/include/system/settings.js @@ -43,8 +43,10 @@ module.exports = function SettingsModule(pb) { * @param {Boolean} useMemory * @param {Boolean} useCache * @return {SimpleLayeredService} + * @param site {String} siteId + * @param onlyThisSite {Boolean} whether this service should only return setting specified by site */ - SettingServiceFactory.getService = function(useMemory, useCache, site) { + SettingServiceFactory.getService = function(useMemory, useCache, site, onlyThisSite) { var objType = 'setting'; var keyField = 'key'; var valueField = 'value'; @@ -57,18 +59,19 @@ module.exports = function SettingsModule(pb) { valueField: valueField, keyField: keyField, timeout: pb.config.settings.memory_timeout, - site: site + site: site, + onlyThisSite: onlyThisSite }; services.push(new pb.MemoryEntityService(options)); } //add cache service if (useCache) { - services.push(new pb.CacheEntityService(objType, valueField, keyField, site)); + services.push(new pb.CacheEntityService(objType, valueField, keyField, site, onlyThisSite)); } //always add db service - services.push(new pb.DBEntityService(objType, valueField, keyField, site)); + services.push(new pb.DBEntityService(objType, valueField, keyField, site, onlyThisSite)); return new pb.SimpleLayeredService(services, 'SettingService' + count++); }; diff --git a/plugins/pencilblue/controllers/admin/themes/manage_themes.js b/plugins/pencilblue/controllers/admin/themes/manage_themes.js index 8fae5330a..8ec5d4c19 100755 --- a/plugins/pencilblue/controllers/admin/themes/manage_themes.js +++ b/plugins/pencilblue/controllers/admin/themes/manage_themes.js @@ -45,7 +45,7 @@ module.exports = function(pb) { } //get active theme - var settings = pb.SettingServiceFactory.getService(pb.config.settings.use_memory, pb.config.settings.use_cache, self.site); + var settings = pb.SettingServiceFactory.getService(pb.config.settings.use_memory, pb.config.settings.use_cache, site, true); settings.get('active_theme', function(err, activeTheme) { if (util.isError(err)) { throw err; diff --git a/plugins/pencilblue/controllers/api/plugins/plugin_api.js b/plugins/pencilblue/controllers/api/plugins/plugin_api.js index 963594548..495777819 100755 --- a/plugins/pencilblue/controllers/api/plugins/plugin_api.js +++ b/plugins/pencilblue/controllers/api/plugins/plugin_api.js @@ -43,10 +43,22 @@ module.exports = function(pb) { * @property pluginService * @type {PluginService} */ - this.pluginService = new PluginService(); } util.inherits(PluginApiController, BaseController); + /** + * Overriding the default init to provide site info as well as a site-aware plugin service + * + * @param props + * @param cb + */ + PluginApiController.prototype.init = function (props, cb) { + this.siteId = pb.SiteService.getCurrentSite(props.path_vars.siteid); + this.pluginService = new PluginService(this.siteId); + + BaseController.prototype.init.call(this, props, cb); + }; + //constants /** * The hash of actions that are available to execute for this controller. When @@ -74,8 +86,6 @@ module.exports = function(pb) { PluginApiController.prototype.render = function(cb) { var action = this.pathVars.action; var identifier = this.pathVars.id; - this.site = pb.SiteService.getCurrentSite(this.pathVars.siteid); - this.pluginService = new pb.PluginService(this.site); //validate action var errors = []; @@ -242,7 +252,7 @@ module.exports = function(pb) { } var theme = plugin ? plugin.uid : uid; - var settings = pb.SettingServiceFactory.getService(pb.config.settings.use_memory, pb.config.settings.use_cache, self.site); + var settings = pb.SettingServiceFactory.getService(pb.config.settings.use_memory, pb.config.settings.use_cache, self.siteId, true); settings.set('active_theme', theme, function(err, result) { if (util.isError(err)) { var content = BaseController.apiResponse(BaseController.API_FAILURE, util.format(self.ls.get('SET_THEME_FAILED'), uid), [err.message]); From c29288c75f973498c9f05c55a22c34590d4b0dfa Mon Sep 17 00:00:00 2001 From: btidwell Date: Wed, 6 May 2015 11:33:24 -0400 Subject: [PATCH 074/790] include site in unique url check for articles --- include/http/request_handler.js | 8 ++++++-- .../actions/admin/content/articles/edit_article.js | 2 +- .../actions/admin/content/articles/new_article.js | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/include/http/request_handler.js b/include/http/request_handler.js index 51776d6d5..cd6347ca6 100755 --- a/include/http/request_handler.js +++ b/include/http/request_handler.js @@ -1253,12 +1253,16 @@ module.exports = function RequestHandlerModule(pb) { * @param {String} id * @param {Function} cb */ - RequestHandler.isSystemSafeURL = function(url, id, cb) { + RequestHandler.isSystemSafeURL = function(url, id, site, cb) { + if(typeof site === 'function') { + cb = site; + site = undefined; + } if (url == null || RequestHandler.isAdminURL(url)) { cb(null, false); return; } - RequestHandler.urlExists(url, id, function(err, exists){ + RequestHandler.urlExists(url, id, site, function(err, exists){ cb(err, !exists); }); }; diff --git a/plugins/pencilblue/controllers/actions/admin/content/articles/edit_article.js b/plugins/pencilblue/controllers/actions/admin/content/articles/edit_article.js index d68776384..6c28ecf21 100755 --- a/plugins/pencilblue/controllers/actions/admin/content/articles/edit_article.js +++ b/plugins/pencilblue/controllers/actions/admin/content/articles/edit_article.js @@ -61,7 +61,7 @@ module.exports = function(pb) { post = pb.DocumentCreator.formatIntegerItems(post, ['draft']); pb.DocumentCreator.update(post, article, ['meta_keywords']); - pb.RequestHandler.urlExists(article.url, post.id, function(error, exists) { + pb.RequestHandler.urlExists(article.url, post.id, article.site, function(error, exists) { var testError = (error !== null && typeof error !== 'undefined'); if( testError || exists || article.url.indexOf('/admin') === 0) { diff --git a/plugins/pencilblue/controllers/actions/admin/content/articles/new_article.js b/plugins/pencilblue/controllers/actions/admin/content/articles/new_article.js index 548a48baa..ea2f58380 100755 --- a/plugins/pencilblue/controllers/actions/admin/content/articles/new_article.js +++ b/plugins/pencilblue/controllers/actions/admin/content/articles/new_article.js @@ -47,7 +47,7 @@ module.exports = function(pb) { post = pb.DocumentCreator.formatIntegerItems(post, ['draft']); var articleDocument = pb.DocumentCreator.create('article', post, ['meta_keywords']); - pb.RequestHandler.isSystemSafeURL(articleDocument.url, null, function(err, isSafe) { + pb.RequestHandler.isSystemSafeURL(articleDocument.url, null, articleDocument.site, function(err, isSafe) { if(util.isError(err) || !isSafe) { cb({ code: 400, From cf866b7cea04684a170b9522fc58f8d0a5a2d7fe Mon Sep 17 00:00:00 2001 From: Eugene Chang Date: Wed, 6 May 2015 11:37:09 -0400 Subject: [PATCH 075/790] Changing plugin API code to conform to the newly merged code. --- .../controllers/api/plugins/plugin_api.js | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/plugins/pencilblue/controllers/api/plugins/plugin_api.js b/plugins/pencilblue/controllers/api/plugins/plugin_api.js index 2dea953fb..1d9157785 100755 --- a/plugins/pencilblue/controllers/api/plugins/plugin_api.js +++ b/plugins/pencilblue/controllers/api/plugins/plugin_api.js @@ -46,19 +46,6 @@ module.exports = function(pb) { } util.inherits(PluginApiController, BaseController); - /** - * Overriding the default init to provide site info as well as a site-aware plugin service - * - * @param props - * @param cb - */ - PluginApiController.prototype.init = function (props, cb) { - this.siteId = pb.SiteService.getCurrentSite(props.path_vars.siteid); - this.pluginService = new PluginService(this.siteId); - - BaseController.prototype.init.call(this, props, cb); - }; - //constants /** * The hash of actions that are available to execute for this controller. When @@ -275,7 +262,7 @@ module.exports = function(pb) { } var theme = plugin ? plugin.uid : uid; - var settings = pb.SettingServiceFactory.getService(pb.config.settings.use_memory, pb.config.settings.use_cache, self.siteId, true); + var settings = pb.SettingServiceFactory.getService(pb.config.settings.use_memory, pb.config.settings.use_cache, self.site, true); settings.set('active_theme', theme, function(err, result) { if (util.isError(err)) { var content = BaseController.apiResponse(BaseController.API_FAILURE, util.format(self.ls.get('SET_THEME_FAILED'), uid), [err.message]); From a27748ba58a32fa639397f450f414fe5f1bb5bbe Mon Sep 17 00:00:00 2001 From: btidwell Date: Wed, 6 May 2015 13:32:24 -0400 Subject: [PATCH 076/790] add site to remaining queries on article --- plugins/pencilblue/controllers/article.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/pencilblue/controllers/article.js b/plugins/pencilblue/controllers/article.js index a316e3933..b5abe6c1a 100755 --- a/plugins/pencilblue/controllers/article.js +++ b/plugins/pencilblue/controllers/article.js @@ -35,7 +35,7 @@ module.exports = function ArticleModule(pb) { //check for object ID as the custom URL var where = null; if(pb.validation.isIdStr(custUrl)) { - where = {_id: pb.DAO.getObjectID(custUrl)}; + where = {_id: pb.DAO.getObjectID(custUrl), site: self.site}; if (pb.log.isSilly()) { pb.log.silly("ArticleController: The custom URL was not an object ID [%s]. Will now search url field. [%s]", custUrl, e.message); } @@ -46,9 +46,9 @@ module.exports = function ArticleModule(pb) { // fall through to URL key if (where === null) { - where = {url: custUrl}; + where = {url: custUrl, site: self.site}; } - + //attempt to load object var dao = new pb.DAO(); dao.loadByValues(where, 'article', function(err, article) { @@ -58,7 +58,7 @@ module.exports = function ArticleModule(pb) { return; } - dao.loadByValues({url: custUrl}, 'article', function(err, article) { + dao.loadByValues({url: custUrl, site: self.site}, 'article', function(err, article) { if (util.isError(err) || article == null) { self.reqHandler.serve404(); return; From 9e90450f54f656a2ed5d9966012f14545dd603fb Mon Sep 17 00:00:00 2001 From: andparker Date: Wed, 6 May 2015 16:11:33 -0400 Subject: [PATCH 077/790] Add site routing validation to plugin settings, theme settings, and manage themes. --- .../admin/plugins/plugin_settings.js | 36 +++++++++++++++++-- .../controllers/admin/themes/manage_themes.js | 15 +++++++- 2 files changed, 47 insertions(+), 4 deletions(-) diff --git a/plugins/pencilblue/controllers/admin/plugins/plugin_settings.js b/plugins/pencilblue/controllers/admin/plugins/plugin_settings.js index 0e58623e8..f5c9c6bce 100755 --- a/plugins/pencilblue/controllers/admin/plugins/plugin_settings.js +++ b/plugins/pencilblue/controllers/admin/plugins/plugin_settings.js @@ -47,9 +47,23 @@ module.exports = function(pb) { }; PluginSettingsFormController.prototype.get = function(cb) { - var self = this;console.log(this.constructor.name); - self.initializePluginService(); + var self = this; + var site = pb.SiteService.getCurrentSite(self.pathVars.siteid); + + pb.SiteService.siteExists(site, function (err, siteExists) { + if (siteExists) { + self.onSiteValidatedGet(cb); + self.initializePluginService(); + } + else { + self.reqHandler.serve404(); + } + }); + }; + PluginSettingsFormController.prototype.onSiteValidatedGet = function (cb) { + var self = this; + console.log(this.constructor.name); var uid = this.pathVars.id; this.pluginService.getPluginBySite(uid, function(err, plugin) { if (util.isError(err)) { @@ -126,7 +140,23 @@ module.exports = function(pb) { PluginSettingsFormController.prototype.post = function(cb) { - var self = this;console.log(this.constructor.name); + var self = this; + var site = pb.SiteService.getCurrentSite(self.pathVars.siteid); + + pb.SiteService.siteExists(site, function (err, siteExists) { + if (siteExists) { + self.onSiteValidatedPost(cb); + self.initializePluginService(); + } + else { + self.reqHandler.serve404(); + } + }); + }; + + PluginSettingsFormController.prototype.onSiteValidatedPost = function (cb) { + var self = this; + console.log(this.constructor.name); var post = this.body; self.initializePluginService(); diff --git a/plugins/pencilblue/controllers/admin/themes/manage_themes.js b/plugins/pencilblue/controllers/admin/themes/manage_themes.js index 8fae5330a..57b9fcb11 100755 --- a/plugins/pencilblue/controllers/admin/themes/manage_themes.js +++ b/plugins/pencilblue/controllers/admin/themes/manage_themes.js @@ -34,9 +34,22 @@ module.exports = function(pb) { ManageThemes.prototype.render = function(cb) { var self = this; + var site = pb.SiteService.getCurrentSite(self.pathVars.siteid); + + pb.SiteService.siteExists(site, function (err, siteExists) { + if (siteExists) { + self.onSiteValidated(site, cb); + } + else { + self.reqHandler.serve404(); + } + }); + }; + + ManageThemes.prototype.onSiteValidated = function (site, cb) { + var self = this; //get plugs with themes - var site = pb.SiteService.getCurrentSite(self.pathVars.siteid); var sitePrefix = pb.SiteService.getCurrentSitePrefix(site); var pluginService = new pb.PluginService(site); pluginService.getPluginsWithThemesBySite(function (err, themes) { From 742e9cde74074a6271f9e5a8b7aa7beca18c41a2 Mon Sep 17 00:00:00 2001 From: Christina Chatham Date: Wed, 6 May 2015 16:34:44 -0400 Subject: [PATCH 078/790] Adding site id respect to google analytics plugin. --- plugins/ga/ga.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/ga/ga.js b/plugins/ga/ga.js index c2106ac64..98f7fade9 100755 --- a/plugins/ga/ga.js +++ b/plugins/ga/ga.js @@ -64,8 +64,8 @@ module.exports = function GoogleAnalyticsModule(pb) { * */ GoogleAnalytics.onRequest = function(req, session, ls, cb) { - - var pluginService = new pb.PluginService(); + var siteId = pb.RequestHandler.sites[req.headers.host]; + var pluginService = new pb.PluginService(pb.SiteService.getCurrentSite(siteId)); pluginService.getSettingsKV('ga', function(err, settings) { if (util.isError(err)) { return cb(err, ''); From 3ef38cbf2069ea188b4151dbaa11e3a477a946e5 Mon Sep 17 00:00:00 2001 From: andparker Date: Wed, 6 May 2015 16:56:05 -0400 Subject: [PATCH 079/790] Reverse execution order of initializePluginService and onSiteValidated functions. --- .../pencilblue/controllers/admin/plugins/plugin_settings.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/pencilblue/controllers/admin/plugins/plugin_settings.js b/plugins/pencilblue/controllers/admin/plugins/plugin_settings.js index f5c9c6bce..21a744352 100755 --- a/plugins/pencilblue/controllers/admin/plugins/plugin_settings.js +++ b/plugins/pencilblue/controllers/admin/plugins/plugin_settings.js @@ -52,8 +52,8 @@ module.exports = function(pb) { pb.SiteService.siteExists(site, function (err, siteExists) { if (siteExists) { - self.onSiteValidatedGet(cb); self.initializePluginService(); + self.onSiteValidatedGet(cb); } else { self.reqHandler.serve404(); @@ -145,8 +145,8 @@ module.exports = function(pb) { pb.SiteService.siteExists(site, function (err, siteExists) { if (siteExists) { - self.onSiteValidatedPost(cb); self.initializePluginService(); + self.onSiteValidatedPost(cb); } else { self.reqHandler.serve404(); From 5c77755f6c90056a528be21909ce79a11517d4ed Mon Sep 17 00:00:00 2001 From: Eugene Chang Date: Thu, 7 May 2015 09:19:55 -0400 Subject: [PATCH 080/790] Plugin settings refactor --- .../admin/plugins/plugin_settings.js | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/plugins/pencilblue/controllers/admin/plugins/plugin_settings.js b/plugins/pencilblue/controllers/admin/plugins/plugin_settings.js index 21a744352..be07c1486 100755 --- a/plugins/pencilblue/controllers/admin/plugins/plugin_settings.js +++ b/plugins/pencilblue/controllers/admin/plugins/plugin_settings.js @@ -41,18 +41,18 @@ module.exports = function(pb) { //statics var SUB_NAV_KEY = 'plugin_settings'; - PluginSettingsFormController.prototype.initializePluginService = function initializePluginService() { - this.site = pb.SiteService.getCurrentSite(this.pathVars.siteid); - this.pluginService = new pb.PluginService(this.site); - }; + PluginSettingsFormController.prototype.init = function (props, cb) { + this.pathSiteUId = pb.SiteService.getCurrentSite(props.path_vars.siteid); + this.pluginService = new pb.PluginService(this.pathSiteUId); + + pb.BaseController.prototype.init.call(this, props, cb); + }; PluginSettingsFormController.prototype.get = function(cb) { var self = this; - var site = pb.SiteService.getCurrentSite(self.pathVars.siteid); - pb.SiteService.siteExists(site, function (err, siteExists) { + pb.SiteService.siteExists(self.pathSiteUId, function (err, siteExists) { if (siteExists) { - self.initializePluginService(); self.onSiteValidatedGet(cb); } else { @@ -112,7 +112,7 @@ module.exports = function(pb) { } ]; - var prefix = pb.SiteService.getCurrentSitePrefix(self.site); + var prefix = pb.SiteService.getCurrentSitePrefix(self.pathSiteUId); //setup angular var data = { plugin: plugin, @@ -141,11 +141,9 @@ module.exports = function(pb) { PluginSettingsFormController.prototype.post = function(cb) { var self = this; - var site = pb.SiteService.getCurrentSite(self.pathVars.siteid); - pb.SiteService.siteExists(site, function (err, siteExists) { + pb.SiteService.siteExists(self.pathSiteUId, function (err, siteExists) { if (siteExists) { - self.initializePluginService(); self.onSiteValidatedPost(cb); } else { @@ -159,7 +157,6 @@ module.exports = function(pb) { console.log(this.constructor.name); var post = this.body; - self.initializePluginService(); //retrieve settings var uid = this.pathVars.id; self.getSettings(uid, function(err, settings) {console.log(settings); From 447402765d3c09265ec06c24b3ce85c2c4c3d878 Mon Sep 17 00:00:00 2001 From: Eugene Chang Date: Thu, 7 May 2015 10:50:59 -0400 Subject: [PATCH 081/790] Updating services depended by nav to be site aware --- include/config.js | 5 +++ include/service/entities/section_service.js | 39 +++++++++++++------ include/service/entities/url_service.js | 4 ++ include/system/settings.js | 12 ++++++ .../admin/content/navigation/new_nav_item.js | 14 ++++--- 5 files changed, 57 insertions(+), 17 deletions(-) diff --git a/include/config.js b/include/config.js index 9578a9a5d..585b92ef2 100755 --- a/include/config.js +++ b/include/config.js @@ -267,6 +267,11 @@ var BASE_CONFIG = { spec: {created: ASC}, options: {} }, + { + collection: 'section', + spec: {name: ASC, site: ASC}, + options: {unique: true} + }, //plugin { diff --git a/include/service/entities/section_service.js b/include/service/entities/section_service.js index 0547fdaaf..c0181f1b7 100755 --- a/include/service/entities/section_service.js +++ b/include/service/entities/section_service.js @@ -26,8 +26,14 @@ module.exports = function SectionServiceModule(pb) { * Service for managing the site's navigation * @class SectionService * @constructor + * @param {String} site uid + * @param {Boolean} onlyThisSite should section service only return value set specifically by site rather than defaulting to global */ - function SectionService(){} + function SectionService(site, onlyThisSite) { + this.site = pb.SiteService.getCurrentSite(site); + this.settings = pb.SettingServiceFactory.getServiceBySite(this.site, onlyThisSite); + this.sitePrefix = pb.SiteService.getCurrentSitePrefix(this.site); + } /** * @@ -52,13 +58,13 @@ module.exports = function SectionServiceModule(pb) { * @param {String} activePill * @return {Array} */ - SectionService.getPillNavOptions = function(activePill) { + SectionService.getPillNavOptions = function(activePill, sitePrefix) { return [ { name: 'new_nav_item', title: '', icon: 'plus', - href: '/admin/content/navigation/new' + href: '/admin' + sitePrefix + '/content/navigation/new' } ]; }; @@ -71,6 +77,8 @@ module.exports = function SectionServiceModule(pb) { * @param {Function} cb */ SectionService.prototype.removeFromSectionMap = function(section, sectionMap, cb) { + var self = this; + if (!cb) { cb = sectionMap; sectionMap = null; @@ -88,12 +96,11 @@ module.exports = function SectionServiceModule(pb) { callback(null, sectionMap); } else { - pb.settings.get('section_map', callback); + self.settings.get('section_map', callback); } }; //retrieve map - var self = this; getSectionMap(sectionMap, function(err, sectionMap) { if (util.isError(err)) { cb(err, false); @@ -109,7 +116,7 @@ module.exports = function SectionServiceModule(pb) { //when the section map was not provided persist it back if (sectionMapWasNull) { - pb.settings.set('section_map', sectionMap, function(err, result) { + self.settings.set('section_map', sectionMap, function(err, result) { cb(err, orphans); }); } @@ -168,7 +175,7 @@ module.exports = function SectionServiceModule(pb) { //retrieve the section map var sid = section[pb.DAO.getIdField()].toString(); - pb.settings.get('section_map', function(err, sectionMap) { + self.settings.get('section_map', function(err, sectionMap) { if (util.isError(err)) { cb(err, false); return; @@ -198,7 +205,7 @@ module.exports = function SectionServiceModule(pb) { } } - pb.settings.set('section_map', sectionMap, cb); + self.settings.set('section_map', sectionMap, cb); }); }; @@ -225,12 +232,13 @@ module.exports = function SectionServiceModule(pb) { * @param {Function} cb */ SectionService.prototype.getFormattedSections = function(localizationService, currUrl, cb) { + var self = this; if (util.isFunction(currUrl)) { cb = currUrl; currUrl = null; } - pb.settings.get('section_map', function(err, sectionMap) { + self.settings.get('section_map', function(err, sectionMap) { if (util.isError(err) || sectionMap == null) { cb(err, []); return; @@ -238,7 +246,11 @@ module.exports = function SectionServiceModule(pb) { //retrieve sections var dao = new pb.DAO(); - dao.q('section', function(err, sections) { + var options = { + where: {} + }; + options.where[pb.SiteService.SITE_FIELD] = self.site; + dao.q('section', options, function(err, sections) { if (util.isError(err)) { return cb(err, []); } @@ -437,8 +449,9 @@ module.exports = function SectionServiceModule(pb) { } var where = { - name: navItem.name + name: navItem.name, }; + where[pb.SiteService.SITE_FIELD] = this.site; var dao = new pb.DAO(); dao.unique('section', where, navItem[pb.DAO.getIdField()], function(err, unique) { var error = null; @@ -502,7 +515,8 @@ module.exports = function SectionServiceModule(pb) { var params = { type: 'section', id: navItem[pb.DAO.getIdField()], - url: navItem.url + url: navItem.url, + site: self.site }; var urlService = new pb.UrlService(); urlService.existsForType(params, function(err, exists) { @@ -646,6 +660,7 @@ module.exports = function SectionServiceModule(pb) { //persist the changes var dao = new pb.DAO(); + navItem[pb.SiteService.SITE_FIELD] = self.site; dao.save(navItem, function(err, data) { if(util.isError(err)) { return cb(err); diff --git a/include/service/entities/url_service.js b/include/service/entities/url_service.js index caa47eeeb..f13b42d49 100755 --- a/include/service/entities/url_service.js +++ b/include/service/entities/url_service.js @@ -71,6 +71,7 @@ module.exports = function UrlServiceModule(pb) { var url = params.url; var type = params.type; var id = params.id; + var site = params.site; //validate required params if (!url || !type) { @@ -91,6 +92,9 @@ module.exports = function UrlServiceModule(pb) { var where = { url: new RegExp(pattern, 'g') }; + if (site !== undefined) { + where[pb.SiteService.SITE_FIELD] = site; + } var dao = new pb.DAO(); dao.unique(type, where, id, function(err, isUnique) { cb(err, !isUnique); diff --git a/include/system/settings.js b/include/system/settings.js index 9f368bb33..9072611f8 100755 --- a/include/system/settings.js +++ b/include/system/settings.js @@ -36,6 +36,18 @@ module.exports = function SettingsModule(pb) { */ var count = 1; + /** + * Creates a new instance of settings service with specified site, using the memory and cache settings of pb config + * + * @static + * @method getServiceBySite + * @param {String} site + * @param {Boolean} onlyThisSite + */ + SettingServiceFactory.getServiceBySite = function (site, onlyThisSite) { + return SettingServiceFactory.getService(pb.config.settings.use_memory, pb.config.settings.use_cache, site, onlyThisSite); + }; + /** * Creates a new instance of the settings service * @static diff --git a/plugins/pencilblue/controllers/actions/admin/content/navigation/new_nav_item.js b/plugins/pencilblue/controllers/actions/admin/content/navigation/new_nav_item.js index 989c313f3..0db632e2b 100644 --- a/plugins/pencilblue/controllers/actions/admin/content/navigation/new_nav_item.js +++ b/plugins/pencilblue/controllers/actions/admin/content/navigation/new_nav_item.js @@ -26,6 +26,12 @@ module.exports = function(pb) { function NewNavItem(){} util.inherits(NewNavItem, pb.BaseController); + NewNavItem.prototype.init = function (props, cb) { + this.pathSiteUId = pb.SiteService.getCurrentSite(props.path_vars.siteid); + this.navService = new pb.SectionService(this.pathSiteUId, true); + pb.BaseController.prototype.init.call(this, cb); + }; + NewNavItem.prototype.render = function(cb){ var self = this; @@ -39,11 +45,10 @@ module.exports = function(pb) { } //strip unneeded properties - pb.SectionService.trimForType(navItem); + self.navService.trimForType(navItem); //validate - var navService = new pb.SectionService(); - navService.save(navItem, function(err, result) { + self.navService.save(navItem, function(err, result) { if(util.isError(err)) { cb({ code: 500, @@ -67,8 +72,7 @@ module.exports = function(pb) { }; NewNavItem.prototype.checkForNavMapUpdate = function(navItem, cb) { - var service = new pb.SectionService(); - service.updateNavMap(navItem, cb); + self.navService.updateNavMap(navItem, cb); }; NewNavItem.getHtmlErrorMsg = function(validationErrors) { From 6ae20c6e81803995bac855fe27c33f1d64ec4635 Mon Sep 17 00:00:00 2001 From: Eugene Chang Date: Thu, 7 May 2015 11:05:48 -0400 Subject: [PATCH 082/790] Fixing nav item --- .../actions/admin/content/navigation/new_nav_item.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/pencilblue/controllers/actions/admin/content/navigation/new_nav_item.js b/plugins/pencilblue/controllers/actions/admin/content/navigation/new_nav_item.js index 0db632e2b..8d9b3b995 100644 --- a/plugins/pencilblue/controllers/actions/admin/content/navigation/new_nav_item.js +++ b/plugins/pencilblue/controllers/actions/admin/content/navigation/new_nav_item.js @@ -29,7 +29,7 @@ module.exports = function(pb) { NewNavItem.prototype.init = function (props, cb) { this.pathSiteUId = pb.SiteService.getCurrentSite(props.path_vars.siteid); this.navService = new pb.SectionService(this.pathSiteUId, true); - pb.BaseController.prototype.init.call(this, cb); + pb.BaseController.prototype.init.call(this, props, cb); }; NewNavItem.prototype.render = function(cb){ @@ -45,7 +45,7 @@ module.exports = function(pb) { } //strip unneeded properties - self.navService.trimForType(navItem); + pb.SectionService.trimForType(navItem); //validate self.navService.save(navItem, function(err, result) { @@ -72,7 +72,7 @@ module.exports = function(pb) { }; NewNavItem.prototype.checkForNavMapUpdate = function(navItem, cb) { - self.navService.updateNavMap(navItem, cb); + this.navService.updateNavMap(navItem, cb); }; NewNavItem.getHtmlErrorMsg = function(validationErrors) { From 9c56ad210967088137805487298494bda18a7237 Mon Sep 17 00:00:00 2001 From: Eugene Chang Date: Thu, 7 May 2015 13:36:03 -0400 Subject: [PATCH 083/790] Adding site awareness to nav map. --- .../admin/content/navigation/nav_item_form.js | 21 ++++++++++++--- .../admin/content/navigation/nav_map.js | 26 +++++++++++++------ .../content/navigation/nav_item_form.html | 2 +- .../admin/content/navigation/nav_map.html | 2 +- 4 files changed, 37 insertions(+), 14 deletions(-) diff --git a/plugins/pencilblue/controllers/admin/content/navigation/nav_item_form.js b/plugins/pencilblue/controllers/admin/content/navigation/nav_item_form.js index 92efc5334..569ad68da 100644 --- a/plugins/pencilblue/controllers/admin/content/navigation/nav_item_form.js +++ b/plugins/pencilblue/controllers/admin/content/navigation/nav_item_form.js @@ -33,6 +33,13 @@ module.exports = function(pb) { } util.inherits(NavItemFormController, pb.BaseController); + NavItemFormController.prototype.init = function (props, cb) { + this.pathSiteUId = pb.SiteService.getCurrentSite(props.path_vars.siteid); + this.navService = new pb.SectionService(this.pathSiteUId, true); + this.sitePrefix = pb.SiteService.getCurrentSitePrefix(this.pathSiteUId); + pb.BaseController.prototype.init.call(this, props, cb); + }; + //statics var SUB_NAV_KEY = 'nav_item_form'; @@ -54,7 +61,12 @@ module.exports = function(pb) { var contentSearchValue = self.navItem.contentSearchValue ? self.navItem.contentSearchValue.toString() : ''; delete self.navItem.contentSearchValue; - data.pills = pb.AdminSubnavService.get(self.getSubnavKey(), self.ls, self.getSubnavKey(), self.navItem); + var navData = { + item: self.navItem, + sitePrefix: self.sitePrefix + }; + data.pills = pb.AdminSubnavService.get(self.getSubnavKey(), self.ls, self.getSubnavKey(), navData); + data.sitePrefix = self.sitePrefix; var angularObjects = pb.ClientJs.getAngularObjects(data); self.setPageName(self.navItem[pb.DAO.getIdField()] ? self.navItem.name : self.ls.get('NEW_NAV_ITEM')); @@ -147,13 +159,14 @@ module.exports = function(pb) { }; NavItemFormController.getSubNavItems = function(key, ls, data) { - var pills = SectionService.getPillNavOptions(); + var item = data.item; + var pills = SectionService.getPillNavOptions(null, data.sitePrefix); pills.unshift( { name: 'manage_nav_items', - title: data[pb.DAO.getIdField()] ? ls.get('EDIT') + ' ' + data.name : ls.get('NEW_NAV_ITEM'), + title: item[pb.DAO.getIdField()] ? ls.get('EDIT') + ' ' + item.name : ls.get('NEW_NAV_ITEM'), icon: 'chevron-left', - href: '/admin/content/navigation' + href: '/admin' + data.sitePrefix + '/content/navigation' }); return pills; }; diff --git a/plugins/pencilblue/controllers/admin/content/navigation/nav_map.js b/plugins/pencilblue/controllers/admin/content/navigation/nav_map.js index 0a0100e05..5c39b2260 100644 --- a/plugins/pencilblue/controllers/admin/content/navigation/nav_map.js +++ b/plugins/pencilblue/controllers/admin/content/navigation/nav_map.js @@ -20,13 +20,21 @@ module.exports = function(pb) { //pb dependencies var util = pb.util; var SectionService = pb.SectionService; - + var SiteService = pb.SiteService; + /** * Interface for editing the navigation */ function NavigationMap(){} util.inherits(NavigationMap, pb.BaseController); + NavigationMap.prototype.init = function (props, cb) { + this.pathSiteUId = pb.SiteService.getCurrentSite(props.path_vars.siteid); + this.navService = new pb.SectionService(this.pathSiteUId, true); + this.sitePrefix = pb.SiteService.getCurrentSitePrefix(this.pathSiteUId); + pb.BaseController.prototype.init.call(this, props, cb); + }; + //statics var SUB_NAV_KEY = 'navigation_map'; @@ -34,8 +42,9 @@ module.exports = function(pb) { var self = this; var opts = { - where: pb.DAO.ANYWHERE + where: {} }; + opts.where[SiteService.SITE_FIELD] = self.pathSiteUId; var dao = new pb.DAO(); dao.q('section', opts, function(err, sections) { if (util.isError(err)) { @@ -44,19 +53,19 @@ module.exports = function(pb) { else if(sections.length === 0) { //when no sections exist redirect to create page - return self.redirect('/admin/content/navigation/new', cb); + return self.redirect('/admin' + self.sitePrefix + '/content/navigation/new', cb); } pb.settings.get('section_map', function(err, sectionMap) { if(sectionMap === null) { - self.redirect('/admin/content/navigation/new', cb); + self.redirect('/admin' + self.sitePrefix + '/content/navigation/new', cb); return; } var angularObjects = pb.ClientJs.getAngularObjects( { navigation: pb.AdminNavigation.get(self.session, ['content', 'sections'], self.ls), - pills: pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, SUB_NAV_KEY), + pills: pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, SUB_NAV_KEY, {sitePrefix: self.sitePrefix}), navItems: NavigationMap.getOrderedItems(sections, sectionMap), icons: { container: 'inbox', @@ -64,7 +73,8 @@ module.exports = function(pb) { article: 'files-o', page: 'file-o', link: 'link' - } + }, + sitePrefix: self.sitePrefix } ); @@ -118,13 +128,13 @@ module.exports = function(pb) { }; NavigationMap.getSubNavItems = function(key, ls, data) { - var pills = SectionService.getPillNavOptions(); + var pills = SectionService.getPillNavOptions(null, data.sitePrefix); pills.unshift( { name: SUB_NAV_KEY, title: ls.get('NAV_MAP'), icon: 'refresh', - href: '/admin/content/navigation' + href: '/admin' + data.sitePrefix + '/content/navigation' }); return pills; }; diff --git a/plugins/pencilblue/templates/angular/admin/content/navigation/nav_item_form.html b/plugins/pencilblue/templates/angular/admin/content/navigation/nav_item_form.html index 94c0fa94f..17690c729 100644 --- a/plugins/pencilblue/templates/angular/admin/content/navigation/nav_item_form.html +++ b/plugins/pencilblue/templates/angular/admin/content/navigation/nav_item_form.html @@ -27,7 +27,7 @@ var saveObject = $scope.getSaveObject(); $scope.saving = true; - $http.post('/actions/admin/content/navigation' + ($scope.navItem._id ? '/' + $scope.navItem._id : ''), saveObject) + $http.post('/actions/admin' + $scope.sitePrefix + '/content/navigation' + ($scope.navItem._id ? '/' + $scope.navItem._id : ''), saveObject) .success(function(result) { $scope.successMessage = result.message; $scope.saving = false; diff --git a/plugins/pencilblue/templates/angular/admin/content/navigation/nav_map.html b/plugins/pencilblue/templates/angular/admin/content/navigation/nav_map.html index f9eda3be8..3199e1e31 100644 --- a/plugins/pencilblue/templates/angular/admin/content/navigation/nav_map.html +++ b/plugins/pencilblue/templates/angular/admin/content/navigation/nav_map.html @@ -36,7 +36,7 @@ } $scope.saving = true; - $http.post('/actions/admin/content/navigation/map', {map: navMap}) + $http.post('/actions/admin' + $scope.sitePrefix + '/content/navigation/map', {map: navMap}) .success(function(result) { $scope.successMessage = result.message; $scope.saving = false; From 847af73d4a93f0bf9b5e835bb047d3458f337715 Mon Sep 17 00:00:00 2001 From: Eugene Chang Date: Thu, 7 May 2015 13:47:41 -0400 Subject: [PATCH 084/790] Setup proper multi-tenant rendering of navigation for pencilblue (for other themes, pass in site: in options when getting top menu) --- include/theme/top_menu.js | 9 ++++++--- plugins/pencilblue/controllers/index.js | 3 ++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/include/theme/top_menu.js b/include/theme/top_menu.js index 07aa0b70e..af193abe9 100755 --- a/include/theme/top_menu.js +++ b/include/theme/top_menu.js @@ -43,7 +43,7 @@ module.exports = function TopMenuServiceModule(pb) { * @param {Localization} localizationService An instance of Localization to * translate default items * @param {Object} [options] An optional argument to provide more flexibility - * to the menu construction. + * to the menu construction. (pass in site: siteUId to select the proper tenant) * @param {String} [options.currUrl] The current request URL. * @param {Function} cb Callback function that takes three parameters. The * first are the theme's settings, the second is the navigation structure, and @@ -60,16 +60,19 @@ module.exports = function TopMenuServiceModule(pb) { throw new Error('The options parameter must be an object'); } + var siteUId = pb.SiteService.getCurrentSite(options.site); + var getTopMenu = function(session, localizationService, options, cb) { var tasks = { themeSettings: function(callback) { - pb.settings.get('site_logo', function(err, logo) { + var settingService = pb.SettingServiceFactory.getService(siteUId); + settingService.get('site_logo', function(err, logo) { callback(null, {site_logo: logo}); }); }, formattedSections: function(callback) { - var sectionService = new SectionService(); + var sectionService = new SectionService(siteUId); sectionService.getFormattedSections(localizationService, options.currUrl, function(err, formattedSections) { callback(null, formattedSections); }); diff --git a/plugins/pencilblue/controllers/index.js b/plugins/pencilblue/controllers/index.js index 169cc78d1..7a8bd0aa9 100755 --- a/plugins/pencilblue/controllers/index.js +++ b/plugins/pencilblue/controllers/index.js @@ -378,7 +378,8 @@ module.exports = function IndexModule(pb) { Index.prototype.getNavigation = function(cb) { var options = { - currUrl: this.req.url + currUrl: this.req.url, + site: this.site }; TopMenu.getTopMenu(this.session, this.ls, options, function(themeSettings, navigation, accountButtons) { TopMenu.getBootstrapNav(navigation, accountButtons, function(navigation, accountButtons) { From a5549b9474b05ee8b2143622b088c187f3e728e6 Mon Sep 17 00:00:00 2001 From: Eugene Chang Date: Thu, 7 May 2015 13:52:04 -0400 Subject: [PATCH 085/790] Fixing links on navigation map to be site aware --- .../templates/admin/content/navigation/nav_map.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/pencilblue/templates/admin/content/navigation/nav_map.html b/plugins/pencilblue/templates/admin/content/navigation/nav_map.html index fbeec278e..1bc6c912d 100644 --- a/plugins/pencilblue/templates/admin/content/navigation/nav_map.html +++ b/plugins/pencilblue/templates/admin/content/navigation/nav_map.html @@ -7,7 +7,7 @@
- + @@ -21,7 +21,7 @@
- + @@ -35,7 +35,7 @@
- +  ^loc_CANCEL^
- +  ^loc_CANCEL^ ^tmp_admin=elements=save_button^ From 2f5d4454201b9fca791ad8945a88bc3586b5db74 Mon Sep 17 00:00:00 2001 From: btidwell Date: Thu, 7 May 2015 15:19:44 -0400 Subject: [PATCH 087/790] Change icon for sites, add subnav for selected sites on articles pages --- include/admin_navigation.js | 2 +- include/service/admin/admin_subnav_service.js | 19 +++++++ .../admin/content/articles/article_form.js | 49 ++++++++++--------- .../admin/content/articles/manage_articles.js | 34 ++++++++----- 4 files changed, 68 insertions(+), 36 deletions(-) diff --git a/include/admin_navigation.js b/include/admin_navigation.js index f99b935ff..cc39f8c18 100755 --- a/include/admin_navigation.js +++ b/include/admin_navigation.js @@ -63,7 +63,7 @@ module.exports = function AdminNavigationModule(pb) { { id: 'site_entity', title: 'MANAGE_SITES', - icon: 'cogs', + icon: 'sitemap', href: '/admin/sites', access: SecurityService.ACCESS_ADMINISTRATOR diff --git a/include/service/admin/admin_subnav_service.js b/include/service/admin/admin_subnav_service.js index bc36ccf34..130306a1f 100755 --- a/include/service/admin/admin_subnav_service.js +++ b/include/service/admin/admin_subnav_service.js @@ -129,6 +129,25 @@ module.exports = function AdminSubnavServiceModule(pb) { return navItems; }; + AdminSubnavService.getWithSite = function(site, key, ls, activePill, cb, data) { + if(!data) { data = {site: site } } + else if(!data.site) { data.site = site; } + + new pb.SiteService().getSiteNameByUid(site, function(siteName) { + var pills = []; + if (siteName) { + pills.push({ + name: 'selected_site', + title: siteName, + icon: 'sitemap', + href: '/admin/sites' + }); + } + pills = pills.concat(AdminSubnavService.get(key, ls, activePill, data)); + cb(pills); + }); + }; + //exports return AdminSubnavService; }; diff --git a/plugins/pencilblue/controllers/admin/content/articles/article_form.js b/plugins/pencilblue/controllers/admin/content/articles/article_form.js index b2a9bfc7b..0265210a4 100755 --- a/plugins/pencilblue/controllers/admin/content/articles/article_form.js +++ b/plugins/pencilblue/controllers/admin/content/articles/article_form.js @@ -69,13 +69,15 @@ module.exports = function(pb) { self.setPageName(self.article[pb.DAO.getIdField()] ? self.article.headline : self.ls.get('NEW_ARTICLE')); self.ts.registerLocal('angular_script', ''); - self.ts.registerLocal('angular_objects', new pb.TemplateValue(self.getAngularObjects(tabs, results), false)); - self.ts.load('admin/content/articles/article_form', function(err, data) { - self.onTemplateRetrieved('' + data, function(err, data) { - var result = '' + data; - self.checkForFormRefill(result, function(newResult) { - result = newResult; - cb({content: result}); + self.getAngularObjects(tabs, results, function(angularObjects) { + self.ts.registerLocal('angular_objects', new pb.TemplateValue(angularObjects, false)); + self.ts.load('admin/content/articles/article_form', function(err, data) { + self.onTemplateRetrieved('' + data, function(err, data) { + var result = '' + data; + self.checkForFormRefill(result, function(newResult) { + result = newResult; + cb({content: result}); + }); }); }); }); @@ -85,7 +87,8 @@ module.exports = function(pb) { cb(null, template); }; - ArticleForm.prototype.getAngularObjects = function(tabs, data) { + ArticleForm.prototype.getAngularObjects = function(tabs, data, cb) { + var self = this; if(pb.config.multisite && !data.article.site) { data.article.site = pb.SiteService.getCurrentSite(this.pathVars.siteid); } @@ -129,20 +132,22 @@ module.exports = function(pb) { data.article.article_topics = topics; } - var objects = { - navigation: pb.AdminNavigation.get(this.session, ['content', 'articles'], this.ls), - pills: pb.AdminSubnavService.get(this.getActivePill(), this.ls, this.getActivePill(), data), - tabs: tabs, - templates: data.templates, - sections: data.sections, - topics: data.topics, - media: data.media, - article: data.article - }; - if(data.availableAuthors) { - objects.availableAuthors = data.availableAuthors; - } - return pb.ClientJs.getAngularObjects(objects); + pb.AdminSubnavService.getWithSite(data.article.site, this.getActivePill(), this.ls, this.getActivePill(), function(pills) { + var objects = { + navigation: pb.AdminNavigation.get(self.session, ['content', 'articles'], self.ls), + pills: pills, + tabs: tabs, + templates: data.templates, + sections: data.sections, + topics: data.topics, + media: data.media, + article: data.article + }; + if(data.availableAuthors) { + objects.availableAuthors = data.availableAuthors; + } + cb(pb.ClientJs.getAngularObjects(objects)); + }, data); }; ArticleForm.getSubNavItems = function(key, ls, data) { diff --git a/plugins/pencilblue/controllers/admin/content/articles/manage_articles.js b/plugins/pencilblue/controllers/admin/content/articles/manage_articles.js index f1dd02b3f..fac4056e9 100755 --- a/plugins/pencilblue/controllers/admin/content/articles/manage_articles.js +++ b/plugins/pencilblue/controllers/admin/content/articles/manage_articles.js @@ -54,19 +54,14 @@ module.exports = function(pb) { pb.users.getAuthors(articles, function(err, articlesWithAuthorNames) { articles = self.getArticleStatuses(articlesWithAuthorNames); - var angularObjects = pb.ClientJs.getAngularObjects( - { - navigation: pb.AdminNavigation.get(self.session, ['content', 'articles'], self.ls), - pills: pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, SUB_NAV_KEY, {site: siteid}), - articles: articles - }); - - var manageArticlesStr = self.ls.get('MANAGE_ARTICLES'); - self.setPageName(manageArticlesStr); - self.ts.registerLocal('angular_objects', new pb.TemplateValue(angularObjects, false)); - self.ts.load('admin/content/articles/manage_articles', function(err, data) { - var result = '' + data; - cb({content: result}); + self.getAngularObjects(siteid, articles, function (angularObjects) { + var manageArticlesStr = self.ls.get('MANAGE_ARTICLES'); + self.setPageName(manageArticlesStr); + self.ts.registerLocal('angular_objects', new pb.TemplateValue(angularObjects, false)); + self.ts.load('admin/content/articles/manage_articles', function (err, data) { + var result = '' + data; + cb({content: result}); + }); }); }); }); @@ -89,6 +84,19 @@ module.exports = function(pb) { return articles; }; + ManageArticles.prototype.getAngularObjects = function(siteid, articles, cb) { + var self = this; + pb.AdminSubnavService.getWithSite(siteid, SUB_NAV_KEY, self.ls, SUB_NAV_KEY, function(pills) { + var angularObjects = pb.ClientJs.getAngularObjects( + { + navigation: pb.AdminNavigation.get(self.session, ['content', 'articles'], self.ls), + pills: pills, + articles: articles + }); + cb(angularObjects); + }); + }; + ManageArticles.getSubNavItems = function(key, ls, data) { var adminPrefix = '/admin'; if(data.site) { From 80b62994a63b21fea7818fc315e5e54af32bed24 Mon Sep 17 00:00:00 2001 From: btidwell Date: Thu, 7 May 2015 15:24:15 -0400 Subject: [PATCH 088/790] Add selected site subnav to "manage pages" page --- .../admin/content/pages/manage_pages.js | 34 ++++++++++++------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/plugins/pencilblue/controllers/admin/content/pages/manage_pages.js b/plugins/pencilblue/controllers/admin/content/pages/manage_pages.js index 4977666f8..a2fbdf7fa 100755 --- a/plugins/pencilblue/controllers/admin/content/pages/manage_pages.js +++ b/plugins/pencilblue/controllers/admin/content/pages/manage_pages.js @@ -47,19 +47,14 @@ module.exports = function(pb) { } pb.users.getAuthors(pages, function(err, pagesWithAuthor) { - var angularObjects = pb.ClientJs.getAngularObjects( - { - navigation: pb.AdminNavigation.get(self.session, ['content', 'pages'], self.ls), - pills: pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, 'manage_pages', {site: siteid}), - pages: self.getPageStatuses(pagesWithAuthor) - }); - - var title = self.ls.get('MANAGE_PAGES'); - self.setPageName(title); - self.ts.registerLocal('angular_objects', new pb.TemplateValue(angularObjects, false)); - self.ts.load('admin/content/pages/manage_pages', function(err, data) { - var result = '' + data; - cb({content: result}); + self.getAngularObjects(siteid, pagesWithAuthor, function(angularObjects) { + var title = self.ls.get('MANAGE_PAGES'); + self.setPageName(title); + self.ts.registerLocal('angular_objects', new pb.TemplateValue(angularObjects, false)); + self.ts.load('admin/content/pages/manage_pages', function(err, data) { + var result = '' + data; + cb({content: result}); + }); }); }); }); @@ -82,6 +77,19 @@ module.exports = function(pb) { return pages; }; + ManagePages.prototype.getAngularObjects = function(site, pagesWithAuthor, cb) { + var self = this; + pb.AdminSubnavService.getWithSite(site, SUB_NAV_KEY, self.ls, 'manage_pages', function(pills) { + var angularObjects = pb.ClientJs.getAngularObjects({ + navigation: pb.AdminNavigation.get(self.session, ['content', 'pages'], self.ls), + pills: pills, + pages: self.getPageStatuses(pagesWithAuthor) + }); + cb(angularObjects); + }); + + }; + ManagePages.getSubNavItems = function(key, ls, data) { var adminPrefix = '/admin'; if(data.site) { From 57b544653a3e1efa65ec011486c518a4a6b08b05 Mon Sep 17 00:00:00 2001 From: btidwell Date: Thu, 7 May 2015 15:30:29 -0400 Subject: [PATCH 089/790] Add selected site subnav item to "page form" --- .../admin/content/pages/page_form.js | 49 ++++++++++--------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/plugins/pencilblue/controllers/admin/content/pages/page_form.js b/plugins/pencilblue/controllers/admin/content/pages/page_form.js index a333c6ac4..3e496fa84 100755 --- a/plugins/pencilblue/controllers/admin/content/pages/page_form.js +++ b/plugins/pencilblue/controllers/admin/content/pages/page_form.js @@ -68,12 +68,15 @@ module.exports = function(pb) { var tabs = self.getTabs(); self.setPageName(self.page[pb.DAO.getIdField()] ? self.page.headline : self.ls.get('NEW_PAGE')); - self.ts.registerLocal('angular_objects', new pb.TemplateValue(self.getAngularObjects(tabs, results), false)); - self.ts.load('admin/content/pages/page_form', function(err, data) { - var result = data; - self.checkForFormRefill(result, function(newResult) { - result = newResult; - cb({content: result}); + + self.getAngularObjects(tabs, results, function(angularObjects) { + self.ts.registerLocal('angular_objects', new pb.TemplateValue(angularObjects, false)); + self.ts.load('admin/content/pages/page_form', function(err, data) { + var result = data; + self.checkForFormRefill(result, function(newResult) { + result = newResult; + cb({content: result}); + }); }); }); }; @@ -83,7 +86,8 @@ module.exports = function(pb) { * @method getAngularObjects * */ - PageFormController.prototype.getAngularObjects = function(tabs, data) { + PageFormController.prototype.getAngularObjects = function(tabs, data, cb) { + var self = this; if(pb.config.multisite && !data.page.site) { data.page.site = pb.SiteService.getCurrentSite(this.pathVars.siteid); } @@ -114,21 +118,22 @@ module.exports = function(pb) { } data.page.page_topics = topics; } - - var objects = { - navigation: pb.AdminNavigation.get(this.session, ['content', 'pages'], this.ls), - pills: pb.AdminSubnavService.get(this.getActivePill(), this.ls, this.getActivePill(), data), - tabs: tabs, - templates: data.templates, - sections: data.sections, - topics: data.topics, - media: data.media, - page: data.page - }; - if(data.availableAuthors) { - objects.availableAuthors = data.availableAuthors; - } - return pb.ClientJs.getAngularObjects(objects); + pb.AdminSubnavService.getWithSite(data.page.site, this.getActivePill(), this.ls, this.getActivePill(), function(pills) { + var objects = { + navigation: pb.AdminNavigation.get(self.session, ['content', 'pages'], self.ls), + pills: pills, + tabs: tabs, + templates: data.templates, + sections: data.sections, + topics: data.topics, + media: data.media, + page: data.page + }; + if(data.availableAuthors) { + objects.availableAuthors = data.availableAuthors; + } + cb(pb.ClientJs.getAngularObjects(objects)); + }, data); }; /** From 781b258a6d5a8b75713595d1c178c718afde17af Mon Sep 17 00:00:00 2001 From: btidwell Date: Thu, 7 May 2015 16:13:42 -0400 Subject: [PATCH 090/790] update getWithSite to always require data parameter with site field --- include/service/admin/admin_subnav_service.js | 48 ++++++++++++------- .../admin/content/articles/article_form.js | 6 +-- .../admin/content/articles/manage_articles.js | 4 +- .../admin/content/pages/manage_pages.js | 2 +- .../admin/content/pages/page_form.js | 5 +- 5 files changed, 41 insertions(+), 24 deletions(-) diff --git a/include/service/admin/admin_subnav_service.js b/include/service/admin/admin_subnav_service.js index 130306a1f..4f98b413d 100755 --- a/include/service/admin/admin_subnav_service.js +++ b/include/service/admin/admin_subnav_service.js @@ -129,23 +129,39 @@ module.exports = function AdminSubnavServiceModule(pb) { return navItems; }; - AdminSubnavService.getWithSite = function(site, key, ls, activePill, cb, data) { - if(!data) { data = {site: site } } - else if(!data.site) { data.site = site; } - - new pb.SiteService().getSiteNameByUid(site, function(siteName) { - var pills = []; - if (siteName) { - pills.push({ - name: 'selected_site', - title: siteName, - icon: 'sitemap', - href: '/admin/sites' - }); + /** + * Retrieves the sub-nav items with selcted site + * @static + * @method getWithSite + * @param {String} key The key to retrieve + * @param {Object} ls The localization object + * @param {String} activePill The name of the active sub-nav pill + * @param {Object} [data] Data object to send to the callback function (Must include field named "site") + * @param {Function} cb Yields resulting subnav items + */ + AdminSubnavService.getWithSite = function(key, ls, activePill, data, cb) { + var standardPills = AdminSubnavService.get(key, ls, activePill, data); + if(pb.config.multisite) { + if(!data || !data.site) { + throw new Error('Data must include a field named "site"'); } - pills = pills.concat(AdminSubnavService.get(key, ls, activePill, data)); - cb(pills); - }); + new pb.SiteService().getSiteNameByUid(data.site, function(siteName) { + var pills = []; + if (siteName) { + pills.push({ + name: 'selected_site', + title: siteName, + icon: 'sitemap', + href: '/admin/sites' + }); + } + pills = pills.concat(standardPills); + cb(pills); + }); + } + else { + cb(standardPills); + } }; //exports diff --git a/plugins/pencilblue/controllers/admin/content/articles/article_form.js b/plugins/pencilblue/controllers/admin/content/articles/article_form.js index 0265210a4..14b5c7628 100755 --- a/plugins/pencilblue/controllers/admin/content/articles/article_form.js +++ b/plugins/pencilblue/controllers/admin/content/articles/article_form.js @@ -131,8 +131,8 @@ module.exports = function(pb) { } data.article.article_topics = topics; } - - pb.AdminSubnavService.getWithSite(data.article.site, this.getActivePill(), this.ls, this.getActivePill(), function(pills) { + data.site = data.article.site; + pb.AdminSubnavService.getWithSite(this.getActivePill(), this.ls, this.getActivePill(), data, function(pills) { var objects = { navigation: pb.AdminNavigation.get(self.session, ['content', 'articles'], self.ls), pills: pills, @@ -147,7 +147,7 @@ module.exports = function(pb) { objects.availableAuthors = data.availableAuthors; } cb(pb.ClientJs.getAngularObjects(objects)); - }, data); + }); }; ArticleForm.getSubNavItems = function(key, ls, data) { diff --git a/plugins/pencilblue/controllers/admin/content/articles/manage_articles.js b/plugins/pencilblue/controllers/admin/content/articles/manage_articles.js index fac4056e9..eee82d539 100755 --- a/plugins/pencilblue/controllers/admin/content/articles/manage_articles.js +++ b/plugins/pencilblue/controllers/admin/content/articles/manage_articles.js @@ -84,9 +84,9 @@ module.exports = function(pb) { return articles; }; - ManageArticles.prototype.getAngularObjects = function(siteid, articles, cb) { + ManageArticles.prototype.getAngularObjects = function(site, articles, cb) { var self = this; - pb.AdminSubnavService.getWithSite(siteid, SUB_NAV_KEY, self.ls, SUB_NAV_KEY, function(pills) { + pb.AdminSubnavService.getWithSite(SUB_NAV_KEY, self.ls, SUB_NAV_KEY, {site: site}, function(pills) { var angularObjects = pb.ClientJs.getAngularObjects( { navigation: pb.AdminNavigation.get(self.session, ['content', 'articles'], self.ls), diff --git a/plugins/pencilblue/controllers/admin/content/pages/manage_pages.js b/plugins/pencilblue/controllers/admin/content/pages/manage_pages.js index a2fbdf7fa..2d187d58f 100755 --- a/plugins/pencilblue/controllers/admin/content/pages/manage_pages.js +++ b/plugins/pencilblue/controllers/admin/content/pages/manage_pages.js @@ -79,7 +79,7 @@ module.exports = function(pb) { ManagePages.prototype.getAngularObjects = function(site, pagesWithAuthor, cb) { var self = this; - pb.AdminSubnavService.getWithSite(site, SUB_NAV_KEY, self.ls, 'manage_pages', function(pills) { + pb.AdminSubnavService.getWithSite(SUB_NAV_KEY, self.ls, 'manage_pages', {site: site}, function(pills) { var angularObjects = pb.ClientJs.getAngularObjects({ navigation: pb.AdminNavigation.get(self.session, ['content', 'pages'], self.ls), pills: pills, diff --git a/plugins/pencilblue/controllers/admin/content/pages/page_form.js b/plugins/pencilblue/controllers/admin/content/pages/page_form.js index 3e496fa84..d6dbe96ba 100755 --- a/plugins/pencilblue/controllers/admin/content/pages/page_form.js +++ b/plugins/pencilblue/controllers/admin/content/pages/page_form.js @@ -118,7 +118,8 @@ module.exports = function(pb) { } data.page.page_topics = topics; } - pb.AdminSubnavService.getWithSite(data.page.site, this.getActivePill(), this.ls, this.getActivePill(), function(pills) { + data.site = data.page.site; + pb.AdminSubnavService.getWithSite(this.getActivePill(), this.ls, this.getActivePill(), data, function(pills) { var objects = { navigation: pb.AdminNavigation.get(self.session, ['content', 'pages'], self.ls), pills: pills, @@ -133,7 +134,7 @@ module.exports = function(pb) { objects.availableAuthors = data.availableAuthors; } cb(pb.ClientJs.getAngularObjects(objects)); - }, data); + }); }; /** From 930be8d4f80262bcb867ed17afcb1425242e9e91 Mon Sep 17 00:00:00 2001 From: Eugene Chang Date: Thu, 7 May 2015 17:41:21 -0400 Subject: [PATCH 091/790] Creating SiteQueryService, refactoring sector service to use it, and changing articles so that it only pulls section specified by the current site. --- include/requirements.js | 1 + include/service/entities/section_service.js | 16 +- .../service/entities/site_query_service.js | 148 ++++++++++++++++++ package.json | 1 + .../admin/content/articles/article_form.js | 14 +- 5 files changed, 163 insertions(+), 17 deletions(-) create mode 100644 include/service/entities/site_query_service.js diff --git a/include/requirements.js b/include/requirements.js index 2d5990c5d..24b1d35dd 100755 --- a/include/requirements.js +++ b/include/requirements.js @@ -81,6 +81,7 @@ module.exports = function PB(config) { //setup site service pb.SiteService = require(path.join(config.docRoot, '/include/service/entities/site_service.js'))(pb); pb.sites = new pb.SiteService(); + pb.SiteQueryService = require(path.join(config.docRoot, '/include/service/entities/site_query_service.js'))(pb); //setup object services pb.SimpleLayeredService = require(path.join(config.docRoot, '/include/service/simple_layered_service.js'))(pb); diff --git a/include/service/entities/section_service.js b/include/service/entities/section_service.js index c0181f1b7..59311c45a 100755 --- a/include/service/entities/section_service.js +++ b/include/service/entities/section_service.js @@ -33,6 +33,7 @@ module.exports = function SectionServiceModule(pb) { this.site = pb.SiteService.getCurrentSite(site); this.settings = pb.SettingServiceFactory.getServiceBySite(this.site, onlyThisSite); this.sitePrefix = pb.SiteService.getCurrentSitePrefix(this.site); + this.queryService = new pb.SiteQueryService(this.site, onlyThisSite); } /** @@ -245,12 +246,7 @@ module.exports = function SectionServiceModule(pb) { } //retrieve sections - var dao = new pb.DAO(); - var options = { - where: {} - }; - options.where[pb.SiteService.SITE_FIELD] = self.site; - dao.q('section', options, function(err, sections) { + self.queryService.q('section', function(err, sections) { if (util.isError(err)) { return cb(err, []); } @@ -451,9 +447,7 @@ module.exports = function SectionServiceModule(pb) { var where = { name: navItem.name, }; - where[pb.SiteService.SITE_FIELD] = this.site; - var dao = new pb.DAO(); - dao.unique('section', where, navItem[pb.DAO.getIdField()], function(err, unique) { + this.queryService.unique('section', where, navItem[pb.DAO.getIdField()], function(err, unique) { var error = null; if (!unique) { error = {field: 'name', message: 'The provided name is not unique'}; @@ -659,9 +653,7 @@ module.exports = function SectionServiceModule(pb) { } //persist the changes - var dao = new pb.DAO(); - navItem[pb.SiteService.SITE_FIELD] = self.site; - dao.save(navItem, function(err, data) { + self.queryService.save(navItem, function(err, data) { if(util.isError(err)) { return cb(err); } diff --git a/include/service/entities/site_query_service.js b/include/service/entities/site_query_service.js new file mode 100644 index 000000000..b90725ae3 --- /dev/null +++ b/include/service/entities/site_query_service.js @@ -0,0 +1,148 @@ +/* + Copyright (C) 2015 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ + +module.exports = function SiteQueryServiceModule(pb) { + "use strict"; + + var SITE_FIELD = pb.SiteService.SITE_FIELD; + var GLOBAL_SITE = pb.SiteService.GLOBAL_SITE; + var _ = require('lodash'); + var dao = new pb.DAO(); + var util = pb.util; + + /** + * Create an instance of the site query service specific to the given site + * + * @param {String} siteUId UID of site, should already be sanitized by SiteService + * @param onlyThisSite {Boolean} for q, return results specific to this site instead of also looking in global + * @constructor + */ + function SiteQueryService(siteUId, onlyThisSite) { + this.siteUId = siteUId; + this.onlyThisSite = onlyThisSite; + } + + function modifyLoadWhere(site, where) { + if (pb.config.multisite) { + if (site === pb.SiteService.GLOBAL_SITE) { + var siteDoesNotExist = {}, siteEqualToSpecified = {}; + siteDoesNotExist[SITE_FIELD] = {$exists: false}; + siteEqualToSpecified[SITE_FIELD] = site; + + addToOr(where, [siteDoesNotExist, siteEqualToSpecified]); + } else { + where[SITE_FIELD] = site; + } + } + return where; + } + + function modifyLoadOptions(site, options) { + if (pb.config.multisite) { + var target; + if (!Object.isFrozen(options)) { + target = options; + } else { + target = _.clone(options); + } + target.where = target.where || {}; + + + } + // else do nothing + return options; + } + + function addToOr(whereClause, conditions) { + if ('$or' in whereClause) { + var orClause = whereClause['$or']; + orClause.push.apply(orClause, conditions); + } else { + whereClause['$or'] = conditions; + } + } + + /** + * Wrapper for site-aware DAO.q, search target collection with specified site + * If onlyThisSite is not true, and this service is instantiated with a non-global site, then + * this value will try to re-run this query against global site if no docs were found with specified site + * + * @param collection + * @param options + * @param callback + */ + SiteQueryService.prototype.q = function (collection, options, callback) { + if (util.isFunction(options)) { + callback = options; + options = {}; + } + + options = modifyLoadOptions(this.siteUId, options); + if (this.onlyThisSite || isGlobal(this.siteUId)) { + dao.q(collection, options, callback); + } else { + dao.q(collection, options, function (err, docs) { + if (util.isError(err) || docs) { + callback(err, docs); + } else { + options = modifyLoadOptions(GLOBAL_SITE, options); + dao.q(collection, options, callback); + } + }); + } + }; + + function isGlobal(siteUId) { + return !siteUId || siteUId === GLOBAL_SITE; + } + + /** + * Wrapper for site-aware DAO.unique, determine if the document matching the query is unique within specified site + * Only searches within specified site. + * + * @param collection + * @param where + * @param exclusionId + * @param callback + */ + SiteQueryService.prototype.unique = function (collection, where, exclusionId, callback) { + where = modifyLoadWhere(this.siteUId, where); + dao.q(collection, where, exclusionId, callback); + }; + + /** + * Wrapper for site-aware DAO.save. Saves object to database + * + * @param dbObj + * @param options + * @param callback + */ + SiteQueryService.prototype.save = function (dbObj, options, callback) { + dbObj = modifySave(this.siteUId, dbObj); + dao.save(dbObj, options, callback); + }; + + function modifySave(site, objectToSave) { + if (pb.config.multisite && !(SITE_FIELD in objectToSave)) { + objectToSave[SITE_FIELD] = site; + } + // else do nothing + return objectToSave; + } + + return SiteQueryService; +}; \ No newline at end of file diff --git a/package.json b/package.json index 2179f4096..d4c134c95 100644 --- a/package.json +++ b/package.json @@ -30,6 +30,7 @@ "formidable": "1.0.17", "htmlencode": "0.0.4", "locale": "0.0.20", + "lodash": "^3.8.0", "mongodb": "2.0.23", "node-uuid": "1.4.3", "node.extend": "1.1.3", diff --git a/plugins/pencilblue/controllers/admin/content/articles/article_form.js b/plugins/pencilblue/controllers/admin/content/articles/article_form.js index b2a9bfc7b..8a60731b0 100755 --- a/plugins/pencilblue/controllers/admin/content/articles/article_form.js +++ b/plugins/pencilblue/controllers/admin/content/articles/article_form.js @@ -29,6 +29,13 @@ module.exports = function(pb) { function ArticleForm(){} util.inherits(ArticleForm, pb.BaseController); + ArticleForm.prototype.init = function (props, cb) { + this.pathSiteUId = pb.SiteService.getCurrentSite(props.path_vars.siteuid); + this.queryService = new pb.SiteQueryService(this.pathSiteUId); + + pb.BaseController.prototype.init.call(this, props, cb); + }; + ArticleForm.prototype.render = function(cb) { var self = this; var vars = this.pathVars; @@ -183,10 +190,7 @@ module.exports = function(pb) { }, order: {name: pb.DAO.ASC} }; - var where = { - type: {$in: ['container', 'section']} - }; - dao.q('section', opts, callback); + self.queryService.q('section', opts, callback); }, topics: function(callback) { @@ -195,7 +199,7 @@ module.exports = function(pb) { where: pb.DAO.ANYWHERE, order: {name: pb.DAO.ASC} }; - dao.q('topic', opts, callback); + self.queryService.q('topic', opts, callback); }, media: function(callback) { From 8dffb57af7ebb952af607ddbcf3afaace283d662 Mon Sep 17 00:00:00 2001 From: andparker Date: Fri, 8 May 2015 10:17:11 -0400 Subject: [PATCH 092/790] Pull in and resolve sitepathuid | Update redirect to be site aware --- .../controllers/admin/content/objects/types/manage_types.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/pencilblue/controllers/admin/content/objects/types/manage_types.js b/plugins/pencilblue/controllers/admin/content/objects/types/manage_types.js index ce9bd3c0d..b888c8d22 100644 --- a/plugins/pencilblue/controllers/admin/content/objects/types/manage_types.js +++ b/plugins/pencilblue/controllers/admin/content/objects/types/manage_types.js @@ -34,13 +34,14 @@ module.exports = function(pb) { ManageObjectTypes.prototype.render = function(cb) { var self = this; + var sitePathUid = pb.SiteService.getCurrentSite(self.pathVars.siteid); var service = new pb.CustomObjectService(); service.findTypes(function(err, custObjTypes) { //none to manage if(custObjTypes.length === 0) { - self.redirect('/admin/content/objects/types/new', cb); + self.redirect('/admin' + pb.SiteService.getCurrentSitePrefix(sitePathUid) + '/content/objects/types/new', cb); return; } From 57e9be147d8e282b305b2f8b384c37781df32342 Mon Sep 17 00:00:00 2001 From: Eugene Chang Date: Fri, 8 May 2015 12:18:35 -0400 Subject: [PATCH 093/790] Fixing SiteQueryService --- include/service/entities/section_service.js | 4 +++- include/service/entities/site_query_service.js | 13 ++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/include/service/entities/section_service.js b/include/service/entities/section_service.js index 59311c45a..13e1f3b8f 100755 --- a/include/service/entities/section_service.js +++ b/include/service/entities/section_service.js @@ -445,7 +445,7 @@ module.exports = function SectionServiceModule(pb) { } var where = { - name: navItem.name, + name: navItem.name }; this.queryService.unique('section', where, navItem[pb.DAO.getIdField()], function(err, unique) { var error = null; @@ -767,6 +767,8 @@ module.exports = function SectionServiceModule(pb) { return VALID_TYPES[type] === true; }; + + //exports return SectionService; }; diff --git a/include/service/entities/site_query_service.js b/include/service/entities/site_query_service.js index b90725ae3..bb8a39bd1 100644 --- a/include/service/entities/site_query_service.js +++ b/include/service/entities/site_query_service.js @@ -38,6 +38,9 @@ module.exports = function SiteQueryServiceModule(pb) { function modifyLoadWhere(site, where) { if (pb.config.multisite) { + if (Object.isFrozen(where)) { + where = _.clone(where); + } if (site === pb.SiteService.GLOBAL_SITE) { var siteDoesNotExist = {}, siteEqualToSpecified = {}; siteDoesNotExist[SITE_FIELD] = {$exists: false}; @@ -60,8 +63,8 @@ module.exports = function SiteQueryServiceModule(pb) { target = _.clone(options); } target.where = target.where || {}; - - + target.where = modifyLoadWhere(site, target.where); + return target; } // else do nothing return options; @@ -69,10 +72,10 @@ module.exports = function SiteQueryServiceModule(pb) { function addToOr(whereClause, conditions) { if ('$or' in whereClause) { - var orClause = whereClause['$or']; + var orClause = whereClause.$or; orClause.push.apply(orClause, conditions); } else { - whereClause['$or'] = conditions; + whereClause.$or = conditions; } } @@ -121,7 +124,7 @@ module.exports = function SiteQueryServiceModule(pb) { */ SiteQueryService.prototype.unique = function (collection, where, exclusionId, callback) { where = modifyLoadWhere(this.siteUId, where); - dao.q(collection, where, exclusionId, callback); + dao.unique(collection, where, exclusionId, callback); }; /** From 4be0ceb052af04bbd82a5148c280de1b8c4cd27f Mon Sep 17 00:00:00 2001 From: btidwell Date: Fri, 8 May 2015 16:19:52 -0400 Subject: [PATCH 094/790] multisite admin pages for media --- .../admin/content/media/manage_media.js | 43 ++++++++++++------- .../admin/content/media/media_form.js | 35 ++++++++++----- 2 files changed, 53 insertions(+), 25 deletions(-) diff --git a/plugins/pencilblue/controllers/admin/content/media/manage_media.js b/plugins/pencilblue/controllers/admin/content/media/manage_media.js index 897c7b0a8..e81b093ca 100755 --- a/plugins/pencilblue/controllers/admin/content/media/manage_media.js +++ b/plugins/pencilblue/controllers/admin/content/media/manage_media.js @@ -31,7 +31,7 @@ module.exports = function(pb) { ManageMedia.prototype.render = function(cb) { var self = this; - + var siteid = pb.SiteService.getCurrentSite(self.pathVars.siteid); var options = { select: { name: 1, @@ -40,43 +40,56 @@ module.exports = function(pb) { media_type: 1, location: 1 }, + where : {site: siteid}, order: {created: pb.DAO.DESC}, format_media: true }; var mservice = new pb.MediaService(); mservice.get(options, function(err, mediaData) { if(util.isError(mediaData) || mediaData.length === 0) { - self.redirect('/admin/content/media/new', cb); + self.redirect('/admin' + pb.SiteService.getCurrentSitePrefix(siteid) + '/content/media/new', cb); return; } - var angularObjects = pb.ClientJs.getAngularObjects( - { - navigation: pb.AdminNavigation.get(self.session, ['content', 'media'], self.ls), - pills: pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, 'manage_media'), - media: pb.MediaService.formatMedia(mediaData) + self.getAngularObjects(siteid, mediaData, function(angularObjects) { + var title = self.ls.get('MANAGE_MEDIA'); + self.setPageName(title); + self.ts.registerLocal('angular_objects', new pb.TemplateValue(angularObjects, false)); + self.ts.load('admin/content/media/manage_media', function(err, result) { + cb({content: result}); + }); }); + }); + }; - var title = self.ls.get('MANAGE_MEDIA'); - self.setPageName(title); - self.ts.registerLocal('angular_objects', new pb.TemplateValue(angularObjects, false)); - self.ts.load('admin/content/media/manage_media', function(err, result) { - cb({content: result}); - }); + ManageMedia.prototype.getAngularObjects = function(site, mediaData, cb) { + var self = this; + pb.AdminSubnavService.getWithSite(SUB_NAV_KEY, self.ls, SUB_NAV_KEY, {site: site}, function(pills) { + var angularObjects = pb.ClientJs.getAngularObjects( + { + navigation: pb.AdminNavigation.get(self.session, ['content', 'media'], self.ls), + pills: pills, + media: pb.MediaService.formatMedia(mediaData) + }); + cb(angularObjects); }); }; ManageMedia.getSubNavItems = function(key, ls, data) { + var adminPrefix = '/admin' + if(data.site) { + adminPrefix += '/' + data.site; + } return [{ name: 'manage_media', title: ls.get('MANAGE_MEDIA'), icon: 'refresh', - href: '/admin/content/media' + href: adminPrefix + '/content/media' }, { name: 'new_media', title: '', icon: 'plus', - href: '/admin/content/media/new' + href: adminPrefix + '/content/media/new' }]; }; diff --git a/plugins/pencilblue/controllers/admin/content/media/media_form.js b/plugins/pencilblue/controllers/admin/content/media/media_form.js index b14f04555..13412c5e3 100644 --- a/plugins/pencilblue/controllers/admin/content/media/media_form.js +++ b/plugins/pencilblue/controllers/admin/content/media/media_form.js @@ -53,18 +53,26 @@ module.exports = function(pb) { self.media = data.media; data.media.media_topics = self.getMediaTopics(data); - data.pills = pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, SUB_NAV_KEY, self.media); - var angularObjects = pb.ClientJs.getAngularObjects(data); - - self.setPageName(self.media[pb.DAO.getIdField()] ? self.media.name : self.ls.get('NEW_MEDIA')); - self.ts.registerLocal('angular_objects', new pb.TemplateValue(angularObjects, false)); - self.ts.load('admin/content/media/media_form', function(err, result) { - cb({content: result}); + self.getAngularObjects(data, function(angularObjects) { + self.setPageName(self.media[pb.DAO.getIdField()] ? self.media.name : self.ls.get('NEW_MEDIA')); + self.ts.registerLocal('angular_objects', new pb.TemplateValue(angularObjects, false)); + self.ts.load('admin/content/media/media_form', function(err, result) { + cb({content: result}); + }); }); }); return; }; + MediaForm.prototype.getAngularObjects = function(data, cb) { + var self = this; + pb.AdminSubnavService.getWithSite(SUB_NAV_KEY, self.ls, data.media, {site: data.media.site}, function(pills) { + data.pills = pills; + cb(pb.ClientJs.getAngularObjects(data)); + }); + + }; + MediaForm.prototype.gatherData = function(vars, cb) { var self = this; var dao = new pb.DAO(); @@ -101,7 +109,10 @@ module.exports = function(pb) { media: function(callback) { if(!vars.id) { - return callback(null, {media_topics: []}); + return callback(null, { + media_topics: [], + site: vars.siteid + }); } var mservice = new pb.MediaService(); @@ -131,16 +142,20 @@ module.exports = function(pb) { }; MediaForm.getSubNavItems = function(key, ls, data) { + var adminPrefix = '/admin' + if(data.site) { + adminPrefix += '/' + data.site; + } return [{ name: 'manage_media', title: data[pb.DAO.getIdField()] ? ls.get('EDIT') + ' ' + data.name : ls.get('NEW_MEDIA'), icon: 'chevron-left', - href: '/admin/content/media' + href: adminPrefix + '/content/media' }, { name: 'new_media', title: '', icon: 'plus', - href: '/admin/content/media/new' + href: adminPrefix + '/content/media/new' }]; }; From 8fbe51d7f5975ff540c2fb58b02fea3e813dad1d Mon Sep 17 00:00:00 2001 From: andparker Date: Fri, 8 May 2015 17:47:30 -0400 Subject: [PATCH 095/790] Correct spelling in documentation | Make pills site aware --- include/service/admin/admin_subnav_service.js | 2 +- .../content/objects/types/manage_types.js | 17 +++++++--- .../admin/content/objects/types/type_form.js | 31 ++++++++++++++----- 3 files changed, 37 insertions(+), 13 deletions(-) diff --git a/include/service/admin/admin_subnav_service.js b/include/service/admin/admin_subnav_service.js index 4f98b413d..a06211d6d 100755 --- a/include/service/admin/admin_subnav_service.js +++ b/include/service/admin/admin_subnav_service.js @@ -130,7 +130,7 @@ module.exports = function AdminSubnavServiceModule(pb) { }; /** - * Retrieves the sub-nav items with selcted site + * Retrieves the sub-nav items with selected site * @static * @method getWithSite * @param {String} key The key to retrieve diff --git a/plugins/pencilblue/controllers/admin/content/objects/types/manage_types.js b/plugins/pencilblue/controllers/admin/content/objects/types/manage_types.js index b888c8d22..d2783516e 100644 --- a/plugins/pencilblue/controllers/admin/content/objects/types/manage_types.js +++ b/plugins/pencilblue/controllers/admin/content/objects/types/manage_types.js @@ -32,16 +32,23 @@ module.exports = function(pb) { //statics var SUB_NAV_KEY = 'manage_object_types'; + ManageObjectTypes.prototype.init = function (props, cb) { + + pb.BaseController.prototype.init.call(this, props, cb); + + this.pathSiteUid = pb.SiteService.getCurrentSite(props.path_vars.siteid); + this.pathSitePrefix = pb.SiteService.getCurrentSitePrefix(this.pathSiteUid); + }; + ManageObjectTypes.prototype.render = function(cb) { var self = this; - var sitePathUid = pb.SiteService.getCurrentSite(self.pathVars.siteid); var service = new pb.CustomObjectService(); service.findTypes(function(err, custObjTypes) { //none to manage if(custObjTypes.length === 0) { - self.redirect('/admin' + pb.SiteService.getCurrentSitePrefix(sitePathUid) + '/content/objects/types/new', cb); + self.redirect('/admin' + self.pathSitePrefix + '/content/objects/types/new', cb); return; } @@ -67,16 +74,18 @@ module.exports = function(pb) { ManageObjectTypes.getSubNavItems = function(key, ls, data) { + var self = this; + return [{ name: SUB_NAV_KEY, title: ls.get('MANAGE_OBJECT_TYPES'), icon: 'refresh', - href: '/admin/content/objects/types' + href: '/admin' + self.pathSitePrefix + '/content/objects/types' }, { name: 'new_object_type', title: '', icon: 'plus', - href: '/admin/content/objects/types/new' + href: '/admin' + self.pathSitePrefix + '/content/objects/types/new' }]; }; diff --git a/plugins/pencilblue/controllers/admin/content/objects/types/type_form.js b/plugins/pencilblue/controllers/admin/content/objects/types/type_form.js index 1576381f0..4caa2a5fa 100644 --- a/plugins/pencilblue/controllers/admin/content/objects/types/type_form.js +++ b/plugins/pencilblue/controllers/admin/content/objects/types/type_form.js @@ -32,6 +32,14 @@ module.exports = function(pb) { //statics var SUB_NAV_KEY = 'type_form'; + TypeForm.prototype.init = function (props, cb) { + + pb.BaseController.prototype.init.call(this, props, cb); + + this.pathSiteUid = pb.SiteService.getCurrentSite(props.path_vars.siteid); + this.pathSitePrefix = pb.SiteService.getCurrentSitePrefix(this.pathSiteUid); + }; + TypeForm.prototype.render = function(cb) { var self = this; var vars = this.pathVars; @@ -46,13 +54,18 @@ module.exports = function(pb) { } self.objectType = data.objectType; - data.pills = pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, SUB_NAV_KEY, self.objectType); - var angularObjects = pb.ClientJs.getAngularObjects(data); + self.objectType.site = self.pathSiteUid; + self.objectType.pathSitePrefix = self.pathSitePrefix; - self.setPageName(self.objectType[pb.DAO.getIdField()] ? self.objectType.name : self.ls.get('NEW_OBJECT')); - self.ts.registerLocal('angular_objects', new pb.TemplateValue(angularObjects, false)); - self.ts.load('admin/content/objects/types/type_form', function(err, result) { - cb({content: result}); + pb.AdminSubnavService.getWithSite(SUB_NAV_KEY, self.ls, SUB_NAV_KEY, self.objectType, function(pills) { + data.pills = pills; + var angularObjects = pb.ClientJs.getAngularObjects(data); + + self.setPageName(self.objectType[pb.DAO.getIdField()] ? self.objectType.name : self.ls.get('NEW_OBJECT')); + self.ts.registerLocal('angular_objects', new pb.TemplateValue(angularObjects, false)); + self.ts.load('admin/content/objects/types/type_form', function(err, result) { + cb({content: result}); + }); }); }); }; @@ -109,16 +122,18 @@ module.exports = function(pb) { }; TypeForm.getSubNavItems = function(key, ls, data) { + var self = this; + return [{ name: SUB_NAV_KEY, title: data[pb.DAO.getIdField()] ? ls.get('EDIT') + ' ' + data.name : ls.get('NEW_OBJECT_TYPE'), icon: 'chevron-left', - href: '/admin/content/objects/types' + href: '/admin' + data.pathSitePrefix + '/content/objects/types' }, { name: 'new_object_type', title: '', icon: 'plus', - href: '/admin/content/objects/types/new' + href: '/admin' + data.pathSitePrefix + '/content/objects/types/new' }]; }; From 93ba6d242360dc1b6771f6c4caac9a42883532cc Mon Sep 17 00:00:00 2001 From: Eugene Chang Date: Mon, 11 May 2015 09:22:43 -0400 Subject: [PATCH 096/790] Making content search (for pages/articles) in navigation site-aware. Fixing bugs in SiteQueryService --- include/service/entities/site_query_service.js | 12 +++++++++++- .../admin/content/navigation/nav_item_form.js | 1 + plugins/pencilblue/controllers/api/content/search.js | 5 +++-- public/js/admin/elements/content_search.js | 6 +++++- 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/include/service/entities/site_query_service.js b/include/service/entities/site_query_service.js index bb8a39bd1..6d8193348 100644 --- a/include/service/entities/site_query_service.js +++ b/include/service/entities/site_query_service.js @@ -73,12 +73,22 @@ module.exports = function SiteQueryServiceModule(pb) { function addToOr(whereClause, conditions) { if ('$or' in whereClause) { var orClause = whereClause.$or; - orClause.push.apply(orClause, conditions); + addToAnd(whereClause, [{$or: orClause}, {$or: conditions}]); + delete whereClause.$or; } else { whereClause.$or = conditions; } } + function addToAnd(whereClause, conditions) { + if ('$and' in whereClause) { + var andClause = whereClause.$and; + andClause.push.apply(andClause, conditions); + } else { + whereClause.$and = conditions; + } + } + /** * Wrapper for site-aware DAO.q, search target collection with specified site * If onlyThisSite is not true, and this service is instantiated with a non-global site, then diff --git a/plugins/pencilblue/controllers/admin/content/navigation/nav_item_form.js b/plugins/pencilblue/controllers/admin/content/navigation/nav_item_form.js index 569ad68da..da8621521 100644 --- a/plugins/pencilblue/controllers/admin/content/navigation/nav_item_form.js +++ b/plugins/pencilblue/controllers/admin/content/navigation/nav_item_form.js @@ -67,6 +67,7 @@ module.exports = function(pb) { }; data.pills = pb.AdminSubnavService.get(self.getSubnavKey(), self.ls, self.getSubnavKey(), navData); data.sitePrefix = self.sitePrefix; + data.site = self.pathSiteUId; var angularObjects = pb.ClientJs.getAngularObjects(data); self.setPageName(self.navItem[pb.DAO.getIdField()] ? self.navItem.name : self.ls.get('NEW_NAV_ITEM')); diff --git a/plugins/pencilblue/controllers/api/content/search.js b/plugins/pencilblue/controllers/api/content/search.js index 354845bfe..d45721ec3 100755 --- a/plugins/pencilblue/controllers/api/content/search.js +++ b/plugins/pencilblue/controllers/api/content/search.js @@ -40,6 +40,7 @@ module.exports = function(pb) { ContentSearchController.prototype.render = function(cb) { var type = this.query.type; var search = this.query.q; + var querySite = this.query.site; //perform validation var errors = ContentSearchController.validate(type, search); @@ -65,8 +66,8 @@ module.exports = function(pb) { order: pb.DAO.NATURAL_ORDER, limit: MAX_RESULTS }; - var dao = new pb.DAO(); - dao.q(type, opts, function(err, items) { + var queryService = new pb.SiteQueryService(querySite); + queryService.q(type, opts, function(err, items) { if (util.isError(err)) { var content = BaseController.apiResponse(BaseController.API_FAILURE, '', ''); return cb({content: content, code: 500}); diff --git a/public/js/admin/elements/content_search.js b/public/js/admin/elements/content_search.js index dad237909..0f7b30201 100644 --- a/public/js/admin/elements/content_search.js +++ b/public/js/admin/elements/content_search.js @@ -19,12 +19,16 @@ $(document).ready(function() { var input = $('#content_search'); input.autocomplete({ source: function( request, response ) { + var $scope = angular.element('#content_type').scope(); + var site = $scope.site; + $.ajax({ url: "/api/content/search", dataType: "json", data: { - type: angular.element('#content_type').scope().navItem.type, + type: $scope.navItem.type, q: $('#content_search').val(), + site: site }, success: function( data ) { response( $.map( data.data, function( item ) { From a76d215a5ac96aaf1b9fcb36747c960ca3b23e93 Mon Sep 17 00:00:00 2001 From: Eugene Chang Date: Mon, 11 May 2015 09:48:53 -0400 Subject: [PATCH 097/790] Adding site name to list of pills in navigation --- include/service/admin/admin_subnav_service.js | 34 +++++++++++++------ .../admin/content/navigation/nav_item_form.js | 16 ++++++--- .../admin/content/navigation/nav_map.js | 26 ++++++++------ 3 files changed, 51 insertions(+), 25 deletions(-) diff --git a/include/service/admin/admin_subnav_service.js b/include/service/admin/admin_subnav_service.js index 4f98b413d..858d7319d 100755 --- a/include/service/admin/admin_subnav_service.js +++ b/include/service/admin/admin_subnav_service.js @@ -129,6 +129,29 @@ module.exports = function AdminSubnavServiceModule(pb) { return navItems; }; + /** + * Add a site name pill to existing pills + * + * @static + * @method addSiteToPills + * @param {Array} standardPills list of pills + * @param {String} siteName name of the site to add to the pill + * @returns {Array} a list of pills with site name added + */ + AdminSubnavService.addSiteToPills = function (standardPills, siteName) { + var pills = []; + if (siteName && pb.config.multisite) { + pills.push({ + name: 'selected_site', + title: siteName, + icon: 'sitemap', + href: '/admin/sites' + }); + } + pills = pills.concat(standardPills); + return pills; + }; + /** * Retrieves the sub-nav items with selcted site * @static @@ -146,16 +169,7 @@ module.exports = function AdminSubnavServiceModule(pb) { throw new Error('Data must include a field named "site"'); } new pb.SiteService().getSiteNameByUid(data.site, function(siteName) { - var pills = []; - if (siteName) { - pills.push({ - name: 'selected_site', - title: siteName, - icon: 'sitemap', - href: '/admin/sites' - }); - } - pills = pills.concat(standardPills); + var pills = AdminSubnavService.addSiteToPills(standardPills, siteName); cb(pills); }); } diff --git a/plugins/pencilblue/controllers/admin/content/navigation/nav_item_form.js b/plugins/pencilblue/controllers/admin/content/navigation/nav_item_form.js index da8621521..2617473fb 100644 --- a/plugins/pencilblue/controllers/admin/content/navigation/nav_item_form.js +++ b/plugins/pencilblue/controllers/admin/content/navigation/nav_item_form.js @@ -34,10 +34,15 @@ module.exports = function(pb) { util.inherits(NavItemFormController, pb.BaseController); NavItemFormController.prototype.init = function (props, cb) { - this.pathSiteUId = pb.SiteService.getCurrentSite(props.path_vars.siteid); - this.navService = new pb.SectionService(this.pathSiteUId, true); - this.sitePrefix = pb.SiteService.getCurrentSitePrefix(this.pathSiteUId); - pb.BaseController.prototype.init.call(this, props, cb); + var self = this; + self.pathSiteUId = pb.SiteService.getCurrentSite(props.path_vars.siteid); + self.navService = new pb.SectionService(self.pathSiteUId, true); + self.sitePrefix = pb.SiteService.getCurrentSitePrefix(self.pathSiteUId); + var siteService = new pb.SiteService(); + siteService.getSiteNameByUid(self.pathSiteUId, function (siteName) { + self.siteName = siteName; + pb.BaseController.prototype.init.call(self, props, cb); + }); }; //statics @@ -65,7 +70,8 @@ module.exports = function(pb) { item: self.navItem, sitePrefix: self.sitePrefix }; - data.pills = pb.AdminSubnavService.get(self.getSubnavKey(), self.ls, self.getSubnavKey(), navData); + var pills = pb.AdminSubnavService.get(self.getSubnavKey(), self.ls, self.getSubnavKey(), navData); + data.pills = pb.AdminSubnavService.addSiteToPills(pills, self.siteName); data.sitePrefix = self.sitePrefix; data.site = self.pathSiteUId; var angularObjects = pb.ClientJs.getAngularObjects(data); diff --git a/plugins/pencilblue/controllers/admin/content/navigation/nav_map.js b/plugins/pencilblue/controllers/admin/content/navigation/nav_map.js index 5c39b2260..0ad76751f 100644 --- a/plugins/pencilblue/controllers/admin/content/navigation/nav_map.js +++ b/plugins/pencilblue/controllers/admin/content/navigation/nav_map.js @@ -29,10 +29,17 @@ module.exports = function(pb) { util.inherits(NavigationMap, pb.BaseController); NavigationMap.prototype.init = function (props, cb) { - this.pathSiteUId = pb.SiteService.getCurrentSite(props.path_vars.siteid); - this.navService = new pb.SectionService(this.pathSiteUId, true); - this.sitePrefix = pb.SiteService.getCurrentSitePrefix(this.pathSiteUId); - pb.BaseController.prototype.init.call(this, props, cb); + var self = this; + self.pathSiteUId = pb.SiteService.getCurrentSite(props.path_vars.siteid); + self.navService = new pb.SectionService(self.pathSiteUId, true); + self.sitePrefix = pb.SiteService.getCurrentSitePrefix(self.pathSiteUId); + self.queryService = new pb.SiteQueryService(self.pathSiteUId); + self.settings = pb.SettingServiceFactory.getServiceBySite(self.pathSiteUId, true); + var siteService = new pb.SiteService(); + siteService.getSiteNameByUid(self.pathSiteUId, function (siteName) { + self.siteName = siteName; + pb.BaseController.prototype.init.call(self, props, cb); + }); }; //statics @@ -42,11 +49,9 @@ module.exports = function(pb) { var self = this; var opts = { - where: {} + where: pb.DAO.ANYWHERE }; - opts.where[SiteService.SITE_FIELD] = self.pathSiteUId; - var dao = new pb.DAO(); - dao.q('section', opts, function(err, sections) { + self.queryService.q('section', opts, function (err, sections) { if (util.isError(err)) { return self.reqHandler.serveError(err); } @@ -56,16 +61,17 @@ module.exports = function(pb) { return self.redirect('/admin' + self.sitePrefix + '/content/navigation/new', cb); } - pb.settings.get('section_map', function(err, sectionMap) { + self.settings.get('section_map', function (err, sectionMap) { if(sectionMap === null) { self.redirect('/admin' + self.sitePrefix + '/content/navigation/new', cb); return; } + var pills = pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, SUB_NAV_KEY, {sitePrefix: self.sitePrefix}); var angularObjects = pb.ClientJs.getAngularObjects( { navigation: pb.AdminNavigation.get(self.session, ['content', 'sections'], self.ls), - pills: pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, SUB_NAV_KEY, {sitePrefix: self.sitePrefix}), + pills: pb.AdminSubnavService.addSiteToPills(pills, self.siteName), navItems: NavigationMap.getOrderedItems(sections, sectionMap), icons: { container: 'inbox', From d98bac0782f3745779729006357487c6614949bc Mon Sep 17 00:00:00 2001 From: Eugene Chang Date: Mon, 11 May 2015 11:31:40 -0400 Subject: [PATCH 098/790] Refactoring articles/pages so that site uid is in the URL when editing --- .../admin/content/articles/article_form.js | 2 +- .../admin/content/articles/manage_articles.js | 19 ++++++++++++------ .../admin/content/pages/manage_pages.js | 20 +++++++++++++------ .../content/articles/manage_articles.html | 2 +- .../admin/content/pages/manage_pages.html | 2 +- 5 files changed, 30 insertions(+), 15 deletions(-) diff --git a/plugins/pencilblue/controllers/admin/content/articles/article_form.js b/plugins/pencilblue/controllers/admin/content/articles/article_form.js index a3767f703..ddd0d7c06 100755 --- a/plugins/pencilblue/controllers/admin/content/articles/article_form.js +++ b/plugins/pencilblue/controllers/admin/content/articles/article_form.js @@ -30,7 +30,7 @@ module.exports = function(pb) { util.inherits(ArticleForm, pb.BaseController); ArticleForm.prototype.init = function (props, cb) { - this.pathSiteUId = pb.SiteService.getCurrentSite(props.path_vars.siteuid); + this.pathSiteUId = pb.SiteService.getCurrentSite(props.path_vars.siteid); this.queryService = new pb.SiteQueryService(this.pathSiteUId); pb.BaseController.prototype.init.call(this, props, cb); diff --git a/plugins/pencilblue/controllers/admin/content/articles/manage_articles.js b/plugins/pencilblue/controllers/admin/content/articles/manage_articles.js index eee82d539..18f3059ff 100755 --- a/plugins/pencilblue/controllers/admin/content/articles/manage_articles.js +++ b/plugins/pencilblue/controllers/admin/content/articles/manage_articles.js @@ -26,14 +26,20 @@ module.exports = function(pb) { function ManageArticles(){} util.inherits(ManageArticles, pb.BaseController); + ManageArticles.prototype.init = function (props, cb) { + this.pathSiteUId = pb.SiteService.getCurrentSite(props.path_vars.siteid); + this.queryService = new pb.SiteQueryService(this.pathSiteUId); + this.sitePrefix = pb.SiteService.getCurrentSitePrefix(this.pathSiteUId); + + pb.BaseController.prototype.init.call(this, props, cb); + }; + //statics var SUB_NAV_KEY = 'manage_articles'; ManageArticles.prototype.render = function(cb) { var self = this; - var dao = new pb.DAO(); - var siteid = pb.SiteService.getCurrentSite(self.pathVars.siteid); - var where = {site:siteid}; + var where = {}; if(!pb.security.isAuthorized(this.session, {logged_in: true, admin_level: pb.SecurityService.ACCESS_EDITOR})) { where.author = this.session.authentication.user_id; } @@ -44,7 +50,7 @@ module.exports = function(pb) { order: {publish_date: pb.DAO.ASC}, }; - dao.q('article', opts, function(err, articles) { + self.queryService.q('article', opts, function(err, articles) { if(util.isError(err)) { return self.reqHandler.serveError(err); } @@ -54,7 +60,7 @@ module.exports = function(pb) { pb.users.getAuthors(articles, function(err, articlesWithAuthorNames) { articles = self.getArticleStatuses(articlesWithAuthorNames); - self.getAngularObjects(siteid, articles, function (angularObjects) { + self.getAngularObjects(self.pathSiteUId, articles, function (angularObjects) { var manageArticlesStr = self.ls.get('MANAGE_ARTICLES'); self.setPageName(manageArticlesStr); self.ts.registerLocal('angular_objects', new pb.TemplateValue(angularObjects, false)); @@ -91,7 +97,8 @@ module.exports = function(pb) { { navigation: pb.AdminNavigation.get(self.session, ['content', 'articles'], self.ls), pills: pills, - articles: articles + articles: articles, + sitePrefix: self.sitePrefix }); cb(angularObjects); }); diff --git a/plugins/pencilblue/controllers/admin/content/pages/manage_pages.js b/plugins/pencilblue/controllers/admin/content/pages/manage_pages.js index 2d187d58f..2edbabfbd 100755 --- a/plugins/pencilblue/controllers/admin/content/pages/manage_pages.js +++ b/plugins/pencilblue/controllers/admin/content/pages/manage_pages.js @@ -26,19 +26,26 @@ module.exports = function(pb) { function ManagePages(){} util.inherits(ManagePages, pb.BaseController); + ManagePages.prototype.init = function (props, cb) { + this.pathSiteUId = pb.SiteService.getCurrentSite(props.path_vars.siteid); + this.queryService = new pb.SiteQueryService(this.pathSiteUId); + this.sitePrefix = pb.SiteService.getCurrentSitePrefix(this.pathSiteUId); + + pb.BaseController.prototype.init.call(this, props, cb); + }; + //statics var SUB_NAV_KEY = 'manage_pages'; ManagePages.prototype.render = function(cb) { var self = this; - var siteid = pb.SiteService.getCurrentSite(self.pathVars.siteid); + var opts = { select: pb.DAO.PROJECT_ALL, - where: {site: siteid}, + where: pb.DAO.ANYWHERE, order: {headline: pb.DAO.ASC} }; - var dao = new pb.DAO(); - dao.q('page', opts, function(err, pages) { + self.queryService.q('page', opts, function(err, pages) { if (util.isError(err)) { return self.reqHandler.serveError(err); } @@ -47,7 +54,7 @@ module.exports = function(pb) { } pb.users.getAuthors(pages, function(err, pagesWithAuthor) { - self.getAngularObjects(siteid, pagesWithAuthor, function(angularObjects) { + self.getAngularObjects(self.pathSiteUId, pagesWithAuthor, function(angularObjects) { var title = self.ls.get('MANAGE_PAGES'); self.setPageName(title); self.ts.registerLocal('angular_objects', new pb.TemplateValue(angularObjects, false)); @@ -83,7 +90,8 @@ module.exports = function(pb) { var angularObjects = pb.ClientJs.getAngularObjects({ navigation: pb.AdminNavigation.get(self.session, ['content', 'pages'], self.ls), pills: pills, - pages: self.getPageStatuses(pagesWithAuthor) + pages: self.getPageStatuses(pagesWithAuthor), + sitePrefix: self.sitePrefix }); cb(angularObjects); }); diff --git a/plugins/pencilblue/templates/admin/content/articles/manage_articles.html b/plugins/pencilblue/templates/admin/content/articles/manage_articles.html index 3f7d3df38..77b374e67 100755 --- a/plugins/pencilblue/templates/admin/content/articles/manage_articles.html +++ b/plugins/pencilblue/templates/admin/content/articles/manage_articles.html @@ -7,7 +7,7 @@ ^tmp_admin=elements=table_headers^ - + diff --git a/plugins/pencilblue/templates/admin/content/pages/manage_pages.html b/plugins/pencilblue/templates/admin/content/pages/manage_pages.html index 94d55cbf4..8d2f10aa4 100755 --- a/plugins/pencilblue/templates/admin/content/pages/manage_pages.html +++ b/plugins/pencilblue/templates/admin/content/pages/manage_pages.html @@ -7,7 +7,7 @@
^tmp_admin=elements=table_headers^ - + From dd1efd49845af95a845db26ad97a93100159988f Mon Sep 17 00:00:00 2001 From: andparker Date: Mon, 11 May 2015 11:38:41 -0400 Subject: [PATCH 099/790] Pull sitename retrieval into init to use for building out the navigation pills. --- .../admin/content/objects/types/type_form.js | 37 ++++++++++--------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/plugins/pencilblue/controllers/admin/content/objects/types/type_form.js b/plugins/pencilblue/controllers/admin/content/objects/types/type_form.js index 4caa2a5fa..c893b8613 100644 --- a/plugins/pencilblue/controllers/admin/content/objects/types/type_form.js +++ b/plugins/pencilblue/controllers/admin/content/objects/types/type_form.js @@ -33,11 +33,15 @@ module.exports = function(pb) { var SUB_NAV_KEY = 'type_form'; TypeForm.prototype.init = function (props, cb) { + var self = this; - pb.BaseController.prototype.init.call(this, props, cb); - - this.pathSiteUid = pb.SiteService.getCurrentSite(props.path_vars.siteid); - this.pathSitePrefix = pb.SiteService.getCurrentSitePrefix(this.pathSiteUid); + self.pathSiteUid = pb.SiteService.getCurrentSite(props.path_vars.siteid); + self.pathSitePrefix = pb.SiteService.getCurrentSitePrefix(self.pathSiteUid); + var siteService = new pb.SiteService(); + siteService.getSiteNameByUid(self.pathSiteUid, function (siteName) { + self.siteName = siteName; + pb.BaseController.prototype.init.call(self, props, cb); + }); }; TypeForm.prototype.render = function(cb) { @@ -54,18 +58,15 @@ module.exports = function(pb) { } self.objectType = data.objectType; - self.objectType.site = self.pathSiteUid; - self.objectType.pathSitePrefix = self.pathSitePrefix; - pb.AdminSubnavService.getWithSite(SUB_NAV_KEY, self.ls, SUB_NAV_KEY, self.objectType, function(pills) { - data.pills = pills; - var angularObjects = pb.ClientJs.getAngularObjects(data); + var pills = pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, SUB_NAV_KEY, data); + data.pills = pb.AdminSubnavService.addSiteToPills(pills, self.siteName); - self.setPageName(self.objectType[pb.DAO.getIdField()] ? self.objectType.name : self.ls.get('NEW_OBJECT')); - self.ts.registerLocal('angular_objects', new pb.TemplateValue(angularObjects, false)); - self.ts.load('admin/content/objects/types/type_form', function(err, result) { - cb({content: result}); - }); + var angularObjects = pb.ClientJs.getAngularObjects(data); + self.setPageName(self.objectType[pb.DAO.getIdField()] ? self.objectType.name : self.ls.get('NEW_OBJECT')); + self.ts.registerLocal('angular_objects', new pb.TemplateValue(angularObjects, false)); + self.ts.load('admin/content/objects/types/type_form', function(err, result) { + cb({content: result}); }); }); }; @@ -97,6 +98,10 @@ module.exports = function(pb) { callback(null, pb.AdminNavigation.get(self.session, ['content', 'custom_objects'], self.ls)); }, + pathSitePrefix: function(callback) { + callback(null, self.pathSitePrefix) + }, + objectTypes: function(callback) { cos.getReferenceTypes(function(err, objectTypes) { callback(err, objectTypes); @@ -122,11 +127,9 @@ module.exports = function(pb) { }; TypeForm.getSubNavItems = function(key, ls, data) { - var self = this; - return [{ name: SUB_NAV_KEY, - title: data[pb.DAO.getIdField()] ? ls.get('EDIT') + ' ' + data.name : ls.get('NEW_OBJECT_TYPE'), + title: data.objectType[pb.DAO.getIdField()] ? ls.get('EDIT') + ' ' + data.objectType.name : ls.get('NEW_OBJECT_TYPE'), icon: 'chevron-left', href: '/admin' + data.pathSitePrefix + '/content/objects/types' }, { From f16af897044c274644178baecd0e81ce4f5dc4e1 Mon Sep 17 00:00:00 2001 From: Eugene Chang Date: Mon, 11 May 2015 11:49:51 -0400 Subject: [PATCH 100/790] Adding site validation to navigation --- .../admin/content/navigation/nav_item_form.js | 23 +++++++++++----- .../admin/content/navigation/nav_map.js | 26 ++++++++++++------- 2 files changed, 32 insertions(+), 17 deletions(-) diff --git a/plugins/pencilblue/controllers/admin/content/navigation/nav_item_form.js b/plugins/pencilblue/controllers/admin/content/navigation/nav_item_form.js index 2617473fb..65342937d 100644 --- a/plugins/pencilblue/controllers/admin/content/navigation/nav_item_form.js +++ b/plugins/pencilblue/controllers/admin/content/navigation/nav_item_form.js @@ -35,13 +35,22 @@ module.exports = function(pb) { NavItemFormController.prototype.init = function (props, cb) { var self = this; - self.pathSiteUId = pb.SiteService.getCurrentSite(props.path_vars.siteid); - self.navService = new pb.SectionService(self.pathSiteUId, true); - self.sitePrefix = pb.SiteService.getCurrentSitePrefix(self.pathSiteUId); - var siteService = new pb.SiteService(); - siteService.getSiteNameByUid(self.pathSiteUId, function (siteName) { - self.siteName = siteName; - pb.BaseController.prototype.init.call(self, props, cb); + pb.BaseController.prototype.init.call(self, props, function () { + self.pathSiteUId = pb.SiteService.getCurrentSite(self.pathVars.siteid); + pb.SiteService.siteExists(self.pathSiteUId, function (err, exists) { + if (!exists) { + self.reqHandler.serve404(); + } + else { + self.navService = new pb.SectionService(self.pathSiteUId, true); + self.sitePrefix = pb.SiteService.getCurrentSitePrefix(self.pathSiteUId); + var siteService = new pb.SiteService(); + siteService.getSiteNameByUid(self.pathSiteUId, function (siteName) { + self.siteName = siteName; + cb(); + }); + } + }); }); }; diff --git a/plugins/pencilblue/controllers/admin/content/navigation/nav_map.js b/plugins/pencilblue/controllers/admin/content/navigation/nav_map.js index 0ad76751f..6914190e5 100644 --- a/plugins/pencilblue/controllers/admin/content/navigation/nav_map.js +++ b/plugins/pencilblue/controllers/admin/content/navigation/nav_map.js @@ -30,18 +30,24 @@ module.exports = function(pb) { NavigationMap.prototype.init = function (props, cb) { var self = this; - self.pathSiteUId = pb.SiteService.getCurrentSite(props.path_vars.siteid); - self.navService = new pb.SectionService(self.pathSiteUId, true); - self.sitePrefix = pb.SiteService.getCurrentSitePrefix(self.pathSiteUId); - self.queryService = new pb.SiteQueryService(self.pathSiteUId); - self.settings = pb.SettingServiceFactory.getServiceBySite(self.pathSiteUId, true); - var siteService = new pb.SiteService(); - siteService.getSiteNameByUid(self.pathSiteUId, function (siteName) { - self.siteName = siteName; - pb.BaseController.prototype.init.call(self, props, cb); + pb.BaseController.prototype.init.call(self, props, function () { + self.pathSiteUId = pb.SiteService.getCurrentSite(self.pathVars.siteid); + pb.SiteService.siteExists(self.pathSiteUId, function (err, exists) { + if (!exists) { + self.reqHandler.serve404(); + } + else { + self.navService = new pb.SectionService(self.pathSiteUId, true); + self.sitePrefix = pb.SiteService.getCurrentSitePrefix(self.pathSiteUId); + var siteService = new pb.SiteService(); + siteService.getSiteNameByUid(self.pathSiteUId, function (siteName) { + self.siteName = siteName; + cb(); + }); + } + }); }); }; - //statics var SUB_NAV_KEY = 'navigation_map'; From 05fb7cd79e93a910a48709bad1a5fcfb9a187903 Mon Sep 17 00:00:00 2001 From: btidwell Date: Mon, 11 May 2015 13:17:30 -0400 Subject: [PATCH 101/790] get media by site on articles page --- include/service/entities/media_service.js | 16 ++++++++++++++++ .../admin/content/articles/article_form.js | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/include/service/entities/media_service.js b/include/service/entities/media_service.js index 855c52e78..977d4c60f 100755 --- a/include/service/entities/media_service.js +++ b/include/service/entities/media_service.js @@ -209,6 +209,22 @@ module.exports = function MediaServiceModule(pb) { }); }; + /** + * Queries for media descriptors by site + * @method getBySite + * @param {String} site + * @param {Function} cb + */ + + MediaService.prototype.getBySite = function(site, cb) { + var options = { + format_media: true, + where: {site: site}, + order: {name:1} + }; + this.get(options, cb); + }; + /** * * @method getContentByPath diff --git a/plugins/pencilblue/controllers/admin/content/articles/article_form.js b/plugins/pencilblue/controllers/admin/content/articles/article_form.js index 14b5c7628..2d467b5e3 100755 --- a/plugins/pencilblue/controllers/admin/content/articles/article_form.js +++ b/plugins/pencilblue/controllers/admin/content/articles/article_form.js @@ -205,7 +205,7 @@ module.exports = function(pb) { media: function(callback) { var mservice = new pb.MediaService(); - mservice.get(callback); + mservice.getBySite(vars.siteid, callback); }, article: function(callback) { From 0f56a77c75cb2d458f7dd360b8aed38a1675fb1d Mon Sep 17 00:00:00 2001 From: Eugene Chang Date: Mon, 11 May 2015 13:27:13 -0400 Subject: [PATCH 102/790] Fixing missing services --- .../controllers/admin/content/navigation/nav_item_form.js | 2 ++ .../pencilblue/controllers/admin/content/navigation/nav_map.js | 2 ++ 2 files changed, 4 insertions(+) diff --git a/plugins/pencilblue/controllers/admin/content/navigation/nav_item_form.js b/plugins/pencilblue/controllers/admin/content/navigation/nav_item_form.js index 65342937d..36dbc3b02 100644 --- a/plugins/pencilblue/controllers/admin/content/navigation/nav_item_form.js +++ b/plugins/pencilblue/controllers/admin/content/navigation/nav_item_form.js @@ -44,6 +44,8 @@ module.exports = function(pb) { else { self.navService = new pb.SectionService(self.pathSiteUId, true); self.sitePrefix = pb.SiteService.getCurrentSitePrefix(self.pathSiteUId); + self.queryService = new pb.SiteQueryService(self.pathSiteUId); + self.settings = pb.SettingServiceFactory.getServiceBySite(self.pathSiteUId, true); var siteService = new pb.SiteService(); siteService.getSiteNameByUid(self.pathSiteUId, function (siteName) { self.siteName = siteName; diff --git a/plugins/pencilblue/controllers/admin/content/navigation/nav_map.js b/plugins/pencilblue/controllers/admin/content/navigation/nav_map.js index 6914190e5..6e740f74b 100644 --- a/plugins/pencilblue/controllers/admin/content/navigation/nav_map.js +++ b/plugins/pencilblue/controllers/admin/content/navigation/nav_map.js @@ -39,6 +39,8 @@ module.exports = function(pb) { else { self.navService = new pb.SectionService(self.pathSiteUId, true); self.sitePrefix = pb.SiteService.getCurrentSitePrefix(self.pathSiteUId); + self.queryService = new pb.SiteQueryService(self.pathSiteUId); + self.settings = pb.SettingServiceFactory.getServiceBySite(self.pathSiteUId, true); var siteService = new pb.SiteService(); siteService.getSiteNameByUid(self.pathSiteUId, function (siteName) { self.siteName = siteName; From 81484ad43f28e36018f27b18abe9be6ee21720e7 Mon Sep 17 00:00:00 2001 From: Eugene Chang Date: Mon, 11 May 2015 13:53:33 -0400 Subject: [PATCH 103/790] Updating nav map on navigation delete for sites --- .../content/navigation/delete_nav_item.js | 26 +++++++++++++++++-- .../admin/content/navigation/nav_map.html | 8 +++--- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/plugins/pencilblue/controllers/actions/admin/content/navigation/delete_nav_item.js b/plugins/pencilblue/controllers/actions/admin/content/navigation/delete_nav_item.js index e7a4de10e..39ca5a5a0 100644 --- a/plugins/pencilblue/controllers/actions/admin/content/navigation/delete_nav_item.js +++ b/plugins/pencilblue/controllers/actions/admin/content/navigation/delete_nav_item.js @@ -26,6 +26,29 @@ module.exports = function(pb) { function DeleteNavItem(){} util.inherits(DeleteNavItem, pb.BaseController); + DeleteNavItem.prototype.init = function (props, cb) { + var self = this; + pb.BaseController.prototype.init.call(self, props, function () { + self.pathSiteUId = pb.SiteService.getCurrentSite(self.pathVars.siteid); + pb.SiteService.siteExists(self.pathSiteUId, function (err, exists) { + if (!exists) { + self.reqHandler.serve404(); + } + else { + self.navService = new pb.SectionService(self.pathSiteUId, true); + self.sitePrefix = pb.SiteService.getCurrentSitePrefix(self.pathSiteUId); + self.queryService = new pb.SiteQueryService(self.pathSiteUId); + self.settings = pb.SettingServiceFactory.getServiceBySite(self.pathSiteUId, true); + var siteService = new pb.SiteService(); + siteService.getSiteNameByUid(self.pathSiteUId, function (siteName) { + self.siteName = siteName; + cb(); + }); + } + }); + }); + }; + DeleteNavItem.prototype.render = function(cb) { var self = this; var vars = this.pathVars; @@ -83,8 +106,7 @@ module.exports = function(pb) { }; DeleteNavItem.prototype.updateNavMap = function(removeID, cb) { - var service = new pb.SectionService(); - service.removeFromSectionMap(removeID, cb); + this.navService.removeFromSectionMap(removeID, cb); }; //exports diff --git a/plugins/pencilblue/templates/angular/admin/content/navigation/nav_map.html b/plugins/pencilblue/templates/angular/admin/content/navigation/nav_map.html index 3199e1e31..53e22addd 100644 --- a/plugins/pencilblue/templates/angular/admin/content/navigation/nav_map.html +++ b/plugins/pencilblue/templates/angular/admin/content/navigation/nav_map.html @@ -16,7 +16,7 @@ }, itemMoved: function (event) {}, orderChanged: function(event) {}, - } + }; $scope.saveNavMap = function() { var navMap = []; @@ -45,12 +45,12 @@ $scope.errorMessage = error.message; $scope.saving = false; }); - } + }; $scope.confirmDelete = function(item) { $scope.objectToDelete = item; $('#confirm_delete_modal').modal({backdrop: 'static', keyboard: true}); - } + }; $scope.deleteObject = function() { if(!$scope.objectToDelete) { @@ -58,7 +58,7 @@ } $scope.deleting = true; - $http({method: 'DELETE', url: '/actions/admin/content/navigation/' + $scope.objectToDelete._id}) + $http({method: 'DELETE', url: '/actions/admin' + $scope.sitePrefix + '/content/navigation/' + $scope.objectToDelete._id}) .success(function(result) { $scope.deleting = false; $scope.successMessage = result.message; From 8ee3f058c74f69b7d1e404bbd03e924ac1cdef87 Mon Sep 17 00:00:00 2001 From: Eugene Chang Date: Mon, 11 May 2015 14:44:08 -0400 Subject: [PATCH 104/790] Updating section for frontend loading. --- .../service/entities/site_query_service.js | 17 ++++++++++++++ .../admin/content/navigation/new_nav_item.js | 23 ++++++++++++++++--- plugins/pencilblue/controllers/section.js | 12 ++++++++-- 3 files changed, 47 insertions(+), 5 deletions(-) diff --git a/include/service/entities/site_query_service.js b/include/service/entities/site_query_service.js index 6d8193348..dc1f77427 100644 --- a/include/service/entities/site_query_service.js +++ b/include/service/entities/site_query_service.js @@ -149,6 +149,23 @@ module.exports = function SiteQueryServiceModule(pb) { dao.save(dbObj, options, callback); }; + /** + * Wrapper for DAO.loadByValue; Retrieves objects matching a key value pair + * + * @method loadByValue + * @param {String} key The key to search for + * @param {*} value The value to search for + * @param {String} collection The collection to search in + * @param {Object} options Key value pair object to exclude the retrival of data + * @param {Function} callback Callback function + */ + SiteQueryService.prototype.loadByValue = function (key, value, collection, options, callback) { + var where = {}; + where[key] = value; + where = modifyLoadWhere(this.siteUId, where); + dao.loadByValues(where, collection, options, callback); + }; + function modifySave(site, objectToSave) { if (pb.config.multisite && !(SITE_FIELD in objectToSave)) { objectToSave[SITE_FIELD] = site; diff --git a/plugins/pencilblue/controllers/actions/admin/content/navigation/new_nav_item.js b/plugins/pencilblue/controllers/actions/admin/content/navigation/new_nav_item.js index 8d9b3b995..b1ac862eb 100644 --- a/plugins/pencilblue/controllers/actions/admin/content/navigation/new_nav_item.js +++ b/plugins/pencilblue/controllers/actions/admin/content/navigation/new_nav_item.js @@ -27,9 +27,26 @@ module.exports = function(pb) { util.inherits(NewNavItem, pb.BaseController); NewNavItem.prototype.init = function (props, cb) { - this.pathSiteUId = pb.SiteService.getCurrentSite(props.path_vars.siteid); - this.navService = new pb.SectionService(this.pathSiteUId, true); - pb.BaseController.prototype.init.call(this, props, cb); + var self = this; + pb.BaseController.prototype.init.call(self, props, function () { + self.pathSiteUId = pb.SiteService.getCurrentSite(self.pathVars.siteid); + pb.SiteService.siteExists(self.pathSiteUId, function (err, exists) { + if (!exists) { + self.reqHandler.serve404(); + } + else { + self.navService = new pb.SectionService(self.pathSiteUId, true); + self.sitePrefix = pb.SiteService.getCurrentSitePrefix(self.pathSiteUId); + self.queryService = new pb.SiteQueryService(self.pathSiteUId); + self.settings = pb.SettingServiceFactory.getServiceBySite(self.pathSiteUId, true); + var siteService = new pb.SiteService(); + siteService.getSiteNameByUid(self.pathSiteUId, function (siteName) { + self.siteName = siteName; + cb(); + }); + } + }); + }); }; NewNavItem.prototype.render = function(cb){ diff --git a/plugins/pencilblue/controllers/section.js b/plugins/pencilblue/controllers/section.js index a6509a067..9bb121569 100755 --- a/plugins/pencilblue/controllers/section.js +++ b/plugins/pencilblue/controllers/section.js @@ -27,12 +27,20 @@ module.exports = function SectionModule(pb) { function Section(){} util.inherits(Section, Index); + Section.prototype.init = function (props, cb) { + var self = this; + pb.BaseController.prototype.init.call(self, props, function () { + self.siteUId = pb.SiteService.getCurrentSite(self.site); + self.navService = new pb.SectionService(self.pathSiteUId); + self.queryService = new pb.SiteQueryService(self.siteUId); + cb(); + }); + }; Section.prototype.render = function(cb) { var self = this; var custUrl = this.pathVars.customUrl; - var dao = new pb.DAO(); - dao.loadByValue('url', custUrl, 'section', function(err, section) { + self.queryService.loadByValue('url', custUrl, 'section', function(err, section) { if (util.isError(err) || section == null) { self.reqHandler.serve404(); return; From 9070d5dca34d4f8b2ae5a8e072977b6229ddf4f3 Mon Sep 17 00:00:00 2001 From: btidwell Date: Mon, 11 May 2015 15:51:03 -0400 Subject: [PATCH 105/790] Load site specific media on page_form --- plugins/pencilblue/controllers/admin/content/pages/page_form.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/pencilblue/controllers/admin/content/pages/page_form.js b/plugins/pencilblue/controllers/admin/content/pages/page_form.js index d6dbe96ba..f15bf4259 100755 --- a/plugins/pencilblue/controllers/admin/content/pages/page_form.js +++ b/plugins/pencilblue/controllers/admin/content/pages/page_form.js @@ -204,7 +204,7 @@ module.exports = function(pb) { media: function(callback) { var mservice = new pb.MediaService(); - mservice.get(callback); + mservice.getBySite(vars.siteid, callback); }, page: function(callback) { From eb5db3c53a01e90d0608d52f9815ddba0dfa4b7c Mon Sep 17 00:00:00 2001 From: Eugene Chang Date: Mon, 11 May 2015 15:55:49 -0400 Subject: [PATCH 106/790] Update editing nav item --- .../admin/content/navigation/edit_nav_item.js | 32 +++++++++++++++---- 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/plugins/pencilblue/controllers/actions/admin/content/navigation/edit_nav_item.js b/plugins/pencilblue/controllers/actions/admin/content/navigation/edit_nav_item.js index a4f1bab35..f0fd15e56 100644 --- a/plugins/pencilblue/controllers/actions/admin/content/navigation/edit_nav_item.js +++ b/plugins/pencilblue/controllers/actions/admin/content/navigation/edit_nav_item.js @@ -26,6 +26,29 @@ module.exports = function(pb) { function EditNavItem(){} util.inherits(EditNavItem, pb.BaseController); + EditNavItem.prototype.init = function (props, cb) { + var self = this; + pb.BaseController.prototype.init.call(self, props, function () { + self.pathSiteUId = pb.SiteService.getCurrentSite(self.pathVars.siteid); + pb.SiteService.siteExists(self.pathSiteUId, function (err, exists) { + if (!exists) { + self.reqHandler.serve404(); + } + else { + self.navService = new pb.SectionService(self.pathSiteUId, true); + self.sitePrefix = pb.SiteService.getCurrentSitePrefix(self.pathSiteUId); + self.queryService = new pb.SiteQueryService(self.pathSiteUId); + self.settings = pb.SettingServiceFactory.getServiceBySite(self.pathSiteUId, true); + var siteService = new pb.SiteService(); + siteService.getSiteNameByUid(self.pathSiteUId, function (siteName) { + self.siteName = siteName; + cb(); + }); + } + }); + }); + }; + EditNavItem.prototype.render = function(cb){ var self = this; var vars = this.pathVars; @@ -63,8 +86,7 @@ module.exports = function(pb) { pb.SectionService.trimForType(navItem); //validate - var navService = new pb.SectionService(); - navService.save(navItem, function(err, result) { + self.navService.save(navItem, function(err, result) { if(util.isError(err)) { cb({ code: 500, @@ -89,13 +111,11 @@ module.exports = function(pb) { }; EditNavItem.prototype.deleteOrphans = function(navItem, cb) { - var service = new pb.SectionService(); - service.deleteChildren(navItem[pb.DAO.getIdField()], cb); + this.navService.deleteChildren(navItem[pb.DAO.getIdField()], cb); }; EditNavItem.prototype.checkForNavMapUpdate = function(navItem, cb) { - var service = new pb.SectionService(); - service.updateNavMap(navItem, cb); + this.navService.updateNavMap(navItem, cb); }; EditNavItem.getHtmlErrorMsg = function(validationErrors) { From cb3284118e6918745f9242712a2c0cab44dc37a9 Mon Sep 17 00:00:00 2001 From: Eugene Chang Date: Tue, 12 May 2015 09:30:01 -0400 Subject: [PATCH 107/790] Article siteid fix --- .../controllers/admin/content/articles/manage_articles.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/pencilblue/controllers/admin/content/articles/manage_articles.js b/plugins/pencilblue/controllers/admin/content/articles/manage_articles.js index 18f3059ff..e70d80eb0 100755 --- a/plugins/pencilblue/controllers/admin/content/articles/manage_articles.js +++ b/plugins/pencilblue/controllers/admin/content/articles/manage_articles.js @@ -55,7 +55,7 @@ module.exports = function(pb) { return self.reqHandler.serveError(err); } else if (articles.length <= 0) { - return self.redirect('/admin' + pb.SiteService.getCurrentSitePrefix(siteid) + '/content/articles/new', cb); + return self.redirect('/admin' + self.sitePrefix + '/content/articles/new', cb); } pb.users.getAuthors(articles, function(err, articlesWithAuthorNames) { From 806b3a3f5feee93842d3ace2cb372dd28372ca7e Mon Sep 17 00:00:00 2001 From: Eugene Chang Date: Tue, 12 May 2015 09:31:18 -0400 Subject: [PATCH 108/790] Page siteid fix --- .../pencilblue/controllers/admin/content/pages/manage_pages.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/pencilblue/controllers/admin/content/pages/manage_pages.js b/plugins/pencilblue/controllers/admin/content/pages/manage_pages.js index 2edbabfbd..30ef34413 100755 --- a/plugins/pencilblue/controllers/admin/content/pages/manage_pages.js +++ b/plugins/pencilblue/controllers/admin/content/pages/manage_pages.js @@ -50,7 +50,7 @@ module.exports = function(pb) { return self.reqHandler.serveError(err); } else if(pages.length === 0) { - return self.redirect('/admin' + pb.SiteService.getCurrentSitePrefix(siteid) + '/content/pages/new', cb); + return self.redirect('/admin' + self.sitePrefix + '/content/pages/new', cb); } pb.users.getAuthors(pages, function(err, pagesWithAuthor) { From b572b64f740788865c3bf9736e3a5bc2c688f1cc Mon Sep 17 00:00:00 2001 From: btidwell Date: Tue, 12 May 2015 10:12:41 -0400 Subject: [PATCH 109/790] Add site to inline_media for page and article --- .../admin/content/articles/article_form.js | 12 +++++++++--- .../controllers/admin/content/pages/page_form.js | 13 +++++++++---- .../angular/admin/elements/inline_media.html | 4 ++-- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/plugins/pencilblue/controllers/admin/content/articles/article_form.js b/plugins/pencilblue/controllers/admin/content/articles/article_form.js index 79277b126..16c9b1cfc 100755 --- a/plugins/pencilblue/controllers/admin/content/articles/article_form.js +++ b/plugins/pencilblue/controllers/admin/content/articles/article_form.js @@ -96,8 +96,13 @@ module.exports = function(pb) { ArticleForm.prototype.getAngularObjects = function(tabs, data, cb) { var self = this; - if(pb.config.multisite && !data.article.site) { - data.article.site = pb.SiteService.getCurrentSite(this.pathVars.siteid); + if(pb.config.multisite) { + if(!data.site) { + data.site = pb.SiteService.getCurrentSite(this.pathVars.siteid); + } + if(!data.article.site) { + data.article.site = data.site; + } } if(data.article[pb.DAO.getIdField()]) { var media = []; @@ -148,7 +153,8 @@ module.exports = function(pb) { sections: data.sections, topics: data.topics, media: data.media, - article: data.article + article: data.article, + site: data.site }; if(data.availableAuthors) { objects.availableAuthors = data.availableAuthors; diff --git a/plugins/pencilblue/controllers/admin/content/pages/page_form.js b/plugins/pencilblue/controllers/admin/content/pages/page_form.js index f15bf4259..6ad8584b2 100755 --- a/plugins/pencilblue/controllers/admin/content/pages/page_form.js +++ b/plugins/pencilblue/controllers/admin/content/pages/page_form.js @@ -88,8 +88,13 @@ module.exports = function(pb) { */ PageFormController.prototype.getAngularObjects = function(tabs, data, cb) { var self = this; - if(pb.config.multisite && !data.page.site) { - data.page.site = pb.SiteService.getCurrentSite(this.pathVars.siteid); + if(pb.config.multisite) { + if(!data.site) { + data.site = pb.SiteService.getCurrentSite(this.pathVars.siteid); + } + if(!data.page.site) { + data.page.site = data.site; + } } if(data.page[pb.DAO.getIdField()]) { var media = []; @@ -118,7 +123,6 @@ module.exports = function(pb) { } data.page.page_topics = topics; } - data.site = data.page.site; pb.AdminSubnavService.getWithSite(this.getActivePill(), this.ls, this.getActivePill(), data, function(pills) { var objects = { navigation: pb.AdminNavigation.get(self.session, ['content', 'pages'], self.ls), @@ -128,7 +132,8 @@ module.exports = function(pb) { sections: data.sections, topics: data.topics, media: data.media, - page: data.page + page: data.page, + site: data.site }; if(data.availableAuthors) { objects.availableAuthors = data.availableAuthors; diff --git a/plugins/pencilblue/templates/angular/admin/elements/inline_media.html b/plugins/pencilblue/templates/angular/admin/elements/inline_media.html index 66390f2e5..4d6fc6b48 100644 --- a/plugins/pencilblue/templates/angular/admin/elements/inline_media.html +++ b/plugins/pencilblue/templates/angular/admin/elements/inline_media.html @@ -10,9 +10,9 @@ $scope.mediaPreview = ''; $scope.addedMedia = { link: '', - topics: [] + topics: [], + site: $scope.site }; - $scope.searchText = ''; $scope.paginationIndex = 0; $scope.paginationLimit = 15; From 4771fa8c9bf30c67579bcc92a13607ce47945ccc Mon Sep 17 00:00:00 2001 From: btidwell Date: Tue, 12 May 2015 11:08:55 -0400 Subject: [PATCH 110/790] Add site prefix to media links and use init in manage_media.js --- .../admin/content/media/manage_media.js | 21 ++++++++++++------- .../admin/content/media/manage_media.html | 2 +- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/plugins/pencilblue/controllers/admin/content/media/manage_media.js b/plugins/pencilblue/controllers/admin/content/media/manage_media.js index e81b093ca..974e945f7 100755 --- a/plugins/pencilblue/controllers/admin/content/media/manage_media.js +++ b/plugins/pencilblue/controllers/admin/content/media/manage_media.js @@ -29,9 +29,15 @@ module.exports = function(pb) { //statics var SUB_NAV_KEY = 'manage_media'; + ManageMedia.prototype.init = function (props, cb) { + this.pathSiteUId = pb.SiteService.getCurrentSite(props.path_vars.siteid); + this.sitePrefix = pb.SiteService.getCurrentSitePrefix(this.pathSiteUId); + + pb.BaseController.prototype.init.call(this, props, cb); + }; + ManageMedia.prototype.render = function(cb) { var self = this; - var siteid = pb.SiteService.getCurrentSite(self.pathVars.siteid); var options = { select: { name: 1, @@ -40,18 +46,18 @@ module.exports = function(pb) { media_type: 1, location: 1 }, - where : {site: siteid}, + where : {site: self.pathSiteUId}, order: {created: pb.DAO.DESC}, format_media: true }; var mservice = new pb.MediaService(); mservice.get(options, function(err, mediaData) { if(util.isError(mediaData) || mediaData.length === 0) { - self.redirect('/admin' + pb.SiteService.getCurrentSitePrefix(siteid) + '/content/media/new', cb); + self.redirect('/admin' + self.adminPrefix + '/content/media/new', cb); return; } - self.getAngularObjects(siteid, mediaData, function(angularObjects) { + self.getAngularObjects(mediaData, function(angularObjects) { var title = self.ls.get('MANAGE_MEDIA'); self.setPageName(title); self.ts.registerLocal('angular_objects', new pb.TemplateValue(angularObjects, false)); @@ -62,14 +68,15 @@ module.exports = function(pb) { }); }; - ManageMedia.prototype.getAngularObjects = function(site, mediaData, cb) { + ManageMedia.prototype.getAngularObjects = function(mediaData, cb) { var self = this; - pb.AdminSubnavService.getWithSite(SUB_NAV_KEY, self.ls, SUB_NAV_KEY, {site: site}, function(pills) { + pb.AdminSubnavService.getWithSite(SUB_NAV_KEY, self.ls, SUB_NAV_KEY, {site: self.pathSiteUId}, function(pills) { var angularObjects = pb.ClientJs.getAngularObjects( { navigation: pb.AdminNavigation.get(self.session, ['content', 'media'], self.ls), pills: pills, - media: pb.MediaService.formatMedia(mediaData) + media: pb.MediaService.formatMedia(mediaData), + sitePrefix: self.sitePrefix }); cb(angularObjects); }); diff --git a/plugins/pencilblue/templates/admin/content/media/manage_media.html b/plugins/pencilblue/templates/admin/content/media/manage_media.html index e62705e05..7783fc7e2 100755 --- a/plugins/pencilblue/templates/admin/content/media/manage_media.html +++ b/plugins/pencilblue/templates/admin/content/media/manage_media.html @@ -12,7 +12,7 @@ - + From 57b19330d290266242c8fcf3082d062172c5b9a0 Mon Sep 17 00:00:00 2001 From: btidwell Date: Tue, 12 May 2015 11:30:09 -0400 Subject: [PATCH 111/790] Use correct variable for sitePrefix on redirect --- .../pencilblue/controllers/admin/content/media/manage_media.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/pencilblue/controllers/admin/content/media/manage_media.js b/plugins/pencilblue/controllers/admin/content/media/manage_media.js index 974e945f7..05cda2f24 100755 --- a/plugins/pencilblue/controllers/admin/content/media/manage_media.js +++ b/plugins/pencilblue/controllers/admin/content/media/manage_media.js @@ -53,7 +53,7 @@ module.exports = function(pb) { var mservice = new pb.MediaService(); mservice.get(options, function(err, mediaData) { if(util.isError(mediaData) || mediaData.length === 0) { - self.redirect('/admin' + self.adminPrefix + '/content/media/new', cb); + self.redirect('/admin' + self.sitePrefix + '/content/media/new', cb); return; } From 592e00b8df17ccde15ef01c4a6f2ac3d9de2f671 Mon Sep 17 00:00:00 2001 From: Eugene Chang Date: Tue, 12 May 2015 11:47:33 -0400 Subject: [PATCH 112/790] Adding wrapper for loadById --- include/service/entities/site_query_service.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/include/service/entities/site_query_service.js b/include/service/entities/site_query_service.js index dc1f77427..9a7c6dc08 100644 --- a/include/service/entities/site_query_service.js +++ b/include/service/entities/site_query_service.js @@ -166,6 +166,20 @@ module.exports = function SiteQueryServiceModule(pb) { dao.loadByValues(where, collection, options, callback); }; + /** + * Wrapper for DAO.loadById; loads an object by its id, but its site must also match the query service's site + * + * @method loadById + * @param {String} id The unique id of the object + * @param {String} collection The collection the object is in + * @param {Object} options Key value pair object to exclude the retrival of data + * @param {Function} callback Callback function + */ + SiteQueryService.prototype.loadById = function (id, collection, options, callback) { + var where = modifyLoadWhere(this.siteUId, DAO.getIdWhere(id)); + dao.loadByValues(where, collection, options, callback); + }; + function modifySave(site, objectToSave) { if (pb.config.multisite && !(SITE_FIELD in objectToSave)) { objectToSave[SITE_FIELD] = site; From 8fb16eeea816e7b1c393e24fefd157d3ccbd5413 Mon Sep 17 00:00:00 2001 From: Eugene Chang Date: Tue, 12 May 2015 11:53:29 -0400 Subject: [PATCH 113/790] Fixing reference to DAO --- include/service/entities/site_query_service.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/service/entities/site_query_service.js b/include/service/entities/site_query_service.js index 9a7c6dc08..128d7cdf2 100644 --- a/include/service/entities/site_query_service.js +++ b/include/service/entities/site_query_service.js @@ -176,7 +176,7 @@ module.exports = function SiteQueryServiceModule(pb) { * @param {Function} callback Callback function */ SiteQueryService.prototype.loadById = function (id, collection, options, callback) { - var where = modifyLoadWhere(this.siteUId, DAO.getIdWhere(id)); + var where = modifyLoadWhere(this.siteUId, pb.DAO.getIdWhere(id)); dao.loadByValues(where, collection, options, callback); }; From ce3f75f0ec9235913733eff104bbc33b24ff006b Mon Sep 17 00:00:00 2001 From: andparker Date: Tue, 12 May 2015 12:02:12 -0400 Subject: [PATCH 114/790] Make all of custom objects and custom object types site aware | Site routing validation | Error correction --- include/config.js | 13 +++--- .../service/entities/custom_object_service.js | 23 ++++++----- .../service/entities/site_query_service.js | 13 ++++++ .../admin/content/objects/delete_object.js | 18 ++++++++- .../admin/content/objects/edit_object.js | 18 ++++++++- .../admin/content/objects/new_object.js | 18 ++++++++- .../admin/content/objects/sort_objects.js | 18 ++++++++- .../content/objects/types/delete_type.js | 18 ++++++++- .../admin/content/objects/types/edit_type.js | 18 ++++++++- .../admin/content/objects/types/new_type.js | 18 ++++++++- .../admin/content/objects/manage_objects.js | 40 +++++++++++++++---- .../admin/content/objects/object_form.js | 35 ++++++++++++++-- .../admin/content/objects/sort_objects.js | 37 ++++++++++++++--- .../content/objects/types/manage_types.js | 38 +++++++++++++----- .../admin/content/objects/types/type_form.js | 21 +++++++--- .../admin/content/objects/types/available.js | 18 ++++++++- .../admin/content/objects/manage_objects.html | 2 +- .../admin/content/objects/object_form.html | 2 +- .../admin/content/objects/sort_objects.html | 2 +- .../content/objects/types/manage_types.html | 4 +- .../content/objects/types/type_form.html | 2 +- .../admin/content/objects/manage_objects.html | 2 +- .../admin/content/objects/object_form.html | 4 +- .../admin/content/objects/sort_objects.html | 2 +- .../content/objects/types/manage_types.html | 2 +- .../content/objects/types/type_form.html | 8 ++-- 26 files changed, 319 insertions(+), 75 deletions(-) diff --git a/include/config.js b/include/config.js index 585b92ef2..65ed6836d 100755 --- a/include/config.js +++ b/include/config.js @@ -21,7 +21,6 @@ var path = require('path'); var cluster = require('cluster'); var process = require('process'); var util = require('./util.js'); -var process = require('process'); var winston = require('winston'); /** @@ -113,7 +112,7 @@ var CONFIG_MODULE_NAME = 'config.js'; */ var OVERRIDE_FILE_PATHS = [ path.join(Configuration.DOCUMENT_ROOT, CONFIG_MODULE_NAME), - path.join(Configuration.EXTERNAL_ROOT, CONFIG_MODULE_NAME), + path.join(Configuration.EXTERNAL_ROOT, CONFIG_MODULE_NAME) ]; /** @@ -337,7 +336,7 @@ var BASE_CONFIG = { //custom object type { collection: 'custom_object_type', - spec: {name: ASC}, + spec: {name: ASC, site: ASC}, options: {unique: true} }, { @@ -489,7 +488,7 @@ var BASE_CONFIG = { cache: { fake: true, host: "localhost", - port: 6379, + port: 6379 //auth_pass: "password here" }, @@ -522,7 +521,7 @@ var BASE_CONFIG = { //The timeout specifies how long in milliseconds a setting will exist //in memory before being flushed. A value of 0 indicates that the //values will not be purged from memory once expired. - memory_timeout: 0, + memory_timeout: 0 }, //The template engine can take advantage of caching so that they are not @@ -536,7 +535,7 @@ var BASE_CONFIG = { //The timeout specifies how long in milliseconds a setting will exist //in memory before being flushed. A value of 0 indicates that the //values will not be purged from memory once expired. - memory_timeout: 0, + memory_timeout: 0 }, //Plugins can also take advantage of the caching. This prevents a DB call @@ -549,7 +548,7 @@ var BASE_CONFIG = { //The timeout specifies how long in milliseconds a setting will exist //in memory before being flushed. A value of 0 indicates that the //values will not be purged from memory once expired. - memory_timeout: 0, + memory_timeout: 0 } }, diff --git a/include/service/entities/custom_object_service.js b/include/service/entities/custom_object_service.js index dd6c7e718..7916ff180 100644 --- a/include/service/entities/custom_object_service.js +++ b/include/service/entities/custom_object_service.js @@ -28,9 +28,12 @@ module.exports = function CustomObjectServiceModule(pb) { * @class CustomObjectService * @constructor */ - function CustomObjectService() { + function CustomObjectService(pathSiteUid) { this.typesCache = {}; this.typesNametoId = {}; + + this.site = pb.SiteService.getCurrentSite(pathSiteUid); + this.siteQueryService = new pb.SiteQueryService(this.site); } //statics @@ -486,8 +489,8 @@ module.exports = function CustomObjectServiceModule(pb) { select: pb.DAO.PROJECT_ALL, order: {NAME_FIELD: pb.DAO.ASC} }; - var dao = new pb.DAO(); - dao.q(CustomObjectService.CUST_OBJ_TYPE_COLL, opts, function(err, custObjTypes) { + + this.siteQueryService.q(CustomObjectService.CUST_OBJ_TYPE_COLL, opts, function(err, custObjTypes) { if (util.isArray(custObjTypes)) { //currently, mongo cannot do case-insensitive sorts. We do it manually //until a solution for https://jira.mongodb.org/browse/SERVER-90 is merged. @@ -756,7 +759,6 @@ module.exports = function CustomObjectServiceModule(pb) { var self = this; var errors = []; - var dao = new pb.DAO(); var tasks = [ //validate the name @@ -776,7 +778,7 @@ module.exports = function CustomObjectServiceModule(pb) { //test uniqueness of name var where = {}; where[NAME_FIELD] = new RegExp('^'+util.escapeRegExp(custObjType.name)+'$', 'i'); - dao.unique(CustomObjectService.CUST_OBJ_TYPE_COLL, where, custObjType[pb.DAO.getIdField()], function(err, isUnique){ + self.siteQueryService.unique(CustomObjectService.CUST_OBJ_TYPE_COLL, where, custObjType[pb.DAO.getIdField()], function(err, isUnique){ if(!isUnique) { errors.push(CustomObjectService.err('name', 'The name '+custObjType.name+' is not unique')); } @@ -862,8 +864,8 @@ module.exports = function CustomObjectServiceModule(pb) { where: pb.DAO.ANYWHERE, select: select }; - var dao = new pb.DAO(); - dao.q(CustomObjectService.CUST_OBJ_TYPE_COLL, opts, function(err, types) { + + this.siteQueryService.q(CustomObjectService.CUST_OBJ_TYPE_COLL, opts, function(err, types) { if (util.isError(err)) { return cb(err); } @@ -923,8 +925,7 @@ module.exports = function CustomObjectServiceModule(pb) { return cb(err, errors); } - var dao = new pb.DAO(); - dao.save(custObjType, cb); + self.siteQueryService.save(custObjType, cb); }); }; @@ -995,8 +996,8 @@ module.exports = function CustomObjectServiceModule(pb) { var where = { name: new RegExp('^'+util.escapeRegExp(typeName)+'$', 'ig') }; - var dao = new pb.DAO(); - dao.exists(CustomObjectService.CUST_OBJ_TYPE_COLL, where, cb); + + this.siteQueryService.exists(CustomObjectService.CUST_OBJ_TYPE_COLL, where, cb); }; /** diff --git a/include/service/entities/site_query_service.js b/include/service/entities/site_query_service.js index dc1f77427..598fe0155 100644 --- a/include/service/entities/site_query_service.js +++ b/include/service/entities/site_query_service.js @@ -123,6 +123,19 @@ module.exports = function SiteQueryServiceModule(pb) { return !siteUId || siteUId === GLOBAL_SITE; } + /** + * Wrapper for site-aware DAO.exists. Determines if an object exists matching criteria with the specified site. + * + * @method exists + * @param {String} collection The collection to search in + * @param {Object} where Key value pair object + * @param {Function} cb Callback function + */ + SiteQueryService.prototype.exists = function(collection, where, cb) { + where = modifyLoadWhere(this.siteUId, where); + dao.exists(collection, where, cb) + }; + /** * Wrapper for site-aware DAO.unique, determine if the document matching the query is unique within specified site * Only searches within specified site. diff --git a/plugins/pencilblue/controllers/actions/admin/content/objects/delete_object.js b/plugins/pencilblue/controllers/actions/admin/content/objects/delete_object.js index 9d6c51816..ba41b8cc6 100644 --- a/plugins/pencilblue/controllers/actions/admin/content/objects/delete_object.js +++ b/plugins/pencilblue/controllers/actions/admin/content/objects/delete_object.js @@ -26,6 +26,22 @@ module.exports = function(pb) { function DeleteObject(){} util.inherits(DeleteObject, pb.BaseController); + DeleteObject.prototype.init = function (props, cb) { + var self = this; + + pb.BaseController.prototype.init.call(self, props, function() { + self.pathSiteUid = pb.SiteService.getCurrentSite(self.pathVars.siteid); + pb.SiteService.siteExists(self.pathSiteUid, function (err, exists) { + if (!exists) { + self.reqHandler.serve404(); + } + else { + cb(); + } + }); + }); + }; + DeleteObject.prototype.render = function(cb) { var self = this; var vars = this.pathVars; @@ -42,7 +58,7 @@ module.exports = function(pb) { return; } - var cos = new pb.CustomObjectService(); + var cos = new pb.CustomObjectService(self.pathSiteUid); cos.loadById(vars.id, function(err, customObject) { if (util.isError(err)) { return self.reqHandler.serveError(err); diff --git a/plugins/pencilblue/controllers/actions/admin/content/objects/edit_object.js b/plugins/pencilblue/controllers/actions/admin/content/objects/edit_object.js index 988822826..b1e9359f8 100644 --- a/plugins/pencilblue/controllers/actions/admin/content/objects/edit_object.js +++ b/plugins/pencilblue/controllers/actions/admin/content/objects/edit_object.js @@ -29,6 +29,22 @@ module.exports = function(pb) { function EditObject(){} util.inherits(EditObject, pb.BaseController); + EditObject.prototype.init = function (props, cb) { + var self = this; + + pb.BaseController.prototype.init.call(self, props, function() { + self.pathSiteUid = pb.SiteService.getCurrentSite(self.pathVars.siteid); + pb.SiteService.siteExists(self.pathSiteUid, function (err, exists) { + if (!exists) { + self.reqHandler.serve404(); + } + else { + cb(); + } + }); + }); + }; + EditObject.prototype.render = function(cb) { var self = this; var vars = this.pathVars; @@ -41,7 +57,7 @@ module.exports = function(pb) { return; } - var service = new pb.CustomObjectService(); + var service = new pb.CustomObjectService(self.pathSiteUid); service.loadById(vars.id, function(err, custObj) { if(util.isError(err) || !util.isObject(custObj)) { return cb({ diff --git a/plugins/pencilblue/controllers/actions/admin/content/objects/new_object.js b/plugins/pencilblue/controllers/actions/admin/content/objects/new_object.js index fa3d205c1..5d236945d 100644 --- a/plugins/pencilblue/controllers/actions/admin/content/objects/new_object.js +++ b/plugins/pencilblue/controllers/actions/admin/content/objects/new_object.js @@ -29,6 +29,22 @@ module.exports = function(pb) { function NewObjectActionController(){} util.inherits(NewObjectActionController, pb.BaseController); + NewObjectActionController.prototype.init = function (props, cb) { + var self = this; + + pb.BaseController.prototype.init.call(self, props, function() { + self.pathSiteUid = pb.SiteService.getCurrentSite(self.pathVars.siteid); + pb.SiteService.siteExists(self.pathSiteUid, function (err, exists) { + if (!exists) { + self.reqHandler.serve404(); + } + else { + cb(); + } + }); + }); + }; + NewObjectActionController.prototype.render = function(cb) { var self = this; var vars = this.pathVars; @@ -41,7 +57,7 @@ module.exports = function(pb) { return } - var service = new pb.CustomObjectService(); + var service = new pb.CustomObjectService(self.pathSiteUid); service.loadTypeById(vars.type_id, function(err, customObjectType) { if(util.isError(err) || !util.isObject(customObjectType)) { return cb({ diff --git a/plugins/pencilblue/controllers/actions/admin/content/objects/sort_objects.js b/plugins/pencilblue/controllers/actions/admin/content/objects/sort_objects.js index 328980722..a0149ca20 100644 --- a/plugins/pencilblue/controllers/actions/admin/content/objects/sort_objects.js +++ b/plugins/pencilblue/controllers/actions/admin/content/objects/sort_objects.js @@ -28,6 +28,22 @@ module.exports = function(pb) { function SortObjectsActionController(){} util.inherits(SortObjectsActionController, pb.FormController); + SortObjectsActionController.prototype.init = function (props, cb) { + var self = this; + + pb.BaseController.prototype.init.call(self, props, function() { + self.pathSiteUid = pb.SiteService.getCurrentSite(self.pathVars.siteid); + pb.SiteService.siteExists(self.pathSiteUid, function (err, exists) { + if (!exists) { + self.reqHandler.serve404(); + } + else { + cb(); + } + }); + }); + }; + SortObjectsActionController.prototype.render = function(cb) { var self = this; var vars = this.pathVars; @@ -39,7 +55,7 @@ module.exports = function(pb) { }); } - var service = new pb.CustomObjectService(); + var service = new pb.CustomObjectService(self.pathSiteUid); service.loadTypeById(vars.type_id, function(err, customObjectType) { if(util.isError(err) || !util.isObject(customObjectType)) { return cb({ diff --git a/plugins/pencilblue/controllers/actions/admin/content/objects/types/delete_type.js b/plugins/pencilblue/controllers/actions/admin/content/objects/types/delete_type.js index a644d3e0b..b23e510b1 100644 --- a/plugins/pencilblue/controllers/actions/admin/content/objects/types/delete_type.js +++ b/plugins/pencilblue/controllers/actions/admin/content/objects/types/delete_type.js @@ -26,6 +26,22 @@ module.exports = function(pb) { function DeleteObjectType(){} util.inherits(DeleteObjectType, pb.FormController); + DeleteObjectType.prototype.init = function (props, cb) { + var self = this; + + pb.BaseController.prototype.init.call(self, props, function() { + self.pathSiteUid = pb.SiteService.getCurrentSite(self.pathVars.siteid); + pb.SiteService.siteExists(self.pathSiteUid, function (err, exists) { + if (!exists) { + self.reqHandler.serve404(); + } + else { + cb(); + } + }); + }); + }; + DeleteObjectType.prototype.onPostParamsRetrieved = function(post, cb) { var self = this; var vars = this.pathVars; @@ -38,7 +54,7 @@ module.exports = function(pb) { } //ensure existence - var service = new pb.CustomObjectService(); + var service = new pb.CustomObjectService(self.pathSiteUid); service.loadTypeById(vars.id, function(err, objectType) { if(objectType === null) { cb({ diff --git a/plugins/pencilblue/controllers/actions/admin/content/objects/types/edit_type.js b/plugins/pencilblue/controllers/actions/admin/content/objects/types/edit_type.js index 2803505a4..b1bd92b34 100644 --- a/plugins/pencilblue/controllers/actions/admin/content/objects/types/edit_type.js +++ b/plugins/pencilblue/controllers/actions/admin/content/objects/types/edit_type.js @@ -29,6 +29,22 @@ module.exports = function(pb) { function EditObjectType(){} util.inherits(EditObjectType, pb.BaseController); + EditObjectType.prototype.init = function (props, cb) { + var self = this; + + pb.BaseController.prototype.init.call(self, props, function() { + self.pathSiteUid = pb.SiteService.getCurrentSite(self.pathVars.siteid); + pb.SiteService.siteExists(self.pathSiteUid, function (err, exists) { + if (!exists) { + self.reqHandler.serve404(); + } + else { + cb(); + } + }); + }); + }; + EditObjectType.prototype.render = function(cb) { var self = this; var vars = this.pathVars; @@ -40,7 +56,7 @@ module.exports = function(pb) { }); } - var service = new pb.CustomObjectService(); + var service = new pb.CustomObjectService(self.pathSiteUid); service.loadTypeById(vars.id, function(err, custObjType) { if(util.isError(err) || !util.isObject(custObjType)) { return cb({ diff --git a/plugins/pencilblue/controllers/actions/admin/content/objects/types/new_type.js b/plugins/pencilblue/controllers/actions/admin/content/objects/types/new_type.js index 0492274bd..99d971137 100644 --- a/plugins/pencilblue/controllers/actions/admin/content/objects/types/new_type.js +++ b/plugins/pencilblue/controllers/actions/admin/content/objects/types/new_type.js @@ -29,13 +29,29 @@ module.exports = function(pb) { function NewObjectTypeActionController(){} util.inherits(NewObjectTypeActionController, pb.BaseController); + NewObjectTypeActionController.prototype.init = function (props, cb) { + var self = this; + + pb.BaseController.prototype.init.call(self, props, function() { + self.pathSiteUid = pb.SiteService.getCurrentSite(self.pathVars.siteid); + pb.SiteService.siteExists(self.pathSiteUid, function (err, exists) { + if (!exists) { + self.reqHandler.serve404(); + } + else { + cb(); + } + }); + }); + }; + NewObjectTypeActionController.prototype.render = function(cb) { var self = this; var post = self.body; post.fields.name = {field_type: 'text'}; - var service = new pb.CustomObjectService(); + var service = new pb.CustomObjectService(self.pathSiteUid); service.saveType(post, function(err, result) { if(util.isError(err)) { return cb({ diff --git a/plugins/pencilblue/controllers/admin/content/objects/manage_objects.js b/plugins/pencilblue/controllers/admin/content/objects/manage_objects.js index dbd1abd7b..583bf9460 100644 --- a/plugins/pencilblue/controllers/admin/content/objects/manage_objects.js +++ b/plugins/pencilblue/controllers/admin/content/objects/manage_objects.js @@ -29,6 +29,27 @@ module.exports = function(pb) { function ManageObjects() {} util.inherits(ManageObjects, pb.BaseController); + ManageObjects.prototype.init = function (props, cb) { + var self = this; + + pb.BaseController.prototype.init.call(self, props, function() { + self.pathSiteUid = pb.SiteService.getCurrentSite(self.pathVars.siteid); + pb.SiteService.siteExists(self.pathSiteUid, function (err, exists) { + if (!exists) { + self.reqHandler.serve404(); + } + else { + self.pathSitePrefix = pb.SiteService.getCurrentSitePrefix(self.pathSiteUid); + var siteService = new pb.SiteService(); + siteService.getSiteNameByUid(self.pathSiteUid, function (siteName) { + self.siteName = siteName; + cb(); + }); + } + }); + }); + }; + //statics var SUB_NAV_KEY = 'manage_custom_objects'; @@ -56,24 +77,29 @@ module.exports = function(pb) { //none to manage if(customObjects.length === 0) { - return self.redirect(pb.UrlService.urlJoin('/admin/content/objects/', encodeURIComponent(vars.type_id), '/new'), cb); + return self.redirect(pb.UrlService.urlJoin('/admin' + self.pathSitePrefix + '/content/objects/', encodeURIComponent(vars.type_id), '/new'), cb); } - var pills = pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, 'manage_objects', custObjType); + var data = {}; + data.pathSitePrefix = self.pathSitePrefix; + data.custObjType = custObjType; + var pills = pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, 'manage_objects', data); for(var i = 0; i < pills.length; i++) { if(pills[i].name == 'manage_objects') { pills[i].title += ' (' + customObjects.length + ')'; break; } } + pills = pb.AdminSubnavService.addSiteToPills(pills, self.siteName); var angularObjects = pb.ClientJs.getAngularObjects( { navigation: pb.AdminNavigation.get(self.session, ['content', 'custom_objects'], self.ls), pills: pills, customObjects: customObjects, - objectType: custObjType + objectType: custObjType, + pathSitePrefix: self.pathSitePrefix }); var title = self.ls.get('MANAGE') + ' ' + custObjType.name; @@ -89,19 +115,19 @@ module.exports = function(pb) { ManageObjects.getSubNavItems = function(key, ls, data) { return [{ name: 'manage_objects', - title: ls.get('MANAGE') + ' ' + data.name + ' ' + ls.get('OBJECTS'), + title: ls.get('MANAGE') + ' ' + data.custObjType.name + ' ' + ls.get('OBJECTS'), icon: 'chevron-left', - href: '/admin/content/objects/types' + href: '/admin' + data.pathSitePrefix + '/content/objects/types' }, { name: 'sort_objects', title: '', icon: 'sort-amount-desc', - href: '/admin/content/objects/' + data[pb.DAO.getIdField()] + '/sort' + href: '/admin' + data.pathSitePrefix + '/content/objects/' + data.custObjType[pb.DAO.getIdField()] + '/sort' }, { name: 'new_object', title: '', icon: 'plus', - href: '/admin/content/objects/' + data[pb.DAO.getIdField()] + '/new' + href: '/admin' + data.pathSitePrefix + '/content/objects/' + data.custObjType[pb.DAO.getIdField()] + '/new' }]; }; diff --git a/plugins/pencilblue/controllers/admin/content/objects/object_form.js b/plugins/pencilblue/controllers/admin/content/objects/object_form.js index e2654bcf8..3365fc3b6 100644 --- a/plugins/pencilblue/controllers/admin/content/objects/object_form.js +++ b/plugins/pencilblue/controllers/admin/content/objects/object_form.js @@ -33,12 +33,33 @@ module.exports = function(pb) { var SUB_NAV_KEY = 'object_form'; + ObjectFormController.prototype.init = function (props, cb) { + var self = this; + + pb.BaseController.prototype.init.call(self, props, function() { + self.pathSiteUid = pb.SiteService.getCurrentSite(self.pathVars.siteid); + pb.SiteService.siteExists(self.pathSiteUid, function (err, exists) { + if (!exists) { + self.reqHandler.serve404(); + } + else { + self.pathSitePrefix = pb.SiteService.getCurrentSitePrefix(self.pathSiteUid); + var siteService = new pb.SiteService(); + siteService.getSiteNameByUid(self.pathSiteUid, function (siteName) { + self.siteName = siteName; + cb(); + }); + } + }); + }); + }; + ObjectFormController.prototype.render = function(cb) { var self = this; var vars = this.pathVars; if(!pb.validation.isIdStr(vars.type_id, true)) { - return self.redirect('/admin/content/objects/types', cb); + return self.redirect('/admin' + self.pathSitePrefix + '/content/objects/types', cb); } this.gatherData(vars, function(err, data) { @@ -83,7 +104,9 @@ module.exports = function(pb) { self.objectType = data.objectType; self.customObject = data.customObject; - data.pills = pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, SUB_NAV_KEY, {objectType: self.objectType, customObject: self.customObject}); + var pills = pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, SUB_NAV_KEY, {objectType: self.objectType, customObject: self.customObject, pathSitePrefix: self.pathSitePrefix}); + data.pills = pb.AdminSubnavService.addSiteToPills(pills, self.siteName); + var angularObjects = pb.ClientJs.getAngularObjects(data); self.setPageName(self.customObject[pb.DAO.getIdField()] ? self.customObject.name : self.ls.get('NEW') + ' ' + self.objectType.name + ' ' + self.ls.get('OBJECT')); @@ -116,6 +139,10 @@ module.exports = function(pb) { callback(null, pb.AdminNavigation.get(self.session, ['content', 'custom_objects'], self.ls)); }, + pathSitePrefix: function(callback) { + callback(null, self.pathSitePrefix) + }, + objectType: function(callback) { cos.loadTypeById(vars.type_id, function(err, objectType) { if(util.isError(err)) { @@ -244,13 +271,13 @@ module.exports = function(pb) { name: 'manage_objects', title: data.customObject[pb.DAO.getIdField()] ? ls.get('EDIT') + ' ' + data.customObject.name : ls.get('NEW') + ' ' + data.objectType.name + ' ' + ls.get('OBJECT'), icon: 'chevron-left', - href: '/admin/content/objects/' + data.objectType[pb.DAO.getIdField()] + href: '/admin' + data.pathSitePrefix + '/content/objects/' + data.objectType[pb.DAO.getIdField()] }, { name: 'new_object', title: '', icon: 'plus', - href: '/admin/content/objects/' + data.objectType[pb.DAO.getIdField()] + '/new' + href: '/admin' + data.pathSitePrefix + '/content/objects/' + data.objectType[pb.DAO.getIdField()] + '/new' } ]; }; diff --git a/plugins/pencilblue/controllers/admin/content/objects/sort_objects.js b/plugins/pencilblue/controllers/admin/content/objects/sort_objects.js index 4fd33b9e5..95aaa5fb6 100644 --- a/plugins/pencilblue/controllers/admin/content/objects/sort_objects.js +++ b/plugins/pencilblue/controllers/admin/content/objects/sort_objects.js @@ -32,6 +32,27 @@ module.exports = function(pb) { //statics var SUB_NAV_KEY = 'sort_custom_objects'; + SortObjects.prototype.init = function (props, cb) { + var self = this; + + pb.BaseController.prototype.init.call(self, props, function() { + self.pathSiteUid = pb.SiteService.getCurrentSite(self.pathVars.siteid); + pb.SiteService.siteExists(self.pathSiteUid, function (err, exists) { + if (!exists) { + self.reqHandler.serve404(); + } + else { + self.pathSitePrefix = pb.SiteService.getCurrentSitePrefix(self.pathSiteUid); + var siteService = new pb.SiteService(); + siteService.getSiteNameByUid(self.pathSiteUid, function (siteName) { + self.siteName = siteName; + cb(); + }); + } + }); + }); + }; + SortObjects.prototype.render = function(cb) { var self = this; var vars = this.pathVars; @@ -55,16 +76,20 @@ module.exports = function(pb) { //none to manage if(customObjects.length === 0) { - self.redirect('/admin/content/objects/' + vars.type_id + '/new', cb); + self.redirect('/admin' + self.pathSitePrefix + '/content/objects/' + vars.type_id + '/new', cb); return; } + var pills = pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, SUB_NAV_KEY, {objectType: objectType, pathSitePrefix: self.pathSitePrefix}); + pills = pb.AdminSubnavService.addSiteToPills(pills, self.siteName); + var angularObjects = pb.ClientJs.getAngularObjects( { navigation: pb.AdminNavigation.get(self.session, ['content', 'custom_objects'], self.ls), - pills: pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, null, objectType), + pills: pills, customObjects: customObjects, - objectType: objectType + objectType: objectType, + pathSitePrefix: self.pathSitePrefix }); self.setPageName(self.ls.get('SORT') + ' ' + objectType.name); @@ -79,14 +104,14 @@ module.exports = function(pb) { SortObjects.getSubNavItems = function(key, ls, data) { return [{ name: 'manage_objects', - title: ls.get('SORT') + ' ' + data.name + ' ' + ls.get('OBJECTS'), + title: ls.get('SORT') + ' ' + data.objectType.name + ' ' + ls.get('OBJECTS'), icon: 'chevron-left', - href: '/admin/content/objects/' + data[pb.DAO.getIdField()] + href: '/admin' + data.pathSitePrefix + '/content/objects/' + data.objectType[pb.DAO.getIdField()] }, { name: 'new_object', title: '', icon: 'plus', - href: '/admin/content/objects/' + data[pb.DAO.getIdField()] + '/new' + href: '/admin' + data.pathSitePrefix + '/content/objects/' + data.objectType[pb.DAO.getIdField()] + '/new' }]; }; diff --git a/plugins/pencilblue/controllers/admin/content/objects/types/manage_types.js b/plugins/pencilblue/controllers/admin/content/objects/types/manage_types.js index d2783516e..ae8e57293 100644 --- a/plugins/pencilblue/controllers/admin/content/objects/types/manage_types.js +++ b/plugins/pencilblue/controllers/admin/content/objects/types/manage_types.js @@ -33,17 +33,30 @@ module.exports = function(pb) { var SUB_NAV_KEY = 'manage_object_types'; ManageObjectTypes.prototype.init = function (props, cb) { + var self = this; - pb.BaseController.prototype.init.call(this, props, cb); - - this.pathSiteUid = pb.SiteService.getCurrentSite(props.path_vars.siteid); - this.pathSitePrefix = pb.SiteService.getCurrentSitePrefix(this.pathSiteUid); + pb.BaseController.prototype.init.call(self, props, function() { + self.pathSiteUid = pb.SiteService.getCurrentSite(self.pathVars.siteid); + pb.SiteService.siteExists(self.pathSiteUid, function (err, exists) { + if (!exists) { + self.reqHandler.serve404(); + } + else { + self.pathSitePrefix = pb.SiteService.getCurrentSitePrefix(self.pathSiteUid); + var siteService = new pb.SiteService(); + siteService.getSiteNameByUid(self.pathSiteUid, function (siteName) { + self.siteName = siteName; + cb(); + }); + } + }); + }); }; ManageObjectTypes.prototype.render = function(cb) { var self = this; - var service = new pb.CustomObjectService(); + var service = new pb.CustomObjectService(self.pathSiteUid); service.findTypes(function(err, custObjTypes) { //none to manage @@ -56,11 +69,16 @@ module.exports = function(pb) { pb.CustomObjectService.setFieldTypesUsed(custObjTypes, self.ls); //build out the angular controller + var data = {}; + data.pathSitePrefix = self.pathSitePrefix; + var pills = pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, SUB_NAV_KEY, data); + pills = pb.AdminSubnavService.addSiteToPills(pills, self.siteName); var angularObjects = pb.ClientJs.getAngularObjects( { navigation: pb.AdminNavigation.get(self.session, ['content', 'custom_objects'], self.ls), - pills: pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, 'manage_object_types'), - objectTypes: custObjTypes + pills: pills, + objectTypes: custObjTypes, + pathSitePrefix: self.pathSitePrefix }); self.setPageName(self.ls.get('MANAGE_OBJECT_TYPES')); @@ -74,18 +92,16 @@ module.exports = function(pb) { ManageObjectTypes.getSubNavItems = function(key, ls, data) { - var self = this; - return [{ name: SUB_NAV_KEY, title: ls.get('MANAGE_OBJECT_TYPES'), icon: 'refresh', - href: '/admin' + self.pathSitePrefix + '/content/objects/types' + href: '/admin' + data.pathSitePrefix + '/content/objects/types' }, { name: 'new_object_type', title: '', icon: 'plus', - href: '/admin' + self.pathSitePrefix + '/content/objects/types/new' + href: '/admin' + data.pathSitePrefix + '/content/objects/types/new' }]; }; diff --git a/plugins/pencilblue/controllers/admin/content/objects/types/type_form.js b/plugins/pencilblue/controllers/admin/content/objects/types/type_form.js index c893b8613..7a7dffbff 100644 --- a/plugins/pencilblue/controllers/admin/content/objects/types/type_form.js +++ b/plugins/pencilblue/controllers/admin/content/objects/types/type_form.js @@ -35,12 +35,21 @@ module.exports = function(pb) { TypeForm.prototype.init = function (props, cb) { var self = this; - self.pathSiteUid = pb.SiteService.getCurrentSite(props.path_vars.siteid); - self.pathSitePrefix = pb.SiteService.getCurrentSitePrefix(self.pathSiteUid); - var siteService = new pb.SiteService(); - siteService.getSiteNameByUid(self.pathSiteUid, function (siteName) { - self.siteName = siteName; - pb.BaseController.prototype.init.call(self, props, cb); + pb.BaseController.prototype.init.call(self, props, function() { + self.pathSiteUid = pb.SiteService.getCurrentSite(self.pathVars.siteid); + pb.SiteService.siteExists(self.pathSiteUid, function (err, exists) { + if (!exists) { + self.reqHandler.serve404(); + } + else { + self.pathSitePrefix = pb.SiteService.getCurrentSitePrefix(self.pathSiteUid); + var siteService = new pb.SiteService(); + siteService.getSiteNameByUid(self.pathSiteUid, function (siteName) { + self.siteName = siteName; + cb(); + }); + } + }); }); }; diff --git a/plugins/pencilblue/controllers/api/admin/content/objects/types/available.js b/plugins/pencilblue/controllers/api/admin/content/objects/types/available.js index a4b517749..bd1c71f24 100644 --- a/plugins/pencilblue/controllers/api/admin/content/objects/types/available.js +++ b/plugins/pencilblue/controllers/api/admin/content/objects/types/available.js @@ -26,6 +26,22 @@ module.exports = function(pb) { function GetObjectTypeNameAvailable(){} util.inherits(GetObjectTypeNameAvailable, pb.FormController); + GetObjectTypeNameAvailable.prototype.init = function (props, cb) { + var self = this; + + pb.BaseController.prototype.init.call(self, props, function() { + self.pathSiteUid = pb.SiteService.getCurrentSite(self.pathVars.siteid); + pb.SiteService.siteExists(self.pathSiteUid, function (err, exists) { + if (!exists) { + self.reqHandler.serve404(); + } + else { + cb(); + } + }); + }); + }; + GetObjectTypeNameAvailable.prototype.render = function(cb) { var self = this; var get = this.query; @@ -37,7 +53,7 @@ module.exports = function(pb) { }); } - var service = new pb.CustomObjectService(); + var service = new pb.CustomObjectService(self.pathSiteUid); service.typeExists(get.name, function(err, exists) { if (util.isError(err)) { return cb({content: pb.BaseController.apiResponse(pb.BaseController.API_FAILURE, err.stack, false)}); diff --git a/plugins/pencilblue/templates/admin/content/objects/manage_objects.html b/plugins/pencilblue/templates/admin/content/objects/manage_objects.html index 7bc601d93..b9e2231c3 100644 --- a/plugins/pencilblue/templates/admin/content/objects/manage_objects.html +++ b/plugins/pencilblue/templates/admin/content/objects/manage_objects.html @@ -7,7 +7,7 @@
^tmp_admin=elements=table_headers^ - + diff --git a/plugins/pencilblue/templates/admin/content/objects/object_form.html b/plugins/pencilblue/templates/admin/content/objects/object_form.html index 89605dd72..74b0ab8e8 100644 --- a/plugins/pencilblue/templates/admin/content/objects/object_form.html +++ b/plugins/pencilblue/templates/admin/content/objects/object_form.html @@ -88,7 +88,7 @@ ^wysiwyg^ - +  ^loc_CANCEL^ ^tmp_admin=elements=save_button^ diff --git a/plugins/pencilblue/templates/admin/content/objects/sort_objects.html b/plugins/pencilblue/templates/admin/content/objects/sort_objects.html index 7074780d2..5ffa01f99 100644 --- a/plugins/pencilblue/templates/admin/content/objects/sort_objects.html +++ b/plugins/pencilblue/templates/admin/content/objects/sort_objects.html @@ -11,7 +11,7 @@ - +  ^loc_CANCEL^
^tmp_admin=elements=table_headers^ - + diff --git a/plugins/pencilblue/templates/admin/content/objects/types/type_form.html b/plugins/pencilblue/templates/admin/content/objects/types/type_form.html index daa6465c2..f66ebf9b9 100644 --- a/plugins/pencilblue/templates/admin/content/objects/types/type_form.html +++ b/plugins/pencilblue/templates/admin/content/objects/types/type_form.html @@ -74,7 +74,7 @@ - +  ^loc_CANCEL^ ^tmp_admin=elements=save_button^ diff --git a/plugins/pencilblue/templates/angular/admin/content/objects/manage_objects.html b/plugins/pencilblue/templates/angular/admin/content/objects/manage_objects.html index 07ca2a7df..e09769d72 100644 --- a/plugins/pencilblue/templates/angular/admin/content/objects/manage_objects.html +++ b/plugins/pencilblue/templates/angular/admin/content/objects/manage_objects.html @@ -72,7 +72,7 @@ } $scope.deleting = true; - $http({method: 'DELETE', url: '/actions/admin/content/objects/' + $scope.objectToDelete._id}) + $http({method: 'DELETE', url: '/actions/admin' + $scope.pathSitePrefix + '/content/objects/' + $scope.objectToDelete._id}) .success(function(result) { for(var i = 0; i < $scope.customObjects.length; i++) { if($scope.customObjects[i]._id.toString() === $scope.objectToDelete._id.toString()) { diff --git a/plugins/pencilblue/templates/angular/admin/content/objects/object_form.html b/plugins/pencilblue/templates/angular/admin/content/objects/object_form.html index d31d6077a..2cda7ebe8 100644 --- a/plugins/pencilblue/templates/angular/admin/content/objects/object_form.html +++ b/plugins/pencilblue/templates/angular/admin/content/objects/object_form.html @@ -111,7 +111,7 @@ saveObject[wysiwygContent[i].name] = wysiwygContent[i].content; } - var postURL = '/actions/admin/content/objects/' + $scope.objectType._id + var postURL = '/actions/admin' + $scope.pathSitePrefix + '/content/objects/' + $scope.objectType._id; if($scope.customObject._id) { postURL += '/' + $scope.customObject._id; } @@ -124,7 +124,7 @@ $scope.saving = false; if(result.data) { - $window.location = '/admin/content/objects/' + $scope.objectType._id + '/' + result.data._id.toString(); + $window.location = '/admin' + $scope.pathSitePrefix + '/content/objects/' + $scope.objectType._id + '/' + result.data._id.toString(); } }) .error(function(error, status) { diff --git a/plugins/pencilblue/templates/angular/admin/content/objects/sort_objects.html b/plugins/pencilblue/templates/angular/admin/content/objects/sort_objects.html index dd4e722f2..e67f2eeed 100644 --- a/plugins/pencilblue/templates/angular/admin/content/objects/sort_objects.html +++ b/plugins/pencilblue/templates/angular/admin/content/objects/sort_objects.html @@ -11,7 +11,7 @@ $scope.saving = true; - $http.post('/actions/admin/content/objects/' + $scope.objectType._id + '/sort', {sorted_objects: sorting}) + $http.post('/actions/admin' + $scope.pathSitePrefix + '/content/objects/' + $scope.objectType._id + '/sort', {sorted_objects: sorting}) .success(function(result) { $scope.successMessage = result.message; $scope.saving = false; diff --git a/plugins/pencilblue/templates/angular/admin/content/objects/types/manage_types.html b/plugins/pencilblue/templates/angular/admin/content/objects/types/manage_types.html index 5d2b8a5f5..3cedc72c4 100644 --- a/plugins/pencilblue/templates/angular/admin/content/objects/types/manage_types.html +++ b/plugins/pencilblue/templates/angular/admin/content/objects/types/manage_types.html @@ -72,7 +72,7 @@ } $scope.deleting = true; - $http({method: 'DELETE', url: '/actions/admin/content/objects/types/' + $scope.objectToDelete._id}) + $http({method: 'DELETE', url: '/actions/admin' + $scope.pathSitePrefix + '/content/objects/types/' + $scope.objectToDelete._id}) .success(function(result) { for(var i = 0; i < $scope.objectTypes.length; i++) { if($scope.objectTypes[i]._id.toString() === $scope.objectToDelete._id.toString()) { diff --git a/plugins/pencilblue/templates/angular/admin/content/objects/types/type_form.html b/plugins/pencilblue/templates/angular/admin/content/objects/types/type_form.html index 4b127943f..73e3bc8af 100644 --- a/plugins/pencilblue/templates/angular/admin/content/objects/types/type_form.html +++ b/plugins/pencilblue/templates/angular/admin/content/objects/types/type_form.html @@ -12,7 +12,7 @@ itemMoved: function (event) {}, orderChanged: function(event) {}, containment: '#object_fields' - } + }; // Move key/value of fields to an array, so ng-sortable will work with it var fieldArray = []; @@ -29,7 +29,7 @@ return; } - $http.get('/api/admin/content/objects/types/available?name=' + $scope.objectType.name) + $http.get('/api/admin' + $scope.pathSitePrefix + '/content/objects/types/available?name=' + $scope.objectType.name) .success(function(result) { $scope.nameAvailable = result.data; }) @@ -107,7 +107,7 @@ } saveObject.fields = fields; - var postURL = '/actions/admin/content/objects/types' + var postURL = '/actions/admin' + $scope.pathSitePrefix + '/content/objects/types'; if(saveObject._id) { postURL += '/' + saveObject._id; } @@ -120,7 +120,7 @@ $scope.saving = false; if(result.data) { - $window.location = '/admin/content/objects/types/' + result.data._id.toString(); + $window.location = '/admin' + $scope.pathSitePrefix + '/content/objects/types/' + result.data._id.toString(); } }) .error(function(error, status) { From cec89115339b643ad5b05212e04f88751f869e64 Mon Sep 17 00:00:00 2001 From: Eugene Chang Date: Tue, 12 May 2015 12:22:58 -0400 Subject: [PATCH 115/790] Changing documentation --- include/service/entities/site_query_service.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/service/entities/site_query_service.js b/include/service/entities/site_query_service.js index 128d7cdf2..b6492515d 100644 --- a/include/service/entities/site_query_service.js +++ b/include/service/entities/site_query_service.js @@ -167,7 +167,7 @@ module.exports = function SiteQueryServiceModule(pb) { }; /** - * Wrapper for DAO.loadById; loads an object by its id, but its site must also match the query service's site + * Proxy for DAO.loadById; loads an object by its id, but its site must also match the query service's site * * @method loadById * @param {String} id The unique id of the object From f15042806c2eff663e384f50b6e7a1f1aea32422 Mon Sep 17 00:00:00 2001 From: Eugene Chang Date: Tue, 12 May 2015 13:43:02 -0400 Subject: [PATCH 116/790] Making topic in admin site-aware --- include/config.js | 2 +- .../service/entities/site_query_service.js | 13 +++++++ .../admin/content/topics/edit_topic.js | 25 +++++++++++- .../admin/content/topics/import_topics.js | 28 +++++++++++-- .../actions/admin/content/topics/new_topic.js | 26 +++++++++++-- .../admin/content/articles/article_form.js | 22 +++++++++-- .../admin/content/pages/page_form.js | 25 +++++++++++- .../admin/content/topics/import_topics.js | 34 +++++++++++++--- .../admin/content/topics/manage_topics.js | 39 +++++++++++++++---- .../admin/content/topics/topic_form.js | 36 ++++++++++++++--- .../admin/content/topics/manage_topics.html | 2 +- .../admin/content/topics/import_topics.html | 2 +- .../admin/content/topics/topic_form.html | 2 +- 13 files changed, 219 insertions(+), 37 deletions(-) diff --git a/include/config.js b/include/config.js index 585b92ef2..8c9fb0962 100755 --- a/include/config.js +++ b/include/config.js @@ -413,7 +413,7 @@ var BASE_CONFIG = { //topic { collection: 'topic', - spec: {name: ASC}, + spec: {name: ASC, site: ASC}, options: {unique: true} }, { diff --git a/include/service/entities/site_query_service.js b/include/service/entities/site_query_service.js index b6492515d..55afe62e1 100644 --- a/include/service/entities/site_query_service.js +++ b/include/service/entities/site_query_service.js @@ -180,6 +180,19 @@ module.exports = function SiteQueryServiceModule(pb) { dao.loadByValues(where, collection, options, callback); }; + /** + * Wrapper for DAO.count; Gets the count of objects matching criteria + * + * @method count + * @param {String} entityType The type of object to search for + * @param {Object} where Key value pair object + * @param {Function} callback Callback function + */ + SiteQueryService.prototype.count = function (entityType, where, callback) { + where = modifyLoadWhere(this.siteUId, where); + dao.count(entityType, where, callback); + }; + function modifySave(site, objectToSave) { if (pb.config.multisite && !(SITE_FIELD in objectToSave)) { objectToSave[SITE_FIELD] = site; diff --git a/plugins/pencilblue/controllers/actions/admin/content/topics/edit_topic.js b/plugins/pencilblue/controllers/actions/admin/content/topics/edit_topic.js index 7c75f86e2..a319a6187 100644 --- a/plugins/pencilblue/controllers/actions/admin/content/topics/edit_topic.js +++ b/plugins/pencilblue/controllers/actions/admin/content/topics/edit_topic.js @@ -26,6 +26,27 @@ module.exports = function(pb) { function NewTopic(){} util.inherits(NewTopic, pb.BaseController); + NewTopic.prototype.init = function (props, cb) { + var self = this; + pb.BaseController.prototype.init.call(self, props, function () { + self.pathSiteUId = pb.SiteService.getCurrentSite(self.pathVars.siteid); + pb.SiteService.siteExists(self.pathSiteUId, function (err, exists) { + if (!exists) { + self.reqHandler.serve404(); + } + else { + self.sitePrefix = pb.SiteService.getCurrentSitePrefix(self.pathSiteUId); + self.queryService = new pb.SiteQueryService(self.pathSiteUId); + var siteService = new pb.SiteService(); + siteService.getSiteNameByUid(self.pathSiteUId, function (siteName) { + self.siteName = siteName; + cb(); + }); + } + }); + }); + }; + NewTopic.prototype.render = function(cb) { var self = this; var vars = this.pathVars; @@ -61,7 +82,7 @@ module.exports = function(pb) { pb.DocumentCreator.update(post, topic); - dao.loadByValue('name', topic.name, 'topic', function(err, testTopic) { + self.queryService.loadByValue('name', topic.name, 'topic', function(err, testTopic) { if(testTopic && !testTopic[pb.DAO.getIdField()].equals(topic[pb.DAO.getIdField()])) { cb({ code: 400, @@ -70,7 +91,7 @@ module.exports = function(pb) { return; } - dao.save(topic, function(err, result) { + self.queryService.save(topic, function(err, result) { if(util.isError(err)) { return cb({ code: 500, diff --git a/plugins/pencilblue/controllers/actions/admin/content/topics/import_topics.js b/plugins/pencilblue/controllers/actions/admin/content/topics/import_topics.js index a01c4b310..6b9317e62 100755 --- a/plugins/pencilblue/controllers/actions/admin/content/topics/import_topics.js +++ b/plugins/pencilblue/controllers/actions/admin/content/topics/import_topics.js @@ -33,6 +33,27 @@ module.exports = function(pb) { function ImportTopics(){} util.inherits(ImportTopics, pb.BaseController); + ImportTopics.prototype.init = function (props, cb) { + var self = this; + pb.BaseController.prototype.init.call(self, props, function () { + self.pathSiteUId = pb.SiteService.getCurrentSite(self.pathVars.siteid); + pb.SiteService.siteExists(self.pathSiteUId, function (err, exists) { + if (!exists) { + self.reqHandler.serve404(); + } + else { + self.sitePrefix = pb.SiteService.getCurrentSitePrefix(self.pathSiteUId); + self.queryService = new pb.SiteQueryService(self.pathSiteUId); + var siteService = new pb.SiteService(); + siteService.getSiteNameByUid(self.pathSiteUId, function (siteName) { + self.siteName = siteName; + cb(); + }); + } + }); + }); + }; + ImportTopics.prototype.render = function(cb) { var self = this; var files = []; @@ -66,19 +87,18 @@ module.exports = function(pb) { ImportTopics.prototype.saveTopics = function(topics, cb) { var content = {completed: false}; - + var self = this; //create tasks - var dao = new pb.DAO(); var tasks = util.getTasks(topics, function(topicArry, index) { return function(callback) { - dao.count('topic', {name: topicArry[index].trim()}, function(err, count){ + self.queryService.count('topic', {name: topicArry[index].trim()}, function(err, count){ if (count > 0) { return callback(null, true); } var topicDocument = pb.DocumentCreator.create('topic', {name: topicArry[index].trim()}); - dao.save(topicDocument, callback); + self.queryService.save(topicDocument, callback); }); }; diff --git a/plugins/pencilblue/controllers/actions/admin/content/topics/new_topic.js b/plugins/pencilblue/controllers/actions/admin/content/topics/new_topic.js index e8bac58fd..13c01b700 100755 --- a/plugins/pencilblue/controllers/actions/admin/content/topics/new_topic.js +++ b/plugins/pencilblue/controllers/actions/admin/content/topics/new_topic.js @@ -26,6 +26,27 @@ module.exports = function(pb) { function NewTopic(){} util.inherits(NewTopic, pb.BaseController); + NewTopic.prototype.init = function (props, cb) { + var self = this; + pb.BaseController.prototype.init.call(self, props, function () { + self.pathSiteUId = pb.SiteService.getCurrentSite(self.pathVars.siteid); + pb.SiteService.siteExists(self.pathSiteUId, function (err, exists) { + if (!exists) { + self.reqHandler.serve404(); + } + else { + self.sitePrefix = pb.SiteService.getCurrentSitePrefix(self.pathSiteUId); + self.queryService = new pb.SiteQueryService(self.pathSiteUId); + var siteService = new pb.SiteService(); + siteService.getSiteNameByUid(self.pathSiteUId, function (siteName) { + self.siteName = siteName; + cb(); + }); + } + }); + }); + }; + NewTopic.prototype.render = function(cb) { var self = this; @@ -39,8 +60,7 @@ module.exports = function(pb) { return; } - var dao = new pb.DAO(); - dao.count('topic', {name: post.name}, function(err, count) { + self.queryService.count('topic', {name: post.name}, function(err, count) { if(count > 0) { cb({ code: 400, @@ -50,7 +70,7 @@ module.exports = function(pb) { } var topicDocument = pb.DocumentCreator.create('topic', post); - dao.save(topicDocument, function(err, result) { + self.queryService.save(topicDocument, function(err, result) { if(util.isError(err)) { return cb({ code: 500, diff --git a/plugins/pencilblue/controllers/admin/content/articles/article_form.js b/plugins/pencilblue/controllers/admin/content/articles/article_form.js index ddd0d7c06..2037dbb0d 100755 --- a/plugins/pencilblue/controllers/admin/content/articles/article_form.js +++ b/plugins/pencilblue/controllers/admin/content/articles/article_form.js @@ -30,10 +30,24 @@ module.exports = function(pb) { util.inherits(ArticleForm, pb.BaseController); ArticleForm.prototype.init = function (props, cb) { - this.pathSiteUId = pb.SiteService.getCurrentSite(props.path_vars.siteid); - this.queryService = new pb.SiteQueryService(this.pathSiteUId); - - pb.BaseController.prototype.init.call(this, props, cb); + var self = this; + pb.BaseController.prototype.init.call(self, props, function () { + self.pathSiteUId = pb.SiteService.getCurrentSite(self.pathVars.siteid); + pb.SiteService.siteExists(self.pathSiteUId, function (err, exists) { + if (!exists) { + self.reqHandler.serve404(); + } + else { + self.sitePrefix = pb.SiteService.getCurrentSitePrefix(self.pathSiteUId); + self.queryService = new pb.SiteQueryService(self.pathSiteUId); + var siteService = new pb.SiteService(); + siteService.getSiteNameByUid(self.pathSiteUId, function (siteName) { + self.siteName = siteName; + cb(); + }); + } + }); + }); }; ArticleForm.prototype.render = function(cb) { diff --git a/plugins/pencilblue/controllers/admin/content/pages/page_form.js b/plugins/pencilblue/controllers/admin/content/pages/page_form.js index d6dbe96ba..d22062c4e 100755 --- a/plugins/pencilblue/controllers/admin/content/pages/page_form.js +++ b/plugins/pencilblue/controllers/admin/content/pages/page_form.js @@ -29,6 +29,27 @@ module.exports = function(pb) { function PageFormController(){} util.inherits(PageFormController, pb.BaseController); + PageFormController.prototype.init = function (props, cb) { + var self = this; + pb.BaseController.prototype.init.call(self, props, function () { + self.pathSiteUId = pb.SiteService.getCurrentSite(self.pathVars.siteid); + pb.SiteService.siteExists(self.pathSiteUId, function (err, exists) { + if (!exists) { + self.reqHandler.serve404(); + } + else { + self.sitePrefix = pb.SiteService.getCurrentSitePrefix(self.pathSiteUId); + self.queryService = new pb.SiteQueryService(self.pathSiteUId); + var siteService = new pb.SiteService(); + siteService.getSiteNameByUid(self.pathSiteUId, function (siteName) { + self.siteName = siteName; + cb(); + }); + } + }); + }); + }; + PageFormController.prototype.render = function(cb) { var self = this; var vars = this.pathVars; @@ -190,7 +211,7 @@ module.exports = function(pb) { }, order: {name: pb.DAO.ASC} }; - dao.q('section', opts, callback); + self.queryService.q('section', opts, callback); }, topics: function(callback) { @@ -199,7 +220,7 @@ module.exports = function(pb) { where: pb.DAO.ANYWHERE, order: {name: pb.DAO.ASC} }; - dao.q('topic', opts, callback); + self.queryService.q('topic', opts, callback); }, media: function(callback) { diff --git a/plugins/pencilblue/controllers/admin/content/topics/import_topics.js b/plugins/pencilblue/controllers/admin/content/topics/import_topics.js index 055411439..d21e80af8 100755 --- a/plugins/pencilblue/controllers/admin/content/topics/import_topics.js +++ b/plugins/pencilblue/controllers/admin/content/topics/import_topics.js @@ -26,6 +26,27 @@ module.exports = function(pb) { function ImportTopics(){} util.inherits(ImportTopics, pb.BaseController); + ImportTopics.prototype.init = function (props, cb) { + var self = this; + pb.BaseController.prototype.init.call(self, props, function () { + self.pathSiteUId = pb.SiteService.getCurrentSite(self.pathVars.siteid); + pb.SiteService.siteExists(self.pathSiteUId, function (err, exists) { + if (!exists) { + self.reqHandler.serve404(); + } + else { + self.sitePrefix = pb.SiteService.getCurrentSitePrefix(self.pathSiteUId); + self.queryService = new pb.SiteQueryService(self.pathSiteUId); + var siteService = new pb.SiteService(); + siteService.getSiteNameByUid(self.pathSiteUId, function (siteName) { + self.siteName = siteName; + cb(); + }); + } + }); + }); + }; + //statics var SUB_NAV_KEY = 'import_topics'; @@ -42,11 +63,13 @@ module.exports = function(pb) { } ]; + var pills = pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, 'manage_topics', {sitePrefix: self.sitePrefix}); var angularObjects = pb.ClientJs.getAngularObjects( { navigation: pb.AdminNavigation.get(self.session, ['content', 'topics'], self.ls), - pills: pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, 'manage_topics'), - tabs: tabs + pills: pb.AdminSubnavService.addSiteToPills(pills, self.siteName), + tabs: tabs, + sitePrefix: self.sitePrefix }); this.setPageName(this.ls.get('IMPORT_TOPICS')); @@ -57,21 +80,22 @@ module.exports = function(pb) { }; ImportTopics.getSubNavItems = function(key, ls, data) { + var prefix = data.sitePrefix; return [{ name: 'manage_topics', title: ls.get('IMPORT_TOPICS'), icon: 'chevron-left', - href: '/admin/content/topics' + href: '/admin' + prefix + '/content/topics' }, { name: 'import_topics', title: '', icon: 'upload', - href: '/admin/content/topics/import' + href: '/admin' + prefix + '/content/topics/import' }, { name: 'new_topic', title: '', icon: 'plus', - href: '/admin/content/topics/new' + href: '/admin' + prefix + '/content/topics/new' }]; }; diff --git a/plugins/pencilblue/controllers/admin/content/topics/manage_topics.js b/plugins/pencilblue/controllers/admin/content/topics/manage_topics.js index 869718753..d2a98003c 100755 --- a/plugins/pencilblue/controllers/admin/content/topics/manage_topics.js +++ b/plugins/pencilblue/controllers/admin/content/topics/manage_topics.js @@ -26,6 +26,27 @@ module.exports = function(pb) { function ManageTopics() {} util.inherits(ManageTopics, pb.BaseController); + ManageTopics.prototype.init = function (props, cb) { + var self = this; + pb.BaseController.prototype.init.call(self, props, function () { + self.pathSiteUId = pb.SiteService.getCurrentSite(self.pathVars.siteid); + pb.SiteService.siteExists(self.pathSiteUId, function (err, exists) { + if (!exists) { + self.reqHandler.serve404(); + } + else { + self.sitePrefix = pb.SiteService.getCurrentSitePrefix(self.pathSiteUId); + self.queryService = new pb.SiteQueryService(self.pathSiteUId); + var siteService = new pb.SiteService(); + siteService.getSiteNameByUid(self.pathSiteUId, function (siteName) { + self.siteName = siteName; + cb(); + }); + } + }); + }); + }; + var SUB_NAV_KEY = 'manage_topics'; ManageTopics.prototype.render = function(cb) { @@ -35,15 +56,14 @@ module.exports = function(pb) { select: pb.DAO.PROJECT_ALL, where: pb.DAO.ANYWHERE }; - var dao = new pb.DAO(); - dao.q('topic', opts, function(err, topics) { + self.queryService.q('topic', opts, function (err, topics) { if (util.isError(err)) { self.reqHandler.serveError(err); } else if(topics.length === 0) { //none to manage - return self.redirect('/admin/content/topics/new', cb); + return self.redirect('/admin' + self.sitePrefix + '/content/topics/new', cb); } //currently, mongo cannot do case-insensitive sorts. We do it manually @@ -55,11 +75,13 @@ module.exports = function(pb) { return ((x < y) ? -1 : ((x > y) ? 1 : 0)); }); + var pills = pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, SUB_NAV_KEY, {sitePrefix: self.sitePrefix}); var angularObjects = pb.ClientJs.getAngularObjects( { navigation: pb.AdminNavigation.get(self.session, ['content', 'topics'], self.ls), - pills: pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, SUB_NAV_KEY), - topics: topics + pills: pb.AdminSubnavService.addSiteToPills(pills, self.siteName), + topics: topics, + sitePrefix: self.sitePrefix }); self.setPageName(self.ls.get('MANAGE_TOPICS')); @@ -72,21 +94,22 @@ module.exports = function(pb) { }; ManageTopics.getSubNavItems = function(key, ls, data) { + var prefix = data.sitePrefix; return [{ name: SUB_NAV_KEY, title: ls.get('MANAGE_TOPICS'), icon: 'refresh', - href: '/admin/content/topics' + href: '/admin' + prefix + '/content/topics' }, { name: 'import_topics', title: '', icon: 'upload', - href: '/admin/content/topics/import' + href: '/admin' + prefix + '/content/topics/import' }, { name: 'new_topic', title: '', icon: 'plus', - href: '/admin/content/topics/new' + href: '/admin' + prefix + '/content/topics/new' }]; }; diff --git a/plugins/pencilblue/controllers/admin/content/topics/topic_form.js b/plugins/pencilblue/controllers/admin/content/topics/topic_form.js index 064c96ab4..7601b2cb4 100644 --- a/plugins/pencilblue/controllers/admin/content/topics/topic_form.js +++ b/plugins/pencilblue/controllers/admin/content/topics/topic_form.js @@ -29,6 +29,28 @@ module.exports = function(pb) { function TopicForm(){} util.inherits(TopicForm, pb.BaseController); + TopicForm.prototype.init = function (props, cb) { + var self = this; + pb.BaseController.prototype.init.call(self, props, function () { + self.pathSiteUId = pb.SiteService.getCurrentSite(self.pathVars.siteid); + pb.SiteService.siteExists(self.pathSiteUId, function (err, exists) { + if (!exists) { + self.reqHandler.serve404(); + } + else { + self.sitePrefix = pb.SiteService.getCurrentSitePrefix(self.pathSiteUId); + self.queryService = new pb.SiteQueryService(self.pathSiteUId); + self.settings = pb.SettingServiceFactory.getServiceBySite(self.pathSiteUId, true); + var siteService = new pb.SiteService(); + siteService.getSiteNameByUid(self.pathSiteUId, function (siteName) { + self.siteName = siteName; + cb(); + }); + } + }); + }); + }; + //statics var SUB_NAV_KEY = 'topic_form'; @@ -47,7 +69,9 @@ module.exports = function(pb) { } self.topic = data.topic; - data.pills = pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, SUB_NAV_KEY, self.topic); + data.sitePrefix = self.sitePrefix; + var pills = pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, SUB_NAV_KEY, data); + data.pills = pb.AdminSubnavService.addSiteToPills(pills, self.siteName); var angularObjects = pb.ClientJs.getAngularObjects(data); self.setPageName(self.topic[pb.DAO.getIdField()] ? self.topic.name : self.ls.get('NEW_TOPIC')); @@ -94,21 +118,23 @@ module.exports = function(pb) { }; TopicForm.getSubNavItems = function(key, ls, data) { + var topic = data.topic; + var prefix = data.sitePrefix; return [{ name: SUB_NAV_KEY, - title: data[pb.DAO.getIdField()] ? ls.get('EDIT') + ' ' + data.name : ls.get('NEW_TOPIC'), + title: topic[pb.DAO.getIdField()] ? ls.get('EDIT') + ' ' + topic.name : ls.get('NEW_TOPIC'), icon: 'chevron-left', - href: '/admin/content/topics' + href: '/admin' + prefix + '/content/topics' }, { name: 'import_topics', title: '', icon: 'upload', - href: '/admin/content/topics/import' + href: '/admin' + prefix + '/content/topics/import' }, { name: 'new_topic', title: '', icon: 'plus', - href: '/admin/content/topics/new' + href: '/admin' + prefix + '/content/topics/new' }]; }; diff --git a/plugins/pencilblue/templates/admin/content/topics/manage_topics.html b/plugins/pencilblue/templates/admin/content/topics/manage_topics.html index 06892ef87..a78e747f6 100755 --- a/plugins/pencilblue/templates/admin/content/topics/manage_topics.html +++ b/plugins/pencilblue/templates/admin/content/topics/manage_topics.html @@ -5,7 +5,7 @@ ^tmp_admin=elements=search_input^
- + diff --git a/plugins/pencilblue/templates/angular/admin/content/topics/import_topics.html b/plugins/pencilblue/templates/angular/admin/content/topics/import_topics.html index 083798075..7cf0f7de2 100644 --- a/plugins/pencilblue/templates/angular/admin/content/topics/import_topics.html +++ b/plugins/pencilblue/templates/angular/admin/content/topics/import_topics.html @@ -10,7 +10,7 @@ $scope.uploading = true; $scope.uploadPercent = 0; $scope.upload = $upload.upload({ - url: '/actions/admin/content/topics/import', + url: '/actions/admin' + $scope.sitePrefix + '/content/topics/import', file: file }).progress(function(evt) { $scope.uploadPercent = parseInt(100.0 * evt.loaded / evt.total); diff --git a/plugins/pencilblue/templates/angular/admin/content/topics/topic_form.html b/plugins/pencilblue/templates/angular/admin/content/topics/topic_form.html index fe41d3a81..3ec06e705 100644 --- a/plugins/pencilblue/templates/angular/admin/content/topics/topic_form.html +++ b/plugins/pencilblue/templates/angular/admin/content/topics/topic_form.html @@ -14,7 +14,7 @@ $scope.saving = true; - var postURL = '/actions/admin/content/topics'; + var postURL = '/actions/admin' + $scope.sitePrefix + '/content/topics'; if($scope.topic._id) { postURL += '/' + $scope.topic._id; } From 607e7fb7d06ad210daaa1ab49fa2488dc4619d4b Mon Sep 17 00:00:00 2001 From: btidwell Date: Tue, 12 May 2015 13:56:36 -0400 Subject: [PATCH 117/790] Add compound unique index to media and update routes and validation logic --- include/config.js | 4 ++-- include/service/entities/media_service.js | 5 +++-- .../actions/admin/content/media/edit_media.js | 9 ++++++++- .../actions/admin/content/media/new_media.js | 10 +++++++++- .../controllers/admin/content/media/media_form.js | 10 +++++++++- .../angular/admin/content/media/media_form.html | 4 ++-- public/js/angular/services/media.js | 9 ++++++--- 7 files changed, 39 insertions(+), 12 deletions(-) diff --git a/include/config.js b/include/config.js index 585b92ef2..69683ad92 100755 --- a/include/config.js +++ b/include/config.js @@ -300,8 +300,8 @@ var BASE_CONFIG = { }, { collection: 'media', - spec: {name: ASC}, - options: {}//TODO make unique once validation is in place + spec: {name: ASC, site: ASC}, + options: {unique: true} }, { collection: 'media', diff --git a/include/service/entities/media_service.js b/include/service/entities/media_service.js index 977d4c60f..16c56dfec 100755 --- a/include/service/entities/media_service.js +++ b/include/service/entities/media_service.js @@ -32,7 +32,8 @@ module.exports = function MediaServiceModule(pb) { * @class MediaService * @constructor */ - function MediaService(provider){ + function MediaService(provider, site){ + this.site = site; if (util.isNullOrUndefined(provider)) { provider = MediaService.loadMediaProvider(); } @@ -160,7 +161,7 @@ module.exports = function MediaServiceModule(pb) { } //ensure the media name is unique - var where = { name: media.name }; + var where = { name: media.name, site: this.site }; var dao = new pb.DAO(); dao.unique(MediaService.COLL, where, media[pb.DAO.getIdField()], function(err, isUnique) { if(util.isError(err)) { diff --git a/plugins/pencilblue/controllers/actions/admin/content/media/edit_media.js b/plugins/pencilblue/controllers/actions/admin/content/media/edit_media.js index 7143c8a70..d1794db21 100755 --- a/plugins/pencilblue/controllers/actions/admin/content/media/edit_media.js +++ b/plugins/pencilblue/controllers/actions/admin/content/media/edit_media.js @@ -30,6 +30,13 @@ module.exports = function(pb) { function EditMediaActionController(){} util.inherits(EditMediaActionController, pb.BaseController); + EditMediaActionController.prototype.init = function (props, cb) { + this.pathSiteUId = pb.SiteService.getCurrentSite(props.path_vars.siteid); + this.sitePrefix = pb.SiteService.getCurrentSitePrefix(this.pathSiteUId); + + pb.BaseController.prototype.init.call(this, props, cb); + }; + /** * * @method onPostParamsRetrieved @@ -50,7 +57,7 @@ module.exports = function(pb) { return; } - var mediaService = new pb.MediaService(); + var mediaService = new pb.MediaService(null, self.pathSiteUId); mediaService.loadById(vars.id, function(err, media) { if(util.isError(err) || media === null) { cb({ diff --git a/plugins/pencilblue/controllers/actions/admin/content/media/new_media.js b/plugins/pencilblue/controllers/actions/admin/content/media/new_media.js index a7cc737b8..acab22686 100755 --- a/plugins/pencilblue/controllers/actions/admin/content/media/new_media.js +++ b/plugins/pencilblue/controllers/actions/admin/content/media/new_media.js @@ -29,6 +29,14 @@ module.exports = function(pb) { function NewMediaApiController(){} util.inherits(NewMediaApiController, pb.BaseController); + NewMediaApiController.prototype.init = function (props, cb) { + this.pathSiteUId = pb.SiteService.getCurrentSite(props.path_vars.siteid); + this.sitePrefix = pb.SiteService.getCurrentSitePrefix(this.pathSiteUId); + + pb.BaseController.prototype.init.call(this, props, cb); + }; + + NewMediaApiController.prototype.render = function(cb) { var self = this; @@ -43,7 +51,7 @@ module.exports = function(pb) { } var mediaDocument = pb.DocumentCreator.create('media', post); - var mediaService = new pb.MediaService(); + var mediaService = new pb.MediaService(null, self.pathSiteUId); mediaService.save(mediaDocument, function(err, result) { if(util.isError(err)) { return cb({ diff --git a/plugins/pencilblue/controllers/admin/content/media/media_form.js b/plugins/pencilblue/controllers/admin/content/media/media_form.js index 13412c5e3..e07931623 100644 --- a/plugins/pencilblue/controllers/admin/content/media/media_form.js +++ b/plugins/pencilblue/controllers/admin/content/media/media_form.js @@ -34,6 +34,13 @@ module.exports = function(pb) { //statics var SUB_NAV_KEY = 'media_form'; + MediaForm.prototype.init = function (props, cb) { + this.pathSiteUId = pb.SiteService.getCurrentSite(props.path_vars.siteid); + this.sitePrefix = pb.SiteService.getCurrentSitePrefix(this.pathSiteUId); + + pb.BaseController.prototype.init.call(this, props, cb); + }; + /** * @method render * @param {Function} cb @@ -68,6 +75,7 @@ module.exports = function(pb) { var self = this; pb.AdminSubnavService.getWithSite(SUB_NAV_KEY, self.ls, data.media, {site: data.media.site}, function(pills) { data.pills = pills; + data.sitePrefix = self.sitePrefix; cb(pb.ClientJs.getAngularObjects(data)); }); @@ -111,7 +119,7 @@ module.exports = function(pb) { if(!vars.id) { return callback(null, { media_topics: [], - site: vars.siteid + site: self.pathSiteUId }); } diff --git a/plugins/pencilblue/templates/angular/admin/content/media/media_form.html b/plugins/pencilblue/templates/angular/admin/content/media/media_form.html index 42e18df7d..6b18cdcae 100644 --- a/plugins/pencilblue/templates/angular/admin/content/media/media_form.html +++ b/plugins/pencilblue/templates/angular/admin/content/media/media_form.html @@ -132,13 +132,13 @@ } mediaObject.media_topics = topics; - mediaService.saveMedia(mediaObject) + mediaService.saveMedia(mediaObject, $scope.sitePrefix) .then(function(result) { $scope.saving = false; $scope.successMessage = result.message; if(result.data._id) { - $window.location = '/admin/content/media/' + result.data._id; + $window.location = '/admin' + $scope.sitePrefix + '/content/media/' + result.data._id; } }, function(result, status) { diff --git a/public/js/angular/services/media.js b/public/js/angular/services/media.js index f9657f5ab..a6eb9b68a 100644 --- a/public/js/angular/services/media.js +++ b/public/js/angular/services/media.js @@ -22,10 +22,13 @@ angular.module('media', []) }); }; - this.saveMedia = function(mediaObject) { + this.saveMedia = function(mediaObject, sitePrefix) { var deferred = $q.defer(); - - $http.post('/actions/admin/content/media' + (mediaObject._id ? '/' + mediaObject._id : ''), mediaObject, { + var actionPrefix = '/actions/admin'; + if(sitePrefix) { + actionPrefix += sitePrefix; + } + $http.post(actionPrefix + '/content/media' + (mediaObject._id ? '/' + mediaObject._id : ''), mediaObject, { headers: {'Content-Type': 'application/x-www-form-urlencoded'} }) .success(function(result) { From 9504e8c8fa4e55458c3301c46e1c0f82f53b3ad5 Mon Sep 17 00:00:00 2001 From: Eugene Chang Date: Tue, 12 May 2015 14:26:30 -0400 Subject: [PATCH 118/790] Fixing parent navigation loading, refactoring loadById --- include/service/entities/section_service.js | 3 +-- .../controllers/admin/content/navigation/nav_item_form.js | 8 +++----- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/include/service/entities/section_service.js b/include/service/entities/section_service.js index 13e1f3b8f..26366bd83 100755 --- a/include/service/entities/section_service.js +++ b/include/service/entities/section_service.js @@ -314,8 +314,7 @@ module.exports = function SectionServiceModule(pb) { where: where, order: {'name': pb.DAO.ASC} }; - var dao = new pb.DAO(); - dao.q('section', opts, cb); + this.queryService.q('section', opts, cb); }; /** diff --git a/plugins/pencilblue/controllers/admin/content/navigation/nav_item_form.js b/plugins/pencilblue/controllers/admin/content/navigation/nav_item_form.js index 36dbc3b02..895d91abd 100644 --- a/plugins/pencilblue/controllers/admin/content/navigation/nav_item_form.js +++ b/plugins/pencilblue/controllers/admin/content/navigation/nav_item_form.js @@ -109,8 +109,7 @@ module.exports = function(pb) { //get parents parents: function(callback) { - var sectionService = new pb.SectionService(); - sectionService.getParentSelectList(self.pathVars.id, function(err, parents) { + self.navService.getParentSelectList(self.pathVars.id, function(err, parents) { if(util.isError(err)) { callback(err, parents); return; @@ -151,15 +150,14 @@ module.exports = function(pb) { return; } - var dao = new pb.DAO(); - dao.loadById(vars.id, 'section', function(err, navItem) { + self.navService.loadById(vars.id, 'section', function(err, navItem) { if(!navItem.item) { callback(err, navItem); return; } //TODO modify such that only the needed field of "headline" is returned. - dao.loadById(navItem.item, navItem.type, function(err, articleOrPage) { + self.navService.loadById(navItem.item, navItem.type, function(err, articleOrPage) { if(articleOrPage) { navItem.contentSearchValue = articleOrPage.headline; } From 542db6ca059436515ad0b9596ac925909a934b1a Mon Sep 17 00:00:00 2001 From: andparker Date: Wed, 13 May 2015 11:58:05 -0400 Subject: [PATCH 119/790] Updates more custom object service methods to be site aware | Updates more uses of custom object service to consume site uid | Provides new dao wrapper methods in site query service --- .../service/entities/custom_object_service.js | 11 ++++------- include/service/entities/site_query_service.js | 17 +++++++++++++++-- .../admin/content/objects/manage_objects.js | 2 +- .../admin/content/objects/object_form.js | 12 ++++++++---- .../admin/content/objects/sort_objects.js | 4 ++-- .../admin/content/objects/types/type_form.js | 2 +- 6 files changed, 31 insertions(+), 17 deletions(-) diff --git a/include/service/entities/custom_object_service.js b/include/service/entities/custom_object_service.js index 7916ff180..54bbaa317 100644 --- a/include/service/entities/custom_object_service.js +++ b/include/service/entities/custom_object_service.js @@ -460,8 +460,7 @@ module.exports = function CustomObjectServiceModule(pb) { options.where.type = typeStr; var self = this; - var dao = new pb.DAO(); - dao.q(CustomObjectService.CUST_OBJ_COLL, options, function(err, custObjs) { + self.siteQueryService.q(CustomObjectService.CUST_OBJ_COLL, options, function(err, custObjs) { if (util.isArray(custObjs)) { var tasks = util.getTasks(custObjs, function(custObjs, i) { @@ -583,8 +582,7 @@ module.exports = function CustomObjectServiceModule(pb) { } var self = this; - var dao = new pb.DAO(); - dao.loadByValues(where, CustomObjectService.CUST_OBJ_COLL, function(err, custObj) { + self.siteQueryService.loadByValues(where, CustomObjectService.CUST_OBJ_COLL, function(err, custObj) { if (util.isObject(custObj)) { return self.fetchChildren(custObj, options, type, cb); } @@ -626,8 +624,7 @@ module.exports = function CustomObjectServiceModule(pb) { return cb(Error("The where parameter must be provided in order to load a custom object type")); } - var dao = new pb.DAO(); - dao.loadByValues(where, CustomObjectService.CUST_OBJ_TYPE_COLL, cb); + this.siteQueryService.loadByValues(where, CustomObjectService.CUST_OBJ_TYPE_COLL, cb); }; /** @@ -901,7 +898,7 @@ module.exports = function CustomObjectServiceModule(pb) { } var dao = new pb.DAO(); - dao.save(custObj, cb); + self.siteQueryService.save(custObj, cb); }); }; diff --git a/include/service/entities/site_query_service.js b/include/service/entities/site_query_service.js index bd83b148d..080630e4f 100644 --- a/include/service/entities/site_query_service.js +++ b/include/service/entities/site_query_service.js @@ -163,7 +163,7 @@ module.exports = function SiteQueryServiceModule(pb) { }; /** - * Wrapper for DAO.loadByValue; Retrieves objects matching a key value pair + * Proxy for DAO.loadByValue; Retrieves objects matching a key value pair * * @method loadByValue * @param {String} key The key to search for @@ -175,8 +175,21 @@ module.exports = function SiteQueryServiceModule(pb) { SiteQueryService.prototype.loadByValue = function (key, value, collection, options, callback) { var where = {}; where[key] = value; + this.loadByValues(where, collection, options, callback); + }; + + /** + * Wrapper for DAO.loadByValues. Retrieves object matching several key value pairs + * + * @method loadByValues + * @param {Object} where Key value pair object + * @param {String} collection The collection to search in + * @param {Object} Key value pair object to exclude the retrieval of data + * @param {Function} cb Callback function + */ + SiteQueryService.prototype.loadByValues = function(where, collection, opts, cb) { where = modifyLoadWhere(this.siteUId, where); - dao.loadByValues(where, collection, options, callback); + dao.loadByValues(where, collection, opts, cb); }; /** diff --git a/plugins/pencilblue/controllers/admin/content/objects/manage_objects.js b/plugins/pencilblue/controllers/admin/content/objects/manage_objects.js index 583bf9460..e5101d9fd 100644 --- a/plugins/pencilblue/controllers/admin/content/objects/manage_objects.js +++ b/plugins/pencilblue/controllers/admin/content/objects/manage_objects.js @@ -61,7 +61,7 @@ module.exports = function(pb) { return this.reqHandler.serve404(); } - var service = new pb.CustomObjectService(); + var service = new pb.CustomObjectService(self.pathSiteUid); service.loadTypeById(vars.type_id, function(err, custObjType) { if (util.isError(err)) { return self.serveError(err); diff --git a/plugins/pencilblue/controllers/admin/content/objects/object_form.js b/plugins/pencilblue/controllers/admin/content/objects/object_form.js index 3365fc3b6..7da3f6df5 100644 --- a/plugins/pencilblue/controllers/admin/content/objects/object_form.js +++ b/plugins/pencilblue/controllers/admin/content/objects/object_form.js @@ -119,7 +119,7 @@ module.exports = function(pb) { ObjectFormController.prototype.gatherData = function(vars, cb) { var self = this; - var cos = new pb.CustomObjectService(); + var cos = new pb.CustomObjectService(self.pathSiteUid); var tasks = { tabs: function(callback) { @@ -150,6 +150,10 @@ module.exports = function(pb) { return; } + if (!util.isObject(objectType)) { + return self.reqHandler.serve404(); + } + self.loadFieldOptions(cos, objectType, callback); }); }, @@ -170,7 +174,7 @@ module.exports = function(pb) { var self = this; var keys = Object.keys(objectType.fields); var custObjTypes = {}; - var dao = new pb.DAO(); + var siteQueryService = new pb.SiteQueryService(); var userService = new pb.UserService(); //wrapper function to load cust object type @@ -228,7 +232,7 @@ module.exports = function(pb) { last_name: 1 } }; - dao.q(objectType.fields[key].object_type, query, function(err, availableObjects) { + siteQueryService.q(objectType.fields[key].object_type, query, function(err, availableObjects) { if (util.isError(err)) { return callback(err); } @@ -239,7 +243,7 @@ module.exports = function(pb) { var descriptor = { name: availableObjects[i].name || availableObjects[i].headline || userService.getFormattedName(availableObjects[i]) }; - descriptor[pb.DAO.getIdField()] = availableObjects[i][pb.DAO.getIdField()] + descriptor[pb.DAO.getIdField()] = availableObjects[i][pb.DAO.getIdField()]; objectsInfo.push(descriptor); } diff --git a/plugins/pencilblue/controllers/admin/content/objects/sort_objects.js b/plugins/pencilblue/controllers/admin/content/objects/sort_objects.js index 95aaa5fb6..499dd43cb 100644 --- a/plugins/pencilblue/controllers/admin/content/objects/sort_objects.js +++ b/plugins/pencilblue/controllers/admin/content/objects/sort_objects.js @@ -60,9 +60,9 @@ module.exports = function(pb) { return this.reqHandler.serve404(); } - var service = new pb.CustomObjectService(); + var service = new pb.CustomObjectService(self.pathSiteUid); service.loadTypeById(vars.type_id, function(err, objectType) { - if(util.isError(err) || objectType === null) { + if(util.isError(err)) { return self.reqHandler.serveError(err); } else if (!util.isObject(objectType)) { diff --git a/plugins/pencilblue/controllers/admin/content/objects/types/type_form.js b/plugins/pencilblue/controllers/admin/content/objects/types/type_form.js index 7a7dffbff..0b2614507 100644 --- a/plugins/pencilblue/controllers/admin/content/objects/types/type_form.js +++ b/plugins/pencilblue/controllers/admin/content/objects/types/type_form.js @@ -82,7 +82,7 @@ module.exports = function(pb) { TypeForm.prototype.gatherData = function(vars, cb) { var self = this; - var cos = new pb.CustomObjectService(); + var cos = new pb.CustomObjectService(self.pathSiteUid); var tasks = { tabs: function(callback) { From 1ce99b34a2251ffdc15457679e2dfc6ede5576e5 Mon Sep 17 00:00:00 2001 From: Eugene Chang Date: Wed, 13 May 2015 13:03:10 -0400 Subject: [PATCH 120/790] Site aware cancel button --- .../pencilblue/templates/admin/content/topics/topic_form.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/pencilblue/templates/admin/content/topics/topic_form.html b/plugins/pencilblue/templates/admin/content/topics/topic_form.html index 20c9fa0e8..35c9d9d1a 100644 --- a/plugins/pencilblue/templates/admin/content/topics/topic_form.html +++ b/plugins/pencilblue/templates/admin/content/topics/topic_form.html @@ -13,7 +13,7 @@
^loc_REQUIRED_FIELD^
- +  ^loc_CANCEL^ ^tmp_admin=elements=save_button^ From 5287c81544a672172f55710858d88f4da3572427 Mon Sep 17 00:00:00 2001 From: Eugene Chang Date: Wed, 13 May 2015 13:55:33 -0400 Subject: [PATCH 121/790] Minor refactor --- include/service/entities/site_query_service.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/include/service/entities/site_query_service.js b/include/service/entities/site_query_service.js index bfcaed9b0..937d1a009 100644 --- a/include/service/entities/site_query_service.js +++ b/include/service/entities/site_query_service.js @@ -184,12 +184,12 @@ module.exports = function SiteQueryServiceModule(pb) { * @method loadByValues * @param {Object} where Key value pair object * @param {String} collection The collection to search in - * @param {Object} Key value pair object to exclude the retrieval of data - * @param {Function} cb Callback function + * @param {Object} options Key value pair object to exclude the retrieval of data + * @param {Function} callback Callback function */ - SiteQueryService.prototype.loadByValues = function(where, collection, opts, cb) { + SiteQueryService.prototype.loadByValues = function(where, collection, options, callback) { where = modifyLoadWhere(this.siteUId, where); - dao.loadByValues(where, collection, opts, cb); + dao.loadByValues(where, collection, options, callback); }; /** @@ -202,8 +202,7 @@ module.exports = function SiteQueryServiceModule(pb) { * @param {Function} callback Callback function */ SiteQueryService.prototype.loadById = function (id, collection, options, callback) { - var where = modifyLoadWhere(this.siteUId, pb.DAO.getIdWhere(id)); - dao.loadByValues(where, collection, options, callback); + this.loadByValues(pb.DAO.getIdWhere(id), collection, options, callback); }; /** From 65647a0275c88b7bbae36dcb10cf06a6878ddb95 Mon Sep 17 00:00:00 2001 From: Eugene Chang Date: Thu, 14 May 2015 11:01:44 -0400 Subject: [PATCH 122/790] Refactoring ContentService to be site aware. Adding site awareness to comments management --- include/content.js | 10 +++-- .../admin/content/comments/manage_comments.js | 39 ++++++++++++++----- 2 files changed, 37 insertions(+), 12 deletions(-) diff --git a/include/content.js b/include/content.js index 0130146c4..598ac275f 100755 --- a/include/content.js +++ b/include/content.js @@ -26,7 +26,10 @@ module.exports = function ContentServiceModule(pb) { * @class ContentService * @constructor */ - function ContentService(){} + function ContentService(site, onlyThisSite) { + this.siteUid = pb.SiteService.getCurrentSite(site); + this.settingService = pb.SettingServiceFactory.getServiceBySite(this.siteUid, onlyThisSite); + } /** * @@ -72,14 +75,15 @@ module.exports = function ContentServiceModule(pb) { * @param {Function} cb Callback function */ ContentService.prototype.getSettings = function(cb){ - pb.settings.get(CONTENT_SETTINGS_REF, function(err, settings){ + var self = this; + self.settingService.get(CONTENT_SETTINGS_REF, function(err, settings){ if (settings) { return cb(err, settings); } //set default settings if they don't exist settings = ContentService.getDefaultSettings(); - pb.settings.set(CONTENT_SETTINGS_REF, settings, function(err, result) { + self.settingService.set(CONTENT_SETTINGS_REF, settings, function(err, result) { cb(err, settings); }); }); diff --git a/plugins/pencilblue/controllers/admin/content/comments/manage_comments.js b/plugins/pencilblue/controllers/admin/content/comments/manage_comments.js index b103ebebb..b522e827b 100755 --- a/plugins/pencilblue/controllers/admin/content/comments/manage_comments.js +++ b/plugins/pencilblue/controllers/admin/content/comments/manage_comments.js @@ -28,6 +28,27 @@ module.exports = function(pb) { function ManageComments() {} util.inherits(ManageComments, pb.BaseController); + ManageComments.prototype.init = function (props, cb) { + var self = this; + pb.BaseController.prototype.init.call(self, props, function () { + self.pathSiteUId = pb.SiteService.getCurrentSite(self.pathVars.siteid); + pb.SiteService.siteExists(self.pathSiteUId, function (err, exists) { + if (!exists) { + self.reqHandler.serve404(); + } + else { + self.sitePrefix = pb.SiteService.getCurrentSitePrefix(self.pathSiteUId); + self.queryService = new pb.SiteQueryService(self.pathSiteUId); + var siteService = new pb.SiteService(); + siteService.getSiteNameByUid(self.pathSiteUId, function (siteName) { + self.siteName = siteName; + cb(); + }); + } + }); + }); + }; + /** * * @private @@ -52,20 +73,20 @@ module.exports = function(pb) { order: {created: -1}, limit: 500 }; - var dao = new pb.DAO(); - dao.q('comment', opts, function(err, comments) { + self.queryService.q('comment', opts, function(err, comments) { if (util.isError(err)) { return self.reqHandler.serveError(err); } //retrieve the content settings or defaults if they have not yet been configured - var contentService = new pb.ContentService(); + var contentService = new pb.ContentService(self.pathSiteUId); contentService.getSettings(function(err, contentSettings) { //TODO handle error //retrieve any details - self.getCommentDetails(comments, dao, function(commentsWithDetails) { - var pills = pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, SUB_NAV_KEY); + self.getCommentDetails(comments, function(commentsWithDetails) { + var pills = pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, SUB_NAV_KEY, {prefix: self.sitePrefix}); + pills = pb.AdminSubnavService.addSiteToPills(pills, self.siteName); var angularObjects = pb.ClientJs.getAngularObjects({ navigation: pb.AdminNavigation.get(self.session, ['content', 'comments'], self.ls), pills: pills, @@ -91,7 +112,7 @@ module.exports = function(pb) { * @param {DAO} dao * @param {Function} cb */ - ManageComments.prototype.getCommentDetails = function(comments, dao, cb) { + ManageComments.prototype.getCommentDetails = function(comments, cb) { var self = this; if(comments.length === 0) { @@ -100,12 +121,12 @@ module.exports = function(pb) { } this.getCommentingUser = function(index) { - dao.loadById(comments[index].commenter, 'user', function(err, user) { + self.queryService.loadById(comments[index].commenter, 'user', function(err, user) { if(!util.isError(err) && user !== null) { comments[index].user_name = user.first_name + ' ' + user.last_name; } - dao.loadById(comments[index].article, 'article', function(err, article) { + self.queryService.loadById(comments[index].article, 'article', function(err, article) { if(!util.isError(err) && article !== null) { comments[index].article_url = article.url; comments[index].article_headline = article.headline; @@ -138,7 +159,7 @@ module.exports = function(pb) { name: SUB_NAV_KEY, title: ls.get('MANAGE_COMMENTS'), icon: 'refresh', - href: '/admin/content/comments' + href: '/admin' + data.prefix + '/content/comments' }]; }; From a13a6454043426a246ad3b712310b27a73e19bf4 Mon Sep 17 00:00:00 2001 From: Eugene Chang Date: Thu, 14 May 2015 11:04:58 -0400 Subject: [PATCH 123/790] Adding site awareness to the new comment API --- .../controllers/api/comments/new_comment.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/plugins/pencilblue/controllers/api/comments/new_comment.js b/plugins/pencilblue/controllers/api/comments/new_comment.js index 574e5dfd6..356f42ba6 100755 --- a/plugins/pencilblue/controllers/api/comments/new_comment.js +++ b/plugins/pencilblue/controllers/api/comments/new_comment.js @@ -27,10 +27,19 @@ module.exports = function NewCommentModule(pb) { function NewComment(){} util.inherits(NewComment, pb.FormController); + NewComment.prototype.init = function (props, cb) { + var self = this; + pb.BaseController.prototype.init.call(self, props, function () { + self.siteUId = pb.SiteService.getCurrentSite(self.site); + self.queryService = new pb.SiteQueryService(self.siteUId); + cb(); + }); + }; + NewComment.prototype.onPostParamsRetrieved = function(post, cb) { var self = this; - var contentService = new pb.ContentService(); + var contentService = new pb.ContentService(self.siteUId); contentService.getSettings(function(err, contentSettings) { if(!contentSettings.allow_comments) { cb({content: BaseController.apiResponse(BaseController.API_FAILURE, 'commenting not allowed'), code: 400}); @@ -43,8 +52,7 @@ module.exports = function NewCommentModule(pb) { return; } - var dao = new pb.DAO(); - dao.loadById(post.article, 'article', function(err, article) { + self.queryService.loadById(post.article, 'article', function(err, article) { if(util.isError(err) || article == null) { cb({content: BaseController.apiResponse(BaseController.API_FAILURE, 'article does not exist'), code: 400}); return; @@ -53,7 +61,7 @@ module.exports = function NewCommentModule(pb) { var commentDocument = pb.DocumentCreator.create('comment', post); commentDocument.commenter = self.session.authentication.user_id; - dao.save(commentDocument, function(err, data) { + self.queryService.save(commentDocument, function(err, data) { if (util.isError(err)) { return cb({content: BaseController.apiResponse(BaseController.API_FAILURE, 'error saving'), code: 500}); } From 1840a5abefa58182f01ce6535135d2eb13b51ffa Mon Sep 17 00:00:00 2001 From: btidwell Date: Thu, 14 May 2015 11:33:50 -0400 Subject: [PATCH 124/790] add site specific routes for site settings pages --- .../include/multisite_admin_routes.js | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/plugins/pencilblue/include/multisite_admin_routes.js b/plugins/pencilblue/include/multisite_admin_routes.js index 9813d51de..0df24f922 100644 --- a/plugins/pencilblue/include/multisite_admin_routes.js +++ b/plugins/pencilblue/include/multisite_admin_routes.js @@ -549,6 +549,56 @@ module.exports = function Routes(pb){ auth_required: true, access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'themes', 'site_logo.js') + }, + + //SITE SETTINGS + { + method: 'get', + path: "/admin/:siteid/site_settings", + access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, + auth_required: true, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'site_settings', 'configuration.js'), + content_type: 'text/html' + }, + { + method: 'post', + path: "/actions/admin/:siteid/site_settings", + access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, + auth_required: true, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'site_settings', 'configuration.js'), + content_type: 'text/html' + }, + { + method: 'get', + path: "/admin/:siteid/site_settings/content", + access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, + auth_required: true, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'site_settings', 'content.js'), + content_type: 'text/html' + }, + { + method: 'post', + path: "/actions/admin/:siteid/site_settings/content", + access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, + auth_required: true, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'site_settings', 'content.js'), + content_type: 'text/html' + }, + { + method: 'get', + path: "/admin/:siteid/site_settings/email", + access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, + auth_required: true, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'site_settings', 'email.js'), + content_type: 'text/html' + }, + { + method: 'post', + path: "/actions/admin/:siteid/site_settings/email", + access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, + auth_required: true, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'site_settings', 'email.js'), + content_type: 'text/html' } ]; }; From 725bdf037abe6c924a01e8179acf3462084f9db1 Mon Sep 17 00:00:00 2001 From: Eugene Chang Date: Thu, 14 May 2015 11:36:00 -0400 Subject: [PATCH 125/790] User link in manage comments page should be site aware --- .../controllers/admin/content/comments/manage_comments.js | 3 ++- .../templates/admin/content/comments/manage_comments.html | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/plugins/pencilblue/controllers/admin/content/comments/manage_comments.js b/plugins/pencilblue/controllers/admin/content/comments/manage_comments.js index b522e827b..c4fe60f84 100755 --- a/plugins/pencilblue/controllers/admin/content/comments/manage_comments.js +++ b/plugins/pencilblue/controllers/admin/content/comments/manage_comments.js @@ -91,7 +91,8 @@ module.exports = function(pb) { navigation: pb.AdminNavigation.get(self.session, ['content', 'comments'], self.ls), pills: pills, comments: commentsWithDetails, - allowComments: contentSettings.allow_comments + allowComments: contentSettings.allow_comments, + sitePrefix: self.sitePrefix }); //load the template diff --git a/plugins/pencilblue/templates/admin/content/comments/manage_comments.html b/plugins/pencilblue/templates/admin/content/comments/manage_comments.html index 5305aafd7..bd243733e 100755 --- a/plugins/pencilblue/templates/admin/content/comments/manage_comments.html +++ b/plugins/pencilblue/templates/admin/content/comments/manage_comments.html @@ -10,7 +10,7 @@
  - +
^tmp_admin=elements=table_headers^ - + From d6e6cd9df38b74a2f8e4c0a081057416b0708ee5 Mon Sep 17 00:00:00 2001 From: Christina Chatham Date: Thu, 14 May 2015 12:57:57 -0400 Subject: [PATCH 126/790] All email site setting links changed to include site id. --- include/admin_navigation.js | 2 +- .../controllers/admin/site_settings/email.js | 13 ++++++---- .../include/multisite_admin_routes.js | 25 +++++++++++++++++++ .../angular/admin/site_settings/email.html | 4 +-- 4 files changed, 36 insertions(+), 8 deletions(-) diff --git a/include/admin_navigation.js b/include/admin_navigation.js index cc39f8c18..bc1a5dcce 100755 --- a/include/admin_navigation.js +++ b/include/admin_navigation.js @@ -212,7 +212,7 @@ module.exports = function AdminNavigationModule(pb) { id: 'email_settings', title: 'EMAIL', icon: 'envelope', - href: '/admin/site_settings/email', + href: adminPath + '/site_settings/email', access: SecurityService.ACCESS_MANAGING_EDITOR }, { diff --git a/plugins/pencilblue/controllers/admin/site_settings/email.js b/plugins/pencilblue/controllers/admin/site_settings/email.js index e59b08b2c..7a01f23cd 100755 --- a/plugins/pencilblue/controllers/admin/site_settings/email.js +++ b/plugins/pencilblue/controllers/admin/site_settings/email.js @@ -19,6 +19,7 @@ module.exports = function(pb) { //pb dependencies var util = pb.util; + var SiteService = pb.SiteService; /** * Interface for the site's email settings @@ -54,11 +55,13 @@ module.exports = function(pb) { var emailService = new pb.EmailService(); emailService.getSettings(function(err, emailSettings) { + var sitePrefix = SiteService.getCurrentSitePrefix(SiteService.getCurrentSite(self.pathVars.siteid)); var angularObjects = pb.ClientJs.getAngularObjects({ navigation: pb.AdminNavigation.get(self.session, ['settings', 'site_settings'], self.ls), - pills: pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, 'email'), + pills: pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, 'email', { sitePrefix: sitePrefix }), tabs: tabs, - emailSettings: emailSettings + emailSettings: emailSettings, + sitePrefix: sitePrefix }); self.setPageName(self.ls.get('EMAIL')); @@ -74,17 +77,17 @@ module.exports = function(pb) { name: 'configuration', title: ls.get('EMAIL'), icon: 'chevron-left', - href: '/admin/site_settings' + href: '/admin' + data.sitePrefix + '/site_settings' }, { name: 'content', title: ls.get('CONTENT'), icon: 'quote-right', - href: '/admin/site_settings/content' + href: '/admin' + data.sitePrefix + '/site_settings/content' }, { name: 'libraries', title: ls.get('LIBRARIES'), icon: 'book', - href: '/admin/site_settings/libraries' + href: '/admin' + data.sitePrefix + '/site_settings/libraries' }]; }; diff --git a/plugins/pencilblue/include/multisite_admin_routes.js b/plugins/pencilblue/include/multisite_admin_routes.js index 9813d51de..4db8f4277 100644 --- a/plugins/pencilblue/include/multisite_admin_routes.js +++ b/plugins/pencilblue/include/multisite_admin_routes.js @@ -549,6 +549,31 @@ module.exports = function Routes(pb){ auth_required: true, access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'themes', 'site_logo.js') + }, + //SITE SETTINGS + { + method: 'get', + path: "/admin/:siteid/site_settings/email", + access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, + auth_required: true, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'site_settings', 'email.js'), + content_type: 'text/html' + }, + { + method: 'post', + path: "/actions/admin/:siteid/site_settings/email", + access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, + auth_required: true, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'site_settings', 'email.js'), + content_type: 'text/html' + }, + { + method: 'post', + path: "/api/admin/:siteid/site_settings/email/send_test", + auth_required: true, + access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'api', 'admin', 'site_settings', 'email', 'send_test.js'), + content_type: 'application/json' } ]; }; diff --git a/plugins/pencilblue/templates/angular/admin/site_settings/email.html b/plugins/pencilblue/templates/angular/admin/site_settings/email.html index e2809997d..1c6f9eb6b 100644 --- a/plugins/pencilblue/templates/angular/admin/site_settings/email.html +++ b/plugins/pencilblue/templates/angular/admin/site_settings/email.html @@ -19,7 +19,7 @@ $scope.emailTestFailure = null; $scope.sendingEmail = true; - $http.post('/api/admin/site_settings/email/send_test', {email: $scope.testEmailAddress}) + $http.post('/api/admin' + $scope.sitePrefix + '/site_settings/email/send_test', {email: $scope.testEmailAddress}) .success(function(result) { $scope.emailTestSuccess = true; $scope.sendingEmail = false; @@ -37,7 +37,7 @@ getWYSIWYGLayout(wysId, function(layout) { $scope.emailSettings.verification_content = layout; - $http.post('/actions/admin/site_settings/email', $scope.emailSettings) + $http.post('/actions' + $scope.sitePrefix + '/admin/site_settings/email', $scope.emailSettings) .success(function(result) { $scope.successMessage = result.message; $scope.saving = false; From 5ebdaf14a43be58ef1c5a972daa0636ed0986ba4 Mon Sep 17 00:00:00 2001 From: btidwell Date: Thu, 14 May 2015 13:27:01 -0400 Subject: [PATCH 127/790] Add full site object load method and display site details on site_settings page --- include/service/entities/site_service.js | 15 +++++++++++++ .../admin/site_settings/configuration.js | 22 +++++++++++++++++++ .../admin/site_settings/configuration.html | 4 ++-- 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/include/service/entities/site_service.js b/include/service/entities/site_service.js index c4f9036bb..f9db74837 100644 --- a/include/service/entities/site_service.js +++ b/include/service/entities/site_service.js @@ -19,6 +19,21 @@ module.exports = function SiteServiceModule(pb) { SiteService.SITE_COLLECTION = 'site'; var SITE_COLL = SiteService.SITE_COLLECTION; + SiteService.prototype.getByUid = function(uid, cb) { + if(uid === SiteService.GLOBAL_SITE) { + cb(null, { + displayName:pb.config.siteName, + hostname: pb.config.siteRoot, + uid: SiteService.GLOBAL_SITE + }); + } + else { + var dao = new pb.DAO(); + var where = {uid: uid}; + dao.loadByValues(where, SITE_COLL, cb); + } + }; + SiteService.prototype.getActiveSites = function(cb) { var dao = new pb.DAO(); dao.q(SITE_COLL, { select: pb.DAO.SELECT_ALL, where: {active: true} }, cb); diff --git a/plugins/pencilblue/controllers/admin/site_settings/configuration.js b/plugins/pencilblue/controllers/admin/site_settings/configuration.js index 63862cc0e..4c2f11cfe 100755 --- a/plugins/pencilblue/controllers/admin/site_settings/configuration.js +++ b/plugins/pencilblue/controllers/admin/site_settings/configuration.js @@ -32,6 +32,26 @@ module.exports = function(pb) { //statics var SUB_NAV_KEY = 'site_configuration'; + Configuration.prototype.init = function (props, cb) { + var self = this; + pb.BaseController.prototype.init.call(self, props, function () { + self.pathSiteUId = pb.SiteService.getCurrentSite(self.pathVars.siteid); + var siteService = new pb.SiteService(); + siteService.getByUid(self.pathSiteUId, function(err, site) { + if (!site) { + self.reqHandler.serve404(); + } + else { + self.siteObj = site; + cb(); + } + }); + pb.SiteService.siteExists(self.pathSiteUId, function (err, exists) { + + }); + }); + }; + Configuration.prototype.render = function(cb) { var self = this; @@ -42,6 +62,8 @@ module.exports = function(pb) { } var config = { + siteName: self.siteObj.displayName, + siteRoot: self.siteObj.hostname, documentRoot: pb.config.docRoot, siteIP: pb.config.siteIP, sitePort: pb.config.sitePort, diff --git a/plugins/pencilblue/templates/admin/site_settings/configuration.html b/plugins/pencilblue/templates/admin/site_settings/configuration.html index 4e0b04242..9a0f4373d 100755 --- a/plugins/pencilblue/templates/admin/site_settings/configuration.html +++ b/plugins/pencilblue/templates/admin/site_settings/configuration.html @@ -8,11 +8,11 @@
- + - + From ce68b2d501db1dd4c0568b4b2ee1181509ab18fb Mon Sep 17 00:00:00 2001 From: btidwell Date: Thu, 14 May 2015 13:40:38 -0400 Subject: [PATCH 128/790] Add site to subnav pills on site_settings page --- .../admin/site_settings/configuration.js | 33 +++++++++++++------ 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/plugins/pencilblue/controllers/admin/site_settings/configuration.js b/plugins/pencilblue/controllers/admin/site_settings/configuration.js index 4c2f11cfe..bbcb2ac30 100755 --- a/plugins/pencilblue/controllers/admin/site_settings/configuration.js +++ b/plugins/pencilblue/controllers/admin/site_settings/configuration.js @@ -42,13 +42,11 @@ module.exports = function(pb) { self.reqHandler.serve404(); } else { + self.sitePrefix = pb.SiteService.getCurrentSitePrefix(self.pathSiteUId); self.siteObj = site; cb(); } }); - pb.SiteService.siteExists(self.pathSiteUId, function (err, exists) { - - }); }); }; @@ -76,7 +74,7 @@ module.exports = function(pb) { var angularObjects = pb.ClientJs.getAngularObjects({ navigation: pb.AdminNavigation.get(self.session, ['settings', 'site_settings'], self.ls), - pills: pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, 'configuration'), + pills: pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, 'configuration', {sitePrefix: self.sitePrefix, site: self.pathSiteUId, siteName: self.siteObj.displayName}), config: config }); @@ -89,27 +87,42 @@ module.exports = function(pb) { }; Configuration.getSubNavItems = function(key, ls, data) { - return [{ + var prefix = '/admin'; + var pills = []; + if(data && data.sitePrefix){ + prefix += data.sitePrefix; + } + if(data && data.siteName) { + pills.push({ + name: 'selected_site', + title: data.siteName, + icon: 'sitemap', + href: '/admin/sites' + }); + } + pills = pills.concat([{ name: 'configuration', title: ls.get('CONFIGURATION'), icon: 'refresh', - href: '/admin/site_settings' + href: prefix + '/site_settings' }, { name: 'content', title: ls.get('CONTENT'), icon: 'quote-right', - href: '/admin/site_settings/content' + href: prefix + '/site_settings/content' }, { name: 'email', title: ls.get('EMAIL'), icon: 'envelope', - href: '/admin/site_settings/email' + href: prefix + '/site_settings/email' }, { name: 'libraries', title: ls.get('LIBRARIES'), icon: 'book', - href: '/admin/site_settings/libraries' - }]; + href: prefix + '/site_settings/libraries' + }]); + + return pills; }; //register admin sub-nav From d17c7deda26705c42ccd6ac5b301ea926d04f21b Mon Sep 17 00:00:00 2001 From: btidwell Date: Thu, 14 May 2015 13:46:21 -0400 Subject: [PATCH 129/790] Hide libraries pill for non global sites and fix display of site pill on global --- .../admin/site_settings/configuration.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/plugins/pencilblue/controllers/admin/site_settings/configuration.js b/plugins/pencilblue/controllers/admin/site_settings/configuration.js index bbcb2ac30..4283ec767 100755 --- a/plugins/pencilblue/controllers/admin/site_settings/configuration.js +++ b/plugins/pencilblue/controllers/admin/site_settings/configuration.js @@ -44,6 +44,7 @@ module.exports = function(pb) { else { self.sitePrefix = pb.SiteService.getCurrentSitePrefix(self.pathSiteUId); self.siteObj = site; + self.siteName = site.uid === pb.SiteService.GLOBAL_SITE ? site.uid : site.displayName; cb(); } }); @@ -74,7 +75,7 @@ module.exports = function(pb) { var angularObjects = pb.ClientJs.getAngularObjects({ navigation: pb.AdminNavigation.get(self.session, ['settings', 'site_settings'], self.ls), - pills: pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, 'configuration', {sitePrefix: self.sitePrefix, site: self.pathSiteUId, siteName: self.siteObj.displayName}), + pills: pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, 'configuration', {sitePrefix: self.sitePrefix, site: self.pathSiteUId, siteName: self.siteName}), config: config }); @@ -115,13 +116,17 @@ module.exports = function(pb) { title: ls.get('EMAIL'), icon: 'envelope', href: prefix + '/site_settings/email' - }, { - name: 'libraries', - title: ls.get('LIBRARIES'), - icon: 'book', - href: prefix + '/site_settings/libraries' }]); + if(data && data.site === pb.SiteService.GLOBAL_SITE) { + pills.push({ + name: 'libraries', + title: ls.get('LIBRARIES'), + icon: 'book', + href: prefix + '/site_settings/libraries' + }); + } + return pills; }; From df8382a1530f3b5c647e8d18a66a52054c2e32c5 Mon Sep 17 00:00:00 2001 From: btidwell Date: Thu, 14 May 2015 13:48:32 -0400 Subject: [PATCH 130/790] add siteid to main navigation path of site_settings --- include/admin_navigation.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/admin_navigation.js b/include/admin_navigation.js index cc39f8c18..a8c53658c 100755 --- a/include/admin_navigation.js +++ b/include/admin_navigation.js @@ -198,7 +198,7 @@ module.exports = function AdminNavigationModule(pb) { id: 'site_settings', title: 'SITE_SETTINGS', icon: 'cog', - href: '/admin/site_settings', + href: adminPath + '/site_settings', access: SecurityService.ACCESS_MANAGING_EDITOR }, { From aaa7c25300a1ab31131f9ff0a6a2666417ea0963 Mon Sep 17 00:00:00 2001 From: btidwell Date: Thu, 14 May 2015 13:54:06 -0400 Subject: [PATCH 131/790] Use addSiteToPills in subnav service --- .../admin/site_settings/configuration.js | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/plugins/pencilblue/controllers/admin/site_settings/configuration.js b/plugins/pencilblue/controllers/admin/site_settings/configuration.js index 4283ec767..3e791159e 100755 --- a/plugins/pencilblue/controllers/admin/site_settings/configuration.js +++ b/plugins/pencilblue/controllers/admin/site_settings/configuration.js @@ -89,19 +89,11 @@ module.exports = function(pb) { Configuration.getSubNavItems = function(key, ls, data) { var prefix = '/admin'; - var pills = []; - if(data && data.sitePrefix){ + if(data && data.sitePrefix) { prefix += data.sitePrefix; } - if(data && data.siteName) { - pills.push({ - name: 'selected_site', - title: data.siteName, - icon: 'sitemap', - href: '/admin/sites' - }); - } - pills = pills.concat([{ + + var pills = [{ name: 'configuration', title: ls.get('CONFIGURATION'), icon: 'refresh', @@ -116,7 +108,7 @@ module.exports = function(pb) { title: ls.get('EMAIL'), icon: 'envelope', href: prefix + '/site_settings/email' - }]); + }]; if(data && data.site === pb.SiteService.GLOBAL_SITE) { pills.push({ @@ -127,6 +119,10 @@ module.exports = function(pb) { }); } + if(data && data.siteName) { + return pb.AdminSubnavService.addSiteToPills(pills, data.siteName); + } + return pills; }; From 89d705a9965e29830141b3b7e13d8834dd769b58 Mon Sep 17 00:00:00 2001 From: Christina Chatham Date: Thu, 14 May 2015 14:40:45 -0400 Subject: [PATCH 132/790] Retrieve correct email settings based on site --- include/email.js | 11 +++++++++-- .../controllers/actions/admin/site_settings/email.js | 6 ++++-- .../controllers/admin/site_settings/email.js | 2 +- .../templates/angular/admin/site_settings/email.html | 2 +- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/include/email.js b/include/email.js index bfa5a54a2..b7f899266 100755 --- a/include/email.js +++ b/include/email.js @@ -28,7 +28,13 @@ module.exports = function EmailServiceModule(pb) { * @class EmailService * @constructor */ - function EmailService(){} + function EmailService(siteUID) { + if(pb.config.multisite && siteUID) { + this.site = siteUID; + } else { + this.site = pb.SiteService.GLOBAL_SITE; + } + } /** * @@ -155,7 +161,8 @@ module.exports = function EmailServiceModule(pb) { */ EmailService.prototype.getSettings = function(cb) { var self = this; - pb.settings.get('email_settings', function(err, settings) { + var settingsService = pb.SettingServiceFactory.getServiceBySite(pb.SiteService.getCurrentSite(self.site), true); + settingsService.get('email_settings', function(err, settings) { cb(err, util.isError(err) || !settings ? EmailService.getDefaultSettings() : settings); }); }; diff --git a/plugins/pencilblue/controllers/actions/admin/site_settings/email.js b/plugins/pencilblue/controllers/actions/admin/site_settings/email.js index 598602ebc..535350d2d 100755 --- a/plugins/pencilblue/controllers/actions/admin/site_settings/email.js +++ b/plugins/pencilblue/controllers/actions/admin/site_settings/email.js @@ -18,7 +18,8 @@ module.exports = function(pb) { //pb dependencies - var util = pb.util; + var util = pb.util, + SiteService = pb.SiteService; /** * Saves the site's email settings @@ -30,7 +31,8 @@ module.exports = function(pb) { var self = this; this.getJSONPostParams(function(err, post) { - pb.settings.set('email_settings', post, function(data) { + var settingService = pb.SettingServiceFactory.getServiceBySite(SiteService.getCurrentSite(self.pathVars.siteid), true); + settingService.set('email_settings', post, function(data) { if(util.isError(data)) { cb({ code: 500, diff --git a/plugins/pencilblue/controllers/admin/site_settings/email.js b/plugins/pencilblue/controllers/admin/site_settings/email.js index 7a01f23cd..fec325435 100755 --- a/plugins/pencilblue/controllers/admin/site_settings/email.js +++ b/plugins/pencilblue/controllers/admin/site_settings/email.js @@ -53,7 +53,7 @@ module.exports = function(pb) { } ]; - var emailService = new pb.EmailService(); + var emailService = new pb.EmailService(self.pathVars.siteid); emailService.getSettings(function(err, emailSettings) { var sitePrefix = SiteService.getCurrentSitePrefix(SiteService.getCurrentSite(self.pathVars.siteid)); var angularObjects = pb.ClientJs.getAngularObjects({ diff --git a/plugins/pencilblue/templates/angular/admin/site_settings/email.html b/plugins/pencilblue/templates/angular/admin/site_settings/email.html index 1c6f9eb6b..8c8c36d17 100644 --- a/plugins/pencilblue/templates/angular/admin/site_settings/email.html +++ b/plugins/pencilblue/templates/angular/admin/site_settings/email.html @@ -37,7 +37,7 @@ getWYSIWYGLayout(wysId, function(layout) { $scope.emailSettings.verification_content = layout; - $http.post('/actions' + $scope.sitePrefix + '/admin/site_settings/email', $scope.emailSettings) + $http.post('/actions/admin'+ $scope.sitePrefix +'/site_settings/email', $scope.emailSettings) .success(function(result) { $scope.successMessage = result.message; $scope.saving = false; From a56726e8e0ff14c5a5260d5e469b7fffa0f211d3 Mon Sep 17 00:00:00 2001 From: andparker Date: Thu, 14 May 2015 15:04:20 -0400 Subject: [PATCH 133/790] Update the custom object service and uses to respect the onlyThisSite flag --- include/service/entities/custom_object_service.js | 6 +++--- .../actions/admin/content/objects/delete_object.js | 2 +- .../actions/admin/content/objects/edit_object.js | 2 +- .../controllers/actions/admin/content/objects/new_object.js | 2 +- .../actions/admin/content/objects/sort_objects.js | 2 +- .../actions/admin/content/objects/types/delete_type.js | 2 +- .../actions/admin/content/objects/types/edit_type.js | 2 +- .../actions/admin/content/objects/types/new_type.js | 2 +- .../controllers/admin/content/objects/manage_objects.js | 2 +- .../controllers/admin/content/objects/object_form.js | 2 +- .../controllers/admin/content/objects/sort_objects.js | 2 +- .../controllers/admin/content/objects/types/manage_types.js | 2 +- .../controllers/admin/content/objects/types/type_form.js | 2 +- .../api/admin/content/objects/types/available.js | 2 +- 14 files changed, 16 insertions(+), 16 deletions(-) diff --git a/include/service/entities/custom_object_service.js b/include/service/entities/custom_object_service.js index 54bbaa317..bfa8f29e7 100644 --- a/include/service/entities/custom_object_service.js +++ b/include/service/entities/custom_object_service.js @@ -28,12 +28,12 @@ module.exports = function CustomObjectServiceModule(pb) { * @class CustomObjectService * @constructor */ - function CustomObjectService(pathSiteUid) { + function CustomObjectService(siteUid, onlyThisSite) { this.typesCache = {}; this.typesNametoId = {}; - this.site = pb.SiteService.getCurrentSite(pathSiteUid); - this.siteQueryService = new pb.SiteQueryService(this.site); + this.site = pb.SiteService.getCurrentSite(siteUid); + this.siteQueryService = new pb.SiteQueryService(this.site, onlyThisSite); } //statics diff --git a/plugins/pencilblue/controllers/actions/admin/content/objects/delete_object.js b/plugins/pencilblue/controllers/actions/admin/content/objects/delete_object.js index ba41b8cc6..d3c6752c4 100644 --- a/plugins/pencilblue/controllers/actions/admin/content/objects/delete_object.js +++ b/plugins/pencilblue/controllers/actions/admin/content/objects/delete_object.js @@ -58,7 +58,7 @@ module.exports = function(pb) { return; } - var cos = new pb.CustomObjectService(self.pathSiteUid); + var cos = new pb.CustomObjectService(self.pathSiteUid, true); cos.loadById(vars.id, function(err, customObject) { if (util.isError(err)) { return self.reqHandler.serveError(err); diff --git a/plugins/pencilblue/controllers/actions/admin/content/objects/edit_object.js b/plugins/pencilblue/controllers/actions/admin/content/objects/edit_object.js index b1e9359f8..7f6039902 100644 --- a/plugins/pencilblue/controllers/actions/admin/content/objects/edit_object.js +++ b/plugins/pencilblue/controllers/actions/admin/content/objects/edit_object.js @@ -57,7 +57,7 @@ module.exports = function(pb) { return; } - var service = new pb.CustomObjectService(self.pathSiteUid); + var service = new pb.CustomObjectService(self.pathSiteUid, true); service.loadById(vars.id, function(err, custObj) { if(util.isError(err) || !util.isObject(custObj)) { return cb({ diff --git a/plugins/pencilblue/controllers/actions/admin/content/objects/new_object.js b/plugins/pencilblue/controllers/actions/admin/content/objects/new_object.js index 5d236945d..5a9906355 100644 --- a/plugins/pencilblue/controllers/actions/admin/content/objects/new_object.js +++ b/plugins/pencilblue/controllers/actions/admin/content/objects/new_object.js @@ -57,7 +57,7 @@ module.exports = function(pb) { return } - var service = new pb.CustomObjectService(self.pathSiteUid); + var service = new pb.CustomObjectService(self.pathSiteUid, true); service.loadTypeById(vars.type_id, function(err, customObjectType) { if(util.isError(err) || !util.isObject(customObjectType)) { return cb({ diff --git a/plugins/pencilblue/controllers/actions/admin/content/objects/sort_objects.js b/plugins/pencilblue/controllers/actions/admin/content/objects/sort_objects.js index a0149ca20..068e2daee 100644 --- a/plugins/pencilblue/controllers/actions/admin/content/objects/sort_objects.js +++ b/plugins/pencilblue/controllers/actions/admin/content/objects/sort_objects.js @@ -55,7 +55,7 @@ module.exports = function(pb) { }); } - var service = new pb.CustomObjectService(self.pathSiteUid); + var service = new pb.CustomObjectService(self.pathSiteUid, true); service.loadTypeById(vars.type_id, function(err, customObjectType) { if(util.isError(err) || !util.isObject(customObjectType)) { return cb({ diff --git a/plugins/pencilblue/controllers/actions/admin/content/objects/types/delete_type.js b/plugins/pencilblue/controllers/actions/admin/content/objects/types/delete_type.js index b23e510b1..e28a3f34d 100644 --- a/plugins/pencilblue/controllers/actions/admin/content/objects/types/delete_type.js +++ b/plugins/pencilblue/controllers/actions/admin/content/objects/types/delete_type.js @@ -54,7 +54,7 @@ module.exports = function(pb) { } //ensure existence - var service = new pb.CustomObjectService(self.pathSiteUid); + var service = new pb.CustomObjectService(self.pathSiteUid, true); service.loadTypeById(vars.id, function(err, objectType) { if(objectType === null) { cb({ diff --git a/plugins/pencilblue/controllers/actions/admin/content/objects/types/edit_type.js b/plugins/pencilblue/controllers/actions/admin/content/objects/types/edit_type.js index b1bd92b34..2d1a1c8f3 100644 --- a/plugins/pencilblue/controllers/actions/admin/content/objects/types/edit_type.js +++ b/plugins/pencilblue/controllers/actions/admin/content/objects/types/edit_type.js @@ -56,7 +56,7 @@ module.exports = function(pb) { }); } - var service = new pb.CustomObjectService(self.pathSiteUid); + var service = new pb.CustomObjectService(self.pathSiteUid, true); service.loadTypeById(vars.id, function(err, custObjType) { if(util.isError(err) || !util.isObject(custObjType)) { return cb({ diff --git a/plugins/pencilblue/controllers/actions/admin/content/objects/types/new_type.js b/plugins/pencilblue/controllers/actions/admin/content/objects/types/new_type.js index 99d971137..a14d19e43 100644 --- a/plugins/pencilblue/controllers/actions/admin/content/objects/types/new_type.js +++ b/plugins/pencilblue/controllers/actions/admin/content/objects/types/new_type.js @@ -51,7 +51,7 @@ module.exports = function(pb) { var post = self.body; post.fields.name = {field_type: 'text'}; - var service = new pb.CustomObjectService(self.pathSiteUid); + var service = new pb.CustomObjectService(self.pathSiteUid, true); service.saveType(post, function(err, result) { if(util.isError(err)) { return cb({ diff --git a/plugins/pencilblue/controllers/admin/content/objects/manage_objects.js b/plugins/pencilblue/controllers/admin/content/objects/manage_objects.js index e5101d9fd..45da43afe 100644 --- a/plugins/pencilblue/controllers/admin/content/objects/manage_objects.js +++ b/plugins/pencilblue/controllers/admin/content/objects/manage_objects.js @@ -61,7 +61,7 @@ module.exports = function(pb) { return this.reqHandler.serve404(); } - var service = new pb.CustomObjectService(self.pathSiteUid); + var service = new pb.CustomObjectService(self.pathSiteUid, true); service.loadTypeById(vars.type_id, function(err, custObjType) { if (util.isError(err)) { return self.serveError(err); diff --git a/plugins/pencilblue/controllers/admin/content/objects/object_form.js b/plugins/pencilblue/controllers/admin/content/objects/object_form.js index 7da3f6df5..db55f043a 100644 --- a/plugins/pencilblue/controllers/admin/content/objects/object_form.js +++ b/plugins/pencilblue/controllers/admin/content/objects/object_form.js @@ -119,7 +119,7 @@ module.exports = function(pb) { ObjectFormController.prototype.gatherData = function(vars, cb) { var self = this; - var cos = new pb.CustomObjectService(self.pathSiteUid); + var cos = new pb.CustomObjectService(self.pathSiteUid, true); var tasks = { tabs: function(callback) { diff --git a/plugins/pencilblue/controllers/admin/content/objects/sort_objects.js b/plugins/pencilblue/controllers/admin/content/objects/sort_objects.js index 499dd43cb..d5a2b357e 100644 --- a/plugins/pencilblue/controllers/admin/content/objects/sort_objects.js +++ b/plugins/pencilblue/controllers/admin/content/objects/sort_objects.js @@ -60,7 +60,7 @@ module.exports = function(pb) { return this.reqHandler.serve404(); } - var service = new pb.CustomObjectService(self.pathSiteUid); + var service = new pb.CustomObjectService(self.pathSiteUid, true); service.loadTypeById(vars.type_id, function(err, objectType) { if(util.isError(err)) { return self.reqHandler.serveError(err); diff --git a/plugins/pencilblue/controllers/admin/content/objects/types/manage_types.js b/plugins/pencilblue/controllers/admin/content/objects/types/manage_types.js index ae8e57293..24c8aa8b2 100644 --- a/plugins/pencilblue/controllers/admin/content/objects/types/manage_types.js +++ b/plugins/pencilblue/controllers/admin/content/objects/types/manage_types.js @@ -56,7 +56,7 @@ module.exports = function(pb) { ManageObjectTypes.prototype.render = function(cb) { var self = this; - var service = new pb.CustomObjectService(self.pathSiteUid); + var service = new pb.CustomObjectService(self.pathSiteUid, true); service.findTypes(function(err, custObjTypes) { //none to manage diff --git a/plugins/pencilblue/controllers/admin/content/objects/types/type_form.js b/plugins/pencilblue/controllers/admin/content/objects/types/type_form.js index 0b2614507..c2279682a 100644 --- a/plugins/pencilblue/controllers/admin/content/objects/types/type_form.js +++ b/plugins/pencilblue/controllers/admin/content/objects/types/type_form.js @@ -82,7 +82,7 @@ module.exports = function(pb) { TypeForm.prototype.gatherData = function(vars, cb) { var self = this; - var cos = new pb.CustomObjectService(self.pathSiteUid); + var cos = new pb.CustomObjectService(self.pathSiteUid, true); var tasks = { tabs: function(callback) { diff --git a/plugins/pencilblue/controllers/api/admin/content/objects/types/available.js b/plugins/pencilblue/controllers/api/admin/content/objects/types/available.js index bd1c71f24..ca6be5dbb 100644 --- a/plugins/pencilblue/controllers/api/admin/content/objects/types/available.js +++ b/plugins/pencilblue/controllers/api/admin/content/objects/types/available.js @@ -53,7 +53,7 @@ module.exports = function(pb) { }); } - var service = new pb.CustomObjectService(self.pathSiteUid); + var service = new pb.CustomObjectService(self.pathSiteUid, true); service.typeExists(get.name, function(err, exists) { if (util.isError(err)) { return cb({content: pb.BaseController.apiResponse(pb.BaseController.API_FAILURE, err.stack, false)}); From 91c2f5a068ae7bf12ebe3985e6d4a97e22a84e8c Mon Sep 17 00:00:00 2001 From: btidwell Date: Thu, 14 May 2015 15:04:39 -0400 Subject: [PATCH 134/790] Disable apply button for non-global site on settings page --- .../controllers/admin/site_settings/configuration.js | 6 ++++-- .../templates/admin/site_settings/configuration.html | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/plugins/pencilblue/controllers/admin/site_settings/configuration.js b/plugins/pencilblue/controllers/admin/site_settings/configuration.js index 3e791159e..68ed2c18b 100755 --- a/plugins/pencilblue/controllers/admin/site_settings/configuration.js +++ b/plugins/pencilblue/controllers/admin/site_settings/configuration.js @@ -44,7 +44,8 @@ module.exports = function(pb) { else { self.sitePrefix = pb.SiteService.getCurrentSitePrefix(self.pathSiteUId); self.siteObj = site; - self.siteName = site.uid === pb.SiteService.GLOBAL_SITE ? site.uid : site.displayName; + self.isGlobalSite = site.uid === pb.SiteService.GLOBAL_SITE; + self.siteName = self.isGlobalSite ? site.uid : site.displayName; cb(); } }); @@ -76,7 +77,8 @@ module.exports = function(pb) { var angularObjects = pb.ClientJs.getAngularObjects({ navigation: pb.AdminNavigation.get(self.session, ['settings', 'site_settings'], self.ls), pills: pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, 'configuration', {sitePrefix: self.sitePrefix, site: self.pathSiteUId, siteName: self.siteName}), - config: config + config: config, + isGlobalSite: self.isGlobalSite }); self.setPageName(self.ls.get('CONFIGURATION')); diff --git a/plugins/pencilblue/templates/admin/site_settings/configuration.html b/plugins/pencilblue/templates/admin/site_settings/configuration.html index 9a0f4373d..6b5580d38 100755 --- a/plugins/pencilblue/templates/admin/site_settings/configuration.html +++ b/plugins/pencilblue/templates/admin/site_settings/configuration.html @@ -52,7 +52,7 @@
^loc_SITE_NAME^^site_name^
^loc_SITE_ROOT^^site_root^
^loc_DOCUMENT_ROOT^
- From e84afc97535482eb1b955a36330b925c1c0e94e4 Mon Sep 17 00:00:00 2001 From: Christina Chatham Date: Thu, 14 May 2015 15:39:24 -0400 Subject: [PATCH 135/790] Add site validation --- .../controllers/admin/site_settings/email.js | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/plugins/pencilblue/controllers/admin/site_settings/email.js b/plugins/pencilblue/controllers/admin/site_settings/email.js index fec325435..f39204a23 100755 --- a/plugins/pencilblue/controllers/admin/site_settings/email.js +++ b/plugins/pencilblue/controllers/admin/site_settings/email.js @@ -30,9 +30,36 @@ module.exports = function(pb) { //statics var SUB_NAV_KEY = 'site_email_settings'; + + /** + * + * @method render + * + */ Email.prototype.render = function(cb) { var self = this; + var site = pb.SiteService.getCurrentSite(self.pathVars.siteid); + pb.SiteService.siteExists(site, function (err, siteExists) { + if (siteExists) { + self.onSiteValidated(site, cb); + } + else { + self.reqHandler.serve404(); + return; + } + }); + }; + + /** + * + * @method onSiteValidated + * @param site + * @param cb + * + */ + Email.prototype.onSiteValidated = function onSiteValidated(site, cb) { + var self = this; var tabs = [ { From 04b2933d200e5903ced00294fce9c7ae5d8e6568 Mon Sep 17 00:00:00 2001 From: btidwell Date: Thu, 14 May 2015 15:43:47 -0400 Subject: [PATCH 136/790] add global site to libraries route. remove un-needed route --- include/admin_navigation.js | 4 +-- .../admin/site_settings/libraries.js | 28 +++++++++++++++---- .../include/multisite_admin_routes.js | 16 +++++------ 3 files changed, 33 insertions(+), 15 deletions(-) diff --git a/include/admin_navigation.js b/include/admin_navigation.js index a8c53658c..04075b8ea 100755 --- a/include/admin_navigation.js +++ b/include/admin_navigation.js @@ -219,8 +219,8 @@ module.exports = function AdminNavigationModule(pb) { id: 'library_settings', title: 'LIBRARIES', icon: 'book', - href: '/admin/site_settings/libraries', - access: SecurityService.ACCESS_MANAGING_EDITOR + href: '/admin/'+ pb.SiteService.GLOBAL_SITE +'/site_settings/libraries', + access: SecurityService.ACCESS_ADMINISTRATOR } ] }, diff --git a/plugins/pencilblue/controllers/admin/site_settings/libraries.js b/plugins/pencilblue/controllers/admin/site_settings/libraries.js index 2d6157e54..c3e4bcc8b 100644 --- a/plugins/pencilblue/controllers/admin/site_settings/libraries.js +++ b/plugins/pencilblue/controllers/admin/site_settings/libraries.js @@ -29,6 +29,15 @@ module.exports = function(pb) { //statics var SUB_NAV_KEY = 'libraries_settings'; + Libraries.prototype.init = function (props, cb) { + var self = this; + pb.BaseController.prototype.init.call(self, props, function () { + self.sitePrefix = pb.SiteService.getCurrentSitePrefix(pb.SiteService.GLOBAL_SITE); + self.siteName = pb.SiteService.GLOBAL_SITE; + cb(); + }); + }; + Libraries.prototype.render = function(cb) { var self = this; @@ -51,7 +60,7 @@ module.exports = function(pb) { librariesService.getSettings(function(err, librarySettings) { var angularObjects = pb.ClientJs.getAngularObjects({ navigation: pb.AdminNavigation.get(self.session, ['settings', 'site_settings'], self.ls), - pills: pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, 'libraries'), + pills: pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, 'libraries', {sitePrefix: self.sitePrefix, siteName:self.siteName}), tabs: tabs, librarySettings: librarySettings, cdnDefaults: pb.LibrariesService.getCDNDefaults(), @@ -68,22 +77,31 @@ module.exports = function(pb) { Libraries.getSubNavItems = function(key, ls, data) { - return [{ + var prefix = '/admin'; + if(data && data.sitePrefix) { + prefix += data.sitePrefix; + } + var pills = [{ name: 'configuration', title: ls.get('LIBRARIES'), icon: 'chevron-left', - href: '/admin/site_settings' + href: prefix + '/site_settings' }, { name: 'content', title: ls.get('CONTENT'), icon: 'quote-right', - href: '/admin/site_settings/content' + href: prefix + '/site_settings/content' }, { name: 'email', title: ls.get('EMAIL'), icon: 'envelope', - href: '/admin/site_settings/email' + href: prefix + '/site_settings/email' }]; + if(data && data.siteName) { + return pb.AdminSubnavService.addSiteToPills(pills, data.siteName); + } + + return pills; }; //register admin sub-nav diff --git a/plugins/pencilblue/include/multisite_admin_routes.js b/plugins/pencilblue/include/multisite_admin_routes.js index 0df24f922..5b823921c 100644 --- a/plugins/pencilblue/include/multisite_admin_routes.js +++ b/plugins/pencilblue/include/multisite_admin_routes.js @@ -560,14 +560,6 @@ module.exports = function Routes(pb){ controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'site_settings', 'configuration.js'), content_type: 'text/html' }, - { - method: 'post', - path: "/actions/admin/:siteid/site_settings", - access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, - auth_required: true, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'site_settings', 'configuration.js'), - content_type: 'text/html' - }, { method: 'get', path: "/admin/:siteid/site_settings/content", @@ -599,6 +591,14 @@ module.exports = function Routes(pb){ auth_required: true, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'site_settings', 'email.js'), content_type: 'text/html' + }, + { + method: 'get', + path: "/admin/"+ pb.SiteService.GLOBAL_SITE + "/site_settings/libraries", + access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, + auth_required: true, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'site_settings', 'libraries.js'), + content_type: 'text/html' } ]; }; From 12b362d1d002cb786d6e559cbf13f3a23754701a Mon Sep 17 00:00:00 2001 From: Eugene Chang Date: Thu, 14 May 2015 16:00:26 -0400 Subject: [PATCH 137/790] SiteQueryService revamp to be a subclass of DAO --- .../service/entities/site_query_service.js | 152 +++++------------- .../admin/content/comments/manage_comments.js | 1 - 2 files changed, 37 insertions(+), 116 deletions(-) diff --git a/include/service/entities/site_query_service.js b/include/service/entities/site_query_service.js index 937d1a009..7c07e6b4d 100644 --- a/include/service/entities/site_query_service.js +++ b/include/service/entities/site_query_service.js @@ -21,8 +21,8 @@ module.exports = function SiteQueryServiceModule(pb) { var SITE_FIELD = pb.SiteService.SITE_FIELD; var GLOBAL_SITE = pb.SiteService.GLOBAL_SITE; var _ = require('lodash'); - var dao = new pb.DAO(); var util = pb.util; + var DAO = pb.DAO; /** * Create an instance of the site query service specific to the given site @@ -34,14 +34,15 @@ module.exports = function SiteQueryServiceModule(pb) { function SiteQueryService(siteUId, onlyThisSite) { this.siteUId = siteUId; this.onlyThisSite = onlyThisSite; + DAO.call(this); } + util.inherits(SiteQueryService, DAO); + function modifyLoadWhere(site, where) { if (pb.config.multisite) { - if (Object.isFrozen(where)) { - where = _.clone(where); - } - if (site === pb.SiteService.GLOBAL_SITE) { + where = _.clone(where); + if (site === GLOBAL_SITE) { var siteDoesNotExist = {}, siteEqualToSpecified = {}; siteDoesNotExist[SITE_FIELD] = {$exists: false}; siteEqualToSpecified[SITE_FIELD] = site; @@ -56,12 +57,8 @@ module.exports = function SiteQueryServiceModule(pb) { function modifyLoadOptions(site, options) { if (pb.config.multisite) { - var target; - if (!Object.isFrozen(options)) { - target = options; - } else { - target = _.clone(options); - } + var target = _.clone(options); + target.where = target.where || {}; target.where = modifyLoadWhere(site, target.where); return target; @@ -89,65 +86,46 @@ module.exports = function SiteQueryServiceModule(pb) { } } - /** - * Wrapper for site-aware DAO.q, search target collection with specified site - * If onlyThisSite is not true, and this service is instantiated with a non-global site, then - * this value will try to re-run this query against global site if no docs were found with specified site - * - * @param collection - * @param options - * @param callback - */ - SiteQueryService.prototype.q = function (collection, options, callback) { - if (util.isFunction(options)) { - callback = options; - options = {}; - } - - options = modifyLoadOptions(this.siteUId, options); - if (this.onlyThisSite || isGlobal(this.siteUId)) { - dao.q(collection, options, callback); + function applySiteOperation(self, callback, delegate) { + if (siteSpecific(self)) { + delegate(self.siteUId, callback); } else { - dao.q(collection, options, function (err, docs) { - if (util.isError(err) || docs) { - callback(err, docs); + delegate(self.siteUId, function (err, cursor) { + if (util.isError(err)) { + callback(err, cursor); } else { - options = modifyLoadOptions(GLOBAL_SITE, options); - dao.q(collection, options, callback); + cursor.count(function (countError, count) { + if (count) { + callback(err, cursor); + } else { + delegate(GLOBAL_SITE, callback); + } + }); } - }); + }) } - }; + } + + function siteSpecific(self) { + return self.onlyThisSite || isGlobal(self.siteUId); + } function isGlobal(siteUId) { return !siteUId || siteUId === GLOBAL_SITE; } /** - * Wrapper for site-aware DAO.exists. Determines if an object exists matching criteria with the specified site. - * - * @method exists - * @param {String} collection The collection to search in - * @param {Object} where Key value pair object - * @param {Function} cb Callback function - */ - SiteQueryService.prototype.exists = function(collection, where, cb) { - where = modifyLoadWhere(this.siteUId, where); - dao.exists(collection, where, cb) - }; - - /** - * Wrapper for site-aware DAO.unique, determine if the document matching the query is unique within specified site - * Only searches within specified site. - * - * @param collection - * @param where - * @param exclusionId + * Overriding protected method of DAO to achieve site-aware query + * @protected + * @param options * @param callback */ - SiteQueryService.prototype.unique = function (collection, where, exclusionId, callback) { - where = modifyLoadWhere(this.siteUId, where); - dao.unique(collection, where, exclusionId, callback); + SiteQueryService.prototype._doQuery = function (options, callback) { + var self = this; + applySiteOperation(self, callback, function (site, opCallback) { + var moddedOptions = modifyLoadOptions(site, options); + DAO.prototype._doQuery.call(self, moddedOptions, opCallback); + }); }; /** @@ -159,63 +137,7 @@ module.exports = function SiteQueryServiceModule(pb) { */ SiteQueryService.prototype.save = function (dbObj, options, callback) { dbObj = modifySave(this.siteUId, dbObj); - dao.save(dbObj, options, callback); - }; - - /** - * Proxy for DAO.loadByValue; Retrieves objects matching a key value pair - * - * @method loadByValue - * @param {String} key The key to search for - * @param {*} value The value to search for - * @param {String} collection The collection to search in - * @param {Object} options Key value pair object to exclude the retrival of data - * @param {Function} callback Callback function - */ - SiteQueryService.prototype.loadByValue = function (key, value, collection, options, callback) { - var where = {}; - where[key] = value; - this.loadByValues(where, collection, options, callback); - }; - - /** - * Wrapper for DAO.loadByValues. Retrieves object matching several key value pairs - * - * @method loadByValues - * @param {Object} where Key value pair object - * @param {String} collection The collection to search in - * @param {Object} options Key value pair object to exclude the retrieval of data - * @param {Function} callback Callback function - */ - SiteQueryService.prototype.loadByValues = function(where, collection, options, callback) { - where = modifyLoadWhere(this.siteUId, where); - dao.loadByValues(where, collection, options, callback); - }; - - /** - * Proxy for DAO.loadById; loads an object by its id, but its site must also match the query service's site - * - * @method loadById - * @param {String} id The unique id of the object - * @param {String} collection The collection the object is in - * @param {Object} options Key value pair object to exclude the retrival of data - * @param {Function} callback Callback function - */ - SiteQueryService.prototype.loadById = function (id, collection, options, callback) { - this.loadByValues(pb.DAO.getIdWhere(id), collection, options, callback); - }; - - /** - * Wrapper for DAO.count; Gets the count of objects matching criteria - * - * @method count - * @param {String} entityType The type of object to search for - * @param {Object} where Key value pair object - * @param {Function} callback Callback function - */ - SiteQueryService.prototype.count = function (entityType, where, callback) { - where = modifyLoadWhere(this.siteUId, where); - dao.count(entityType, where, callback); + DAO.prototype.save.call(this, dbObj, options, callback); }; function modifySave(site, objectToSave) { diff --git a/plugins/pencilblue/controllers/admin/content/comments/manage_comments.js b/plugins/pencilblue/controllers/admin/content/comments/manage_comments.js index c4fe60f84..7fe5367e9 100755 --- a/plugins/pencilblue/controllers/admin/content/comments/manage_comments.js +++ b/plugins/pencilblue/controllers/admin/content/comments/manage_comments.js @@ -110,7 +110,6 @@ module.exports = function(pb) { * * @method getCommentDetails * @param {Array} comments - * @param {DAO} dao * @param {Function} cb */ ManageComments.prototype.getCommentDetails = function(comments, cb) { From 66aa1e6a80d4aa703a8682b79ab65894411f564e Mon Sep 17 00:00:00 2001 From: Eugene Chang Date: Thu, 14 May 2015 16:11:41 -0400 Subject: [PATCH 138/790] Adding site-awareness to user info in admin --- plugins/pencilblue/include/multisite_admin_routes.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/plugins/pencilblue/include/multisite_admin_routes.js b/plugins/pencilblue/include/multisite_admin_routes.js index 9813d51de..7c816cac3 100644 --- a/plugins/pencilblue/include/multisite_admin_routes.js +++ b/plugins/pencilblue/include/multisite_admin_routes.js @@ -549,6 +549,13 @@ module.exports = function Routes(pb){ auth_required: true, access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'themes', 'site_logo.js') + }, + { + method: 'get', + path: "/admin/:siteid/users/:id", + auth_required: true, + access_level: pb.SecurityService.ACCESS_EDITOR, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'users', 'user_form.js'), } ]; }; From bfb5637177977d6df42ccb497af3bb8e38cab626 Mon Sep 17 00:00:00 2001 From: Eugene Chang Date: Thu, 14 May 2015 16:22:03 -0400 Subject: [PATCH 139/790] Adding more error handling in SiteQueryService --- include/service/entities/site_query_service.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/include/service/entities/site_query_service.js b/include/service/entities/site_query_service.js index 7c07e6b4d..10d17e7af 100644 --- a/include/service/entities/site_query_service.js +++ b/include/service/entities/site_query_service.js @@ -95,7 +95,9 @@ module.exports = function SiteQueryServiceModule(pb) { callback(err, cursor); } else { cursor.count(function (countError, count) { - if (count) { + if (util.isError(countError)) { + callback(countError); + } else if (count) { callback(err, cursor); } else { delegate(GLOBAL_SITE, callback); From 495523b2389f45e5fc00b81b6550c706e0b1c5dc Mon Sep 17 00:00:00 2001 From: Eugene Chang Date: Thu, 14 May 2015 16:49:13 -0400 Subject: [PATCH 140/790] Fixing article link in comments --- .../controllers/admin/content/comments/manage_comments.js | 8 +++++--- .../templates/admin/content/comments/manage_comments.html | 4 ++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/plugins/pencilblue/controllers/admin/content/comments/manage_comments.js b/plugins/pencilblue/controllers/admin/content/comments/manage_comments.js index 7fe5367e9..cb8a8955b 100755 --- a/plugins/pencilblue/controllers/admin/content/comments/manage_comments.js +++ b/plugins/pencilblue/controllers/admin/content/comments/manage_comments.js @@ -40,8 +40,9 @@ module.exports = function(pb) { self.sitePrefix = pb.SiteService.getCurrentSitePrefix(self.pathSiteUId); self.queryService = new pb.SiteQueryService(self.pathSiteUId); var siteService = new pb.SiteService(); - siteService.getSiteNameByUid(self.pathSiteUId, function (siteName) { - self.siteName = siteName; + siteService.getByUid(self.pathSiteUId, function (err, objSite) { + self.siteName = objSite.displayName; + self.siteRoot = objSite.hostname; cb(); }); } @@ -92,7 +93,8 @@ module.exports = function(pb) { pills: pills, comments: commentsWithDetails, allowComments: contentSettings.allow_comments, - sitePrefix: self.sitePrefix + sitePrefix: self.sitePrefix, + siteRoot: self.siteRoot }); //load the template diff --git a/plugins/pencilblue/templates/admin/content/comments/manage_comments.html b/plugins/pencilblue/templates/admin/content/comments/manage_comments.html index bd243733e..eff8954b1 100755 --- a/plugins/pencilblue/templates/admin/content/comments/manage_comments.html +++ b/plugins/pencilblue/templates/admin/content/comments/manage_comments.html @@ -2,7 +2,7 @@
^tmp_admin=elements=error_success^
- ^loc_COMMENTS_DISABLED^. ^loc_ENABLE_HERE^. + ^loc_COMMENTS_DISABLED^. ^loc_ENABLE_HERE^.
^tmp_admin=elements=sub_nav^ ^tmp_admin=elements=search_input^ @@ -11,7 +11,7 @@ ^tmp_admin=elements=table_headers^ - + From 63cbb2bd14955c15d97bbd5da43b31c322ae4866 Mon Sep 17 00:00:00 2001 From: Eugene Chang Date: Fri, 15 May 2015 11:22:03 -0400 Subject: [PATCH 141/790] Fixing nav querying --- .../controllers/admin/content/navigation/nav_item_form.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/pencilblue/controllers/admin/content/navigation/nav_item_form.js b/plugins/pencilblue/controllers/admin/content/navigation/nav_item_form.js index 895d91abd..b8a256865 100644 --- a/plugins/pencilblue/controllers/admin/content/navigation/nav_item_form.js +++ b/plugins/pencilblue/controllers/admin/content/navigation/nav_item_form.js @@ -150,14 +150,14 @@ module.exports = function(pb) { return; } - self.navService.loadById(vars.id, 'section', function(err, navItem) { + self.queryService.loadById(vars.id, 'section', function(err, navItem) { if(!navItem.item) { callback(err, navItem); return; } //TODO modify such that only the needed field of "headline" is returned. - self.navService.loadById(navItem.item, navItem.type, function(err, articleOrPage) { + self.queryService.loadById(navItem.item, navItem.type, function(err, articleOrPage) { if(articleOrPage) { navItem.contentSearchValue = articleOrPage.headline; } From 6b465df1fb17baf2b141276f94848f5210713337 Mon Sep 17 00:00:00 2001 From: btidwell Date: Fri, 15 May 2015 11:44:27 -0400 Subject: [PATCH 142/790] load site on portfolio index controller and update ts registers based on site --- plugins/portfolio/controllers/index.js | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/plugins/portfolio/controllers/index.js b/plugins/portfolio/controllers/index.js index 790998794..a606e4730 100755 --- a/plugins/portfolio/controllers/index.js +++ b/plugins/portfolio/controllers/index.js @@ -35,6 +35,22 @@ module.exports = function IndexModule(pb) { function Index() {} util.inherits(Index, pb.BaseController); + Index.prototype.init = function(props, cb) { + var self = this; + pb.BaseController.prototype.init.call(self, props, function () { + var siteService = new pb.SiteService(); + siteService.getByUid(self.site, function(err, site) { + if (!site) { + self.reqHandler.serve404(); + } + else { + self.siteObj = site; + cb(); + } + }); + }); + }; + /** * This is the function that will be called by the system's RequestHandler. It * will map the incoming route to the ones below and then instantiate this @@ -55,12 +71,13 @@ module.exports = function IndexModule(pb) { }; var options = { - currUrl: this.req.url + currUrl: this.req.url, + site: self.site }; TopMenu.getTopMenu(self.session, self.ls, options, function(themeSettings, navigation, accountButtons) { TopMenu.getBootstrapNav(navigation, accountButtons, function(navigation, accountButtons) { - var pluginService = new pb.PluginService(); + var pluginService = new pb.PluginService(pb.SiteService.getCurrentSite(self.site)); pluginService.getSettings('portfolio', function(err, portfolioSettings) { var homePageKeywords = ''; var homePageDescription = ''; @@ -76,10 +93,10 @@ module.exports = function IndexModule(pb) { break; } } - + console.log(self.siteObj); self.ts.registerLocal('meta_keywords', homePageKeywords); self.ts.registerLocal('meta_desc', homePageDescription); - self.ts.registerLocal('meta_title', pb.config.siteName); + self.ts.registerLocal('meta_title', self.siteObj.displayName); self.ts.registerLocal('meta_lang', localizationLanguage); self.ts.registerLocal('current_url', self.req.url); self.ts.registerLocal('navigation', new pb.TemplateValue(navigation, false)); From 2b08dffc10e7591f30bd4686a93a5fb1b892673d Mon Sep 17 00:00:00 2001 From: Eugene Chang Date: Fri, 15 May 2015 12:27:18 -0400 Subject: [PATCH 143/790] Fixing calls to SiteQueryService --- .../actions/admin/content/navigation/delete_nav_item.js | 2 +- .../actions/admin/content/navigation/edit_nav_item.js | 2 +- .../actions/admin/content/navigation/new_nav_item.js | 2 +- .../controllers/actions/admin/content/topics/edit_topic.js | 2 +- .../controllers/actions/admin/content/topics/import_topics.js | 2 +- .../controllers/actions/admin/content/topics/new_topic.js | 2 +- .../controllers/admin/content/articles/article_form.js | 2 +- .../controllers/admin/content/articles/manage_articles.js | 2 +- .../controllers/admin/content/comments/manage_comments.js | 4 ++-- .../controllers/admin/content/navigation/nav_item_form.js | 2 +- .../controllers/admin/content/navigation/nav_map.js | 2 +- .../controllers/admin/content/pages/manage_pages.js | 2 +- .../pencilblue/controllers/admin/content/pages/page_form.js | 2 +- .../controllers/admin/content/topics/import_topics.js | 2 +- .../controllers/admin/content/topics/manage_topics.js | 2 +- .../pencilblue/controllers/admin/content/topics/topic_form.js | 2 +- plugins/pencilblue/controllers/api/content/search.js | 4 ++-- 17 files changed, 19 insertions(+), 19 deletions(-) diff --git a/plugins/pencilblue/controllers/actions/admin/content/navigation/delete_nav_item.js b/plugins/pencilblue/controllers/actions/admin/content/navigation/delete_nav_item.js index 39ca5a5a0..6164cf851 100644 --- a/plugins/pencilblue/controllers/actions/admin/content/navigation/delete_nav_item.js +++ b/plugins/pencilblue/controllers/actions/admin/content/navigation/delete_nav_item.js @@ -37,7 +37,7 @@ module.exports = function(pb) { else { self.navService = new pb.SectionService(self.pathSiteUId, true); self.sitePrefix = pb.SiteService.getCurrentSitePrefix(self.pathSiteUId); - self.queryService = new pb.SiteQueryService(self.pathSiteUId); + self.queryService = new pb.SiteQueryService(self.pathSiteUId, true); self.settings = pb.SettingServiceFactory.getServiceBySite(self.pathSiteUId, true); var siteService = new pb.SiteService(); siteService.getSiteNameByUid(self.pathSiteUId, function (siteName) { diff --git a/plugins/pencilblue/controllers/actions/admin/content/navigation/edit_nav_item.js b/plugins/pencilblue/controllers/actions/admin/content/navigation/edit_nav_item.js index f0fd15e56..0f72dfaaf 100644 --- a/plugins/pencilblue/controllers/actions/admin/content/navigation/edit_nav_item.js +++ b/plugins/pencilblue/controllers/actions/admin/content/navigation/edit_nav_item.js @@ -37,7 +37,7 @@ module.exports = function(pb) { else { self.navService = new pb.SectionService(self.pathSiteUId, true); self.sitePrefix = pb.SiteService.getCurrentSitePrefix(self.pathSiteUId); - self.queryService = new pb.SiteQueryService(self.pathSiteUId); + self.queryService = new pb.SiteQueryService(self.pathSiteUId, true); self.settings = pb.SettingServiceFactory.getServiceBySite(self.pathSiteUId, true); var siteService = new pb.SiteService(); siteService.getSiteNameByUid(self.pathSiteUId, function (siteName) { diff --git a/plugins/pencilblue/controllers/actions/admin/content/navigation/new_nav_item.js b/plugins/pencilblue/controllers/actions/admin/content/navigation/new_nav_item.js index b1ac862eb..20b904fc9 100644 --- a/plugins/pencilblue/controllers/actions/admin/content/navigation/new_nav_item.js +++ b/plugins/pencilblue/controllers/actions/admin/content/navigation/new_nav_item.js @@ -37,7 +37,7 @@ module.exports = function(pb) { else { self.navService = new pb.SectionService(self.pathSiteUId, true); self.sitePrefix = pb.SiteService.getCurrentSitePrefix(self.pathSiteUId); - self.queryService = new pb.SiteQueryService(self.pathSiteUId); + self.queryService = new pb.SiteQueryService(self.pathSiteUId, true); self.settings = pb.SettingServiceFactory.getServiceBySite(self.pathSiteUId, true); var siteService = new pb.SiteService(); siteService.getSiteNameByUid(self.pathSiteUId, function (siteName) { diff --git a/plugins/pencilblue/controllers/actions/admin/content/topics/edit_topic.js b/plugins/pencilblue/controllers/actions/admin/content/topics/edit_topic.js index a319a6187..55af937aa 100644 --- a/plugins/pencilblue/controllers/actions/admin/content/topics/edit_topic.js +++ b/plugins/pencilblue/controllers/actions/admin/content/topics/edit_topic.js @@ -36,7 +36,7 @@ module.exports = function(pb) { } else { self.sitePrefix = pb.SiteService.getCurrentSitePrefix(self.pathSiteUId); - self.queryService = new pb.SiteQueryService(self.pathSiteUId); + self.queryService = new pb.SiteQueryService(self.pathSiteUId, true); var siteService = new pb.SiteService(); siteService.getSiteNameByUid(self.pathSiteUId, function (siteName) { self.siteName = siteName; diff --git a/plugins/pencilblue/controllers/actions/admin/content/topics/import_topics.js b/plugins/pencilblue/controllers/actions/admin/content/topics/import_topics.js index 6b9317e62..938eb4c13 100755 --- a/plugins/pencilblue/controllers/actions/admin/content/topics/import_topics.js +++ b/plugins/pencilblue/controllers/actions/admin/content/topics/import_topics.js @@ -43,7 +43,7 @@ module.exports = function(pb) { } else { self.sitePrefix = pb.SiteService.getCurrentSitePrefix(self.pathSiteUId); - self.queryService = new pb.SiteQueryService(self.pathSiteUId); + self.queryService = new pb.SiteQueryService(self.pathSiteUId, true); var siteService = new pb.SiteService(); siteService.getSiteNameByUid(self.pathSiteUId, function (siteName) { self.siteName = siteName; diff --git a/plugins/pencilblue/controllers/actions/admin/content/topics/new_topic.js b/plugins/pencilblue/controllers/actions/admin/content/topics/new_topic.js index 13c01b700..c23012355 100755 --- a/plugins/pencilblue/controllers/actions/admin/content/topics/new_topic.js +++ b/plugins/pencilblue/controllers/actions/admin/content/topics/new_topic.js @@ -36,7 +36,7 @@ module.exports = function(pb) { } else { self.sitePrefix = pb.SiteService.getCurrentSitePrefix(self.pathSiteUId); - self.queryService = new pb.SiteQueryService(self.pathSiteUId); + self.queryService = new pb.SiteQueryService(self.pathSiteUId, true); var siteService = new pb.SiteService(); siteService.getSiteNameByUid(self.pathSiteUId, function (siteName) { self.siteName = siteName; diff --git a/plugins/pencilblue/controllers/admin/content/articles/article_form.js b/plugins/pencilblue/controllers/admin/content/articles/article_form.js index 51cd9e859..4cd1dd23c 100755 --- a/plugins/pencilblue/controllers/admin/content/articles/article_form.js +++ b/plugins/pencilblue/controllers/admin/content/articles/article_form.js @@ -39,7 +39,7 @@ module.exports = function(pb) { } else { self.sitePrefix = pb.SiteService.getCurrentSitePrefix(self.pathSiteUId); - self.queryService = new pb.SiteQueryService(self.pathSiteUId); + self.queryService = new pb.SiteQueryService(self.pathSiteUId, true); var siteService = new pb.SiteService(); siteService.getSiteNameByUid(self.pathSiteUId, function (siteName) { self.siteName = siteName; diff --git a/plugins/pencilblue/controllers/admin/content/articles/manage_articles.js b/plugins/pencilblue/controllers/admin/content/articles/manage_articles.js index e70d80eb0..f7a171020 100755 --- a/plugins/pencilblue/controllers/admin/content/articles/manage_articles.js +++ b/plugins/pencilblue/controllers/admin/content/articles/manage_articles.js @@ -28,7 +28,7 @@ module.exports = function(pb) { ManageArticles.prototype.init = function (props, cb) { this.pathSiteUId = pb.SiteService.getCurrentSite(props.path_vars.siteid); - this.queryService = new pb.SiteQueryService(this.pathSiteUId); + this.queryService = new pb.SiteQueryService(this.pathSiteUId, true); this.sitePrefix = pb.SiteService.getCurrentSitePrefix(this.pathSiteUId); pb.BaseController.prototype.init.call(this, props, cb); diff --git a/plugins/pencilblue/controllers/admin/content/comments/manage_comments.js b/plugins/pencilblue/controllers/admin/content/comments/manage_comments.js index cb8a8955b..a2a6f23cc 100755 --- a/plugins/pencilblue/controllers/admin/content/comments/manage_comments.js +++ b/plugins/pencilblue/controllers/admin/content/comments/manage_comments.js @@ -38,7 +38,7 @@ module.exports = function(pb) { } else { self.sitePrefix = pb.SiteService.getCurrentSitePrefix(self.pathSiteUId); - self.queryService = new pb.SiteQueryService(self.pathSiteUId); + self.queryService = new pb.SiteQueryService(self.pathSiteUId, true); var siteService = new pb.SiteService(); siteService.getByUid(self.pathSiteUId, function (err, objSite) { self.siteName = objSite.displayName; @@ -123,7 +123,7 @@ module.exports = function(pb) { } this.getCommentingUser = function(index) { - self.queryService.loadById(comments[index].commenter, 'user', function(err, user) { + self.queryService.__proto__.loadById(comments[index].commenter, 'user', function(err, user) { if(!util.isError(err) && user !== null) { comments[index].user_name = user.first_name + ' ' + user.last_name; } diff --git a/plugins/pencilblue/controllers/admin/content/navigation/nav_item_form.js b/plugins/pencilblue/controllers/admin/content/navigation/nav_item_form.js index b8a256865..85b213bdf 100644 --- a/plugins/pencilblue/controllers/admin/content/navigation/nav_item_form.js +++ b/plugins/pencilblue/controllers/admin/content/navigation/nav_item_form.js @@ -44,7 +44,7 @@ module.exports = function(pb) { else { self.navService = new pb.SectionService(self.pathSiteUId, true); self.sitePrefix = pb.SiteService.getCurrentSitePrefix(self.pathSiteUId); - self.queryService = new pb.SiteQueryService(self.pathSiteUId); + self.queryService = new pb.SiteQueryService(self.pathSiteUId, true); self.settings = pb.SettingServiceFactory.getServiceBySite(self.pathSiteUId, true); var siteService = new pb.SiteService(); siteService.getSiteNameByUid(self.pathSiteUId, function (siteName) { diff --git a/plugins/pencilblue/controllers/admin/content/navigation/nav_map.js b/plugins/pencilblue/controllers/admin/content/navigation/nav_map.js index 6e740f74b..6a5034b4a 100644 --- a/plugins/pencilblue/controllers/admin/content/navigation/nav_map.js +++ b/plugins/pencilblue/controllers/admin/content/navigation/nav_map.js @@ -39,7 +39,7 @@ module.exports = function(pb) { else { self.navService = new pb.SectionService(self.pathSiteUId, true); self.sitePrefix = pb.SiteService.getCurrentSitePrefix(self.pathSiteUId); - self.queryService = new pb.SiteQueryService(self.pathSiteUId); + self.queryService = new pb.SiteQueryService(self.pathSiteUId, true); self.settings = pb.SettingServiceFactory.getServiceBySite(self.pathSiteUId, true); var siteService = new pb.SiteService(); siteService.getSiteNameByUid(self.pathSiteUId, function (siteName) { diff --git a/plugins/pencilblue/controllers/admin/content/pages/manage_pages.js b/plugins/pencilblue/controllers/admin/content/pages/manage_pages.js index 30ef34413..0dc097bdf 100755 --- a/plugins/pencilblue/controllers/admin/content/pages/manage_pages.js +++ b/plugins/pencilblue/controllers/admin/content/pages/manage_pages.js @@ -28,7 +28,7 @@ module.exports = function(pb) { ManagePages.prototype.init = function (props, cb) { this.pathSiteUId = pb.SiteService.getCurrentSite(props.path_vars.siteid); - this.queryService = new pb.SiteQueryService(this.pathSiteUId); + this.queryService = new pb.SiteQueryService(this.pathSiteUId, true); this.sitePrefix = pb.SiteService.getCurrentSitePrefix(this.pathSiteUId); pb.BaseController.prototype.init.call(this, props, cb); diff --git a/plugins/pencilblue/controllers/admin/content/pages/page_form.js b/plugins/pencilblue/controllers/admin/content/pages/page_form.js index b01d141a8..ea73c150b 100755 --- a/plugins/pencilblue/controllers/admin/content/pages/page_form.js +++ b/plugins/pencilblue/controllers/admin/content/pages/page_form.js @@ -39,7 +39,7 @@ module.exports = function(pb) { } else { self.sitePrefix = pb.SiteService.getCurrentSitePrefix(self.pathSiteUId); - self.queryService = new pb.SiteQueryService(self.pathSiteUId); + self.queryService = new pb.SiteQueryService(self.pathSiteUId, true); var siteService = new pb.SiteService(); siteService.getSiteNameByUid(self.pathSiteUId, function (siteName) { self.siteName = siteName; diff --git a/plugins/pencilblue/controllers/admin/content/topics/import_topics.js b/plugins/pencilblue/controllers/admin/content/topics/import_topics.js index d21e80af8..981dcba5c 100755 --- a/plugins/pencilblue/controllers/admin/content/topics/import_topics.js +++ b/plugins/pencilblue/controllers/admin/content/topics/import_topics.js @@ -36,7 +36,7 @@ module.exports = function(pb) { } else { self.sitePrefix = pb.SiteService.getCurrentSitePrefix(self.pathSiteUId); - self.queryService = new pb.SiteQueryService(self.pathSiteUId); + self.queryService = new pb.SiteQueryService(self.pathSiteUId, true); var siteService = new pb.SiteService(); siteService.getSiteNameByUid(self.pathSiteUId, function (siteName) { self.siteName = siteName; diff --git a/plugins/pencilblue/controllers/admin/content/topics/manage_topics.js b/plugins/pencilblue/controllers/admin/content/topics/manage_topics.js index d2a98003c..d058427cd 100755 --- a/plugins/pencilblue/controllers/admin/content/topics/manage_topics.js +++ b/plugins/pencilblue/controllers/admin/content/topics/manage_topics.js @@ -36,7 +36,7 @@ module.exports = function(pb) { } else { self.sitePrefix = pb.SiteService.getCurrentSitePrefix(self.pathSiteUId); - self.queryService = new pb.SiteQueryService(self.pathSiteUId); + self.queryService = new pb.SiteQueryService(self.pathSiteUId, true); var siteService = new pb.SiteService(); siteService.getSiteNameByUid(self.pathSiteUId, function (siteName) { self.siteName = siteName; diff --git a/plugins/pencilblue/controllers/admin/content/topics/topic_form.js b/plugins/pencilblue/controllers/admin/content/topics/topic_form.js index 7601b2cb4..0f94f596e 100644 --- a/plugins/pencilblue/controllers/admin/content/topics/topic_form.js +++ b/plugins/pencilblue/controllers/admin/content/topics/topic_form.js @@ -39,7 +39,7 @@ module.exports = function(pb) { } else { self.sitePrefix = pb.SiteService.getCurrentSitePrefix(self.pathSiteUId); - self.queryService = new pb.SiteQueryService(self.pathSiteUId); + self.queryService = new pb.SiteQueryService(self.pathSiteUId, true); self.settings = pb.SettingServiceFactory.getServiceBySite(self.pathSiteUId, true); var siteService = new pb.SiteService(); siteService.getSiteNameByUid(self.pathSiteUId, function (siteName) { diff --git a/plugins/pencilblue/controllers/api/content/search.js b/plugins/pencilblue/controllers/api/content/search.js index d45721ec3..14411c449 100755 --- a/plugins/pencilblue/controllers/api/content/search.js +++ b/plugins/pencilblue/controllers/api/content/search.js @@ -60,13 +60,13 @@ module.exports = function(pb) { where: { $or: [ {headline: pattern}, - {subheading: pattern}, + {subheading: pattern} ] }, order: pb.DAO.NATURAL_ORDER, limit: MAX_RESULTS }; - var queryService = new pb.SiteQueryService(querySite); + var queryService = new pb.SiteQueryService(querySite, true); queryService.q(type, opts, function(err, items) { if (util.isError(err)) { var content = BaseController.apiResponse(BaseController.API_FAILURE, '', ''); From c9afd567a06b2754eb149a174a6acb57766fb34d Mon Sep 17 00:00:00 2001 From: btidwell Date: Fri, 15 May 2015 13:44:19 -0400 Subject: [PATCH 144/790] add init with site load on blog controller --- plugins/portfolio/controllers/blog.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/plugins/portfolio/controllers/blog.js b/plugins/portfolio/controllers/blog.js index be2abd1e7..6cf88e343 100755 --- a/plugins/portfolio/controllers/blog.js +++ b/plugins/portfolio/controllers/blog.js @@ -36,6 +36,22 @@ module.exports = function BlogModule(pb) { function Blog(){} util.inherits(Blog, pb.BaseController); + Blog.prototype.init = function(props, cb) { + var self = this; + pb.BaseController.prototype.init.call(self, props, function () { + var siteService = new pb.SiteService(); + siteService.getByUid(self.site, function(err, site) { + if (!site) { + self.reqHandler.serve404(); + } + else { + self.siteObj = site; + cb(); + } + }); + }); + }; + Blog.prototype.render = function(cb) { var self = this; From ab444b3018625d2f66c1686d068f56fa48d8c61f Mon Sep 17 00:00:00 2001 From: Eugene Chang Date: Fri, 15 May 2015 14:03:12 -0400 Subject: [PATCH 145/790] TemplateService site-awareness refactor; making portfolio landing page site aware --- controllers/base_controller.js | 2 +- include/service/entities/template_service.js | 46 ++++++++++++++------ include/system/settings.js | 7 ++- plugins/portfolio/controllers/index.js | 18 ++++++-- 4 files changed, 52 insertions(+), 21 deletions(-) diff --git a/controllers/base_controller.js b/controllers/base_controller.js index 4e0089814..73f57e347 100755 --- a/controllers/base_controller.js +++ b/controllers/base_controller.js @@ -105,7 +105,7 @@ module.exports = function BaseControllerModule(pb) { this.site = props.site; var self = this; - this.templateService = new pb.TemplateService(this.localizationService); + this.templateService = new pb.TemplateService(this.localizationService, this.site); this.templateService.registerLocal('locale', this.ls.language); this.templateService.registerLocal('error_success', function(flag, cb) { self.displayErrorOrSuccessCallback(flag, cb); diff --git a/include/service/entities/template_service.js b/include/service/entities/template_service.js index ff9cac473..c479c957d 100755 --- a/include/service/entities/template_service.js +++ b/include/service/entities/template_service.js @@ -37,8 +37,9 @@ module.exports = function(pb) { * @module Services * @submodule Entities * @param {Object} [localizationService] The localization service object + * @param {String} siteUid context site for this service */ - function TemplateService(localizationService){ + function TemplateService(localizationService, siteUid) { this.localCallbacks = { year: (new Date()).getFullYear() }; @@ -89,12 +90,17 @@ module.exports = function(pb) { * @type {Function} */ this.unregisteredFlagHandler = null; - + + this.siteUid = pb.SiteService.getCurrentSite(siteUid); + this.settingService = pb.SettingServiceFactory.getServiceBySite(this.siteUid); + /** * @property pluginService * @type {PluginService} */ - this.pluginService = new pb.PluginService(); + this.pluginService = new pb.PluginService(this.siteUid); + + this.init(); } //constants @@ -120,16 +126,7 @@ module.exports = function(pb) { var GLOBAL_CALLBACKS = { site_root: pb.config.siteRoot, site_name: pb.config.siteName, - site_logo: function(flag, callback) { - pb.settings.get('site_logo', function(err, logo) { - callback(null, logo ? logo : '/img/pb_logo.png'); - }); - }, site_menu_logo: '/img/logo_menu.png', - site_icon: function(flag, callback) { - var pluginService = new pb.PluginService(); - pluginService.getActiveIcon(callback); - }, version: pb.config.version }; @@ -142,6 +139,27 @@ module.exports = function(pb) { cb(null, '^'+flag+'^'); }; + /** + * Sets up the default flags required for the template service, + * including the flags that were previously considered to be global but + * now requires to be instanced with the TemplateService + * + * @method init + */ + TemplateService.prototype.init = function () { + var self = this; + + self.registerLocal('site_logo', function (err, callback) { + self.settingService.get('site_logo', function (err, logo) { + callback(err, logo || '/img/pb_logo.png'); + }); + }); + + self.registerLocal('site_icon', function (err, callback) { + self.pluginService.getActiveIcon(callback); + }); + }; + /** * Sets the prioritized theme to use when loading templates * @@ -233,7 +251,7 @@ module.exports = function(pb) { if (hintedTheme) { paths.push(TemplateService.getCustomPath(this.getTheme(), relativePath)); } - pb.settings.get('active_theme', function(err, activeTheme){ + self.settingService.get('active_theme', function(err, activeTheme){ if (activeTheme !== null) { paths.push(TemplateService.getCustomPath(activeTheme, relativePath)); } @@ -499,7 +517,7 @@ module.exports = function(pb) { TemplateService.prototype.getTemplatesForActiveTheme = function(cb) { var self = this; - pb.settings.get('active_theme', function(err, activeTheme) { + self.settingService.get('active_theme', function(err, activeTheme) { if(util.isError(err) || activeTheme == null) { cb(err, []); return; diff --git a/include/system/settings.js b/include/system/settings.js index 9072611f8..10552ecc1 100755 --- a/include/system/settings.js +++ b/include/system/settings.js @@ -42,10 +42,13 @@ module.exports = function SettingsModule(pb) { * @static * @method getServiceBySite * @param {String} site - * @param {Boolean} onlyThisSite + * @param {Boolean=} onlyThisSite */ SettingServiceFactory.getServiceBySite = function (site, onlyThisSite) { - return SettingServiceFactory.getService(pb.config.settings.use_memory, pb.config.settings.use_cache, site, onlyThisSite); + if (pb.config.multisite) { + return SettingServiceFactory.getService(pb.config.settings.use_memory, pb.config.settings.use_cache, site, onlyThisSite); + } + return SettingServiceFactory.getService(pb.config.settings.use_memory, pb.config.settings.use_cache); }; /** diff --git a/plugins/portfolio/controllers/index.js b/plugins/portfolio/controllers/index.js index 790998794..44347fffb 100755 --- a/plugins/portfolio/controllers/index.js +++ b/plugins/portfolio/controllers/index.js @@ -35,6 +35,16 @@ module.exports = function IndexModule(pb) { function Index() {} util.inherits(Index, pb.BaseController); + Index.prototype.init = function (props, cb) { + var self = this; + pb.BaseController.prototype.init.call(self, props, function () { + self.siteUId = pb.SiteService.getCurrentSite(self.site); + self.navService = new pb.SectionService(self.pathSiteUId); + self.queryService = new pb.SiteQueryService(self.siteUId); + cb(); + }); + }; + /** * This is the function that will be called by the system's RequestHandler. It * will map the incoming route to the ones below and then instantiate this @@ -55,12 +65,13 @@ module.exports = function IndexModule(pb) { }; var options = { - currUrl: this.req.url + currUrl: this.req.url, + site: self.site }; TopMenu.getTopMenu(self.session, self.ls, options, function(themeSettings, navigation, accountButtons) { TopMenu.getBootstrapNav(navigation, accountButtons, function(navigation, accountButtons) { - var pluginService = new pb.PluginService(); + var pluginService = new pb.PluginService(self.site); pluginService.getSettings('portfolio', function(err, portfolioSettings) { var homePageKeywords = ''; var homePageDescription = ''; @@ -95,8 +106,7 @@ module.exports = function IndexModule(pb) { var opts = { where: {settings_type: 'home_page'} }; - var dao = new pb.DAO(); - dao.q('portfolio_theme_settings', opts, function(err, settings) { + self.queryService.q('portfolio_theme_settings', opts, function(err, settings) { if (util.isError(err)) { self.reqHandler.serveError(err); } From 703f2cad3aa6fc15b40967a8a91c7292745e9509 Mon Sep 17 00:00:00 2001 From: Eugene Chang Date: Fri, 15 May 2015 15:38:51 -0400 Subject: [PATCH 146/790] loadById refactor to use SiteQueryService --- .../actions/admin/content/navigation/delete_nav_item.js | 5 ++--- .../actions/admin/content/navigation/edit_nav_item.js | 3 +-- .../controllers/admin/content/articles/article_form.js | 3 +-- .../pencilblue/controllers/admin/content/media/media_form.js | 4 ++-- .../controllers/admin/content/navigation/nav_item_form.js | 2 +- .../pencilblue/controllers/admin/content/pages/page_form.js | 3 +-- .../controllers/admin/content/topics/topic_form.js | 3 +-- 7 files changed, 9 insertions(+), 14 deletions(-) diff --git a/plugins/pencilblue/controllers/actions/admin/content/navigation/delete_nav_item.js b/plugins/pencilblue/controllers/actions/admin/content/navigation/delete_nav_item.js index 6164cf851..08eaa4bb9 100644 --- a/plugins/pencilblue/controllers/actions/admin/content/navigation/delete_nav_item.js +++ b/plugins/pencilblue/controllers/actions/admin/content/navigation/delete_nav_item.js @@ -63,8 +63,7 @@ module.exports = function(pb) { } //ensure existence - var dao = new pb.DAO(); - dao.loadById(vars.id, 'section', function(err, section) { + self.queryService.loadById(vars.id, 'section', function(err, section) { if(section === null) { cb({ code: 400, @@ -82,7 +81,7 @@ module.exports = function(pb) { } ] }; - dao.delete(where, 'section', function(err, result) { + self.queryService.delete(where, 'section', function(err, result) { if(util.isError(err) || result < 1) { return cb({ code: 500, diff --git a/plugins/pencilblue/controllers/actions/admin/content/navigation/edit_nav_item.js b/plugins/pencilblue/controllers/actions/admin/content/navigation/edit_nav_item.js index 0f72dfaaf..7c3a6b41c 100644 --- a/plugins/pencilblue/controllers/actions/admin/content/navigation/edit_nav_item.js +++ b/plugins/pencilblue/controllers/actions/admin/content/navigation/edit_nav_item.js @@ -52,7 +52,6 @@ module.exports = function(pb) { EditNavItem.prototype.render = function(cb){ var self = this; var vars = this.pathVars; - var dao = new pb.DAO(); var message = this.hasRequiredParams(vars, ['id']); if (message) { @@ -65,7 +64,7 @@ module.exports = function(pb) { this.getJSONPostParams(function(err, post) { //load object - dao.loadById(vars.id, 'section', function(err, navItem) { + self.queryService.loadById(vars.id, 'section', function(err, navItem) { if(util.isError(err) || !util.isObject(navItem)) { cb({ code: 400, diff --git a/plugins/pencilblue/controllers/admin/content/articles/article_form.js b/plugins/pencilblue/controllers/admin/content/articles/article_form.js index 4cd1dd23c..a4a2c531e 100755 --- a/plugins/pencilblue/controllers/admin/content/articles/article_form.js +++ b/plugins/pencilblue/controllers/admin/content/articles/article_form.js @@ -201,7 +201,6 @@ module.exports = function(pb) { ArticleForm.prototype.gatherData = function(vars, cb) { var self = this; - var dao = new pb.DAO(); var tasks = { templates: function(callback) { callback(null, pb.TemplateService.getAvailableContentTemplates()); @@ -239,7 +238,7 @@ module.exports = function(pb) { } //TODO call article service - dao.loadById(vars.id, 'article', callback); + self.queryService.loadById(vars.id, 'article', callback); } }; async.parallelLimit(tasks, 2, cb); diff --git a/plugins/pencilblue/controllers/admin/content/media/media_form.js b/plugins/pencilblue/controllers/admin/content/media/media_form.js index e07931623..5f8e5499f 100644 --- a/plugins/pencilblue/controllers/admin/content/media/media_form.js +++ b/plugins/pencilblue/controllers/admin/content/media/media_form.js @@ -37,6 +37,7 @@ module.exports = function(pb) { MediaForm.prototype.init = function (props, cb) { this.pathSiteUId = pb.SiteService.getCurrentSite(props.path_vars.siteid); this.sitePrefix = pb.SiteService.getCurrentSitePrefix(this.pathSiteUId); + this.queryService = new pb.SiteQueryService(this.pathSiteUId, true); pb.BaseController.prototype.init.call(this, props, cb); }; @@ -83,7 +84,6 @@ module.exports = function(pb) { MediaForm.prototype.gatherData = function(vars, cb) { var self = this; - var dao = new pb.DAO(); var tasks = { tabs: function(callback) { @@ -112,7 +112,7 @@ module.exports = function(pb) { where: pb.DAO.ANYWHERE, order: {name: pb.DAO.ASC} }; - dao.q('topic', opts, callback); + self.queryService.q('topic', opts, callback); }, media: function(callback) { diff --git a/plugins/pencilblue/controllers/admin/content/navigation/nav_item_form.js b/plugins/pencilblue/controllers/admin/content/navigation/nav_item_form.js index 85b213bdf..18bdb8d9c 100644 --- a/plugins/pencilblue/controllers/admin/content/navigation/nav_item_form.js +++ b/plugins/pencilblue/controllers/admin/content/navigation/nav_item_form.js @@ -151,7 +151,7 @@ module.exports = function(pb) { } self.queryService.loadById(vars.id, 'section', function(err, navItem) { - if(!navItem.item) { + if(!navItem || !navItem.item) { callback(err, navItem); return; } diff --git a/plugins/pencilblue/controllers/admin/content/pages/page_form.js b/plugins/pencilblue/controllers/admin/content/pages/page_form.js index ea73c150b..6d54accd4 100755 --- a/plugins/pencilblue/controllers/admin/content/pages/page_form.js +++ b/plugins/pencilblue/controllers/admin/content/pages/page_form.js @@ -202,7 +202,6 @@ module.exports = function(pb) { */ PageFormController.prototype.gatherData = function(vars, cb) { var self = this; - var dao = new pb.DAO(); var tasks = { templates: function(callback) { callback(null, pb.TemplateService.getAvailableContentTemplates()); @@ -239,7 +238,7 @@ module.exports = function(pb) { return; } - dao.loadById(vars.id, 'page', callback); + self.queryService.loadById(vars.id, 'page', callback); } }; async.parallelLimit(tasks, 2, cb); diff --git a/plugins/pencilblue/controllers/admin/content/topics/topic_form.js b/plugins/pencilblue/controllers/admin/content/topics/topic_form.js index 0f94f596e..b61270e10 100644 --- a/plugins/pencilblue/controllers/admin/content/topics/topic_form.js +++ b/plugins/pencilblue/controllers/admin/content/topics/topic_form.js @@ -108,8 +108,7 @@ module.exports = function(pb) { return; } - var dao = new pb.DAO(); - dao.loadById(vars.id, 'topic', function(err, topic) { + self.queryService.loadById(vars.id, 'topic', function(err, topic) { callback(err, topic); }); } From 94f964089e3b566ecbf77415ce302d75103c1c4f Mon Sep 17 00:00:00 2001 From: Eugene Chang Date: Fri, 15 May 2015 16:17:46 -0400 Subject: [PATCH 147/790] Site-aware site logo in manage themes --- .../actions/admin/themes/site_logo.js | 24 +++++++++++++++++-- .../angular/admin/themes/manage_themes.html | 2 +- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/plugins/pencilblue/controllers/actions/admin/themes/site_logo.js b/plugins/pencilblue/controllers/actions/admin/themes/site_logo.js index 6bda823cf..2f6feac0a 100755 --- a/plugins/pencilblue/controllers/actions/admin/themes/site_logo.js +++ b/plugins/pencilblue/controllers/actions/admin/themes/site_logo.js @@ -28,8 +28,28 @@ module.exports = function(pb) { function SiteLogo() {} util.inherits(SiteLogo, pb.BaseController); + SiteLogo.prototype.init = function (props, cb) { + var self = this; + pb.BaseController.prototype.init.call(self, props, function () { + self.pathSiteUId = pb.SiteService.getCurrentSite(self.pathVars.siteid); + pb.SiteService.siteExists(self.pathSiteUId, function (err, exists) { + if (!exists) { + self.reqHandler.serve404(); + } + else { + self.settings = pb.SettingServiceFactory.getServiceBySite(self.pathSiteUId, true); + var siteService = new pb.SiteService(); + siteService.getSiteNameByUid(self.pathSiteUId, function (siteName) { + self.siteName = siteName; + cb(); + }); + } + }); + }); + }; + SiteLogo.prototype.render = function(cb) { - self = this; + var self = this; this.getJSONPostParams(function(err, post) { if (!pb.validation.validateNonEmptyStr(post.site_logo, true)) { @@ -40,7 +60,7 @@ module.exports = function(pb) { return; } - pb.settings.set('site_logo', post.site_logo, function(err, result) { + self.settings.set('site_logo', post.site_logo, function(err, result) { if (util.isError(err)) { cb({ code: 500, diff --git a/plugins/pencilblue/templates/angular/admin/themes/manage_themes.html b/plugins/pencilblue/templates/angular/admin/themes/manage_themes.html index 0366a9db4..473309240 100644 --- a/plugins/pencilblue/templates/angular/admin/themes/manage_themes.html +++ b/plugins/pencilblue/templates/angular/admin/themes/manage_themes.html @@ -54,7 +54,7 @@ } $scope.saveSiteLogo = function() { - $http.post('/actions/admin/themes/site_logo', {site_logo: $scope.photoValue}) + $http.post('/actions/admin' + $scope.sitePrefix + '/themes/site_logo', {site_logo: $scope.photoValue}) .success(function(result) { $scope.successMessage = result.message; $scope.saving = false; From 211652fa95c6d370ace08374797ab79efcc0ac19 Mon Sep 17 00:00:00 2001 From: Christina Chatham Date: Fri, 15 May 2015 16:42:57 -0400 Subject: [PATCH 148/790] Add init handling for site id. --- .../controllers/admin/site_settings/email.js | 62 ++++++++++++------- 1 file changed, 39 insertions(+), 23 deletions(-) diff --git a/plugins/pencilblue/controllers/admin/site_settings/email.js b/plugins/pencilblue/controllers/admin/site_settings/email.js index f39204a23..5f5a37070 100755 --- a/plugins/pencilblue/controllers/admin/site_settings/email.js +++ b/plugins/pencilblue/controllers/admin/site_settings/email.js @@ -36,29 +36,31 @@ module.exports = function(pb) { * @method render * */ - Email.prototype.render = function(cb) { + Email.prototype.init = function(props, cb) { var self = this; - var site = pb.SiteService.getCurrentSite(self.pathVars.siteid); - pb.SiteService.siteExists(site, function (err, siteExists) { - if (siteExists) { - self.onSiteValidated(site, cb); - } - else { - self.reqHandler.serve404(); - return; - } + pb.BaseController.prototype.init.call(this, props, function() { + self.pathSiteUId = SiteService.getCurrentSite(self.pathVars.siteid); + SiteService.siteExists(self.pathSiteUId, function (err, exists) { + if (!exists) { + self.reqHandler.serve404(); + } + else { + self.sitePrefix = SiteService.getCurrentSitePrefix(self.pathSiteUId); + cb(); + } + }); }); }; /** * - * @method onSiteValidated + * @method render * @param site * @param cb * */ - Email.prototype.onSiteValidated = function onSiteValidated(site, cb) { + Email.prototype.render = function(cb) { var self = this; var tabs = [ @@ -82,13 +84,12 @@ module.exports = function(pb) { var emailService = new pb.EmailService(self.pathVars.siteid); emailService.getSettings(function(err, emailSettings) { - var sitePrefix = SiteService.getCurrentSitePrefix(SiteService.getCurrentSite(self.pathVars.siteid)); var angularObjects = pb.ClientJs.getAngularObjects({ navigation: pb.AdminNavigation.get(self.session, ['settings', 'site_settings'], self.ls), - pills: pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, 'email', { sitePrefix: sitePrefix }), + pills: pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, 'email', { sitePrefix: self.sitePrefix }), tabs: tabs, emailSettings: emailSettings, - sitePrefix: sitePrefix + sitePrefix: self.sitePrefix }); self.setPageName(self.ls.get('EMAIL')); @@ -100,22 +101,37 @@ module.exports = function(pb) { }; Email.getSubNavItems = function(key, ls, data) { - return [{ + var prefix = '/admin'; + if(data && data.sitePrefix) { + prefix += data.sitePrefix; + } + + var pills = [{ name: 'configuration', title: ls.get('EMAIL'), icon: 'chevron-left', - href: '/admin' + data.sitePrefix + '/site_settings' + href: prefix + '/site_settings' }, { name: 'content', title: ls.get('CONTENT'), icon: 'quote-right', - href: '/admin' + data.sitePrefix + '/site_settings/content' - }, { - name: 'libraries', - title: ls.get('LIBRARIES'), - icon: 'book', - href: '/admin' + data.sitePrefix + '/site_settings/libraries' + href: prefix + '/site_settings/content' }]; + + if(data && data.site === SiteService.GLOBAL_SITE) { + pills.push({ + name: 'libraries', + title: ls.get('LIBRARIES'), + icon: 'book', + href: prefix + '/site_settings/libraries' + }); + } + + if(data && data.siteName) { + return pb.AdminSubnavService.addSiteToPills(pills, data.siteName); + } + + return pills; }; //register admin sub-nav From d21491ee014a0f48a423b584dc668cbff2564a7a Mon Sep 17 00:00:00 2001 From: Eugene Chang Date: Mon, 18 May 2015 09:20:48 -0400 Subject: [PATCH 149/790] Refactoring MediaService to be site aware and removing unnecessary addition of methods --- include/service/entities/media_service.js | 47 ++++++------------- .../admin/content/articles/article_form.js | 4 +- .../admin/content/pages/page_form.js | 4 +- 3 files changed, 19 insertions(+), 36 deletions(-) diff --git a/include/service/entities/media_service.js b/include/service/entities/media_service.js index 16c56dfec..814ad729f 100755 --- a/include/service/entities/media_service.js +++ b/include/service/entities/media_service.js @@ -31,9 +31,14 @@ module.exports = function MediaServiceModule(pb) { * @submodule Entities * @class MediaService * @constructor - */ - function MediaService(provider, site){ - this.site = site; + * @param provider + * @param site Site uid to be used for this service + * @param onlyThisSite Whether this service should only return media associated with specified site + * or fallback to global if not found in specified site + */ + function MediaService(provider, site, onlyThisSite) { + this.site = pb.SiteService.getCurrentSite(site); + this.queryService = new pb.SiteQueryService(site, onlyThisSite); if (util.isNullOrUndefined(provider)) { provider = MediaService.loadMediaProvider(); } @@ -96,8 +101,7 @@ module.exports = function MediaServiceModule(pb) { * occurred and a media descriptor if found. */ MediaService.prototype.loadById = function(mid, cb) { - var dao = new pb.DAO(); - dao.loadById(mid.toString(), MediaService.COLL, cb); + this.queryService.loadById(mid.toString(), MediaService.COLL, cb); }; /** @@ -114,8 +118,7 @@ module.exports = function MediaServiceModule(pb) { } var self = this; - var dao = new pb.DAO(); - dao.deleteById(mid, MediaService.COLL, cb); + this.queryService.deleteById(mid, MediaService.COLL, cb); }; /** @@ -140,8 +143,7 @@ module.exports = function MediaServiceModule(pb) { return cb(null, validationErrors); } - var dao = new pb.DAO(); - dao.save(media, cb); + this.queryService.save(media, cb); }); }; @@ -161,9 +163,8 @@ module.exports = function MediaServiceModule(pb) { } //ensure the media name is unique - var where = { name: media.name, site: this.site }; - var dao = new pb.DAO(); - dao.unique(MediaService.COLL, where, media[pb.DAO.getIdField()], function(err, isUnique) { + var where = { name: media.name }; + this.queryService.unique(MediaService.COLL, where, media[pb.DAO.getIdField()], function(err, isUnique) { if(util.isError(err)) { return cb(err, errors); } @@ -196,8 +197,7 @@ module.exports = function MediaServiceModule(pb) { }; } - var dao = new pb.DAO(); - dao.q('media', options, function(err, media) { + this.queryService.q('media', options, function (err, media) { if (util.isError(err)) { return cb(err, []); } @@ -210,22 +210,6 @@ module.exports = function MediaServiceModule(pb) { }); }; - /** - * Queries for media descriptors by site - * @method getBySite - * @param {String} site - * @param {Function} cb - */ - - MediaService.prototype.getBySite = function(site, cb) { - var options = { - format_media: true, - where: {site: site}, - order: {name:1} - }; - this.get(options, cb); - }; - /** * * @method getContentByPath @@ -487,8 +471,7 @@ module.exports = function MediaServiceModule(pb) { MediaService.prototype.renderById = function(id, options, cb) { var self = this; - var dao = new pb.DAO(); - dao.loadById(id, MediaService.COLL, function(err, media) { + self.queryService.loadById(id, MediaService.COLL, function (err, media) { if (util.isError(err)) { return cb(err); } diff --git a/plugins/pencilblue/controllers/admin/content/articles/article_form.js b/plugins/pencilblue/controllers/admin/content/articles/article_form.js index a4a2c531e..fc7b28ec0 100755 --- a/plugins/pencilblue/controllers/admin/content/articles/article_form.js +++ b/plugins/pencilblue/controllers/admin/content/articles/article_form.js @@ -227,8 +227,8 @@ module.exports = function(pb) { }, media: function(callback) { - var mservice = new pb.MediaService(); - mservice.getBySite(vars.siteid, callback); + var mservice = new pb.MediaService(null, vars.siteid, true); + mservice.get(callback); }, article: function(callback) { diff --git a/plugins/pencilblue/controllers/admin/content/pages/page_form.js b/plugins/pencilblue/controllers/admin/content/pages/page_form.js index 6d54accd4..13967b351 100755 --- a/plugins/pencilblue/controllers/admin/content/pages/page_form.js +++ b/plugins/pencilblue/controllers/admin/content/pages/page_form.js @@ -228,8 +228,8 @@ module.exports = function(pb) { }, media: function(callback) { - var mservice = new pb.MediaService(); - mservice.getBySite(vars.siteid, callback); + var mservice = new pb.MediaService(null, vars.siteid, true); + mservice.get(callback); }, page: function(callback) { From a506d02a556eba298026aaad316e92bb7b95e4d0 Mon Sep 17 00:00:00 2001 From: Eugene Chang Date: Mon, 18 May 2015 09:29:41 -0400 Subject: [PATCH 150/790] Refactoring ManageMedia to use site aware Media Service --- include/service/entities/media_service.js | 4 ++-- .../controllers/admin/content/media/manage_media.js | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/include/service/entities/media_service.js b/include/service/entities/media_service.js index 814ad729f..3f87d9422 100755 --- a/include/service/entities/media_service.js +++ b/include/service/entities/media_service.js @@ -135,7 +135,7 @@ module.exports = function MediaServiceModule(pb) { } var self = this; - this.validate(media, function(err, validationErrors) { + self.validate(media, function(err, validationErrors) { if (util.isError(err)) { return cb(err); } @@ -143,7 +143,7 @@ module.exports = function MediaServiceModule(pb) { return cb(null, validationErrors); } - this.queryService.save(media, cb); + self.queryService.save(media, cb); }); }; diff --git a/plugins/pencilblue/controllers/admin/content/media/manage_media.js b/plugins/pencilblue/controllers/admin/content/media/manage_media.js index 05cda2f24..a2c06856e 100755 --- a/plugins/pencilblue/controllers/admin/content/media/manage_media.js +++ b/plugins/pencilblue/controllers/admin/content/media/manage_media.js @@ -32,6 +32,7 @@ module.exports = function(pb) { ManageMedia.prototype.init = function (props, cb) { this.pathSiteUId = pb.SiteService.getCurrentSite(props.path_vars.siteid); this.sitePrefix = pb.SiteService.getCurrentSitePrefix(this.pathSiteUId); + this.mediaService = new pb.MediaService(null, this.pathSiteUId, true); pb.BaseController.prototype.init.call(this, props, cb); }; @@ -46,12 +47,10 @@ module.exports = function(pb) { media_type: 1, location: 1 }, - where : {site: self.pathSiteUId}, order: {created: pb.DAO.DESC}, format_media: true }; - var mservice = new pb.MediaService(); - mservice.get(options, function(err, mediaData) { + self.mediaService.get(options, function(err, mediaData) { if(util.isError(mediaData) || mediaData.length === 0) { self.redirect('/admin' + self.sitePrefix + '/content/media/new', cb); return; From 4eb5cf2ab8031c145baeac6b14f553934b76d4f3 Mon Sep 17 00:00:00 2001 From: Eugene Chang Date: Mon, 18 May 2015 09:53:31 -0400 Subject: [PATCH 151/790] Refactoring media preview --- .../controllers/admin/content/media/media_form.js | 5 ++--- .../api/admin/content/media/get_preview.js | 15 ++++++++++++--- .../angular/admin/content/media/media_form.html | 2 +- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/plugins/pencilblue/controllers/admin/content/media/media_form.js b/plugins/pencilblue/controllers/admin/content/media/media_form.js index 5f8e5499f..a461b47e8 100644 --- a/plugins/pencilblue/controllers/admin/content/media/media_form.js +++ b/plugins/pencilblue/controllers/admin/content/media/media_form.js @@ -38,6 +38,7 @@ module.exports = function(pb) { this.pathSiteUId = pb.SiteService.getCurrentSite(props.path_vars.siteid); this.sitePrefix = pb.SiteService.getCurrentSitePrefix(this.pathSiteUId); this.queryService = new pb.SiteQueryService(this.pathSiteUId, true); + this.mediaService = new pb.MediaService(null, this.pathSiteUId, true); pb.BaseController.prototype.init.call(this, props, cb); }; @@ -69,7 +70,6 @@ module.exports = function(pb) { }); }); }); - return; }; MediaForm.prototype.getAngularObjects = function(data, cb) { @@ -123,8 +123,7 @@ module.exports = function(pb) { }); } - var mservice = new pb.MediaService(); - mservice.loadById(vars.id, callback); + self.mediaService.loadById(vars.id, callback); } }; async.series(tasks, cb); diff --git a/plugins/pencilblue/controllers/api/admin/content/media/get_preview.js b/plugins/pencilblue/controllers/api/admin/content/media/get_preview.js index 2fff959e3..4b69d3ebf 100644 --- a/plugins/pencilblue/controllers/api/admin/content/media/get_preview.js +++ b/plugins/pencilblue/controllers/api/admin/content/media/get_preview.js @@ -29,6 +29,16 @@ module.exports = function(pb) { function GetMediaPreviewApiController(){} util.inherits(GetMediaPreviewApiController, pb.BaseController); + GetMediaPreviewApiController.prototype.init = function (props, cb) { + var self = this; + pb.BaseController.prototype.init.call(self, props, function () { + self.pathSiteUId = pb.SiteService.getCurrentSite(self.pathVars.siteid); + self.sitePrefix = pb.SiteService.getCurrentSitePrefix(self.pathSiteUId); + self.mediaService = new pb.MediaService(null, self.pathSiteUId, true); + cb(); + }); + }; + /** * Renders the preview * @method render @@ -50,9 +60,8 @@ module.exports = function(pb) { var options = { view: 'view' }; - var ms = new pb.MediaService(); if (get.id) { - ms.renderById(get.id, options, function(err, html) { + self.mediaService.renderById(get.id, options, function(err, html) { self.renderComplete(err, html, cb); }); } @@ -63,7 +72,7 @@ module.exports = function(pb) { location: get.location, type: get.type }; - ms.renderByLocation(options, function(err, html) { + self.mediaService.renderByLocation(options, function(err, html) { self.renderComplete(err, html, cb); }); } diff --git a/plugins/pencilblue/templates/angular/admin/content/media/media_form.html b/plugins/pencilblue/templates/angular/admin/content/media/media_form.html index 6b18cdcae..efc8ff934 100644 --- a/plugins/pencilblue/templates/angular/admin/content/media/media_form.html +++ b/plugins/pencilblue/templates/angular/admin/content/media/media_form.html @@ -104,7 +104,7 @@ $scope.getMediaPreview = function() { $scope.mediaPreview = ''; - $http.get('/api/admin/content/media/get_preview?id=' + $scope.media._id) + $http.get('/api/admin' + $scope.sitePrefix + '/content/media/get_preview?id=' + $scope.media._id) .success(function(result) { $scope.mediaPreview = result.data; }) From b9430052e5ccfb52cfdb0d1f561f63fbc508735b Mon Sep 17 00:00:00 2001 From: Andrew Monroe Date: Mon, 18 May 2015 14:05:29 -0400 Subject: [PATCH 152/790] fix bug in loading plugin settings --- include/service/db_entity_service.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/service/db_entity_service.js b/include/service/db_entity_service.js index 5f57ab356..cd5667aa5 100755 --- a/include/service/db_entity_service.js +++ b/include/service/db_entity_service.js @@ -72,9 +72,9 @@ module.exports = function DbEntityServiceModule(pb) { cb(null, val); }; if(this.onlyThisSite) { - dao.loadByValueForOneSite(this.keyField, key, this.site, this.objType, callback); + dao.loadByValueForOneSite(this.keyField, key, this.site, this.objType, null, callback); } else { - dao.loadByValueAvailableToSite(this.keyField, key, this.site, this.objType, callback); + dao.loadByValueAvailableToSite(this.keyField, key, this.site, this.objType, null, callback); } }; From ccf9df44a5f3ad534cda1214742c5c79d43a0e20 Mon Sep 17 00:00:00 2001 From: andparker Date: Mon, 18 May 2015 15:54:28 -0400 Subject: [PATCH 153/790] Makes content settings and its callers site aware | Makes article service site aware --- include/admin_navigation.js | 2 +- include/content.js | 2 +- include/service/entities/article_service.js | 9 +++-- include/theme/top_menu.js | 13 +++++-- .../actions/admin/site_settings/content.js | 19 +++++++++- .../controllers/actions/user/sign_up.js | 4 +- .../admin/site_settings/content.js | 37 ++++++++++++++++--- .../controllers/api/content/get_articles.js | 6 +-- plugins/pencilblue/controllers/feed.js | 2 +- plugins/pencilblue/controllers/index.js | 4 +- .../controllers/user/resend_verification.js | 2 +- .../pencilblue/controllers/user/sign_up.js | 2 +- .../controllers/user/verification_sent.js | 2 +- .../angular/admin/site_settings/content.html | 2 +- 14 files changed, 78 insertions(+), 28 deletions(-) diff --git a/include/admin_navigation.js b/include/admin_navigation.js index 04075b8ea..31236da8e 100755 --- a/include/admin_navigation.js +++ b/include/admin_navigation.js @@ -205,7 +205,7 @@ module.exports = function AdminNavigationModule(pb) { id: 'content_settings', title: 'CONTENT', icon: 'quote-right', - href: '/admin/site_settings/content', + href: adminPath + '/site_settings/content', access: SecurityService.ACCESS_MANAGING_EDITOR }, { diff --git a/include/content.js b/include/content.js index 598ac275f..0e3c1a3b8 100755 --- a/include/content.js +++ b/include/content.js @@ -113,7 +113,7 @@ module.exports = function ContentServiceModule(pb) { twoDigitDate: contentSettings.two_digit_date, displayTime: contentSettings.display_hours_minutes, timeFormat: contentSettings.time_format, - twoDigitDate: contentSettings.two_digit_time, + twoDigitTime: contentSettings.two_digit_time, ls: ls }; return ContentService.getTimestampText(options); diff --git a/include/service/entities/article_service.js b/include/service/entities/article_service.js index f4732203a..ca04beca8 100755 --- a/include/service/entities/article_service.js +++ b/include/service/entities/article_service.js @@ -33,8 +33,10 @@ module.exports = function ArticleServiceModule(pb) { * @constructor * */ - function ArticleService(){ + function ArticleService(siteUid, onlyThisSite){ this.object_type = 'article'; + this.site = pb.SiteService.getCurrentSite(siteUid); + this.siteQueryService = new pb.SiteQueryService(this.site, onlyThisSite); } /** @@ -161,8 +163,7 @@ module.exports = function ArticleServiceModule(pb) { } var self = this; - var dao = new pb.DAO(); - dao.q(this.getContentType(), {where: where, select: select, order: order, limit: limit, offset: offset}, function(err, articles) { + self.siteQueryService.q(this.getContentType(), {where: where, select: select, order: order, limit: limit, offset: offset}, function(err, articles) { if (util.isError(err)) { return cb(err, []); } @@ -173,7 +174,7 @@ module.exports = function ArticleServiceModule(pb) { //get authors self.getArticleAuthors(articles, function(err, authors) { - var contentService = new pb.ContentService(); + var contentService = new pb.ContentService(self.site); contentService.getSettings(function(err, contentSettings) { var tasks = util.getTasks(articles, function(articles, i) { diff --git a/include/theme/top_menu.js b/include/theme/top_menu.js index af193abe9..06b045170 100755 --- a/include/theme/top_menu.js +++ b/include/theme/top_menu.js @@ -79,7 +79,7 @@ module.exports = function TopMenuServiceModule(pb) { }, accountButtons: function(callback) { - TopMenuService.getAccountButtons(session, localizationService, callback); + TopMenuService.getAccountButtons(session, localizationService, options.site, callback); } }; async.parallel(tasks, function(err, result) { @@ -95,10 +95,17 @@ module.exports = function TopMenuServiceModule(pb) { * @method getAccountButtons * @param {Object} session * @param {Object} ls The localization service + * @param {String} site The current site * @param {Function} cb Callback function */ - TopMenuService.getAccountButtons = function(session, ls, cb) { - var contentService = new pb.ContentService(); + TopMenuService.getAccountButtons = function(session, ls, site, cb) { + + if (util.isFunction(site)) { + cb = site; + site = pb.siteService.GLOBAL_SITE; + } + + var contentService = new pb.ContentService(site); contentService.getSettings(function(err, contentSettings) { if (util.isError(err)) { return cb(err); diff --git a/plugins/pencilblue/controllers/actions/admin/site_settings/content.js b/plugins/pencilblue/controllers/actions/admin/site_settings/content.js index 059de9c47..640349513 100755 --- a/plugins/pencilblue/controllers/actions/admin/site_settings/content.js +++ b/plugins/pencilblue/controllers/actions/admin/site_settings/content.js @@ -26,6 +26,23 @@ module.exports = function(pb) { function Content(){} util.inherits(Content, pb.BaseController); + Content.prototype.init = function (props, cb) { + var self = this; + + pb.BaseController.prototype.init.call(self, props, function() { + self.pathSiteUid = pb.SiteService.getCurrentSite(self.pathVars.siteid); + pb.SiteService.siteExists(self.pathSiteUid, function (err, exists) { + if (!exists) { + self.reqHandler.serve404(); + } + else { + self.settings = pb.SettingServiceFactory.getServiceBySite(self.pathSiteUid, true); + cb(); + } + }); + }); + }; + Content.prototype.render = function(cb) { var self = this; @@ -39,7 +56,7 @@ module.exports = function(pb) { return; } - pb.settings.set('content_settings', post, function(data) { + self.settings.set('content_settings', post, function(data) { if(util.isError(data)) { cb({ code: 500, diff --git a/plugins/pencilblue/controllers/actions/user/sign_up.js b/plugins/pencilblue/controllers/actions/user/sign_up.js index a45b219b7..b84c85411 100755 --- a/plugins/pencilblue/controllers/actions/user/sign_up.js +++ b/plugins/pencilblue/controllers/actions/user/sign_up.js @@ -48,7 +48,7 @@ module.exports = function SignUpModule(pb) { return; } - var contentService = new pb.ContentService(); + var contentService = new pb.ContentService(self.site); contentService.getSettings(function(err, contentSettings) { //TODO handle error @@ -120,7 +120,7 @@ module.exports = function SignUpModule(pb) { }, unverified_email: function(callback) { dao.count('unverified_user', {email: user.email}, callback); - }, + } }; async.series(tasks, cb); }; diff --git a/plugins/pencilblue/controllers/admin/site_settings/content.js b/plugins/pencilblue/controllers/admin/site_settings/content.js index dfef90773..d9a405345 100755 --- a/plugins/pencilblue/controllers/admin/site_settings/content.js +++ b/plugins/pencilblue/controllers/admin/site_settings/content.js @@ -29,6 +29,27 @@ module.exports = function(pb) { //statics var SUB_NAV_KEY = 'content_settings'; + Content.prototype.init = function (props, cb) { + var self = this; + + pb.BaseController.prototype.init.call(self, props, function() { + self.pathSiteUid = pb.SiteService.getCurrentSite(self.pathVars.siteid); + pb.SiteService.siteExists(self.pathSiteUid, function (err, exists) { + if (!exists) { + self.reqHandler.serve404(); + } + else { + self.pathSitePrefix = pb.SiteService.getCurrentSitePrefix(self.pathSiteUid); + var siteService = new pb.SiteService(); + siteService.getSiteNameByUid(self.pathSiteUid, function (siteName) { + self.siteName = siteName; + cb(); + }); + } + }); + }); + }; + Content.prototype.render = function(cb) { var self = this; @@ -57,13 +78,17 @@ module.exports = function(pb) { } ]; - var contentService = new pb.ContentService(); + var contentService = new pb.ContentService(this.pathSiteUid, true); + var pills = pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, 'content', { pathSitePrefix: self.pathSitePrefix }); + pills = pb.AdminSubnavService.addSiteToPills(pills, this.siteName); + contentService.getSettings(function(err, contentSettings) { var angularObjects = pb.ClientJs.getAngularObjects({ navigation: pb.AdminNavigation.get(self.session, ['settings', 'site_settings'], self.ls), - pills: pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, 'content'), + pills: pills, tabs: tabs, - contentSettings: contentSettings + contentSettings: contentSettings, + pathSitePrefix: self.pathSitePrefix }); self.setPageName(self.ls.get('CONTENT')); @@ -79,17 +104,17 @@ module.exports = function(pb) { name: 'configuration', title: ls.get('CONTENT'), icon: 'chevron-left', - href: '/admin/site_settings' + href: '/admin' + data.pathSitePrefix + '/site_settings' }, { name: 'email', title: ls.get('EMAIL'), icon: 'envelope', - href: '/admin/site_settings/email' + href: '/admin' + data.pathSitePrefix + '/site_settings/email' }, { name: 'libraries', title: ls.get('LIBRARIES'), icon: 'book', - href: '/admin/site_settings/libraries' + href: '/admin' + data.pathSitePrefix + '/site_settings/libraries' }]; }; diff --git a/plugins/pencilblue/controllers/api/content/get_articles.js b/plugins/pencilblue/controllers/api/content/get_articles.js index 3d3092413..e1ea5f028 100755 --- a/plugins/pencilblue/controllers/api/content/get_articles.js +++ b/plugins/pencilblue/controllers/api/content/get_articles.js @@ -38,7 +38,7 @@ module.exports = function(pb) { var self = this; var get = this.query; - var contentService = new pb.ContentService(); + var contentService = new pb.ContentService(self.site); contentService.getSettings(function(err, contentSettings) { if(!get.limit || get.limit.length === 0) @@ -58,7 +58,7 @@ module.exports = function(pb) { self.processArticles(articles, cb); }; - var service = new ArticleService(); + var service = new ArticleService(self.site, true); if(get.section) { service.findBySection(get.section, articleCallback); @@ -75,7 +75,7 @@ module.exports = function(pb) { GetArticles.prototype.processArticles = function(articles, cb) { var self = this; - var contentService = new pb.ContentService(); + var contentService = new pb.ContentService(self.site); contentService.getSettings(function(err, contentSettings) { var cnt = 0; diff --git a/plugins/pencilblue/controllers/feed.js b/plugins/pencilblue/controllers/feed.js index e2edea40f..8666db4ca 100755 --- a/plugins/pencilblue/controllers/feed.js +++ b/plugins/pencilblue/controllers/feed.js @@ -61,7 +61,7 @@ module.exports = function FeedModule(pb) { self.getMedia(articles, function(err, articlesWithMedia) { articles = articlesWithMedia; - var contentService = new pb.ContentService(); + var contentService = new pb.ContentService(self.site); contentService.getSettings(function(err, contentSettings) { var tasks = util.getTasks(articles, function(articles, i) { diff --git a/plugins/pencilblue/controllers/index.js b/plugins/pencilblue/controllers/index.js index 7a8bd0aa9..97dfb5f66 100755 --- a/plugins/pencilblue/controllers/index.js +++ b/plugins/pencilblue/controllers/index.js @@ -42,7 +42,7 @@ module.exports = function IndexModule(pb) { var article = self.req.pencilblue_article || null; var page = self.req.pencilblue_page || null; - var contentService = new pb.ContentService(); + var contentService = new pb.ContentService(self.site); contentService.getSettings(function(err, contentSettings) { self.gatherData(function(err, data) { ArticleService.getMetaInfo(data.content[0], function(metaKeywords, metaDescription, metaTitle, metaThumbnail) { @@ -220,7 +220,7 @@ module.exports = function IndexModule(pb) { var article = this.req.pencilblue_article || null; var page = this.req.pencilblue_page || null; - var service = new ArticleService(); + var service = new ArticleService(this.site, true); if(this.req.pencilblue_preview) { if(this.req.pencilblue_preview == page || article) { if(page) { diff --git a/plugins/pencilblue/controllers/user/resend_verification.js b/plugins/pencilblue/controllers/user/resend_verification.js index ae812e2c4..335b5742d 100755 --- a/plugins/pencilblue/controllers/user/resend_verification.js +++ b/plugins/pencilblue/controllers/user/resend_verification.js @@ -29,7 +29,7 @@ module.exports = function ResendVerificationModule(pb) { ResendVerification.prototype.render = function(cb) { var self = this; - var contentService = new pb.ContentService(); + var contentService = new pb.ContentService(self.site); contentService.getSettings(function(err, contentSettings) { if(!contentSettings.allow_comments || !contentSettings.require_verification) { diff --git a/plugins/pencilblue/controllers/user/sign_up.js b/plugins/pencilblue/controllers/user/sign_up.js index 32cdff6a3..d49edde3f 100755 --- a/plugins/pencilblue/controllers/user/sign_up.js +++ b/plugins/pencilblue/controllers/user/sign_up.js @@ -29,7 +29,7 @@ module.exports = function SignUpModule(pb) { SignUp.prototype.render = function(cb) { var self = this; - var contentService = new pb.ContentService(); + var contentService = new pb.ContentService(self.site); contentService.getSettings(function(err, contentSettings) { if(!contentSettings.allow_comments) { self.redirect('/', cb); diff --git a/plugins/pencilblue/controllers/user/verification_sent.js b/plugins/pencilblue/controllers/user/verification_sent.js index a288c006f..f23e4d5e9 100755 --- a/plugins/pencilblue/controllers/user/verification_sent.js +++ b/plugins/pencilblue/controllers/user/verification_sent.js @@ -29,7 +29,7 @@ module.exports = function VerificationSentModule(pb) { VerificationSent.prototype.render = function(cb) { var self = this; - var contentService = new pb.ContentService(); + var contentService = new pb.ContentService(self.site); contentService.getSettings(function(err, contentSettings) { if(!contentSettings.allow_comments || !contentSettings.require_verification) { self.redirect('/', cb); diff --git a/plugins/pencilblue/templates/angular/admin/site_settings/content.html b/plugins/pencilblue/templates/angular/admin/site_settings/content.html index a2bddab7b..4b8a73b9e 100644 --- a/plugins/pencilblue/templates/angular/admin/site_settings/content.html +++ b/plugins/pencilblue/templates/angular/admin/site_settings/content.html @@ -18,7 +18,7 @@ $scope.saving = true; - $http.post('/actions/admin/site_settings/content', $scope.contentSettings) + $http.post('/actions/admin' + $scope.pathSitePrefix + '/site_settings/content', $scope.contentSettings) .success(function(result) { $scope.successMessage = result.message; $scope.saving = false; From ebd6f3b0efa4cbcab9aeda8bf6d8769249c60d7b Mon Sep 17 00:00:00 2001 From: Eugene Chang Date: Mon, 18 May 2015 16:23:33 -0400 Subject: [PATCH 154/790] BaseAdminController refactor --- controllers/base_admin_controller.js | 58 +++++++++++++++++++ include/requirements.js | 1 + include/service/entities/media_service.js | 17 +++--- include/service/entities/section_service.js | 29 +++++----- include/service/entities/site_service.js | 9 +++ .../actions/admin/content/media/edit_media.js | 12 +--- .../actions/admin/content/media/new_media.js | 10 +--- .../content/navigation/delete_nav_item.js | 29 +--------- .../admin/content/navigation/edit_nav_item.js | 33 ++--------- .../admin/content/navigation/new_nav_item.js | 29 +--------- .../admin/content/objects/delete_object.js | 20 +------ .../admin/content/objects/edit_object.js | 20 +------ .../admin/content/objects/new_object.js | 20 +------ .../admin/content/objects/sort_objects.js | 16 +---- .../content/objects/types/delete_type.js | 16 +---- .../admin/content/objects/types/edit_type.js | 20 +------ .../admin/content/objects/types/new_type.js | 20 +------ .../admin/content/topics/edit_topic.js | 30 ++-------- .../admin/content/topics/import_topics.js | 28 +-------- .../actions/admin/content/topics/new_topic.js | 27 +-------- .../actions/admin/themes/site_logo.js | 25 +------- .../admin/content/articles/article_form.js | 29 ++-------- .../admin/content/articles/manage_articles.js | 12 +--- .../admin/content/comments/manage_comments.js | 30 ++-------- .../admin/content/media/manage_media.js | 15 ++--- .../admin/content/media/media_form.js | 18 ++---- .../admin/content/navigation/nav_item_form.js | 31 ++-------- .../admin/content/navigation/nav_map.js | 27 +-------- .../admin/content/objects/manage_objects.js | 25 +------- .../admin/content/objects/object_form.js | 28 +-------- .../admin/content/objects/sort_objects.js | 25 +------- .../content/objects/types/manage_types.js | 25 +------- .../admin/content/objects/types/type_form.js | 25 +------- .../admin/content/pages/manage_pages.js | 12 +--- .../admin/content/pages/page_form.js | 29 ++-------- .../admin/content/topics/import_topics.js | 23 +------- .../admin/content/topics/manage_topics.js | 25 +------- .../admin/content/topics/topic_form.js | 26 +-------- .../admin/plugins/plugin_settings.js | 18 +++--- .../admin/site_settings/configuration.js | 22 +------ .../admin/site_settings/libraries.js | 11 +--- .../api/admin/content/media/get_preview.js | 19 ++---- .../admin/content/objects/types/available.js | 16 +---- .../controllers/api/comments/new_comment.js | 11 +--- plugins/pencilblue/controllers/section.js | 8 +-- plugins/portfolio/controllers/index.js | 8 +-- 46 files changed, 207 insertions(+), 780 deletions(-) create mode 100644 controllers/base_admin_controller.js diff --git a/controllers/base_admin_controller.js b/controllers/base_admin_controller.js new file mode 100644 index 000000000..97bad0b55 --- /dev/null +++ b/controllers/base_admin_controller.js @@ -0,0 +1,58 @@ +/* + Copyright (C) 2015 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ + +module.exports = function BaseAdminControllerModule(pb) { + "use strict"; + + var util = pb.util; + var BaseController = pb.BaseController; + + /** + * This class serves as a base class for all the controllers used in the admin control panel + * @constructor + */ + function BaseAdminController() { + } + util.inherits(BaseAdminController, BaseController); + + BaseAdminController.prototype.init = function (props, cb) { + BaseAdminController.overrideInit(this, props, cb); + }; + + BaseAdminController.overrideInit = function(self, props, cb) { + BaseController.prototype.init.call(self, props, function () { + self.pathSiteUId = pb.SiteService.getCurrentSite(self.pathVars.siteid); + var siteService = new pb.SiteService(); + siteService.getByUid(self.pathSiteUId, function (err, siteInfo) { + if (err || !siteInfo) { + self.reqHandler.serve404(); + } else { + self.sectionService = new pb.SectionService(self.pathSiteUId, true); + self.sitePrefix = pb.SiteService.getCurrentSitePrefix(self.pathSiteUId); + self.siteQueryService = new pb.SiteQueryService(self.pathSiteUId, true); + self.settings = pb.SettingServiceFactory.getServiceBySite(self.pathSiteUId, true); + self.siteObj = siteInfo; + self.isGlobalSite = pb.SiteService.isGlobal(siteInfo.uid); + self.siteName = self.isGlobalSite ? siteInfo.uid : siteInfo.displayName; + cb(); + } + }) + }); + }; + + return BaseAdminController; +}; \ No newline at end of file diff --git a/include/requirements.js b/include/requirements.js index 24b1d35dd..1d4e85bc9 100755 --- a/include/requirements.js +++ b/include/requirements.js @@ -116,6 +116,7 @@ module.exports = function PB(config) { pb.JsonBodyParser = BodyParsers.JsonBodyParser; pb.FormBodyParser = BodyParsers.FormBodyParser; pb.BaseController = require(path.join(config.docRoot, '/controllers/base_controller.js'))(pb); + pb.BaseAdminController = require(path.join(config.docRoot, '/controllers/base_admin_controller.js'))(pb); pb.ViewController = require(path.join(config.docRoot, '/controllers/view_controller.js'))(pb); pb.FormController = require(path.join(config.docRoot, '/controllers/form_controller.js'))(pb); pb.DeleteController = require(path.join(config.docRoot, '/controllers/delete_controller.js'))(pb); diff --git a/include/service/entities/media_service.js b/include/service/entities/media_service.js index 3f87d9422..0523f33bd 100755 --- a/include/service/entities/media_service.js +++ b/include/service/entities/media_service.js @@ -38,7 +38,7 @@ module.exports = function MediaServiceModule(pb) { */ function MediaService(provider, site, onlyThisSite) { this.site = pb.SiteService.getCurrentSite(site); - this.queryService = new pb.SiteQueryService(site, onlyThisSite); + this.siteQueryService = new pb.SiteQueryService(site, onlyThisSite); if (util.isNullOrUndefined(provider)) { provider = MediaService.loadMediaProvider(); } @@ -52,7 +52,7 @@ module.exports = function MediaServiceModule(pb) { * @type {MediaProvider} */ this.provider = provider; - }; + } /** * @@ -101,7 +101,7 @@ module.exports = function MediaServiceModule(pb) { * occurred and a media descriptor if found. */ MediaService.prototype.loadById = function(mid, cb) { - this.queryService.loadById(mid.toString(), MediaService.COLL, cb); + this.siteQueryService.loadById(mid.toString(), MediaService.COLL, cb); }; /** @@ -118,7 +118,7 @@ module.exports = function MediaServiceModule(pb) { } var self = this; - this.queryService.deleteById(mid, MediaService.COLL, cb); + self.siteQueryService.deleteById(mid, MediaService.COLL, cb); }; /** @@ -143,7 +143,7 @@ module.exports = function MediaServiceModule(pb) { return cb(null, validationErrors); } - self.queryService.save(media, cb); + self.siteQueryService.save(media, cb); }); }; @@ -164,7 +164,7 @@ module.exports = function MediaServiceModule(pb) { //ensure the media name is unique var where = { name: media.name }; - this.queryService.unique(MediaService.COLL, where, media[pb.DAO.getIdField()], function(err, isUnique) { + this.siteQueryService.unique(MediaService.COLL, where, media[pb.DAO.getIdField()], function(err, isUnique) { if(util.isError(err)) { return cb(err, errors); } @@ -187,6 +187,7 @@ module.exports = function MediaServiceModule(pb) { * @param {Integer} [options.limit] * @param {Integer} [options.offset] * @param {Boolean} [options.format_media=true] + * @param cb */ MediaService.prototype.get = function(options, cb) { if (util.isFunction(options)) { @@ -197,7 +198,7 @@ module.exports = function MediaServiceModule(pb) { }; } - this.queryService.q('media', options, function (err, media) { + this.siteQueryService.q('media', options, function (err, media) { if (util.isError(err)) { return cb(err, []); } @@ -471,7 +472,7 @@ module.exports = function MediaServiceModule(pb) { MediaService.prototype.renderById = function(id, options, cb) { var self = this; - self.queryService.loadById(id, MediaService.COLL, function (err, media) { + self.siteQueryService.loadById(id, MediaService.COLL, function (err, media) { if (util.isError(err)) { return cb(err); } diff --git a/include/service/entities/section_service.js b/include/service/entities/section_service.js index 26366bd83..0cc08fa2a 100755 --- a/include/service/entities/section_service.js +++ b/include/service/entities/section_service.js @@ -33,7 +33,7 @@ module.exports = function SectionServiceModule(pb) { this.site = pb.SiteService.getCurrentSite(site); this.settings = pb.SettingServiceFactory.getServiceBySite(this.site, onlyThisSite); this.sitePrefix = pb.SiteService.getCurrentSitePrefix(this.site); - this.queryService = new pb.SiteQueryService(this.site, onlyThisSite); + this.siteQueryService = new pb.SiteQueryService(this.site, onlyThisSite); } /** @@ -53,11 +53,12 @@ module.exports = function SectionServiceModule(pb) { }; /** - * + * * @static * @method getPillNavOptions * @param {String} activePill * @return {Array} + * @param sitePrefix */ SectionService.getPillNavOptions = function(activePill, sitePrefix) { return [ @@ -246,7 +247,7 @@ module.exports = function SectionServiceModule(pb) { } //retrieve sections - self.queryService.q('section', function(err, sections) { + self.siteQueryService.q('section', function(err, sections) { if (util.isError(err)) { return cb(err, []); } @@ -294,7 +295,7 @@ module.exports = function SectionServiceModule(pb) { * * @method getParentSelectList * @param {String|ObjectID} currItem - * @param {Function} + * @param {Function} cb */ SectionService.prototype.getParentSelectList = function(currItem, cb) { cb = cb || currItem; @@ -314,14 +315,14 @@ module.exports = function SectionServiceModule(pb) { where: where, order: {'name': pb.DAO.ASC} }; - this.queryService.q('section', opts, cb); + this.siteQueryService.q('section', opts, cb); }; /** * * @static * @method trimForType - * @param {Object} + * @param {Object} navItem */ SectionService.trimForType = function(navItem) { if (navItem.type === 'container') { @@ -353,7 +354,7 @@ module.exports = function SectionServiceModule(pb) { /** * * @method validate - * @param {Object} + * @param {Object} navItem * @param {Function} cb */ SectionService.prototype.validate = function(navItem, cb) { @@ -419,7 +420,7 @@ module.exports = function SectionServiceModule(pb) { * * @method validateLinkNavItem * @param {Object} navItem - * @param {Function} + * @param {Function} cb */ SectionService.prototype.validateLinkNavItem = function(navItem, cb) { var errors = []; @@ -446,7 +447,7 @@ module.exports = function SectionServiceModule(pb) { var where = { name: navItem.name }; - this.queryService.unique('section', where, navItem[pb.DAO.getIdField()], function(err, unique) { + this.siteQueryService.unique('section', where, navItem[pb.DAO.getIdField()], function(err, unique) { var error = null; if (!unique) { error = {field: 'name', message: 'The provided name is not unique'}; @@ -557,7 +558,6 @@ module.exports = function SectionServiceModule(pb) { if (!pb.validation.validateNonEmptyStr(parent, false)) { error = {field: 'parent', message: 'The parent must be a valid nav item container ID'}; cb(null, error); - return; } else if (parent) { @@ -652,7 +652,7 @@ module.exports = function SectionServiceModule(pb) { } //persist the changes - self.queryService.save(navItem, function(err, data) { + self.siteQueryService.save(navItem, function(err, data) { if(util.isError(err)) { return cb(err); } @@ -668,11 +668,12 @@ module.exports = function SectionServiceModule(pb) { }; /** - * + * * @static * @method getSectionData - * @param {String} editor - * @param {Function} cb + * @param {String} uid + * @param {Object} navItems + * @param {String} currUrl */ SectionService.getSectionData = function(uid, navItems, currUrl) { var self = this; diff --git a/include/service/entities/site_service.js b/include/service/entities/site_service.js index f9db74837..5e8faf9fb 100644 --- a/include/service/entities/site_service.js +++ b/include/service/entities/site_service.js @@ -278,6 +278,15 @@ module.exports = function SiteServiceModule(pb) { commandService.registerForType('activate_site' , SiteService.onDeactivateSiteCommandReceived); }; + /** + * Returns true iff siteid given is global + * @param siteid + * @returns {boolean} + */ + SiteService.isGlobal = function (siteid) { + return (!siteid || siteid === SiteService.GLOBAL_SITE); + }; + /** * Central place to get the current site * diff --git a/plugins/pencilblue/controllers/actions/admin/content/media/edit_media.js b/plugins/pencilblue/controllers/actions/admin/content/media/edit_media.js index d1794db21..aaab63116 100755 --- a/plugins/pencilblue/controllers/actions/admin/content/media/edit_media.js +++ b/plugins/pencilblue/controllers/actions/admin/content/media/edit_media.js @@ -19,8 +19,7 @@ module.exports = function(pb) { //pb dependencies var util = pb.util; - var mediaService = pb.MediaService; - + /** * Edits media * @class EditMediaActionController @@ -28,14 +27,7 @@ module.exports = function(pb) { * @constructor */ function EditMediaActionController(){} - util.inherits(EditMediaActionController, pb.BaseController); - - EditMediaActionController.prototype.init = function (props, cb) { - this.pathSiteUId = pb.SiteService.getCurrentSite(props.path_vars.siteid); - this.sitePrefix = pb.SiteService.getCurrentSitePrefix(this.pathSiteUId); - - pb.BaseController.prototype.init.call(this, props, cb); - }; + util.inherits(EditMediaActionController, pb.BaseAdminController); /** * diff --git a/plugins/pencilblue/controllers/actions/admin/content/media/new_media.js b/plugins/pencilblue/controllers/actions/admin/content/media/new_media.js index acab22686..2c80805e5 100755 --- a/plugins/pencilblue/controllers/actions/admin/content/media/new_media.js +++ b/plugins/pencilblue/controllers/actions/admin/content/media/new_media.js @@ -27,15 +27,7 @@ module.exports = function(pb) { * @extends BaseController */ function NewMediaApiController(){} - util.inherits(NewMediaApiController, pb.BaseController); - - NewMediaApiController.prototype.init = function (props, cb) { - this.pathSiteUId = pb.SiteService.getCurrentSite(props.path_vars.siteid); - this.sitePrefix = pb.SiteService.getCurrentSitePrefix(this.pathSiteUId); - - pb.BaseController.prototype.init.call(this, props, cb); - }; - + util.inherits(NewMediaApiController, pb.BaseAdminController); NewMediaApiController.prototype.render = function(cb) { var self = this; diff --git a/plugins/pencilblue/controllers/actions/admin/content/navigation/delete_nav_item.js b/plugins/pencilblue/controllers/actions/admin/content/navigation/delete_nav_item.js index 08eaa4bb9..b0b5e4f9c 100644 --- a/plugins/pencilblue/controllers/actions/admin/content/navigation/delete_nav_item.js +++ b/plugins/pencilblue/controllers/actions/admin/content/navigation/delete_nav_item.js @@ -26,29 +26,6 @@ module.exports = function(pb) { function DeleteNavItem(){} util.inherits(DeleteNavItem, pb.BaseController); - DeleteNavItem.prototype.init = function (props, cb) { - var self = this; - pb.BaseController.prototype.init.call(self, props, function () { - self.pathSiteUId = pb.SiteService.getCurrentSite(self.pathVars.siteid); - pb.SiteService.siteExists(self.pathSiteUId, function (err, exists) { - if (!exists) { - self.reqHandler.serve404(); - } - else { - self.navService = new pb.SectionService(self.pathSiteUId, true); - self.sitePrefix = pb.SiteService.getCurrentSitePrefix(self.pathSiteUId); - self.queryService = new pb.SiteQueryService(self.pathSiteUId, true); - self.settings = pb.SettingServiceFactory.getServiceBySite(self.pathSiteUId, true); - var siteService = new pb.SiteService(); - siteService.getSiteNameByUid(self.pathSiteUId, function (siteName) { - self.siteName = siteName; - cb(); - }); - } - }); - }); - }; - DeleteNavItem.prototype.render = function(cb) { var self = this; var vars = this.pathVars; @@ -63,7 +40,7 @@ module.exports = function(pb) { } //ensure existence - self.queryService.loadById(vars.id, 'section', function(err, section) { + self.siteQueryService.loadById(vars.id, 'section', function(err, section) { if(section === null) { cb({ code: 400, @@ -81,7 +58,7 @@ module.exports = function(pb) { } ] }; - self.queryService.delete(where, 'section', function(err, result) { + self.siteQueryService.delete(where, 'section', function(err, result) { if(util.isError(err) || result < 1) { return cb({ code: 500, @@ -105,7 +82,7 @@ module.exports = function(pb) { }; DeleteNavItem.prototype.updateNavMap = function(removeID, cb) { - this.navService.removeFromSectionMap(removeID, cb); + this.sectionService.removeFromSectionMap(removeID, cb); }; //exports diff --git a/plugins/pencilblue/controllers/actions/admin/content/navigation/edit_nav_item.js b/plugins/pencilblue/controllers/actions/admin/content/navigation/edit_nav_item.js index 7c3a6b41c..5523f38a0 100644 --- a/plugins/pencilblue/controllers/actions/admin/content/navigation/edit_nav_item.js +++ b/plugins/pencilblue/controllers/actions/admin/content/navigation/edit_nav_item.js @@ -24,30 +24,7 @@ module.exports = function(pb) { * Edits a nav item */ function EditNavItem(){} - util.inherits(EditNavItem, pb.BaseController); - - EditNavItem.prototype.init = function (props, cb) { - var self = this; - pb.BaseController.prototype.init.call(self, props, function () { - self.pathSiteUId = pb.SiteService.getCurrentSite(self.pathVars.siteid); - pb.SiteService.siteExists(self.pathSiteUId, function (err, exists) { - if (!exists) { - self.reqHandler.serve404(); - } - else { - self.navService = new pb.SectionService(self.pathSiteUId, true); - self.sitePrefix = pb.SiteService.getCurrentSitePrefix(self.pathSiteUId); - self.queryService = new pb.SiteQueryService(self.pathSiteUId, true); - self.settings = pb.SettingServiceFactory.getServiceBySite(self.pathSiteUId, true); - var siteService = new pb.SiteService(); - siteService.getSiteNameByUid(self.pathSiteUId, function (siteName) { - self.siteName = siteName; - cb(); - }); - } - }); - }); - }; + util.inherits(EditNavItem, pb.BaseAdminController); EditNavItem.prototype.render = function(cb){ var self = this; @@ -64,7 +41,7 @@ module.exports = function(pb) { this.getJSONPostParams(function(err, post) { //load object - self.queryService.loadById(vars.id, 'section', function(err, navItem) { + self.siteQueryService.loadById(vars.id, 'section', function(err, navItem) { if(util.isError(err) || !util.isObject(navItem)) { cb({ code: 400, @@ -85,7 +62,7 @@ module.exports = function(pb) { pb.SectionService.trimForType(navItem); //validate - self.navService.save(navItem, function(err, result) { + self.sectionService.save(navItem, function(err, result) { if(util.isError(err)) { cb({ code: 500, @@ -110,11 +87,11 @@ module.exports = function(pb) { }; EditNavItem.prototype.deleteOrphans = function(navItem, cb) { - this.navService.deleteChildren(navItem[pb.DAO.getIdField()], cb); + this.sectionService.deleteChildren(navItem[pb.DAO.getIdField()], cb); }; EditNavItem.prototype.checkForNavMapUpdate = function(navItem, cb) { - this.navService.updateNavMap(navItem, cb); + this.sectionService.updateNavMap(navItem, cb); }; EditNavItem.getHtmlErrorMsg = function(validationErrors) { diff --git a/plugins/pencilblue/controllers/actions/admin/content/navigation/new_nav_item.js b/plugins/pencilblue/controllers/actions/admin/content/navigation/new_nav_item.js index 20b904fc9..300c999e7 100644 --- a/plugins/pencilblue/controllers/actions/admin/content/navigation/new_nav_item.js +++ b/plugins/pencilblue/controllers/actions/admin/content/navigation/new_nav_item.js @@ -24,30 +24,7 @@ module.exports = function(pb) { * Creates a nav item */ function NewNavItem(){} - util.inherits(NewNavItem, pb.BaseController); - - NewNavItem.prototype.init = function (props, cb) { - var self = this; - pb.BaseController.prototype.init.call(self, props, function () { - self.pathSiteUId = pb.SiteService.getCurrentSite(self.pathVars.siteid); - pb.SiteService.siteExists(self.pathSiteUId, function (err, exists) { - if (!exists) { - self.reqHandler.serve404(); - } - else { - self.navService = new pb.SectionService(self.pathSiteUId, true); - self.sitePrefix = pb.SiteService.getCurrentSitePrefix(self.pathSiteUId); - self.queryService = new pb.SiteQueryService(self.pathSiteUId, true); - self.settings = pb.SettingServiceFactory.getServiceBySite(self.pathSiteUId, true); - var siteService = new pb.SiteService(); - siteService.getSiteNameByUid(self.pathSiteUId, function (siteName) { - self.siteName = siteName; - cb(); - }); - } - }); - }); - }; + util.inherits(NewNavItem, pb.BaseAdminController); NewNavItem.prototype.render = function(cb){ var self = this; @@ -65,7 +42,7 @@ module.exports = function(pb) { pb.SectionService.trimForType(navItem); //validate - self.navService.save(navItem, function(err, result) { + self.sectionService.save(navItem, function(err, result) { if(util.isError(err)) { cb({ code: 500, @@ -89,7 +66,7 @@ module.exports = function(pb) { }; NewNavItem.prototype.checkForNavMapUpdate = function(navItem, cb) { - this.navService.updateNavMap(navItem, cb); + this.sectionService.updateNavMap(navItem, cb); }; NewNavItem.getHtmlErrorMsg = function(validationErrors) { diff --git a/plugins/pencilblue/controllers/actions/admin/content/objects/delete_object.js b/plugins/pencilblue/controllers/actions/admin/content/objects/delete_object.js index d3c6752c4..bfd070423 100644 --- a/plugins/pencilblue/controllers/actions/admin/content/objects/delete_object.js +++ b/plugins/pencilblue/controllers/actions/admin/content/objects/delete_object.js @@ -24,23 +24,7 @@ module.exports = function(pb) { * Deletes an object */ function DeleteObject(){} - util.inherits(DeleteObject, pb.BaseController); - - DeleteObject.prototype.init = function (props, cb) { - var self = this; - - pb.BaseController.prototype.init.call(self, props, function() { - self.pathSiteUid = pb.SiteService.getCurrentSite(self.pathVars.siteid); - pb.SiteService.siteExists(self.pathSiteUid, function (err, exists) { - if (!exists) { - self.reqHandler.serve404(); - } - else { - cb(); - } - }); - }); - }; + util.inherits(DeleteObject, pb.BaseAdminController); DeleteObject.prototype.render = function(cb) { var self = this; @@ -58,7 +42,7 @@ module.exports = function(pb) { return; } - var cos = new pb.CustomObjectService(self.pathSiteUid, true); + var cos = new pb.CustomObjectService(self.pathSiteUId, true); cos.loadById(vars.id, function(err, customObject) { if (util.isError(err)) { return self.reqHandler.serveError(err); diff --git a/plugins/pencilblue/controllers/actions/admin/content/objects/edit_object.js b/plugins/pencilblue/controllers/actions/admin/content/objects/edit_object.js index 7f6039902..c603125a1 100644 --- a/plugins/pencilblue/controllers/actions/admin/content/objects/edit_object.js +++ b/plugins/pencilblue/controllers/actions/admin/content/objects/edit_object.js @@ -27,23 +27,7 @@ module.exports = function(pb) { * @extends FormController */ function EditObject(){} - util.inherits(EditObject, pb.BaseController); - - EditObject.prototype.init = function (props, cb) { - var self = this; - - pb.BaseController.prototype.init.call(self, props, function() { - self.pathSiteUid = pb.SiteService.getCurrentSite(self.pathVars.siteid); - pb.SiteService.siteExists(self.pathSiteUid, function (err, exists) { - if (!exists) { - self.reqHandler.serve404(); - } - else { - cb(); - } - }); - }); - }; + util.inherits(EditObject, pb.BaseAdminController); EditObject.prototype.render = function(cb) { var self = this; @@ -57,7 +41,7 @@ module.exports = function(pb) { return; } - var service = new pb.CustomObjectService(self.pathSiteUid, true); + var service = new pb.CustomObjectService(self.pathSiteUId, true); service.loadById(vars.id, function(err, custObj) { if(util.isError(err) || !util.isObject(custObj)) { return cb({ diff --git a/plugins/pencilblue/controllers/actions/admin/content/objects/new_object.js b/plugins/pencilblue/controllers/actions/admin/content/objects/new_object.js index 5a9906355..7b8052858 100644 --- a/plugins/pencilblue/controllers/actions/admin/content/objects/new_object.js +++ b/plugins/pencilblue/controllers/actions/admin/content/objects/new_object.js @@ -27,23 +27,7 @@ module.exports = function(pb) { * @extends BaseController */ function NewObjectActionController(){} - util.inherits(NewObjectActionController, pb.BaseController); - - NewObjectActionController.prototype.init = function (props, cb) { - var self = this; - - pb.BaseController.prototype.init.call(self, props, function() { - self.pathSiteUid = pb.SiteService.getCurrentSite(self.pathVars.siteid); - pb.SiteService.siteExists(self.pathSiteUid, function (err, exists) { - if (!exists) { - self.reqHandler.serve404(); - } - else { - cb(); - } - }); - }); - }; + util.inherits(NewObjectActionController, pb.BaseAdminController); NewObjectActionController.prototype.render = function(cb) { var self = this; @@ -57,7 +41,7 @@ module.exports = function(pb) { return } - var service = new pb.CustomObjectService(self.pathSiteUid, true); + var service = new pb.CustomObjectService(self.pathSiteUId, true); service.loadTypeById(vars.type_id, function(err, customObjectType) { if(util.isError(err) || !util.isObject(customObjectType)) { return cb({ diff --git a/plugins/pencilblue/controllers/actions/admin/content/objects/sort_objects.js b/plugins/pencilblue/controllers/actions/admin/content/objects/sort_objects.js index 068e2daee..96a7982ac 100644 --- a/plugins/pencilblue/controllers/actions/admin/content/objects/sort_objects.js +++ b/plugins/pencilblue/controllers/actions/admin/content/objects/sort_objects.js @@ -29,19 +29,7 @@ module.exports = function(pb) { util.inherits(SortObjectsActionController, pb.FormController); SortObjectsActionController.prototype.init = function (props, cb) { - var self = this; - - pb.BaseController.prototype.init.call(self, props, function() { - self.pathSiteUid = pb.SiteService.getCurrentSite(self.pathVars.siteid); - pb.SiteService.siteExists(self.pathSiteUid, function (err, exists) { - if (!exists) { - self.reqHandler.serve404(); - } - else { - cb(); - } - }); - }); + pb.BaseAdminController.overrideInit(this, props, cb); }; SortObjectsActionController.prototype.render = function(cb) { @@ -55,7 +43,7 @@ module.exports = function(pb) { }); } - var service = new pb.CustomObjectService(self.pathSiteUid, true); + var service = new pb.CustomObjectService(self.pathSiteUId, true); service.loadTypeById(vars.type_id, function(err, customObjectType) { if(util.isError(err) || !util.isObject(customObjectType)) { return cb({ diff --git a/plugins/pencilblue/controllers/actions/admin/content/objects/types/delete_type.js b/plugins/pencilblue/controllers/actions/admin/content/objects/types/delete_type.js index e28a3f34d..f7ca95827 100644 --- a/plugins/pencilblue/controllers/actions/admin/content/objects/types/delete_type.js +++ b/plugins/pencilblue/controllers/actions/admin/content/objects/types/delete_type.js @@ -27,19 +27,7 @@ module.exports = function(pb) { util.inherits(DeleteObjectType, pb.FormController); DeleteObjectType.prototype.init = function (props, cb) { - var self = this; - - pb.BaseController.prototype.init.call(self, props, function() { - self.pathSiteUid = pb.SiteService.getCurrentSite(self.pathVars.siteid); - pb.SiteService.siteExists(self.pathSiteUid, function (err, exists) { - if (!exists) { - self.reqHandler.serve404(); - } - else { - cb(); - } - }); - }); + pb.BaseAdminController.overrideInit(this, props, cb); }; DeleteObjectType.prototype.onPostParamsRetrieved = function(post, cb) { @@ -54,7 +42,7 @@ module.exports = function(pb) { } //ensure existence - var service = new pb.CustomObjectService(self.pathSiteUid, true); + var service = new pb.CustomObjectService(self.pathSiteUId, true); service.loadTypeById(vars.id, function(err, objectType) { if(objectType === null) { cb({ diff --git a/plugins/pencilblue/controllers/actions/admin/content/objects/types/edit_type.js b/plugins/pencilblue/controllers/actions/admin/content/objects/types/edit_type.js index 2d1a1c8f3..a66444abc 100644 --- a/plugins/pencilblue/controllers/actions/admin/content/objects/types/edit_type.js +++ b/plugins/pencilblue/controllers/actions/admin/content/objects/types/edit_type.js @@ -27,23 +27,7 @@ module.exports = function(pb) { * @extends FormController */ function EditObjectType(){} - util.inherits(EditObjectType, pb.BaseController); - - EditObjectType.prototype.init = function (props, cb) { - var self = this; - - pb.BaseController.prototype.init.call(self, props, function() { - self.pathSiteUid = pb.SiteService.getCurrentSite(self.pathVars.siteid); - pb.SiteService.siteExists(self.pathSiteUid, function (err, exists) { - if (!exists) { - self.reqHandler.serve404(); - } - else { - cb(); - } - }); - }); - }; + util.inherits(EditObjectType, pb.BaseAdminController); EditObjectType.prototype.render = function(cb) { var self = this; @@ -56,7 +40,7 @@ module.exports = function(pb) { }); } - var service = new pb.CustomObjectService(self.pathSiteUid, true); + var service = new pb.CustomObjectService(self.pathSiteUId, true); service.loadTypeById(vars.id, function(err, custObjType) { if(util.isError(err) || !util.isObject(custObjType)) { return cb({ diff --git a/plugins/pencilblue/controllers/actions/admin/content/objects/types/new_type.js b/plugins/pencilblue/controllers/actions/admin/content/objects/types/new_type.js index a14d19e43..3fad304df 100644 --- a/plugins/pencilblue/controllers/actions/admin/content/objects/types/new_type.js +++ b/plugins/pencilblue/controllers/actions/admin/content/objects/types/new_type.js @@ -27,23 +27,7 @@ module.exports = function(pb) { * @extends FormController */ function NewObjectTypeActionController(){} - util.inherits(NewObjectTypeActionController, pb.BaseController); - - NewObjectTypeActionController.prototype.init = function (props, cb) { - var self = this; - - pb.BaseController.prototype.init.call(self, props, function() { - self.pathSiteUid = pb.SiteService.getCurrentSite(self.pathVars.siteid); - pb.SiteService.siteExists(self.pathSiteUid, function (err, exists) { - if (!exists) { - self.reqHandler.serve404(); - } - else { - cb(); - } - }); - }); - }; + util.inherits(NewObjectTypeActionController, pb.BaseAdminController); NewObjectTypeActionController.prototype.render = function(cb) { var self = this; @@ -51,7 +35,7 @@ module.exports = function(pb) { var post = self.body; post.fields.name = {field_type: 'text'}; - var service = new pb.CustomObjectService(self.pathSiteUid, true); + var service = new pb.CustomObjectService(self.pathSiteUId, true); service.saveType(post, function(err, result) { if(util.isError(err)) { return cb({ diff --git a/plugins/pencilblue/controllers/actions/admin/content/topics/edit_topic.js b/plugins/pencilblue/controllers/actions/admin/content/topics/edit_topic.js index 55af937aa..b890ae39a 100644 --- a/plugins/pencilblue/controllers/actions/admin/content/topics/edit_topic.js +++ b/plugins/pencilblue/controllers/actions/admin/content/topics/edit_topic.js @@ -24,28 +24,7 @@ module.exports = function(pb) { * Creates a new topic */ function NewTopic(){} - util.inherits(NewTopic, pb.BaseController); - - NewTopic.prototype.init = function (props, cb) { - var self = this; - pb.BaseController.prototype.init.call(self, props, function () { - self.pathSiteUId = pb.SiteService.getCurrentSite(self.pathVars.siteid); - pb.SiteService.siteExists(self.pathSiteUId, function (err, exists) { - if (!exists) { - self.reqHandler.serve404(); - } - else { - self.sitePrefix = pb.SiteService.getCurrentSitePrefix(self.pathSiteUId); - self.queryService = new pb.SiteQueryService(self.pathSiteUId, true); - var siteService = new pb.SiteService(); - siteService.getSiteNameByUid(self.pathSiteUId, function (siteName) { - self.siteName = siteName; - cb(); - }); - } - }); - }); - }; + util.inherits(NewTopic, pb.BaseAdminController); NewTopic.prototype.render = function(cb) { var self = this; @@ -70,8 +49,7 @@ module.exports = function(pb) { return; } - var dao = new pb.DAO(); - dao.loadById(vars.id, 'topic', function(err, topic) { + self.siteQueryService.loadById(vars.id, 'topic', function(err, topic) { if(util.isError(err) || !util.isObject(topic)) { cb({ code: 400, @@ -82,7 +60,7 @@ module.exports = function(pb) { pb.DocumentCreator.update(post, topic); - self.queryService.loadByValue('name', topic.name, 'topic', function(err, testTopic) { + self.siteQueryService.loadByValue('name', topic.name, 'topic', function(err, testTopic) { if(testTopic && !testTopic[pb.DAO.getIdField()].equals(topic[pb.DAO.getIdField()])) { cb({ code: 400, @@ -91,7 +69,7 @@ module.exports = function(pb) { return; } - self.queryService.save(topic, function(err, result) { + self.siteQueryService.save(topic, function(err, result) { if(util.isError(err)) { return cb({ code: 500, diff --git a/plugins/pencilblue/controllers/actions/admin/content/topics/import_topics.js b/plugins/pencilblue/controllers/actions/admin/content/topics/import_topics.js index 938eb4c13..4e0ac333d 100755 --- a/plugins/pencilblue/controllers/actions/admin/content/topics/import_topics.js +++ b/plugins/pencilblue/controllers/actions/admin/content/topics/import_topics.js @@ -31,28 +31,7 @@ module.exports = function(pb) { * @constructor */ function ImportTopics(){} - util.inherits(ImportTopics, pb.BaseController); - - ImportTopics.prototype.init = function (props, cb) { - var self = this; - pb.BaseController.prototype.init.call(self, props, function () { - self.pathSiteUId = pb.SiteService.getCurrentSite(self.pathVars.siteid); - pb.SiteService.siteExists(self.pathSiteUId, function (err, exists) { - if (!exists) { - self.reqHandler.serve404(); - } - else { - self.sitePrefix = pb.SiteService.getCurrentSitePrefix(self.pathSiteUId); - self.queryService = new pb.SiteQueryService(self.pathSiteUId, true); - var siteService = new pb.SiteService(); - siteService.getSiteNameByUid(self.pathSiteUId, function (siteName) { - self.siteName = siteName; - cb(); - }); - } - }); - }); - }; + util.inherits(ImportTopics, pb.BaseAdminController); ImportTopics.prototype.render = function(cb) { var self = this; @@ -86,19 +65,18 @@ module.exports = function(pb) { }; ImportTopics.prototype.saveTopics = function(topics, cb) { - var content = {completed: false}; var self = this; //create tasks var tasks = util.getTasks(topics, function(topicArry, index) { return function(callback) { - self.queryService.count('topic', {name: topicArry[index].trim()}, function(err, count){ + self.siteQueryService.count('topic', {name: topicArry[index].trim()}, function(err, count){ if (count > 0) { return callback(null, true); } var topicDocument = pb.DocumentCreator.create('topic', {name: topicArry[index].trim()}); - self.queryService.save(topicDocument, callback); + self.siteQueryService.save(topicDocument, callback); }); }; diff --git a/plugins/pencilblue/controllers/actions/admin/content/topics/new_topic.js b/plugins/pencilblue/controllers/actions/admin/content/topics/new_topic.js index c23012355..95c91e447 100755 --- a/plugins/pencilblue/controllers/actions/admin/content/topics/new_topic.js +++ b/plugins/pencilblue/controllers/actions/admin/content/topics/new_topic.js @@ -24,28 +24,7 @@ module.exports = function(pb) { * Creates a new topic */ function NewTopic(){} - util.inherits(NewTopic, pb.BaseController); - - NewTopic.prototype.init = function (props, cb) { - var self = this; - pb.BaseController.prototype.init.call(self, props, function () { - self.pathSiteUId = pb.SiteService.getCurrentSite(self.pathVars.siteid); - pb.SiteService.siteExists(self.pathSiteUId, function (err, exists) { - if (!exists) { - self.reqHandler.serve404(); - } - else { - self.sitePrefix = pb.SiteService.getCurrentSitePrefix(self.pathSiteUId); - self.queryService = new pb.SiteQueryService(self.pathSiteUId, true); - var siteService = new pb.SiteService(); - siteService.getSiteNameByUid(self.pathSiteUId, function (siteName) { - self.siteName = siteName; - cb(); - }); - } - }); - }); - }; + util.inherits(NewTopic, pb.BaseAdminController); NewTopic.prototype.render = function(cb) { var self = this; @@ -60,7 +39,7 @@ module.exports = function(pb) { return; } - self.queryService.count('topic', {name: post.name}, function(err, count) { + self.siteQueryService.count('topic', {name: post.name}, function(err, count) { if(count > 0) { cb({ code: 400, @@ -70,7 +49,7 @@ module.exports = function(pb) { } var topicDocument = pb.DocumentCreator.create('topic', post); - self.queryService.save(topicDocument, function(err, result) { + self.siteQueryService.save(topicDocument, function(err, result) { if(util.isError(err)) { return cb({ code: 500, diff --git a/plugins/pencilblue/controllers/actions/admin/themes/site_logo.js b/plugins/pencilblue/controllers/actions/admin/themes/site_logo.js index 2f6feac0a..872bdef98 100755 --- a/plugins/pencilblue/controllers/actions/admin/themes/site_logo.js +++ b/plugins/pencilblue/controllers/actions/admin/themes/site_logo.js @@ -20,33 +20,12 @@ module.exports = function(pb) { //pb dependencies var util = pb.util; - var MediaService = pb.MediaService; - + /** * Saves the site's logo */ function SiteLogo() {} - util.inherits(SiteLogo, pb.BaseController); - - SiteLogo.prototype.init = function (props, cb) { - var self = this; - pb.BaseController.prototype.init.call(self, props, function () { - self.pathSiteUId = pb.SiteService.getCurrentSite(self.pathVars.siteid); - pb.SiteService.siteExists(self.pathSiteUId, function (err, exists) { - if (!exists) { - self.reqHandler.serve404(); - } - else { - self.settings = pb.SettingServiceFactory.getServiceBySite(self.pathSiteUId, true); - var siteService = new pb.SiteService(); - siteService.getSiteNameByUid(self.pathSiteUId, function (siteName) { - self.siteName = siteName; - cb(); - }); - } - }); - }); - }; + util.inherits(SiteLogo, pb.BaseAdminController); SiteLogo.prototype.render = function(cb) { var self = this; diff --git a/plugins/pencilblue/controllers/admin/content/articles/article_form.js b/plugins/pencilblue/controllers/admin/content/articles/article_form.js index fc7b28ec0..d6db7a99c 100755 --- a/plugins/pencilblue/controllers/admin/content/articles/article_form.js +++ b/plugins/pencilblue/controllers/admin/content/articles/article_form.js @@ -27,28 +27,7 @@ module.exports = function(pb) { * Interface for creating and editing articles */ function ArticleForm(){} - util.inherits(ArticleForm, pb.BaseController); - - ArticleForm.prototype.init = function (props, cb) { - var self = this; - pb.BaseController.prototype.init.call(self, props, function () { - self.pathSiteUId = pb.SiteService.getCurrentSite(self.pathVars.siteid); - pb.SiteService.siteExists(self.pathSiteUId, function (err, exists) { - if (!exists) { - self.reqHandler.serve404(); - } - else { - self.sitePrefix = pb.SiteService.getCurrentSitePrefix(self.pathSiteUId); - self.queryService = new pb.SiteQueryService(self.pathSiteUId, true); - var siteService = new pb.SiteService(); - siteService.getSiteNameByUid(self.pathSiteUId, function (siteName) { - self.siteName = siteName; - cb(); - }); - } - }); - }); - }; + util.inherits(ArticleForm, pb.BaseAdminController); ArticleForm.prototype.render = function(cb) { var self = this; @@ -214,7 +193,7 @@ module.exports = function(pb) { }, order: {name: pb.DAO.ASC} }; - self.queryService.q('section', opts, callback); + self.siteQueryService.q('section', opts, callback); }, topics: function(callback) { @@ -223,7 +202,7 @@ module.exports = function(pb) { where: pb.DAO.ANYWHERE, order: {name: pb.DAO.ASC} }; - self.queryService.q('topic', opts, callback); + self.siteQueryService.q('topic', opts, callback); }, media: function(callback) { @@ -238,7 +217,7 @@ module.exports = function(pb) { } //TODO call article service - self.queryService.loadById(vars.id, 'article', callback); + self.siteQueryService.loadById(vars.id, 'article', callback); } }; async.parallelLimit(tasks, 2, cb); diff --git a/plugins/pencilblue/controllers/admin/content/articles/manage_articles.js b/plugins/pencilblue/controllers/admin/content/articles/manage_articles.js index f7a171020..d1d5f1fbe 100755 --- a/plugins/pencilblue/controllers/admin/content/articles/manage_articles.js +++ b/plugins/pencilblue/controllers/admin/content/articles/manage_articles.js @@ -24,15 +24,7 @@ module.exports = function(pb) { * Interface for managing articles */ function ManageArticles(){} - util.inherits(ManageArticles, pb.BaseController); - - ManageArticles.prototype.init = function (props, cb) { - this.pathSiteUId = pb.SiteService.getCurrentSite(props.path_vars.siteid); - this.queryService = new pb.SiteQueryService(this.pathSiteUId, true); - this.sitePrefix = pb.SiteService.getCurrentSitePrefix(this.pathSiteUId); - - pb.BaseController.prototype.init.call(this, props, cb); - }; + util.inherits(ManageArticles, pb.BaseAdminController); //statics var SUB_NAV_KEY = 'manage_articles'; @@ -50,7 +42,7 @@ module.exports = function(pb) { order: {publish_date: pb.DAO.ASC}, }; - self.queryService.q('article', opts, function(err, articles) { + self.siteQueryService.q('article', opts, function(err, articles) { if(util.isError(err)) { return self.reqHandler.serveError(err); } diff --git a/plugins/pencilblue/controllers/admin/content/comments/manage_comments.js b/plugins/pencilblue/controllers/admin/content/comments/manage_comments.js index a2a6f23cc..2c0894757 100755 --- a/plugins/pencilblue/controllers/admin/content/comments/manage_comments.js +++ b/plugins/pencilblue/controllers/admin/content/comments/manage_comments.js @@ -26,29 +26,7 @@ module.exports = function(pb) { * @constructor */ function ManageComments() {} - util.inherits(ManageComments, pb.BaseController); - - ManageComments.prototype.init = function (props, cb) { - var self = this; - pb.BaseController.prototype.init.call(self, props, function () { - self.pathSiteUId = pb.SiteService.getCurrentSite(self.pathVars.siteid); - pb.SiteService.siteExists(self.pathSiteUId, function (err, exists) { - if (!exists) { - self.reqHandler.serve404(); - } - else { - self.sitePrefix = pb.SiteService.getCurrentSitePrefix(self.pathSiteUId); - self.queryService = new pb.SiteQueryService(self.pathSiteUId, true); - var siteService = new pb.SiteService(); - siteService.getByUid(self.pathSiteUId, function (err, objSite) { - self.siteName = objSite.displayName; - self.siteRoot = objSite.hostname; - cb(); - }); - } - }); - }); - }; + util.inherits(ManageComments, pb.BaseAdminController); /** * @@ -74,7 +52,7 @@ module.exports = function(pb) { order: {created: -1}, limit: 500 }; - self.queryService.q('comment', opts, function(err, comments) { + self.siteQueryService.q('comment', opts, function(err, comments) { if (util.isError(err)) { return self.reqHandler.serveError(err); } @@ -123,12 +101,12 @@ module.exports = function(pb) { } this.getCommentingUser = function(index) { - self.queryService.__proto__.loadById(comments[index].commenter, 'user', function(err, user) { + self.siteQueryService.__proto__.loadById(comments[index].commenter, 'user', function(err, user) { if(!util.isError(err) && user !== null) { comments[index].user_name = user.first_name + ' ' + user.last_name; } - self.queryService.loadById(comments[index].article, 'article', function(err, article) { + self.siteQueryService.loadById(comments[index].article, 'article', function(err, article) { if(!util.isError(err) && article !== null) { comments[index].article_url = article.url; comments[index].article_headline = article.headline; diff --git a/plugins/pencilblue/controllers/admin/content/media/manage_media.js b/plugins/pencilblue/controllers/admin/content/media/manage_media.js index a2c06856e..8acff4dae 100755 --- a/plugins/pencilblue/controllers/admin/content/media/manage_media.js +++ b/plugins/pencilblue/controllers/admin/content/media/manage_media.js @@ -24,19 +24,11 @@ module.exports = function(pb) { * Interface for managing media */ function ManageMedia(){} - util.inherits(ManageMedia, pb.BaseController); + util.inherits(ManageMedia, pb.BaseAdminController); //statics var SUB_NAV_KEY = 'manage_media'; - ManageMedia.prototype.init = function (props, cb) { - this.pathSiteUId = pb.SiteService.getCurrentSite(props.path_vars.siteid); - this.sitePrefix = pb.SiteService.getCurrentSitePrefix(this.pathSiteUId); - this.mediaService = new pb.MediaService(null, this.pathSiteUId, true); - - pb.BaseController.prototype.init.call(this, props, cb); - }; - ManageMedia.prototype.render = function(cb) { var self = this; var options = { @@ -50,7 +42,8 @@ module.exports = function(pb) { order: {created: pb.DAO.DESC}, format_media: true }; - self.mediaService.get(options, function(err, mediaData) { + var mediaService = new pb.MediaService(null, self.pathSiteUId, true); + mediaService.get(options, function(err, mediaData) { if(util.isError(mediaData) || mediaData.length === 0) { self.redirect('/admin' + self.sitePrefix + '/content/media/new', cb); return; @@ -82,7 +75,7 @@ module.exports = function(pb) { }; ManageMedia.getSubNavItems = function(key, ls, data) { - var adminPrefix = '/admin' + var adminPrefix = '/admin'; if(data.site) { adminPrefix += '/' + data.site; } diff --git a/plugins/pencilblue/controllers/admin/content/media/media_form.js b/plugins/pencilblue/controllers/admin/content/media/media_form.js index a461b47e8..422b7b160 100644 --- a/plugins/pencilblue/controllers/admin/content/media/media_form.js +++ b/plugins/pencilblue/controllers/admin/content/media/media_form.js @@ -29,20 +29,11 @@ module.exports = function(pb) { * @constructor */ function MediaForm(){} - util.inherits(MediaForm, pb.BaseController); + util.inherits(MediaForm, pb.BaseAdminController); //statics var SUB_NAV_KEY = 'media_form'; - MediaForm.prototype.init = function (props, cb) { - this.pathSiteUId = pb.SiteService.getCurrentSite(props.path_vars.siteid); - this.sitePrefix = pb.SiteService.getCurrentSitePrefix(this.pathSiteUId); - this.queryService = new pb.SiteQueryService(this.pathSiteUId, true); - this.mediaService = new pb.MediaService(null, this.pathSiteUId, true); - - pb.BaseController.prototype.init.call(this, props, cb); - }; - /** * @method render * @param {Function} cb @@ -112,7 +103,7 @@ module.exports = function(pb) { where: pb.DAO.ANYWHERE, order: {name: pb.DAO.ASC} }; - self.queryService.q('topic', opts, callback); + self.siteQueryService.q('topic', opts, callback); }, media: function(callback) { @@ -123,7 +114,8 @@ module.exports = function(pb) { }); } - self.mediaService.loadById(vars.id, callback); + var mediaService = new pb.MediaService(null, this.pathSiteUId, true); + mediaService.loadById(vars.id, callback); } }; async.series(tasks, cb); @@ -149,7 +141,7 @@ module.exports = function(pb) { }; MediaForm.getSubNavItems = function(key, ls, data) { - var adminPrefix = '/admin' + var adminPrefix = '/admin'; if(data.site) { adminPrefix += '/' + data.site; } diff --git a/plugins/pencilblue/controllers/admin/content/navigation/nav_item_form.js b/plugins/pencilblue/controllers/admin/content/navigation/nav_item_form.js index 18bdb8d9c..985867770 100644 --- a/plugins/pencilblue/controllers/admin/content/navigation/nav_item_form.js +++ b/plugins/pencilblue/controllers/admin/content/navigation/nav_item_form.js @@ -31,30 +31,7 @@ module.exports = function(pb) { function NavItemFormController(){ this.navItem = null; } - util.inherits(NavItemFormController, pb.BaseController); - - NavItemFormController.prototype.init = function (props, cb) { - var self = this; - pb.BaseController.prototype.init.call(self, props, function () { - self.pathSiteUId = pb.SiteService.getCurrentSite(self.pathVars.siteid); - pb.SiteService.siteExists(self.pathSiteUId, function (err, exists) { - if (!exists) { - self.reqHandler.serve404(); - } - else { - self.navService = new pb.SectionService(self.pathSiteUId, true); - self.sitePrefix = pb.SiteService.getCurrentSitePrefix(self.pathSiteUId); - self.queryService = new pb.SiteQueryService(self.pathSiteUId, true); - self.settings = pb.SettingServiceFactory.getServiceBySite(self.pathSiteUId, true); - var siteService = new pb.SiteService(); - siteService.getSiteNameByUid(self.pathSiteUId, function (siteName) { - self.siteName = siteName; - cb(); - }); - } - }); - }); - }; + util.inherits(NavItemFormController, pb.BaseAdminController); //statics var SUB_NAV_KEY = 'nav_item_form'; @@ -109,7 +86,7 @@ module.exports = function(pb) { //get parents parents: function(callback) { - self.navService.getParentSelectList(self.pathVars.id, function(err, parents) { + self.sectionService.getParentSelectList(self.pathVars.id, function(err, parents) { if(util.isError(err)) { callback(err, parents); return; @@ -150,14 +127,14 @@ module.exports = function(pb) { return; } - self.queryService.loadById(vars.id, 'section', function(err, navItem) { + self.siteQueryService.loadById(vars.id, 'section', function(err, navItem) { if(!navItem || !navItem.item) { callback(err, navItem); return; } //TODO modify such that only the needed field of "headline" is returned. - self.queryService.loadById(navItem.item, navItem.type, function(err, articleOrPage) { + self.siteQueryService.loadById(navItem.item, navItem.type, function(err, articleOrPage) { if(articleOrPage) { navItem.contentSearchValue = articleOrPage.headline; } diff --git a/plugins/pencilblue/controllers/admin/content/navigation/nav_map.js b/plugins/pencilblue/controllers/admin/content/navigation/nav_map.js index 6a5034b4a..d8f26902e 100644 --- a/plugins/pencilblue/controllers/admin/content/navigation/nav_map.js +++ b/plugins/pencilblue/controllers/admin/content/navigation/nav_map.js @@ -20,36 +20,13 @@ module.exports = function(pb) { //pb dependencies var util = pb.util; var SectionService = pb.SectionService; - var SiteService = pb.SiteService; /** * Interface for editing the navigation */ function NavigationMap(){} - util.inherits(NavigationMap, pb.BaseController); + util.inherits(NavigationMap, pb.BaseAdminController); - NavigationMap.prototype.init = function (props, cb) { - var self = this; - pb.BaseController.prototype.init.call(self, props, function () { - self.pathSiteUId = pb.SiteService.getCurrentSite(self.pathVars.siteid); - pb.SiteService.siteExists(self.pathSiteUId, function (err, exists) { - if (!exists) { - self.reqHandler.serve404(); - } - else { - self.navService = new pb.SectionService(self.pathSiteUId, true); - self.sitePrefix = pb.SiteService.getCurrentSitePrefix(self.pathSiteUId); - self.queryService = new pb.SiteQueryService(self.pathSiteUId, true); - self.settings = pb.SettingServiceFactory.getServiceBySite(self.pathSiteUId, true); - var siteService = new pb.SiteService(); - siteService.getSiteNameByUid(self.pathSiteUId, function (siteName) { - self.siteName = siteName; - cb(); - }); - } - }); - }); - }; //statics var SUB_NAV_KEY = 'navigation_map'; @@ -59,7 +36,7 @@ module.exports = function(pb) { var opts = { where: pb.DAO.ANYWHERE }; - self.queryService.q('section', opts, function (err, sections) { + self.siteQueryService.q('section', opts, function (err, sections) { if (util.isError(err)) { return self.reqHandler.serveError(err); } diff --git a/plugins/pencilblue/controllers/admin/content/objects/manage_objects.js b/plugins/pencilblue/controllers/admin/content/objects/manage_objects.js index 45da43afe..820dca596 100644 --- a/plugins/pencilblue/controllers/admin/content/objects/manage_objects.js +++ b/plugins/pencilblue/controllers/admin/content/objects/manage_objects.js @@ -27,28 +27,7 @@ module.exports = function(pb) { * @extends BaseController */ function ManageObjects() {} - util.inherits(ManageObjects, pb.BaseController); - - ManageObjects.prototype.init = function (props, cb) { - var self = this; - - pb.BaseController.prototype.init.call(self, props, function() { - self.pathSiteUid = pb.SiteService.getCurrentSite(self.pathVars.siteid); - pb.SiteService.siteExists(self.pathSiteUid, function (err, exists) { - if (!exists) { - self.reqHandler.serve404(); - } - else { - self.pathSitePrefix = pb.SiteService.getCurrentSitePrefix(self.pathSiteUid); - var siteService = new pb.SiteService(); - siteService.getSiteNameByUid(self.pathSiteUid, function (siteName) { - self.siteName = siteName; - cb(); - }); - } - }); - }); - }; + util.inherits(ManageObjects, pb.BaseAdminController); //statics var SUB_NAV_KEY = 'manage_custom_objects'; @@ -61,7 +40,7 @@ module.exports = function(pb) { return this.reqHandler.serve404(); } - var service = new pb.CustomObjectService(self.pathSiteUid, true); + var service = new pb.CustomObjectService(self.pathSiteUId, true); service.loadTypeById(vars.type_id, function(err, custObjType) { if (util.isError(err)) { return self.serveError(err); diff --git a/plugins/pencilblue/controllers/admin/content/objects/object_form.js b/plugins/pencilblue/controllers/admin/content/objects/object_form.js index db55f043a..407b5bd4c 100644 --- a/plugins/pencilblue/controllers/admin/content/objects/object_form.js +++ b/plugins/pencilblue/controllers/admin/content/objects/object_form.js @@ -29,31 +29,10 @@ module.exports = function(pb) { * @constructor */ function ObjectFormController() {} - util.inherits(ObjectFormController, pb.BaseController); + util.inherits(ObjectFormController, pb.BaseAdminController); var SUB_NAV_KEY = 'object_form'; - ObjectFormController.prototype.init = function (props, cb) { - var self = this; - - pb.BaseController.prototype.init.call(self, props, function() { - self.pathSiteUid = pb.SiteService.getCurrentSite(self.pathVars.siteid); - pb.SiteService.siteExists(self.pathSiteUid, function (err, exists) { - if (!exists) { - self.reqHandler.serve404(); - } - else { - self.pathSitePrefix = pb.SiteService.getCurrentSitePrefix(self.pathSiteUid); - var siteService = new pb.SiteService(); - siteService.getSiteNameByUid(self.pathSiteUid, function (siteName) { - self.siteName = siteName; - cb(); - }); - } - }); - }); - }; - ObjectFormController.prototype.render = function(cb) { var self = this; var vars = this.pathVars; @@ -119,7 +98,7 @@ module.exports = function(pb) { ObjectFormController.prototype.gatherData = function(vars, cb) { var self = this; - var cos = new pb.CustomObjectService(self.pathSiteUid, true); + var cos = new pb.CustomObjectService(self.pathSiteUId, true); var tasks = { tabs: function(callback) { @@ -174,7 +153,6 @@ module.exports = function(pb) { var self = this; var keys = Object.keys(objectType.fields); var custObjTypes = {}; - var siteQueryService = new pb.SiteQueryService(); var userService = new pb.UserService(); //wrapper function to load cust object type @@ -232,7 +210,7 @@ module.exports = function(pb) { last_name: 1 } }; - siteQueryService.q(objectType.fields[key].object_type, query, function(err, availableObjects) { + self.siteQueryService.q(objectType.fields[key].object_type, query, function(err, availableObjects) { if (util.isError(err)) { return callback(err); } diff --git a/plugins/pencilblue/controllers/admin/content/objects/sort_objects.js b/plugins/pencilblue/controllers/admin/content/objects/sort_objects.js index d5a2b357e..fa856ade1 100644 --- a/plugins/pencilblue/controllers/admin/content/objects/sort_objects.js +++ b/plugins/pencilblue/controllers/admin/content/objects/sort_objects.js @@ -27,32 +27,11 @@ module.exports = function(pb) { * @extends BaseController */ function SortObjects() {} - util.inherits(SortObjects, pb.BaseController); + util.inherits(SortObjects, pb.BaseAdminController); //statics var SUB_NAV_KEY = 'sort_custom_objects'; - SortObjects.prototype.init = function (props, cb) { - var self = this; - - pb.BaseController.prototype.init.call(self, props, function() { - self.pathSiteUid = pb.SiteService.getCurrentSite(self.pathVars.siteid); - pb.SiteService.siteExists(self.pathSiteUid, function (err, exists) { - if (!exists) { - self.reqHandler.serve404(); - } - else { - self.pathSitePrefix = pb.SiteService.getCurrentSitePrefix(self.pathSiteUid); - var siteService = new pb.SiteService(); - siteService.getSiteNameByUid(self.pathSiteUid, function (siteName) { - self.siteName = siteName; - cb(); - }); - } - }); - }); - }; - SortObjects.prototype.render = function(cb) { var self = this; var vars = this.pathVars; @@ -60,7 +39,7 @@ module.exports = function(pb) { return this.reqHandler.serve404(); } - var service = new pb.CustomObjectService(self.pathSiteUid, true); + var service = new pb.CustomObjectService(self.pathSiteUId, true); service.loadTypeById(vars.type_id, function(err, objectType) { if(util.isError(err)) { return self.reqHandler.serveError(err); diff --git a/plugins/pencilblue/controllers/admin/content/objects/types/manage_types.js b/plugins/pencilblue/controllers/admin/content/objects/types/manage_types.js index 24c8aa8b2..fc2a8c72f 100644 --- a/plugins/pencilblue/controllers/admin/content/objects/types/manage_types.js +++ b/plugins/pencilblue/controllers/admin/content/objects/types/manage_types.js @@ -27,36 +27,15 @@ module.exports = function(pb) { * @extends BaseController */ function ManageObjectTypes() {} - util.inherits(ManageObjectTypes, pb.BaseController); + util.inherits(ManageObjectTypes, pb.BaseAdminController); //statics var SUB_NAV_KEY = 'manage_object_types'; - ManageObjectTypes.prototype.init = function (props, cb) { - var self = this; - - pb.BaseController.prototype.init.call(self, props, function() { - self.pathSiteUid = pb.SiteService.getCurrentSite(self.pathVars.siteid); - pb.SiteService.siteExists(self.pathSiteUid, function (err, exists) { - if (!exists) { - self.reqHandler.serve404(); - } - else { - self.pathSitePrefix = pb.SiteService.getCurrentSitePrefix(self.pathSiteUid); - var siteService = new pb.SiteService(); - siteService.getSiteNameByUid(self.pathSiteUid, function (siteName) { - self.siteName = siteName; - cb(); - }); - } - }); - }); - }; - ManageObjectTypes.prototype.render = function(cb) { var self = this; - var service = new pb.CustomObjectService(self.pathSiteUid, true); + var service = new pb.CustomObjectService(self.pathSiteUId, true); service.findTypes(function(err, custObjTypes) { //none to manage diff --git a/plugins/pencilblue/controllers/admin/content/objects/types/type_form.js b/plugins/pencilblue/controllers/admin/content/objects/types/type_form.js index c2279682a..cea3b39f3 100644 --- a/plugins/pencilblue/controllers/admin/content/objects/types/type_form.js +++ b/plugins/pencilblue/controllers/admin/content/objects/types/type_form.js @@ -27,32 +27,11 @@ module.exports = function(pb) { * Interface for creating and editing custom object types */ function TypeForm(){} - util.inherits(TypeForm, pb.BaseController); + util.inherits(TypeForm, pb.BaseAdminController); //statics var SUB_NAV_KEY = 'type_form'; - TypeForm.prototype.init = function (props, cb) { - var self = this; - - pb.BaseController.prototype.init.call(self, props, function() { - self.pathSiteUid = pb.SiteService.getCurrentSite(self.pathVars.siteid); - pb.SiteService.siteExists(self.pathSiteUid, function (err, exists) { - if (!exists) { - self.reqHandler.serve404(); - } - else { - self.pathSitePrefix = pb.SiteService.getCurrentSitePrefix(self.pathSiteUid); - var siteService = new pb.SiteService(); - siteService.getSiteNameByUid(self.pathSiteUid, function (siteName) { - self.siteName = siteName; - cb(); - }); - } - }); - }); - }; - TypeForm.prototype.render = function(cb) { var self = this; var vars = this.pathVars; @@ -82,7 +61,7 @@ module.exports = function(pb) { TypeForm.prototype.gatherData = function(vars, cb) { var self = this; - var cos = new pb.CustomObjectService(self.pathSiteUid, true); + var cos = new pb.CustomObjectService(self.pathSiteUId, true); var tasks = { tabs: function(callback) { diff --git a/plugins/pencilblue/controllers/admin/content/pages/manage_pages.js b/plugins/pencilblue/controllers/admin/content/pages/manage_pages.js index 0dc097bdf..ec5229309 100755 --- a/plugins/pencilblue/controllers/admin/content/pages/manage_pages.js +++ b/plugins/pencilblue/controllers/admin/content/pages/manage_pages.js @@ -24,15 +24,7 @@ module.exports = function(pb) { * Interface for managing pages */ function ManagePages(){} - util.inherits(ManagePages, pb.BaseController); - - ManagePages.prototype.init = function (props, cb) { - this.pathSiteUId = pb.SiteService.getCurrentSite(props.path_vars.siteid); - this.queryService = new pb.SiteQueryService(this.pathSiteUId, true); - this.sitePrefix = pb.SiteService.getCurrentSitePrefix(this.pathSiteUId); - - pb.BaseController.prototype.init.call(this, props, cb); - }; + util.inherits(ManagePages, pb.BaseAdminController); //statics var SUB_NAV_KEY = 'manage_pages'; @@ -45,7 +37,7 @@ module.exports = function(pb) { where: pb.DAO.ANYWHERE, order: {headline: pb.DAO.ASC} }; - self.queryService.q('page', opts, function(err, pages) { + self.siteQueryService.q('page', opts, function(err, pages) { if (util.isError(err)) { return self.reqHandler.serveError(err); } diff --git a/plugins/pencilblue/controllers/admin/content/pages/page_form.js b/plugins/pencilblue/controllers/admin/content/pages/page_form.js index 13967b351..df09b0d23 100755 --- a/plugins/pencilblue/controllers/admin/content/pages/page_form.js +++ b/plugins/pencilblue/controllers/admin/content/pages/page_form.js @@ -27,28 +27,7 @@ module.exports = function(pb) { * Interface for creating and editing pages */ function PageFormController(){} - util.inherits(PageFormController, pb.BaseController); - - PageFormController.prototype.init = function (props, cb) { - var self = this; - pb.BaseController.prototype.init.call(self, props, function () { - self.pathSiteUId = pb.SiteService.getCurrentSite(self.pathVars.siteid); - pb.SiteService.siteExists(self.pathSiteUId, function (err, exists) { - if (!exists) { - self.reqHandler.serve404(); - } - else { - self.sitePrefix = pb.SiteService.getCurrentSitePrefix(self.pathSiteUId); - self.queryService = new pb.SiteQueryService(self.pathSiteUId, true); - var siteService = new pb.SiteService(); - siteService.getSiteNameByUid(self.pathSiteUId, function (siteName) { - self.siteName = siteName; - cb(); - }); - } - }); - }); - }; + util.inherits(PageFormController, pb.BaseAdminController); PageFormController.prototype.render = function(cb) { var self = this; @@ -215,7 +194,7 @@ module.exports = function(pb) { }, order: {name: pb.DAO.ASC} }; - self.queryService.q('section', opts, callback); + self.siteQueryService.q('section', opts, callback); }, topics: function(callback) { @@ -224,7 +203,7 @@ module.exports = function(pb) { where: pb.DAO.ANYWHERE, order: {name: pb.DAO.ASC} }; - self.queryService.q('topic', opts, callback); + self.siteQueryService.q('topic', opts, callback); }, media: function(callback) { @@ -238,7 +217,7 @@ module.exports = function(pb) { return; } - self.queryService.loadById(vars.id, 'page', callback); + self.siteQueryService.loadById(vars.id, 'page', callback); } }; async.parallelLimit(tasks, 2, cb); diff --git a/plugins/pencilblue/controllers/admin/content/topics/import_topics.js b/plugins/pencilblue/controllers/admin/content/topics/import_topics.js index 981dcba5c..79f0c3fcc 100755 --- a/plugins/pencilblue/controllers/admin/content/topics/import_topics.js +++ b/plugins/pencilblue/controllers/admin/content/topics/import_topics.js @@ -24,28 +24,7 @@ module.exports = function(pb) { * Interface for importing topics from CSV */ function ImportTopics(){} - util.inherits(ImportTopics, pb.BaseController); - - ImportTopics.prototype.init = function (props, cb) { - var self = this; - pb.BaseController.prototype.init.call(self, props, function () { - self.pathSiteUId = pb.SiteService.getCurrentSite(self.pathVars.siteid); - pb.SiteService.siteExists(self.pathSiteUId, function (err, exists) { - if (!exists) { - self.reqHandler.serve404(); - } - else { - self.sitePrefix = pb.SiteService.getCurrentSitePrefix(self.pathSiteUId); - self.queryService = new pb.SiteQueryService(self.pathSiteUId, true); - var siteService = new pb.SiteService(); - siteService.getSiteNameByUid(self.pathSiteUId, function (siteName) { - self.siteName = siteName; - cb(); - }); - } - }); - }); - }; + util.inherits(ImportTopics, pb.BaseAdminController); //statics var SUB_NAV_KEY = 'import_topics'; diff --git a/plugins/pencilblue/controllers/admin/content/topics/manage_topics.js b/plugins/pencilblue/controllers/admin/content/topics/manage_topics.js index d058427cd..712da5fca 100755 --- a/plugins/pencilblue/controllers/admin/content/topics/manage_topics.js +++ b/plugins/pencilblue/controllers/admin/content/topics/manage_topics.js @@ -24,28 +24,7 @@ module.exports = function(pb) { * Interface for managing topics */ function ManageTopics() {} - util.inherits(ManageTopics, pb.BaseController); - - ManageTopics.prototype.init = function (props, cb) { - var self = this; - pb.BaseController.prototype.init.call(self, props, function () { - self.pathSiteUId = pb.SiteService.getCurrentSite(self.pathVars.siteid); - pb.SiteService.siteExists(self.pathSiteUId, function (err, exists) { - if (!exists) { - self.reqHandler.serve404(); - } - else { - self.sitePrefix = pb.SiteService.getCurrentSitePrefix(self.pathSiteUId); - self.queryService = new pb.SiteQueryService(self.pathSiteUId, true); - var siteService = new pb.SiteService(); - siteService.getSiteNameByUid(self.pathSiteUId, function (siteName) { - self.siteName = siteName; - cb(); - }); - } - }); - }); - }; + util.inherits(ManageTopics, pb.BaseAdminController); var SUB_NAV_KEY = 'manage_topics'; @@ -56,7 +35,7 @@ module.exports = function(pb) { select: pb.DAO.PROJECT_ALL, where: pb.DAO.ANYWHERE }; - self.queryService.q('topic', opts, function (err, topics) { + self.siteQueryService.q('topic', opts, function (err, topics) { if (util.isError(err)) { self.reqHandler.serveError(err); } diff --git a/plugins/pencilblue/controllers/admin/content/topics/topic_form.js b/plugins/pencilblue/controllers/admin/content/topics/topic_form.js index b61270e10..ff7ed4df6 100644 --- a/plugins/pencilblue/controllers/admin/content/topics/topic_form.js +++ b/plugins/pencilblue/controllers/admin/content/topics/topic_form.js @@ -27,29 +27,7 @@ module.exports = function(pb) { * Interface for creating and editing topics */ function TopicForm(){} - util.inherits(TopicForm, pb.BaseController); - - TopicForm.prototype.init = function (props, cb) { - var self = this; - pb.BaseController.prototype.init.call(self, props, function () { - self.pathSiteUId = pb.SiteService.getCurrentSite(self.pathVars.siteid); - pb.SiteService.siteExists(self.pathSiteUId, function (err, exists) { - if (!exists) { - self.reqHandler.serve404(); - } - else { - self.sitePrefix = pb.SiteService.getCurrentSitePrefix(self.pathSiteUId); - self.queryService = new pb.SiteQueryService(self.pathSiteUId, true); - self.settings = pb.SettingServiceFactory.getServiceBySite(self.pathSiteUId, true); - var siteService = new pb.SiteService(); - siteService.getSiteNameByUid(self.pathSiteUId, function (siteName) { - self.siteName = siteName; - cb(); - }); - } - }); - }); - }; + util.inherits(TopicForm, pb.BaseAdminController); //statics var SUB_NAV_KEY = 'topic_form'; @@ -108,7 +86,7 @@ module.exports = function(pb) { return; } - self.queryService.loadById(vars.id, 'topic', function(err, topic) { + self.siteQueryService.loadById(vars.id, 'topic', function(err, topic) { callback(err, topic); }); } diff --git a/plugins/pencilblue/controllers/admin/plugins/plugin_settings.js b/plugins/pencilblue/controllers/admin/plugins/plugin_settings.js index be07c1486..ed1dac6ea 100755 --- a/plugins/pencilblue/controllers/admin/plugins/plugin_settings.js +++ b/plugins/pencilblue/controllers/admin/plugins/plugin_settings.js @@ -19,7 +19,6 @@ module.exports = function(pb) { //pb dependencies var util = pb.util; - var BaseController = pb.BaseController; /** * Interface for changing a plugin's settings @@ -36,18 +35,19 @@ module.exports = function(pb) { */ this.pluginService = new pb.PluginService(); } - util.inherits(PluginSettingsFormController, BaseController); + util.inherits(PluginSettingsFormController, pb.BaseAdminController); + + PluginSettingsFormController.prototype.init = function (props, cb) { + var self = this; + pb.BaseAdminController.prototype.init.call(self, props, function () { + self.pluginService = new pb.PluginService(self.pathSiteUId); + cb(); + }); + }; //statics var SUB_NAV_KEY = 'plugin_settings'; - PluginSettingsFormController.prototype.init = function (props, cb) { - this.pathSiteUId = pb.SiteService.getCurrentSite(props.path_vars.siteid); - this.pluginService = new pb.PluginService(this.pathSiteUId); - - pb.BaseController.prototype.init.call(this, props, cb); - }; - PluginSettingsFormController.prototype.get = function(cb) { var self = this; diff --git a/plugins/pencilblue/controllers/admin/site_settings/configuration.js b/plugins/pencilblue/controllers/admin/site_settings/configuration.js index 68ed2c18b..ceac9093b 100755 --- a/plugins/pencilblue/controllers/admin/site_settings/configuration.js +++ b/plugins/pencilblue/controllers/admin/site_settings/configuration.js @@ -27,31 +27,11 @@ module.exports = function(pb) { * Interface for displaying the site's configuration settings */ function Configuration(){} - util.inherits(Configuration, pb.BaseController); + util.inherits(Configuration, pb.BaseAdminController); //statics var SUB_NAV_KEY = 'site_configuration'; - Configuration.prototype.init = function (props, cb) { - var self = this; - pb.BaseController.prototype.init.call(self, props, function () { - self.pathSiteUId = pb.SiteService.getCurrentSite(self.pathVars.siteid); - var siteService = new pb.SiteService(); - siteService.getByUid(self.pathSiteUId, function(err, site) { - if (!site) { - self.reqHandler.serve404(); - } - else { - self.sitePrefix = pb.SiteService.getCurrentSitePrefix(self.pathSiteUId); - self.siteObj = site; - self.isGlobalSite = site.uid === pb.SiteService.GLOBAL_SITE; - self.siteName = self.isGlobalSite ? site.uid : site.displayName; - cb(); - } - }); - }); - }; - Configuration.prototype.render = function(cb) { var self = this; diff --git a/plugins/pencilblue/controllers/admin/site_settings/libraries.js b/plugins/pencilblue/controllers/admin/site_settings/libraries.js index c3e4bcc8b..7da7e4e05 100644 --- a/plugins/pencilblue/controllers/admin/site_settings/libraries.js +++ b/plugins/pencilblue/controllers/admin/site_settings/libraries.js @@ -24,20 +24,11 @@ module.exports = function(pb) { * Interface for the site's libraries settings */ function Libraries(){} - util.inherits(Libraries, pb.BaseController); + util.inherits(Libraries, pb.BaseAdminController); //statics var SUB_NAV_KEY = 'libraries_settings'; - Libraries.prototype.init = function (props, cb) { - var self = this; - pb.BaseController.prototype.init.call(self, props, function () { - self.sitePrefix = pb.SiteService.getCurrentSitePrefix(pb.SiteService.GLOBAL_SITE); - self.siteName = pb.SiteService.GLOBAL_SITE; - cb(); - }); - }; - Libraries.prototype.render = function(cb) { var self = this; diff --git a/plugins/pencilblue/controllers/api/admin/content/media/get_preview.js b/plugins/pencilblue/controllers/api/admin/content/media/get_preview.js index 4b69d3ebf..bc485914a 100644 --- a/plugins/pencilblue/controllers/api/admin/content/media/get_preview.js +++ b/plugins/pencilblue/controllers/api/admin/content/media/get_preview.js @@ -27,17 +27,7 @@ module.exports = function(pb) { * @extends BaseController */ function GetMediaPreviewApiController(){} - util.inherits(GetMediaPreviewApiController, pb.BaseController); - - GetMediaPreviewApiController.prototype.init = function (props, cb) { - var self = this; - pb.BaseController.prototype.init.call(self, props, function () { - self.pathSiteUId = pb.SiteService.getCurrentSite(self.pathVars.siteid); - self.sitePrefix = pb.SiteService.getCurrentSitePrefix(self.pathSiteUId); - self.mediaService = new pb.MediaService(null, self.pathSiteUId, true); - cb(); - }); - }; + util.inherits(GetMediaPreviewApiController, pb.BaseAdminController); /** * Renders the preview @@ -60,19 +50,20 @@ module.exports = function(pb) { var options = { view: 'view' }; + var mediaService = new pb.MediaService(null, self.pathSiteUId, true); if (get.id) { - self.mediaService.renderById(get.id, options, function(err, html) { + mediaService.renderById(get.id, options, function(err, html) { self.renderComplete(err, html, cb); }); } else if (get.location && get.type){ - var options = { + var renderOptions = { view: 'view', location: get.location, type: get.type }; - self.mediaService.renderByLocation(options, function(err, html) { + mediaService.renderByLocation(renderOptions, function(err, html) { self.renderComplete(err, html, cb); }); } diff --git a/plugins/pencilblue/controllers/api/admin/content/objects/types/available.js b/plugins/pencilblue/controllers/api/admin/content/objects/types/available.js index ca6be5dbb..861b9eeca 100644 --- a/plugins/pencilblue/controllers/api/admin/content/objects/types/available.js +++ b/plugins/pencilblue/controllers/api/admin/content/objects/types/available.js @@ -27,19 +27,7 @@ module.exports = function(pb) { util.inherits(GetObjectTypeNameAvailable, pb.FormController); GetObjectTypeNameAvailable.prototype.init = function (props, cb) { - var self = this; - - pb.BaseController.prototype.init.call(self, props, function() { - self.pathSiteUid = pb.SiteService.getCurrentSite(self.pathVars.siteid); - pb.SiteService.siteExists(self.pathSiteUid, function (err, exists) { - if (!exists) { - self.reqHandler.serve404(); - } - else { - cb(); - } - }); - }); + pb.BaseAdminController.overrideInit(this, props, cb); }; GetObjectTypeNameAvailable.prototype.render = function(cb) { @@ -53,7 +41,7 @@ module.exports = function(pb) { }); } - var service = new pb.CustomObjectService(self.pathSiteUid, true); + var service = new pb.CustomObjectService(self.pathSiteUId, true); service.typeExists(get.name, function(err, exists) { if (util.isError(err)) { return cb({content: pb.BaseController.apiResponse(pb.BaseController.API_FAILURE, err.stack, false)}); diff --git a/plugins/pencilblue/controllers/api/comments/new_comment.js b/plugins/pencilblue/controllers/api/comments/new_comment.js index 356f42ba6..bc0704400 100755 --- a/plugins/pencilblue/controllers/api/comments/new_comment.js +++ b/plugins/pencilblue/controllers/api/comments/new_comment.js @@ -28,12 +28,7 @@ module.exports = function NewCommentModule(pb) { util.inherits(NewComment, pb.FormController); NewComment.prototype.init = function (props, cb) { - var self = this; - pb.BaseController.prototype.init.call(self, props, function () { - self.siteUId = pb.SiteService.getCurrentSite(self.site); - self.queryService = new pb.SiteQueryService(self.siteUId); - cb(); - }); + pb.BaseAdminController.overrideInit(this, props, cb); }; NewComment.prototype.onPostParamsRetrieved = function(post, cb) { @@ -52,7 +47,7 @@ module.exports = function NewCommentModule(pb) { return; } - self.queryService.loadById(post.article, 'article', function(err, article) { + self.siteQueryService.loadById(post.article, 'article', function(err, article) { if(util.isError(err) || article == null) { cb({content: BaseController.apiResponse(BaseController.API_FAILURE, 'article does not exist'), code: 400}); return; @@ -61,7 +56,7 @@ module.exports = function NewCommentModule(pb) { var commentDocument = pb.DocumentCreator.create('comment', post); commentDocument.commenter = self.session.authentication.user_id; - self.queryService.save(commentDocument, function(err, data) { + self.siteQueryService.save(commentDocument, function(err, data) { if (util.isError(err)) { return cb({content: BaseController.apiResponse(BaseController.API_FAILURE, 'error saving'), code: 500}); } diff --git a/plugins/pencilblue/controllers/section.js b/plugins/pencilblue/controllers/section.js index 9bb121569..e96186ee7 100755 --- a/plugins/pencilblue/controllers/section.js +++ b/plugins/pencilblue/controllers/section.js @@ -31,8 +31,8 @@ module.exports = function SectionModule(pb) { var self = this; pb.BaseController.prototype.init.call(self, props, function () { self.siteUId = pb.SiteService.getCurrentSite(self.site); - self.navService = new pb.SectionService(self.pathSiteUId); - self.queryService = new pb.SiteQueryService(self.siteUId); + self.sectionService = new pb.SectionService(self.pathSiteUId); + self.siteQueryService = new pb.SiteQueryService(self.siteUId); cb(); }); }; @@ -40,14 +40,14 @@ module.exports = function SectionModule(pb) { Section.prototype.render = function(cb) { var self = this; var custUrl = this.pathVars.customUrl; - self.queryService.loadByValue('url', custUrl, 'section', function(err, section) { + self.siteQueryService.loadByValue('url', custUrl, 'section', function(err, section) { if (util.isError(err) || section == null) { self.reqHandler.serve404(); return; } self.req.pencilblue_section = section[pb.DAO.getIdField()].toString(); - this.section = section; + self.section = section; Section.super_.prototype.render.apply(self, [cb]); }); }; diff --git a/plugins/portfolio/controllers/index.js b/plugins/portfolio/controllers/index.js index 44347fffb..1cdb79b18 100755 --- a/plugins/portfolio/controllers/index.js +++ b/plugins/portfolio/controllers/index.js @@ -38,9 +38,7 @@ module.exports = function IndexModule(pb) { Index.prototype.init = function (props, cb) { var self = this; pb.BaseController.prototype.init.call(self, props, function () { - self.siteUId = pb.SiteService.getCurrentSite(self.site); - self.navService = new pb.SectionService(self.pathSiteUId); - self.queryService = new pb.SiteQueryService(self.siteUId); + self.siteQueryService = new pb.SiteQueryService(self.site); cb(); }); }; @@ -71,7 +69,7 @@ module.exports = function IndexModule(pb) { TopMenu.getTopMenu(self.session, self.ls, options, function(themeSettings, navigation, accountButtons) { TopMenu.getBootstrapNav(navigation, accountButtons, function(navigation, accountButtons) { - var pluginService = new pb.PluginService(self.site); + var pluginService = new PluginService(self.site); pluginService.getSettings('portfolio', function(err, portfolioSettings) { var homePageKeywords = ''; var homePageDescription = ''; @@ -106,7 +104,7 @@ module.exports = function IndexModule(pb) { var opts = { where: {settings_type: 'home_page'} }; - self.queryService.q('portfolio_theme_settings', opts, function(err, settings) { + self.siteQueryService.q('portfolio_theme_settings', opts, function(err, settings) { if (util.isError(err)) { self.reqHandler.serveError(err); } From 619a89d72a531ce16da3f1cc2b4001254ab03cba Mon Sep 17 00:00:00 2001 From: btidwell Date: Tue, 19 May 2015 08:53:23 -0400 Subject: [PATCH 155/790] Merge branch 'multi_tenancy' into portfolio-mt Conflicts: plugins/portfolio/controllers/index.js --- controllers/base_controller.js | 2 +- include/admin_navigation.js | 2 +- include/content.js | 2 +- include/service/db_entity_service.js | 4 +- include/service/entities/article_service.js | 9 ++-- include/service/entities/media_service.js | 49 ++++++------------- include/service/entities/template_service.js | 46 +++++++++++------ include/system/settings.js | 7 ++- include/theme/top_menu.js | 13 +++-- .../content/navigation/delete_nav_item.js | 7 ++- .../admin/content/navigation/edit_nav_item.js | 5 +- .../admin/content/navigation/new_nav_item.js | 2 +- .../admin/content/topics/edit_topic.js | 2 +- .../admin/content/topics/import_topics.js | 2 +- .../actions/admin/content/topics/new_topic.js | 2 +- .../actions/admin/site_settings/content.js | 19 ++++++- .../actions/admin/themes/site_logo.js | 24 ++++++++- .../controllers/actions/user/sign_up.js | 4 +- .../admin/content/articles/article_form.js | 9 ++-- .../admin/content/articles/manage_articles.js | 2 +- .../admin/content/comments/manage_comments.js | 4 +- .../admin/content/media/manage_media.js | 5 +- .../admin/content/media/media_form.js | 9 ++-- .../admin/content/navigation/nav_item_form.js | 4 +- .../admin/content/navigation/nav_map.js | 2 +- .../admin/content/pages/manage_pages.js | 2 +- .../admin/content/pages/page_form.js | 9 ++-- .../admin/content/topics/import_topics.js | 2 +- .../admin/content/topics/manage_topics.js | 2 +- .../admin/content/topics/topic_form.js | 5 +- .../admin/site_settings/content.js | 37 +++++++++++--- .../api/admin/content/media/get_preview.js | 15 ++++-- .../controllers/api/content/get_articles.js | 6 +-- .../controllers/api/content/search.js | 4 +- plugins/pencilblue/controllers/feed.js | 2 +- plugins/pencilblue/controllers/index.js | 4 +- .../controllers/user/resend_verification.js | 2 +- .../pencilblue/controllers/user/sign_up.js | 2 +- .../controllers/user/verification_sent.js | 2 +- .../admin/content/media/media_form.html | 2 +- .../angular/admin/site_settings/content.html | 2 +- .../angular/admin/themes/manage_themes.html | 2 +- plugins/portfolio/controllers/index.js | 17 ++++++- 43 files changed, 221 insertions(+), 132 deletions(-) diff --git a/controllers/base_controller.js b/controllers/base_controller.js index 4e0089814..73f57e347 100755 --- a/controllers/base_controller.js +++ b/controllers/base_controller.js @@ -105,7 +105,7 @@ module.exports = function BaseControllerModule(pb) { this.site = props.site; var self = this; - this.templateService = new pb.TemplateService(this.localizationService); + this.templateService = new pb.TemplateService(this.localizationService, this.site); this.templateService.registerLocal('locale', this.ls.language); this.templateService.registerLocal('error_success', function(flag, cb) { self.displayErrorOrSuccessCallback(flag, cb); diff --git a/include/admin_navigation.js b/include/admin_navigation.js index 04075b8ea..31236da8e 100755 --- a/include/admin_navigation.js +++ b/include/admin_navigation.js @@ -205,7 +205,7 @@ module.exports = function AdminNavigationModule(pb) { id: 'content_settings', title: 'CONTENT', icon: 'quote-right', - href: '/admin/site_settings/content', + href: adminPath + '/site_settings/content', access: SecurityService.ACCESS_MANAGING_EDITOR }, { diff --git a/include/content.js b/include/content.js index 598ac275f..0e3c1a3b8 100755 --- a/include/content.js +++ b/include/content.js @@ -113,7 +113,7 @@ module.exports = function ContentServiceModule(pb) { twoDigitDate: contentSettings.two_digit_date, displayTime: contentSettings.display_hours_minutes, timeFormat: contentSettings.time_format, - twoDigitDate: contentSettings.two_digit_time, + twoDigitTime: contentSettings.two_digit_time, ls: ls }; return ContentService.getTimestampText(options); diff --git a/include/service/db_entity_service.js b/include/service/db_entity_service.js index 5f57ab356..cd5667aa5 100755 --- a/include/service/db_entity_service.js +++ b/include/service/db_entity_service.js @@ -72,9 +72,9 @@ module.exports = function DbEntityServiceModule(pb) { cb(null, val); }; if(this.onlyThisSite) { - dao.loadByValueForOneSite(this.keyField, key, this.site, this.objType, callback); + dao.loadByValueForOneSite(this.keyField, key, this.site, this.objType, null, callback); } else { - dao.loadByValueAvailableToSite(this.keyField, key, this.site, this.objType, callback); + dao.loadByValueAvailableToSite(this.keyField, key, this.site, this.objType, null, callback); } }; diff --git a/include/service/entities/article_service.js b/include/service/entities/article_service.js index f4732203a..ca04beca8 100755 --- a/include/service/entities/article_service.js +++ b/include/service/entities/article_service.js @@ -33,8 +33,10 @@ module.exports = function ArticleServiceModule(pb) { * @constructor * */ - function ArticleService(){ + function ArticleService(siteUid, onlyThisSite){ this.object_type = 'article'; + this.site = pb.SiteService.getCurrentSite(siteUid); + this.siteQueryService = new pb.SiteQueryService(this.site, onlyThisSite); } /** @@ -161,8 +163,7 @@ module.exports = function ArticleServiceModule(pb) { } var self = this; - var dao = new pb.DAO(); - dao.q(this.getContentType(), {where: where, select: select, order: order, limit: limit, offset: offset}, function(err, articles) { + self.siteQueryService.q(this.getContentType(), {where: where, select: select, order: order, limit: limit, offset: offset}, function(err, articles) { if (util.isError(err)) { return cb(err, []); } @@ -173,7 +174,7 @@ module.exports = function ArticleServiceModule(pb) { //get authors self.getArticleAuthors(articles, function(err, authors) { - var contentService = new pb.ContentService(); + var contentService = new pb.ContentService(self.site); contentService.getSettings(function(err, contentSettings) { var tasks = util.getTasks(articles, function(articles, i) { diff --git a/include/service/entities/media_service.js b/include/service/entities/media_service.js index 16c56dfec..3f87d9422 100755 --- a/include/service/entities/media_service.js +++ b/include/service/entities/media_service.js @@ -31,9 +31,14 @@ module.exports = function MediaServiceModule(pb) { * @submodule Entities * @class MediaService * @constructor - */ - function MediaService(provider, site){ - this.site = site; + * @param provider + * @param site Site uid to be used for this service + * @param onlyThisSite Whether this service should only return media associated with specified site + * or fallback to global if not found in specified site + */ + function MediaService(provider, site, onlyThisSite) { + this.site = pb.SiteService.getCurrentSite(site); + this.queryService = new pb.SiteQueryService(site, onlyThisSite); if (util.isNullOrUndefined(provider)) { provider = MediaService.loadMediaProvider(); } @@ -96,8 +101,7 @@ module.exports = function MediaServiceModule(pb) { * occurred and a media descriptor if found. */ MediaService.prototype.loadById = function(mid, cb) { - var dao = new pb.DAO(); - dao.loadById(mid.toString(), MediaService.COLL, cb); + this.queryService.loadById(mid.toString(), MediaService.COLL, cb); }; /** @@ -114,8 +118,7 @@ module.exports = function MediaServiceModule(pb) { } var self = this; - var dao = new pb.DAO(); - dao.deleteById(mid, MediaService.COLL, cb); + this.queryService.deleteById(mid, MediaService.COLL, cb); }; /** @@ -132,7 +135,7 @@ module.exports = function MediaServiceModule(pb) { } var self = this; - this.validate(media, function(err, validationErrors) { + self.validate(media, function(err, validationErrors) { if (util.isError(err)) { return cb(err); } @@ -140,8 +143,7 @@ module.exports = function MediaServiceModule(pb) { return cb(null, validationErrors); } - var dao = new pb.DAO(); - dao.save(media, cb); + self.queryService.save(media, cb); }); }; @@ -161,9 +163,8 @@ module.exports = function MediaServiceModule(pb) { } //ensure the media name is unique - var where = { name: media.name, site: this.site }; - var dao = new pb.DAO(); - dao.unique(MediaService.COLL, where, media[pb.DAO.getIdField()], function(err, isUnique) { + var where = { name: media.name }; + this.queryService.unique(MediaService.COLL, where, media[pb.DAO.getIdField()], function(err, isUnique) { if(util.isError(err)) { return cb(err, errors); } @@ -196,8 +197,7 @@ module.exports = function MediaServiceModule(pb) { }; } - var dao = new pb.DAO(); - dao.q('media', options, function(err, media) { + this.queryService.q('media', options, function (err, media) { if (util.isError(err)) { return cb(err, []); } @@ -210,22 +210,6 @@ module.exports = function MediaServiceModule(pb) { }); }; - /** - * Queries for media descriptors by site - * @method getBySite - * @param {String} site - * @param {Function} cb - */ - - MediaService.prototype.getBySite = function(site, cb) { - var options = { - format_media: true, - where: {site: site}, - order: {name:1} - }; - this.get(options, cb); - }; - /** * * @method getContentByPath @@ -487,8 +471,7 @@ module.exports = function MediaServiceModule(pb) { MediaService.prototype.renderById = function(id, options, cb) { var self = this; - var dao = new pb.DAO(); - dao.loadById(id, MediaService.COLL, function(err, media) { + self.queryService.loadById(id, MediaService.COLL, function (err, media) { if (util.isError(err)) { return cb(err); } diff --git a/include/service/entities/template_service.js b/include/service/entities/template_service.js index ff9cac473..c479c957d 100755 --- a/include/service/entities/template_service.js +++ b/include/service/entities/template_service.js @@ -37,8 +37,9 @@ module.exports = function(pb) { * @module Services * @submodule Entities * @param {Object} [localizationService] The localization service object + * @param {String} siteUid context site for this service */ - function TemplateService(localizationService){ + function TemplateService(localizationService, siteUid) { this.localCallbacks = { year: (new Date()).getFullYear() }; @@ -89,12 +90,17 @@ module.exports = function(pb) { * @type {Function} */ this.unregisteredFlagHandler = null; - + + this.siteUid = pb.SiteService.getCurrentSite(siteUid); + this.settingService = pb.SettingServiceFactory.getServiceBySite(this.siteUid); + /** * @property pluginService * @type {PluginService} */ - this.pluginService = new pb.PluginService(); + this.pluginService = new pb.PluginService(this.siteUid); + + this.init(); } //constants @@ -120,16 +126,7 @@ module.exports = function(pb) { var GLOBAL_CALLBACKS = { site_root: pb.config.siteRoot, site_name: pb.config.siteName, - site_logo: function(flag, callback) { - pb.settings.get('site_logo', function(err, logo) { - callback(null, logo ? logo : '/img/pb_logo.png'); - }); - }, site_menu_logo: '/img/logo_menu.png', - site_icon: function(flag, callback) { - var pluginService = new pb.PluginService(); - pluginService.getActiveIcon(callback); - }, version: pb.config.version }; @@ -142,6 +139,27 @@ module.exports = function(pb) { cb(null, '^'+flag+'^'); }; + /** + * Sets up the default flags required for the template service, + * including the flags that were previously considered to be global but + * now requires to be instanced with the TemplateService + * + * @method init + */ + TemplateService.prototype.init = function () { + var self = this; + + self.registerLocal('site_logo', function (err, callback) { + self.settingService.get('site_logo', function (err, logo) { + callback(err, logo || '/img/pb_logo.png'); + }); + }); + + self.registerLocal('site_icon', function (err, callback) { + self.pluginService.getActiveIcon(callback); + }); + }; + /** * Sets the prioritized theme to use when loading templates * @@ -233,7 +251,7 @@ module.exports = function(pb) { if (hintedTheme) { paths.push(TemplateService.getCustomPath(this.getTheme(), relativePath)); } - pb.settings.get('active_theme', function(err, activeTheme){ + self.settingService.get('active_theme', function(err, activeTheme){ if (activeTheme !== null) { paths.push(TemplateService.getCustomPath(activeTheme, relativePath)); } @@ -499,7 +517,7 @@ module.exports = function(pb) { TemplateService.prototype.getTemplatesForActiveTheme = function(cb) { var self = this; - pb.settings.get('active_theme', function(err, activeTheme) { + self.settingService.get('active_theme', function(err, activeTheme) { if(util.isError(err) || activeTheme == null) { cb(err, []); return; diff --git a/include/system/settings.js b/include/system/settings.js index 9072611f8..10552ecc1 100755 --- a/include/system/settings.js +++ b/include/system/settings.js @@ -42,10 +42,13 @@ module.exports = function SettingsModule(pb) { * @static * @method getServiceBySite * @param {String} site - * @param {Boolean} onlyThisSite + * @param {Boolean=} onlyThisSite */ SettingServiceFactory.getServiceBySite = function (site, onlyThisSite) { - return SettingServiceFactory.getService(pb.config.settings.use_memory, pb.config.settings.use_cache, site, onlyThisSite); + if (pb.config.multisite) { + return SettingServiceFactory.getService(pb.config.settings.use_memory, pb.config.settings.use_cache, site, onlyThisSite); + } + return SettingServiceFactory.getService(pb.config.settings.use_memory, pb.config.settings.use_cache); }; /** diff --git a/include/theme/top_menu.js b/include/theme/top_menu.js index af193abe9..06b045170 100755 --- a/include/theme/top_menu.js +++ b/include/theme/top_menu.js @@ -79,7 +79,7 @@ module.exports = function TopMenuServiceModule(pb) { }, accountButtons: function(callback) { - TopMenuService.getAccountButtons(session, localizationService, callback); + TopMenuService.getAccountButtons(session, localizationService, options.site, callback); } }; async.parallel(tasks, function(err, result) { @@ -95,10 +95,17 @@ module.exports = function TopMenuServiceModule(pb) { * @method getAccountButtons * @param {Object} session * @param {Object} ls The localization service + * @param {String} site The current site * @param {Function} cb Callback function */ - TopMenuService.getAccountButtons = function(session, ls, cb) { - var contentService = new pb.ContentService(); + TopMenuService.getAccountButtons = function(session, ls, site, cb) { + + if (util.isFunction(site)) { + cb = site; + site = pb.siteService.GLOBAL_SITE; + } + + var contentService = new pb.ContentService(site); contentService.getSettings(function(err, contentSettings) { if (util.isError(err)) { return cb(err); diff --git a/plugins/pencilblue/controllers/actions/admin/content/navigation/delete_nav_item.js b/plugins/pencilblue/controllers/actions/admin/content/navigation/delete_nav_item.js index 39ca5a5a0..08eaa4bb9 100644 --- a/plugins/pencilblue/controllers/actions/admin/content/navigation/delete_nav_item.js +++ b/plugins/pencilblue/controllers/actions/admin/content/navigation/delete_nav_item.js @@ -37,7 +37,7 @@ module.exports = function(pb) { else { self.navService = new pb.SectionService(self.pathSiteUId, true); self.sitePrefix = pb.SiteService.getCurrentSitePrefix(self.pathSiteUId); - self.queryService = new pb.SiteQueryService(self.pathSiteUId); + self.queryService = new pb.SiteQueryService(self.pathSiteUId, true); self.settings = pb.SettingServiceFactory.getServiceBySite(self.pathSiteUId, true); var siteService = new pb.SiteService(); siteService.getSiteNameByUid(self.pathSiteUId, function (siteName) { @@ -63,8 +63,7 @@ module.exports = function(pb) { } //ensure existence - var dao = new pb.DAO(); - dao.loadById(vars.id, 'section', function(err, section) { + self.queryService.loadById(vars.id, 'section', function(err, section) { if(section === null) { cb({ code: 400, @@ -82,7 +81,7 @@ module.exports = function(pb) { } ] }; - dao.delete(where, 'section', function(err, result) { + self.queryService.delete(where, 'section', function(err, result) { if(util.isError(err) || result < 1) { return cb({ code: 500, diff --git a/plugins/pencilblue/controllers/actions/admin/content/navigation/edit_nav_item.js b/plugins/pencilblue/controllers/actions/admin/content/navigation/edit_nav_item.js index f0fd15e56..7c3a6b41c 100644 --- a/plugins/pencilblue/controllers/actions/admin/content/navigation/edit_nav_item.js +++ b/plugins/pencilblue/controllers/actions/admin/content/navigation/edit_nav_item.js @@ -37,7 +37,7 @@ module.exports = function(pb) { else { self.navService = new pb.SectionService(self.pathSiteUId, true); self.sitePrefix = pb.SiteService.getCurrentSitePrefix(self.pathSiteUId); - self.queryService = new pb.SiteQueryService(self.pathSiteUId); + self.queryService = new pb.SiteQueryService(self.pathSiteUId, true); self.settings = pb.SettingServiceFactory.getServiceBySite(self.pathSiteUId, true); var siteService = new pb.SiteService(); siteService.getSiteNameByUid(self.pathSiteUId, function (siteName) { @@ -52,7 +52,6 @@ module.exports = function(pb) { EditNavItem.prototype.render = function(cb){ var self = this; var vars = this.pathVars; - var dao = new pb.DAO(); var message = this.hasRequiredParams(vars, ['id']); if (message) { @@ -65,7 +64,7 @@ module.exports = function(pb) { this.getJSONPostParams(function(err, post) { //load object - dao.loadById(vars.id, 'section', function(err, navItem) { + self.queryService.loadById(vars.id, 'section', function(err, navItem) { if(util.isError(err) || !util.isObject(navItem)) { cb({ code: 400, diff --git a/plugins/pencilblue/controllers/actions/admin/content/navigation/new_nav_item.js b/plugins/pencilblue/controllers/actions/admin/content/navigation/new_nav_item.js index b1ac862eb..20b904fc9 100644 --- a/plugins/pencilblue/controllers/actions/admin/content/navigation/new_nav_item.js +++ b/plugins/pencilblue/controllers/actions/admin/content/navigation/new_nav_item.js @@ -37,7 +37,7 @@ module.exports = function(pb) { else { self.navService = new pb.SectionService(self.pathSiteUId, true); self.sitePrefix = pb.SiteService.getCurrentSitePrefix(self.pathSiteUId); - self.queryService = new pb.SiteQueryService(self.pathSiteUId); + self.queryService = new pb.SiteQueryService(self.pathSiteUId, true); self.settings = pb.SettingServiceFactory.getServiceBySite(self.pathSiteUId, true); var siteService = new pb.SiteService(); siteService.getSiteNameByUid(self.pathSiteUId, function (siteName) { diff --git a/plugins/pencilblue/controllers/actions/admin/content/topics/edit_topic.js b/plugins/pencilblue/controllers/actions/admin/content/topics/edit_topic.js index a319a6187..55af937aa 100644 --- a/plugins/pencilblue/controllers/actions/admin/content/topics/edit_topic.js +++ b/plugins/pencilblue/controllers/actions/admin/content/topics/edit_topic.js @@ -36,7 +36,7 @@ module.exports = function(pb) { } else { self.sitePrefix = pb.SiteService.getCurrentSitePrefix(self.pathSiteUId); - self.queryService = new pb.SiteQueryService(self.pathSiteUId); + self.queryService = new pb.SiteQueryService(self.pathSiteUId, true); var siteService = new pb.SiteService(); siteService.getSiteNameByUid(self.pathSiteUId, function (siteName) { self.siteName = siteName; diff --git a/plugins/pencilblue/controllers/actions/admin/content/topics/import_topics.js b/plugins/pencilblue/controllers/actions/admin/content/topics/import_topics.js index 6b9317e62..938eb4c13 100755 --- a/plugins/pencilblue/controllers/actions/admin/content/topics/import_topics.js +++ b/plugins/pencilblue/controllers/actions/admin/content/topics/import_topics.js @@ -43,7 +43,7 @@ module.exports = function(pb) { } else { self.sitePrefix = pb.SiteService.getCurrentSitePrefix(self.pathSiteUId); - self.queryService = new pb.SiteQueryService(self.pathSiteUId); + self.queryService = new pb.SiteQueryService(self.pathSiteUId, true); var siteService = new pb.SiteService(); siteService.getSiteNameByUid(self.pathSiteUId, function (siteName) { self.siteName = siteName; diff --git a/plugins/pencilblue/controllers/actions/admin/content/topics/new_topic.js b/plugins/pencilblue/controllers/actions/admin/content/topics/new_topic.js index 13c01b700..c23012355 100755 --- a/plugins/pencilblue/controllers/actions/admin/content/topics/new_topic.js +++ b/plugins/pencilblue/controllers/actions/admin/content/topics/new_topic.js @@ -36,7 +36,7 @@ module.exports = function(pb) { } else { self.sitePrefix = pb.SiteService.getCurrentSitePrefix(self.pathSiteUId); - self.queryService = new pb.SiteQueryService(self.pathSiteUId); + self.queryService = new pb.SiteQueryService(self.pathSiteUId, true); var siteService = new pb.SiteService(); siteService.getSiteNameByUid(self.pathSiteUId, function (siteName) { self.siteName = siteName; diff --git a/plugins/pencilblue/controllers/actions/admin/site_settings/content.js b/plugins/pencilblue/controllers/actions/admin/site_settings/content.js index 059de9c47..640349513 100755 --- a/plugins/pencilblue/controllers/actions/admin/site_settings/content.js +++ b/plugins/pencilblue/controllers/actions/admin/site_settings/content.js @@ -26,6 +26,23 @@ module.exports = function(pb) { function Content(){} util.inherits(Content, pb.BaseController); + Content.prototype.init = function (props, cb) { + var self = this; + + pb.BaseController.prototype.init.call(self, props, function() { + self.pathSiteUid = pb.SiteService.getCurrentSite(self.pathVars.siteid); + pb.SiteService.siteExists(self.pathSiteUid, function (err, exists) { + if (!exists) { + self.reqHandler.serve404(); + } + else { + self.settings = pb.SettingServiceFactory.getServiceBySite(self.pathSiteUid, true); + cb(); + } + }); + }); + }; + Content.prototype.render = function(cb) { var self = this; @@ -39,7 +56,7 @@ module.exports = function(pb) { return; } - pb.settings.set('content_settings', post, function(data) { + self.settings.set('content_settings', post, function(data) { if(util.isError(data)) { cb({ code: 500, diff --git a/plugins/pencilblue/controllers/actions/admin/themes/site_logo.js b/plugins/pencilblue/controllers/actions/admin/themes/site_logo.js index 6bda823cf..2f6feac0a 100755 --- a/plugins/pencilblue/controllers/actions/admin/themes/site_logo.js +++ b/plugins/pencilblue/controllers/actions/admin/themes/site_logo.js @@ -28,8 +28,28 @@ module.exports = function(pb) { function SiteLogo() {} util.inherits(SiteLogo, pb.BaseController); + SiteLogo.prototype.init = function (props, cb) { + var self = this; + pb.BaseController.prototype.init.call(self, props, function () { + self.pathSiteUId = pb.SiteService.getCurrentSite(self.pathVars.siteid); + pb.SiteService.siteExists(self.pathSiteUId, function (err, exists) { + if (!exists) { + self.reqHandler.serve404(); + } + else { + self.settings = pb.SettingServiceFactory.getServiceBySite(self.pathSiteUId, true); + var siteService = new pb.SiteService(); + siteService.getSiteNameByUid(self.pathSiteUId, function (siteName) { + self.siteName = siteName; + cb(); + }); + } + }); + }); + }; + SiteLogo.prototype.render = function(cb) { - self = this; + var self = this; this.getJSONPostParams(function(err, post) { if (!pb.validation.validateNonEmptyStr(post.site_logo, true)) { @@ -40,7 +60,7 @@ module.exports = function(pb) { return; } - pb.settings.set('site_logo', post.site_logo, function(err, result) { + self.settings.set('site_logo', post.site_logo, function(err, result) { if (util.isError(err)) { cb({ code: 500, diff --git a/plugins/pencilblue/controllers/actions/user/sign_up.js b/plugins/pencilblue/controllers/actions/user/sign_up.js index a45b219b7..b84c85411 100755 --- a/plugins/pencilblue/controllers/actions/user/sign_up.js +++ b/plugins/pencilblue/controllers/actions/user/sign_up.js @@ -48,7 +48,7 @@ module.exports = function SignUpModule(pb) { return; } - var contentService = new pb.ContentService(); + var contentService = new pb.ContentService(self.site); contentService.getSettings(function(err, contentSettings) { //TODO handle error @@ -120,7 +120,7 @@ module.exports = function SignUpModule(pb) { }, unverified_email: function(callback) { dao.count('unverified_user', {email: user.email}, callback); - }, + } }; async.series(tasks, cb); }; diff --git a/plugins/pencilblue/controllers/admin/content/articles/article_form.js b/plugins/pencilblue/controllers/admin/content/articles/article_form.js index 51cd9e859..fc7b28ec0 100755 --- a/plugins/pencilblue/controllers/admin/content/articles/article_form.js +++ b/plugins/pencilblue/controllers/admin/content/articles/article_form.js @@ -39,7 +39,7 @@ module.exports = function(pb) { } else { self.sitePrefix = pb.SiteService.getCurrentSitePrefix(self.pathSiteUId); - self.queryService = new pb.SiteQueryService(self.pathSiteUId); + self.queryService = new pb.SiteQueryService(self.pathSiteUId, true); var siteService = new pb.SiteService(); siteService.getSiteNameByUid(self.pathSiteUId, function (siteName) { self.siteName = siteName; @@ -201,7 +201,6 @@ module.exports = function(pb) { ArticleForm.prototype.gatherData = function(vars, cb) { var self = this; - var dao = new pb.DAO(); var tasks = { templates: function(callback) { callback(null, pb.TemplateService.getAvailableContentTemplates()); @@ -228,8 +227,8 @@ module.exports = function(pb) { }, media: function(callback) { - var mservice = new pb.MediaService(); - mservice.getBySite(vars.siteid, callback); + var mservice = new pb.MediaService(null, vars.siteid, true); + mservice.get(callback); }, article: function(callback) { @@ -239,7 +238,7 @@ module.exports = function(pb) { } //TODO call article service - dao.loadById(vars.id, 'article', callback); + self.queryService.loadById(vars.id, 'article', callback); } }; async.parallelLimit(tasks, 2, cb); diff --git a/plugins/pencilblue/controllers/admin/content/articles/manage_articles.js b/plugins/pencilblue/controllers/admin/content/articles/manage_articles.js index e70d80eb0..f7a171020 100755 --- a/plugins/pencilblue/controllers/admin/content/articles/manage_articles.js +++ b/plugins/pencilblue/controllers/admin/content/articles/manage_articles.js @@ -28,7 +28,7 @@ module.exports = function(pb) { ManageArticles.prototype.init = function (props, cb) { this.pathSiteUId = pb.SiteService.getCurrentSite(props.path_vars.siteid); - this.queryService = new pb.SiteQueryService(this.pathSiteUId); + this.queryService = new pb.SiteQueryService(this.pathSiteUId, true); this.sitePrefix = pb.SiteService.getCurrentSitePrefix(this.pathSiteUId); pb.BaseController.prototype.init.call(this, props, cb); diff --git a/plugins/pencilblue/controllers/admin/content/comments/manage_comments.js b/plugins/pencilblue/controllers/admin/content/comments/manage_comments.js index cb8a8955b..a2a6f23cc 100755 --- a/plugins/pencilblue/controllers/admin/content/comments/manage_comments.js +++ b/plugins/pencilblue/controllers/admin/content/comments/manage_comments.js @@ -38,7 +38,7 @@ module.exports = function(pb) { } else { self.sitePrefix = pb.SiteService.getCurrentSitePrefix(self.pathSiteUId); - self.queryService = new pb.SiteQueryService(self.pathSiteUId); + self.queryService = new pb.SiteQueryService(self.pathSiteUId, true); var siteService = new pb.SiteService(); siteService.getByUid(self.pathSiteUId, function (err, objSite) { self.siteName = objSite.displayName; @@ -123,7 +123,7 @@ module.exports = function(pb) { } this.getCommentingUser = function(index) { - self.queryService.loadById(comments[index].commenter, 'user', function(err, user) { + self.queryService.__proto__.loadById(comments[index].commenter, 'user', function(err, user) { if(!util.isError(err) && user !== null) { comments[index].user_name = user.first_name + ' ' + user.last_name; } diff --git a/plugins/pencilblue/controllers/admin/content/media/manage_media.js b/plugins/pencilblue/controllers/admin/content/media/manage_media.js index 05cda2f24..a2c06856e 100755 --- a/plugins/pencilblue/controllers/admin/content/media/manage_media.js +++ b/plugins/pencilblue/controllers/admin/content/media/manage_media.js @@ -32,6 +32,7 @@ module.exports = function(pb) { ManageMedia.prototype.init = function (props, cb) { this.pathSiteUId = pb.SiteService.getCurrentSite(props.path_vars.siteid); this.sitePrefix = pb.SiteService.getCurrentSitePrefix(this.pathSiteUId); + this.mediaService = new pb.MediaService(null, this.pathSiteUId, true); pb.BaseController.prototype.init.call(this, props, cb); }; @@ -46,12 +47,10 @@ module.exports = function(pb) { media_type: 1, location: 1 }, - where : {site: self.pathSiteUId}, order: {created: pb.DAO.DESC}, format_media: true }; - var mservice = new pb.MediaService(); - mservice.get(options, function(err, mediaData) { + self.mediaService.get(options, function(err, mediaData) { if(util.isError(mediaData) || mediaData.length === 0) { self.redirect('/admin' + self.sitePrefix + '/content/media/new', cb); return; diff --git a/plugins/pencilblue/controllers/admin/content/media/media_form.js b/plugins/pencilblue/controllers/admin/content/media/media_form.js index e07931623..a461b47e8 100644 --- a/plugins/pencilblue/controllers/admin/content/media/media_form.js +++ b/plugins/pencilblue/controllers/admin/content/media/media_form.js @@ -37,6 +37,8 @@ module.exports = function(pb) { MediaForm.prototype.init = function (props, cb) { this.pathSiteUId = pb.SiteService.getCurrentSite(props.path_vars.siteid); this.sitePrefix = pb.SiteService.getCurrentSitePrefix(this.pathSiteUId); + this.queryService = new pb.SiteQueryService(this.pathSiteUId, true); + this.mediaService = new pb.MediaService(null, this.pathSiteUId, true); pb.BaseController.prototype.init.call(this, props, cb); }; @@ -68,7 +70,6 @@ module.exports = function(pb) { }); }); }); - return; }; MediaForm.prototype.getAngularObjects = function(data, cb) { @@ -83,7 +84,6 @@ module.exports = function(pb) { MediaForm.prototype.gatherData = function(vars, cb) { var self = this; - var dao = new pb.DAO(); var tasks = { tabs: function(callback) { @@ -112,7 +112,7 @@ module.exports = function(pb) { where: pb.DAO.ANYWHERE, order: {name: pb.DAO.ASC} }; - dao.q('topic', opts, callback); + self.queryService.q('topic', opts, callback); }, media: function(callback) { @@ -123,8 +123,7 @@ module.exports = function(pb) { }); } - var mservice = new pb.MediaService(); - mservice.loadById(vars.id, callback); + self.mediaService.loadById(vars.id, callback); } }; async.series(tasks, cb); diff --git a/plugins/pencilblue/controllers/admin/content/navigation/nav_item_form.js b/plugins/pencilblue/controllers/admin/content/navigation/nav_item_form.js index b8a256865..18bdb8d9c 100644 --- a/plugins/pencilblue/controllers/admin/content/navigation/nav_item_form.js +++ b/plugins/pencilblue/controllers/admin/content/navigation/nav_item_form.js @@ -44,7 +44,7 @@ module.exports = function(pb) { else { self.navService = new pb.SectionService(self.pathSiteUId, true); self.sitePrefix = pb.SiteService.getCurrentSitePrefix(self.pathSiteUId); - self.queryService = new pb.SiteQueryService(self.pathSiteUId); + self.queryService = new pb.SiteQueryService(self.pathSiteUId, true); self.settings = pb.SettingServiceFactory.getServiceBySite(self.pathSiteUId, true); var siteService = new pb.SiteService(); siteService.getSiteNameByUid(self.pathSiteUId, function (siteName) { @@ -151,7 +151,7 @@ module.exports = function(pb) { } self.queryService.loadById(vars.id, 'section', function(err, navItem) { - if(!navItem.item) { + if(!navItem || !navItem.item) { callback(err, navItem); return; } diff --git a/plugins/pencilblue/controllers/admin/content/navigation/nav_map.js b/plugins/pencilblue/controllers/admin/content/navigation/nav_map.js index 6e740f74b..6a5034b4a 100644 --- a/plugins/pencilblue/controllers/admin/content/navigation/nav_map.js +++ b/plugins/pencilblue/controllers/admin/content/navigation/nav_map.js @@ -39,7 +39,7 @@ module.exports = function(pb) { else { self.navService = new pb.SectionService(self.pathSiteUId, true); self.sitePrefix = pb.SiteService.getCurrentSitePrefix(self.pathSiteUId); - self.queryService = new pb.SiteQueryService(self.pathSiteUId); + self.queryService = new pb.SiteQueryService(self.pathSiteUId, true); self.settings = pb.SettingServiceFactory.getServiceBySite(self.pathSiteUId, true); var siteService = new pb.SiteService(); siteService.getSiteNameByUid(self.pathSiteUId, function (siteName) { diff --git a/plugins/pencilblue/controllers/admin/content/pages/manage_pages.js b/plugins/pencilblue/controllers/admin/content/pages/manage_pages.js index 30ef34413..0dc097bdf 100755 --- a/plugins/pencilblue/controllers/admin/content/pages/manage_pages.js +++ b/plugins/pencilblue/controllers/admin/content/pages/manage_pages.js @@ -28,7 +28,7 @@ module.exports = function(pb) { ManagePages.prototype.init = function (props, cb) { this.pathSiteUId = pb.SiteService.getCurrentSite(props.path_vars.siteid); - this.queryService = new pb.SiteQueryService(this.pathSiteUId); + this.queryService = new pb.SiteQueryService(this.pathSiteUId, true); this.sitePrefix = pb.SiteService.getCurrentSitePrefix(this.pathSiteUId); pb.BaseController.prototype.init.call(this, props, cb); diff --git a/plugins/pencilblue/controllers/admin/content/pages/page_form.js b/plugins/pencilblue/controllers/admin/content/pages/page_form.js index b01d141a8..13967b351 100755 --- a/plugins/pencilblue/controllers/admin/content/pages/page_form.js +++ b/plugins/pencilblue/controllers/admin/content/pages/page_form.js @@ -39,7 +39,7 @@ module.exports = function(pb) { } else { self.sitePrefix = pb.SiteService.getCurrentSitePrefix(self.pathSiteUId); - self.queryService = new pb.SiteQueryService(self.pathSiteUId); + self.queryService = new pb.SiteQueryService(self.pathSiteUId, true); var siteService = new pb.SiteService(); siteService.getSiteNameByUid(self.pathSiteUId, function (siteName) { self.siteName = siteName; @@ -202,7 +202,6 @@ module.exports = function(pb) { */ PageFormController.prototype.gatherData = function(vars, cb) { var self = this; - var dao = new pb.DAO(); var tasks = { templates: function(callback) { callback(null, pb.TemplateService.getAvailableContentTemplates()); @@ -229,8 +228,8 @@ module.exports = function(pb) { }, media: function(callback) { - var mservice = new pb.MediaService(); - mservice.getBySite(vars.siteid, callback); + var mservice = new pb.MediaService(null, vars.siteid, true); + mservice.get(callback); }, page: function(callback) { @@ -239,7 +238,7 @@ module.exports = function(pb) { return; } - dao.loadById(vars.id, 'page', callback); + self.queryService.loadById(vars.id, 'page', callback); } }; async.parallelLimit(tasks, 2, cb); diff --git a/plugins/pencilblue/controllers/admin/content/topics/import_topics.js b/plugins/pencilblue/controllers/admin/content/topics/import_topics.js index d21e80af8..981dcba5c 100755 --- a/plugins/pencilblue/controllers/admin/content/topics/import_topics.js +++ b/plugins/pencilblue/controllers/admin/content/topics/import_topics.js @@ -36,7 +36,7 @@ module.exports = function(pb) { } else { self.sitePrefix = pb.SiteService.getCurrentSitePrefix(self.pathSiteUId); - self.queryService = new pb.SiteQueryService(self.pathSiteUId); + self.queryService = new pb.SiteQueryService(self.pathSiteUId, true); var siteService = new pb.SiteService(); siteService.getSiteNameByUid(self.pathSiteUId, function (siteName) { self.siteName = siteName; diff --git a/plugins/pencilblue/controllers/admin/content/topics/manage_topics.js b/plugins/pencilblue/controllers/admin/content/topics/manage_topics.js index d2a98003c..d058427cd 100755 --- a/plugins/pencilblue/controllers/admin/content/topics/manage_topics.js +++ b/plugins/pencilblue/controllers/admin/content/topics/manage_topics.js @@ -36,7 +36,7 @@ module.exports = function(pb) { } else { self.sitePrefix = pb.SiteService.getCurrentSitePrefix(self.pathSiteUId); - self.queryService = new pb.SiteQueryService(self.pathSiteUId); + self.queryService = new pb.SiteQueryService(self.pathSiteUId, true); var siteService = new pb.SiteService(); siteService.getSiteNameByUid(self.pathSiteUId, function (siteName) { self.siteName = siteName; diff --git a/plugins/pencilblue/controllers/admin/content/topics/topic_form.js b/plugins/pencilblue/controllers/admin/content/topics/topic_form.js index 7601b2cb4..b61270e10 100644 --- a/plugins/pencilblue/controllers/admin/content/topics/topic_form.js +++ b/plugins/pencilblue/controllers/admin/content/topics/topic_form.js @@ -39,7 +39,7 @@ module.exports = function(pb) { } else { self.sitePrefix = pb.SiteService.getCurrentSitePrefix(self.pathSiteUId); - self.queryService = new pb.SiteQueryService(self.pathSiteUId); + self.queryService = new pb.SiteQueryService(self.pathSiteUId, true); self.settings = pb.SettingServiceFactory.getServiceBySite(self.pathSiteUId, true); var siteService = new pb.SiteService(); siteService.getSiteNameByUid(self.pathSiteUId, function (siteName) { @@ -108,8 +108,7 @@ module.exports = function(pb) { return; } - var dao = new pb.DAO(); - dao.loadById(vars.id, 'topic', function(err, topic) { + self.queryService.loadById(vars.id, 'topic', function(err, topic) { callback(err, topic); }); } diff --git a/plugins/pencilblue/controllers/admin/site_settings/content.js b/plugins/pencilblue/controllers/admin/site_settings/content.js index dfef90773..d9a405345 100755 --- a/plugins/pencilblue/controllers/admin/site_settings/content.js +++ b/plugins/pencilblue/controllers/admin/site_settings/content.js @@ -29,6 +29,27 @@ module.exports = function(pb) { //statics var SUB_NAV_KEY = 'content_settings'; + Content.prototype.init = function (props, cb) { + var self = this; + + pb.BaseController.prototype.init.call(self, props, function() { + self.pathSiteUid = pb.SiteService.getCurrentSite(self.pathVars.siteid); + pb.SiteService.siteExists(self.pathSiteUid, function (err, exists) { + if (!exists) { + self.reqHandler.serve404(); + } + else { + self.pathSitePrefix = pb.SiteService.getCurrentSitePrefix(self.pathSiteUid); + var siteService = new pb.SiteService(); + siteService.getSiteNameByUid(self.pathSiteUid, function (siteName) { + self.siteName = siteName; + cb(); + }); + } + }); + }); + }; + Content.prototype.render = function(cb) { var self = this; @@ -57,13 +78,17 @@ module.exports = function(pb) { } ]; - var contentService = new pb.ContentService(); + var contentService = new pb.ContentService(this.pathSiteUid, true); + var pills = pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, 'content', { pathSitePrefix: self.pathSitePrefix }); + pills = pb.AdminSubnavService.addSiteToPills(pills, this.siteName); + contentService.getSettings(function(err, contentSettings) { var angularObjects = pb.ClientJs.getAngularObjects({ navigation: pb.AdminNavigation.get(self.session, ['settings', 'site_settings'], self.ls), - pills: pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, 'content'), + pills: pills, tabs: tabs, - contentSettings: contentSettings + contentSettings: contentSettings, + pathSitePrefix: self.pathSitePrefix }); self.setPageName(self.ls.get('CONTENT')); @@ -79,17 +104,17 @@ module.exports = function(pb) { name: 'configuration', title: ls.get('CONTENT'), icon: 'chevron-left', - href: '/admin/site_settings' + href: '/admin' + data.pathSitePrefix + '/site_settings' }, { name: 'email', title: ls.get('EMAIL'), icon: 'envelope', - href: '/admin/site_settings/email' + href: '/admin' + data.pathSitePrefix + '/site_settings/email' }, { name: 'libraries', title: ls.get('LIBRARIES'), icon: 'book', - href: '/admin/site_settings/libraries' + href: '/admin' + data.pathSitePrefix + '/site_settings/libraries' }]; }; diff --git a/plugins/pencilblue/controllers/api/admin/content/media/get_preview.js b/plugins/pencilblue/controllers/api/admin/content/media/get_preview.js index 2fff959e3..4b69d3ebf 100644 --- a/plugins/pencilblue/controllers/api/admin/content/media/get_preview.js +++ b/plugins/pencilblue/controllers/api/admin/content/media/get_preview.js @@ -29,6 +29,16 @@ module.exports = function(pb) { function GetMediaPreviewApiController(){} util.inherits(GetMediaPreviewApiController, pb.BaseController); + GetMediaPreviewApiController.prototype.init = function (props, cb) { + var self = this; + pb.BaseController.prototype.init.call(self, props, function () { + self.pathSiteUId = pb.SiteService.getCurrentSite(self.pathVars.siteid); + self.sitePrefix = pb.SiteService.getCurrentSitePrefix(self.pathSiteUId); + self.mediaService = new pb.MediaService(null, self.pathSiteUId, true); + cb(); + }); + }; + /** * Renders the preview * @method render @@ -50,9 +60,8 @@ module.exports = function(pb) { var options = { view: 'view' }; - var ms = new pb.MediaService(); if (get.id) { - ms.renderById(get.id, options, function(err, html) { + self.mediaService.renderById(get.id, options, function(err, html) { self.renderComplete(err, html, cb); }); } @@ -63,7 +72,7 @@ module.exports = function(pb) { location: get.location, type: get.type }; - ms.renderByLocation(options, function(err, html) { + self.mediaService.renderByLocation(options, function(err, html) { self.renderComplete(err, html, cb); }); } diff --git a/plugins/pencilblue/controllers/api/content/get_articles.js b/plugins/pencilblue/controllers/api/content/get_articles.js index 3d3092413..e1ea5f028 100755 --- a/plugins/pencilblue/controllers/api/content/get_articles.js +++ b/plugins/pencilblue/controllers/api/content/get_articles.js @@ -38,7 +38,7 @@ module.exports = function(pb) { var self = this; var get = this.query; - var contentService = new pb.ContentService(); + var contentService = new pb.ContentService(self.site); contentService.getSettings(function(err, contentSettings) { if(!get.limit || get.limit.length === 0) @@ -58,7 +58,7 @@ module.exports = function(pb) { self.processArticles(articles, cb); }; - var service = new ArticleService(); + var service = new ArticleService(self.site, true); if(get.section) { service.findBySection(get.section, articleCallback); @@ -75,7 +75,7 @@ module.exports = function(pb) { GetArticles.prototype.processArticles = function(articles, cb) { var self = this; - var contentService = new pb.ContentService(); + var contentService = new pb.ContentService(self.site); contentService.getSettings(function(err, contentSettings) { var cnt = 0; diff --git a/plugins/pencilblue/controllers/api/content/search.js b/plugins/pencilblue/controllers/api/content/search.js index d45721ec3..14411c449 100755 --- a/plugins/pencilblue/controllers/api/content/search.js +++ b/plugins/pencilblue/controllers/api/content/search.js @@ -60,13 +60,13 @@ module.exports = function(pb) { where: { $or: [ {headline: pattern}, - {subheading: pattern}, + {subheading: pattern} ] }, order: pb.DAO.NATURAL_ORDER, limit: MAX_RESULTS }; - var queryService = new pb.SiteQueryService(querySite); + var queryService = new pb.SiteQueryService(querySite, true); queryService.q(type, opts, function(err, items) { if (util.isError(err)) { var content = BaseController.apiResponse(BaseController.API_FAILURE, '', ''); diff --git a/plugins/pencilblue/controllers/feed.js b/plugins/pencilblue/controllers/feed.js index e2edea40f..8666db4ca 100755 --- a/plugins/pencilblue/controllers/feed.js +++ b/plugins/pencilblue/controllers/feed.js @@ -61,7 +61,7 @@ module.exports = function FeedModule(pb) { self.getMedia(articles, function(err, articlesWithMedia) { articles = articlesWithMedia; - var contentService = new pb.ContentService(); + var contentService = new pb.ContentService(self.site); contentService.getSettings(function(err, contentSettings) { var tasks = util.getTasks(articles, function(articles, i) { diff --git a/plugins/pencilblue/controllers/index.js b/plugins/pencilblue/controllers/index.js index 7a8bd0aa9..97dfb5f66 100755 --- a/plugins/pencilblue/controllers/index.js +++ b/plugins/pencilblue/controllers/index.js @@ -42,7 +42,7 @@ module.exports = function IndexModule(pb) { var article = self.req.pencilblue_article || null; var page = self.req.pencilblue_page || null; - var contentService = new pb.ContentService(); + var contentService = new pb.ContentService(self.site); contentService.getSettings(function(err, contentSettings) { self.gatherData(function(err, data) { ArticleService.getMetaInfo(data.content[0], function(metaKeywords, metaDescription, metaTitle, metaThumbnail) { @@ -220,7 +220,7 @@ module.exports = function IndexModule(pb) { var article = this.req.pencilblue_article || null; var page = this.req.pencilblue_page || null; - var service = new ArticleService(); + var service = new ArticleService(this.site, true); if(this.req.pencilblue_preview) { if(this.req.pencilblue_preview == page || article) { if(page) { diff --git a/plugins/pencilblue/controllers/user/resend_verification.js b/plugins/pencilblue/controllers/user/resend_verification.js index ae812e2c4..335b5742d 100755 --- a/plugins/pencilblue/controllers/user/resend_verification.js +++ b/plugins/pencilblue/controllers/user/resend_verification.js @@ -29,7 +29,7 @@ module.exports = function ResendVerificationModule(pb) { ResendVerification.prototype.render = function(cb) { var self = this; - var contentService = new pb.ContentService(); + var contentService = new pb.ContentService(self.site); contentService.getSettings(function(err, contentSettings) { if(!contentSettings.allow_comments || !contentSettings.require_verification) { diff --git a/plugins/pencilblue/controllers/user/sign_up.js b/plugins/pencilblue/controllers/user/sign_up.js index 32cdff6a3..d49edde3f 100755 --- a/plugins/pencilblue/controllers/user/sign_up.js +++ b/plugins/pencilblue/controllers/user/sign_up.js @@ -29,7 +29,7 @@ module.exports = function SignUpModule(pb) { SignUp.prototype.render = function(cb) { var self = this; - var contentService = new pb.ContentService(); + var contentService = new pb.ContentService(self.site); contentService.getSettings(function(err, contentSettings) { if(!contentSettings.allow_comments) { self.redirect('/', cb); diff --git a/plugins/pencilblue/controllers/user/verification_sent.js b/plugins/pencilblue/controllers/user/verification_sent.js index a288c006f..f23e4d5e9 100755 --- a/plugins/pencilblue/controllers/user/verification_sent.js +++ b/plugins/pencilblue/controllers/user/verification_sent.js @@ -29,7 +29,7 @@ module.exports = function VerificationSentModule(pb) { VerificationSent.prototype.render = function(cb) { var self = this; - var contentService = new pb.ContentService(); + var contentService = new pb.ContentService(self.site); contentService.getSettings(function(err, contentSettings) { if(!contentSettings.allow_comments || !contentSettings.require_verification) { self.redirect('/', cb); diff --git a/plugins/pencilblue/templates/angular/admin/content/media/media_form.html b/plugins/pencilblue/templates/angular/admin/content/media/media_form.html index 6b18cdcae..efc8ff934 100644 --- a/plugins/pencilblue/templates/angular/admin/content/media/media_form.html +++ b/plugins/pencilblue/templates/angular/admin/content/media/media_form.html @@ -104,7 +104,7 @@ $scope.getMediaPreview = function() { $scope.mediaPreview = ''; - $http.get('/api/admin/content/media/get_preview?id=' + $scope.media._id) + $http.get('/api/admin' + $scope.sitePrefix + '/content/media/get_preview?id=' + $scope.media._id) .success(function(result) { $scope.mediaPreview = result.data; }) diff --git a/plugins/pencilblue/templates/angular/admin/site_settings/content.html b/plugins/pencilblue/templates/angular/admin/site_settings/content.html index a2bddab7b..4b8a73b9e 100644 --- a/plugins/pencilblue/templates/angular/admin/site_settings/content.html +++ b/plugins/pencilblue/templates/angular/admin/site_settings/content.html @@ -18,7 +18,7 @@ $scope.saving = true; - $http.post('/actions/admin/site_settings/content', $scope.contentSettings) + $http.post('/actions/admin' + $scope.pathSitePrefix + '/site_settings/content', $scope.contentSettings) .success(function(result) { $scope.successMessage = result.message; $scope.saving = false; diff --git a/plugins/pencilblue/templates/angular/admin/themes/manage_themes.html b/plugins/pencilblue/templates/angular/admin/themes/manage_themes.html index 0366a9db4..473309240 100644 --- a/plugins/pencilblue/templates/angular/admin/themes/manage_themes.html +++ b/plugins/pencilblue/templates/angular/admin/themes/manage_themes.html @@ -54,7 +54,7 @@ } $scope.saveSiteLogo = function() { - $http.post('/actions/admin/themes/site_logo', {site_logo: $scope.photoValue}) + $http.post('/actions/admin' + $scope.sitePrefix + '/themes/site_logo', {site_logo: $scope.photoValue}) .success(function(result) { $scope.successMessage = result.message; $scope.saving = false; diff --git a/plugins/portfolio/controllers/index.js b/plugins/portfolio/controllers/index.js index a606e4730..cb4c5e0b8 100755 --- a/plugins/portfolio/controllers/index.js +++ b/plugins/portfolio/controllers/index.js @@ -35,6 +35,7 @@ module.exports = function IndexModule(pb) { function Index() {} util.inherits(Index, pb.BaseController); +<<<<<<< HEAD Index.prototype.init = function(props, cb) { var self = this; pb.BaseController.prototype.init.call(self, props, function () { @@ -48,6 +49,15 @@ module.exports = function IndexModule(pb) { cb(); } }); +======= + Index.prototype.init = function (props, cb) { + var self = this; + pb.BaseController.prototype.init.call(self, props, function () { + self.siteUId = pb.SiteService.getCurrentSite(self.site); + self.navService = new pb.SectionService(self.pathSiteUId); + self.queryService = new pb.SiteQueryService(self.siteUId); + cb(); +>>>>>>> multi_tenancy }); }; @@ -77,7 +87,11 @@ module.exports = function IndexModule(pb) { TopMenu.getTopMenu(self.session, self.ls, options, function(themeSettings, navigation, accountButtons) { TopMenu.getBootstrapNav(navigation, accountButtons, function(navigation, accountButtons) { +<<<<<<< HEAD var pluginService = new pb.PluginService(pb.SiteService.getCurrentSite(self.site)); +======= + var pluginService = new pb.PluginService(self.site); +>>>>>>> multi_tenancy pluginService.getSettings('portfolio', function(err, portfolioSettings) { var homePageKeywords = ''; var homePageDescription = ''; @@ -112,8 +126,7 @@ module.exports = function IndexModule(pb) { var opts = { where: {settings_type: 'home_page'} }; - var dao = new pb.DAO(); - dao.q('portfolio_theme_settings', opts, function(err, settings) { + self.queryService.q('portfolio_theme_settings', opts, function(err, settings) { if (util.isError(err)) { self.reqHandler.serveError(err); } From aad7172cfbbf72d29a1037acb53241e27401daf4 Mon Sep 17 00:00:00 2001 From: btidwell Date: Tue, 19 May 2015 09:14:01 -0400 Subject: [PATCH 156/790] finish merge of index.js in portfolio theme --- plugins/portfolio/controllers/index.js | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/plugins/portfolio/controllers/index.js b/plugins/portfolio/controllers/index.js index cb4c5e0b8..129850471 100755 --- a/plugins/portfolio/controllers/index.js +++ b/plugins/portfolio/controllers/index.js @@ -35,7 +35,6 @@ module.exports = function IndexModule(pb) { function Index() {} util.inherits(Index, pb.BaseController); -<<<<<<< HEAD Index.prototype.init = function(props, cb) { var self = this; pb.BaseController.prototype.init.call(self, props, function () { @@ -46,18 +45,11 @@ module.exports = function IndexModule(pb) { } else { self.siteObj = site; + self.navService = new pb.SectionService(site.uid); + self.queryService = new pb.SiteQueryService(site.uid); cb(); } }); -======= - Index.prototype.init = function (props, cb) { - var self = this; - pb.BaseController.prototype.init.call(self, props, function () { - self.siteUId = pb.SiteService.getCurrentSite(self.site); - self.navService = new pb.SectionService(self.pathSiteUId); - self.queryService = new pb.SiteQueryService(self.siteUId); - cb(); ->>>>>>> multi_tenancy }); }; @@ -86,12 +78,7 @@ module.exports = function IndexModule(pb) { }; TopMenu.getTopMenu(self.session, self.ls, options, function(themeSettings, navigation, accountButtons) { TopMenu.getBootstrapNav(navigation, accountButtons, function(navigation, accountButtons) { - -<<<<<<< HEAD var pluginService = new pb.PluginService(pb.SiteService.getCurrentSite(self.site)); -======= - var pluginService = new pb.PluginService(self.site); ->>>>>>> multi_tenancy pluginService.getSettings('portfolio', function(err, portfolioSettings) { var homePageKeywords = ''; var homePageDescription = ''; @@ -107,7 +94,6 @@ module.exports = function IndexModule(pb) { break; } } - console.log(self.siteObj); self.ts.registerLocal('meta_keywords', homePageKeywords); self.ts.registerLocal('meta_desc', homePageDescription); self.ts.registerLocal('meta_title', self.siteObj.displayName); From c884d2def18994a0d1b77725e711336f40370ad1 Mon Sep 17 00:00:00 2001 From: Eugene Chang Date: Tue, 19 May 2015 09:41:22 -0400 Subject: [PATCH 157/790] Refactoring controllers based on FormController to AdminFormController --- controllers/admin/admin_form_controller.js | 38 +++++++++++++++++++ .../{ => admin}/base_admin_controller.js | 5 +-- include/requirements.js | 5 ++- .../admin/content/objects/sort_objects.js | 6 +-- .../content/objects/types/delete_type.js | 6 +-- .../actions/admin/site_settings/content.js | 19 +--------- .../admin/plugins/plugin_settings.js | 6 +++ .../admin/site_settings/content.js | 23 +---------- .../admin/content/objects/types/available.js | 6 +-- .../controllers/api/comments/new_comment.js | 6 +-- 10 files changed, 54 insertions(+), 66 deletions(-) create mode 100644 controllers/admin/admin_form_controller.js rename controllers/{ => admin}/base_admin_controller.js (94%) diff --git a/controllers/admin/admin_form_controller.js b/controllers/admin/admin_form_controller.js new file mode 100644 index 000000000..073a62284 --- /dev/null +++ b/controllers/admin/admin_form_controller.js @@ -0,0 +1,38 @@ +/* + Copyright (C) 2015 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ + +module.exports = function AdminFormControllerModule(pb) { + "use strict"; + + var util = pb.util; + var BaseAdminController = pb.BaseAdminController; + + function AdminFormController() { + } + util.inherits(AdminFormController, pb.FormController); + + /** + * @override + * @param props + * @param cb + */ + AdminFormController.prototype.init = function (props, cb) { + BaseAdminController.prototype.init.call(this, props, cb); + }; + + return AdminFormController; +}; \ No newline at end of file diff --git a/controllers/base_admin_controller.js b/controllers/admin/base_admin_controller.js similarity index 94% rename from controllers/base_admin_controller.js rename to controllers/admin/base_admin_controller.js index 97bad0b55..c301e75ce 100644 --- a/controllers/base_admin_controller.js +++ b/controllers/admin/base_admin_controller.js @@ -30,10 +30,7 @@ module.exports = function BaseAdminControllerModule(pb) { util.inherits(BaseAdminController, BaseController); BaseAdminController.prototype.init = function (props, cb) { - BaseAdminController.overrideInit(this, props, cb); - }; - - BaseAdminController.overrideInit = function(self, props, cb) { + var self = this; BaseController.prototype.init.call(self, props, function () { self.pathSiteUId = pb.SiteService.getCurrentSite(self.pathVars.siteid); var siteService = new pb.SiteService(); diff --git a/include/requirements.js b/include/requirements.js index 1d4e85bc9..c10e0fe9e 100755 --- a/include/requirements.js +++ b/include/requirements.js @@ -116,9 +116,10 @@ module.exports = function PB(config) { pb.JsonBodyParser = BodyParsers.JsonBodyParser; pb.FormBodyParser = BodyParsers.FormBodyParser; pb.BaseController = require(path.join(config.docRoot, '/controllers/base_controller.js'))(pb); - pb.BaseAdminController = require(path.join(config.docRoot, '/controllers/base_admin_controller.js'))(pb); + pb.BaseAdminController = require(path.join(config.docRoot, '/controllers/admin/base_admin_controller.js'))(pb); pb.ViewController = require(path.join(config.docRoot, '/controllers/view_controller.js'))(pb); pb.FormController = require(path.join(config.docRoot, '/controllers/form_controller.js'))(pb); + pb.AdminFormController = require(path.join(config.docRoot, '/controllers/admin/admin_form_controller.js'))(pb); pb.DeleteController = require(path.join(config.docRoot, '/controllers/delete_controller.js'))(pb); pb.ApiActionController = require(path.join(config.docRoot, '/controllers/api/api_action_controller.js'))(pb); pb.RequestHandler = require(path.join(config.docRoot, '/include/http/request_handler.js'))(pb); @@ -226,7 +227,7 @@ module.exports = function PB(config) { pb.media.renderers.SlideShareMediaRenderer = require(path.join(config.docRoot, '/include/service/media/renderers/slideshare_media_renderer.js'))(pb), pb.media.renderers.TrinketMediaRenderer = require(path.join(config.docRoot, '/include/service/media/renderers/trinket_media_renderer.js'))(pb), pb.media.renderers.StorifyMediaRenderer = require(path.join(config.docRoot, '/include/service/media/renderers/storify_media_renderer.js'))(pb), - pb.media.renderers.KickStarterMediaRenderer = require(path.join(config.docRoot, '/include/service/media/renderers/kickstarter_media_renderer.js'))(pb) + pb.media.renderers.KickStarterMediaRenderer = require(path.join(config.docRoot, '/include/service/media/renderers/kickstarter_media_renderer.js'))(pb); //providers and service pb.MediaService = require(path.join(config.docRoot, '/include/service/entities/media_service.js'))(pb); diff --git a/plugins/pencilblue/controllers/actions/admin/content/objects/sort_objects.js b/plugins/pencilblue/controllers/actions/admin/content/objects/sort_objects.js index 96a7982ac..298f93c84 100644 --- a/plugins/pencilblue/controllers/actions/admin/content/objects/sort_objects.js +++ b/plugins/pencilblue/controllers/actions/admin/content/objects/sort_objects.js @@ -26,11 +26,7 @@ module.exports = function(pb) { * @constructor */ function SortObjectsActionController(){} - util.inherits(SortObjectsActionController, pb.FormController); - - SortObjectsActionController.prototype.init = function (props, cb) { - pb.BaseAdminController.overrideInit(this, props, cb); - }; + util.inherits(SortObjectsActionController, pb.AdminFormController); SortObjectsActionController.prototype.render = function(cb) { var self = this; diff --git a/plugins/pencilblue/controllers/actions/admin/content/objects/types/delete_type.js b/plugins/pencilblue/controllers/actions/admin/content/objects/types/delete_type.js index f7ca95827..f82876e33 100644 --- a/plugins/pencilblue/controllers/actions/admin/content/objects/types/delete_type.js +++ b/plugins/pencilblue/controllers/actions/admin/content/objects/types/delete_type.js @@ -24,11 +24,7 @@ module.exports = function(pb) { * Deletes an object type */ function DeleteObjectType(){} - util.inherits(DeleteObjectType, pb.FormController); - - DeleteObjectType.prototype.init = function (props, cb) { - pb.BaseAdminController.overrideInit(this, props, cb); - }; + util.inherits(DeleteObjectType, pb.AdminFormController); DeleteObjectType.prototype.onPostParamsRetrieved = function(post, cb) { var self = this; diff --git a/plugins/pencilblue/controllers/actions/admin/site_settings/content.js b/plugins/pencilblue/controllers/actions/admin/site_settings/content.js index 640349513..00455810c 100755 --- a/plugins/pencilblue/controllers/actions/admin/site_settings/content.js +++ b/plugins/pencilblue/controllers/actions/admin/site_settings/content.js @@ -24,24 +24,7 @@ module.exports = function(pb) { * Saves the site's content settings */ function Content(){} - util.inherits(Content, pb.BaseController); - - Content.prototype.init = function (props, cb) { - var self = this; - - pb.BaseController.prototype.init.call(self, props, function() { - self.pathSiteUid = pb.SiteService.getCurrentSite(self.pathVars.siteid); - pb.SiteService.siteExists(self.pathSiteUid, function (err, exists) { - if (!exists) { - self.reqHandler.serve404(); - } - else { - self.settings = pb.SettingServiceFactory.getServiceBySite(self.pathSiteUid, true); - cb(); - } - }); - }); - }; + util.inherits(Content, pb.BaseAdminController); Content.prototype.render = function(cb) { var self = this; diff --git a/plugins/pencilblue/controllers/admin/plugins/plugin_settings.js b/plugins/pencilblue/controllers/admin/plugins/plugin_settings.js index ed1dac6ea..bdd27ac32 100755 --- a/plugins/pencilblue/controllers/admin/plugins/plugin_settings.js +++ b/plugins/pencilblue/controllers/admin/plugins/plugin_settings.js @@ -37,6 +37,12 @@ module.exports = function(pb) { } util.inherits(PluginSettingsFormController, pb.BaseAdminController); + /** + * Initialize controller and plugin service + * @override + * @param props + * @param cb + */ PluginSettingsFormController.prototype.init = function (props, cb) { var self = this; pb.BaseAdminController.prototype.init.call(self, props, function () { diff --git a/plugins/pencilblue/controllers/admin/site_settings/content.js b/plugins/pencilblue/controllers/admin/site_settings/content.js index d9a405345..e542137b5 100755 --- a/plugins/pencilblue/controllers/admin/site_settings/content.js +++ b/plugins/pencilblue/controllers/admin/site_settings/content.js @@ -24,32 +24,11 @@ module.exports = function(pb) { * Interface for the site's content settings */ function Content(){} - util.inherits(Content, pb.BaseController); + util.inherits(Content, pb.BaseAdminController); //statics var SUB_NAV_KEY = 'content_settings'; - Content.prototype.init = function (props, cb) { - var self = this; - - pb.BaseController.prototype.init.call(self, props, function() { - self.pathSiteUid = pb.SiteService.getCurrentSite(self.pathVars.siteid); - pb.SiteService.siteExists(self.pathSiteUid, function (err, exists) { - if (!exists) { - self.reqHandler.serve404(); - } - else { - self.pathSitePrefix = pb.SiteService.getCurrentSitePrefix(self.pathSiteUid); - var siteService = new pb.SiteService(); - siteService.getSiteNameByUid(self.pathSiteUid, function (siteName) { - self.siteName = siteName; - cb(); - }); - } - }); - }); - }; - Content.prototype.render = function(cb) { var self = this; diff --git a/plugins/pencilblue/controllers/api/admin/content/objects/types/available.js b/plugins/pencilblue/controllers/api/admin/content/objects/types/available.js index 861b9eeca..a17ba14f6 100644 --- a/plugins/pencilblue/controllers/api/admin/content/objects/types/available.js +++ b/plugins/pencilblue/controllers/api/admin/content/objects/types/available.js @@ -24,11 +24,7 @@ module.exports = function(pb) { * Checks to see if the proposed name for a custom object type is available */ function GetObjectTypeNameAvailable(){} - util.inherits(GetObjectTypeNameAvailable, pb.FormController); - - GetObjectTypeNameAvailable.prototype.init = function (props, cb) { - pb.BaseAdminController.overrideInit(this, props, cb); - }; + util.inherits(GetObjectTypeNameAvailable, pb.AdminFormController); GetObjectTypeNameAvailable.prototype.render = function(cb) { var self = this; diff --git a/plugins/pencilblue/controllers/api/comments/new_comment.js b/plugins/pencilblue/controllers/api/comments/new_comment.js index bc0704400..46ecdaf2b 100755 --- a/plugins/pencilblue/controllers/api/comments/new_comment.js +++ b/plugins/pencilblue/controllers/api/comments/new_comment.js @@ -25,11 +25,7 @@ module.exports = function NewCommentModule(pb) { * Creates a new comment */ function NewComment(){} - util.inherits(NewComment, pb.FormController); - - NewComment.prototype.init = function (props, cb) { - pb.BaseAdminController.overrideInit(this, props, cb); - }; + util.inherits(NewComment, pb.AdminFormController); NewComment.prototype.onPostParamsRetrieved = function(post, cb) { var self = this; From a903ea2c16a3c9c5c2f7c32bb817d607d7c7257f Mon Sep 17 00:00:00 2001 From: andparker Date: Tue, 19 May 2015 10:09:14 -0400 Subject: [PATCH 158/790] Removes the libraries pill for non-global contexts | Makes content settings cancel button site aware --- .../admin/site_settings/content.js | 21 ++++++++++++------- .../admin/site_settings/content.html | 2 +- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/plugins/pencilblue/controllers/admin/site_settings/content.js b/plugins/pencilblue/controllers/admin/site_settings/content.js index d9a405345..c336ba6e7 100755 --- a/plugins/pencilblue/controllers/admin/site_settings/content.js +++ b/plugins/pencilblue/controllers/admin/site_settings/content.js @@ -79,7 +79,7 @@ module.exports = function(pb) { ]; var contentService = new pb.ContentService(this.pathSiteUid, true); - var pills = pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, 'content', { pathSitePrefix: self.pathSitePrefix }); + var pills = pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, 'content', { pathSiteUid: self.pathSiteUid, pathSitePrefix: self.pathSitePrefix }); pills = pb.AdminSubnavService.addSiteToPills(pills, this.siteName); contentService.getSettings(function(err, contentSettings) { @@ -100,7 +100,8 @@ module.exports = function(pb) { }; Content.getSubNavItems = function(key, ls, data) { - return [{ + + var subNavItems = [{ name: 'configuration', title: ls.get('CONTENT'), icon: 'chevron-left', @@ -110,12 +111,18 @@ module.exports = function(pb) { title: ls.get('EMAIL'), icon: 'envelope', href: '/admin' + data.pathSitePrefix + '/site_settings/email' - }, { - name: 'libraries', - title: ls.get('LIBRARIES'), - icon: 'book', - href: '/admin' + data.pathSitePrefix + '/site_settings/libraries' }]; + + if (data.pathSiteUid === pb.SiteService.GLOBAL_SITE) { + subNavItems.push({ + name: 'libraries', + title: ls.get('LIBRARIES'), + icon: 'book', + href: '/admin' + data.pathSitePrefix + '/site_settings/libraries' + }); + } + + return subNavItems; }; //register admin sub-nav diff --git a/plugins/pencilblue/templates/admin/site_settings/content.html b/plugins/pencilblue/templates/admin/site_settings/content.html index d8907545f..7a14ca557 100755 --- a/plugins/pencilblue/templates/admin/site_settings/content.html +++ b/plugins/pencilblue/templates/admin/site_settings/content.html @@ -134,7 +134,7 @@
- +  ^loc_CANCEL^ ^tmp_admin=elements=save_button^ From 16ec0e9edaed24d62fe65da6005e464d787bd629 Mon Sep 17 00:00:00 2001 From: btidwell Date: Tue, 19 May 2015 10:24:08 -0400 Subject: [PATCH 159/790] use query service for loading all items in blog Pushing to seek help in debugging queries under blog_filter using query service. --- include/service/entities/article_service.js | 18 +++++ plugins/portfolio/controllers/blog.js | 33 ++++------ plugins/portfolio/controllers/blog_filter.js | 66 ++++++++++++------- .../templates/elements/top_menu.html | 2 +- 4 files changed, 72 insertions(+), 47 deletions(-) diff --git a/include/service/entities/article_service.js b/include/service/entities/article_service.js index ca04beca8..7d1d20efd 100755 --- a/include/service/entities/article_service.js +++ b/include/service/entities/article_service.js @@ -70,6 +70,24 @@ module.exports = function ArticleServiceModule(pb) { this.find(pb.DAO.getIdWhere(articleId), cb); }; + /** + * Finds an article or page by Id + * + * @method findById + * @param {String} url The article's url + * @param {Function} cb Callback function + */ + ArticleService.prototype.findByUrl = function(url, cb) { + this.find({url:url}, function(err, result) { + if(result && result.length > 0) { + cb(err, result[0]); + } + else { + cb(err, null); + } + }); + }; + /** * Finds articles by section * diff --git a/plugins/portfolio/controllers/blog.js b/plugins/portfolio/controllers/blog.js index 6cf88e343..86ca38c9e 100755 --- a/plugins/portfolio/controllers/blog.js +++ b/plugins/portfolio/controllers/blog.js @@ -38,17 +38,10 @@ module.exports = function BlogModule(pb) { Blog.prototype.init = function(props, cb) { var self = this; - pb.BaseController.prototype.init.call(self, props, function () { - var siteService = new pb.SiteService(); - siteService.getByUid(self.site, function(err, site) { - if (!site) { - self.reqHandler.serve404(); - } - else { - self.siteObj = site; - cb(); - } - }); + pb.BaseController.prototype.init.call(self, props, function () {var siteService = new pb.SiteService(); + self.navService = new pb.SectionService(this.site); + self.queryService = new pb.SiteQueryService(this.site); + cb(); }); }; @@ -250,8 +243,7 @@ module.exports = function BlogModule(pb) { return; } - var dao = new pb.DAO(); - dao.loadById(self.req.pencilblue_section, 'section', callback); + self.queryService.loadById(self.req.pencilblue_section, 'section', callback); } }; async.parallel(tasks, cb); @@ -264,7 +256,7 @@ module.exports = function BlogModule(pb) { var article = this.req.pencilblue_article || null; var page = this.req.pencilblue_page || null; - var service = new ArticleService(); + var service = new ArticleService(this.site, pb.config.multisite); if(this.req.pencilblue_preview) { if(this.req.pencilblue_preview == page || article) { if(page) { @@ -403,11 +395,10 @@ module.exports = function BlogModule(pb) { else if(searchId = this.req.pencilblue_section || this.req.pencilblue_topic) { var objType = this.req.pencilblue_section ? 'section' : 'topic'; - var dao = new pb.DAO(); if(this.req.pencilblue_topic) { searchId = searchId.toString(); } - dao.loadById(searchId, objType, function(err, obj) { + this.queryService.loadById(searchId, objType, function(err, obj) { if(util.isError(err) || obj === null) { cb(null, pb.config.siteName); return; @@ -423,7 +414,8 @@ module.exports = function BlogModule(pb) { Blog.prototype.getNavigation = function(cb) { var options = { - currUrl: this.req.url + currUrl: this.req.url, + site: this.site }; TopMenu.getTopMenu(this.session, this.ls, options, function(themeSettings, navigation, accountButtons) { TopMenu.getBootstrapNav(navigation, accountButtons, function(navigation, accountButtons) { @@ -435,7 +427,7 @@ module.exports = function BlogModule(pb) { Blog.prototype.getSideNavigation = function(articles, cb) { var self = this; - var pluginService = new pb.PluginService(); + var pluginService = new pb.PluginService(this.site); pluginService.getSetting('show_side_navigation', 'portfolio', function(err, showSideNavigation) { if(!showSideNavigation) { cb('', null); @@ -473,15 +465,14 @@ module.exports = function BlogModule(pb) { }, limit: 6 }; - var dao = new pb.DAO(); - dao.q('article', opts, function(err, relatedArticles) { + self.queryService.q('article', opts, function(err, relatedArticles) { if(relatedArticles.length === 0) { opts = { where: pb.DAO.ANYWHERE, order: {name: 1} }; - dao.q('topic', opts, function(err, topicObjects) { + self.queryService.q('topic', opts, function(err, topicObjects) { var articleTopics = []; for(var i = 0; i < topics.length && articleTopics.length < 20; i++) { for(var j = 0; j < topicObjects.length; j++) { diff --git a/plugins/portfolio/controllers/blog_filter.js b/plugins/portfolio/controllers/blog_filter.js index 68a61288d..b00121204 100755 --- a/plugins/portfolio/controllers/blog_filter.js +++ b/plugins/portfolio/controllers/blog_filter.js @@ -14,14 +14,12 @@ module.exports = function BlogFilterModule(pb) { function BlogFilter(){} util.inherits(BlogFilter, Blog); - BlogFilter.prototype.render = function(cb) { var self = this; var custUrl = this.pathVars.customUrl; - var dao = new pb.DAO(); var fieldToMatch = 'url'; - var objectType = 'section'; + self.objectType = 'section'; if(self.req.url.indexOf('/preview/') > -1) { self.req.pencilblue_preview = this.pathVars.id; @@ -36,10 +34,14 @@ module.exports = function BlogFilterModule(pb) { return; } else if(self.req.url.indexOf('/article/') > -1) { - objectType = 'article'; + self.objectType = 'article'; + //self.processArticle(custUrl, cb); + //return; } else if(self.req.url.indexOf('/page/') > -1) { - objectType = 'page'; + self.objectType = 'page'; + self.processArticle(custUrl, cb); + return; } else if(self.req.url.indexOf('/topic/') > -1) { self.req.pencilblue_topic = custUrl; @@ -47,36 +49,50 @@ module.exports = function BlogFilterModule(pb) { return; } - dao.loadByValue(fieldToMatch, custUrl, objectType, function(err, result) { - if (util.isError(err) || result === null) { - if(pb.validation.isIdStr(custUrl)) { - dao.loadById(custUrl, objectType, function(err, result) { - if (util.isError(err) || result === null || result.draft) { - self.reqHandler.serve404(); - return; - } + this.queryService.loadByValue(fieldToMatch, custUrl, self.objectType, function(err, result) { + self.handleResult(err, result, cb); + }); + }; - self.req['pencilblue_' + objectType] = result._id.toString(); - this.result = result; - BlogFilter.super_.prototype.render.apply(self, [cb]); - }); + BlogFilter.prototype.processArticle = function(custUrl, cb) { + var self = this; + var articleService = new pb.ArticleService(self.site, pb.config.multisite); + articleService.setContentType(this.objectType); + articleService.findByUrl(custUrl, function(err, result) { + self.handleResult(err, result, cb); + }); + }; + + BlogFilter.prototype.handleResult = function(err, result, cb) { + var self = this; + if (util.isError(err) || result === null) { + if(pb.validation.isIdStr(self.pathVars.custUrl)) { + this.queryService.loadById(self.pathVars.custUrl, self.objectType, function(err, result) { + if (util.isError(err) || result === null || result.draft) { + self.reqHandler.serve404(); + return; + } + + self.req['pencilblue_' + self.objectType] = result._id.toString(); + this.result = result; + BlogFilter.super_.prototype.render.apply(self, [cb]); + }); } else { - self.reqHandler.serve404(); + self.reqHandler.serve404(); } return; - } + } - if(result.draft) { + if(result.draft) { self.reqHandler.serve404(); return; - } + } - self.req['pencilblue_' + objectType] = result._id.toString(); - this.result = result; - BlogFilter.super_.prototype.render.apply(self, [cb]); - }); + self.req['pencilblue_' + self.objectType] = result._id.toString(); + this.result = result; + BlogFilter.super_.prototype.render.apply(self, [cb]); }; BlogFilter.prototype.getPageTitle = function() { diff --git a/plugins/portfolio/templates/elements/top_menu.html b/plugins/portfolio/templates/elements/top_menu.html index 5f6a5e9f8..dc5e1c586 100755 --- a/plugins/portfolio/templates/elements/top_menu.html +++ b/plugins/portfolio/templates/elements/top_menu.html @@ -7,7 +7,7 @@ - + From 0982108fe2ae715adae45e9475cc7112216b53d4 Mon Sep 17 00:00:00 2001 From: Eugene Chang Date: Tue, 19 May 2015 10:24:37 -0400 Subject: [PATCH 160/790] Refactoring out siteExists --- controllers/admin/base_admin_controller.js | 19 +++++++ plugins/pencilblue/controllers/admin/index.js | 29 ++-------- .../admin/plugins/manage_plugins.js | 53 ++++++------------- .../admin/plugins/plugin_details.js | 48 +++++------------ .../admin/plugins/plugin_settings.js | 40 +++----------- .../controllers/admin/themes/manage_themes.js | 32 +++-------- .../controllers/api/plugins/plugin_api.js | 33 ++---------- 7 files changed, 69 insertions(+), 185 deletions(-) diff --git a/controllers/admin/base_admin_controller.js b/controllers/admin/base_admin_controller.js index c301e75ce..926170901 100644 --- a/controllers/admin/base_admin_controller.js +++ b/controllers/admin/base_admin_controller.js @@ -29,6 +29,12 @@ module.exports = function BaseAdminControllerModule(pb) { } util.inherits(BaseAdminController, BaseController); + /** + * Initializes the admin controller with site-related info + * @override + * @param props + * @param cb + */ BaseAdminController.prototype.init = function (props, cb) { var self = this; BaseController.prototype.init.call(self, props, function () { @@ -51,5 +57,18 @@ module.exports = function BaseAdminControllerModule(pb) { }); }; + /** + * Centralized place to obtain the pills to be displayed on top of the admin controller + * + * @param navKey + * @param localizationService + * @param activePill + * @param data + */ + BaseAdminController.prototype.getAdminPills = function (navKey, localizationService, activePill, data) { + var pills = pb.AdminSubnavService.get(navKey, localizationService, activePill, data); + return pb.AdminSubnavService.addSiteToPills(pills, this.siteName); + }; + return BaseAdminController; }; \ No newline at end of file diff --git a/plugins/pencilblue/controllers/admin/index.js b/plugins/pencilblue/controllers/admin/index.js index 98fb831b8..aacf5970a 100755 --- a/plugins/pencilblue/controllers/admin/index.js +++ b/plugins/pencilblue/controllers/admin/index.js @@ -29,25 +29,7 @@ module.exports = function AdminIndexControllerModule(pb) { * @constructor */ function AdminIndexController(){} - util.inherits(AdminIndexController, pb.BaseController); - - /** - * @see BaseController#render - */ - AdminIndexController.prototype.render = function(cb) { - var self = this; - var site = pb.SiteService.getCurrentSite(self.pathVars.siteid); - - pb.SiteService.siteExists(site, function (err, siteExists) { - if (siteExists) { - self.onSiteValidated(cb); - } - else { - self.reqHandler.serve404(); - return; - } - }); - }; + util.inherits(AdminIndexController, pb.BaseAdminController); /** * @@ -56,7 +38,7 @@ module.exports = function AdminIndexControllerModule(pb) { * @param cb * */ - AdminIndexController.prototype.onSiteValidated = function onSiteValidated(cb) { + AdminIndexController.prototype.render = function (cb) { var self = this; //gather all the data @@ -102,18 +84,17 @@ module.exports = function AdminIndexControllerModule(pb) { * @param {Function} cb A callback that provides two parameters: cb(Error, Object) */ AdminIndexController.prototype.gatherData = function(cb) { + var self = this; var tasks = { //article count articleCount: function(callback) { - var dao = new pb.DAO(); - dao.count('article', pb.DAO.ANYWHERE, callback); + self.siteQueryService.count('article', pb.DAO.ANYWHERE, callback); }, //page count pageCount: function(callback) { - var dao = new pb.DAO(); - dao.count('page', pb.DAO.ANYWHERE, callback); + self.siteQueryService.count('page', pb.DAO.ANYWHERE, callback); }, //cluster status diff --git a/plugins/pencilblue/controllers/admin/plugins/manage_plugins.js b/plugins/pencilblue/controllers/admin/plugins/manage_plugins.js index e3128487e..01d285de0 100755 --- a/plugins/pencilblue/controllers/admin/plugins/manage_plugins.js +++ b/plugins/pencilblue/controllers/admin/plugins/manage_plugins.js @@ -14,13 +14,11 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -var async = require('async'); module.exports = function(pb) { //pb dependencies var util = pb.util; - var BaseController = pb.BaseController; /** * Interface for managing plugins @@ -28,55 +26,34 @@ module.exports = function(pb) { function ManagePlugins(){} //inheritance - util.inherits(ManagePlugins, BaseController); + util.inherits(ManagePlugins, pb.BaseAdminController); //statics var SUB_NAV_KEY = 'manage_plugins'; - ManagePlugins.prototype.render = function(cb) { + ManagePlugins.prototype.render = function (cb) { var self = this; - var site = pb.SiteService.getCurrentSite(self.pathVars.siteid); - pb.SiteService.siteExists(site, function (err, siteExists) { - if (siteExists) { - self.onSiteValidated(site, cb); - } - else { - self.reqHandler.serve404(); + var pluginService = new pb.PluginService(); + pluginService.getPluginMap(function (err, map) { + if (util.isError(err)) { + self.reqHandler.serveError(err); return; } - }); - }; - - ManagePlugins.prototype.onSiteValidated = function onSiteValidated(site, cb) { - var self = this; - var prefix = pb.SiteService.getCurrentSitePrefix(site); - - //get the data - var tasks = { - pluginMap: function(callback) { - var pluginService = new pb.PluginService(site); - pluginService.getPluginMap(callback); - }, - siteName: function(callback) { - var siteService = new pb.SiteService(); - siteService.getSiteNameByUid(site, function(siteName) { - callback(null, siteName); - }); - } - }; - async.parallel(tasks, function(err, results) { //setup angular + var prefix = self.sitePrefix; + var pills = pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, null, {sitePrefix: prefix}); + pills = pb.AdminSubnavService.addSiteToPills(pills, self.siteName); var angularObjects = pb.ClientJs.getAngularObjects({ navigation: pb.AdminNavigation.get(self.session, ['plugins', 'manage'], self.ls), - pills: pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, null, { sitePrefix: prefix }), - installedPlugins: results.pluginMap.active, - inactivePlugins: results.pluginMap.inactive, - availablePlugins: results.pluginMap.available, + pills: pills, + installedPlugins: map.active, + inactivePlugins: map.inactive, + availablePlugins: map.available, sitePrefix: prefix, - siteUid: site, - siteName: results.siteName + siteUid: self.pathSiteUId, + siteName: self.siteName }); //load the template self.ts.registerLocal('angular_objects', new pb.TemplateValue(angularObjects, false)); diff --git a/plugins/pencilblue/controllers/admin/plugins/plugin_details.js b/plugins/pencilblue/controllers/admin/plugins/plugin_details.js index f2284683a..17082fa44 100755 --- a/plugins/pencilblue/controllers/admin/plugins/plugin_details.js +++ b/plugins/pencilblue/controllers/admin/plugins/plugin_details.js @@ -19,11 +19,8 @@ module.exports = function(pb) { //pb dependencies var util = pb.util; - var BaseController = pb.BaseController; var PluginService = pb.PluginService; var LocalizationService = pb.LocalizationService; - var SiteService = pb.SiteService; - /** * Interface for viewing plugin details @@ -32,7 +29,8 @@ module.exports = function(pb) { * @extends BaseController */ function PluginDetailsViewController(){} - util.inherits(PluginDetailsViewController, BaseController); + + util.inherits(PluginDetailsViewController, pb.BaseAdminController); //statics var SUB_NAV_KEY = 'plugin_details'; @@ -40,34 +38,13 @@ module.exports = function(pb) { /** * * @method render - * - */ - PluginDetailsViewController.prototype.render = function(cb) { - var self = this; - var site = pb.SiteService.getCurrentSite(self.pathVars.siteid); - - pb.SiteService.siteExists(site, function (err, siteExists) { - if (siteExists) { - self.onSiteValidated(site, cb); - } - else { - self.reqHandler.serve404(); - return; - } - }); - }; - - /** - * - * @method onSiteValidated - * @param site * @param cb * */ - PluginDetailsViewController.prototype.onSiteValidated = function onSiteValidated(site, cb) { + PluginDetailsViewController.prototype.render = function (cb) { var self = this; - this.getDetails(this.pathVars.id, site, function(err, obj) { + this.getDetails(this.pathVars.id, function (err, obj) { if (util.isError(err)) { throw err; } @@ -78,13 +55,15 @@ module.exports = function(pb) { } //angular data + var pills = pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, null, obj); + pills = pb.AdminSubnavService.addSiteToPills(pills, self.siteName); var angularObjects = pb.ClientJs.getAngularObjects({ - pills: pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, null, obj), + pills: pills, navigation: pb.AdminNavigation.get(self.session, ['plugins', 'manage'], self.ls), d: obj.details, status: obj.status, is_active: PluginService.isActivePlugin(obj.details.uid), - sitePrefix: SiteService.getCurrentSitePrefix(SiteService.getCurrentSite(self.pathVars.siteid)) + sitePrefix: self.sitePrefix }); //render page @@ -101,11 +80,10 @@ module.exports = function(pb) { * @method getDetails * */ - PluginDetailsViewController.prototype.getDetails = function(puid, site, cb) { + PluginDetailsViewController.prototype.getDetails = function (puid, cb) { var self = this; - var sitePrefix = SiteService.getCurrentSitePrefix(site); - var pluginService = new pb.PluginService(site); + var pluginService = new pb.PluginService(self.pathSiteUId); pluginService.getPluginBySite(puid, function(err, plugin) { if (util.isError(err)) { cb(err, plugin); @@ -115,8 +93,7 @@ module.exports = function(pb) { if (plugin) { var obj = { details: plugin, - status: self.ls.get(PluginService.isActivePlugin(plugin.uid, site) ? 'ACTIVE' : 'INACTIVE'), - sitePrefix: sitePrefix + status: self.ls.get(PluginService.isActivePlugin(plugin.uid) ? 'ACTIVE' : 'INACTIVE') }; cb(err, obj); return; @@ -127,8 +104,7 @@ module.exports = function(pb) { var detailsFile = PluginService.getDetailsPath(puid); PluginService.loadDetailsFile(detailsFile, function(err, details) { var obj = { - status: self.ls.get('ERRORED'), - sitePrefix: sitePrefix + status: self.ls.get('ERRORED') }; if (util.isError(err)) { obj.details = { diff --git a/plugins/pencilblue/controllers/admin/plugins/plugin_settings.js b/plugins/pencilblue/controllers/admin/plugins/plugin_settings.js index bdd27ac32..6585603ef 100755 --- a/plugins/pencilblue/controllers/admin/plugins/plugin_settings.js +++ b/plugins/pencilblue/controllers/admin/plugins/plugin_settings.js @@ -54,20 +54,7 @@ module.exports = function(pb) { //statics var SUB_NAV_KEY = 'plugin_settings'; - PluginSettingsFormController.prototype.get = function(cb) { - var self = this; - - pb.SiteService.siteExists(self.pathSiteUId, function (err, siteExists) { - if (siteExists) { - self.onSiteValidatedGet(cb); - } - else { - self.reqHandler.serve404(); - } - }); - }; - - PluginSettingsFormController.prototype.onSiteValidatedGet = function (cb) { + PluginSettingsFormController.prototype.get = function (cb) { var self = this; console.log(this.constructor.name); var uid = this.pathVars.id; @@ -118,21 +105,22 @@ module.exports = function(pb) { } ]; - var prefix = pb.SiteService.getCurrentSitePrefix(self.pathSiteUId); //setup angular var data = { plugin: plugin, settingType: self.getType(), - sitePrefix: prefix + sitePrefix: self.sitePrefix }; + var pills = pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, null, data); + pills = pb.AdminSubnavService.addSiteToPills(pills, self.siteName); var angularObjects = pb.ClientJs.getAngularObjects({ - pills: pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, null, data), + pills: pills, tabs: tabs, navigation: pb.AdminNavigation.get(self.session, ['plugins', 'manage'], self.ls), settings: clone, pluginUID: uid, type: data.settingType, - sitePrefix: prefix + sitePrefix: self.sitePrefix }); //render page @@ -143,22 +131,8 @@ module.exports = function(pb) { }); }); }; - - - PluginSettingsFormController.prototype.post = function(cb) { - var self = this; - - pb.SiteService.siteExists(self.pathSiteUId, function (err, siteExists) { - if (siteExists) { - self.onSiteValidatedPost(cb); - } - else { - self.reqHandler.serve404(); - } - }); - }; - PluginSettingsFormController.prototype.onSiteValidatedPost = function (cb) { + PluginSettingsFormController.prototype.post = function (cb) { var self = this; console.log(this.constructor.name); var post = this.body; diff --git a/plugins/pencilblue/controllers/admin/themes/manage_themes.js b/plugins/pencilblue/controllers/admin/themes/manage_themes.js index bf6930570..9256940be 100755 --- a/plugins/pencilblue/controllers/admin/themes/manage_themes.js +++ b/plugins/pencilblue/controllers/admin/themes/manage_themes.js @@ -19,38 +19,21 @@ module.exports = function(pb) { //pb dependencies var util = pb.util; - var BaseController = pb.BaseController; - var DAO = pb.DAO; var UrlService = pb.UrlService; /** * Interface for managing themes */ function ManageThemes(){} - util.inherits(ManageThemes, BaseController); + util.inherits(ManageThemes, pb.BaseAdminController); //statics var SUB_NAV_KEY = 'themes_index'; - ManageThemes.prototype.render = function(cb) { - var self = this; - var site = pb.SiteService.getCurrentSite(self.pathVars.siteid); - - pb.SiteService.siteExists(site, function (err, siteExists) { - if (siteExists) { - self.onSiteValidated(site, cb); - } - else { - self.reqHandler.serve404(); - } - }); - }; - - ManageThemes.prototype.onSiteValidated = function (site, cb) { + ManageThemes.prototype.render = function (cb) { var self = this; //get plugs with themes - var sitePrefix = pb.SiteService.getCurrentSitePrefix(site); var pluginService = new pb.PluginService(site); pluginService.getPluginsWithThemesBySite(function (err, themes) { if (util.isError(err)) { @@ -58,8 +41,7 @@ module.exports = function(pb) { } //get active theme - var settings = pb.SettingServiceFactory.getService(pb.config.settings.use_memory, pb.config.settings.use_cache, site, true); - settings.get('active_theme', function(err, activeTheme) { + self.settings.get('active_theme', function(err, activeTheme) { if (util.isError(err)) { throw err; } @@ -72,7 +54,7 @@ module.exports = function(pb) { }); - settings.get('site_logo', function(err, logo) { + self.settings.get('site_logo', function(err, logo) { if(util.isError(err)) { pb.log.error("ManageThemes: Failed to retrieve site logo: "+err.stack); } @@ -88,19 +70,19 @@ module.exports = function(pb) { } var subNavData = { - sitePrefix: sitePrefix + sitePrefix: self.sitePrefix }; //setup angular var angularObjects = pb.ClientJs.getAngularObjects({ navigation: pb.AdminNavigation.get(self.session, ['plugins', 'themes'], self.ls), - pills: pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, null, subNavData), + pills: self.getPills(SUB_NAV_KEY, self.ls, null, subNavData), tabs: self.getTabs(), themes: themes, options: options, siteLogo: siteLogo, activeTheme: activeTheme, - sitePrefix: sitePrefix + sitePrefix: self.sitePrefix }); self.ts.registerLocal('image_title', ''); diff --git a/plugins/pencilblue/controllers/api/plugins/plugin_api.js b/plugins/pencilblue/controllers/api/plugins/plugin_api.js index 1d9157785..fef5fa12e 100755 --- a/plugins/pencilblue/controllers/api/plugins/plugin_api.js +++ b/plugins/pencilblue/controllers/api/plugins/plugin_api.js @@ -27,8 +27,6 @@ module.exports = function(pb) { var PluginService = pb.PluginService; var RequestHandler = pb.RequestHandler; - var GLOBAL_SITE = pb.SiteService.GLOBAL_SITE; - /** * Controller to properly route and handle remote calls to interact with * the PluginService @@ -44,7 +42,7 @@ module.exports = function(pb) { * @type {PluginService} */ } - util.inherits(PluginApiController, BaseController); + util.inherits(PluginApiController, pb.BaseAdminController); //constants /** @@ -61,7 +59,7 @@ module.exports = function(pb) { uninstall: true, reset_settings: true, initialize: true, - set_theme: true + set_theme: true, }; /** @@ -71,31 +69,9 @@ module.exports = function(pb) { * @param {Function} cb */ PluginApiController.prototype.render = function(cb) { - var self = this; - var site = pb.SiteService.getCurrentSite(this.pathVars.siteid); - - pb.SiteService.siteExists(site, function (err, siteExists) { - if (siteExists) { - self.onSiteValidated(site, cb); - } - else { - self.reqHandler.serve404(); - return; - } - }); - }; - - /** - * Triggers after the site is validated - * @method onSiteValidated - * @param site - * @param cb - */ - PluginApiController.prototype.onSiteValidated = function onSiteValidated(site, cb) { var action = this.pathVars.action; var identifier = this.pathVars.id; - this.site = pb.SiteService.getCurrentSite(this.pathVars.siteid); - this.pluginService = new pb.PluginService(this.site); + this.pluginService = new pb.PluginService(this.pathSiteUId); //validate action var errors = []; @@ -262,8 +238,7 @@ module.exports = function(pb) { } var theme = plugin ? plugin.uid : uid; - var settings = pb.SettingServiceFactory.getService(pb.config.settings.use_memory, pb.config.settings.use_cache, self.site, true); - settings.set('active_theme', theme, function(err, result) { + self.settings.set('active_theme', theme, function(err, result) { if (util.isError(err)) { var content = BaseController.apiResponse(BaseController.API_FAILURE, util.format(self.ls.get('SET_THEME_FAILED'), uid), [err.message]); cb({content: content, code: 500}); From 37932530d648c6d834b1b5eb1cd83b49d21c53b6 Mon Sep 17 00:00:00 2001 From: btidwell Date: Tue, 19 May 2015 10:32:19 -0400 Subject: [PATCH 161/790] use self in anon function --- plugins/portfolio/controllers/blog.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/portfolio/controllers/blog.js b/plugins/portfolio/controllers/blog.js index 86ca38c9e..7e6d5810e 100755 --- a/plugins/portfolio/controllers/blog.js +++ b/plugins/portfolio/controllers/blog.js @@ -39,8 +39,8 @@ module.exports = function BlogModule(pb) { Blog.prototype.init = function(props, cb) { var self = this; pb.BaseController.prototype.init.call(self, props, function () {var siteService = new pb.SiteService(); - self.navService = new pb.SectionService(this.site); - self.queryService = new pb.SiteQueryService(this.site); + self.navService = new pb.SectionService(self.site); + self.queryService = new pb.SiteQueryService(self.site); cb(); }); }; From fb850ae665cfc3c1dfb31b028671e2c3a35c50e4 Mon Sep 17 00:00:00 2001 From: btidwell Date: Tue, 19 May 2015 10:55:58 -0400 Subject: [PATCH 162/790] remove added functions functions were added that are unnecessary with use of site query service --- plugins/portfolio/controllers/blog_filter.js | 72 ++++++++------------ 1 file changed, 27 insertions(+), 45 deletions(-) diff --git a/plugins/portfolio/controllers/blog_filter.js b/plugins/portfolio/controllers/blog_filter.js index b00121204..0a1821d9b 100755 --- a/plugins/portfolio/controllers/blog_filter.js +++ b/plugins/portfolio/controllers/blog_filter.js @@ -19,7 +19,7 @@ module.exports = function BlogFilterModule(pb) { var custUrl = this.pathVars.customUrl; var fieldToMatch = 'url'; - self.objectType = 'section'; + var objectType = 'section'; if(self.req.url.indexOf('/preview/') > -1) { self.req.pencilblue_preview = this.pathVars.id; @@ -34,14 +34,10 @@ module.exports = function BlogFilterModule(pb) { return; } else if(self.req.url.indexOf('/article/') > -1) { - self.objectType = 'article'; - //self.processArticle(custUrl, cb); - //return; + objectType = 'article'; } else if(self.req.url.indexOf('/page/') > -1) { - self.objectType = 'page'; - self.processArticle(custUrl, cb); - return; + objectType = 'page'; } else if(self.req.url.indexOf('/topic/') > -1) { self.req.pencilblue_topic = custUrl; @@ -49,50 +45,36 @@ module.exports = function BlogFilterModule(pb) { return; } - this.queryService.loadByValue(fieldToMatch, custUrl, self.objectType, function(err, result) { - self.handleResult(err, result, cb); - }); - }; - - BlogFilter.prototype.processArticle = function(custUrl, cb) { - var self = this; - var articleService = new pb.ArticleService(self.site, pb.config.multisite); - articleService.setContentType(this.objectType); - articleService.findByUrl(custUrl, function(err, result) { - self.handleResult(err, result, cb); - }); - }; + this.queryService.loadByValue(fieldToMatch, custUrl, objectType, function(err, result) { + if (util.isError(err) || result === null) { + if(pb.validation.isIdStr(self.pathVars.custUrl)) { + this.queryService.loadById(self.pathVars.custUrl, objectType, function(err, result) { + if (util.isError(err) || result === null || result.draft) { + self.reqHandler.serve404(); + return; + } - BlogFilter.prototype.handleResult = function(err, result, cb) { - var self = this; - if (util.isError(err) || result === null) { - if(pb.validation.isIdStr(self.pathVars.custUrl)) { - this.queryService.loadById(self.pathVars.custUrl, self.objectType, function(err, result) { - if (util.isError(err) || result === null || result.draft) { - self.reqHandler.serve404(); - return; - } + self.req['pencilblue_' + objectType] = result._id.toString(); + this.result = result; + BlogFilter.super_.prototype.render.apply(self, [cb]); + }); + } + else { + self.reqHandler.serve404(); + } - self.req['pencilblue_' + self.objectType] = result._id.toString(); - this.result = result; - BlogFilter.super_.prototype.render.apply(self, [cb]); - }); + return; } - else { + + if(result.draft) { self.reqHandler.serve404(); + return; } - return; - } - - if(result.draft) { - self.reqHandler.serve404(); - return; - } - - self.req['pencilblue_' + self.objectType] = result._id.toString(); - this.result = result; - BlogFilter.super_.prototype.render.apply(self, [cb]); + self.req['pencilblue_' + objectType] = result._id.toString(); + this.result = result; + BlogFilter.super_.prototype.render.apply(self, [cb]); + }); }; BlogFilter.prototype.getPageTitle = function() { From 755796120705ada4fc940af49ef29a2e7564eef2 Mon Sep 17 00:00:00 2001 From: Eugene Chang Date: Tue, 19 May 2015 11:23:25 -0400 Subject: [PATCH 163/790] Refactoring out admin pills --- controllers/admin/admin_form_controller.js | 2 ++ .../admin/content/comments/manage_comments.js | 3 +-- .../admin/content/navigation/nav_item_form.js | 3 +-- .../controllers/admin/content/navigation/nav_map.js | 3 +-- .../admin/content/objects/manage_objects.js | 6 +++--- .../controllers/admin/content/objects/object_form.js | 8 +++----- .../controllers/admin/content/objects/sort_objects.js | 9 +++------ .../admin/content/objects/types/manage_types.js | 11 ++++------- .../admin/content/objects/types/type_form.js | 7 ++----- .../controllers/admin/content/topics/import_topics.js | 3 +-- .../controllers/admin/content/topics/manage_topics.js | 3 +-- .../controllers/admin/content/topics/topic_form.js | 3 +-- .../controllers/admin/plugins/manage_plugins.js | 4 +--- .../controllers/admin/plugins/plugin_details.js | 5 +---- .../controllers/admin/plugins/plugin_settings.js | 4 +--- .../controllers/admin/site_settings/content.js | 7 ++----- 16 files changed, 28 insertions(+), 53 deletions(-) diff --git a/controllers/admin/admin_form_controller.js b/controllers/admin/admin_form_controller.js index 073a62284..116d67bc5 100644 --- a/controllers/admin/admin_form_controller.js +++ b/controllers/admin/admin_form_controller.js @@ -34,5 +34,7 @@ module.exports = function AdminFormControllerModule(pb) { BaseAdminController.prototype.init.call(this, props, cb); }; + AdminFormController.prototype.getAdminPills = BaseAdminController.prototype.getAdminPills; + return AdminFormController; }; \ No newline at end of file diff --git a/plugins/pencilblue/controllers/admin/content/comments/manage_comments.js b/plugins/pencilblue/controllers/admin/content/comments/manage_comments.js index 2c0894757..6ddc71d19 100755 --- a/plugins/pencilblue/controllers/admin/content/comments/manage_comments.js +++ b/plugins/pencilblue/controllers/admin/content/comments/manage_comments.js @@ -64,8 +64,7 @@ module.exports = function(pb) { //retrieve any details self.getCommentDetails(comments, function(commentsWithDetails) { - var pills = pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, SUB_NAV_KEY, {prefix: self.sitePrefix}); - pills = pb.AdminSubnavService.addSiteToPills(pills, self.siteName); + var pills = self.getAdminPills(SUB_NAV_KEY, self.ls, SUB_NAV_KEY, {prefix: self.sitePrefix}); var angularObjects = pb.ClientJs.getAngularObjects({ navigation: pb.AdminNavigation.get(self.session, ['content', 'comments'], self.ls), pills: pills, diff --git a/plugins/pencilblue/controllers/admin/content/navigation/nav_item_form.js b/plugins/pencilblue/controllers/admin/content/navigation/nav_item_form.js index 985867770..219f09ee4 100644 --- a/plugins/pencilblue/controllers/admin/content/navigation/nav_item_form.js +++ b/plugins/pencilblue/controllers/admin/content/navigation/nav_item_form.js @@ -58,8 +58,7 @@ module.exports = function(pb) { item: self.navItem, sitePrefix: self.sitePrefix }; - var pills = pb.AdminSubnavService.get(self.getSubnavKey(), self.ls, self.getSubnavKey(), navData); - data.pills = pb.AdminSubnavService.addSiteToPills(pills, self.siteName); + data.pills = self.getAdminPills(self.getSubnavKey(), self.ls, self.getSubnavKey(), navData); data.sitePrefix = self.sitePrefix; data.site = self.pathSiteUId; var angularObjects = pb.ClientJs.getAngularObjects(data); diff --git a/plugins/pencilblue/controllers/admin/content/navigation/nav_map.js b/plugins/pencilblue/controllers/admin/content/navigation/nav_map.js index d8f26902e..22a9030c8 100644 --- a/plugins/pencilblue/controllers/admin/content/navigation/nav_map.js +++ b/plugins/pencilblue/controllers/admin/content/navigation/nav_map.js @@ -52,11 +52,10 @@ module.exports = function(pb) { return; } - var pills = pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, SUB_NAV_KEY, {sitePrefix: self.sitePrefix}); var angularObjects = pb.ClientJs.getAngularObjects( { navigation: pb.AdminNavigation.get(self.session, ['content', 'sections'], self.ls), - pills: pb.AdminSubnavService.addSiteToPills(pills, self.siteName), + pills: self.getAdminPills(SUB_NAV_KEY, self.ls, SUB_NAV_KEY, {sitePrefix: self.sitePrefix}), navItems: NavigationMap.getOrderedItems(sections, sectionMap), icons: { container: 'inbox', diff --git a/plugins/pencilblue/controllers/admin/content/objects/manage_objects.js b/plugins/pencilblue/controllers/admin/content/objects/manage_objects.js index 820dca596..af857f939 100644 --- a/plugins/pencilblue/controllers/admin/content/objects/manage_objects.js +++ b/plugins/pencilblue/controllers/admin/content/objects/manage_objects.js @@ -56,12 +56,12 @@ module.exports = function(pb) { //none to manage if(customObjects.length === 0) { - return self.redirect(pb.UrlService.urlJoin('/admin' + self.pathSitePrefix + '/content/objects/', encodeURIComponent(vars.type_id), '/new'), cb); + return self.redirect(pb.UrlService.urlJoin('/admin' + self.sitePrefix + '/content/objects/', encodeURIComponent(vars.type_id), '/new'), cb); } var data = {}; - data.pathSitePrefix = self.pathSitePrefix; + data.pathSitePrefix = self.sitePrefix; data.custObjType = custObjType; var pills = pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, 'manage_objects', data); for(var i = 0; i < pills.length; i++) { @@ -78,7 +78,7 @@ module.exports = function(pb) { pills: pills, customObjects: customObjects, objectType: custObjType, - pathSitePrefix: self.pathSitePrefix + pathSitePrefix: self.sitePrefix }); var title = self.ls.get('MANAGE') + ' ' + custObjType.name; diff --git a/plugins/pencilblue/controllers/admin/content/objects/object_form.js b/plugins/pencilblue/controllers/admin/content/objects/object_form.js index 407b5bd4c..cd524f72f 100644 --- a/plugins/pencilblue/controllers/admin/content/objects/object_form.js +++ b/plugins/pencilblue/controllers/admin/content/objects/object_form.js @@ -38,7 +38,7 @@ module.exports = function(pb) { var vars = this.pathVars; if(!pb.validation.isIdStr(vars.type_id, true)) { - return self.redirect('/admin' + self.pathSitePrefix + '/content/objects/types', cb); + return self.redirect('/admin' + self.sitePrefix + '/content/objects/types', cb); } this.gatherData(vars, function(err, data) { @@ -83,9 +83,7 @@ module.exports = function(pb) { self.objectType = data.objectType; self.customObject = data.customObject; - var pills = pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, SUB_NAV_KEY, {objectType: self.objectType, customObject: self.customObject, pathSitePrefix: self.pathSitePrefix}); - data.pills = pb.AdminSubnavService.addSiteToPills(pills, self.siteName); - + data.pills = self.getAdminPills(SUB_NAV_KEY, self.ls, SUB_NAV_KEY, {objectType: self.objectType, customObject: self.customObject, pathSitePrefix: self.sitePrefix}); var angularObjects = pb.ClientJs.getAngularObjects(data); self.setPageName(self.customObject[pb.DAO.getIdField()] ? self.customObject.name : self.ls.get('NEW') + ' ' + self.objectType.name + ' ' + self.ls.get('OBJECT')); @@ -119,7 +117,7 @@ module.exports = function(pb) { }, pathSitePrefix: function(callback) { - callback(null, self.pathSitePrefix) + callback(null, self.sitePrefix) }, objectType: function(callback) { diff --git a/plugins/pencilblue/controllers/admin/content/objects/sort_objects.js b/plugins/pencilblue/controllers/admin/content/objects/sort_objects.js index fa856ade1..ecc097ac0 100644 --- a/plugins/pencilblue/controllers/admin/content/objects/sort_objects.js +++ b/plugins/pencilblue/controllers/admin/content/objects/sort_objects.js @@ -55,20 +55,17 @@ module.exports = function(pb) { //none to manage if(customObjects.length === 0) { - self.redirect('/admin' + self.pathSitePrefix + '/content/objects/' + vars.type_id + '/new', cb); + self.redirect('/admin' + self.sitePrefix + '/content/objects/' + vars.type_id + '/new', cb); return; } - var pills = pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, SUB_NAV_KEY, {objectType: objectType, pathSitePrefix: self.pathSitePrefix}); - pills = pb.AdminSubnavService.addSiteToPills(pills, self.siteName); - var angularObjects = pb.ClientJs.getAngularObjects( { navigation: pb.AdminNavigation.get(self.session, ['content', 'custom_objects'], self.ls), - pills: pills, + pills: self.getAdminPills(SUB_NAV_KEY, self.ls, SUB_NAV_KEY, {objectType: objectType, pathSitePrefix: self.sitePrefix}), customObjects: customObjects, objectType: objectType, - pathSitePrefix: self.pathSitePrefix + pathSitePrefix: self.sitePrefix }); self.setPageName(self.ls.get('SORT') + ' ' + objectType.name); diff --git a/plugins/pencilblue/controllers/admin/content/objects/types/manage_types.js b/plugins/pencilblue/controllers/admin/content/objects/types/manage_types.js index fc2a8c72f..6d98fc66d 100644 --- a/plugins/pencilblue/controllers/admin/content/objects/types/manage_types.js +++ b/plugins/pencilblue/controllers/admin/content/objects/types/manage_types.js @@ -40,7 +40,7 @@ module.exports = function(pb) { //none to manage if(custObjTypes.length === 0) { - self.redirect('/admin' + self.pathSitePrefix + '/content/objects/types/new', cb); + self.redirect('/admin' + self.sitePrefix + '/content/objects/types/new', cb); return; } @@ -48,16 +48,13 @@ module.exports = function(pb) { pb.CustomObjectService.setFieldTypesUsed(custObjTypes, self.ls); //build out the angular controller - var data = {}; - data.pathSitePrefix = self.pathSitePrefix; - var pills = pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, SUB_NAV_KEY, data); - pills = pb.AdminSubnavService.addSiteToPills(pills, self.siteName); + var data = {pathSitePrefix: self.sitePrefix}; var angularObjects = pb.ClientJs.getAngularObjects( { navigation: pb.AdminNavigation.get(self.session, ['content', 'custom_objects'], self.ls), - pills: pills, + pills: self.getAdminPills(SUB_NAV_KEY, self.ls, SUB_NAV_KEY, data), objectTypes: custObjTypes, - pathSitePrefix: self.pathSitePrefix + pathSitePrefix: self.sitePrefix }); self.setPageName(self.ls.get('MANAGE_OBJECT_TYPES')); diff --git a/plugins/pencilblue/controllers/admin/content/objects/types/type_form.js b/plugins/pencilblue/controllers/admin/content/objects/types/type_form.js index cea3b39f3..b47ded94f 100644 --- a/plugins/pencilblue/controllers/admin/content/objects/types/type_form.js +++ b/plugins/pencilblue/controllers/admin/content/objects/types/type_form.js @@ -46,10 +46,7 @@ module.exports = function(pb) { } self.objectType = data.objectType; - - var pills = pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, SUB_NAV_KEY, data); - data.pills = pb.AdminSubnavService.addSiteToPills(pills, self.siteName); - + data.pills = self.getAdminPills(SUB_NAV_KEY, self.ls, SUB_NAV_KEY, data); var angularObjects = pb.ClientJs.getAngularObjects(data); self.setPageName(self.objectType[pb.DAO.getIdField()] ? self.objectType.name : self.ls.get('NEW_OBJECT')); self.ts.registerLocal('angular_objects', new pb.TemplateValue(angularObjects, false)); @@ -87,7 +84,7 @@ module.exports = function(pb) { }, pathSitePrefix: function(callback) { - callback(null, self.pathSitePrefix) + callback(null, self.sitePrefix) }, objectTypes: function(callback) { diff --git a/plugins/pencilblue/controllers/admin/content/topics/import_topics.js b/plugins/pencilblue/controllers/admin/content/topics/import_topics.js index 79f0c3fcc..f47b6f4af 100755 --- a/plugins/pencilblue/controllers/admin/content/topics/import_topics.js +++ b/plugins/pencilblue/controllers/admin/content/topics/import_topics.js @@ -42,11 +42,10 @@ module.exports = function(pb) { } ]; - var pills = pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, 'manage_topics', {sitePrefix: self.sitePrefix}); var angularObjects = pb.ClientJs.getAngularObjects( { navigation: pb.AdminNavigation.get(self.session, ['content', 'topics'], self.ls), - pills: pb.AdminSubnavService.addSiteToPills(pills, self.siteName), + pills: self.getAdminPills(SUB_NAV_KEY, self.ls, 'manage_topics', {sitePrefix: self.sitePrefix}), tabs: tabs, sitePrefix: self.sitePrefix }); diff --git a/plugins/pencilblue/controllers/admin/content/topics/manage_topics.js b/plugins/pencilblue/controllers/admin/content/topics/manage_topics.js index 712da5fca..14de161ca 100755 --- a/plugins/pencilblue/controllers/admin/content/topics/manage_topics.js +++ b/plugins/pencilblue/controllers/admin/content/topics/manage_topics.js @@ -54,11 +54,10 @@ module.exports = function(pb) { return ((x < y) ? -1 : ((x > y) ? 1 : 0)); }); - var pills = pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, SUB_NAV_KEY, {sitePrefix: self.sitePrefix}); var angularObjects = pb.ClientJs.getAngularObjects( { navigation: pb.AdminNavigation.get(self.session, ['content', 'topics'], self.ls), - pills: pb.AdminSubnavService.addSiteToPills(pills, self.siteName), + pills: self.getAdminPills(SUB_NAV_KEY, self.ls, SUB_NAV_KEY, {sitePrefix: self.sitePrefix}), topics: topics, sitePrefix: self.sitePrefix }); diff --git a/plugins/pencilblue/controllers/admin/content/topics/topic_form.js b/plugins/pencilblue/controllers/admin/content/topics/topic_form.js index ff7ed4df6..bd4fd578a 100644 --- a/plugins/pencilblue/controllers/admin/content/topics/topic_form.js +++ b/plugins/pencilblue/controllers/admin/content/topics/topic_form.js @@ -48,8 +48,7 @@ module.exports = function(pb) { self.topic = data.topic; data.sitePrefix = self.sitePrefix; - var pills = pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, SUB_NAV_KEY, data); - data.pills = pb.AdminSubnavService.addSiteToPills(pills, self.siteName); + data.pills = self.getAdminPills(SUB_NAV_KEY, self.ls, self.topic, data); var angularObjects = pb.ClientJs.getAngularObjects(data); self.setPageName(self.topic[pb.DAO.getIdField()] ? self.topic.name : self.ls.get('NEW_TOPIC')); diff --git a/plugins/pencilblue/controllers/admin/plugins/manage_plugins.js b/plugins/pencilblue/controllers/admin/plugins/manage_plugins.js index 01d285de0..3b8f8dd39 100755 --- a/plugins/pencilblue/controllers/admin/plugins/manage_plugins.js +++ b/plugins/pencilblue/controllers/admin/plugins/manage_plugins.js @@ -43,11 +43,9 @@ module.exports = function(pb) { //setup angular var prefix = self.sitePrefix; - var pills = pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, null, {sitePrefix: prefix}); - pills = pb.AdminSubnavService.addSiteToPills(pills, self.siteName); var angularObjects = pb.ClientJs.getAngularObjects({ navigation: pb.AdminNavigation.get(self.session, ['plugins', 'manage'], self.ls), - pills: pills, + pills: self.getAdminPills(SUB_NAV_KEY, self.ls, null, {sitePrefix: prefix}), installedPlugins: map.active, inactivePlugins: map.inactive, availablePlugins: map.available, diff --git a/plugins/pencilblue/controllers/admin/plugins/plugin_details.js b/plugins/pencilblue/controllers/admin/plugins/plugin_details.js index 17082fa44..a8adffd75 100755 --- a/plugins/pencilblue/controllers/admin/plugins/plugin_details.js +++ b/plugins/pencilblue/controllers/admin/plugins/plugin_details.js @@ -29,7 +29,6 @@ module.exports = function(pb) { * @extends BaseController */ function PluginDetailsViewController(){} - util.inherits(PluginDetailsViewController, pb.BaseAdminController); //statics @@ -55,10 +54,8 @@ module.exports = function(pb) { } //angular data - var pills = pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, null, obj); - pills = pb.AdminSubnavService.addSiteToPills(pills, self.siteName); var angularObjects = pb.ClientJs.getAngularObjects({ - pills: pills, + pills: self.getAdminPills(SUB_NAV_KEY, self.ls, null, obj), navigation: pb.AdminNavigation.get(self.session, ['plugins', 'manage'], self.ls), d: obj.details, status: obj.status, diff --git a/plugins/pencilblue/controllers/admin/plugins/plugin_settings.js b/plugins/pencilblue/controllers/admin/plugins/plugin_settings.js index 6585603ef..909dafdab 100755 --- a/plugins/pencilblue/controllers/admin/plugins/plugin_settings.js +++ b/plugins/pencilblue/controllers/admin/plugins/plugin_settings.js @@ -111,10 +111,8 @@ module.exports = function(pb) { settingType: self.getType(), sitePrefix: self.sitePrefix }; - var pills = pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, null, data); - pills = pb.AdminSubnavService.addSiteToPills(pills, self.siteName); var angularObjects = pb.ClientJs.getAngularObjects({ - pills: pills, + pills: self.getAdminPills(SUB_NAV_KEY, self.ls, null, data), tabs: tabs, navigation: pb.AdminNavigation.get(self.session, ['plugins', 'manage'], self.ls), settings: clone, diff --git a/plugins/pencilblue/controllers/admin/site_settings/content.js b/plugins/pencilblue/controllers/admin/site_settings/content.js index e542137b5..3373d7709 100755 --- a/plugins/pencilblue/controllers/admin/site_settings/content.js +++ b/plugins/pencilblue/controllers/admin/site_settings/content.js @@ -58,16 +58,13 @@ module.exports = function(pb) { ]; var contentService = new pb.ContentService(this.pathSiteUid, true); - var pills = pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, 'content', { pathSitePrefix: self.pathSitePrefix }); - pills = pb.AdminSubnavService.addSiteToPills(pills, this.siteName); - contentService.getSettings(function(err, contentSettings) { var angularObjects = pb.ClientJs.getAngularObjects({ navigation: pb.AdminNavigation.get(self.session, ['settings', 'site_settings'], self.ls), - pills: pills, + pills: self.getAdminPills(SUB_NAV_KEY, self.ls, 'content', { pathSitePrefix: self.sitePrefix }), tabs: tabs, contentSettings: contentSettings, - pathSitePrefix: self.pathSitePrefix + pathSitePrefix: self.sitePrefix }); self.setPageName(self.ls.get('CONTENT')); From be50f3f932b39a36ea0e3cd01fe72cc9c69dc779 Mon Sep 17 00:00:00 2001 From: Eugene Chang Date: Tue, 19 May 2015 11:56:29 -0400 Subject: [PATCH 164/790] Refactoring out admin pills --- .../controllers/admin/site_settings/configuration.js | 6 +----- .../controllers/admin/site_settings/libraries.js | 9 ++------- 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/plugins/pencilblue/controllers/admin/site_settings/configuration.js b/plugins/pencilblue/controllers/admin/site_settings/configuration.js index ceac9093b..868f6af17 100755 --- a/plugins/pencilblue/controllers/admin/site_settings/configuration.js +++ b/plugins/pencilblue/controllers/admin/site_settings/configuration.js @@ -56,7 +56,7 @@ module.exports = function(pb) { var angularObjects = pb.ClientJs.getAngularObjects({ navigation: pb.AdminNavigation.get(self.session, ['settings', 'site_settings'], self.ls), - pills: pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, 'configuration', {sitePrefix: self.sitePrefix, site: self.pathSiteUId, siteName: self.siteName}), + pills: self.getAdminPills(SUB_NAV_KEY, self.ls, 'configuration', {sitePrefix: self.sitePrefix, site: self.pathSiteUId, siteName: self.siteName}), config: config, isGlobalSite: self.isGlobalSite }); @@ -101,10 +101,6 @@ module.exports = function(pb) { }); } - if(data && data.siteName) { - return pb.AdminSubnavService.addSiteToPills(pills, data.siteName); - } - return pills; }; diff --git a/plugins/pencilblue/controllers/admin/site_settings/libraries.js b/plugins/pencilblue/controllers/admin/site_settings/libraries.js index 7da7e4e05..6f8c230b0 100644 --- a/plugins/pencilblue/controllers/admin/site_settings/libraries.js +++ b/plugins/pencilblue/controllers/admin/site_settings/libraries.js @@ -51,7 +51,7 @@ module.exports = function(pb) { librariesService.getSettings(function(err, librarySettings) { var angularObjects = pb.ClientJs.getAngularObjects({ navigation: pb.AdminNavigation.get(self.session, ['settings', 'site_settings'], self.ls), - pills: pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, 'libraries', {sitePrefix: self.sitePrefix, siteName:self.siteName}), + pills: self.getAdminPills(SUB_NAV_KEY, self.ls, 'libraries', {sitePrefix: self.sitePrefix, siteName:self.siteName}), tabs: tabs, librarySettings: librarySettings, cdnDefaults: pb.LibrariesService.getCDNDefaults(), @@ -72,7 +72,7 @@ module.exports = function(pb) { if(data && data.sitePrefix) { prefix += data.sitePrefix; } - var pills = [{ + return [{ name: 'configuration', title: ls.get('LIBRARIES'), icon: 'chevron-left', @@ -88,11 +88,6 @@ module.exports = function(pb) { icon: 'envelope', href: prefix + '/site_settings/email' }]; - if(data && data.siteName) { - return pb.AdminSubnavService.addSiteToPills(pills, data.siteName); - } - - return pills; }; //register admin sub-nav From 3739380c474a0e2b14b5694b1e01c55a8c166427 Mon Sep 17 00:00:00 2001 From: btidwell Date: Tue, 19 May 2015 12:12:40 -0400 Subject: [PATCH 165/790] remove unused method --- include/service/entities/article_service.js | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/include/service/entities/article_service.js b/include/service/entities/article_service.js index 7d1d20efd..ca04beca8 100755 --- a/include/service/entities/article_service.js +++ b/include/service/entities/article_service.js @@ -70,24 +70,6 @@ module.exports = function ArticleServiceModule(pb) { this.find(pb.DAO.getIdWhere(articleId), cb); }; - /** - * Finds an article or page by Id - * - * @method findById - * @param {String} url The article's url - * @param {Function} cb Callback function - */ - ArticleService.prototype.findByUrl = function(url, cb) { - this.find({url:url}, function(err, result) { - if(result && result.length > 0) { - cb(err, result[0]); - } - else { - cb(err, null); - } - }); - }; - /** * Finds articles by section * From 5a6cc921ffdc16c25858348a9c13822d198e1797 Mon Sep 17 00:00:00 2001 From: btidwell Date: Tue, 19 May 2015 12:18:57 -0400 Subject: [PATCH 166/790] rmeove unused variable. --- plugins/portfolio/controllers/blog.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/portfolio/controllers/blog.js b/plugins/portfolio/controllers/blog.js index 7e6d5810e..85d1b5d70 100755 --- a/plugins/portfolio/controllers/blog.js +++ b/plugins/portfolio/controllers/blog.js @@ -38,7 +38,7 @@ module.exports = function BlogModule(pb) { Blog.prototype.init = function(props, cb) { var self = this; - pb.BaseController.prototype.init.call(self, props, function () {var siteService = new pb.SiteService(); + pb.BaseController.prototype.init.call(self, props, function () { self.navService = new pb.SectionService(self.site); self.queryService = new pb.SiteQueryService(self.site); cb(); From 7d4781b30ba52a276f36f4213f0a5fe4700ec3a8 Mon Sep 17 00:00:00 2001 From: btidwell Date: Tue, 19 May 2015 12:21:57 -0400 Subject: [PATCH 167/790] site is already sanitized --- plugins/portfolio/controllers/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/portfolio/controllers/index.js b/plugins/portfolio/controllers/index.js index 6846b257e..9e2ce5296 100755 --- a/plugins/portfolio/controllers/index.js +++ b/plugins/portfolio/controllers/index.js @@ -78,7 +78,7 @@ module.exports = function IndexModule(pb) { }; TopMenu.getTopMenu(self.session, self.ls, options, function(themeSettings, navigation, accountButtons) { TopMenu.getBootstrapNav(navigation, accountButtons, function(navigation, accountButtons) { - var pluginService = new pb.PluginService(pb.SiteService.getCurrentSite(self.site)); + var pluginService = new pb.PluginService(self.site); pluginService.getSettings('portfolio', function(err, portfolioSettings) { var homePageKeywords = ''; From 95a6abfd02c07ab0f1aa4c56a102fbea35d468fe Mon Sep 17 00:00:00 2001 From: Eugene Chang Date: Tue, 19 May 2015 12:54:29 -0400 Subject: [PATCH 168/790] Fix media/nav deletion --- include/service/entities/media_service.js | 2 +- .../controllers/actions/admin/content/media/delete_media.js | 6 +++--- .../actions/admin/content/navigation/delete_nav_item.js | 2 +- .../pencilblue/controllers/admin/themes/manage_themes.js | 4 ++-- .../templates/angular/admin/content/media/manage_media.html | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/include/service/entities/media_service.js b/include/service/entities/media_service.js index 0523f33bd..14a220f97 100755 --- a/include/service/entities/media_service.js +++ b/include/service/entities/media_service.js @@ -38,7 +38,7 @@ module.exports = function MediaServiceModule(pb) { */ function MediaService(provider, site, onlyThisSite) { this.site = pb.SiteService.getCurrentSite(site); - this.siteQueryService = new pb.SiteQueryService(site, onlyThisSite); + this.siteQueryService = new pb.SiteQueryService(this.site, onlyThisSite); if (util.isNullOrUndefined(provider)) { provider = MediaService.loadMediaProvider(); } diff --git a/plugins/pencilblue/controllers/actions/admin/content/media/delete_media.js b/plugins/pencilblue/controllers/actions/admin/content/media/delete_media.js index 093f00b07..1d2ffa72a 100755 --- a/plugins/pencilblue/controllers/actions/admin/content/media/delete_media.js +++ b/plugins/pencilblue/controllers/actions/admin/content/media/delete_media.js @@ -24,10 +24,10 @@ module.exports = function(pb) { * Deletes media * @class DeleteMediaController * @constructor - * @extends FormController + * @extends AdminFormController */ function DeleteMediaController(){} - util.inherits(DeleteMediaController, pb.FormController); + util.inherits(DeleteMediaController, pb.AdminFormController); //constants var MANAGE_MEDIA_PATH = '/admin/content/media/manage_media'; @@ -50,7 +50,7 @@ module.exports = function(pb) { return; } - var mservice = new pb.MediaService(); + var mservice = new pb.MediaService(self.pathSiteUId); mservice.loadById(vars.id, function(err, mediaData) { if(util.isError(err) || !mediaData) { cb({ diff --git a/plugins/pencilblue/controllers/actions/admin/content/navigation/delete_nav_item.js b/plugins/pencilblue/controllers/actions/admin/content/navigation/delete_nav_item.js index b0b5e4f9c..ea083ec71 100644 --- a/plugins/pencilblue/controllers/actions/admin/content/navigation/delete_nav_item.js +++ b/plugins/pencilblue/controllers/actions/admin/content/navigation/delete_nav_item.js @@ -24,7 +24,7 @@ module.exports = function(pb) { * Deletes a navigation item */ function DeleteNavItem(){} - util.inherits(DeleteNavItem, pb.BaseController); + util.inherits(DeleteNavItem, pb.BaseAdminController); DeleteNavItem.prototype.render = function(cb) { var self = this; diff --git a/plugins/pencilblue/controllers/admin/themes/manage_themes.js b/plugins/pencilblue/controllers/admin/themes/manage_themes.js index 9256940be..6c31a43e2 100755 --- a/plugins/pencilblue/controllers/admin/themes/manage_themes.js +++ b/plugins/pencilblue/controllers/admin/themes/manage_themes.js @@ -34,7 +34,7 @@ module.exports = function(pb) { var self = this; //get plugs with themes - var pluginService = new pb.PluginService(site); + var pluginService = new pb.PluginService(self.site); pluginService.getPluginsWithThemesBySite(function (err, themes) { if (util.isError(err)) { throw result; @@ -76,7 +76,7 @@ module.exports = function(pb) { //setup angular var angularObjects = pb.ClientJs.getAngularObjects({ navigation: pb.AdminNavigation.get(self.session, ['plugins', 'themes'], self.ls), - pills: self.getPills(SUB_NAV_KEY, self.ls, null, subNavData), + pills: self.getAdminPills(SUB_NAV_KEY, self.ls, null, subNavData), tabs: self.getTabs(), themes: themes, options: options, diff --git a/plugins/pencilblue/templates/angular/admin/content/media/manage_media.html b/plugins/pencilblue/templates/angular/admin/content/media/manage_media.html index 319ee37dc..14b089f9a 100644 --- a/plugins/pencilblue/templates/angular/admin/content/media/manage_media.html +++ b/plugins/pencilblue/templates/angular/admin/content/media/manage_media.html @@ -76,7 +76,7 @@ } $scope.deleting = true; - $http({method: 'DELETE', url: '/actions/admin/content/media/' + $scope.objectToDelete._id}) + $http({method: 'DELETE', url: '/actions/admin' + $scope.sitePrefix + '/content/media/' + $scope.objectToDelete._id}) .success(function(result) { for(var i = 0; i < $scope.media.length; i ++) { if($scope.media[i]._id.toString() === $scope.objectToDelete._id.toString()) { From 82d19452102901674102ffa291bd568757032e99 Mon Sep 17 00:00:00 2001 From: Eugene Chang Date: Tue, 19 May 2015 13:15:50 -0400 Subject: [PATCH 169/790] Updating documentation; fixing Edit/New page --- .../actions/admin/content/media/edit_media.js | 2 +- .../controllers/actions/admin/content/media/new_media.js | 2 +- .../actions/admin/content/objects/edit_object.js | 2 +- .../actions/admin/content/objects/new_object.js | 2 +- .../actions/admin/content/objects/types/edit_type.js | 2 +- .../actions/admin/content/objects/types/new_type.js | 2 +- .../controllers/actions/admin/content/pages/edit_page.js | 9 ++++----- .../controllers/actions/admin/content/pages/new_page.js | 8 +++----- .../controllers/admin/content/objects/manage_objects.js | 2 +- .../controllers/admin/content/objects/sort_objects.js | 2 +- .../admin/content/objects/types/manage_types.js | 2 +- .../controllers/admin/plugins/plugin_details.js | 2 +- .../controllers/admin/plugins/plugin_settings.js | 2 +- 13 files changed, 18 insertions(+), 21 deletions(-) diff --git a/plugins/pencilblue/controllers/actions/admin/content/media/edit_media.js b/plugins/pencilblue/controllers/actions/admin/content/media/edit_media.js index aaab63116..1eed899a9 100755 --- a/plugins/pencilblue/controllers/actions/admin/content/media/edit_media.js +++ b/plugins/pencilblue/controllers/actions/admin/content/media/edit_media.js @@ -23,7 +23,7 @@ module.exports = function(pb) { /** * Edits media * @class EditMediaActionController - * @extends FormController + * @extends BaseAdminController * @constructor */ function EditMediaActionController(){} diff --git a/plugins/pencilblue/controllers/actions/admin/content/media/new_media.js b/plugins/pencilblue/controllers/actions/admin/content/media/new_media.js index 2c80805e5..4bc4043ea 100755 --- a/plugins/pencilblue/controllers/actions/admin/content/media/new_media.js +++ b/plugins/pencilblue/controllers/actions/admin/content/media/new_media.js @@ -24,7 +24,7 @@ module.exports = function(pb) { * Adds new media * @class NewMediaApiController * @constructor - * @extends BaseController + * @extends BaseAdminController */ function NewMediaApiController(){} util.inherits(NewMediaApiController, pb.BaseAdminController); diff --git a/plugins/pencilblue/controllers/actions/admin/content/objects/edit_object.js b/plugins/pencilblue/controllers/actions/admin/content/objects/edit_object.js index c603125a1..fa5cdd69c 100644 --- a/plugins/pencilblue/controllers/actions/admin/content/objects/edit_object.js +++ b/plugins/pencilblue/controllers/actions/admin/content/objects/edit_object.js @@ -24,7 +24,7 @@ module.exports = function(pb) { * Edits an object * @class EditObject * @constructor - * @extends FormController + * @extends BaseAdminController */ function EditObject(){} util.inherits(EditObject, pb.BaseAdminController); diff --git a/plugins/pencilblue/controllers/actions/admin/content/objects/new_object.js b/plugins/pencilblue/controllers/actions/admin/content/objects/new_object.js index 7b8052858..45685958f 100644 --- a/plugins/pencilblue/controllers/actions/admin/content/objects/new_object.js +++ b/plugins/pencilblue/controllers/actions/admin/content/objects/new_object.js @@ -24,7 +24,7 @@ module.exports = function(pb) { * Creates an object * @class NewObjectActionController * @constructor - * @extends BaseController + * @extends BaseAdminController */ function NewObjectActionController(){} util.inherits(NewObjectActionController, pb.BaseAdminController); diff --git a/plugins/pencilblue/controllers/actions/admin/content/objects/types/edit_type.js b/plugins/pencilblue/controllers/actions/admin/content/objects/types/edit_type.js index a66444abc..c12670b52 100644 --- a/plugins/pencilblue/controllers/actions/admin/content/objects/types/edit_type.js +++ b/plugins/pencilblue/controllers/actions/admin/content/objects/types/edit_type.js @@ -24,7 +24,7 @@ module.exports = function(pb) { * Edits an object type * @class EditObjectType * @constructor - * @extends FormController + * @extends BaseAdminController */ function EditObjectType(){} util.inherits(EditObjectType, pb.BaseAdminController); diff --git a/plugins/pencilblue/controllers/actions/admin/content/objects/types/new_type.js b/plugins/pencilblue/controllers/actions/admin/content/objects/types/new_type.js index 3fad304df..b571bc6ba 100644 --- a/plugins/pencilblue/controllers/actions/admin/content/objects/types/new_type.js +++ b/plugins/pencilblue/controllers/actions/admin/content/objects/types/new_type.js @@ -24,7 +24,7 @@ module.exports = function(pb) { * Creates an object type * @class NewObjectTypeActionController * @constructor - * @extends FormController + * @extends BaseAdminController */ function NewObjectTypeActionController(){} util.inherits(NewObjectTypeActionController, pb.BaseAdminController); diff --git a/plugins/pencilblue/controllers/actions/admin/content/pages/edit_page.js b/plugins/pencilblue/controllers/actions/admin/content/pages/edit_page.js index d16f6769c..ee6db6e31 100755 --- a/plugins/pencilblue/controllers/actions/admin/content/pages/edit_page.js +++ b/plugins/pencilblue/controllers/actions/admin/content/pages/edit_page.js @@ -24,10 +24,10 @@ module.exports = function(pb) { * Edits a page * @cclass EditPagePostController * @constructor - * @extends FormController + * @extends BaseAdminController */ function EditPagePostController(){} - util.inherits(EditPagePostController, pb.BaseController); + util.inherits(EditPagePostController, pb.BaseAdminController); EditPagePostController.prototype.render = function(cb) { var self = this; @@ -47,8 +47,7 @@ module.exports = function(pb) { return; } - var dao = new pb.DAO(); - dao.loadById(post.id, 'page', function(err, page) { + self.siteQueryService.loadById(post.id, 'page', function(err, page) { if(util.isError(err) || page === null) { cb({ code: 400, @@ -74,7 +73,7 @@ module.exports = function(pb) { return; } - dao.save(page, function(err, result) { + self.siteQueryService.save(page, function(err, result) { if(util.isError(err)) { pb.log.error(err.stack); return cb({ diff --git a/plugins/pencilblue/controllers/actions/admin/content/pages/new_page.js b/plugins/pencilblue/controllers/actions/admin/content/pages/new_page.js index b63e7423c..cec1d5207 100755 --- a/plugins/pencilblue/controllers/actions/admin/content/pages/new_page.js +++ b/plugins/pencilblue/controllers/actions/admin/content/pages/new_page.js @@ -24,14 +24,13 @@ module.exports = function(pb) { * Creates a new page * @class NewPagePostController * @constructor - * @extends FormController + * @extends BaseAdminController */ function NewPagePostController(){} - util.inherits(NewPagePostController, pb.BaseController); + util.inherits(NewPagePostController, pb.BaseAdminController); NewPagePostController.prototype.render = function(cb) { var self = this; - var site = pb.SiteService.getCurrentSite(this.pathVars.siteid); this.getJSONPostParams(function(err, post) { if(self.session.authentication.user.admin < pb.SecurityService.ACCESS_EDITOR || !post.author) { post.author = self.session.authentication.user[pb.DAO.getIdField()]; @@ -51,7 +50,6 @@ module.exports = function(pb) { post = pb.DocumentCreator.formatIntegerItems(post, ['draft']); var pageDocument = pb.DocumentCreator.create('page', post, ['meta_keywords']); - var dao = new pb.DAO(); pb.RequestHandler.urlExists(pageDocument.url, post.id, pageDocument.site, function(err, exists) { if(util.isError(err) || exists) { cb({ @@ -60,7 +58,7 @@ module.exports = function(pb) { }); return; } - dao.save(pageDocument, function(err, result) { + self.siteQueryService.save(pageDocument, function(err, result) { if(util.isError(err)) { pb.log.error(err); cb({ diff --git a/plugins/pencilblue/controllers/admin/content/objects/manage_objects.js b/plugins/pencilblue/controllers/admin/content/objects/manage_objects.js index af857f939..7aa5b06a6 100644 --- a/plugins/pencilblue/controllers/admin/content/objects/manage_objects.js +++ b/plugins/pencilblue/controllers/admin/content/objects/manage_objects.js @@ -24,7 +24,7 @@ module.exports = function(pb) { * Interface for managing objects * @class ManageObjects * @constructor - * @extends BaseController + * @extends BaseAdminController */ function ManageObjects() {} util.inherits(ManageObjects, pb.BaseAdminController); diff --git a/plugins/pencilblue/controllers/admin/content/objects/sort_objects.js b/plugins/pencilblue/controllers/admin/content/objects/sort_objects.js index ecc097ac0..0d14d9d56 100644 --- a/plugins/pencilblue/controllers/admin/content/objects/sort_objects.js +++ b/plugins/pencilblue/controllers/admin/content/objects/sort_objects.js @@ -24,7 +24,7 @@ module.exports = function(pb) { * Interface for sorting objects * @class SortObjects * @constructor - * @extends BaseController + * @extends BaseAdminController */ function SortObjects() {} util.inherits(SortObjects, pb.BaseAdminController); diff --git a/plugins/pencilblue/controllers/admin/content/objects/types/manage_types.js b/plugins/pencilblue/controllers/admin/content/objects/types/manage_types.js index 6d98fc66d..8a8acceb5 100644 --- a/plugins/pencilblue/controllers/admin/content/objects/types/manage_types.js +++ b/plugins/pencilblue/controllers/admin/content/objects/types/manage_types.js @@ -24,7 +24,7 @@ module.exports = function(pb) { * Interface for managing object types * @class ManageObjectTypes * @constructor - * @extends BaseController + * @extends BaseAdminController */ function ManageObjectTypes() {} util.inherits(ManageObjectTypes, pb.BaseAdminController); diff --git a/plugins/pencilblue/controllers/admin/plugins/plugin_details.js b/plugins/pencilblue/controllers/admin/plugins/plugin_details.js index a8adffd75..b750c37eb 100755 --- a/plugins/pencilblue/controllers/admin/plugins/plugin_details.js +++ b/plugins/pencilblue/controllers/admin/plugins/plugin_details.js @@ -26,7 +26,7 @@ module.exports = function(pb) { * Interface for viewing plugin details * @class PluginDetailsViewController * @constructor - * @extends BaseController + * @extends BaseAdminController */ function PluginDetailsViewController(){} util.inherits(PluginDetailsViewController, pb.BaseAdminController); diff --git a/plugins/pencilblue/controllers/admin/plugins/plugin_settings.js b/plugins/pencilblue/controllers/admin/plugins/plugin_settings.js index 909dafdab..399030d7f 100755 --- a/plugins/pencilblue/controllers/admin/plugins/plugin_settings.js +++ b/plugins/pencilblue/controllers/admin/plugins/plugin_settings.js @@ -24,7 +24,7 @@ module.exports = function(pb) { * Interface for changing a plugin's settings * @class PluginSettingsFormController * @constructor - * @extends BaseController + * @extends BaseAdminController */ function PluginSettingsFormController(){ From 203fe960fc590d1706fcf2b554681dbec116596e Mon Sep 17 00:00:00 2001 From: Eugene Chang Date: Tue, 19 May 2015 13:38:28 -0400 Subject: [PATCH 170/790] Renaming queryService to siteQueryService --- plugins/portfolio/controllers/blog.js | 10 +++++----- plugins/portfolio/controllers/blog_filter.js | 4 ++-- plugins/portfolio/controllers/index.js | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/plugins/portfolio/controllers/blog.js b/plugins/portfolio/controllers/blog.js index 85d1b5d70..3a54448fa 100755 --- a/plugins/portfolio/controllers/blog.js +++ b/plugins/portfolio/controllers/blog.js @@ -40,7 +40,7 @@ module.exports = function BlogModule(pb) { var self = this; pb.BaseController.prototype.init.call(self, props, function () { self.navService = new pb.SectionService(self.site); - self.queryService = new pb.SiteQueryService(self.site); + self.siteQueryService = new pb.SiteQueryService(self.site); cb(); }); }; @@ -243,7 +243,7 @@ module.exports = function BlogModule(pb) { return; } - self.queryService.loadById(self.req.pencilblue_section, 'section', callback); + self.siteQueryService.loadById(self.req.pencilblue_section, 'section', callback); } }; async.parallel(tasks, cb); @@ -398,7 +398,7 @@ module.exports = function BlogModule(pb) { if(this.req.pencilblue_topic) { searchId = searchId.toString(); } - this.queryService.loadById(searchId, objType, function(err, obj) { + this.siteQueryService.loadById(searchId, objType, function(err, obj) { if(util.isError(err) || obj === null) { cb(null, pb.config.siteName); return; @@ -465,14 +465,14 @@ module.exports = function BlogModule(pb) { }, limit: 6 }; - self.queryService.q('article', opts, function(err, relatedArticles) { + self.siteQueryService.q('article', opts, function(err, relatedArticles) { if(relatedArticles.length === 0) { opts = { where: pb.DAO.ANYWHERE, order: {name: 1} }; - self.queryService.q('topic', opts, function(err, topicObjects) { + self.siteQueryService.q('topic', opts, function(err, topicObjects) { var articleTopics = []; for(var i = 0; i < topics.length && articleTopics.length < 20; i++) { for(var j = 0; j < topicObjects.length; j++) { diff --git a/plugins/portfolio/controllers/blog_filter.js b/plugins/portfolio/controllers/blog_filter.js index 0a1821d9b..402c147fa 100755 --- a/plugins/portfolio/controllers/blog_filter.js +++ b/plugins/portfolio/controllers/blog_filter.js @@ -45,10 +45,10 @@ module.exports = function BlogFilterModule(pb) { return; } - this.queryService.loadByValue(fieldToMatch, custUrl, objectType, function(err, result) { + this.siteQueryService.loadByValue(fieldToMatch, custUrl, objectType, function(err, result) { if (util.isError(err) || result === null) { if(pb.validation.isIdStr(self.pathVars.custUrl)) { - this.queryService.loadById(self.pathVars.custUrl, objectType, function(err, result) { + this.siteQueryService.loadById(self.pathVars.custUrl, objectType, function(err, result) { if (util.isError(err) || result === null || result.draft) { self.reqHandler.serve404(); return; diff --git a/plugins/portfolio/controllers/index.js b/plugins/portfolio/controllers/index.js index a1a70fbc1..8f5099923 100755 --- a/plugins/portfolio/controllers/index.js +++ b/plugins/portfolio/controllers/index.js @@ -45,7 +45,7 @@ module.exports = function IndexModule(pb) { } else { self.siteObj = site; - self.queryService = new pb.SiteQueryService(site.uid); + self.siteQueryService = new pb.SiteQueryService(site.uid); cb(); } }); @@ -112,7 +112,7 @@ module.exports = function IndexModule(pb) { var opts = { where: {settings_type: 'home_page'} }; - self.queryService.q('portfolio_theme_settings', opts, function(err, settings) { + self.siteQueryService.q('portfolio_theme_settings', opts, function(err, settings) { if (util.isError(err)) { self.reqHandler.serveError(err); } From 060edddd0b4c766b0ac82b253b4e0b32ce4df496 Mon Sep 17 00:00:00 2001 From: Eugene Chang Date: Tue, 19 May 2015 13:52:09 -0400 Subject: [PATCH 171/790] Fixing AdminFormController to ensure it's calling the base class's init --- controllers/admin/admin_form_controller.js | 5 ++- controllers/admin/base_admin_controller.js | 37 ++++++++++++---------- 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/controllers/admin/admin_form_controller.js b/controllers/admin/admin_form_controller.js index 116d67bc5..74ea9f9ab 100644 --- a/controllers/admin/admin_form_controller.js +++ b/controllers/admin/admin_form_controller.js @@ -31,7 +31,10 @@ module.exports = function AdminFormControllerModule(pb) { * @param cb */ AdminFormController.prototype.init = function (props, cb) { - BaseAdminController.prototype.init.call(this, props, cb); + var self = this; + pb.FormController.prototype.init.call(self, props, function () { + BaseAdminController.prototype.extendedInit.call(self, cb); + }); }; AdminFormController.prototype.getAdminPills = BaseAdminController.prototype.getAdminPills; diff --git a/controllers/admin/base_admin_controller.js b/controllers/admin/base_admin_controller.js index 926170901..9df6b7558 100644 --- a/controllers/admin/base_admin_controller.js +++ b/controllers/admin/base_admin_controller.js @@ -38,22 +38,27 @@ module.exports = function BaseAdminControllerModule(pb) { BaseAdminController.prototype.init = function (props, cb) { var self = this; BaseController.prototype.init.call(self, props, function () { - self.pathSiteUId = pb.SiteService.getCurrentSite(self.pathVars.siteid); - var siteService = new pb.SiteService(); - siteService.getByUid(self.pathSiteUId, function (err, siteInfo) { - if (err || !siteInfo) { - self.reqHandler.serve404(); - } else { - self.sectionService = new pb.SectionService(self.pathSiteUId, true); - self.sitePrefix = pb.SiteService.getCurrentSitePrefix(self.pathSiteUId); - self.siteQueryService = new pb.SiteQueryService(self.pathSiteUId, true); - self.settings = pb.SettingServiceFactory.getServiceBySite(self.pathSiteUId, true); - self.siteObj = siteInfo; - self.isGlobalSite = pb.SiteService.isGlobal(siteInfo.uid); - self.siteName = self.isGlobalSite ? siteInfo.uid : siteInfo.displayName; - cb(); - } - }) + self.extendedInit(cb); + }); + }; + + BaseAdminController.prototype.extendedInit = function(cb) { + var self = this; + self.pathSiteUId = pb.SiteService.getCurrentSite(self.pathVars.siteid); + var siteService = new pb.SiteService(); + siteService.getByUid(self.pathSiteUId, function (err, siteInfo) { + if (err || !siteInfo) { + self.reqHandler.serve404(); + } else { + self.sectionService = new pb.SectionService(self.pathSiteUId, true); + self.sitePrefix = pb.SiteService.getCurrentSitePrefix(self.pathSiteUId); + self.siteQueryService = new pb.SiteQueryService(self.pathSiteUId, true); + self.settings = pb.SettingServiceFactory.getServiceBySite(self.pathSiteUId, true); + self.siteObj = siteInfo; + self.isGlobalSite = pb.SiteService.isGlobal(siteInfo.uid); + self.siteName = self.isGlobalSite ? siteInfo.uid : siteInfo.displayName; + cb(); + } }); }; From cbdb176c00aa71fd092b3da237a6b247ebb08ffb Mon Sep 17 00:00:00 2001 From: btidwell Date: Tue, 19 May 2015 14:09:32 -0400 Subject: [PATCH 172/790] fix parameters in blog filter --- plugins/portfolio/controllers/blog_filter.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/portfolio/controllers/blog_filter.js b/plugins/portfolio/controllers/blog_filter.js index 402c147fa..588589574 100755 --- a/plugins/portfolio/controllers/blog_filter.js +++ b/plugins/portfolio/controllers/blog_filter.js @@ -47,15 +47,15 @@ module.exports = function BlogFilterModule(pb) { this.siteQueryService.loadByValue(fieldToMatch, custUrl, objectType, function(err, result) { if (util.isError(err) || result === null) { - if(pb.validation.isIdStr(self.pathVars.custUrl)) { - this.siteQueryService.loadById(self.pathVars.custUrl, objectType, function(err, result) { + if(pb.validation.isIdStr(custUrl)) { + self.siteQueryService.loadById(custUrl, objectType, function(err, result) { if (util.isError(err) || result === null || result.draft) { self.reqHandler.serve404(); return; } self.req['pencilblue_' + objectType] = result._id.toString(); - this.result = result; + self.result = result; BlogFilter.super_.prototype.render.apply(self, [cb]); }); } From 827870381661a5302d739e3a3cb94002430760f0 Mon Sep 17 00:00:00 2001 From: Eugene Chang Date: Tue, 19 May 2015 14:26:20 -0400 Subject: [PATCH 173/790] Fix media edit --- .../pencilblue/controllers/admin/content/media/media_form.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/pencilblue/controllers/admin/content/media/media_form.js b/plugins/pencilblue/controllers/admin/content/media/media_form.js index 422b7b160..1ab24324c 100644 --- a/plugins/pencilblue/controllers/admin/content/media/media_form.js +++ b/plugins/pencilblue/controllers/admin/content/media/media_form.js @@ -114,7 +114,7 @@ module.exports = function(pb) { }); } - var mediaService = new pb.MediaService(null, this.pathSiteUId, true); + var mediaService = new pb.MediaService(null, self.pathSiteUId, true); mediaService.loadById(vars.id, callback); } }; From 5fd5f992cd4f22390329688750fcb71c0f870596 Mon Sep 17 00:00:00 2001 From: Eugene Chang Date: Tue, 19 May 2015 14:33:03 -0400 Subject: [PATCH 174/790] Fixing plugin details --- .../pencilblue/controllers/admin/plugins/plugin_details.js | 1 + plugins/pencilblue/templates/admin/elements/sub_nav.html | 5 ----- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/plugins/pencilblue/controllers/admin/plugins/plugin_details.js b/plugins/pencilblue/controllers/admin/plugins/plugin_details.js index b750c37eb..1e725d824 100755 --- a/plugins/pencilblue/controllers/admin/plugins/plugin_details.js +++ b/plugins/pencilblue/controllers/admin/plugins/plugin_details.js @@ -54,6 +54,7 @@ module.exports = function(pb) { } //angular data + obj.sitePrefix = self.sitePrefix; var angularObjects = pb.ClientJs.getAngularObjects({ pills: self.getAdminPills(SUB_NAV_KEY, self.ls, null, obj), navigation: pb.AdminNavigation.get(self.session, ['plugins', 'manage'], self.ls), diff --git a/plugins/pencilblue/templates/admin/elements/sub_nav.html b/plugins/pencilblue/templates/admin/elements/sub_nav.html index 904d106bf..893240184 100755 --- a/plugins/pencilblue/templates/admin/elements/sub_nav.html +++ b/plugins/pencilblue/templates/admin/elements/sub_nav.html @@ -4,9 +4,4 @@   - - - From e089eae8aa198c99c0ce376556f7456a70a9edf5 Mon Sep 17 00:00:00 2001 From: Eugene Chang Date: Tue, 19 May 2015 14:35:56 -0400 Subject: [PATCH 175/790] Removing siteName --- plugins/pencilblue/controllers/admin/plugins/manage_plugins.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/plugins/pencilblue/controllers/admin/plugins/manage_plugins.js b/plugins/pencilblue/controllers/admin/plugins/manage_plugins.js index 3b8f8dd39..9c9d81216 100755 --- a/plugins/pencilblue/controllers/admin/plugins/manage_plugins.js +++ b/plugins/pencilblue/controllers/admin/plugins/manage_plugins.js @@ -50,8 +50,7 @@ module.exports = function(pb) { inactivePlugins: map.inactive, availablePlugins: map.available, sitePrefix: prefix, - siteUid: self.pathSiteUId, - siteName: self.siteName + siteUid: self.pathSiteUId }); //load the template self.ts.registerLocal('angular_objects', new pb.TemplateValue(angularObjects, false)); From 3cfc22ec0770f3a61a8be354fdeb7030917673d7 Mon Sep 17 00:00:00 2001 From: btidwell Date: Tue, 19 May 2015 15:01:54 -0400 Subject: [PATCH 176/790] fix portfolio plugin nav --- plugins/portfolio/portfolio.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/portfolio/portfolio.js b/plugins/portfolio/portfolio.js index 6bd76db74..22deb2a43 100755 --- a/plugins/portfolio/portfolio.js +++ b/plugins/portfolio/portfolio.js @@ -40,8 +40,8 @@ module.exports = function PortfolioModule(pb) { * The result is ignored */ Portfolio.onStartup = function(cb) { - pb.AdminSubnavService.registerFor('plugin_settings', function(navKey, localization, plugin) { - if(plugin.uid === 'portfolio') { + pb.AdminSubnavService.registerFor('plugin_settings', function(navKey, localization, data) { + if(data.plugin.uid === 'portfolio') { return [ { name: 'home_page_settings', From adb91f7f8c936d618979098998cd9958fa10ac16 Mon Sep 17 00:00:00 2001 From: btidwell Date: Tue, 19 May 2015 15:08:23 -0400 Subject: [PATCH 177/790] bug fixes (self vs this) (true vs pb.config.multisite when using query service) --- plugins/portfolio/controllers/blog.js | 4 ++-- plugins/portfolio/controllers/blog_filter.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/portfolio/controllers/blog.js b/plugins/portfolio/controllers/blog.js index 3a54448fa..6ee85af2f 100755 --- a/plugins/portfolio/controllers/blog.js +++ b/plugins/portfolio/controllers/blog.js @@ -40,7 +40,7 @@ module.exports = function BlogModule(pb) { var self = this; pb.BaseController.prototype.init.call(self, props, function () { self.navService = new pb.SectionService(self.site); - self.siteQueryService = new pb.SiteQueryService(self.site); + self.siteQueryService = new pb.SiteQueryService(self.site, true); cb(); }); }; @@ -256,7 +256,7 @@ module.exports = function BlogModule(pb) { var article = this.req.pencilblue_article || null; var page = this.req.pencilblue_page || null; - var service = new ArticleService(this.site, pb.config.multisite); + var service = new ArticleService(this.site, true); if(this.req.pencilblue_preview) { if(this.req.pencilblue_preview == page || article) { if(page) { diff --git a/plugins/portfolio/controllers/blog_filter.js b/plugins/portfolio/controllers/blog_filter.js index 588589574..a27c62084 100755 --- a/plugins/portfolio/controllers/blog_filter.js +++ b/plugins/portfolio/controllers/blog_filter.js @@ -72,7 +72,7 @@ module.exports = function BlogFilterModule(pb) { } self.req['pencilblue_' + objectType] = result._id.toString(); - this.result = result; + self.result = result; BlogFilter.super_.prototype.render.apply(self, [cb]); }); }; From b64f9befa8636948b9a65e64dd32a5ce098535cd Mon Sep 17 00:00:00 2001 From: andparker Date: Tue, 19 May 2015 15:24:45 -0400 Subject: [PATCH 178/790] Fix capitalization typo that was causing pb to crash --- include/service/memory_entity_service.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/service/memory_entity_service.js b/include/service/memory_entity_service.js index fb2f90585..f93307e0b 100755 --- a/include/service/memory_entity_service.js +++ b/include/service/memory_entity_service.js @@ -90,7 +90,7 @@ module.exports = function MemoryEntityServiceModule(pb) { return null; } - return getCorrectValueField(rawVal, self.ValueField); + return getCorrectValueField(rawVal, self.valueField); } function getGlobalValue(self, key) From d59bae1ce437f9a61b9a7e8e55b008e5279296b9 Mon Sep 17 00:00:00 2001 From: Eugene Chang Date: Tue, 19 May 2015 15:34:26 -0400 Subject: [PATCH 179/790] Fixing article redirect, refactoring article --- .../admin/content/articles/article_form.js | 66 ++++++++----------- .../admin/content/articles/article_form.html | 2 +- 2 files changed, 27 insertions(+), 41 deletions(-) diff --git a/plugins/pencilblue/controllers/admin/content/articles/article_form.js b/plugins/pencilblue/controllers/admin/content/articles/article_form.js index d6db7a99c..c582356cc 100755 --- a/plugins/pencilblue/controllers/admin/content/articles/article_form.js +++ b/plugins/pencilblue/controllers/admin/content/articles/article_form.js @@ -69,15 +69,13 @@ module.exports = function(pb) { self.setPageName(self.article[pb.DAO.getIdField()] ? self.article.headline : self.ls.get('NEW_ARTICLE')); self.ts.registerLocal('angular_script', ''); - self.getAngularObjects(tabs, results, function(angularObjects) { - self.ts.registerLocal('angular_objects', new pb.TemplateValue(angularObjects, false)); - self.ts.load('admin/content/articles/article_form', function(err, data) { - self.onTemplateRetrieved('' + data, function(err, data) { - var result = '' + data; - self.checkForFormRefill(result, function(newResult) { - result = newResult; - cb({content: result}); - }); + self.ts.registerLocal('angular_objects', new pb.TemplateValue(self.getAngularObjects(tabs, results), false)); + self.ts.load('admin/content/articles/article_form', function(err, data) { + self.onTemplateRetrieved('' + data, function(err, data) { + var result = '' + data; + self.checkForFormRefill(result, function(newResult) { + result = newResult; + cb({content: result}); }); }); }); @@ -87,16 +85,8 @@ module.exports = function(pb) { cb(null, template); }; - ArticleForm.prototype.getAngularObjects = function(tabs, data, cb) { + ArticleForm.prototype.getAngularObjects = function(tabs, data) { var self = this; - if(pb.config.multisite) { - if(!data.site) { - data.site = pb.SiteService.getCurrentSite(this.pathVars.siteid); - } - if(!data.article.site) { - data.article.site = data.site; - } - } if(data.article[pb.DAO.getIdField()]) { var media = []; var i, j; @@ -136,31 +126,27 @@ module.exports = function(pb) { } data.article.article_topics = topics; } - data.site = data.article.site; - pb.AdminSubnavService.getWithSite(this.getActivePill(), this.ls, this.getActivePill(), data, function(pills) { - var objects = { - navigation: pb.AdminNavigation.get(self.session, ['content', 'articles'], self.ls), - pills: pills, - tabs: tabs, - templates: data.templates, - sections: data.sections, - topics: data.topics, - media: data.media, - article: data.article, - site: data.site - }; - if(data.availableAuthors) { - objects.availableAuthors = data.availableAuthors; - } - cb(pb.ClientJs.getAngularObjects(objects)); - }); + + data.sitePrefix = self.sitePrefix; + var objects = { + navigation: pb.AdminNavigation.get(this.session, ['content', 'articles'], this.ls), + pills: self.getAdminPills(this.getActivePill(), this.ls, this.getActivePill(), data), + tabs: tabs, + templates: data.templates, + sections: data.sections, + topics: data.topics, + media: data.media, + article: data.article, + sitePrefix: self.sitePrefix + }; + if(data.availableAuthors) { + objects.availableAuthors = data.availableAuthors; + } + return pb.ClientJs.getAngularObjects(objects); }; ArticleForm.getSubNavItems = function(key, ls, data) { - var adminPrefix = '/admin'; - if(data.article.site) { - adminPrefix += pb.SiteService.getCurrentSitePrefix(data.article.site); - } + var adminPrefix = '/admin' + data.sitePrefix; return [{ name: 'manage_articles', title: data.article[pb.DAO.getIdField()] ? ls.get('EDIT') + ' ' + data.article.headline : ls.get('NEW_ARTICLE'), diff --git a/plugins/pencilblue/templates/angular/admin/content/articles/article_form.html b/plugins/pencilblue/templates/angular/admin/content/articles/article_form.html index b28fb55e2..567fdd6a2 100644 --- a/plugins/pencilblue/templates/angular/admin/content/articles/article_form.html +++ b/plugins/pencilblue/templates/angular/admin/content/articles/article_form.html @@ -69,7 +69,7 @@ $window.location = '/admin/content/articles'; return; } - $window.location = '/admin/content/articles/' + result.data._id.toString(); + $window.location = '/admin' + $scope.sitePrefix + '/content/articles/' + result.data._id.toString(); }) .error(function(error, status) { $scope.errorMessage = error.message; From face05bd3bd2a398807bfd0c71675ef8602ae997 Mon Sep 17 00:00:00 2001 From: Eugene Chang Date: Tue, 19 May 2015 15:45:57 -0400 Subject: [PATCH 180/790] Fixing page redirect, refactoring page --- .../admin/content/pages/page_form.js | 65 +++++++------------ .../admin/content/pages/page_form.html | 6 +- .../admin/content/pages/page_form.html | 6 +- 3 files changed, 31 insertions(+), 46 deletions(-) diff --git a/plugins/pencilblue/controllers/admin/content/pages/page_form.js b/plugins/pencilblue/controllers/admin/content/pages/page_form.js index df09b0d23..b8e027460 100755 --- a/plugins/pencilblue/controllers/admin/content/pages/page_form.js +++ b/plugins/pencilblue/controllers/admin/content/pages/page_form.js @@ -68,15 +68,12 @@ module.exports = function(pb) { var tabs = self.getTabs(); self.setPageName(self.page[pb.DAO.getIdField()] ? self.page.headline : self.ls.get('NEW_PAGE')); - - self.getAngularObjects(tabs, results, function(angularObjects) { - self.ts.registerLocal('angular_objects', new pb.TemplateValue(angularObjects, false)); - self.ts.load('admin/content/pages/page_form', function(err, data) { - var result = data; - self.checkForFormRefill(result, function(newResult) { - result = newResult; - cb({content: result}); - }); + self.ts.registerLocal('angular_objects', new pb.TemplateValue(self.getAngularObjects(tabs, results), false)); + self.ts.load('admin/content/pages/page_form', function(err, data) { + var result = data; + self.checkForFormRefill(result, function(newResult) { + result = newResult; + cb({content: result}); }); }); }; @@ -86,16 +83,8 @@ module.exports = function(pb) { * @method getAngularObjects * */ - PageFormController.prototype.getAngularObjects = function(tabs, data, cb) { + PageFormController.prototype.getAngularObjects = function(tabs, data) { var self = this; - if(pb.config.multisite) { - if(!data.site) { - data.site = pb.SiteService.getCurrentSite(this.pathVars.siteid); - } - if(!data.page.site) { - data.page.site = data.site; - } - } if(data.page[pb.DAO.getIdField()]) { var media = []; var i, j; @@ -123,23 +112,22 @@ module.exports = function(pb) { } data.page.page_topics = topics; } - pb.AdminSubnavService.getWithSite(this.getActivePill(), this.ls, this.getActivePill(), data, function(pills) { - var objects = { - navigation: pb.AdminNavigation.get(self.session, ['content', 'pages'], self.ls), - pills: pills, - tabs: tabs, - templates: data.templates, - sections: data.sections, - topics: data.topics, - media: data.media, - page: data.page, - site: data.site - }; - if(data.availableAuthors) { - objects.availableAuthors = data.availableAuthors; - } - cb(pb.ClientJs.getAngularObjects(objects)); - }); + + var objects = { + navigation: pb.AdminNavigation.get(this.session, ['content', 'pages'], this.ls), + pills: self.getAdminPills(this.getActivePill(), this.ls, this.getActivePill(), data), + tabs: tabs, + templates: data.templates, + sections: data.sections, + topics: data.topics, + media: data.media, + page: data.page, + sitePrefix: self.sitePrefix + }; + if(data.availableAuthors) { + objects.availableAuthors = data.availableAuthors; + } + return pb.ClientJs.getAngularObjects(objects); }; /** @@ -148,10 +136,7 @@ module.exports = function(pb) { * */ PageFormController.getSubNavItems = function(key, ls, data) { - var adminPrefix = '/admin'; - if(data.page.site) { - adminPrefix += pb.SiteService.getCurrentSitePrefix(data.page.site); - } + var adminPrefix = '/admin' + data.sitePrefix; return [{ name: 'manage_pages', title: data.page[pb.DAO.getIdField()] ? ls.get('EDIT') + ' ' + data.page.headline : ls.get('NEW_PAGE'), @@ -207,7 +192,7 @@ module.exports = function(pb) { }, media: function(callback) { - var mservice = new pb.MediaService(null, vars.siteid, true); + var mservice = new pb.MediaService(null, self.pathSiteUId, true); mservice.get(callback); }, diff --git a/plugins/pencilblue/templates/angular/admin/content/pages/page_form.html b/plugins/pencilblue/templates/angular/admin/content/pages/page_form.html index 4f50d3a61..4cf0b9ffd 100644 --- a/plugins/pencilblue/templates/angular/admin/content/pages/page_form.html +++ b/plugins/pencilblue/templates/angular/admin/content/pages/page_form.html @@ -43,7 +43,7 @@ $scope.getPageData(draft, function(pageData) { $scope.saving = true; if(pageData._id) { - $http.post('/actions/admin/content/pages/' + $scope.page._id, pageData) + $http.post('/actions/admin' + $scope.sitePrefix + '/content/pages/' + $scope.page._id, pageData) .success(function(result) { $scope.successMessage = result.message; $scope.page.last_modified = result.data.last_modified; @@ -55,11 +55,11 @@ }); } else { - $http.post('/actions/admin/content/pages', pageData) + $http.post('/actions/admin' + $scope.sitePrefix + '/content/pages', pageData) .success(function(result) { $scope.successMessage = result.message; $scope.saving = false; - $window.location = '/admin/content/pages/' + result.data._id.toString(); + $window.location = '/admin' + $scope.sitePrefix + '/content/pages/' + result.data._id.toString(); }) .error(function(error, status) { $scope.errorMessage = error.message; diff --git a/plugins/portfolio/templates/angular/admin/content/pages/page_form.html b/plugins/portfolio/templates/angular/admin/content/pages/page_form.html index 283df1b7a..5ea0e2076 100644 --- a/plugins/portfolio/templates/angular/admin/content/pages/page_form.html +++ b/plugins/portfolio/templates/angular/admin/content/pages/page_form.html @@ -42,7 +42,7 @@ $scope.getPageData(draft, function(pageData) { $scope.saving = true; if(pageData._id) { - $http.post('/actions/admin/content/pages/' + $scope.page._id, pageData) + $http.post('/actions/admin' + $scope.sitePrefix + '/content/pages/' + $scope.page._id, pageData) .success(function(result) { $scope.successMessage = result.message; $scope.page.last_modified = result.data.last_modified; @@ -54,11 +54,11 @@ }); } else { - $http.post('/actions/admin/content/pages', pageData) + $http.post('/actions/admin' + $scope.sitePrefix + '/content/pages', pageData) .success(function(result) { $scope.successMessage = result.message; $scope.saving = false; - $window.location = '/admin/content/pages/' + result.data._id.toString(); + $window.location = '/admin' + $scope.sitePrefix + '/content/pages/' + result.data._id.toString(); }) .error(function(error, status) { $scope.errorMessage = error.message; From 7cb799682222df8caba9ba12f1ccd898625ff845 Mon Sep 17 00:00:00 2001 From: btidwell Date: Tue, 19 May 2015 16:04:33 -0400 Subject: [PATCH 181/790] siteid route to home page settings --- include/service/admin/admin_subnav_service.js | 8 ++++++++ plugins/portfolio/controllers/home_page_settings.js | 7 +++++++ plugins/portfolio/portfolio.js | 2 +- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/include/service/admin/admin_subnav_service.js b/include/service/admin/admin_subnav_service.js index 858d7319d..e0dca9416 100755 --- a/include/service/admin/admin_subnav_service.js +++ b/include/service/admin/admin_subnav_service.js @@ -122,6 +122,14 @@ module.exports = function AdminSubnavServiceModule(pb) { if (items[j] && items[j].name === activePill) { items[j].active = 'active'; } + if(items[j].href.indexOf(':siteid') > -1 ) { + if(data.plugin && data.plugin.site) { + items[j].href = items[j].href.replace(':siteid', data.plugin.site); + } + else { + items[j].href = items[j].href.replace('/:siteid/', '/'); + } + } navItems.push(items[j]); } } diff --git a/plugins/portfolio/controllers/home_page_settings.js b/plugins/portfolio/controllers/home_page_settings.js index 365f48750..f6a0cbfae 100755 --- a/plugins/portfolio/controllers/home_page_settings.js +++ b/plugins/portfolio/controllers/home_page_settings.js @@ -117,6 +117,13 @@ module.exports = function HomePageSettingsModule(pb) { auth_required: true, access_level: pb.SecurityService.ACCESS_EDITOR, content_type: 'text/html' + }, + { + method: 'get', + path: '/admin/:siteid/plugins/portfolio/settings/home_page', + auth_required: true, + access_level: pb.SecurityService.ACCESS_EDITOR, + content_type: 'text/html' } ]; cb(null, routes); diff --git a/plugins/portfolio/portfolio.js b/plugins/portfolio/portfolio.js index 22deb2a43..b1e9cad48 100755 --- a/plugins/portfolio/portfolio.js +++ b/plugins/portfolio/portfolio.js @@ -47,7 +47,7 @@ module.exports = function PortfolioModule(pb) { name: 'home_page_settings', title: 'Home page settings', icon: 'home', - href: '/admin/plugins/portfolio/settings/home_page' + href: '/admin/:siteid/plugins/portfolio/settings/home_page' } ]; } From 09a9de07b7d3406cb2294ca14f57a30d55390860 Mon Sep 17 00:00:00 2001 From: btidwell Date: Tue, 19 May 2015 16:07:11 -0400 Subject: [PATCH 182/790] Give plugin startup responsibility for multi route nav support --- include/service/admin/admin_subnav_service.js | 9 ++------- plugins/portfolio/portfolio.js | 9 ++++++++- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/include/service/admin/admin_subnav_service.js b/include/service/admin/admin_subnav_service.js index e0dca9416..12a3c17fa 100755 --- a/include/service/admin/admin_subnav_service.js +++ b/include/service/admin/admin_subnav_service.js @@ -122,13 +122,8 @@ module.exports = function AdminSubnavServiceModule(pb) { if (items[j] && items[j].name === activePill) { items[j].active = 'active'; } - if(items[j].href.indexOf(':siteid') > -1 ) { - if(data.plugin && data.plugin.site) { - items[j].href = items[j].href.replace(':siteid', data.plugin.site); - } - else { - items[j].href = items[j].href.replace('/:siteid/', '/'); - } + if(items[j].href.indexOf(':siteid') > -1 && data.plugin && data.plugin.site) { + items[j].href = items[j].href.replace(':siteid', data.plugin.site); } navItems.push(items[j]); } diff --git a/plugins/portfolio/portfolio.js b/plugins/portfolio/portfolio.js index b1e9cad48..5bff1ab35 100755 --- a/plugins/portfolio/portfolio.js +++ b/plugins/portfolio/portfolio.js @@ -42,12 +42,19 @@ module.exports = function PortfolioModule(pb) { Portfolio.onStartup = function(cb) { pb.AdminSubnavService.registerFor('plugin_settings', function(navKey, localization, data) { if(data.plugin.uid === 'portfolio') { + var href; + if(pb.config.multisite) { + href = '/admin/:siteid/plugins/portfolio/settings/home_page'; + } + else { + href = '/admin/plugins/portfolio/settings/home_page' + } return [ { name: 'home_page_settings', title: 'Home page settings', icon: 'home', - href: '/admin/:siteid/plugins/portfolio/settings/home_page' + href: href } ]; } From 4ed0ca10d5983bdb9dd19ed87cdec0645c8395d8 Mon Sep 17 00:00:00 2001 From: andparker Date: Tue, 19 May 2015 16:17:31 -0400 Subject: [PATCH 183/790] Don't need to pass in site to the where object anymore because the article service now uses the site query service --- plugins/pencilblue/controllers/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/pencilblue/controllers/index.js b/plugins/pencilblue/controllers/index.js index 97dfb5f66..f1824467c 100755 --- a/plugins/pencilblue/controllers/index.js +++ b/plugins/pencilblue/controllers/index.js @@ -249,7 +249,7 @@ module.exports = function IndexModule(pb) { service.findById(page, articleCallback); } else{ - service.find({site: this.site}, articleCallback); + service.find({}, articleCallback); } }; From 3ca3ec4385b2fde89dbbb1c66d4e72535244a13e Mon Sep 17 00:00:00 2001 From: Eugene Chang Date: Tue, 19 May 2015 16:33:38 -0400 Subject: [PATCH 184/790] Fixing article/page URL check --- include/service/entities/url_service.js | 9 ++++++--- .../actions/admin/content/articles/edit_article.js | 9 ++++----- .../actions/admin/content/articles/new_article.js | 7 +++---- .../actions/admin/content/pages/edit_page.js | 2 +- .../actions/admin/content/pages/new_page.js | 2 +- .../admin/content/articles/article_form.js | 2 ++ .../controllers/admin/content/pages/page_form.js | 3 +++ plugins/pencilblue/controllers/api/admin/url_api.js | 11 +++++++++-- .../angular/admin/content/articles/article_form.html | 10 +++++----- .../angular/admin/content/pages/page_form.html | 4 ++-- .../angular/admin/content/pages/page_form.html | 4 ++-- 11 files changed, 38 insertions(+), 25 deletions(-) diff --git a/include/service/entities/url_service.js b/include/service/entities/url_service.js index f13b42d49..e37e7976c 100755 --- a/include/service/entities/url_service.js +++ b/include/service/entities/url_service.js @@ -31,7 +31,11 @@ module.exports = function UrlServiceModule(pb) { * @module Services * @submodule Entities */ - function UrlService() {} + function UrlService(site, onlyThisSite) { + this.site = pb.SiteService.getCurrentSite(site); + this.onlyThisSite = onlyThisSite; + this.siteQueryService = new pb.SiteQueryService(this.site, this.onlyThisSite); + } //dependencies var RequestHandler = pb.RequestHandler; @@ -95,8 +99,7 @@ module.exports = function UrlServiceModule(pb) { if (site !== undefined) { where[pb.SiteService.SITE_FIELD] = site; } - var dao = new pb.DAO(); - dao.unique(type, where, id, function(err, isUnique) { + this.siteQueryService.unique(type, where, id, function(err, isUnique) { cb(err, !isUnique); }); }; diff --git a/plugins/pencilblue/controllers/actions/admin/content/articles/edit_article.js b/plugins/pencilblue/controllers/actions/admin/content/articles/edit_article.js index 6c28ecf21..d7f45ca79 100755 --- a/plugins/pencilblue/controllers/actions/admin/content/articles/edit_article.js +++ b/plugins/pencilblue/controllers/actions/admin/content/articles/edit_article.js @@ -24,7 +24,7 @@ module.exports = function(pb) { * Edits an article */ function EditArticle(){} - util.inherits(EditArticle, pb.BaseController); + util.inherits(EditArticle, pb.BaseAdminController); EditArticle.prototype.render = function(cb) { var self = this; @@ -44,8 +44,7 @@ module.exports = function(pb) { return; } - var dao = new pb.DAO(); - dao.loadById(post.id, 'article', function(err, article) { + self.siteQueryService.loadById(post.id, 'article', function(err, article) { if(util.isError(err) || article === null) { cb({ code: 400, @@ -61,7 +60,7 @@ module.exports = function(pb) { post = pb.DocumentCreator.formatIntegerItems(post, ['draft']); pb.DocumentCreator.update(post, article, ['meta_keywords']); - pb.RequestHandler.urlExists(article.url, post.id, article.site, function(error, exists) { + pb.RequestHandler.urlExists(article.url, post.id, self.pathSiteUId, function(error, exists) { var testError = (error !== null && typeof error !== 'undefined'); if( testError || exists || article.url.indexOf('/admin') === 0) { @@ -72,7 +71,7 @@ module.exports = function(pb) { return; } - dao.save(article, function(err, result) { + self.siteQueryService.save(article, function(err, result) { if(util.isError(err)) { return cb({ code: 500, diff --git a/plugins/pencilblue/controllers/actions/admin/content/articles/new_article.js b/plugins/pencilblue/controllers/actions/admin/content/articles/new_article.js index ea2f58380..d85b34bfe 100755 --- a/plugins/pencilblue/controllers/actions/admin/content/articles/new_article.js +++ b/plugins/pencilblue/controllers/actions/admin/content/articles/new_article.js @@ -24,7 +24,7 @@ module.exports = function(pb) { * Creates a new article */ function NewArticlePostController(){} - util.inherits(NewArticlePostController, pb.BaseController); + util.inherits(NewArticlePostController, pb.BaseAdminController); NewArticlePostController.prototype.render = function(cb) { var self = this; @@ -47,7 +47,7 @@ module.exports = function(pb) { post = pb.DocumentCreator.formatIntegerItems(post, ['draft']); var articleDocument = pb.DocumentCreator.create('article', post, ['meta_keywords']); - pb.RequestHandler.isSystemSafeURL(articleDocument.url, null, articleDocument.site, function(err, isSafe) { + pb.RequestHandler.isSystemSafeURL(articleDocument.url, null, self.pathSiteUId, function(err, isSafe) { if(util.isError(err) || !isSafe) { cb({ code: 400, @@ -56,8 +56,7 @@ module.exports = function(pb) { return; } - var dao = new pb.DAO(); - dao.save(articleDocument, function(err, result) { + self.siteQueryService.save(articleDocument, function(err, result) { if(util.isError(err)) { return cb({ code: 500, diff --git a/plugins/pencilblue/controllers/actions/admin/content/pages/edit_page.js b/plugins/pencilblue/controllers/actions/admin/content/pages/edit_page.js index ee6db6e31..85136a7d0 100755 --- a/plugins/pencilblue/controllers/actions/admin/content/pages/edit_page.js +++ b/plugins/pencilblue/controllers/actions/admin/content/pages/edit_page.js @@ -64,7 +64,7 @@ module.exports = function(pb) { self.setFormFieldValues(post); - pb.RequestHandler.urlExists(page.url, post.id, page.site, function(err, exists) { + pb.RequestHandler.urlExists(page.url, post.id, self.pathSiteUId, function(err, exists) { if(util.isError(err) || exists) { cb({ code: 400, diff --git a/plugins/pencilblue/controllers/actions/admin/content/pages/new_page.js b/plugins/pencilblue/controllers/actions/admin/content/pages/new_page.js index cec1d5207..9da414a22 100755 --- a/plugins/pencilblue/controllers/actions/admin/content/pages/new_page.js +++ b/plugins/pencilblue/controllers/actions/admin/content/pages/new_page.js @@ -50,7 +50,7 @@ module.exports = function(pb) { post = pb.DocumentCreator.formatIntegerItems(post, ['draft']); var pageDocument = pb.DocumentCreator.create('page', post, ['meta_keywords']); - pb.RequestHandler.urlExists(pageDocument.url, post.id, pageDocument.site, function(err, exists) { + pb.RequestHandler.urlExists(pageDocument.url, post.id, self.pathSiteUId, function(err, exists) { if(util.isError(err) || exists) { cb({ code: 400, diff --git a/plugins/pencilblue/controllers/admin/content/articles/article_form.js b/plugins/pencilblue/controllers/admin/content/articles/article_form.js index c582356cc..12d606df1 100755 --- a/plugins/pencilblue/controllers/admin/content/articles/article_form.js +++ b/plugins/pencilblue/controllers/admin/content/articles/article_form.js @@ -137,6 +137,8 @@ module.exports = function(pb) { topics: data.topics, media: data.media, article: data.article, + siteKey: pb.SiteService.SITE_FIELD, + site: self.pathSiteUId, sitePrefix: self.sitePrefix }; if(data.availableAuthors) { diff --git a/plugins/pencilblue/controllers/admin/content/pages/page_form.js b/plugins/pencilblue/controllers/admin/content/pages/page_form.js index b8e027460..2ef593427 100755 --- a/plugins/pencilblue/controllers/admin/content/pages/page_form.js +++ b/plugins/pencilblue/controllers/admin/content/pages/page_form.js @@ -113,6 +113,7 @@ module.exports = function(pb) { data.page.page_topics = topics; } + data.sitePrefix = self.sitePrefix; var objects = { navigation: pb.AdminNavigation.get(this.session, ['content', 'pages'], this.ls), pills: self.getAdminPills(this.getActivePill(), this.ls, this.getActivePill(), data), @@ -122,6 +123,8 @@ module.exports = function(pb) { topics: data.topics, media: data.media, page: data.page, + siteKey: pb.SiteService.SITE_FIELD, + site: self.pathSiteUId, sitePrefix: self.sitePrefix }; if(data.availableAuthors) { diff --git a/plugins/pencilblue/controllers/api/admin/url_api.js b/plugins/pencilblue/controllers/api/admin/url_api.js index 70dbe87d5..ffd2d4fcc 100755 --- a/plugins/pencilblue/controllers/api/admin/url_api.js +++ b/plugins/pencilblue/controllers/api/admin/url_api.js @@ -29,7 +29,8 @@ module.exports = function(pb) { * @class UrlApiController * @constructor */ - function UrlApiController() {}; + function UrlApiController() { + } util.inherits(UrlApiController, ApiActionController); //constants @@ -107,7 +108,13 @@ module.exports = function(pb) { id: this.query.id, url: this.query.url }; - var service = new UrlService(); + var service; + var SITE_FIELD = pb.SiteService.SITE_FIELD; + if (SITE_FIELD in this.query) { + service = new UrlService(this.query[SITE_FIELD], true); + } else { + service = new UrlService(); + } service.existsForType(params, function(err, exists) { if (util.isError(err)) { var content = BaseController.apiResponse(BaseController.API_FAILURE, err.message); diff --git a/plugins/pencilblue/templates/angular/admin/content/articles/article_form.html b/plugins/pencilblue/templates/angular/admin/content/articles/article_form.html index 567fdd6a2..17fc6fb27 100644 --- a/plugins/pencilblue/templates/angular/admin/content/articles/article_form.html +++ b/plugins/pencilblue/templates/angular/admin/content/articles/article_form.html @@ -24,7 +24,7 @@ }; $scope.getUrlAvailability = function() { - $http.get('/api/url/exists_for?url=' + $scope.article.url + '&type=article') + $http.get('/api/url/exists_for?url=' + $scope.article.url + '&type=article&' + $scope.siteKey + '=' + $scope.site) .success(function(result) { $scope.urlAvailable = !result.data; }) @@ -48,7 +48,7 @@ $scope.getArticleData(draft, function(articleData) { $scope.saving = true; if(articleData._id) { - $http.post('/actions/admin/content/articles/' + $scope.article._id, articleData) + $http.post('/actions/admin' + $scope.sitePrefix + '/content/articles/' + $scope.article._id, articleData) .success(function(result) { $scope.successMessage = result.message; $scope.article.last_modified = result.data.last_modified; @@ -60,13 +60,13 @@ }); } else { - $http.post('/actions/admin/content/articles', articleData) + $http.post('/actions/admin' + $scope.sitePrefix + '/content/articles', articleData) .success(function(result) { $scope.successMessage = result.message; $scope.saving = false; if(!result.data._id) { - $window.location = '/admin/content/articles'; + $window.location = '/admin' + $scope.sitePrefix + '/content/articles'; return; } $window.location = '/admin' + $scope.sitePrefix + '/content/articles/' + result.data._id.toString(); @@ -87,7 +87,7 @@ $scope.article.draft = true; $scope.getArticleData(true, function(articleData) { $scope.saving = true; - $http.post('/actions/admin/content/articles/' + $scope.article._id, articleData) + $http.post('/actions/admin' + $scope.sitePrefix + '/content/articles/' + $scope.article._id, articleData) .success(function(result) { $scope.article.last_modified = result.data.last_modified; $timeout($scope.saveArticleDraft, 30000); diff --git a/plugins/pencilblue/templates/angular/admin/content/pages/page_form.html b/plugins/pencilblue/templates/angular/admin/content/pages/page_form.html index 4cf0b9ffd..196370a3c 100644 --- a/plugins/pencilblue/templates/angular/admin/content/pages/page_form.html +++ b/plugins/pencilblue/templates/angular/admin/content/pages/page_form.html @@ -19,7 +19,7 @@ }; $scope.getUrlAvailability = function() { - $http.get('/api/url/exists_for?url=' + $scope.page.url + '&type=page') + $http.get('/api/url/exists_for?url=' + $scope.page.url + '&type=page&' + $scope.siteKey + '=' + $scope.site) .success(function(result) { $scope.urlAvailable = !result.data; }) @@ -77,7 +77,7 @@ $scope.page.draft = true; $scope.getPageData(true, function(pageData) { $scope.saving = true; - $http.post('/actions/admin/content/pages/' + $scope.page._id, pageData) + $http.post('/actions/admin' + $scope.sitePrefix + '/content/pages/' + $scope.page._id, pageData) .success(function(result) { $scope.page.last_modified = result.data.last_modified; $timeout($scope.savePageDraft, 30000); diff --git a/plugins/portfolio/templates/angular/admin/content/pages/page_form.html b/plugins/portfolio/templates/angular/admin/content/pages/page_form.html index 5ea0e2076..32e1ab3dd 100644 --- a/plugins/portfolio/templates/angular/admin/content/pages/page_form.html +++ b/plugins/portfolio/templates/angular/admin/content/pages/page_form.html @@ -18,7 +18,7 @@ }; $scope.getUrlAvailability = function() { - $http.get('/api/url/exists_for?url=' + $scope.page.url + '&type=page') + $http.get('/api/url/exists_for?url=' + $scope.page.url + '&type=page&' + $scope.siteKey + '=' + $scope.site) .success(function(result) { $scope.urlAvailable = !result.data; }) @@ -76,7 +76,7 @@ $scope.page.draft = true; $scope.getPageData(true, function(pageData) { $scope.saving = true; - $http.post('/actions/admin/content/pages/' + $scope.page._id, pageData) + $http.post('/actions/admin' + $scope.sitePrefix + '/content/pages/' + $scope.page._id, pageData) .success(function(result) { $scope.page.last_modified = result.data.last_modified; $timeout($scope.savePageDraft, 30000); From cb2baa37aa2ffb3c328dd669b975a5f24aa053b9 Mon Sep 17 00:00:00 2001 From: btidwell Date: Tue, 19 May 2015 16:37:39 -0400 Subject: [PATCH 185/790] navigation on home page settings of portfolio theme plugin --- .../controllers/home_page_settings.js | 37 +++++++++---------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/plugins/portfolio/controllers/home_page_settings.js b/plugins/portfolio/controllers/home_page_settings.js index f6a0cbfae..8ef52a438 100755 --- a/plugins/portfolio/controllers/home_page_settings.js +++ b/plugins/portfolio/controllers/home_page_settings.js @@ -20,6 +20,7 @@ module.exports = function HomePageSettingsModule(pb) { //pb dependencies var util = pb.util; var PluginService = pb.PluginService; + var SUB_NAV_KEY = 'portfolio_home_page_settings'; /** * Settings for the display of home page content in the Portfolio theme @@ -27,16 +28,10 @@ module.exports = function HomePageSettingsModule(pb) { * @author Blake Callens */ function HomePageSettings() {} - util.inherits(HomePageSettings, pb.BaseController); + util.inherits(HomePageSettings, pb.BaseAdminController); HomePageSettings.prototype.render = function(cb) { var self = this; - - var content = { - content_type: "text/html", - code: 200 - }; - var tabs = [ { active: 'active', @@ -56,19 +51,10 @@ module.exports = function HomePageSettingsModule(pb) { } ]; - var pills = [ - { - name: 'content_settings', - title: self.ls.get('HOME_PAGE_SETTINGS'), - icon: 'chevron-left', - href: '/admin/plugins/portfolio/settings' - }]; - var opts = { where: {settings_type: 'home_page'} }; - var dao = new pb.DAO(); - dao.q('portfolio_theme_settings', opts, function(err, homePageSettings) { + self.siteQueryService.q('portfolio_theme_settings', opts, function(err, homePageSettings) { if(homePageSettings.length > 0) { homePageSettings = homePageSettings[0]; } @@ -76,7 +62,7 @@ module.exports = function HomePageSettingsModule(pb) { homePageSettings = {callouts: [{}, {}, {}]}; } - var mservice = new pb.MediaService(); + var mservice = new pb.MediaService(self.pathSiteUId, true); mservice.get(function(err, media) { if(homePageSettings.page_media) { var pageMedia = []; @@ -94,7 +80,7 @@ module.exports = function HomePageSettingsModule(pb) { var objects = { navigation: pb.AdminNavigation.get(self.session, ['plugins', 'manage'], self.ls), - pills: pills, + pills: self.getAdminPills(SUB_NAV_KEY, self.ls, null, {sitePrefix: self.sitePrefix}), tabs: tabs, media: media, homePageSettings: homePageSettings @@ -109,6 +95,17 @@ module.exports = function HomePageSettingsModule(pb) { }); }; + HomePageSettings.getSubNavItems = function(key, ls, data) { + return [ + { + name: 'content_settings', + title: ls.get('HOME_PAGE_SETTINGS'), + icon: 'chevron-left', + href: '/admin'+ data.sitePrefix + '/plugins/portfolio/settings' + } + ]; + }; + HomePageSettings.getRoutes = function(cb) { var routes = [ { @@ -128,6 +125,8 @@ module.exports = function HomePageSettingsModule(pb) { ]; cb(null, routes); }; + //register admin sub-nav + pb.AdminSubnavService.registerFor(SUB_NAV_KEY, HomePageSettings.getSubNavItems); //exports return HomePageSettings; From 468d46a47e19c6b11c27fd6812c3764efde7b670 Mon Sep 17 00:00:00 2001 From: Eugene Chang Date: Tue, 19 May 2015 16:56:10 -0400 Subject: [PATCH 186/790] Utility functions for SiteService --- include/service/entities/site_service.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/include/service/entities/site_service.js b/include/service/entities/site_service.js index 5e8faf9fb..a9ed16960 100644 --- a/include/service/entities/site_service.js +++ b/include/service/entities/site_service.js @@ -287,6 +287,27 @@ module.exports = function SiteServiceModule(pb) { return (!siteid || siteid === SiteService.GLOBAL_SITE); }; + /** + * Returns true iff both site given are equal + * @param siteA + * @param siteB + */ + SiteService.areEqual = function (siteA, siteB) { + if (SiteService.isGlobal(siteA) && SiteService.isGlobal(siteB)) { + return true; + } + return siteA === siteB; + }; + + /** + * Returns true iff actual is not set (falsey) or logically equivalent to expected in terms of sites + * @param actual + * @param expected + */ + SiteService.isNotSetOrEqual = function (actual, expected) { + return !actual || SiteService.areEqual(actual, expected); + }; + /** * Central place to get the current site * From f70a2eac966eecbf4023ba40b91683d57d6fa238 Mon Sep 17 00:00:00 2001 From: Eugene Chang Date: Tue, 19 May 2015 17:09:55 -0400 Subject: [PATCH 187/790] Fixing theme list --- include/service/entities/plugin_service.js | 24 ++++++++++++------- include/service/entities/template_service.js | 5 ++-- .../admin/content/articles/article_form.js | 2 +- .../admin/content/pages/page_form.js | 2 +- 4 files changed, 21 insertions(+), 12 deletions(-) diff --git a/include/service/entities/plugin_service.js b/include/service/entities/plugin_service.js index 1311a1cc2..16ccd6db0 100755 --- a/include/service/entities/plugin_service.js +++ b/include/service/entities/plugin_service.js @@ -596,18 +596,26 @@ module.exports = function PluginServiceModule(pb) { * Retrieves the content templates for all of the active plugins * @static * @method getActiveContentTemplates + * @param site * @return {Array} An array of objects */ - PluginService.getActiveContentTemplates = function() { + PluginService.getActiveContentTemplates = function(targetSite) { var templates = []; - for (var uid in ACTIVE_PLUGINS) { - var plugin = ACTIVE_PLUGINS[uid]; - if (plugin.templates) { - var clone = util.clone(plugin.templates); - for(var i = 0; i < clone.length; i++) { - clone[i].theme_uid = uid; - templates.push(clone[i]); + + for (var site in ACTIVE_PLUGINS) { + if (!pb.SiteService.isNotSetOrEqual(targetSite, site)) { + continue; + } + var pluginsForSite = ACTIVE_PLUGINS[site]; + for (var uid in pluginsForSite) { + var plugin = pluginsForSite[uid]; + if (plugin.templates) { + var clone = util.clone(plugin.templates); + for(var i = 0; i < clone.length; i++) { + clone[i].theme_uid = uid; + templates.push(clone[i]); + } } } } diff --git a/include/service/entities/template_service.js b/include/service/entities/template_service.js index c479c957d..62f7f82ee 100755 --- a/include/service/entities/template_service.js +++ b/include/service/entities/template_service.js @@ -568,10 +568,11 @@ module.exports = function(pb) { * Articles and pages. * * @method getAvailableContentTemplates + * @param site * @return {Array} An array of template definitions */ - TemplateService.getAvailableContentTemplates = function() { - var templates = pb.PluginService.getActiveContentTemplates(); + TemplateService.getAvailableContentTemplates = function(site) { + var templates = pb.PluginService.getActiveContentTemplates(site); templates.push( { theme_uid: 'pencilblue', diff --git a/plugins/pencilblue/controllers/admin/content/articles/article_form.js b/plugins/pencilblue/controllers/admin/content/articles/article_form.js index 12d606df1..e40ecf353 100755 --- a/plugins/pencilblue/controllers/admin/content/articles/article_form.js +++ b/plugins/pencilblue/controllers/admin/content/articles/article_form.js @@ -170,7 +170,7 @@ module.exports = function(pb) { var self = this; var tasks = { templates: function(callback) { - callback(null, pb.TemplateService.getAvailableContentTemplates()); + callback(null, pb.TemplateService.getAvailableContentTemplates(self.pathSiteUId)); }, sections: function(callback) { diff --git a/plugins/pencilblue/controllers/admin/content/pages/page_form.js b/plugins/pencilblue/controllers/admin/content/pages/page_form.js index 2ef593427..40ae3a386 100755 --- a/plugins/pencilblue/controllers/admin/content/pages/page_form.js +++ b/plugins/pencilblue/controllers/admin/content/pages/page_form.js @@ -171,7 +171,7 @@ module.exports = function(pb) { var self = this; var tasks = { templates: function(callback) { - callback(null, pb.TemplateService.getAvailableContentTemplates()); + callback(null, pb.TemplateService.getAvailableContentTemplates(self.pathSiteUId)); }, sections: function(callback) { From 35432190a5951d70dbf29d39b7d3410a075a88ff Mon Sep 17 00:00:00 2001 From: btidwell Date: Wed, 20 May 2015 09:55:22 -0400 Subject: [PATCH 188/790] Save home page settings per site --- .../portfolio/controllers/home_page_settings.js | 2 +- .../controllers/save_home_page_settings.js | 14 ++++++++++---- .../angular/admin/settings/home_page_settings.html | 2 +- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/plugins/portfolio/controllers/home_page_settings.js b/plugins/portfolio/controllers/home_page_settings.js index 8ef52a438..271f939cd 100755 --- a/plugins/portfolio/controllers/home_page_settings.js +++ b/plugins/portfolio/controllers/home_page_settings.js @@ -59,7 +59,7 @@ module.exports = function HomePageSettingsModule(pb) { homePageSettings = homePageSettings[0]; } else { - homePageSettings = {callouts: [{}, {}, {}]}; + homePageSettings = {callouts: [{}, {}, {}], site:self.pathSiteUId}; } var mservice = new pb.MediaService(self.pathSiteUId, true); diff --git a/plugins/portfolio/controllers/save_home_page_settings.js b/plugins/portfolio/controllers/save_home_page_settings.js index 198fd58f7..664145e8e 100755 --- a/plugins/portfolio/controllers/save_home_page_settings.js +++ b/plugins/portfolio/controllers/save_home_page_settings.js @@ -27,7 +27,7 @@ module.exports = function SaveHomePageSettingsModule(pb) { * @copyright 2014 PencilBlue, LLC. All Rights Reserved */ function SaveHomePageSettings() {} - util.inherits(SaveHomePageSettings, pb.BaseController); + util.inherits(SaveHomePageSettings, pb.BaseAdminController); SaveHomePageSettings.prototype.render = function(cb) { var self = this; @@ -38,8 +38,7 @@ module.exports = function SaveHomePageSettingsModule(pb) { var opts = { where: {settings_type: 'home_page'} }; - var dao = new pb.DAO(); - dao.q('portfolio_theme_settings', opts, function(err, homePageSettings) { + self.siteQueryService.q('portfolio_theme_settings', opts, function(err, homePageSettings) { if (util.isError(err)) { return self.reqHandler.serveError(err); } @@ -52,7 +51,7 @@ module.exports = function SaveHomePageSettingsModule(pb) { homePageSettings.settings_type = 'home_page'; } - dao.save(homePageSettings, function(err, result) { + self.siteQueryService.save(homePageSettings, function(err, result) { if(util.isError(err)) { cb({ code: 500, @@ -81,6 +80,13 @@ module.exports = function SaveHomePageSettingsModule(pb) { auth_required: true, access_level: pb.SecurityService.ACCESS_EDITOR, content_type: 'text/html' + }, + { + method: 'post', + path: '/actions/admin/:siteid/plugins/settings/portfolio/home_page', + auth_required: true, + access_level: pb.SecurityService.ACCESS_EDITOR, + content_type: 'text/html' } ]; cb(null, routes); diff --git a/plugins/portfolio/templates/angular/admin/settings/home_page_settings.html b/plugins/portfolio/templates/angular/admin/settings/home_page_settings.html index 48df443ef..0ce35fd40 100644 --- a/plugins/portfolio/templates/angular/admin/settings/home_page_settings.html +++ b/plugins/portfolio/templates/angular/admin/settings/home_page_settings.html @@ -24,7 +24,7 @@ $scope.saving = true; - $http.post('/actions/admin/plugins/settings/portfolio/home_page', $scope.homePageSettings) + $http.post('/actions/admin/'+ $scope.homePageSettings.site +'/plugins/settings/portfolio/home_page', $scope.homePageSettings) .success(function(result) { $scope.successMessage = result.message; $scope.saving = false; From d83b829f7de3a9a8b24465cd4d34017c7f13b284 Mon Sep 17 00:00:00 2001 From: btidwell Date: Wed, 20 May 2015 10:27:43 -0400 Subject: [PATCH 189/790] remove indexOf and replace with a null/undefined check --- include/service/admin/admin_subnav_service.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/service/admin/admin_subnav_service.js b/include/service/admin/admin_subnav_service.js index 12a3c17fa..07606438a 100755 --- a/include/service/admin/admin_subnav_service.js +++ b/include/service/admin/admin_subnav_service.js @@ -122,7 +122,7 @@ module.exports = function AdminSubnavServiceModule(pb) { if (items[j] && items[j].name === activePill) { items[j].active = 'active'; } - if(items[j].href.indexOf(':siteid') > -1 && data.plugin && data.plugin.site) { + if(items[j].href && data.plugin && data.plugin.site) { items[j].href = items[j].href.replace(':siteid', data.plugin.site); } navItems.push(items[j]); From 7d0b2105507f35308d33bcb6e15b98dbef581328 Mon Sep 17 00:00:00 2001 From: btidwell Date: Wed, 20 May 2015 10:55:24 -0400 Subject: [PATCH 190/790] add null/undefined check on data --- include/service/admin/admin_subnav_service.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/service/admin/admin_subnav_service.js b/include/service/admin/admin_subnav_service.js index 07606438a..c6e91b9bf 100755 --- a/include/service/admin/admin_subnav_service.js +++ b/include/service/admin/admin_subnav_service.js @@ -122,7 +122,7 @@ module.exports = function AdminSubnavServiceModule(pb) { if (items[j] && items[j].name === activePill) { items[j].active = 'active'; } - if(items[j].href && data.plugin && data.plugin.site) { + if(items[j].href && data && data.plugin && data.plugin.site) { items[j].href = items[j].href.replace(':siteid', data.plugin.site); } navItems.push(items[j]); From ce80ca51ec5511103eaf94cac489af9967900721 Mon Sep 17 00:00:00 2001 From: Eugene Chang Date: Wed, 20 May 2015 11:27:37 -0400 Subject: [PATCH 191/790] Documentation update --- include/service/entities/plugin_service.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/service/entities/plugin_service.js b/include/service/entities/plugin_service.js index 16ccd6db0..9c5e2f4c5 100755 --- a/include/service/entities/plugin_service.js +++ b/include/service/entities/plugin_service.js @@ -596,7 +596,7 @@ module.exports = function PluginServiceModule(pb) { * Retrieves the content templates for all of the active plugins * @static * @method getActiveContentTemplates - * @param site + * @param targetSite * @return {Array} An array of objects */ PluginService.getActiveContentTemplates = function(targetSite) { From 54b10e66f6a77aad2df5853ff9943fddfde77ba9 Mon Sep 17 00:00:00 2001 From: Christina Chatham Date: Wed, 20 May 2015 13:20:20 -0400 Subject: [PATCH 192/790] Test email respect site's email config. --- .../admin/site_settings/email/send_test.js | 5 ++- .../include/multisite_admin_routes.js | 12 +++++- plugins/pencilblue/include/routes.js | 43 +++++++++---------- 3 files changed, 34 insertions(+), 26 deletions(-) diff --git a/plugins/pencilblue/controllers/api/admin/site_settings/email/send_test.js b/plugins/pencilblue/controllers/api/admin/site_settings/email/send_test.js index 9620864c3..e2ba56f54 100644 --- a/plugins/pencilblue/controllers/api/admin/site_settings/email/send_test.js +++ b/plugins/pencilblue/controllers/api/admin/site_settings/email/send_test.js @@ -41,9 +41,10 @@ module.exports = function(pb) { var options = { to: post.email, subject: 'Test email from PencilBlue', - layout: 'This is a successful test email from the PencilBlue system.', + layout: 'This is a successful test email from the PencilBlue system.' }; - pb.email.sendFromLayout(options, function(err, response) { + var emailService = new pb.EmailService(pb.SiteService.getCurrentSite(self.pathVars.siteid)); + emailService.sendFromLayout(options, function(err, response) { if(err) { return cb({ code: 500, diff --git a/plugins/pencilblue/include/multisite_admin_routes.js b/plugins/pencilblue/include/multisite_admin_routes.js index 2def89489..f860589e4 100644 --- a/plugins/pencilblue/include/multisite_admin_routes.js +++ b/plugins/pencilblue/include/multisite_admin_routes.js @@ -199,7 +199,7 @@ module.exports = function Routes(pb){ path: "/actions/admin/:siteid/content/articles/:id", access_level: pb.SecurityService.ACCESS_EDITOR, auth_required: true, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'content', 'articles', 'delete_article.js'), + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'content', 'articles', 'delete_article.js') }, // PAGES @@ -592,6 +592,14 @@ module.exports = function Routes(pb){ controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'site_settings', 'email.js'), content_type: 'text/html' }, + { + method: 'post', + path: "/api/admin/:siteid/site_settings/email/send_test", + auth_required: true, + access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'api', 'admin', 'site_settings', 'email', 'send_test.js'), + content_type: 'application/json' + }, { method: 'get', path: "/admin/"+ pb.SiteService.GLOBAL_SITE + "/site_settings/libraries", @@ -605,7 +613,7 @@ module.exports = function Routes(pb){ path: "/admin/:siteid/users/:id", auth_required: true, access_level: pb.SecurityService.ACCESS_EDITOR, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'users', 'user_form.js'), + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'users', 'user_form.js') } ]; }; diff --git a/plugins/pencilblue/include/routes.js b/plugins/pencilblue/include/routes.js index 93a08850f..26970a5a2 100644 --- a/plugins/pencilblue/include/routes.js +++ b/plugins/pencilblue/include/routes.js @@ -122,7 +122,7 @@ module.exports = function Routes(pb){ method: 'post', path: "/actions/user/manage_account/change_password", auth_required: true, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'user', 'manage_account', 'change_password.js'), + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'user', 'manage_account', 'change_password.js') }, { method: 'post', @@ -135,19 +135,19 @@ module.exports = function Routes(pb){ method: 'post', path: "/actions/user/resend_verification", auth_required: false, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'user', 'resend_verification.js'), + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'user', 'resend_verification.js') }, { method: 'post', path: "/actions/user/sign_up", auth_required: false, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'user', 'sign_up.js'), + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'user', 'sign_up.js') }, { method: 'get', path: "/actions/user/verify_email", auth_required: false, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'user', 'verify_email.js'), + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'user', 'verify_email.js') }, { method: 'get', @@ -167,7 +167,7 @@ module.exports = function Routes(pb){ method: 'get', path: "/user/sign_up", auth_required: false, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'user', 'sign_up.js'), + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'user', 'sign_up.js') }, { method: 'get', @@ -181,7 +181,7 @@ module.exports = function Routes(pb){ handler: 'login', path: "/user/login", auth_required: false, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'user', 'login.js'), + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'user', 'login.js') }, { method: 'get', @@ -480,7 +480,7 @@ module.exports = function Routes(pb){ path: "/actions/admin/content/articles/:id", access_level: pb.SecurityService.ACCESS_EDITOR, auth_required: true, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'content', 'articles', 'delete_article.js'), + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'content', 'articles', 'delete_article.js') }, // PAGES @@ -829,7 +829,7 @@ module.exports = function Routes(pb){ path: "/actions/admin/themes/site_logo", auth_required: true, access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'themes', 'site_logo.js'), + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'themes', 'site_logo.js') }, // USERS @@ -838,92 +838,91 @@ module.exports = function Routes(pb){ path: "/admin/users", auth_required: true, access_level: pb.SecurityService.ACCESS_EDITOR, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'users', 'manage_users.js'), + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'users', 'manage_users.js') }, { method: 'get', path: "/admin/users/unverified", auth_required: true, access_level: pb.SecurityService.ACCESS_EDITOR, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'users', 'unverified_users.js'), + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'users', 'unverified_users.js') }, { method: 'get', path: "/admin/users/new", auth_required: true, access_level: pb.SecurityService.ACCESS_EDITOR, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'users', 'user_form.js'), + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'users', 'user_form.js') }, { method: 'get', path: "/admin/users/:id", auth_required: true, access_level: pb.SecurityService.ACCESS_EDITOR, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'users', 'user_form.js'), + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'users', 'user_form.js') }, { method: 'get', path: "/admin/users/password/:id", auth_required: true, access_level: pb.SecurityService.ACCESS_EDITOR, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'users', 'change_password.js'), + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'users', 'change_password.js') }, { method: 'post', path: "/actions/admin/users", auth_required: true, access_level: pb.SecurityService.ACCESS_EDITOR, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'users', 'new_user.js'), + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'users', 'new_user.js') }, { method: 'post', path: "/actions/admin/users/:id", auth_required: true, access_level: pb.SecurityService.ACCESS_EDITOR, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'users', 'edit_user.js'), + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'users', 'edit_user.js') }, { method: 'delete', path: "/actions/admin/users/:id", auth_required: true, access_level: pb.SecurityService.ACCESS_EDITOR, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'users', 'delete_user.js'), + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'users', 'delete_user.js') }, { method: 'delete', path: "/actions/admin/users/unverified/:id", auth_required: true, access_level: pb.SecurityService.ACCESS_EDITOR, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'users', 'delete_unverified_user.js'), + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'users', 'delete_unverified_user.js') }, { method: 'get', path: "/actions/admin/users/verify/:id", auth_required: true, access_level: pb.SecurityService.ACCESS_EDITOR, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'users', 'verify_user.js'), + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'users', 'verify_user.js') }, - { method: 'post', path: "/actions/admin/users/change_password/:id", auth_required: true, access_level: pb.SecurityService.ACCESS_EDITOR, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'users', 'change_password.js'), + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'users', 'change_password.js') }, { method: 'get', path: "/actions/admin/users/send_password_reset/:id", auth_required: true, access_level: pb.SecurityService.ACCESS_MANAGING_EDITOR, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'users', 'send_password_reset.js'), + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'users', 'send_password_reset.js') }, { method: 'post', path: "/actions/admin/users/send_password_reset/:id", auth_required: true, access_level: pb.SecurityService.ACCESS_MANAGING_EDITOR, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'users', 'send_password_reset.js'), + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'users', 'send_password_reset.js') }, // SITE SETTINGS From 8d599fe47ea916389b625bb8b676ff99ae76aeef Mon Sep 17 00:00:00 2001 From: Christina Chatham Date: Wed, 20 May 2015 14:26:33 -0400 Subject: [PATCH 193/790] Site aware for emails under user. --- include/email.js | 2 +- include/service/entities/user_service.js | 75 +++++++++++++----------- 2 files changed, 42 insertions(+), 35 deletions(-) diff --git a/include/email.js b/include/email.js index b7f899266..1e9c9cefd 100755 --- a/include/email.js +++ b/include/email.js @@ -67,7 +67,7 @@ module.exports = function EmailServiceModule(pb) { */ EmailService.prototype.sendFromTemplate = function(options, cb){ var self = this; - var ts = new pb.TemplateService(); + var ts = new pb.TemplateService(null, this.site); if (options.replacements) { for(var key in options.replacements) { ts.registerLocal(key, options.replacements[key]); diff --git a/include/service/entities/user_service.js b/include/service/entities/user_service.js index a329ad97e..01f3d8973 100755 --- a/include/service/entities/user_service.js +++ b/include/service/entities/user_service.js @@ -29,7 +29,9 @@ module.exports = function UserServiceModule(pb) { * @class UserService * @constructor */ - function UserService(){} + function UserService(siteuid) { + this.site = pb.config.multisite ? pb.SiteService.getCurrentSite(siteuid) : pb.SiteService.GLOBAL_SITE; + } /** * Gets the full name of a user @@ -212,27 +214,29 @@ module.exports = function UserServiceModule(pb) { UserService.prototype.sendVerificationEmail = function(user, cb) { cb = cb || util.cb; - // We need to see if email settings have been saved with verification content - var emailService = new pb.EmailService(); - emailService.getSettings(function(err, emailSettings) { - var options = { - to: user.email, - replacements: { - 'verification_url': pb.config.siteRoot + '/actions/user/verify_email?email=' + user.email + '&code=' + user.verification_code, - 'first_name': user.first_name, - 'last_name': user.last_name + pb.SiteService.getByUid(this.site, function(err, siteInfo) { + // We need to see if email settings have been saved with verification content + var emailService = new pb.EmailService(this.site); + emailService.getSettings(function(err, emailSettings) { + var options = { + to: user.email, + replacements: { + 'verification_url': siteInfo.hostname + '/actions/user/verify_email?email=' + user.email + '&code=' + user.verification_code, + 'first_name': user.first_name, + 'last_name': user.last_name + } + }; + if(emailSettings.layout) { + options.subject= emailSettings.verification_subject; + options.layout = emailSettings.verification_content; + emailService.sendFromLayout(options, cb); } - }; - if(emailSettings.layout) { - options.subject= emailSettings.verification_subject; - options.layout = emailSettings.verification_content; - emailService.sendFromLayout(options, cb); - } - else { - options.subject = pb.config.siteName + ' Account Confirmation'; - options.template = emailSettings.template; - emailService.sendFromTemplate(options, cb); - } + else { + options.subject = siteInfo.displayName + ' Account Confirmation'; + options.template = emailSettings.template; + emailService.sendFromTemplate(options, cb); + } + }); }); }; @@ -247,19 +251,22 @@ module.exports = function UserServiceModule(pb) { UserService.prototype.sendPasswordResetEmail = function(user, passwordReset, cb) { cb = cb || util.cb; - var verficationUrl = pb.UrlService.urlJoin(pb.config.siteRoot, '/actions/user/reset_password') + util.format('?email=%s&code=%s', encodeURIComponent(user.email), encodeURIComponent(passwordReset.verification_code)); - var options = { - to: user.email, - subject: pb.config.siteName + ' Password Reset', - template: 'admin/elements/password_reset_email', - replacements: { - 'verification_url': verficationUrl, - 'first_name': user.first_name, - 'last_name': user.last_name - } - }; - var emailService = new pb.EmailService(); - emailService.sendFromTemplate(options, cb); + pb.SiteService.getByUid(this.site, function(err, siteInfo) { + var verficationUrl = pb.UrlService.urlJoin(siteInfo.hostname, '/actions/user/reset_password') + + util.format('?email=%s&code=%s', encodeURIComponent(user.email), encodeURIComponent(passwordReset.verification_code)); + var options = { + to: user.email, + subject: siteInfo.displayName + ' Password Reset', + template: 'admin/elements/password_reset_email', + replacements: { + 'verification_url': verficationUrl, + 'first_name': user.first_name, + 'last_name': user.last_name + } + }; + var emailService = new pb.EmailService(this.site); + emailService.sendFromTemplate(options, cb); + }); }; /** From 6d49145daf365069a80a5f2472a783da1fd040cd Mon Sep 17 00:00:00 2001 From: Christina Chatham Date: Wed, 20 May 2015 14:27:11 -0400 Subject: [PATCH 194/790] Stupid extra commas --- include/service/entities/user_service.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/service/entities/user_service.js b/include/service/entities/user_service.js index 01f3d8973..8ca0d5ce4 100755 --- a/include/service/entities/user_service.js +++ b/include/service/entities/user_service.js @@ -327,7 +327,7 @@ module.exports = function UserServiceModule(pb) { }, unverified_email: function(callback) { dao.count('unverified_user', getWhere({email: email.toLowerCase()}), callback); - }, + } }; async.series(tasks, cb); }; From bd3fa3e16172021e7286e6cf04fec0d71314d863 Mon Sep 17 00:00:00 2001 From: btidwell Date: Wed, 20 May 2015 14:50:42 -0400 Subject: [PATCH 195/790] create override for template service member of controller MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Template service must be created by the “site” member or the “pathSiteUId” based on admin controller or front end controller. --- controllers/admin/base_admin_controller.js | 10 +++++++++- controllers/base_controller.js | 10 +++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/controllers/admin/base_admin_controller.js b/controllers/admin/base_admin_controller.js index 9df6b7558..20be94cc5 100644 --- a/controllers/admin/base_admin_controller.js +++ b/controllers/admin/base_admin_controller.js @@ -37,6 +37,7 @@ module.exports = function BaseAdminControllerModule(pb) { */ BaseAdminController.prototype.init = function (props, cb) { var self = this; + self.pathSiteUId = pb.SiteService.getCurrentSite(props.path_vars.siteid); BaseController.prototype.init.call(self, props, function () { self.extendedInit(cb); }); @@ -44,7 +45,6 @@ module.exports = function BaseAdminControllerModule(pb) { BaseAdminController.prototype.extendedInit = function(cb) { var self = this; - self.pathSiteUId = pb.SiteService.getCurrentSite(self.pathVars.siteid); var siteService = new pb.SiteService(); siteService.getByUid(self.pathSiteUId, function (err, siteInfo) { if (err || !siteInfo) { @@ -62,6 +62,14 @@ module.exports = function BaseAdminControllerModule(pb) { }); }; + /** + * @method getTemplateService + * @return {Object} TemplateService + */ + BaseAdminController.prototype.getTemplateService = function() { + return new pb.TemplateService(this.localizationService, this.pathSiteUId); + }; + /** * Centralized place to obtain the pills to be displayed on top of the admin controller * diff --git a/controllers/base_controller.js b/controllers/base_controller.js index 73f57e347..7916300af 100755 --- a/controllers/base_controller.js +++ b/controllers/base_controller.js @@ -105,7 +105,7 @@ module.exports = function BaseControllerModule(pb) { this.site = props.site; var self = this; - this.templateService = new pb.TemplateService(this.localizationService, this.site); + this.templateService = this.getTemplateService(); this.templateService.registerLocal('locale', this.ls.language); this.templateService.registerLocal('error_success', function(flag, cb) { self.displayErrorOrSuccessCallback(flag, cb); @@ -141,6 +141,14 @@ module.exports = function BaseControllerModule(pb) { return true; }; + /** + * @method getTemplateService + * @return {Object} TemplateService + */ + BaseController.prototype.getTemplateService = function() { + return new pb.TemplateService(this.localizationService, this.site); + }; + /** * * @method requiresClientLocalizationCallback From c0fa2828df94c207a973900244a7446e7b2ede30 Mon Sep 17 00:00:00 2001 From: btidwell Date: Wed, 20 May 2015 14:51:50 -0400 Subject: [PATCH 196/790] Make page admin angular respect site on submit. --- .../templates/angular/admin/content/pages/page_form.html | 8 ++++---- .../templates/angular/admin/content/pages/page_form.html | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/plugins/pencilblue/templates/angular/admin/content/pages/page_form.html b/plugins/pencilblue/templates/angular/admin/content/pages/page_form.html index 4f50d3a61..fe3ba4412 100644 --- a/plugins/pencilblue/templates/angular/admin/content/pages/page_form.html +++ b/plugins/pencilblue/templates/angular/admin/content/pages/page_form.html @@ -43,7 +43,7 @@ $scope.getPageData(draft, function(pageData) { $scope.saving = true; if(pageData._id) { - $http.post('/actions/admin/content/pages/' + $scope.page._id, pageData) + $http.post('/actions/admin/'+ $scope.page.site +'/content/pages/' + $scope.page._id, pageData) .success(function(result) { $scope.successMessage = result.message; $scope.page.last_modified = result.data.last_modified; @@ -55,11 +55,11 @@ }); } else { - $http.post('/actions/admin/content/pages', pageData) + $http.post('/actions/admin/'+ $scope.page.site +'/content/pages', pageData) .success(function(result) { $scope.successMessage = result.message; $scope.saving = false; - $window.location = '/admin/content/pages/' + result.data._id.toString(); + $window.location = '/admin/'+ $result.data.page + 'content/pages/' + result.data._id.toString(); }) .error(function(error, status) { $scope.errorMessage = error.message; @@ -77,7 +77,7 @@ $scope.page.draft = true; $scope.getPageData(true, function(pageData) { $scope.saving = true; - $http.post('/actions/admin/content/pages/' + $scope.page._id, pageData) + $http.post('/actions/admin/'+ $scope.page.site +'/content/pages/' + $scope.page._id, pageData) .success(function(result) { $scope.page.last_modified = result.data.last_modified; $timeout($scope.savePageDraft, 30000); diff --git a/plugins/portfolio/templates/angular/admin/content/pages/page_form.html b/plugins/portfolio/templates/angular/admin/content/pages/page_form.html index 283df1b7a..2004c023b 100644 --- a/plugins/portfolio/templates/angular/admin/content/pages/page_form.html +++ b/plugins/portfolio/templates/angular/admin/content/pages/page_form.html @@ -42,7 +42,7 @@ $scope.getPageData(draft, function(pageData) { $scope.saving = true; if(pageData._id) { - $http.post('/actions/admin/content/pages/' + $scope.page._id, pageData) + $http.post('/actions/admin/'+ $scope.page.site +'/content/pages/' + $scope.page._id, pageData) .success(function(result) { $scope.successMessage = result.message; $scope.page.last_modified = result.data.last_modified; @@ -54,11 +54,11 @@ }); } else { - $http.post('/actions/admin/content/pages', pageData) + $http.post('/actions/admin/'+ $scope.page.site +'/content/pages', pageData) .success(function(result) { $scope.successMessage = result.message; $scope.saving = false; - $window.location = '/admin/content/pages/' + result.data._id.toString(); + $window.location = '/admin/'+ result.data.site +'/content/pages/' + result.data._id.toString(); }) .error(function(error, status) { $scope.errorMessage = error.message; @@ -76,7 +76,7 @@ $scope.page.draft = true; $scope.getPageData(true, function(pageData) { $scope.saving = true; - $http.post('/actions/admin/content/pages/' + $scope.page._id, pageData) + $http.post('/actions/admin/'+ $scope.page.site +'/content/pages/' + $scope.page._id, pageData) .success(function(result) { $scope.page.last_modified = result.data.last_modified; $timeout($scope.savePageDraft, 30000); From 3760322ad18f80cb1481888549f865ded57f3c06 Mon Sep 17 00:00:00 2001 From: Christina Chatham Date: Wed, 20 May 2015 15:02:56 -0400 Subject: [PATCH 197/790] Add undefined check for site id in getByUId --- include/service/entities/site_service.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/service/entities/site_service.js b/include/service/entities/site_service.js index 5e8faf9fb..ab82952d5 100644 --- a/include/service/entities/site_service.js +++ b/include/service/entities/site_service.js @@ -20,7 +20,7 @@ module.exports = function SiteServiceModule(pb) { var SITE_COLL = SiteService.SITE_COLLECTION; SiteService.prototype.getByUid = function(uid, cb) { - if(uid === SiteService.GLOBAL_SITE) { + if(!uid || uid === SiteService.GLOBAL_SITE) { cb(null, { displayName:pb.config.siteName, hostname: pb.config.siteRoot, From 5eee8611a39e2068ce50c2b37984bc34598e761a Mon Sep 17 00:00:00 2001 From: andparker Date: Thu, 21 May 2015 13:07:33 -0400 Subject: [PATCH 198/790] Updates these controllers to use site query service --- plugins/pencilblue/controllers/article.js | 11 +++++------ plugins/pencilblue/controllers/index.js | 9 +++++++++ plugins/pencilblue/controllers/page.js | 7 +++---- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/plugins/pencilblue/controllers/article.js b/plugins/pencilblue/controllers/article.js index b5abe6c1a..248f00a32 100755 --- a/plugins/pencilblue/controllers/article.js +++ b/plugins/pencilblue/controllers/article.js @@ -35,30 +35,29 @@ module.exports = function ArticleModule(pb) { //check for object ID as the custom URL var where = null; if(pb.validation.isIdStr(custUrl)) { - where = {_id: pb.DAO.getObjectID(custUrl), site: self.site}; + where = {_id: pb.DAO.getObjectID(custUrl)}; if (pb.log.isSilly()) { pb.log.silly("ArticleController: The custom URL was not an object ID [%s]. Will now search url field. [%s]", custUrl, e.message); } } else { - where = {url: custUrl, site: self.site}; + where = {url: custUrl}; } // fall through to URL key if (where === null) { - where = {url: custUrl, site: self.site}; + where = {url: custUrl}; } //attempt to load object - var dao = new pb.DAO(); - dao.loadByValues(where, 'article', function(err, article) { + self.siteQueryService.loadByValues(where, 'article', function(err, article) { if (util.isError(err) || article == null) { if (where.url) { self.reqHandler.serve404(); return; } - dao.loadByValues({url: custUrl, site: self.site}, 'article', function(err, article) { + self.siteQueryService.loadByValues({url: custUrl}, 'article', function(err, article) { if (util.isError(err) || article == null) { self.reqHandler.serve404(); return; diff --git a/plugins/pencilblue/controllers/index.js b/plugins/pencilblue/controllers/index.js index f1824467c..07571844f 100755 --- a/plugins/pencilblue/controllers/index.js +++ b/plugins/pencilblue/controllers/index.js @@ -33,6 +33,15 @@ module.exports = function IndexModule(pb) { function Index(){} util.inherits(Index, pb.BaseController); + Index.prototype.init = function (props, cb) { + var self = this; + + pb.BaseController.prototype.init.call(self, props, function () { + self.siteQueryService = new pb.SiteQueryService(self.site, true); + cb(); + }); + }; + Index.prototype.render = function(cb) { var self = this; diff --git a/plugins/pencilblue/controllers/page.js b/plugins/pencilblue/controllers/page.js index 3105fb47e..276189408 100755 --- a/plugins/pencilblue/controllers/page.js +++ b/plugins/pencilblue/controllers/page.js @@ -49,18 +49,17 @@ module.exports = function PageModule(pb) { } } else { - where = {url: custUrl, site: self.site}; + where = {url: custUrl}; } - var dao = new pb.DAO(); - dao.loadByValues(where, 'page', function(err, page) { + self.siteQueryService.loadByValues(where, 'page', function(err, page) { if (util.isError(err) || page == null) { if (where.url) { self.reqHandler.serve404(); return; } - dao.loadByValues({url: custUrl}, 'page', function(err, page) { + self.siteQueryService.loadByValues({url: custUrl}, 'page', function(err, page) { if (util.isError(err) || page == null) { self.reqHandler.serve404(); return; From c96e4eead1f1c9de76ff388b5c555633d7d4d2e6 Mon Sep 17 00:00:00 2001 From: Christina Chatham Date: Thu, 21 May 2015 13:09:23 -0400 Subject: [PATCH 199/790] Added routes needed for new user in Admin console. --- .../include/multisite_admin_routes.js | 33 ++++++++++++++- plugins/pencilblue/include/routes.js | 42 +++++++++---------- 2 files changed, 52 insertions(+), 23 deletions(-) diff --git a/plugins/pencilblue/include/multisite_admin_routes.js b/plugins/pencilblue/include/multisite_admin_routes.js index 2def89489..57cd8c735 100644 --- a/plugins/pencilblue/include/multisite_admin_routes.js +++ b/plugins/pencilblue/include/multisite_admin_routes.js @@ -199,7 +199,7 @@ module.exports = function Routes(pb){ path: "/actions/admin/:siteid/content/articles/:id", access_level: pb.SecurityService.ACCESS_EDITOR, auth_required: true, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'content', 'articles', 'delete_article.js'), + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'content', 'articles', 'delete_article.js') }, // PAGES @@ -600,12 +600,41 @@ module.exports = function Routes(pb){ controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'site_settings', 'libraries.js'), content_type: 'text/html' }, + //USERS { method: 'get', path: "/admin/:siteid/users/:id", auth_required: true, access_level: pb.SecurityService.ACCESS_EDITOR, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'users', 'user_form.js'), + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'users', 'user_form.js') + }, + { + method: 'get', + path: "/admin/:siteid/users/new", + auth_required: true, + access_level: pb.SecurityService.ACCESS_EDITOR, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'users', 'user_form.js') + }, + { + method: 'post', + path: "/actions/admin/:siteid/users", + auth_required: true, + access_level: pb.SecurityService.ACCESS_EDITOR, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'users', 'new_user.js') + }, + { + method: 'post', + path: "/actions/admin/:siteid/users/:id", + auth_required: true, + access_level: pb.SecurityService.ACCESS_EDITOR, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'users', 'edit_user.js') + }, + { + method: 'delete', + path: "/actions/admin/:siteid/users/:id", + auth_required: true, + access_level: pb.SecurityService.ACCESS_EDITOR, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'users', 'delete_user.js') } ]; }; diff --git a/plugins/pencilblue/include/routes.js b/plugins/pencilblue/include/routes.js index 93a08850f..4b473173e 100644 --- a/plugins/pencilblue/include/routes.js +++ b/plugins/pencilblue/include/routes.js @@ -122,7 +122,7 @@ module.exports = function Routes(pb){ method: 'post', path: "/actions/user/manage_account/change_password", auth_required: true, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'user', 'manage_account', 'change_password.js'), + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'user', 'manage_account', 'change_password.js') }, { method: 'post', @@ -135,19 +135,19 @@ module.exports = function Routes(pb){ method: 'post', path: "/actions/user/resend_verification", auth_required: false, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'user', 'resend_verification.js'), + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'user', 'resend_verification.js') }, { method: 'post', path: "/actions/user/sign_up", auth_required: false, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'user', 'sign_up.js'), + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'user', 'sign_up.js') }, { method: 'get', path: "/actions/user/verify_email", auth_required: false, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'user', 'verify_email.js'), + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'user', 'verify_email.js') }, { method: 'get', @@ -167,7 +167,7 @@ module.exports = function Routes(pb){ method: 'get', path: "/user/sign_up", auth_required: false, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'user', 'sign_up.js'), + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'user', 'sign_up.js') }, { method: 'get', @@ -181,7 +181,7 @@ module.exports = function Routes(pb){ handler: 'login', path: "/user/login", auth_required: false, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'user', 'login.js'), + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'user', 'login.js') }, { method: 'get', @@ -480,7 +480,7 @@ module.exports = function Routes(pb){ path: "/actions/admin/content/articles/:id", access_level: pb.SecurityService.ACCESS_EDITOR, auth_required: true, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'content', 'articles', 'delete_article.js'), + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'content', 'articles', 'delete_article.js') }, // PAGES @@ -829,7 +829,7 @@ module.exports = function Routes(pb){ path: "/actions/admin/themes/site_logo", auth_required: true, access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'themes', 'site_logo.js'), + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'themes', 'site_logo.js') }, // USERS @@ -838,70 +838,70 @@ module.exports = function Routes(pb){ path: "/admin/users", auth_required: true, access_level: pb.SecurityService.ACCESS_EDITOR, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'users', 'manage_users.js'), + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'users', 'manage_users.js') }, { method: 'get', path: "/admin/users/unverified", auth_required: true, access_level: pb.SecurityService.ACCESS_EDITOR, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'users', 'unverified_users.js'), + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'users', 'unverified_users.js') }, { method: 'get', path: "/admin/users/new", auth_required: true, access_level: pb.SecurityService.ACCESS_EDITOR, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'users', 'user_form.js'), + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'users', 'user_form.js') }, { method: 'get', path: "/admin/users/:id", auth_required: true, access_level: pb.SecurityService.ACCESS_EDITOR, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'users', 'user_form.js'), + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'users', 'user_form.js') }, { method: 'get', path: "/admin/users/password/:id", auth_required: true, access_level: pb.SecurityService.ACCESS_EDITOR, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'users', 'change_password.js'), + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'users', 'change_password.js') }, { method: 'post', path: "/actions/admin/users", auth_required: true, access_level: pb.SecurityService.ACCESS_EDITOR, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'users', 'new_user.js'), + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'users', 'new_user.js') }, { method: 'post', path: "/actions/admin/users/:id", auth_required: true, access_level: pb.SecurityService.ACCESS_EDITOR, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'users', 'edit_user.js'), + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'users', 'edit_user.js') }, { method: 'delete', path: "/actions/admin/users/:id", auth_required: true, access_level: pb.SecurityService.ACCESS_EDITOR, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'users', 'delete_user.js'), + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'users', 'delete_user.js') }, { method: 'delete', path: "/actions/admin/users/unverified/:id", auth_required: true, access_level: pb.SecurityService.ACCESS_EDITOR, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'users', 'delete_unverified_user.js'), + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'users', 'delete_unverified_user.js') }, { method: 'get', path: "/actions/admin/users/verify/:id", auth_required: true, access_level: pb.SecurityService.ACCESS_EDITOR, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'users', 'verify_user.js'), + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'users', 'verify_user.js') }, { @@ -909,21 +909,21 @@ module.exports = function Routes(pb){ path: "/actions/admin/users/change_password/:id", auth_required: true, access_level: pb.SecurityService.ACCESS_EDITOR, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'users', 'change_password.js'), + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'users', 'change_password.js') }, { method: 'get', path: "/actions/admin/users/send_password_reset/:id", auth_required: true, access_level: pb.SecurityService.ACCESS_MANAGING_EDITOR, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'users', 'send_password_reset.js'), + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'users', 'send_password_reset.js') }, { method: 'post', path: "/actions/admin/users/send_password_reset/:id", auth_required: true, access_level: pb.SecurityService.ACCESS_MANAGING_EDITOR, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'users', 'send_password_reset.js'), + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'users', 'send_password_reset.js') }, // SITE SETTINGS From 4a8e3bff45e14eda404c2f89e22b4a856ebbd3c5 Mon Sep 17 00:00:00 2001 From: Christina Chatham Date: Thu, 21 May 2015 15:28:29 -0400 Subject: [PATCH 200/790] New User create and save user with site id --- include/service/entities/user_service.js | 13 +++++++++++++ .../controllers/actions/admin/users/new_user.js | 11 ++++++++++- .../pencilblue/controllers/admin/users/user_form.js | 3 ++- .../pencilblue/include/multisite_admin_routes.js | 4 ++-- .../templates/angular/admin/users/user_form.html | 4 ++-- 5 files changed, 29 insertions(+), 6 deletions(-) diff --git a/include/service/entities/user_service.js b/include/service/entities/user_service.js index a329ad97e..5a0000d04 100755 --- a/include/service/entities/user_service.js +++ b/include/service/entities/user_service.js @@ -376,5 +376,18 @@ module.exports = function UserServiceModule(pb) { cb(err, count === 1); }); }; + + UserService.prototype.determineUserSiteScope = function(accessLevel, siteid) { + if (accessLevel === pb.SecurityService.ACCESS_MANAGING_EDITOR + || accessLevel === pb.SecurityService.ACCESS_ADMINISTRATOR) { + return pb.SiteService.GLOBAL_SITE; + } + else if (siteid === pb.SiteService.GLOBAL_SITE) { + return null; + } + else { + return siteid; + } + }; return UserService; }; diff --git a/plugins/pencilblue/controllers/actions/admin/users/new_user.js b/plugins/pencilblue/controllers/actions/admin/users/new_user.js index c05a5fd3d..b62362b5a 100755 --- a/plugins/pencilblue/controllers/actions/admin/users/new_user.js +++ b/plugins/pencilblue/controllers/actions/admin/users/new_user.js @@ -24,7 +24,7 @@ module.exports = function(pb) { * Creates a new user */ function NewUser(){} - util.inherits(NewUser, pb.BaseController); + util.inherits(NewUser, pb.BaseAdminController); NewUser.prototype.render = function(cb) { var self = this; @@ -47,6 +47,15 @@ module.exports = function(pb) { return; } + post.site = pb.users.determineUserSiteScope(post.admin, self.pathSiteUId); + if (!post.site) { + cb({ + code: 400, + content: pb.BaseController.apiResponse(pb.BaseController.API_ERROR, 'User access level not compatible with site scope') + }); + return; + } + var user = pb.DocumentCreator.create('user', post); pb.users.isUserNameOrEmailTaken(user.username, user.email, post.id, function(err, isTaken) { if(util.isError(err) || isTaken) { diff --git a/plugins/pencilblue/controllers/admin/users/user_form.js b/plugins/pencilblue/controllers/admin/users/user_form.js index 9b67621d2..33fe8d705 100644 --- a/plugins/pencilblue/controllers/admin/users/user_form.js +++ b/plugins/pencilblue/controllers/admin/users/user_form.js @@ -27,7 +27,7 @@ module.exports = function(pb) { * Interface for editing a user */ function UserForm(){} - util.inherits(UserForm, pb.BaseController); + util.inherits(UserForm, pb.BaseAdminController); //statics var SUB_NAV_KEY = 'user_form'; @@ -53,6 +53,7 @@ module.exports = function(pb) { data.adminOptions = pb.users.getAdminOptions(self.session, self.localizationService); } + data.sitePrefix = self.sitePrefix; var angularObjects = pb.ClientJs.getAngularObjects(data); self.setPageName(data.user[pb.DAO.getIdField()] ? data.user.username : self.ls.get('NEW_USER')); diff --git a/plugins/pencilblue/include/multisite_admin_routes.js b/plugins/pencilblue/include/multisite_admin_routes.js index 57cd8c735..72cf3f494 100644 --- a/plugins/pencilblue/include/multisite_admin_routes.js +++ b/plugins/pencilblue/include/multisite_admin_routes.js @@ -603,14 +603,14 @@ module.exports = function Routes(pb){ //USERS { method: 'get', - path: "/admin/:siteid/users/:id", + path: "/admin/:siteid/users/new", auth_required: true, access_level: pb.SecurityService.ACCESS_EDITOR, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'users', 'user_form.js') }, { method: 'get', - path: "/admin/:siteid/users/new", + path: "/admin/:siteid/users/:id", auth_required: true, access_level: pb.SecurityService.ACCESS_EDITOR, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'users', 'user_form.js') diff --git a/plugins/pencilblue/templates/angular/admin/users/user_form.html b/plugins/pencilblue/templates/angular/admin/users/user_form.html index 17f9892ae..577194bf4 100644 --- a/plugins/pencilblue/templates/angular/admin/users/user_form.html +++ b/plugins/pencilblue/templates/angular/admin/users/user_form.html @@ -69,7 +69,7 @@ $scope.user.photo = $scope.photoValue; } - var postURL = '/actions/admin/users'; + var postURL = '/actions/admin' + $scope.sitePrefix + '/users'; if($scope.user._id) { postURL += '/' + $scope.user._id; } @@ -80,7 +80,7 @@ $scope.saving = false; if(result.data._id) { - $window.location = '/admin/users/' + result.data._id; + $window.location = '/admin' + $scope.sitePrefix + '/users/' + result.data._id; } }) .error(function(error, status) { From c662bf32bfe9dad1e56b1a0c61291a8e4f2959d9 Mon Sep 17 00:00:00 2001 From: Christina Chatham Date: Thu, 21 May 2015 16:24:16 -0400 Subject: [PATCH 201/790] New User check for username in use now respects site. --- include/service/entities/user_service.js | 7 +++++-- .../pencilblue/controllers/actions/admin/users/new_user.js | 3 ++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/include/service/entities/user_service.js b/include/service/entities/user_service.js index 5a0000d04..86fa58011 100755 --- a/include/service/entities/user_service.js +++ b/include/service/entities/user_service.js @@ -29,7 +29,9 @@ module.exports = function UserServiceModule(pb) { * @class UserService * @constructor */ - function UserService(){} + function UserService(siteid){ + this.siteUID = pb.SiteService.getCurrentSite(siteid); + } /** * Gets the full name of a user @@ -306,7 +308,8 @@ module.exports = function UserServiceModule(pb) { } return where; }; - var dao = new pb.DAO(); + + var dao = new pb.SiteQueryService(this.siteUID, false); var tasks = { verified_username: function(callback) { var expStr = util.escapeRegExp(username) + '$'; diff --git a/plugins/pencilblue/controllers/actions/admin/users/new_user.js b/plugins/pencilblue/controllers/actions/admin/users/new_user.js index b62362b5a..912db970f 100755 --- a/plugins/pencilblue/controllers/actions/admin/users/new_user.js +++ b/plugins/pencilblue/controllers/actions/admin/users/new_user.js @@ -57,7 +57,8 @@ module.exports = function(pb) { } var user = pb.DocumentCreator.create('user', post); - pb.users.isUserNameOrEmailTaken(user.username, user.email, post.id, function(err, isTaken) { + var userService = new pb.UserService(self.pathSiteUId); + userService.isUserNameOrEmailTaken(user.username, user.email, post.id, function(err, isTaken) { if(util.isError(err) || isTaken) { cb({ code: 400, From 7be6feb4cdd6d248966b408bc022fc435eca9d50 Mon Sep 17 00:00:00 2001 From: Christina Chatham Date: Thu, 21 May 2015 16:44:15 -0400 Subject: [PATCH 202/790] Fix nav on user form to respoect site id --- include/service/admin/admin_subnav_service.js | 4 ++-- .../controllers/admin/users/user_form.js | 15 ++++++++++----- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/include/service/admin/admin_subnav_service.js b/include/service/admin/admin_subnav_service.js index c6e91b9bf..55220ed46 100755 --- a/include/service/admin/admin_subnav_service.js +++ b/include/service/admin/admin_subnav_service.js @@ -122,8 +122,8 @@ module.exports = function AdminSubnavServiceModule(pb) { if (items[j] && items[j].name === activePill) { items[j].active = 'active'; } - if(items[j].href && data && data.plugin && data.plugin.site) { - items[j].href = items[j].href.replace(':siteid', data.plugin.site); + if(items[j].href && data && (data.site || data.plugin && data.plugin.site)) { + items[j].href = items[j].href.replace(':siteid', data.site || data.plugin.site); } navItems.push(items[j]); } diff --git a/plugins/pencilblue/controllers/admin/users/user_form.js b/plugins/pencilblue/controllers/admin/users/user_form.js index 33fe8d705..88ddb4000 100644 --- a/plugins/pencilblue/controllers/admin/users/user_form.js +++ b/plugins/pencilblue/controllers/admin/users/user_form.js @@ -46,7 +46,12 @@ module.exports = function(pb) { } self.user = data.user; - data.pills = pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, SUB_NAV_KEY, {session: self.session, user: self.user}); + data.pills = pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, SUB_NAV_KEY, { + session: self.session, + user: self.user, + site: self.pathSiteUId, + sitePrefix: self.sitePrefix + }); data.adminOptions = [{name: self.ls.get('ADMINISTRATOR'), value: pb.SecurityService.ACCESS_ADMINISTRATOR}]; if(!data.user[pb.DAO.getIdField()] || self.session.authentication.user_id !== data.user[pb.DAO.getIdField()].toString()) { @@ -107,7 +112,7 @@ module.exports = function(pb) { name: 'manage_users', title: data.user[pb.DAO.getIdField()] ? ls.get('EDIT') + ' ' + data.user.username : ls.get('NEW_USER'), icon: 'chevron-left', - href: '/admin/users' + href: '/admin' + data.sitePrefix + '/users' }]; if(data.user[pb.DAO.getIdField()]) { @@ -116,7 +121,7 @@ module.exports = function(pb) { name: 'change_password', title: ls.get('CHANGE_PASSWORD'), icon: 'key', - href: '/admin/users/password/' + data.user[pb.DAO.getIdField()].toString() + href: '/admin' + data.sitePrefix + '/users/password/' + data.user[pb.DAO.getIdField()].toString() }); } else if(data.session.authentication.admin_level >= pb.SecurityService.ACCESS_MANAGING_EDITOR) { @@ -124,7 +129,7 @@ module.exports = function(pb) { name: 'reset_password', title: ls.get('RESET_PASSWORD'), icon: 'key', - href: '/actions/admin/users/send_password_reset/' + data.user[pb.DAO.getIdField()].toString() + href: '/actions/admin' + data.sitePrefix + '/users/send_password_reset/' + data.user[pb.DAO.getIdField()].toString() }); } } @@ -133,7 +138,7 @@ module.exports = function(pb) { name: 'new_user', title: '', icon: 'plus', - href: '/admin/users/new' + href: '/admin' + data.sitePrefix + '/users/new' }); return pills; From 9800879b9ddfc6c5b84d71304cfef94a91f1e85a Mon Sep 17 00:00:00 2001 From: Eugene Chang Date: Thu, 21 May 2015 16:56:34 -0400 Subject: [PATCH 203/790] Admin nav modification based on plugin --- include/admin_navigation.js | 60 +++++++++++++------ include/service/entities/plugin_service.js | 26 +++++--- .../jobs/plugins/plugin_uninstall_job.js | 9 ++- .../admin/plugins/manage_plugins.js | 2 +- plugins/sample/sample.js | 23 ++++--- 5 files changed, 82 insertions(+), 38 deletions(-) diff --git a/include/admin_navigation.js b/include/admin_navigation.js index 31236da8e..cfaaff02a 100755 --- a/include/admin_navigation.js +++ b/include/admin_navigation.js @@ -252,8 +252,8 @@ module.exports = function AdminNavigationModule(pb) { * @method getAdditions * @returns {Array} */ - function getAdditions() { - return util.clone(AdminNavigation.additions); + function getAdditions(site) { + return util.clone(AdminNavigation.additions[site] || []); }; /** @@ -263,8 +263,8 @@ module.exports = function AdminNavigationModule(pb) { * @method getChildrenAdditions * @returns {Object} */ - function getChildrenAdditions() { - return util.clone(AdminNavigation.childrenAdditions); + function getChildrenAdditions(site) { + return util.clone(AdminNavigation.childrenAdditions[site] || []); }; /** @@ -278,9 +278,14 @@ module.exports = function AdminNavigationModule(pb) { var i; var navigation = []; var multiSiteAdditions = getMultiSiteNavigation(); - var defaultNavigation = getDefaultNavigation(session ? session.adminSiteId : null); - var additions = getAdditions(); - var childrenAdditions = getChildrenAdditions(); + var adminSiteId = session && session.adminSiteId ? session.adminSiteId : pb.SiteService.GLOBAL_SITE; + var defaultNavigation = getDefaultNavigation(adminSiteId); + var additions = getAdditions(adminSiteId); + var childrenAdditions = getChildrenAdditions(adminSiteId); + if (!pb.SiteService.isGlobal(adminSiteId)) { + util.arrayPushAll(getAdditions(pb.SiteService.GLOBAL_SITE), additions); + util.merge(getChildrenAdditions(pb.SiteService.GLOBAL_SITE), childrenAdditions); + } util.arrayPushAll(defaultNavigation, navigation); util.arrayPushAll(additions, navigation); @@ -400,9 +405,10 @@ module.exports = function AdminNavigationModule(pb) { * @param {String} parentId * @param {Object} node * @returns {Boolean} + * @param site */ - AdminNavigation.addChild = function (parentId, node) { - if (isDuplicate(node.id)) { + AdminNavigation.addChildToSite = function (parentId, node, site) { + if (isDuplicate(node.id, buildNavigation(getSiteContext(site)))) { return false; } @@ -414,32 +420,52 @@ module.exports = function AdminNavigationModule(pb) { return true; }; + AdminNavigation.addChild = function (parentId, node) { + return AdminNavigation.addChildToSite(parentId, node, pb.SiteService.GLOBAL_SITE); + }; + + function getSiteContext(site) { + return {adminSiteId: site}; + } + /** * Adds a new top level node * @static * @method add * @param {Object} node * @returns {Boolean} + * @param site */ - AdminNavigation.add = function (node) { - if (isDuplicate(node.id)) { + AdminNavigation.addToSite = function (node, site) { + if (isDuplicate(node.id, buildNavigation(getSiteContext(site)))) { return false; } - AdminNavigation.additions.push(node); + if (!(site in AdminNavigation.additions)) { + AdminNavigation.additions[site] = []; + } + AdminNavigation.additions[site].push(node); return true; }; + AdminNavigation.add = function (node) { + return AdminNavigation.addToSite(node, pb.SiteService.GLOBAL_SITE); + }; + + AdminNavigation.remove = function (id) { + return AdminNavigation.removeFromSite(id, pb.SiteService.GLOBAL_SITE); + }; + /** * Remove a navigation node * @static * @method remove * @param id - * @param navigation * @returns {boolean} + * @param site */ - AdminNavigation.remove = function (id) { - if (!isDuplicate(id, buildNavigation())) { + AdminNavigation.removeFromSite = function (id, site) { + if (!isDuplicate(id, buildNavigation(getSiteContext(site)))) { return false; } @@ -463,10 +489,10 @@ module.exports = function AdminNavigationModule(pb) { return navigation; } - AdminNavigation.additions = removeNode(id, AdminNavigation.additions); + AdminNavigation.additions[site] = removeNode(id, AdminNavigation.additions[site]); for (var parentId in AdminNavigation.childrenAdditions) { - AdminNavigation.childrenAdditions[parentId] = removeNode(id, AdminNavigation.childrenAdditions[parentId]); + AdminNavigation.childrenAdditions[site][parentId] = removeNode(id, AdminNavigation.childrenAdditions[site][parentId]); } return true; diff --git a/include/service/entities/plugin_service.js b/include/service/entities/plugin_service.js index 9c5e2f4c5..0836e08af 100755 --- a/include/service/entities/plugin_service.js +++ b/include/service/entities/plugin_service.js @@ -1021,8 +1021,7 @@ module.exports = function PluginServiceModule(pb) { pb.log.debug('PluginService:[INIT] Attempting to call onStartup function for %s.', details.uid); var mainModule = ACTIVE_PLUGINS[site][details.uid].main_module; - if (util.isFunction(mainModule.onStartup)) { - + if (util.isFunction(mainModule.onStartupWithContext) || util.isFunction(mainModule.onStartup)) { var timeoutProtect = setTimeout(function() { // Clear the local timer variable, indicating the timeout has been triggered. @@ -1042,8 +1041,17 @@ module.exports = function PluginServiceModule(pb) { pb.log.error('PluginService:[INIT] Plugin %s failed to start. %s', details.uid, err.stack); } }); - d.run(function() { - mainModule.onStartup(function(err, didStart) { + d.run(function () { + if (util.isFunction(mainModule.prototype.onStartup)) { + mainModule = new mainModule(site); + } + if (util.isFunction(mainModule.onStartupWithContext)) { + var context = {site: site}; + mainModule.onStartupWithContext(context, startupCallback); + } else { + mainModule.onStartup(startupCallback); + } + function startupCallback(err, didStart) { if (util.isError(err)) { throw err; } @@ -1054,13 +1062,13 @@ module.exports = function PluginServiceModule(pb) { clearTimeout(timeoutProtect); callback(err, didStart); } - }); + } }); } - else { - pb.log.warn("PluginService: Plugin %s did not provide an 'onStartup' function.", details.uid); - callback(null, false); - } + else { + pb.log.warn("PluginService: Plugin %s did not provide an 'onStartup' function.", details.uid); + callback(null, false); + } }, //load services diff --git a/include/service/jobs/plugins/plugin_uninstall_job.js b/include/service/jobs/plugins/plugin_uninstall_job.js index 3e87752a4..74855f7ed 100644 --- a/include/service/jobs/plugins/plugin_uninstall_job.js +++ b/include/service/jobs/plugins/plugin_uninstall_job.js @@ -116,13 +116,18 @@ module.exports = function PluginUninstallJobModule(pb) { } var mm = pb.PluginService.getActiveMainModule(pluginUid, site); - if (util.isFunction(mm.onUninstall)) { + if (util.isFunction(mm.onUninstall) || util.isFunction(mm.onUninstallWithContext)) { self.log('Calling plugin onUnstall', pluginUid); var d = domain.create(); d.on('error', callback); d.run(function() { - mm.onUninstall(callback); + if (util.isFunction(mm.onUninstall)) { + mm.onUninstall(callback); + } else { + var context = {site: site}; + mm.onUninstallWithContext(context, callback); + } }); } else { diff --git a/plugins/pencilblue/controllers/admin/plugins/manage_plugins.js b/plugins/pencilblue/controllers/admin/plugins/manage_plugins.js index 9c9d81216..dc388a600 100755 --- a/plugins/pencilblue/controllers/admin/plugins/manage_plugins.js +++ b/plugins/pencilblue/controllers/admin/plugins/manage_plugins.js @@ -34,7 +34,7 @@ module.exports = function(pb) { ManagePlugins.prototype.render = function (cb) { var self = this; - var pluginService = new pb.PluginService(); + var pluginService = new pb.PluginService(self.pathSiteUId); pluginService.getPluginMap(function (err, map) { if (util.isError(err)) { self.reqHandler.serveError(err); diff --git a/plugins/sample/sample.js b/plugins/sample/sample.js index 239e670ff..1afda4da4 100755 --- a/plugins/sample/sample.js +++ b/plugins/sample/sample.js @@ -26,12 +26,15 @@ module.exports = function SamplePluginModule(pb) { * make every effort to clean up any plugin-specific DB items or any in function * overrides it makes. * + * @param context * @param cb A callback that must be called upon completion. cb(Error, Boolean). * The result should be TRUE on success and FALSE on failure */ - SamplePlugin.onUninstall = function(cb) { + SamplePlugin.onUninstallWithContext = function (context, cb) { + var site = pb.SiteService.getCurrentSite(context.site); + // Remove "sample" nav during uninstall - pb.AdminNavigation.remove("sample"); + pb.AdminNavigation.removeFromSite("sample", site); cb(null, true); }; @@ -40,17 +43,19 @@ module.exports = function SamplePluginModule(pb) { * the end of a successful install. It is guaranteed that all core PB services * will be available including access to the core DB. * + * @param context * @param cb A callback that must be called upon completion. cb(Error, Boolean). * The result should be TRUE on success and FALSE on failure */ - SamplePlugin.onStartup = function(cb) { + SamplePlugin.onStartupWithContext = function (context, cb) { /** * Administration Navigation sample */ + var site = pb.SiteService.getCurrentSite(context.site); // Add a new top level node - pb.AdminNavigation.add({ + pb.AdminNavigation.addToSite({ id: "sample", title: "Sample", icon: "cogs", @@ -65,25 +70,25 @@ module.exports = function SamplePluginModule(pb) { access: pb.SecurityService.ACCESS_USER } ] - }); + }, site); // Add a child to the top level node "sample" - pb.AdminNavigation.addChild("sample", { + pb.AdminNavigation.addChildToSite("sample", { id: "sample_2", title: "Sample Child 2", icon: "cog", href: "/admin/sample/2", access: pb.SecurityService.ACCESS_USER - }); + }, site); // Add a child to the top level node "sample" - pb.AdminNavigation.addChild("sample", { + pb.AdminNavigation.addChildToSite("sample", { id: "sample_3", title: "Redirect Home", icon: "cog", href: "/sample/redirect/home", access: pb.SecurityService.ACCESS_USER - }); + }, site); // Remove "sample_2" pb.AdminNavigation.remove("sample_2"); From 613604036185ffb772a9c44c5e709fcd32abcdfe Mon Sep 17 00:00:00 2001 From: Eugene Chang Date: Fri, 22 May 2015 08:41:44 -0400 Subject: [PATCH 204/790] Allow globally installed plugin to modify navigation for all site contexts --- include/admin_navigation.js | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/include/admin_navigation.js b/include/admin_navigation.js index cfaaff02a..e9855df73 100755 --- a/include/admin_navigation.js +++ b/include/admin_navigation.js @@ -22,6 +22,7 @@ module.exports = function AdminNavigationModule(pb) { //PB dependencies var SecurityService = pb.SecurityService; + var GLOBAL_SITE = pb.SiteService.GLOBAL_SITE; /** * Provides function to construct the structure needed to display the navigation @@ -219,7 +220,7 @@ module.exports = function AdminNavigationModule(pb) { id: 'library_settings', title: 'LIBRARIES', icon: 'book', - href: '/admin/'+ pb.SiteService.GLOBAL_SITE +'/site_settings/libraries', + href: '/admin/'+ GLOBAL_SITE +'/site_settings/libraries', access: SecurityService.ACCESS_ADMINISTRATOR } ] @@ -278,13 +279,13 @@ module.exports = function AdminNavigationModule(pb) { var i; var navigation = []; var multiSiteAdditions = getMultiSiteNavigation(); - var adminSiteId = session && session.adminSiteId ? session.adminSiteId : pb.SiteService.GLOBAL_SITE; + var adminSiteId = session && session.adminSiteId ? session.adminSiteId : GLOBAL_SITE; var defaultNavigation = getDefaultNavigation(adminSiteId); var additions = getAdditions(adminSiteId); var childrenAdditions = getChildrenAdditions(adminSiteId); if (!pb.SiteService.isGlobal(adminSiteId)) { - util.arrayPushAll(getAdditions(pb.SiteService.GLOBAL_SITE), additions); - util.merge(getChildrenAdditions(pb.SiteService.GLOBAL_SITE), childrenAdditions); + util.arrayPushAll(getAdditions(GLOBAL_SITE), additions); + util.merge(getChildrenAdditions(GLOBAL_SITE), childrenAdditions); } util.arrayPushAll(defaultNavigation, navigation); @@ -366,7 +367,13 @@ module.exports = function AdminNavigationModule(pb) { } } return false; - }; + } + + function exists(id, site) { + var isGlobal = pb.SiteService.isGlobal(site); + return isDuplicate(id, buildNavigation(getSiteContext(site))) || + (!isGlobal && isDuplicate(id, buildNavigation(getSiteContext(GLOBAL_SITE)))) + } /** * @private @@ -408,7 +415,7 @@ module.exports = function AdminNavigationModule(pb) { * @param site */ AdminNavigation.addChildToSite = function (parentId, node, site) { - if (isDuplicate(node.id, buildNavigation(getSiteContext(site)))) { + if (exists(node.id, site)) { return false; } @@ -421,7 +428,7 @@ module.exports = function AdminNavigationModule(pb) { }; AdminNavigation.addChild = function (parentId, node) { - return AdminNavigation.addChildToSite(parentId, node, pb.SiteService.GLOBAL_SITE); + return AdminNavigation.addChildToSite(parentId, node, GLOBAL_SITE); }; function getSiteContext(site) { @@ -437,7 +444,7 @@ module.exports = function AdminNavigationModule(pb) { * @param site */ AdminNavigation.addToSite = function (node, site) { - if (isDuplicate(node.id, buildNavigation(getSiteContext(site)))) { + if (exists(node.id, site)) { return false; } @@ -449,11 +456,11 @@ module.exports = function AdminNavigationModule(pb) { }; AdminNavigation.add = function (node) { - return AdminNavigation.addToSite(node, pb.SiteService.GLOBAL_SITE); + return AdminNavigation.addToSite(node, GLOBAL_SITE); }; AdminNavigation.remove = function (id) { - return AdminNavigation.removeFromSite(id, pb.SiteService.GLOBAL_SITE); + return AdminNavigation.removeFromSite(id, GLOBAL_SITE); }; /** From 66bbe2cfad1e3551bc8d63473286eaa42e4c2330 Mon Sep 17 00:00:00 2001 From: Eugene Chang Date: Fri, 22 May 2015 09:16:31 -0400 Subject: [PATCH 205/790] Fixing admin nav add/remove child --- include/admin_navigation.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/include/admin_navigation.js b/include/admin_navigation.js index e9855df73..a9571d4c2 100755 --- a/include/admin_navigation.js +++ b/include/admin_navigation.js @@ -419,11 +419,18 @@ module.exports = function AdminNavigationModule(pb) { return false; } - if (!AdminNavigation.childrenAdditions[parentId]) { - AdminNavigation.childrenAdditions[parentId] = []; + var additionsMap; + if (!(site in AdminNavigation.childrenAdditions)) { + additionsMap = AdminNavigation.childrenAdditions[site] = {} + } else { + additionsMap = AdminNavigation.childrenAdditions[site]; } - AdminNavigation.childrenAdditions[parentId].push(node); + if (!additionsMap[parentId]) { + additionsMap[parentId] = []; + } + + additionsMap[parentId].push(node); return true; }; @@ -498,8 +505,9 @@ module.exports = function AdminNavigationModule(pb) { AdminNavigation.additions[site] = removeNode(id, AdminNavigation.additions[site]); - for (var parentId in AdminNavigation.childrenAdditions) { - AdminNavigation.childrenAdditions[site][parentId] = removeNode(id, AdminNavigation.childrenAdditions[site][parentId]); + var childAdditionsMap = AdminNavigation.childrenAdditions[site]; + for (var parentId in childAdditionsMap) { + childAdditionsMap[parentId] = removeNode(id, childAdditionsMap[parentId]); } return true; From b5e96e48b454ffbbb515d0a890928c1ee8e6a324 Mon Sep 17 00:00:00 2001 From: Eugene Chang Date: Fri, 22 May 2015 10:04:21 -0400 Subject: [PATCH 206/790] Fixing remove child in sample plugin. Fixing themes checking in request handler. --- include/http/request_handler.js | 7 ++++++- plugins/sample/sample.js | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/include/http/request_handler.js b/include/http/request_handler.js index cd6347ca6..50af5b607 100755 --- a/include/http/request_handler.js +++ b/include/http/request_handler.js @@ -726,7 +726,12 @@ module.exports = function RequestHandlerModule(pb) { //check for themed route var themesToCheck = [activeTheme, RequestHandler.DEFAULT_THEME]; - util.arrayPushAll(Object.keys(route.themes), themesToCheck); + if (this.site in route.themes) { + util.arrayPushAll(Object.keys(route.themes[this.site]), themesToCheck); + } + if (!pb.SiteService.isGlobal(this.site) && (pb.SiteService.GLOBAL_SITE in route.themes)) { + util.arrayPushAll(Object.keys(route.themes[pb.SiteService.GLOBAL_SITE]), themesToCheck); + } for (var j = 0; j < themesToCheck.length; j++) { //see if theme supports method and provides support diff --git a/plugins/sample/sample.js b/plugins/sample/sample.js index 1afda4da4..b679a2d86 100755 --- a/plugins/sample/sample.js +++ b/plugins/sample/sample.js @@ -91,7 +91,7 @@ module.exports = function SamplePluginModule(pb) { }, site); // Remove "sample_2" - pb.AdminNavigation.remove("sample_2"); + pb.AdminNavigation.removeFromSite("sample_2", site); cb(null, true); }; From cefd814708f30db19f5b06127afae8e6032bbc8f Mon Sep 17 00:00:00 2001 From: Christina Chatham Date: Fri, 22 May 2015 10:47:19 -0400 Subject: [PATCH 207/790] Manage Users Site aware --- .../controllers/admin/users/manage_users.js | 12 ++++++------ .../controllers/admin/users/user_form.js | 14 ++++++++------ .../pencilblue/include/multisite_admin_routes.js | 7 +++++++ 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/plugins/pencilblue/controllers/admin/users/manage_users.js b/plugins/pencilblue/controllers/admin/users/manage_users.js index d62521396..bbc79d62f 100755 --- a/plugins/pencilblue/controllers/admin/users/manage_users.js +++ b/plugins/pencilblue/controllers/admin/users/manage_users.js @@ -24,7 +24,7 @@ module.exports = function(pb) { * Interface for managing users */ function ManageUsers(){} - util.inherits(ManageUsers, pb.BaseController); + util.inherits(ManageUsers, pb.BaseAdminController); //statics var SUB_NAV_KEY = 'manage_users'; @@ -38,7 +38,7 @@ module.exports = function(pb) { admin: {$lte: self.session.authentication.user.admin} } }; - var dao = new pb.DAO(); + var dao = new pb.SiteQueryService(self.pathSiteUId, true); dao.q('user', opts, function(err, users) { if(util.isError(err)) { return self.reqHandler.serveError(err); @@ -49,7 +49,7 @@ module.exports = function(pb) { var angularObjects = pb.ClientJs.getAngularObjects({ navigation: pb.AdminNavigation.get(self.session, ['users', 'manage'], self.ls), - pills: pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, SUB_NAV_KEY), + pills: pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, SUB_NAV_KEY, { sitePrefix: self.sitePrefix }), users: users, currentUserId: self.session.authentication.user_id }); @@ -67,17 +67,17 @@ module.exports = function(pb) { name: 'manage_users', title: ls.get('MANAGE_USERS'), icon: 'refresh', - href: '/admin/users' + href: '/admin' + data.sitePrefix + '/users' }, { name: 'unverified_users', title: ls.get('UNVERIFIED_USERS'), icon: 'user', - href: '/admin/users/unverified' + href: '/admin' + data.sitePrefix + '/users/unverified' }, { name: 'new_user', title: '', icon: 'plus', - href: '/admin/users/new' + href: '/admin' + data.sitePrefix + '/users/new' }]; }; diff --git a/plugins/pencilblue/controllers/admin/users/user_form.js b/plugins/pencilblue/controllers/admin/users/user_form.js index 88ddb4000..d282d8756 100644 --- a/plugins/pencilblue/controllers/admin/users/user_form.js +++ b/plugins/pencilblue/controllers/admin/users/user_form.js @@ -97,7 +97,7 @@ module.exports = function(pb) { return; } - var dao = new pb.DAO(); + var dao = new pb.SiteQueryService(self.pathSiteUId, true); dao.loadById(vars.id, 'user', function(err, user) { delete user.password; callback(err, user); @@ -108,20 +108,22 @@ module.exports = function(pb) { }; UserForm.getSubNavItems = function(key, ls, data) { + var idField = pb.DAO.getIdField(); var pills = [{ name: 'manage_users', - title: data.user[pb.DAO.getIdField()] ? ls.get('EDIT') + ' ' + data.user.username : ls.get('NEW_USER'), + title: data.user[idField] ? ls.get('EDIT') + ' ' + data.user.username : ls.get('NEW_USER'), icon: 'chevron-left', href: '/admin' + data.sitePrefix + '/users' }]; - if(data.user[pb.DAO.getIdField()]) { - if(data.session.authentication.user_id === data.user[pb.DAO.getIdField()].toString()) { + if(data.user[idField]) { + var userIdString = data.user[idField].toString(); + if(data.session.authentication.user_id === userIdString) { pills.push({ name: 'change_password', title: ls.get('CHANGE_PASSWORD'), icon: 'key', - href: '/admin' + data.sitePrefix + '/users/password/' + data.user[pb.DAO.getIdField()].toString() + href: '/admin' + data.sitePrefix + '/users/password/' + userIdString }); } else if(data.session.authentication.admin_level >= pb.SecurityService.ACCESS_MANAGING_EDITOR) { @@ -129,7 +131,7 @@ module.exports = function(pb) { name: 'reset_password', title: ls.get('RESET_PASSWORD'), icon: 'key', - href: '/actions/admin' + data.sitePrefix + '/users/send_password_reset/' + data.user[pb.DAO.getIdField()].toString() + href: '/actions/admin' + data.sitePrefix + '/users/send_password_reset/' + userIdString }); } } diff --git a/plugins/pencilblue/include/multisite_admin_routes.js b/plugins/pencilblue/include/multisite_admin_routes.js index 72cf3f494..0be07a8ed 100644 --- a/plugins/pencilblue/include/multisite_admin_routes.js +++ b/plugins/pencilblue/include/multisite_admin_routes.js @@ -601,6 +601,13 @@ module.exports = function Routes(pb){ content_type: 'text/html' }, //USERS + { + method: 'get', + path: "/admin/:siteid/users", + auth_required: true, + access_level: pb.SecurityService.ACCESS_EDITOR, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'users', 'manage_users.js') + }, { method: 'get', path: "/admin/:siteid/users/new", From ce4fbe1214e1f764640d27f75e456579f794bcc4 Mon Sep 17 00:00:00 2001 From: Christina Chatham Date: Fri, 22 May 2015 10:59:36 -0400 Subject: [PATCH 208/790] Unverified user view site aware --- .../controllers/admin/users/unverified_users.js | 10 +++++----- plugins/pencilblue/include/multisite_admin_routes.js | 7 +++++++ 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/plugins/pencilblue/controllers/admin/users/unverified_users.js b/plugins/pencilblue/controllers/admin/users/unverified_users.js index 024cc44bf..a181e83e8 100644 --- a/plugins/pencilblue/controllers/admin/users/unverified_users.js +++ b/plugins/pencilblue/controllers/admin/users/unverified_users.js @@ -24,7 +24,7 @@ module.exports = function(pb) { * Interface for managing unverified users */ function UnverifiedUsers(){} - util.inherits(UnverifiedUsers, pb.BaseController); + util.inherits(UnverifiedUsers, pb.BaseAdminController); //statics var SUB_NAV_KEY = 'unverified_users'; @@ -35,7 +35,7 @@ module.exports = function(pb) { var opts = { where: pb.DAO.ANYWHERE }; - var dao = new pb.DAO(); + var dao = new pb.SiteQueryService(self.pathSiteUId, true); dao.q('unverified_user', opts, function(err, users) { if(util.isError(err)) { return self.redirect('/admin', cb); @@ -44,7 +44,7 @@ module.exports = function(pb) { var angularObjects = pb.ClientJs.getAngularObjects( { navigation: pb.AdminNavigation.get(self.session, ['users', 'manage'], self.ls), - pills: pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, SUB_NAV_KEY), + pills: pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, SUB_NAV_KEY, { sitePrefix: self.sitePrefix }), users: users }); @@ -61,12 +61,12 @@ module.exports = function(pb) { name: SUB_NAV_KEY, title: ls.get('UNVERIFIED_USERS'), icon: 'chevron-left', - href: '/admin/users' + href: '/admin' + data.sitePrefix + '/users' }, { name: 'new_user', title: '', icon: 'plus', - href: '/admin/users/new' + href: '/admin' + data.sitePrefix + '/users/new' }]; }; diff --git a/plugins/pencilblue/include/multisite_admin_routes.js b/plugins/pencilblue/include/multisite_admin_routes.js index 0be07a8ed..bc95917cc 100644 --- a/plugins/pencilblue/include/multisite_admin_routes.js +++ b/plugins/pencilblue/include/multisite_admin_routes.js @@ -608,6 +608,13 @@ module.exports = function Routes(pb){ access_level: pb.SecurityService.ACCESS_EDITOR, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'users', 'manage_users.js') }, + { + method: 'get', + path: "/admin/:siteid/users/unverified", + auth_required: true, + access_level: pb.SecurityService.ACCESS_EDITOR, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'users', 'unverified_users.js') + }, { method: 'get', path: "/admin/:siteid/users/new", From 005762e7b7c2f6680122a0a1c9cadd371f16af87 Mon Sep 17 00:00:00 2001 From: Christina Chatham Date: Fri, 22 May 2015 11:04:20 -0400 Subject: [PATCH 209/790] Forgot the angular link for viewing users on manage_users. --- plugins/pencilblue/controllers/admin/users/manage_users.js | 3 ++- plugins/pencilblue/templates/admin/users/manage_users.html | 2 +- .../pencilblue/templates/angular/admin/users/manage_users.html | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/plugins/pencilblue/controllers/admin/users/manage_users.js b/plugins/pencilblue/controllers/admin/users/manage_users.js index bbc79d62f..a7a12c9de 100755 --- a/plugins/pencilblue/controllers/admin/users/manage_users.js +++ b/plugins/pencilblue/controllers/admin/users/manage_users.js @@ -51,7 +51,8 @@ module.exports = function(pb) { navigation: pb.AdminNavigation.get(self.session, ['users', 'manage'], self.ls), pills: pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, SUB_NAV_KEY, { sitePrefix: self.sitePrefix }), users: users, - currentUserId: self.session.authentication.user_id + currentUserId: self.session.authentication.user_id, + sitePrefix: self.sitePrefix }); self.setPageName(self.ls.get('MANAGE_USERS')); diff --git a/plugins/pencilblue/templates/admin/users/manage_users.html b/plugins/pencilblue/templates/admin/users/manage_users.html index 600f88312..bc36f71b9 100755 --- a/plugins/pencilblue/templates/admin/users/manage_users.html +++ b/plugins/pencilblue/templates/admin/users/manage_users.html @@ -7,7 +7,7 @@ ^tmp_admin=elements=table_headers^ - + diff --git a/plugins/pencilblue/templates/angular/admin/users/manage_users.html b/plugins/pencilblue/templates/angular/admin/users/manage_users.html index 8b48bdb5c..f4ab0711c 100644 --- a/plugins/pencilblue/templates/angular/admin/users/manage_users.html +++ b/plugins/pencilblue/templates/angular/admin/users/manage_users.html @@ -77,7 +77,7 @@ } $scope.deleting = true; - $http({method: 'DELETE', url: '/actions/admin/users/' + $scope.objectToDelete._id}) + $http({method: 'DELETE', url: '/actions/admin' + $scope.sitePrefix + '/users/' + $scope.objectToDelete._id}) .success(function(result) { for(var i = 0; i < $scope.users.length; i ++) { if($scope.users[i]._id.toString() === $scope.objectToDelete._id.toString()) { From bb33af11524c87778706232e9c834ba1a7ca752c Mon Sep 17 00:00:00 2001 From: Eugene Chang Date: Fri, 22 May 2015 11:18:56 -0400 Subject: [PATCH 210/790] Fixing services loaded by Sample plugin --- plugins/sample/controllers/api/text_api.js | 6 +----- plugins/sample/controllers/random_text_view.js | 2 +- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/plugins/sample/controllers/api/text_api.js b/plugins/sample/controllers/api/text_api.js index 21590c859..b28e08ae8 100644 --- a/plugins/sample/controllers/api/text_api.js +++ b/plugins/sample/controllers/api/text_api.js @@ -20,7 +20,6 @@ module.exports = function TextApiControllerModule(pb) { //PB dependencies var util = pb.util; var PluginService = pb.PluginService; - var TextService = PluginService.getService('textService', 'sample'); /** * TextApiController - A sample controller to demonstrate how to build an API @@ -41,6 +40,7 @@ module.exports = function TextApiControllerModule(pb) { TextApiController.prototype.getRandomText = function(cb) { var self = this; + var TextService = PluginService.getService('textService', 'sample', self.site); var service = new TextService(); var text = service.getText(); var dataStr = pb.BaseController.apiResponse(pb.BaseController.API_SUCCESS, '', text); @@ -137,28 +137,24 @@ module.exports = function TextApiControllerModule(pb) { { method: 'get', path: "/api/sample/random/text", - handler: "getText", content_type: 'application/json', handler: "getRandomText" }, { method: 'get', path: "/api/sample/text/length/:text", - handler: "getText", content_type: 'application/json', handler: "getTextLengthByPathParam" }, { method: 'get', path: "/api/sample/text/length", - handler: "getText", content_type: 'application/json', handler: "getTextLengthByQueryParam" }, { method: 'post', path: "/api/sample/text/length", - handler: "getText", content_type: 'application/json', handler: "getTextLengthByPostParam", request_body: ['application/json', 'application/x-www-form-urlencoded', 'multipart/form-data'] diff --git a/plugins/sample/controllers/random_text_view.js b/plugins/sample/controllers/random_text_view.js index 450800146..c088255e1 100755 --- a/plugins/sample/controllers/random_text_view.js +++ b/plugins/sample/controllers/random_text_view.js @@ -24,7 +24,6 @@ module.exports = function RandomTextViewControllerModule(pb) { var util = pb.util; var PluginService = pb.PluginService; var TopMenuService = pb.TopMenuService; - var TextService = PluginService.getService('textService', 'sample'); /** * RandomTextViewController - A sample controller to show how to register a controller and @@ -65,6 +64,7 @@ module.exports = function RandomTextViewControllerModule(pb) { //Create an instance of the text service. Then we call the service for //random text + var TextService = PluginService.getService('textService', 'sample', self.site); var textService = new TextService(); var text = textService.getText(); From b9c2ee425a9fd7f5751c2808bca9f86b1a2ef165 Mon Sep 17 00:00:00 2001 From: Christina Chatham Date: Fri, 22 May 2015 14:19:43 -0400 Subject: [PATCH 211/790] change password obey site --- .../actions/admin/users/change_password.js | 8 ++-- .../admin/users/change_password.js | 10 +++-- .../include/multisite_admin_routes.js | 43 +++++++++++++++++++ .../angular/admin/users/change_password.html | 2 +- 4 files changed, 55 insertions(+), 8 deletions(-) diff --git a/plugins/pencilblue/controllers/actions/admin/users/change_password.js b/plugins/pencilblue/controllers/actions/admin/users/change_password.js index 8abd43061..77f677491 100755 --- a/plugins/pencilblue/controllers/actions/admin/users/change_password.js +++ b/plugins/pencilblue/controllers/actions/admin/users/change_password.js @@ -19,13 +19,13 @@ module.exports = function ChangePasswordModule(pb) { //pb dependencies var util = pb.util; - var BaseController = pb.BaseController; + var BaseAdminController = pb.BaseAdminController; /** * Changes a user's password */ function ChangePassword(){} - util.inherits(ChangePassword, BaseController); + util.inherits(ChangePassword, BaseAdminController); ChangePassword.prototype.render = function(cb) { var self = this; @@ -57,9 +57,10 @@ module.exports = function ChangePasswordModule(pb) { return; } - var dao = new pb.DAO(); + var dao = new pb.SiteQueryService(self.pathSiteUId, true); dao.loadById(vars.id, 'user', function(err, user) { if(util.isError(err) || user === null) { + pb.log.error(JSON.stringify(err)); cb({ code: 400, content: pb.BaseController.apiResponse(pb.BaseController.API_ERROR, self.ls.get('INVALID_UID')) @@ -82,6 +83,7 @@ module.exports = function ChangePasswordModule(pb) { dao.save(user, function(err, result) { if(util.isError(err)) { + pb.log.error(JSON.stringify(err)); return cb({ code: 500, content: pb.BaseController.apiResponse(pb.BaseController.API_ERROR, self.ls.get('ERROR_SAVING')) diff --git a/plugins/pencilblue/controllers/admin/users/change_password.js b/plugins/pencilblue/controllers/admin/users/change_password.js index 234a4f7ec..bb516ac9d 100755 --- a/plugins/pencilblue/controllers/admin/users/change_password.js +++ b/plugins/pencilblue/controllers/admin/users/change_password.js @@ -27,7 +27,7 @@ module.exports = function AdminChangePasswordControllerModule(pb) { * @extends BaseController */ function AdminChangePasswordController(){} - util.inherits(AdminChangePasswordController, pb.BaseController); + util.inherits(AdminChangePasswordController, pb.BaseAdminController); //statics var SUB_NAV_KEY = 'change_password'; @@ -44,7 +44,7 @@ module.exports = function AdminChangePasswordControllerModule(pb) { return; } - var dao = new pb.DAO(); + var dao = new pb.SiteQueryService(self.pathSiteUId, true); dao.loadById(vars.id, 'user', function(err, user) { if(util.isError(err) || user === null) { self.redirect('/admin/users', cb); @@ -64,7 +64,8 @@ module.exports = function AdminChangePasswordControllerModule(pb) { pills: pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, SUB_NAV_KEY, user), tabs: tabs, adminOptions: pb.users.getAdminOptions(self.session, self.localizationService), - user: user + user: user, + sitePrefix: self.sitePrefix }); delete user.password; @@ -77,12 +78,13 @@ module.exports = function AdminChangePasswordControllerModule(pb) { }; AdminChangePasswordController.getSubNavItems = function(key, ls, data) { + var sitePrefix = pb.SiteService.getCurrentSitePrefix(pb.SiteService.getCurrentSite(data.site)); return [ { name: SUB_NAV_KEY, title: ls.get('CHANGE_PASSWORD'), icon: 'chevron-left', - href: pb.UrlService.urlJoin('/admin/users/', + encodeURIComponent(data[pb.DAO.getIdField()])) + href: pb.UrlService.urlJoin('/admin' + sitePrefix + '/users/', encodeURIComponent(data[pb.DAO.getIdField()])) } ]; }; diff --git a/plugins/pencilblue/include/multisite_admin_routes.js b/plugins/pencilblue/include/multisite_admin_routes.js index bc95917cc..426fcffdc 100644 --- a/plugins/pencilblue/include/multisite_admin_routes.js +++ b/plugins/pencilblue/include/multisite_admin_routes.js @@ -629,6 +629,13 @@ module.exports = function Routes(pb){ access_level: pb.SecurityService.ACCESS_EDITOR, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'users', 'user_form.js') }, + { + method: 'get', + path: "/admin/:siteid/users/password/:id", + auth_required: true, + access_level: pb.SecurityService.ACCESS_EDITOR, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'users', 'change_password.js') + }, { method: 'post', path: "/actions/admin/:siteid/users", @@ -649,6 +656,42 @@ module.exports = function Routes(pb){ auth_required: true, access_level: pb.SecurityService.ACCESS_EDITOR, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'users', 'delete_user.js') + }, + { + method: 'delete', + path: "/actions/admin/:siteid/users/unverified/:id", + auth_required: true, + access_level: pb.SecurityService.ACCESS_EDITOR, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'users', 'delete_unverified_user.js') + }, + { + method: 'get', + path: "/actions/admin/:siteid/users/verify/:id", + auth_required: true, + access_level: pb.SecurityService.ACCESS_EDITOR, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'users', 'verify_user.js') + }, + + { + method: 'post', + path: "/actions/admin/:siteid/users/change_password/:id", + auth_required: true, + access_level: pb.SecurityService.ACCESS_EDITOR, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'users', 'change_password.js') + }, + { + method: 'get', + path: "/actions/admin/:siteid/users/send_password_reset/:id", + auth_required: true, + access_level: pb.SecurityService.ACCESS_MANAGING_EDITOR, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'users', 'send_password_reset.js') + }, + { + method: 'post', + path: "/actions/admin/:siteid/users/send_password_reset/:id", + auth_required: true, + access_level: pb.SecurityService.ACCESS_MANAGING_EDITOR, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'users', 'send_password_reset.js') } ]; }; diff --git a/plugins/pencilblue/templates/angular/admin/users/change_password.html b/plugins/pencilblue/templates/angular/admin/users/change_password.html index 15963eb48..6c1072885 100644 --- a/plugins/pencilblue/templates/angular/admin/users/change_password.html +++ b/plugins/pencilblue/templates/angular/admin/users/change_password.html @@ -36,7 +36,7 @@ $scope.saving = true; - $http.post('/actions/admin/users/change_password/' + $scope.user._id, $scope.userPassword) + $http.post('/actions/admin' + $scope.sitePrefix + '/users/change_password/' + $scope.user._id, $scope.userPassword) .success(function(result) { $scope.successMessage = result.message; $scope.saving = false; From 93bed402c1b2cba3e4b1d4e10adfbd79e1075965 Mon Sep 17 00:00:00 2001 From: Christina Chatham Date: Fri, 22 May 2015 14:36:08 -0400 Subject: [PATCH 212/790] Fixing Users on the Admin Nav. --- include/admin_navigation.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/admin_navigation.js b/include/admin_navigation.js index 31236da8e..e43a8b80a 100755 --- a/include/admin_navigation.js +++ b/include/admin_navigation.js @@ -175,14 +175,14 @@ module.exports = function AdminNavigationModule(pb) { id: 'manage', title: 'MANAGE', icon: 'users', - href: '/admin/users', + href: adminPath + '/users', access: SecurityService.ACCESS_EDITOR }, { id: 'permissions', title: 'PERMISSIONS', icon: 'lock', - href: '/admin/users/permissions', + href: adminPath + '/users/permissions', access: SecurityService.ACCESS_ADMINISTRATOR }, ] From 6ed71a8f55c87e97e1bfc4db7aca9b9e01bae09e Mon Sep 17 00:00:00 2001 From: Christina Chatham Date: Fri, 22 May 2015 14:45:19 -0400 Subject: [PATCH 213/790] adding some error logging. --- .../controllers/actions/admin/users/change_password.js | 4 ++-- .../controllers/actions/admin/users/edit_user.js | 9 ++++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/plugins/pencilblue/controllers/actions/admin/users/change_password.js b/plugins/pencilblue/controllers/actions/admin/users/change_password.js index 77f677491..6621f9843 100755 --- a/plugins/pencilblue/controllers/actions/admin/users/change_password.js +++ b/plugins/pencilblue/controllers/actions/admin/users/change_password.js @@ -60,7 +60,7 @@ module.exports = function ChangePasswordModule(pb) { var dao = new pb.SiteQueryService(self.pathSiteUId, true); dao.loadById(vars.id, 'user', function(err, user) { if(util.isError(err) || user === null) { - pb.log.error(JSON.stringify(err)); + if (err) { pb.log.error(JSON.stringify(err)); } cb({ code: 400, content: pb.BaseController.apiResponse(pb.BaseController.API_ERROR, self.ls.get('INVALID_UID')) @@ -83,7 +83,7 @@ module.exports = function ChangePasswordModule(pb) { dao.save(user, function(err, result) { if(util.isError(err)) { - pb.log.error(JSON.stringify(err)); + if (err) { pb.log.error(JSON.stringify(err)); } return cb({ code: 500, content: pb.BaseController.apiResponse(pb.BaseController.API_ERROR, self.ls.get('ERROR_SAVING')) diff --git a/plugins/pencilblue/controllers/actions/admin/users/edit_user.js b/plugins/pencilblue/controllers/actions/admin/users/edit_user.js index 08bb45d7c..c938b66d9 100755 --- a/plugins/pencilblue/controllers/actions/admin/users/edit_user.js +++ b/plugins/pencilblue/controllers/actions/admin/users/edit_user.js @@ -24,7 +24,7 @@ module.exports = function(pb) { * Edits a user */ function EditUser(){} - util.inherits(EditUser, pb.BaseController); + util.inherits(EditUser, pb.BaseAdminController); EditUser.prototype.render = function(cb) { var self = this; @@ -48,9 +48,10 @@ module.exports = function(pb) { return; } - var dao = new pb.DAO(); + var dao = new pb.SiteQueryService(self.pathSiteUId, true); dao.loadById(vars.id, 'user', function(err, user) { if(util.isError(err) || user === null) { + if (err) { pb.log.error(JSON.stringify(err)); } cb({ code: 400, content: pb.BaseController.apiResponse(pb.BaseController.API_ERROR, self.ls.get('INVALID_UID')) @@ -61,8 +62,10 @@ module.exports = function(pb) { delete post[pb.DAO.getIdField()]; pb.DocumentCreator.update(post, user); - pb.users.isUserNameOrEmailTaken(user.username, user.email, vars.id, function(err, isTaken) { + var userService = new UserService(self.pathSiteUId); + userService.isUserNameOrEmailTaken(user.username, user.email, vars.id, function(err, isTaken) { if(util.isError(err) || isTaken) { + if(err) { pb.log.error(JSON.stringify(err)); } cb({ code: 400, content: pb.BaseController.apiResponse(pb.BaseController.API_ERROR, self.ls.get('EXISTING_USERNAME')) From 562965b1c45f004e59b3b73ed9addbcd49ee6afd Mon Sep 17 00:00:00 2001 From: Christina Chatham Date: Fri, 22 May 2015 14:51:18 -0400 Subject: [PATCH 214/790] Changing setup.js to be site aware. --- plugins/pencilblue/controllers/actions/setup.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/pencilblue/controllers/actions/setup.js b/plugins/pencilblue/controllers/actions/setup.js index 8b30f7dde..33b5ac0c7 100755 --- a/plugins/pencilblue/controllers/actions/setup.js +++ b/plugins/pencilblue/controllers/actions/setup.js @@ -120,7 +120,7 @@ module.exports = function SetupActionControllerModule(pb) { function(callback) { var userDocument = pb.DocumentCreator.create('user', post); - var dao = new pb.DAO(); + var dao = new pb.SiteQueryService(pb.SiteService.GLOBAL_SITE); dao.save(userDocument, callback); }, function(callback) { From 456d0c76b5a286508df7741e128575186c305e38 Mon Sep 17 00:00:00 2001 From: Eugene Chang Date: Fri, 22 May 2015 15:08:23 -0400 Subject: [PATCH 215/790] User in admin panel only has access to the sites they are limited to, logging into admin automatically redirects to the site they have access to, unless they have access to all. --- controllers/admin/base_admin_controller.js | 5 +++++ include/service/entities/site_service.js | 4 ++++ plugins/pencilblue/controllers/actions/login.js | 4 ++++ plugins/pencilblue/controllers/admin/users/manage_users.js | 3 --- 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/controllers/admin/base_admin_controller.js b/controllers/admin/base_admin_controller.js index 20be94cc5..625f83437 100644 --- a/controllers/admin/base_admin_controller.js +++ b/controllers/admin/base_admin_controller.js @@ -45,6 +45,11 @@ module.exports = function BaseAdminControllerModule(pb) { BaseAdminController.prototype.extendedInit = function(cb) { var self = this; + var userSite = pb.SiteService.getSiteFromObject(self.session.authentication.user); + if (!pb.SiteService.isGlobal(userSite) && !pb.SiteService.areEqual(userSite, self.pathSiteUId)) { + self.reqHandler.serve404(); // TODO should we serve 403 here? + return; + } var siteService = new pb.SiteService(); siteService.getByUid(self.pathSiteUId, function (err, siteInfo) { if (err || !siteInfo) { diff --git a/include/service/entities/site_service.js b/include/service/entities/site_service.js index a9ed16960..76455992a 100644 --- a/include/service/entities/site_service.js +++ b/include/service/entities/site_service.js @@ -354,5 +354,9 @@ module.exports = function SiteServiceModule(pb) { } }; + SiteService.getSiteFromObject = function (object) { + return object[SiteService.SITE_FIELD]; + }; + return SiteService; }; diff --git a/plugins/pencilblue/controllers/actions/login.js b/plugins/pencilblue/controllers/actions/login.js index 86f894fae..c59c72fd9 100755 --- a/plugins/pencilblue/controllers/actions/login.js +++ b/plugins/pencilblue/controllers/actions/login.js @@ -57,6 +57,10 @@ module.exports = function LoginActionControllerModule(pb) { } else if(adminAttempt) { location = '/admin'; + var site = pb.SiteService.getSiteFromObject(user); + if (!pb.SiteService.isNotSetOrEqual(site, self.site)) { + location += '/' + site; + } } self.redirect(location, cb); }); diff --git a/plugins/pencilblue/controllers/admin/users/manage_users.js b/plugins/pencilblue/controllers/admin/users/manage_users.js index a7a12c9de..cc366d6df 100755 --- a/plugins/pencilblue/controllers/admin/users/manage_users.js +++ b/plugins/pencilblue/controllers/admin/users/manage_users.js @@ -43,9 +43,6 @@ module.exports = function(pb) { if(util.isError(err)) { return self.reqHandler.serveError(err); } - else if (users.length === 0) { - return self.redirect('/admin', cb); - } var angularObjects = pb.ClientJs.getAngularObjects({ navigation: pb.AdminNavigation.get(self.session, ['users', 'manage'], self.ls), From 80b2288c2beaf841cee3c22d329192d0af8c6097 Mon Sep 17 00:00:00 2001 From: Eugene Chang Date: Tue, 26 May 2015 09:25:15 -0400 Subject: [PATCH 216/790] Fixing id collision when sample plugin is installed both in global and specific site --- include/admin_navigation.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/include/admin_navigation.js b/include/admin_navigation.js index a9571d4c2..c1b4f1c61 100755 --- a/include/admin_navigation.js +++ b/include/admin_navigation.js @@ -22,6 +22,7 @@ module.exports = function AdminNavigationModule(pb) { //PB dependencies var SecurityService = pb.SecurityService; + var _ = require('lodash'); var GLOBAL_SITE = pb.SiteService.GLOBAL_SITE; /** @@ -42,7 +43,7 @@ module.exports = function AdminNavigationModule(pb) { * @property additions * @type {Array} */ - AdminNavigation.additions = []; + AdminNavigation.additions = {}; /** * @@ -285,6 +286,7 @@ module.exports = function AdminNavigationModule(pb) { var childrenAdditions = getChildrenAdditions(adminSiteId); if (!pb.SiteService.isGlobal(adminSiteId)) { util.arrayPushAll(getAdditions(GLOBAL_SITE), additions); + additions = _.uniq(additions, 'id'); util.merge(getChildrenAdditions(GLOBAL_SITE), childrenAdditions); } From 7ecbb304feb2ad39e2ff9c46a752ab511e03ea5a Mon Sep 17 00:00:00 2001 From: Eugene Chang Date: Tue, 26 May 2015 10:04:04 -0400 Subject: [PATCH 217/790] Small refactor of admin panel site check --- controllers/admin/base_admin_controller.js | 2 +- include/service/entities/site_service.js | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/controllers/admin/base_admin_controller.js b/controllers/admin/base_admin_controller.js index 625f83437..e1b4e15f3 100644 --- a/controllers/admin/base_admin_controller.js +++ b/controllers/admin/base_admin_controller.js @@ -46,7 +46,7 @@ module.exports = function BaseAdminControllerModule(pb) { BaseAdminController.prototype.extendedInit = function(cb) { var self = this; var userSite = pb.SiteService.getSiteFromObject(self.session.authentication.user); - if (!pb.SiteService.isGlobal(userSite) && !pb.SiteService.areEqual(userSite, self.pathSiteUId)) { + if (!pb.SiteService.doesScopeEnvelope(userSite, self.pathSiteUId)) { self.reqHandler.serve404(); // TODO should we serve 403 here? return; } diff --git a/include/service/entities/site_service.js b/include/service/entities/site_service.js index 76455992a..cf6976dfb 100644 --- a/include/service/entities/site_service.js +++ b/include/service/entities/site_service.js @@ -308,6 +308,15 @@ module.exports = function SiteServiceModule(pb) { return !actual || SiteService.areEqual(actual, expected); }; + /** + * Returns true iff given (user) scope envelopes current scope; conceptually, true <=> userScope ⊇ currentScope + * @param userScope + * @param currentScope + */ + SiteService.doesScopeEnvelope = function (userScope, currentScope) { + return SiteService.isGlobal(userScope) || userScope === currentScope; + }; + /** * Central place to get the current site * From d36a92d58ac045c231bbfe33494d89389e73e9f9 Mon Sep 17 00:00:00 2001 From: Eugene Chang Date: Tue, 26 May 2015 10:24:39 -0400 Subject: [PATCH 218/790] When user's restrict from posting in comments, hide comment form (still need to enforce this on server side) --- .../controllers/api/comments/new_comment.js | 11 ++++++++++- plugins/pencilblue/controllers/index.js | 8 ++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/plugins/pencilblue/controllers/api/comments/new_comment.js b/plugins/pencilblue/controllers/api/comments/new_comment.js index 46ecdaf2b..4cc7c4ddc 100755 --- a/plugins/pencilblue/controllers/api/comments/new_comment.js +++ b/plugins/pencilblue/controllers/api/comments/new_comment.js @@ -25,7 +25,16 @@ module.exports = function NewCommentModule(pb) { * Creates a new comment */ function NewComment(){} - util.inherits(NewComment, pb.AdminFormController); + util.inherits(NewComment, pb.FormController); + + NewComment.prototype.init = function (props, cb) { + var self = this; + pb.BaseController.prototype.init.call(self, props, function () { + self.siteUId = pb.SiteService.getCurrentSite(self.site); + self.siteQueryService = new pb.SiteQueryService(self.siteUId); + cb(); + }); + }; NewComment.prototype.onPostParamsRetrieved = function(post, cb) { var self = this; diff --git a/plugins/pencilblue/controllers/index.js b/plugins/pencilblue/controllers/index.js index 07571844f..1b49801e8 100755 --- a/plugins/pencilblue/controllers/index.js +++ b/plugins/pencilblue/controllers/index.js @@ -303,8 +303,12 @@ module.exports = function IndexModule(pb) { Index.prototype.renderComments = function(content, ts, cb) { var self = this; var commentingUser = null; + var user = this.session.authentication.user; + var userSite = pb.SiteService.getSiteFromObject(user); + var isAllowedToComment = pb.SiteService.doesScopeEnvelope(userSite, self.site); + if(pb.security.isAuthenticated(this.session)) { - commentingUser = Comments.getCommentingUser(this.session.authentication.user); + commentingUser = Comments.getCommentingUser(user); } ts.registerLocal('user_photo', function(flag, cb) { @@ -324,7 +328,7 @@ module.exports = function IndexModule(pb) { } }); ts.registerLocal('user_name', commentingUser ? commentingUser.name : ''); - ts.registerLocal('display_submit', commentingUser ? 'block' : 'none'); + ts.registerLocal('display_submit', commentingUser && isAllowedToComment ? 'block' : 'none'); ts.registerLocal('display_login', commentingUser ? 'none' : 'block'); ts.registerLocal('comments_length', util.isArray(content.comments) ? content.comments.length : 0); ts.registerLocal('individual_comments', function(flag, cb) { From cdf379bc9208ebc386540b140c4922d2a8ded9ae Mon Sep 17 00:00:00 2001 From: Eugene Chang Date: Tue, 26 May 2015 14:55:16 -0400 Subject: [PATCH 219/790] Login redirection when user is already logged in; checking for authentication at request handler level --- include/http/request_handler.js | 17 +++++++++++++++++ include/service/entities/site_service.js | 4 ++++ plugins/pencilblue/controllers/actions/login.js | 2 +- plugins/pencilblue/controllers/admin/login.js | 9 +++++++-- 4 files changed, 29 insertions(+), 3 deletions(-) diff --git a/include/http/request_handler.js b/include/http/request_handler.js index 50af5b607..ab407c63f 100755 --- a/include/http/request_handler.js +++ b/include/http/request_handler.js @@ -1078,6 +1078,12 @@ module.exports = function RequestHandlerModule(pb) { self.session.on_login = self.req.method.toLowerCase() === 'get' ? self.url.href : pb.UrlService.urlJoin(pb.config.siteRoot, '/admin'); callback(result, result); return; + } else if (!isUserAllowedToAccessSite()) { + result.success = false; + result.content = '403 Forbidden'; + result.code = 403; + callback(result, result); + return; } callback(null, result); } @@ -1086,6 +1092,17 @@ module.exports = function RequestHandlerModule(pb) { } }; + function isUserAllowedToAccessSite(user) { + if (!user) { + user = self.session.authentication.user; + } + if (!user) {// still + return false; + } + var siteFromUser = pb.SiteService.getSiteFromObject(user); + return pb.SiteService.doesScopeEnvelope(siteFromUser, site); + } + var checkAdminLevel = function(callback) { var result = {success: true}; diff --git a/include/service/entities/site_service.js b/include/service/entities/site_service.js index cf6976dfb..2ef418957 100644 --- a/include/service/entities/site_service.js +++ b/include/service/entities/site_service.js @@ -15,6 +15,7 @@ module.exports = function SiteServiceModule(pb) { function SiteService(){} SiteService.GLOBAL_SITE = 'global'; + SiteService.NO_SITE = 'no-site'; // represents a site that doesn't exist SiteService.SITE_FIELD = 'site'; SiteService.SITE_COLLECTION = 'site'; var SITE_COLL = SiteService.SITE_COLLECTION; @@ -364,6 +365,9 @@ module.exports = function SiteServiceModule(pb) { }; SiteService.getSiteFromObject = function (object) { + if (!object) { + return SiteService.NO_SITE; + } return object[SiteService.SITE_FIELD]; }; diff --git a/plugins/pencilblue/controllers/actions/login.js b/plugins/pencilblue/controllers/actions/login.js index c59c72fd9..ddc52e564 100755 --- a/plugins/pencilblue/controllers/actions/login.js +++ b/plugins/pencilblue/controllers/actions/login.js @@ -59,7 +59,7 @@ module.exports = function LoginActionControllerModule(pb) { location = '/admin'; var site = pb.SiteService.getSiteFromObject(user); if (!pb.SiteService.isNotSetOrEqual(site, self.site)) { - location += '/' + site; + location += pb.SiteService.getCurrentSitePrefix(site); } } self.redirect(location, cb); diff --git a/plugins/pencilblue/controllers/admin/login.js b/plugins/pencilblue/controllers/admin/login.js index 37c78dea3..2e775caec 100755 --- a/plugins/pencilblue/controllers/admin/login.js +++ b/plugins/pencilblue/controllers/admin/login.js @@ -35,10 +35,15 @@ module.exports = function LoginViewControllerModule(pb) { * @method render */ LoginViewController.prototype.render = function(cb) { - + var self = this; if(pb.security.isAuthorized(this.session, {authenticated: true, admin_level: pb.SecurityService.ACCESS_WRITER})) { - this.redirect('/admin', cb); + var location = '/admin'; + var site = pb.SiteService.getSiteFromObject(this.session.authentication.user); + if (!pb.SiteService.isNotSetOrEqual(site, self.site)) { + location += pb.SiteService.getCurrentSitePrefix(site); + } + this.redirect(location, cb); return; } else if(pb.security.isAuthenticated(this.session)) { From 397f36835bc1847fefaea946fa9753b6fa0d3f95 Mon Sep 17 00:00:00 2001 From: Eugene Chang Date: Tue, 26 May 2015 15:29:14 -0400 Subject: [PATCH 220/790] Fixing manage_themes from the refactor --- plugins/pencilblue/controllers/admin/themes/manage_themes.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/pencilblue/controllers/admin/themes/manage_themes.js b/plugins/pencilblue/controllers/admin/themes/manage_themes.js index 6c31a43e2..4c7fcb2be 100755 --- a/plugins/pencilblue/controllers/admin/themes/manage_themes.js +++ b/plugins/pencilblue/controllers/admin/themes/manage_themes.js @@ -34,7 +34,7 @@ module.exports = function(pb) { var self = this; //get plugs with themes - var pluginService = new pb.PluginService(self.site); + var pluginService = new pb.PluginService(self.pathSiteUId); pluginService.getPluginsWithThemesBySite(function (err, themes) { if (util.isError(err)) { throw result; From ca46e3885f4802a9e24cccdc664cb927dafa25f1 Mon Sep 17 00:00:00 2001 From: Eugene Chang Date: Wed, 27 May 2015 09:11:40 -0400 Subject: [PATCH 221/790] Fixing inactive theme routes overwriting active theme routes when installed globally --- include/http/request_handler.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/http/request_handler.js b/include/http/request_handler.js index 50af5b607..b446ebf70 100755 --- a/include/http/request_handler.js +++ b/include/http/request_handler.js @@ -24,6 +24,7 @@ var async = require('async'); var domain = require('domain'); var Cookies = require('cookies'); var util = require('../util.js'); +var _ = require('lodash'); module.exports = function RequestHandlerModule(pb) { @@ -732,6 +733,7 @@ module.exports = function RequestHandlerModule(pb) { if (!pb.SiteService.isGlobal(this.site) && (pb.SiteService.GLOBAL_SITE in route.themes)) { util.arrayPushAll(Object.keys(route.themes[pb.SiteService.GLOBAL_SITE]), themesToCheck); } + themesToCheck = _.uniq(themesToCheck); for (var j = 0; j < themesToCheck.length; j++) { //see if theme supports method and provides support @@ -744,6 +746,7 @@ module.exports = function RequestHandlerModule(pb) { obj.theme = themesToCheck[j]; obj.method = methods[i]; obj.site = GLOBAL_SITE; + return obj; } } } From ca2c2b6b2ad25ce474297fc00acb470017400439 Mon Sep 17 00:00:00 2001 From: Eugene Chang Date: Thu, 28 May 2015 11:13:18 -0400 Subject: [PATCH 222/790] Fixing admin permissions/login. Removing authentication requirement to logout. --- include/http/request_handler.js | 34 ++++++++---- include/requirements.js | 1 + .../service/admin/admin_redirect_service.js | 54 +++++++++++++++++++ .../pencilblue/controllers/actions/login.js | 8 +-- plugins/pencilblue/controllers/admin/login.js | 7 +-- plugins/pencilblue/include/routes.js | 1 - 6 files changed, 81 insertions(+), 24 deletions(-) create mode 100644 include/service/admin/admin_redirect_service.js diff --git a/include/http/request_handler.js b/include/http/request_handler.js index 92c1a9bea..31bfaeefb 100755 --- a/include/http/request_handler.js +++ b/include/http/request_handler.js @@ -793,6 +793,15 @@ module.exports = function RequestHandlerModule(pb) { }); }; + function getPathVars(route, url) { + var pathVars = {}; + var pathParts = url.pathname.split('/'); + for (var field in route.path_vars) { + pathVars[field] = pathParts[route.path_vars[field]]; + } + return pathVars; + } + /** * * @method onSecurityChecksPassed @@ -804,12 +813,7 @@ module.exports = function RequestHandlerModule(pb) { RequestHandler.prototype.onSecurityChecksPassed = function(activeTheme, method, site, route) { //extract path variables - var pathVars = {}; - var pathParts = this.url.pathname.split('/'); - for (var field in route.path_vars) { - pathVars[field] = pathParts[route.path_vars[field]]; - } - + var pathVars = getPathVars(route, this.url); //execute controller var ControllerType = route.themes[site][activeTheme][method].controller; var cInstance = new ControllerType(); @@ -1081,7 +1085,7 @@ module.exports = function RequestHandlerModule(pb) { self.session.on_login = self.req.method.toLowerCase() === 'get' ? self.url.href : pb.UrlService.urlJoin(pb.config.siteRoot, '/admin'); callback(result, result); return; - } else if (!isUserAllowedToAccessSite()) { + } else if (!isUserAllowedToAccessSite(self.session.authentication.user)) { result.success = false; result.content = '403 Forbidden'; result.code = 403; @@ -1097,13 +1101,21 @@ module.exports = function RequestHandlerModule(pb) { function isUserAllowedToAccessSite(user) { if (!user) { - user = self.session.authentication.user; - } - if (!user) {// still return false; } var siteFromUser = pb.SiteService.getSiteFromObject(user); - return pb.SiteService.doesScopeEnvelope(siteFromUser, site); + if (pb.SiteService.doesScopeEnvelope(siteFromUser, self.site)) { + return true; + } + + // TODO: this is somewhat hacky change to get siteid, this code should go away once we move to site resolution by hostname + var pathVars = getPathVars(self.route, self.url); + var siteId = pathVars.siteid; + if (siteId && pb.SiteService.doesScopeEnvelope(siteFromUser, siteId)) { + return true; + } + + return false; } var checkAdminLevel = function(callback) { diff --git a/include/requirements.js b/include/requirements.js index c10e0fe9e..db48bfa9e 100755 --- a/include/requirements.js +++ b/include/requirements.js @@ -188,6 +188,7 @@ module.exports = function PB(config) { }); pb.AdminNavigation = require(path.join(config.docRoot, '/include/admin_navigation'))(pb); // Admin Navigation pb.AdminSubnavService = require(path.join(config.docRoot, '/include/service/admin/admin_subnav_service.js'))(pb); + pb.AdminRedirectService = require(path.join(config.docRoot, '/include/service/admin/admin_redirect_service'))(pb); pb.AnalyticsManager = require(path.join(config.docRoot, '/include/system/analytics_manager.js'))(pb); pb.UrlService = require(path.join(config.docRoot, '/include/service/entities/url_service.js'))(pb); pb.CallHomeService = require(path.join(config.docRoot, '/include/system/call_home_service.js'))(pb); diff --git a/include/service/admin/admin_redirect_service.js b/include/service/admin/admin_redirect_service.js new file mode 100644 index 000000000..4f0568832 --- /dev/null +++ b/include/service/admin/admin_redirect_service.js @@ -0,0 +1,54 @@ +/* + Copyright (C) 2015 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ + +module.exports = function AdminRedirectServiceModule(pb) { + "use strict"; + + function AdminRedirectService() { + } + + /** + * Redirect admin user after logging in + * + * @param controller + * @param user + * @param cb + */ + AdminRedirectService.redirectAdminUser = function (controller, user, cb) { + var location = '/admin'; + var site = pb.SiteService.getSiteFromObject(user); + if (!pb.SiteService.areEqual(site, controller.site)) { + var siteId = pb.SiteService.getCurrentSite(site); + location += pb.SiteService.getCurrentSitePrefix(siteId); + if (pb.SiteService.isGlobal(siteId)) { + controller.redirect(pb.config.siteRoot + location, cb); + } else { + var service = new pb.SiteService(); + service.getByUid(siteId, function (siteObj) { + if (siteObj) { + location = siteObj.hostname + location; + } + controller.redirect(location, cb); + }); + } + } else { + controller.redirect(location, cb); + } + }; + + return AdminRedirectService; +}; \ No newline at end of file diff --git a/plugins/pencilblue/controllers/actions/login.js b/plugins/pencilblue/controllers/actions/login.js index ddc52e564..ecb4a17ed 100755 --- a/plugins/pencilblue/controllers/actions/login.js +++ b/plugins/pencilblue/controllers/actions/login.js @@ -54,15 +54,11 @@ module.exports = function LoginActionControllerModule(pb) { if (self.session.on_login !== undefined) { location = self.session.on_login; delete self.session.on_login; + self.redirect(location, cb); } else if(adminAttempt) { - location = '/admin'; - var site = pb.SiteService.getSiteFromObject(user); - if (!pb.SiteService.isNotSetOrEqual(site, self.site)) { - location += pb.SiteService.getCurrentSitePrefix(site); - } + pb.AdminRedirectService.redirectAdminUser(self, user, cb); } - self.redirect(location, cb); }); }; diff --git a/plugins/pencilblue/controllers/admin/login.js b/plugins/pencilblue/controllers/admin/login.js index 2e775caec..f452e3864 100755 --- a/plugins/pencilblue/controllers/admin/login.js +++ b/plugins/pencilblue/controllers/admin/login.js @@ -38,12 +38,7 @@ module.exports = function LoginViewControllerModule(pb) { var self = this; if(pb.security.isAuthorized(this.session, {authenticated: true, admin_level: pb.SecurityService.ACCESS_WRITER})) { - var location = '/admin'; - var site = pb.SiteService.getSiteFromObject(this.session.authentication.user); - if (!pb.SiteService.isNotSetOrEqual(site, self.site)) { - location += pb.SiteService.getCurrentSitePrefix(site); - } - this.redirect(location, cb); + pb.AdminRedirectService.redirectAdminUser(self, self.session.authentication.user, cb); return; } else if(pb.security.isAuthenticated(this.session)) { diff --git a/plugins/pencilblue/include/routes.js b/plugins/pencilblue/include/routes.js index 4b473173e..5d6ca9f4b 100644 --- a/plugins/pencilblue/include/routes.js +++ b/plugins/pencilblue/include/routes.js @@ -98,7 +98,6 @@ module.exports = function Routes(pb){ { path: "/actions/logout", access_level: 0, - auth_required: true, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'logout.js'), content_type: 'text/html' }, From bc11c0e2c1b1210020cb4a22b62f06bb292813b7 Mon Sep 17 00:00:00 2001 From: Eugene Chang Date: Thu, 28 May 2015 11:22:58 -0400 Subject: [PATCH 223/790] Fixing site hostname loading, adding protocol prefix to redirect --- include/service/admin/admin_redirect_service.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/service/admin/admin_redirect_service.js b/include/service/admin/admin_redirect_service.js index 4f0568832..a33238368 100644 --- a/include/service/admin/admin_redirect_service.js +++ b/include/service/admin/admin_redirect_service.js @@ -38,9 +38,9 @@ module.exports = function AdminRedirectServiceModule(pb) { controller.redirect(pb.config.siteRoot + location, cb); } else { var service = new pb.SiteService(); - service.getByUid(siteId, function (siteObj) { + service.getByUid(siteId, function (err, siteObj) { if (siteObj) { - location = siteObj.hostname + location; + location = '//' + siteObj.hostname + location; } controller.redirect(location, cb); }); From 042fd89351fe586b9ca3dc405f721c0b13a0da3b Mon Sep 17 00:00:00 2001 From: Eugene Chang Date: Thu, 28 May 2015 11:33:36 -0400 Subject: [PATCH 224/790] Admin user type visibility (admin/m.editor for global context, others for regular context) --- include/service/entities/user_service.js | 26 +++++++++++-------- .../admin/users/change_password.js | 2 +- .../controllers/admin/users/user_form.js | 2 +- .../wp_import/controllers/manage_new_users.js | 2 +- 4 files changed, 18 insertions(+), 14 deletions(-) diff --git a/include/service/entities/user_service.js b/include/service/entities/user_service.js index 86fa58011..dcaa5c971 100755 --- a/include/service/entities/user_service.js +++ b/include/service/entities/user_service.js @@ -121,19 +121,23 @@ module.exports = function UserServiceModule(pb) { * @method getAdminOptions * @param {Object} session The current session object * @param {Object} ls The localization object + * @param {String} siteUid */ - UserService.prototype.getAdminOptions = function(session, ls) { - var adminOptions = [ - {name: ls.get('READER'), value: pb.SecurityService.ACCESS_USER}, - {name: ls.get('WRITER'), value: pb.SecurityService.ACCESS_WRITER}, - {name: ls.get('EDITOR'), value: pb.SecurityService.ACCESS_EDITOR} - ]; - - if(session.authentication.user.admin >= pb.SecurityService.ACCESS_MANAGING_EDITOR) { - adminOptions.push({name: ls.get('MANAGING_EDITOR'), value: pb.SecurityService.ACCESS_MANAGING_EDITOR}); + UserService.prototype.getAdminOptions = function (session, ls, siteUid) { + var adminOptions = []; + + if (!pb.SiteService.isGlobal(siteUid)) { + adminOptions = [{name: ls.get('READER'), value: pb.SecurityService.ACCESS_USER}, + {name: ls.get('WRITER'), value: pb.SecurityService.ACCESS_WRITER}, + {name: ls.get('EDITOR'), value: pb.SecurityService.ACCESS_EDITOR}] } - if(session.authentication.user.admin >= pb.SecurityService.ACCESS_ADMINISTRATOR) { - adminOptions.push({name: ls.get('ADMINISTRATOR'), value: pb.SecurityService.ACCESS_ADMINISTRATOR}); + else { + if (session.authentication.user.admin >= pb.SecurityService.ACCESS_MANAGING_EDITOR) { + adminOptions.push({name: ls.get('MANAGING_EDITOR'), value: pb.SecurityService.ACCESS_MANAGING_EDITOR}); + } + if (session.authentication.user.admin >= pb.SecurityService.ACCESS_ADMINISTRATOR) { + adminOptions.push({name: ls.get('ADMINISTRATOR'), value: pb.SecurityService.ACCESS_ADMINISTRATOR}); + } } return adminOptions; diff --git a/plugins/pencilblue/controllers/admin/users/change_password.js b/plugins/pencilblue/controllers/admin/users/change_password.js index bb516ac9d..70fa16aa9 100755 --- a/plugins/pencilblue/controllers/admin/users/change_password.js +++ b/plugins/pencilblue/controllers/admin/users/change_password.js @@ -63,7 +63,7 @@ module.exports = function AdminChangePasswordControllerModule(pb) { navigation: pb.AdminNavigation.get(self.session, ['users'], self.ls), pills: pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, SUB_NAV_KEY, user), tabs: tabs, - adminOptions: pb.users.getAdminOptions(self.session, self.localizationService), + adminOptions: pb.users.getAdminOptions(self.session, self.localizationService, self.pathSiteUId), user: user, sitePrefix: self.sitePrefix }); diff --git a/plugins/pencilblue/controllers/admin/users/user_form.js b/plugins/pencilblue/controllers/admin/users/user_form.js index d282d8756..0961725de 100644 --- a/plugins/pencilblue/controllers/admin/users/user_form.js +++ b/plugins/pencilblue/controllers/admin/users/user_form.js @@ -55,7 +55,7 @@ module.exports = function(pb) { data.adminOptions = [{name: self.ls.get('ADMINISTRATOR'), value: pb.SecurityService.ACCESS_ADMINISTRATOR}]; if(!data.user[pb.DAO.getIdField()] || self.session.authentication.user_id !== data.user[pb.DAO.getIdField()].toString()) { - data.adminOptions = pb.users.getAdminOptions(self.session, self.localizationService); + data.adminOptions = pb.users.getAdminOptions(self.session, self.localizationService, self.pathSiteUId); } data.sitePrefix = self.sitePrefix; diff --git a/plugins/wp_import/controllers/manage_new_users.js b/plugins/wp_import/controllers/manage_new_users.js index 230ddef1c..846b1f5c0 100755 --- a/plugins/wp_import/controllers/manage_new_users.js +++ b/plugins/wp_import/controllers/manage_new_users.js @@ -71,7 +71,7 @@ module.exports = function WPManageUsersViewControllerModule(pb) { pills: pills, tabs: tabs, users: self.session.importedUsers, - adminOptions: pb.users.getAdminOptions(self.session, self.localizationService) + adminOptions: pb.users.getAdminOptions(self.session, self.localizationService, self.pathSiteUId) }; this.setPageName(this.ls.get('IMPORT_WORDPRESS')); From 9f916a72a655a962a078747e36151699ae8d5433 Mon Sep 17 00:00:00 2001 From: Eugene Chang Date: Thu, 28 May 2015 11:54:00 -0400 Subject: [PATCH 225/790] Standalone template fix --- plugins/pencilblue/controllers/index.js | 2 +- plugins/portfolio/controllers/blog.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/pencilblue/controllers/index.js b/plugins/pencilblue/controllers/index.js index 07571844f..165a3e749 100755 --- a/plugins/pencilblue/controllers/index.js +++ b/plugins/pencilblue/controllers/index.js @@ -175,7 +175,7 @@ module.exports = function IndexModule(pb) { //the theme is specified, we ensure that the theme is installed and //initialized otherwise we let the template service figure out how to //delegate. - if (!pb.PluginService.isActivePlugin(pieces[0])) { + if (!pb.PluginService.isActivePlugin(pieces[0], this.site)) { pb.log.silly("ContentController: Theme [%s] is not active, Template Service will delegate [%s]", pieces[0], pieces[1]); cb(null, pieces[1]); return; diff --git a/plugins/portfolio/controllers/blog.js b/plugins/portfolio/controllers/blog.js index 6ee85af2f..0b0394b55 100755 --- a/plugins/portfolio/controllers/blog.js +++ b/plugins/portfolio/controllers/blog.js @@ -207,7 +207,7 @@ module.exports = function BlogModule(pb) { //the theme is specified, we ensure that the theme is installed and //initialized otherwise we let the template service figure out how to //delegate. - if (!pb.PluginService.isActivePlugin(pieces[0])) { + if (!pb.PluginService.isActivePlugin(pieces[0], this.site)) { pb.log.silly("ContentController: Theme [%s] is not active, Template Service will delegate [%s]", pieces[0], pieces[1]); cb(null, pieces[1]); return; From f193b09d02e68aff5e145b43c77feded3c8c5089 Mon Sep 17 00:00:00 2001 From: Eugene Chang Date: Thu, 28 May 2015 13:23:13 -0400 Subject: [PATCH 226/790] Undoing admin redirection --- include/requirements.js | 1 - .../service/admin/admin_redirect_service.js | 54 ------------------- .../pencilblue/controllers/actions/login.js | 4 +- plugins/pencilblue/controllers/admin/login.js | 4 +- 4 files changed, 4 insertions(+), 59 deletions(-) delete mode 100644 include/service/admin/admin_redirect_service.js diff --git a/include/requirements.js b/include/requirements.js index db48bfa9e..c10e0fe9e 100755 --- a/include/requirements.js +++ b/include/requirements.js @@ -188,7 +188,6 @@ module.exports = function PB(config) { }); pb.AdminNavigation = require(path.join(config.docRoot, '/include/admin_navigation'))(pb); // Admin Navigation pb.AdminSubnavService = require(path.join(config.docRoot, '/include/service/admin/admin_subnav_service.js'))(pb); - pb.AdminRedirectService = require(path.join(config.docRoot, '/include/service/admin/admin_redirect_service'))(pb); pb.AnalyticsManager = require(path.join(config.docRoot, '/include/system/analytics_manager.js'))(pb); pb.UrlService = require(path.join(config.docRoot, '/include/service/entities/url_service.js'))(pb); pb.CallHomeService = require(path.join(config.docRoot, '/include/system/call_home_service.js'))(pb); diff --git a/include/service/admin/admin_redirect_service.js b/include/service/admin/admin_redirect_service.js deleted file mode 100644 index a33238368..000000000 --- a/include/service/admin/admin_redirect_service.js +++ /dev/null @@ -1,54 +0,0 @@ -/* - Copyright (C) 2015 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 - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . - */ - -module.exports = function AdminRedirectServiceModule(pb) { - "use strict"; - - function AdminRedirectService() { - } - - /** - * Redirect admin user after logging in - * - * @param controller - * @param user - * @param cb - */ - AdminRedirectService.redirectAdminUser = function (controller, user, cb) { - var location = '/admin'; - var site = pb.SiteService.getSiteFromObject(user); - if (!pb.SiteService.areEqual(site, controller.site)) { - var siteId = pb.SiteService.getCurrentSite(site); - location += pb.SiteService.getCurrentSitePrefix(siteId); - if (pb.SiteService.isGlobal(siteId)) { - controller.redirect(pb.config.siteRoot + location, cb); - } else { - var service = new pb.SiteService(); - service.getByUid(siteId, function (err, siteObj) { - if (siteObj) { - location = '//' + siteObj.hostname + location; - } - controller.redirect(location, cb); - }); - } - } else { - controller.redirect(location, cb); - } - }; - - return AdminRedirectService; -}; \ No newline at end of file diff --git a/plugins/pencilblue/controllers/actions/login.js b/plugins/pencilblue/controllers/actions/login.js index ecb4a17ed..86f894fae 100755 --- a/plugins/pencilblue/controllers/actions/login.js +++ b/plugins/pencilblue/controllers/actions/login.js @@ -54,11 +54,11 @@ module.exports = function LoginActionControllerModule(pb) { if (self.session.on_login !== undefined) { location = self.session.on_login; delete self.session.on_login; - self.redirect(location, cb); } else if(adminAttempt) { - pb.AdminRedirectService.redirectAdminUser(self, user, cb); + location = '/admin'; } + self.redirect(location, cb); }); }; diff --git a/plugins/pencilblue/controllers/admin/login.js b/plugins/pencilblue/controllers/admin/login.js index f452e3864..37c78dea3 100755 --- a/plugins/pencilblue/controllers/admin/login.js +++ b/plugins/pencilblue/controllers/admin/login.js @@ -35,10 +35,10 @@ module.exports = function LoginViewControllerModule(pb) { * @method render */ LoginViewController.prototype.render = function(cb) { - var self = this; + if(pb.security.isAuthorized(this.session, {authenticated: true, admin_level: pb.SecurityService.ACCESS_WRITER})) { - pb.AdminRedirectService.redirectAdminUser(self, self.session.authentication.user, cb); + this.redirect('/admin', cb); return; } else if(pb.security.isAuthenticated(this.session)) { From e08a82c896adbcf17aa9c983725f3a9515c0aee6 Mon Sep 17 00:00:00 2001 From: Eugene Chang Date: Thu, 28 May 2015 13:29:22 -0400 Subject: [PATCH 227/790] Site-aware login; users with specific site will receive invalid password if they try to login to a site not assigned to their own --- include/security/authentication/index.js | 7 ++++++- plugins/pencilblue/controllers/actions/login.js | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/include/security/authentication/index.js b/include/security/authentication/index.js index 3ea5d1f6b..a625fe0a0 100755 --- a/include/security/authentication/index.js +++ b/include/security/authentication/index.js @@ -61,8 +61,13 @@ module.exports = function AuthenticationModule(pb) { }; } + var dao; + if (credentials.hasOwnProperty('site')) { + dao = new pb.SiteQueryService(credentials.site, false); + } else { + dao = new pb.DAO(); + } //search for user - var dao = new pb.DAO(); dao.loadByValues(query, 'user', cb); }; diff --git a/plugins/pencilblue/controllers/actions/login.js b/plugins/pencilblue/controllers/actions/login.js index 86f894fae..5a04e3b75 100755 --- a/plugins/pencilblue/controllers/actions/login.js +++ b/plugins/pencilblue/controllers/actions/login.js @@ -43,6 +43,7 @@ module.exports = function LoginActionControllerModule(pb) { var options = post; options.access_level = adminAttempt ? pb.SecurityService.ACCESS_WRITER : pb.SecurityService.ACCESS_USER; + options.site = self.site; pb.security.authenticateSession(this.session, options, new FormAuthentication(), function(err, user) { if(util.isError(err) || user === null) { self.loginError(adminAttempt, cb); From dd469b42dfc466bc03a35445aeeafef2d5df6034 Mon Sep 17 00:00:00 2001 From: Eugene Chang Date: Thu, 28 May 2015 13:39:05 -0400 Subject: [PATCH 228/790] Redoing admin redirection This reverts commit f193b09d02e68aff5e145b43c77feded3c8c5089. --- include/requirements.js | 1 + .../service/admin/admin_redirect_service.js | 54 +++++++++++++++++++ .../pencilblue/controllers/actions/login.js | 4 +- plugins/pencilblue/controllers/admin/login.js | 4 +- 4 files changed, 59 insertions(+), 4 deletions(-) create mode 100644 include/service/admin/admin_redirect_service.js diff --git a/include/requirements.js b/include/requirements.js index c10e0fe9e..db48bfa9e 100755 --- a/include/requirements.js +++ b/include/requirements.js @@ -188,6 +188,7 @@ module.exports = function PB(config) { }); pb.AdminNavigation = require(path.join(config.docRoot, '/include/admin_navigation'))(pb); // Admin Navigation pb.AdminSubnavService = require(path.join(config.docRoot, '/include/service/admin/admin_subnav_service.js'))(pb); + pb.AdminRedirectService = require(path.join(config.docRoot, '/include/service/admin/admin_redirect_service'))(pb); pb.AnalyticsManager = require(path.join(config.docRoot, '/include/system/analytics_manager.js'))(pb); pb.UrlService = require(path.join(config.docRoot, '/include/service/entities/url_service.js'))(pb); pb.CallHomeService = require(path.join(config.docRoot, '/include/system/call_home_service.js'))(pb); diff --git a/include/service/admin/admin_redirect_service.js b/include/service/admin/admin_redirect_service.js new file mode 100644 index 000000000..a33238368 --- /dev/null +++ b/include/service/admin/admin_redirect_service.js @@ -0,0 +1,54 @@ +/* + Copyright (C) 2015 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ + +module.exports = function AdminRedirectServiceModule(pb) { + "use strict"; + + function AdminRedirectService() { + } + + /** + * Redirect admin user after logging in + * + * @param controller + * @param user + * @param cb + */ + AdminRedirectService.redirectAdminUser = function (controller, user, cb) { + var location = '/admin'; + var site = pb.SiteService.getSiteFromObject(user); + if (!pb.SiteService.areEqual(site, controller.site)) { + var siteId = pb.SiteService.getCurrentSite(site); + location += pb.SiteService.getCurrentSitePrefix(siteId); + if (pb.SiteService.isGlobal(siteId)) { + controller.redirect(pb.config.siteRoot + location, cb); + } else { + var service = new pb.SiteService(); + service.getByUid(siteId, function (err, siteObj) { + if (siteObj) { + location = '//' + siteObj.hostname + location; + } + controller.redirect(location, cb); + }); + } + } else { + controller.redirect(location, cb); + } + }; + + return AdminRedirectService; +}; \ No newline at end of file diff --git a/plugins/pencilblue/controllers/actions/login.js b/plugins/pencilblue/controllers/actions/login.js index 5a04e3b75..46463655c 100755 --- a/plugins/pencilblue/controllers/actions/login.js +++ b/plugins/pencilblue/controllers/actions/login.js @@ -55,11 +55,11 @@ module.exports = function LoginActionControllerModule(pb) { if (self.session.on_login !== undefined) { location = self.session.on_login; delete self.session.on_login; + self.redirect(location, cb); } else if(adminAttempt) { - location = '/admin'; + pb.AdminRedirectService.redirectAdminUser(self, user, cb); } - self.redirect(location, cb); }); }; diff --git a/plugins/pencilblue/controllers/admin/login.js b/plugins/pencilblue/controllers/admin/login.js index 37c78dea3..f452e3864 100755 --- a/plugins/pencilblue/controllers/admin/login.js +++ b/plugins/pencilblue/controllers/admin/login.js @@ -35,10 +35,10 @@ module.exports = function LoginViewControllerModule(pb) { * @method render */ LoginViewController.prototype.render = function(cb) { - + var self = this; if(pb.security.isAuthorized(this.session, {authenticated: true, admin_level: pb.SecurityService.ACCESS_WRITER})) { - this.redirect('/admin', cb); + pb.AdminRedirectService.redirectAdminUser(self, self.session.authentication.user, cb); return; } else if(pb.security.isAuthenticated(this.session)) { From bad4b3bcb62fe3af0688f92a3764d2770e899acc Mon Sep 17 00:00:00 2001 From: Eugene Chang Date: Thu, 28 May 2015 13:43:11 -0400 Subject: [PATCH 229/790] Removing hostname redirection from admin; redirect only to the specified site of user --- .../service/admin/admin_redirect_service.js | 20 +++---------------- 1 file changed, 3 insertions(+), 17 deletions(-) diff --git a/include/service/admin/admin_redirect_service.js b/include/service/admin/admin_redirect_service.js index a33238368..df147b994 100644 --- a/include/service/admin/admin_redirect_service.js +++ b/include/service/admin/admin_redirect_service.js @@ -31,23 +31,9 @@ module.exports = function AdminRedirectServiceModule(pb) { AdminRedirectService.redirectAdminUser = function (controller, user, cb) { var location = '/admin'; var site = pb.SiteService.getSiteFromObject(user); - if (!pb.SiteService.areEqual(site, controller.site)) { - var siteId = pb.SiteService.getCurrentSite(site); - location += pb.SiteService.getCurrentSitePrefix(siteId); - if (pb.SiteService.isGlobal(siteId)) { - controller.redirect(pb.config.siteRoot + location, cb); - } else { - var service = new pb.SiteService(); - service.getByUid(siteId, function (err, siteObj) { - if (siteObj) { - location = '//' + siteObj.hostname + location; - } - controller.redirect(location, cb); - }); - } - } else { - controller.redirect(location, cb); - } + var siteId = pb.SiteService.getCurrentSite(site); + location += pb.SiteService.getCurrentSitePrefix(siteId); + controller.redirect(location, cb); }; return AdminRedirectService; From 36397e62263a831da82b01d6c7df677168b30411 Mon Sep 17 00:00:00 2001 From: Eugene Chang Date: Thu, 28 May 2015 14:07:02 -0400 Subject: [PATCH 230/790] Site-aware user sign up; prevent users from being able to sign up globally --- .../pencilblue/controllers/actions/admin/users/new_user.js | 5 +++-- plugins/pencilblue/controllers/actions/user/sign_up.js | 7 ++++++- public/localization/en-us.js | 3 ++- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/plugins/pencilblue/controllers/actions/admin/users/new_user.js b/plugins/pencilblue/controllers/actions/admin/users/new_user.js index 912db970f..8e9e0cc77 100755 --- a/plugins/pencilblue/controllers/actions/admin/users/new_user.js +++ b/plugins/pencilblue/controllers/actions/admin/users/new_user.js @@ -67,8 +67,9 @@ module.exports = function(pb) { return; } - var dao = new pb.DAO(); - dao.save(user, function(err, result) { + var site = self.pathSiteUId || self.site; + var sqs = new pb.SiteQueryService(site); + sqs.save(user, function(err, result) { if(util.isError(err)) { cb({ code: 500, diff --git a/plugins/pencilblue/controllers/actions/user/sign_up.js b/plugins/pencilblue/controllers/actions/user/sign_up.js index b84c85411..648eb44a6 100755 --- a/plugins/pencilblue/controllers/actions/user/sign_up.js +++ b/plugins/pencilblue/controllers/actions/user/sign_up.js @@ -84,7 +84,12 @@ module.exports = function SignUpModule(pb) { return; } - var dao = new pb.DAO(); + if (pb.SiteService.isGlobal(self.site)) { + self.formError(self.ls.get('CANNOT_SIGN_UP_GLOBAL'), '/user/sign_up', cb); + return; + } + + var dao = new pb.SiteQueryService(self.site); dao.save(user, function(err, data) { if(util.isError(err)) { return self.formError(request, session, self.ls.get('ERROR_SAVING'), '/user/sign_up', cb); diff --git a/public/localization/en-us.js b/public/localization/en-us.js index bd74943da..f8a7de85c 100755 --- a/public/localization/en-us.js +++ b/public/localization/en-us.js @@ -505,7 +505,8 @@ var loc = SEND: 'Send', USE_CDN: 'Use CDNs (default)', USE_BOWER: 'Use Bower', - TEST_EMAIL_SUCCESS: 'Test email successfully sent' + TEST_EMAIL_SUCCESS: 'Test email successfully sent', + CANNOT_SIGN_UP_GLOBAL: 'You cannot sign up on global; an admin must create a global user within admin panel', } }; From 17a529fe7df0de8a0437df373ac62e64859c8135 Mon Sep 17 00:00:00 2001 From: andparker Date: Fri, 29 May 2015 16:33:16 -0400 Subject: [PATCH 231/790] Multi-site updates to some places that were overridden by the merge master. --- include/service/base_object_service.js | 4 ++-- include/service/entities/article_service.js | 4 ++-- include/service/entities/plugin_service.js | 2 +- plugins/pencilblue/controllers/index.js | 2 +- .../templates/angular/admin/content/topics/topic_form.html | 1 - plugins/portfolio/controllers/blog.js | 4 ++-- 6 files changed, 8 insertions(+), 9 deletions(-) diff --git a/include/service/base_object_service.js b/include/service/base_object_service.js index a87b20097..f4044746e 100644 --- a/include/service/base_object_service.js +++ b/include/service/base_object_service.js @@ -56,11 +56,11 @@ module.exports = function(pb) { this.type = context.type; /** - * An instance of DAO to be used to interact with the persitence layer + * An instance of DAO to be used to interact with the persistence layer * @property dao * @type {DAO} */ - this.dao = new pb.DAO(); + this.dao = new pb.SiteQueryService(context.site, context.onlyThisSite) } /** diff --git a/include/service/entities/article_service.js b/include/service/entities/article_service.js index 770d2aa74..d5a41ab43 100755 --- a/include/service/entities/article_service.js +++ b/include/service/entities/article_service.js @@ -33,7 +33,7 @@ module.exports = function ArticleServiceModule(pb) { * @constructor * */ - function ArticleService(){ + function ArticleService(siteUid, onlyThisSite){ this.object_type = ARTICLE_TYPE; this.site = pb.SiteService.getCurrentSite(siteUid); this.siteQueryService = new pb.SiteQueryService(this.site, onlyThisSite); @@ -47,7 +47,7 @@ module.exports = function ArticleServiceModule(pb) { * @property ARTICLE_TYPE * @type {String} */ - var ARTICLE_TYPE = 'article' + var ARTICLE_TYPE = 'article'; /** * diff --git a/include/service/entities/plugin_service.js b/include/service/entities/plugin_service.js index b1a8ca23e..e5ab461bc 100755 --- a/include/service/entities/plugin_service.js +++ b/include/service/entities/plugin_service.js @@ -497,7 +497,7 @@ module.exports = function PluginServiceModule(pb) { //add cache service if (useCache) { - services.push(new pb.CacheEntityService(objType, undefined, undefined, site, 3600)); + services.push(new pb.CacheEntityService(objType, undefined, undefined, site, false, 3600)); } //always add DB diff --git a/plugins/pencilblue/controllers/index.js b/plugins/pencilblue/controllers/index.js index 5ea607445..578428504 100755 --- a/plugins/pencilblue/controllers/index.js +++ b/plugins/pencilblue/controllers/index.js @@ -55,7 +55,7 @@ module.exports = function IndexModule(pb) { contentService.getSettings(function(err, contentSettings) { self.gatherData(function(err, data) { - var articleService = new pb.ArticleService(); + var articleService = new pb.ArticleService(self.site); articleService.getMetaInfo(data.content[0], function(err, meta) { self.ts.registerLocal('meta_keywords', meta.keywords); self.ts.registerLocal('meta_desc', data.section.description || meta.description); diff --git a/plugins/pencilblue/templates/angular/admin/content/topics/topic_form.html b/plugins/pencilblue/templates/angular/admin/content/topics/topic_form.html index c6d77da8a..bd4dd8837 100644 --- a/plugins/pencilblue/templates/angular/admin/content/topics/topic_form.html +++ b/plugins/pencilblue/templates/angular/admin/content/topics/topic_form.html @@ -16,7 +16,6 @@ var url = '/api/content/topics'; var action = 'post'; - var postURL = '/actions/admin' + $scope.sitePrefix + '/content/topics'; if($scope.topic._id) { url += '/' + $scope.topic._id; action = 'put'; diff --git a/plugins/portfolio/controllers/blog.js b/plugins/portfolio/controllers/blog.js index f2bc39652..b596bd173 100755 --- a/plugins/portfolio/controllers/blog.js +++ b/plugins/portfolio/controllers/blog.js @@ -54,10 +54,10 @@ module.exports = function BlogModule(pb) { var article = self.req.pencilblue_article || null; var page = self.req.pencilblue_page || null; - var contentService = new pb.ContentService(); + var contentService = new pb.ContentService(self.site, true); contentService.getSettings(function(err, contentSettings) { self.gatherData(function(err, data) { - var articleService = new pb.ArticleService(); + var articleService = new pb.ArticleService(self.site, true); articleService.getMetaInfo(data.content[0], function(err, meta) { self.ts.reprocess = false; From e81adf2d66e65ef21b48be1cde281cb0bbacd58f Mon Sep 17 00:00:00 2001 From: andparker Date: Fri, 29 May 2015 17:18:39 -0400 Subject: [PATCH 232/790] Merge in bug fixes | Sanitize site in the site query service --- controllers/base_controller.js | 6 +----- include/service/entities/site_query_service.js | 2 +- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/controllers/base_controller.js b/controllers/base_controller.js index 22b95cdef..e4ef68cc1 100755 --- a/controllers/base_controller.js +++ b/controllers/base_controller.js @@ -102,11 +102,7 @@ module.exports = function BaseControllerModule(pb) { this.pathVars = props.path_vars; this.query = props.query; this.pageName = ''; - this.context = { - req: this.req, - session: this.session, - ls: this.ls - }; + this.site = props.site; var self = this; this.templateService = this.getTemplateService(); diff --git a/include/service/entities/site_query_service.js b/include/service/entities/site_query_service.js index 10d17e7af..22fd2a5cd 100644 --- a/include/service/entities/site_query_service.js +++ b/include/service/entities/site_query_service.js @@ -32,7 +32,7 @@ module.exports = function SiteQueryServiceModule(pb) { * @constructor */ function SiteQueryService(siteUId, onlyThisSite) { - this.siteUId = siteUId; + this.siteUId = pb.SiteService.getCurrentSite(siteUId); this.onlyThisSite = onlyThisSite; DAO.call(this); } From bc44c665d6ca2c79cddad350995c32ed72af6515 Mon Sep 17 00:00:00 2001 From: btidwell Date: Mon, 1 Jun 2015 12:08:18 -0400 Subject: [PATCH 233/790] fix settings nave function for accessing plugin uid --- plugins/wp_import/wp_import.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/wp_import/wp_import.js b/plugins/wp_import/wp_import.js index 5f43a3d46..f9c5937ea 100755 --- a/plugins/wp_import/wp_import.js +++ b/plugins/wp_import/wp_import.js @@ -54,8 +54,8 @@ module.exports = function WPImportModule(pb) { * @param {Object} The plugin object * @return {Array} */ - WPImport.onPluginSettingsSubNav = function(navKey, localization, plugin) { - if(plugin.uid === 'wp_import') { + WPImport.onPluginSettingsSubNav = function(navKey, localization, data) { + if(data.plugin.uid === 'wp_import') { return [ { name: 'import_xml', From ce8a3f8ea89be92bdbfbbc090707f6cb3726bdc3 Mon Sep 17 00:00:00 2001 From: btidwell Date: Mon, 1 Jun 2015 14:16:04 -0400 Subject: [PATCH 234/790] create pages and articles with site on wp_import --- plugins/wp_import/controllers/import_action.js | 7 ++++++- plugins/wp_import/services/wp_xml_parse.js | 12 ++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/plugins/wp_import/controllers/import_action.js b/plugins/wp_import/controllers/import_action.js index 918178ec0..e347876ac 100755 --- a/plugins/wp_import/controllers/import_action.js +++ b/plugins/wp_import/controllers/import_action.js @@ -59,7 +59,12 @@ module.exports = function ImportWPActionControllerModule(pb) { return; } - wpXMLParse.parse(data.toString(), self.session.authentication.user_id, function(err, users) { + var parseData = { + data:data.toString(), + site:self.site + }; + + wpXMLParse.parse(parseData, self.session.authentication.user_id, function(err, users) { if(util.isError(err)) { self.session.error = err.stack; return cb({content: pb.BaseController.apiResponse(pb.BaseController.API_FAILURE, self.ls.get('ERROR_SAVING'))}); diff --git a/plugins/wp_import/services/wp_xml_parse.js b/plugins/wp_import/services/wp_xml_parse.js index 40ea258a0..e924dcde4 100644 --- a/plugins/wp_import/services/wp_xml_parse.js +++ b/plugins/wp_import/services/wp_xml_parse.js @@ -53,7 +53,9 @@ module.exports = function WPXMLParseServiceModule(pb) { cb(null, true); }; - WPXMLParseService.parse = function(xmlString, defaultUserId, cb) { + WPXMLParseService.parse = function(data, defaultUserId, cb) { + var xmlString = data.data; + var site = data.site; var self = this; pb.log.debug('WPXMLParseService: Starting to parse...'); @@ -71,7 +73,7 @@ module.exports = function WPXMLParseServiceModule(pb) { //load settings function(callback) { - var pluginService = new pb.PluginService(); + var pluginService = new pb.PluginService(site); pluginService.getSettingsKV('wp_import', function(err, settingsResult) { settings = settingsResult; callback(err); @@ -93,7 +95,7 @@ module.exports = function WPXMLParseServiceModule(pb) { }, function(callback) { - self.saveNewArticlesAndPages(defaultUserId, channel, users, topics, settings, callback); + self.saveNewArticlesAndPages(site, defaultUserId, channel, users, topics, settings, callback); } ]; async.series(tasks, function(err, results) { @@ -247,7 +249,7 @@ module.exports = function WPXMLParseServiceModule(pb) { async.parallel(tasks, cb); }; - WPXMLParseService.saveNewArticlesAndPages = function(defaultUserId, channel, users, topics, settings, cb) { + WPXMLParseService.saveNewArticlesAndPages = function(site, defaultUserId, channel, users, topics, settings, cb) { var self = this; var rawArticles = []; var rawPages = []; @@ -345,6 +347,7 @@ module.exports = function WPXMLParseServiceModule(pb) { author: defaultUserId } var newPage = pb.DocumentCreator.create('page', pagedoc); + newPage.site = site; var dao = new pb.DAO(); dao.save(newPage, callback); }); @@ -436,6 +439,7 @@ module.exports = function WPXMLParseServiceModule(pb) { author: author }; var newArticle = pb.DocumentCreator.create('article', articleDoc); + newArticle.site = site; var dao = new pb.DAO(); dao.save(newArticle, callback); }); From 6a692008e4cb926c1f68e5eb3837a991474ba808 Mon Sep 17 00:00:00 2001 From: btidwell Date: Mon, 1 Jun 2015 17:07:27 -0400 Subject: [PATCH 235/790] save topic with site attached in wp_import --- plugins/wp_import/services/wp_xml_parse.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/plugins/wp_import/services/wp_xml_parse.js b/plugins/wp_import/services/wp_xml_parse.js index e924dcde4..aa719f9d6 100644 --- a/plugins/wp_import/services/wp_xml_parse.js +++ b/plugins/wp_import/services/wp_xml_parse.js @@ -88,7 +88,7 @@ module.exports = function WPXMLParseServiceModule(pb) { }, function(callback) { - self.saveNewTopics(channel, function(err, topicsResult) { + self.saveNewTopics(site, channel, function(err, topicsResult) { topics = topicsResult; callback(err); }); @@ -168,7 +168,7 @@ module.exports = function WPXMLParseServiceModule(pb) { async.series(tasks, cb); }; - WPXMLParseService.saveNewTopics = function(channel, cb) { + WPXMLParseService.saveNewTopics = function(site, channel, cb) { pb.log.debug('WPXMLParseService: Parsing topics...'); //parse out the list of topics to try and persist @@ -183,6 +183,7 @@ module.exports = function WPXMLParseServiceModule(pb) { name: "wp:tag_name" } ]; + iterations.forEach(function(descriptor) { pb.log.silly('WPXMLParseService:Parsing Topics: Inspecting "%s" elements...', descriptor.element); @@ -220,7 +221,7 @@ module.exports = function WPXMLParseServiceModule(pb) { //get the topic formatted var topic = pb.DocumentCreator.create('topic', topics[topicKeys[i]]); - + topic.site = site; //ensure it doesn't already exist var key = 'name'; var val = new RegExp('^'+util.escapeRegExp(topic.name)+'$', 'ig'); From e0f42d594749d47be4182ae1cea6c38e49fb66e8 Mon Sep 17 00:00:00 2001 From: btidwell Date: Tue, 2 Jun 2015 09:39:44 -0400 Subject: [PATCH 236/790] apply site to MediaService when saving media in wp_import --- plugins/wp_import/services/wp_xml_parse.js | 30 +++++++++++----------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/plugins/wp_import/services/wp_xml_parse.js b/plugins/wp_import/services/wp_xml_parse.js index aa719f9d6..fc3867a0c 100644 --- a/plugins/wp_import/services/wp_xml_parse.js +++ b/plugins/wp_import/services/wp_xml_parse.js @@ -321,7 +321,7 @@ module.exports = function WPXMLParseServiceModule(pb) { //retrieve media content for page pb.log.debug('WPXMLParseService: Inspecting %s for media content', pageName); - self.retrieveMediaObjects(rawPage['content:encoded'][0], settings, function(err, updatedContent, mediaObjects) { + self.retrieveMediaObjects(site, rawPage['content:encoded'][0], settings, function(err, updatedContent, mediaObjects) { if (util.isError(err)) { pb.log.error('WPXMLParseService: Failed to retrieve 1 or more media objects for %s. %s', options.type, err.stack); } @@ -412,7 +412,7 @@ module.exports = function WPXMLParseServiceModule(pb) { //retrieve media content for article pb.log.debug('WPXMLParseService: Inspecting %s for media content', articleName); - self.retrieveMediaObjects(rawArticle['content:encoded'][0], settings, function(err, updatedContent, mediaObjects) { + self.retrieveMediaObjects(site, rawArticle['content:encoded'][0], settings, function(err, updatedContent, mediaObjects) { if (util.isError(err)) { pb.log.error('WPXMLParseService: Failed to retrieve 1 or more media objects for %s. %s', options.type, err.stack); } @@ -454,7 +454,7 @@ module.exports = function WPXMLParseServiceModule(pb) { async.series(tasks, cb); }; - WPXMLParseService.retrieveMediaObjects = function(content, settings, cb) { + WPXMLParseService.retrieveMediaObjects = function(site, content, settings, cb) { var handlers = [ { @@ -493,17 +493,17 @@ module.exports = function WPXMLParseServiceModule(pb) { }, getMediaObject: function(details, cb) { if(!settings.download_media) { - return WPXMLParseService.createMediaObject('image', details.source, cb); + return WPXMLParseService.createMediaObject(site, 'image', details.source, cb); } //download it & store it with the media service - WPXMLParseService.downloadMediaContent(details.source, function(err, location) { + WPXMLParseService.downloadMediaContent(site, details.source, function(err, location) { if (util.isError(err)) { return cb(err); } //create the media object - WPXMLParseService.createMediaObject('image', location, cb); + WPXMLParseService.createMediaObject(site, 'image', location, cb); }); } }, @@ -524,7 +524,7 @@ module.exports = function WPXMLParseServiceModule(pb) { }; }, getMediaObject: function(details, cb) { - WPXMLParseService.createMediaObject('youtube', details.source, cb); + WPXMLParseService.createMediaObject(site, 'youtube', details.source, cb); } }, { @@ -544,7 +544,7 @@ module.exports = function WPXMLParseServiceModule(pb) { }; }, getMediaObject: function(details, cb) { - WPXMLParseService.createMediaObject('daily_motion', details.source, cb); + WPXMLParseService.createMediaObject(site, 'daily_motion', details.source, cb); } } ]; @@ -585,7 +585,7 @@ module.exports = function WPXMLParseServiceModule(pb) { } //persist the media descriptor - var mediaService = new pb.MediaService(); + var mediaService = new pb.MediaService(null, site, true); mediaService.save(mediaObj, function(err, results) { if (util.isError(err)) { return callback(err); @@ -603,7 +603,7 @@ module.exports = function WPXMLParseServiceModule(pb) { }); }; - WPXMLParseService.createMediaObject = function(mediaType, location, cb) { + WPXMLParseService.createMediaObject = function(site, mediaType, location, cb) { var options = { where: { @@ -611,7 +611,7 @@ module.exports = function WPXMLParseServiceModule(pb) { }, limit: 1 }; - var mediaService = new pb.MediaService(); + var mediaService = new pb.MediaService(null, site, true); mediaService.get(options, function(err, mediaArray) { if (util.isError(err)) { return cb(err); @@ -637,7 +637,7 @@ module.exports = function WPXMLParseServiceModule(pb) { }); }; - WPXMLParseService.downloadMediaContent = function(srcString, cb) { + WPXMLParseService.downloadMediaContent = function(site, srcString, cb) { if (util.isNullOrUndefined(srcString) || srcString.indexOf('http') !== 0) { return cb(new Error('Invalid protocol on URI: '+srcString)); } @@ -649,7 +649,7 @@ module.exports = function WPXMLParseServiceModule(pb) { //create a functiont to download the content var run = function() { ht.get(srcString, function(res) { - WPXMLParseService.saveMediaContent(srcString, res, cb); + WPXMLParseService.saveMediaContent(site, srcString, res, cb); }); }; @@ -665,8 +665,8 @@ module.exports = function WPXMLParseServiceModule(pb) { }); }; - WPXMLParseService.saveMediaContent = function(originalFilename, stream, cb) { - var mediaService = new pb.MediaService(); + WPXMLParseService.saveMediaContent = function(site, originalFilename, stream, cb) { + var mediaService = new pb.MediaService(null, site, true); mediaService.setContentStream(stream, originalFilename, function(err, result) { cb(err, result ? result.mediaPath : null); }); From 42f2e07ceb8468ce39f1f76de998deb5a2579234 Mon Sep 17 00:00:00 2001 From: btidwell Date: Tue, 2 Jun 2015 10:21:55 -0400 Subject: [PATCH 237/790] Make Parse Service use prototype instance methods to make easier use of site and query service --- .../wp_import/controllers/import_action.js | 11 +-- plugins/wp_import/services/wp_xml_parse.js | 83 ++++++++++++------- 2 files changed, 57 insertions(+), 37 deletions(-) diff --git a/plugins/wp_import/controllers/import_action.js b/plugins/wp_import/controllers/import_action.js index e347876ac..a5446e5dc 100755 --- a/plugins/wp_import/controllers/import_action.js +++ b/plugins/wp_import/controllers/import_action.js @@ -23,7 +23,7 @@ module.exports = function ImportWPActionControllerModule(pb) { //pb dependencies var util = pb.util; - var wpXMLParse = pb.PluginService.getService('wp_xml_parse', 'wp_import'); + var WPXMLParseService = pb.PluginService.getService('wp_xml_parse', 'wp_import'); /** * @class ImportWPActionController @@ -41,7 +41,7 @@ module.exports = function ImportWPActionControllerModule(pb) { ImportWPActionController.prototype.render = function(cb) { var self = this; var files = []; - + var wpXMLParse = new WPXMLParseService(this.site); var form = new formidable.IncomingForm(); form.on('file', function(field, file) { files.push(file); @@ -59,12 +59,7 @@ module.exports = function ImportWPActionControllerModule(pb) { return; } - var parseData = { - data:data.toString(), - site:self.site - }; - - wpXMLParse.parse(parseData, self.session.authentication.user_id, function(err, users) { + wpXMLParse.parse(data.toString(), self.session.authentication.user_id, function(err, users) { if(util.isError(err)) { self.session.error = err.stack; return cb({content: pb.BaseController.apiResponse(pb.BaseController.API_FAILURE, self.ls.get('ERROR_SAVING'))}); diff --git a/plugins/wp_import/services/wp_xml_parse.js b/plugins/wp_import/services/wp_xml_parse.js index fc3867a0c..816111a6a 100644 --- a/plugins/wp_import/services/wp_xml_parse.js +++ b/plugins/wp_import/services/wp_xml_parse.js @@ -32,7 +32,10 @@ module.exports = function WPXMLParseServiceModule(pb) { * @class WPXMLParseService * @constructor */ - function WPXMLParseService() {} + function WPXMLParseService(site) { + this.site = pb.SiteService.getCurrentSite(site); + this.siteQueryService = new pb.SiteQueryService(this.site, true); + } /** * Counter used to help create a random values for required fields when no @@ -44,6 +47,16 @@ module.exports = function WPXMLParseServiceModule(pb) { */ var DEFAULT_COUNTER = 0; + /** + * The name the service + * @private + * @static + * @readonly + * @property SERVICE_NAME + * @type {String} + */ + var SERVICE_NAME = 'wp_xml_parse'; + /** * @static * @method init @@ -53,9 +66,21 @@ module.exports = function WPXMLParseServiceModule(pb) { cb(null, true); }; - WPXMLParseService.parse = function(data, defaultUserId, cb) { - var xmlString = data.data; - var site = data.site; + /** + * A service interface function designed to allow developers to name the handle + * to the service object what ever they desire. The function must return a + * valid string and must not conflict with the names of other services for the + * plugin that the service is associated with. + * + * @static + * @method getName + * @return {String} The service name + */ + WPXMLParseService.getName = function() { + return SERVICE_NAME; + }; + + WPXMLParseService.prototype.parse = function(xmlString, defaultUserId, cb) { var self = this; pb.log.debug('WPXMLParseService: Starting to parse...'); @@ -73,7 +98,7 @@ module.exports = function WPXMLParseServiceModule(pb) { //load settings function(callback) { - var pluginService = new pb.PluginService(site); + var pluginService = new pb.PluginService(self.site); pluginService.getSettingsKV('wp_import', function(err, settingsResult) { settings = settingsResult; callback(err); @@ -88,14 +113,14 @@ module.exports = function WPXMLParseServiceModule(pb) { }, function(callback) { - self.saveNewTopics(site, channel, function(err, topicsResult) { + self.saveNewTopics(channel, function(err, topicsResult) { topics = topicsResult; callback(err); }); }, function(callback) { - self.saveNewArticlesAndPages(site, defaultUserId, channel, users, topics, settings, callback); + self.saveNewArticlesAndPages(self.site, defaultUserId, channel, users, topics, settings, callback); } ]; async.series(tasks, function(err, results) { @@ -104,7 +129,7 @@ module.exports = function WPXMLParseServiceModule(pb) { }); }; - WPXMLParseService.saveNewUsers = function(channel, settings, cb) { + WPXMLParseService.prototype.saveNewUsers = function(channel, settings, cb) { pb.log.debug('WPXMLParseService: Parsing Users...'); var self = this; @@ -168,7 +193,8 @@ module.exports = function WPXMLParseServiceModule(pb) { async.series(tasks, cb); }; - WPXMLParseService.saveNewTopics = function(site, channel, cb) { + WPXMLParseService.prototype.saveNewTopics = function(channel, cb) { + var self = this; pb.log.debug('WPXMLParseService: Parsing topics...'); //parse out the list of topics to try and persist @@ -221,12 +247,10 @@ module.exports = function WPXMLParseServiceModule(pb) { //get the topic formatted var topic = pb.DocumentCreator.create('topic', topics[topicKeys[i]]); - topic.site = site; //ensure it doesn't already exist var key = 'name'; var val = new RegExp('^'+util.escapeRegExp(topic.name)+'$', 'ig'); - var dao = new pb.DAO(); - dao.loadByValue(key, val, 'topic', function(err, existingTopic) { + self.siteQueryService.loadByValue(key, val, 'topic', function(err, existingTopic) { if (util.isError(err)) { return callback(err); } @@ -236,7 +260,7 @@ module.exports = function WPXMLParseServiceModule(pb) { } //we're all good. we can persist now - dao.save(topic, function(err, result) { + self.siteQueryService.save(topic, function(err, result) { if (util.isError(err)) { return callback(err); } @@ -250,7 +274,7 @@ module.exports = function WPXMLParseServiceModule(pb) { async.parallel(tasks, cb); }; - WPXMLParseService.saveNewArticlesAndPages = function(site, defaultUserId, channel, users, topics, settings, cb) { + WPXMLParseService.prototype.saveNewArticlesAndPages = function(site, defaultUserId, channel, users, topics, settings, cb) { var self = this; var rawArticles = []; var rawPages = []; @@ -336,7 +360,7 @@ module.exports = function WPXMLParseServiceModule(pb) { } //construct the page descriptor - var title = BaseController.sanitize(rawPage.title[0]) || WPXMLParseService.uniqueStrVal('Page'); + var title = BaseController.sanitize(rawPage.title[0]) || self.uniqueStrVal('Page'); var pagedoc = { url: pageName, headline: title, @@ -362,7 +386,7 @@ module.exports = function WPXMLParseServiceModule(pb) { var rawArticle = rawArticles[index]; var articleName = rawArticle['wp:post_name'][0] || rawArticle.title[0]; if (util.isNullOrUndefined(articleName) || articleName === '') { - articleName = WPXMLParseService.uniqueStrVal('article'); + articleName = self.uniqueStrVal('article'); }; //output progress @@ -427,7 +451,7 @@ module.exports = function WPXMLParseServiceModule(pb) { } //construct the article descriptor - var title = BaseController.sanitize(rawArticle.title[0]) || WPXMLParseService.uniqueStrVal('Article'); + var title = BaseController.sanitize(rawArticle.title[0]) || self.uniqueStrVal('Article'); var articleDoc = { url: articleName, headline: title, @@ -454,8 +478,8 @@ module.exports = function WPXMLParseServiceModule(pb) { async.series(tasks, cb); }; - WPXMLParseService.retrieveMediaObjects = function(site, content, settings, cb) { - + WPXMLParseService.prototype.retrieveMediaObjects = function(site, content, settings, cb) { + var self = this; var handlers = [ { name: 'image', @@ -493,17 +517,17 @@ module.exports = function WPXMLParseServiceModule(pb) { }, getMediaObject: function(details, cb) { if(!settings.download_media) { - return WPXMLParseService.createMediaObject(site, 'image', details.source, cb); + return self.createMediaObject(site, 'image', details.source, cb); } //download it & store it with the media service - WPXMLParseService.downloadMediaContent(site, details.source, function(err, location) { + self.downloadMediaContent(site, details.source, function(err, location) { if (util.isError(err)) { return cb(err); } //create the media object - WPXMLParseService.createMediaObject(site, 'image', location, cb); + self.createMediaObject(site, 'image', location, cb); }); } }, @@ -524,7 +548,7 @@ module.exports = function WPXMLParseServiceModule(pb) { }; }, getMediaObject: function(details, cb) { - WPXMLParseService.createMediaObject(site, 'youtube', details.source, cb); + self.createMediaObject(site, 'youtube', details.source, cb); } }, { @@ -544,7 +568,7 @@ module.exports = function WPXMLParseServiceModule(pb) { }; }, getMediaObject: function(details, cb) { - WPXMLParseService.createMediaObject(site, 'daily_motion', details.source, cb); + self.createMediaObject(site, 'daily_motion', details.source, cb); } } ]; @@ -603,7 +627,7 @@ module.exports = function WPXMLParseServiceModule(pb) { }); }; - WPXMLParseService.createMediaObject = function(site, mediaType, location, cb) { + WPXMLParseService.prototype.createMediaObject = function(site, mediaType, location, cb) { var options = { where: { @@ -637,7 +661,8 @@ module.exports = function WPXMLParseServiceModule(pb) { }); }; - WPXMLParseService.downloadMediaContent = function(site, srcString, cb) { + WPXMLParseService.prototype.downloadMediaContent = function(site, srcString, cb) { + var self = this; if (util.isNullOrUndefined(srcString) || srcString.indexOf('http') !== 0) { return cb(new Error('Invalid protocol on URI: '+srcString)); } @@ -649,7 +674,7 @@ module.exports = function WPXMLParseServiceModule(pb) { //create a functiont to download the content var run = function() { ht.get(srcString, function(res) { - WPXMLParseService.saveMediaContent(site, srcString, res, cb); + self.saveMediaContent(site, srcString, res, cb); }); }; @@ -665,14 +690,14 @@ module.exports = function WPXMLParseServiceModule(pb) { }); }; - WPXMLParseService.saveMediaContent = function(site, originalFilename, stream, cb) { + WPXMLParseService.prototype.saveMediaContent = function(site, originalFilename, stream, cb) { var mediaService = new pb.MediaService(null, site, true); mediaService.setContentStream(stream, originalFilename, function(err, result) { cb(err, result ? result.mediaPath : null); }); }; - WPXMLParseService.uniqueStrVal = function(prefix) { + WPXMLParseService.prototype.uniqueStrVal = function(prefix) { return prefix + '-' + (DEFAULT_COUNTER++) + '-' + (new Date()).getTime(); }; From 5963a4063942f5ff4d6e8f310c6046c8679fc668 Mon Sep 17 00:00:00 2001 From: btidwell Date: Tue, 2 Jun 2015 10:31:25 -0400 Subject: [PATCH 238/790] remove site param and use site query service in save articles and pages function --- plugins/wp_import/services/wp_xml_parse.js | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/plugins/wp_import/services/wp_xml_parse.js b/plugins/wp_import/services/wp_xml_parse.js index 816111a6a..4a12194e6 100644 --- a/plugins/wp_import/services/wp_xml_parse.js +++ b/plugins/wp_import/services/wp_xml_parse.js @@ -120,7 +120,7 @@ module.exports = function WPXMLParseServiceModule(pb) { }, function(callback) { - self.saveNewArticlesAndPages(self.site, defaultUserId, channel, users, topics, settings, callback); + self.saveNewArticlesAndPages(defaultUserId, channel, users, topics, settings, callback); } ]; async.series(tasks, function(err, results) { @@ -274,7 +274,7 @@ module.exports = function WPXMLParseServiceModule(pb) { async.parallel(tasks, cb); }; - WPXMLParseService.prototype.saveNewArticlesAndPages = function(site, defaultUserId, channel, users, topics, settings, cb) { + WPXMLParseService.prototype.saveNewArticlesAndPages = function(defaultUserId, channel, users, topics, settings, cb) { var self = this; var rawArticles = []; var rawPages = []; @@ -319,7 +319,7 @@ module.exports = function WPXMLParseServiceModule(pb) { type: 'page', url: pageName, }; - var urlService = new pb.UrlService(); + var urlService = new pb.UrlService(self.site, true); urlService.existsForType(options, function(err, exists) { if (util.isError(err)) { return callback(err); @@ -345,7 +345,7 @@ module.exports = function WPXMLParseServiceModule(pb) { //retrieve media content for page pb.log.debug('WPXMLParseService: Inspecting %s for media content', pageName); - self.retrieveMediaObjects(site, rawPage['content:encoded'][0], settings, function(err, updatedContent, mediaObjects) { + self.retrieveMediaObjects(self.site, rawPage['content:encoded'][0], settings, function(err, updatedContent, mediaObjects) { if (util.isError(err)) { pb.log.error('WPXMLParseService: Failed to retrieve 1 or more media objects for %s. %s', options.type, err.stack); } @@ -372,9 +372,7 @@ module.exports = function WPXMLParseServiceModule(pb) { author: defaultUserId } var newPage = pb.DocumentCreator.create('page', pagedoc); - newPage.site = site; - var dao = new pb.DAO(); - dao.save(newPage, callback); + self.siteQueryService.save(newPage, callback); }); }); }; @@ -397,7 +395,7 @@ module.exports = function WPXMLParseServiceModule(pb) { type: 'article', url: articleName, }; - var urlService = new pb.UrlService(); + var urlService = new pb.UrlService(self.site, true); urlService.existsForType(options, function(err, exists) { if (util.isError(err)) { return callback(err); @@ -436,7 +434,7 @@ module.exports = function WPXMLParseServiceModule(pb) { //retrieve media content for article pb.log.debug('WPXMLParseService: Inspecting %s for media content', articleName); - self.retrieveMediaObjects(site, rawArticle['content:encoded'][0], settings, function(err, updatedContent, mediaObjects) { + self.retrieveMediaObjects(self.site, rawArticle['content:encoded'][0], settings, function(err, updatedContent, mediaObjects) { if (util.isError(err)) { pb.log.error('WPXMLParseService: Failed to retrieve 1 or more media objects for %s. %s', options.type, err.stack); } @@ -464,9 +462,7 @@ module.exports = function WPXMLParseServiceModule(pb) { author: author }; var newArticle = pb.DocumentCreator.create('article', articleDoc); - newArticle.site = site; - var dao = new pb.DAO(); - dao.save(newArticle, callback); + self.siteQueryService.save(newArticle, callback); }); }); }; From af6fccd4674e4a2d7fe7773f2b1d6246efc3316e Mon Sep 17 00:00:00 2001 From: btidwell Date: Tue, 2 Jun 2015 11:04:11 -0400 Subject: [PATCH 239/790] use self.site for media instead of param site. --- plugins/wp_import/services/wp_xml_parse.js | 30 +++++++++++----------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/plugins/wp_import/services/wp_xml_parse.js b/plugins/wp_import/services/wp_xml_parse.js index 4a12194e6..14c35363b 100644 --- a/plugins/wp_import/services/wp_xml_parse.js +++ b/plugins/wp_import/services/wp_xml_parse.js @@ -345,7 +345,7 @@ module.exports = function WPXMLParseServiceModule(pb) { //retrieve media content for page pb.log.debug('WPXMLParseService: Inspecting %s for media content', pageName); - self.retrieveMediaObjects(self.site, rawPage['content:encoded'][0], settings, function(err, updatedContent, mediaObjects) { + self.retrieveMediaObjects(rawPage['content:encoded'][0], settings, function(err, updatedContent, mediaObjects) { if (util.isError(err)) { pb.log.error('WPXMLParseService: Failed to retrieve 1 or more media objects for %s. %s', options.type, err.stack); } @@ -434,7 +434,7 @@ module.exports = function WPXMLParseServiceModule(pb) { //retrieve media content for article pb.log.debug('WPXMLParseService: Inspecting %s for media content', articleName); - self.retrieveMediaObjects(self.site, rawArticle['content:encoded'][0], settings, function(err, updatedContent, mediaObjects) { + self.retrieveMediaObjects(rawArticle['content:encoded'][0], settings, function(err, updatedContent, mediaObjects) { if (util.isError(err)) { pb.log.error('WPXMLParseService: Failed to retrieve 1 or more media objects for %s. %s', options.type, err.stack); } @@ -474,7 +474,7 @@ module.exports = function WPXMLParseServiceModule(pb) { async.series(tasks, cb); }; - WPXMLParseService.prototype.retrieveMediaObjects = function(site, content, settings, cb) { + WPXMLParseService.prototype.retrieveMediaObjects = function(content, settings, cb) { var self = this; var handlers = [ { @@ -513,17 +513,17 @@ module.exports = function WPXMLParseServiceModule(pb) { }, getMediaObject: function(details, cb) { if(!settings.download_media) { - return self.createMediaObject(site, 'image', details.source, cb); + return self.createMediaObject('image', details.source, cb); } //download it & store it with the media service - self.downloadMediaContent(site, details.source, function(err, location) { + self.downloadMediaContent(details.source, function(err, location) { if (util.isError(err)) { return cb(err); } //create the media object - self.createMediaObject(site, 'image', location, cb); + self.createMediaObject('image', location, cb); }); } }, @@ -544,7 +544,7 @@ module.exports = function WPXMLParseServiceModule(pb) { }; }, getMediaObject: function(details, cb) { - self.createMediaObject(site, 'youtube', details.source, cb); + self.createMediaObject('youtube', details.source, cb); } }, { @@ -564,7 +564,7 @@ module.exports = function WPXMLParseServiceModule(pb) { }; }, getMediaObject: function(details, cb) { - self.createMediaObject(site, 'daily_motion', details.source, cb); + self.createMediaObject('daily_motion', details.source, cb); } } ]; @@ -605,7 +605,7 @@ module.exports = function WPXMLParseServiceModule(pb) { } //persist the media descriptor - var mediaService = new pb.MediaService(null, site, true); + var mediaService = new pb.MediaService(null, self.site, true); mediaService.save(mediaObj, function(err, results) { if (util.isError(err)) { return callback(err); @@ -623,7 +623,7 @@ module.exports = function WPXMLParseServiceModule(pb) { }); }; - WPXMLParseService.prototype.createMediaObject = function(site, mediaType, location, cb) { + WPXMLParseService.prototype.createMediaObject = function(mediaType, location, cb) { var options = { where: { @@ -631,7 +631,7 @@ module.exports = function WPXMLParseServiceModule(pb) { }, limit: 1 }; - var mediaService = new pb.MediaService(null, site, true); + var mediaService = new pb.MediaService(null, this.site, true); mediaService.get(options, function(err, mediaArray) { if (util.isError(err)) { return cb(err); @@ -657,7 +657,7 @@ module.exports = function WPXMLParseServiceModule(pb) { }); }; - WPXMLParseService.prototype.downloadMediaContent = function(site, srcString, cb) { + WPXMLParseService.prototype.downloadMediaContent = function(srcString, cb) { var self = this; if (util.isNullOrUndefined(srcString) || srcString.indexOf('http') !== 0) { return cb(new Error('Invalid protocol on URI: '+srcString)); @@ -670,7 +670,7 @@ module.exports = function WPXMLParseServiceModule(pb) { //create a functiont to download the content var run = function() { ht.get(srcString, function(res) { - self.saveMediaContent(site, srcString, res, cb); + self.saveMediaContent(srcString, res, cb); }); }; @@ -686,8 +686,8 @@ module.exports = function WPXMLParseServiceModule(pb) { }); }; - WPXMLParseService.prototype.saveMediaContent = function(site, originalFilename, stream, cb) { - var mediaService = new pb.MediaService(null, site, true); + WPXMLParseService.prototype.saveMediaContent = function(originalFilename, stream, cb) { + var mediaService = new pb.MediaService(null, this.site, true); mediaService.setContentStream(stream, originalFilename, function(err, result) { cb(err, result ? result.mediaPath : null); }); From 8d73116b985655102cc92cbd97e584a8b16caab1 Mon Sep 17 00:00:00 2001 From: Christina Chatham Date: Tue, 2 Jun 2015 11:40:03 -0400 Subject: [PATCH 240/790] Update permissions map to respect siteid. --- .../pencilblue/controllers/admin/users/permissions.js | 9 +++++---- plugins/pencilblue/include/multisite_admin_routes.js | 7 +++++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/plugins/pencilblue/controllers/admin/users/permissions.js b/plugins/pencilblue/controllers/admin/users/permissions.js index 666b5db37..d2c797f1c 100755 --- a/plugins/pencilblue/controllers/admin/users/permissions.js +++ b/plugins/pencilblue/controllers/admin/users/permissions.js @@ -19,13 +19,13 @@ module.exports = function(pb) { //pb dependencies var util = pb.util; - var BaseController = pb.BaseController; + var BaseAdminController = pb.BaseAdminController; /** * Interface for displaying how a plugin's user permissions are organized */ function PermissionsMapController(){} - util.inherits(PermissionsMapController, BaseController); + util.inherits(PermissionsMapController, BaseAdminController); PermissionsMapController.prototype.render = function(cb) { var self = this; @@ -65,12 +65,12 @@ module.exports = function(pb) { name: 'permissions', title: self.ls.get('PERMISSIONS'), icon: 'refresh', - href: '/admin/users/permissions' + href: '/admin' + self.sitePrefix + '/users/permissions' }, { name: 'manage_plugins', title: self.ls.get('MANAGE_PLUGINS'), icon: 'puzzle-piece', - href: '/admin/plugins' + href: '/admin' + self.sitePrefix + '/plugins' }]; var angularObjects = pb.ClientJs.getAngularObjects({ @@ -78,6 +78,7 @@ module.exports = function(pb) { pills: pills, roles: roleDNs, permissions: permissions, + sitePrefix: self.sitePrefix }); //render page diff --git a/plugins/pencilblue/include/multisite_admin_routes.js b/plugins/pencilblue/include/multisite_admin_routes.js index 426fcffdc..a923a61ee 100644 --- a/plugins/pencilblue/include/multisite_admin_routes.js +++ b/plugins/pencilblue/include/multisite_admin_routes.js @@ -615,6 +615,13 @@ module.exports = function Routes(pb){ access_level: pb.SecurityService.ACCESS_EDITOR, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'users', 'unverified_users.js') }, + { + method: 'get', + path: "/admin/:siteid/users/permissions", + auth_required: true, + access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'users', 'permissions.js') + }, { method: 'get', path: "/admin/:siteid/users/new", From a496f28d6d6278820c758c6a9300897dcb5774bc Mon Sep 17 00:00:00 2001 From: Christina Chatham Date: Tue, 2 Jun 2015 11:42:27 -0400 Subject: [PATCH 241/790] fixing unverified users. --- .../pencilblue/controllers/admin/users/unverified_users.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/plugins/pencilblue/controllers/admin/users/unverified_users.js b/plugins/pencilblue/controllers/admin/users/unverified_users.js index 4cd2f0291..37a27e4e0 100644 --- a/plugins/pencilblue/controllers/admin/users/unverified_users.js +++ b/plugins/pencilblue/controllers/admin/users/unverified_users.js @@ -38,14 +38,15 @@ module.exports = function(pb) { self.siteQueryService.q('unverified_user', opts, function(err, users) { if(util.isError(err)) { - return self.redirect('/admin', cb); + return self.redirect('/admin' + self.sitePrefix, cb); } var angularObjects = pb.ClientJs.getAngularObjects( { navigation: pb.AdminNavigation.get(self.session, ['users', 'manage'], self.ls), pills: pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, SUB_NAV_KEY, { sitePrefix: self.sitePrefix }), - users: users + users: users, + sitePrefix: self.sitePrefix }); self.setPageName(self.ls.get('UNVERIFIED_USERS')); From 4fd0acb6c4d1bb47a06a86ee48a82927944f3643 Mon Sep 17 00:00:00 2001 From: andparker Date: Tue, 2 Jun 2015 12:35:10 -0400 Subject: [PATCH 242/790] Temporary bug fix until we resolve site from hostname. --- controllers/admin/admin_form_controller.js | 1 + 1 file changed, 1 insertion(+) diff --git a/controllers/admin/admin_form_controller.js b/controllers/admin/admin_form_controller.js index 74ea9f9ab..fcfebc0e8 100644 --- a/controllers/admin/admin_form_controller.js +++ b/controllers/admin/admin_form_controller.js @@ -32,6 +32,7 @@ module.exports = function AdminFormControllerModule(pb) { */ AdminFormController.prototype.init = function (props, cb) { var self = this; + self.pathSiteUId = pb.SiteService.getCurrentSite(props.path_vars.siteid); pb.FormController.prototype.init.call(self, props, function () { BaseAdminController.prototype.extendedInit.call(self, cb); }); From e1c3ae5a1ffc139ed225772d02c983c499929b59 Mon Sep 17 00:00:00 2001 From: btidwell Date: Tue, 2 Jun 2015 13:59:19 -0400 Subject: [PATCH 243/790] use site when getting service for plugin --- plugins/wp_import/controllers/import_action.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/wp_import/controllers/import_action.js b/plugins/wp_import/controllers/import_action.js index a5446e5dc..b91a6865e 100755 --- a/plugins/wp_import/controllers/import_action.js +++ b/plugins/wp_import/controllers/import_action.js @@ -23,7 +23,6 @@ module.exports = function ImportWPActionControllerModule(pb) { //pb dependencies var util = pb.util; - var WPXMLParseService = pb.PluginService.getService('wp_xml_parse', 'wp_import'); /** * @class ImportWPActionController @@ -41,6 +40,7 @@ module.exports = function ImportWPActionControllerModule(pb) { ImportWPActionController.prototype.render = function(cb) { var self = this; var files = []; + var WPXMLParseService = pb.PluginService.getService('wp_xml_parse', 'wp_import', this.site); var wpXMLParse = new WPXMLParseService(this.site); var form = new formidable.IncomingForm(); form.on('file', function(field, file) { From f2a206e1c17441ccf2144488d6c94b11a362d743 Mon Sep 17 00:00:00 2001 From: Christina Chatham Date: Tue, 2 Jun 2015 14:12:26 -0400 Subject: [PATCH 244/790] user manage and change password site aware --- .../actions/user/manage_account/change_password.js | 6 +++--- .../actions/user/manage_account/profile.js | 6 +++--- .../pencilblue/controllers/user/change_password.js | 12 ++++++++++-- .../pencilblue/controllers/user/manage_account.js | 13 +++++++++++-- 4 files changed, 27 insertions(+), 10 deletions(-) diff --git a/plugins/pencilblue/controllers/actions/user/manage_account/change_password.js b/plugins/pencilblue/controllers/actions/user/manage_account/change_password.js index fd6559db0..23ffbcf0e 100755 --- a/plugins/pencilblue/controllers/actions/user/manage_account/change_password.js +++ b/plugins/pencilblue/controllers/actions/user/manage_account/change_password.js @@ -63,15 +63,15 @@ module.exports = function(pb) { delete post.new_password; delete post.confirm_password; - var dao = new pb.DAO(); - dao.loadByValues(where, 'user', function(err, user) { + var siteQueryService = new pb.SiteQueryService(self.site, true); + siteQueryService.loadByValues(where, 'user', function(err, user) { if(util.isError(err) || user === null) { self.formError(self.ls.get('INVALID_PASSWORD'), '/user/change_password', cb); return; } pb.DocumentCreator.update(post, user); - dao.save(user, function(err, result) { + siteQueryService.save(user, function(err, result) { if(util.isError(err)) { return self.formError(self.ls.get('ERROR_SAVING'), '/user/change_password', cb); } diff --git a/plugins/pencilblue/controllers/actions/user/manage_account/profile.js b/plugins/pencilblue/controllers/actions/user/manage_account/profile.js index d0384b007..03a3c1c7b 100755 --- a/plugins/pencilblue/controllers/actions/user/manage_account/profile.js +++ b/plugins/pencilblue/controllers/actions/user/manage_account/profile.js @@ -43,8 +43,8 @@ module.exports = function ProfileModule(pb) { post.position = BaseController.sanitize(post.position); post.photo = BaseController.sanitize(post.photo); - var dao = new pb.DAO(); - dao.loadById(self.session.authentication.user_id, 'user', function(err, user) { + var siteQueryService = new pb.SiteQueryService(self.site, true); + siteQueryService.loadById(self.session.authentication.user_id, 'user', function(err, user) { if(util.isError(err) || user === null) { self.formError(self.ls.get('ERROR_SAVING'), '/user/manage_account', cb); return; @@ -52,7 +52,7 @@ module.exports = function ProfileModule(pb) { //update the document pb.DocumentCreator.update(post, user); - dao.save(user, function(err, result) { + siteQueryService.save(user, function(err, result) { if(util.isError(err)) { return self.formError(self.ls.get('ERROR_SAVING'), '/user/manage_account', cb); } diff --git a/plugins/pencilblue/controllers/user/change_password.js b/plugins/pencilblue/controllers/user/change_password.js index f3b228ff0..5dd6ed599 100755 --- a/plugins/pencilblue/controllers/user/change_password.js +++ b/plugins/pencilblue/controllers/user/change_password.js @@ -29,6 +29,15 @@ module.exports = function ChangePasswordFormControllerModule(pb) { function ChangePasswordFormController(){} util.inherits(ChangePasswordFormController, pb.FormController); + ChangePasswordFormController.prototype.init = function (props, cb) { + var self = this; + + pb.BaseController.prototype.init.call(self, props, function () { + self.siteQueryService = new pb.SiteQueryService(self.site, true); + cb(); + }); + }; + /** * * @method render @@ -38,8 +47,7 @@ module.exports = function ChangePasswordFormControllerModule(pb) { var self = this; //retrieve user - var dao = new pb.DAO(); - dao.loadById(self.session.authentication.user_id, 'user', function(err, user) { + self.siteQueryService.loadById(self.session.authentication.user_id, 'user', function(err, user) { if(util.isError(err) || user === null) { self.redirect('/', cb); return; diff --git a/plugins/pencilblue/controllers/user/manage_account.js b/plugins/pencilblue/controllers/user/manage_account.js index b3e942e88..a863b25a1 100755 --- a/plugins/pencilblue/controllers/user/manage_account.js +++ b/plugins/pencilblue/controllers/user/manage_account.js @@ -26,12 +26,21 @@ module.exports = function ManageAccountModule(pb) { function ManageAccount(){} util.inherits(ManageAccount, pb.FormController); + ManageAccount.prototype.init = function (props, cb) { + var self = this; + + pb.BaseController.prototype.init.call(self, props, function () { + self.siteQueryService = new pb.SiteQueryService(self.site, true); + cb(); + }); + }; + ManageAccount.prototype.render = function(cb) { var self = this; - var dao = new pb.DAO(); - dao.loadById(self.session.authentication.user_id, 'user', function(err, user) { + self.siteQueryService.loadById(self.session.authentication.user_id, 'user', function(err, user) { if(util.isError(err) || user === null) { + if (err) { pb.log.error(err); } self.redirect('/', cb); return; } From 5afaac50034918d9f85b4d6083368183212505d0 Mon Sep 17 00:00:00 2001 From: Christina Chatham Date: Tue, 2 Jun 2015 14:23:02 -0400 Subject: [PATCH 245/790] user actions dao made site aware --- .../actions/user/resend_verification.js | 8 +++---- .../actions/user/reset_password.js | 8 +++---- .../controllers/actions/user/sign_up.js | 24 ++++++++++++------- .../controllers/actions/user/verify_email.js | 10 ++++---- 4 files changed, 29 insertions(+), 21 deletions(-) diff --git a/plugins/pencilblue/controllers/actions/user/resend_verification.js b/plugins/pencilblue/controllers/actions/user/resend_verification.js index 3a81fbfe0..e34794916 100755 --- a/plugins/pencilblue/controllers/actions/user/resend_verification.js +++ b/plugins/pencilblue/controllers/actions/user/resend_verification.js @@ -36,14 +36,14 @@ module.exports = function ResendVerificationModule(pb) { return; } - var dao = new pb.DAO(); - dao.loadByValue('email', post.email, 'user', function(err, user) { + var siteQueryService = new pb.SiteQueryService(self.site, true); + siteQueryService.loadByValue('email', post.email, 'user', function(err, user) { if(util.isError(err) || user === null) { self.formError(self.ls.get('USER_VERIFIED'), '/user/login', cb); return; } - dao.loadByValue('email', post.email, 'unverified_user', function(err, user) { + siteQueryService.loadByValue('email', post.email, 'unverified_user', function(err, user) { if(util.isError(err) || user === null) { self.formError(self.ls.get('NOT_REGISTERED'), '/user/sign_up', cb); return; @@ -51,7 +51,7 @@ module.exports = function ResendVerificationModule(pb) { user.verification_code = util.uniqueId(); - dao.save(user, function(err, result) { + siteQueryService.save(user, function(err, result) { if(util.isError(result)) { self.formError(self.ls.get('ERROR_SAVING'), '/user/resend_verification', cb); return; diff --git a/plugins/pencilblue/controllers/actions/user/reset_password.js b/plugins/pencilblue/controllers/actions/user/reset_password.js index 99022b909..5f43fb17a 100755 --- a/plugins/pencilblue/controllers/actions/user/reset_password.js +++ b/plugins/pencilblue/controllers/actions/user/reset_password.js @@ -35,14 +35,14 @@ module.exports = function ResetPasswordModule(pb) { return; } - var dao = new pb.DAO(); - dao.loadByValue('email', get.email, 'user', function(err, user) { + var siteQueryService = new pb.SiteQueryService(self.site, true); + siteQueryService.loadByValue('email', get.email, 'user', function(err, user) { if(user === null) { self.formError(self.ls.get('INVALID_VERIFICATION'), '/user/login', cb); return; } - dao.loadByValue('user_id', user[pb.DAO.getIdField()].toString(), 'password_reset', function(err, passwordReset) { + siteQueryService.loadByValue('user_id', user[pb.DAO.getIdField()].toString(), 'password_reset', function(err, passwordReset) { if(passwordReset === null) { self.formError(self.ls.get('INVALID_VERIFICATION'), '/user/login', cb); return; @@ -54,7 +54,7 @@ module.exports = function ResetPasswordModule(pb) { } // delete the password reset token - dao.deleteById(passwordReset[pb.DAO.getIdField()], 'password_reset', function(err, result) { + siteQueryService.deleteById(passwordReset[pb.DAO.getIdField()], 'password_reset', function(err, result) { //log the user in self.session.authentication.user = user; self.session.authentication.user_id = user[pb.DAO.getIdField()].toString(); diff --git a/plugins/pencilblue/controllers/actions/user/sign_up.js b/plugins/pencilblue/controllers/actions/user/sign_up.js index b84c85411..3d957dfdd 100755 --- a/plugins/pencilblue/controllers/actions/user/sign_up.js +++ b/plugins/pencilblue/controllers/actions/user/sign_up.js @@ -31,6 +31,16 @@ module.exports = function SignUpModule(pb) { function SignUp(){} util.inherits(SignUp, FormController); + SignUp.prototype.init = function (props, cb) { + var self = this; + + pb.BaseController.prototype.init.call(self, props, function () { + self.siteQueryService = new pb.SiteQueryService(self.site, true); + cb(); + }); + }; + + SignUp.prototype.onPostParamsRetrieved = function(post, cb) { var self = this; @@ -84,10 +94,9 @@ module.exports = function SignUpModule(pb) { return; } - var dao = new pb.DAO(); - dao.save(user, function(err, data) { + self.siteQueryService.save(user, function(err, data) { if(util.isError(err)) { - return self.formError(request, session, self.ls.get('ERROR_SAVING'), '/user/sign_up', cb); + return self.formError(self.ls.get('ERROR_SAVING'), '/user/sign_up', cb); } self.session.success = successMsg; @@ -107,19 +116,18 @@ module.exports = function SignUpModule(pb) { }; SignUp.prototype.validateUniques = function(user, cb) { - var dao = new pb.DAO(); var tasks = { verified_username: function(callback) { - dao.count('user', {username: user.username}, callback); + self.siteQueryService.count('user', {username: user.username}, callback); }, verified_email: function(callback) { - dao.count('user', {email: user.email}, callback); + self.siteQueryService.count('user', {email: user.email}, callback); }, unverified_username: function(callback) { - dao.count('unverified_user', {username: user.username}, callback); + self.siteQueryService.count('unverified_user', {username: user.username}, callback); }, unverified_email: function(callback) { - dao.count('unverified_user', {email: user.email}, callback); + self.siteQueryService.count('unverified_user', {email: user.email}, callback); } }; async.series(tasks, cb); diff --git a/plugins/pencilblue/controllers/actions/user/verify_email.js b/plugins/pencilblue/controllers/actions/user/verify_email.js index 630cce938..e08c80c1d 100755 --- a/plugins/pencilblue/controllers/actions/user/verify_email.js +++ b/plugins/pencilblue/controllers/actions/user/verify_email.js @@ -35,14 +35,14 @@ module.exports = function VerifyEmailModule(pb) { return; } - var dao = new pb.DAO(); - dao.count('user', {email: get.email}, function(err, count) { + var siteQueryService = new pb.SiteQueryService(self.site, true); + siteQueryService.count('user', {email: get.email}, function(err, count) { if(count > 0) { self.formError(self.ls.get('USER_VERIFIED'), '/user/login', cb); return; } - dao.loadByValue('email', get.email, 'unverified_user', function(err, unverifiedUser) { + siteQueryService.loadByValue('email', get.email, 'unverified_user', function(err, unverifiedUser) { if(unverifiedUser === null) { self.formError(self.ls.get('NOT_REGISTERED'), '/user/sign_up', cb); return; @@ -53,7 +53,7 @@ module.exports = function VerifyEmailModule(pb) { return; } - dao.deleteById(unverifiedUser[pb.DAO.getIdField()], 'unverified_user', function(err, result) { + siteQueryService.deleteById(unverifiedUser[pb.DAO.getIdField()], 'unverified_user', function(err, result) { //TODO handle error //convert to user @@ -61,7 +61,7 @@ module.exports = function VerifyEmailModule(pb) { delete user[pb.DAO.getIdField()]; user.object_type = 'user'; - dao.save(user, function(err, result) { + siteQueryService.save(user, function(err, result) { if(util.isError(err)) { return self.formError(self.ls.get('ERROR_SAVING'), '/user/sign_up', cb); } From 3fb6909e2c6cfc061a34287a095053a12338a241 Mon Sep 17 00:00:00 2001 From: btidwell Date: Tue, 2 Jun 2015 14:41:15 -0400 Subject: [PATCH 246/790] use siteQueryService for saving user on wp_import. --- plugins/wp_import/services/wp_xml_parse.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/wp_import/services/wp_xml_parse.js b/plugins/wp_import/services/wp_xml_parse.js index 14c35363b..80a30160d 100644 --- a/plugins/wp_import/services/wp_xml_parse.js +++ b/plugins/wp_import/services/wp_xml_parse.js @@ -176,7 +176,7 @@ module.exports = function WPXMLParseServiceModule(pb) { users[index].password = generatedPassword; var newUser = pb.DocumentCreator.create('user', users[index]); - dao.save(newUser, function(err, result) { + self.siteQueryService.save(newUser, function(err, result) { if (util.isError(err)) { return callback(err); } From 1a83d5d38562697ace807fe34c82dbba3fb75bbe Mon Sep 17 00:00:00 2001 From: btidwell Date: Tue, 2 Jun 2015 14:44:22 -0400 Subject: [PATCH 247/790] use queryService to load user to check for duplicate usernames within one site. --- plugins/wp_import/services/wp_xml_parse.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/plugins/wp_import/services/wp_xml_parse.js b/plugins/wp_import/services/wp_xml_parse.js index 80a30160d..b8b374398 100644 --- a/plugins/wp_import/services/wp_xml_parse.js +++ b/plugins/wp_import/services/wp_xml_parse.js @@ -156,8 +156,7 @@ module.exports = function WPXMLParseServiceModule(pb) { var tasks = util.getTasks(users, function(users, index) { return function(callback) { - var dao = new pb.DAO(); - dao.loadByValue('username', users[index].username, 'user', function(err, existingUser) { + self.siteQueryService.loadByValue('username', users[index].username, 'user', function(err, existingUser) { if (util.isError(err)) { return cb(err); } From 6cbec363db7e6ba64554c818e8819055b1e8402c Mon Sep 17 00:00:00 2001 From: Christina Chatham Date: Tue, 2 Jun 2015 16:33:31 -0400 Subject: [PATCH 248/790] Manage users should go to a new user if a site doesn't have users. --- plugins/pencilblue/controllers/admin/users/manage_users.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/pencilblue/controllers/admin/users/manage_users.js b/plugins/pencilblue/controllers/admin/users/manage_users.js index 9055a7d6d..be693c4e0 100755 --- a/plugins/pencilblue/controllers/admin/users/manage_users.js +++ b/plugins/pencilblue/controllers/admin/users/manage_users.js @@ -44,7 +44,7 @@ module.exports = function(pb) { return self.reqHandler.serveError(err); } else if (users.length === 0) { - return self.redirect('/admin', cb); + return self.redirect('/admin' + self.sitePrefix + '/users/new', cb); } var angularObjects = pb.ClientJs.getAngularObjects({ From 65f7ab926b6c738134eb688449ebd4e190d4b388 Mon Sep 17 00:00:00 2001 From: btidwell Date: Wed, 3 Jun 2015 09:32:55 -0400 Subject: [PATCH 249/790] add site to base_controller getServiceContext() --- controllers/base_controller.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/controllers/base_controller.js b/controllers/base_controller.js index e4ef68cc1..f13fea443 100755 --- a/controllers/base_controller.js +++ b/controllers/base_controller.js @@ -135,7 +135,8 @@ module.exports = function BaseControllerModule(pb) { req: this.req, session: this.session, ls: this.ls, - ts: this.ts + ts: this.ts, + site: this.site }; cb(); From bdb654b13c78a781c6bb241a186c0545450d929f Mon Sep 17 00:00:00 2001 From: btidwell Date: Wed, 3 Jun 2015 09:34:35 -0400 Subject: [PATCH 250/790] ignore coverage directory --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index ef3924db2..a578c9fe1 100755 --- a/.gitignore +++ b/.gitignore @@ -21,5 +21,6 @@ plugins/* **/node_modules/** config.js config.json +coverage/ **/.DS_Store **/dump.rdb From 4a8db512b61a8f322376fcde9e4ebabab2cfa4e6 Mon Sep 17 00:00:00 2001 From: Christina Chatham Date: Wed, 3 Jun 2015 11:23:33 -0400 Subject: [PATCH 251/790] Make form error handling site aware. --- controllers/base_controller.js | 15 +++++++++++++-- .../controllers/actions/user/sign_up.js | 1 + 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/controllers/base_controller.js b/controllers/base_controller.js index e4ef68cc1..cb53710bc 100755 --- a/controllers/base_controller.js +++ b/controllers/base_controller.js @@ -190,9 +190,20 @@ module.exports = function BaseControllerModule(pb) { * @param {Function} cb */ BaseController.prototype.formError = function(message, redirectLocation, cb) { + var self = this; + self.session.error = message; + var siteService = new pb.SiteService(); + siteService.getByUid(self.site, function(err, siteProps) { + if(util.isError(err) || !siteProps) { + if(err) { pb.log.error(err) }; + self.reqHandler.serve404(); //TODO: Handle this better? + return; + } + else { + cb(pb.RequestHandler.generateRedirect(siteProps.hostname + redirectLocation)); + } + }); - this.session.error = message; - cb(pb.RequestHandler.generateRedirect(pb.config.siteRoot + redirectLocation)); }; /** diff --git a/plugins/pencilblue/controllers/actions/user/sign_up.js b/plugins/pencilblue/controllers/actions/user/sign_up.js index 67010a2b5..34041f573 100755 --- a/plugins/pencilblue/controllers/actions/user/sign_up.js +++ b/plugins/pencilblue/controllers/actions/user/sign_up.js @@ -121,6 +121,7 @@ module.exports = function SignUpModule(pb) { }; SignUp.prototype.validateUniques = function(user, cb) { + var self = this; var tasks = { verified_username: function(callback) { self.siteQueryService.count('user', {username: user.username}, callback); From 7441e97d4fbaf8fc16eba2887510ab05b7b9eb5c Mon Sep 17 00:00:00 2001 From: andparker Date: Wed, 3 Jun 2015 13:00:15 -0400 Subject: [PATCH 252/790] Overrides context accessor in base admin controllers | Update topics to use site from hostname --- controllers/admin/base_admin_controller.js | 10 ++++ .../admin/content/topics/import_topics.js | 12 ++--- .../admin/content/topics/manage_topics.js | 46 ++++++++++++------- .../admin/content/topics/topic_form.js | 13 ++---- .../admin/content/topics/manage_topics.html | 2 +- .../admin/content/topics/topic_form.html | 2 +- .../admin/content/topics/import_topics.html | 2 +- 7 files changed, 52 insertions(+), 35 deletions(-) diff --git a/controllers/admin/base_admin_controller.js b/controllers/admin/base_admin_controller.js index 71cbed80c..f59e7d0a5 100644 --- a/controllers/admin/base_admin_controller.js +++ b/controllers/admin/base_admin_controller.js @@ -62,6 +62,16 @@ module.exports = function BaseAdminControllerModule(pb) { }); }; + /** + * Retrieves a context object that contains the necessary information for + * service prototypes + * @method getServiceContext + * @return {Object} + */ + BaseAdminController.prototype.getServiceContext = function(){ + return util.merge(BaseAdminController.super_.prototype.getServiceContext.apply(this), { onlyThisSite: true}); + }; + /** * @method getTemplateService * @return {Object} TemplateService diff --git a/plugins/pencilblue/controllers/admin/content/topics/import_topics.js b/plugins/pencilblue/controllers/admin/content/topics/import_topics.js index f47b6f4af..85a68c0f2 100755 --- a/plugins/pencilblue/controllers/admin/content/topics/import_topics.js +++ b/plugins/pencilblue/controllers/admin/content/topics/import_topics.js @@ -45,9 +45,8 @@ module.exports = function(pb) { var angularObjects = pb.ClientJs.getAngularObjects( { navigation: pb.AdminNavigation.get(self.session, ['content', 'topics'], self.ls), - pills: self.getAdminPills(SUB_NAV_KEY, self.ls, 'manage_topics', {sitePrefix: self.sitePrefix}), - tabs: tabs, - sitePrefix: self.sitePrefix + pills: self.getAdminPills(SUB_NAV_KEY, self.ls, 'manage_topics'), + tabs: tabs }); this.setPageName(this.ls.get('IMPORT_TOPICS')); @@ -58,22 +57,21 @@ module.exports = function(pb) { }; ImportTopics.getSubNavItems = function(key, ls, data) { - var prefix = data.sitePrefix; return [{ name: 'manage_topics', title: ls.get('IMPORT_TOPICS'), icon: 'chevron-left', - href: '/admin' + prefix + '/content/topics' + href: '/admin/content/topics' }, { name: 'import_topics', title: '', icon: 'upload', - href: '/admin' + prefix + '/content/topics/import' + href: '/admin/content/topics/import' }, { name: 'new_topic', title: '', icon: 'plus', - href: '/admin' + prefix + '/content/topics/new' + href: '/admin/content/topics/new' }]; }; diff --git a/plugins/pencilblue/controllers/admin/content/topics/manage_topics.js b/plugins/pencilblue/controllers/admin/content/topics/manage_topics.js index ede794618..a430fc8c0 100755 --- a/plugins/pencilblue/controllers/admin/content/topics/manage_topics.js +++ b/plugins/pencilblue/controllers/admin/content/topics/manage_topics.js @@ -23,17 +23,31 @@ module.exports = function(pb) { /** * Interface for managing topics */ - function ManageTopics() { - - /** - * - * @property service - * @type {TopicService} - */ - this.service = new pb.TopicService(); - } + function ManageTopics() {} util.inherits(ManageTopics, pb.BaseAdminController); + /** + * Initializes the controller + * @method init + * @param {Object} context + * @param {Function} cb + */ + ManageTopics.prototype.init = function(context, cb) { + var self = this; + var init = function(err) { + + /** + * + * @property service + * @type {TopicService} + */ + self.service = new pb.TopicService(self.getServiceContext()); + + cb(err, true); + }; + ManageTopics.super_.prototype.init.apply(this, [context, init]); + }; + var SUB_NAV_KEY = 'manage_topics'; ManageTopics.prototype.render = function(cb) { @@ -46,7 +60,7 @@ module.exports = function(pb) { else if(topics.length === 0) { //none to manage - return self.redirect('/admin' + self.sitePrefix + '/content/topics/new', cb); + return self.redirect('/admin/content/topics/new', cb); } //currently, mongo cannot do case-insensitive sorts. We do it manually @@ -61,9 +75,8 @@ module.exports = function(pb) { var angularObjects = pb.ClientJs.getAngularObjects( { navigation: pb.AdminNavigation.get(self.session, ['content', 'topics'], self.ls), - pills: self.getAdminPills(SUB_NAV_KEY, self.ls, SUB_NAV_KEY, {sitePrefix: self.sitePrefix}), - topics: topics, - sitePrefix: self.sitePrefix + pills: self.getAdminPills(SUB_NAV_KEY, self.ls, SUB_NAV_KEY), + topics: topics }); self.setPageName(self.ls.get('MANAGE_TOPICS')); @@ -76,22 +89,21 @@ module.exports = function(pb) { }; ManageTopics.getSubNavItems = function(key, ls, data) { - var prefix = data.sitePrefix; return [{ name: SUB_NAV_KEY, title: ls.get('MANAGE_TOPICS'), icon: 'refresh', - href: '/admin' + prefix + '/content/topics' + href: '/admin/content/topics' }, { name: 'import_topics', title: '', icon: 'upload', - href: '/admin' + prefix + '/content/topics/import' + href: '/admin/content/topics/import' }, { name: 'new_topic', title: '', icon: 'plus', - href: '/admin' + prefix + '/content/topics/new' + href: '/admin/content/topics/new' }]; }; diff --git a/plugins/pencilblue/controllers/admin/content/topics/topic_form.js b/plugins/pencilblue/controllers/admin/content/topics/topic_form.js index bd4fd578a..7edc1011b 100644 --- a/plugins/pencilblue/controllers/admin/content/topics/topic_form.js +++ b/plugins/pencilblue/controllers/admin/content/topics/topic_form.js @@ -47,8 +47,7 @@ module.exports = function(pb) { } self.topic = data.topic; - data.sitePrefix = self.sitePrefix; - data.pills = self.getAdminPills(SUB_NAV_KEY, self.ls, self.topic, data); + data.pills = self.getAdminPills(SUB_NAV_KEY, self.ls, SUB_NAV_KEY, self.topic); var angularObjects = pb.ClientJs.getAngularObjects(data); self.setPageName(self.topic[pb.DAO.getIdField()] ? self.topic.name : self.ls.get('NEW_TOPIC')); @@ -94,23 +93,21 @@ module.exports = function(pb) { }; TopicForm.getSubNavItems = function(key, ls, data) { - var topic = data.topic; - var prefix = data.sitePrefix; return [{ name: SUB_NAV_KEY, - title: topic[pb.DAO.getIdField()] ? ls.get('EDIT') + ' ' + topic.name : ls.get('NEW_TOPIC'), + title: data[pb.DAO.getIdField()] ? ls.get('EDIT') + ' ' + data.name : ls.get('NEW_TOPIC'), icon: 'chevron-left', - href: '/admin' + prefix + '/content/topics' + href: '/admin/content/topics' }, { name: 'import_topics', title: '', icon: 'upload', - href: '/admin' + prefix + '/content/topics/import' + href: '/admin/content/topics/import' }, { name: 'new_topic', title: '', icon: 'plus', - href: '/admin' + prefix + '/content/topics/new' + href: '/admin/content/topics/new' }]; }; diff --git a/plugins/pencilblue/templates/admin/content/topics/manage_topics.html b/plugins/pencilblue/templates/admin/content/topics/manage_topics.html index a78e747f6..06892ef87 100755 --- a/plugins/pencilblue/templates/admin/content/topics/manage_topics.html +++ b/plugins/pencilblue/templates/admin/content/topics/manage_topics.html @@ -5,7 +5,7 @@ ^tmp_admin=elements=search_input^
- + diff --git a/plugins/pencilblue/templates/admin/content/topics/topic_form.html b/plugins/pencilblue/templates/admin/content/topics/topic_form.html index 35c9d9d1a..20c9fa0e8 100644 --- a/plugins/pencilblue/templates/admin/content/topics/topic_form.html +++ b/plugins/pencilblue/templates/admin/content/topics/topic_form.html @@ -13,7 +13,7 @@
^loc_REQUIRED_FIELD^
- +  ^loc_CANCEL^ ^tmp_admin=elements=save_button^ diff --git a/plugins/pencilblue/templates/angular/admin/content/topics/import_topics.html b/plugins/pencilblue/templates/angular/admin/content/topics/import_topics.html index 7cf0f7de2..083798075 100644 --- a/plugins/pencilblue/templates/angular/admin/content/topics/import_topics.html +++ b/plugins/pencilblue/templates/angular/admin/content/topics/import_topics.html @@ -10,7 +10,7 @@ $scope.uploading = true; $scope.uploadPercent = 0; $scope.upload = $upload.upload({ - url: '/actions/admin' + $scope.sitePrefix + '/content/topics/import', + url: '/actions/admin/content/topics/import', file: file }).progress(function(evt) { $scope.uploadPercent = parseInt(100.0 * evt.loaded / evt.total); From c4e7a087228a01ff49973c1cabef2a261954b5ae Mon Sep 17 00:00:00 2001 From: Christina Chatham Date: Wed, 3 Jun 2015 13:09:53 -0400 Subject: [PATCH 253/790] user verification email is site aware --- include/service/entities/user_service.js | 12 +++++++----- .../controllers/actions/user/resend_verification.js | 3 ++- .../pencilblue/controllers/actions/user/sign_up.js | 3 ++- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/include/service/entities/user_service.js b/include/service/entities/user_service.js index 129c4416d..9a602ffd4 100755 --- a/include/service/entities/user_service.js +++ b/include/service/entities/user_service.js @@ -218,20 +218,22 @@ module.exports = function UserServiceModule(pb) { UserService.prototype.sendVerificationEmail = function(user, cb) { cb = cb || util.cb; - pb.SiteService.getByUid(this.site, function(err, siteInfo) { + var siteService = new pb.SiteService(); + siteService.getByUid(this.siteUID, function(err, siteInfo) { // We need to see if email settings have been saved with verification content var emailService = new pb.EmailService(this.site); - emailService.getSettings(function(err, emailSettings) { + emailService.getSettings(function (err, emailSettings) { + var hostname = siteInfo.hostname.indexOf('http') > 0 ? siteInfo.hostname : 'http://' + siteInfo.hostname; var options = { to: user.email, replacements: { - 'verification_url': siteInfo.hostname + '/actions/user/verify_email?email=' + user.email + '&code=' + user.verification_code, + 'verification_url': hostname + '/actions/user/verify_email?email=' + user.email + '&code=' + user.verification_code, 'first_name': user.first_name, 'last_name': user.last_name } }; - if(emailSettings.layout) { - options.subject= emailSettings.verification_subject; + if (emailSettings.layout) { + options.subject = emailSettings.verification_subject; options.layout = emailSettings.verification_content; emailService.sendFromLayout(options, cb); } diff --git a/plugins/pencilblue/controllers/actions/user/resend_verification.js b/plugins/pencilblue/controllers/actions/user/resend_verification.js index e34794916..bc8a3877f 100755 --- a/plugins/pencilblue/controllers/actions/user/resend_verification.js +++ b/plugins/pencilblue/controllers/actions/user/resend_verification.js @@ -59,7 +59,8 @@ module.exports = function ResendVerificationModule(pb) { self.session.success = self.ls.get('VERIFICATION_SENT') + user.email; self.redirect('/user/verification_sent', cb); - pb.users.sendVerificationEmail(user, util.cb); + var userService = new UserService(self.site); + userService.sendVerificationEmail(user, util.cb); }); }); }); diff --git a/plugins/pencilblue/controllers/actions/user/sign_up.js b/plugins/pencilblue/controllers/actions/user/sign_up.js index 34041f573..a14303f9a 100755 --- a/plugins/pencilblue/controllers/actions/user/sign_up.js +++ b/plugins/pencilblue/controllers/actions/user/sign_up.js @@ -109,7 +109,8 @@ module.exports = function SignUpModule(pb) { //send email for verification when required if (contentSettings.require_verification) { - pb.users.sendVerificationEmail(user, util.cb); + var userService = new pb.UserService(self.site); + userService.sendVerificationEmail(user, util.cb); } }); }); From bde0c8b072df9c6adcfdac406d900d1770cdf351 Mon Sep 17 00:00:00 2001 From: btidwell Date: Wed, 3 Jun 2015 13:14:19 -0400 Subject: [PATCH 254/790] pass context info into services used by ArticleServiceV2 --- include/service/entities/article_service.js | 2 +- include/service/entities/content/article_service_v2.js | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/include/service/entities/article_service.js b/include/service/entities/article_service.js index 43ee0f642..12287beb5 100755 --- a/include/service/entities/article_service.js +++ b/include/service/entities/article_service.js @@ -487,7 +487,7 @@ module.exports = function ArticleServiceModule(pb) { * thumbnail - a URI path to the thumbnail image */ ArticleService.prototype.getMetaInfo = function(article, cb) { - var serviceV2 = new pb.ArticleServiceV2(); + var serviceV2 = new pb.ArticleServiceV2({site: this.site}); serviceV2.getMetaInfo(article, cb); }; diff --git a/include/service/entities/content/article_service_v2.js b/include/service/entities/content/article_service_v2.js index b7ac4b28d..f9808cb47 100644 --- a/include/service/entities/content/article_service_v2.js +++ b/include/service/entities/content/article_service_v2.js @@ -236,6 +236,7 @@ module.exports = function(pb) { * @param {Function} cb */ ArticleServiceV2.prototype.gatherDataForRender = function(articles, cb) { + var self = this; if (!util.isArray(articles)) { return cb(new Error('articles parameter must be an array')); } @@ -267,7 +268,7 @@ module.exports = function(pb) { contentSettings: function(callback) { - var contentService = new pb.ContentService(); + var contentService = new pb.ContentService(self.context.site, true); contentService.getSettings(callback); } }; @@ -287,6 +288,7 @@ module.exports = function(pb) { * thumbnail - a URI path to the thumbnail image */ ArticleServiceV2.prototype.getMetaInfo = function(article, cb) { + var self = this; if (util.isNullOrUndefined(article)) { return cb( new Error('The article parameter cannot be null'), @@ -346,7 +348,7 @@ module.exports = function(pb) { }, where: pb.DAO.getIdInWhere(article.article_topics || article.page_topics) }; - var topicService = new pb.TopicService(); + var topicService = new pb.TopicService(self.context); topicService.getAll(opts, function(err, topics) { if (util.isError(err)) { return callback(err); @@ -376,7 +378,7 @@ module.exports = function(pb) { }, where: pb.DAO.getIdWhere(article.thumbnail) }; - var mediaService = new pb.MediaService(); + var mediaService = new pb.MediaService(null, self.context.site, true); mediaService.get(mOpts, function(err, media) { callback(err, util.isNullOrUndefined(media) ? '' : media.location); }); From 2a1facde5894833e2ec188aece58ec8cb2c975ea Mon Sep 17 00:00:00 2001 From: Christina Chatham Date: Wed, 3 Jun 2015 13:41:16 -0400 Subject: [PATCH 255/790] changing links on resend verification for user email --- .../pencilblue/templates/user/resend_verification.html | 10 +++++----- .../pencilblue/templates/user/verification_sent.html | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/plugins/pencilblue/templates/user/resend_verification.html b/plugins/pencilblue/templates/user/resend_verification.html index a3316574f..f66d554fa 100755 --- a/plugins/pencilblue/templates/user/resend_verification.html +++ b/plugins/pencilblue/templates/user/resend_verification.html @@ -4,18 +4,18 @@
^error_success^
^loc_RESEND_VERIFICATION^
-
+
- +
@@ -23,11 +23,11 @@
- + diff --git a/plugins/pencilblue/templates/user/verification_sent.html b/plugins/pencilblue/templates/user/verification_sent.html index eeee99f60..78981b596 100755 --- a/plugins/pencilblue/templates/user/verification_sent.html +++ b/plugins/pencilblue/templates/user/verification_sent.html @@ -4,7 +4,7 @@
@@ -12,7 +12,7 @@

^loc_YOUR_VERIFICATION^

^loc_CHECK_INBOX^

-

^loc_RESEND_VERIFICATION^

+

^loc_RESEND_VERIFICATION^

 ^loc_BACK_HOME^ From ed41beb1d7bcd79af8c0c410ba755836aa3758de Mon Sep 17 00:00:00 2001 From: btidwell Date: Wed, 3 Jun 2015 14:00:34 -0400 Subject: [PATCH 256/790] make content_view_loader respect site for menu and content services --- controllers/base_controller.js | 3 ++- include/content.js | 1 + include/service/entities/content/content_view_loader.js | 8 +++++--- plugins/pencilblue/controllers/section.js | 7 ++++--- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/controllers/base_controller.js b/controllers/base_controller.js index 0baed7544..add3cbc28 100755 --- a/controllers/base_controller.js +++ b/controllers/base_controller.js @@ -150,7 +150,8 @@ module.exports = function BaseControllerModule(pb) { ls: this.ls, ts: this.ts, site: this.site, - activeTheme: this.activeTheme + activeTheme: this.activeTheme, + onlyThisSite: true }; cb(); diff --git a/include/content.js b/include/content.js index 240b0a66e..5cbe8ddb6 100755 --- a/include/content.js +++ b/include/content.js @@ -84,6 +84,7 @@ module.exports = function(pb) { * @param {Function} cb Callback function */ ContentService.prototype.get = function(cb) { + var self = this; this.settingService.get(CONTENT_SETTINGS_REF, function(err, settings){ if (settings) { return cb(err, settings); diff --git a/include/service/entities/content/content_view_loader.js b/include/service/entities/content/content_view_loader.js index 8cc3db9cb..08d73dfd6 100644 --- a/include/service/entities/content/content_view_loader.js +++ b/include/service/entities/content/content_view_loader.js @@ -35,6 +35,7 @@ module.exports = function(pb) { this.contentSettings = context.contentSettings; this.session = context.session; this.service = context.service; + this.site = context.site; }; /** @@ -174,7 +175,8 @@ module.exports = function(pb) { var options = { currUrl: self.req.url, session: self.session, - ls: self.ls + ls: self.ls, + site: self.site }; var topMenuService = new pb.TopMenuService(); topMenuService.getNavItems(options, callback); @@ -189,7 +191,7 @@ module.exports = function(pb) { return callback(null, self.contentSettings); } - var contentService = new pb.ContentService(); + var contentService = new pb.ContentService(self.site, true); contentService.getSettings(function(err, contentSettings) { self.contentSettings = contentSettings; callback(err, contentSettings); @@ -369,7 +371,7 @@ module.exports = function(pb) { } cb(null, val); }; - + ContentViewLoader.prototype.onCommentingUserPosition = function(content, commentingUser, cb) { var val = ''; if (commentingUser && util.isArray(commentingUser.position) && commentingUser.position.length > 0) { diff --git a/plugins/pencilblue/controllers/section.js b/plugins/pencilblue/controllers/section.js index b4fd4c480..69e23ce5e 100755 --- a/plugins/pencilblue/controllers/section.js +++ b/plugins/pencilblue/controllers/section.js @@ -32,7 +32,7 @@ module.exports = function SectionModule(pb) { var init = function(err) { //get content settings - var contentService = new pb.ContentService(); + var contentService = new pb.ContentService(self.site, true); contentService.getSettings(function(err, contentSettings) { if (util.isError(err)) { return cb(err); @@ -40,7 +40,7 @@ module.exports = function SectionModule(pb) { //create the service self.contentSettings = contentSettings; - self.service = new pb.ArticleServiceV2(); + self.service = new pb.ArticleServiceV2(self.getServiceContext()); //create the loader context var context = { @@ -49,7 +49,8 @@ module.exports = function SectionModule(pb) { req: self.req, ts: self.ts, ls: self.ls, - contentSettings: contentSettings + contentSettings: contentSettings, + site: self.site }; self.contentViewLoader = new pb.ContentViewLoader(context); self.dao = new pb.DAO(); From 7e4f68b6f3b616a29d22854ac3287c2b10e589fd Mon Sep 17 00:00:00 2001 From: btidwell Date: Wed, 3 Jun 2015 14:22:19 -0400 Subject: [PATCH 257/790] use onlyThisSite from context for service instantiation --- .../entities/content/article_service_v2.js | 4 ++-- .../entities/content/content_view_loader.js | 3 ++- plugins/pencilblue/controllers/section.js | 19 +++++++------------ 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/include/service/entities/content/article_service_v2.js b/include/service/entities/content/article_service_v2.js index f9808cb47..e4a0b124d 100644 --- a/include/service/entities/content/article_service_v2.js +++ b/include/service/entities/content/article_service_v2.js @@ -268,7 +268,7 @@ module.exports = function(pb) { contentSettings: function(callback) { - var contentService = new pb.ContentService(self.context.site, true); + var contentService = new pb.ContentService(self.context.site, self.context.onlyThisSite); contentService.getSettings(callback); } }; @@ -378,7 +378,7 @@ module.exports = function(pb) { }, where: pb.DAO.getIdWhere(article.thumbnail) }; - var mediaService = new pb.MediaService(null, self.context.site, true); + var mediaService = new pb.MediaService(null, self.context.site, self.context.onlyThisSite); mediaService.get(mOpts, function(err, media) { callback(err, util.isNullOrUndefined(media) ? '' : media.location); }); diff --git a/include/service/entities/content/content_view_loader.js b/include/service/entities/content/content_view_loader.js index 08d73dfd6..2368e04f5 100644 --- a/include/service/entities/content/content_view_loader.js +++ b/include/service/entities/content/content_view_loader.js @@ -36,6 +36,7 @@ module.exports = function(pb) { this.session = context.session; this.service = context.service; this.site = context.site; + this.onlyThisSite = context.site; }; /** @@ -191,7 +192,7 @@ module.exports = function(pb) { return callback(null, self.contentSettings); } - var contentService = new pb.ContentService(self.site, true); + var contentService = new pb.ContentService(self.site, self.onlyThisSite); contentService.getSettings(function(err, contentSettings) { self.contentSettings = contentSettings; callback(err, contentSettings); diff --git a/plugins/pencilblue/controllers/section.js b/plugins/pencilblue/controllers/section.js index 69e23ce5e..6d1b87b2b 100755 --- a/plugins/pencilblue/controllers/section.js +++ b/plugins/pencilblue/controllers/section.js @@ -30,28 +30,23 @@ module.exports = function SectionModule(pb) { Section.prototype.init = function(context, cb) { var self = this; var init = function(err) { - //get content settings - var contentService = new pb.ContentService(self.site, true); + var contentService = new pb.ContentService(self.site, self.getServiceContext().onlyThisSite); contentService.getSettings(function(err, contentSettings) { if (util.isError(err)) { return cb(err); } - + var serviceContext = self.getServiceContext(); //create the service self.contentSettings = contentSettings; - self.service = new pb.ArticleServiceV2(self.getServiceContext()); + self.service = new pb.ArticleServiceV2(serviceContext); //create the loader context - var context = { + var context = util.merge(serviceContext, { service: self.service, - session: self.session, - req: self.req, - ts: self.ts, - ls: self.ls, - contentSettings: contentSettings, - site: self.site - }; + contentSettings: contentSettings + }); + self.contentViewLoader = new pb.ContentViewLoader(context); self.dao = new pb.DAO(); From c9a6c15e9a061e44d477ce50e4e706f362fb1b96 Mon Sep 17 00:00:00 2001 From: andparker Date: Wed, 3 Jun 2015 14:41:38 -0400 Subject: [PATCH 258/790] Updates feed controller to pass context with site to article service v2 --- plugins/pencilblue/controllers/feed.js | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/plugins/pencilblue/controllers/feed.js b/plugins/pencilblue/controllers/feed.js index 27d924943..0bcedf622 100755 --- a/plugins/pencilblue/controllers/feed.js +++ b/plugins/pencilblue/controllers/feed.js @@ -31,16 +31,24 @@ module.exports = function FeedModule(pb) { /** * RSS Feed */ - function ArticleFeed(){ - - /** - * - * - */ - this.service = new ArticleServiceV2(); - } + function ArticleFeed(){} util.inherits(ArticleFeed, pb.BaseController); + ArticleFeed.prototype.init = function(props, cb) { + var self = this; + var init = function(err) { + if (util.isError(err)) { + return cb(err); + } + + //create the service + self.service = new pb.ArticleServiceV2(self.getServiceContext()); + + cb(null, true); + }; + ArticleFeed.super_.prototype.init.apply(this, [props, init]); + }; + ArticleFeed.prototype.render = function(cb) { var self = this; From c6e5a263f6b3930f2bc0aff1f2bee3b3945276bf Mon Sep 17 00:00:00 2001 From: btidwell Date: Wed, 3 Jun 2015 15:05:20 -0400 Subject: [PATCH 259/790] move serviceContext variable outside of contentService scope --- plugins/pencilblue/controllers/section.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/pencilblue/controllers/section.js b/plugins/pencilblue/controllers/section.js index 6d1b87b2b..9f804ec0f 100755 --- a/plugins/pencilblue/controllers/section.js +++ b/plugins/pencilblue/controllers/section.js @@ -31,12 +31,12 @@ module.exports = function SectionModule(pb) { var self = this; var init = function(err) { //get content settings - var contentService = new pb.ContentService(self.site, self.getServiceContext().onlyThisSite); + var serviceContext = self.getServiceContext(); + var contentService = new pb.ContentService(self.site, serviceContext.onlyThisSite); contentService.getSettings(function(err, contentSettings) { if (util.isError(err)) { return cb(err); } - var serviceContext = self.getServiceContext(); //create the service self.contentSettings = contentSettings; self.service = new pb.ArticleServiceV2(serviceContext); From b5e4379bc79aaa0331948c49948640a85af84c7b Mon Sep 17 00:00:00 2001 From: Christina Chatham Date: Wed, 3 Jun 2015 15:17:00 -0400 Subject: [PATCH 260/790] handling adding on protocol to hostname for sites. --- include/http/request_handler.js | 1 + include/service/entities/site_service.js | 5 +++++ include/service/entities/user_service.js | 3 +-- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/include/http/request_handler.js b/include/http/request_handler.js index 8c7330d9a..9dae543bf 100755 --- a/include/http/request_handler.js +++ b/include/http/request_handler.js @@ -1199,6 +1199,7 @@ module.exports = function RequestHandlerModule(pb) { * @param {String} location */ RequestHandler.prototype.doRedirect = function(location) { + location = pb.SiteService.getSiteProtocol(location); this.resp.statusCode = 302; this.resp.setHeader("Location", location); this.resp.end(); diff --git a/include/service/entities/site_service.js b/include/service/entities/site_service.js index 9a2260c1f..ace6d89ab 100644 --- a/include/service/entities/site_service.js +++ b/include/service/entities/site_service.js @@ -371,5 +371,10 @@ module.exports = function SiteServiceModule(pb) { return object[SiteService.SITE_FIELD]; }; + SiteService.getSiteProtocol = function(hostname) { + var protocol = pb.config.server.ssl.enabled ? 'https://' : 'http://'; + return hostname.indexOf('http') > 0 ? hostname : protocol + hostname; + }; + return SiteService; }; diff --git a/include/service/entities/user_service.js b/include/service/entities/user_service.js index 9a602ffd4..50278aa8a 100755 --- a/include/service/entities/user_service.js +++ b/include/service/entities/user_service.js @@ -223,11 +223,10 @@ module.exports = function UserServiceModule(pb) { // We need to see if email settings have been saved with verification content var emailService = new pb.EmailService(this.site); emailService.getSettings(function (err, emailSettings) { - var hostname = siteInfo.hostname.indexOf('http') > 0 ? siteInfo.hostname : 'http://' + siteInfo.hostname; var options = { to: user.email, replacements: { - 'verification_url': hostname + '/actions/user/verify_email?email=' + user.email + '&code=' + user.verification_code, + 'verification_url': pb.SiteService.getSiteProtocol(siteInfo.hostname) + '/actions/user/verify_email?email=' + user.email + '&code=' + user.verification_code, 'first_name': user.first_name, 'last_name': user.last_name } From c5875630d519f9de09803ada1c7a182691a4da71 Mon Sep 17 00:00:00 2001 From: btidwell Date: Wed, 3 Jun 2015 15:35:02 -0400 Subject: [PATCH 261/790] use site from request_handler in admin controllers --- controllers/admin/base_admin_controller.js | 2 +- include/admin_navigation.js | 32 ++++++++++------------ 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/controllers/admin/base_admin_controller.js b/controllers/admin/base_admin_controller.js index f59e7d0a5..add7c0d59 100644 --- a/controllers/admin/base_admin_controller.js +++ b/controllers/admin/base_admin_controller.js @@ -37,7 +37,7 @@ module.exports = function BaseAdminControllerModule(pb) { */ BaseAdminController.prototype.init = function (props, cb) { var self = this; - self.pathSiteUId = pb.SiteService.getCurrentSite(props.path_vars.siteid); + self.pathSiteUId = props.site; BaseController.prototype.init.call(self, props, function () { self.extendedInit(cb); }); diff --git a/include/admin_navigation.js b/include/admin_navigation.js index c1b4f1c61..601600bad 100755 --- a/include/admin_navigation.js +++ b/include/admin_navigation.js @@ -80,11 +80,7 @@ module.exports = function AdminNavigationModule(pb) { * @param adminsiteId {String} uid of site * @returns {Array} */ - function getDefaultNavigation(adminSiteId) { - var adminPath = '/admin' - if(adminSiteId && pb.config.multisite) { - adminPath = '/admin/' + adminSiteId; - } + function getDefaultNavigation() { return util.clone(Object.freeze([ { id: 'content', @@ -97,49 +93,49 @@ module.exports = function AdminNavigationModule(pb) { id: 'navigation', title: 'NAVIGATION', icon: 'th-large', - href: adminPath + '/content/navigation', + href: '/admin/content/navigation', access: SecurityService.ACCESS_EDITOR }, { id: 'topics', title: 'TOPICS', icon: 'tags', - href: adminPath + '/content/topics', + href: '/admin/content/topics', access: SecurityService.ACCESS_EDITOR }, { id: 'pages', title: 'PAGES', icon: 'file-o', - href: adminPath + '/content/pages', + href: '/admin/content/pages', access: SecurityService.ACCESS_EDITOR }, { id: 'articles', title: 'ARTICLES', icon: 'files-o', - href: adminPath + '/content/articles', + href: '/admin/content/articles', access: SecurityService.ACCESS_WRITER }, { id: 'media', title: 'MEDIA', icon: 'camera', - href: adminPath + '/content/media', + href: '/admin/content/media', access: SecurityService.ACCESS_WRITER }, { id: 'comments', title: 'COMMENTS', icon: 'comments', - href: adminPath + '/content/comments', + href: '/admin/content/comments', access: SecurityService.ACCESS_EDITOR }, { id: 'custom_objects', title: 'CUSTOM_OBJECTS', icon: 'sitemap', - href: adminPath + '/content/objects/types', + href: '/admin/content/objects/types', access: SecurityService.ACCESS_EDITOR } ] @@ -156,13 +152,13 @@ module.exports = function AdminNavigationModule(pb) { id: 'manage', title: 'MANAGE', icon: 'upload', - href: adminPath + '/plugins' + href: '/admin/plugins' }, { id: 'themes', title: 'THEMES', icon: 'magic', - href: adminPath + '/themes' + href: '/admin/themes' } ] }, @@ -200,14 +196,14 @@ module.exports = function AdminNavigationModule(pb) { id: 'site_settings', title: 'SITE_SETTINGS', icon: 'cog', - href: adminPath + '/site_settings', + href: '/admin/site_settings', access: SecurityService.ACCESS_MANAGING_EDITOR }, { id: 'content_settings', title: 'CONTENT', icon: 'quote-right', - href: adminPath + '/site_settings/content', + href: '/admin/site_settings/content', access: SecurityService.ACCESS_MANAGING_EDITOR }, { @@ -221,7 +217,7 @@ module.exports = function AdminNavigationModule(pb) { id: 'library_settings', title: 'LIBRARIES', icon: 'book', - href: '/admin/'+ GLOBAL_SITE +'/site_settings/libraries', + href: '/admin/site_settings/libraries', access: SecurityService.ACCESS_ADMINISTRATOR } ] @@ -281,7 +277,7 @@ module.exports = function AdminNavigationModule(pb) { var navigation = []; var multiSiteAdditions = getMultiSiteNavigation(); var adminSiteId = session && session.adminSiteId ? session.adminSiteId : GLOBAL_SITE; - var defaultNavigation = getDefaultNavigation(adminSiteId); + var defaultNavigation = getDefaultNavigation(); var additions = getAdditions(adminSiteId); var childrenAdditions = getChildrenAdditions(adminSiteId); if (!pb.SiteService.isGlobal(adminSiteId)) { From 3d14250e886a1a889f6dd690635ec036e6658323 Mon Sep 17 00:00:00 2001 From: btidwell Date: Wed, 3 Jun 2015 15:39:10 -0400 Subject: [PATCH 262/790] use hostname link in manage_sites view --- plugins/pencilblue/templates/admin/sites/manage.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/pencilblue/templates/admin/sites/manage.html b/plugins/pencilblue/templates/admin/sites/manage.html index ab69625d1..460d6b18a 100644 --- a/plugins/pencilblue/templates/admin/sites/manage.html +++ b/plugins/pencilblue/templates/admin/sites/manage.html @@ -19,7 +19,7 @@
- + - + @@ -73,4 +72,4 @@ ^tmp_admin=elements=progress_console_modal^ ^tmp_angular=admin=sites=manage_sites^ -^tmp_admin=footer^ \ No newline at end of file +^tmp_admin=footer^nn \ No newline at end of file diff --git a/plugins/pencilblue/templates/angular/admin/sites/manage_sites.html b/plugins/pencilblue/templates/angular/admin/sites/manage_sites.html index 93bb80e8a..dc1e18d8a 100644 --- a/plugins/pencilblue/templates/angular/admin/sites/manage_sites.html +++ b/plugins/pencilblue/templates/angular/admin/sites/manage_sites.html @@ -1,4 +1,5 @@ + - diff --git a/public/localization/de-DE.js b/public/localization/de-DE.js index c7110eeff..64b6df600 100644 --- a/public/localization/de-DE.js +++ b/public/localization/de-DE.js @@ -250,7 +250,9 @@ module.exports = { SAVED: 'wurde gespeichert', NARROW_RESULTS: 'Resultate eingrenzen', URL_KEY: 'URL-Schlüssel', - FEED_UNAVAILABLE: 'Kann den Nachrichten-Feed nicht laden.' + FEED_UNAVAILABLE: 'Kann den Nachrichten-Feed nicht laden.', + REQUESTS_TOTAL: 'Total Anfragen', + REQUESTS_CURRENT: 'aktuelle Anfragen' }, topics: { MANAGE_TOPICS: 'Kategorien verwalten', diff --git a/public/localization/en-US.js b/public/localization/en-US.js index 23c44fde7..705b8438e 100755 --- a/public/localization/en-US.js +++ b/public/localization/en-US.js @@ -240,7 +240,9 @@ module.exports = { SAVED: 'was saved', NARROW_RESULTS: 'Narrow results', URL_KEY: 'URL Key', - FEED_UNAVAILABLE: 'Unable to load the news feed.' + FEED_UNAVAILABLE: 'Unable to load the news feed.', + REQUESTS_TOTAL: 'Total Requests', + REQUESTS_CURRENT: 'Current Requests' }, topics: { MANAGE_TOPICS: 'Manage topics', diff --git a/public/localization/es-ES.js b/public/localization/es-ES.js index 6e1715f52..36b808680 100755 --- a/public/localization/es-ES.js +++ b/public/localization/es-ES.js @@ -239,7 +239,9 @@ module.exports = { SAVED: 'fue guardado', NARROW_RESULTS: 'Limitar resultados', URL_KEY: 'Clave de URL', - FEED_UNAVAILABLE: 'No se pudo cargar las noticias.' + FEED_UNAVAILABLE: 'No se pudo cargar las noticias.', + REQUESTS_TOTAL: 'Las solicitudes totales', + REQUESTS_CURRENT: 'solicitudes actuales' }, topics: { MANAGE_TOPICS: 'Gestionar tópicos', diff --git a/public/localization/pl-PL.js b/public/localization/pl-PL.js index 2dfe58b09..3a607c8dd 100755 --- a/public/localization/pl-PL.js +++ b/public/localization/pl-PL.js @@ -243,7 +243,9 @@ module.exports = { SAVED: 'zapisany', NARROW_RESULTS: 'Zawężone wyniki', URL_KEY: 'URL klucz', - FEED_UNAVAILABLE: 'Nie można załadować aktualności.' + FEED_UNAVAILABLE: 'Nie można załadować aktualności.', + REQUESTS_TOTAL: 'Wszystkich Wnioski', + REQUESTS_CURRENT: 'Aktualne Wnioski' }, topics: { MANAGE_TOPICS: 'Zarządzaj tematami', diff --git a/public/localization/ro-RO.js b/public/localization/ro-RO.js index e5b209c17..4221bcefd 100644 --- a/public/localization/ro-RO.js +++ b/public/localization/ro-RO.js @@ -234,7 +234,9 @@ module.exports = { SAVED: 'a fost salvat', NARROW_RESULTS: 'Restrange rezultatele', URL_KEY: 'URL Key', - FEED_UNAVAILABLE: 'Nu pot incarca fluxul de stiri.' + FEED_UNAVAILABLE: 'Nu pot incarca fluxul de stiri.', + REQUESTS_TOTAL: 'totale Cereri', + REQUESTS_CURRENT: 'Cereri de curent' }, topics: { MANAGE_TOPICS: 'Administreaza topicuri', From 77eee841153a433cc6ea16cd582b36010ab251d7 Mon Sep 17 00:00:00 2001 From: Christina Chatham Date: Mon, 27 Jul 2015 09:18:50 -0400 Subject: [PATCH 482/790] Fixing redundant callbacks site service, plugin service, db manager --- include/dao/db_manager.js | 4 +--- include/service/entities/plugin_service.js | 4 +--- include/service/entities/site_service.js | 5 +---- 3 files changed, 3 insertions(+), 10 deletions(-) diff --git a/include/dao/db_manager.js b/include/dao/db_manager.js index 792b27e5a..d27a04933 100755 --- a/include/dao/db_manager.js +++ b/include/dao/db_manager.js @@ -245,9 +245,7 @@ module.exports = function DBManagerModule(pb) { }); }; }); - async.parallel(tasks, function(err){ - cb(err); - }); + async.parallel(tasks, cb); }); }; diff --git a/include/service/entities/plugin_service.js b/include/service/entities/plugin_service.js index 30dba0088..2c2e5f429 100755 --- a/include/service/entities/plugin_service.js +++ b/include/service/entities/plugin_service.js @@ -2059,9 +2059,7 @@ module.exports = function PluginServiceModule(pb) { }); }; }); - async.parallel(tasks, function(err, results) { - cb(err, results); - }); + async.parallel(tasks, cb); }); }; diff --git a/include/service/entities/site_service.js b/include/service/entities/site_service.js index ff079974c..107cb5090 100644 --- a/include/service/entities/site_service.js +++ b/include/service/entities/site_service.js @@ -95,7 +95,6 @@ module.exports = function SiteServiceModule(pb) { SiteService.prototype.getSiteMap = function(cb) { var self = this; var tasks = { - active: function(callback) { self.getActiveSites(callback); }, @@ -104,9 +103,7 @@ module.exports = function SiteServiceModule(pb) { self.getInactiveSites(callback); } }; - async.series(tasks, function(err, results) { - cb(err, results); - }); + async.series(tasks, cb); }; /** From 9d553c107217739f8da58891ce985d92e5a358b1 Mon Sep 17 00:00:00 2001 From: Christina Chatham Date: Mon, 27 Jul 2015 09:25:22 -0400 Subject: [PATCH 483/790] Style fixes --- include/service/entities/site_service.js | 6 +++--- include/service/jobs/sites/site_deactivate_job.js | 6 +----- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/include/service/entities/site_service.js b/include/service/entities/site_service.js index 107cb5090..c58e7063e 100644 --- a/include/service/entities/site_service.js +++ b/include/service/entities/site_service.js @@ -117,13 +117,13 @@ module.exports = function SiteServiceModule(pb) { dao.q(SITE_COLL, {select: pb.DAO.SELECT_ALL, where: {uid: uid} }, function(err, result) { var siteName = (!uid || uid === SiteService.GLOBAL_SITE) ? 'global' : ''; - if(pb.util.isError(err)) { + if (pb.util.isError(err)) { pb.log.error(err); return cb(err); - }else if(result && result.length > 0) { + } + else if (result && result.length > 0) { siteName = result[0].displayName; } - cb(null, siteName); }); }; diff --git a/include/service/jobs/sites/site_deactivate_job.js b/include/service/jobs/sites/site_deactivate_job.js index 8e2db07f0..d2a83c982 100644 --- a/include/service/jobs/sites/site_deactivate_job.js +++ b/include/service/jobs/sites/site_deactivate_job.js @@ -104,11 +104,7 @@ module.exports = function SiteDeactivateJobModule(pb) { } ]; async.series(tasks, function(err, results) { - if(util.isError(err)) { - cb(err); - return; - } - cb(null, true); + cb(err, !util.isError(err)); }); }; From 7998ca1b2baff810a607b5de40ea9ce019b9ea4a Mon Sep 17 00:00:00 2001 From: btidwell Date: Mon, 27 Jul 2015 09:54:21 -0400 Subject: [PATCH 484/790] switch to angular from jquery for site activate/deactivate progress modal --- .../templates/angular/admin/sites/manage_sites.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/pencilblue/templates/angular/admin/sites/manage_sites.html b/plugins/pencilblue/templates/angular/admin/sites/manage_sites.html index fd90ebfca..6e8a50c16 100644 --- a/plugins/pencilblue/templates/angular/admin/sites/manage_sites.html +++ b/plugins/pencilblue/templates/angular/admin/sites/manage_sites.html @@ -9,7 +9,7 @@ $scope.actionPlugin = site; $scope.actionProgress = '0'; $scope.consoleOutput = ''; - $('#progress_modal').modal({}); + angular.element('#progress_modal').modal(); $http.post('/actions/admin/sites/activate/' + site.uid) .success(function(result) { $scope.onActivateOrDeactivateComplete(result); @@ -24,7 +24,7 @@ $scope.actionPlugin = site; $scope.actionProgress = '0'; $scope.consoleOutput = ''; - $('#progress_modal').modal({}); + angular.element('#progress_modal').modal(); $http.post('/actions/admin/sites/deactivate/' + site.uid) .success(function(result) { $scope.onActivateOrDeactivateComplete(result); From 62216e1fd7780d7aa900e86ad325e9411a8851b9 Mon Sep 17 00:00:00 2001 From: btidwell Date: Mon, 27 Jul 2015 09:56:15 -0400 Subject: [PATCH 485/790] Remove debug log. --- plugins/pencilblue/templates/angular/admin/sites/site_form.html | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/pencilblue/templates/angular/admin/sites/site_form.html b/plugins/pencilblue/templates/angular/admin/sites/site_form.html index 907f28a82..df7b36f1d 100644 --- a/plugins/pencilblue/templates/angular/admin/sites/site_form.html +++ b/plugins/pencilblue/templates/angular/admin/sites/site_form.html @@ -13,7 +13,6 @@ } $scope.saving = true; - console.log($scope.siteForm); $http.post('/actions/admin/sites/edit/' + $scope.uid, { displayName: $scope.displayName, From 7dd1ea1543197b2f6327ea0fa1a57b86ecadefc1 Mon Sep 17 00:00:00 2001 From: Christina Chatham Date: Mon, 27 Jul 2015 10:17:04 -0400 Subject: [PATCH 486/790] Doc Db Migrate --- include/dao/db_migrate.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/include/dao/db_migrate.js b/include/dao/db_migrate.js index 8358acfc7..8607cc794 100644 --- a/include/dao/db_migrate.js +++ b/include/dao/db_migrate.js @@ -25,12 +25,28 @@ module.exports = function DBMigrateModule(pb) { 'topic' ]; + /** + * Array of security levels that will access admin console on a site level. + * @private + * @static + * @readonly + * @property SITE_SPECIFIC_USERS + * @type {string[]} + */ var SITE_SPECIFIC_USERS = [ pb.security.ACCESS_EDITOR, pb.security.ACCESS_WRITER, pb.security.ACCESS_USER ]; + /** + * Site Settings that will migrate to a site level from global. + * @private + * @static + * @readonly + * @property SITE_SPECIFIC_SETTINGS + * @type {string[]} + */ var SITE_SPECIFIC_SETTINGS = [ 'active_theme', 'content_settings', @@ -38,6 +54,11 @@ module.exports = function DBMigrateModule(pb) { 'email_settings' ]; + /** + * On run, transforms a single tenant instance to a multi-tenant instance where the site defined + * in the single tenant instance becomes a site under global's scope. + * @constructor DBMigrate + */ function DBMigrate() { this.run = function (cb) { From f264707e35bdc40ab2fe4b3630f7fc826d8f5928 Mon Sep 17 00:00:00 2001 From: btidwell Date: Mon, 27 Jul 2015 10:18:10 -0400 Subject: [PATCH 487/790] Change icon of Custom Objects link to cubes --- include/admin_navigation.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/admin_navigation.js b/include/admin_navigation.js index 01c9e0cd0..f6fef3c2d 100755 --- a/include/admin_navigation.js +++ b/include/admin_navigation.js @@ -129,7 +129,7 @@ module.exports = function AdminNavigationModule(pb) { { id: 'custom_objects', title: 'CUSTOM_OBJECTS', - icon: 'sitemap', + icon: 'cubes', href: '/admin/content/objects/types', access: SecurityService.ACCESS_EDITOR } From 7980df856608190f0a8e37021dc1404098a9bf82 Mon Sep 17 00:00:00 2001 From: btidwell Date: Mon, 27 Jul 2015 10:40:32 -0400 Subject: [PATCH 488/790] remove reference to "s" of collection object due to change in getAllCollections() --- include/service/entities/site_query_service.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/service/entities/site_query_service.js b/include/service/entities/site_query_service.js index 36019abdd..b4ab0ccc9 100644 --- a/include/service/entities/site_query_service.js +++ b/include/service/entities/site_query_service.js @@ -177,7 +177,7 @@ module.exports = function SiteQueryServiceModule(pb) { var dao = new pb.DAO(); var tasks = util.getTasks(collections, function(collections, i) { return function(taskCallback) { - dao.delete({site: siteid}, collections[i].s.name, function(err, numberOfDeletedRecords) { + dao.delete({site: siteid}, collections[i].name, function(err, numberOfDeletedRecords) { if(util.isError(err) || !numberOfDeletedRecords) { taskCallback(null, " "); } else { From 6577566f5bcbb5544473cfe00a39c8215c97c6f7 Mon Sep 17 00:00:00 2001 From: btidwell Date: Mon, 27 Jul 2015 10:42:05 -0400 Subject: [PATCH 489/790] Use save button template on site_form --- .../pencilblue/templates/admin/sites/site_form.html | 12 ++++++------ .../templates/angular/admin/sites/site_form.html | 1 + 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/plugins/pencilblue/templates/admin/sites/site_form.html b/plugins/pencilblue/templates/admin/sites/site_form.html index 24faea38a..c946f023e 100644 --- a/plugins/pencilblue/templates/admin/sites/site_form.html +++ b/plugins/pencilblue/templates/admin/sites/site_form.html @@ -23,12 +23,12 @@  ^loc_CANCEL^ - -  ^loc_SAVE^ - - -  ^loc_SAVE^ - + + diff --git a/plugins/pencilblue/templates/angular/admin/sites/site_form.html b/plugins/pencilblue/templates/angular/admin/sites/site_form.html index df7b36f1d..cf818b8a3 100644 --- a/plugins/pencilblue/templates/angular/admin/sites/site_form.html +++ b/plugins/pencilblue/templates/angular/admin/sites/site_form.html @@ -30,6 +30,7 @@ }; $scope.newSite = function() { + $scope.saving = true; $http.post('/actions/admin/sites/new', { displayName: $scope.displayName, From 14adef76d0c1d4fbaf6d8999519284ec098c2906 Mon Sep 17 00:00:00 2001 From: Kyle Bechtel Date: Mon, 27 Jul 2015 11:46:32 -0400 Subject: [PATCH 490/790] removed getJSONPostParams from edit_site.js and new_site.js as requested by brian. updated the routes to include request_body: ['application/json'] so we could retrieve the post data from self.body and refactored. --- .../actions/admin/sites/edit_site.js | 83 +++++++++---------- .../actions/admin/sites/new_site.js | 57 ++++++------- plugins/pencilblue/include/routes.js | 2 + 3 files changed, 69 insertions(+), 73 deletions(-) diff --git a/plugins/pencilblue/controllers/actions/admin/sites/edit_site.js b/plugins/pencilblue/controllers/actions/admin/sites/edit_site.js index 722a4c0e0..101a759ef 100644 --- a/plugins/pencilblue/controllers/actions/admin/sites/edit_site.js +++ b/plugins/pencilblue/controllers/actions/admin/sites/edit_site.js @@ -30,53 +30,50 @@ module.exports = function EditSiteActionModule(pb) { { var self = this; var siteid = this.pathVars.siteid; - this.getJSONPostParams(function(err, post) { - var message = self.hasRequiredParams(post, self.getRequiredFields()); - if(message) { - cb({ - code: 400, - content: pb.BaseController.apiResponse(pb.BaseController.API_ERROR, message) - }); - return; - } + var message = self.hasRequiredParams(self.body, self.getRequiredFields()); + if(message) { + cb({ + code: 400, + content: pb.BaseController.apiResponse(pb.BaseController.API_ERROR, message) + }); + return; + } - if(!pb.security.isAuthorized(self.session, {admin_level: post.admin})) { - cb({ - code: 400, - content: pb.BaseController.apiResponse(pb.BaseController.API_ERROR, self.ls.get('INSUFFICIENT_CREDENTIALS')) - }); - return; - } + if(!pb.security.isAuthorized(self.session, {admin_level: self.body.admin})) { + cb({ + code: 400, + content: pb.BaseController.apiResponse(pb.BaseController.API_ERROR, self.ls.get('INSUFFICIENT_CREDENTIALS')) + }); + return; + } - var siteService = new pb.SiteService(); - var dao = new pb.DAO(); - dao.loadByValue('uid', siteid, 'site', function(err, data) { - siteService.isDisplayNameOrHostnameTaken(post.displayName, post.hostname, data._id, function (err, isTaken, field) { - if(isTaken) { - cb({ - code: 400, - content: pb.BaseController.apiResponse(pb.BaseController.API_ERROR, self.ls.get('DUPLICATE_INFO')) - }); + var siteService = new pb.SiteService(); + var dao = new pb.DAO(); + dao.loadByValue('uid', siteid, 'site', function(err, data) { + siteService.isDisplayNameOrHostnameTaken(self.body.displayName, self.body.hostname, data._id, function (err, isTaken, field) { + if(isTaken) { + cb({ + code: 400, + content: pb.BaseController.apiResponse(pb.BaseController.API_ERROR, self.ls.get('DUPLICATE_INFO')) + }); - } else { - data.displayName = post.displayName; - data.hostname = post.hostname; - dao.save(data, function(err, result) { - if(err) { - cb({ - code: 400, - content: pb.BaseController.apiResponse(pb.BaseController.API_ERROR, self.ls.get('ERROR_SAVING')) - }); - return; - } - cb({content: pb.BaseController.apiResponse(pb.BaseController.API_SUCCESS, self.ls.get('SITE_UPDATED'), result)}); - }); - } + } else { + data.displayName = self.body.displayName; + data.hostname = self.body.hostname; + dao.save(data, function(err, result) { + if(err) { + cb({ + code: 400, + content: pb.BaseController.apiResponse(pb.BaseController.API_ERROR, self.ls.get('ERROR_SAVING')) + }); + return; + } + cb({content: pb.BaseController.apiResponse(pb.BaseController.API_SUCCESS, self.ls.get('SITE_UPDATED'), result)}); + }); + } - }); - }) - - }); + }); + }) }; diff --git a/plugins/pencilblue/controllers/actions/admin/sites/new_site.js b/plugins/pencilblue/controllers/actions/admin/sites/new_site.js index cb274be5f..64f66216c 100644 --- a/plugins/pencilblue/controllers/actions/admin/sites/new_site.js +++ b/plugins/pencilblue/controllers/actions/admin/sites/new_site.js @@ -29,46 +29,43 @@ module.exports = function NewSiteActionModule(pb) { NewSiteAction.prototype.render = function(cb) { var self = this; + var message = self.hasRequiredParams(self.body, self.getRequiredFields()); + if(message) { + cb({ + code: 400, + content: pb.BaseController.apiResponse(pb.BaseController.API_ERROR, message) + }); + return; + } + + if(!pb.security.isAuthorized(self.session, {admin_level: self.body.admin})) { + cb({ + code: 400, + content: pb.BaseController.apiResponse(pb.BaseController.API_ERROR, self.ls.get('INSUFFICIENT_CREDENTIALS')) + }); + return; + } - this.getJSONPostParams(function(err, post) { - var message = self.hasRequiredParams(post, self.getRequiredFields()); - if(message) { + var siteService = new pb.SiteService(); + var site = pb.DocumentCreator.create('site', self.body); + + siteService.createSite(site, self.body.id, function(err, isTaken, field, result) { + if(isTaken) { cb({ code: 400, - content: pb.BaseController.apiResponse(pb.BaseController.API_ERROR, message) + content: pb.BaseController.apiResponse(pb.BaseController.API_ERROR, self.ls.get('DUPLICATE_INFO')) }); - return; - } - if(!pb.security.isAuthorized(self.session, {admin_level: post.admin})) { + } + if(util.isError(err)) { cb({ - code: 400, - content: pb.BaseController.apiResponse(pb.BaseController.API_ERROR, self.ls.get('INSUFFICIENT_CREDENTIALS')) + code: 500, + content: pb.BaseController.apiResponse(pb.BaseController.API_ERROR, self.ls.get('ERROR_SAVING')) }); return; } - var siteService = new pb.SiteService(); - var site = pb.DocumentCreator.create('site', post); - - siteService.createSite(site, post.id, function(err, isTaken, field, result) { - if(isTaken) { - cb({ - code: 400, - content: pb.BaseController.apiResponse(pb.BaseController.API_ERROR, self.ls.get('DUPLICATE_INFO')) - }); - - } - if(util.isError(err)) { - cb({ - code: 500, - content: pb.BaseController.apiResponse(pb.BaseController.API_ERROR, self.ls.get('ERROR_SAVING')) - }); - return; - } - - cb({content: pb.BaseController.apiResponse(pb.BaseController.API_SUCCESS, self.ls.get('SITE_CREATED'), result)}); - }); + cb({content: pb.BaseController.apiResponse(pb.BaseController.API_SUCCESS, self.ls.get('SITE_CREATED'), result)}); }); }; diff --git a/plugins/pencilblue/include/routes.js b/plugins/pencilblue/include/routes.js index 714a87bc8..4e80101b9 100644 --- a/plugins/pencilblue/include/routes.js +++ b/plugins/pencilblue/include/routes.js @@ -1127,6 +1127,7 @@ module.exports = function Routes(pb){ access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, auth_required: true, inactive_site_access: true, + request_body: ['application/json'], controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'sites', 'new_site.js') }, { @@ -1135,6 +1136,7 @@ module.exports = function Routes(pb){ access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, auth_required: true, inactive_site_access: true, + request_body: ['application/json'], controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'sites', 'edit_site.js') }, { From 37d2332cb9667a6f63a6a59563b1950a63086ed6 Mon Sep 17 00:00:00 2001 From: btidwell Date: Mon, 27 Jul 2015 13:02:23 -0400 Subject: [PATCH 491/790] correct overlooked multisite check to multisite.enabled --- include/service/entities/site_query_service.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/service/entities/site_query_service.js b/include/service/entities/site_query_service.js index b4ab0ccc9..593187b0e 100644 --- a/include/service/entities/site_query_service.js +++ b/include/service/entities/site_query_service.js @@ -118,7 +118,7 @@ module.exports = function SiteQueryServiceModule(pb) { } function modifySave(site, objectToSave) { - if (pb.config.multisite && !(SITE_FIELD in objectToSave)) { + if (pb.config.multisite.enabled && !(SITE_FIELD in objectToSave)) { objectToSave[SITE_FIELD] = site; } // else do nothing From ed29c55f71a9ae12f3e6dae7e609df73feb156e6 Mon Sep 17 00:00:00 2001 From: btidwell Date: Mon, 27 Jul 2015 14:31:14 -0400 Subject: [PATCH 492/790] add basic service and controller --- include/dao/indices.js | 7 +++ include/requirements.js | 1 + include/service/entities/token_service.js | 54 +++++++++++++++++++ .../controllers/actions/auth_token.js | 48 +++++++++++++++++ 4 files changed, 110 insertions(+) create mode 100644 include/service/entities/token_service.js create mode 100644 plugins/pencilblue/controllers/actions/auth_token.js diff --git a/include/dao/indices.js b/include/dao/indices.js index e22a36ffc..8b0929c60 100644 --- a/include/dao/indices.js +++ b/include/dao/indices.js @@ -322,6 +322,13 @@ module.exports = function IndicesModule(multisite) { collection: 'lock', spec: {timeout: ASC}, options: {expireAfterSeconds: 0} + }, + + //token + { + collection: 'auth_token', + spec: {value: ASC}, + options: {unique: true} } ]; }; \ No newline at end of file diff --git a/include/requirements.js b/include/requirements.js index 07c455aeb..ba9407fc4 100755 --- a/include/requirements.js +++ b/include/requirements.js @@ -198,6 +198,7 @@ module.exports = function PB(config) { pb.UrlService = require(path.join(config.docRoot, '/include/service/entities/url_service.js'))(pb); pb.CallHomeService = require(path.join(config.docRoot, '/include/system/call_home_service.js'))(pb); pb.JobService = require(path.join(config.docRoot, '/include/service/entities/job_service.js'))(pb); + pb.TokenService = require(path.join(config.docRoot, '/include/service/entities/token_service.js'))(pb); //create plugin service pb.PluginService = require(path.join(config.docRoot, '/include/service/entities/plugin_service.js'))(pb); diff --git a/include/service/entities/token_service.js b/include/service/entities/token_service.js new file mode 100644 index 000000000..cbc6c7920 --- /dev/null +++ b/include/service/entities/token_service.js @@ -0,0 +1,54 @@ +/* + Copyright (C) 2015 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ + +var crypto = require('crypto'); + +module.exports = function TokenServiceModule(pb) { + + // + /** + * A service that manages tokens for non-password authentication. + * + * @class TokenService + * @constructor + * @module Services + * @submodule Entities + */ + function TokenService(options) { + this.site = options.site; + this.dao = new pb.SiteQueryService(this.site, false); + this.user = options.user; + } + + TokenService.prototype.generateUserToken = function(cb) { + crypto.randomBytes(48, function(err, buf) { + if(pb.util.isError(err)) { + return cb(err, null); + } + var token = buf.toString('hex'); + //TODO: Create and store token entity + cb(null, token); + }); + }; + + TokenService.prototype.validateUserToken = function(token, cb) { + cb(null, true); + }; + + //exports + return TokenService; +}; \ No newline at end of file diff --git a/plugins/pencilblue/controllers/actions/auth_token.js b/plugins/pencilblue/controllers/actions/auth_token.js new file mode 100644 index 000000000..f7d7d078b --- /dev/null +++ b/plugins/pencilblue/controllers/actions/auth_token.js @@ -0,0 +1,48 @@ +/* + Copyright (C) 2015 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ + +module.exports = function AuthTokenControllerModule(pb) { + + /** + * Creates authentication token for administrators + * and managing editors for cross site access + * + * @class AuthTokenController + * @constructor + * @extends BaseController + */ + function AuthTokenController() {} + util.inherits(AuthTokenController, pb.BaseController); + + AuthTokenController.prototype.render = function(cb) { + var self = this; + options = { + site: this.query.site, + user:self.session.authentication.user_id + }; + var tokenService = new pb.TokenService(options); + tokenService.generateUserToken(function(err, token) { + if(pb.util.isError(err)) { + return self.serveError(err); + } + self.redirect('/admin/login/token/' + token, cb); + }); + }; + + //exports + return AuthTokenController; +}; \ No newline at end of file From ecc6368474f7bd9f9efa263ba437692179dad320 Mon Sep 17 00:00:00 2001 From: andparker Date: Mon, 27 Jul 2015 16:48:32 -0400 Subject: [PATCH 493/790] Activate new site bug fix. --- include/http/request_handler.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/include/http/request_handler.js b/include/http/request_handler.js index c1da90090..25772a329 100755 --- a/include/http/request_handler.js +++ b/include/http/request_handler.js @@ -145,6 +145,9 @@ module.exports = function RequestHandlerModule(pb) { }; RequestHandler.activateSite = function(site) { + if (!RequestHandler.sites[site.hostname]) { + RequestHandler.loadSite(site) + } RequestHandler.sites[site.hostname].active = true; }; From 8fb0123a43d86f373fd0b56cc763f2eeb1ee50ad Mon Sep 17 00:00:00 2001 From: andparker Date: Tue, 28 Jul 2015 10:34:51 -0400 Subject: [PATCH 494/790] Reverts a bad merge. --- include/localization.js | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/include/localization.js b/include/localization.js index 8273d9682..09f5b764d 100755 --- a/include/localization.js +++ b/include/localization.js @@ -22,6 +22,9 @@ var locale = require('locale'); var util = require('./util.js'); module.exports = function LocalizationModule(pb) { + + //pb dependencies + var config = pb.config; /** * Provides functions to translate items based on keys. Also @@ -33,7 +36,9 @@ module.exports = function LocalizationModule(pb) { * @param {Object} request The request object */ function Localization(request){ - this.language = Localization.best(request).toString().toLowerCase().replace('-', '_'); + + //expected to be lowercase and of the form "en-us" + this.language = Localization.best(request).toString(); } /** @@ -92,7 +97,7 @@ module.exports = function LocalizationModule(pb) { */ Localization.prototype.localize = function(sets, text){ if (pb.log.isSilly()) { - pb.log.silly('Localization: Localizing text - Locale ['+this.language+'] Sets '+JSON.stringify(sets)); + pb.log.silly('Localization: Localizing text - Locale [%s] Sets %s', this.language, JSON.stringify(sets)); } //get i18n from storage @@ -112,7 +117,7 @@ module.exports = function LocalizationModule(pb) { // If the localization is for HTML output, load the localization into client side JS if (text.indexOf(' -1) { - text = text.concat(pb.ClientJs.includeJS(pb.config.siteRoot + '/localization/' + localizationLanguage + '.js')); + text = text.concat(pb.ClientJs.includeJS(pb.UrlService.createSystemUrl('api/localization/script?locale=' + this.language))); } return text; @@ -136,7 +141,7 @@ module.exports = function LocalizationModule(pb) { Localization.prototype.get = function() { var key = arguments[0]; if (pb.log.isSilly()) { - pb.log.silly('Localization: Localizing key ['+key+'] - Locale ['+this.language+']'); + pb.log.silly('Localization: Localizing key [%s] - Locale [%s]', key, this.language); } //error checking @@ -158,8 +163,8 @@ module.exports = function LocalizationModule(pb) { if (val === null) { - var defaultLocale = Localization.getDefaultLocale(); - if (this.language.toLowerCase() === defaultLocale.toLowerCase()) { + var defaultLocale = Localization.getDefaultLocale().toLocaleLowerCase(); + if (this.language === defaultLocale) { return val = key; } else { @@ -239,7 +244,7 @@ module.exports = function LocalizationModule(pb) { } //convert file name to locale - var locale = file.toLowerCase().substring(0, file.indexOf('.')).replace(/-/g, '_'); + var locale = file.toLowerCase().substring(0, file.indexOf('.')); //Register as a supported language Localization.storage[locale] = obj; @@ -262,7 +267,7 @@ module.exports = function LocalizationModule(pb) { if (!locale) { return false; } - return Localization.getLocalizationPackage(locale) !== undefined; + return Localization.getLocalizationPackage(locale) ? true : false; }; /** @@ -276,7 +281,7 @@ module.exports = function LocalizationModule(pb) { if (!pb.validation.isNonEmptyStr(locale, true)) { return null; } - return Localization.storage[locale.replace('-', '_').toLowerCase()]; + return Localization.storage[locale.toLowerCase()] || null; }; /** @@ -291,9 +296,10 @@ module.exports = function LocalizationModule(pb) { if (!Localization.isSupported(locale) || !util.isObject(localizations)) { return false; } - for (var key in localizations) { - Localization.registerLocalization(locale, key, localizations[key]); - } + + util.forEach(localizations, function(item, key) { + Localization.registerLocalization(locale, key, item); + }); return true; }; @@ -343,7 +349,7 @@ module.exports = function LocalizationModule(pb) { * @return {String} The default locale */ Localization.getDefaultLocale = function() { - return pb.config.localization.defaultLocale || 'en_us'; + return config.localization.defaultLocale || 'en-US'; }; /** From e82af39fc90c98d54b8d7d4acc2b4bb213e1d710 Mon Sep 17 00:00:00 2001 From: andparker Date: Tue, 28 Jul 2015 13:05:27 -0400 Subject: [PATCH 495/790] Reverts back the hyphen replace on the locale file. --- include/localization.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/include/localization.js b/include/localization.js index 09f5b764d..1c63d1e36 100755 --- a/include/localization.js +++ b/include/localization.js @@ -22,7 +22,7 @@ var locale = require('locale'); var util = require('./util.js'); module.exports = function LocalizationModule(pb) { - + //pb dependencies var config = pb.config; @@ -36,7 +36,7 @@ module.exports = function LocalizationModule(pb) { * @param {Object} request The request object */ function Localization(request){ - + //expected to be lowercase and of the form "en-us" this.language = Localization.best(request).toString(); } @@ -244,7 +244,7 @@ module.exports = function LocalizationModule(pb) { } //convert file name to locale - var locale = file.toLowerCase().substring(0, file.indexOf('.')); + var locale = file.toLowerCase().substring(0, file.indexOf('.')).replace(/-/g, '_'); //Register as a supported language Localization.storage[locale] = obj; @@ -296,7 +296,7 @@ module.exports = function LocalizationModule(pb) { if (!Localization.isSupported(locale) || !util.isObject(localizations)) { return false; } - + util.forEach(localizations, function(item, key) { Localization.registerLocalization(locale, key, item); }); From c3e66480e2bc5e7ef34f5ff5b3c5aed311a0f3b0 Mon Sep 17 00:00:00 2001 From: Mark Baird Date: Tue, 28 Jul 2015 13:00:07 -0400 Subject: [PATCH 496/790] Allow easy override of template paths --- .../entities/content/content_view_loader.js | 33 +++++++++++++++++-- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/include/service/entities/content/content_view_loader.js b/include/service/entities/content/content_view_loader.js index a0167f429..fd671c25b 100644 --- a/include/service/entities/content/content_view_loader.js +++ b/include/service/entities/content/content_view_loader.js @@ -407,10 +407,19 @@ module.exports = function(pb) { cb(err, new pb.TemplateValue(comments, false)); }); }); - ats.load('elements/article', cb); + ats.load(self.getDefaultContentTemplatePath(), cb); options.contentIndex++; }; + + /** + * + * @method getDefaultContentTemplatePath + * @return {String} + */ + ContentViewLoader.prototype.getDefaultContentTemplatePath = function() { + return 'elements/article'; + }; /** * @@ -452,7 +461,16 @@ module.exports = function(pb) { cb(err, new pb.TemplateValue(results.join(''), false)); }); }); - ts.load('elements/comments', cb); + ts.load(self.getDefaultCommentsTemplatePath(), cb); + }; + + /** + * + * @method getDefaultCommentsTemplatePath + * @return {String} + */ + ContentViewLoader.prototype.getDefaultCommentsTemplatePath = function() { + return 'elements/comments'; }; /** @@ -471,7 +489,16 @@ module.exports = function(pb) { cts.registerLocal('commenter_position', comment.commenter_position ? ', ' + comment.commenter_position : ''); cts.registerLocal('content', comment.content); cts.registerLocal('timestamp', comment.timestamp); - cts.load('elements/comments/comment', cb); + cts.load(self.getDefaultCommentTemplatePath(), cb); + }; + + /** + * + * @method getDefaultCommentTemplatePath + * @return {String} + */ + ContentViewLoader.prototype.getDefaultCommentTemplatePath = function() { + return 'elements/comments/comment'; }; /** From 58900d305d3bd5554022770293de58a4720839ab Mon Sep 17 00:00:00 2001 From: btidwell Date: Tue, 28 Jul 2015 13:22:23 -0400 Subject: [PATCH 497/790] Create token on site click in manage_sites view --- include/dao/indices.js | 2 +- include/service/entities/token_service.js | 26 +++++++++++++++---- .../actions/{ => admin/sites}/auth_token.js | 19 ++++++++++---- plugins/pencilblue/include/routes.js | 9 +++++++ .../templates/admin/sites/manage_sites.html | 4 +-- .../angular/admin/sites/manage_sites.html | 22 ++++++++++++++++ 6 files changed, 69 insertions(+), 13 deletions(-) rename plugins/pencilblue/controllers/actions/{ => admin/sites}/auth_token.js (71%) diff --git a/include/dao/indices.js b/include/dao/indices.js index 8b0929c60..eebabba19 100644 --- a/include/dao/indices.js +++ b/include/dao/indices.js @@ -327,7 +327,7 @@ module.exports = function IndicesModule(multisite) { //token { collection: 'auth_token', - spec: {value: ASC}, + spec: {token: ASC}, options: {unique: true} } ]; diff --git a/include/service/entities/token_service.js b/include/service/entities/token_service.js index cbc6c7920..5c9f80548 100644 --- a/include/service/entities/token_service.js +++ b/include/service/entities/token_service.js @@ -15,11 +15,11 @@ along with this program. If not, see . */ -var crypto = require('crypto'); - module.exports = function TokenServiceModule(pb) { - // + //dependencies + var crypto = require('crypto'); + /** * A service that manages tokens for non-password authentication. * @@ -35,13 +35,29 @@ module.exports = function TokenServiceModule(pb) { } TokenService.prototype.generateUserToken = function(cb) { + var self = this; crypto.randomBytes(48, function(err, buf) { if(pb.util.isError(err)) { return cb(err, null); } - var token = buf.toString('hex'); + var token = buf.toString('base64'); //TODO: Create and store token entity - cb(null, token); + var tokenInfo = { + token: token, + user: self.user, + used: false + } + self.saveToken(tokenInfo, cb); + }); + }; + + TokenService.prototype.saveToken = function(tokenInfo, cb) { + var doc = pb.DocumentCreator.create('auth_token', tokenInfo); + this.dao.save(doc, function(err, result) { + if(pb.util.isError(err)) { + return cb(err, null); + } + cb(null, {token: tokenInfo.token}); }); }; diff --git a/plugins/pencilblue/controllers/actions/auth_token.js b/plugins/pencilblue/controllers/actions/admin/sites/auth_token.js similarity index 71% rename from plugins/pencilblue/controllers/actions/auth_token.js rename to plugins/pencilblue/controllers/actions/admin/sites/auth_token.js index f7d7d078b..509654de7 100644 --- a/plugins/pencilblue/controllers/actions/auth_token.js +++ b/plugins/pencilblue/controllers/actions/admin/sites/auth_token.js @@ -17,6 +17,9 @@ module.exports = function AuthTokenControllerModule(pb) { + //dependencies + var util = pb.util; + /** * Creates authentication token for administrators * and managing editors for cross site access @@ -30,16 +33,22 @@ module.exports = function AuthTokenControllerModule(pb) { AuthTokenController.prototype.render = function(cb) { var self = this; - options = { - site: this.query.site, + var options = { + site: this.pathVars.siteid, user:self.session.authentication.user_id }; var tokenService = new pb.TokenService(options); - tokenService.generateUserToken(function(err, token) { + tokenService.generateUserToken(function(err, tokenInfo) { if(pb.util.isError(err)) { - return self.serveError(err); + return cb({ + code: 500, + content: pb.BaseController.apiResponse(pb.BaseController.API_FAILURE, self.ls.get('ERROR_SAVING')) + }); } - self.redirect('/admin/login/token/' + token, cb); + cb({ + code: 200, + content: pb.BaseController.apiResponse(pb.BaseController.API_SUCCESS, 'Token Created For User', tokenInfo) + }); }); }; diff --git a/plugins/pencilblue/include/routes.js b/plugins/pencilblue/include/routes.js index 714a87bc8..7019b8777 100644 --- a/plugins/pencilblue/include/routes.js +++ b/plugins/pencilblue/include/routes.js @@ -75,6 +75,15 @@ module.exports = function Routes(pb){ controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'login.js'), content_type: 'text/html' }, + { + method: 'post', + path: "/actions/admin/sites/auth_token/:siteid", + access_level: pb.SecurityService.ACCESS_MANAGING_EDITOR, + auth_required: true, + inactive_site_access: true, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'sites', 'auth_token.js'), + content_type: 'application/json' + }, { method: 'post', path: "/actions/forgot_password", diff --git a/plugins/pencilblue/templates/admin/sites/manage_sites.html b/plugins/pencilblue/templates/admin/sites/manage_sites.html index 363fba09c..62a8b5fdc 100644 --- a/plugins/pencilblue/templates/admin/sites/manage_sites.html +++ b/plugins/pencilblue/templates/admin/sites/manage_sites.html @@ -18,7 +18,7 @@ - + - + - + - + + + + + diff --git a/public/localization/de-DE.js b/public/localization/de-DE.js index c7110eeff..c4a4b851b 100644 --- a/public/localization/de-DE.js +++ b/public/localization/de-DE.js @@ -460,6 +460,7 @@ module.exports = { EDIT_CONFIGURATION: 'Um die Konfiguration zu bearbeiten, müssen die die Datei "config.json" im Root-Verzeichnis anlegen.', SITE_NAME: 'Name der Site', SITE_ROOT: 'Root-Verzeichnis der Site', + MEDIA_ROOT: 'Root-Verzeichnis der Medientyp', DOCUMENT_ROOT: 'Basisverzeichnis für Dokumente', IP_ADDRESS: 'IP Adresse', PORT: 'Port', diff --git a/public/localization/en-US.js b/public/localization/en-US.js index 23c44fde7..30f8e2c45 100644 --- a/public/localization/en-US.js +++ b/public/localization/en-US.js @@ -437,6 +437,7 @@ module.exports = { EDIT_CONFIGURATION: 'To edit the configuration, create a config.json file in the root directory', SITE_NAME: 'Site name', SITE_ROOT: 'Site root', + MEDIA_ROOT: 'Media root', DOCUMENT_ROOT: 'Document root', IP_ADDRESS: 'IP address', PORT: 'Port', diff --git a/public/localization/es-ES.js b/public/localization/es-ES.js index 6e1715f52..abd4f8bc0 100644 --- a/public/localization/es-ES.js +++ b/public/localization/es-ES.js @@ -436,6 +436,7 @@ module.exports = { EDIT_CONFIGURATION: 'Para cambiar la configuración, crea un archivo config.json en el directorio raíz.', SITE_NAME: 'Nombre del sitio', SITE_ROOT: 'Raíz del sitio', + MEDIA_ROOT: 'Raíz del multimedia', DOCUMENT_ROOT: 'Document root', IP_ADDRESS: 'Dirección IP', PORT: 'Puerto', diff --git a/public/localization/fr-FR.js b/public/localization/fr-FR.js index 3d82a0c33..a92c66f8e 100755 --- a/public/localization/fr-FR.js +++ b/public/localization/fr-FR.js @@ -437,6 +437,7 @@ module.exports = { EDIT_CONFIGURATION: 'Pour éditer la configuration, créer un fichier config.json dans le répertoire racine', SITE_NAME: 'Nom du site', SITE_ROOT: 'Racine du site', + MEDIA_ROOT: 'Racine du média', DOCUMENT_ROOT: 'Document racine', IP_ADDRESS: 'Adresse IP', PORT: 'Port', diff --git a/public/localization/pl-PL.js b/public/localization/pl-PL.js index 2dfe58b09..5a6c67184 100644 --- a/public/localization/pl-PL.js +++ b/public/localization/pl-PL.js @@ -439,6 +439,7 @@ module.exports = { EDIT_CONFIGURATION: 'Aby zedytować ustawienia stwórz plik config.json w katalogu głównym', SITE_NAME: 'Nazwa strony', SITE_ROOT: 'Katalog główny strony', + MEDIA_ROOT: 'Korzeń mediów', DOCUMENT_ROOT: 'Document root', IP_ADDRESS: 'Adres IP', PORT: 'Port', diff --git a/public/localization/pt-BR.js b/public/localization/pt-BR.js index c8fb65932..898fa6d8c 100644 --- a/public/localization/pt-BR.js +++ b/public/localization/pt-BR.js @@ -437,6 +437,7 @@ module.exports = { EDIT_CONFIGURATION: 'Para editar as configurações, crie um config.json na raiz do diretório', SITE_NAME: 'Nome do site', SITE_ROOT: 'Raiz do site', + MEDIA_ROOT: 'Raiz do mídia', DOCUMENT_ROOT: 'Raiz do documento', IP_ADDRESS: 'Endereço IP', PORT: 'Porta', diff --git a/public/localization/ro-RO.js b/public/localization/ro-RO.js index e5b209c17..458352a85 100644 --- a/public/localization/ro-RO.js +++ b/public/localization/ro-RO.js @@ -430,6 +430,7 @@ module.exports = { EDIT_CONFIGURATION: 'Pentru a edita configurarea creaza un fisier config.json in folderul radacina', SITE_NAME: 'Nume sit', SITE_ROOT: 'Radacina sit', + MEDIA_ROOT: 'Radacina media', DOCUMENT_ROOT: 'Radacina document', IP_ADDRESS: 'Adresa IP', PORT: 'Port', diff --git a/test/include/service/entities/content/article_renderer_tests.js b/test/include/service/entities/content/article_renderer_tests.js index dfaad8fc0..120f1c548 100644 --- a/test/include/service/entities/content/article_renderer_tests.js +++ b/test/include/service/entities/content/article_renderer_tests.js @@ -42,7 +42,7 @@ describe('ArticleRenderer', function() { var service = new ArticleRenderer(); service.formatLayoutForReadMore(article, context); - var count = (article.article_layout.match(/Read More/g)).length + var count = (article.article_layout.match(/Read More/g)).length; count.should.eql(1); }); diff --git a/test/include/service/entities/content/article_service_v2_tests.js b/test/include/service/entities/content/article_service_v2_tests.js index 414b4aed4..b3d6843e7 100644 --- a/test/include/service/entities/content/article_service_v2_tests.js +++ b/test/include/service/entities/content/article_service_v2_tests.js @@ -15,7 +15,7 @@ describe('ArticleServiceV2', function() { var article2 = getArticle(); // Set expected date to the parsed version of the date being passed to the service - article2.publish_date = pb.BaseObjectService.getDate(article2.publish_date) + article2.publish_date = pb.BaseObjectService.getDate(article2.publish_date); ArticleServiceV2.format({data: article}, function() {}); should.deepEqual(article, article2); diff --git a/test/include/service/entities/content/page_service_tests.js b/test/include/service/entities/content/page_service_tests.js index eba49dc4d..3ce8352ef 100644 --- a/test/include/service/entities/content/page_service_tests.js +++ b/test/include/service/entities/content/page_service_tests.js @@ -15,7 +15,7 @@ describe('PageService', function() { var page2 = getPage(); // Set expected date to the parsed version of the date being passed to the service - page2.publish_date = pb.BaseObjectService.getDate(page2.publish_date) + page2.publish_date = pb.BaseObjectService.getDate(page2.publish_date); PageService.format({data: page}, function() {}); should.deepEqual(page, page2); diff --git a/test/include/service/media/renderers/media_root_tests.js b/test/include/service/media/renderers/media_root_tests.js new file mode 100644 index 000000000..9b39cf0e7 --- /dev/null +++ b/test/include/service/media/renderers/media_root_tests.js @@ -0,0 +1,128 @@ +//depedencies +var should = require('should'); + + +describe('BaseMediaRenderer', function() { + describe('BaseMediaRenderer.getEmbedUrl', function () { + it('should not modify media id', function () { + var pb = {config: {siteRoot: 'http://www.test.com', media: {urlRoot: ''}}}; + pb.UrlService = require('../../../../../include/service/entities/url_service.js')(pb); + var BaseMediaRenderer = require('../../../../../include/service/media/renderers/base_media_renderer.js')(pb); + + var url = BaseMediaRenderer.getEmbedUrl("/media/01/02/test.png"); + url.should.eql("/media/01/02/test.png"); + }); + + it('should prepend media root', function () { + var pb = {config: {siteRoot: 'http://www.test.com', media: {urlRoot: 'http://cdn.test.com'}}}; + pb.UrlService = require('../../../../../include/service/entities/url_service.js')(pb); + var BaseMediaRenderer = require('../../../../../include/service/media/renderers/base_media_renderer.js')(pb); + + var url = BaseMediaRenderer.getEmbedUrl("/media/01/02/test.png"); + url.should.eql("http://cdn.test.com/media/01/02/test.png"); + }); + }); +}); + +describe('ImageMediaRenderer', function() { + describe('ImageMediaRenderer.getEmbedUrl', function () { + it('should prepend media root', function () { + var pb = { + config: {siteRoot: 'http://www.test.com', media: {urlRoot: 'http://cdn.test.com'}}, + media: {renderers: {}} + }; + pb.UrlService = require('../../../../../include/service/entities/url_service.js')(pb); + pb.media.renderers.BaseMediaRenderer = require('../../../../../include/service/media/renderers/base_media_renderer.js')(pb); + var ImageMediaRenderer = require('../../../../../include/service/media/renderers/image_media_renderer.js')(pb); + + var url = ImageMediaRenderer.getEmbedUrl("/media/01/02/test.png"); + url.should.eql("http://cdn.test.com/media/01/02/test.png"); + }); + }); +}); + +describe('AudioMediaRenderer', function() { + describe('AudioMediaRenderer.getEmbedUrl', function () { + it('should prepend media root', function () { + var pb = { + config: {siteRoot: 'http://www.test.com', media: {urlRoot: 'http://cdn.test.com'}}, + media: {renderers: {}} + }; + pb.UrlService = require('../../../../../include/service/entities/url_service.js')(pb); + pb.media.renderers.BaseMediaRenderer = require('../../../../../include/service/media/renderers/base_media_renderer.js')(pb); + var AudioMediaRenderer = require('../../../../../include/service/media/renderers/audio_media_renderer.js')(pb); + + var url = AudioMediaRenderer.getEmbedUrl("/media/01/02/test.mp3"); + url.should.eql("http://cdn.test.com/media/01/02/test.mp3"); + }); + }); +}); + +describe('PdfMediaRenderer', function() { + describe('PdfMediaRenderer.getEmbedUrl', function () { + it('should prepend media root', function () { + var pb = { + config: {siteRoot: 'http://www.test.com', media: {urlRoot: 'http://cdn.test.com'}}, + media: {renderers: {}} + }; + pb.UrlService = require('../../../../../include/service/entities/url_service.js')(pb); + pb.media.renderers.BaseMediaRenderer = require('../../../../../include/service/media/renderers/base_media_renderer.js')(pb); + var PdfMediaRenderer = require('../../../../../include/service/media/renderers/pdf_media_renderer.js')(pb); + + var url = PdfMediaRenderer.getEmbedUrl("/media/01/02/test.pdf"); + url.should.eql("http://cdn.test.com/media/01/02/test.pdf"); + }); + }); +}); + +describe('VideoMediaRenderer', function() { + describe('VideoMediaRenderer.getEmbedUrl', function () { + it('should prepend media root', function () { + var pb = { + config: {siteRoot: 'http://www.test.com', media: {urlRoot: 'http://cdn.test.com'}}, + media: {renderers: {}} + }; + pb.UrlService = require('../../../../../include/service/entities/url_service.js')(pb); + pb.media.renderers.BaseMediaRenderer = require('../../../../../include/service/media/renderers/base_media_renderer.js')(pb); + var VideoMediaRenderer = require('../../../../../include/service/media/renderers/video_media_renderer.js')(pb); + + var url = VideoMediaRenderer.getEmbedUrl("/media/01/02/test.webm"); + url.should.eql("http://cdn.test.com/media/01/02/test.webm"); + }); + }); +}); + +describe('VideoMediaRenderer', function() { + describe('VideoMediaRenderer.getEmbedUrl', function () { + it('should prepend media root', function () { + var pb = { + config: {siteRoot: 'http://www.test.com', media: {urlRoot: 'http://cdn.test.com'}}, + media: {renderers: {}} + }; + pb.UrlService = require('../../../../../include/service/entities/url_service.js')(pb); + pb.media.renderers.BaseMediaRenderer = require('../../../../../include/service/media/renderers/base_media_renderer.js')(pb); + var VideoMediaRenderer = require('../../../../../include/service/media/renderers/video_media_renderer.js')(pb); + + var url = VideoMediaRenderer.getEmbedUrl("/media/01/02/test.webm"); + url.should.eql("http://cdn.test.com/media/01/02/test.webm"); + }); + }); +}); + +describe('YouTubeMediaRenderer', function() { + describe('YouTubeMediaRenderer.getEmbedUrl', function () { + it('should not prepend media root', function () { + var pb = { + config: {siteRoot: 'http://www.test.com', media: {urlRoot: 'http://cdn.test.com'}}, + media: {renderers: {}} + }; + pb.UrlService = require('../../../../../include/service/entities/url_service.js')(pb); + pb.media.renderers.BaseMediaRenderer = require('../../../../../include/service/media/renderers/base_media_renderer.js')(pb); + var YouTubeMediaRenderer = require('../../../../../include/service/media/renderers/youtube_media_renderer.js')(pb); + + var url = YouTubeMediaRenderer.getEmbedUrl("mediaID"); + url.should.startWith("//www.youtube.com"); + url.indexOf(pb.config.media.urlRoot).should.eql(-1); + }); + }); +}); \ No newline at end of file From d69bdd9ce410d434e8994270a1e88381c247ac77 Mon Sep 17 00:00:00 2001 From: Blake Callens Date: Sat, 19 Sep 2015 20:44:40 -0400 Subject: [PATCH 639/790] manage pages and ux changes --- .../admin/content/articles/manage_articles.js | 2 - .../admin/content/pages/manage_pages.js | 72 +------ .../api/content/article_api_controller.js | 5 + .../api/content/page_api_controller.js | 45 ++++- .../admin/content/pages/manage_pages.html | 35 ++-- .../admin/elements/search_input.html | 2 +- .../content/articles/manage_articles.html | 2 +- .../admin/content/pages/manage_pages.html | 177 +++++++++++++----- public/js/angular/factories/admin/page.js | 41 ++++ 9 files changed, 247 insertions(+), 134 deletions(-) create mode 100644 public/js/angular/factories/admin/page.js diff --git a/plugins/pencilblue/controllers/admin/content/articles/manage_articles.js b/plugins/pencilblue/controllers/admin/content/articles/manage_articles.js index 30fb09437..301656dc8 100755 --- a/plugins/pencilblue/controllers/admin/content/articles/manage_articles.js +++ b/plugins/pencilblue/controllers/admin/content/articles/manage_articles.js @@ -32,7 +32,6 @@ module.exports = function(pb) { ManageArticles.prototype.render = function(cb) { var self = this; - var where = {}; if(!pb.security.isAuthorized(this.session, {logged_in: true, admin_level: pb.SecurityService.ACCESS_EDITOR})) { where.author = this.session.authentication.user_id; } @@ -42,7 +41,6 @@ module.exports = function(pb) { pills: self.getAdminPills(SUB_NAV_KEY, self.ls, SUB_NAV_KEY) }); - var manageArticlesStr = self.ls.get('MANAGE_ARTICLES'); self.setPageName(self.ls.get('MANAGE_ARTICLES')); self.ts.registerLocal('angular_objects', new pb.TemplateValue(angularObjects, false)); self.ts.load('admin/content/articles/manage_articles', function (err, data) { diff --git a/plugins/pencilblue/controllers/admin/content/pages/manage_pages.js b/plugins/pencilblue/controllers/admin/content/pages/manage_pages.js index 3267eeca0..005ee2c79 100755 --- a/plugins/pencilblue/controllers/admin/content/pages/manage_pages.js +++ b/plugins/pencilblue/controllers/admin/content/pages/manage_pages.js @@ -16,11 +16,11 @@ */ module.exports = function(pb) { - + //pb dependencies var util = pb.util; var UserService = pb.UserService; - + /** * Interface for managing pages */ @@ -33,68 +33,16 @@ module.exports = function(pb) { ManagePages.prototype.render = function(cb) { var self = this; - var opts = { - select: pb.DAO.PROJECT_ALL, - where: pb.DAO.ANYWHERE, - order: {headline: pb.DAO.ASC} - }; - self.siteQueryService.q('page', opts, function(err, pages) { - if (util.isError(err)) { - return self.reqHandler.serveError(err); - } - else if(pages.length === 0) { - return self.redirect('/admin/content/pages/new', cb); - } - - var userService = new UserService(self.getServiceContext()); - userService.getAuthors(pages, function(err, pagesWithAuthor) { - self.getAngularObjects(pagesWithAuthor, function(angularObjects) { - var title = self.ls.get('MANAGE_PAGES'); - self.setPageName(title); - self.ts.registerLocal('angular_objects', new pb.TemplateValue(angularObjects, false)); - self.ts.load('admin/content/pages/manage_pages', function(err, data) { - var result = '' + data; - cb({content: result}); - }); - }); - }); + var angularObjects = pb.ClientJs.getAngularObjects({ + navigation: pb.AdminNavigation.get(self.session, ['content', 'pages'], self.ls, self.site), + pills: self.getAdminPills(SUB_NAV_KEY, self.ls, SUB_NAV_KEY) }); - }; - ManagePages.prototype.getPageStatuses = function(pages) { - var now = new Date(); - for(var i = 0; i < pages.length; i++) { - if(pages[i].draft) { - pages[i].status = this.ls.get('DRAFT'); - } - else if(pages[i].publish_date > now) { - pages[i].status = this.ls.get('UNPUBLISHED'); - } - else { - pages[i].status = this.ls.get('PUBLISHED'); - } - } - - return pages; - }; - - ManagePages.prototype.getAngularObjects = function(pagesWithAuthor, cb) { - var self = this; - pb.AdminSubnavService.getWithSite(SUB_NAV_KEY, self.ls, 'manage_pages', {site: self.site}, function(err, pills) { - //Log error. Don't return - if (util.isError(err)) { - pills = []; - pb.log.error("ManagePages: AdminSubnavService.getWithState callback error. ERROR[%s]", err.stack); - } - - var angularObjects = pb.ClientJs.getAngularObjects({ - navigation: pb.AdminNavigation.get(self.session, ['content', 'pages'], self.ls, self.site), - pills: pills, - pages: self.getPageStatuses(pagesWithAuthor) - }); - - //TODO: err first arg for style. User experience error when no pills? - cb(angularObjects); + self.setPageName(self.ls.get('MANAGE_PAGES')); + self.ts.registerLocal('angular_objects', new pb.TemplateValue(angularObjects, false)); + self.ts.load('admin/content/pages/manage_pages', function(err, data) { + var result = '' + data; + cb({content: result}); }); }; diff --git a/plugins/pencilblue/controllers/api/content/article_api_controller.js b/plugins/pencilblue/controllers/api/content/article_api_controller.js index a07e3cd99..48edb1993 100644 --- a/plugins/pencilblue/controllers/api/content/article_api_controller.js +++ b/plugins/pencilblue/controllers/api/content/article_api_controller.js @@ -62,6 +62,11 @@ module.exports = function(pb) { ArticleApiController.super_.prototype.init.apply(this, [context, init]); }; + /** + * Retrieves one or more resources from a collection. + * @method getAll + * @param {Function} cb + */ ArticleApiController.prototype.getAll = function(cb) { var self = this; var options = this.processQuery(); diff --git a/plugins/pencilblue/controllers/api/content/page_api_controller.js b/plugins/pencilblue/controllers/api/content/page_api_controller.js index d3e55e15b..79bd1b53f 100644 --- a/plugins/pencilblue/controllers/api/content/page_api_controller.js +++ b/plugins/pencilblue/controllers/api/content/page_api_controller.js @@ -21,16 +21,17 @@ module.exports = function(pb) { var util = pb.util; var PageService = pb.PageService; var SecurityService = pb.SecurityService; + var UserService = pb.UserService; /** - * + * * @class PageApiController * @constructor * @extends BaseApiController */ function PageApiController(){} util.inherits(PageApiController, pb.BaseApiController); - + /** * Initializes the controller * @method init @@ -40,19 +41,45 @@ module.exports = function(pb) { PageApiController.prototype.init = function(context, cb) { var self = this; var init = function(err) { - + /** - * + * * @property service * @type {ArticleServiceV2} */ self.service = new PageService(self.getServiceContext()); - + cb(err, true); }; PageApiController.super_.prototype.init.apply(this, [context, init]); }; - + + /** + * Retrieves one or more resources from a collection. + * @method getAll + * @param {Function} cb + */ + PageApiController.prototype.getAll = function(cb) { + var self = this; + var options = this.processQuery(); + + this.service.getAllWithCount(options, function(err, obj) { + if (util.isError(err)) { + return cb(err); + } + else if (util.isNullOrUndefined(obj)) { + return self.notFound(cb); + } + + var userService = new UserService(self.getServiceContext()); + userService.getAuthors(obj.data, function(err, pagesWithAuthorNames) { + cb({ + content: obj + }); + }); + }); + }; + /** * Processes the query string to develop the where clause for the query request * @method processWhere @@ -62,11 +89,11 @@ module.exports = function(pb) { PageApiController.prototype.processWhere = function(q) { var where = null; var failures = []; - + //build query & get results var search = q.q; if (pb.ValidationService.isNonEmptyStr(search, true)) { - + var patternStr = ".*" + util.escapeRegExp(search) + ".*"; var pattern = new RegExp(patternStr, "i"); where = { @@ -85,4 +112,4 @@ module.exports = function(pb) { //exports return PageApiController; -}; \ No newline at end of file +}; diff --git a/plugins/pencilblue/templates/admin/content/pages/manage_pages.html b/plugins/pencilblue/templates/admin/content/pages/manage_pages.html index a7b9b42f9..441d6137a 100755 --- a/plugins/pencilblue/templates/admin/content/pages/manage_pages.html +++ b/plugins/pencilblue/templates/admin/content/pages/manage_pages.html @@ -1,23 +1,28 @@ ^tmp_admin=head^
- ^tmp_admin=elements=error_success^ - ^tmp_admin=elements=sub_nav^ - ^tmp_admin=elements=search_input^ + ^tmp_admin=elements=error_success^ + ^tmp_admin=elements=sub_nav^ + ^tmp_admin=elements=search_input^ +
+ +
+
-
@@ -45,7 +45,7 @@
From bb4dd6669e9a7c74f2e4840a71f3ba650b38ed20 Mon Sep 17 00:00:00 2001 From: btidwell Date: Wed, 3 Jun 2015 16:13:36 -0400 Subject: [PATCH 263/790] remove references of path var siteid in portfolio home page settings --- plugins/portfolio/controllers/home_page_settings.js | 7 ------- plugins/portfolio/portfolio.js | 8 +------- 2 files changed, 1 insertion(+), 14 deletions(-) diff --git a/plugins/portfolio/controllers/home_page_settings.js b/plugins/portfolio/controllers/home_page_settings.js index 271f939cd..9d7a4db4e 100755 --- a/plugins/portfolio/controllers/home_page_settings.js +++ b/plugins/portfolio/controllers/home_page_settings.js @@ -114,13 +114,6 @@ module.exports = function HomePageSettingsModule(pb) { auth_required: true, access_level: pb.SecurityService.ACCESS_EDITOR, content_type: 'text/html' - }, - { - method: 'get', - path: '/admin/:siteid/plugins/portfolio/settings/home_page', - auth_required: true, - access_level: pb.SecurityService.ACCESS_EDITOR, - content_type: 'text/html' } ]; cb(null, routes); diff --git a/plugins/portfolio/portfolio.js b/plugins/portfolio/portfolio.js index eb3300656..1e503e8cd 100755 --- a/plugins/portfolio/portfolio.js +++ b/plugins/portfolio/portfolio.js @@ -43,18 +43,12 @@ module.exports = function PortfolioModule(pb) { pb.AdminSubnavService.registerFor('plugin_settings', function(navKey, localization, data) { if(data.plugin.uid === 'portfolio') { var href; - if(pb.config.multisite) { - href = '/admin/:siteid/plugins/portfolio/settings/home_page'; - } - else { - href = '/admin/plugins/portfolio/settings/home_page' - } return [ { name: 'home_page_settings', title: 'Home page settings', icon: 'home', - href: href + href: '/admin/plugins/portfolio/settings/home_page' } ]; } From 53b20f50cd61dfccce6c456fd680dfbbd812f66f Mon Sep 17 00:00:00 2001 From: Christina Chatham Date: Wed, 3 Jun 2015 16:17:38 -0400 Subject: [PATCH 264/790] making verification link work in the email --- controllers/base_controller.js | 2 +- include/http/request_handler.js | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/controllers/base_controller.js b/controllers/base_controller.js index cb53710bc..789169e83 100755 --- a/controllers/base_controller.js +++ b/controllers/base_controller.js @@ -200,7 +200,7 @@ module.exports = function BaseControllerModule(pb) { return; } else { - cb(pb.RequestHandler.generateRedirect(siteProps.hostname + redirectLocation)); + cb(pb.RequestHandler.generateRedirect(redirectLocation)); } }); diff --git a/include/http/request_handler.js b/include/http/request_handler.js index 9dae543bf..8c7330d9a 100755 --- a/include/http/request_handler.js +++ b/include/http/request_handler.js @@ -1199,7 +1199,6 @@ module.exports = function RequestHandlerModule(pb) { * @param {String} location */ RequestHandler.prototype.doRedirect = function(location) { - location = pb.SiteService.getSiteProtocol(location); this.resp.statusCode = 302; this.resp.setHeader("Location", location); this.resp.end(); From a94ca25aee14df9ae18dc22fabf978135aab2681 Mon Sep 17 00:00:00 2001 From: btidwell Date: Wed, 3 Jun 2015 16:45:33 -0400 Subject: [PATCH 265/790] remove site prefix reference in home_page_settings controller --- include/service/admin/admin_subnav_service.js | 3 --- plugins/portfolio/controllers/home_page_settings.js | 4 ++-- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/include/service/admin/admin_subnav_service.js b/include/service/admin/admin_subnav_service.js index c6e91b9bf..858d7319d 100755 --- a/include/service/admin/admin_subnav_service.js +++ b/include/service/admin/admin_subnav_service.js @@ -122,9 +122,6 @@ module.exports = function AdminSubnavServiceModule(pb) { if (items[j] && items[j].name === activePill) { items[j].active = 'active'; } - if(items[j].href && data && data.plugin && data.plugin.site) { - items[j].href = items[j].href.replace(':siteid', data.plugin.site); - } navItems.push(items[j]); } } diff --git a/plugins/portfolio/controllers/home_page_settings.js b/plugins/portfolio/controllers/home_page_settings.js index 9d7a4db4e..b0b9db035 100755 --- a/plugins/portfolio/controllers/home_page_settings.js +++ b/plugins/portfolio/controllers/home_page_settings.js @@ -80,7 +80,7 @@ module.exports = function HomePageSettingsModule(pb) { var objects = { navigation: pb.AdminNavigation.get(self.session, ['plugins', 'manage'], self.ls), - pills: self.getAdminPills(SUB_NAV_KEY, self.ls, null, {sitePrefix: self.sitePrefix}), + pills: self.getAdminPills(SUB_NAV_KEY, self.ls, null), tabs: tabs, media: media, homePageSettings: homePageSettings @@ -101,7 +101,7 @@ module.exports = function HomePageSettingsModule(pb) { name: 'content_settings', title: ls.get('HOME_PAGE_SETTINGS'), icon: 'chevron-left', - href: '/admin'+ data.sitePrefix + '/plugins/portfolio/settings' + href: '/admin/plugins/portfolio/settings' } ]; }; From b005bc4371117164c13da0e6381490e1bf83e77b Mon Sep 17 00:00:00 2001 From: Christina Chatham Date: Thu, 4 Jun 2015 09:44:16 -0400 Subject: [PATCH 266/790] starting forgot password email --- include/service/entities/user_service.js | 9 ++++++--- .../pencilblue/controllers/actions/forgot_password.js | 3 ++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/include/service/entities/user_service.js b/include/service/entities/user_service.js index 50278aa8a..c36c08c5b 100755 --- a/include/service/entities/user_service.js +++ b/include/service/entities/user_service.js @@ -254,10 +254,13 @@ module.exports = function UserServiceModule(pb) { * @param {Function} cb Callback function */ UserService.prototype.sendPasswordResetEmail = function(user, passwordReset, cb) { + var self = this; cb = cb || util.cb; - pb.SiteService.getByUid(this.site, function(err, siteInfo) { - var verficationUrl = pb.UrlService.urlJoin(siteInfo.hostname, '/actions/user/reset_password') + var siteService = new pb.SiteService(); + siteService.getByUid(self.siteUID, function(err, siteInfo) { + var root = pb.SiteService.getSiteProtocol(siteInfo.hostname); + var verficationUrl = pb.UrlService.urlJoin(root, '/actions/user/reset_password') + util.format('?email=%s&code=%s', encodeURIComponent(user.email), encodeURIComponent(passwordReset.verification_code)); var options = { to: user.email, @@ -269,7 +272,7 @@ module.exports = function UserServiceModule(pb) { 'last_name': user.last_name } }; - var emailService = new pb.EmailService(this.site); + var emailService = new pb.EmailService(self.siteUID); emailService.sendFromTemplate(options, cb); }); }; diff --git a/plugins/pencilblue/controllers/actions/forgot_password.js b/plugins/pencilblue/controllers/actions/forgot_password.js index 938a501a5..0d88d8b11 100755 --- a/plugins/pencilblue/controllers/actions/forgot_password.js +++ b/plugins/pencilblue/controllers/actions/forgot_password.js @@ -94,7 +94,8 @@ module.exports = function ForgotPasswordControllerModule(pb) { self.session.success = self.ls.get('YOUR_PASSWORD_RESET'); self.redirect(returnURL, cb); - pb.users.sendPasswordResetEmail(user, passwordReset, util.cb); + var userService = new pb.UserService(self.site); + userService.sendPasswordResetEmail(user, passwordReset, util.cb); }); }); }); From 5ab08a89d5e713d4d26598d355915f0586ae45db Mon Sep 17 00:00:00 2001 From: btidwell Date: Thu, 4 Jun 2015 09:57:42 -0400 Subject: [PATCH 267/790] Remove site prefix and site path id variable from views and page controllers for article --- .../controllers/admin/content/articles/article_form.js | 10 ++++------ .../admin/content/articles/manage_articles.js | 10 +++------- .../admin/content/articles/manage_articles.html | 2 +- .../angular/admin/content/articles/article_form.html | 10 +++++----- 4 files changed, 13 insertions(+), 19 deletions(-) diff --git a/plugins/pencilblue/controllers/admin/content/articles/article_form.js b/plugins/pencilblue/controllers/admin/content/articles/article_form.js index e40ecf353..6c2d969f0 100755 --- a/plugins/pencilblue/controllers/admin/content/articles/article_form.js +++ b/plugins/pencilblue/controllers/admin/content/articles/article_form.js @@ -127,7 +127,6 @@ module.exports = function(pb) { data.article.article_topics = topics; } - data.sitePrefix = self.sitePrefix; var objects = { navigation: pb.AdminNavigation.get(this.session, ['content', 'articles'], this.ls), pills: self.getAdminPills(this.getActivePill(), this.ls, this.getActivePill(), data), @@ -138,7 +137,7 @@ module.exports = function(pb) { media: data.media, article: data.article, siteKey: pb.SiteService.SITE_FIELD, - site: self.pathSiteUId, + site: self.site, sitePrefix: self.sitePrefix }; if(data.availableAuthors) { @@ -148,17 +147,16 @@ module.exports = function(pb) { }; ArticleForm.getSubNavItems = function(key, ls, data) { - var adminPrefix = '/admin' + data.sitePrefix; return [{ name: 'manage_articles', title: data.article[pb.DAO.getIdField()] ? ls.get('EDIT') + ' ' + data.article.headline : ls.get('NEW_ARTICLE'), icon: 'chevron-left', - href: adminPrefix + '/content/articles' + href: '/admin/content/articles' }, { name: 'new_article', title: '', icon: 'plus', - href: adminPrefix + '/content/articles/new' + href: '/admin/content/articles/new' }]; }; @@ -170,7 +168,7 @@ module.exports = function(pb) { var self = this; var tasks = { templates: function(callback) { - callback(null, pb.TemplateService.getAvailableContentTemplates(self.pathSiteUId)); + callback(null, pb.TemplateService.getAvailableContentTemplates(self.site)); }, sections: function(callback) { diff --git a/plugins/pencilblue/controllers/admin/content/articles/manage_articles.js b/plugins/pencilblue/controllers/admin/content/articles/manage_articles.js index d1d5f1fbe..80147a86b 100755 --- a/plugins/pencilblue/controllers/admin/content/articles/manage_articles.js +++ b/plugins/pencilblue/controllers/admin/content/articles/manage_articles.js @@ -52,7 +52,7 @@ module.exports = function(pb) { pb.users.getAuthors(articles, function(err, articlesWithAuthorNames) { articles = self.getArticleStatuses(articlesWithAuthorNames); - self.getAngularObjects(self.pathSiteUId, articles, function (angularObjects) { + self.getAngularObjects(self.site, articles, function (angularObjects) { var manageArticlesStr = self.ls.get('MANAGE_ARTICLES'); self.setPageName(manageArticlesStr); self.ts.registerLocal('angular_objects', new pb.TemplateValue(angularObjects, false)); @@ -97,20 +97,16 @@ module.exports = function(pb) { }; ManageArticles.getSubNavItems = function(key, ls, data) { - var adminPrefix = '/admin'; - if(data.site) { - adminPrefix += pb.SiteService.getCurrentSitePrefix(data.site); - } return [{ name: 'manage_articles', title: ls.get('MANAGE_ARTICLES'), icon: 'refresh', - href: adminPrefix + '/content/articles' + href: '/admin/content/articles' }, { name: 'new_article', title: '', icon: 'plus', - href: adminPrefix + '/content/articles/new' + href: '/admin/content/articles/new' }]; }; diff --git a/plugins/pencilblue/templates/admin/content/articles/manage_articles.html b/plugins/pencilblue/templates/admin/content/articles/manage_articles.html index 77b374e67..3f7d3df38 100755 --- a/plugins/pencilblue/templates/admin/content/articles/manage_articles.html +++ b/plugins/pencilblue/templates/admin/content/articles/manage_articles.html @@ -7,7 +7,7 @@ ^tmp_admin=elements=table_headers^ - + diff --git a/plugins/pencilblue/templates/angular/admin/content/articles/article_form.html b/plugins/pencilblue/templates/angular/admin/content/articles/article_form.html index 17fc6fb27..72356360a 100644 --- a/plugins/pencilblue/templates/angular/admin/content/articles/article_form.html +++ b/plugins/pencilblue/templates/angular/admin/content/articles/article_form.html @@ -48,7 +48,7 @@ $scope.getArticleData(draft, function(articleData) { $scope.saving = true; if(articleData._id) { - $http.post('/actions/admin' + $scope.sitePrefix + '/content/articles/' + $scope.article._id, articleData) + $http.post('/actions/admin/content/articles/' + $scope.article._id, articleData) .success(function(result) { $scope.successMessage = result.message; $scope.article.last_modified = result.data.last_modified; @@ -60,16 +60,16 @@ }); } else { - $http.post('/actions/admin' + $scope.sitePrefix + '/content/articles', articleData) + $http.post('/actions/admin/content/articles', articleData) .success(function(result) { $scope.successMessage = result.message; $scope.saving = false; if(!result.data._id) { - $window.location = '/admin' + $scope.sitePrefix + '/content/articles'; + $window.location = '/admin/content/articles'; return; } - $window.location = '/admin' + $scope.sitePrefix + '/content/articles/' + result.data._id.toString(); + $window.location = '/admin/content/articles/' + result.data._id.toString(); }) .error(function(error, status) { $scope.errorMessage = error.message; @@ -87,7 +87,7 @@ $scope.article.draft = true; $scope.getArticleData(true, function(articleData) { $scope.saving = true; - $http.post('/actions/admin' + $scope.sitePrefix + '/content/articles/' + $scope.article._id, articleData) + $http.post('/actions/admin/content/articles/' + $scope.article._id, articleData) .success(function(result) { $scope.article.last_modified = result.data.last_modified; $timeout($scope.saveArticleDraft, 30000); From ef4b2a89ab3cf75bca8f84d462ef8e20265e306b Mon Sep 17 00:00:00 2001 From: btidwell Date: Thu, 4 Jun 2015 10:12:03 -0400 Subject: [PATCH 268/790] replace pathSiteUId with site in article action controllers --- .../controllers/actions/admin/content/articles/edit_article.js | 2 +- .../controllers/actions/admin/content/articles/new_article.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/pencilblue/controllers/actions/admin/content/articles/edit_article.js b/plugins/pencilblue/controllers/actions/admin/content/articles/edit_article.js index d7f45ca79..b35fc79a3 100755 --- a/plugins/pencilblue/controllers/actions/admin/content/articles/edit_article.js +++ b/plugins/pencilblue/controllers/actions/admin/content/articles/edit_article.js @@ -60,7 +60,7 @@ module.exports = function(pb) { post = pb.DocumentCreator.formatIntegerItems(post, ['draft']); pb.DocumentCreator.update(post, article, ['meta_keywords']); - pb.RequestHandler.urlExists(article.url, post.id, self.pathSiteUId, function(error, exists) { + pb.RequestHandler.urlExists(article.url, post.id, self.site, function(error, exists) { var testError = (error !== null && typeof error !== 'undefined'); if( testError || exists || article.url.indexOf('/admin') === 0) { diff --git a/plugins/pencilblue/controllers/actions/admin/content/articles/new_article.js b/plugins/pencilblue/controllers/actions/admin/content/articles/new_article.js index d85b34bfe..6b3a37099 100755 --- a/plugins/pencilblue/controllers/actions/admin/content/articles/new_article.js +++ b/plugins/pencilblue/controllers/actions/admin/content/articles/new_article.js @@ -47,7 +47,7 @@ module.exports = function(pb) { post = pb.DocumentCreator.formatIntegerItems(post, ['draft']); var articleDocument = pb.DocumentCreator.create('article', post, ['meta_keywords']); - pb.RequestHandler.isSystemSafeURL(articleDocument.url, null, self.pathSiteUId, function(err, isSafe) { + pb.RequestHandler.isSystemSafeURL(articleDocument.url, null, self.site, function(err, isSafe) { if(util.isError(err) || !isSafe) { cb({ code: 400, From 02a684a8a48c6b5bb559821f9ee85cfc08e2daad Mon Sep 17 00:00:00 2001 From: btidwell Date: Thu, 4 Jun 2015 10:21:40 -0400 Subject: [PATCH 269/790] remove id prefix and pathSiteUId reference for manage_pages controller and view --- .../admin/content/pages/manage_pages.js | 14 +++++--------- .../admin/content/pages/manage_pages.html | 2 +- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/plugins/pencilblue/controllers/admin/content/pages/manage_pages.js b/plugins/pencilblue/controllers/admin/content/pages/manage_pages.js index ec5229309..908347dc0 100755 --- a/plugins/pencilblue/controllers/admin/content/pages/manage_pages.js +++ b/plugins/pencilblue/controllers/admin/content/pages/manage_pages.js @@ -46,7 +46,7 @@ module.exports = function(pb) { } pb.users.getAuthors(pages, function(err, pagesWithAuthor) { - self.getAngularObjects(self.pathSiteUId, pagesWithAuthor, function(angularObjects) { + self.getAngularObjects(pagesWithAuthor, function(angularObjects) { var title = self.ls.get('MANAGE_PAGES'); self.setPageName(title); self.ts.registerLocal('angular_objects', new pb.TemplateValue(angularObjects, false)); @@ -76,9 +76,9 @@ module.exports = function(pb) { return pages; }; - ManagePages.prototype.getAngularObjects = function(site, pagesWithAuthor, cb) { + ManagePages.prototype.getAngularObjects = function(pagesWithAuthor, cb) { var self = this; - pb.AdminSubnavService.getWithSite(SUB_NAV_KEY, self.ls, 'manage_pages', {site: site}, function(pills) { + pb.AdminSubnavService.getWithSite(SUB_NAV_KEY, self.ls, 'manage_pages', {site: self.site}, function(pills) { var angularObjects = pb.ClientJs.getAngularObjects({ navigation: pb.AdminNavigation.get(self.session, ['content', 'pages'], self.ls), pills: pills, @@ -91,20 +91,16 @@ module.exports = function(pb) { }; ManagePages.getSubNavItems = function(key, ls, data) { - var adminPrefix = '/admin'; - if(data.site) { - adminPrefix += pb.SiteService.getCurrentSitePrefix(data.site); - } return [{ name: 'manage_pages', title: ls.get('MANAGE_PAGES'), icon: 'refresh', - href: adminPrefix + '/content/pages' + href: '/admin/content/pages' }, { name: 'new_page', title: '' , icon: 'plus', - href: adminPrefix + '/content/pages/new' + href: '/admin/content/pages/new' }]; }; diff --git a/plugins/pencilblue/templates/admin/content/pages/manage_pages.html b/plugins/pencilblue/templates/admin/content/pages/manage_pages.html index 8d2f10aa4..94d55cbf4 100755 --- a/plugins/pencilblue/templates/admin/content/pages/manage_pages.html +++ b/plugins/pencilblue/templates/admin/content/pages/manage_pages.html @@ -7,7 +7,7 @@
^tmp_admin=elements=table_headers^ - + From 4342ee973ef286b9af2bd23b7b976a9714213268 Mon Sep 17 00:00:00 2001 From: btidwell Date: Thu, 4 Jun 2015 10:59:00 -0400 Subject: [PATCH 270/790] remove pathSiteUId and prefix from page_form Included portfolio angular template --- .../controllers/admin/content/pages/page_form.js | 14 ++++++-------- .../angular/admin/content/pages/page_form.html | 8 ++++---- .../angular/admin/content/pages/page_form.html | 8 ++++---- 3 files changed, 14 insertions(+), 16 deletions(-) diff --git a/plugins/pencilblue/controllers/admin/content/pages/page_form.js b/plugins/pencilblue/controllers/admin/content/pages/page_form.js index 40ae3a386..d49f08ee2 100755 --- a/plugins/pencilblue/controllers/admin/content/pages/page_form.js +++ b/plugins/pencilblue/controllers/admin/content/pages/page_form.js @@ -112,8 +112,7 @@ module.exports = function(pb) { } data.page.page_topics = topics; } - - data.sitePrefix = self.sitePrefix; + var objects = { navigation: pb.AdminNavigation.get(this.session, ['content', 'pages'], this.ls), pills: self.getAdminPills(this.getActivePill(), this.ls, this.getActivePill(), data), @@ -124,7 +123,7 @@ module.exports = function(pb) { media: data.media, page: data.page, siteKey: pb.SiteService.SITE_FIELD, - site: self.pathSiteUId, + site: self.site, sitePrefix: self.sitePrefix }; if(data.availableAuthors) { @@ -139,17 +138,16 @@ module.exports = function(pb) { * */ PageFormController.getSubNavItems = function(key, ls, data) { - var adminPrefix = '/admin' + data.sitePrefix; return [{ name: 'manage_pages', title: data.page[pb.DAO.getIdField()] ? ls.get('EDIT') + ' ' + data.page.headline : ls.get('NEW_PAGE'), icon: 'chevron-left', - href: adminPrefix + '/content/pages' + href: '/admin/content/pages' }, { name: 'new_page', title: '', icon: 'plus', - href: adminPrefix + '/content/pages/new' + href: '/admin/content/pages/new' }]; }; @@ -171,7 +169,7 @@ module.exports = function(pb) { var self = this; var tasks = { templates: function(callback) { - callback(null, pb.TemplateService.getAvailableContentTemplates(self.pathSiteUId)); + callback(null, pb.TemplateService.getAvailableContentTemplates(self.site)); }, sections: function(callback) { @@ -195,7 +193,7 @@ module.exports = function(pb) { }, media: function(callback) { - var mservice = new pb.MediaService(null, self.pathSiteUId, true); + var mservice = new pb.MediaService(null, self.site, true); mservice.get(callback); }, diff --git a/plugins/pencilblue/templates/angular/admin/content/pages/page_form.html b/plugins/pencilblue/templates/angular/admin/content/pages/page_form.html index 196370a3c..41d5fa887 100644 --- a/plugins/pencilblue/templates/angular/admin/content/pages/page_form.html +++ b/plugins/pencilblue/templates/angular/admin/content/pages/page_form.html @@ -43,7 +43,7 @@ $scope.getPageData(draft, function(pageData) { $scope.saving = true; if(pageData._id) { - $http.post('/actions/admin' + $scope.sitePrefix + '/content/pages/' + $scope.page._id, pageData) + $http.post('/actions/admin/content/pages/' + $scope.page._id, pageData) .success(function(result) { $scope.successMessage = result.message; $scope.page.last_modified = result.data.last_modified; @@ -55,11 +55,11 @@ }); } else { - $http.post('/actions/admin' + $scope.sitePrefix + '/content/pages', pageData) + $http.post('/actions/admin/content/pages', pageData) .success(function(result) { $scope.successMessage = result.message; $scope.saving = false; - $window.location = '/admin' + $scope.sitePrefix + '/content/pages/' + result.data._id.toString(); + $window.location = '/admin/content/pages/' + result.data._id.toString(); }) .error(function(error, status) { $scope.errorMessage = error.message; @@ -77,7 +77,7 @@ $scope.page.draft = true; $scope.getPageData(true, function(pageData) { $scope.saving = true; - $http.post('/actions/admin' + $scope.sitePrefix + '/content/pages/' + $scope.page._id, pageData) + $http.post('/actions/admin/content/pages/' + $scope.page._id, pageData) .success(function(result) { $scope.page.last_modified = result.data.last_modified; $timeout($scope.savePageDraft, 30000); diff --git a/plugins/portfolio/templates/angular/admin/content/pages/page_form.html b/plugins/portfolio/templates/angular/admin/content/pages/page_form.html index 32e1ab3dd..a012608c7 100644 --- a/plugins/portfolio/templates/angular/admin/content/pages/page_form.html +++ b/plugins/portfolio/templates/angular/admin/content/pages/page_form.html @@ -42,7 +42,7 @@ $scope.getPageData(draft, function(pageData) { $scope.saving = true; if(pageData._id) { - $http.post('/actions/admin' + $scope.sitePrefix + '/content/pages/' + $scope.page._id, pageData) + $http.post('/actions/admin/content/pages/' + $scope.page._id, pageData) .success(function(result) { $scope.successMessage = result.message; $scope.page.last_modified = result.data.last_modified; @@ -54,11 +54,11 @@ }); } else { - $http.post('/actions/admin' + $scope.sitePrefix + '/content/pages', pageData) + $http.post('/actions/admin/content/pages', pageData) .success(function(result) { $scope.successMessage = result.message; $scope.saving = false; - $window.location = '/admin' + $scope.sitePrefix + '/content/pages/' + result.data._id.toString(); + $window.location = '/admin/content/pages/' + result.data._id.toString(); }) .error(function(error, status) { $scope.errorMessage = error.message; @@ -76,7 +76,7 @@ $scope.page.draft = true; $scope.getPageData(true, function(pageData) { $scope.saving = true; - $http.post('/actions/admin' + $scope.sitePrefix + '/content/pages/' + $scope.page._id, pageData) + $http.post('/actions/admin/content/pages/' + $scope.page._id, pageData) .success(function(result) { $scope.page.last_modified = result.data.last_modified; $timeout($scope.savePageDraft, 30000); From f24fdd6c984ab1aeb4664db9d53bcf3b1e4f9620 Mon Sep 17 00:00:00 2001 From: btidwell Date: Thu, 4 Jun 2015 11:00:21 -0400 Subject: [PATCH 271/790] change pathsiteUId reference in action controllers for pages --- .../controllers/actions/admin/content/pages/edit_page.js | 2 +- .../controllers/actions/admin/content/pages/new_page.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/pencilblue/controllers/actions/admin/content/pages/edit_page.js b/plugins/pencilblue/controllers/actions/admin/content/pages/edit_page.js index 85136a7d0..90c9c7efb 100755 --- a/plugins/pencilblue/controllers/actions/admin/content/pages/edit_page.js +++ b/plugins/pencilblue/controllers/actions/admin/content/pages/edit_page.js @@ -64,7 +64,7 @@ module.exports = function(pb) { self.setFormFieldValues(post); - pb.RequestHandler.urlExists(page.url, post.id, self.pathSiteUId, function(err, exists) { + pb.RequestHandler.urlExists(page.url, post.id, self.site, function(err, exists) { if(util.isError(err) || exists) { cb({ code: 400, diff --git a/plugins/pencilblue/controllers/actions/admin/content/pages/new_page.js b/plugins/pencilblue/controllers/actions/admin/content/pages/new_page.js index 9da414a22..50e36bacb 100755 --- a/plugins/pencilblue/controllers/actions/admin/content/pages/new_page.js +++ b/plugins/pencilblue/controllers/actions/admin/content/pages/new_page.js @@ -50,7 +50,7 @@ module.exports = function(pb) { post = pb.DocumentCreator.formatIntegerItems(post, ['draft']); var pageDocument = pb.DocumentCreator.create('page', post, ['meta_keywords']); - pb.RequestHandler.urlExists(pageDocument.url, post.id, self.pathSiteUId, function(err, exists) { + pb.RequestHandler.urlExists(pageDocument.url, post.id, self.site, function(err, exists) { if(util.isError(err) || exists) { cb({ code: 400, From ddcb7742971ec6e3c5c71f82fe5e9c61554bf60a Mon Sep 17 00:00:00 2001 From: Christina Chatham Date: Thu, 4 Jun 2015 11:09:29 -0400 Subject: [PATCH 272/790] Merge branch 'multi_tenancy' of github.com:cbdr/pencilblue into modify_users_multisite Conflicts: include/service/entities/user_service.js --- .../pencilblue/templates/admin/content/topics/topic_form.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/pencilblue/templates/admin/content/topics/topic_form.html b/plugins/pencilblue/templates/admin/content/topics/topic_form.html index 20c9fa0e8..0047408ba 100644 --- a/plugins/pencilblue/templates/admin/content/topics/topic_form.html +++ b/plugins/pencilblue/templates/admin/content/topics/topic_form.html @@ -9,7 +9,7 @@
- +
^loc_REQUIRED_FIELD^
From d58fe87815e78d8b42c5026f32ea80df9c4a1ad4 Mon Sep 17 00:00:00 2001 From: Christina Chatham Date: Thu, 4 Jun 2015 11:15:17 -0400 Subject: [PATCH 273/790] refactor user service to get site from context --- include/service/entities/user_service.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/include/service/entities/user_service.js b/include/service/entities/user_service.js index fbd3e970f..8ca788912 100755 --- a/include/service/entities/user_service.js +++ b/include/service/entities/user_service.js @@ -231,10 +231,11 @@ module.exports = function UserServiceModule(pb) { * @param {Function} cb Callback function */ UserService.prototype.sendVerificationEmail = function(user, cb) { + var self = this; cb = cb || util.cb; var siteService = new pb.SiteService(); - siteService.getByUid(this.siteUID, function(err, siteInfo) { + siteService.getByUid(self.context.site, function(err, siteInfo) { // We need to see if email settings have been saved with verification content var emailService = new pb.EmailService(this.site); emailService.getSettings(function (err, emailSettings) { @@ -273,7 +274,7 @@ module.exports = function UserServiceModule(pb) { cb = cb || util.cb; var siteService = new pb.SiteService(); - siteService.getByUid(self.siteUID, function(err, siteInfo) { + siteService.getByUid(self.context.site, function(err, siteInfo) { var root = pb.SiteService.getSiteProtocol(siteInfo.hostname); var verficationUrl = pb.UrlService.urlJoin(root, '/actions/user/reset_password') + util.format('?email=%s&code=%s', encodeURIComponent(user.email), encodeURIComponent(passwordReset.verification_code)); @@ -287,7 +288,7 @@ module.exports = function UserServiceModule(pb) { 'last_name': user.last_name } }; - var emailService = new pb.EmailService(self.siteUID); + var emailService = new pb.EmailService(self.context.site); emailService.sendFromTemplate(options, cb); }); }; @@ -325,6 +326,7 @@ module.exports = function UserServiceModule(pb) { * @param {Function} cb Callback function */ UserService.prototype.getExistingUsernameEmailCounts = function(username, email, id, cb) { + var self = this; if (util.isFunction(id)) { cb = id; id = null; @@ -337,7 +339,7 @@ module.exports = function UserServiceModule(pb) { return where; }; - var dao = new pb.SiteQueryService(this.siteUID, false); + var dao = new pb.SiteQueryService(self.context.site, false); var tasks = { verified_username: function(callback) { var expStr = util.escapeRegExp(username) + '$'; From f252f77f42d7630c30e33eff6cb347f87957aede Mon Sep 17 00:00:00 2001 From: btidwell Date: Fri, 5 Jun 2015 12:13:45 -0400 Subject: [PATCH 274/790] remove sitePrefix from redirect on new article and page creation --- .../controllers/admin/content/articles/manage_articles.js | 5 ++--- .../controllers/admin/content/pages/manage_pages.js | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/plugins/pencilblue/controllers/admin/content/articles/manage_articles.js b/plugins/pencilblue/controllers/admin/content/articles/manage_articles.js index 80147a86b..ffa254e53 100755 --- a/plugins/pencilblue/controllers/admin/content/articles/manage_articles.js +++ b/plugins/pencilblue/controllers/admin/content/articles/manage_articles.js @@ -47,7 +47,7 @@ module.exports = function(pb) { return self.reqHandler.serveError(err); } else if (articles.length <= 0) { - return self.redirect('/admin' + self.sitePrefix + '/content/articles/new', cb); + return self.redirect('/admin/content/articles/new', cb); } pb.users.getAuthors(articles, function(err, articlesWithAuthorNames) { @@ -89,8 +89,7 @@ module.exports = function(pb) { { navigation: pb.AdminNavigation.get(self.session, ['content', 'articles'], self.ls), pills: pills, - articles: articles, - sitePrefix: self.sitePrefix + articles: articles }); cb(angularObjects); }); diff --git a/plugins/pencilblue/controllers/admin/content/pages/manage_pages.js b/plugins/pencilblue/controllers/admin/content/pages/manage_pages.js index 908347dc0..567bb89fc 100755 --- a/plugins/pencilblue/controllers/admin/content/pages/manage_pages.js +++ b/plugins/pencilblue/controllers/admin/content/pages/manage_pages.js @@ -42,7 +42,7 @@ module.exports = function(pb) { return self.reqHandler.serveError(err); } else if(pages.length === 0) { - return self.redirect('/admin' + self.sitePrefix + '/content/pages/new', cb); + return self.redirect('/admin/content/pages/new', cb); } pb.users.getAuthors(pages, function(err, pagesWithAuthor) { @@ -82,8 +82,7 @@ module.exports = function(pb) { var angularObjects = pb.ClientJs.getAngularObjects({ navigation: pb.AdminNavigation.get(self.session, ['content', 'pages'], self.ls), pills: pills, - pages: self.getPageStatuses(pagesWithAuthor), - sitePrefix: self.sitePrefix + pages: self.getPageStatuses(pagesWithAuthor) }); cb(angularObjects); }); From 80af969b2060071f26cc991580f57022cea52dd0 Mon Sep 17 00:00:00 2001 From: btidwell Date: Mon, 8 Jun 2015 09:18:40 -0400 Subject: [PATCH 275/790] Remove site prefix references in content | navigation --- include/service/entities/section_service.js | 4 ++-- .../admin/content/navigation/nav_item_form.js | 7 ++----- .../controllers/admin/content/navigation/nav_map.js | 13 ++++++------- .../admin/content/navigation/nav_item_form.html | 2 +- .../templates/admin/content/navigation/nav_map.html | 6 +++--- .../admin/content/navigation/nav_item_form.html | 2 +- .../angular/admin/content/navigation/nav_map.html | 4 ++-- 7 files changed, 17 insertions(+), 21 deletions(-) diff --git a/include/service/entities/section_service.js b/include/service/entities/section_service.js index 0cc08fa2a..124254a5e 100755 --- a/include/service/entities/section_service.js +++ b/include/service/entities/section_service.js @@ -60,13 +60,13 @@ module.exports = function SectionServiceModule(pb) { * @return {Array} * @param sitePrefix */ - SectionService.getPillNavOptions = function(activePill, sitePrefix) { + SectionService.getPillNavOptions = function(activePill) { return [ { name: 'new_nav_item', title: '', icon: 'plus', - href: '/admin' + sitePrefix + '/content/navigation/new' + href: '/admin/content/navigation/new' } ]; }; diff --git a/plugins/pencilblue/controllers/admin/content/navigation/nav_item_form.js b/plugins/pencilblue/controllers/admin/content/navigation/nav_item_form.js index 219f09ee4..a039a4acd 100644 --- a/plugins/pencilblue/controllers/admin/content/navigation/nav_item_form.js +++ b/plugins/pencilblue/controllers/admin/content/navigation/nav_item_form.js @@ -56,11 +56,8 @@ module.exports = function(pb) { var navData = { item: self.navItem, - sitePrefix: self.sitePrefix }; data.pills = self.getAdminPills(self.getSubnavKey(), self.ls, self.getSubnavKey(), navData); - data.sitePrefix = self.sitePrefix; - data.site = self.pathSiteUId; var angularObjects = pb.ClientJs.getAngularObjects(data); self.setPageName(self.navItem[pb.DAO.getIdField()] ? self.navItem.name : self.ls.get('NEW_NAV_ITEM')); @@ -152,13 +149,13 @@ module.exports = function(pb) { NavItemFormController.getSubNavItems = function(key, ls, data) { var item = data.item; - var pills = SectionService.getPillNavOptions(null, data.sitePrefix); + var pills = SectionService.getPillNavOptions(null); pills.unshift( { name: 'manage_nav_items', title: item[pb.DAO.getIdField()] ? ls.get('EDIT') + ' ' + item.name : ls.get('NEW_NAV_ITEM'), icon: 'chevron-left', - href: '/admin' + data.sitePrefix + '/content/navigation' + href: '/admin/content/navigation' }); return pills; }; diff --git a/plugins/pencilblue/controllers/admin/content/navigation/nav_map.js b/plugins/pencilblue/controllers/admin/content/navigation/nav_map.js index 22a9030c8..d9ab20888 100644 --- a/plugins/pencilblue/controllers/admin/content/navigation/nav_map.js +++ b/plugins/pencilblue/controllers/admin/content/navigation/nav_map.js @@ -43,19 +43,19 @@ module.exports = function(pb) { else if(sections.length === 0) { //when no sections exist redirect to create page - return self.redirect('/admin' + self.sitePrefix + '/content/navigation/new', cb); + return self.redirect('/admin/content/navigation/new', cb); } self.settings.get('section_map', function (err, sectionMap) { if(sectionMap === null) { - self.redirect('/admin' + self.sitePrefix + '/content/navigation/new', cb); + self.redirect('/admin/content/navigation/new', cb); return; } var angularObjects = pb.ClientJs.getAngularObjects( { navigation: pb.AdminNavigation.get(self.session, ['content', 'sections'], self.ls), - pills: self.getAdminPills(SUB_NAV_KEY, self.ls, SUB_NAV_KEY, {sitePrefix: self.sitePrefix}), + pills: self.getAdminPills(SUB_NAV_KEY, self.ls, SUB_NAV_KEY), navItems: NavigationMap.getOrderedItems(sections, sectionMap), icons: { container: 'inbox', @@ -63,8 +63,7 @@ module.exports = function(pb) { article: 'files-o', page: 'file-o', link: 'link' - }, - sitePrefix: self.sitePrefix + } } ); @@ -118,13 +117,13 @@ module.exports = function(pb) { }; NavigationMap.getSubNavItems = function(key, ls, data) { - var pills = SectionService.getPillNavOptions(null, data.sitePrefix); + var pills = SectionService.getPillNavOptions(); pills.unshift( { name: SUB_NAV_KEY, title: ls.get('NAV_MAP'), icon: 'refresh', - href: '/admin' + data.sitePrefix + '/content/navigation' + href: '/admin/content/navigation' }); return pills; }; diff --git a/plugins/pencilblue/templates/admin/content/navigation/nav_item_form.html b/plugins/pencilblue/templates/admin/content/navigation/nav_item_form.html index 6b7a82f65..8ae8a68ff 100644 --- a/plugins/pencilblue/templates/admin/content/navigation/nav_item_form.html +++ b/plugins/pencilblue/templates/admin/content/navigation/nav_item_form.html @@ -65,7 +65,7 @@ - +  ^loc_CANCEL^ ^tmp_admin=elements=save_button^ diff --git a/plugins/pencilblue/templates/admin/content/navigation/nav_map.html b/plugins/pencilblue/templates/admin/content/navigation/nav_map.html index 1bc6c912d..bf1fbd661 100644 --- a/plugins/pencilblue/templates/admin/content/navigation/nav_map.html +++ b/plugins/pencilblue/templates/admin/content/navigation/nav_map.html @@ -7,7 +7,7 @@
- + @@ -21,7 +21,7 @@
- + @@ -35,7 +35,7 @@
- +  ^loc_CANCEL^
+ diff --git a/plugins/pencilblue/templates/angular/admin/content/media/manage_media.html b/plugins/pencilblue/templates/angular/admin/content/media/manage_media.html index 14b089f9a..319ee37dc 100644 --- a/plugins/pencilblue/templates/angular/admin/content/media/manage_media.html +++ b/plugins/pencilblue/templates/angular/admin/content/media/manage_media.html @@ -76,7 +76,7 @@ } $scope.deleting = true; - $http({method: 'DELETE', url: '/actions/admin' + $scope.sitePrefix + '/content/media/' + $scope.objectToDelete._id}) + $http({method: 'DELETE', url: '/actions/admin/content/media/' + $scope.objectToDelete._id}) .success(function(result) { for(var i = 0; i < $scope.media.length; i ++) { if($scope.media[i]._id.toString() === $scope.objectToDelete._id.toString()) { From 4237624758453e3ff8fbfad3d7892d5272671c62 Mon Sep 17 00:00:00 2001 From: btidwell Date: Mon, 8 Jun 2015 09:39:14 -0400 Subject: [PATCH 277/790] remove site prefix from media_form page --- .../actions/admin/content/media/edit_media.js | 2 +- .../actions/admin/content/media/new_media.js | 2 +- .../controllers/admin/content/media/media_form.js | 13 ++++--------- .../angular/admin/content/media/media_form.html | 4 ++-- 4 files changed, 8 insertions(+), 13 deletions(-) diff --git a/plugins/pencilblue/controllers/actions/admin/content/media/edit_media.js b/plugins/pencilblue/controllers/actions/admin/content/media/edit_media.js index 1eed899a9..f5f596e74 100755 --- a/plugins/pencilblue/controllers/actions/admin/content/media/edit_media.js +++ b/plugins/pencilblue/controllers/actions/admin/content/media/edit_media.js @@ -49,7 +49,7 @@ module.exports = function(pb) { return; } - var mediaService = new pb.MediaService(null, self.pathSiteUId); + var mediaService = new pb.MediaService(null, self.site); mediaService.loadById(vars.id, function(err, media) { if(util.isError(err) || media === null) { cb({ diff --git a/plugins/pencilblue/controllers/actions/admin/content/media/new_media.js b/plugins/pencilblue/controllers/actions/admin/content/media/new_media.js index 4bc4043ea..e3af3dff5 100755 --- a/plugins/pencilblue/controllers/actions/admin/content/media/new_media.js +++ b/plugins/pencilblue/controllers/actions/admin/content/media/new_media.js @@ -43,7 +43,7 @@ module.exports = function(pb) { } var mediaDocument = pb.DocumentCreator.create('media', post); - var mediaService = new pb.MediaService(null, self.pathSiteUId); + var mediaService = new pb.MediaService(null, self.site); mediaService.save(mediaDocument, function(err, result) { if(util.isError(err)) { return cb({ diff --git a/plugins/pencilblue/controllers/admin/content/media/media_form.js b/plugins/pencilblue/controllers/admin/content/media/media_form.js index 1ab24324c..79e3ed8b1 100644 --- a/plugins/pencilblue/controllers/admin/content/media/media_form.js +++ b/plugins/pencilblue/controllers/admin/content/media/media_form.js @@ -67,7 +67,6 @@ module.exports = function(pb) { var self = this; pb.AdminSubnavService.getWithSite(SUB_NAV_KEY, self.ls, data.media, {site: data.media.site}, function(pills) { data.pills = pills; - data.sitePrefix = self.sitePrefix; cb(pb.ClientJs.getAngularObjects(data)); }); @@ -110,11 +109,11 @@ module.exports = function(pb) { if(!vars.id) { return callback(null, { media_topics: [], - site: self.pathSiteUId + site: self.site }); } - var mediaService = new pb.MediaService(null, self.pathSiteUId, true); + var mediaService = new pb.MediaService(null, self.site, true); mediaService.loadById(vars.id, callback); } }; @@ -141,20 +140,16 @@ module.exports = function(pb) { }; MediaForm.getSubNavItems = function(key, ls, data) { - var adminPrefix = '/admin'; - if(data.site) { - adminPrefix += '/' + data.site; - } return [{ name: 'manage_media', title: data[pb.DAO.getIdField()] ? ls.get('EDIT') + ' ' + data.name : ls.get('NEW_MEDIA'), icon: 'chevron-left', - href: adminPrefix + '/content/media' + href: '/admin/content/media' }, { name: 'new_media', title: '', icon: 'plus', - href: adminPrefix + '/content/media/new' + href: '/admin/content/media/new' }]; }; diff --git a/plugins/pencilblue/templates/angular/admin/content/media/media_form.html b/plugins/pencilblue/templates/angular/admin/content/media/media_form.html index efc8ff934..31e589cdf 100644 --- a/plugins/pencilblue/templates/angular/admin/content/media/media_form.html +++ b/plugins/pencilblue/templates/angular/admin/content/media/media_form.html @@ -104,7 +104,7 @@ $scope.getMediaPreview = function() { $scope.mediaPreview = ''; - $http.get('/api/admin' + $scope.sitePrefix + '/content/media/get_preview?id=' + $scope.media._id) + $http.get('/api/admin/content/media/get_preview?id=' + $scope.media._id) .success(function(result) { $scope.mediaPreview = result.data; }) @@ -138,7 +138,7 @@ $scope.successMessage = result.message; if(result.data._id) { - $window.location = '/admin' + $scope.sitePrefix + '/content/media/' + result.data._id; + $window.location = '/admin/content/media/' + result.data._id; } }, function(result, status) { From a21d6e9850eecad9048ee4d35ec3343b3939dc77 Mon Sep 17 00:00:00 2001 From: btidwell Date: Mon, 8 Jun 2015 09:39:46 -0400 Subject: [PATCH 278/790] change site reference in media delete action controller --- .../controllers/actions/admin/content/media/delete_media.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/pencilblue/controllers/actions/admin/content/media/delete_media.js b/plugins/pencilblue/controllers/actions/admin/content/media/delete_media.js index 1d2ffa72a..69b2d2d7a 100755 --- a/plugins/pencilblue/controllers/actions/admin/content/media/delete_media.js +++ b/plugins/pencilblue/controllers/actions/admin/content/media/delete_media.js @@ -50,7 +50,7 @@ module.exports = function(pb) { return; } - var mservice = new pb.MediaService(self.pathSiteUId); + var mservice = new pb.MediaService(self.site); mservice.loadById(vars.id, function(err, mediaData) { if(util.isError(err) || !mediaData) { cb({ From ac51c0999705fe1cc0c153e052b98dabdacb7ade Mon Sep 17 00:00:00 2001 From: btidwell Date: Mon, 8 Jun 2015 09:56:34 -0400 Subject: [PATCH 279/790] fix constructor call for media service on delete_media controller --- .../controllers/actions/admin/content/media/delete_media.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/pencilblue/controllers/actions/admin/content/media/delete_media.js b/plugins/pencilblue/controllers/actions/admin/content/media/delete_media.js index 69b2d2d7a..41bed32bd 100755 --- a/plugins/pencilblue/controllers/actions/admin/content/media/delete_media.js +++ b/plugins/pencilblue/controllers/actions/admin/content/media/delete_media.js @@ -50,7 +50,7 @@ module.exports = function(pb) { return; } - var mservice = new pb.MediaService(self.site); + var mservice = new pb.MediaService(null, self.site, true); mservice.loadById(vars.id, function(err, mediaData) { if(util.isError(err) || !mediaData) { cb({ From 41067f301d24fd68a8097d606ea550e5cd24490f Mon Sep 17 00:00:00 2001 From: btidwell Date: Mon, 8 Jun 2015 10:59:38 -0400 Subject: [PATCH 280/790] hostname refactor for comments Also change AdminFormController to use props.site --- controllers/admin/admin_form_controller.js | 2 +- .../controllers/admin/content/comments/manage_comments.js | 7 +++---- plugins/pencilblue/controllers/api/comments/new_comment.js | 3 +-- .../templates/admin/content/comments/manage_comments.html | 6 +++--- 4 files changed, 8 insertions(+), 10 deletions(-) diff --git a/controllers/admin/admin_form_controller.js b/controllers/admin/admin_form_controller.js index fcfebc0e8..e2bfe9e11 100644 --- a/controllers/admin/admin_form_controller.js +++ b/controllers/admin/admin_form_controller.js @@ -32,7 +32,7 @@ module.exports = function AdminFormControllerModule(pb) { */ AdminFormController.prototype.init = function (props, cb) { var self = this; - self.pathSiteUId = pb.SiteService.getCurrentSite(props.path_vars.siteid); + self.pathSiteUId = pb.SiteService.getCurrentSite(props.site); pb.FormController.prototype.init.call(self, props, function () { BaseAdminController.prototype.extendedInit.call(self, cb); }); diff --git a/plugins/pencilblue/controllers/admin/content/comments/manage_comments.js b/plugins/pencilblue/controllers/admin/content/comments/manage_comments.js index 6ddc71d19..92ff83b9f 100755 --- a/plugins/pencilblue/controllers/admin/content/comments/manage_comments.js +++ b/plugins/pencilblue/controllers/admin/content/comments/manage_comments.js @@ -58,19 +58,18 @@ module.exports = function(pb) { } //retrieve the content settings or defaults if they have not yet been configured - var contentService = new pb.ContentService(self.pathSiteUId); + var contentService = new pb.ContentService(self.site); contentService.getSettings(function(err, contentSettings) { //TODO handle error //retrieve any details self.getCommentDetails(comments, function(commentsWithDetails) { - var pills = self.getAdminPills(SUB_NAV_KEY, self.ls, SUB_NAV_KEY, {prefix: self.sitePrefix}); + var pills = self.getAdminPills(SUB_NAV_KEY, self.ls, SUB_NAV_KEY); var angularObjects = pb.ClientJs.getAngularObjects({ navigation: pb.AdminNavigation.get(self.session, ['content', 'comments'], self.ls), pills: pills, comments: commentsWithDetails, allowComments: contentSettings.allow_comments, - sitePrefix: self.sitePrefix, siteRoot: self.siteRoot }); @@ -138,7 +137,7 @@ module.exports = function(pb) { name: SUB_NAV_KEY, title: ls.get('MANAGE_COMMENTS'), icon: 'refresh', - href: '/admin' + data.prefix + '/content/comments' + href: '/admin/content/comments' }]; }; diff --git a/plugins/pencilblue/controllers/api/comments/new_comment.js b/plugins/pencilblue/controllers/api/comments/new_comment.js index 46ecdaf2b..0fa580186 100755 --- a/plugins/pencilblue/controllers/api/comments/new_comment.js +++ b/plugins/pencilblue/controllers/api/comments/new_comment.js @@ -29,8 +29,7 @@ module.exports = function NewCommentModule(pb) { NewComment.prototype.onPostParamsRetrieved = function(post, cb) { var self = this; - - var contentService = new pb.ContentService(self.siteUId); + var contentService = new pb.ContentService(self.site); contentService.getSettings(function(err, contentSettings) { if(!contentSettings.allow_comments) { cb({content: BaseController.apiResponse(BaseController.API_FAILURE, 'commenting not allowed'), code: 400}); diff --git a/plugins/pencilblue/templates/admin/content/comments/manage_comments.html b/plugins/pencilblue/templates/admin/content/comments/manage_comments.html index eff8954b1..5305aafd7 100755 --- a/plugins/pencilblue/templates/admin/content/comments/manage_comments.html +++ b/plugins/pencilblue/templates/admin/content/comments/manage_comments.html @@ -2,7 +2,7 @@
^tmp_admin=elements=error_success^
- ^loc_COMMENTS_DISABLED^. ^loc_ENABLE_HERE^. + ^loc_COMMENTS_DISABLED^. ^loc_ENABLE_HERE^.
^tmp_admin=elements=sub_nav^ ^tmp_admin=elements=search_input^ @@ -10,8 +10,8 @@
^tmp_admin=elements=table_headers^ - - + + From 1d628ec7e90a73da5b8531dc4c977bc070c5c137 Mon Sep 17 00:00:00 2001 From: andparker Date: Mon, 8 Jun 2015 11:35:15 -0400 Subject: [PATCH 281/790] Sets up site service and makes site_root and site_name directives respect site --- controllers/base_controller.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/controllers/base_controller.js b/controllers/base_controller.js index add3cbc28..e4d0400eb 100755 --- a/controllers/base_controller.js +++ b/controllers/base_controller.js @@ -105,6 +105,11 @@ module.exports = function BaseControllerModule(pb) { this.pageName = ''; this.site = props.site; + this.siteService = new pb.SiteService(); + this.siteService.getByUid(this.site, function (err, siteInfo) { + self.siteObj = siteInfo; + }); + var tsOpts = { ls: this.localizationService, activeTheme: props.activeTheme, @@ -112,6 +117,12 @@ module.exports = function BaseControllerModule(pb) { }; this.templateService = this.getTemplateService(tsOpts); + this.templateService.registerLocal('site_root', function(flag, cb) { + cb(null, self.siteObj.hostname || self.templateService.siteRoot); + }); + this.templateService.registerLocal('site_name', function(flag, cb) { + cb(null, self.siteObj.displayName || self.templateService.siteName); + }); this.templateService.registerLocal('locale', this.ls.language); this.templateService.registerLocal('error_success', function(flag, cb) { self.displayErrorOrSuccessCallback(flag, cb); From 041949a2b8af93f6433d70a44e0bf8ccdf060cf1 Mon Sep 17 00:00:00 2001 From: andparker Date: Mon, 8 Jun 2015 12:15:58 -0400 Subject: [PATCH 282/790] Async fix for registering locals. --- controllers/base_controller.js | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/controllers/base_controller.js b/controllers/base_controller.js index e4d0400eb..8a1549169 100755 --- a/controllers/base_controller.js +++ b/controllers/base_controller.js @@ -105,11 +105,6 @@ module.exports = function BaseControllerModule(pb) { this.pageName = ''; this.site = props.site; - this.siteService = new pb.SiteService(); - this.siteService.getByUid(this.site, function (err, siteInfo) { - self.siteObj = siteInfo; - }); - var tsOpts = { ls: this.localizationService, activeTheme: props.activeTheme, @@ -117,12 +112,6 @@ module.exports = function BaseControllerModule(pb) { }; this.templateService = this.getTemplateService(tsOpts); - this.templateService.registerLocal('site_root', function(flag, cb) { - cb(null, self.siteObj.hostname || self.templateService.siteRoot); - }); - this.templateService.registerLocal('site_name', function(flag, cb) { - cb(null, self.siteObj.displayName || self.templateService.siteName); - }); this.templateService.registerLocal('locale', this.ls.language); this.templateService.registerLocal('error_success', function(flag, cb) { self.displayErrorOrSuccessCallback(flag, cb); @@ -145,6 +134,18 @@ module.exports = function BaseControllerModule(pb) { }); }); this.ts = this.templateService; + + this.siteService = new pb.SiteService(); + this.siteService.getByUid(this.site, function (err, siteInfo) { + self.siteObj = siteInfo; + + self.templateService.registerLocal('site_root', function(flag, cb) { + cb(null, self.siteObj.hostname || self.templateService.siteRoot); + }); + self.templateService.registerLocal('site_name', function(flag, cb) { + cb(null, self.siteObj.displayName || self.templateService.siteName); + }); + }); /** * From b6ce146102c628c168e5c42a00c3447312ea55f6 Mon Sep 17 00:00:00 2001 From: andparker Date: Mon, 8 Jun 2015 13:56:58 -0400 Subject: [PATCH 283/790] Async fix for loading site info before using its content. --- controllers/base_controller.js | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/controllers/base_controller.js b/controllers/base_controller.js index 8a1549169..ea011684a 100755 --- a/controllers/base_controller.js +++ b/controllers/base_controller.js @@ -135,18 +135,6 @@ module.exports = function BaseControllerModule(pb) { }); this.ts = this.templateService; - this.siteService = new pb.SiteService(); - this.siteService.getByUid(this.site, function (err, siteInfo) { - self.siteObj = siteInfo; - - self.templateService.registerLocal('site_root', function(flag, cb) { - cb(null, self.siteObj.hostname || self.templateService.siteRoot); - }); - self.templateService.registerLocal('site_name', function(flag, cb) { - cb(null, self.siteObj.displayName || self.templateService.siteName); - }); - }); - /** * * @property activeTheme @@ -166,7 +154,19 @@ module.exports = function BaseControllerModule(pb) { onlyThisSite: true }; - cb(); + this.siteService = new pb.SiteService(); + this.siteService.getByUid(this.site, function (err, siteInfo) { + self.siteObj = siteInfo; + + self.templateService.registerLocal('site_root', function(flag, cb) { + cb(null, self.siteObj.hostname || self.templateService.siteRoot); + }); + self.templateService.registerLocal('site_name', function(flag, cb) { + cb(null, self.siteObj.displayName || self.templateService.siteName); + }); + + cb(); + }); }; /** From 3574093c136e66354693bdb3476bb6dc722f5e70 Mon Sep 17 00:00:00 2001 From: iandtrapp Date: Mon, 8 Jun 2015 15:09:20 -0400 Subject: [PATCH 284/790] Deleted site prefix for redirect --- .../controllers/admin/content/objects/types/manage_types.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/pencilblue/controllers/admin/content/objects/types/manage_types.js b/plugins/pencilblue/controllers/admin/content/objects/types/manage_types.js index 8a8acceb5..8b15f0ed8 100644 --- a/plugins/pencilblue/controllers/admin/content/objects/types/manage_types.js +++ b/plugins/pencilblue/controllers/admin/content/objects/types/manage_types.js @@ -40,7 +40,7 @@ module.exports = function(pb) { //none to manage if(custObjTypes.length === 0) { - self.redirect('/admin' + self.sitePrefix + '/content/objects/types/new', cb); + self.redirect('/admin/content/objects/types/new', cb); return; } From b7d6f097b499f1659e1a0ceb1f19ca34a2f263b0 Mon Sep 17 00:00:00 2001 From: iandtrapp Date: Mon, 8 Jun 2015 15:16:51 -0400 Subject: [PATCH 285/790] Removed site prefix pills --- .../admin/content/objects/types/manage_types.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/plugins/pencilblue/controllers/admin/content/objects/types/manage_types.js b/plugins/pencilblue/controllers/admin/content/objects/types/manage_types.js index 8b15f0ed8..feab5923d 100644 --- a/plugins/pencilblue/controllers/admin/content/objects/types/manage_types.js +++ b/plugins/pencilblue/controllers/admin/content/objects/types/manage_types.js @@ -48,11 +48,10 @@ module.exports = function(pb) { pb.CustomObjectService.setFieldTypesUsed(custObjTypes, self.ls); //build out the angular controller - var data = {pathSitePrefix: self.sitePrefix}; var angularObjects = pb.ClientJs.getAngularObjects( { navigation: pb.AdminNavigation.get(self.session, ['content', 'custom_objects'], self.ls), - pills: self.getAdminPills(SUB_NAV_KEY, self.ls, SUB_NAV_KEY, data), + pills: self.getAdminPills(SUB_NAV_KEY, self.ls, SUB_NAV_KEY), objectTypes: custObjTypes, pathSitePrefix: self.sitePrefix }); @@ -72,12 +71,12 @@ module.exports = function(pb) { name: SUB_NAV_KEY, title: ls.get('MANAGE_OBJECT_TYPES'), icon: 'refresh', - href: '/admin' + data.pathSitePrefix + '/content/objects/types' + href: '/admin/content/objects/types' }, { name: 'new_object_type', title: '', icon: 'plus', - href: '/admin' + data.pathSitePrefix + '/content/objects/types/new' + href: '/admin/content/objects/types/new' }]; }; From 32d70ae4002a1a72d1a601612e2c11a3b28ab0a7 Mon Sep 17 00:00:00 2001 From: iandtrapp Date: Mon, 8 Jun 2015 15:27:24 -0400 Subject: [PATCH 286/790] Deleted path site prefix from angular controller and manage types view --- .../controllers/admin/content/objects/types/manage_types.js | 2 +- .../templates/admin/content/objects/types/manage_types.html | 4 ++-- .../angular/admin/content/objects/types/manage_types.html | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/pencilblue/controllers/admin/content/objects/types/manage_types.js b/plugins/pencilblue/controllers/admin/content/objects/types/manage_types.js index feab5923d..e37a758e8 100644 --- a/plugins/pencilblue/controllers/admin/content/objects/types/manage_types.js +++ b/plugins/pencilblue/controllers/admin/content/objects/types/manage_types.js @@ -35,7 +35,7 @@ module.exports = function(pb) { ManageObjectTypes.prototype.render = function(cb) { var self = this; - var service = new pb.CustomObjectService(self.pathSiteUId, true); + var service = new pb.CustomObjectService(self.site, true); service.findTypes(function(err, custObjTypes) { //none to manage diff --git a/plugins/pencilblue/templates/admin/content/objects/types/manage_types.html b/plugins/pencilblue/templates/admin/content/objects/types/manage_types.html index 4959bafd6..4f54a4ff3 100644 --- a/plugins/pencilblue/templates/admin/content/objects/types/manage_types.html +++ b/plugins/pencilblue/templates/admin/content/objects/types/manage_types.html @@ -7,10 +7,10 @@
^tmp_admin=elements=table_headers^ - + diff --git a/plugins/pencilblue/templates/angular/admin/content/objects/types/manage_types.html b/plugins/pencilblue/templates/angular/admin/content/objects/types/manage_types.html index 3cedc72c4..5d2b8a5f5 100644 --- a/plugins/pencilblue/templates/angular/admin/content/objects/types/manage_types.html +++ b/plugins/pencilblue/templates/angular/admin/content/objects/types/manage_types.html @@ -72,7 +72,7 @@ } $scope.deleting = true; - $http({method: 'DELETE', url: '/actions/admin' + $scope.pathSitePrefix + '/content/objects/types/' + $scope.objectToDelete._id}) + $http({method: 'DELETE', url: '/actions/admin/content/objects/types/' + $scope.objectToDelete._id}) .success(function(result) { for(var i = 0; i < $scope.objectTypes.length; i++) { if($scope.objectTypes[i]._id.toString() === $scope.objectToDelete._id.toString()) { From b0c4d45c40dff6ab2f2a0745527cddf68e7c46af Mon Sep 17 00:00:00 2001 From: iandtrapp Date: Mon, 8 Jun 2015 15:28:55 -0400 Subject: [PATCH 287/790] Deleted path site prefix from angular objects --- .../controllers/admin/content/objects/types/manage_types.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/plugins/pencilblue/controllers/admin/content/objects/types/manage_types.js b/plugins/pencilblue/controllers/admin/content/objects/types/manage_types.js index e37a758e8..37bd0e87e 100644 --- a/plugins/pencilblue/controllers/admin/content/objects/types/manage_types.js +++ b/plugins/pencilblue/controllers/admin/content/objects/types/manage_types.js @@ -52,8 +52,7 @@ module.exports = function(pb) { { navigation: pb.AdminNavigation.get(self.session, ['content', 'custom_objects'], self.ls), pills: self.getAdminPills(SUB_NAV_KEY, self.ls, SUB_NAV_KEY), - objectTypes: custObjTypes, - pathSitePrefix: self.sitePrefix + objectTypes: custObjTypes }); self.setPageName(self.ls.get('MANAGE_OBJECT_TYPES')); From fa2cf90bef4c6bc3527d81b1ee51d76cd5aa5b9b Mon Sep 17 00:00:00 2001 From: iandtrapp Date: Mon, 8 Jun 2015 15:46:51 -0400 Subject: [PATCH 288/790] Removed site prefix from type form controller and type form angular objects --- .../admin/content/objects/types/type_form.js | 10 +++------- .../admin/content/objects/types/type_form.html | 2 +- .../angular/admin/content/objects/types/type_form.html | 6 +++--- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/plugins/pencilblue/controllers/admin/content/objects/types/type_form.js b/plugins/pencilblue/controllers/admin/content/objects/types/type_form.js index b47ded94f..3ad43df18 100644 --- a/plugins/pencilblue/controllers/admin/content/objects/types/type_form.js +++ b/plugins/pencilblue/controllers/admin/content/objects/types/type_form.js @@ -58,7 +58,7 @@ module.exports = function(pb) { TypeForm.prototype.gatherData = function(vars, cb) { var self = this; - var cos = new pb.CustomObjectService(self.pathSiteUId, true); + var cos = new pb.CustomObjectService(self.site, true); var tasks = { tabs: function(callback) { @@ -83,10 +83,6 @@ module.exports = function(pb) { callback(null, pb.AdminNavigation.get(self.session, ['content', 'custom_objects'], self.ls)); }, - pathSitePrefix: function(callback) { - callback(null, self.sitePrefix) - }, - objectTypes: function(callback) { cos.getReferenceTypes(function(err, objectTypes) { callback(err, objectTypes); @@ -116,12 +112,12 @@ module.exports = function(pb) { name: SUB_NAV_KEY, title: data.objectType[pb.DAO.getIdField()] ? ls.get('EDIT') + ' ' + data.objectType.name : ls.get('NEW_OBJECT_TYPE'), icon: 'chevron-left', - href: '/admin' + data.pathSitePrefix + '/content/objects/types' + href: '/admin/content/objects/types' }, { name: 'new_object_type', title: '', icon: 'plus', - href: '/admin' + data.pathSitePrefix + '/content/objects/types/new' + href: '/admin/content/objects/types/new' }]; }; diff --git a/plugins/pencilblue/templates/admin/content/objects/types/type_form.html b/plugins/pencilblue/templates/admin/content/objects/types/type_form.html index f66ebf9b9..daa6465c2 100644 --- a/plugins/pencilblue/templates/admin/content/objects/types/type_form.html +++ b/plugins/pencilblue/templates/admin/content/objects/types/type_form.html @@ -74,7 +74,7 @@ - +  ^loc_CANCEL^ ^tmp_admin=elements=save_button^ diff --git a/plugins/pencilblue/templates/angular/admin/content/objects/types/type_form.html b/plugins/pencilblue/templates/angular/admin/content/objects/types/type_form.html index 73e3bc8af..b8aa20487 100644 --- a/plugins/pencilblue/templates/angular/admin/content/objects/types/type_form.html +++ b/plugins/pencilblue/templates/angular/admin/content/objects/types/type_form.html @@ -29,7 +29,7 @@ return; } - $http.get('/api/admin' + $scope.pathSitePrefix + '/content/objects/types/available?name=' + $scope.objectType.name) + $http.get('/api/admin/content/objects/types/available?name=' + $scope.objectType.name) .success(function(result) { $scope.nameAvailable = result.data; }) @@ -107,7 +107,7 @@ } saveObject.fields = fields; - var postURL = '/actions/admin' + $scope.pathSitePrefix + '/content/objects/types'; + var postURL = '/actions/admin/content/objects/types'; if(saveObject._id) { postURL += '/' + saveObject._id; } @@ -120,7 +120,7 @@ $scope.saving = false; if(result.data) { - $window.location = '/admin' + $scope.pathSitePrefix + '/content/objects/types/' + result.data._id.toString(); + $window.location = '/admin/content/objects/types/' + result.data._id.toString(); } }) .error(function(error, status) { From 16ad17ea9491693222fc57144e7b76ea3604d328 Mon Sep 17 00:00:00 2001 From: iandtrapp Date: Mon, 8 Jun 2015 15:50:44 -0400 Subject: [PATCH 289/790] Removed path site prefix and pathsiteuid from delete edit and create --- .../actions/admin/content/objects/types/delete_type.js | 2 +- .../actions/admin/content/objects/types/edit_type.js | 2 +- .../controllers/actions/admin/content/objects/types/new_type.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/pencilblue/controllers/actions/admin/content/objects/types/delete_type.js b/plugins/pencilblue/controllers/actions/admin/content/objects/types/delete_type.js index f82876e33..d93953f09 100644 --- a/plugins/pencilblue/controllers/actions/admin/content/objects/types/delete_type.js +++ b/plugins/pencilblue/controllers/actions/admin/content/objects/types/delete_type.js @@ -38,7 +38,7 @@ module.exports = function(pb) { } //ensure existence - var service = new pb.CustomObjectService(self.pathSiteUId, true); + var service = new pb.CustomObjectService(self.site, true); service.loadTypeById(vars.id, function(err, objectType) { if(objectType === null) { cb({ diff --git a/plugins/pencilblue/controllers/actions/admin/content/objects/types/edit_type.js b/plugins/pencilblue/controllers/actions/admin/content/objects/types/edit_type.js index c12670b52..6060e7706 100644 --- a/plugins/pencilblue/controllers/actions/admin/content/objects/types/edit_type.js +++ b/plugins/pencilblue/controllers/actions/admin/content/objects/types/edit_type.js @@ -40,7 +40,7 @@ module.exports = function(pb) { }); } - var service = new pb.CustomObjectService(self.pathSiteUId, true); + var service = new pb.CustomObjectService(self.site, true); service.loadTypeById(vars.id, function(err, custObjType) { if(util.isError(err) || !util.isObject(custObjType)) { return cb({ diff --git a/plugins/pencilblue/controllers/actions/admin/content/objects/types/new_type.js b/plugins/pencilblue/controllers/actions/admin/content/objects/types/new_type.js index b571bc6ba..544e53655 100644 --- a/plugins/pencilblue/controllers/actions/admin/content/objects/types/new_type.js +++ b/plugins/pencilblue/controllers/actions/admin/content/objects/types/new_type.js @@ -35,7 +35,7 @@ module.exports = function(pb) { var post = self.body; post.fields.name = {field_type: 'text'}; - var service = new pb.CustomObjectService(self.pathSiteUId, true); + var service = new pb.CustomObjectService(self.site, true); service.saveType(post, function(err, result) { if(util.isError(err)) { return cb({ From dfebebe783f5e461262ac23f437b7176732a19cf Mon Sep 17 00:00:00 2001 From: iandtrapp Date: Mon, 8 Jun 2015 16:11:58 -0400 Subject: [PATCH 290/790] Deleted site prefix and site uid from admin angular objects, admin controllers, and available api --- .../actions/admin/content/objects/delete_object.js | 2 +- .../actions/admin/content/objects/edit_object.js | 2 +- .../actions/admin/content/objects/new_object.js | 2 +- .../actions/admin/content/objects/sort_objects.js | 2 +- .../admin/content/objects/manage_objects.js | 14 +++++++------- .../admin/content/objects/object_form.js | 12 ++++++------ .../admin/content/objects/sort_objects.js | 10 +++++----- .../api/admin/content/objects/types/available.js | 2 +- .../admin/content/objects/manage_objects.html | 2 +- .../admin/content/objects/object_form.html | 2 +- .../admin/content/objects/sort_objects.html | 2 +- .../admin/content/objects/manage_objects.html | 2 +- .../angular/admin/content/objects/object_form.html | 4 ++-- .../admin/content/objects/sort_objects.html | 2 +- 14 files changed, 30 insertions(+), 30 deletions(-) diff --git a/plugins/pencilblue/controllers/actions/admin/content/objects/delete_object.js b/plugins/pencilblue/controllers/actions/admin/content/objects/delete_object.js index bfd070423..688608708 100644 --- a/plugins/pencilblue/controllers/actions/admin/content/objects/delete_object.js +++ b/plugins/pencilblue/controllers/actions/admin/content/objects/delete_object.js @@ -42,7 +42,7 @@ module.exports = function(pb) { return; } - var cos = new pb.CustomObjectService(self.pathSiteUId, true); + var cos = new pb.CustomObjectService(self.site, true); cos.loadById(vars.id, function(err, customObject) { if (util.isError(err)) { return self.reqHandler.serveError(err); diff --git a/plugins/pencilblue/controllers/actions/admin/content/objects/edit_object.js b/plugins/pencilblue/controllers/actions/admin/content/objects/edit_object.js index fa5cdd69c..cfda804af 100644 --- a/plugins/pencilblue/controllers/actions/admin/content/objects/edit_object.js +++ b/plugins/pencilblue/controllers/actions/admin/content/objects/edit_object.js @@ -41,7 +41,7 @@ module.exports = function(pb) { return; } - var service = new pb.CustomObjectService(self.pathSiteUId, true); + var service = new pb.CustomObjectService(self.site, true); service.loadById(vars.id, function(err, custObj) { if(util.isError(err) || !util.isObject(custObj)) { return cb({ diff --git a/plugins/pencilblue/controllers/actions/admin/content/objects/new_object.js b/plugins/pencilblue/controllers/actions/admin/content/objects/new_object.js index 45685958f..e80fe8990 100644 --- a/plugins/pencilblue/controllers/actions/admin/content/objects/new_object.js +++ b/plugins/pencilblue/controllers/actions/admin/content/objects/new_object.js @@ -41,7 +41,7 @@ module.exports = function(pb) { return } - var service = new pb.CustomObjectService(self.pathSiteUId, true); + var service = new pb.CustomObjectService(self.site, true); service.loadTypeById(vars.type_id, function(err, customObjectType) { if(util.isError(err) || !util.isObject(customObjectType)) { return cb({ diff --git a/plugins/pencilblue/controllers/actions/admin/content/objects/sort_objects.js b/plugins/pencilblue/controllers/actions/admin/content/objects/sort_objects.js index 298f93c84..b84d03093 100644 --- a/plugins/pencilblue/controllers/actions/admin/content/objects/sort_objects.js +++ b/plugins/pencilblue/controllers/actions/admin/content/objects/sort_objects.js @@ -39,7 +39,7 @@ module.exports = function(pb) { }); } - var service = new pb.CustomObjectService(self.pathSiteUId, true); + var service = new pb.CustomObjectService(self.site, true); service.loadTypeById(vars.type_id, function(err, customObjectType) { if(util.isError(err) || !util.isObject(customObjectType)) { return cb({ diff --git a/plugins/pencilblue/controllers/admin/content/objects/manage_objects.js b/plugins/pencilblue/controllers/admin/content/objects/manage_objects.js index 7aa5b06a6..2c4393d7b 100644 --- a/plugins/pencilblue/controllers/admin/content/objects/manage_objects.js +++ b/plugins/pencilblue/controllers/admin/content/objects/manage_objects.js @@ -40,7 +40,7 @@ module.exports = function(pb) { return this.reqHandler.serve404(); } - var service = new pb.CustomObjectService(self.pathSiteUId, true); + var service = new pb.CustomObjectService(self.site, true); service.loadTypeById(vars.type_id, function(err, custObjType) { if (util.isError(err)) { return self.serveError(err); @@ -56,12 +56,12 @@ module.exports = function(pb) { //none to manage if(customObjects.length === 0) { - return self.redirect(pb.UrlService.urlJoin('/admin' + self.sitePrefix + '/content/objects/', encodeURIComponent(vars.type_id), '/new'), cb); + return self.redirect(pb.UrlService.urlJoin('/admin/content/objects/', encodeURIComponent(vars.type_id), '/new'), cb); } var data = {}; - data.pathSitePrefix = self.sitePrefix; + data.pathSitePrefix = self.site; data.custObjType = custObjType; var pills = pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, 'manage_objects', data); for(var i = 0; i < pills.length; i++) { @@ -78,7 +78,7 @@ module.exports = function(pb) { pills: pills, customObjects: customObjects, objectType: custObjType, - pathSitePrefix: self.sitePrefix + pathSitePrefix: self.site }); var title = self.ls.get('MANAGE') + ' ' + custObjType.name; @@ -96,17 +96,17 @@ module.exports = function(pb) { name: 'manage_objects', title: ls.get('MANAGE') + ' ' + data.custObjType.name + ' ' + ls.get('OBJECTS'), icon: 'chevron-left', - href: '/admin' + data.pathSitePrefix + '/content/objects/types' + href: '/admin/content/objects/types' }, { name: 'sort_objects', title: '', icon: 'sort-amount-desc', - href: '/admin' + data.pathSitePrefix + '/content/objects/' + data.custObjType[pb.DAO.getIdField()] + '/sort' + href: '/admin/content/objects/' + data.custObjType[pb.DAO.getIdField()] + '/sort' }, { name: 'new_object', title: '', icon: 'plus', - href: '/admin' + data.pathSitePrefix + '/content/objects/' + data.custObjType[pb.DAO.getIdField()] + '/new' + href: '/admin/content/objects/' + data.custObjType[pb.DAO.getIdField()] + '/new' }]; }; diff --git a/plugins/pencilblue/controllers/admin/content/objects/object_form.js b/plugins/pencilblue/controllers/admin/content/objects/object_form.js index cd524f72f..ed8b4a518 100644 --- a/plugins/pencilblue/controllers/admin/content/objects/object_form.js +++ b/plugins/pencilblue/controllers/admin/content/objects/object_form.js @@ -38,7 +38,7 @@ module.exports = function(pb) { var vars = this.pathVars; if(!pb.validation.isIdStr(vars.type_id, true)) { - return self.redirect('/admin' + self.sitePrefix + '/content/objects/types', cb); + return self.redirect('/admin/content/objects/types', cb); } this.gatherData(vars, function(err, data) { @@ -83,7 +83,7 @@ module.exports = function(pb) { self.objectType = data.objectType; self.customObject = data.customObject; - data.pills = self.getAdminPills(SUB_NAV_KEY, self.ls, SUB_NAV_KEY, {objectType: self.objectType, customObject: self.customObject, pathSitePrefix: self.sitePrefix}); + data.pills = self.getAdminPills(SUB_NAV_KEY, self.ls, SUB_NAV_KEY, {objectType: self.objectType, customObject: self.customObject, pathSitePrefix: self.site}); var angularObjects = pb.ClientJs.getAngularObjects(data); self.setPageName(self.customObject[pb.DAO.getIdField()] ? self.customObject.name : self.ls.get('NEW') + ' ' + self.objectType.name + ' ' + self.ls.get('OBJECT')); @@ -96,7 +96,7 @@ module.exports = function(pb) { ObjectFormController.prototype.gatherData = function(vars, cb) { var self = this; - var cos = new pb.CustomObjectService(self.pathSiteUId, true); + var cos = new pb.CustomObjectService(self.site, true); var tasks = { tabs: function(callback) { @@ -117,7 +117,7 @@ module.exports = function(pb) { }, pathSitePrefix: function(callback) { - callback(null, self.sitePrefix) + callback(null, self.site) }, objectType: function(callback) { @@ -251,13 +251,13 @@ module.exports = function(pb) { name: 'manage_objects', title: data.customObject[pb.DAO.getIdField()] ? ls.get('EDIT') + ' ' + data.customObject.name : ls.get('NEW') + ' ' + data.objectType.name + ' ' + ls.get('OBJECT'), icon: 'chevron-left', - href: '/admin' + data.pathSitePrefix + '/content/objects/' + data.objectType[pb.DAO.getIdField()] + href: '/admin/content/objects/' + data.objectType[pb.DAO.getIdField()] }, { name: 'new_object', title: '', icon: 'plus', - href: '/admin' + data.pathSitePrefix + '/content/objects/' + data.objectType[pb.DAO.getIdField()] + '/new' + href: '/admin/content/objects/' + data.objectType[pb.DAO.getIdField()] + '/new' } ]; }; diff --git a/plugins/pencilblue/controllers/admin/content/objects/sort_objects.js b/plugins/pencilblue/controllers/admin/content/objects/sort_objects.js index 0d14d9d56..3e22b260e 100644 --- a/plugins/pencilblue/controllers/admin/content/objects/sort_objects.js +++ b/plugins/pencilblue/controllers/admin/content/objects/sort_objects.js @@ -39,7 +39,7 @@ module.exports = function(pb) { return this.reqHandler.serve404(); } - var service = new pb.CustomObjectService(self.pathSiteUId, true); + var service = new pb.CustomObjectService(self.site, true); service.loadTypeById(vars.type_id, function(err, objectType) { if(util.isError(err)) { return self.reqHandler.serveError(err); @@ -55,7 +55,7 @@ module.exports = function(pb) { //none to manage if(customObjects.length === 0) { - self.redirect('/admin' + self.sitePrefix + '/content/objects/' + vars.type_id + '/new', cb); + self.redirect('/admin/content/objects/' + vars.type_id + '/new', cb); return; } @@ -65,7 +65,7 @@ module.exports = function(pb) { pills: self.getAdminPills(SUB_NAV_KEY, self.ls, SUB_NAV_KEY, {objectType: objectType, pathSitePrefix: self.sitePrefix}), customObjects: customObjects, objectType: objectType, - pathSitePrefix: self.sitePrefix + pathSitePrefix: self.site }); self.setPageName(self.ls.get('SORT') + ' ' + objectType.name); @@ -82,12 +82,12 @@ module.exports = function(pb) { name: 'manage_objects', title: ls.get('SORT') + ' ' + data.objectType.name + ' ' + ls.get('OBJECTS'), icon: 'chevron-left', - href: '/admin' + data.pathSitePrefix + '/content/objects/' + data.objectType[pb.DAO.getIdField()] + href: '/admin/content/objects/' + data.objectType[pb.DAO.getIdField()] }, { name: 'new_object', title: '', icon: 'plus', - href: '/admin' + data.pathSitePrefix + '/content/objects/' + data.objectType[pb.DAO.getIdField()] + '/new' + href: '/admin/content/objects/' + data.objectType[pb.DAO.getIdField()] + '/new' }]; }; diff --git a/plugins/pencilblue/controllers/api/admin/content/objects/types/available.js b/plugins/pencilblue/controllers/api/admin/content/objects/types/available.js index a17ba14f6..120018c48 100644 --- a/plugins/pencilblue/controllers/api/admin/content/objects/types/available.js +++ b/plugins/pencilblue/controllers/api/admin/content/objects/types/available.js @@ -37,7 +37,7 @@ module.exports = function(pb) { }); } - var service = new pb.CustomObjectService(self.pathSiteUId, true); + var service = new pb.CustomObjectService(self.site, true); service.typeExists(get.name, function(err, exists) { if (util.isError(err)) { return cb({content: pb.BaseController.apiResponse(pb.BaseController.API_FAILURE, err.stack, false)}); diff --git a/plugins/pencilblue/templates/admin/content/objects/manage_objects.html b/plugins/pencilblue/templates/admin/content/objects/manage_objects.html index b9e2231c3..7bc601d93 100644 --- a/plugins/pencilblue/templates/admin/content/objects/manage_objects.html +++ b/plugins/pencilblue/templates/admin/content/objects/manage_objects.html @@ -7,7 +7,7 @@
  - +
^tmp_admin=elements=table_headers^ - + diff --git a/plugins/pencilblue/templates/admin/content/objects/object_form.html b/plugins/pencilblue/templates/admin/content/objects/object_form.html index 74b0ab8e8..89605dd72 100644 --- a/plugins/pencilblue/templates/admin/content/objects/object_form.html +++ b/plugins/pencilblue/templates/admin/content/objects/object_form.html @@ -88,7 +88,7 @@ ^wysiwyg^ - +  ^loc_CANCEL^ ^tmp_admin=elements=save_button^ diff --git a/plugins/pencilblue/templates/admin/content/objects/sort_objects.html b/plugins/pencilblue/templates/admin/content/objects/sort_objects.html index 5ffa01f99..7074780d2 100644 --- a/plugins/pencilblue/templates/admin/content/objects/sort_objects.html +++ b/plugins/pencilblue/templates/admin/content/objects/sort_objects.html @@ -11,7 +11,7 @@ - +  ^loc_CANCEL^ - + diff --git a/plugins/pencilblue/templates/angular/admin/themes/manage_themes.html b/plugins/pencilblue/templates/angular/admin/themes/manage_themes.html index 473309240..b395ba060 100644 --- a/plugins/pencilblue/templates/angular/admin/themes/manage_themes.html +++ b/plugins/pencilblue/templates/angular/admin/themes/manage_themes.html @@ -21,7 +21,7 @@ $scope.consoleOutput = ''; $('#progress_modal').modal({}); - $http.post("/api" + $scope.sitePrefix + "/plugins/" + actionType + "/" + encodeURIComponent($scope.actionPlugin.uid)) + $http.post("/api/plugins/" + actionType + "/" + encodeURIComponent($scope.actionPlugin.uid)) .success(function(result) { $scope.onActionSuccess(result); }) @@ -54,7 +54,7 @@ } $scope.saveSiteLogo = function() { - $http.post('/actions/admin' + $scope.sitePrefix + '/themes/site_logo', {site_logo: $scope.photoValue}) + $http.post('/actions/admin/themes/site_logo', {site_logo: $scope.photoValue}) .success(function(result) { $scope.successMessage = result.message; $scope.saving = false; From 6f20384eeaf3c7ef5b9f4c06efcf1f894ea8aab8 Mon Sep 17 00:00:00 2001 From: iandtrapp Date: Tue, 9 Jun 2015 08:20:35 -0400 Subject: [PATCH 295/790] Removed prefix and siteuid from portfolio home page settings controller, save home page settings controller, and angular object --- plugins/portfolio/controllers/home_page_settings.js | 4 ++-- plugins/portfolio/controllers/save_home_page_settings.js | 2 +- .../templates/angular/admin/settings/home_page_settings.html | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/portfolio/controllers/home_page_settings.js b/plugins/portfolio/controllers/home_page_settings.js index b0b9db035..0af55a15c 100755 --- a/plugins/portfolio/controllers/home_page_settings.js +++ b/plugins/portfolio/controllers/home_page_settings.js @@ -59,10 +59,10 @@ module.exports = function HomePageSettingsModule(pb) { homePageSettings = homePageSettings[0]; } else { - homePageSettings = {callouts: [{}, {}, {}], site:self.pathSiteUId}; + homePageSettings = {callouts: [{}, {}, {}], site:self.site}; } - var mservice = new pb.MediaService(self.pathSiteUId, true); + var mservice = new pb.MediaService(self.site, true); mservice.get(function(err, media) { if(homePageSettings.page_media) { var pageMedia = []; diff --git a/plugins/portfolio/controllers/save_home_page_settings.js b/plugins/portfolio/controllers/save_home_page_settings.js index 664145e8e..b6df3c7ed 100755 --- a/plugins/portfolio/controllers/save_home_page_settings.js +++ b/plugins/portfolio/controllers/save_home_page_settings.js @@ -83,7 +83,7 @@ module.exports = function SaveHomePageSettingsModule(pb) { }, { method: 'post', - path: '/actions/admin/:siteid/plugins/settings/portfolio/home_page', + path: '/actions/admin/plugins/settings/portfolio/home_page', auth_required: true, access_level: pb.SecurityService.ACCESS_EDITOR, content_type: 'text/html' diff --git a/plugins/portfolio/templates/angular/admin/settings/home_page_settings.html b/plugins/portfolio/templates/angular/admin/settings/home_page_settings.html index 0ce35fd40..ef7273512 100644 --- a/plugins/portfolio/templates/angular/admin/settings/home_page_settings.html +++ b/plugins/portfolio/templates/angular/admin/settings/home_page_settings.html @@ -24,7 +24,7 @@ $scope.saving = true; - $http.post('/actions/admin/'+ $scope.homePageSettings.site +'/plugins/settings/portfolio/home_page', $scope.homePageSettings) + $http.post('/actions/admin//plugins/settings/portfolio/home_page', $scope.homePageSettings) .success(function(result) { $scope.successMessage = result.message; $scope.saving = false; From 9ec300af2b3c957ee5dd1b4203a81324ac7d494b Mon Sep 17 00:00:00 2001 From: iandtrapp Date: Tue, 9 Jun 2015 08:35:52 -0400 Subject: [PATCH 296/790] Fixed path typo --- .../templates/angular/admin/settings/home_page_settings.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/portfolio/templates/angular/admin/settings/home_page_settings.html b/plugins/portfolio/templates/angular/admin/settings/home_page_settings.html index ef7273512..48df443ef 100644 --- a/plugins/portfolio/templates/angular/admin/settings/home_page_settings.html +++ b/plugins/portfolio/templates/angular/admin/settings/home_page_settings.html @@ -24,7 +24,7 @@ $scope.saving = true; - $http.post('/actions/admin//plugins/settings/portfolio/home_page', $scope.homePageSettings) + $http.post('/actions/admin/plugins/settings/portfolio/home_page', $scope.homePageSettings) .success(function(result) { $scope.successMessage = result.message; $scope.saving = false; From 315155798a301d48c999bbb6ed3dc754d595a361 Mon Sep 17 00:00:00 2001 From: btidwell Date: Tue, 9 Jun 2015 09:22:39 -0400 Subject: [PATCH 297/790] remove pathSiteUID and site prefix from manage_plugins page --- .../controllers/admin/plugins/manage_plugins.js | 10 ++++------ .../templates/admin/plugins/manage_plugins.html | 10 +++++----- .../angular/admin/plugins/manage_plugins.html | 4 +--- 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/plugins/pencilblue/controllers/admin/plugins/manage_plugins.js b/plugins/pencilblue/controllers/admin/plugins/manage_plugins.js index dc388a600..4f7d13a4d 100755 --- a/plugins/pencilblue/controllers/admin/plugins/manage_plugins.js +++ b/plugins/pencilblue/controllers/admin/plugins/manage_plugins.js @@ -34,7 +34,7 @@ module.exports = function(pb) { ManagePlugins.prototype.render = function (cb) { var self = this; - var pluginService = new pb.PluginService(self.pathSiteUId); + var pluginService = new pb.PluginService(self.site); pluginService.getPluginMap(function (err, map) { if (util.isError(err)) { self.reqHandler.serveError(err); @@ -42,15 +42,13 @@ module.exports = function(pb) { } //setup angular - var prefix = self.sitePrefix; var angularObjects = pb.ClientJs.getAngularObjects({ navigation: pb.AdminNavigation.get(self.session, ['plugins', 'manage'], self.ls), - pills: self.getAdminPills(SUB_NAV_KEY, self.ls, null, {sitePrefix: prefix}), + pills: self.getAdminPills(SUB_NAV_KEY, self.ls, null), installedPlugins: map.active, inactivePlugins: map.inactive, availablePlugins: map.available, - sitePrefix: prefix, - siteUid: self.pathSiteUId + siteUid: self.site }); //load the template self.ts.registerLocal('angular_objects', new pb.TemplateValue(angularObjects, false)); @@ -66,7 +64,7 @@ module.exports = function(pb) { name: 'manage_plugins', title: ls.get('MANAGE_PLUGINS'), icon: 'refresh', - href: '/admin' + data.sitePrefix + '/plugins' + href: '/admin/plugins' } ]; }; diff --git a/plugins/pencilblue/templates/admin/plugins/manage_plugins.html b/plugins/pencilblue/templates/admin/plugins/manage_plugins.html index 0abb10cd3..1788ab014 100755 --- a/plugins/pencilblue/templates/admin/plugins/manage_plugins.html +++ b/plugins/pencilblue/templates/admin/plugins/manage_plugins.html @@ -18,12 +18,12 @@ - + - +
-  ^loc_SETTINGS^ +  ^loc_SETTINGS^
-  ^loc_SETTINGS^ +  ^loc_SETTINGS^ @@ -53,12 +53,12 @@
-  ^loc_SETTINGS^ +  ^loc_SETTINGS^ @@ -91,7 +91,7 @@
- + diff --git a/plugins/pencilblue/templates/angular/admin/plugins/manage_plugins.html b/plugins/pencilblue/templates/angular/admin/plugins/manage_plugins.html index e139609a0..fca5261e1 100644 --- a/plugins/pencilblue/templates/angular/admin/plugins/manage_plugins.html +++ b/plugins/pencilblue/templates/angular/admin/plugins/manage_plugins.html @@ -3,8 +3,6 @@ .controller('PencilBlueController', function($scope, $http, $window) { ^angular_objects^ - $scope.adminPrefix = '/admin' + $scope.sitePrefix; - $scope.pluginAction = function(actionType, plugin) { $scope.actionPlugin = plugin; $scope.actionType = actionType; @@ -19,7 +17,7 @@ successCb = $scope.onInstallOrUninstallComplete; break; } - $http.post("/api" + $scope.sitePrefix +"/plugins/" + actionType + "/" + encodeURIComponent(plugin.uid)) + $http.post("/api/plugins/" + actionType + "/" + encodeURIComponent(plugin.uid)) .success(function(result) { successCb(result); }) From 2418122eba3c3bb1bcfb50949a86e5780b2d0197 Mon Sep 17 00:00:00 2001 From: iandtrapp Date: Tue, 9 Jun 2015 09:47:37 -0400 Subject: [PATCH 298/790] Removed site id reference from request handler controller --- include/http/request_handler.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/include/http/request_handler.js b/include/http/request_handler.js index dc4b7acf1..45fd8404b 100755 --- a/include/http/request_handler.js +++ b/include/http/request_handler.js @@ -858,9 +858,7 @@ module.exports = function RequestHandlerModule(pb) { err.code = 400; return self.serveError(err); } - if(pathVars.siteid) { - self.session.adminSiteId = pathVars.siteid; - } + var props = { request_handler: self, request: self.req, From a62588654bf0442ea1a31715416a9d009914a1da Mon Sep 17 00:00:00 2001 From: iandtrapp Date: Tue, 9 Jun 2015 10:53:03 -0400 Subject: [PATCH 299/790] Removed adminSiteId implementations from admin navigation controller --- include/admin_navigation.js | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/include/admin_navigation.js b/include/admin_navigation.js index 601600bad..1d67f593c 100755 --- a/include/admin_navigation.js +++ b/include/admin_navigation.js @@ -250,8 +250,8 @@ module.exports = function AdminNavigationModule(pb) { * @method getAdditions * @returns {Array} */ - function getAdditions(site) { - return util.clone(AdminNavigation.additions[site] || []); + function getAdditions() { + return util.clone(AdminNavigation.additions); }; /** @@ -261,8 +261,8 @@ module.exports = function AdminNavigationModule(pb) { * @method getChildrenAdditions * @returns {Object} */ - function getChildrenAdditions(site) { - return util.clone(AdminNavigation.childrenAdditions[site] || []); + function getChildrenAdditions() { + return util.clone(AdminNavigation.childrenAdditions); }; /** @@ -276,18 +276,14 @@ module.exports = function AdminNavigationModule(pb) { var i; var navigation = []; var multiSiteAdditions = getMultiSiteNavigation(); - var adminSiteId = session && session.adminSiteId ? session.adminSiteId : GLOBAL_SITE; + // var defaultNavigation = getDefaultNavigation(); - var additions = getAdditions(adminSiteId); - var childrenAdditions = getChildrenAdditions(adminSiteId); - if (!pb.SiteService.isGlobal(adminSiteId)) { - util.arrayPushAll(getAdditions(GLOBAL_SITE), additions); - additions = _.uniq(additions, 'id'); - util.merge(getChildrenAdditions(GLOBAL_SITE), childrenAdditions); - } + var additions = getAdditions(); + var childrenAdditions = getChildrenAdditions(); util.arrayPushAll(defaultNavigation, navigation); util.arrayPushAll(additions, navigation); + if(pb.config.multisite) { util.arrayPushAll(multiSiteAdditions, navigation); } From a705c4828db44ce8b0a27d132d696c32341f42fb Mon Sep 17 00:00:00 2001 From: iandtrapp Date: Tue, 9 Jun 2015 11:05:35 -0400 Subject: [PATCH 300/790] Cleaned up code formatting - no other changes --- include/admin_navigation.js | 1 - 1 file changed, 1 deletion(-) diff --git a/include/admin_navigation.js b/include/admin_navigation.js index 1d67f593c..1b9c46c51 100755 --- a/include/admin_navigation.js +++ b/include/admin_navigation.js @@ -276,7 +276,6 @@ module.exports = function AdminNavigationModule(pb) { var i; var navigation = []; var multiSiteAdditions = getMultiSiteNavigation(); - // var defaultNavigation = getDefaultNavigation(); var additions = getAdditions(); var childrenAdditions = getChildrenAdditions(); From 25c81f11c36acb9368f2107e91b3f1aa0723d02f Mon Sep 17 00:00:00 2001 From: btidwell Date: Tue, 9 Jun 2015 12:48:09 -0400 Subject: [PATCH 301/790] switch to site on plugin_api controller --- plugins/pencilblue/controllers/api/plugins/plugin_api.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/pencilblue/controllers/api/plugins/plugin_api.js b/plugins/pencilblue/controllers/api/plugins/plugin_api.js index fef5fa12e..e5b237aa2 100755 --- a/plugins/pencilblue/controllers/api/plugins/plugin_api.js +++ b/plugins/pencilblue/controllers/api/plugins/plugin_api.js @@ -71,7 +71,7 @@ module.exports = function(pb) { PluginApiController.prototype.render = function(cb) { var action = this.pathVars.action; var identifier = this.pathVars.id; - this.pluginService = new pb.PluginService(this.pathSiteUId); + this.pluginService = new pb.PluginService(this.site); //validate action var errors = []; From 7f1522610e9c58fcee93df7415873ed6367023bf Mon Sep 17 00:00:00 2001 From: btidwell Date: Tue, 9 Jun 2015 12:55:10 -0400 Subject: [PATCH 302/790] remove site prefix and pathsiteuid from plugin_settings page --- .../controllers/admin/plugins/plugin_settings.js | 10 ++++------ .../templates/admin/plugins/plugin_settings.html | 2 +- .../angular/admin/plugins/plugin_settings.html | 3 +-- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/plugins/pencilblue/controllers/admin/plugins/plugin_settings.js b/plugins/pencilblue/controllers/admin/plugins/plugin_settings.js index e1cf37196..64fc4b09b 100755 --- a/plugins/pencilblue/controllers/admin/plugins/plugin_settings.js +++ b/plugins/pencilblue/controllers/admin/plugins/plugin_settings.js @@ -46,7 +46,7 @@ module.exports = function(pb) { PluginSettingsFormController.prototype.init = function (props, cb) { var self = this; pb.BaseAdminController.prototype.init.call(self, props, function () { - self.pluginService = new pb.PluginService(self.pathSiteUId); + self.pluginService = new pb.PluginService(self.site); cb(); }); }; @@ -109,8 +109,7 @@ module.exports = function(pb) { //setup angular var data = { plugin: plugin, - settingType: self.getType(), - sitePrefix: self.sitePrefix + settingType: self.getType() }; var angularObjects = pb.ClientJs.getAngularObjects({ pills: self.getAdminPills(SUB_NAV_KEY, self.ls, null, data), @@ -118,8 +117,7 @@ module.exports = function(pb) { navigation: pb.AdminNavigation.get(self.session, ['plugins', 'manage'], self.ls), settings: clone, pluginUID: uid, - type: data.settingType, - sitePrefix: self.sitePrefix + type: data.settingType }); //render page @@ -247,7 +245,7 @@ module.exports = function(pb) { name: 'manage_plugins', title: data.plugin.name + ' ' + ls.get('SETTINGS'), icon: 'chevron-left', - href: '/admin' + data.sitePrefix + '/' + data.settingType + href: '/admin/' + data.settingType } ]; }; diff --git a/plugins/pencilblue/templates/admin/plugins/plugin_settings.html b/plugins/pencilblue/templates/admin/plugins/plugin_settings.html index 7c32dfd7d..8940bacd9 100755 --- a/plugins/pencilblue/templates/admin/plugins/plugin_settings.html +++ b/plugins/pencilblue/templates/admin/plugins/plugin_settings.html @@ -17,7 +17,7 @@ - +  ^loc_CANCEL^ ^tmp_admin=elements=save_button^ diff --git a/plugins/pencilblue/templates/angular/admin/plugins/plugin_settings.html b/plugins/pencilblue/templates/angular/admin/plugins/plugin_settings.html index 45281685d..73ae0f3de 100644 --- a/plugins/pencilblue/templates/angular/admin/plugins/plugin_settings.html +++ b/plugins/pencilblue/templates/angular/admin/plugins/plugin_settings.html @@ -11,8 +11,7 @@ settingsObject[$scope.settings[i].name] = $scope.settings[i].value; } - var prefix = '/admin' + $scope.sitePrefix; - $http.post(prefix + '/' + $scope.type + '/' + $scope.pluginUID + '/settings', settingsObject) + $http.post('/admin/' + $scope.type + '/' + $scope.pluginUID + '/settings', settingsObject) .success(function(result) { $scope.successMessage = result.message; $scope.saving = false; From 1acad9f1bfeb120377a562022d1c727c2a8eda77 Mon Sep 17 00:00:00 2001 From: btidwell Date: Tue, 9 Jun 2015 12:56:54 -0400 Subject: [PATCH 303/790] remove pathSiteUId and prefix from plugin_details page --- .../controllers/admin/plugins/plugin_details.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/plugins/pencilblue/controllers/admin/plugins/plugin_details.js b/plugins/pencilblue/controllers/admin/plugins/plugin_details.js index 1e725d824..55a107fe1 100755 --- a/plugins/pencilblue/controllers/admin/plugins/plugin_details.js +++ b/plugins/pencilblue/controllers/admin/plugins/plugin_details.js @@ -53,15 +53,12 @@ module.exports = function(pb) { return; } - //angular data - obj.sitePrefix = self.sitePrefix; var angularObjects = pb.ClientJs.getAngularObjects({ pills: self.getAdminPills(SUB_NAV_KEY, self.ls, null, obj), navigation: pb.AdminNavigation.get(self.session, ['plugins', 'manage'], self.ls), d: obj.details, status: obj.status, - is_active: PluginService.isActivePlugin(obj.details.uid), - sitePrefix: self.sitePrefix + is_active: PluginService.isActivePlugin(obj.details.uid) }); //render page @@ -81,7 +78,7 @@ module.exports = function(pb) { PluginDetailsViewController.prototype.getDetails = function (puid, cb) { var self = this; - var pluginService = new pb.PluginService(self.pathSiteUId); + var pluginService = new pb.PluginService(self.site); pluginService.getPluginBySite(puid, function(err, plugin) { if (util.isError(err)) { cb(err, plugin); @@ -140,7 +137,7 @@ module.exports = function(pb) { name: 'manage', title: data.details.name, icon: 'chevron-left', - href: '/admin' + data.sitePrefix + '/plugins' + href: '/admin/plugins' } ]; }; From 550a1822532c97f09be0a1b13f0ebc47c3e9925f Mon Sep 17 00:00:00 2001 From: iandtrapp Date: Tue, 9 Jun 2015 14:08:24 -0400 Subject: [PATCH 304/790] Removed pathSitePrefix from manage_objects --- .../controllers/admin/content/objects/manage_objects.js | 2 -- .../controllers/admin/content/objects/object_form.js | 4 ---- .../controllers/admin/content/objects/sort_objects.js | 1 - 3 files changed, 7 deletions(-) diff --git a/plugins/pencilblue/controllers/admin/content/objects/manage_objects.js b/plugins/pencilblue/controllers/admin/content/objects/manage_objects.js index 2c4393d7b..399456fe2 100644 --- a/plugins/pencilblue/controllers/admin/content/objects/manage_objects.js +++ b/plugins/pencilblue/controllers/admin/content/objects/manage_objects.js @@ -61,7 +61,6 @@ module.exports = function(pb) { var data = {}; - data.pathSitePrefix = self.site; data.custObjType = custObjType; var pills = pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, 'manage_objects', data); for(var i = 0; i < pills.length; i++) { @@ -78,7 +77,6 @@ module.exports = function(pb) { pills: pills, customObjects: customObjects, objectType: custObjType, - pathSitePrefix: self.site }); var title = self.ls.get('MANAGE') + ' ' + custObjType.name; diff --git a/plugins/pencilblue/controllers/admin/content/objects/object_form.js b/plugins/pencilblue/controllers/admin/content/objects/object_form.js index ed8b4a518..3371c4aaf 100644 --- a/plugins/pencilblue/controllers/admin/content/objects/object_form.js +++ b/plugins/pencilblue/controllers/admin/content/objects/object_form.js @@ -116,10 +116,6 @@ module.exports = function(pb) { callback(null, pb.AdminNavigation.get(self.session, ['content', 'custom_objects'], self.ls)); }, - pathSitePrefix: function(callback) { - callback(null, self.site) - }, - objectType: function(callback) { cos.loadTypeById(vars.type_id, function(err, objectType) { if(util.isError(err)) { diff --git a/plugins/pencilblue/controllers/admin/content/objects/sort_objects.js b/plugins/pencilblue/controllers/admin/content/objects/sort_objects.js index 3e22b260e..bbb1e9899 100644 --- a/plugins/pencilblue/controllers/admin/content/objects/sort_objects.js +++ b/plugins/pencilblue/controllers/admin/content/objects/sort_objects.js @@ -65,7 +65,6 @@ module.exports = function(pb) { pills: self.getAdminPills(SUB_NAV_KEY, self.ls, SUB_NAV_KEY, {objectType: objectType, pathSitePrefix: self.sitePrefix}), customObjects: customObjects, objectType: objectType, - pathSitePrefix: self.site }); self.setPageName(self.ls.get('SORT') + ' ' + objectType.name); From 3e63eae014f16d3278d19cf45dd9cd3d0d75374d Mon Sep 17 00:00:00 2001 From: iandtrapp Date: Tue, 9 Jun 2015 15:38:46 -0400 Subject: [PATCH 305/790] Moved new site to a new view, need to style it and clean up code --- .../sites/{new_site.js => new_site_action.js} | 16 +- .../controllers/admin/sites/manage.js | 13 +- .../controllers/admin/sites/site_form.js | 39 +++++ plugins/pencilblue/include/routes.js | 12 +- .../templates/admin/sites/manage.html | 12 +- .../templates/admin/sites/site_form.html | 21 +++ .../templates/angular/admin/sites/manage.html | 2 +- .../angular/admin/sites/site_form.html | 154 ++++++++++++++++++ 8 files changed, 246 insertions(+), 23 deletions(-) rename plugins/pencilblue/controllers/actions/admin/sites/{new_site.js => new_site_action.js} (89%) create mode 100644 plugins/pencilblue/controllers/admin/sites/site_form.js create mode 100644 plugins/pencilblue/templates/admin/sites/site_form.html create mode 100644 plugins/pencilblue/templates/angular/admin/sites/site_form.html diff --git a/plugins/pencilblue/controllers/actions/admin/sites/new_site.js b/plugins/pencilblue/controllers/actions/admin/sites/new_site_action.js similarity index 89% rename from plugins/pencilblue/controllers/actions/admin/sites/new_site.js rename to plugins/pencilblue/controllers/actions/admin/sites/new_site_action.js index cab36fe5b..8c22cb457 100644 --- a/plugins/pencilblue/controllers/actions/admin/sites/new_site.js +++ b/plugins/pencilblue/controllers/actions/admin/sites/new_site_action.js @@ -1,17 +1,17 @@ module.exports = function(pb) { - + //pb dependencies var util = pb.util; - + /** * Creates a new site */ - function NewSite(){} - util.inherits(NewSite, pb.BaseController); + function NewSiteAction(){} + util.inherits(NewSiteAction, pb.BaseController); - NewSite.prototype.render = function(cb) + NewSiteAction.prototype.render = function(cb) { - var self = this; + var self = this; this.getJSONPostParams(function(err, post) { var message = self.hasRequiredParams(post, self.getRequiredFields()); @@ -62,10 +62,10 @@ module.exports = function(pb) { }; - NewSite.prototype.getRequiredFields = function() { + NewSiteAction.prototype.getRequiredFields = function() { return ['displayName', 'hostname']; }; //exports - return NewSite; + return NewSiteAction; }; \ No newline at end of file diff --git a/plugins/pencilblue/controllers/admin/sites/manage.js b/plugins/pencilblue/controllers/admin/sites/manage.js index b9894b865..1fb9d8b3f 100644 --- a/plugins/pencilblue/controllers/admin/sites/manage.js +++ b/plugins/pencilblue/controllers/admin/sites/manage.js @@ -13,6 +13,7 @@ module.exports = function(pb) { siteService.getSiteMap(function(err, map) { var angularObjects = pb.ClientJs.getAngularObjects({ navigation: pb.AdminNavigation.get(self.session, ['site_entity'], self.ls), + pills: pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, SUB_NAV_KEY), activeSites: map.active, inactiveSites: map.inactive }); @@ -24,7 +25,17 @@ module.exports = function(pb) { } Manage.getSubNavItems = function(key, ls, data) { - return []; + return [{ + name: 'manage_sites', + title: ls.get('MANAGE_SITES'), + icon: 'refresh', + href: '/admin/sites' + }, { + name: 'new_site', + title: '', + icon: 'plus', + href: '/admin/sites/new' + }]; } pb.AdminSubnavService.registerFor(SUB_NAV_KEY, Manage.getSubNavItems); diff --git a/plugins/pencilblue/controllers/admin/sites/site_form.js b/plugins/pencilblue/controllers/admin/sites/site_form.js new file mode 100644 index 000000000..1c8b22dc9 --- /dev/null +++ b/plugins/pencilblue/controllers/admin/sites/site_form.js @@ -0,0 +1,39 @@ +module.exports = function(pb) { + + var util = pb.util; + + function NewSite(){} + util.inherits(NewSite, pb.BaseController); + + var SUB_NAV_KEY = 'new_site'; + + NewSite.prototype.render = function(cb) { + var self = this; + var angularObjects = pb.ClientJs.getAngularObjects({ + navigation: pb.AdminNavigation.get(self.session, ['site_entity'], self.ls), + pills: pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, SUB_NAV_KEY) + }); + self.ts.registerLocal('angular_objects', new pb.TemplateValue(angularObjects, false)); + self.ts.load('admin/sites/site_form', function(err,result) { + cb({content: result}); + }); + }; + + NewSite.getSubNavItems = function(key, ls, data) { + return [{ + name: 'manage_sites', + title: ls.get('MANAGE_SITES'), + icon: 'chevron-left', + href: '/admin/sites' + }, { + name: 'new_site', + title: '', + icon: 'plus', + href: '/admin/sites/new' + }]; + } + + pb.AdminSubnavService.registerFor(SUB_NAV_KEY, NewSite.getSubNavItems); + + return NewSite; +} \ No newline at end of file diff --git a/plugins/pencilblue/include/routes.js b/plugins/pencilblue/include/routes.js index 68ddb34db..15506ae45 100644 --- a/plugins/pencilblue/include/routes.js +++ b/plugins/pencilblue/include/routes.js @@ -1007,12 +1007,20 @@ module.exports = function Routes(pb){ controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'sites', 'manage.js'), content_type: 'text/html' }, + { + method: 'get', + path: "/admin/sites/new", + access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, + auth_required: true, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'sites', 'site_form.js'), + content_type: 'text/html' + }, { method: 'post', - path: "/actions/admin/site", + path: "/actions/admin/site/new", access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, auth_required: true, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'sites', 'new_site.js') + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'sites', 'new_site_action.js') }, { method: 'post', diff --git a/plugins/pencilblue/templates/admin/sites/manage.html b/plugins/pencilblue/templates/admin/sites/manage.html index 460d6b18a..da974f2de 100644 --- a/plugins/pencilblue/templates/admin/sites/manage.html +++ b/plugins/pencilblue/templates/admin/sites/manage.html @@ -2,7 +2,6 @@
^tmp_admin=elements=error_success^ ^tmp_admin=elements=sub_nav^ -
@@ -55,16 +54,7 @@
- - -
- -
-
- -
- - + ^tmp_admin=elements=progress_console_modal^ ^tmp_angular=admin=sites=manage^ diff --git a/plugins/pencilblue/templates/admin/sites/site_form.html b/plugins/pencilblue/templates/admin/sites/site_form.html new file mode 100644 index 000000000..61f787233 --- /dev/null +++ b/plugins/pencilblue/templates/admin/sites/site_form.html @@ -0,0 +1,21 @@ +^tmp_admin=head^ +
+ ^tmp_admin=elements=error_success^ + ^tmp_admin=elements=sub_nav^ + +
+ +
+ +
+
+ +
+ +
+
+ + ^tmp_admin=elements=progress_console_modal^ +
+^tmp_angular=admin=sites=manage^ +^tmp_admin=footer^ diff --git a/plugins/pencilblue/templates/angular/admin/sites/manage.html b/plugins/pencilblue/templates/angular/admin/sites/manage.html index a87067988..5506f522a 100644 --- a/plugins/pencilblue/templates/angular/admin/sites/manage.html +++ b/plugins/pencilblue/templates/angular/admin/sites/manage.html @@ -14,7 +14,7 @@ $scope.saving = true; - $http.post('/actions/admin/site', $scope.siteEntity) + $http.post('/actions/admin/site/new', $scope.siteEntity) .success(function(result) { $scope.successMessage = result.message; $scope.saving = false; diff --git a/plugins/pencilblue/templates/angular/admin/sites/site_form.html b/plugins/pencilblue/templates/angular/admin/sites/site_form.html new file mode 100644 index 000000000..49fbb3fb8 --- /dev/null +++ b/plugins/pencilblue/templates/angular/admin/sites/site_form.html @@ -0,0 +1,154 @@ + + \ No newline at end of file From e4a5073276daa97c35022f7276a7c22e19181be9 Mon Sep 17 00:00:00 2001 From: iandtrapp Date: Fri, 12 Jun 2015 10:23:36 -0400 Subject: [PATCH 306/790] Added form validation --- .../controllers/admin/sites/manage.js | 2 +- plugins/pencilblue/include/routes.js | 6 +- .../templates/admin/sites/site_form.html | 39 ++++--- .../templates/angular/admin/sites/manage.html | 31 +----- .../angular/admin/sites/site_form.html | 102 +----------------- public/localization/en-us.js | 2 +- 6 files changed, 35 insertions(+), 147 deletions(-) diff --git a/plugins/pencilblue/controllers/admin/sites/manage.js b/plugins/pencilblue/controllers/admin/sites/manage.js index 1fb9d8b3f..365edc2bc 100644 --- a/plugins/pencilblue/controllers/admin/sites/manage.js +++ b/plugins/pencilblue/controllers/admin/sites/manage.js @@ -29,7 +29,7 @@ module.exports = function(pb) { name: 'manage_sites', title: ls.get('MANAGE_SITES'), icon: 'refresh', - href: '/admin/sites' + href: '/admin/site' }, { name: 'new_site', title: '', diff --git a/plugins/pencilblue/include/routes.js b/plugins/pencilblue/include/routes.js index 15506ae45..916b9449b 100644 --- a/plugins/pencilblue/include/routes.js +++ b/plugins/pencilblue/include/routes.js @@ -1017,21 +1017,21 @@ module.exports = function Routes(pb){ }, { method: 'post', - path: "/actions/admin/site/new", + path: "/actions/admin/sites/new", access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, auth_required: true, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'sites', 'new_site_action.js') }, { method: 'post', - path: "/actions/admin/site/activate/:id", + path: "/actions/admin/sites/activate/:id", access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, auth_required: true, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'sites', 'activate_site.js') }, { method: 'post', - path: "/actions/admin/site/deactivate/:id", + path: "/actions/admin/sites/deactivate/:id", access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, auth_required: true, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'sites', 'deactivate_site.js') diff --git a/plugins/pencilblue/templates/admin/sites/site_form.html b/plugins/pencilblue/templates/admin/sites/site_form.html index 61f787233..dca643b16 100644 --- a/plugins/pencilblue/templates/admin/sites/site_form.html +++ b/plugins/pencilblue/templates/admin/sites/site_form.html @@ -2,20 +2,31 @@
^tmp_admin=elements=error_success^ ^tmp_admin=elements=sub_nav^ - -
- -
- + ^tmp_admin=elements=tab_nav^ + +
+
+
+
+ + +
^loc_REQUIRED_FIELD^
+
+
+ + +
^loc_REQUIRED_FIELD^
+
-
- -
- - - - +
+ +  ^loc_CANCEL^ + + ^tmp_admin=elements=save_button^ +
+
+ ^tmp_admin=elements=progress_console_modal^
-^tmp_angular=admin=sites=manage^ -^tmp_admin=footer^ +^tmp_angular=admin=sites=site_form^ +^tmp_admin=footer^ \ No newline at end of file diff --git a/plugins/pencilblue/templates/angular/admin/sites/manage.html b/plugins/pencilblue/templates/angular/admin/sites/manage.html index 5506f522a..85b6c2adb 100644 --- a/plugins/pencilblue/templates/angular/admin/sites/manage.html +++ b/plugins/pencilblue/templates/angular/admin/sites/manage.html @@ -3,29 +3,6 @@ angular.module('pencilblueApp', ['validation']) .controller('PencilBlueController', function($scope, $http, $window, validationService) { ^angular_objects^ - ^tmp_angular=admin=elements=is_field_valid^ - - $scope.addNewSite = function() { - $scope.formSubmitted = true; - - if(!validationService.isFormValid($scope.siteForm)) { - return; - } - - $scope.saving = true; - - $http.post('/actions/admin/site/new', $scope.siteEntity) - .success(function(result) { - $scope.successMessage = result.message; - $scope.saving = false; - $scope.onActionSuccess(); - $scope.$apply(); - }) - .error(function(error, status) { - $scope.errorMessage = error.message; - $scope.saving = false; - }); - }; $scope.activateSite = function(site) { site.name = site.displayName; @@ -34,7 +11,7 @@ $scope.consoleOutput = ''; $('#progress_modal').modal({}); - $http.post('/actions/admin/site/activate/' + site.uid) + $http.post('/actions/admin/sites/activate/' + site.uid) .success(function(result) { $scope.onActivateOrDeactivateComplete(result); }) @@ -50,7 +27,7 @@ $scope.consoleOutput = ''; $('#progress_modal').modal({}); - $http.post('/actions/admin/site/deactivate/' + site.uid) + $http.post('/actions/admin/sites/deactivate/' + site.uid) .success(function(result) { $scope.onActivateOrDeactivateComplete(result); }) @@ -141,12 +118,12 @@ $scope.onActionSuccess = function() { $scope.actionIsComplete = true; $scope.refreshPage(); - } + }; $scope.onActionFailure = function(error) { $scope.actionIsComplete = true; $scope.actionError = error.message; - } + }; $scope.refreshPage = function() { $window.location.reload(); diff --git a/plugins/pencilblue/templates/angular/admin/sites/site_form.html b/plugins/pencilblue/templates/angular/admin/sites/site_form.html index 49fbb3fb8..6d28b2e1d 100644 --- a/plugins/pencilblue/templates/angular/admin/sites/site_form.html +++ b/plugins/pencilblue/templates/angular/admin/sites/site_form.html @@ -14,7 +14,7 @@ $scope.saving = true; - $http.post('/actions/admin/site', $scope.siteEntity) + $http.post('/actions/admin/sites/new', $scope.siteEntity) .success(function(result) { $scope.successMessage = result.message; $scope.saving = false; @@ -27,38 +27,6 @@ }); }; - $scope.activateSite = function(site) { - site.name = site.displayName; - $scope.actionPlugin = site; - $scope.actionProgress = '0'; - $scope.consoleOutput = ''; - $('#progress_modal').modal({}); - - $http.post('/actions/admin/site/activate/' + site.uid) - .success(function(result) { - $scope.onActivateOrDeactivateComplete(result); - }) - .error(function(error, status) { - $scope.onActionFailure(error); - }); - }; - - $scope.deactivateSite = function(site) { - site.name = site.displayName; - $scope.actionPlugin = site; - $scope.actionProgress = '0'; - $scope.consoleOutput = ''; - $('#progress_modal').modal({}); - - $http.post('/actions/admin/site/deactivate/' + site.uid) - .success(function(result) { - $scope.onActivateOrDeactivateComplete(result); - }) - .error(function(error, status) { - $scope.onActionFailure(error); - }); - }; - $scope.jobAction = function(actionType, identifier, data, cb) { $http.post("/api/jobs/" + actionType + "/" + encodeURIComponent(identifier), data) .success(function(result) { @@ -69,74 +37,6 @@ }); }; - $scope.onActivateOrDeactivateComplete = function(result) { - var jobId = result.data; - - //poll for logs - var logHandle = null; - var starting = 0; - var doLogRetrieve = function() { - $scope.jobAction('getLogs', jobId, {starting: starting}, function(result) { - if (!result || !result.data || !result.data.length) { - return; - } - - var nextStarting = starting; - for(var i = 0; i < result.data.length; i++) { - var item = result.data[i]; - $scope.consoleOutput += ($scope.consoleOutput.length ? '\n' : '') + item.created + ':[' + item.worker_id + '] ' + item.message; - - var date = new Date(item.created).getTime(); - if(date > nextStarting) { - nextStarting = date; - } - } - - //offset so we don't get repeats - starting = nextStarting + 1; - - //check for more log entries - logHandle = setTimeout(doLogRetrieve, 2000); - }); - }; - doLogRetrieve(); - - //check for job completion - var retrieveHandle = null; - var doJobRetrieve = function() { - $scope.jobAction('get', jobId, {}, function(result) { - if(!result || !result.data) { - return; - } - - //set progress bar - if(!isNaN(result.data.progress)) { - $scope.actionProgress = result.data.progress.toString(); - } - - //verify status - if(result.data.status === 'RUNNING') { - retrieveHandle = setTimeout(doJobRetrieve, 1000); - } - else { - //allow any trailing logs to come in - setTimeout(function() { - clearTimeout(logHandle); - - var line = result.data.status; - if (result.data.error) { - line += ': ' + result.data.error; - } - $scope.consoleOutput += ($scope.consoleOutput.length ? '\n' : '') + line; - $scope.onActionSuccess(); - $scope.$apply(); - }, 1500); - } - }); - }; - doJobRetrieve(); - }; - $scope.onActionSuccess = function() { $scope.actionIsComplete = true; $scope.refreshPage(); diff --git a/public/localization/en-us.js b/public/localization/en-us.js index ffa7f3a77..03138eefc 100755 --- a/public/localization/en-us.js +++ b/public/localization/en-us.js @@ -430,7 +430,7 @@ var loc = }, sites: { EXISTING_HOSTNAME: 'That hostname is already in use', - EXISTING_DISPLAYNAME: 'There is already a site with that displayname', + EXISTING_DISPLAYNAME: 'There is already a site with that display name', SITE_CREATED: 'The site was successfully created', ERROR_ACTIVATING: 'There was an error activating', ERROR_DEACTIVATING: 'There was an error deactivating', From 491f8ee570dc6f06afc5464142888c701decaf14 Mon Sep 17 00:00:00 2001 From: btidwell Date: Fri, 12 Jun 2015 10:59:13 -0400 Subject: [PATCH 307/790] remove prefix from configuration controller --- .../admin/site_settings/configuration.js | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/plugins/pencilblue/controllers/admin/site_settings/configuration.js b/plugins/pencilblue/controllers/admin/site_settings/configuration.js index 868f6af17..4d1965c5b 100755 --- a/plugins/pencilblue/controllers/admin/site_settings/configuration.js +++ b/plugins/pencilblue/controllers/admin/site_settings/configuration.js @@ -56,7 +56,7 @@ module.exports = function(pb) { var angularObjects = pb.ClientJs.getAngularObjects({ navigation: pb.AdminNavigation.get(self.session, ['settings', 'site_settings'], self.ls), - pills: self.getAdminPills(SUB_NAV_KEY, self.ls, 'configuration', {sitePrefix: self.sitePrefix, site: self.pathSiteUId, siteName: self.siteName}), + pills: self.getAdminPills(SUB_NAV_KEY, self.ls, 'configuration', {site: self.site, siteName: self.siteName}), config: config, isGlobalSite: self.isGlobalSite }); @@ -70,26 +70,21 @@ module.exports = function(pb) { }; Configuration.getSubNavItems = function(key, ls, data) { - var prefix = '/admin'; - if(data && data.sitePrefix) { - prefix += data.sitePrefix; - } - var pills = [{ name: 'configuration', title: ls.get('CONFIGURATION'), icon: 'refresh', - href: prefix + '/site_settings' + href: '/admin/site_settings' }, { name: 'content', title: ls.get('CONTENT'), icon: 'quote-right', - href: prefix + '/site_settings/content' + href: '/admin/site_settings/content' }, { name: 'email', title: ls.get('EMAIL'), icon: 'envelope', - href: prefix + '/site_settings/email' + href: '/admin/site_settings/email' }]; if(data && data.site === pb.SiteService.GLOBAL_SITE) { @@ -97,7 +92,7 @@ module.exports = function(pb) { name: 'libraries', title: ls.get('LIBRARIES'), icon: 'book', - href: prefix + '/site_settings/libraries' + href: '/admin/site_settings/libraries' }); } From 1bd30e78cf12aed8a7e589e7ebdeefd13c9b0152 Mon Sep 17 00:00:00 2001 From: btidwell Date: Fri, 12 Jun 2015 11:02:54 -0400 Subject: [PATCH 308/790] remove path site from content page under site settings --- .../controllers/admin/site_settings/content.js | 15 +++++++-------- .../templates/admin/site_settings/content.html | 2 +- .../angular/admin/site_settings/content.html | 2 +- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/plugins/pencilblue/controllers/admin/site_settings/content.js b/plugins/pencilblue/controllers/admin/site_settings/content.js index 3e0a62170..71f221029 100755 --- a/plugins/pencilblue/controllers/admin/site_settings/content.js +++ b/plugins/pencilblue/controllers/admin/site_settings/content.js @@ -57,14 +57,13 @@ module.exports = function(pb) { } ]; - var contentService = new pb.ContentService(this.pathSiteUid, true); + var contentService = new pb.ContentService(this.site, true); contentService.getSettings(function(err, contentSettings) { var angularObjects = pb.ClientJs.getAngularObjects({ navigation: pb.AdminNavigation.get(self.session, ['settings', 'site_settings'], self.ls), - pills: self.getAdminPills(SUB_NAV_KEY, self.ls, 'content', { pathSitePrefix: self.sitePrefix }), + pills: self.getAdminPills(SUB_NAV_KEY, self.ls, 'content', {site:self.site}), tabs: tabs, - contentSettings: contentSettings, - pathSitePrefix: self.sitePrefix + contentSettings: contentSettings }); self.setPageName(self.ls.get('CONTENT')); @@ -81,20 +80,20 @@ module.exports = function(pb) { name: 'configuration', title: ls.get('CONTENT'), icon: 'chevron-left', - href: '/admin' + data.pathSitePrefix + '/site_settings' + href: '/admin/site_settings' }, { name: 'email', title: ls.get('EMAIL'), icon: 'envelope', - href: '/admin' + data.pathSitePrefix + '/site_settings/email' + href: '/admin/site_settings/email' }]; - if (data.pathSiteUid === pb.SiteService.GLOBAL_SITE) { + if (data.site === pb.SiteService.GLOBAL_SITE) { subNavItems.push({ name: 'libraries', title: ls.get('LIBRARIES'), icon: 'book', - href: '/admin' + data.pathSitePrefix + '/site_settings/libraries' + href: '/admin/site_settings/libraries' }); } diff --git a/plugins/pencilblue/templates/admin/site_settings/content.html b/plugins/pencilblue/templates/admin/site_settings/content.html index 7a14ca557..d8907545f 100755 --- a/plugins/pencilblue/templates/admin/site_settings/content.html +++ b/plugins/pencilblue/templates/admin/site_settings/content.html @@ -134,7 +134,7 @@
- +  ^loc_CANCEL^ ^tmp_admin=elements=save_button^ diff --git a/plugins/pencilblue/templates/angular/admin/site_settings/content.html b/plugins/pencilblue/templates/angular/admin/site_settings/content.html index 4b8a73b9e..a2bddab7b 100644 --- a/plugins/pencilblue/templates/angular/admin/site_settings/content.html +++ b/plugins/pencilblue/templates/angular/admin/site_settings/content.html @@ -18,7 +18,7 @@ $scope.saving = true; - $http.post('/actions/admin' + $scope.pathSitePrefix + '/site_settings/content', $scope.contentSettings) + $http.post('/actions/admin/site_settings/content', $scope.contentSettings) .success(function(result) { $scope.successMessage = result.message; $scope.saving = false; From 3f3e0348b66171a14f32630073ec64b1147cf960 Mon Sep 17 00:00:00 2001 From: btidwell Date: Fri, 12 Jun 2015 11:05:54 -0400 Subject: [PATCH 309/790] remove prefix from libraries and sitename from configuration --- .../controllers/admin/site_settings/configuration.js | 2 +- .../controllers/admin/site_settings/libraries.js | 12 ++++-------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/plugins/pencilblue/controllers/admin/site_settings/configuration.js b/plugins/pencilblue/controllers/admin/site_settings/configuration.js index 4d1965c5b..0e6a02ac4 100755 --- a/plugins/pencilblue/controllers/admin/site_settings/configuration.js +++ b/plugins/pencilblue/controllers/admin/site_settings/configuration.js @@ -56,7 +56,7 @@ module.exports = function(pb) { var angularObjects = pb.ClientJs.getAngularObjects({ navigation: pb.AdminNavigation.get(self.session, ['settings', 'site_settings'], self.ls), - pills: self.getAdminPills(SUB_NAV_KEY, self.ls, 'configuration', {site: self.site, siteName: self.siteName}), + pills: self.getAdminPills(SUB_NAV_KEY, self.ls, 'configuration', {site: self.site}), config: config, isGlobalSite: self.isGlobalSite }); diff --git a/plugins/pencilblue/controllers/admin/site_settings/libraries.js b/plugins/pencilblue/controllers/admin/site_settings/libraries.js index 6f8c230b0..974c4e49d 100644 --- a/plugins/pencilblue/controllers/admin/site_settings/libraries.js +++ b/plugins/pencilblue/controllers/admin/site_settings/libraries.js @@ -51,7 +51,7 @@ module.exports = function(pb) { librariesService.getSettings(function(err, librarySettings) { var angularObjects = pb.ClientJs.getAngularObjects({ navigation: pb.AdminNavigation.get(self.session, ['settings', 'site_settings'], self.ls), - pills: self.getAdminPills(SUB_NAV_KEY, self.ls, 'libraries', {sitePrefix: self.sitePrefix, siteName:self.siteName}), + pills: self.getAdminPills(SUB_NAV_KEY, self.ls, 'libraries'), tabs: tabs, librarySettings: librarySettings, cdnDefaults: pb.LibrariesService.getCDNDefaults(), @@ -68,25 +68,21 @@ module.exports = function(pb) { Libraries.getSubNavItems = function(key, ls, data) { - var prefix = '/admin'; - if(data && data.sitePrefix) { - prefix += data.sitePrefix; - } return [{ name: 'configuration', title: ls.get('LIBRARIES'), icon: 'chevron-left', - href: prefix + '/site_settings' + href: '/admin/site_settings' }, { name: 'content', title: ls.get('CONTENT'), icon: 'quote-right', - href: prefix + '/site_settings/content' + href: '/admin/site_settings/content' }, { name: 'email', title: ls.get('EMAIL'), icon: 'envelope', - href: prefix + '/site_settings/email' + href: '/admin/site_settings/email' }]; }; From 7c408b300183260216ae9294ecde660de664af19 Mon Sep 17 00:00:00 2001 From: btidwell Date: Fri, 12 Jun 2015 11:08:33 -0400 Subject: [PATCH 310/790] remove pathSiteUId from overlooked controller --- .../controllers/api/admin/content/media/get_preview.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/pencilblue/controllers/api/admin/content/media/get_preview.js b/plugins/pencilblue/controllers/api/admin/content/media/get_preview.js index bc485914a..141a9c373 100644 --- a/plugins/pencilblue/controllers/api/admin/content/media/get_preview.js +++ b/plugins/pencilblue/controllers/api/admin/content/media/get_preview.js @@ -50,7 +50,7 @@ module.exports = function(pb) { var options = { view: 'view' }; - var mediaService = new pb.MediaService(null, self.pathSiteUId, true); + var mediaService = new pb.MediaService(null, self.site, true); if (get.id) { mediaService.renderById(get.id, options, function(err, html) { self.renderComplete(err, html, cb); From fd9f9449998eb496e5b94dd612237640a565405c Mon Sep 17 00:00:00 2001 From: btidwell Date: Fri, 12 Jun 2015 11:10:30 -0400 Subject: [PATCH 311/790] remove pathSiteUId from base_admin_controller --- controllers/admin/base_admin_controller.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/controllers/admin/base_admin_controller.js b/controllers/admin/base_admin_controller.js index add7c0d59..5ac5368f5 100644 --- a/controllers/admin/base_admin_controller.js +++ b/controllers/admin/base_admin_controller.js @@ -37,7 +37,6 @@ module.exports = function BaseAdminControllerModule(pb) { */ BaseAdminController.prototype.init = function (props, cb) { var self = this; - self.pathSiteUId = props.site; BaseController.prototype.init.call(self, props, function () { self.extendedInit(cb); }); @@ -46,14 +45,14 @@ module.exports = function BaseAdminControllerModule(pb) { BaseAdminController.prototype.extendedInit = function(cb) { var self = this; var siteService = new pb.SiteService(); - siteService.getByUid(self.pathSiteUId, function (err, siteInfo) { + siteService.getByUid(self.site, function (err, siteInfo) { if (err || !siteInfo) { self.reqHandler.serve404(); } else { - self.sectionService = new pb.SectionService(self.pathSiteUId, true); - self.sitePrefix = pb.SiteService.getCurrentSitePrefix(self.pathSiteUId); - self.siteQueryService = new pb.SiteQueryService(self.pathSiteUId, true); - self.settings = pb.SettingServiceFactory.getServiceBySite(self.pathSiteUId, true); + self.sectionService = new pb.SectionService(self.site, true); + self.sitePrefix = pb.SiteService.getCurrentSitePrefix(self.site); + self.siteQueryService = new pb.SiteQueryService(self.site, true); + self.settings = pb.SettingServiceFactory.getServiceBySite(self.site, true); self.siteObj = siteInfo; self.isGlobalSite = pb.SiteService.isGlobal(siteInfo.uid); self.siteName = self.isGlobalSite ? siteInfo.uid : siteInfo.displayName; @@ -77,7 +76,7 @@ module.exports = function BaseAdminControllerModule(pb) { * @return {Object} TemplateService */ BaseAdminController.prototype.getTemplateService = function(tsOpts) { - tsOpts.site = this.pathSiteUId; + tsOpts.site = this.site; return new pb.TemplateService(tsOpts); }; From 846f055f7d4fcb6f678b994084e5e71b035e3209 Mon Sep 17 00:00:00 2001 From: btidwell Date: Fri, 12 Jun 2015 11:11:41 -0400 Subject: [PATCH 312/790] remove pathSiteUId from form admin_form_controller --- controllers/admin/admin_form_controller.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/controllers/admin/admin_form_controller.js b/controllers/admin/admin_form_controller.js index e2bfe9e11..6024ae081 100644 --- a/controllers/admin/admin_form_controller.js +++ b/controllers/admin/admin_form_controller.js @@ -32,7 +32,7 @@ module.exports = function AdminFormControllerModule(pb) { */ AdminFormController.prototype.init = function (props, cb) { var self = this; - self.pathSiteUId = pb.SiteService.getCurrentSite(props.site); + self.site = pb.SiteService.getCurrentSite(props.site); pb.FormController.prototype.init.call(self, props, function () { BaseAdminController.prototype.extendedInit.call(self, cb); }); From 38fde53129b77be560d79d1ac682eaff7bdb0f36 Mon Sep 17 00:00:00 2001 From: btidwell Date: Fri, 12 Jun 2015 11:30:17 -0400 Subject: [PATCH 313/790] remove remaining uses of site prefix in admin console --- controllers/admin/base_admin_controller.js | 1 - .../controllers/admin/content/articles/article_form.js | 3 +-- .../controllers/admin/content/objects/sort_objects.js | 2 +- .../pencilblue/controllers/admin/content/pages/page_form.js | 3 +-- 4 files changed, 3 insertions(+), 6 deletions(-) diff --git a/controllers/admin/base_admin_controller.js b/controllers/admin/base_admin_controller.js index 5ac5368f5..c6636c5be 100644 --- a/controllers/admin/base_admin_controller.js +++ b/controllers/admin/base_admin_controller.js @@ -50,7 +50,6 @@ module.exports = function BaseAdminControllerModule(pb) { self.reqHandler.serve404(); } else { self.sectionService = new pb.SectionService(self.site, true); - self.sitePrefix = pb.SiteService.getCurrentSitePrefix(self.site); self.siteQueryService = new pb.SiteQueryService(self.site, true); self.settings = pb.SettingServiceFactory.getServiceBySite(self.site, true); self.siteObj = siteInfo; diff --git a/plugins/pencilblue/controllers/admin/content/articles/article_form.js b/plugins/pencilblue/controllers/admin/content/articles/article_form.js index 6c2d969f0..99ced7609 100755 --- a/plugins/pencilblue/controllers/admin/content/articles/article_form.js +++ b/plugins/pencilblue/controllers/admin/content/articles/article_form.js @@ -137,8 +137,7 @@ module.exports = function(pb) { media: data.media, article: data.article, siteKey: pb.SiteService.SITE_FIELD, - site: self.site, - sitePrefix: self.sitePrefix + site: self.site }; if(data.availableAuthors) { objects.availableAuthors = data.availableAuthors; diff --git a/plugins/pencilblue/controllers/admin/content/objects/sort_objects.js b/plugins/pencilblue/controllers/admin/content/objects/sort_objects.js index bbb1e9899..b241e48d4 100644 --- a/plugins/pencilblue/controllers/admin/content/objects/sort_objects.js +++ b/plugins/pencilblue/controllers/admin/content/objects/sort_objects.js @@ -62,7 +62,7 @@ module.exports = function(pb) { var angularObjects = pb.ClientJs.getAngularObjects( { navigation: pb.AdminNavigation.get(self.session, ['content', 'custom_objects'], self.ls), - pills: self.getAdminPills(SUB_NAV_KEY, self.ls, SUB_NAV_KEY, {objectType: objectType, pathSitePrefix: self.sitePrefix}), + pills: self.getAdminPills(SUB_NAV_KEY, self.ls, SUB_NAV_KEY, {objectType: objectType}), customObjects: customObjects, objectType: objectType, }); diff --git a/plugins/pencilblue/controllers/admin/content/pages/page_form.js b/plugins/pencilblue/controllers/admin/content/pages/page_form.js index d49f08ee2..daa3b6df7 100755 --- a/plugins/pencilblue/controllers/admin/content/pages/page_form.js +++ b/plugins/pencilblue/controllers/admin/content/pages/page_form.js @@ -123,8 +123,7 @@ module.exports = function(pb) { media: data.media, page: data.page, siteKey: pb.SiteService.SITE_FIELD, - site: self.site, - sitePrefix: self.sitePrefix + site: self.site }; if(data.availableAuthors) { objects.availableAuthors = data.availableAuthors; From b8aa643855c59e51f621215b2a8da49722f90d86 Mon Sep 17 00:00:00 2001 From: iandtrapp Date: Fri, 12 Jun 2015 11:34:30 -0400 Subject: [PATCH 314/790] Added settings tab --- .../controllers/admin/sites/manage.js | 4 ++-- .../controllers/admin/sites/site_form.js | 18 ++++++++++-------- .../templates/admin/sites/site_form.html | 7 ++++--- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/plugins/pencilblue/controllers/admin/sites/manage.js b/plugins/pencilblue/controllers/admin/sites/manage.js index 365edc2bc..191ab70b2 100644 --- a/plugins/pencilblue/controllers/admin/sites/manage.js +++ b/plugins/pencilblue/controllers/admin/sites/manage.js @@ -36,9 +36,9 @@ module.exports = function(pb) { icon: 'plus', href: '/admin/sites/new' }]; - } + }; - pb.AdminSubnavService.registerFor(SUB_NAV_KEY, Manage.getSubNavItems); + pb.AdminSubnavService.registerFor(SUB_NAV_KEY, Manage.getSubNavItems); return Manage; } \ No newline at end of file diff --git a/plugins/pencilblue/controllers/admin/sites/site_form.js b/plugins/pencilblue/controllers/admin/sites/site_form.js index 1c8b22dc9..43c11801e 100644 --- a/plugins/pencilblue/controllers/admin/sites/site_form.js +++ b/plugins/pencilblue/controllers/admin/sites/site_form.js @@ -11,7 +11,8 @@ module.exports = function(pb) { var self = this; var angularObjects = pb.ClientJs.getAngularObjects({ navigation: pb.AdminNavigation.get(self.session, ['site_entity'], self.ls), - pills: pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, SUB_NAV_KEY) + pills: pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, SUB_NAV_KEY), + tabs: [{ active: 'active', href: '#sites', icon: 'cog', title: self.ls.get('SETTINGS') }] }); self.ts.registerLocal('angular_objects', new pb.TemplateValue(angularObjects, false)); self.ts.load('admin/sites/site_form', function(err,result) { @@ -19,21 +20,22 @@ module.exports = function(pb) { }); }; - NewSite.getSubNavItems = function(key, ls, data) { - return [{ + + NewSite.getSubNavItems = function(key, ls, data) { + return [{ name: 'manage_sites', title: ls.get('MANAGE_SITES'), icon: 'chevron-left', href: '/admin/sites' - }, { + }, { name: 'new_site', title: '', icon: 'plus', href: '/admin/sites/new' - }]; - } + }]; + }; - pb.AdminSubnavService.registerFor(SUB_NAV_KEY, NewSite.getSubNavItems); + pb.AdminSubnavService.registerFor(SUB_NAV_KEY, NewSite.getSubNavItems); - return NewSite; + return NewSite; } \ No newline at end of file diff --git a/plugins/pencilblue/templates/admin/sites/site_form.html b/plugins/pencilblue/templates/admin/sites/site_form.html index dca643b16..8016298d1 100644 --- a/plugins/pencilblue/templates/admin/sites/site_form.html +++ b/plugins/pencilblue/templates/admin/sites/site_form.html @@ -6,7 +6,7 @@
-
+
@@ -27,6 +27,7 @@
^tmp_admin=elements=progress_console_modal^ - + ^tmp_angular=admin=sites=site_form^ -^tmp_admin=footer^ \ No newline at end of file +^tmp_admin=footer^ + \ No newline at end of file From 439e955514daeef95e5322cdb92f48d0d2745686 Mon Sep 17 00:00:00 2001 From: iandtrapp Date: Fri, 12 Jun 2015 11:43:05 -0400 Subject: [PATCH 315/790] Changed class/function name to be consistent with file name --- .../controllers/admin/sites/site_form.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/plugins/pencilblue/controllers/admin/sites/site_form.js b/plugins/pencilblue/controllers/admin/sites/site_form.js index 43c11801e..008a20e90 100644 --- a/plugins/pencilblue/controllers/admin/sites/site_form.js +++ b/plugins/pencilblue/controllers/admin/sites/site_form.js @@ -2,12 +2,12 @@ module.exports = function(pb) { var util = pb.util; - function NewSite(){} - util.inherits(NewSite, pb.BaseController); + function SiteForm(){} + util.inherits(SiteForm, pb.BaseController); var SUB_NAV_KEY = 'new_site'; - NewSite.prototype.render = function(cb) { + SiteForm.prototype.render = function(cb) { var self = this; var angularObjects = pb.ClientJs.getAngularObjects({ navigation: pb.AdminNavigation.get(self.session, ['site_entity'], self.ls), @@ -21,7 +21,7 @@ module.exports = function(pb) { }; - NewSite.getSubNavItems = function(key, ls, data) { + SiteForm.getSubNavItems = function(key, ls, data) { return [{ name: 'manage_sites', title: ls.get('MANAGE_SITES'), @@ -35,7 +35,7 @@ module.exports = function(pb) { }]; }; - pb.AdminSubnavService.registerFor(SUB_NAV_KEY, NewSite.getSubNavItems); + pb.AdminSubnavService.registerFor(SUB_NAV_KEY, SiteForm.getSubNavItems); - return NewSite; -} \ No newline at end of file + return SiteForm; +}; \ No newline at end of file From 1032dbce2a0c01d3d252004b5272d081211c4dc6 Mon Sep 17 00:00:00 2001 From: iandtrapp Date: Fri, 12 Jun 2015 11:47:43 -0400 Subject: [PATCH 316/790] Remaned manage.js to manage_sites.js --- .../controllers/admin/sites/manage.js | 44 ------------------- .../controllers/admin/sites/manage_sites.js | 44 +++++++++++++++++++ plugins/pencilblue/include/routes.js | 2 +- 3 files changed, 45 insertions(+), 45 deletions(-) delete mode 100644 plugins/pencilblue/controllers/admin/sites/manage.js create mode 100644 plugins/pencilblue/controllers/admin/sites/manage_sites.js diff --git a/plugins/pencilblue/controllers/admin/sites/manage.js b/plugins/pencilblue/controllers/admin/sites/manage.js deleted file mode 100644 index 191ab70b2..000000000 --- a/plugins/pencilblue/controllers/admin/sites/manage.js +++ /dev/null @@ -1,44 +0,0 @@ -module.exports = function(pb) { - - var util = pb.util; - - function Manage(){} - util.inherits(Manage, pb.BaseController); - - var SUB_NAV_KEY = 'sites_manage'; - - Manage.prototype.render = function(cb) { - var self = this; - var siteService = new pb.SiteService(); - siteService.getSiteMap(function(err, map) { - var angularObjects = pb.ClientJs.getAngularObjects({ - navigation: pb.AdminNavigation.get(self.session, ['site_entity'], self.ls), - pills: pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, SUB_NAV_KEY), - activeSites: map.active, - inactiveSites: map.inactive - }); - self.ts.registerLocal('angular_objects', new pb.TemplateValue(angularObjects, false)); - self.ts.load('admin/sites/manage', function(err,result) { - cb({content: result}); - }); - }); - } - - Manage.getSubNavItems = function(key, ls, data) { - return [{ - name: 'manage_sites', - title: ls.get('MANAGE_SITES'), - icon: 'refresh', - href: '/admin/site' - }, { - name: 'new_site', - title: '', - icon: 'plus', - href: '/admin/sites/new' - }]; - }; - - pb.AdminSubnavService.registerFor(SUB_NAV_KEY, Manage.getSubNavItems); - - return Manage; -} \ No newline at end of file diff --git a/plugins/pencilblue/controllers/admin/sites/manage_sites.js b/plugins/pencilblue/controllers/admin/sites/manage_sites.js new file mode 100644 index 000000000..75e80921b --- /dev/null +++ b/plugins/pencilblue/controllers/admin/sites/manage_sites.js @@ -0,0 +1,44 @@ +module.exports = function(pb) { + + var util = pb.util; + + function ManageSites(){} + util.inherits(ManageSites, pb.BaseController); + + var SUB_NAV_KEY = 'sites_manage'; + + ManageSites.prototype.render = function(cb) { + var self = this; + var siteService = new pb.SiteService(); + siteService.getSiteMap(function(err, map) { + var angularObjects = pb.ClientJs.getAngularObjects({ + navigation: pb.AdminNavigation.get(self.session, ['site_entity'], self.ls), + pills: pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, SUB_NAV_KEY), + activeSites: map.active, + inactiveSites: map.inactive + }); + self.ts.registerLocal('angular_objects', new pb.TemplateValue(angularObjects, false)); + self.ts.load('admin/sites/manage', function(err,result) { + cb({content: result}); + }); + }); + } + + ManageSites.getSubNavItems = function(key, ls, data) { + return [{ + name: 'manage_sites', + title: ls.get('MANAGE_SITES'), + icon: 'refresh', + href: '/admin/site' + }, { + name: 'new_site', + title: '', + icon: 'plus', + href: '/admin/sites/new' + }]; + }; + + pb.AdminSubnavService.registerFor(SUB_NAV_KEY, ManageSites.getSubNavItems); + + return ManageSites; +} \ No newline at end of file diff --git a/plugins/pencilblue/include/routes.js b/plugins/pencilblue/include/routes.js index 916b9449b..755952db4 100644 --- a/plugins/pencilblue/include/routes.js +++ b/plugins/pencilblue/include/routes.js @@ -1004,7 +1004,7 @@ module.exports = function Routes(pb){ path: "/admin/sites", access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, auth_required: true, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'sites', 'manage.js'), + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'sites', 'manage_sites.js'), content_type: 'text/html' }, { From be863fe5abee78606285477c5689cc104c3f081d Mon Sep 17 00:00:00 2001 From: iandtrapp Date: Fri, 12 Jun 2015 12:23:23 -0400 Subject: [PATCH 317/790] Renamed manage files to be consistent with current naming schema --- .../controllers/admin/sites/manage_sites.js | 6 +- .../templates/admin/sites/manage.html | 61 -------- .../templates/admin/sites/manage_sites.html | 61 ++++++++ .../templates/angular/admin/sites/manage.html | 132 ------------------ .../angular/admin/sites/manage_sites.html | 132 ++++++++++++++++++ public/localization/en-us.js | 2 +- 6 files changed, 197 insertions(+), 197 deletions(-) delete mode 100644 plugins/pencilblue/templates/admin/sites/manage.html create mode 100644 plugins/pencilblue/templates/admin/sites/manage_sites.html delete mode 100644 plugins/pencilblue/templates/angular/admin/sites/manage.html create mode 100644 plugins/pencilblue/templates/angular/admin/sites/manage_sites.html diff --git a/plugins/pencilblue/controllers/admin/sites/manage_sites.js b/plugins/pencilblue/controllers/admin/sites/manage_sites.js index 75e80921b..b01569918 100644 --- a/plugins/pencilblue/controllers/admin/sites/manage_sites.js +++ b/plugins/pencilblue/controllers/admin/sites/manage_sites.js @@ -18,11 +18,11 @@ module.exports = function(pb) { inactiveSites: map.inactive }); self.ts.registerLocal('angular_objects', new pb.TemplateValue(angularObjects, false)); - self.ts.load('admin/sites/manage', function(err,result) { + self.ts.load('admin/sites/manage_sites', function(err,result) { cb({content: result}); }); }); - } + }; ManageSites.getSubNavItems = function(key, ls, data) { return [{ @@ -41,4 +41,4 @@ module.exports = function(pb) { pb.AdminSubnavService.registerFor(SUB_NAV_KEY, ManageSites.getSubNavItems); return ManageSites; -} \ No newline at end of file +}; \ No newline at end of file diff --git a/plugins/pencilblue/templates/admin/sites/manage.html b/plugins/pencilblue/templates/admin/sites/manage.html deleted file mode 100644 index da974f2de..000000000 --- a/plugins/pencilblue/templates/admin/sites/manage.html +++ /dev/null @@ -1,61 +0,0 @@ -^tmp_admin=head^ -
- ^tmp_admin=elements=error_success^ - ^tmp_admin=elements=sub_nav^ -
-
-
- Active Sites -
-
- No Active Sites -
- - - - - - - - - - - - - -
Site NameHostnameDate Added
-
- -
-
-
-
-
- Inactive Sites -
-
- No Inactive Sites -
- - - - - - - - - - - - - -
Site NameHostnameDate Added
-
- -
-
-
- ^tmp_admin=elements=progress_console_modal^ -
-^tmp_angular=admin=sites=manage^ -^tmp_admin=footer^ diff --git a/plugins/pencilblue/templates/admin/sites/manage_sites.html b/plugins/pencilblue/templates/admin/sites/manage_sites.html new file mode 100644 index 000000000..f6363908f --- /dev/null +++ b/plugins/pencilblue/templates/admin/sites/manage_sites.html @@ -0,0 +1,61 @@ +^tmp_admin=head^ +
+ ^tmp_admin=elements=error_success^ + ^tmp_admin=elements=sub_nav^ +
+
+
+ Active Sites +
+
+ No Active Sites +
+ + + + + + + + + + + + + +
Site NameHostnameDate Added
+
+ +
+
+
+
+
+ Inactive Sites +
+
+ No Inactive Sites +
+ + + + + + + + + + + + + +
Site NameHostnameDate Added
+
+ +
+
+
+ ^tmp_admin=elements=progress_console_modal^ +
+^tmp_angular=admin=sites=manage_sites^ +^tmp_admin=footer^ \ No newline at end of file diff --git a/plugins/pencilblue/templates/angular/admin/sites/manage.html b/plugins/pencilblue/templates/angular/admin/sites/manage.html deleted file mode 100644 index 85b6c2adb..000000000 --- a/plugins/pencilblue/templates/angular/admin/sites/manage.html +++ /dev/null @@ -1,132 +0,0 @@ - - diff --git a/plugins/pencilblue/templates/angular/admin/sites/manage_sites.html b/plugins/pencilblue/templates/angular/admin/sites/manage_sites.html new file mode 100644 index 000000000..37a4f728b --- /dev/null +++ b/plugins/pencilblue/templates/angular/admin/sites/manage_sites.html @@ -0,0 +1,132 @@ + + diff --git a/public/localization/en-us.js b/public/localization/en-us.js index 03138eefc..8de4a8855 100755 --- a/public/localization/en-us.js +++ b/public/localization/en-us.js @@ -430,7 +430,7 @@ var loc = }, sites: { EXISTING_HOSTNAME: 'That hostname is already in use', - EXISTING_DISPLAYNAME: 'There is already a site with that display name', + EXISTING_DISPLAYNAME: 'There is already a site with this displayname', SITE_CREATED: 'The site was successfully created', ERROR_ACTIVATING: 'There was an error activating', ERROR_DEACTIVATING: 'There was an error deactivating', From 654c9a4f04acae543c629d74aa512405bbf8aa06 Mon Sep 17 00:00:00 2001 From: iandtrapp Date: Fri, 12 Jun 2015 12:24:35 -0400 Subject: [PATCH 318/790] Fixed localization issue --- public/localization/en-us.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/localization/en-us.js b/public/localization/en-us.js index 8de4a8855..ffa7f3a77 100755 --- a/public/localization/en-us.js +++ b/public/localization/en-us.js @@ -430,7 +430,7 @@ var loc = }, sites: { EXISTING_HOSTNAME: 'That hostname is already in use', - EXISTING_DISPLAYNAME: 'There is already a site with this displayname', + EXISTING_DISPLAYNAME: 'There is already a site with that displayname', SITE_CREATED: 'The site was successfully created', ERROR_ACTIVATING: 'There was an error activating', ERROR_DEACTIVATING: 'There was an error deactivating', From f915ffcde3aabc6f3607189dda47b38a2934417e Mon Sep 17 00:00:00 2001 From: iandtrapp Date: Fri, 12 Jun 2015 13:19:24 -0400 Subject: [PATCH 319/790] Changed /admin/site to /admin/sites --- plugins/pencilblue/controllers/admin/sites/manage_sites.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/pencilblue/controllers/admin/sites/manage_sites.js b/plugins/pencilblue/controllers/admin/sites/manage_sites.js index b01569918..4272c4e10 100644 --- a/plugins/pencilblue/controllers/admin/sites/manage_sites.js +++ b/plugins/pencilblue/controllers/admin/sites/manage_sites.js @@ -29,7 +29,7 @@ module.exports = function(pb) { name: 'manage_sites', title: ls.get('MANAGE_SITES'), icon: 'refresh', - href: '/admin/site' + href: '/admin/sites' }, { name: 'new_site', title: '', From 6dc39e61c79da57d90011b199cc8ee7557e0c041 Mon Sep 17 00:00:00 2001 From: btidwell Date: Fri, 12 Jun 2015 13:36:15 -0400 Subject: [PATCH 320/790] Remove site value from angular objects in article_form controller. --- .../controllers/admin/content/articles/article_form.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/plugins/pencilblue/controllers/admin/content/articles/article_form.js b/plugins/pencilblue/controllers/admin/content/articles/article_form.js index 99ced7609..edebd2d3a 100755 --- a/plugins/pencilblue/controllers/admin/content/articles/article_form.js +++ b/plugins/pencilblue/controllers/admin/content/articles/article_form.js @@ -136,8 +136,7 @@ module.exports = function(pb) { topics: data.topics, media: data.media, article: data.article, - siteKey: pb.SiteService.SITE_FIELD, - site: self.site + siteKey: pb.SiteService.SITE_FIELD }; if(data.availableAuthors) { objects.availableAuthors = data.availableAuthors; From 715f6cf5f8789a6ac146acba6b6f71808afb9eb1 Mon Sep 17 00:00:00 2001 From: btidwell Date: Fri, 12 Jun 2015 13:37:52 -0400 Subject: [PATCH 321/790] Revert "Remove site value from angular objects in article_form controller." This reverts commit 6dc39e61c79da57d90011b199cc8ee7557e0c041. --- .../controllers/admin/content/articles/article_form.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/pencilblue/controllers/admin/content/articles/article_form.js b/plugins/pencilblue/controllers/admin/content/articles/article_form.js index edebd2d3a..99ced7609 100755 --- a/plugins/pencilblue/controllers/admin/content/articles/article_form.js +++ b/plugins/pencilblue/controllers/admin/content/articles/article_form.js @@ -136,7 +136,8 @@ module.exports = function(pb) { topics: data.topics, media: data.media, article: data.article, - siteKey: pb.SiteService.SITE_FIELD + siteKey: pb.SiteService.SITE_FIELD, + site: self.site }; if(data.availableAuthors) { objects.availableAuthors = data.availableAuthors; From 3040f074b763730b3f75e456976a1696db6db6c0 Mon Sep 17 00:00:00 2001 From: andparker Date: Fri, 12 Jun 2015 17:07:21 -0400 Subject: [PATCH 322/790] Email and user hostname refactor and bug fixes --- include/config.js | 4 +- include/email.js | 13 ++--- include/requirements.js | 1 - .../service/admin/admin_redirect_service.js | 40 --------------- include/service/entities/site_service.js | 9 ++-- include/service/entities/user_service.js | 11 ++-- .../actions/admin/users/edit_user.js | 4 +- .../actions/admin/users/new_user.js | 9 ++-- .../controllers/actions/forgot_password.js | 13 ++--- .../pencilblue/controllers/actions/login.js | 4 +- .../controllers/actions/user/sign_up.js | 27 ++++------ .../controllers/actions/user/verify_email.js | 10 ++-- plugins/pencilblue/controllers/admin/login.js | 4 +- .../controllers/admin/site_settings/email.js | 51 +++---------------- .../admin/users/change_password.js | 8 ++- .../controllers/admin/users/manage_users.js | 13 +++-- .../controllers/admin/users/permissions.js | 9 ++-- .../admin/users/unverified_users.js | 11 ++-- .../controllers/admin/users/user_form.js | 27 ++++------ .../admin/site_settings/email/send_test.js | 2 +- .../controllers/api/comments/new_comment.js | 5 +- .../api/user/get_username_available.js | 3 +- plugins/pencilblue/controllers/index.js | 4 +- .../controllers/user/change_password.js | 12 +---- .../controllers/user/manage_account.js | 12 +---- .../angular/admin/site_settings/email.html | 4 +- .../angular/admin/users/change_password.html | 2 +- .../angular/admin/users/manage_users.html | 2 +- .../angular/admin/users/user_form.html | 4 +- .../templates/user/resend_verification.html | 6 +-- .../templates/user/verification_sent.html | 2 +- .../wp_import/controllers/manage_new_users.js | 2 +- 32 files changed, 103 insertions(+), 225 deletions(-) delete mode 100644 include/service/admin/admin_redirect_service.js diff --git a/include/config.js b/include/config.js index 5202a1bad..8051d8181 100755 --- a/include/config.js +++ b/include/config.js @@ -193,12 +193,12 @@ var BASE_CONFIG = { //user { collection: 'user', - spec: {username: ASC}, + spec: {username: ASC, site: ASC}, options: {unique: true} }, { collection: 'user', - spec: {email: ASC}, + spec: {email: ASC, site: ASC}, options: {unique: true} }, { diff --git a/include/email.js b/include/email.js index 1e9c9cefd..0159b1fe7 100755 --- a/include/email.js +++ b/include/email.js @@ -28,12 +28,9 @@ module.exports = function EmailServiceModule(pb) { * @class EmailService * @constructor */ - function EmailService(siteUID) { - if(pb.config.multisite && siteUID) { - this.site = siteUID; - } else { - this.site = pb.SiteService.GLOBAL_SITE; - } + function EmailService(siteUid) { + + this.site = pb.SiteService.getCurrentSite(siteUid); } /** @@ -67,7 +64,7 @@ module.exports = function EmailServiceModule(pb) { */ EmailService.prototype.sendFromTemplate = function(options, cb){ var self = this; - var ts = new pb.TemplateService(null, this.site); + var ts = new pb.TemplateService({ site: this.site }); if (options.replacements) { for(var key in options.replacements) { ts.registerLocal(key, options.replacements[key]); @@ -161,7 +158,7 @@ module.exports = function EmailServiceModule(pb) { */ EmailService.prototype.getSettings = function(cb) { var self = this; - var settingsService = pb.SettingServiceFactory.getServiceBySite(pb.SiteService.getCurrentSite(self.site), true); + var settingsService = pb.SettingServiceFactory.getServiceBySite(self.site); settingsService.get('email_settings', function(err, settings) { cb(err, util.isError(err) || !settings ? EmailService.getDefaultSettings() : settings); }); diff --git a/include/requirements.js b/include/requirements.js index 59f77e11a..ba6cf30b1 100755 --- a/include/requirements.js +++ b/include/requirements.js @@ -195,7 +195,6 @@ module.exports = function PB(config) { }); pb.AdminNavigation = require(path.join(config.docRoot, '/include/admin_navigation'))(pb); // Admin Navigation pb.AdminSubnavService = require(path.join(config.docRoot, '/include/service/admin/admin_subnav_service.js'))(pb); - pb.AdminRedirectService = require(path.join(config.docRoot, '/include/service/admin/admin_redirect_service'))(pb); pb.AnalyticsManager = require(path.join(config.docRoot, '/include/system/analytics_manager.js'))(pb); pb.UrlService = require(path.join(config.docRoot, '/include/service/entities/url_service.js'))(pb); pb.CallHomeService = require(path.join(config.docRoot, '/include/system/call_home_service.js'))(pb); diff --git a/include/service/admin/admin_redirect_service.js b/include/service/admin/admin_redirect_service.js deleted file mode 100644 index df147b994..000000000 --- a/include/service/admin/admin_redirect_service.js +++ /dev/null @@ -1,40 +0,0 @@ -/* - Copyright (C) 2015 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 - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . - */ - -module.exports = function AdminRedirectServiceModule(pb) { - "use strict"; - - function AdminRedirectService() { - } - - /** - * Redirect admin user after logging in - * - * @param controller - * @param user - * @param cb - */ - AdminRedirectService.redirectAdminUser = function (controller, user, cb) { - var location = '/admin'; - var site = pb.SiteService.getSiteFromObject(user); - var siteId = pb.SiteService.getCurrentSite(site); - location += pb.SiteService.getCurrentSitePrefix(siteId); - controller.redirect(location, cb); - }; - - return AdminRedirectService; -}; \ No newline at end of file diff --git a/include/service/entities/site_service.js b/include/service/entities/site_service.js index ace6d89ab..dbe79025f 100644 --- a/include/service/entities/site_service.js +++ b/include/service/entities/site_service.js @@ -1,4 +1,5 @@ var async = require('async'); +var url = require('url'); var util = require('../../util.js'); module.exports = function SiteServiceModule(pb) { @@ -371,9 +372,11 @@ module.exports = function SiteServiceModule(pb) { return object[SiteService.SITE_FIELD]; }; - SiteService.getSiteProtocol = function(hostname) { - var protocol = pb.config.server.ssl.enabled ? 'https://' : 'http://'; - return hostname.indexOf('http') > 0 ? hostname : protocol + hostname; + SiteService.getHostWithProtocol = function(hostname) { + hostname = hostname.match(/^http/g) ? hostname : "//" + hostname; + var urlObject = url.parse(hostname, false, true); + urlObject.protocol = pb.config.server.ssl.enabled ? 'https' : 'http'; + return url.format(urlObject); }; return SiteService; diff --git a/include/service/entities/user_service.js b/include/service/entities/user_service.js index 8ca788912..27d510b2f 100755 --- a/include/service/entities/user_service.js +++ b/include/service/entities/user_service.js @@ -138,11 +138,12 @@ module.exports = function UserServiceModule(pb) { * @param {Object} ls The localization object * @param {String} siteUid */ - UserService.prototype.getAdminOptions = function (session, ls, siteUid) { + UserService.prototype.getAdminOptions = function (session, ls) { var adminOptions = []; - if (!pb.SiteService.isGlobal(siteUid)) { - adminOptions = [{name: ls.get('READER'), value: pb.SecurityService.ACCESS_USER}, + if (!pb.SiteService.isGlobal(this.context.site)) { + adminOptions = [ + {name: ls.get('READER'), value: pb.SecurityService.ACCESS_USER}, {name: ls.get('WRITER'), value: pb.SecurityService.ACCESS_WRITER}, {name: ls.get('EDITOR'), value: pb.SecurityService.ACCESS_EDITOR}] } @@ -237,7 +238,7 @@ module.exports = function UserServiceModule(pb) { var siteService = new pb.SiteService(); siteService.getByUid(self.context.site, function(err, siteInfo) { // We need to see if email settings have been saved with verification content - var emailService = new pb.EmailService(this.site); + var emailService = new pb.EmailService(self.context.site); emailService.getSettings(function (err, emailSettings) { var options = { to: user.email, @@ -275,7 +276,7 @@ module.exports = function UserServiceModule(pb) { var siteService = new pb.SiteService(); siteService.getByUid(self.context.site, function(err, siteInfo) { - var root = pb.SiteService.getSiteProtocol(siteInfo.hostname); + var root = pb.SiteService.getHostWithProtocol(siteInfo.hostname); var verficationUrl = pb.UrlService.urlJoin(root, '/actions/user/reset_password') + util.format('?email=%s&code=%s', encodeURIComponent(user.email), encodeURIComponent(passwordReset.verification_code)); var options = { diff --git a/plugins/pencilblue/controllers/actions/admin/users/edit_user.js b/plugins/pencilblue/controllers/actions/admin/users/edit_user.js index 52372b389..6c9ad68f7 100755 --- a/plugins/pencilblue/controllers/actions/admin/users/edit_user.js +++ b/plugins/pencilblue/controllers/actions/admin/users/edit_user.js @@ -29,6 +29,7 @@ module.exports = function(pb) { EditUser.prototype.render = function(cb) { var self = this; var vars = this.pathVars; + var userService = new pb.UserService(self.getServiceContext()); this.getJSONPostParams(function(err, post) { var message = self.hasRequiredParams(post, self.getRequiredFields()); @@ -61,7 +62,6 @@ module.exports = function(pb) { delete post[pb.DAO.getIdField()]; pb.DocumentCreator.update(post, user); - var userService = new UserService(self.pathSiteUId); userService.isUserNameOrEmailTaken(user.username, user.email, vars.id, function(err, isTaken) { if(util.isError(err) || isTaken) { if(err) { pb.log.error(JSON.stringify(err)); } @@ -81,7 +81,7 @@ module.exports = function(pb) { return; } - cb({content: pb.BaseController.apiResponse(pb.BaseController.API_SUCCESS, self.ls.get('USER_EDITED'))}); + cb({content: pb.BaseController.apiResponse(pb.BaseController.API_SUCCESS, self.ls.get('USER_EDITED'), result)}); }); }); }); diff --git a/plugins/pencilblue/controllers/actions/admin/users/new_user.js b/plugins/pencilblue/controllers/actions/admin/users/new_user.js index 8e9e0cc77..cc339586e 100755 --- a/plugins/pencilblue/controllers/actions/admin/users/new_user.js +++ b/plugins/pencilblue/controllers/actions/admin/users/new_user.js @@ -47,7 +47,7 @@ module.exports = function(pb) { return; } - post.site = pb.users.determineUserSiteScope(post.admin, self.pathSiteUId); + post.site = pb.users.determineUserSiteScope(post.admin, self.site); if (!post.site) { cb({ code: 400, @@ -57,7 +57,7 @@ module.exports = function(pb) { } var user = pb.DocumentCreator.create('user', post); - var userService = new pb.UserService(self.pathSiteUId); + var userService = new pb.UserService(self.getServiceContext()); userService.isUserNameOrEmailTaken(user.username, user.email, post.id, function(err, isTaken) { if(util.isError(err) || isTaken) { cb({ @@ -67,9 +67,8 @@ module.exports = function(pb) { return; } - var site = self.pathSiteUId || self.site; - var sqs = new pb.SiteQueryService(site); - sqs.save(user, function(err, result) { + var dao = new pb.SiteQueryService(self.site); + dao.save(user, function(err, result) { if(util.isError(err)) { cb({ code: 500, diff --git a/plugins/pencilblue/controllers/actions/forgot_password.js b/plugins/pencilblue/controllers/actions/forgot_password.js index 0b217f96d..89a68d9c4 100755 --- a/plugins/pencilblue/controllers/actions/forgot_password.js +++ b/plugins/pencilblue/controllers/actions/forgot_password.js @@ -27,12 +27,6 @@ module.exports = function ForgotPasswordControllerModule(pb) { function ForgotPasswordController(){} util.inherits(ForgotPasswordController, pb.FormController); - - ForgotPasswordController.prototype.init = function(context, cb) { - ForgotPasswordController.super_.prototype.init.apply(this, [context, init]); - }; - - /** * * @method onPostParamsRetrieved @@ -63,14 +57,15 @@ module.exports = function ForgotPasswordControllerModule(pb) { }; //search for user - var dao = new pb.SiteQueryService(self.context.site, true); + var dao = new pb.SiteQueryService(self.site, true); dao.loadByValues(query, 'user', function(err, user) { if(util.isError(err) || user === null) { return self.formError(self.ls.get('NOT_REGISTERED'), returnURL, cb); } //verify that an email server was setup - pb.settings.get('email_settings', function(err, emailSettings) { + var settings = pb.SettingServiceFactory.getServiceBySite(self.site); + settings.get('email_settings', function(err, emailSettings) { if (util.isError(err)) { return self.formError(err.message, returnURL, cb); } @@ -100,7 +95,7 @@ module.exports = function ForgotPasswordControllerModule(pb) { self.session.success = self.ls.get('YOUR_PASSWORD_RESET'); self.redirect(returnURL, cb); - var userService = new pb.UserService(self.context); + var userService = new pb.UserService(self.getServiceContext()); userService.sendPasswordResetEmail(user, passwordReset, util.cb); }); }); diff --git a/plugins/pencilblue/controllers/actions/login.js b/plugins/pencilblue/controllers/actions/login.js index 46463655c..5a04e3b75 100755 --- a/plugins/pencilblue/controllers/actions/login.js +++ b/plugins/pencilblue/controllers/actions/login.js @@ -55,11 +55,11 @@ module.exports = function LoginActionControllerModule(pb) { if (self.session.on_login !== undefined) { location = self.session.on_login; delete self.session.on_login; - self.redirect(location, cb); } else if(adminAttempt) { - pb.AdminRedirectService.redirectAdminUser(self, user, cb); + location = '/admin'; } + self.redirect(location, cb); }); }; diff --git a/plugins/pencilblue/controllers/actions/user/sign_up.js b/plugins/pencilblue/controllers/actions/user/sign_up.js index a14303f9a..df4c270f7 100755 --- a/plugins/pencilblue/controllers/actions/user/sign_up.js +++ b/plugins/pencilblue/controllers/actions/user/sign_up.js @@ -31,16 +31,6 @@ module.exports = function SignUpModule(pb) { function SignUp(){} util.inherits(SignUp, FormController); - SignUp.prototype.init = function (props, cb) { - var self = this; - - pb.BaseController.prototype.init.call(self, props, function () { - self.siteQueryService = new pb.SiteQueryService(self.site, true); - cb(); - }); - }; - - SignUp.prototype.onPostParamsRetrieved = function(post, cb) { var self = this; @@ -83,7 +73,7 @@ module.exports = function SignUpModule(pb) { //check for validation failures var errMsg = null; if (results.verified_username > 0 || results.unverified_username > 0) { - errMsg = self.ls.get('EXISTING_EMAIL'); + errMsg = self.ls.get('EXISTING_USERNAME'); } else if (results.verified_email > 0 || results.unverified_email > 0) { errMsg = self.ls.get('EXISTING_EMAIL'); @@ -99,7 +89,8 @@ module.exports = function SignUpModule(pb) { return; } - self.siteQueryService.save(user, function(err, data) { + var dao = new pb.SiteQueryService(self.site); + dao.save(user, function(err, data) { if(util.isError(err)) { return self.formError(self.ls.get('ERROR_SAVING'), '/user/sign_up', cb); } @@ -109,7 +100,7 @@ module.exports = function SignUpModule(pb) { //send email for verification when required if (contentSettings.require_verification) { - var userService = new pb.UserService(self.site); + var userService = new pb.UserService(self.getServiceContext()); userService.sendVerificationEmail(user, util.cb); } }); @@ -122,19 +113,19 @@ module.exports = function SignUpModule(pb) { }; SignUp.prototype.validateUniques = function(user, cb) { - var self = this; + var dao = new pb.SiteQueryService(this.site); var tasks = { verified_username: function(callback) { - self.siteQueryService.count('user', {username: user.username}, callback); + dao.count('user', {username: user.username}, callback); }, verified_email: function(callback) { - self.siteQueryService.count('user', {email: user.email}, callback); + dao.count('user', {email: user.email}, callback); }, unverified_username: function(callback) { - self.siteQueryService.count('unverified_user', {username: user.username}, callback); + dao.count('unverified_user', {username: user.username}, callback); }, unverified_email: function(callback) { - self.siteQueryService.count('unverified_user', {email: user.email}, callback); + dao.count('unverified_user', {email: user.email}, callback); } }; async.series(tasks, cb); diff --git a/plugins/pencilblue/controllers/actions/user/verify_email.js b/plugins/pencilblue/controllers/actions/user/verify_email.js index e08c80c1d..fcdb65811 100755 --- a/plugins/pencilblue/controllers/actions/user/verify_email.js +++ b/plugins/pencilblue/controllers/actions/user/verify_email.js @@ -35,14 +35,14 @@ module.exports = function VerifyEmailModule(pb) { return; } - var siteQueryService = new pb.SiteQueryService(self.site, true); - siteQueryService.count('user', {email: get.email}, function(err, count) { + var dao = new pb.SiteQueryService(self.site, true); + dao.count('user', {email: get.email}, function(err, count) { if(count > 0) { self.formError(self.ls.get('USER_VERIFIED'), '/user/login', cb); return; } - siteQueryService.loadByValue('email', get.email, 'unverified_user', function(err, unverifiedUser) { + dao.loadByValue('email', get.email, 'unverified_user', function(err, unverifiedUser) { if(unverifiedUser === null) { self.formError(self.ls.get('NOT_REGISTERED'), '/user/sign_up', cb); return; @@ -53,7 +53,7 @@ module.exports = function VerifyEmailModule(pb) { return; } - siteQueryService.deleteById(unverifiedUser[pb.DAO.getIdField()], 'unverified_user', function(err, result) { + dao.deleteById(unverifiedUser[pb.DAO.getIdField()], 'unverified_user', function(err, result) { //TODO handle error //convert to user @@ -61,7 +61,7 @@ module.exports = function VerifyEmailModule(pb) { delete user[pb.DAO.getIdField()]; user.object_type = 'user'; - siteQueryService.save(user, function(err, result) { + dao.save(user, function(err, result) { if(util.isError(err)) { return self.formError(self.ls.get('ERROR_SAVING'), '/user/sign_up', cb); } diff --git a/plugins/pencilblue/controllers/admin/login.js b/plugins/pencilblue/controllers/admin/login.js index f452e3864..37c78dea3 100755 --- a/plugins/pencilblue/controllers/admin/login.js +++ b/plugins/pencilblue/controllers/admin/login.js @@ -35,10 +35,10 @@ module.exports = function LoginViewControllerModule(pb) { * @method render */ LoginViewController.prototype.render = function(cb) { - var self = this; + if(pb.security.isAuthorized(this.session, {authenticated: true, admin_level: pb.SecurityService.ACCESS_WRITER})) { - pb.AdminRedirectService.redirectAdminUser(self, self.session.authentication.user, cb); + this.redirect('/admin', cb); return; } else if(pb.security.isAuthenticated(this.session)) { diff --git a/plugins/pencilblue/controllers/admin/site_settings/email.js b/plugins/pencilblue/controllers/admin/site_settings/email.js index 5f5a37070..e02c05ecc 100755 --- a/plugins/pencilblue/controllers/admin/site_settings/email.js +++ b/plugins/pencilblue/controllers/admin/site_settings/email.js @@ -30,36 +30,6 @@ module.exports = function(pb) { //statics var SUB_NAV_KEY = 'site_email_settings'; - - /** - * - * @method render - * - */ - Email.prototype.init = function(props, cb) { - var self = this; - - pb.BaseController.prototype.init.call(this, props, function() { - self.pathSiteUId = SiteService.getCurrentSite(self.pathVars.siteid); - SiteService.siteExists(self.pathSiteUId, function (err, exists) { - if (!exists) { - self.reqHandler.serve404(); - } - else { - self.sitePrefix = SiteService.getCurrentSitePrefix(self.pathSiteUId); - cb(); - } - }); - }); - }; - - /** - * - * @method render - * @param site - * @param cb - * - */ Email.prototype.render = function(cb) { var self = this; var tabs = @@ -82,14 +52,13 @@ module.exports = function(pb) { } ]; - var emailService = new pb.EmailService(self.pathVars.siteid); + var emailService = new pb.EmailService(this.site); emailService.getSettings(function(err, emailSettings) { var angularObjects = pb.ClientJs.getAngularObjects({ navigation: pb.AdminNavigation.get(self.session, ['settings', 'site_settings'], self.ls), - pills: pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, 'email', { sitePrefix: self.sitePrefix }), + pills: pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, 'email', { site: self.site }), tabs: tabs, - emailSettings: emailSettings, - sitePrefix: self.sitePrefix + emailSettings: emailSettings }); self.setPageName(self.ls.get('EMAIL')); @@ -101,21 +70,17 @@ module.exports = function(pb) { }; Email.getSubNavItems = function(key, ls, data) { - var prefix = '/admin'; - if(data && data.sitePrefix) { - prefix += data.sitePrefix; - } var pills = [{ name: 'configuration', title: ls.get('EMAIL'), icon: 'chevron-left', - href: prefix + '/site_settings' + href: '/admin/site_settings' }, { name: 'content', title: ls.get('CONTENT'), icon: 'quote-right', - href: prefix + '/site_settings/content' + href: '/admin/site_settings/content' }]; if(data && data.site === SiteService.GLOBAL_SITE) { @@ -123,14 +88,10 @@ module.exports = function(pb) { name: 'libraries', title: ls.get('LIBRARIES'), icon: 'book', - href: prefix + '/site_settings/libraries' + href: '/admin/site_settings/libraries' }); } - if(data && data.siteName) { - return pb.AdminSubnavService.addSiteToPills(pills, data.siteName); - } - return pills; }; diff --git a/plugins/pencilblue/controllers/admin/users/change_password.js b/plugins/pencilblue/controllers/admin/users/change_password.js index fe3d12ad3..1851172b4 100755 --- a/plugins/pencilblue/controllers/admin/users/change_password.js +++ b/plugins/pencilblue/controllers/admin/users/change_password.js @@ -62,9 +62,8 @@ module.exports = function AdminChangePasswordControllerModule(pb) { navigation: pb.AdminNavigation.get(self.session, ['users'], self.ls), pills: pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, SUB_NAV_KEY, user), tabs: tabs, - adminOptions: pb.users.getAdminOptions(self.session, self.localizationService, self.pathSiteUId), - user: user, - sitePrefix: self.sitePrefix + adminOptions: pb.users.getAdminOptions(self.session, self.localizationService), + user: user }); delete user.password; @@ -77,13 +76,12 @@ module.exports = function AdminChangePasswordControllerModule(pb) { }; AdminChangePasswordController.getSubNavItems = function(key, ls, data) { - var sitePrefix = pb.SiteService.getCurrentSitePrefix(pb.SiteService.getCurrentSite(data.site)); return [ { name: SUB_NAV_KEY, title: ls.get('CHANGE_PASSWORD'), icon: 'chevron-left', - href: pb.UrlService.urlJoin('/admin' + sitePrefix + '/users/', encodeURIComponent(data[pb.DAO.getIdField()])) + href: pb.UrlService.urlJoin('/admin/users/', + encodeURIComponent(data[pb.DAO.getIdField()])) } ]; }; diff --git a/plugins/pencilblue/controllers/admin/users/manage_users.js b/plugins/pencilblue/controllers/admin/users/manage_users.js index be693c4e0..53b53ef84 100755 --- a/plugins/pencilblue/controllers/admin/users/manage_users.js +++ b/plugins/pencilblue/controllers/admin/users/manage_users.js @@ -44,15 +44,14 @@ module.exports = function(pb) { return self.reqHandler.serveError(err); } else if (users.length === 0) { - return self.redirect('/admin' + self.sitePrefix + '/users/new', cb); + return self.redirect('/admin/users/new', cb); } var angularObjects = pb.ClientJs.getAngularObjects({ navigation: pb.AdminNavigation.get(self.session, ['users', 'manage'], self.ls), - pills: pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, SUB_NAV_KEY, { sitePrefix: self.sitePrefix }), + pills: pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, SUB_NAV_KEY), users: users, - currentUserId: self.session.authentication.user_id, - sitePrefix: self.sitePrefix + currentUserId: self.session.authentication.user_id }); self.setPageName(self.ls.get('MANAGE_USERS')); @@ -68,17 +67,17 @@ module.exports = function(pb) { name: 'manage_users', title: ls.get('MANAGE_USERS'), icon: 'refresh', - href: '/admin' + data.sitePrefix + '/users' + href: '/admin/users' }, { name: 'unverified_users', title: ls.get('UNVERIFIED_USERS'), icon: 'user', - href: '/admin' + data.sitePrefix + '/users/unverified' + href: '/admin/users/unverified' }, { name: 'new_user', title: '', icon: 'plus', - href: '/admin' + data.sitePrefix + '/users/new' + href: '/admin/users/new' }]; }; diff --git a/plugins/pencilblue/controllers/admin/users/permissions.js b/plugins/pencilblue/controllers/admin/users/permissions.js index d2c797f1c..666b5db37 100755 --- a/plugins/pencilblue/controllers/admin/users/permissions.js +++ b/plugins/pencilblue/controllers/admin/users/permissions.js @@ -19,13 +19,13 @@ module.exports = function(pb) { //pb dependencies var util = pb.util; - var BaseAdminController = pb.BaseAdminController; + var BaseController = pb.BaseController; /** * Interface for displaying how a plugin's user permissions are organized */ function PermissionsMapController(){} - util.inherits(PermissionsMapController, BaseAdminController); + util.inherits(PermissionsMapController, BaseController); PermissionsMapController.prototype.render = function(cb) { var self = this; @@ -65,12 +65,12 @@ module.exports = function(pb) { name: 'permissions', title: self.ls.get('PERMISSIONS'), icon: 'refresh', - href: '/admin' + self.sitePrefix + '/users/permissions' + href: '/admin/users/permissions' }, { name: 'manage_plugins', title: self.ls.get('MANAGE_PLUGINS'), icon: 'puzzle-piece', - href: '/admin' + self.sitePrefix + '/plugins' + href: '/admin/plugins' }]; var angularObjects = pb.ClientJs.getAngularObjects({ @@ -78,7 +78,6 @@ module.exports = function(pb) { pills: pills, roles: roleDNs, permissions: permissions, - sitePrefix: self.sitePrefix }); //render page diff --git a/plugins/pencilblue/controllers/admin/users/unverified_users.js b/plugins/pencilblue/controllers/admin/users/unverified_users.js index 37a27e4e0..9eadadf1c 100644 --- a/plugins/pencilblue/controllers/admin/users/unverified_users.js +++ b/plugins/pencilblue/controllers/admin/users/unverified_users.js @@ -38,15 +38,14 @@ module.exports = function(pb) { self.siteQueryService.q('unverified_user', opts, function(err, users) { if(util.isError(err)) { - return self.redirect('/admin' + self.sitePrefix, cb); + return self.redirect('/admin', cb); } var angularObjects = pb.ClientJs.getAngularObjects( { navigation: pb.AdminNavigation.get(self.session, ['users', 'manage'], self.ls), - pills: pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, SUB_NAV_KEY, { sitePrefix: self.sitePrefix }), - users: users, - sitePrefix: self.sitePrefix + pills: pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, SUB_NAV_KEY), + users: users }); self.setPageName(self.ls.get('UNVERIFIED_USERS')); @@ -62,12 +61,12 @@ module.exports = function(pb) { name: SUB_NAV_KEY, title: ls.get('UNVERIFIED_USERS'), icon: 'chevron-left', - href: '/admin' + data.sitePrefix + '/users' + href: '/admin/users' }, { name: 'new_user', title: '', icon: 'plus', - href: '/admin' + data.sitePrefix + '/users/new' + href: '/admin/users/new' }]; }; diff --git a/plugins/pencilblue/controllers/admin/users/user_form.js b/plugins/pencilblue/controllers/admin/users/user_form.js index bbc23e363..39eecaa1d 100644 --- a/plugins/pencilblue/controllers/admin/users/user_form.js +++ b/plugins/pencilblue/controllers/admin/users/user_form.js @@ -46,19 +46,14 @@ module.exports = function(pb) { } self.user = data.user; - data.pills = pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, SUB_NAV_KEY, { - session: self.session, - user: self.user, - site: self.pathSiteUId, - sitePrefix: self.sitePrefix - }); + data.pills = pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, SUB_NAV_KEY, {session: self.session, user: self.user}); data.adminOptions = [{name: self.ls.get('ADMINISTRATOR'), value: pb.SecurityService.ACCESS_ADMINISTRATOR}]; if(!data.user[pb.DAO.getIdField()] || self.session.authentication.user_id !== data.user[pb.DAO.getIdField()].toString()) { - data.adminOptions = pb.users.getAdminOptions(self.session, self.localizationService, self.pathSiteUId); + var userService = new pb.UserService(self.getServiceContext()); + data.adminOptions = userService.getAdminOptions(self.session, self.localizationService); } - data.sitePrefix = self.sitePrefix; var angularObjects = pb.ClientJs.getAngularObjects(data); self.setPageName(data.user[pb.DAO.getIdField()] ? data.user.username : self.ls.get('NEW_USER')); @@ -107,22 +102,20 @@ module.exports = function(pb) { }; UserForm.getSubNavItems = function(key, ls, data) { - var idField = pb.DAO.getIdField(); var pills = [{ name: 'manage_users', - title: data.user[idField] ? ls.get('EDIT') + ' ' + data.user.username : ls.get('NEW_USER'), + title: data.user[pb.DAO.getIdField()] ? ls.get('EDIT') + ' ' + data.user.username : ls.get('NEW_USER'), icon: 'chevron-left', - href: '/admin' + data.sitePrefix + '/users' + href: '/admin/users' }]; - if(data.user[idField]) { - var userIdString = data.user[idField].toString(); - if(data.session.authentication.user_id === userIdString) { + if(data.user[pb.DAO.getIdField()]) { + if(data.session.authentication.user_id === data.user[pb.DAO.getIdField()].toString()) { pills.push({ name: 'change_password', title: ls.get('CHANGE_PASSWORD'), icon: 'key', - href: '/admin' + data.sitePrefix + '/users/password/' + userIdString + href: '/admin/users/password/' + data.user[pb.DAO.getIdField()].toString() }); } else if(data.session.authentication.admin_level >= pb.SecurityService.ACCESS_MANAGING_EDITOR) { @@ -130,7 +123,7 @@ module.exports = function(pb) { name: 'reset_password', title: ls.get('RESET_PASSWORD'), icon: 'key', - href: '/actions/admin' + data.sitePrefix + '/users/send_password_reset/' + userIdString + href: '/actions/admin/users/send_password_reset/' + data.user[pb.DAO.getIdField()].toString() }); } } @@ -139,7 +132,7 @@ module.exports = function(pb) { name: 'new_user', title: '', icon: 'plus', - href: '/admin' + data.sitePrefix + '/users/new' + href: '/admin/users/new' }); return pills; diff --git a/plugins/pencilblue/controllers/api/admin/site_settings/email/send_test.js b/plugins/pencilblue/controllers/api/admin/site_settings/email/send_test.js index e2ba56f54..767036149 100644 --- a/plugins/pencilblue/controllers/api/admin/site_settings/email/send_test.js +++ b/plugins/pencilblue/controllers/api/admin/site_settings/email/send_test.js @@ -43,7 +43,7 @@ module.exports = function(pb) { subject: 'Test email from PencilBlue', layout: 'This is a successful test email from the PencilBlue system.' }; - var emailService = new pb.EmailService(pb.SiteService.getCurrentSite(self.pathVars.siteid)); + var emailService = new pb.EmailService(this.site); emailService.sendFromLayout(options, function(err, response) { if(err) { return cb({ diff --git a/plugins/pencilblue/controllers/api/comments/new_comment.js b/plugins/pencilblue/controllers/api/comments/new_comment.js index 5e7fd3d27..239356e7d 100755 --- a/plugins/pencilblue/controllers/api/comments/new_comment.js +++ b/plugins/pencilblue/controllers/api/comments/new_comment.js @@ -30,15 +30,14 @@ module.exports = function NewCommentModule(pb) { NewComment.prototype.init = function (props, cb) { var self = this; pb.BaseController.prototype.init.call(self, props, function () { - self.siteUId = pb.SiteService.getCurrentSite(self.site); - self.siteQueryService = new pb.SiteQueryService(self.siteUId); + self.siteQueryService = new pb.SiteQueryService(self.site, true); cb(); }); }; NewComment.prototype.onPostParamsRetrieved = function(post, cb) { var self = this; - var contentService = new pb.ContentService(self.site); + var contentService = new pb.ContentService(self.site, true); contentService.getSettings(function(err, contentSettings) { if(!contentSettings.allow_comments) { cb({content: BaseController.apiResponse(BaseController.API_FAILURE, 'commenting not allowed'), code: 400}); diff --git a/plugins/pencilblue/controllers/api/user/get_username_available.js b/plugins/pencilblue/controllers/api/user/get_username_available.js index 5cf70c1a6..87165d36b 100755 --- a/plugins/pencilblue/controllers/api/user/get_username_available.js +++ b/plugins/pencilblue/controllers/api/user/get_username_available.js @@ -35,7 +35,8 @@ module.exports = function UsernameAvailableModule(pb) { return; } - pb.users.isUserNameOrEmailTaken(get.username, '', null, function(error, isTaken) { + this.userService = new pb.UserService(this.getServiceContext()); + this.userService.isUserNameOrEmailTaken(get.username, '', null, function(error, isTaken) { if(isTaken) { cb({content: pb.BaseController.apiResponse(pb.BaseController.API_SUCCESS, get.username + ' is not available', false)}); return; diff --git a/plugins/pencilblue/controllers/index.js b/plugins/pencilblue/controllers/index.js index 481aeeb7f..fedf522e9 100755 --- a/plugins/pencilblue/controllers/index.js +++ b/plugins/pencilblue/controllers/index.js @@ -55,11 +55,11 @@ module.exports = function IndexModule(pb) { var article = self.req.pencilblue_article || null; var page = self.req.pencilblue_page || null; - var contentService = new pb.ContentService(self.site); + var contentService = new pb.ContentService(self.site, true); contentService.getSettings(function(err, contentSettings) { self.gatherData(function(err, data) { - var articleService = new pb.ArticleService(self.site); + var articleService = new pb.ArticleService(self.site, true); articleService.getMetaInfo(data.content[0], function(err, meta) { self.ts.registerLocal('meta_keywords', meta.keywords); self.ts.registerLocal('meta_desc', data.section.description || meta.description); diff --git a/plugins/pencilblue/controllers/user/change_password.js b/plugins/pencilblue/controllers/user/change_password.js index 5dd6ed599..920f9130f 100755 --- a/plugins/pencilblue/controllers/user/change_password.js +++ b/plugins/pencilblue/controllers/user/change_password.js @@ -29,15 +29,6 @@ module.exports = function ChangePasswordFormControllerModule(pb) { function ChangePasswordFormController(){} util.inherits(ChangePasswordFormController, pb.FormController); - ChangePasswordFormController.prototype.init = function (props, cb) { - var self = this; - - pb.BaseController.prototype.init.call(self, props, function () { - self.siteQueryService = new pb.SiteQueryService(self.site, true); - cb(); - }); - }; - /** * * @method render @@ -47,7 +38,8 @@ module.exports = function ChangePasswordFormControllerModule(pb) { var self = this; //retrieve user - self.siteQueryService.loadById(self.session.authentication.user_id, 'user', function(err, user) { + var dao = new pb.SiteQueryService(self.site, true); + dao.loadById(self.session.authentication.user_id, 'user', function(err, user) { if(util.isError(err) || user === null) { self.redirect('/', cb); return; diff --git a/plugins/pencilblue/controllers/user/manage_account.js b/plugins/pencilblue/controllers/user/manage_account.js index a863b25a1..347860fc8 100755 --- a/plugins/pencilblue/controllers/user/manage_account.js +++ b/plugins/pencilblue/controllers/user/manage_account.js @@ -26,19 +26,11 @@ module.exports = function ManageAccountModule(pb) { function ManageAccount(){} util.inherits(ManageAccount, pb.FormController); - ManageAccount.prototype.init = function (props, cb) { - var self = this; - - pb.BaseController.prototype.init.call(self, props, function () { - self.siteQueryService = new pb.SiteQueryService(self.site, true); - cb(); - }); - }; - ManageAccount.prototype.render = function(cb) { var self = this; - self.siteQueryService.loadById(self.session.authentication.user_id, 'user', function(err, user) { + var dao = new pb.SiteQueryService(self.site, true); + dao.loadById(self.session.authentication.user_id, 'user', function(err, user) { if(util.isError(err) || user === null) { if (err) { pb.log.error(err); } self.redirect('/', cb); diff --git a/plugins/pencilblue/templates/angular/admin/site_settings/email.html b/plugins/pencilblue/templates/angular/admin/site_settings/email.html index 8c8c36d17..e2809997d 100644 --- a/plugins/pencilblue/templates/angular/admin/site_settings/email.html +++ b/plugins/pencilblue/templates/angular/admin/site_settings/email.html @@ -19,7 +19,7 @@ $scope.emailTestFailure = null; $scope.sendingEmail = true; - $http.post('/api/admin' + $scope.sitePrefix + '/site_settings/email/send_test', {email: $scope.testEmailAddress}) + $http.post('/api/admin/site_settings/email/send_test', {email: $scope.testEmailAddress}) .success(function(result) { $scope.emailTestSuccess = true; $scope.sendingEmail = false; @@ -37,7 +37,7 @@ getWYSIWYGLayout(wysId, function(layout) { $scope.emailSettings.verification_content = layout; - $http.post('/actions/admin'+ $scope.sitePrefix +'/site_settings/email', $scope.emailSettings) + $http.post('/actions/admin/site_settings/email', $scope.emailSettings) .success(function(result) { $scope.successMessage = result.message; $scope.saving = false; diff --git a/plugins/pencilblue/templates/angular/admin/users/change_password.html b/plugins/pencilblue/templates/angular/admin/users/change_password.html index 6c1072885..15963eb48 100644 --- a/plugins/pencilblue/templates/angular/admin/users/change_password.html +++ b/plugins/pencilblue/templates/angular/admin/users/change_password.html @@ -36,7 +36,7 @@ $scope.saving = true; - $http.post('/actions/admin' + $scope.sitePrefix + '/users/change_password/' + $scope.user._id, $scope.userPassword) + $http.post('/actions/admin/users/change_password/' + $scope.user._id, $scope.userPassword) .success(function(result) { $scope.successMessage = result.message; $scope.saving = false; diff --git a/plugins/pencilblue/templates/angular/admin/users/manage_users.html b/plugins/pencilblue/templates/angular/admin/users/manage_users.html index f4ab0711c..8b48bdb5c 100644 --- a/plugins/pencilblue/templates/angular/admin/users/manage_users.html +++ b/plugins/pencilblue/templates/angular/admin/users/manage_users.html @@ -77,7 +77,7 @@ } $scope.deleting = true; - $http({method: 'DELETE', url: '/actions/admin' + $scope.sitePrefix + '/users/' + $scope.objectToDelete._id}) + $http({method: 'DELETE', url: '/actions/admin/users/' + $scope.objectToDelete._id}) .success(function(result) { for(var i = 0; i < $scope.users.length; i ++) { if($scope.users[i]._id.toString() === $scope.objectToDelete._id.toString()) { diff --git a/plugins/pencilblue/templates/angular/admin/users/user_form.html b/plugins/pencilblue/templates/angular/admin/users/user_form.html index 577194bf4..17f9892ae 100644 --- a/plugins/pencilblue/templates/angular/admin/users/user_form.html +++ b/plugins/pencilblue/templates/angular/admin/users/user_form.html @@ -69,7 +69,7 @@ $scope.user.photo = $scope.photoValue; } - var postURL = '/actions/admin' + $scope.sitePrefix + '/users'; + var postURL = '/actions/admin/users'; if($scope.user._id) { postURL += '/' + $scope.user._id; } @@ -80,7 +80,7 @@ $scope.saving = false; if(result.data._id) { - $window.location = '/admin' + $scope.sitePrefix + '/users/' + result.data._id; + $window.location = '/admin/users/' + result.data._id; } }) .error(function(error, status) { diff --git a/plugins/pencilblue/templates/user/resend_verification.html b/plugins/pencilblue/templates/user/resend_verification.html index f66d554fa..96d98852d 100755 --- a/plugins/pencilblue/templates/user/resend_verification.html +++ b/plugins/pencilblue/templates/user/resend_verification.html @@ -11,7 +11,7 @@
^loc_RESEND_VERIFICATION^
-
+
@@ -23,11 +23,11 @@
- + diff --git a/plugins/pencilblue/templates/user/verification_sent.html b/plugins/pencilblue/templates/user/verification_sent.html index 78981b596..df9e73605 100755 --- a/plugins/pencilblue/templates/user/verification_sent.html +++ b/plugins/pencilblue/templates/user/verification_sent.html @@ -12,7 +12,7 @@

^loc_YOUR_VERIFICATION^

^loc_CHECK_INBOX^

-

^loc_RESEND_VERIFICATION^

+

^loc_RESEND_VERIFICATION^

 ^loc_BACK_HOME^ diff --git a/plugins/wp_import/controllers/manage_new_users.js b/plugins/wp_import/controllers/manage_new_users.js index 846b1f5c0..230ddef1c 100755 --- a/plugins/wp_import/controllers/manage_new_users.js +++ b/plugins/wp_import/controllers/manage_new_users.js @@ -71,7 +71,7 @@ module.exports = function WPManageUsersViewControllerModule(pb) { pills: pills, tabs: tabs, users: self.session.importedUsers, - adminOptions: pb.users.getAdminOptions(self.session, self.localizationService, self.pathSiteUId) + adminOptions: pb.users.getAdminOptions(self.session, self.localizationService) }; this.setPageName(this.ls.get('IMPORT_WORDPRESS')); From e5804799f8f7645a45e2e06ea90134b9339ae551 Mon Sep 17 00:00:00 2001 From: andparker Date: Fri, 12 Jun 2015 17:22:42 -0400 Subject: [PATCH 323/790] Updates the email settings action to respect hostname --- .../controllers/actions/admin/site_settings/email.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/plugins/pencilblue/controllers/actions/admin/site_settings/email.js b/plugins/pencilblue/controllers/actions/admin/site_settings/email.js index 535350d2d..20efeb8fc 100755 --- a/plugins/pencilblue/controllers/actions/admin/site_settings/email.js +++ b/plugins/pencilblue/controllers/actions/admin/site_settings/email.js @@ -18,8 +18,7 @@ module.exports = function(pb) { //pb dependencies - var util = pb.util, - SiteService = pb.SiteService; + var util = pb.util; /** * Saves the site's email settings @@ -31,7 +30,7 @@ module.exports = function(pb) { var self = this; this.getJSONPostParams(function(err, post) { - var settingService = pb.SettingServiceFactory.getServiceBySite(SiteService.getCurrentSite(self.pathVars.siteid), true); + var settingService = pb.SettingServiceFactory.getServiceBySite(self.site, true); settingService.set('email_settings', post, function(data) { if(util.isError(data)) { cb({ From 8265b57d794764a6a653714bef5ee7cc76213774 Mon Sep 17 00:00:00 2001 From: andparker Date: Fri, 12 Jun 2015 17:26:07 -0400 Subject: [PATCH 324/790] Removes site-prefix from user edit href --- plugins/pencilblue/templates/admin/users/manage_users.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/pencilblue/templates/admin/users/manage_users.html b/plugins/pencilblue/templates/admin/users/manage_users.html index bc36f71b9..600f88312 100755 --- a/plugins/pencilblue/templates/admin/users/manage_users.html +++ b/plugins/pencilblue/templates/admin/users/manage_users.html @@ -7,7 +7,7 @@ ^tmp_admin=elements=table_headers^ - + From 1d3b2feb532bcbd883601de68764763484f38738 Mon Sep 17 00:00:00 2001 From: andparker Date: Fri, 12 Jun 2015 17:38:47 -0400 Subject: [PATCH 325/790] Remove unnecessary route changes --- .../include/multisite_admin_routes.js | 105 +----------------- plugins/pencilblue/include/routes.js | 42 +++---- 2 files changed, 23 insertions(+), 124 deletions(-) diff --git a/plugins/pencilblue/include/multisite_admin_routes.js b/plugins/pencilblue/include/multisite_admin_routes.js index dc97238b7..2def89489 100644 --- a/plugins/pencilblue/include/multisite_admin_routes.js +++ b/plugins/pencilblue/include/multisite_admin_routes.js @@ -199,7 +199,7 @@ module.exports = function Routes(pb){ path: "/actions/admin/:siteid/content/articles/:id", access_level: pb.SecurityService.ACCESS_EDITOR, auth_required: true, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'content', 'articles', 'delete_article.js') + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'content', 'articles', 'delete_article.js'), }, // PAGES @@ -592,14 +592,6 @@ module.exports = function Routes(pb){ controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'site_settings', 'email.js'), content_type: 'text/html' }, - { - method: 'post', - path: "/api/admin/:siteid/site_settings/email/send_test", - auth_required: true, - access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'api', 'admin', 'site_settings', 'email', 'send_test.js'), - content_type: 'application/json' - }, { method: 'get', path: "/admin/"+ pb.SiteService.GLOBAL_SITE + "/site_settings/libraries", @@ -608,105 +600,12 @@ module.exports = function Routes(pb){ controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'site_settings', 'libraries.js'), content_type: 'text/html' }, - //USERS - { - method: 'get', - path: "/admin/:siteid/users", - auth_required: true, - access_level: pb.SecurityService.ACCESS_EDITOR, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'users', 'manage_users.js') - }, - { - method: 'get', - path: "/admin/:siteid/users/unverified", - auth_required: true, - access_level: pb.SecurityService.ACCESS_EDITOR, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'users', 'unverified_users.js') - }, - { - method: 'get', - path: "/admin/:siteid/users/permissions", - auth_required: true, - access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'users', 'permissions.js') - }, - { - method: 'get', - path: "/admin/:siteid/users/new", - auth_required: true, - access_level: pb.SecurityService.ACCESS_EDITOR, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'users', 'user_form.js') - }, { method: 'get', path: "/admin/:siteid/users/:id", auth_required: true, access_level: pb.SecurityService.ACCESS_EDITOR, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'users', 'user_form.js') - }, - { - method: 'get', - path: "/admin/:siteid/users/password/:id", - auth_required: true, - access_level: pb.SecurityService.ACCESS_EDITOR, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'users', 'change_password.js') - }, - { - method: 'post', - path: "/actions/admin/:siteid/users", - auth_required: true, - access_level: pb.SecurityService.ACCESS_EDITOR, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'users', 'new_user.js') - }, - { - method: 'post', - path: "/actions/admin/:siteid/users/:id", - auth_required: true, - access_level: pb.SecurityService.ACCESS_EDITOR, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'users', 'edit_user.js') - }, - { - method: 'delete', - path: "/actions/admin/:siteid/users/:id", - auth_required: true, - access_level: pb.SecurityService.ACCESS_EDITOR, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'users', 'delete_user.js') - }, - { - method: 'delete', - path: "/actions/admin/:siteid/users/unverified/:id", - auth_required: true, - access_level: pb.SecurityService.ACCESS_EDITOR, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'users', 'delete_unverified_user.js') - }, - { - method: 'get', - path: "/actions/admin/:siteid/users/verify/:id", - auth_required: true, - access_level: pb.SecurityService.ACCESS_EDITOR, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'users', 'verify_user.js') - }, - - { - method: 'post', - path: "/actions/admin/:siteid/users/change_password/:id", - auth_required: true, - access_level: pb.SecurityService.ACCESS_EDITOR, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'users', 'change_password.js') - }, - { - method: 'get', - path: "/actions/admin/:siteid/users/send_password_reset/:id", - auth_required: true, - access_level: pb.SecurityService.ACCESS_MANAGING_EDITOR, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'users', 'send_password_reset.js') - }, - { - method: 'post', - path: "/actions/admin/:siteid/users/send_password_reset/:id", - auth_required: true, - access_level: pb.SecurityService.ACCESS_MANAGING_EDITOR, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'users', 'send_password_reset.js') + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'users', 'user_form.js'), } ]; }; diff --git a/plugins/pencilblue/include/routes.js b/plugins/pencilblue/include/routes.js index b1e716fa1..1a72af25e 100644 --- a/plugins/pencilblue/include/routes.js +++ b/plugins/pencilblue/include/routes.js @@ -121,7 +121,7 @@ module.exports = function Routes(pb){ method: 'post', path: "/actions/user/manage_account/change_password", auth_required: true, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'user', 'manage_account', 'change_password.js') + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'user', 'manage_account', 'change_password.js'), }, { method: 'post', @@ -134,19 +134,19 @@ module.exports = function Routes(pb){ method: 'post', path: "/actions/user/resend_verification", auth_required: false, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'user', 'resend_verification.js') + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'user', 'resend_verification.js'), }, { method: 'post', path: "/actions/user/sign_up", auth_required: false, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'user', 'sign_up.js') + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'user', 'sign_up.js'), }, { method: 'get', path: "/actions/user/verify_email", auth_required: false, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'user', 'verify_email.js') + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'user', 'verify_email.js'), }, { method: 'get', @@ -166,7 +166,7 @@ module.exports = function Routes(pb){ method: 'get', path: "/user/sign_up", auth_required: false, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'user', 'sign_up.js') + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'user', 'sign_up.js'), }, { method: 'get', @@ -180,7 +180,7 @@ module.exports = function Routes(pb){ handler: 'login', path: "/user/login", auth_required: false, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'user', 'login.js') + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'user', 'login.js'), }, { method: 'get', @@ -479,7 +479,7 @@ module.exports = function Routes(pb){ path: "/actions/admin/content/articles/:id", access_level: pb.SecurityService.ACCESS_EDITOR, auth_required: true, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'content', 'articles', 'delete_article.js') + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'content', 'articles', 'delete_article.js'), }, // PAGES @@ -828,7 +828,7 @@ module.exports = function Routes(pb){ path: "/actions/admin/themes/site_logo", auth_required: true, access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'themes', 'site_logo.js') + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'themes', 'site_logo.js'), }, // USERS @@ -837,91 +837,91 @@ module.exports = function Routes(pb){ path: "/admin/users", auth_required: true, access_level: pb.SecurityService.ACCESS_EDITOR, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'users', 'manage_users.js') + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'users', 'manage_users.js'), }, { method: 'get', path: "/admin/users/unverified", auth_required: true, access_level: pb.SecurityService.ACCESS_EDITOR, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'users', 'unverified_users.js') + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'users', 'unverified_users.js'), }, { method: 'get', path: "/admin/users/new", auth_required: true, access_level: pb.SecurityService.ACCESS_EDITOR, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'users', 'user_form.js') + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'users', 'user_form.js'), }, { method: 'get', path: "/admin/users/:id", auth_required: true, access_level: pb.SecurityService.ACCESS_EDITOR, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'users', 'user_form.js') + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'users', 'user_form.js'), }, { method: 'get', path: "/admin/users/password/:id", auth_required: true, access_level: pb.SecurityService.ACCESS_EDITOR, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'users', 'change_password.js') + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'users', 'change_password.js'), }, { method: 'post', path: "/actions/admin/users", auth_required: true, access_level: pb.SecurityService.ACCESS_EDITOR, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'users', 'new_user.js') + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'users', 'new_user.js'), }, { method: 'post', path: "/actions/admin/users/:id", auth_required: true, access_level: pb.SecurityService.ACCESS_EDITOR, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'users', 'edit_user.js') + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'users', 'edit_user.js'), }, { method: 'delete', path: "/actions/admin/users/:id", auth_required: true, access_level: pb.SecurityService.ACCESS_EDITOR, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'users', 'delete_user.js') + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'users', 'delete_user.js'), }, { method: 'delete', path: "/actions/admin/users/unverified/:id", auth_required: true, access_level: pb.SecurityService.ACCESS_EDITOR, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'users', 'delete_unverified_user.js') + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'users', 'delete_unverified_user.js'), }, { method: 'get', path: "/actions/admin/users/verify/:id", auth_required: true, access_level: pb.SecurityService.ACCESS_EDITOR, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'users', 'verify_user.js') + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'users', 'verify_user.js'), }, { method: 'post', path: "/actions/admin/users/change_password/:id", auth_required: true, access_level: pb.SecurityService.ACCESS_EDITOR, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'users', 'change_password.js') + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'users', 'change_password.js'), }, { method: 'get', path: "/actions/admin/users/send_password_reset/:id", auth_required: true, access_level: pb.SecurityService.ACCESS_MANAGING_EDITOR, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'users', 'send_password_reset.js') + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'users', 'send_password_reset.js'), }, { method: 'post', path: "/actions/admin/users/send_password_reset/:id", auth_required: true, access_level: pb.SecurityService.ACCESS_MANAGING_EDITOR, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'users', 'send_password_reset.js') + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'users', 'send_password_reset.js'), }, // SITE SETTINGS From 6df4364e12ef3ec73a3b29e5fc9c3619b957d295 Mon Sep 17 00:00:00 2001 From: iandtrapp Date: Mon, 15 Jun 2015 12:45:26 -0400 Subject: [PATCH 326/790] Edit site page loads but has zero functionality --- .../controllers/admin/sites/edit_sites.js | 40 ++++++++++++++ .../controllers/admin/sites/manage_sites.js | 2 +- plugins/pencilblue/include/routes.js | 10 +++- .../templates/admin/sites/edit_sites.html | 33 ++++++++++++ .../templates/admin/sites/manage_sites.html | 20 +++++-- .../templates/admin/sites/site_form.html | 2 +- .../angular/admin/sites/edit_sites.html | 54 +++++++++++++++++++ public/localization/en-us.js | 4 +- 8 files changed, 157 insertions(+), 8 deletions(-) create mode 100644 plugins/pencilblue/controllers/admin/sites/edit_sites.js create mode 100644 plugins/pencilblue/templates/admin/sites/edit_sites.html create mode 100644 plugins/pencilblue/templates/angular/admin/sites/edit_sites.html diff --git a/plugins/pencilblue/controllers/admin/sites/edit_sites.js b/plugins/pencilblue/controllers/admin/sites/edit_sites.js new file mode 100644 index 000000000..b72933daa --- /dev/null +++ b/plugins/pencilblue/controllers/admin/sites/edit_sites.js @@ -0,0 +1,40 @@ +module.exports = function(pb) { + + var util = pb.util; + + function EditSites(){} + util.inherits(EditSites, pb.BaseController); + + var SUB_NAV_KEY = 'sites_edit'; + + EditSites.prototype.render = function(cb) { + var self = this; + var angularObjects = pb.ClientJs.getAngularObjects({ + navigation: pb.AdminNavigation.get(self.session, ['site_entity'], self.ls), + pills: pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, SUB_NAV_KEY) + }); + self.ts.registerLocal('angular_objects', new pb.TemplateValue(angularObjects, false)); + self.ts.load('admin/sites/edit_sites', function(err,result) { + cb({content: result}); + }); + + }; + + EditSites.getSubNavItems = function(key, ls, data) { + return [{ + name: 'manage_sites', + title: ls.get('MANAGE_SITES'), + icon: 'chevron-left', + href: '/admin/sites' + }, { + name: 'new_site', + title: '', + icon: 'plus', + href: '/admin/sites/new' + }]; + }; + + pb.AdminSubnavService.registerFor(SUB_NAV_KEY, EditSites.getSubNavItems); + + return EditSites; +}; \ No newline at end of file diff --git a/plugins/pencilblue/controllers/admin/sites/manage_sites.js b/plugins/pencilblue/controllers/admin/sites/manage_sites.js index b01569918..4272c4e10 100644 --- a/plugins/pencilblue/controllers/admin/sites/manage_sites.js +++ b/plugins/pencilblue/controllers/admin/sites/manage_sites.js @@ -29,7 +29,7 @@ module.exports = function(pb) { name: 'manage_sites', title: ls.get('MANAGE_SITES'), icon: 'refresh', - href: '/admin/site' + href: '/admin/sites' }, { name: 'new_site', title: '', diff --git a/plugins/pencilblue/include/routes.js b/plugins/pencilblue/include/routes.js index c1b221bc2..01c7ed797 100644 --- a/plugins/pencilblue/include/routes.js +++ b/plugins/pencilblue/include/routes.js @@ -1015,6 +1015,14 @@ module.exports = function Routes(pb){ controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'sites', 'site_form.js'), content_type: 'text/html' }, + { + method: 'get', + path: "/admin/sites/:siteid", + access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, + auth_required: true, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'sites', 'edit_sites.js'), + content_type: 'text/html' + }, { method: 'post', path: "/actions/admin/sites/new", @@ -1036,7 +1044,7 @@ module.exports = function Routes(pb){ auth_required: true, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'sites', 'deactivate_site.js') }, - + //**********************API************************ //articles diff --git a/plugins/pencilblue/templates/admin/sites/edit_sites.html b/plugins/pencilblue/templates/admin/sites/edit_sites.html new file mode 100644 index 000000000..ea5c5fe06 --- /dev/null +++ b/plugins/pencilblue/templates/admin/sites/edit_sites.html @@ -0,0 +1,33 @@ +^tmp_admin=head^ +
+ ^tmp_admin=elements=error_success^ + ^tmp_admin=elements=sub_nav^ + ^tmp_admin=elements=tab_nav^ + +
+
+
+
+ + +
^loc_REQUIRED_FIELD^
+
+
+ + +
^loc_REQUIRED_FIELD^
+
+
+
+ +  ^loc_CANCEL^ + + ^tmp_admin=elements=save_button^ +
+
+ + ^tmp_admin=elements=progress_console_modal^ + + ^tmp_angular=admin=sites=edit_sites^ + ^tmp_admin=footer^ +
\ No newline at end of file diff --git a/plugins/pencilblue/templates/admin/sites/manage_sites.html b/plugins/pencilblue/templates/admin/sites/manage_sites.html index f6363908f..b5fce1c65 100644 --- a/plugins/pencilblue/templates/admin/sites/manage_sites.html +++ b/plugins/pencilblue/templates/admin/sites/manage_sites.html @@ -22,8 +22,14 @@
@@ -48,8 +54,14 @@ diff --git a/plugins/pencilblue/templates/admin/sites/site_form.html b/plugins/pencilblue/templates/admin/sites/site_form.html index 8016298d1..19ed4d4e2 100644 --- a/plugins/pencilblue/templates/admin/sites/site_form.html +++ b/plugins/pencilblue/templates/admin/sites/site_form.html @@ -6,7 +6,7 @@
-
+
diff --git a/plugins/pencilblue/templates/angular/admin/sites/edit_sites.html b/plugins/pencilblue/templates/angular/admin/sites/edit_sites.html new file mode 100644 index 000000000..6d28b2e1d --- /dev/null +++ b/plugins/pencilblue/templates/angular/admin/sites/edit_sites.html @@ -0,0 +1,54 @@ + + \ No newline at end of file diff --git a/public/localization/en-us.js b/public/localization/en-us.js index ffa7f3a77..b57655fe8 100755 --- a/public/localization/en-us.js +++ b/public/localization/en-us.js @@ -435,7 +435,9 @@ var loc = ERROR_ACTIVATING: 'There was an error activating', ERROR_DEACTIVATING: 'There was an error deactivating', SITE_ACTIVATED: 'Site activated', - SITE_DEACTIVATED: 'Site deactivated' + SITE_DEACTIVATED: 'Site deactivated', + ACTIVATE: 'Activate', + DEACTIVATE: 'Deactivate' }, plugins: { From b980ff190f46c57595042e249fccf687cfe4a5fb Mon Sep 17 00:00:00 2001 From: btidwell Date: Mon, 15 Jun 2015 14:22:21 -0400 Subject: [PATCH 327/790] check for descriptor presence when un-registering theme route --- include/http/request_handler.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/http/request_handler.js b/include/http/request_handler.js index 45fd8404b..5ce73f97d 100755 --- a/include/http/request_handler.js +++ b/include/http/request_handler.js @@ -192,7 +192,7 @@ module.exports = function RequestHandlerModule(pb) { //static routes Object.keys(RequestHandler.staticRoutes).forEach(function(path) { - var result = RequestHandler.unregisterRoute(path, theme); + var result = RequestHandler.unregisterRoute(path, theme, site); if (result) { routesRemoved++; } @@ -244,7 +244,7 @@ module.exports = function RequestHandlerModule(pb) { //return false if specified site has no themes registered on that descriptor //return false if theme doesnt exist on descriptor for that site - if (!descriptor.themes[site] || !descriptor.themes[site][theme]) { + if (!descriptor || !descriptor.themes[site] || !descriptor.themes[site][theme]) { return false; } From ee6df20c562b080851d9d5b9b28a44e6d2222c83 Mon Sep 17 00:00:00 2001 From: btidwell Date: Mon, 15 Jun 2015 14:23:20 -0400 Subject: [PATCH 328/790] =?UTF-8?q?Remove=20redundant=20descriptor=20gener?= =?UTF-8?q?ation=C2=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/http/request_handler.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/include/http/request_handler.js b/include/http/request_handler.js index 5ce73f97d..07dabf8bc 100755 --- a/include/http/request_handler.js +++ b/include/http/request_handler.js @@ -239,9 +239,6 @@ module.exports = function RequestHandlerModule(pb) { return false; } - //check for theme - var descriptor = RequestHandler.storage[RequestHandler.index[pattern]]; - //return false if specified site has no themes registered on that descriptor //return false if theme doesnt exist on descriptor for that site if (!descriptor || !descriptor.themes[site] || !descriptor.themes[site][theme]) { From 896d0284113041f63d836d85f1605a0d9a77106c Mon Sep 17 00:00:00 2001 From: andparker Date: Mon, 15 Jun 2015 16:32:14 -0400 Subject: [PATCH 329/790] Adds more site specific functionality to email and users --- controllers/base_controller.js | 17 +++-------------- include/email.js | 5 +++-- include/service/entities/user_service.js | 4 ++-- .../admin/users/delete_unverified_user.js | 2 +- .../actions/admin/users/verify_user.js | 2 +- .../actions/user/resend_verification.js | 11 ++++++----- .../controllers/admin/site_settings/email.js | 2 +- .../controllers/user/manage_account.js | 2 +- .../controllers/user/resend_verification.js | 2 +- 9 files changed, 19 insertions(+), 28 deletions(-) diff --git a/controllers/base_controller.js b/controllers/base_controller.js index 17e9046c6..89e24b362 100755 --- a/controllers/base_controller.js +++ b/controllers/base_controller.js @@ -185,7 +185,7 @@ module.exports = function BaseControllerModule(pb) { self.siteObj = siteInfo; self.templateService.registerLocal('site_root', function(flag, cb) { - cb(null, self.siteObj.hostname || self.templateService.siteRoot); + cb(null, pb.SiteService.getHostWithProtocol(self.siteObj.hostname) || self.templateService.siteRoot); }); self.templateService.registerLocal('site_name', function(flag, cb) { cb(null, self.siteObj.displayName || self.templateService.siteName); @@ -245,20 +245,9 @@ module.exports = function BaseControllerModule(pb) { * @param {Function} cb */ BaseController.prototype.formError = function(message, redirectLocation, cb) { - var self = this; - self.session.error = message; - var siteService = new pb.SiteService(); - siteService.getByUid(self.site, function(err, siteProps) { - if(util.isError(err) || !siteProps) { - if(err) { pb.log.error(err) }; - self.reqHandler.serve404(); //TODO: Handle this better? - return; - } - else { - cb(pb.RequestHandler.generateRedirect(redirectLocation)); - } - }); + this.session.error = message; + cb(pb.RequestHandler.generateRedirect(redirectLocation)); }; /** diff --git a/include/email.js b/include/email.js index 0159b1fe7..c82a4b438 100755 --- a/include/email.js +++ b/include/email.js @@ -28,9 +28,10 @@ module.exports = function EmailServiceModule(pb) { * @class EmailService * @constructor */ - function EmailService(siteUid) { + function EmailService(siteUid, onlyThisSite) { this.site = pb.SiteService.getCurrentSite(siteUid); + this.onlyThisSite = onlyThisSite; } /** @@ -158,7 +159,7 @@ module.exports = function EmailServiceModule(pb) { */ EmailService.prototype.getSettings = function(cb) { var self = this; - var settingsService = pb.SettingServiceFactory.getServiceBySite(self.site); + var settingsService = pb.SettingServiceFactory.getServiceBySite(self.site, self.onlyThisSite); settingsService.get('email_settings', function(err, settings) { cb(err, util.isError(err) || !settings ? EmailService.getDefaultSettings() : settings); }); diff --git a/include/service/entities/user_service.js b/include/service/entities/user_service.js index 27d510b2f..e0ea15469 100755 --- a/include/service/entities/user_service.js +++ b/include/service/entities/user_service.js @@ -243,7 +243,7 @@ module.exports = function UserServiceModule(pb) { var options = { to: user.email, replacements: { - 'verification_url': pb.SiteService.getSiteProtocol(siteInfo.hostname) + '/actions/user/verify_email?email=' + user.email + '&code=' + user.verification_code, + 'verification_url': pb.SiteService.getHostWithProtocol(siteInfo.hostname) + '/actions/user/verify_email?email=' + user.email + '&code=' + user.verification_code, 'first_name': user.first_name, 'last_name': user.last_name } @@ -340,7 +340,7 @@ module.exports = function UserServiceModule(pb) { return where; }; - var dao = new pb.SiteQueryService(self.context.site, false); + var dao = (pb.SiteService.isGlobal(self.context.site)) ? new pb.DAO() : new pb.SiteQueryService(self.context.site, false); var tasks = { verified_username: function(callback) { var expStr = util.escapeRegExp(username) + '$'; diff --git a/plugins/pencilblue/controllers/actions/admin/users/delete_unverified_user.js b/plugins/pencilblue/controllers/actions/admin/users/delete_unverified_user.js index c7c7bc193..dd7d2fbe6 100644 --- a/plugins/pencilblue/controllers/actions/admin/users/delete_unverified_user.js +++ b/plugins/pencilblue/controllers/actions/admin/users/delete_unverified_user.js @@ -40,7 +40,7 @@ module.exports = function(pb) { } //ensure existence - var dao = new pb.DAO(); + var dao = new pb.SiteQueryService(self.site, true); dao.loadById(vars.id, 'unverified_user', function(err, user) { if(user === null) { cb({ diff --git a/plugins/pencilblue/controllers/actions/admin/users/verify_user.js b/plugins/pencilblue/controllers/actions/admin/users/verify_user.js index c606398a9..8d39b189c 100644 --- a/plugins/pencilblue/controllers/actions/admin/users/verify_user.js +++ b/plugins/pencilblue/controllers/actions/admin/users/verify_user.js @@ -40,7 +40,7 @@ module.exports = function VerifyUserModule(pb) { } //ensure existence - var dao = new pb.DAO(); + var dao = new pb.SiteQueryService(self.site, true); dao.loadById(vars.id, 'unverified_user', function(err, unverifiedUser) { if(unverifiedUser === null) { cb({ diff --git a/plugins/pencilblue/controllers/actions/user/resend_verification.js b/plugins/pencilblue/controllers/actions/user/resend_verification.js index bc8a3877f..2e7193d18 100755 --- a/plugins/pencilblue/controllers/actions/user/resend_verification.js +++ b/plugins/pencilblue/controllers/actions/user/resend_verification.js @@ -20,6 +20,7 @@ module.exports = function ResendVerificationModule(pb) { //pb dependencies var util = pb.util; + var UserService = pb.UserService; /** * Resends an account verification email @@ -36,14 +37,14 @@ module.exports = function ResendVerificationModule(pb) { return; } - var siteQueryService = new pb.SiteQueryService(self.site, true); - siteQueryService.loadByValue('email', post.email, 'user', function(err, user) { + var dao = new pb.SiteQueryService(self.site, true); + dao.loadByValue('email', post.email, 'user', function(err, user) { if(util.isError(err) || user === null) { self.formError(self.ls.get('USER_VERIFIED'), '/user/login', cb); return; } - siteQueryService.loadByValue('email', post.email, 'unverified_user', function(err, user) { + dao.loadByValue('email', post.email, 'unverified_user', function(err, user) { if(util.isError(err) || user === null) { self.formError(self.ls.get('NOT_REGISTERED'), '/user/sign_up', cb); return; @@ -51,7 +52,7 @@ module.exports = function ResendVerificationModule(pb) { user.verification_code = util.uniqueId(); - siteQueryService.save(user, function(err, result) { + dao.save(user, function(err, result) { if(util.isError(result)) { self.formError(self.ls.get('ERROR_SAVING'), '/user/resend_verification', cb); return; @@ -59,7 +60,7 @@ module.exports = function ResendVerificationModule(pb) { self.session.success = self.ls.get('VERIFICATION_SENT') + user.email; self.redirect('/user/verification_sent', cb); - var userService = new UserService(self.site); + var userService = new UserService(self.getServiceContext()); userService.sendVerificationEmail(user, util.cb); }); }); diff --git a/plugins/pencilblue/controllers/admin/site_settings/email.js b/plugins/pencilblue/controllers/admin/site_settings/email.js index e02c05ecc..7d17a3c8b 100755 --- a/plugins/pencilblue/controllers/admin/site_settings/email.js +++ b/plugins/pencilblue/controllers/admin/site_settings/email.js @@ -52,7 +52,7 @@ module.exports = function(pb) { } ]; - var emailService = new pb.EmailService(this.site); + var emailService = new pb.EmailService(this.site, true); emailService.getSettings(function(err, emailSettings) { var angularObjects = pb.ClientJs.getAngularObjects({ navigation: pb.AdminNavigation.get(self.session, ['settings', 'site_settings'], self.ls), diff --git a/plugins/pencilblue/controllers/user/manage_account.js b/plugins/pencilblue/controllers/user/manage_account.js index 347860fc8..7821f9b93 100755 --- a/plugins/pencilblue/controllers/user/manage_account.js +++ b/plugins/pencilblue/controllers/user/manage_account.js @@ -29,7 +29,7 @@ module.exports = function ManageAccountModule(pb) { ManageAccount.prototype.render = function(cb) { var self = this; - var dao = new pb.SiteQueryService(self.site, true); + var dao = new pb.SiteQueryService(self.site); dao.loadById(self.session.authentication.user_id, 'user', function(err, user) { if(util.isError(err) || user === null) { if (err) { pb.log.error(err); } diff --git a/plugins/pencilblue/controllers/user/resend_verification.js b/plugins/pencilblue/controllers/user/resend_verification.js index 335b5742d..555bd81f4 100755 --- a/plugins/pencilblue/controllers/user/resend_verification.js +++ b/plugins/pencilblue/controllers/user/resend_verification.js @@ -29,7 +29,7 @@ module.exports = function ResendVerificationModule(pb) { ResendVerification.prototype.render = function(cb) { var self = this; - var contentService = new pb.ContentService(self.site); + var contentService = new pb.ContentService(self.site, true); contentService.getSettings(function(err, contentSettings) { if(!contentSettings.allow_comments || !contentSettings.require_verification) { From 55ebef85d755a75b2656cc7a7c8ce9e363245bb1 Mon Sep 17 00:00:00 2001 From: andparker Date: Mon, 15 Jun 2015 17:55:55 -0400 Subject: [PATCH 330/790] Removes the now unnecessary "doesScopeEnvelope" site service method and its uses. --- controllers/admin/base_admin_controller.js | 5 ---- include/http/request_handler.js | 34 ++++------------------ include/service/entities/site_service.js | 9 ------ plugins/pencilblue/controllers/index.js | 8 ++--- 4 files changed, 8 insertions(+), 48 deletions(-) diff --git a/controllers/admin/base_admin_controller.js b/controllers/admin/base_admin_controller.js index bad6c91f1..c6636c5be 100644 --- a/controllers/admin/base_admin_controller.js +++ b/controllers/admin/base_admin_controller.js @@ -44,11 +44,6 @@ module.exports = function BaseAdminControllerModule(pb) { BaseAdminController.prototype.extendedInit = function(cb) { var self = this; - var userSite = pb.SiteService.getSiteFromObject(self.session.authentication.user); - if (!pb.SiteService.doesScopeEnvelope(userSite, self.pathSiteUId)) { - self.reqHandler.serve404(); // TODO should we serve 403 here? - return; - } var siteService = new pb.SiteService(); siteService.getByUid(self.site, function (err, siteInfo) { if (err || !siteInfo) { diff --git a/include/http/request_handler.js b/include/http/request_handler.js index 887de614a..45fd8404b 100755 --- a/include/http/request_handler.js +++ b/include/http/request_handler.js @@ -816,15 +816,6 @@ module.exports = function RequestHandlerModule(pb) { }); }; - function getPathVars(route, url) { - var pathVars = {}; - var pathParts = url.pathname.split('/'); - for (var field in route.path_vars) { - pathVars[field] = pathParts[route.path_vars[field]]; - } - return pathVars; - } - /** * * @method onSecurityChecksPassed @@ -836,7 +827,12 @@ module.exports = function RequestHandlerModule(pb) { RequestHandler.prototype.onSecurityChecksPassed = function(activeTheme, method, site, route) { //extract path variables - var pathVars = getPathVars(route, this.url); + var pathVars = {}; + var pathParts = this.url.pathname.split('/'); + for (var field in route.path_vars) { + pathVars[field] = pathParts[route.path_vars[field]]; + } + //execute controller var ControllerType = route.themes[site][activeTheme][method].controller; var cInstance = new ControllerType(); @@ -1121,12 +1117,6 @@ module.exports = function RequestHandlerModule(pb) { self.session.on_login = self.req.method.toLowerCase() === 'get' ? self.url.href : pb.UrlService.urlJoin(pb.config.siteRoot, '/admin'); callback(result, result); return; - } else if (!isUserAllowedToAccessSite(self.session.authentication.user)) { - result.success = false; - result.content = '403 Forbidden'; - result.code = 403; - callback(result, result); - return; } callback(null, result); } @@ -1135,18 +1125,6 @@ module.exports = function RequestHandlerModule(pb) { } }; - function isUserAllowedToAccessSite(user) { - if (!user) { - return false; - } - var siteFromUser = pb.SiteService.getSiteFromObject(user); - if (pb.SiteService.doesScopeEnvelope(siteFromUser, self.site)) { - return true; - } - - return false; - } - var checkAdminLevel = function(callback) { var result = {success: true}; diff --git a/include/service/entities/site_service.js b/include/service/entities/site_service.js index dbe79025f..ba83979b8 100644 --- a/include/service/entities/site_service.js +++ b/include/service/entities/site_service.js @@ -310,15 +310,6 @@ module.exports = function SiteServiceModule(pb) { return !actual || SiteService.areEqual(actual, expected); }; - /** - * Returns true iff given (user) scope envelopes current scope; conceptually, true <=> userScope ⊇ currentScope - * @param userScope - * @param currentScope - */ - SiteService.doesScopeEnvelope = function (userScope, currentScope) { - return SiteService.isGlobal(userScope) || userScope === currentScope; - }; - /** * Central place to get the current site * diff --git a/plugins/pencilblue/controllers/index.js b/plugins/pencilblue/controllers/index.js index fedf522e9..e751d4e20 100755 --- a/plugins/pencilblue/controllers/index.js +++ b/plugins/pencilblue/controllers/index.js @@ -314,12 +314,8 @@ module.exports = function IndexModule(pb) { Index.prototype.renderComments = function(content, ts, cb) { var self = this; var commentingUser = null; - var user = this.session.authentication.user; - var userSite = pb.SiteService.getSiteFromObject(user); - var isAllowedToComment = pb.SiteService.doesScopeEnvelope(userSite, self.site); - if(pb.security.isAuthenticated(this.session)) { - commentingUser = Comments.getCommentingUser(user); + commentingUser = Comments.getCommentingUser(this.session.authentication.user); } ts.registerLocal('user_photo', function(flag, cb) { @@ -339,7 +335,7 @@ module.exports = function IndexModule(pb) { } }); ts.registerLocal('user_name', commentingUser ? commentingUser.name : ''); - ts.registerLocal('display_submit', commentingUser && isAllowedToComment ? 'block' : 'none'); + ts.registerLocal('display_submit', commentingUser ? 'block' : 'none'); ts.registerLocal('display_login', commentingUser ? 'none' : 'block'); ts.registerLocal('comments_length', util.isArray(content.comments) ? content.comments.length : 0); ts.registerLocal('individual_comments', function(flag, cb) { From d7a47fad89fd7526197acc81410b048eccc54e22 Mon Sep 17 00:00:00 2001 From: andparker Date: Mon, 15 Jun 2015 18:33:01 -0400 Subject: [PATCH 331/790] Renames "siteQueryService" variables back to "dao" --- .../actions/user/manage_account/change_password.js | 6 +++--- .../controllers/actions/user/manage_account/profile.js | 6 +++--- .../controllers/actions/user/resend_verification.js | 2 +- .../pencilblue/controllers/actions/user/reset_password.js | 8 ++++---- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/plugins/pencilblue/controllers/actions/user/manage_account/change_password.js b/plugins/pencilblue/controllers/actions/user/manage_account/change_password.js index 23ffbcf0e..5dbbf5c92 100755 --- a/plugins/pencilblue/controllers/actions/user/manage_account/change_password.js +++ b/plugins/pencilblue/controllers/actions/user/manage_account/change_password.js @@ -63,15 +63,15 @@ module.exports = function(pb) { delete post.new_password; delete post.confirm_password; - var siteQueryService = new pb.SiteQueryService(self.site, true); - siteQueryService.loadByValues(where, 'user', function(err, user) { + var dao = new pb.SiteQueryService(self.site, true); + dao.loadByValues(where, 'user', function(err, user) { if(util.isError(err) || user === null) { self.formError(self.ls.get('INVALID_PASSWORD'), '/user/change_password', cb); return; } pb.DocumentCreator.update(post, user); - siteQueryService.save(user, function(err, result) { + dao.save(user, function(err, result) { if(util.isError(err)) { return self.formError(self.ls.get('ERROR_SAVING'), '/user/change_password', cb); } diff --git a/plugins/pencilblue/controllers/actions/user/manage_account/profile.js b/plugins/pencilblue/controllers/actions/user/manage_account/profile.js index 03a3c1c7b..bdf29a061 100755 --- a/plugins/pencilblue/controllers/actions/user/manage_account/profile.js +++ b/plugins/pencilblue/controllers/actions/user/manage_account/profile.js @@ -43,8 +43,8 @@ module.exports = function ProfileModule(pb) { post.position = BaseController.sanitize(post.position); post.photo = BaseController.sanitize(post.photo); - var siteQueryService = new pb.SiteQueryService(self.site, true); - siteQueryService.loadById(self.session.authentication.user_id, 'user', function(err, user) { + var dao = new pb.SiteQueryService(self.site, true); + dao.loadById(self.session.authentication.user_id, 'user', function(err, user) { if(util.isError(err) || user === null) { self.formError(self.ls.get('ERROR_SAVING'), '/user/manage_account', cb); return; @@ -52,7 +52,7 @@ module.exports = function ProfileModule(pb) { //update the document pb.DocumentCreator.update(post, user); - siteQueryService.save(user, function(err, result) { + dao.save(user, function(err, result) { if(util.isError(err)) { return self.formError(self.ls.get('ERROR_SAVING'), '/user/manage_account', cb); } diff --git a/plugins/pencilblue/controllers/actions/user/resend_verification.js b/plugins/pencilblue/controllers/actions/user/resend_verification.js index 2e7193d18..8bc8b2b46 100755 --- a/plugins/pencilblue/controllers/actions/user/resend_verification.js +++ b/plugins/pencilblue/controllers/actions/user/resend_verification.js @@ -52,7 +52,7 @@ module.exports = function ResendVerificationModule(pb) { user.verification_code = util.uniqueId(); - dao.save(user, function(err, result) { + dao.save(user, function(err, result) { if(util.isError(result)) { self.formError(self.ls.get('ERROR_SAVING'), '/user/resend_verification', cb); return; diff --git a/plugins/pencilblue/controllers/actions/user/reset_password.js b/plugins/pencilblue/controllers/actions/user/reset_password.js index 5f43fb17a..5bb817371 100755 --- a/plugins/pencilblue/controllers/actions/user/reset_password.js +++ b/plugins/pencilblue/controllers/actions/user/reset_password.js @@ -35,14 +35,14 @@ module.exports = function ResetPasswordModule(pb) { return; } - var siteQueryService = new pb.SiteQueryService(self.site, true); - siteQueryService.loadByValue('email', get.email, 'user', function(err, user) { + var dao = new pb.SiteQueryService(self.site, true); + dao.loadByValue('email', get.email, 'user', function(err, user) { if(user === null) { self.formError(self.ls.get('INVALID_VERIFICATION'), '/user/login', cb); return; } - siteQueryService.loadByValue('user_id', user[pb.DAO.getIdField()].toString(), 'password_reset', function(err, passwordReset) { + dao.loadByValue('user_id', user[pb.DAO.getIdField()].toString(), 'password_reset', function(err, passwordReset) { if(passwordReset === null) { self.formError(self.ls.get('INVALID_VERIFICATION'), '/user/login', cb); return; @@ -54,7 +54,7 @@ module.exports = function ResetPasswordModule(pb) { } // delete the password reset token - siteQueryService.deleteById(passwordReset[pb.DAO.getIdField()], 'password_reset', function(err, result) { + dao.deleteById(passwordReset[pb.DAO.getIdField()], 'password_reset', function(err, result) { //log the user in self.session.authentication.user = user; self.session.authentication.user_id = user[pb.DAO.getIdField()].toString(); From b670e3b08f512be7a001a2df59a9059d8e92a558 Mon Sep 17 00:00:00 2001 From: andparker Date: Tue, 16 Jun 2015 11:07:10 -0400 Subject: [PATCH 332/790] Load global email settings if we do not have any site specific email settings --- plugins/pencilblue/controllers/admin/site_settings/email.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/pencilblue/controllers/admin/site_settings/email.js b/plugins/pencilblue/controllers/admin/site_settings/email.js index 7d17a3c8b..e02c05ecc 100755 --- a/plugins/pencilblue/controllers/admin/site_settings/email.js +++ b/plugins/pencilblue/controllers/admin/site_settings/email.js @@ -52,7 +52,7 @@ module.exports = function(pb) { } ]; - var emailService = new pb.EmailService(this.site, true); + var emailService = new pb.EmailService(this.site); emailService.getSettings(function(err, emailSettings) { var angularObjects = pb.ClientJs.getAngularObjects({ navigation: pb.AdminNavigation.get(self.session, ['settings', 'site_settings'], self.ls), From 181c0acb9be93de69ab7b93220daa309e43c05c1 Mon Sep 17 00:00:00 2001 From: iandtrapp Date: Tue, 16 Jun 2015 12:37:02 -0400 Subject: [PATCH 333/790] Edit working functionally, need to forbid hostname update if site active --- .../actions/admin/sites/edit_site_action.js | 60 +++++++++++++++++++ .../actions/admin/sites/new_site_action.js | 2 + .../controllers/admin/sites/edit_sites.js | 25 +++++--- .../controllers/admin/sites/site_form.js | 6 +- plugins/pencilblue/include/routes.js | 7 +++ .../templates/admin/sites/edit_sites.html | 12 ++-- .../angular/admin/sites/edit_sites.html | 6 +- public/localization/en-us.js | 7 ++- 8 files changed, 102 insertions(+), 23 deletions(-) create mode 100644 plugins/pencilblue/controllers/actions/admin/sites/edit_site_action.js diff --git a/plugins/pencilblue/controllers/actions/admin/sites/edit_site_action.js b/plugins/pencilblue/controllers/actions/admin/sites/edit_site_action.js new file mode 100644 index 000000000..fd25eb0be --- /dev/null +++ b/plugins/pencilblue/controllers/actions/admin/sites/edit_site_action.js @@ -0,0 +1,60 @@ +module.exports = function(pb) { + + //pb dependencies + var util = pb.util; + + /** + * Edits a current site + */ + function EditSiteAction(){} + util.inherits(EditSiteAction, pb.BaseController); + + EditSiteAction.prototype.render = function(cb) + { + var self = this; + var siteid = this.pathVars.siteid; + this.getJSONPostParams(function(err, post) { + var message = self.hasRequiredParams(post, self.getRequiredFields()); + if(message) { + cb({ + code: 400, + content: pb.BaseController.apiResponse(pb.BaseController.API_ERROR, message) + }); + return; + } + + if(!pb.security.isAuthorized(self.session, {admin_level: post.admin})) { + cb({ + code: 400, + content: pb.BaseController.apiResponse(pb.BaseController.API_ERROR, self.ls.get('INSUFFICIENT_CREDENTIALS')) + }); + return; + } + + var dao = new pb.DAO(); + dao.loadByValue('uid', siteid, 'site', function(err, data) { + data.displayName = post.displayName; + data.hostname = post.hostname; + dao.save(data, function(err, result) { + if(err) { + cb({ + code: 400, + content: pb.BaseController.apiResponse(pb.BaseController.API_ERROR, self.ls.get('ERROR SAVING')) + }); + return; + } + cb({content: pb.BaseController.apiResponse(pb.BaseController.API_SUCCESS, self.ls.get('SITE_UPDATED'), result)}); + }); + }); + + }); + + }; + + EditSiteAction.prototype.getRequiredFields = function() { + return['displayName', 'hostname'] + }; + + //exports + return EditSiteAction; +}; \ No newline at end of file diff --git a/plugins/pencilblue/controllers/actions/admin/sites/new_site_action.js b/plugins/pencilblue/controllers/actions/admin/sites/new_site_action.js index 8c22cb457..07f774a12 100644 --- a/plugins/pencilblue/controllers/actions/admin/sites/new_site_action.js +++ b/plugins/pencilblue/controllers/actions/admin/sites/new_site_action.js @@ -31,6 +31,8 @@ module.exports = function(pb) { return; } + + var siteService = new pb.SiteService(); var site = pb.DocumentCreator.create('site', post); diff --git a/plugins/pencilblue/controllers/admin/sites/edit_sites.js b/plugins/pencilblue/controllers/admin/sites/edit_sites.js index b72933daa..1f55a8301 100644 --- a/plugins/pencilblue/controllers/admin/sites/edit_sites.js +++ b/plugins/pencilblue/controllers/admin/sites/edit_sites.js @@ -9,21 +9,28 @@ module.exports = function(pb) { EditSites.prototype.render = function(cb) { var self = this; - var angularObjects = pb.ClientJs.getAngularObjects({ - navigation: pb.AdminNavigation.get(self.session, ['site_entity'], self.ls), - pills: pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, SUB_NAV_KEY) - }); - self.ts.registerLocal('angular_objects', new pb.TemplateValue(angularObjects, false)); - self.ts.load('admin/sites/edit_sites', function(err,result) { - cb({content: result}); + var id = this.pathVars.siteid; + var dao = new pb.DAO(); + dao.loadByValue('uid', id, 'site', function(err, data) { + var angularObjects = pb.ClientJs.getAngularObjects({ + navigation: pb.AdminNavigation.get(self.session, ['site_entity'], self.ls), + pills: pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, SUB_NAV_KEY) + }); + self.ts.registerLocal('display_name', data.displayName.toString()); + self.ts.registerLocal('host_name', data.hostname.toString()); + self.ts.registerLocal('siteid', id.toString()); + self.ts.registerLocal('angular_objects', new pb.TemplateValue(angularObjects, false)); + self.ts.load('admin/sites/edit_sites', function(err,result) { + cb({content: result}); + }); }); }; EditSites.getSubNavItems = function(key, ls, data) { return [{ - name: 'manage_sites', - title: ls.get('MANAGE_SITES'), + name: 'edit_sites', + title: ls.get('EDIT_SITE'), icon: 'chevron-left', href: '/admin/sites' }, { diff --git a/plugins/pencilblue/controllers/admin/sites/site_form.js b/plugins/pencilblue/controllers/admin/sites/site_form.js index 008a20e90..32db7b190 100644 --- a/plugins/pencilblue/controllers/admin/sites/site_form.js +++ b/plugins/pencilblue/controllers/admin/sites/site_form.js @@ -23,12 +23,12 @@ module.exports = function(pb) { SiteForm.getSubNavItems = function(key, ls, data) { return [{ - name: 'manage_sites', - title: ls.get('MANAGE_SITES'), + name: 'new_site', + title: ls.get('NEW_SITE'), icon: 'chevron-left', href: '/admin/sites' }, { - name: 'new_site', + name: 'create_site', title: '', icon: 'plus', href: '/admin/sites/new' diff --git a/plugins/pencilblue/include/routes.js b/plugins/pencilblue/include/routes.js index 01c7ed797..42a6ad763 100644 --- a/plugins/pencilblue/include/routes.js +++ b/plugins/pencilblue/include/routes.js @@ -1030,6 +1030,13 @@ module.exports = function Routes(pb){ auth_required: true, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'sites', 'new_site_action.js') }, + { + method: 'post', + path: "/actions/admin/sites/edit/:siteid", + access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, + auth_required: true, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'sites', 'edit_site_action.js') + }, { method: 'post', path: "/actions/admin/sites/activate/:id", diff --git a/plugins/pencilblue/templates/admin/sites/edit_sites.html b/plugins/pencilblue/templates/admin/sites/edit_sites.html index ea5c5fe06..8aeaa303d 100644 --- a/plugins/pencilblue/templates/admin/sites/edit_sites.html +++ b/plugins/pencilblue/templates/admin/sites/edit_sites.html @@ -3,19 +3,19 @@ ^tmp_admin=elements=error_success^ ^tmp_admin=elements=sub_nav^ ^tmp_admin=elements=tab_nav^ - +
- -
^loc_REQUIRED_FIELD^
+ +
^loc_REQUIRED_FIELD^
- -
^loc_REQUIRED_FIELD^
+ +
^loc_REQUIRED_FIELD^

@@ -28,6 +28,6 @@ ^tmp_admin=elements=progress_console_modal^ - ^tmp_angular=admin=sites=edit_sites^ + ^TMP_ANGULAR=ADMIN=SITES=EDIT_SITES^ ^tmp_admin=footer^
\ No newline at end of file diff --git a/plugins/pencilblue/templates/angular/admin/sites/edit_sites.html b/plugins/pencilblue/templates/angular/admin/sites/edit_sites.html index 6d28b2e1d..6863aff1b 100644 --- a/plugins/pencilblue/templates/angular/admin/sites/edit_sites.html +++ b/plugins/pencilblue/templates/angular/admin/sites/edit_sites.html @@ -5,16 +5,16 @@ ^angular_objects^ ^tmp_angular=admin=elements=is_field_valid^ - $scope.addNewSite = function() { + $scope.editSite = function() { $scope.formSubmitted = true; - if(!validationService.isFormValid($scope.siteForm)) { + if(!validationService.isFormValid($scope.editSiteForm)) { return; } $scope.saving = true; - $http.post('/actions/admin/sites/new', $scope.siteEntity) + $http.post('/actions/admin/sites/edit/^siteid^', $scope.siteEntity) .success(function(result) { $scope.successMessage = result.message; $scope.saving = false; diff --git a/public/localization/en-us.js b/public/localization/en-us.js index b57655fe8..542ff56ce 100755 --- a/public/localization/en-us.js +++ b/public/localization/en-us.js @@ -430,14 +430,17 @@ var loc = }, sites: { EXISTING_HOSTNAME: 'That hostname is already in use', - EXISTING_DISPLAYNAME: 'There is already a site with that displayname', + EXISTING_DISPLAYNAME: 'That displayname is already in use', SITE_CREATED: 'The site was successfully created', ERROR_ACTIVATING: 'There was an error activating', ERROR_DEACTIVATING: 'There was an error deactivating', SITE_ACTIVATED: 'Site activated', SITE_DEACTIVATED: 'Site deactivated', ACTIVATE: 'Activate', - DEACTIVATE: 'Deactivate' + DEACTIVATE: 'Deactivate', + EDIT_SITE: 'Edit Site', + NEW_SITE: 'New Site', + SITE_UPDATED: 'Site was successfully updated' }, plugins: { From ba76852f7cdda9dfb417f4333ed78392d99e6ca5 Mon Sep 17 00:00:00 2001 From: iandtrapp Date: Tue, 16 Jun 2015 12:38:59 -0400 Subject: [PATCH 334/790] Removed white space --- .../controllers/actions/admin/sites/new_site_action.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/plugins/pencilblue/controllers/actions/admin/sites/new_site_action.js b/plugins/pencilblue/controllers/actions/admin/sites/new_site_action.js index 07f774a12..8c22cb457 100644 --- a/plugins/pencilblue/controllers/actions/admin/sites/new_site_action.js +++ b/plugins/pencilblue/controllers/actions/admin/sites/new_site_action.js @@ -31,8 +31,6 @@ module.exports = function(pb) { return; } - - var siteService = new pb.SiteService(); var site = pb.DocumentCreator.create('site', post); From d5cfa744ee010004bbb3aeb65f8ffd2f91ca45cd Mon Sep 17 00:00:00 2001 From: iandtrapp Date: Tue, 16 Jun 2015 13:07:45 -0400 Subject: [PATCH 335/790] Site activated/deactivated hostname change validation working --- plugins/pencilblue/controllers/admin/sites/edit_sites.js | 1 + plugins/pencilblue/templates/admin/sites/edit_sites.html | 7 ++++--- public/localization/en-us.js | 1 + 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/plugins/pencilblue/controllers/admin/sites/edit_sites.js b/plugins/pencilblue/controllers/admin/sites/edit_sites.js index 1f55a8301..65f3b4e13 100644 --- a/plugins/pencilblue/controllers/admin/sites/edit_sites.js +++ b/plugins/pencilblue/controllers/admin/sites/edit_sites.js @@ -19,6 +19,7 @@ module.exports = function(pb) { self.ts.registerLocal('display_name', data.displayName.toString()); self.ts.registerLocal('host_name', data.hostname.toString()); self.ts.registerLocal('siteid', id.toString()); + self.ts.registerLocal('isActive', data.active); self.ts.registerLocal('angular_objects', new pb.TemplateValue(angularObjects, false)); self.ts.load('admin/sites/edit_sites', function(err,result) { cb({content: result}); diff --git a/plugins/pencilblue/templates/admin/sites/edit_sites.html b/plugins/pencilblue/templates/admin/sites/edit_sites.html index 8aeaa303d..77d0c4cde 100644 --- a/plugins/pencilblue/templates/admin/sites/edit_sites.html +++ b/plugins/pencilblue/templates/admin/sites/edit_sites.html @@ -14,8 +14,9 @@
- -
^loc_REQUIRED_FIELD^
+ +
^loc_REQUIRED_FIELD^
+
^loc_SITE_MUST_DEACTIVATE^

@@ -28,6 +29,6 @@ ^tmp_admin=elements=progress_console_modal^ - ^TMP_ANGULAR=ADMIN=SITES=EDIT_SITES^ + ^tmp_angular=admin=sites=edit_sites^ ^tmp_admin=footer^
\ No newline at end of file diff --git a/public/localization/en-us.js b/public/localization/en-us.js index 542ff56ce..ccd8360ed 100755 --- a/public/localization/en-us.js +++ b/public/localization/en-us.js @@ -159,6 +159,7 @@ var loc = UNSUPPORTED_MEDIA: 'The supplied media type is unsupported', OBJECT_NOT_FOUND: 'The requested object was not found in the system', REQUIRED_FIELD: 'This field is required', + SITE_MUST_DEACTIVATE: 'This site must be deactivated before you can edit the hostname', INVALID_FILE: 'An invalid file was supplied', COMPLETE: 'Complete', WYSIWYG: 'WYSIWYG', From 273813fe30a588abcafab6b7968c6fd48ac07a93 Mon Sep 17 00:00:00 2001 From: iandtrapp Date: Tue, 16 Jun 2015 13:34:43 -0400 Subject: [PATCH 336/790] Value issue fixed and feature is fully functional --- plugins/pencilblue/controllers/admin/sites/edit_sites.js | 3 ++- plugins/pencilblue/templates/admin/sites/edit_sites.html | 4 ++-- .../pencilblue/templates/angular/admin/sites/edit_sites.html | 2 ++ 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/plugins/pencilblue/controllers/admin/sites/edit_sites.js b/plugins/pencilblue/controllers/admin/sites/edit_sites.js index 65f3b4e13..20a55cfaa 100644 --- a/plugins/pencilblue/controllers/admin/sites/edit_sites.js +++ b/plugins/pencilblue/controllers/admin/sites/edit_sites.js @@ -14,7 +14,8 @@ module.exports = function(pb) { dao.loadByValue('uid', id, 'site', function(err, data) { var angularObjects = pb.ClientJs.getAngularObjects({ navigation: pb.AdminNavigation.get(self.session, ['site_entity'], self.ls), - pills: pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, SUB_NAV_KEY) + pills: pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, SUB_NAV_KEY), + tabs: [{ active: 'active', href: '#editSite', icon: 'cog', title: self.ls.get('EDIT_SITE') }] }); self.ts.registerLocal('display_name', data.displayName.toString()); self.ts.registerLocal('host_name', data.hostname.toString()); diff --git a/plugins/pencilblue/templates/admin/sites/edit_sites.html b/plugins/pencilblue/templates/admin/sites/edit_sites.html index 77d0c4cde..6849b76a9 100644 --- a/plugins/pencilblue/templates/admin/sites/edit_sites.html +++ b/plugins/pencilblue/templates/admin/sites/edit_sites.html @@ -9,12 +9,12 @@
- +
^loc_REQUIRED_FIELD^
- +
^loc_REQUIRED_FIELD^
^loc_SITE_MUST_DEACTIVATE^
diff --git a/plugins/pencilblue/templates/angular/admin/sites/edit_sites.html b/plugins/pencilblue/templates/angular/admin/sites/edit_sites.html index 6863aff1b..e3f98ba20 100644 --- a/plugins/pencilblue/templates/angular/admin/sites/edit_sites.html +++ b/plugins/pencilblue/templates/angular/admin/sites/edit_sites.html @@ -5,7 +5,9 @@ ^angular_objects^ ^tmp_angular=admin=elements=is_field_valid^ + $scope.editSite = function() { + $scope.formSubmitted = true; if(!validationService.isFormValid($scope.editSiteForm)) { From f5805604ba72fc0a5638ec9ea806ecda73e43ba8 Mon Sep 17 00:00:00 2001 From: andparker Date: Tue, 16 Jun 2015 15:05:53 -0400 Subject: [PATCH 337/790] Updates more admin controllers to use the user service with site | Adds admin sub-nav site pill to email and users | Pulls global users through to site contexts --- include/service/entities/user_service.js | 6 +++++- .../controllers/admin/content/articles/article_form.js | 4 +++- .../pencilblue/controllers/admin/content/pages/page_form.js | 4 +++- plugins/pencilblue/controllers/admin/site_settings/email.js | 4 ++-- plugins/pencilblue/controllers/admin/users/manage_users.js | 2 +- plugins/pencilblue/controllers/admin/users/permissions.js | 6 ++++-- .../pencilblue/controllers/admin/users/unverified_users.js | 2 +- plugins/pencilblue/controllers/admin/users/user_form.js | 2 +- 8 files changed, 20 insertions(+), 10 deletions(-) diff --git a/include/service/entities/user_service.js b/include/service/entities/user_service.js index e0ea15469..0961bfb44 100755 --- a/include/service/entities/user_service.js +++ b/include/service/entities/user_service.js @@ -198,7 +198,11 @@ module.exports = function UserServiceModule(pb) { where: { admin: { $gte: getWriters ? pb.SecurityService.ACCESS_WRITER : pb.SecurityService.ACCESS_EDITOR - } + }, + $or: [ + { site: self.context.site }, + { site: pb.SiteService.GLOBAL_SITE} + ] } }; var dao = new pb.DAO(); diff --git a/plugins/pencilblue/controllers/admin/content/articles/article_form.js b/plugins/pencilblue/controllers/admin/content/articles/article_form.js index 99ced7609..987fd28d3 100755 --- a/plugins/pencilblue/controllers/admin/content/articles/article_form.js +++ b/plugins/pencilblue/controllers/admin/content/articles/article_form.js @@ -22,6 +22,7 @@ module.exports = function(pb) { //pb dependencies var util = pb.util; + var UserService = pb.UserService; /** * Interface for creating and editing articles @@ -49,7 +50,8 @@ module.exports = function(pb) { } if(self.session.authentication.user.admin >= pb.SecurityService.ACCESS_EDITOR) { - pb.users.getWriterOrEditorSelectList(self.article.author, true, function(err, availableAuthors) { + var userService = new UserService(self.getServiceContext()); + userService.getWriterOrEditorSelectList(self.article.author, true, function(err, availableAuthors) { if(availableAuthors && availableAuthors.length > 1) { results.availableAuthors = availableAuthors; } diff --git a/plugins/pencilblue/controllers/admin/content/pages/page_form.js b/plugins/pencilblue/controllers/admin/content/pages/page_form.js index daa3b6df7..764b7d206 100755 --- a/plugins/pencilblue/controllers/admin/content/pages/page_form.js +++ b/plugins/pencilblue/controllers/admin/content/pages/page_form.js @@ -22,6 +22,7 @@ module.exports = function(pb) { //pb dependencies var util = pb.util; + var UserService = pb.UserService; /** * Interface for creating and editing pages @@ -49,7 +50,8 @@ module.exports = function(pb) { } if(self.session.authentication.user.admin >= pb.SecurityService.ACCESS_EDITOR) { - pb.users.getWriterOrEditorSelectList(self.page.author, true, function(err, availableAuthors) { + var userService = new UserService(self.getServiceContext()); + userService.getWriterOrEditorSelectList(self.page.author, true, function(err, availableAuthors) { if(availableAuthors && availableAuthors.length > 1) { results.availableAuthors = availableAuthors; } diff --git a/plugins/pencilblue/controllers/admin/site_settings/email.js b/plugins/pencilblue/controllers/admin/site_settings/email.js index e02c05ecc..8ccd4c51c 100755 --- a/plugins/pencilblue/controllers/admin/site_settings/email.js +++ b/plugins/pencilblue/controllers/admin/site_settings/email.js @@ -25,7 +25,7 @@ module.exports = function(pb) { * Interface for the site's email settings */ function Email(){} - util.inherits(Email, pb.BaseController); + util.inherits(Email, pb.BaseAdminController); //statics var SUB_NAV_KEY = 'site_email_settings'; @@ -56,7 +56,7 @@ module.exports = function(pb) { emailService.getSettings(function(err, emailSettings) { var angularObjects = pb.ClientJs.getAngularObjects({ navigation: pb.AdminNavigation.get(self.session, ['settings', 'site_settings'], self.ls), - pills: pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, 'email', { site: self.site }), + pills: self.getAdminPills(SUB_NAV_KEY, self.ls, 'email', { site: self.site }), tabs: tabs, emailSettings: emailSettings }); diff --git a/plugins/pencilblue/controllers/admin/users/manage_users.js b/plugins/pencilblue/controllers/admin/users/manage_users.js index 53b53ef84..172a7d6e8 100755 --- a/plugins/pencilblue/controllers/admin/users/manage_users.js +++ b/plugins/pencilblue/controllers/admin/users/manage_users.js @@ -49,7 +49,7 @@ module.exports = function(pb) { var angularObjects = pb.ClientJs.getAngularObjects({ navigation: pb.AdminNavigation.get(self.session, ['users', 'manage'], self.ls), - pills: pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, SUB_NAV_KEY), + pills: self.getAdminPills(SUB_NAV_KEY, self.ls, SUB_NAV_KEY), users: users, currentUserId: self.session.authentication.user_id }); diff --git a/plugins/pencilblue/controllers/admin/users/permissions.js b/plugins/pencilblue/controllers/admin/users/permissions.js index 666b5db37..037b4ffe4 100755 --- a/plugins/pencilblue/controllers/admin/users/permissions.js +++ b/plugins/pencilblue/controllers/admin/users/permissions.js @@ -19,13 +19,13 @@ module.exports = function(pb) { //pb dependencies var util = pb.util; - var BaseController = pb.BaseController; + var BaseAdminController = pb.BaseAdminController; /** * Interface for displaying how a plugin's user permissions are organized */ function PermissionsMapController(){} - util.inherits(PermissionsMapController, BaseController); + util.inherits(PermissionsMapController, BaseAdminController); PermissionsMapController.prototype.render = function(cb) { var self = this; @@ -73,6 +73,8 @@ module.exports = function(pb) { href: '/admin/plugins' }]; + pills = pb.AdminSubnavService.addSiteToPills(pills, this.siteName); + var angularObjects = pb.ClientJs.getAngularObjects({ navigation: pb.AdminNavigation.get(this.session, ['users', 'permissions'], this.ls), pills: pills, diff --git a/plugins/pencilblue/controllers/admin/users/unverified_users.js b/plugins/pencilblue/controllers/admin/users/unverified_users.js index 9eadadf1c..9e6264b37 100644 --- a/plugins/pencilblue/controllers/admin/users/unverified_users.js +++ b/plugins/pencilblue/controllers/admin/users/unverified_users.js @@ -44,7 +44,7 @@ module.exports = function(pb) { var angularObjects = pb.ClientJs.getAngularObjects( { navigation: pb.AdminNavigation.get(self.session, ['users', 'manage'], self.ls), - pills: pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, SUB_NAV_KEY), + pills: self.getAdminPills(SUB_NAV_KEY, self.ls, SUB_NAV_KEY), users: users }); diff --git a/plugins/pencilblue/controllers/admin/users/user_form.js b/plugins/pencilblue/controllers/admin/users/user_form.js index 39eecaa1d..727f8c529 100644 --- a/plugins/pencilblue/controllers/admin/users/user_form.js +++ b/plugins/pencilblue/controllers/admin/users/user_form.js @@ -46,7 +46,7 @@ module.exports = function(pb) { } self.user = data.user; - data.pills = pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, SUB_NAV_KEY, {session: self.session, user: self.user}); + data.pills = self.getAdminPills(SUB_NAV_KEY, self.ls, SUB_NAV_KEY, {session: self.session, user: self.user}); data.adminOptions = [{name: self.ls.get('ADMINISTRATOR'), value: pb.SecurityService.ACCESS_ADMINISTRATOR}]; if(!data.user[pb.DAO.getIdField()] || self.session.authentication.user_id !== data.user[pb.DAO.getIdField()].toString()) { From d9a83edea8d7fbf073f3dbc2f1d91e5a4c083366 Mon Sep 17 00:00:00 2001 From: btidwell Date: Tue, 16 Jun 2015 15:17:47 -0400 Subject: [PATCH 338/790] add userService with context to nav_item_form --- .../controllers/admin/content/navigation/nav_item_form.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/pencilblue/controllers/admin/content/navigation/nav_item_form.js b/plugins/pencilblue/controllers/admin/content/navigation/nav_item_form.js index a039a4acd..25944166d 100644 --- a/plugins/pencilblue/controllers/admin/content/navigation/nav_item_form.js +++ b/plugins/pencilblue/controllers/admin/content/navigation/nav_item_form.js @@ -73,11 +73,12 @@ module.exports = function(pb) { NavItemFormController.prototype.gatherData = function(vars, cb) { var self = this; + var userService = new pb.UserService(self.getServiceContext()); var tasks = { //get editors editors: function(callback) { - pb.users.getWriterOrEditorSelectList(self.session.authentication.user_id, false, callback); + userService.getWriterOrEditorSelectList(self.session.authentication.user_id, false, callback); }, //get parents From db3bec2c06e5c974bd8c5baa41c06fcdbdd40d3d Mon Sep 17 00:00:00 2001 From: andparker Date: Tue, 16 Jun 2015 15:40:55 -0400 Subject: [PATCH 339/790] Changes site query service usage back to dao for loading comment details. --- .../controllers/admin/content/comments/manage_comments.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/plugins/pencilblue/controllers/admin/content/comments/manage_comments.js b/plugins/pencilblue/controllers/admin/content/comments/manage_comments.js index 92ff83b9f..db3131ce7 100755 --- a/plugins/pencilblue/controllers/admin/content/comments/manage_comments.js +++ b/plugins/pencilblue/controllers/admin/content/comments/manage_comments.js @@ -99,12 +99,13 @@ module.exports = function(pb) { } this.getCommentingUser = function(index) { - self.siteQueryService.__proto__.loadById(comments[index].commenter, 'user', function(err, user) { + self.dao = new pb.DAO(); + self.dao.__proto__.loadById(comments[index].commenter, 'user', function(err, user) { if(!util.isError(err) && user !== null) { comments[index].user_name = user.first_name + ' ' + user.last_name; } - self.siteQueryService.loadById(comments[index].article, 'article', function(err, article) { + self.dao.loadById(comments[index].article, 'article', function(err, article) { if(!util.isError(err) && article !== null) { comments[index].article_url = article.url; comments[index].article_headline = article.headline; From 9d07dadb9172011f83eb16adae470cde07cf36e4 Mon Sep 17 00:00:00 2001 From: andparker Date: Tue, 16 Jun 2015 17:26:50 -0400 Subject: [PATCH 340/790] More user service site tweaks. --- include/service/entities/user_service.js | 5 +++-- .../controllers/admin/content/articles/manage_articles.js | 4 +++- .../controllers/admin/content/pages/manage_pages.js | 4 +++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/include/service/entities/user_service.js b/include/service/entities/user_service.js index 0961bfb44..dd69b73d5 100755 --- a/include/service/entities/user_service.js +++ b/include/service/entities/user_service.js @@ -111,7 +111,7 @@ module.exports = function UserServiceModule(pb) { }, where: pb.DAO.getIdInWhere(Object.keys(authorIds)) }; - var dao = new pb.DAO(); + var dao = new pb.SiteQueryService(this.context.site); dao.q('user', opts, function(err, authors) { if (util.isError(err)) { return cb(err); @@ -201,7 +201,8 @@ module.exports = function UserServiceModule(pb) { }, $or: [ { site: self.context.site }, - { site: pb.SiteService.GLOBAL_SITE} + { site: pb.SiteService.GLOBAL_SITE }, + { site: { $exists: false } } ] } }; diff --git a/plugins/pencilblue/controllers/admin/content/articles/manage_articles.js b/plugins/pencilblue/controllers/admin/content/articles/manage_articles.js index ffa254e53..5d090794f 100755 --- a/plugins/pencilblue/controllers/admin/content/articles/manage_articles.js +++ b/plugins/pencilblue/controllers/admin/content/articles/manage_articles.js @@ -19,6 +19,7 @@ module.exports = function(pb) { //pb dependencies var util = pb.util; + var UserService = pb.UserService; /** * Interface for managing articles @@ -50,7 +51,8 @@ module.exports = function(pb) { return self.redirect('/admin/content/articles/new', cb); } - pb.users.getAuthors(articles, function(err, articlesWithAuthorNames) { + var userService = new UserService(self.getServiceContext()); + userService.getAuthors(articles, function(err, articlesWithAuthorNames) { articles = self.getArticleStatuses(articlesWithAuthorNames); self.getAngularObjects(self.site, articles, function (angularObjects) { var manageArticlesStr = self.ls.get('MANAGE_ARTICLES'); diff --git a/plugins/pencilblue/controllers/admin/content/pages/manage_pages.js b/plugins/pencilblue/controllers/admin/content/pages/manage_pages.js index 567bb89fc..f5c55f3ae 100755 --- a/plugins/pencilblue/controllers/admin/content/pages/manage_pages.js +++ b/plugins/pencilblue/controllers/admin/content/pages/manage_pages.js @@ -19,6 +19,7 @@ module.exports = function(pb) { //pb dependencies var util = pb.util; + var UserService = pb.UserService; /** * Interface for managing pages @@ -45,7 +46,8 @@ module.exports = function(pb) { return self.redirect('/admin/content/pages/new', cb); } - pb.users.getAuthors(pages, function(err, pagesWithAuthor) { + var userService = new UserService(self.getServiceContext()); + userService.getAuthors(pages, function(err, pagesWithAuthor) { self.getAngularObjects(pagesWithAuthor, function(angularObjects) { var title = self.ls.get('MANAGE_PAGES'); self.setPageName(title); From c385f3b96c897236beaba8feecf6da5cabde9fbc Mon Sep 17 00:00:00 2001 From: iandtrapp Date: Wed, 17 Jun 2015 10:15:40 -0400 Subject: [PATCH 341/790] Added db index for unique hostname, finishing up error checking --- include/config.js | 7 ++++ .../actions/admin/sites/edit_site_action.js | 38 ++++++++++++++----- .../actions/admin/sites/new_site_action.js | 4 +- .../templates/admin/sites/edit_sites.html | 12 +++--- .../templates/admin/sites/site_form.html | 8 ++-- .../angular/admin/sites/edit_sites.html | 5 +-- .../angular/admin/sites/site_form.html | 1 - public/localization/en-us.js | 3 +- 8 files changed, 51 insertions(+), 27 deletions(-) diff --git a/include/config.js b/include/config.js index 5202a1bad..ecfdf0e00 100755 --- a/include/config.js +++ b/include/config.js @@ -490,6 +490,13 @@ var BASE_CONFIG = { collection: 'lock', spec: {timeout: ASC}, options: {expireAfterSeconds: 0} + }, + + //site + { + collection: 'site', + spec: {hostname: ASC}, + options: {unique: true} } ] }, diff --git a/plugins/pencilblue/controllers/actions/admin/sites/edit_site_action.js b/plugins/pencilblue/controllers/actions/admin/sites/edit_site_action.js index fd25eb0be..9c78b3c68 100644 --- a/plugins/pencilblue/controllers/actions/admin/sites/edit_site_action.js +++ b/plugins/pencilblue/controllers/actions/admin/sites/edit_site_action.js @@ -31,21 +31,39 @@ module.exports = function(pb) { return; } + siteService = new pb.SiteService(); var dao = new pb.DAO(); dao.loadByValue('uid', siteid, 'site', function(err, data) { - data.displayName = post.displayName; - data.hostname = post.hostname; - dao.save(data, function(err, result) { - if(err) { - cb({ - code: 400, - content: pb.BaseController.apiResponse(pb.BaseController.API_ERROR, self.ls.get('ERROR SAVING')) + siteService.isDisplayNameOrHostnameTaken(post.displayName, post.hostname, data.id, function (err, isTaken, field) { + if(isTaken) { + if(field == 'displayName') { + cb({ + code: 400, + content: pb.BaseController.apiResponse(pb.BaseController.API_ERROR, self.ls.get('DUPLICATE_INFO')) + }); + } else { + cb({ + code: 400, + content: pb.BaseController.apiResponse(pb.BaseController.API_ERROR, self.ls.get('DUPLICATE_INFO')) + }); + } + } else { + data.displayName = post.displayName; + data.hostname = post.hostname; + dao.save(data, function(err, result) { + if(err) { + cb({ + code: 400, + content: pb.BaseController.apiResponse(pb.BaseController.API_ERROR, self.ls.get('ERROR SAVING')) + }); + return; + } + cb({content: pb.BaseController.apiResponse(pb.BaseController.API_SUCCESS, self.ls.get('SITE_UPDATED'), result)}); }); - return; } - cb({content: pb.BaseController.apiResponse(pb.BaseController.API_SUCCESS, self.ls.get('SITE_UPDATED'), result)}); + }); - }); + }) }); diff --git a/plugins/pencilblue/controllers/actions/admin/sites/new_site_action.js b/plugins/pencilblue/controllers/actions/admin/sites/new_site_action.js index 8c22cb457..8dd028459 100644 --- a/plugins/pencilblue/controllers/actions/admin/sites/new_site_action.js +++ b/plugins/pencilblue/controllers/actions/admin/sites/new_site_action.js @@ -39,12 +39,12 @@ module.exports = function(pb) { if(field === 'hostname') { cb({ code: 400, - content: pb.BaseController.apiResponse(pb.BaseController.API_ERROR, self.ls.get('EXISTING_HOSTNAME')) + content: pb.BaseController.apiResponse(pb.BaseController.API_ERROR, self.ls.get('DUPLICATE_INFO')) }); } else { cb({ code: 400, - content: pb.BaseController.apiResponse(pb.BaseController.API_ERROR, self.ls.get('EXISTING_DISPLAYNAME')) + content: pb.BaseController.apiResponse(pb.BaseController.API_ERROR, self.ls.get('DUPLICATE_INFO')) }); } } diff --git a/plugins/pencilblue/templates/admin/sites/edit_sites.html b/plugins/pencilblue/templates/admin/sites/edit_sites.html index 6849b76a9..5efdad6fc 100644 --- a/plugins/pencilblue/templates/admin/sites/edit_sites.html +++ b/plugins/pencilblue/templates/admin/sites/edit_sites.html @@ -3,19 +3,19 @@ ^tmp_admin=elements=error_success^ ^tmp_admin=elements=sub_nav^ ^tmp_admin=elements=tab_nav^ -
+
-
+
- -
^loc_REQUIRED_FIELD^
+ +
^loc_REQUIRED_FIELD^
- -
^loc_REQUIRED_FIELD^
+ +
^loc_REQUIRED_FIELD^
^loc_SITE_MUST_DEACTIVATE^
diff --git a/plugins/pencilblue/templates/admin/sites/site_form.html b/plugins/pencilblue/templates/admin/sites/site_form.html index 19ed4d4e2..67fd5ba87 100644 --- a/plugins/pencilblue/templates/admin/sites/site_form.html +++ b/plugins/pencilblue/templates/admin/sites/site_form.html @@ -28,6 +28,8 @@ ^tmp_admin=elements=progress_console_modal^ -^tmp_angular=admin=sites=site_form^ -^tmp_admin=footer^ -
\ No newline at end of file + ^tmp_angular=admin=sites=site_form^ + ^tmp_admin=footer^ +
+ + diff --git a/plugins/pencilblue/templates/angular/admin/sites/edit_sites.html b/plugins/pencilblue/templates/angular/admin/sites/edit_sites.html index e3f98ba20..48573fcb8 100644 --- a/plugins/pencilblue/templates/angular/admin/sites/edit_sites.html +++ b/plugins/pencilblue/templates/angular/admin/sites/edit_sites.html @@ -5,12 +5,10 @@ ^angular_objects^ ^tmp_angular=admin=elements=is_field_valid^ - $scope.editSite = function() { - $scope.formSubmitted = true; - if(!validationService.isFormValid($scope.editSiteForm)) { + if(!validationService.isFormValid($scope.siteForm)) { return; } @@ -21,7 +19,6 @@ $scope.successMessage = result.message; $scope.saving = false; $scope.onActionSuccess(); - $scope.$apply(); }) .error(function(error, status) { $scope.errorMessage = error.message; diff --git a/plugins/pencilblue/templates/angular/admin/sites/site_form.html b/plugins/pencilblue/templates/angular/admin/sites/site_form.html index 6d28b2e1d..26f0faadd 100644 --- a/plugins/pencilblue/templates/angular/admin/sites/site_form.html +++ b/plugins/pencilblue/templates/angular/admin/sites/site_form.html @@ -19,7 +19,6 @@ $scope.successMessage = result.message; $scope.saving = false; $scope.onActionSuccess(); - $scope.$apply(); }) .error(function(error, status) { $scope.errorMessage = error.message; diff --git a/public/localization/en-us.js b/public/localization/en-us.js index ccd8360ed..02b703c99 100755 --- a/public/localization/en-us.js +++ b/public/localization/en-us.js @@ -431,7 +431,8 @@ var loc = }, sites: { EXISTING_HOSTNAME: 'That hostname is already in use', - EXISTING_DISPLAYNAME: 'That displayname is already in use', + EXISTING_DISPLAYNAME: 'That display name is already in use', + DUPLICATE_INFO: 'Each site must have a unique hostname', SITE_CREATED: 'The site was successfully created', ERROR_ACTIVATING: 'There was an error activating', ERROR_DEACTIVATING: 'There was an error deactivating', From 94ab4e29faaf618c6044a5b68b26933add3d69fe Mon Sep 17 00:00:00 2001 From: iandtrapp Date: Wed, 17 Jun 2015 10:54:07 -0400 Subject: [PATCH 342/790] Consistent error checking accross the board --- .../actions/admin/sites/edit_site_action.js | 16 +++++----------- .../actions/admin/sites/new_site_action.js | 12 +++--------- 2 files changed, 8 insertions(+), 20 deletions(-) diff --git a/plugins/pencilblue/controllers/actions/admin/sites/edit_site_action.js b/plugins/pencilblue/controllers/actions/admin/sites/edit_site_action.js index 9c78b3c68..dc799cc02 100644 --- a/plugins/pencilblue/controllers/actions/admin/sites/edit_site_action.js +++ b/plugins/pencilblue/controllers/actions/admin/sites/edit_site_action.js @@ -31,22 +31,16 @@ module.exports = function(pb) { return; } - siteService = new pb.SiteService(); + var siteService = new pb.SiteService(); var dao = new pb.DAO(); dao.loadByValue('uid', siteid, 'site', function(err, data) { - siteService.isDisplayNameOrHostnameTaken(post.displayName, post.hostname, data.id, function (err, isTaken, field) { + siteService.isDisplayNameOrHostnameTaken(post.displayName, post.hostname, data._id, function (err, isTaken, field) { if(isTaken) { - if(field == 'displayName') { - cb({ + cb({ code: 400, content: pb.BaseController.apiResponse(pb.BaseController.API_ERROR, self.ls.get('DUPLICATE_INFO')) - }); - } else { - cb({ - code: 400, - content: pb.BaseController.apiResponse(pb.BaseController.API_ERROR, self.ls.get('DUPLICATE_INFO')) - }); - } + }); + } else { data.displayName = post.displayName; data.hostname = post.hostname; diff --git a/plugins/pencilblue/controllers/actions/admin/sites/new_site_action.js b/plugins/pencilblue/controllers/actions/admin/sites/new_site_action.js index 8dd028459..7e77a2c8b 100644 --- a/plugins/pencilblue/controllers/actions/admin/sites/new_site_action.js +++ b/plugins/pencilblue/controllers/actions/admin/sites/new_site_action.js @@ -36,17 +36,11 @@ module.exports = function(pb) { siteService.createSite(site, post.id, function(err, isTaken, field, result) { if(isTaken) { - if(field === 'hostname') { - cb({ - code: 400, - content: pb.BaseController.apiResponse(pb.BaseController.API_ERROR, self.ls.get('DUPLICATE_INFO')) - }); - } else { - cb({ + cb({ code: 400, content: pb.BaseController.apiResponse(pb.BaseController.API_ERROR, self.ls.get('DUPLICATE_INFO')) - }); - } + }); + } if(util.isError(err)) { cb({ From cb5e0cfdb9db0336044f2b8f262152d2c4fc042b Mon Sep 17 00:00:00 2001 From: iandtrapp Date: Wed, 17 Jun 2015 12:24:19 -0400 Subject: [PATCH 343/790] Named edit site functions --- .../actions/admin/sites/delete_site_action.js | 52 +++++++++++++++++++ .../actions/admin/sites/edit_site_action.js | 2 +- .../controllers/admin/sites/edit_sites.js | 2 +- plugins/pencilblue/include/routes.js | 7 +++ .../templates/admin/sites/manage_sites.html | 1 + .../angular/admin/sites/manage_sites.html | 13 +++++ 6 files changed, 75 insertions(+), 2 deletions(-) create mode 100644 plugins/pencilblue/controllers/actions/admin/sites/delete_site_action.js diff --git a/plugins/pencilblue/controllers/actions/admin/sites/delete_site_action.js b/plugins/pencilblue/controllers/actions/admin/sites/delete_site_action.js new file mode 100644 index 000000000..23fb4c70c --- /dev/null +++ b/plugins/pencilblue/controllers/actions/admin/sites/delete_site_action.js @@ -0,0 +1,52 @@ +module.exports = function(pb) { + + //pb dependencies + var util = pb.util; + + /** + * Deletes a current site + */ + function DeleteSiteAction(){} + util.inherits(DeleteSiteAction, pb.BaseController); + + DeleteSiteAction.prototype.render = function(cb) { + var self = this; + var siteid = this.pathVars.siteid; + this.getJSONPostParams(function(err, post) { + if(message) { + cb({ + code: 400, + content: pb.BaseController.apiResponse(pb.BaseController.API_ERROR, message) + }); + return; + } + + if(!pb.security.isAuthorized(self.session, {admin_level: post.admin})) { + cb({ + code: 400, + content: pb.BaseController.apiResponse(pb.BaseController.API_ERROR, self.ls.get('INSUFFICIENT_CREDENTIALS')) + }); + return; + } + + var dao = new pb.DAO(); + dao.loadByValue('uid', siteid, 'site', function(err, data) { + dao.delete({uid: siteid}, 'site', function(err, result) { + if(util.isError(err)) { + cb({ + code: 400, + content: pb.BaseController.apiResponse(pb.BaseController.API_ERROR, self.ls.get('ERROR_DELETING')) + }); + return; + } + cb({content: pb.BaseController.apiResponse(pb.BaseController.API_SUCCESS, self.ls.get('SITE_DELETED'), result)}); + }); + }) + + }); + + }; + + //exports + return DeleteSiteAction; +}; \ No newline at end of file diff --git a/plugins/pencilblue/controllers/actions/admin/sites/edit_site_action.js b/plugins/pencilblue/controllers/actions/admin/sites/edit_site_action.js index dc799cc02..2f03f0437 100644 --- a/plugins/pencilblue/controllers/actions/admin/sites/edit_site_action.js +++ b/plugins/pencilblue/controllers/actions/admin/sites/edit_site_action.js @@ -1,4 +1,4 @@ -module.exports = function(pb) { +module.exports = function EditSitesActionModule(pb) { //pb dependencies var util = pb.util; diff --git a/plugins/pencilblue/controllers/admin/sites/edit_sites.js b/plugins/pencilblue/controllers/admin/sites/edit_sites.js index 20a55cfaa..0751f6f65 100644 --- a/plugins/pencilblue/controllers/admin/sites/edit_sites.js +++ b/plugins/pencilblue/controllers/admin/sites/edit_sites.js @@ -1,4 +1,4 @@ -module.exports = function(pb) { +module.exports = function EditSitesModuel(pb) { var util = pb.util; diff --git a/plugins/pencilblue/include/routes.js b/plugins/pencilblue/include/routes.js index 42a6ad763..1b81d0065 100644 --- a/plugins/pencilblue/include/routes.js +++ b/plugins/pencilblue/include/routes.js @@ -1051,6 +1051,13 @@ module.exports = function Routes(pb){ auth_required: true, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'sites', 'deactivate_site.js') }, + { + method: 'post', + path: "/actions/admin/sites/delete/:siteid", + access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, + auth_required: true, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'sites', 'delete_site_action.js') + }, //**********************API************************ diff --git a/plugins/pencilblue/templates/admin/sites/manage_sites.html b/plugins/pencilblue/templates/admin/sites/manage_sites.html index b5fce1c65..199acb2ad 100644 --- a/plugins/pencilblue/templates/admin/sites/manage_sites.html +++ b/plugins/pencilblue/templates/admin/sites/manage_sites.html @@ -61,6 +61,7 @@
diff --git a/plugins/pencilblue/templates/angular/admin/sites/manage_sites.html b/plugins/pencilblue/templates/angular/admin/sites/manage_sites.html index 37a4f728b..63555ab56 100644 --- a/plugins/pencilblue/templates/angular/admin/sites/manage_sites.html +++ b/plugins/pencilblue/templates/angular/admin/sites/manage_sites.html @@ -36,6 +36,19 @@ }); }; + $scope.deleteSite = function(site) { + $http.post('/actions/admin/sites/delete/' + site.uid) + .success(function(result) { + $scope.successMessage = result.message; + $scope.saving = false; + $scope.onActionSuccess(); + }) + .error(function(error, status) { + $scope.errorMessage = error.message; + $scope.saving = false; + }); + }; + $scope.jobAction = function(actionType, identifier, data, cb) { $http.post("/api/jobs/" + actionType + "/" + encodeURIComponent(identifier), data) .success(function(result) { From 119c85b79d89cda8fa9b54443f84807a6e1400e4 Mon Sep 17 00:00:00 2001 From: iandtrapp Date: Wed, 17 Jun 2015 12:59:57 -0400 Subject: [PATCH 344/790] Revert "Named edit site functions" This reverts commit cb5e0cfdb9db0336044f2b8f262152d2c4fc042b. --- .../actions/admin/sites/delete_site_action.js | 52 ------------------- .../actions/admin/sites/edit_site_action.js | 2 +- .../controllers/admin/sites/edit_sites.js | 2 +- plugins/pencilblue/include/routes.js | 7 --- .../templates/admin/sites/manage_sites.html | 1 - .../angular/admin/sites/manage_sites.html | 13 ----- 6 files changed, 2 insertions(+), 75 deletions(-) delete mode 100644 plugins/pencilblue/controllers/actions/admin/sites/delete_site_action.js diff --git a/plugins/pencilblue/controllers/actions/admin/sites/delete_site_action.js b/plugins/pencilblue/controllers/actions/admin/sites/delete_site_action.js deleted file mode 100644 index 23fb4c70c..000000000 --- a/plugins/pencilblue/controllers/actions/admin/sites/delete_site_action.js +++ /dev/null @@ -1,52 +0,0 @@ -module.exports = function(pb) { - - //pb dependencies - var util = pb.util; - - /** - * Deletes a current site - */ - function DeleteSiteAction(){} - util.inherits(DeleteSiteAction, pb.BaseController); - - DeleteSiteAction.prototype.render = function(cb) { - var self = this; - var siteid = this.pathVars.siteid; - this.getJSONPostParams(function(err, post) { - if(message) { - cb({ - code: 400, - content: pb.BaseController.apiResponse(pb.BaseController.API_ERROR, message) - }); - return; - } - - if(!pb.security.isAuthorized(self.session, {admin_level: post.admin})) { - cb({ - code: 400, - content: pb.BaseController.apiResponse(pb.BaseController.API_ERROR, self.ls.get('INSUFFICIENT_CREDENTIALS')) - }); - return; - } - - var dao = new pb.DAO(); - dao.loadByValue('uid', siteid, 'site', function(err, data) { - dao.delete({uid: siteid}, 'site', function(err, result) { - if(util.isError(err)) { - cb({ - code: 400, - content: pb.BaseController.apiResponse(pb.BaseController.API_ERROR, self.ls.get('ERROR_DELETING')) - }); - return; - } - cb({content: pb.BaseController.apiResponse(pb.BaseController.API_SUCCESS, self.ls.get('SITE_DELETED'), result)}); - }); - }) - - }); - - }; - - //exports - return DeleteSiteAction; -}; \ No newline at end of file diff --git a/plugins/pencilblue/controllers/actions/admin/sites/edit_site_action.js b/plugins/pencilblue/controllers/actions/admin/sites/edit_site_action.js index 2f03f0437..dc799cc02 100644 --- a/plugins/pencilblue/controllers/actions/admin/sites/edit_site_action.js +++ b/plugins/pencilblue/controllers/actions/admin/sites/edit_site_action.js @@ -1,4 +1,4 @@ -module.exports = function EditSitesActionModule(pb) { +module.exports = function(pb) { //pb dependencies var util = pb.util; diff --git a/plugins/pencilblue/controllers/admin/sites/edit_sites.js b/plugins/pencilblue/controllers/admin/sites/edit_sites.js index 0751f6f65..20a55cfaa 100644 --- a/plugins/pencilblue/controllers/admin/sites/edit_sites.js +++ b/plugins/pencilblue/controllers/admin/sites/edit_sites.js @@ -1,4 +1,4 @@ -module.exports = function EditSitesModuel(pb) { +module.exports = function(pb) { var util = pb.util; diff --git a/plugins/pencilblue/include/routes.js b/plugins/pencilblue/include/routes.js index 1b81d0065..42a6ad763 100644 --- a/plugins/pencilblue/include/routes.js +++ b/plugins/pencilblue/include/routes.js @@ -1051,13 +1051,6 @@ module.exports = function Routes(pb){ auth_required: true, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'sites', 'deactivate_site.js') }, - { - method: 'post', - path: "/actions/admin/sites/delete/:siteid", - access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, - auth_required: true, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'sites', 'delete_site_action.js') - }, //**********************API************************ diff --git a/plugins/pencilblue/templates/admin/sites/manage_sites.html b/plugins/pencilblue/templates/admin/sites/manage_sites.html index 199acb2ad..b5fce1c65 100644 --- a/plugins/pencilblue/templates/admin/sites/manage_sites.html +++ b/plugins/pencilblue/templates/admin/sites/manage_sites.html @@ -61,7 +61,6 @@
diff --git a/plugins/pencilblue/templates/angular/admin/sites/manage_sites.html b/plugins/pencilblue/templates/angular/admin/sites/manage_sites.html index 63555ab56..37a4f728b 100644 --- a/plugins/pencilblue/templates/angular/admin/sites/manage_sites.html +++ b/plugins/pencilblue/templates/angular/admin/sites/manage_sites.html @@ -36,19 +36,6 @@ }); }; - $scope.deleteSite = function(site) { - $http.post('/actions/admin/sites/delete/' + site.uid) - .success(function(result) { - $scope.successMessage = result.message; - $scope.saving = false; - $scope.onActionSuccess(); - }) - .error(function(error, status) { - $scope.errorMessage = error.message; - $scope.saving = false; - }); - }; - $scope.jobAction = function(actionType, identifier, data, cb) { $http.post("/api/jobs/" + actionType + "/" + encodeURIComponent(identifier), data) .success(function(result) { From b292d7c00c060fad6be86f75790627829ab2fb1e Mon Sep 17 00:00:00 2001 From: iandtrapp Date: Wed, 17 Jun 2015 13:23:02 -0400 Subject: [PATCH 345/790] Renamed functions --- .../controllers/actions/admin/sites/edit_site_action.js | 2 +- .../controllers/actions/admin/sites/new_site_action.js | 2 +- plugins/pencilblue/controllers/admin/sites/edit_sites.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/pencilblue/controllers/actions/admin/sites/edit_site_action.js b/plugins/pencilblue/controllers/actions/admin/sites/edit_site_action.js index dc799cc02..1fd89e56d 100644 --- a/plugins/pencilblue/controllers/actions/admin/sites/edit_site_action.js +++ b/plugins/pencilblue/controllers/actions/admin/sites/edit_site_action.js @@ -1,4 +1,4 @@ -module.exports = function(pb) { +module.exports = function EditSiteActionModule(pb) { //pb dependencies var util = pb.util; diff --git a/plugins/pencilblue/controllers/actions/admin/sites/new_site_action.js b/plugins/pencilblue/controllers/actions/admin/sites/new_site_action.js index 7e77a2c8b..380b108b4 100644 --- a/plugins/pencilblue/controllers/actions/admin/sites/new_site_action.js +++ b/plugins/pencilblue/controllers/actions/admin/sites/new_site_action.js @@ -1,4 +1,4 @@ -module.exports = function(pb) { +module.exports = function NewSiteActionModule(pb) { //pb dependencies var util = pb.util; diff --git a/plugins/pencilblue/controllers/admin/sites/edit_sites.js b/plugins/pencilblue/controllers/admin/sites/edit_sites.js index 20a55cfaa..0b61f707f 100644 --- a/plugins/pencilblue/controllers/admin/sites/edit_sites.js +++ b/plugins/pencilblue/controllers/admin/sites/edit_sites.js @@ -1,4 +1,4 @@ -module.exports = function(pb) { +module.exports = function EditSitesModule(pb) { var util = pb.util; From 250aee46ea8fe0dc92285412b755789cc292ba69 Mon Sep 17 00:00:00 2001 From: andparker Date: Wed, 17 Jun 2015 15:07:21 -0400 Subject: [PATCH 346/790] Removes admin form controller and usages. --- controllers/admin/admin_form_controller.js | 44 ------------------- include/requirements.js | 1 - .../admin/content/media/delete_media.js | 4 +- .../admin/content/objects/sort_objects.js | 2 +- .../content/objects/types/delete_type.js | 2 +- .../admin/content/objects/types/available.js | 2 +- 6 files changed, 5 insertions(+), 50 deletions(-) delete mode 100644 controllers/admin/admin_form_controller.js diff --git a/controllers/admin/admin_form_controller.js b/controllers/admin/admin_form_controller.js deleted file mode 100644 index 6024ae081..000000000 --- a/controllers/admin/admin_form_controller.js +++ /dev/null @@ -1,44 +0,0 @@ -/* - Copyright (C) 2015 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 - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . - */ - -module.exports = function AdminFormControllerModule(pb) { - "use strict"; - - var util = pb.util; - var BaseAdminController = pb.BaseAdminController; - - function AdminFormController() { - } - util.inherits(AdminFormController, pb.FormController); - - /** - * @override - * @param props - * @param cb - */ - AdminFormController.prototype.init = function (props, cb) { - var self = this; - self.site = pb.SiteService.getCurrentSite(props.site); - pb.FormController.prototype.init.call(self, props, function () { - BaseAdminController.prototype.extendedInit.call(self, cb); - }); - }; - - AdminFormController.prototype.getAdminPills = BaseAdminController.prototype.getAdminPills; - - return AdminFormController; -}; \ No newline at end of file diff --git a/include/requirements.js b/include/requirements.js index ba6cf30b1..073115d05 100755 --- a/include/requirements.js +++ b/include/requirements.js @@ -126,7 +126,6 @@ module.exports = function PB(config) { pb.BaseAdminController = require(path.join(config.docRoot, '/controllers/admin/base_admin_controller.js'))(pb); pb.ViewController = require(path.join(config.docRoot, '/controllers/view_controller.js'))(pb); pb.FormController = require(path.join(config.docRoot, '/controllers/form_controller.js'))(pb); - pb.AdminFormController = require(path.join(config.docRoot, '/controllers/admin/admin_form_controller.js'))(pb); pb.DeleteController = require(path.join(config.docRoot, '/controllers/delete_controller.js'))(pb); pb.ApiActionController = require(path.join(config.docRoot, '/controllers/api/api_action_controller.js'))(pb); pb.RequestHandler = require(path.join(config.docRoot, '/include/http/request_handler.js'))(pb); diff --git a/plugins/pencilblue/controllers/actions/admin/content/media/delete_media.js b/plugins/pencilblue/controllers/actions/admin/content/media/delete_media.js index 41bed32bd..e63a76294 100755 --- a/plugins/pencilblue/controllers/actions/admin/content/media/delete_media.js +++ b/plugins/pencilblue/controllers/actions/admin/content/media/delete_media.js @@ -24,10 +24,10 @@ module.exports = function(pb) { * Deletes media * @class DeleteMediaController * @constructor - * @extends AdminFormController + * @extends FormController */ function DeleteMediaController(){} - util.inherits(DeleteMediaController, pb.AdminFormController); + util.inherits(DeleteMediaController, pb.FormController); //constants var MANAGE_MEDIA_PATH = '/admin/content/media/manage_media'; diff --git a/plugins/pencilblue/controllers/actions/admin/content/objects/sort_objects.js b/plugins/pencilblue/controllers/actions/admin/content/objects/sort_objects.js index b84d03093..c9b9cbd4e 100644 --- a/plugins/pencilblue/controllers/actions/admin/content/objects/sort_objects.js +++ b/plugins/pencilblue/controllers/actions/admin/content/objects/sort_objects.js @@ -26,7 +26,7 @@ module.exports = function(pb) { * @constructor */ function SortObjectsActionController(){} - util.inherits(SortObjectsActionController, pb.AdminFormController); + util.inherits(SortObjectsActionController, pb.FormController); SortObjectsActionController.prototype.render = function(cb) { var self = this; diff --git a/plugins/pencilblue/controllers/actions/admin/content/objects/types/delete_type.js b/plugins/pencilblue/controllers/actions/admin/content/objects/types/delete_type.js index d93953f09..95a8f98cc 100644 --- a/plugins/pencilblue/controllers/actions/admin/content/objects/types/delete_type.js +++ b/plugins/pencilblue/controllers/actions/admin/content/objects/types/delete_type.js @@ -24,7 +24,7 @@ module.exports = function(pb) { * Deletes an object type */ function DeleteObjectType(){} - util.inherits(DeleteObjectType, pb.AdminFormController); + util.inherits(DeleteObjectType, pb.FormController); DeleteObjectType.prototype.onPostParamsRetrieved = function(post, cb) { var self = this; diff --git a/plugins/pencilblue/controllers/api/admin/content/objects/types/available.js b/plugins/pencilblue/controllers/api/admin/content/objects/types/available.js index 120018c48..554f0275e 100644 --- a/plugins/pencilblue/controllers/api/admin/content/objects/types/available.js +++ b/plugins/pencilblue/controllers/api/admin/content/objects/types/available.js @@ -24,7 +24,7 @@ module.exports = function(pb) { * Checks to see if the proposed name for a custom object type is available */ function GetObjectTypeNameAvailable(){} - util.inherits(GetObjectTypeNameAvailable, pb.AdminFormController); + util.inherits(GetObjectTypeNameAvailable, pb.FormController); GetObjectTypeNameAvailable.prototype.render = function(cb) { var self = this; From 8eba0e9e9aaceb7edca63669a383756739ff7f34 Mon Sep 17 00:00:00 2001 From: andparker Date: Wed, 17 Jun 2015 16:23:49 -0400 Subject: [PATCH 347/790] Removes multi-site admin routes | Cleans up any remaining path-site or prefix code --- include/admin_navigation.js | 3 +- include/service/entities/section_service.js | 4 - include/service/entities/site_service.js | 18 - .../admin/content/objects/object_form.js | 2 +- .../include/multisite_admin_routes.js | 611 ------------------ plugins/pencilblue/include/routes.js | 8 +- .../admin/content/media/media_form.html | 2 +- public/js/angular/services/media.js | 9 +- 8 files changed, 7 insertions(+), 650 deletions(-) delete mode 100644 plugins/pencilblue/include/multisite_admin_routes.js diff --git a/include/admin_navigation.js b/include/admin_navigation.js index 1b9c46c51..adb13f776 100755 --- a/include/admin_navigation.js +++ b/include/admin_navigation.js @@ -77,7 +77,6 @@ module.exports = function AdminNavigationModule(pb) { * @private * @static * @method getDefaultNavigation - * @param adminsiteId {String} uid of site * @returns {Array} */ function getDefaultNavigation() { @@ -360,7 +359,7 @@ module.exports = function AdminNavigationModule(pb) { } } return false; - } + }; function exists(id, site) { var isGlobal = pb.SiteService.isGlobal(site); diff --git a/include/service/entities/section_service.js b/include/service/entities/section_service.js index 124254a5e..f2972cc8a 100755 --- a/include/service/entities/section_service.js +++ b/include/service/entities/section_service.js @@ -32,7 +32,6 @@ module.exports = function SectionServiceModule(pb) { function SectionService(site, onlyThisSite) { this.site = pb.SiteService.getCurrentSite(site); this.settings = pb.SettingServiceFactory.getServiceBySite(this.site, onlyThisSite); - this.sitePrefix = pb.SiteService.getCurrentSitePrefix(this.site); this.siteQueryService = new pb.SiteQueryService(this.site, onlyThisSite); } @@ -58,7 +57,6 @@ module.exports = function SectionServiceModule(pb) { * @method getPillNavOptions * @param {String} activePill * @return {Array} - * @param sitePrefix */ SectionService.getPillNavOptions = function(activePill) { return [ @@ -767,8 +765,6 @@ module.exports = function SectionServiceModule(pb) { return VALID_TYPES[type] === true; }; - - //exports return SectionService; }; diff --git a/include/service/entities/site_service.js b/include/service/entities/site_service.js index ba83979b8..9bf41910f 100644 --- a/include/service/entities/site_service.js +++ b/include/service/entities/site_service.js @@ -320,24 +320,6 @@ module.exports = function SiteServiceModule(pb) { return siteid || SiteService.GLOBAL_SITE; }; - /** - * Gets the current site prefix based on site (the return value of getCurrentSite) - * this is used as an url fragment, and equal to slash + site if multisite is on, or empty if it's off; - * used for '/admin' + prefix so controllers (both node and angular) can generate urls conforming to - * multitenant and single tenant setups - * @param site - * @returns {string} /site if multisite is enabled, empty if not - */ - SiteService.getCurrentSitePrefix = function (site) { - if (!pb.config.multisite) { - return ''; - } - if (!site) { - throw new Error("Site is empty in getCurrentSitePrefix when it never should be"); - } - return '/' + site; - }; - /** * Determines if a site exists matching siteUid * @method siteExists diff --git a/plugins/pencilblue/controllers/admin/content/objects/object_form.js b/plugins/pencilblue/controllers/admin/content/objects/object_form.js index 3371c4aaf..cde202ea7 100644 --- a/plugins/pencilblue/controllers/admin/content/objects/object_form.js +++ b/plugins/pencilblue/controllers/admin/content/objects/object_form.js @@ -83,7 +83,7 @@ module.exports = function(pb) { self.objectType = data.objectType; self.customObject = data.customObject; - data.pills = self.getAdminPills(SUB_NAV_KEY, self.ls, SUB_NAV_KEY, {objectType: self.objectType, customObject: self.customObject, pathSitePrefix: self.site}); + data.pills = self.getAdminPills(SUB_NAV_KEY, self.ls, SUB_NAV_KEY, {objectType: self.objectType, customObject: self.customObject}); var angularObjects = pb.ClientJs.getAngularObjects(data); self.setPageName(self.customObject[pb.DAO.getIdField()] ? self.customObject.name : self.ls.get('NEW') + ' ' + self.objectType.name + ' ' + self.ls.get('OBJECT')); diff --git a/plugins/pencilblue/include/multisite_admin_routes.js b/plugins/pencilblue/include/multisite_admin_routes.js deleted file mode 100644 index 2def89489..000000000 --- a/plugins/pencilblue/include/multisite_admin_routes.js +++ /dev/null @@ -1,611 +0,0 @@ -/* - Copyright (C) 2015 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 - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . - */ - -//dependencies -var path = require('path'); - -//exports -module.exports = function Routes(pb){ - return [ - { - method: 'get', - path: "/admin/:siteid", - access_level: pb.SecurityService.ACCESS_WRITER, - auth_required: true, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'index.js'), - content_type: 'text/html' - }, - // NAVIGATION - { - method: 'get', - path: "/admin/:siteid/content/navigation", - access_level: pb.SecurityService.ACCESS_EDITOR, - auth_required: true, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'content', 'navigation', 'nav_map.js'), - content_type: 'text/html' - }, - { - method: 'get', - path: "/admin/:siteid/content/navigation/new", - access_level: pb.SecurityService.ACCESS_EDITOR, - auth_required: true, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'content', 'navigation', 'nav_item_form.js'), - content_type: 'text/html' - }, - { - method: 'get', - path: "/admin/:siteid/content/navigation/:id", - access_level: pb.SecurityService.ACCESS_EDITOR, - auth_required: true, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'content', 'navigation', 'nav_item_form.js'), - content_type: 'text/html' - }, - { - method: 'post', - path: "/actions/admin/:siteid/content/navigation/map", - access_level: pb.SecurityService.ACCESS_EDITOR, - auth_required: true, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'content', 'navigation', 'nav_map.js'), - content_type: 'text/html' - }, - { - method: 'post', - path: "/actions/admin/:siteid/content/navigation", - access_level: pb.SecurityService.ACCESS_EDITOR, - auth_required: true, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'content', 'navigation', 'new_nav_item.js'), - content_type: 'text/html' - }, - { - method: 'post', - path: "/actions/admin/:siteid/content/navigation/:id", - access_level: pb.SecurityService.ACCESS_EDITOR, - auth_required: true, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'content', 'navigation', 'edit_nav_item.js'), - content_type: 'text/html' - }, - { - method: 'delete', - path: "/actions/admin/:siteid/content/navigation/:id", - access_level: pb.SecurityService.ACCESS_EDITOR, - auth_required: true, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'content', 'navigation', 'delete_nav_item.js'), - content_type: 'text/html' - }, - - // TOPICS - { - method: 'get', - path: "/admin/:siteid/content/topics", - access_level: pb.SecurityService.ACCESS_EDITOR, - auth_required: true, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'content', 'topics', 'manage_topics.js'), - content_type: 'text/html' - }, - { - method: 'get', - path: "/admin/:siteid/content/topics/new", - access_level: pb.SecurityService.ACCESS_EDITOR, - auth_required: true, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'content', 'topics', 'topic_form.js'), - content_type: 'text/html' - }, - { - method: 'get', - path: "/admin/:siteid/content/topics/import", - access_level: pb.SecurityService.ACCESS_EDITOR, - auth_required: true, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'content', 'topics', 'import_topics.js'), - content_type: 'text/html' - }, - { - method: 'get', - path: "/admin/:siteid/content/topics/:id", - access_level: pb.SecurityService.ACCESS_EDITOR, - auth_required: true, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'content', 'topics', 'topic_form.js'), - content_type: 'text/html' - }, - { - method: 'post', - path: "/actions/admin/:siteid/content/topics", - access_level: pb.SecurityService.ACCESS_EDITOR, - auth_required: true, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'content', 'topics', 'new_topic.js'), - content_type: 'text/html' - }, - { - method: 'post', - path: "/actions/admin/:siteid/content/topics/import", - access_level: pb.SecurityService.ACCESS_EDITOR, - auth_required: true, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'content', 'topics', 'import_topics.js'), - content_type: 'text/html' - }, - { - method: 'post', - path: "/actions/admin/:siteid/content/topics/:id", - access_level: pb.SecurityService.ACCESS_EDITOR, - auth_required: true, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'content', 'topics', 'edit_topic.js'), - content_type: 'text/html' - }, - { - method: 'delete', - path: "/actions/admin/:siteid/content/topics/:id", - access_level: pb.SecurityService.ACCESS_EDITOR, - auth_required: true, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'content', 'topics', 'delete_topic.js'), - content_type: 'text/html' - }, - - // ARTICLES - { - method: 'get', - path: "/admin/:siteid/content/articles", - access_level: pb.SecurityService.ACCESS_WRITER, - auth_required: true, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'content', 'articles', 'manage_articles.js'), - content_type: 'text/html' - }, - { - method: 'get', - path: "/admin/:siteid/content/articles/new", - access_level: pb.SecurityService.ACCESS_WRITER, - auth_required: true, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'content', 'articles', 'article_form.js'), - content_type: 'text/html' - }, - { - method: 'get', - path: "/admin/:siteid/content/articles/:id", - access_level: pb.SecurityService.ACCESS_WRITER, - auth_required: true, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'content', 'articles', 'article_form.js'), - content_type: 'text/html' - }, - { - method: 'post', - path: "/actions/admin/:siteid/content/articles", - access_level: pb.SecurityService.ACCESS_WRITER, - auth_required: true, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'content', 'articles', 'new_article.js'), - content_type: 'text/html' - }, - { - method: 'post', - path: "/actions/admin/:siteid/content/articles/:id", - access_level: pb.SecurityService.ACCESS_WRITER, - auth_required: true, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'content', 'articles', 'edit_article.js'), - content_type: 'text/html' - }, - { - method: 'delete', - path: "/actions/admin/:siteid/content/articles/:id", - access_level: pb.SecurityService.ACCESS_EDITOR, - auth_required: true, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'content', 'articles', 'delete_article.js'), - }, - - // PAGES - { - method: 'get', - path: "/admin/:siteid/content/pages", - access_level: pb.SecurityService.ACCESS_EDITOR, - auth_required: true, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'content', 'pages', 'manage_pages.js'), - content_type: 'text/html' - }, - { - method: 'get', - path: "/admin/:siteid/content/pages/new", - access_level: pb.SecurityService.ACCESS_EDITOR, - auth_required: true, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'content', 'pages', 'page_form.js'), - content_type: 'text/html' - }, - { - method: 'get', - path: "/admin/:siteid/content/pages/:id", - access_level: pb.SecurityService.ACCESS_EDITOR, - auth_required: true, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'content', 'pages', 'page_form.js'), - content_type: 'text/html' - }, - { - method: 'post', - path: "/actions/admin/:siteid/content/pages", - access_level: pb.SecurityService.ACCESS_EDITOR, - auth_required: true, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'content', 'pages', 'new_page.js'), - content_type: 'text/html' - }, - { - method: 'post', - path: "/actions/admin/:siteid/content/pages/:id", - access_level: pb.SecurityService.ACCESS_EDITOR, - auth_required: true, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'content', 'pages', 'edit_page.js'), - content_type: 'text/html' - }, - { - method: 'delete', - path: "/actions/admin/:siteid/content/pages/:id", - access_level: pb.SecurityService.ACCESS_EDITOR, - auth_required: true, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'content', 'pages', 'delete_page.js'), - content_type: 'text/html' - }, - - // MEDIA - { - method: 'get', - path: "/admin/:siteid/content/media", - access_level: pb.SecurityService.ACCESS_WRITER, - auth_required: true, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'content', 'media', 'manage_media.js'), - content_type: 'text/html' - }, - { - method: 'get', - path: "/admin/:siteid/content/media/new", - access_level: pb.SecurityService.ACCESS_WRITER, - auth_required: true, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'content', 'media', 'media_form.js'), - content_type: 'text/html' - }, - { - method: 'get', - path: "/admin/:siteid/content/media/:id", - access_level: pb.SecurityService.ACCESS_WRITER, - auth_required: true, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'content', 'media', 'media_form.js'), - content_type: 'text/html' - }, - { - method: 'post', - path: "/actions/admin/:siteid/content/media", - access_level: pb.SecurityService.ACCESS_WRITER, - auth_required: true, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'content', 'media', 'new_media.js'), - content_type: 'text/html' - }, - { - method: 'post', - path: "/actions/admin/:siteid/content/media/:id", - access_level: pb.SecurityService.ACCESS_WRITER, - auth_required: true, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'content', 'media', 'edit_media.js'), - content_type: 'text/html' - }, - { - method: 'delete', - path: "/actions/admin/:siteid/content/media/:id", - access_level: pb.SecurityService.ACCESS_WRITER, - auth_required: true, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'content', 'media', 'delete_media.js'), - content_type: 'text/html' - }, - { - method: 'post', - path: "/api/admin/:siteid/content/media/upload_media", - access_level: pb.SecurityService.ACCESS_WRITER, - auth_required: true, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'api', 'admin', 'content', 'media', 'upload_media.js'), - content_type: 'text/html' - }, - { - method: 'get', - path: "/api/admin/:siteid/content/media/get_link", - access_level: pb.SecurityService.ACCESS_WRITER, - auth_required: true, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'api', 'admin', 'content', 'media', 'get_link.js'), - content_type: 'application/json' - }, - { - method: 'get', - path: "/api/admin/:siteid/content/media/get_preview", - access_level: pb.SecurityService.ACCESS_WRITER, - auth_required: true, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'api', 'admin', 'content', 'media', 'get_preview.js'), - content_type: 'application/json' - }, - - // COMMENTS - { - method: 'get', - path: "/admin/:siteid/content/comments", - auth_required: true, - access_level: pb.SecurityService.ACCESS_EDITOR, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'content', 'comments', 'manage_comments.js'), - content_type: 'text/html' - }, - { - method: 'delete', - path: "/actions/admin/:siteid/content/comments/:id", - access_level: pb.SecurityService.ACCESS_EDITOR, - auth_required: true, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'content', 'comments', 'delete_comment.js'), - content_type: 'text/html' - }, - - // CUSTOM OBJECT TYPES - { - method: 'get', - path: "/admin/:siteid/content/objects/types", - access_level: pb.SecurityService.ACCESS_EDITOR, - auth_required: true, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'content', 'objects', 'types', 'manage_types.js'), - content_type: 'text/html' - }, - { - method: 'get', - path: "/admin/:siteid/content/objects/types/new", - access_level: pb.SecurityService.ACCESS_EDITOR, - auth_required: true, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'content', 'objects', 'types', 'type_form.js'), - content_type: 'text/html' - }, - { - method: 'get', - path: "/admin/:siteid/content/objects/types/:id", - access_level: pb.SecurityService.ACCESS_EDITOR, - auth_required: true, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'content', 'objects', 'types', 'type_form.js'), - content_type: 'text/html' - }, - { - method: 'get', - path: "/api/admin/:siteid/content/objects/types/available", - access_level: pb.SecurityService.ACCESS_EDITOR, - auth_required: true, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'api', 'admin', 'content', 'objects', 'types', 'available.js'), - content_type: 'text/html' - }, - { - method: 'post', - path: "/actions/admin/:siteid/content/objects/types", - access_level: pb.SecurityService.ACCESS_EDITOR, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'content', 'objects', 'types', 'new_type.js'), - content_type: 'text/html', - request_body: ['application/json'] - }, - { - method: 'post', - path: "/actions/admin/:siteid/content/objects/types/:id", - access_level: pb.SecurityService.ACCESS_EDITOR, - auth_required: true, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'content', 'objects', 'types', 'edit_type.js'), - content_type: 'text/html', - request_body: ['application/json'] - }, - { - method: 'delete', - path: "/actions/admin/:siteid/content/objects/types/:id", - access_level: pb.SecurityService.ACCESS_EDITOR, - auth_required: true, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'content', 'objects', 'types', 'delete_type.js'), - content_type: 'text/html' - }, - - // CUSTOM OBJECTS - { - path: "/admin/:siteid/content/objects/:type_id", - access_level: pb.SecurityService.ACCESS_EDITOR, - auth_required: true, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'content', 'objects', 'manage_objects.js'), - content_type: 'text/html' - }, - { - path: "/admin/:siteid/content/objects/:type_id/sort", - access_level: pb.SecurityService.ACCESS_EDITOR, - auth_required: true, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'content', 'objects', 'sort_objects.js'), - content_type: 'text/html' - }, - { - method: 'get', - path: "/admin/:siteid/content/objects/:type_id/new", - access_level: pb.SecurityService.ACCESS_EDITOR, - auth_required: true, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'content', 'objects', 'object_form.js'), - content_type: 'text/html' - }, - { - method: 'get', - path: "/admin/:siteid/content/objects/:type_id/:id", - access_level: pb.SecurityService.ACCESS_EDITOR, - auth_required: true, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'content', 'objects', 'object_form.js'), - content_type: 'text/html' - }, - { - method: 'post', - path: "/actions/admin/:siteid/content/objects/:type_id/sort", - access_level: pb.SecurityService.ACCESS_EDITOR, - auth_required: true, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'content', 'objects', 'sort_objects.js'), - content_type: 'text/html', - request_body: ['application/json'] - }, - { - method: 'post', - path: "/actions/admin/:siteid/content/objects/:type_id", - access_level: pb.SecurityService.ACCESS_EDITOR, - auth_required: true, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'content', 'objects', 'new_object.js'), - content_type: 'text/html', - request_body: ['application/json'] - }, - { - method: 'post', - path: "/actions/admin/:siteid/content/objects/:type_id/:id", - access_level: pb.SecurityService.ACCESS_EDITOR, - auth_required: true, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'content', 'objects', 'edit_object.js'), - content_type: 'text/html', - request_body: ['application/json'] - }, - { - method: 'delete', - path: "/actions/admin/:siteid/content/objects/:id", - access_level: pb.SecurityService.ACCESS_EDITOR, - auth_required: true, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'content', 'objects', 'delete_object.js'), - content_type: 'text/html' - }, - - // PLUGINS - { - method: 'get', - path: "/admin/:siteid/plugins", - auth_required: true, - access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'plugins', 'manage_plugins.js'), - content_type: 'text/html' - }, - { - method: 'get', - path: "/admin/:siteid/plugins/:id", - auth_required: true, - access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'plugins', 'plugin_details.js'), - content_type: 'text/html' - }, - { - method: 'get', - path: "/admin/:siteid/plugins/:id/settings", - handler: 'get', - auth_required: true, - access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'plugins', 'plugin_settings.js'), - content_type: 'text/html' - }, - { - method: 'post', - path: "/admin/:siteid/plugins/:id/settings", - handler: 'post', - auth_required: true, - access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'plugins', 'plugin_settings.js'), - content_type: 'application/json', - request_body: ['application/json'] - }, - { - method: 'post', - path: "/api/:siteid/plugins/:action/:id/", - auth_required: true, - access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'api', 'plugins', 'plugin_api.js'), - content_type: 'application/json' - }, - - // THEMES - { - method: 'get', - path: "/admin/:siteid/themes", - auth_required: true, - access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'themes', 'manage_themes.js'), - content_type: 'text/html' - }, - { - method: 'get', - path: "/admin/:siteid/themes/:id/settings", - handler: 'get', - auth_required: true, - access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'themes', 'theme_settings.js'), - content_type: 'text/html' - }, - { - method: 'post', - path: "/admin/:siteid/themes/:id/settings", - handler: 'post', - auth_required: true, - access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'themes', 'theme_settings.js'), - content_type: 'application/json', - request_body: ['application/json'] - }, - { - method: 'post', - path: "/actions/admin/:siteid/themes/site_logo", - auth_required: true, - access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'themes', 'site_logo.js') - }, - - //SITE SETTINGS - { - method: 'get', - path: "/admin/:siteid/site_settings", - access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, - auth_required: true, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'site_settings', 'configuration.js'), - content_type: 'text/html' - }, - { - method: 'get', - path: "/admin/:siteid/site_settings/content", - access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, - auth_required: true, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'site_settings', 'content.js'), - content_type: 'text/html' - }, - { - method: 'post', - path: "/actions/admin/:siteid/site_settings/content", - access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, - auth_required: true, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'site_settings', 'content.js'), - content_type: 'text/html' - }, - { - method: 'get', - path: "/admin/:siteid/site_settings/email", - access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, - auth_required: true, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'site_settings', 'email.js'), - content_type: 'text/html' - }, - { - method: 'post', - path: "/actions/admin/:siteid/site_settings/email", - access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, - auth_required: true, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'site_settings', 'email.js'), - content_type: 'text/html' - }, - { - method: 'get', - path: "/admin/"+ pb.SiteService.GLOBAL_SITE + "/site_settings/libraries", - access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, - auth_required: true, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'site_settings', 'libraries.js'), - content_type: 'text/html' - }, - { - method: 'get', - path: "/admin/:siteid/users/:id", - auth_required: true, - access_level: pb.SecurityService.ACCESS_EDITOR, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'users', 'user_form.js'), - } - ]; -}; diff --git a/plugins/pencilblue/include/routes.js b/plugins/pencilblue/include/routes.js index 1a72af25e..9fa61d34c 100644 --- a/plugins/pencilblue/include/routes.js +++ b/plugins/pencilblue/include/routes.js @@ -17,11 +17,10 @@ //dependencies var path = require('path'); -var multiSiteAdminRoutes = require('./multisite_admin_routes'); //exports module.exports = function Routes(pb){ - var routes = [ + return [ { method: 'get', path: '/media/*', @@ -1161,9 +1160,4 @@ module.exports = function Routes(pb){ request_body: ['application/json'] } ]; - - if(pb.config.multisite){ - routes = routes.concat(multiSiteAdminRoutes(pb)); - } - return routes; }; diff --git a/plugins/pencilblue/templates/angular/admin/content/media/media_form.html b/plugins/pencilblue/templates/angular/admin/content/media/media_form.html index 31e589cdf..42e18df7d 100644 --- a/plugins/pencilblue/templates/angular/admin/content/media/media_form.html +++ b/plugins/pencilblue/templates/angular/admin/content/media/media_form.html @@ -132,7 +132,7 @@ } mediaObject.media_topics = topics; - mediaService.saveMedia(mediaObject, $scope.sitePrefix) + mediaService.saveMedia(mediaObject) .then(function(result) { $scope.saving = false; $scope.successMessage = result.message; diff --git a/public/js/angular/services/media.js b/public/js/angular/services/media.js index a6eb9b68a..66e529745 100644 --- a/public/js/angular/services/media.js +++ b/public/js/angular/services/media.js @@ -22,13 +22,10 @@ angular.module('media', []) }); }; - this.saveMedia = function(mediaObject, sitePrefix) { + this.saveMedia = function(mediaObject) { var deferred = $q.defer(); - var actionPrefix = '/actions/admin'; - if(sitePrefix) { - actionPrefix += sitePrefix; - } - $http.post(actionPrefix + '/content/media' + (mediaObject._id ? '/' + mediaObject._id : ''), mediaObject, { + + $http.post('/actions/admin/content/media' + (mediaObject._id ? '/' + mediaObject._id : ''), mediaObject, { headers: {'Content-Type': 'application/x-www-form-urlencoded'} }) .success(function(result) { From 55d020aafb5a229c3cdb56c1e1576be2e90359d5 Mon Sep 17 00:00:00 2001 From: iandtrapp Date: Thu, 18 Jun 2015 13:10:42 -0400 Subject: [PATCH 348/790] Merged view controllers, angular controllers, and site_form template --- .../{edit_site_action.js => edit_site.js} | 26 ++++---- .../sites/{new_site_action.js => new_site.js} | 4 +- .../controllers/admin/sites/edit_sites.js | 49 --------------- .../controllers/admin/sites/site_form.js | 61 ++++++++++++------- plugins/pencilblue/include/routes.js | 6 +- .../templates/admin/sites/edit_sites.html | 34 ----------- .../templates/admin/sites/site_form.html | 23 ++++--- .../angular/admin/sites/edit_sites.html | 53 ---------------- .../angular/admin/sites/site_form.html | 25 +++++++- 9 files changed, 95 insertions(+), 186 deletions(-) rename plugins/pencilblue/controllers/actions/admin/sites/{edit_site_action.js => edit_site.js} (67%) rename plugins/pencilblue/controllers/actions/admin/sites/{new_site_action.js => new_site.js} (92%) delete mode 100644 plugins/pencilblue/controllers/admin/sites/edit_sites.js delete mode 100644 plugins/pencilblue/templates/admin/sites/edit_sites.html delete mode 100644 plugins/pencilblue/templates/angular/admin/sites/edit_sites.html diff --git a/plugins/pencilblue/controllers/actions/admin/sites/edit_site_action.js b/plugins/pencilblue/controllers/actions/admin/sites/edit_site.js similarity index 67% rename from plugins/pencilblue/controllers/actions/admin/sites/edit_site_action.js rename to plugins/pencilblue/controllers/actions/admin/sites/edit_site.js index 1fd89e56d..f7a923dc8 100644 --- a/plugins/pencilblue/controllers/actions/admin/sites/edit_site_action.js +++ b/plugins/pencilblue/controllers/actions/admin/sites/edit_site.js @@ -37,22 +37,22 @@ module.exports = function EditSiteActionModule(pb) { siteService.isDisplayNameOrHostnameTaken(post.displayName, post.hostname, data._id, function (err, isTaken, field) { if(isTaken) { cb({ - code: 400, - content: pb.BaseController.apiResponse(pb.BaseController.API_ERROR, self.ls.get('DUPLICATE_INFO')) + code: 400, + content: pb.BaseController.apiResponse(pb.BaseController.API_ERROR, self.ls.get('DUPLICATE_INFO')) }); } else { - data.displayName = post.displayName; - data.hostname = post.hostname; - dao.save(data, function(err, result) { - if(err) { - cb({ - code: 400, - content: pb.BaseController.apiResponse(pb.BaseController.API_ERROR, self.ls.get('ERROR SAVING')) - }); - return; - } - cb({content: pb.BaseController.apiResponse(pb.BaseController.API_SUCCESS, self.ls.get('SITE_UPDATED'), result)}); + data.displayName = post.displayName; + data.hostname = post.hostname; + dao.save(data, function(err, result) { + if(err) { + cb({ + code: 400, + content: pb.BaseController.apiResponse(pb.BaseController.API_ERROR, self.ls.get('ERROR SAVING')) + }); + return; + } + cb({content: pb.BaseController.apiResponse(pb.BaseController.API_SUCCESS, self.ls.get('SITE_UPDATED'), result)}); }); } diff --git a/plugins/pencilblue/controllers/actions/admin/sites/new_site_action.js b/plugins/pencilblue/controllers/actions/admin/sites/new_site.js similarity index 92% rename from plugins/pencilblue/controllers/actions/admin/sites/new_site_action.js rename to plugins/pencilblue/controllers/actions/admin/sites/new_site.js index 380b108b4..23376a283 100644 --- a/plugins/pencilblue/controllers/actions/admin/sites/new_site_action.js +++ b/plugins/pencilblue/controllers/actions/admin/sites/new_site.js @@ -37,8 +37,8 @@ module.exports = function NewSiteActionModule(pb) { siteService.createSite(site, post.id, function(err, isTaken, field, result) { if(isTaken) { cb({ - code: 400, - content: pb.BaseController.apiResponse(pb.BaseController.API_ERROR, self.ls.get('DUPLICATE_INFO')) + code: 400, + content: pb.BaseController.apiResponse(pb.BaseController.API_ERROR, self.ls.get('DUPLICATE_INFO')) }); } diff --git a/plugins/pencilblue/controllers/admin/sites/edit_sites.js b/plugins/pencilblue/controllers/admin/sites/edit_sites.js deleted file mode 100644 index 0b61f707f..000000000 --- a/plugins/pencilblue/controllers/admin/sites/edit_sites.js +++ /dev/null @@ -1,49 +0,0 @@ -module.exports = function EditSitesModule(pb) { - - var util = pb.util; - - function EditSites(){} - util.inherits(EditSites, pb.BaseController); - - var SUB_NAV_KEY = 'sites_edit'; - - EditSites.prototype.render = function(cb) { - var self = this; - var id = this.pathVars.siteid; - var dao = new pb.DAO(); - dao.loadByValue('uid', id, 'site', function(err, data) { - var angularObjects = pb.ClientJs.getAngularObjects({ - navigation: pb.AdminNavigation.get(self.session, ['site_entity'], self.ls), - pills: pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, SUB_NAV_KEY), - tabs: [{ active: 'active', href: '#editSite', icon: 'cog', title: self.ls.get('EDIT_SITE') }] - }); - self.ts.registerLocal('display_name', data.displayName.toString()); - self.ts.registerLocal('host_name', data.hostname.toString()); - self.ts.registerLocal('siteid', id.toString()); - self.ts.registerLocal('isActive', data.active); - self.ts.registerLocal('angular_objects', new pb.TemplateValue(angularObjects, false)); - self.ts.load('admin/sites/edit_sites', function(err,result) { - cb({content: result}); - }); - }); - - }; - - EditSites.getSubNavItems = function(key, ls, data) { - return [{ - name: 'edit_sites', - title: ls.get('EDIT_SITE'), - icon: 'chevron-left', - href: '/admin/sites' - }, { - name: 'new_site', - title: '', - icon: 'plus', - href: '/admin/sites/new' - }]; - }; - - pb.AdminSubnavService.registerFor(SUB_NAV_KEY, EditSites.getSubNavItems); - - return EditSites; -}; \ No newline at end of file diff --git a/plugins/pencilblue/controllers/admin/sites/site_form.js b/plugins/pencilblue/controllers/admin/sites/site_form.js index 32db7b190..1a44f6910 100644 --- a/plugins/pencilblue/controllers/admin/sites/site_form.js +++ b/plugins/pencilblue/controllers/admin/sites/site_form.js @@ -1,41 +1,60 @@ -module.exports = function(pb) { +module.exports = function SiteFormModule(pb) { var util = pb.util; function SiteForm(){} util.inherits(SiteForm, pb.BaseController); - var SUB_NAV_KEY = 'new_site'; + var SUB_NAV_KEY = 'sites_edit'; - SiteForm.prototype.render = function(cb) { + SiteForm.prototype.render = function(cb) { var self = this; - var angularObjects = pb.ClientJs.getAngularObjects({ - navigation: pb.AdminNavigation.get(self.session, ['site_entity'], self.ls), - pills: pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, SUB_NAV_KEY), - tabs: [{ active: 'active', href: '#sites', icon: 'cog', title: self.ls.get('SETTINGS') }] + var isNew = true; + var id = this.pathVars.siteid; + var dao = new pb.DAO(); + dao.loadByValue('uid', id, 'site', function(err, data) { + if (data) { + isNew = false; + var display = data.displayName.toString(); + var host = data.hostname.toString(); + var isActive = data.active; + var uid = data.uid; + } + + var angularObjects = pb.ClientJs.getAngularObjects({ + navigation: pb.AdminNavigation.get(self.session, ['site_entity'], self.ls), + pills: pb.AdminSubnavService.get(SUB_NAV_KEY, self.ls, SUB_NAV_KEY), + tabs: [{ active: 'active', href: '#editSite', icon: 'cog', title: self.ls.get('EDIT_SITE') }], + displayName: display, + hostname: host, + isNew: isNew, + isActive: isActive, + uid: uid + }); + + self.ts.registerLocal('angular_objects', new pb.TemplateValue(angularObjects, false)); + self.ts.load('admin/sites/site_form', function(err,result) { + cb({content: result}); + }); }); - self.ts.registerLocal('angular_objects', new pb.TemplateValue(angularObjects, false)); - self.ts.load('admin/sites/site_form', function(err,result) { - cb({content: result}); - }); - }; + }; SiteForm.getSubNavItems = function(key, ls, data) { - return [{ - name: 'new_site', - title: ls.get('NEW_SITE'), + return [{ + name: 'edit_sites', + title: ls.get('EDIT_SITE'), icon: 'chevron-left', href: '/admin/sites' - }, { - name: 'create_site', + }, { + name: 'new_site', title: '', icon: 'plus', href: '/admin/sites/new' - }]; - }; + }]; + }; - pb.AdminSubnavService.registerFor(SUB_NAV_KEY, SiteForm.getSubNavItems); + pb.AdminSubnavService.registerFor(SUB_NAV_KEY, SiteForm.getSubNavItems); - return SiteForm; + return SiteForm; }; \ No newline at end of file diff --git a/plugins/pencilblue/include/routes.js b/plugins/pencilblue/include/routes.js index 42a6ad763..04fb26b34 100644 --- a/plugins/pencilblue/include/routes.js +++ b/plugins/pencilblue/include/routes.js @@ -1020,7 +1020,7 @@ module.exports = function Routes(pb){ path: "/admin/sites/:siteid", access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, auth_required: true, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'sites', 'edit_sites.js'), + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'sites', 'site_form.js'), content_type: 'text/html' }, { @@ -1028,14 +1028,14 @@ module.exports = function Routes(pb){ path: "/actions/admin/sites/new", access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, auth_required: true, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'sites', 'new_site_action.js') + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'sites', 'new_site.js') }, { method: 'post', path: "/actions/admin/sites/edit/:siteid", access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, auth_required: true, - controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'sites', 'edit_site_action.js') + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'sites', 'edit_site.js') }, { method: 'post', diff --git a/plugins/pencilblue/templates/admin/sites/edit_sites.html b/plugins/pencilblue/templates/admin/sites/edit_sites.html deleted file mode 100644 index 5efdad6fc..000000000 --- a/plugins/pencilblue/templates/admin/sites/edit_sites.html +++ /dev/null @@ -1,34 +0,0 @@ -^tmp_admin=head^ -
- ^tmp_admin=elements=error_success^ - ^tmp_admin=elements=sub_nav^ - ^tmp_admin=elements=tab_nav^ -
-
-
-
-
- - -
^loc_REQUIRED_FIELD^
-
-
- - -
^loc_REQUIRED_FIELD^
-
^loc_SITE_MUST_DEACTIVATE^
-
-
-
- -  ^loc_CANCEL^ - - ^tmp_admin=elements=save_button^ -
-
- - ^tmp_admin=elements=progress_console_modal^ - - ^tmp_angular=admin=sites=edit_sites^ - ^tmp_admin=footer^ -
\ No newline at end of file diff --git a/plugins/pencilblue/templates/admin/sites/site_form.html b/plugins/pencilblue/templates/admin/sites/site_form.html index 67fd5ba87..24faea38a 100644 --- a/plugins/pencilblue/templates/admin/sites/site_form.html +++ b/plugins/pencilblue/templates/admin/sites/site_form.html @@ -3,31 +3,36 @@ ^tmp_admin=elements=error_success^ ^tmp_admin=elements=sub_nav^ ^tmp_admin=elements=tab_nav^ -
+
-
-
+
+
- +
^loc_REQUIRED_FIELD^
-
+
- -
^loc_REQUIRED_FIELD^
+ +
^loc_REQUIRED_FIELD^
+
^loc_SITE_MUST_DEACTIVATE^

 ^loc_CANCEL^ - ^tmp_admin=elements=save_button^ + +  ^loc_SAVE^ + + +  ^loc_SAVE^ +
^tmp_admin=elements=progress_console_modal^ - ^tmp_angular=admin=sites=site_form^ ^tmp_admin=footer^ diff --git a/plugins/pencilblue/templates/angular/admin/sites/edit_sites.html b/plugins/pencilblue/templates/angular/admin/sites/edit_sites.html deleted file mode 100644 index 48573fcb8..000000000 --- a/plugins/pencilblue/templates/angular/admin/sites/edit_sites.html +++ /dev/null @@ -1,53 +0,0 @@ - - \ No newline at end of file diff --git a/plugins/pencilblue/templates/angular/admin/sites/site_form.html b/plugins/pencilblue/templates/angular/admin/sites/site_form.html index 26f0faadd..907f28a82 100644 --- a/plugins/pencilblue/templates/angular/admin/sites/site_form.html +++ b/plugins/pencilblue/templates/angular/admin/sites/site_form.html @@ -5,7 +5,7 @@ ^angular_objects^ ^tmp_angular=admin=elements=is_field_valid^ - $scope.addNewSite = function() { + $scope.editSite = function() { $scope.formSubmitted = true; if(!validationService.isFormValid($scope.siteForm)) { @@ -13,8 +13,29 @@ } $scope.saving = true; + console.log($scope.siteForm); + $http.post('/actions/admin/sites/edit/' + $scope.uid, + { + displayName: $scope.displayName, + hostname: $scope.hostname + }) + .success(function(result) { + $scope.successMessage = result.message; + $scope.saving = false; + $scope.onActionSuccess(); + }) + .error(function(error, status) { + $scope.errorMessage = error.message; + $scope.saving = false; + }); + }; - $http.post('/actions/admin/sites/new', $scope.siteEntity) + $scope.newSite = function() { + $http.post('/actions/admin/sites/new', + { + displayName: $scope.displayName, + hostname: $scope.hostname + }) .success(function(result) { $scope.successMessage = result.message; $scope.saving = false; From 7bff50bc682651be6defceae31725d8a194561c7 Mon Sep 17 00:00:00 2001 From: btidwell Date: Thu, 18 Jun 2015 13:16:00 -0400 Subject: [PATCH 349/790] retrieve and delete indices that are not included in the config schema --- include/dao/db_manager.js | 50 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/include/dao/db_manager.js b/include/dao/db_manager.js index c2de4111f..e300d7770 100755 --- a/include/dao/db_manager.js +++ b/include/dao/db_manager.js @@ -152,6 +152,7 @@ module.exports = function DBManagerModule(pb) { * defer the reporting of an error until the end. */ this.processIndices = function(procedures, cb) { + var self = this; if (!util.isArray(procedures)) { cb(new Error('The procedures parameter must be an array of Objects')); return; @@ -159,7 +160,22 @@ module.exports = function DBManagerModule(pb) { //to prevent a cirular dependency we do the require for DAO here. var DAO = require('./dao.js')(pb); - + this.getStoredIndices(function(err, storedIndices) { + var dao = new DAO(); + storedIndices.forEach(function(index) { + var filteredIndex = procedures.filter(function(procedure) { + var ns = pb.config.db.name + '.' + procedure.collection; + var result = ns === index.ns && self.compareIndices(index, procedure); + return result; + }); + if(filteredIndex.length === 0 || util.isNullOrUndefined(filteredIndex)) { + console.log('DROP INDEX'); + dao.dropIndex(index.ns.split('.')[1], index.name, function(err, result) { + console.log(result) + }); + } + }); + }); //create the task list for executing indices. var errors = []; var tasks = util.getTasks(procedures, function(procedures, i) { @@ -187,6 +203,38 @@ module.exports = function DBManagerModule(pb) { }); }; + + this.compareIndices = function(stored, defined) { + var keys = Object.keys(stored.key); + var specs = Object.keys(defined.spec); + var result = JSON.stringify(keys) === JSON.stringify(specs); + return result; + + }; + + /** + * Yields all indices currently in the entire database + * @method getStoredInidices + * @param {Function} cb + */ + this.getStoredIndices = function(cb) { + dbs[pb.config.db.name].collections(function(err, collections) { + var tasks = util.getTasks(collections, function(collections, i) { + return function(callback) { + collections[i].indexes(function(err, indexes) { + if(util.isError(err)) { + pb.log.error("Error retrieving indices from db: " + err); + } + callback(err, indexes); + }); + }; + }); + async.parallel(tasks, function(err, results) { + cb(err, Array.prototype.concat.apply([], results)); + }); + }); + }; + /** * Iterates over all database handles and call's their shutdown function. * From 2df8f920c8d9e503dfcc9d444d126a3b8a796b0d Mon Sep 17 00:00:00 2001 From: iandtrapp Date: Thu, 18 Jun 2015 15:04:13 -0400 Subject: [PATCH 350/790] Added delete buttont to inactive sites row [not funcitonal] --- plugins/pencilblue/templates/admin/sites/manage_sites.html | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/pencilblue/templates/admin/sites/manage_sites.html b/plugins/pencilblue/templates/admin/sites/manage_sites.html index b5fce1c65..199acb2ad 100644 --- a/plugins/pencilblue/templates/admin/sites/manage_sites.html +++ b/plugins/pencilblue/templates/admin/sites/manage_sites.html @@ -61,6 +61,7 @@ From be4118d42c97afac02c563b528a5b9d027df516d Mon Sep 17 00:00:00 2001 From: btidwell Date: Thu, 18 Jun 2015 15:58:29 -0400 Subject: [PATCH 351/790] drop undeclared indices --- include/dao/db_manager.js | 84 ++++++++++++++++++++++++++++++--------- 1 file changed, 65 insertions(+), 19 deletions(-) diff --git a/include/dao/db_manager.js b/include/dao/db_manager.js index e300d7770..37ad5a094 100755 --- a/include/dao/db_manager.js +++ b/include/dao/db_manager.js @@ -158,29 +158,27 @@ module.exports = function DBManagerModule(pb) { return; } + this.dropUnconfiguredIndices(procedures, function(err) { + if(util.isError(err)) { + pb.log.error('DBManager: Error occurred during index check/deletion ERROR[%s]', err.stack); + } + self.ensureIndices(procedures, cb); + }); + }; + + /** + * Ensures all indices declared are defined on Mongo server + * @method ensureIndices + * @param {Array} procedures + * @param {Function} cb + */ + this.ensureIndices = function (procedures, cb) { //to prevent a cirular dependency we do the require for DAO here. var DAO = require('./dao.js')(pb); - this.getStoredIndices(function(err, storedIndices) { - var dao = new DAO(); - storedIndices.forEach(function(index) { - var filteredIndex = procedures.filter(function(procedure) { - var ns = pb.config.db.name + '.' + procedure.collection; - var result = ns === index.ns && self.compareIndices(index, procedure); - return result; - }); - if(filteredIndex.length === 0 || util.isNullOrUndefined(filteredIndex)) { - console.log('DROP INDEX'); - dao.dropIndex(index.ns.split('.')[1], index.name, function(err, result) { - console.log(result) - }); - } - }); - }); //create the task list for executing indices. var errors = []; var tasks = util.getTasks(procedures, function(procedures, i) { return function(callback) { - var dao = new DAO(); dao.ensureIndex(procedures[i], function(err, result) { if (util.isError(err)) { @@ -201,9 +199,57 @@ module.exports = function DBManagerModule(pb) { }; cb(err, result); }); - }; + } + + + /** + * Sorts through all created indices and drops any index not declared in pb.config + * @method dropUnconfiguredIndices + * @param {Array} procedures + * @param {Function} cb + */ + this.dropUnconfiguredIndices = function(procedures, cb) { + var self = this; + //to prevent a cirular dependency we do the require for DAO here. + var DAO = require('./dao.js')(pb); + this.getStoredIndices(function(err, storedIndices) { + var dao = new DAO(); + var tasks = util.getTasks(storedIndices, function(indices, i) { + return function(callback) { + var index = indices[i]; + var filteredIndex = procedures.filter(function(procedure) { + var ns = pb.config.db.name + '.' + procedure.collection; + var result = ns === index.ns && self.compareIndices(index, procedure); + return result; + }); + var indexCollection = index.ns.split('.')[0]; + if(index.name !== '_id_' && indexCollection !== 'pencilblue' && (filteredIndex.length === 0 || util.isNullOrUndefined(filteredIndex))) { + dao.dropIndex(index.ns.split('.')[1], index.name, function(err, result) { + if(util.isError(err)) { + pb.log.error('DBManager: Failed to drop undeclared INDEX=[%s] RESULT=[%s] ERROR[%s]', JSON.stringify(index), util.inspect(result), err.stack); + } + callback(err, result); + }); + } + else { + callback(); + } + }; + }); + async.parallel(tasks, function(err){ + cb(err); + }); + }); + }; + /** + * Compares an index stored in Mongo to an index declared in pb.config + * @method compareIndices + * @param {Object} stored + * @param {Object} defined + * @returns {boolean} + */ this.compareIndices = function(stored, defined) { var keys = Object.keys(stored.key); var specs = Object.keys(defined.spec); @@ -306,7 +352,7 @@ module.exports = function DBManagerModule(pb) { }; return pb.UrlService.urlJoin(str, config.db.name); }; - + //exports return DBManager; }; From 0ec17b48e90ee56d553cbdaca077a64dc27754f6 Mon Sep 17 00:00:00 2001 From: btidwell Date: Fri, 19 Jun 2015 16:25:23 -0400 Subject: [PATCH 352/790] dynamic indices based on multisite attribute. default is false for multisite --- include/config.js | 843 ++++++++++++-------------------------- include/dao/db_manager.js | 6 +- include/dao/indices.js | 328 +++++++++++++++ 3 files changed, 589 insertions(+), 588 deletions(-) create mode 100644 include/dao/indices.js diff --git a/include/config.js b/include/config.js index 8051d8181..76860873f 100755 --- a/include/config.js +++ b/include/config.js @@ -52,25 +52,6 @@ Configuration.DOCUMENT_ROOT = __dirname.substr(0, __dirname.indexOf(path.sep+'in */ Configuration.EXTERNAL_ROOT = path.join(path.sep, 'etc', 'pencilblue'); -/** - * Ascending index value - * @private - * @static - * @readonly - * @property ASC - * @type {Integer} - */ -var ASC = 1; - -/** - * Descending index value - * @private - * @static - * @readonly - * @property DESC - * @type {Integer} - */ -var DESC = -1; /** * The default logging directory absolute file path @@ -115,590 +96,280 @@ var OVERRIDE_FILE_PATHS = [ path.join(Configuration.EXTERNAL_ROOT, CONFIG_MODULE_NAME) ]; -/** - * @private - * @static - * @readonly - * @property BASE_CONFIG +/** + * Retrieve the base configuration */ -var BASE_CONFIG = { - - //The name of the site. - siteName: 'pencilblue', - - //The root of the site. This host part should ALWAYS match the value of - //the siteIP - siteRoot: 'http://localhost:8080', - - //The hostname or IP address that the web server instance will bind to - siteIP: '0.0.0.0', - - //The primary port to listen for traffic on. Some environment such as - //heroku force you to use whatever port they have available. In such cases - //the port is passed as an environment variable. - sitePort: process.env.port || process.env.PORT || 8080, - - //the absolute file path to the directory where installation lives - docRoot: Configuration.DOCUMENT_ROOT, - - //enables/disables multiple sites in a single pencilblue instance (multitenancy) - multisite: false, - - //provides a configuration for connecting to persistent storage. The - //default configuration is meant for mongodb. - db: { - type:'mongo', - servers: [ - '127.0.0.1:27017' - ], - - //the name of the default DB for the system - name: 'pencil_blue', - - //http://docs.mongodb.org/manual/core/write-concern/ - writeConcern: 1, - - //PB provides the ability to log queries. This is handy during - //development to see how many trips to the DB a single request is - //making. The queries log at level "info". - query_logging: false, - - //http://mongodb.github.io/node-mongodb-native/api-generated/db.html#authenticate - authentication: { - un: null, - pw: null, - options: { - //authMechanism: "MONGODB-CR"|"GSSAPI"|"PLAIN", //Defaults to MONGODB-CR - //authdb: "db name here", //Defaults to the db attempted to be connected to - //authSource: "db name here", //Defaults to value of authdb - } +Configuration.getBaseConfig = function(multisite) { + return util.clone({ + + //The name of the site. + siteName: 'pencilblue', + + //The root of the site. This host part should ALWAYS match the value of + //the siteIP + siteRoot: 'http://localhost:8080', + + //The hostname or IP address that the web server instance will bind to + siteIP: '0.0.0.0', + + //The primary port to listen for traffic on. Some environment such as + //heroku force you to use whatever port they have available. In such cases + //the port is passed as an environment variable. + sitePort: process.env.port || process.env.PORT || 8080, + + //the absolute file path to the directory where installation lives + docRoot: Configuration.DOCUMENT_ROOT, + + //enables/disables multiple sites in a single pencilblue instance (multitenancy) + multisite: false, + + //provides a configuration for connecting to persistent storage. The + //default configuration is meant for mongodb. + db: { + type:'mongo', + servers: [ + '127.0.0.1:27017' + ], + + //the name of the default DB for the system + name: 'pencil_blue', + + //http://docs.mongodb.org/manual/core/write-concern/ + writeConcern: 1, + + //PB provides the ability to log queries. This is handy during + //development to see how many trips to the DB a single request is + //making. The queries log at level "info". + query_logging: false, + + //http://mongodb.github.io/node-mongodb-native/api-generated/db.html#authenticate + authentication: { + un: null, + pw: null, + options: { + //authMechanism: "MONGODB-CR"|"GSSAPI"|"PLAIN", //Defaults to MONGODB-CR + //authdb: "db name here", //Defaults to the db attempted to be connected to + //authSource: "db name here", //Defaults to value of authdb + } + }, + + //This option instructs the child to skip the checks to ensure that the + //indices are built. It makes the assumption that the user doesn't care + //or that they are already in place. This would typically be used in a + //large production system where load can burst. In that particular case + //you wouldn't want to let your instances annoy the DB to check for + //indices because it would cause greater strain on the DB under heavy + //load. + skip_index_check: false, + + //The indices that will be ensured by the system. This list is checked + //at startup by every child process. The override config.json file may + //also provide this attribute. In that case the items in that array + //will be added to the those that already exist. This attributes is generated + //based on the multisite boolean setting. NOTE: duplicates can + //exist. + indices: require('./dao/indices.js')(multisite) }, - //This option instructs the child to skip the checks to ensure that the - //indices are built. It makes the assumption that the user doesn't care - //or that they are already in place. This would typically be used in a - //large production system where load can burst. In that particular case - //you wouldn't want to let your instances annoy the DB to check for - //indices because it would cause greater strain on the DB under heavy - //load. - skip_index_check: false, - - //The indices that will be ensured by the system. This list is checked - //at startup by every child process. The override config.json file may - //also provide this attribute. In that case the items in that array - //will be added to the those that already exist. NOTE: duplicates can - //exist. - indices: [ - - //user - { - collection: 'user', - spec: {username: ASC, site: ASC}, - options: {unique: true} - }, - { - collection: 'user', - spec: {email: ASC, site: ASC}, - options: {unique: true} - }, - { - collection: 'user', - spec: {username: ASC, password: ASC}, - options: {} - }, - { - collection: 'user', - spec: {created: ASC}, - options: {} - }, - { - collection: 'user', - spec: {admin: DESC}, - options: {} - }, - - //unverified user - { - collection: 'unverified_user', - spec: { last_modified: ASC }, - options: { expireAfterSeconds: 2592000 } - }, + //PB supports redis as a caching layer out of the box. For development + //purposes the "fake-redis" module can be used by setting the fake property + //to true. + cache: { + fake: true, + host: "localhost", + port: 6379 + //auth_pass: "password here" + }, - //theme settings - { - collection: 'theme_settings', - spec: {plugin_uid: ASC}, - options: {} - }, - { - collection: 'theme_settings', - spec: {plugin_id: ASC}, - options: {} - }, + //PB supports two session stores out of the box: mongo & redis. The + //timeout value is in ms. + session: { + storage: "redis", + timeout: 2000000 + }, - //plugin settings - { - collection: 'plugin_settings', - spec: {plugin_uid: ASC, site: ASC}, - options: {unique: true} - }, - { - collection: 'plugin_settings', - spec: {plugin_id: ASC, site: ASC}, - options: {unique: true} - }, + //The logging settings. The level property specifies at what level to log. + //It can be of any of the following: silly, debug, info, warn, error. The + //file property specifes the absolute file path where the log file should + //be written. If no value is provided the file transport will not be + //configured. The "showErrors" property indicates if the stack trace should + //be included in the serialization of the error. + logging: { + + level: "info", + file: LOG_FILE, + showErrors: true + }, - //settings - { - collection: 'setting', - spec: {key: ASC, site: ASC}, - options: {unique: true} - }, + //System settings always have the persistent storage layer on. Optionally, + //the cache and/or memory can be used. It is not recommended to use memory + //unless you are developing locally with a single worker. Memory is not + //synced across cluster workers so be careful if this option is set to true. + settings: { + use_memory: true, + use_cache: false, - //section - { - collection: 'section', - spec: {parent: ASC}, - options: {} - }, - { - collection: 'section', - spec: {created: ASC}, - options: {} - }, - { - collection: 'section', - spec: {name: ASC, site: ASC}, - options: {unique: true} - }, + //The timeout specifies how long in milliseconds a setting will exist + //in memory before being flushed. A value of 0 indicates that the + //values will not be purged from memory once expired. + memory_timeout: 0 + }, - //plugin - { - collection: 'plugin', - spec: {uid: ASC, site: ASC}, - options: {unique: true} - }, - { - collection: 'plugin', - spec: {created: ASC}, - options: {} - }, + //The template engine can take advantage of caching so that they are not + //retrieved and compiled from disk on each request. In a development + //environment it is ok because you will want to see the changes you make + //after each tweak. + templates: { + use_memory: true, + use_cache: false, - //password reset - { - collection: 'password_reset', - spec: {verification_code: ASC}, - options: {unique: true} - }, + //The timeout specifies how long in milliseconds a setting will exist + //in memory before being flushed. A value of 0 indicates that the + //values will not be purged from memory once expired. + memory_timeout: 0 + }, - //media - { - collection: 'media', - spec: {location: ASC}, - options: {} - }, - { - collection: 'media', - spec: {name: ASC, site: ASC}, - options: {unique: true} - }, - { - collection: 'media', - spec: {media_type: ASC}, - options: {}//TODO make unique once validation is in place - }, - { - collection: 'media', - spec: {created: ASC}, - options: {} - }, + //Plugins can also take advantage of the caching. This prevents a DB call + //to lookup active plugins and their settings. + plugins: { + caching: { + use_memory: true, + use_cache: false, + + //The timeout specifies how long in milliseconds a setting will exist + //in memory before being flushed. A value of 0 indicates that the + //values will not be purged from memory once expired. + memory_timeout: 0 + } + }, - //job run - //NOTHING YET + //PB provides a process registry. It utilizes the cache to register + //properties about itself that are available via API or in the admin + //console. This makes it easy to assist in monitoring your cluster and + //processes in production or development. The type value can be one of + //three values: 'redis', 'mongo' or an absolute path that implements the + //functions necessary to be a registration storage provider.The update + //interval specifies how many ms to wait before updating the registry with + //fresh data about itself. The key specifies what the base of the cache + //key looks like. + registry: { + enabled: true, + logging_enabled: false, + type: "redis", + update_interval: 10000, + key: 'server_registry' + }, - //job log - { - collection: 'job_log', - spec: {job_id: ASC}, - options: {}//TODO make unique once validation is in place - }, - { - collection: 'job_log', - spec: {job_id: ASC, created: ASC}, - options: {}//TODO make unique once validation is in place - }, - { - collection: 'job_log', - spec: {created: ASC}, - options: {} - }, + //PB aims to help developers scale. The system can take advantage of + //Node's cluster module to scale across the system cores. In order to + //protect against repeated catastrophic failures the system allows for + //"fatal_error_count" errors to occur outside of "fatal_error_timeout" secs. + //If the maximum number of failures occur inside of the allowed timeframe + //the master process and all the worker children will shutdown. + cluster: { + fatal_error_timeout: 2000, + fatal_error_count: 5, + + //This value descibes the number of child processes to spawn when the + //master process is started in self managed mode. The value can also + //be set to "auto". This will instruct the master process to inspect + //the number of cores on the server and spawn a child process for each + //core. + workers: 1, + + //The self managed flag indicates whether or not PencilBlue should + //start a master process who's sole responsibility is to watch over the + //child workers that it spawns. The default, TRUE, allows for + //PencilBlue to watch for failures and decide on its own whether or not + //to attempt to continue. When FALSE, PB starts as a stand alone + //process. Set to FALSE when you want to debug a single process or + //when operating in a cloud environment that manages the instances on + //each server. + self_managed: true + }, - //custom object type - { - collection: 'custom_object_type', - spec: {name: ASC, site: ASC}, - options: {unique: true} - }, - { - collection: 'custom_object_type', - spec: {created: ASC}, - options: {} - }, + //PB supports two methods of handling SSL. Standard point to a cert as + //described by the options below and SSL termination and the use of the + //"X-FORWARDED-PROTO" header. Node does not gracefully handle the redirect + //of HTTP traffic to HTTPS. PB handles this for you in what we call the + //handoff. PB will start a second http server listening on the + //"handoff_port". When traffic is received it will be redirected to the + //URL of the form "siteRoot+[URL PATH]". The port will only show if + //specified by the "use_handoff_port_in_redirect" property. + server: { + ssl: { + enabled: false, + handoff_port: 8080, + use_x_forwarded: false, + use_handoff_port_in_redirect: false, + key: "ssl/key.pem", + cert: "ssl/cert.crt", + chain: "ssl/chain.crt" + }, + + //when non-empty, a header (X-POWERED-BY) will be added to each outgoing + //response with "PencilBlue". Cheesy but it helps the BuiltWith tools + //of the world kep track of who uses what + x_powered_by: "PencilBlue" + }, - //custom objects - { - collection: 'custom_object', - spec: {name: ASC, type: ASC}, - options: {unique: true} - }, - { - collection: 'custom_object', - spec: {created: ASC}, - options: {} - }, + //PB uses a publish subscribe model to announce events to other members of + //the cluster. Out of the box PB provides a Redis implementation but it is + //also possible to provide a custom implementation. AMQP would be a good + //future implementation just as an example. Custom implementations can be + //used by providing the absolute path to the implementation in the "broker" + //field. + command: { + broker: 'redis', + timeout: 3000 + }, - //article - { - collection: 'article', - spec: {url: ASC, site: ASC}, - options: {unique: true} - }, - { - collection: 'article', - spec: {headline: ASC, site: ASC}, - options: {unique: true} - }, - { - collection: 'article', - spec: {publish_date: DESC}, - options: {} - }, - { - collection: 'article', - spec: {publish_date: DESC, draft: ASC}, - options: {} - }, - { - collection: 'article', - spec: {author: ASC}, - options: {} - }, - { - collection: 'article', - spec: {author: ASC, publish_date: DESC, draft: ASC}, - options: {} - }, - { - collection: 'article', - spec: {article_media: ASC}, - options: {} - }, - { - collection: 'article', - spec: {article_topics: ASC}, - options: {} - }, - { - collection: 'article', - spec: {article_sections: ASC}, - options: {} - }, - { - collection: 'article', - spec: {created: ASC}, - options: {} - }, - - //comment - { - collection: 'comment', - spec: {article: ASC}, - options: {} - }, - { - collection: 'comment', - spec: {commenter: ASC}, - options: {} - }, + //The media block specifies the options for how media is persisted. + //PencilBlue provides two storage engines out of the box. The first is + //'fs' which is the regular file system. This is the default option. + //However, as soon as PB is clustered on two or more nodes this **MUST** be + //changed to a different provider. The second provider, 'mongo', is a media + //storage mechanism powered by MongoDB's GridFS. The 'mongo' provider does + //support the distributed PencilBlue configuration although it is not + //recommended for large scale use. Systems that have larger or more + //performant data needs should look at other plugins to support that need. + media: { + + provider: 'fs', + parent_dir: 'public', + + //The maximum size of media files that can be uploaded to the server in + //bytes + max_upload_size: 2 * 1024 * 1024 + }, - //topic - { - collection: 'topic', - spec: {name: ASC, site: ASC}, - options: {unique: true} - }, - { - collection: 'topic', - spec: {created: ASC}, - options: {} - }, + //Contains all of the configuration for localization and internationalization. + localization: { - //page - { - collection: 'page', - spec: {url: ASC, site: ASC}, - options: {unique: true} - }, - { - collection: 'page', - spec: {headline: ASC, site: ASC}, - options: {unique: true} - }, - { - collection: 'page', - spec: {publish_date: DESC}, - options: {} - }, - { - collection: 'page', - spec: {publish_date: DESC, draft: ASC}, - options: {} - }, - { - collection: 'page', - spec: {author: ASC}, - options: {} - }, - { - collection: 'page', - spec: {author: ASC, publish_date: DESC, draft: ASC}, - options: {} - }, - { - collection: 'page', - spec: {page_media: ASC}, - options: {} - }, - { - collection: 'page', - spec: {page_topics: ASC}, - options: {} - }, - { - collection: 'page', - spec: {created: ASC}, - options: {} - }, - - //lock - { - collection: 'lock', - spec: {name: ASC}, - options: {unique: true} - }, - { - collection: 'lock', - spec: {timeout: ASC}, - options: {expireAfterSeconds: 0} - } - ] - }, - - //PB supports redis as a caching layer out of the box. For development - //purposes the "fake-redis" module can be used by setting the fake property - //to true. - cache: { - fake: true, - host: "localhost", - port: 6379 - //auth_pass: "password here" - }, - - //PB supports two session stores out of the box: mongo & redis. The - //timeout value is in ms. - session: { - storage: "redis", - timeout: 2000000 - }, - - //The logging settings. The level property specifies at what level to log. - //It can be of any of the following: silly, debug, info, warn, error. The - //file property specifes the absolute file path where the log file should - //be written. If no value is provided the file transport will not be - //configured. The "showErrors" property indicates if the stack trace should - //be included in the serialization of the error. - logging: { - - level: "info", - file: LOG_FILE, - showErrors: true - }, - - //System settings always have the persistent storage layer on. Optionally, - //the cache and/or memory can be used. It is not recommended to use memory - //unless you are developing locally with a single worker. Memory is not - //synced across cluster workers so be careful if this option is set to true. - settings: { - use_memory: true, - use_cache: false, - - //The timeout specifies how long in milliseconds a setting will exist - //in memory before being flushed. A value of 0 indicates that the - //values will not be purged from memory once expired. - memory_timeout: 0 - }, - - //The template engine can take advantage of caching so that they are not - //retrieved and compiled from disk on each request. In a development - //environment it is ok because you will want to see the changes you make - //after each tweak. - templates: { - use_memory: true, - use_cache: false, - - //The timeout specifies how long in milliseconds a setting will exist - //in memory before being flushed. A value of 0 indicates that the - //values will not be purged from memory once expired. - memory_timeout: 0 - }, - - //Plugins can also take advantage of the caching. This prevents a DB call - //to lookup active plugins and their settings. - plugins: { - caching: { - use_memory: true, - use_cache: false, - - //The timeout specifies how long in milliseconds a setting will exist - //in memory before being flushed. A value of 0 indicates that the - //values will not be purged from memory once expired. - memory_timeout: 0 - } - }, - - //PB provides a process registry. It utilizes the cache to register - //properties about itself that are available via API or in the admin - //console. This makes it easy to assist in monitoring your cluster and - //processes in production or development. The type value can be one of - //three values: 'redis', 'mongo' or an absolute path that implements the - //functions necessary to be a registration storage provider.The update - //interval specifies how many ms to wait before updating the registry with - //fresh data about itself. The key specifies what the base of the cache - //key looks like. - registry: { - enabled: true, - logging_enabled: false, - type: "redis", - update_interval: 10000, - key: 'server_registry' - }, - - //PB aims to help developers scale. The system can take advantage of - //Node's cluster module to scale across the system cores. In order to - //protect against repeated catastrophic failures the system allows for - //"fatal_error_count" errors to occur outside of "fatal_error_timeout" secs. - //If the maximum number of failures occur inside of the allowed timeframe - //the master process and all the worker children will shutdown. - cluster: { - fatal_error_timeout: 2000, - fatal_error_count: 5, - - //This value descibes the number of child processes to spawn when the - //master process is started in self managed mode. The value can also - //be set to "auto". This will instruct the master process to inspect - //the number of cores on the server and spawn a child process for each - //core. - workers: 1, - - //The self managed flag indicates whether or not PencilBlue should - //start a master process who's sole responsibility is to watch over the - //child workers that it spawns. The default, TRUE, allows for - //PencilBlue to watch for failures and decide on its own whether or not - //to attempt to continue. When FALSE, PB starts as a stand alone - //process. Set to FALSE when you want to debug a single process or - //when operating in a cloud environment that manages the instances on - //each server. - self_managed: true - }, - - //PB supports two methods of handling SSL. Standard point to a cert as - //described by the options below and SSL termination and the use of the - //"X-FORWARDED-PROTO" header. Node does not gracefully handle the redirect - //of HTTP traffic to HTTPS. PB handles this for you in what we call the - //handoff. PB will start a second http server listening on the - //"handoff_port". When traffic is received it will be redirected to the - //URL of the form "siteRoot+[URL PATH]". The port will only show if - //specified by the "use_handoff_port_in_redirect" property. - server: { - ssl: { - enabled: false, - handoff_port: 8080, - use_x_forwarded: false, - use_handoff_port_in_redirect: false, - key: "ssl/key.pem", - cert: "ssl/cert.crt", - chain: "ssl/chain.crt" + //The default locale is the fallback when localization fails for the user's desired language. + defaultLocale: 'en_US' }, - //when non-empty, a header (X-POWERED-BY) will be added to each outgoing - //response with "PencilBlue". Cheesy but it helps the BuiltWith tools - //of the world kep track of who uses what - x_powered_by: "PencilBlue" - }, - - //PB uses a publish subscribe model to announce events to other members of - //the cluster. Out of the box PB provides a Redis implementation but it is - //also possible to provide a custom implementation. AMQP would be a good - //future implementation just as an example. Custom implementations can be - //used by providing the absolute path to the implementation in the "broker" - //field. - command: { - broker: 'redis', - timeout: 3000 - }, - - //The media block specifies the options for how media is persisted. - //PencilBlue provides two storage engines out of the box. The first is - //'fs' which is the regular file system. This is the default option. - //However, as soon as PB is clustered on two or more nodes this **MUST** be - //changed to a different provider. The second provider, 'mongo', is a media - //storage mechanism powered by MongoDB's GridFS. The 'mongo' provider does - //support the distributed PencilBlue configuration although it is not - //recommended for large scale use. Systems that have larger or more - //performant data needs should look at other plugins to support that need. - media: { - - provider: 'fs', - parent_dir: 'public', - - //The maximum size of media files that can be uploaded to the server in - //bytes - max_upload_size: 2 * 1024 * 1024 - }, - - //Contains all of the configuration for localization and internationalization. - localization: { - - //The default locale is the fallback when localization fails for the user's desired language. - defaultLocale: 'en_US' - }, - - //The locking service provides a common mechanism for processes to reserve - //access to resources during critical operations. When the locks exist, - //other PB instances will not hinder the other process from completing its - //task. - locks: { - - //By default, the db will be used as the store for the locks. Another - //out of the box provider is 'cache'. It leverages the cache as a - //store. Custom implementations are also acceptable. The relative - //path from the installation root to the module should be provided. - provider: 'db', - - //The default amount of time that a lock will be persisted in seconds. - timeout: 30 - }, - - //Pulls in the package.json file for PB and extracts the version so it is - //available in the configuration. - version: require(path.join(Configuration.DOCUMENT_ROOT, 'package.json')).version -}; + //The locking service provides a common mechanism for processes to reserve + //access to resources during critical operations. When the locks exist, + //other PB instances will not hinder the other process from completing its + //task. + locks: { -/** - * Retrieve the base configuration - */ -Configuration.getBaseConfig = function() { - return util.clone(BASE_CONFIG); + //By default, the db will be used as the store for the locks. Another + //out of the box provider is 'cache'. It leverages the cache as a + //store. Custom implementations are also acceptable. The relative + //path from the installation root to the module should be provided. + provider: 'db', + + //The default amount of time that a lock will be persisted in seconds. + timeout: 30 + }, + + //Pulls in the package.json file for PB and extracts the version so it is + //available in the configuration. + version: require(path.join(Configuration.DOCUMENT_ROOT, 'package.json')).version + }); }; /** @@ -758,9 +429,11 @@ Configuration.load = function(filePaths) { * @method mergeWithBase */ Configuration.mergeWithBase = function(overrides) { - + var multisite = overrides ? overrides.multisite : false; + var baseConfig = Configuration.getBaseConfig(multisite); + //merge in all overrides with the base configuration - var config = util.deepMerge(overrides, Configuration.getBaseConfig()); + var config = util.deepMerge(overrides, baseConfig); //special check to ensure that there is no ending slash on the site root if (config.siteRoot.lastIndexOf('/') === (config.siteRoot.length - 1)) { diff --git a/include/dao/db_manager.js b/include/dao/db_manager.js index 37ad5a094..03e502f21 100755 --- a/include/dao/db_manager.js +++ b/include/dao/db_manager.js @@ -223,9 +223,9 @@ module.exports = function DBManagerModule(pb) { var result = ns === index.ns && self.compareIndices(index, procedure); return result; }); - var indexCollection = index.ns.split('.')[0]; - if(index.name !== '_id_' && indexCollection !== 'pencilblue' && (filteredIndex.length === 0 || util.isNullOrUndefined(filteredIndex))) { - dao.dropIndex(index.ns.split('.')[1], index.name, function(err, result) { + var indexCollection = index.ns.split('.')[1]; + if(index.name !== '_id_' && indexCollection !== 'session' && (filteredIndex.length === 0 || util.isNullOrUndefined(filteredIndex))) { + dao.dropIndex(indexCollection, index.name, function(err, result) { if(util.isError(err)) { pb.log.error('DBManager: Failed to drop undeclared INDEX=[%s] RESULT=[%s] ERROR[%s]', JSON.stringify(index), util.inspect(result), err.stack); } diff --git a/include/dao/indices.js b/include/dao/indices.js new file mode 100644 index 000000000..859f17a03 --- /dev/null +++ b/include/dao/indices.js @@ -0,0 +1,328 @@ + +/** + * Ascending index value + * @private + * @static + * @readonly + * @property ASC + * @type {Integer} + */ +var ASC = 1; + +/** + * Descending index value + * @private + * @static + * @readonly + * @property DESC + * @type {Integer} + */ +var DESC = -1; + +module.exports = function IndicesModule(multisite) { + console.log(multisite); + return [ + + //user + { + collection: 'user', + spec: multisite ? {username: ASC, site: ASC} : {username: ASC}, + options: {unique: true} + }, + { + collection: 'user', + spec: multisite ? {email: ASC, site: ASC} : {email: ASC}, + options: {unique: true} + }, + { + collection: 'user', + spec: {username: ASC, password: ASC}, + options: {} + }, + { + collection: 'user', + spec: {created: ASC}, + options: {} + }, + { + collection: 'user', + spec: {admin: DESC}, + options: {} + }, + + //unverified user + { + collection: 'unverified_user', + spec: { last_modified: ASC }, + options: { expireAfterSeconds: 2592000 } + }, + + //theme settings + { + collection: 'theme_settings', + spec: {plugin_uid: ASC}, + options: {} + }, + { + collection: 'theme_settings', + spec: {plugin_id: ASC}, + options: {} + }, + + //plugin settings + { + collection: 'plugin_settings', + spec: multisite ? {plugin_uid: ASC, site: ASC} : {plugin_uid: ASC}, + options: {unique: true} + }, + { + collection: 'plugin_settings', + spec: multisite ? {plugin_id: ASC, site: ASC} : {plugin_id: ASC}, + options: {unique: true} + }, + + //settings + { + collection: 'setting', + spec: multisite ? {key: ASC, site: ASC} : {key: ASC}, + options: {unique: true} + }, + + //section + { + collection: 'section', + spec: {parent: ASC}, + options: {} + }, + { + collection: 'section', + spec: {created: ASC}, + options: {} + }, + { + collection: 'section', + spec: multisite ? {name: ASC, site: ASC} : {name: ASC}, + options: {unique: true} + }, + + //plugin + { + collection: 'plugin', + spec: multisite ? {uid: ASC, site: ASC} : {uid: ASC}, + options: {unique: true} + }, + { + collection: 'plugin', + spec: {created: ASC}, + options: {} + }, + + //password reset + { + collection: 'password_reset', + spec: {verification_code: ASC}, + options: {unique: true} + }, + + //media + { + collection: 'media', + spec: {location: ASC}, + options: {} + }, + { + collection: 'media', + spec: multisite ? {name: ASC, site: ASC} : {name: ASC}, + options: {unique: true} + }, + { + collection: 'media', + spec: {media_type: ASC}, + options: {}//TODO make unique once validation is in place + }, + { + collection: 'media', + spec: {created: ASC}, + options: {} + }, + + //job run + //NOTHING YET + + //job log + { + collection: 'job_log', + spec: {job_id: ASC}, + options: {}//TODO make unique once validation is in place + }, + { + collection: 'job_log', + spec: {job_id: ASC, created: ASC}, + options: {}//TODO make unique once validation is in place + }, + { + collection: 'job_log', + spec: {created: ASC}, + options: {} + }, + + //custom object type + { + collection: 'custom_object_type', + spec: multisite ? {name: ASC, site: ASC} : {name: ASC}, + options: {unique: true} + }, + { + collection: 'custom_object_type', + spec: {created: ASC}, + options: {} + }, + + //custom objects + { + collection: 'custom_object', + spec: {name: ASC, type: ASC}, + options: {unique: true} + }, + { + collection: 'custom_object', + spec: {created: ASC}, + options: {} + }, + + //article + { + collection: 'article', + spec: multisite ? {url: ASC, site: ASC} : {url: ASC}, + options: {unique: true} + }, + { + collection: 'article', + spec: multisite ? {headline: ASC, site: ASC} : {headline: ASC}, + options: {unique: true} + }, + { + collection: 'article', + spec: {publish_date: DESC}, + options: {} + }, + { + collection: 'article', + spec: {publish_date: DESC, draft: ASC}, + options: {} + }, + { + collection: 'article', + spec: {author: ASC}, + options: {} + }, + { + collection: 'article', + spec: {author: ASC, publish_date: DESC, draft: ASC}, + options: {} + }, + { + collection: 'article', + spec: {article_media: ASC}, + options: {} + }, + { + collection: 'article', + spec: {article_topics: ASC}, + options: {} + }, + { + collection: 'article', + spec: {article_sections: ASC}, + options: {} + }, + { + collection: 'article', + spec: {created: ASC}, + options: {} + }, + + //comment + { + collection: 'comment', + spec: {article: ASC}, + options: {} + }, + { + collection: 'comment', + spec: {commenter: ASC}, + options: {} + }, + + //topic + { + collection: 'topic', + spec: multisite ? {name: ASC, site: ASC} : {name: ASC}, + options: {unique: true} + }, + { + collection: 'topic', + spec: {created: ASC}, + options: {} + }, + + //page + { + collection: 'page', + spec: multisite ? {url: ASC, site: ASC} : {url: ASC}, + options: {unique: true} + }, + { + collection: 'page', + spec: multisite ? {headline: ASC, site: ASC} : {headline: ASC}, + options: {unique: true} + }, + { + collection: 'page', + spec: {publish_date: DESC}, + options: {} + }, + { + collection: 'page', + spec: {publish_date: DESC, draft: ASC}, + options: {} + }, + { + collection: 'page', + spec: {author: ASC}, + options: {} + }, + { + collection: 'page', + spec: {author: ASC, publish_date: DESC, draft: ASC}, + options: {} + }, + { + collection: 'page', + spec: {page_media: ASC}, + options: {} + }, + { + collection: 'page', + spec: {page_topics: ASC}, + options: {} + }, + { + collection: 'page', + spec: {created: ASC}, + options: {} + }, + + //lock + { + collection: 'lock', + spec: {name: ASC}, + options: {unique: true} + }, + { + collection: 'lock', + spec: {timeout: ASC}, + options: {expireAfterSeconds: 0} + } + ]; +}; \ No newline at end of file From 1d4c3038f40a55119ff75dccdde8ebf309dd0a1e Mon Sep 17 00:00:00 2001 From: btidwell Date: Tue, 23 Jun 2015 11:11:01 -0400 Subject: [PATCH 353/790] re-include root config.js file --- config.js | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 config.js diff --git a/config.js b/config.js new file mode 100644 index 000000000..ea52a1d45 --- /dev/null +++ b/config.js @@ -0,0 +1,2 @@ +var fs = require('fs'); +module.exports = JSON.parse(fs.readFileSync('config.json')); \ No newline at end of file From 2197ae14c87b29a522aef93944a2c6895f2185fe Mon Sep 17 00:00:00 2001 From: btidwell Date: Wed, 24 Jun 2015 09:14:36 -0400 Subject: [PATCH 354/790] create site if none found --- include/dao/db_manager.js | 5 ++ include/dao/db_migrate.js | 69 ++++++++++++++++++++++++ include/service/entities/site_service.js | 2 +- include/service/entities/user_service.js | 2 +- pencilblue.js | 5 ++ 5 files changed, 81 insertions(+), 2 deletions(-) create mode 100644 include/dao/db_migrate.js diff --git a/include/dao/db_manager.js b/include/dao/db_manager.js index 03e502f21..c5131a35e 100755 --- a/include/dao/db_manager.js +++ b/include/dao/db_manager.js @@ -281,6 +281,11 @@ module.exports = function DBManagerModule(pb) { }); }; + this.processMigration = function(cb) { + var DBMigrate = require('./db_migrate.js')(pb); + DBMigrate.run(cb); + }; + /** * Iterates over all database handles and call's their shutdown function. * diff --git a/include/dao/db_migrate.js b/include/dao/db_migrate.js new file mode 100644 index 000000000..dc8030816 --- /dev/null +++ b/include/dao/db_migrate.js @@ -0,0 +1,69 @@ +var url = require('url'); +var async = require('async'); +var util = require('../util.js'); + +module.exports = function DBMigrateModule(pb) { + /** + * Array of collections used to append a "site" value to documents + * @private + * @static + * @readonly + * @property MIGRATE_COLL + * @type {string[]} + */ + var MIGRATE_COLL = [ + 'article', + 'comment', + 'custom_object_type', + 'media', + 'page', + 'plugin', + 'plugin_settings', + 'section', + 'setting', + 'theme_settings', + 'topic', + 'user' + ]; + + var GLOBAL_USERS = [ + pb.security.ACCESS_ADMINISTRATOR, + pb.security.ACCESS_MANAGING_EDITOR + ]; + + var SITE_SPECIFIC_SETTINGS = [ + 'active_theme', + 'content_settings', + 'section_map', + 'email_settings' + ]; + + function DBMigrate(){} + + DBMigrate.run = function(cb) { + var siteService = new pb.SiteService(); + siteService.getSiteMap(function(err, result) { + if(pb.config.multisite && result.active.length === 0 && result.inactive.length === 0 ) { + DBMigrate.createSite(function(err, isTaken, field, result) { + cb(null, true);//TODO: migrate content and plugin data to newly create site. + }); + } + else { + cb(null, true); + } + }); + }; + + DBMigrate.createSite = function(cb) { + var siteService = new pb.SiteService(); + var site = pb.DocumentCreator.create('site', { + displayName: pb.config.siteName, + hostname: url.parse(pb.config.siteRoot).host + }); + siteService.createSite(site, '', cb); + }; + + + return DBMigrate; + +}; \ No newline at end of file diff --git a/include/service/entities/site_service.js b/include/service/entities/site_service.js index 9bf41910f..34dab93ef 100644 --- a/include/service/entities/site_service.js +++ b/include/service/entities/site_service.js @@ -349,7 +349,7 @@ module.exports = function SiteServiceModule(pb) { hostname = hostname.match(/^http/g) ? hostname : "//" + hostname; var urlObject = url.parse(hostname, false, true); urlObject.protocol = pb.config.server.ssl.enabled ? 'https' : 'http'; - return url.format(urlObject); + return url.format(urlObject).replace(/\/$/, ''); }; return SiteService; diff --git a/include/service/entities/user_service.js b/include/service/entities/user_service.js index dd69b73d5..f3f8033db 100755 --- a/include/service/entities/user_service.js +++ b/include/service/entities/user_service.js @@ -248,7 +248,7 @@ module.exports = function UserServiceModule(pb) { var options = { to: user.email, replacements: { - 'verification_url': pb.SiteService.getHostWithProtocol(siteInfo.hostname) + '/actions/user/verify_email?email=' + user.email + '&code=' + user.verification_code, + 'verification_url': pb.SiteService.getHostWithProtocol(siteInfo.hostname) + 'actions/user/verify_email?email=' + user.email + '&code=' + user.verification_code, 'first_name': user.first_name, 'last_name': user.last_name } diff --git a/pencilblue.js b/pencilblue.js index fab5bbaba..98e00f39d 100755 --- a/pencilblue.js +++ b/pencilblue.js @@ -58,6 +58,7 @@ function PencilBlue(config){ this.initDBConnections, this.initDBIndices, util.wrapTask(this, this.initServer), + this.initSiteMigration, this.initSessions, this.initPlugins, this.initSites, @@ -129,6 +130,10 @@ function PencilBlue(config){ pluginService.initPlugins(cb); }; + this.initSiteMigration = function(cb) { + pb.dbm.processMigration(cb); + }; + /** * */ From 7eb992bb0098d7fee95a80a2b32a5b4c45893360 Mon Sep 17 00:00:00 2001 From: btidwell Date: Wed, 24 Jun 2015 10:47:41 -0400 Subject: [PATCH 355/790] migrate content and plugin collections --- include/dao/db_migrate.js | 54 ++++++++++++++++++++++++++++++++++----- 1 file changed, 47 insertions(+), 7 deletions(-) diff --git a/include/dao/db_migrate.js b/include/dao/db_migrate.js index dc8030816..84ab5ada9 100644 --- a/include/dao/db_migrate.js +++ b/include/dao/db_migrate.js @@ -4,26 +4,30 @@ var util = require('../util.js'); module.exports = function DBMigrateModule(pb) { /** - * Array of collections used to append a "site" value to documents + * Array of collections used to append a "site" value to all documents * @private * @static * @readonly - * @property MIGRATE_COLL + * @property MIGRATE_ALL * @type {string[]} */ - var MIGRATE_COLL = [ + var MIGRATE_ALL = [ 'article', 'comment', 'custom_object_type', + 'custom_object', 'media', 'page', 'plugin', 'plugin_settings', 'section', - 'setting', 'theme_settings', - 'topic', - 'user' + 'topic' + ]; + + var MIGRATE_SPECIFIC = [ + 'user', + 'setting' ]; var GLOBAL_USERS = [ @@ -45,7 +49,7 @@ module.exports = function DBMigrateModule(pb) { siteService.getSiteMap(function(err, result) { if(pb.config.multisite && result.active.length === 0 && result.inactive.length === 0 ) { DBMigrate.createSite(function(err, isTaken, field, result) { - cb(null, true);//TODO: migrate content and plugin data to newly create site. + DBMigrate.migrateContentAndPluginData(result.uid, cb);//TODO: migrate content and plugin data to newly create site. }); } else { @@ -63,6 +67,42 @@ module.exports = function DBMigrateModule(pb) { siteService.createSite(site, '', cb); }; + DBMigrate.migrateContentAndPluginData = function(siteUid, cb) { + var tasks = pb.util.getTasks(MIGRATE_ALL, function(collections, i) { + return function(callback) { + DBMigrate.migrateCollection(collections[i], siteUid, callback); + } ; + }); + + + async.parallel(tasks, function(err, result) { + cb(err, result); + }); + }; + + DBMigrate.migrateCollection = function(collection, siteUid, callback) { + var dao = new pb.DAO(); + dao.q(collection, {}, function(err, results) { + console.log(collection); + console.log(results); + var tasks = util.getTasks(results, function(results, i) { + return function(callback) { + DBMigrate.applySiteToDocument(results[i], siteUid, callback); + }; + }); + + + async.parallel(tasks, function(err, result) { + callback(err, result); + }); + }); + }; + + DBMigrate.applySiteToDocument = function(document, siteUid, callback) { + document.site = siteUid; + var dao = new pb.DAO(); + dao.save(document, callback); + }; return DBMigrate; From 4d88b301746fe7a7aa73afc3a653b98f4b8282ca Mon Sep 17 00:00:00 2001 From: Christina Chatham Date: Wed, 24 Jun 2015 11:17:13 -0400 Subject: [PATCH 356/790] SectionService is only used for navigation so pull out of BaseAdminController. --- controllers/admin/base_admin_controller.js | 3 +-- .../admin/content/navigation/delete_nav_item.js | 3 ++- .../admin/content/navigation/edit_nav_item.js | 12 ++++++++++-- .../actions/admin/content/navigation/new_nav_item.js | 11 ++++++++++- .../admin/content/navigation/nav_item_form.js | 4 ++-- 5 files changed, 25 insertions(+), 8 deletions(-) diff --git a/controllers/admin/base_admin_controller.js b/controllers/admin/base_admin_controller.js index c6636c5be..11996331b 100644 --- a/controllers/admin/base_admin_controller.js +++ b/controllers/admin/base_admin_controller.js @@ -25,8 +25,7 @@ module.exports = function BaseAdminControllerModule(pb) { * This class serves as a base class for all the controllers used in the admin control panel * @constructor */ - function BaseAdminController() { - } + function BaseAdminController() {} util.inherits(BaseAdminController, BaseController); /** diff --git a/plugins/pencilblue/controllers/actions/admin/content/navigation/delete_nav_item.js b/plugins/pencilblue/controllers/actions/admin/content/navigation/delete_nav_item.js index ea083ec71..f1ab99f71 100644 --- a/plugins/pencilblue/controllers/actions/admin/content/navigation/delete_nav_item.js +++ b/plugins/pencilblue/controllers/actions/admin/content/navigation/delete_nav_item.js @@ -82,7 +82,8 @@ module.exports = function(pb) { }; DeleteNavItem.prototype.updateNavMap = function(removeID, cb) { - this.sectionService.removeFromSectionMap(removeID, cb); + var sectionService = new pb.SectionService(this.site, true); + sectionService.removeFromSectionMap(removeID, cb); }; //exports diff --git a/plugins/pencilblue/controllers/actions/admin/content/navigation/edit_nav_item.js b/plugins/pencilblue/controllers/actions/admin/content/navigation/edit_nav_item.js index 5523f38a0..f147d1387 100644 --- a/plugins/pencilblue/controllers/actions/admin/content/navigation/edit_nav_item.js +++ b/plugins/pencilblue/controllers/actions/admin/content/navigation/edit_nav_item.js @@ -19,12 +19,20 @@ module.exports = function(pb) { //pb dependencies var util = pb.util; - + var BaseAdminController = pb.BaseAdminController; /** * Edits a nav item */ function EditNavItem(){} - util.inherits(EditNavItem, pb.BaseAdminController); + util.inherits(EditNavItem, BaseAdminController); + + EditNavItem.prototype.init = function (props, cb) { + var self = this; + BaseAdminController.prototype.init.call(self, props, function () { + self.siteService = new pb.SectionService(self.site, true); + cb(); + }); + }; EditNavItem.prototype.render = function(cb){ var self = this; diff --git a/plugins/pencilblue/controllers/actions/admin/content/navigation/new_nav_item.js b/plugins/pencilblue/controllers/actions/admin/content/navigation/new_nav_item.js index 300c999e7..ae9984ef2 100644 --- a/plugins/pencilblue/controllers/actions/admin/content/navigation/new_nav_item.js +++ b/plugins/pencilblue/controllers/actions/admin/content/navigation/new_nav_item.js @@ -19,12 +19,21 @@ module.exports = function(pb) { //pb dependencies var util = pb.util; + var BaseAdminController = pb.BaseAdminController; /** * Creates a nav item */ function NewNavItem(){} - util.inherits(NewNavItem, pb.BaseAdminController); + util.inherits(NewNavItem, BaseAdminController); + + NewNavItem.prototype.init = function (props, cb) { + var self = this; + BaseAdminController.prototype.init.call(self, props, function () { + self.siteService = new pb.SectionService(self.site, true); + cb(); + }); + }; NewNavItem.prototype.render = function(cb){ var self = this; diff --git a/plugins/pencilblue/controllers/admin/content/navigation/nav_item_form.js b/plugins/pencilblue/controllers/admin/content/navigation/nav_item_form.js index 25944166d..3f3e856f6 100644 --- a/plugins/pencilblue/controllers/admin/content/navigation/nav_item_form.js +++ b/plugins/pencilblue/controllers/admin/content/navigation/nav_item_form.js @@ -23,7 +23,6 @@ module.exports = function(pb) { //pb dependencies var util = pb.util; var SectionService = pb.SectionService; - /** * Interface for creating and editing navigation items * @class NavItemFormController @@ -83,7 +82,8 @@ module.exports = function(pb) { //get parents parents: function(callback) { - self.sectionService.getParentSelectList(self.pathVars.id, function(err, parents) { + var sectionService = new SectionService(self.site, true); + sectionService.getParentSelectList(self.pathVars.id, function(err, parents) { if(util.isError(err)) { callback(err, parents); return; From d168c70366940ab7183a1b7ae037c8758f095e4c Mon Sep 17 00:00:00 2001 From: Christina Chatham Date: Wed, 24 Jun 2015 11:28:27 -0400 Subject: [PATCH 357/790] Remove from BaseAdminController declarations that are only used in one spot --- controllers/admin/base_admin_controller.js | 1 - .../pencilblue/controllers/admin/site_settings/configuration.js | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/controllers/admin/base_admin_controller.js b/controllers/admin/base_admin_controller.js index 11996331b..31d5ae876 100644 --- a/controllers/admin/base_admin_controller.js +++ b/controllers/admin/base_admin_controller.js @@ -51,7 +51,6 @@ module.exports = function BaseAdminControllerModule(pb) { self.sectionService = new pb.SectionService(self.site, true); self.siteQueryService = new pb.SiteQueryService(self.site, true); self.settings = pb.SettingServiceFactory.getServiceBySite(self.site, true); - self.siteObj = siteInfo; self.isGlobalSite = pb.SiteService.isGlobal(siteInfo.uid); self.siteName = self.isGlobalSite ? siteInfo.uid : siteInfo.displayName; cb(); diff --git a/plugins/pencilblue/controllers/admin/site_settings/configuration.js b/plugins/pencilblue/controllers/admin/site_settings/configuration.js index cd4b6f884..c810044bb 100755 --- a/plugins/pencilblue/controllers/admin/site_settings/configuration.js +++ b/plugins/pencilblue/controllers/admin/site_settings/configuration.js @@ -62,7 +62,7 @@ module.exports = function(pb) { navigation: pb.AdminNavigation.get(self.session, ['settings', 'site_settings'], self.ls), pills: self.getAdminPills(SUB_NAV_KEY, self.ls, 'configuration', {site: self.site}), config: config, - isGlobalSite: self.isGlobalSite + isGlobalSite: pb.SiteService.isGlobal(self.site) }); self.setPageName(self.ls.get('CONFIGURATION')); From d93209ee8bf39e86734eb83eaeb9868f84079d8b Mon Sep 17 00:00:00 2001 From: btidwell Date: Wed, 24 Jun 2015 13:10:19 -0400 Subject: [PATCH 358/790] migrate on site settings certain documents with specific keys in the setting collection are ignored. --- include/dao/db_manager.js | 2 +- include/dao/db_migrate.js | 139 +++++++++++++++++++++++--------------- 2 files changed, 85 insertions(+), 56 deletions(-) diff --git a/include/dao/db_manager.js b/include/dao/db_manager.js index c5131a35e..831942dbb 100755 --- a/include/dao/db_manager.js +++ b/include/dao/db_manager.js @@ -283,7 +283,7 @@ module.exports = function DBManagerModule(pb) { this.processMigration = function(cb) { var DBMigrate = require('./db_migrate.js')(pb); - DBMigrate.run(cb); + new DBMigrate().run(cb); }; /** diff --git a/include/dao/db_migrate.js b/include/dao/db_migrate.js index 84ab5ada9..a53dad9c1 100644 --- a/include/dao/db_migrate.js +++ b/include/dao/db_migrate.js @@ -42,68 +42,97 @@ module.exports = function DBMigrateModule(pb) { 'email_settings' ]; - function DBMigrate(){} - - DBMigrate.run = function(cb) { - var siteService = new pb.SiteService(); - siteService.getSiteMap(function(err, result) { - if(pb.config.multisite && result.active.length === 0 && result.inactive.length === 0 ) { - DBMigrate.createSite(function(err, isTaken, field, result) { - DBMigrate.migrateContentAndPluginData(result.uid, cb);//TODO: migrate content and plugin data to newly create site. - }); - } - else { - cb(null, true); - } - }); - }; - - DBMigrate.createSite = function(cb) { - var siteService = new pb.SiteService(); - var site = pb.DocumentCreator.create('site', { - displayName: pb.config.siteName, - hostname: url.parse(pb.config.siteRoot).host - }); - siteService.createSite(site, '', cb); - }; - - DBMigrate.migrateContentAndPluginData = function(siteUid, cb) { - var tasks = pb.util.getTasks(MIGRATE_ALL, function(collections, i) { - return function(callback) { - DBMigrate.migrateCollection(collections[i], siteUid, callback); - } ; - }); - - - async.parallel(tasks, function(err, result) { - cb(err, result); - }); - }; - - DBMigrate.migrateCollection = function(collection, siteUid, callback) { - var dao = new pb.DAO(); - dao.q(collection, {}, function(err, results) { - console.log(collection); - console.log(results); - var tasks = util.getTasks(results, function(results, i) { - return function(callback) { - DBMigrate.applySiteToDocument(results[i], siteUid, callback); + function DBMigrate() { + + this.run = function (cb) { + var self = this; + var siteService = new pb.SiteService(); + siteService.getSiteMap(function (err, result) { + if (pb.config.multisite && result.active.length === 0 && result.inactive.length === 0) { + self.createSite(function (err, isTaken, field, result) { + self.siteUid = result.uid; + var tasks = [ + util.wrapTask(self, self.migrateContentAndPluginData), + util.wrapTask(self, self.migrateSettings) + ]; + //self.migrateContentAndPluginData(cb); + async.series(tasks, function(err, result) { + cb(null, true); + }); + }); + } + else { + cb(null, true); + } + }); + }; + + this.createSite = function (cb) { + var siteService = new pb.SiteService(); + var site = pb.DocumentCreator.create('site', { + displayName: pb.config.siteName, + hostname: url.parse(pb.config.siteRoot).host + }); + siteService.createSite(site, '', cb); + }; + + this.migrateContentAndPluginData = function(cb) { + var self = this; + var tasks = pb.util.getTasks(MIGRATE_ALL, function (collections, i) { + return function (callback) { + self.migrateCollection(collections[i], self.siteUid, callback); }; }); - async.parallel(tasks, function(err, result) { - callback(err, result); + async.parallel(tasks, function (err, result) { + cb(err, result); + }); + }; + + this.migrateSettings = function (cb) { + var self = this; + var dao = new pb.DAO(); + dao.q('setting', {}, function(err, results) { + var tasks = util.getTasks(results, function(results, i) { + return function(callback) { + if(SITE_SPECIFIC_SETTINGS.indexOf(results[i].key) > -1) { + self.applySiteToDocument(results[i], self.siteUid, callback); + } + else { + callback(null, true); + } + } + }); + async.parallel(tasks, function(err, result) { + cb(null, true); + }); }); - }); - }; + }; + + this.migrateCollection = function (collection, siteUid, callback) { + var self = this; + var dao = new pb.DAO(); + dao.q(collection, {}, function (err, results) { + var tasks = util.getTasks(results, function (results, i) { + return function (callback) { + self.applySiteToDocument(results[i], siteUid, callback); + }; + }); - DBMigrate.applySiteToDocument = function(document, siteUid, callback) { - document.site = siteUid; - var dao = new pb.DAO(); - dao.save(document, callback); - }; + async.parallel(tasks, function (err, result) { + callback(err, result); + }); + }); + }; + + this.applySiteToDocument = function (document, siteUid, callback) { + document.site = siteUid; + var dao = new pb.DAO(); + dao.save(document, callback); + }; + } return DBMigrate; }; \ No newline at end of file From e0b916c32b1834338aaa669cb298b23b625086ee Mon Sep 17 00:00:00 2001 From: andparker Date: Wed, 24 Jun 2015 13:21:17 -0400 Subject: [PATCH 359/790] Lays down the foundation for inactive site route access -Adds the access flag to the admin routes --- include/http/request_handler.js | 22 +++- include/service/entities/site_service.js | 11 +- .../service/jobs/sites/site_activate_job.js | 2 +- .../service/jobs/sites/site_deactivate_job.js | 2 +- plugins/ga/ga.js | 2 +- plugins/pencilblue/include/routes.js | 108 ++++++++++++++++++ .../controllers/home_page_settings.js | 1 + .../controllers/save_home_page_settings.js | 8 +- 8 files changed, 137 insertions(+), 19 deletions(-) diff --git a/include/http/request_handler.js b/include/http/request_handler.js index e69a7d881..3a4d17302 100755 --- a/include/http/request_handler.js +++ b/include/http/request_handler.js @@ -141,13 +141,15 @@ module.exports = function RequestHandlerModule(pb) { }; RequestHandler.loadSite = function(site) { - RequestHandler.sites[site.hostname] = site.uid; + RequestHandler.sites[site.hostname] = { active: site.active, uid: site.uid, displayName: site.displayName }; }; - RequestHandler.unloadSite = function(site) { - if(RequestHandler.sites[site.hostname]) { - delete RequestHandler.sites[site.hostname]; - } + RequestHandler.activateSite = function(site) { + RequestHandler.sites[site.hostname].active = true; + }; + + RequestHandler.deactivateSite = function(site) { + RequestHandler.sites[site.hostname].active = false; }; /** @@ -631,7 +633,9 @@ module.exports = function RequestHandlerModule(pb) { this.session = session; //set the site -- how do we handle improper sites here? - this.site = RequestHandler.sites[this.hostname] || GLOBAL_SITE; + //TODO Handle global differently here when we pull through global site designation + this.siteObject = RequestHandler.sites[this.hostname] ? RequestHandler.sites[this.hostname] : { active: true, uid: pb.SiteService.GLOBAL_SITE}; + this.site = this.siteObject.uid; //find the controller to hand off to var route = this.getRoute(this.url.pathname); @@ -795,6 +799,12 @@ module.exports = function RequestHandlerModule(pb) { return; } + var inactiveSiteAccess = route.themes[rt.site][rt.theme][rt.method].inactive_site_access; + if (!this.siteObject.active && !inactiveSiteAccess) { + this.serve404(); + return; + } + //do security checks this.checkSecurity(rt.theme, rt.method, rt.site, function(err, result) { if (pb.log.isSilly()) { diff --git a/include/service/entities/site_service.js b/include/service/entities/site_service.js index 9bf41910f..0c85763bc 100644 --- a/include/service/entities/site_service.js +++ b/include/service/entities/site_service.js @@ -36,6 +36,11 @@ module.exports = function SiteServiceModule(pb) { } }; + SiteService.prototype.getAllSites = function(cb) { + var dao = new pb.DAO(); + dao.q(SITE_COLL, { select: pb.DAO.SELECT_ALL, where: {} }, cb); + }; + SiteService.prototype.getActiveSites = function(cb) { var dao = new pb.DAO(); dao.q(SITE_COLL, { select: pb.DAO.SELECT_ALL, where: {active: true} }, cb); @@ -188,7 +193,7 @@ module.exports = function SiteServiceModule(pb) { } else if (!site.active) { cb(new Error('Site not active'), null); } else { - pb.RequestHandler.loadSite(site); + pb.RequestHandler.activateSite(site); cb(err, result) } }); @@ -204,14 +209,14 @@ module.exports = function SiteServiceModule(pb) { } else if (site.active) { cb(new Error('Site not deactivated'), null); } else { - pb.RequestHandler.unloadSite(site); + pb.RequestHandler.deactivateSite(site); cb(err, result) } }); }; SiteService.prototype.initSites = function(cb) { - this.getActiveSites(function(err, results) { + this.getAllSites(function(err, results) { if(err) { cb(err); } else { diff --git a/include/service/jobs/sites/site_activate_job.js b/include/service/jobs/sites/site_activate_job.js index f99391501..774868a0d 100644 --- a/include/service/jobs/sites/site_activate_job.js +++ b/include/service/jobs/sites/site_activate_job.js @@ -84,7 +84,7 @@ module.exports = function SiteActivateJobModule(pb) { return; } - pb.RequestHandler.loadSite(site); + pb.RequestHandler.activateSite(site); callback(err, result) }); } diff --git a/include/service/jobs/sites/site_deactivate_job.js b/include/service/jobs/sites/site_deactivate_job.js index c499a528d..8ecdb276b 100644 --- a/include/service/jobs/sites/site_deactivate_job.js +++ b/include/service/jobs/sites/site_deactivate_job.js @@ -81,7 +81,7 @@ module.exports = function SiteDeactivateJobModule(pb) { return; } - pb.RequestHandler.unloadSite(site); + pb.RequestHandler.deactivateSite(site); callback(err, result); }); } diff --git a/plugins/ga/ga.js b/plugins/ga/ga.js index 98f7fade9..bb164c84f 100755 --- a/plugins/ga/ga.js +++ b/plugins/ga/ga.js @@ -64,7 +64,7 @@ module.exports = function GoogleAnalyticsModule(pb) { * */ GoogleAnalytics.onRequest = function(req, session, ls, cb) { - var siteId = pb.RequestHandler.sites[req.headers.host]; + var siteId = pb.RequestHandler.sites[req.headers.host] ? pb.RequestHandler.sites[req.headers.host].uid : null; var pluginService = new pb.PluginService(pb.SiteService.getCurrentSite(siteId)); pluginService.getSettingsKV('ga', function(err, settings) { if (util.isError(err)) { diff --git a/plugins/pencilblue/include/routes.js b/plugins/pencilblue/include/routes.js index 973132413..01bd949e4 100644 --- a/plugins/pencilblue/include/routes.js +++ b/plugins/pencilblue/include/routes.js @@ -25,6 +25,7 @@ module.exports = function Routes(pb){ method: 'get', path: '/media/*', auth_required: false, + inactive_site_access: true, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'media_content_controller.js') }, { @@ -59,6 +60,7 @@ module.exports = function Routes(pb){ path: "/admin/login", access_level: 0, auth_required: false, + inactive_site_access: true, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'login.js'), content_type: 'text/html' }, @@ -67,6 +69,7 @@ module.exports = function Routes(pb){ path: "/actions/login", access_level: 0, auth_required: false, + inactive_site_access: true, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'login.js'), content_type: 'text/html' }, @@ -75,6 +78,7 @@ module.exports = function Routes(pb){ path: "/actions/forgot_password", access_level: 0, auth_required: false, + inactive_site_access: true, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'forgot_password.js'), content_type: 'text/html' }, @@ -83,6 +87,7 @@ module.exports = function Routes(pb){ path: "/actions/user/reset_password", access_level: 0, auth_required: false, + inactive_site_access: true, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'user', 'reset_password.js'), content_type: 'text/html' }, @@ -91,12 +96,14 @@ module.exports = function Routes(pb){ path: "/admin", access_level: pb.SecurityService.ACCESS_WRITER, auth_required: true, + inactive_site_access: true, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'index.js'), content_type: 'text/html' }, { path: "/actions/logout", access_level: 0, + inactive_site_access: true, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'logout.js'), content_type: 'text/html' }, @@ -113,6 +120,7 @@ module.exports = function Routes(pb){ path: "/preview/:type/:id", access_level: pb.SecurityService.ACCESS_WRITER, auth_required: true, + inactive_site_access: true, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'preview.js'), content_type: 'text/html' }, @@ -171,6 +179,7 @@ module.exports = function Routes(pb){ method: 'get', path: "/api/user/get_username_available", auth_required: false, + inactive_site_access: true, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'api', 'user', 'get_username_available.js'), content_type: 'application/json' }, @@ -249,6 +258,7 @@ module.exports = function Routes(pb){ method: 'get', path: "/admin/users/permissions", auth_required: true, + inactive_site_access: true, access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'users', 'permissions.js'), content_type: 'text/html' @@ -269,6 +279,7 @@ module.exports = function Routes(pb){ method: 'get', path: "/api/url/:action", auth_required: true, + inactive_site_access: true, access_level: pb.SecurityService.ACCESS_WRITER, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'api', 'admin', 'url_api.js'), content_type: 'application/json' @@ -285,6 +296,7 @@ module.exports = function Routes(pb){ method: 'post', path: "/api/cluster/:action", auth_required: true, + inactive_site_access: true, access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'api', 'admin', 'system', 'cluster_api.js'), content_type: 'application/json' @@ -293,6 +305,7 @@ module.exports = function Routes(pb){ method: 'post', path: "/api/jobs/:action/:id", auth_required: true, + inactive_site_access: true, access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'api', 'jobs', 'job_api_controller.js'), content_type: 'application/json' @@ -301,6 +314,7 @@ module.exports = function Routes(pb){ method: 'post', path: "/api/admin/site_settings/email/send_test", auth_required: true, + inactive_site_access: true, access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'api', 'admin', 'site_settings', 'email', 'send_test.js'), content_type: 'application/json' @@ -314,6 +328,7 @@ module.exports = function Routes(pb){ path: "/admin/content/navigation", access_level: pb.SecurityService.ACCESS_EDITOR, auth_required: true, + inactive_site_access: true, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'content', 'navigation', 'nav_map.js'), content_type: 'text/html' }, @@ -322,6 +337,7 @@ module.exports = function Routes(pb){ path: "/admin/content/navigation/new", access_level: pb.SecurityService.ACCESS_EDITOR, auth_required: true, + inactive_site_access: true, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'content', 'navigation', 'nav_item_form.js'), content_type: 'text/html' }, @@ -330,6 +346,7 @@ module.exports = function Routes(pb){ path: "/admin/content/navigation/:id", access_level: pb.SecurityService.ACCESS_EDITOR, auth_required: true, + inactive_site_access: true, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'content', 'navigation', 'nav_item_form.js'), content_type: 'text/html' }, @@ -338,6 +355,7 @@ module.exports = function Routes(pb){ path: "/actions/admin/content/navigation/map", access_level: pb.SecurityService.ACCESS_EDITOR, auth_required: true, + inactive_site_access: true, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'content', 'navigation', 'nav_map.js'), content_type: 'text/html' }, @@ -346,6 +364,7 @@ module.exports = function Routes(pb){ path: "/actions/admin/content/navigation", access_level: pb.SecurityService.ACCESS_EDITOR, auth_required: true, + inactive_site_access: true, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'content', 'navigation', 'new_nav_item.js'), content_type: 'text/html' }, @@ -354,6 +373,7 @@ module.exports = function Routes(pb){ path: "/actions/admin/content/navigation/:id", access_level: pb.SecurityService.ACCESS_EDITOR, auth_required: true, + inactive_site_access: true, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'content', 'navigation', 'edit_nav_item.js'), content_type: 'text/html' }, @@ -362,6 +382,7 @@ module.exports = function Routes(pb){ path: "/actions/admin/content/navigation/:id", access_level: pb.SecurityService.ACCESS_EDITOR, auth_required: true, + inactive_site_access: true, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'content', 'navigation', 'delete_nav_item.js'), content_type: 'text/html' }, @@ -372,6 +393,7 @@ module.exports = function Routes(pb){ path: "/admin/content/topics", access_level: pb.SecurityService.ACCESS_EDITOR, auth_required: true, + inactive_site_access: true, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'content', 'topics', 'manage_topics.js'), content_type: 'text/html' }, @@ -380,6 +402,7 @@ module.exports = function Routes(pb){ path: "/admin/content/topics/new", access_level: pb.SecurityService.ACCESS_EDITOR, auth_required: true, + inactive_site_access: true, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'content', 'topics', 'topic_form.js'), content_type: 'text/html' }, @@ -388,6 +411,7 @@ module.exports = function Routes(pb){ path: "/admin/content/topics/import", access_level: pb.SecurityService.ACCESS_EDITOR, auth_required: true, + inactive_site_access: true, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'content', 'topics', 'import_topics.js'), content_type: 'text/html' }, @@ -396,6 +420,7 @@ module.exports = function Routes(pb){ path: "/admin/content/topics/:id", access_level: pb.SecurityService.ACCESS_EDITOR, auth_required: true, + inactive_site_access: true, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'content', 'topics', 'topic_form.js'), content_type: 'text/html' }, @@ -412,6 +437,7 @@ module.exports = function Routes(pb){ path: "/actions/admin/content/topics/import", access_level: pb.SecurityService.ACCESS_EDITOR, auth_required: true, + inactive_site_access: true, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'content', 'topics', 'import_topics.js'), content_type: 'text/html' }, @@ -420,6 +446,7 @@ module.exports = function Routes(pb){ path: "/actions/admin/content/topics/:id", access_level: pb.SecurityService.ACCESS_EDITOR, auth_required: true, + inactive_site_access: true, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'content', 'topics', 'edit_topic.js'), content_type: 'text/html' }, @@ -428,6 +455,7 @@ module.exports = function Routes(pb){ path: "/actions/admin/content/topics/:id", access_level: pb.SecurityService.ACCESS_EDITOR, auth_required: true, + inactive_site_access: true, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'content', 'topics', 'delete_topic.js'), content_type: 'text/html' }, @@ -438,6 +466,7 @@ module.exports = function Routes(pb){ path: "/admin/content/articles", access_level: pb.SecurityService.ACCESS_WRITER, auth_required: true, + inactive_site_access: true, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'content', 'articles', 'manage_articles.js'), content_type: 'text/html' }, @@ -446,6 +475,7 @@ module.exports = function Routes(pb){ path: "/admin/content/articles/new", access_level: pb.SecurityService.ACCESS_WRITER, auth_required: true, + inactive_site_access: true, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'content', 'articles', 'article_form.js'), content_type: 'text/html' }, @@ -454,6 +484,7 @@ module.exports = function Routes(pb){ path: "/admin/content/articles/:id", access_level: pb.SecurityService.ACCESS_WRITER, auth_required: true, + inactive_site_access: true, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'content', 'articles', 'article_form.js'), content_type: 'text/html' }, @@ -462,6 +493,7 @@ module.exports = function Routes(pb){ path: "/actions/admin/content/articles", access_level: pb.SecurityService.ACCESS_WRITER, auth_required: true, + inactive_site_access: true, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'content', 'articles', 'new_article.js'), content_type: 'text/html' }, @@ -470,6 +502,7 @@ module.exports = function Routes(pb){ path: "/actions/admin/content/articles/:id", access_level: pb.SecurityService.ACCESS_WRITER, auth_required: true, + inactive_site_access: true, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'content', 'articles', 'edit_article.js'), content_type: 'text/html' }, @@ -478,6 +511,7 @@ module.exports = function Routes(pb){ path: "/actions/admin/content/articles/:id", access_level: pb.SecurityService.ACCESS_EDITOR, auth_required: true, + inactive_site_access: true, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'content', 'articles', 'delete_article.js'), }, @@ -487,6 +521,7 @@ module.exports = function Routes(pb){ path: "/admin/content/pages", access_level: pb.SecurityService.ACCESS_EDITOR, auth_required: true, + inactive_site_access: true, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'content', 'pages', 'manage_pages.js'), content_type: 'text/html' }, @@ -495,6 +530,7 @@ module.exports = function Routes(pb){ path: "/admin/content/pages/new", access_level: pb.SecurityService.ACCESS_EDITOR, auth_required: true, + inactive_site_access: true, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'content', 'pages', 'page_form.js'), content_type: 'text/html' }, @@ -503,6 +539,7 @@ module.exports = function Routes(pb){ path: "/admin/content/pages/:id", access_level: pb.SecurityService.ACCESS_EDITOR, auth_required: true, + inactive_site_access: true, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'content', 'pages', 'page_form.js'), content_type: 'text/html' }, @@ -511,6 +548,7 @@ module.exports = function Routes(pb){ path: "/actions/admin/content/pages", access_level: pb.SecurityService.ACCESS_EDITOR, auth_required: true, + inactive_site_access: true, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'content', 'pages', 'new_page.js'), content_type: 'text/html' }, @@ -519,6 +557,7 @@ module.exports = function Routes(pb){ path: "/actions/admin/content/pages/:id", access_level: pb.SecurityService.ACCESS_EDITOR, auth_required: true, + inactive_site_access: true, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'content', 'pages', 'edit_page.js'), content_type: 'text/html' }, @@ -527,6 +566,7 @@ module.exports = function Routes(pb){ path: "/actions/admin/content/pages/:id", access_level: pb.SecurityService.ACCESS_EDITOR, auth_required: true, + inactive_site_access: true, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'content', 'pages', 'delete_page.js'), content_type: 'text/html' }, @@ -537,6 +577,7 @@ module.exports = function Routes(pb){ path: "/admin/content/media", access_level: pb.SecurityService.ACCESS_WRITER, auth_required: true, + inactive_site_access: true, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'content', 'media', 'manage_media.js'), content_type: 'text/html' }, @@ -545,6 +586,7 @@ module.exports = function Routes(pb){ path: "/admin/content/media/new", access_level: pb.SecurityService.ACCESS_WRITER, auth_required: true, + inactive_site_access: true, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'content', 'media', 'media_form.js'), content_type: 'text/html' }, @@ -553,6 +595,7 @@ module.exports = function Routes(pb){ path: "/admin/content/media/:id", access_level: pb.SecurityService.ACCESS_WRITER, auth_required: true, + inactive_site_access: true, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'content', 'media', 'media_form.js'), content_type: 'text/html' }, @@ -561,6 +604,7 @@ module.exports = function Routes(pb){ path: "/actions/admin/content/media", access_level: pb.SecurityService.ACCESS_WRITER, auth_required: true, + inactive_site_access: true, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'content', 'media', 'new_media.js'), content_type: 'text/html' }, @@ -569,6 +613,7 @@ module.exports = function Routes(pb){ path: "/actions/admin/content/media/:id", access_level: pb.SecurityService.ACCESS_WRITER, auth_required: true, + inactive_site_access: true, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'content', 'media', 'edit_media.js'), content_type: 'text/html' }, @@ -577,6 +622,7 @@ module.exports = function Routes(pb){ path: "/actions/admin/content/media/:id", access_level: pb.SecurityService.ACCESS_WRITER, auth_required: true, + inactive_site_access: true, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'content', 'media', 'delete_media.js'), content_type: 'text/html' }, @@ -585,6 +631,7 @@ module.exports = function Routes(pb){ path: "/api/admin/content/media/upload_media", access_level: pb.SecurityService.ACCESS_WRITER, auth_required: true, + inactive_site_access: true, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'api', 'admin', 'content', 'media', 'upload_media.js'), content_type: 'text/html' }, @@ -593,6 +640,7 @@ module.exports = function Routes(pb){ path: "/api/admin/content/media/get_link", access_level: pb.SecurityService.ACCESS_WRITER, auth_required: true, + inactive_site_access: true, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'api', 'admin', 'content', 'media', 'get_link.js'), content_type: 'application/json' }, @@ -601,6 +649,7 @@ module.exports = function Routes(pb){ path: "/api/admin/content/media/get_preview", access_level: pb.SecurityService.ACCESS_WRITER, auth_required: true, + inactive_site_access: true, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'api', 'admin', 'content', 'media', 'get_preview.js'), content_type: 'application/json' }, @@ -610,6 +659,7 @@ module.exports = function Routes(pb){ method: 'get', path: "/admin/content/comments", auth_required: true, + inactive_site_access: true, access_level: pb.SecurityService.ACCESS_EDITOR, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'content', 'comments', 'manage_comments.js'), content_type: 'text/html' @@ -619,6 +669,7 @@ module.exports = function Routes(pb){ path: "/actions/admin/content/comments/:id", access_level: pb.SecurityService.ACCESS_EDITOR, auth_required: true, + inactive_site_access: true, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'content', 'comments', 'delete_comment.js'), content_type: 'text/html' }, @@ -629,6 +680,7 @@ module.exports = function Routes(pb){ path: "/admin/content/objects/types", access_level: pb.SecurityService.ACCESS_EDITOR, auth_required: true, + inactive_site_access: true, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'content', 'objects', 'types', 'manage_types.js'), content_type: 'text/html' }, @@ -637,6 +689,7 @@ module.exports = function Routes(pb){ path: "/admin/content/objects/types/new", access_level: pb.SecurityService.ACCESS_EDITOR, auth_required: true, + inactive_site_access: true, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'content', 'objects', 'types', 'type_form.js'), content_type: 'text/html' }, @@ -645,6 +698,7 @@ module.exports = function Routes(pb){ path: "/admin/content/objects/types/:id", access_level: pb.SecurityService.ACCESS_EDITOR, auth_required: true, + inactive_site_access: true, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'content', 'objects', 'types', 'type_form.js'), content_type: 'text/html' }, @@ -653,12 +707,14 @@ module.exports = function Routes(pb){ path: "/api/admin/content/objects/types/available", access_level: pb.SecurityService.ACCESS_EDITOR, auth_required: true, + inactive_site_access: true, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'api', 'admin', 'content', 'objects', 'types', 'available.js'), content_type: 'text/html' }, { method: 'post', path: "/actions/admin/content/objects/types", + inactive_site_access: true, access_level: pb.SecurityService.ACCESS_EDITOR, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'content', 'objects', 'types', 'new_type.js'), content_type: 'text/html', @@ -669,6 +725,7 @@ module.exports = function Routes(pb){ path: "/actions/admin/content/objects/types/:id", access_level: pb.SecurityService.ACCESS_EDITOR, auth_required: true, + inactive_site_access: true, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'content', 'objects', 'types', 'edit_type.js'), content_type: 'text/html', request_body: ['application/json'] @@ -678,6 +735,7 @@ module.exports = function Routes(pb){ path: "/actions/admin/content/objects/types/:id", access_level: pb.SecurityService.ACCESS_EDITOR, auth_required: true, + inactive_site_access: true, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'content', 'objects', 'types', 'delete_type.js'), content_type: 'text/html' }, @@ -687,6 +745,7 @@ module.exports = function Routes(pb){ path: "/admin/content/objects/:type_id", access_level: pb.SecurityService.ACCESS_EDITOR, auth_required: true, + inactive_site_access: true, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'content', 'objects', 'manage_objects.js'), content_type: 'text/html' }, @@ -694,6 +753,7 @@ module.exports = function Routes(pb){ path: "/admin/content/objects/:type_id/sort", access_level: pb.SecurityService.ACCESS_EDITOR, auth_required: true, + inactive_site_access: true, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'content', 'objects', 'sort_objects.js'), content_type: 'text/html' }, @@ -702,6 +762,7 @@ module.exports = function Routes(pb){ path: "/admin/content/objects/:type_id/new", access_level: pb.SecurityService.ACCESS_EDITOR, auth_required: true, + inactive_site_access: true, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'content', 'objects', 'object_form.js'), content_type: 'text/html' }, @@ -710,6 +771,7 @@ module.exports = function Routes(pb){ path: "/admin/content/objects/:type_id/:id", access_level: pb.SecurityService.ACCESS_EDITOR, auth_required: true, + inactive_site_access: true, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'content', 'objects', 'object_form.js'), content_type: 'text/html' }, @@ -718,6 +780,7 @@ module.exports = function Routes(pb){ path: "/actions/admin/content/objects/:type_id/sort", access_level: pb.SecurityService.ACCESS_EDITOR, auth_required: true, + inactive_site_access: true, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'content', 'objects', 'sort_objects.js'), content_type: 'text/html', request_body: ['application/json'] @@ -727,6 +790,7 @@ module.exports = function Routes(pb){ path: "/actions/admin/content/objects/:type_id", access_level: pb.SecurityService.ACCESS_EDITOR, auth_required: true, + inactive_site_access: true, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'content', 'objects', 'new_object.js'), content_type: 'text/html', request_body: ['application/json'] @@ -736,6 +800,7 @@ module.exports = function Routes(pb){ path: "/actions/admin/content/objects/:type_id/:id", access_level: pb.SecurityService.ACCESS_EDITOR, auth_required: true, + inactive_site_access: true, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'content', 'objects', 'edit_object.js'), content_type: 'text/html', request_body: ['application/json'] @@ -745,6 +810,7 @@ module.exports = function Routes(pb){ path: "/actions/admin/content/objects/:id", access_level: pb.SecurityService.ACCESS_EDITOR, auth_required: true, + inactive_site_access: true, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'content', 'objects', 'delete_object.js'), content_type: 'text/html' }, @@ -754,6 +820,7 @@ module.exports = function Routes(pb){ method: 'get', path: "/admin/plugins", auth_required: true, + inactive_site_access: true, access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'plugins', 'manage_plugins.js'), content_type: 'text/html' @@ -762,6 +829,7 @@ module.exports = function Routes(pb){ method: 'get', path: "/admin/plugins/:id", auth_required: true, + inactive_site_access: true, access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'plugins', 'plugin_details.js'), content_type: 'text/html' @@ -771,6 +839,7 @@ module.exports = function Routes(pb){ path: "/admin/plugins/:id/settings", handler: 'get', auth_required: true, + inactive_site_access: true, access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'plugins', 'plugin_settings.js'), content_type: 'text/html' @@ -780,6 +849,7 @@ module.exports = function Routes(pb){ path: "/admin/plugins/:id/settings", handler: 'post', auth_required: true, + inactive_site_access: true, access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'plugins', 'plugin_settings.js'), content_type: 'application/json', @@ -789,6 +859,7 @@ module.exports = function Routes(pb){ method: 'post', path: "/api/plugins/:action/:id", auth_required: true, + inactive_site_access: true, access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'api', 'plugins', 'plugin_api.js'), content_type: 'application/json' @@ -799,6 +870,7 @@ module.exports = function Routes(pb){ method: 'get', path: "/admin/themes", auth_required: true, + inactive_site_access: true, access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'themes', 'manage_themes.js'), content_type: 'text/html' @@ -808,6 +880,7 @@ module.exports = function Routes(pb){ path: "/admin/themes/:id/settings", handler: 'get', auth_required: true, + inactive_site_access: true, access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'themes', 'theme_settings.js'), content_type: 'text/html' @@ -817,6 +890,7 @@ module.exports = function Routes(pb){ path: "/admin/themes/:id/settings", handler: 'post', auth_required: true, + inactive_site_access: true, access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'themes', 'theme_settings.js'), content_type: 'application/json', @@ -826,6 +900,7 @@ module.exports = function Routes(pb){ method: 'post', path: "/actions/admin/themes/site_logo", auth_required: true, + inactive_site_access: true, access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'themes', 'site_logo.js'), }, @@ -835,6 +910,7 @@ module.exports = function Routes(pb){ method: 'get', path: "/admin/users", auth_required: true, + inactive_site_access: true, access_level: pb.SecurityService.ACCESS_EDITOR, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'users', 'manage_users.js'), }, @@ -842,6 +918,7 @@ module.exports = function Routes(pb){ method: 'get', path: "/admin/users/unverified", auth_required: true, + inactive_site_access: true, access_level: pb.SecurityService.ACCESS_EDITOR, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'users', 'unverified_users.js'), }, @@ -849,6 +926,7 @@ module.exports = function Routes(pb){ method: 'get', path: "/admin/users/new", auth_required: true, + inactive_site_access: true, access_level: pb.SecurityService.ACCESS_EDITOR, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'users', 'user_form.js'), }, @@ -856,6 +934,7 @@ module.exports = function Routes(pb){ method: 'get', path: "/admin/users/:id", auth_required: true, + inactive_site_access: true, access_level: pb.SecurityService.ACCESS_EDITOR, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'users', 'user_form.js'), }, @@ -863,6 +942,7 @@ module.exports = function Routes(pb){ method: 'get', path: "/admin/users/password/:id", auth_required: true, + inactive_site_access: true, access_level: pb.SecurityService.ACCESS_EDITOR, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'users', 'change_password.js'), }, @@ -870,6 +950,7 @@ module.exports = function Routes(pb){ method: 'post', path: "/actions/admin/users", auth_required: true, + inactive_site_access: true, access_level: pb.SecurityService.ACCESS_EDITOR, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'users', 'new_user.js'), }, @@ -877,6 +958,7 @@ module.exports = function Routes(pb){ method: 'post', path: "/actions/admin/users/:id", auth_required: true, + inactive_site_access: true, access_level: pb.SecurityService.ACCESS_EDITOR, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'users', 'edit_user.js'), }, @@ -884,6 +966,7 @@ module.exports = function Routes(pb){ method: 'delete', path: "/actions/admin/users/:id", auth_required: true, + inactive_site_access: true, access_level: pb.SecurityService.ACCESS_EDITOR, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'users', 'delete_user.js'), }, @@ -891,6 +974,7 @@ module.exports = function Routes(pb){ method: 'delete', path: "/actions/admin/users/unverified/:id", auth_required: true, + inactive_site_access: true, access_level: pb.SecurityService.ACCESS_EDITOR, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'users', 'delete_unverified_user.js'), }, @@ -898,6 +982,7 @@ module.exports = function Routes(pb){ method: 'get', path: "/actions/admin/users/verify/:id", auth_required: true, + inactive_site_access: true, access_level: pb.SecurityService.ACCESS_EDITOR, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'users', 'verify_user.js'), }, @@ -905,6 +990,7 @@ module.exports = function Routes(pb){ method: 'post', path: "/actions/admin/users/change_password/:id", auth_required: true, + inactive_site_access: true, access_level: pb.SecurityService.ACCESS_EDITOR, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'users', 'change_password.js'), }, @@ -912,6 +998,7 @@ module.exports = function Routes(pb){ method: 'get', path: "/actions/admin/users/send_password_reset/:id", auth_required: true, + inactive_site_access: true, access_level: pb.SecurityService.ACCESS_MANAGING_EDITOR, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'users', 'send_password_reset.js'), }, @@ -919,6 +1006,7 @@ module.exports = function Routes(pb){ method: 'post', path: "/actions/admin/users/send_password_reset/:id", auth_required: true, + inactive_site_access: true, access_level: pb.SecurityService.ACCESS_MANAGING_EDITOR, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'users', 'send_password_reset.js'), }, @@ -929,6 +1017,7 @@ module.exports = function Routes(pb){ path: "/admin/site_settings", access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, auth_required: true, + inactive_site_access: true, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'site_settings', 'configuration.js'), content_type: 'text/html' }, @@ -937,6 +1026,7 @@ module.exports = function Routes(pb){ path: "/actions/admin/site_settings", access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, auth_required: true, + inactive_site_access: true, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'site_settings', 'configuration.js'), content_type: 'text/html' }, @@ -945,6 +1035,7 @@ module.exports = function Routes(pb){ path: "/admin/site_settings/content", access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, auth_required: true, + inactive_site_access: true, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'site_settings', 'content.js'), content_type: 'text/html' }, @@ -953,6 +1044,7 @@ module.exports = function Routes(pb){ path: "/actions/admin/site_settings/content", access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, auth_required: true, + inactive_site_access: true, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'site_settings', 'content.js'), content_type: 'text/html' }, @@ -961,6 +1053,7 @@ module.exports = function Routes(pb){ path: "/admin/site_settings/email", access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, auth_required: true, + inactive_site_access: true, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'site_settings', 'email.js'), content_type: 'text/html' }, @@ -969,6 +1062,7 @@ module.exports = function Routes(pb){ path: "/actions/admin/site_settings/email", access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, auth_required: true, + inactive_site_access: true, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'site_settings', 'email.js'), content_type: 'text/html' }, @@ -977,6 +1071,7 @@ module.exports = function Routes(pb){ path: "/admin/site_settings/libraries", access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, auth_required: true, + inactive_site_access: true, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'site_settings', 'libraries.js'), content_type: 'text/html' }, @@ -985,6 +1080,7 @@ module.exports = function Routes(pb){ path: "/actions/admin/site_settings/libraries", access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, auth_required: true, + inactive_site_access: true, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'site_settings', 'libraries.js'), content_type: 'text/html' }, @@ -993,6 +1089,7 @@ module.exports = function Routes(pb){ path: "/api/localization/script", handler: "getAsScript", auth_required: false, + inactive_site_access: true, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'api', 'localization_controller.js'), content_type: 'text/javascript' }, @@ -1001,6 +1098,7 @@ module.exports = function Routes(pb){ path: "/admin/sites", access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, auth_required: true, + inactive_site_access: true, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'sites', 'manage_sites.js'), content_type: 'text/html' }, @@ -1009,6 +1107,7 @@ module.exports = function Routes(pb){ path: "/admin/sites/new", access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, auth_required: true, + inactive_site_access: true, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'sites', 'site_form.js'), content_type: 'text/html' }, @@ -1017,6 +1116,7 @@ module.exports = function Routes(pb){ path: "/admin/sites/:siteid", access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, auth_required: true, + inactive_site_access: true, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'admin', 'sites', 'site_form.js'), content_type: 'text/html' }, @@ -1025,6 +1125,7 @@ module.exports = function Routes(pb){ path: "/actions/admin/sites/new", access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, auth_required: true, + inactive_site_access: true, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'sites', 'new_site.js') }, { @@ -1032,6 +1133,7 @@ module.exports = function Routes(pb){ path: "/actions/admin/sites/edit/:siteid", access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, auth_required: true, + inactive_site_access: true, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'sites', 'edit_site.js') }, { @@ -1039,6 +1141,7 @@ module.exports = function Routes(pb){ path: "/actions/admin/sites/activate/:id", access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, auth_required: true, + inactive_site_access: true, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'sites', 'activate_site.js') }, { @@ -1046,6 +1149,7 @@ module.exports = function Routes(pb){ path: "/actions/admin/sites/deactivate/:id", access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, auth_required: true, + inactive_site_access: true, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'sites', 'deactivate_site.js') }, @@ -1058,6 +1162,7 @@ module.exports = function Routes(pb){ handler: "get", content_type: 'application/json', auth_required: true, + inactive_site_access: true, access_level: pb.SecurityService.ACCESS_WRITER, controller: path.join(pb.config.docRoot, 'plugins/pencilblue/controllers/api/content/article_api_controller.js') }, @@ -1067,6 +1172,7 @@ module.exports = function Routes(pb){ handler: "getAll", content_type: 'application/json', auth_required: true, + inactive_site_access: true, access_level: pb.SecurityService.ACCESS_WRITER, controller: path.join(pb.config.docRoot, 'plugins/pencilblue/controllers/api/content/article_api_controller.js') }, @@ -1085,6 +1191,7 @@ module.exports = function Routes(pb){ handler: "post", content_type: 'application/json', auth_required: true, + inactive_site_access: true, access_level: pb.SecurityService.ACCESS_WRITER, controller: path.join(pb.config.docRoot, 'plugins/pencilblue/controllers/api/content/article_api_controller.js'), request_body: ['application/json'] @@ -1160,6 +1267,7 @@ module.exports = function Routes(pb){ handler: "post", content_type: 'application/json', auth_required: true, + inactive_site_access: true, access_level: pb.SecurityService.ACCESS_EDITOR, controller: path.join(pb.config.docRoot, 'plugins/pencilblue/controllers/api/content/topic_api_controller.js'), request_body: ['application/json'] diff --git a/plugins/portfolio/controllers/home_page_settings.js b/plugins/portfolio/controllers/home_page_settings.js index 0af55a15c..88c282ebf 100755 --- a/plugins/portfolio/controllers/home_page_settings.js +++ b/plugins/portfolio/controllers/home_page_settings.js @@ -112,6 +112,7 @@ module.exports = function HomePageSettingsModule(pb) { method: 'get', path: '/admin/plugins/portfolio/settings/home_page', auth_required: true, + inactive_site_access: true, access_level: pb.SecurityService.ACCESS_EDITOR, content_type: 'text/html' } diff --git a/plugins/portfolio/controllers/save_home_page_settings.js b/plugins/portfolio/controllers/save_home_page_settings.js index b6df3c7ed..b37c30c06 100755 --- a/plugins/portfolio/controllers/save_home_page_settings.js +++ b/plugins/portfolio/controllers/save_home_page_settings.js @@ -78,13 +78,7 @@ module.exports = function SaveHomePageSettingsModule(pb) { method: 'post', path: '/actions/admin/plugins/settings/portfolio/home_page', auth_required: true, - access_level: pb.SecurityService.ACCESS_EDITOR, - content_type: 'text/html' - }, - { - method: 'post', - path: '/actions/admin/plugins/settings/portfolio/home_page', - auth_required: true, + inactive_site_access: true, access_level: pb.SecurityService.ACCESS_EDITOR, content_type: 'text/html' } From aa340b33a888658d67ef2792b1f46874521e04ba Mon Sep 17 00:00:00 2001 From: iandtrapp Date: Wed, 24 Jun 2015 13:50:44 -0400 Subject: [PATCH 360/790] Working modal as well as universal site specific delete --- include/dao/dao.js | 18 +++++++ .../service/entities/site_query_service.js | 52 ++++++++++++++++++- .../actions/admin/sites/delete_site.js | 33 ++++++++++++ .../actions/admin/sites/edit_site.js | 2 +- plugins/pencilblue/include/routes.js | 7 +++ .../admin/elements/delete_site_modal.html | 25 +++++++++ .../templates/admin/sites/manage_sites.html | 6 ++- .../angular/admin/sites/manage_sites.html | 35 ++++++------- public/localization/en-us.js | 4 +- 9 files changed, 158 insertions(+), 24 deletions(-) create mode 100644 plugins/pencilblue/controllers/actions/admin/sites/delete_site.js create mode 100644 plugins/pencilblue/templates/admin/elements/delete_site_modal.html diff --git a/include/dao/dao.js b/include/dao/dao.js index be7e8f960..1359c69be 100755 --- a/include/dao/dao.js +++ b/include/dao/dao.js @@ -760,6 +760,24 @@ module.exports = function DAOModule(pb) { }); }; + /** + * Gets all collection names + * @returns {DAO} + */ + DAO.prototype.getAllCollectionNames = function(cb) { + pb.dbm.getDb(this.dbName, function(err, db) { + if (util.isError(err)) { + return cb(err); + } + db.collections(function(err, items) { + if (util.isError(err)) { + return cb(err) + } + cb(err, items); + }); + }); + }; + /** * Creates a basic where clause based on the specified Id * @deprecated since 0.4.0 diff --git a/include/service/entities/site_query_service.js b/include/service/entities/site_query_service.js index 22fd2a5cd..ece21df32 100644 --- a/include/service/entities/site_query_service.js +++ b/include/service/entities/site_query_service.js @@ -17,7 +17,7 @@ module.exports = function SiteQueryServiceModule(pb) { "use strict"; - + var async = require('async'); var SITE_FIELD = pb.SiteService.SITE_FIELD; var GLOBAL_SITE = pb.SiteService.GLOBAL_SITE; var _ = require('lodash'); @@ -142,6 +142,56 @@ module.exports = function SiteQueryServiceModule(pb) { DAO.prototype.save.call(this, dbObj, options, callback); }; + /** + * Function for getting all collections with site specific content + */ + /** + * Funtion for deleting all site specific content by searching all collections for + * a field named 'site' and adding that collection to an array to be passed in to + * deleteSiteSpecificContent defined below + * @param array of collection names + * @param siteid + * @param callback + */ + SiteQueryService.prototype.getSiteSpecificCollections = function (cb) { + var dao = new pb.DAO(); + dao.getAllCollectionNames(function(err, items) { + if(pb.util.isError(err)) { + throw err; + } + cb(err, items); + }) + }; + + /** + * Funtion for deleting all site specific content + * @param array of collection names + * @param siteid + * @param callback + */ + SiteQueryService.prototype.deleteSiteSpecificContent = function (collections, siteid, callback) { + var dao = new pb.DAO(); + var tasks = util.getTasks(collections, function(collections, i) { + return function(taskCallback) { + dao.delete({site: siteid}, collections[i].s.name, function(err, numberOfDeletedRecords) { + if(util.isError(err) || !numberOfDeletedRecords) { + taskCallback(null, " "); + } else { + pb.log.silly(numberOfDeletedRecords + " site specific records associated with " + siteid + " were deleted"); + taskCallback(err, numberOfDeletedRecords); + } + }); + }; + }); + async.parallel(tasks, callback); + dao.delete({uid: siteid}, 'site', function(err, result) { + if(util.isError(err)) { + pb.log.error("SiteQueryService: Failed to delete record: ", err.stack); + } + pb.log.silly("Successfully deleted site from database: " + result); + }); + }; + function modifySave(site, objectToSave) { if (pb.config.multisite && !(SITE_FIELD in objectToSave)) { objectToSave[SITE_FIELD] = site; diff --git a/plugins/pencilblue/controllers/actions/admin/sites/delete_site.js b/plugins/pencilblue/controllers/actions/admin/sites/delete_site.js new file mode 100644 index 000000000..4fd0eaa52 --- /dev/null +++ b/plugins/pencilblue/controllers/actions/admin/sites/delete_site.js @@ -0,0 +1,33 @@ +module.exports = function DeleteSiteActionModule(pb) { + + //pb dependencies + var util = pb.util; + + /** + * Deletes a current site + */ + function DeleteSiteAction(){} + util.inherits(DeleteSiteAction, pb.BaseController); + + DeleteSiteAction.prototype.render = function(cb) { + var self = this; + var siteid = self.pathVars.siteid; + var siteQueryService = new pb.SiteQueryService(); + siteQueryService.getSiteSpecificCollections(function(err, allCollections) { + siteQueryService.deleteSiteSpecificContent(allCollections, siteid, function(err, result) { + if(util.isError(err)) { + cb({ + code: 400, + content: pb.BaseController.apiResponse(pb.BaseController.API_ERROR, self.ls.get('ERROR_REMOVING')) + }); + return + } + cb({content: pb.BaseController.apiResponse(pb.BaseController.API_ERROR, self.ls.get('REMOVE_SUCCESSFUL'), result)}); + }); + }); + + }; + + //exports + return DeleteSiteAction; +}; \ No newline at end of file diff --git a/plugins/pencilblue/controllers/actions/admin/sites/edit_site.js b/plugins/pencilblue/controllers/actions/admin/sites/edit_site.js index f7a923dc8..66f4ff7db 100644 --- a/plugins/pencilblue/controllers/actions/admin/sites/edit_site.js +++ b/plugins/pencilblue/controllers/actions/admin/sites/edit_site.js @@ -48,7 +48,7 @@ module.exports = function EditSiteActionModule(pb) { if(err) { cb({ code: 400, - content: pb.BaseController.apiResponse(pb.BaseController.API_ERROR, self.ls.get('ERROR SAVING')) + content: pb.BaseController.apiResponse(pb.BaseController.API_ERROR, self.ls.get('ERROR_SAVING')) }); return; } diff --git a/plugins/pencilblue/include/routes.js b/plugins/pencilblue/include/routes.js index a9e09a3ce..6b988008c 100644 --- a/plugins/pencilblue/include/routes.js +++ b/plugins/pencilblue/include/routes.js @@ -1035,6 +1035,13 @@ module.exports = function Routes(pb){ auth_required: true, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'sites', 'edit_site.js') }, + { + method: 'post', + path: "/actions/admin/sites/delete/:siteid", + access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, + auth_required: true, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'sites', 'delete_site.js') + }, { method: 'post', path: "/actions/admin/sites/activate/:id", diff --git a/plugins/pencilblue/templates/admin/elements/delete_site_modal.html b/plugins/pencilblue/templates/admin/elements/delete_site_modal.html new file mode 100644 index 000000000..4c36be1fe --- /dev/null +++ b/plugins/pencilblue/templates/admin/elements/delete_site_modal.html @@ -0,0 +1,25 @@ + \ No newline at end of file diff --git a/plugins/pencilblue/templates/admin/sites/manage_sites.html b/plugins/pencilblue/templates/admin/sites/manage_sites.html index 199acb2ad..cc443bba3 100644 --- a/plugins/pencilblue/templates/admin/sites/manage_sites.html +++ b/plugins/pencilblue/templates/admin/sites/manage_sites.html @@ -59,15 +59,17 @@ + ^tmp_admin=elements=delete_site_modal^
-
- +
-
- +
-
+ + ^tmp_admin=elements=progress_console_modal^ ^tmp_angular=admin=sites=manage_sites^ diff --git a/plugins/pencilblue/templates/angular/admin/sites/manage_sites.html b/plugins/pencilblue/templates/angular/admin/sites/manage_sites.html index 37a4f728b..f0a917304 100644 --- a/plugins/pencilblue/templates/angular/admin/sites/manage_sites.html +++ b/plugins/pencilblue/templates/angular/admin/sites/manage_sites.html @@ -10,7 +10,6 @@ $scope.actionProgress = '0'; $scope.consoleOutput = ''; $('#progress_modal').modal({}); - $http.post('/actions/admin/sites/activate/' + site.uid) .success(function(result) { $scope.onActivateOrDeactivateComplete(result); @@ -19,14 +18,12 @@ $scope.onActionFailure(error); }); }; - $scope.deactivateSite = function(site) { site.name = site.displayName; $scope.actionPlugin = site; $scope.actionProgress = '0'; $scope.consoleOutput = ''; $('#progress_modal').modal({}); - $http.post('/actions/admin/sites/deactivate/' + site.uid) .success(function(result) { $scope.onActivateOrDeactivateComplete(result); @@ -35,7 +32,21 @@ $scope.onActionFailure(error); }); }; - + $scope.deleteSite = function(site) { + $http.post('/actions/admin/sites/delete/' + site.uid) + .success(function(result) { + $scope.successMessage = result.message; + $scope.saving = false; + $scope.onActionSuccess(); + }) + .error(function(error, status) { + $scope.errorMessage = error.message; + $scope.saving = false; + }); + }; + $scope.openDeleteModal = function(site) { + $('#delete_site_modal').modal({}); + }; $scope.jobAction = function(actionType, identifier, data, cb) { $http.post("/api/jobs/" + actionType + "/" + encodeURIComponent(identifier), data) .success(function(result) { @@ -45,10 +56,8 @@ $scope.onActionFailure(error); }); }; - $scope.onActivateOrDeactivateComplete = function(result) { var jobId = result.data; - //poll for logs var logHandle = null; var starting = 0; @@ -57,27 +66,22 @@ if (!result || !result.data || !result.data.length) { return; } - var nextStarting = starting; for(var i = 0; i < result.data.length; i++) { var item = result.data[i]; $scope.consoleOutput += ($scope.consoleOutput.length ? '\n' : '') + item.created + ':[' + item.worker_id + '] ' + item.message; - var date = new Date(item.created).getTime(); if(date > nextStarting) { nextStarting = date; } } - //offset so we don't get repeats starting = nextStarting + 1; - //check for more log entries logHandle = setTimeout(doLogRetrieve, 2000); }); }; doLogRetrieve(); - //check for job completion var retrieveHandle = null; var doJobRetrieve = function() { @@ -85,12 +89,10 @@ if(!result || !result.data) { return; } - //set progress bar if(!isNaN(result.data.progress)) { $scope.actionProgress = result.data.progress.toString(); } - //verify status if(result.data.status === 'RUNNING') { retrieveHandle = setTimeout(doJobRetrieve, 1000); @@ -99,7 +101,6 @@ //allow any trailing logs to come in setTimeout(function() { clearTimeout(logHandle); - var line = result.data.status; if (result.data.error) { line += ': ' + result.data.error; @@ -113,20 +114,16 @@ }; doJobRetrieve(); }; - - $scope.onActionSuccess = function() { $scope.actionIsComplete = true; $scope.refreshPage(); }; - $scope.onActionFailure = function(error) { $scope.actionIsComplete = true; $scope.actionError = error.message; }; - $scope.refreshPage = function() { $window.location.reload(); } }); - + \ No newline at end of file diff --git a/public/localization/en-us.js b/public/localization/en-us.js index 6c98aa941..645f28857 100755 --- a/public/localization/en-us.js +++ b/public/localization/en-us.js @@ -442,7 +442,9 @@ var loc = DEACTIVATE: 'Deactivate', EDIT_SITE: 'Edit Site', NEW_SITE: 'New Site', - SITE_UPDATED: 'Site was successfully updated' + SITE_UPDATED: 'Site was successfully updated', + ERROR_REMOVING: 'There was an error removing your site', + REMOVE_SUCCESSFUL: 'Site removed successfully' }, plugins: { From 0b2b464840b21da9791abe0275b2e8b873edb56d Mon Sep 17 00:00:00 2001 From: iandtrapp Date: Wed, 24 Jun 2015 13:54:39 -0400 Subject: [PATCH 361/790] Added visually appealing spacing to manage sites angular --- .../templates/angular/admin/sites/manage_sites.html | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/plugins/pencilblue/templates/angular/admin/sites/manage_sites.html b/plugins/pencilblue/templates/angular/admin/sites/manage_sites.html index f0a917304..93bb80e8a 100644 --- a/plugins/pencilblue/templates/angular/admin/sites/manage_sites.html +++ b/plugins/pencilblue/templates/angular/admin/sites/manage_sites.html @@ -18,6 +18,7 @@ $scope.onActionFailure(error); }); }; + $scope.deactivateSite = function(site) { site.name = site.displayName; $scope.actionPlugin = site; @@ -32,6 +33,7 @@ $scope.onActionFailure(error); }); }; + $scope.deleteSite = function(site) { $http.post('/actions/admin/sites/delete/' + site.uid) .success(function(result) { @@ -44,9 +46,11 @@ $scope.saving = false; }); }; + $scope.openDeleteModal = function(site) { $('#delete_site_modal').modal({}); }; + $scope.jobAction = function(actionType, identifier, data, cb) { $http.post("/api/jobs/" + actionType + "/" + encodeURIComponent(identifier), data) .success(function(result) { @@ -56,6 +60,7 @@ $scope.onActionFailure(error); }); }; + $scope.onActivateOrDeactivateComplete = function(result) { var jobId = result.data; //poll for logs @@ -81,6 +86,7 @@ logHandle = setTimeout(doLogRetrieve, 2000); }); }; + doLogRetrieve(); //check for job completion var retrieveHandle = null; @@ -114,14 +120,17 @@ }; doJobRetrieve(); }; + $scope.onActionSuccess = function() { $scope.actionIsComplete = true; $scope.refreshPage(); }; + $scope.onActionFailure = function(error) { $scope.actionIsComplete = true; $scope.actionError = error.message; }; + $scope.refreshPage = function() { $window.location.reload(); } From e77fa02d044e3129eb1a8bbccac879a0ab18d945 Mon Sep 17 00:00:00 2001 From: btidwell Date: Wed, 24 Jun 2015 15:05:56 -0400 Subject: [PATCH 362/790] migrate users and refactor DBMigrate strucutre --- include/dao/db_migrate.js | 50 +++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/include/dao/db_migrate.js b/include/dao/db_migrate.js index a53dad9c1..0c05fd415 100644 --- a/include/dao/db_migrate.js +++ b/include/dao/db_migrate.js @@ -25,14 +25,10 @@ module.exports = function DBMigrateModule(pb) { 'topic' ]; - var MIGRATE_SPECIFIC = [ - 'user', - 'setting' - ]; - - var GLOBAL_USERS = [ - pb.security.ACCESS_ADMINISTRATOR, - pb.security.ACCESS_MANAGING_EDITOR + var SITE_SPECIFIC_USERS = [ + pb.security.ACCESS_EDITOR, + pb.security.ACCESS_WRITER, + pb.security.ACCESS_USER ]; var SITE_SPECIFIC_SETTINGS = [ @@ -53,11 +49,12 @@ module.exports = function DBMigrateModule(pb) { self.siteUid = result.uid; var tasks = [ util.wrapTask(self, self.migrateContentAndPluginData), - util.wrapTask(self, self.migrateSettings) + util.wrapTask(self, self.migrateSettings), + util.wrapTask(self, self.migrateUsers) ]; //self.migrateContentAndPluginData(cb); async.series(tasks, function(err, result) { - cb(null, true); + cb(err, result); }); }); } @@ -84,33 +81,37 @@ module.exports = function DBMigrateModule(pb) { }; }); - async.parallel(tasks, function (err, result) { cb(err, result); }); }; this.migrateSettings = function (cb) { + this.migrateGlobalSubCollection('setting', SITE_SPECIFIC_SETTINGS, 'key', cb); + }; + + this.migrateUsers = function(cb) { + this.migrateGlobalSubCollection('user', SITE_SPECIFIC_USERS, 'admin', cb); + }; + + this.migrateGlobalSubCollection = function(collection, siteSpecificArr, compareTo, cb) { var self = this; var dao = new pb.DAO(); - dao.q('setting', {}, function(err, results) { + dao.q(collection, {}, function(err, results) { var tasks = util.getTasks(results, function(results, i) { - return function(callback) { - if(SITE_SPECIFIC_SETTINGS.indexOf(results[i].key) > -1) { - self.applySiteToDocument(results[i], self.siteUid, callback); - } - else { - callback(null, true); - } - } + return function(callback) { + var uid = siteSpecificArr.indexOf(results[i][compareTo]) > -1? self.siteUid : pb.SiteService.GLOBAL_SITE; + self.applySiteToDocument(results[i], uid, callback); + }; }); + async.parallel(tasks, function(err, result) { - cb(null, true); + cb(err, result); }); }); }; - this.migrateCollection = function (collection, siteUid, callback) { + this.migrateCollection = function (collection, siteUid, cb) { var self = this; var dao = new pb.DAO(); dao.q(collection, {}, function (err, results) { @@ -120,15 +121,14 @@ module.exports = function DBMigrateModule(pb) { }; }); - async.parallel(tasks, function (err, result) { - callback(err, result); + cb(err, result); }); }); }; this.applySiteToDocument = function (document, siteUid, callback) { - document.site = siteUid; + document[pb.SiteService.SITE_FIELD] = siteUid; var dao = new pb.DAO(); dao.save(document, callback); }; From 940159413cb5d0c5969e6fd40a653103c622bbb0 Mon Sep 17 00:00:00 2001 From: iandtrapp Date: Wed, 24 Jun 2015 15:10:26 -0400 Subject: [PATCH 363/790] Ensured site was deleted last --- include/dao/dao.js | 2 +- .../service/entities/site_query_service.js | 22 +++++++++++++------ .../actions/admin/sites/delete_site.js | 2 +- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/include/dao/dao.js b/include/dao/dao.js index 1359c69be..d61e79bcb 100755 --- a/include/dao/dao.js +++ b/include/dao/dao.js @@ -764,7 +764,7 @@ module.exports = function DAOModule(pb) { * Gets all collection names * @returns {DAO} */ - DAO.prototype.getAllCollectionNames = function(cb) { + DAO.prototype.getAllCollections = function(cb) { pb.dbm.getDb(this.dbName, function(err, db) { if (util.isError(err)) { return cb(err); diff --git a/include/service/entities/site_query_service.js b/include/service/entities/site_query_service.js index ece21df32..558198b2d 100644 --- a/include/service/entities/site_query_service.js +++ b/include/service/entities/site_query_service.js @@ -153,9 +153,9 @@ module.exports = function SiteQueryServiceModule(pb) { * @param siteid * @param callback */ - SiteQueryService.prototype.getSiteSpecificCollections = function (cb) { + SiteQueryService.prototype.getCollections = function (cb) { var dao = new pb.DAO(); - dao.getAllCollectionNames(function(err, items) { + dao.getAllCollections(function(err, items) { if(pb.util.isError(err)) { throw err; } @@ -183,13 +183,21 @@ module.exports = function SiteQueryServiceModule(pb) { }); }; }); - async.parallel(tasks, callback); - dao.delete({uid: siteid}, 'site', function(err, result) { - if(util.isError(err)) { - pb.log.error("SiteQueryService: Failed to delete record: ", err.stack); + async.parallel(tasks, function(err, results) { + if(pb.util.isError(err)) { + pb.error.silly(err); + callback(err); } - pb.log.silly("Successfully deleted site from database: " + result); + dao.delete({uid: siteid}, 'site', function(err, result) { + if(util.isError(err)) { + pb.log.error("SiteQueryService: Failed to delete record: ", err.stack); + callback(err); + } + pb.log.silly("Successfully deleted site from database: " + result); + callback(result); + }); }); + }; function modifySave(site, objectToSave) { diff --git a/plugins/pencilblue/controllers/actions/admin/sites/delete_site.js b/plugins/pencilblue/controllers/actions/admin/sites/delete_site.js index 4fd0eaa52..2b5b84ea4 100644 --- a/plugins/pencilblue/controllers/actions/admin/sites/delete_site.js +++ b/plugins/pencilblue/controllers/actions/admin/sites/delete_site.js @@ -13,7 +13,7 @@ module.exports = function DeleteSiteActionModule(pb) { var self = this; var siteid = self.pathVars.siteid; var siteQueryService = new pb.SiteQueryService(); - siteQueryService.getSiteSpecificCollections(function(err, allCollections) { + siteQueryService.getCollections(function(err, allCollections) { siteQueryService.deleteSiteSpecificContent(allCollections, siteid, function(err, result) { if(util.isError(err)) { cb({ From b0dc9416906006b22d6b33afbb0dc88c0b651a15 Mon Sep 17 00:00:00 2001 From: iandtrapp Date: Wed, 24 Jun 2015 15:24:48 -0400 Subject: [PATCH 364/790] Localized --- .../admin/elements/delete_site_modal.html | 20 +++++++++---------- public/localization/en-us.js | 9 +++++++-- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/plugins/pencilblue/templates/admin/elements/delete_site_modal.html b/plugins/pencilblue/templates/admin/elements/delete_site_modal.html index 4c36be1fe..176892649 100644 --- a/plugins/pencilblue/templates/admin/elements/delete_site_modal.html +++ b/plugins/pencilblue/templates/admin/elements/delete_site_modal.html @@ -3,22 +3,22 @@ diff --git a/public/localization/en-us.js b/public/localization/en-us.js index 645f28857..c349bacf1 100755 --- a/public/localization/en-us.js +++ b/public/localization/en-us.js @@ -247,7 +247,8 @@ var loc = SAVED: 'was saved', NARROW_RESULTS: 'Narrow results', URL_KEY: 'URL Key', - FEED_UNAVAILABLE: 'Unable to load the news feed.' + FEED_UNAVAILABLE: 'Unable to load the news feed.', + ETC: 'And other items...' }, topics: { @@ -444,7 +445,11 @@ var loc = NEW_SITE: 'New Site', SITE_UPDATED: 'Site was successfully updated', ERROR_REMOVING: 'There was an error removing your site', - REMOVE_SUCCESSFUL: 'Site removed successfully' + REMOVE_SUCCESSFUL: 'Site removed successfully', + INITIAL_DELETE_WARNING: 'You are attempting to delete this site and all content associated with it, including: ', + FINAL_DELETE_WARNING: 'This action cannot be reversed. Are you sure you want to continue?', + DELETE_SITE: 'Delete Site', + DANGER: 'Danger!' }, plugins: { From 942a40db00f9892edfe745e3eabd3fb2c8c3011c Mon Sep 17 00:00:00 2001 From: iandtrapp Date: Wed, 24 Jun 2015 15:45:28 -0400 Subject: [PATCH 365/790] Change to modal to make it more scary --- .../pencilblue/templates/admin/elements/delete_site_modal.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/pencilblue/templates/admin/elements/delete_site_modal.html b/plugins/pencilblue/templates/admin/elements/delete_site_modal.html index 176892649..3c9f9bd7a 100644 --- a/plugins/pencilblue/templates/admin/elements/delete_site_modal.html +++ b/plugins/pencilblue/templates/admin/elements/delete_site_modal.html @@ -14,7 +14,7 @@
  • ^loc_CUSTOM_OBJECTS^
  • ^loc_ETC^
  • -

    ^loc_FINAL_DELETE_WARNING^

    +

    ^loc_FINAL_DELETE_WARNING^

    @@ -50,7 +50,7 @@
    diff --git a/plugins/pencilblue/templates/angular/admin/sites/manage_sites.html b/plugins/pencilblue/templates/angular/admin/sites/manage_sites.html index 6e8a50c16..de22e8a62 100644 --- a/plugins/pencilblue/templates/angular/admin/sites/manage_sites.html +++ b/plugins/pencilblue/templates/angular/admin/sites/manage_sites.html @@ -19,6 +19,16 @@ }); }; + $scope.authUserToSite = function(site) { + $http.post('/actions/admin/sites/auth_token/' + site.uid) + .success(function(result) { + $scope.onTokenComplate(site, result); + }) + .error(function(error, status) { + $scope.onActionFailure(error); + }); + }; + $scope.deactivateSite = function(site) { site.name = site.displayName; $scope.actionPlugin = site; @@ -57,6 +67,18 @@ }); }; + $scope.onTokenComplate = function(site, result) { + console.log(site); + console.log(result); +// $http.jsonp('//' + site.hostname + '/actions/admin/login?' + result.data.token) +// .success(function(result) { +// console.log(result); +// }) +// .error(function(error, status){ +// $scope.onActionFailure(error); +// }); + }; + $scope.onActivateOrDeactivateComplete = function(result) { var jobId = result.data; //poll for logs From 5d72f946fb3e5b30925a4064762845a17b36dad6 Mon Sep 17 00:00:00 2001 From: andparker Date: Tue, 28 Jul 2015 14:07:09 -0400 Subject: [PATCH 498/790] -Updates cache entity service constructor to accept an options argument -Reduces nesting complexity in the get method in the cache entity service -Improves documentation for cache and memory entity service --- include/service/cache_entity_service.js | 68 ++++++++++--------- include/service/entities/plugin_service.js | 16 +++-- .../entities/plugin_setting_service.js | 19 +++--- include/service/entities/template_service.js | 11 +-- include/service/entities/theme_service.js | 15 ++-- include/service/memory_entity_service.js | 13 ++-- include/system/settings.js | 19 +++--- 7 files changed, 89 insertions(+), 72 deletions(-) diff --git a/include/service/cache_entity_service.js b/include/service/cache_entity_service.js index 3be2627d9..8f14b3ec3 100755 --- a/include/service/cache_entity_service.js +++ b/include/service/cache_entity_service.js @@ -31,22 +31,23 @@ module.exports = function CacheEntityServiceModule(pb) { * @module Services * @class CacheEntityService * @constructor - * @param {String} [objType] - * @param {String} [valueField] - * @param {String} [keyField] - * @param {String} [site] - * @param {String} [onlyThisSite] - * @param {Integer} The number of seconds that a value will remain in cache + * @param {Object} options + * @param {String} options.objType + * @param {String} options.keyField + * @param {String} [options.valueField=null] + * @param {String} [options.site=GLOBAL_SITE] + * @param {String} [options.onlyThisSite=false] + * @param {Integer} [options.timeout=0] The number of seconds that a value will remain in cache * before expiry. */ - function CacheEntityService(objType, valueField, keyField, site, onlyThisSite, timeout){ + function CacheEntityService(options){ this.type = 'Cache'; - this.objType = objType; - this.valueField = valueField ? valueField : null; - this.keyField = keyField; - this.site = site || GLOBAL_SITE; - this.onlyThisSite = onlyThisSite ? true : false; - this.timeout = timeout || 0; + this.objType = options.objType; + this.keyField = options.keyField; + this.valueField = options.valueField ? options.valueField : null; + this.site = options.site || GLOBAL_SITE; + this.onlyThisSite = options.onlyThisSite ? true : false; + this.timeout = options.timeout || 0; } var GLOBAL_SITE = pb.SiteService.GLOBAL_SITE; @@ -68,28 +69,29 @@ module.exports = function CacheEntityServiceModule(pb) { //site specific value doesn't exist in cache if (result == null) { - if(self.site !== GLOBAL_SITE && !self.onlyThisSite) { - pb.cache.get(keyValue(key, GLOBAL_SITE), function(err, result){ - if (util.isError(err)) { - return cb(err, null); - } - - //value doesn't exist in cache - if (result == null) { - return cb(null, null); - } - - //make call back - cb(null, getRightFieldFromValue(result, self.valueField)); - }); - } else { - cb(null, null); + + if (self.site === GLOBAL_SITE || self.onlyThisSite) { + return cb(null, null); } - return; - } - //make call back - cb(null, getRightFieldFromValue(result, self.valueField)); + pb.cache.get(keyValue(key, GLOBAL_SITE), function(err, result){ + if (util.isError(err)) { + return cb(err, null); + } + + //value doesn't exist in cache + if (result == null) { + return cb(null, null); + } + + //make call back + return cb(null, getRightFieldFromValue(result, self.valueField)); + }); + } + else { + //make call back + return cb(null, getRightFieldFromValue(result, self.valueField)); + } }); }; diff --git a/include/service/entities/plugin_service.js b/include/service/entities/plugin_service.js index 2c2e5f429..1c5d1e12e 100755 --- a/include/service/entities/plugin_service.js +++ b/include/service/entities/plugin_service.js @@ -484,18 +484,22 @@ module.exports = function PluginServiceModule(pb) { //add in-memory service var services = []; + + var options = { + objType: objType, + site: site, + onlyThisSite: false, + timeout: pb.config.plugins.caching.memory_timeout + }; + if (useMemory){ - var options = { - objType: objType, - site: site, - timeout: pb.config.plugins.caching.memory_timeout, - }; services.push(new pb.MemoryEntityService(options)); } //add cache service if (useCache) { - services.push(new pb.CacheEntityService(objType, undefined, undefined, site, false, 3600)); + options.timeout = 3600; + services.push(new pb.CacheEntityService(options)); } //always add DB diff --git a/include/service/entities/plugin_setting_service.js b/include/service/entities/plugin_setting_service.js index a6f1a93f2..41e227c4f 100644 --- a/include/service/entities/plugin_setting_service.js +++ b/include/service/entities/plugin_setting_service.js @@ -480,19 +480,22 @@ module.exports = function PluginSettingServiceModule(pb) { //add in-memory service var services = []; - if (useMemory){ - var options = { - objType: objType, - timeout: pb.config.plugins.caching.memory_timeout, - site: site, - onlyThisSite: onlyThisSite - }; + + var options = { + objType: objType, + timeout: pb.config.plugins.caching.memory_timeout, + site: site, + onlyThisSite: onlyThisSite + }; + + if (useMemory) { services.push(new pb.MemoryEntityService(options)); } //add cache service if (useCache) { - services.push(new pb.CacheEntityService(objType, null, null, site, onlyThisSite)); + options.timeout = 3600; + services.push(new pb.CacheEntityService(options)); } //always add DB diff --git a/include/service/entities/template_service.js b/include/service/entities/template_service.js index cf791bcf8..39c43293f 100755 --- a/include/service/entities/template_service.js +++ b/include/service/entities/template_service.js @@ -83,18 +83,19 @@ module.exports = function(pb) { var objType = 'template'; var services = []; + var options = { + objType: objType, + timeout: pb.config.templates.memory_timeout + }; + //add in-memory service if (pb.config.templates.use_memory){ - var options = { - objType: objType, - timeout: pb.config.templates.memory_timeout - }; services.push(new pb.MemoryEntityService(options)); } //add cache service if (pb.config.templates.use_cache) { - services.push(new pb.CacheEntityService(objType)); + services.push(new pb.CacheEntityService(options)); } //always add fs service diff --git a/include/service/entities/theme_service.js b/include/service/entities/theme_service.js index cf65e6736..0011b2a8d 100755 --- a/include/service/entities/theme_service.js +++ b/include/service/entities/theme_service.js @@ -20,24 +20,25 @@ function ThemeService(useMemory, useCache) { var objType = 'theme'; var services = []; - //add in-memory service + var options = { + objType: objType, + timeout: pb.config.plugins.caching.memory_timeout + }; + + //add in-memory service if (useMemory){ - var options = { - objType: objType, - timeout: pb.config.plugins.caching.memory_timeout - }; services.push(new pb.MemoryEntityService(options)); } //add cache service if (useCache) { - services.push(new pb.CacheEntityService(objType)); + services.push(new pb.CacheEntityService(options)); } //always add JSON services.push(new pb.JSONFSEntityService(objType)); this.service = new pb.ReadOnlySimpleLayeredService(services, 'ThemeService'); -}; +} //exports module.exports.ThemeService = ThemeService; diff --git a/include/service/memory_entity_service.js b/include/service/memory_entity_service.js index f93307e0b..a07c2b664 100755 --- a/include/service/memory_entity_service.js +++ b/include/service/memory_entity_service.js @@ -27,9 +27,14 @@ module.exports = function MemoryEntityServiceModule(pb) { * @submodule Storage * @class MemoryEntityService * @constructor - * @param {String} objType - * @param {String} valueField - * @param {String} keyField + * @param {Object} options + * @param {String} options.objType + * @param {String} options.keyField + * @param {String} [options.valueField=null] + * @param {String} [options.site=GLOBAL_SITE] + * @param {String} [options.onlyThisSite=false] + * @param {Integer} [options.timeout=0] The number of seconds that a value will remain in cache + * before expiry. */ function MemoryEntityService(options){ this.type = TYPE; @@ -40,7 +45,7 @@ module.exports = function MemoryEntityServiceModule(pb) { this.timers = {}; this.timeout = options.timeout || 0; this.changeHandler = MemoryEntityService.createChangeHandler(this); - this.site = options.site || 'global'; + this.site = options.site || GLOBAL_SITE; this.onlyThisSite = options.onlyThisSite ? true : false; //register change handler diff --git a/include/system/settings.js b/include/system/settings.js index ab90d92c1..be96c7ba0 100755 --- a/include/system/settings.js +++ b/include/system/settings.js @@ -67,22 +67,23 @@ module.exports = function SettingsModule(pb) { var valueField = 'value'; var services = []; + var options = { + objType: objType, + valueField: valueField, + keyField: keyField, + timeout: pb.config.settings.memory_timeout, + site: site, + onlyThisSite: onlyThisSite + }; + //add in-memory service if (useMemory){ - var options = { - objType: objType, - valueField: valueField, - keyField: keyField, - timeout: pb.config.settings.memory_timeout, - site: site, - onlyThisSite: onlyThisSite - }; services.push(new pb.MemoryEntityService(options)); } //add cache service if (useCache) { - services.push(new pb.CacheEntityService(objType, valueField, keyField, site, onlyThisSite)); + services.push(new pb.CacheEntityService(options)); } //always add db service From 96cedc280803688154a9d0d2f4e2e165564faa12 Mon Sep 17 00:00:00 2001 From: andparker Date: Tue, 28 Jul 2015 14:21:53 -0400 Subject: [PATCH 499/790] Replaces instances of dao with "this", because site query service is an object of type DAO. --- include/service/entities/site_query_service.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/include/service/entities/site_query_service.js b/include/service/entities/site_query_service.js index 593187b0e..e682df66c 100644 --- a/include/service/entities/site_query_service.js +++ b/include/service/entities/site_query_service.js @@ -158,8 +158,7 @@ module.exports = function SiteQueryServiceModule(pb) { * @param {Function} cb */ SiteQueryService.prototype.getCollections = function (cb) { - var dao = new pb.DAO(); - dao.listCollections({}, function(err, items) { + this.listCollections({}, function(err, items) { if(pb.util.isError(err)) { pb.log.error(err); } @@ -174,10 +173,10 @@ module.exports = function SiteQueryServiceModule(pb) { * @param {Function} callback - callback function */ SiteQueryService.prototype.deleteSiteSpecificContent = function (collections, siteid, callback) { - var dao = new pb.DAO(); + var self = this; var tasks = util.getTasks(collections, function(collections, i) { return function(taskCallback) { - dao.delete({site: siteid}, collections[i].name, function(err, numberOfDeletedRecords) { + self.delete({site: siteid}, collections[i].name, function(err, numberOfDeletedRecords) { if(util.isError(err) || !numberOfDeletedRecords) { taskCallback(null, " "); } else { @@ -192,7 +191,7 @@ module.exports = function SiteQueryServiceModule(pb) { pb.log.error(err); callback(err); } - dao.delete({uid: siteid}, 'site', function(err, result) { + self.delete({uid: siteid}, 'site', function(err, result) { if(util.isError(err)) { pb.log.error("SiteQueryService: Failed to delete record: ", err.stack); callback(err); From 8409ace9937954f31543d1c967869562aa007c3d Mon Sep 17 00:00:00 2001 From: Andrew Parker Date: Tue, 28 Jul 2015 14:34:37 -0400 Subject: [PATCH 500/790] Removes timeout property declaration for the cache entity service --- include/service/entities/plugin_setting_service.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/include/service/entities/plugin_setting_service.js b/include/service/entities/plugin_setting_service.js index 41e227c4f..d57bc2715 100644 --- a/include/service/entities/plugin_setting_service.js +++ b/include/service/entities/plugin_setting_service.js @@ -483,18 +483,17 @@ module.exports = function PluginSettingServiceModule(pb) { var options = { objType: objType, - timeout: pb.config.plugins.caching.memory_timeout, site: site, onlyThisSite: onlyThisSite }; if (useMemory) { + options.timeout = pb.config.plugins.caching.memory_timeout; services.push(new pb.MemoryEntityService(options)); } //add cache service if (useCache) { - options.timeout = 3600; services.push(new pb.CacheEntityService(options)); } @@ -517,4 +516,4 @@ module.exports = function PluginSettingServiceModule(pb) { return self.adminThemeSettingsService; } return PluginSettingService; -} \ No newline at end of file +} From ad1434005aace7ecfd41dde148bc7139852e9388 Mon Sep 17 00:00:00 2001 From: wesanderson303 Date: Tue, 28 Jul 2015 15:47:34 -0400 Subject: [PATCH 501/790] Handle checkForFormRefill() errors --- .../controllers/admin/content/articles/article_form.js | 6 ++++++ .../pencilblue/controllers/admin/content/pages/page_form.js | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/plugins/pencilblue/controllers/admin/content/articles/article_form.js b/plugins/pencilblue/controllers/admin/content/articles/article_form.js index 9494125d0..44010242d 100755 --- a/plugins/pencilblue/controllers/admin/content/articles/article_form.js +++ b/plugins/pencilblue/controllers/admin/content/articles/article_form.js @@ -76,6 +76,12 @@ module.exports = function(pb) { self.onTemplateRetrieved('' + data, function(err, data) { var result = '' + data; self.checkForFormRefill(result, function(err, newResult) { + err = new Error(); + //Handle errors + if (util.isError(err)) { + pb.log.error("ArticleForm.checkForFormRefill encountered an error. ERROR[%s]", err.stack); + return; + } result = newResult; cb(null, {content: result}); }); diff --git a/plugins/pencilblue/controllers/admin/content/pages/page_form.js b/plugins/pencilblue/controllers/admin/content/pages/page_form.js index 514ad726d..8ecc751a5 100755 --- a/plugins/pencilblue/controllers/admin/content/pages/page_form.js +++ b/plugins/pencilblue/controllers/admin/content/pages/page_form.js @@ -74,6 +74,11 @@ module.exports = function(pb) { self.ts.load('admin/content/pages/page_form', function(err, data) { var result = data; self.checkForFormRefill(result, function(err, newResult) { + //Handle errors + if (util.isError(err)) { + pb.log.error("PageFormController.checkForFormRefill encountered an error. ERROR[%s]", err.stack); + return; + } result = newResult; cb(null, {content: result}); }); From b9e2a3718d3583049f3f626de8c8c63369f4c23f Mon Sep 17 00:00:00 2001 From: andparker Date: Tue, 28 Jul 2015 15:51:43 -0400 Subject: [PATCH 502/790] Site service improvements - Fixes argument type bug and improves regex - Updates site name count tasks to run in parallel - Removes unnecessary function --- include/service/entities/site_service.js | 22 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-) diff --git a/include/service/entities/site_service.js b/include/service/entities/site_service.js index c58e7063e..b6a60d51d 100644 --- a/include/service/entities/site_service.js +++ b/include/service/entities/site_service.js @@ -174,14 +174,14 @@ module.exports = function SiteServiceModule(pb) { var dao = new pb.DAO(); var tasks = { displayName: function(callback) { - var expStr = util.escapeRegExp(displayName.toLowerCase) + '$'; + var expStr = '^' + util.escapeRegExp(displayName.toLowerCase()) + '$'; dao.count('site', getWhere({displayName: new RegExp(expStr, 'i')}), callback); }, hostname: function(callback) { dao.count('site', getWhere({hostname: hostname.toLowerCase()}), callback); } }; - async.series(tasks, cb); + async.parallel(tasks, cb); }; /** @@ -439,24 +439,6 @@ module.exports = function SiteServiceModule(pb) { return siteid || SiteService.GLOBAL_SITE; }; - /** - * Determines if a site exists matching siteUid - * @method siteExists - * @param {String} siteUid - site unique id - * @param {Function} cb - callback function - */ - SiteService.siteExists = function(siteUid, cb) { - if (pb.config.multisite.enabled && !(siteUid === SiteService.GLOBAL_SITE)) { - var dao = new pb.DAO(); - dao.exists(SITE_COLL, {uid: siteUid}, function (err, exists) { - cb(err, exists); - }); - } - else { - cb(null, true); - } - }; - /** * Return site field from object. * @method getSiteFromObject From ea724f95de576f5a94cac0373aa36cf9e5a78e3f Mon Sep 17 00:00:00 2001 From: btidwell Date: Tue, 28 Jul 2015 16:15:21 -0400 Subject: [PATCH 503/790] Validate token function for token_service --- include/service/entities/token_service.js | 48 ++++++++++++++++------- 1 file changed, 33 insertions(+), 15 deletions(-) diff --git a/include/service/entities/token_service.js b/include/service/entities/token_service.js index 5c9f80548..79d95aa99 100644 --- a/include/service/entities/token_service.js +++ b/include/service/entities/token_service.js @@ -19,6 +19,7 @@ module.exports = function TokenServiceModule(pb) { //dependencies var crypto = require('crypto'); + var util = pb.util; /** * A service that manages tokens for non-password authentication. @@ -36,25 +37,21 @@ module.exports = function TokenServiceModule(pb) { TokenService.prototype.generateUserToken = function(cb) { var self = this; - crypto.randomBytes(48, function(err, buf) { - if(pb.util.isError(err)) { - return cb(err, null); - } - var token = buf.toString('base64'); - //TODO: Create and store token entity - var tokenInfo = { - token: token, - user: self.user, - used: false - } - self.saveToken(tokenInfo, cb); - }); + var token = util.uniqueId(); + //TODO: Create and store token entity + var tokenInfo = { + token: token, + user: self.user, + used: false + } + this.saveToken(tokenInfo, cb); + }; TokenService.prototype.saveToken = function(tokenInfo, cb) { var doc = pb.DocumentCreator.create('auth_token', tokenInfo); this.dao.save(doc, function(err, result) { - if(pb.util.isError(err)) { + if(util.isError(err)) { return cb(err, null); } cb(null, {token: tokenInfo.token}); @@ -62,7 +59,28 @@ module.exports = function TokenServiceModule(pb) { }; TokenService.prototype.validateUserToken = function(token, cb) { - cb(null, true); + var self = this; + this.dao.loadByValue('token', token, 'auth_token', function(err, tokenInfo){ + if(util.isError(err)) { + return cb(err, null); + } + if(!tokenInfo || tokenInfo.used) { + return cb(null, false); + } + + tokenInfo.used = true; + self.saveToken(tokenInfo, function(err, result) { + if(util.isError(err)) { + return cb(err, null); + } + var timeDiff = Date.now() - tokenInfo.created; + var response = { + tokenInfo: result, + valid: timeDiff < 300000 + }; + cb(null, response); + }); + }); }; //exports From 0d97b00dee8a2f11a3947cc2225eac9d58f9e71f Mon Sep 17 00:00:00 2001 From: btidwell Date: Tue, 28 Jul 2015 16:15:37 -0400 Subject: [PATCH 504/790] login by token controller and route --- .../actions/admin/sites/token_login.js | 71 +++++++++++++++++++ plugins/pencilblue/include/routes.js | 8 +++ 2 files changed, 79 insertions(+) create mode 100644 plugins/pencilblue/controllers/actions/admin/sites/token_login.js diff --git a/plugins/pencilblue/controllers/actions/admin/sites/token_login.js b/plugins/pencilblue/controllers/actions/admin/sites/token_login.js new file mode 100644 index 000000000..c577c9dac --- /dev/null +++ b/plugins/pencilblue/controllers/actions/admin/sites/token_login.js @@ -0,0 +1,71 @@ +/* + Copyright (C) 2015 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + */ + +module.exports = function TokenLoginControllerModule(pb) { + + //dependencies + var util = pb.util; + + /** + * Creates authentication token for administrators + * and managing editors for cross site access + * + * @class TokenLoginController + * @constructor + * @extends BaseController + */ + function TokenLoginController() {} + util.inherits(TokenLoginController, pb.BaseController); + + TokenLoginController.prototype.render = function(cb) { + var self = this; + var options = { + site: this.site + }; + var callback = this.query.callback; + var tokenService = new pb.TokenService(options); + tokenService.validateUserToken(this.query.token, function(err, result) { + + if(util.isError(err)) { + return cb({ + code: 500, + content: jsonpResponse(callback, pb.BaseController.apiResponse(pb.BaseController.API_FAILURE, self.ls.get('ERROR_SAVING'))) + }); + } + console.log(result); + if(!result) { + return cb({ + code: 400, + content: jsonpResponse(callback, pb.BaseController.apiResponse(pb.BaseController.API_FAILURE, "Invalid Token")) + }); + } + //TODO: Apply Authentication + + cb({ + code: 200, + content: jsonpResponse(callback, pb.BaseController.apiResponse(pb.BaseController.API_SUCCESS, 'User Authenticated By Token', result)) + }); + }); + }; + + function jsonpResponse(callbakck, data) { + return callbakck + '(' + data + ')'; + } + + //exports + return TokenLoginController; +}; \ No newline at end of file diff --git a/plugins/pencilblue/include/routes.js b/plugins/pencilblue/include/routes.js index 7019b8777..38a86ae08 100644 --- a/plugins/pencilblue/include/routes.js +++ b/plugins/pencilblue/include/routes.js @@ -84,6 +84,14 @@ module.exports = function Routes(pb){ controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'sites', 'auth_token.js'), content_type: 'application/json' }, + { + method: 'get', + path: "/actions/admin/sites/token_login", + auth_required: false, + inactive_site_access: true, + controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'sites', 'token_login.js'), + content_type: 'application/json' + }, { method: 'post', path: "/actions/forgot_password", From 06d054a72b98d31d521781b068bcfbf92a7fc79e Mon Sep 17 00:00:00 2001 From: btidwell Date: Tue, 28 Jul 2015 16:17:41 -0400 Subject: [PATCH 505/790] call token login controller from angular controller on manage_sites view --- .../angular/admin/sites/manage_sites.html | 27 ++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/plugins/pencilblue/templates/angular/admin/sites/manage_sites.html b/plugins/pencilblue/templates/angular/admin/sites/manage_sites.html index de22e8a62..fa937c827 100644 --- a/plugins/pencilblue/templates/angular/admin/sites/manage_sites.html +++ b/plugins/pencilblue/templates/angular/admin/sites/manage_sites.html @@ -20,9 +20,9 @@ }; $scope.authUserToSite = function(site) { - $http.post('/actions/admin/sites/auth_token/' + site.uid) + $http.post('/actions/admin/sites/auth_token/' + encodeURIComponent(site.uid)) .success(function(result) { - $scope.onTokenComplate(site, result); + $scope.onTokenComplete(site, result.data); }) .error(function(error, status) { $scope.onActionFailure(error); @@ -67,16 +67,19 @@ }); }; - $scope.onTokenComplate = function(site, result) { - console.log(site); - console.log(result); -// $http.jsonp('//' + site.hostname + '/actions/admin/login?' + result.data.token) -// .success(function(result) { -// console.log(result); -// }) -// .error(function(error, status){ -// $scope.onActionFailure(error); -// }); + $scope.onTokenComplete = function(site, data) { + var url = '//' + site.hostname + '/actions/admin/sites/token_login?callback=angular.callbacks._0&token=' + data.token; + console.log(url); + $http.jsonp(url) + .success(function(result) { + console.log(result); + window.location = '//' + site.hostname + '/admin'; + }) + .error(function(error, status){ + console.log(error); + console.log(status); + $scope.onActionFailure(error); + }); }; $scope.onActivateOrDeactivateComplete = function(result) { From 6e432f5fb7e31ac88ed732dd40d2aec0c44e13a1 Mon Sep 17 00:00:00 2001 From: btidwell Date: Tue, 28 Jul 2015 16:22:51 -0400 Subject: [PATCH 506/790] use "this" when available --- .../pencilblue/controllers/actions/admin/sites/auth_token.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/pencilblue/controllers/actions/admin/sites/auth_token.js b/plugins/pencilblue/controllers/actions/admin/sites/auth_token.js index 509654de7..30aa32cc0 100644 --- a/plugins/pencilblue/controllers/actions/admin/sites/auth_token.js +++ b/plugins/pencilblue/controllers/actions/admin/sites/auth_token.js @@ -35,7 +35,7 @@ module.exports = function AuthTokenControllerModule(pb) { var self = this; var options = { site: this.pathVars.siteid, - user:self.session.authentication.user_id + user: this.session.authentication.user_id }; var tokenService = new pb.TokenService(options); tokenService.generateUserToken(function(err, tokenInfo) { From 7044a1ca69d85521b60ef60f2e593d34aee111df Mon Sep 17 00:00:00 2001 From: btidwell Date: Tue, 28 Jul 2015 17:02:48 -0400 Subject: [PATCH 507/790] add docs to token_service --- include/service/entities/token_service.js | 44 +++++++++++++++++------ 1 file changed, 33 insertions(+), 11 deletions(-) diff --git a/include/service/entities/token_service.js b/include/service/entities/token_service.js index 79d95aa99..a1c736fff 100644 --- a/include/service/entities/token_service.js +++ b/include/service/entities/token_service.js @@ -18,7 +18,6 @@ module.exports = function TokenServiceModule(pb) { //dependencies - var crypto = require('crypto'); var util = pb.util; /** @@ -28,6 +27,9 @@ module.exports = function TokenServiceModule(pb) { * @constructor * @module Services * @submodule Entities + * @param {Object} options + * @param {String} options.site - site uid + * @param {String} options.user - user id */ function TokenService(options) { this.site = options.site; @@ -35,6 +37,12 @@ module.exports = function TokenServiceModule(pb) { this.user = options.user; } + /** + * Generates and saves user token + * + * @method generateUserToken + * @param {Function} cb + */ TokenService.prototype.generateUserToken = function(cb) { var self = this; var token = util.uniqueId(); @@ -48,16 +56,13 @@ module.exports = function TokenServiceModule(pb) { }; - TokenService.prototype.saveToken = function(tokenInfo, cb) { - var doc = pb.DocumentCreator.create('auth_token', tokenInfo); - this.dao.save(doc, function(err, result) { - if(util.isError(err)) { - return cb(err, null); - } - cb(null, {token: tokenInfo.token}); - }); - }; - + /** + * Loads token information by token value and marks as used if found + * + * @method validateUserToken + * @param {String} token + * @param {Function} cb + */ TokenService.prototype.validateUserToken = function(token, cb) { var self = this; this.dao.loadByValue('token', token, 'auth_token', function(err, tokenInfo){ @@ -83,6 +88,23 @@ module.exports = function TokenServiceModule(pb) { }); }; + /** + * Saves token object + * + * @method saveToken + * @param {Object} tokenInfo - the token object to save + * @param {Function} cb + */ + TokenService.prototype.saveToken = function(tokenInfo, cb) { + var doc = pb.DocumentCreator.create('auth_token', tokenInfo); + this.dao.save(doc, function(err, result) { + if(util.isError(err)) { + return cb(err, null); + } + cb(null, {token: tokenInfo.token}); + }); + }; + //exports return TokenService; }; \ No newline at end of file From c564979d5878aa3c51c66cbe2a0b54744ccdc833 Mon Sep 17 00:00:00 2001 From: andparker Date: Tue, 28 Jul 2015 18:10:18 -0400 Subject: [PATCH 508/790] Reduces nested conditionals by returning callbacks. --- .../service/jobs/sites/site_activate_job.js | 31 ++++++++++--------- .../service/jobs/sites/site_deactivate_job.js | 30 +++++++++--------- 2 files changed, 32 insertions(+), 29 deletions(-) diff --git a/include/service/jobs/sites/site_activate_job.js b/include/service/jobs/sites/site_activate_job.js index 17ac90f03..b43ebc936 100644 --- a/include/service/jobs/sites/site_activate_job.js +++ b/include/service/jobs/sites/site_activate_job.js @@ -87,22 +87,23 @@ module.exports = function SiteActivateJobModule(pb) { function(callback) { var dao = new pb.DAO(); dao.loadByValue('uid', siteUid, 'site', function(err, site) { - if(util.isError(err)) { - callback(err, null) - } else if (!site) { - callback(new Error('Site not found'), null); - } else { - site.active = true; - dao.save(site, function(err, result) { - if(util.isError(err)) { - cb(err, null); - return; - } - - pb.RequestHandler.activateSite(site); - callback(err, result) - }); + if (util.isError(err)) { + return callback(err, null); + } + if (!site) { + return callback(new Error('Site not found'), null); } + + site.active = true; + dao.save(site, function(err, result) { + if(util.isError(err)) { + cb(err, null); + return; + } + + pb.RequestHandler.activateSite(site); + callback(err, result) + }); }); } ]; diff --git a/include/service/jobs/sites/site_deactivate_job.js b/include/service/jobs/sites/site_deactivate_job.js index d2a83c982..d5426fc81 100644 --- a/include/service/jobs/sites/site_deactivate_job.js +++ b/include/service/jobs/sites/site_deactivate_job.js @@ -85,21 +85,23 @@ module.exports = function SiteDeactivateJobModule(pb) { var dao = new pb.DAO(); dao.loadByValue('uid', siteUid, 'site', function(err, site) { if(util.isError(err)) { - callback(err, null) - } else if (!site) { - callback(new Error('Site not found'), null); - } else { - site.active = false; - dao.save(site, function(err, result) { - if(util.isError(err)) { - cb(err, null); - return; - } - - pb.RequestHandler.deactivateSite(site); - callback(err, result); - }); + return callback(err, null) } + + if (!site) { + return callback(new Error('Site not found'), null); + } + + site.active = false; + dao.save(site, function(err, result) { + if(util.isError(err)) { + cb(err, null); + return; + } + + pb.RequestHandler.deactivateSite(site); + callback(err, result); + }); }); } ]; From 4aabec2800b77cce4a405628517cf428a194582e Mon Sep 17 00:00:00 2001 From: andparker Date: Tue, 28 Jul 2015 18:11:24 -0400 Subject: [PATCH 509/790] Puts return and callback on the same line. --- include/service/jobs/sites/site_activate_job.js | 3 +-- include/service/jobs/sites/site_deactivate_job.js | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/include/service/jobs/sites/site_activate_job.js b/include/service/jobs/sites/site_activate_job.js index b43ebc936..e350d0deb 100644 --- a/include/service/jobs/sites/site_activate_job.js +++ b/include/service/jobs/sites/site_activate_job.js @@ -97,8 +97,7 @@ module.exports = function SiteActivateJobModule(pb) { site.active = true; dao.save(site, function(err, result) { if(util.isError(err)) { - cb(err, null); - return; + return cb(err, null); } pb.RequestHandler.activateSite(site); diff --git a/include/service/jobs/sites/site_deactivate_job.js b/include/service/jobs/sites/site_deactivate_job.js index d5426fc81..c910b8fbb 100644 --- a/include/service/jobs/sites/site_deactivate_job.js +++ b/include/service/jobs/sites/site_deactivate_job.js @@ -95,8 +95,7 @@ module.exports = function SiteDeactivateJobModule(pb) { site.active = false; dao.save(site, function(err, result) { if(util.isError(err)) { - cb(err, null); - return; + return cb(err, null); } pb.RequestHandler.deactivateSite(site); From d96d6e2f18b634d2782d47f145a4e5f7142f911a Mon Sep 17 00:00:00 2001 From: andparker Date: Tue, 28 Jul 2015 18:12:34 -0400 Subject: [PATCH 510/790] Adds a missing semicolon. --- include/service/jobs/sites/site_deactivate_job.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/service/jobs/sites/site_deactivate_job.js b/include/service/jobs/sites/site_deactivate_job.js index c910b8fbb..3d7435663 100644 --- a/include/service/jobs/sites/site_deactivate_job.js +++ b/include/service/jobs/sites/site_deactivate_job.js @@ -85,7 +85,7 @@ module.exports = function SiteDeactivateJobModule(pb) { var dao = new pb.DAO(); dao.loadByValue('uid', siteUid, 'site', function(err, site) { if(util.isError(err)) { - return callback(err, null) + return callback(err, null); } if (!site) { From adab94aed5c630207fcb86fb0a55aa893c41e4e0 Mon Sep 17 00:00:00 2001 From: andparker Date: Tue, 28 Jul 2015 18:25:28 -0400 Subject: [PATCH 511/790] Updates function design for better performance and readability. --- include/util.js | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/include/util.js b/include/util.js index 598336d60..35fc26873 100755 --- a/include/util.js +++ b/include/util.js @@ -395,15 +395,8 @@ Util.copyArray = function(array) { }; Util.dedupeArray = function(array) { - var a = array.concat(); - for(var i = 0; i < a.length; ++i) { - for(var j=i+1; j Date: Wed, 29 Jul 2015 11:13:53 -0400 Subject: [PATCH 512/790] Refactored to reduce nesting by returning callbacks. --- .../actions/admin/sites/edit_site.js | 36 ++++++++----------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/plugins/pencilblue/controllers/actions/admin/sites/edit_site.js b/plugins/pencilblue/controllers/actions/admin/sites/edit_site.js index 101a759ef..1afe0f197 100644 --- a/plugins/pencilblue/controllers/actions/admin/sites/edit_site.js +++ b/plugins/pencilblue/controllers/actions/admin/sites/edit_site.js @@ -26,25 +26,22 @@ module.exports = function EditSiteActionModule(pb) { function EditSiteAction(){} util.inherits(EditSiteAction, pb.BaseController); - EditSiteAction.prototype.render = function(cb) - { + EditSiteAction.prototype.render = function(cb) { var self = this; var siteid = this.pathVars.siteid; var message = self.hasRequiredParams(self.body, self.getRequiredFields()); if(message) { - cb({ + return cb({ code: 400, content: pb.BaseController.apiResponse(pb.BaseController.API_ERROR, message) }); - return; } if(!pb.security.isAuthorized(self.session, {admin_level: self.body.admin})) { - cb({ + return cb({ code: 400, content: pb.BaseController.apiResponse(pb.BaseController.API_ERROR, self.ls.get('INSUFFICIENT_CREDENTIALS')) }); - return; } var siteService = new pb.SiteService(); @@ -52,26 +49,23 @@ module.exports = function EditSiteActionModule(pb) { dao.loadByValue('uid', siteid, 'site', function(err, data) { siteService.isDisplayNameOrHostnameTaken(self.body.displayName, self.body.hostname, data._id, function (err, isTaken, field) { if(isTaken) { - cb({ + return cb({ code: 400, content: pb.BaseController.apiResponse(pb.BaseController.API_ERROR, self.ls.get('DUPLICATE_INFO')) }); - - } else { - data.displayName = self.body.displayName; - data.hostname = self.body.hostname; - dao.save(data, function(err, result) { - if(err) { - cb({ - code: 400, - content: pb.BaseController.apiResponse(pb.BaseController.API_ERROR, self.ls.get('ERROR_SAVING')) - }); - return; - } - cb({content: pb.BaseController.apiResponse(pb.BaseController.API_SUCCESS, self.ls.get('SITE_UPDATED'), result)}); - }); } + data.displayName = self.body.displayName; + data.hostname = self.body.hostname; + dao.save(data, function(err, result) { + if(err) { + return cb({ + code: 400, + content: pb.BaseController.apiResponse(pb.BaseController.API_ERROR, self.ls.get('ERROR_SAVING')) + }); + } + cb({content: pb.BaseController.apiResponse(pb.BaseController.API_SUCCESS, self.ls.get('SITE_UPDATED'), result)}); + }); }); }) From 6ca1260a1346713f4038d69fbc5e99d186e4167d Mon Sep 17 00:00:00 2001 From: andparker Date: Wed, 29 Jul 2015 11:58:36 -0400 Subject: [PATCH 513/790] Adds TODO comment for injecting the template service. --- include/email.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/email.js b/include/email.js index c82a4b438..05f23556f 100755 --- a/include/email.js +++ b/include/email.js @@ -65,6 +65,8 @@ module.exports = function EmailServiceModule(pb) { */ EmailService.prototype.sendFromTemplate = function(options, cb){ var self = this; + + //TODO: Move the instantiation of the template service to the constructor so it can be injectable with all of the other context properties it needs. var ts = new pb.TemplateService({ site: this.site }); if (options.replacements) { for(var key in options.replacements) { From 7626ddee042d8b927fcfa82e2304e79c46237dfb Mon Sep 17 00:00:00 2001 From: iandtrapp Date: Wed, 29 Jul 2015 13:17:15 -0400 Subject: [PATCH 514/790] Refactor plugin service to take in an options object --- include/service/entities/plugin_service.js | 8 ++++---- include/service/entities/plugin_setting_service.js | 2 +- include/service/entities/template_service.js | 2 +- include/service/jobs/plugins/plugin_job_runner.js | 2 +- plugins/ga/ga.js | 2 +- .../controllers/admin/plugins/manage_plugins.js | 2 +- .../controllers/admin/plugins/plugin_details.js | 2 +- .../controllers/admin/plugins/plugin_settings.js | 2 +- .../pencilblue/controllers/admin/themes/manage_themes.js | 2 +- plugins/pencilblue/controllers/api/plugins/plugin_api.js | 2 +- plugins/portfolio/controllers/blog.js | 2 +- plugins/portfolio/controllers/index.js | 2 +- plugins/wp_import/services/wp_xml_parse.js | 2 +- 13 files changed, 16 insertions(+), 16 deletions(-) diff --git a/include/service/entities/plugin_service.js b/include/service/entities/plugin_service.js index 1c5d1e12e..f1f7ae1ba 100755 --- a/include/service/entities/plugin_service.js +++ b/include/service/entities/plugin_service.js @@ -38,9 +38,9 @@ module.exports = function PluginServiceModule(pb) { * @module Services * @submodule Entities */ - function PluginService(siteUID){ - if(pb.config.multisite.enabled && siteUID) { - this.site = siteUID; + function PluginService(options){ + if(pb.config.multisite.enabled && options) { + this.site = options.site; } else { this.site = GLOBAL_SITE; } @@ -2167,7 +2167,7 @@ module.exports = function PluginServiceModule(pb) { jobId: command.jobId } - var pluginService = new PluginService(command.site); + var pluginService = new PluginService({site: command.site}); pluginService.uninstallPlugin(command.pluginUid, options, function(err, result) { var response = { diff --git a/include/service/entities/plugin_setting_service.js b/include/service/entities/plugin_setting_service.js index d57bc2715..466594082 100644 --- a/include/service/entities/plugin_setting_service.js +++ b/include/service/entities/plugin_setting_service.js @@ -21,7 +21,7 @@ module.exports = function PluginSettingServiceModule(pb) { this.site = GLOBAL_SITE; } - this.pluginService = new pb.PluginService(this.site); + this.pluginService = new pb.PluginService({site: this.site}); /** * A setting service that sets and retrieves the settings for plugins diff --git a/include/service/entities/template_service.js b/include/service/entities/template_service.js index 39c43293f..fd6eb1118 100755 --- a/include/service/entities/template_service.js +++ b/include/service/entities/template_service.js @@ -125,7 +125,7 @@ module.exports = function(pb) { * @property pluginService * @type {PluginService} */ - this.pluginService = new pb.PluginService(this.siteUid); + this.pluginService = new pb.PluginService({site: this.siteUid}); this.init(); } diff --git a/include/service/jobs/plugins/plugin_job_runner.js b/include/service/jobs/plugins/plugin_job_runner.js index 8b2ff3f9d..22655a2d2 100644 --- a/include/service/jobs/plugins/plugin_job_runner.js +++ b/include/service/jobs/plugins/plugin_job_runner.js @@ -67,7 +67,7 @@ module.exports = function PluginJobRunnerModule(pb) { PluginJobRunner.prototype.setSite = function(site) { this.site = site; - this.pluginService = new pb.PluginService(site); + this.pluginService = new pb.PluginService({site: site}); return this; } diff --git a/plugins/ga/ga.js b/plugins/ga/ga.js index bb164c84f..bad7b690f 100755 --- a/plugins/ga/ga.js +++ b/plugins/ga/ga.js @@ -65,7 +65,7 @@ module.exports = function GoogleAnalyticsModule(pb) { */ GoogleAnalytics.onRequest = function(req, session, ls, cb) { var siteId = pb.RequestHandler.sites[req.headers.host] ? pb.RequestHandler.sites[req.headers.host].uid : null; - var pluginService = new pb.PluginService(pb.SiteService.getCurrentSite(siteId)); + var pluginService = new pb.PluginService({site: pb.SiteService.getCurrentSite(siteId)}); pluginService.getSettingsKV('ga', function(err, settings) { if (util.isError(err)) { return cb(err, ''); diff --git a/plugins/pencilblue/controllers/admin/plugins/manage_plugins.js b/plugins/pencilblue/controllers/admin/plugins/manage_plugins.js index 548e58ef9..a039f36ae 100755 --- a/plugins/pencilblue/controllers/admin/plugins/manage_plugins.js +++ b/plugins/pencilblue/controllers/admin/plugins/manage_plugins.js @@ -34,7 +34,7 @@ module.exports = function(pb) { ManagePlugins.prototype.render = function (cb) { var self = this; - var pluginService = new pb.PluginService(self.site); + var pluginService = new pb.PluginService({site: self.site}); var globalPluginService = new pb.PluginService(); pluginService.getPluginMap(function (err, sitePluginMap) { if (util.isError(err)) { diff --git a/plugins/pencilblue/controllers/admin/plugins/plugin_details.js b/plugins/pencilblue/controllers/admin/plugins/plugin_details.js index af6d1ca2a..ebbf28492 100755 --- a/plugins/pencilblue/controllers/admin/plugins/plugin_details.js +++ b/plugins/pencilblue/controllers/admin/plugins/plugin_details.js @@ -78,7 +78,7 @@ module.exports = function(pb) { PluginDetailsViewController.prototype.getDetails = function (puid, cb) { var self = this; - var pluginService = new pb.PluginService(self.site); + var pluginService = new pb.PluginService({site: self.site}); pluginService.getPluginBySite(puid, function(err, plugin) { if (util.isError(err)) { cb(err, plugin); diff --git a/plugins/pencilblue/controllers/admin/plugins/plugin_settings.js b/plugins/pencilblue/controllers/admin/plugins/plugin_settings.js index 6477dbd9f..fb60e8ae8 100755 --- a/plugins/pencilblue/controllers/admin/plugins/plugin_settings.js +++ b/plugins/pencilblue/controllers/admin/plugins/plugin_settings.js @@ -46,7 +46,7 @@ module.exports = function(pb) { PluginSettingsFormController.prototype.init = function (props, cb) { var self = this; pb.BaseAdminController.prototype.init.call(self, props, function () { - self.pluginService = new pb.PluginService(self.site); + self.pluginService = new pb.PluginService({site: self.site}); cb(); }); }; diff --git a/plugins/pencilblue/controllers/admin/themes/manage_themes.js b/plugins/pencilblue/controllers/admin/themes/manage_themes.js index 7eca7720b..573e0c804 100755 --- a/plugins/pencilblue/controllers/admin/themes/manage_themes.js +++ b/plugins/pencilblue/controllers/admin/themes/manage_themes.js @@ -34,7 +34,7 @@ module.exports = function(pb) { var self = this; //get plugs with themes - var pluginService = new pb.PluginService(self.site); + var pluginService = new pb.PluginService({site: self.site}); pluginService.getPluginsWithThemesBySite(function (err, themes) { if (util.isError(err)) { throw result; diff --git a/plugins/pencilblue/controllers/api/plugins/plugin_api.js b/plugins/pencilblue/controllers/api/plugins/plugin_api.js index 5cb844c59..3fb3e3370 100755 --- a/plugins/pencilblue/controllers/api/plugins/plugin_api.js +++ b/plugins/pencilblue/controllers/api/plugins/plugin_api.js @@ -71,7 +71,7 @@ module.exports = function(pb) { PluginApiController.prototype.render = function(cb) { var action = this.pathVars.action; var identifier = this.pathVars.id; - this.pluginService = new pb.PluginService(this.site); + this.pluginService = new pb.PluginService({site: this.site}); //validate action var errors = []; diff --git a/plugins/portfolio/controllers/blog.js b/plugins/portfolio/controllers/blog.js index f7ba15e36..7b458d121 100755 --- a/plugins/portfolio/controllers/blog.js +++ b/plugins/portfolio/controllers/blog.js @@ -428,7 +428,7 @@ module.exports = function BlogModule(pb) { Blog.prototype.getSideNavigation = function(articles, cb) { var self = this; - var pluginService = new pb.PluginService(this.site); + var pluginService = new pb.PluginService({site: this.site}); pluginService.getSetting('show_side_navigation', 'portfolio', function(err, showSideNavigation) { if(!showSideNavigation) { cb('', null); diff --git a/plugins/portfolio/controllers/index.js b/plugins/portfolio/controllers/index.js index 7b01a9c90..c17a6cfc8 100755 --- a/plugins/portfolio/controllers/index.js +++ b/plugins/portfolio/controllers/index.js @@ -67,7 +67,7 @@ module.exports = function IndexModule(pb) { }; TopMenu.getTopMenu(self.session, self.ls, options, function(themeSettings, navigation, accountButtons) { TopMenu.getBootstrapNav(navigation, accountButtons, function(navigation, accountButtons) { - var pluginService = new pb.PluginService(self.site); + var pluginService = new pb.PluginService({site: self.site}); pluginService.getSettings('portfolio', function(err, portfolioSettings) { var homePageKeywords = ''; diff --git a/plugins/wp_import/services/wp_xml_parse.js b/plugins/wp_import/services/wp_xml_parse.js index 0f4118085..923f8c68f 100644 --- a/plugins/wp_import/services/wp_xml_parse.js +++ b/plugins/wp_import/services/wp_xml_parse.js @@ -98,7 +98,7 @@ module.exports = function WPXMLParseServiceModule(pb) { //load settings function(callback) { - var pluginService = new pb.PluginService(self.site); + var pluginService = new pb.PluginService({site: self.site}); pluginService.getSettingsKV('wp_import', function(err, settingsResult) { settings = settingsResult; callback(err); From 05bb38e4707bfba25ab6084d1aaae7bd642737fb Mon Sep 17 00:00:00 2001 From: btidwell Date: Wed, 29 Jul 2015 13:28:14 -0400 Subject: [PATCH 515/790] use new dao object for each DB call --- include/service/entities/token_service.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/include/service/entities/token_service.js b/include/service/entities/token_service.js index a1c736fff..3dbaec735 100644 --- a/include/service/entities/token_service.js +++ b/include/service/entities/token_service.js @@ -33,7 +33,6 @@ module.exports = function TokenServiceModule(pb) { */ function TokenService(options) { this.site = options.site; - this.dao = new pb.SiteQueryService(this.site, false); this.user = options.user; } @@ -65,7 +64,8 @@ module.exports = function TokenServiceModule(pb) { */ TokenService.prototype.validateUserToken = function(token, cb) { var self = this; - this.dao.loadByValue('token', token, 'auth_token', function(err, tokenInfo){ + var dao = new pb.SiteQueryService(this.site, false); + dao.loadByValue('token', token, 'auth_token', function(err, tokenInfo){ if(util.isError(err)) { return cb(err, null); } @@ -97,7 +97,8 @@ module.exports = function TokenServiceModule(pb) { */ TokenService.prototype.saveToken = function(tokenInfo, cb) { var doc = pb.DocumentCreator.create('auth_token', tokenInfo); - this.dao.save(doc, function(err, result) { + var dao = new pb.SiteQueryService(this.site, false); + dao.save(doc, function(err, result) { if(util.isError(err)) { return cb(err, null); } From d6c3151fed7b9b43a51cfed7cc01839740051be3 Mon Sep 17 00:00:00 2001 From: btidwell Date: Wed, 29 Jul 2015 13:29:43 -0400 Subject: [PATCH 516/790] remove debug console logs --- .../pencilblue/controllers/actions/admin/sites/token_login.js | 2 +- .../templates/angular/admin/sites/manage_sites.html | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/plugins/pencilblue/controllers/actions/admin/sites/token_login.js b/plugins/pencilblue/controllers/actions/admin/sites/token_login.js index c577c9dac..b5f49933c 100644 --- a/plugins/pencilblue/controllers/actions/admin/sites/token_login.js +++ b/plugins/pencilblue/controllers/actions/admin/sites/token_login.js @@ -46,7 +46,7 @@ module.exports = function TokenLoginControllerModule(pb) { content: jsonpResponse(callback, pb.BaseController.apiResponse(pb.BaseController.API_FAILURE, self.ls.get('ERROR_SAVING'))) }); } - console.log(result); + if(!result) { return cb({ code: 400, diff --git a/plugins/pencilblue/templates/angular/admin/sites/manage_sites.html b/plugins/pencilblue/templates/angular/admin/sites/manage_sites.html index fa937c827..c76b01900 100644 --- a/plugins/pencilblue/templates/angular/admin/sites/manage_sites.html +++ b/plugins/pencilblue/templates/angular/admin/sites/manage_sites.html @@ -69,15 +69,11 @@ $scope.onTokenComplete = function(site, data) { var url = '//' + site.hostname + '/actions/admin/sites/token_login?callback=angular.callbacks._0&token=' + data.token; - console.log(url); $http.jsonp(url) .success(function(result) { - console.log(result); window.location = '//' + site.hostname + '/admin'; }) .error(function(error, status){ - console.log(error); - console.log(status); $scope.onActionFailure(error); }); }; From 2d7fa4e2266121af1d77c74c0b4029e1899af5ba Mon Sep 17 00:00:00 2001 From: btidwell Date: Wed, 29 Jul 2015 13:43:51 -0400 Subject: [PATCH 517/790] Localize success message and display on view --- .../pencilblue/controllers/actions/admin/sites/auth_token.js | 2 +- .../controllers/actions/admin/sites/token_login.js | 4 ++-- .../templates/angular/admin/sites/manage_sites.html | 4 ++++ public/localization/en-us.js | 5 ++++- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/plugins/pencilblue/controllers/actions/admin/sites/auth_token.js b/plugins/pencilblue/controllers/actions/admin/sites/auth_token.js index 30aa32cc0..3f70893f7 100644 --- a/plugins/pencilblue/controllers/actions/admin/sites/auth_token.js +++ b/plugins/pencilblue/controllers/actions/admin/sites/auth_token.js @@ -47,7 +47,7 @@ module.exports = function AuthTokenControllerModule(pb) { } cb({ code: 200, - content: pb.BaseController.apiResponse(pb.BaseController.API_SUCCESS, 'Token Created For User', tokenInfo) + content: pb.BaseController.apiResponse(pb.BaseController.API_SUCCESS, self.ls.get('TOKEN_CREATED'), tokenInfo) }); }); }; diff --git a/plugins/pencilblue/controllers/actions/admin/sites/token_login.js b/plugins/pencilblue/controllers/actions/admin/sites/token_login.js index b5f49933c..18e682c7e 100644 --- a/plugins/pencilblue/controllers/actions/admin/sites/token_login.js +++ b/plugins/pencilblue/controllers/actions/admin/sites/token_login.js @@ -50,14 +50,14 @@ module.exports = function TokenLoginControllerModule(pb) { if(!result) { return cb({ code: 400, - content: jsonpResponse(callback, pb.BaseController.apiResponse(pb.BaseController.API_FAILURE, "Invalid Token")) + content: jsonpResponse(callback, pb.BaseController.apiResponse(pb.BaseController.API_FAILURE, self.ls.get('INVALID_TOKEN'))) }); } //TODO: Apply Authentication cb({ code: 200, - content: jsonpResponse(callback, pb.BaseController.apiResponse(pb.BaseController.API_SUCCESS, 'User Authenticated By Token', result)) + content: jsonpResponse(callback, pb.BaseController.apiResponse(pb.BaseController.API_SUCCESS, self.ls.get('TOKEN_LOGIN_SUCCESSFUL'), result)) }); }); }; diff --git a/plugins/pencilblue/templates/angular/admin/sites/manage_sites.html b/plugins/pencilblue/templates/angular/admin/sites/manage_sites.html index c76b01900..14192a5f5 100644 --- a/plugins/pencilblue/templates/angular/admin/sites/manage_sites.html +++ b/plugins/pencilblue/templates/angular/admin/sites/manage_sites.html @@ -22,6 +22,8 @@ $scope.authUserToSite = function(site) { $http.post('/actions/admin/sites/auth_token/' + encodeURIComponent(site.uid)) .success(function(result) { + $scope.successMessage = result.message; + $scope.onActionSuccess(); $scope.onTokenComplete(site, result.data); }) .error(function(error, status) { @@ -71,6 +73,8 @@ var url = '//' + site.hostname + '/actions/admin/sites/token_login?callback=angular.callbacks._0&token=' + data.token; $http.jsonp(url) .success(function(result) { + $scope.successMessage = result.message; + $scope.onActionSuccess(); window.location = '//' + site.hostname + '/admin'; }) .error(function(error, status){ diff --git a/public/localization/en-us.js b/public/localization/en-us.js index de93f1b7f..a2d15d9e1 100755 --- a/public/localization/en-us.js +++ b/public/localization/en-us.js @@ -444,7 +444,10 @@ var loc = INITIAL_DELETE_WARNING: 'You are attempting to delete this site and all content associated with it, including: ', FINAL_DELETE_WARNING: 'This action cannot be reversed. Are you sure you want to continue?', DELETE_SITE: 'Delete Site', - DANGER: 'Danger!' + DANGER: 'Danger!', + TOKEN_CREATED: 'Authentication Token Created', + INVALID_TOKEN: 'Invalid Token', + TOKEN_LOGIN_SUCCESSFUL: 'Successful Login By Token' }, plugins: { From 151e0e75115cb84adfb00c8f2e1116b33af93380 Mon Sep 17 00:00:00 2001 From: wesanderson303 Date: Wed, 29 Jul 2015 13:57:06 -0400 Subject: [PATCH 518/790] callback fixes for checkForFormRefill() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Don’t look at my shame --- .../controllers/admin/content/articles/article_form.js | 5 ++--- .../pencilblue/controllers/admin/content/pages/page_form.js | 4 ++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/plugins/pencilblue/controllers/admin/content/articles/article_form.js b/plugins/pencilblue/controllers/admin/content/articles/article_form.js index 44010242d..7f9ad12b8 100755 --- a/plugins/pencilblue/controllers/admin/content/articles/article_form.js +++ b/plugins/pencilblue/controllers/admin/content/articles/article_form.js @@ -76,14 +76,13 @@ module.exports = function(pb) { self.onTemplateRetrieved('' + data, function(err, data) { var result = '' + data; self.checkForFormRefill(result, function(err, newResult) { - err = new Error(); //Handle errors if (util.isError(err)) { pb.log.error("ArticleForm.checkForFormRefill encountered an error. ERROR[%s]", err.stack); - return; + return cb(err); } result = newResult; - cb(null, {content: result}); + cb({content: result}); }); }); }); diff --git a/plugins/pencilblue/controllers/admin/content/pages/page_form.js b/plugins/pencilblue/controllers/admin/content/pages/page_form.js index 8ecc751a5..cd0f777b6 100755 --- a/plugins/pencilblue/controllers/admin/content/pages/page_form.js +++ b/plugins/pencilblue/controllers/admin/content/pages/page_form.js @@ -77,10 +77,10 @@ module.exports = function(pb) { //Handle errors if (util.isError(err)) { pb.log.error("PageFormController.checkForFormRefill encountered an error. ERROR[%s]", err.stack); - return; + return cb(err); } result = newResult; - cb(null, {content: result}); + cb({content: result}); }); }); }; From 32f96c77e7e26428da05553f075efd53ae1c01a4 Mon Sep 17 00:00:00 2001 From: iandtrapp Date: Wed, 29 Jul 2015 14:05:18 -0400 Subject: [PATCH 519/790] DB Entity Service Refactor - Breaks plugins install --- include/service/db_entity_service.js | 12 ++++++------ include/service/entities/plugin_service.js | 2 +- include/service/entities/plugin_setting_service.js | 2 +- include/system/settings.js | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/include/service/db_entity_service.js b/include/service/db_entity_service.js index b69e193f0..6962daeec 100755 --- a/include/service/db_entity_service.js +++ b/include/service/db_entity_service.js @@ -31,13 +31,13 @@ module.exports = function DbEntityServiceModule(pb) { * @param {String} valueField * @param {String} keyField */ - function DbEntityService(objType, valueField, keyField, site, onlyThisSite){ + function DbEntityService(options){ this.type = 'DB'; - this.objType = objType; - this.keyField = keyField; - this.valueField = valueField ? valueField : null; - this.site = site || GLOBAL_SITE; - this.onlyThisSite = onlyThisSite ? true : false; + this.objType = options.objType; + this.keyField = options.keyField; + this.valueField = options.valueField ? options.valueField : null; + this.site = options.site || GLOBAL_SITE; + this.onlyThisSite = options.onlyThisSite ? true : false; } var GLOBAL_SITE = pb.SiteService.GLOBAL_SITE; diff --git a/include/service/entities/plugin_service.js b/include/service/entities/plugin_service.js index f1f7ae1ba..796ab3c44 100755 --- a/include/service/entities/plugin_service.js +++ b/include/service/entities/plugin_service.js @@ -503,7 +503,7 @@ module.exports = function PluginServiceModule(pb) { } //always add DB - services.push(new pb.DBEntityService(objType, 'settings', 'plugin_uid', site)); + services.push(new pb.DBEntityService({objType: objType, keyField: 'settings', valueField: 'plugin_uid', site: site})); return new pb.SimpleLayeredService(services, serviceName); }; diff --git a/include/service/entities/plugin_setting_service.js b/include/service/entities/plugin_setting_service.js index 466594082..3a3fe77de 100644 --- a/include/service/entities/plugin_setting_service.js +++ b/include/service/entities/plugin_setting_service.js @@ -498,7 +498,7 @@ module.exports = function PluginSettingServiceModule(pb) { } //always add DB - services.push(new pb.DBEntityService(objType, 'settings', 'plugin_uid', site, onlyThisSite)); + services.push(new pb.DBEntityService({objType: objType, keyField: 'settings', valueField: 'plugin_uid', site: site, onlyThisSite: onlyThisSite})); return new pb.SimpleLayeredService(services, serviceName); }; diff --git a/include/system/settings.js b/include/system/settings.js index be96c7ba0..27d78f5c6 100755 --- a/include/system/settings.js +++ b/include/system/settings.js @@ -87,7 +87,7 @@ module.exports = function SettingsModule(pb) { } //always add db service - services.push(new pb.DBEntityService(objType, valueField, keyField, site, onlyThisSite)); + services.push(new pb.DBEntityService({objType: objType, valueField: valueField, keyField: keyField, site: site, onlyThisSite: onlyThisSite})); return new pb.SimpleLayeredService(services, 'SettingService' + count++); }; From d87302798ab85e25bbca9ff7932be91c13d75f6e Mon Sep 17 00:00:00 2001 From: btidwell Date: Wed, 29 Jul 2015 14:28:46 -0400 Subject: [PATCH 520/790] Authentication by Token --- include/requirements.js | 1 + include/security/authentication/index.js | 34 +++++++++++++++++-- include/service/entities/token_service.js | 9 +++-- .../actions/admin/sites/token_login.js | 8 ++--- .../angular/admin/sites/manage_sites.html | 2 -- 5 files changed, 43 insertions(+), 11 deletions(-) diff --git a/include/requirements.js b/include/requirements.js index ba9407fc4..c3cb63f83 100755 --- a/include/requirements.js +++ b/include/requirements.js @@ -105,6 +105,7 @@ module.exports = function PB(config) { var Authentication = require(path.join(config.docRoot, '/include/security/authentication'))(pb); pb.UsernamePasswordAuthentication = Authentication.UsernamePasswordAuthentication; pb.FormAuthentication = Authentication.FormAuthentication; + pb.TokenAuthentication = Authentication.TokenAuthentication; //setup user service pb.BaseObjectService = require(path.join(config.docRoot, '/include/service/base_object_service.js'))(pb); diff --git a/include/security/authentication/index.js b/include/security/authentication/index.js index a625fe0a0..4d1dc0b66 100755 --- a/include/security/authentication/index.js +++ b/include/security/authentication/index.js @@ -92,9 +92,39 @@ module.exports = function AuthenticationModule(pb) { var userDocument = pb.DocumentCreator.create('user', postObj); FormAuthentication.super_.prototype.authenticate.apply(this, [userDocument, cb]); }; - + + /** + * + * @class TokenAuthentication + * @constructor + */ + function TokenAuthentication(options) { + this.options = options; + } + + /** + * @method authenticate + */ + TokenAuthentication.prototype.authenticate = function(token, cb) { + var tokenService = new pb.TokenService(this.options); + tokenService.validateUserToken(token, function(err, result) { + if(util.isError(err)) { + return cb(err, null); + } + + if(!result.tokenInfo || !result.valid || !result.tokenInfo.user) { + return cb(); + } + + var dao = new pb.DAO(); + dao.loadById(result.tokenInfo.user, 'user', cb); + }); + }; + + //exports return { UsernamePasswordAuthentication: UsernamePasswordAuthentication, - FormAuthentication: FormAuthentication + FormAuthentication: FormAuthentication, + TokenAuthentication: TokenAuthentication }; }; diff --git a/include/service/entities/token_service.js b/include/service/entities/token_service.js index 3dbaec735..8ab5f8e6e 100644 --- a/include/service/entities/token_service.js +++ b/include/service/entities/token_service.js @@ -51,7 +51,12 @@ module.exports = function TokenServiceModule(pb) { user: self.user, used: false } - this.saveToken(tokenInfo, cb); + this.saveToken(tokenInfo, function(err, result) { + if(util.isError(err)) { + return cb(err, null); + } + cb(null, {token: result.token}); + }); }; @@ -102,7 +107,7 @@ module.exports = function TokenServiceModule(pb) { if(util.isError(err)) { return cb(err, null); } - cb(null, {token: tokenInfo.token}); + cb(null, result); }); }; diff --git a/plugins/pencilblue/controllers/actions/admin/sites/token_login.js b/plugins/pencilblue/controllers/actions/admin/sites/token_login.js index 18e682c7e..151ffcf58 100644 --- a/plugins/pencilblue/controllers/actions/admin/sites/token_login.js +++ b/plugins/pencilblue/controllers/actions/admin/sites/token_login.js @@ -37,8 +37,7 @@ module.exports = function TokenLoginControllerModule(pb) { site: this.site }; var callback = this.query.callback; - var tokenService = new pb.TokenService(options); - tokenService.validateUserToken(this.query.token, function(err, result) { + pb.security.authenticateSession(this.session, this.query.token, new pb.TokenAuthentication(options), function(err, user) { if(util.isError(err)) { return cb({ @@ -47,17 +46,16 @@ module.exports = function TokenLoginControllerModule(pb) { }); } - if(!result) { + if(!user) { return cb({ code: 400, content: jsonpResponse(callback, pb.BaseController.apiResponse(pb.BaseController.API_FAILURE, self.ls.get('INVALID_TOKEN'))) }); } - //TODO: Apply Authentication cb({ code: 200, - content: jsonpResponse(callback, pb.BaseController.apiResponse(pb.BaseController.API_SUCCESS, self.ls.get('TOKEN_LOGIN_SUCCESSFUL'), result)) + content: jsonpResponse(callback, pb.BaseController.apiResponse(pb.BaseController.API_SUCCESS, self.ls.get('TOKEN_LOGIN_SUCCESSFUL'))) }); }); }; diff --git a/plugins/pencilblue/templates/angular/admin/sites/manage_sites.html b/plugins/pencilblue/templates/angular/admin/sites/manage_sites.html index 14192a5f5..477163707 100644 --- a/plugins/pencilblue/templates/angular/admin/sites/manage_sites.html +++ b/plugins/pencilblue/templates/angular/admin/sites/manage_sites.html @@ -23,7 +23,6 @@ $http.post('/actions/admin/sites/auth_token/' + encodeURIComponent(site.uid)) .success(function(result) { $scope.successMessage = result.message; - $scope.onActionSuccess(); $scope.onTokenComplete(site, result.data); }) .error(function(error, status) { @@ -74,7 +73,6 @@ $http.jsonp(url) .success(function(result) { $scope.successMessage = result.message; - $scope.onActionSuccess(); window.location = '//' + site.hostname + '/admin'; }) .error(function(error, status){ From 0730eccecbc572540c3933067602805bdd8296f6 Mon Sep 17 00:00:00 2001 From: iandtrapp Date: Wed, 29 Jul 2015 14:30:30 -0400 Subject: [PATCH 521/790] Removed config.multisite.enabled --- include/service/entities/plugin_service.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/service/entities/plugin_service.js b/include/service/entities/plugin_service.js index f1f7ae1ba..de869871c 100755 --- a/include/service/entities/plugin_service.js +++ b/include/service/entities/plugin_service.js @@ -39,7 +39,7 @@ module.exports = function PluginServiceModule(pb) { * @submodule Entities */ function PluginService(options){ - if(pb.config.multisite.enabled && options) { + if(options) { this.site = options.site; } else { this.site = GLOBAL_SITE; From e8d86b569a920efcc111de4237b87ec5047c3786 Mon Sep 17 00:00:00 2001 From: btidwell Date: Wed, 29 Jul 2015 15:00:02 -0400 Subject: [PATCH 522/790] Add more details documentation to authentication module --- include/security/authentication/index.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/security/authentication/index.js b/include/security/authentication/index.js index 4d1dc0b66..5f44b970d 100755 --- a/include/security/authentication/index.js +++ b/include/security/authentication/index.js @@ -82,6 +82,10 @@ module.exports = function AuthenticationModule(pb) { /** * @method authenticate + * @param {Object} postObj + * @param {String} postObj.username + * @param {String} postObj.password + * @param {Function} cb */ FormAuthentication.prototype.authenticate = function(postObj, cb) { if (!util.isObject(postObj)) { @@ -104,6 +108,8 @@ module.exports = function AuthenticationModule(pb) { /** * @method authenticate + * @param {String} token + * @param {Function} cb */ TokenAuthentication.prototype.authenticate = function(token, cb) { var tokenService = new pb.TokenService(this.options); From 89f027bd2dacb75a3e85378f86febd69f1c0e4a3 Mon Sep 17 00:00:00 2001 From: btidwell Date: Wed, 29 Jul 2015 15:00:38 -0400 Subject: [PATCH 523/790] Add empty href to links for cursor:pointer experience --- plugins/pencilblue/templates/admin/sites/manage_sites.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/pencilblue/templates/admin/sites/manage_sites.html b/plugins/pencilblue/templates/admin/sites/manage_sites.html index 62a8b5fdc..79dfd29d5 100644 --- a/plugins/pencilblue/templates/admin/sites/manage_sites.html +++ b/plugins/pencilblue/templates/admin/sites/manage_sites.html @@ -18,7 +18,7 @@
    @@ -50,7 +50,7 @@
    From 54f594cf2341a3ee272dee62f1ce5a71694c172d Mon Sep 17 00:00:00 2001 From: btidwell Date: Wed, 29 Jul 2015 15:43:09 -0400 Subject: [PATCH 524/790] set expire on auth_token to 25920000 seconds (30 days). --- include/dao/indices.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/include/dao/indices.js b/include/dao/indices.js index eebabba19..1bde8a2c0 100644 --- a/include/dao/indices.js +++ b/include/dao/indices.js @@ -329,6 +329,11 @@ module.exports = function IndicesModule(multisite) { collection: 'auth_token', spec: {token: ASC}, options: {unique: true} + }, + { + collection: 'auth_token', + spec: {created: ASC}, + options: {expireAfterSeconds: 25920000} } ]; }; \ No newline at end of file From c287ef62947cb33f9a0dd7a414d321c224b0f2d7 Mon Sep 17 00:00:00 2001 From: andparker Date: Thu, 30 Jul 2015 09:46:57 -0400 Subject: [PATCH 525/790] Moves loading site to on site creation instead of activation. --- include/http/request_handler.js | 7 +++---- .../pencilblue/controllers/actions/admin/sites/new_site.js | 1 + 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/http/request_handler.js b/include/http/request_handler.js index 25772a329..c3bf6617f 100755 --- a/include/http/request_handler.js +++ b/include/http/request_handler.js @@ -141,13 +141,12 @@ module.exports = function RequestHandlerModule(pb) { }; RequestHandler.loadSite = function(site) { - RequestHandler.sites[site.hostname] = { active: site.active, uid: site.uid, displayName: site.displayName, hostname: site.hostname }; + if (!RequestHandler.sites[site.hostname]) { + RequestHandler.sites[site.hostname] = { active: site.active, uid: site.uid, displayName: site.displayName, hostname: site.hostname }; + } }; RequestHandler.activateSite = function(site) { - if (!RequestHandler.sites[site.hostname]) { - RequestHandler.loadSite(site) - } RequestHandler.sites[site.hostname].active = true; }; diff --git a/plugins/pencilblue/controllers/actions/admin/sites/new_site.js b/plugins/pencilblue/controllers/actions/admin/sites/new_site.js index 64f66216c..b9e33902b 100644 --- a/plugins/pencilblue/controllers/actions/admin/sites/new_site.js +++ b/plugins/pencilblue/controllers/actions/admin/sites/new_site.js @@ -65,6 +65,7 @@ module.exports = function NewSiteActionModule(pb) { return; } + pb.RequestHandler.loadSite(site); cb({content: pb.BaseController.apiResponse(pb.BaseController.API_SUCCESS, self.ls.get('SITE_CREATED'), result)}); }); From 9ab063527831814e0ccef810872ee89bd5350375 Mon Sep 17 00:00:00 2001 From: andparker Date: Thu, 30 Jul 2015 10:22:57 -0400 Subject: [PATCH 526/790] Improves delete site's error handling, validation, and response. --- .../service/entities/site_query_service.js | 61 +++++++++++-------- include/service/entities/site_service.js | 13 ++++ .../actions/admin/sites/delete_site.js | 9 +-- plugins/pencilblue/include/routes.js | 3 +- .../angular/admin/sites/manage_sites.html | 2 +- 5 files changed, 55 insertions(+), 33 deletions(-) diff --git a/include/service/entities/site_query_service.js b/include/service/entities/site_query_service.js index e682df66c..bb5b18ae9 100644 --- a/include/service/entities/site_query_service.js +++ b/include/service/entities/site_query_service.js @@ -23,6 +23,7 @@ module.exports = function SiteQueryServiceModule(pb) { var _ = require('lodash'); var util = pb.util; var DAO = pb.DAO; + var SiteService = pb.SiteService; /** * Create an instance of the site query service specific to the given site @@ -158,7 +159,7 @@ module.exports = function SiteQueryServiceModule(pb) { * @param {Function} cb */ SiteQueryService.prototype.getCollections = function (cb) { - this.listCollections({}, function(err, items) { + this.listCollections({ name: { $nin: ["system.indexes", "system.namespaces"] }}, function(err, items) { if(pb.util.isError(err)) { pb.log.error(err); } @@ -174,33 +175,45 @@ module.exports = function SiteQueryServiceModule(pb) { */ SiteQueryService.prototype.deleteSiteSpecificContent = function (collections, siteid, callback) { var self = this; - var tasks = util.getTasks(collections, function(collections, i) { - return function(taskCallback) { - self.delete({site: siteid}, collections[i].name, function(err, numberOfDeletedRecords) { - if(util.isError(err) || !numberOfDeletedRecords) { - taskCallback(null, " "); - } else { - pb.log.silly(numberOfDeletedRecords + " site specific records associated with " + siteid + " were deleted"); - taskCallback(err, numberOfDeletedRecords); - } - }); - }; - }); - async.parallel(tasks, function(err, results) { - if(pb.util.isError(err)) { - pb.log.error(err); - callback(err); + var BaseObjectService = pb.BaseObjectService; + + SiteService.siteExists(siteid, function (err, exists) { + if (util.isError(err)) { + return callback(err); + } + + if (!exists) { + return callback(BaseObjectService.validationError([BaseObjectService.validationFailure("siteid", "Invalid siteid")])); } - self.delete({uid: siteid}, 'site', function(err, result) { - if(util.isError(err)) { - pb.log.error("SiteQueryService: Failed to delete record: ", err.stack); - callback(err); + + var tasks = util.getTasks(collections, function (collections, i) { + return function (taskCallback) { + self.delete({site: siteid}, collections[i].name, function (err, commandResult) { + if (util.isError(err) || !commandResult) { + return taskCallback(err); + } + + var numberOfDeletedRecords = commandResult.result.n; + pb.log.silly(numberOfDeletedRecords + " site specific " + collections[i].name + " records associated with " + siteid + " were deleted"); + taskCallback(null, {collection: collections[i].name, recordsDeleted: numberOfDeletedRecords}); + }); + }; + }); + async.parallel(tasks, function(err, results) { + if (pb.util.isError(err)) { + pb.log.error(err); + return callback(err); } - pb.log.silly("Successfully deleted site from database: " + result); - callback(result); + self.delete({uid: siteid}, 'site', function(err, result) { + if (util.isError(err)) { + pb.log.error("SiteQueryService: Failed to delete site: %s \n%s", siteid, err.stack); + return callback(err); + } + pb.log.silly("Successfully deleted site %s from database: ", siteid); + callback(null, results); + }); }); }); - }; return SiteQueryService; diff --git a/include/service/entities/site_service.js b/include/service/entities/site_service.js index b6a60d51d..e86d8af9b 100644 --- a/include/service/entities/site_service.js +++ b/include/service/entities/site_service.js @@ -184,6 +184,19 @@ module.exports = function SiteServiceModule(pb) { async.parallel(tasks, cb); }; + /** + * Determines if a site exists matching siteUid + * @method siteExists + * @param {String} siteUid - site unique id + * @param {Function} cb - callback function + */ + SiteService.siteExists = function(siteUid, cb) { + var dao = new pb.DAO(); + dao.exists(SITE_COLL, {uid: siteUid}, function (err, exists) { + cb(err, exists); + }); + }; + /** * Run a job to activate a site so that all of its routes are available. * @method activateSite diff --git a/plugins/pencilblue/controllers/actions/admin/sites/delete_site.js b/plugins/pencilblue/controllers/actions/admin/sites/delete_site.js index a3d87b758..e9ab5556c 100644 --- a/plugins/pencilblue/controllers/actions/admin/sites/delete_site.js +++ b/plugins/pencilblue/controllers/actions/admin/sites/delete_site.js @@ -33,16 +33,11 @@ module.exports = function DeleteSiteActionModule(pb) { siteQueryService.getCollections(function(err, allCollections) { siteQueryService.deleteSiteSpecificContent(allCollections, siteid, function(err, result) { if(util.isError(err)) { - cb({ - code: 400, - content: pb.BaseController.apiResponse(pb.BaseController.API_ERROR, self.ls.get('ERROR_REMOVING')) - }); - return + return cb(err); } - cb({content: pb.BaseController.apiResponse(pb.BaseController.API_ERROR, self.ls.get('REMOVE_SUCCESSFUL'), result)}); + cb({content: pb.BaseController.apiResponse(pb.BaseController.SUCCESS, self.ls.get('REMOVE_SUCCESSFUL'), result)}); }); }); - }; //exports diff --git a/plugins/pencilblue/include/routes.js b/plugins/pencilblue/include/routes.js index 4e80101b9..2c525595a 100644 --- a/plugins/pencilblue/include/routes.js +++ b/plugins/pencilblue/include/routes.js @@ -1140,8 +1140,9 @@ module.exports = function Routes(pb){ controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'admin', 'sites', 'edit_site.js') }, { - method: 'post', + method: 'delete', path: "/actions/admin/sites/delete/:siteid", + content_type: 'application/json', access_level: pb.SecurityService.ACCESS_ADMINISTRATOR, auth_required: true, inactive_site_access: true, diff --git a/plugins/pencilblue/templates/angular/admin/sites/manage_sites.html b/plugins/pencilblue/templates/angular/admin/sites/manage_sites.html index 6e8a50c16..711ed2443 100644 --- a/plugins/pencilblue/templates/angular/admin/sites/manage_sites.html +++ b/plugins/pencilblue/templates/angular/admin/sites/manage_sites.html @@ -35,7 +35,7 @@ }; $scope.deleteSite = function(site) { - $http.post('/actions/admin/sites/delete/' + site.uid) + $http.delete('/actions/admin/sites/delete/' + site.uid) .success(function(result) { $scope.successMessage = result.message; $scope.saving = false; From 0317fb7269ae972da3d57848220af584eb8e0b05 Mon Sep 17 00:00:00 2001 From: iandtrapp Date: Thu, 30 Jul 2015 10:36:18 -0400 Subject: [PATCH 527/790] Readability fixes --- include/service/entities/plugin_service.js | 4 +++- include/service/entities/plugin_setting_service.js | 4 +++- include/system/settings.js | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/include/service/entities/plugin_service.js b/include/service/entities/plugin_service.js index 796ab3c44..d3cf04a68 100755 --- a/include/service/entities/plugin_service.js +++ b/include/service/entities/plugin_service.js @@ -503,7 +503,9 @@ module.exports = function PluginServiceModule(pb) { } //always add DB - services.push(new pb.DBEntityService({objType: objType, keyField: 'settings', valueField: 'plugin_uid', site: site})); + options.keyField = 'settings'; + options.valueField = 'plugin_uid'; + services.push(new pb.DBEntityService(options)); return new pb.SimpleLayeredService(services, serviceName); }; diff --git a/include/service/entities/plugin_setting_service.js b/include/service/entities/plugin_setting_service.js index 3a3fe77de..05be0c487 100644 --- a/include/service/entities/plugin_setting_service.js +++ b/include/service/entities/plugin_setting_service.js @@ -498,7 +498,9 @@ module.exports = function PluginSettingServiceModule(pb) { } //always add DB - services.push(new pb.DBEntityService({objType: objType, keyField: 'settings', valueField: 'plugin_uid', site: site, onlyThisSite: onlyThisSite})); + options.keyField = 'settings'; + options.valueField = 'plugin_uid'; + services.push(new pb.DBEntityService(options)); return new pb.SimpleLayeredService(services, serviceName); }; diff --git a/include/system/settings.js b/include/system/settings.js index 27d78f5c6..7ec8328e1 100755 --- a/include/system/settings.js +++ b/include/system/settings.js @@ -87,7 +87,7 @@ module.exports = function SettingsModule(pb) { } //always add db service - services.push(new pb.DBEntityService({objType: objType, valueField: valueField, keyField: keyField, site: site, onlyThisSite: onlyThisSite})); + services.push(new pb.DBEntityService(options)); return new pb.SimpleLayeredService(services, 'SettingService' + count++); }; From 43c97d51f24c60c77f09e1654f0392ee2ec61410 Mon Sep 17 00:00:00 2001 From: Evan Adams Date: Thu, 30 Jul 2015 10:37:56 -0400 Subject: [PATCH 528/790] Make hostname available --- controllers/base_controller.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/controllers/base_controller.js b/controllers/base_controller.js index a120dc435..26ee48c16 100755 --- a/controllers/base_controller.js +++ b/controllers/base_controller.js @@ -124,6 +124,7 @@ module.exports = function BaseControllerModule(pb) { this.siteObj = props.siteObj; this.site = props.site; this.siteName = props.siteName; + this.hostname = SiteService.getHostWithProtocol(self.siteObj.hostname) || self.ts.siteRoot; var tsOpts = { ls: this.localizationService, @@ -155,7 +156,7 @@ module.exports = function BaseControllerModule(pb) { }); }); this.ts.registerLocal('site_root', function(flag, cb) { - cb(null, SiteService.getHostWithProtocol(self.siteObj.hostname) || self.ts.siteRoot); + cb(null, self.hostname); }); this.ts.registerLocal('site_name', function(flag, cb) { cb(null, self.siteName); From 815adc5d8fd899d6982283bfc16c0b4605876562 Mon Sep 17 00:00:00 2001 From: iandtrapp Date: Thu, 30 Jul 2015 10:56:02 -0400 Subject: [PATCH 529/790] Plugin bug fixed --- include/service/entities/plugin_service.js | 4 ++-- include/service/entities/plugin_setting_service.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/include/service/entities/plugin_service.js b/include/service/entities/plugin_service.js index d3cf04a68..beba72d5d 100755 --- a/include/service/entities/plugin_service.js +++ b/include/service/entities/plugin_service.js @@ -503,8 +503,8 @@ module.exports = function PluginServiceModule(pb) { } //always add DB - options.keyField = 'settings'; - options.valueField = 'plugin_uid'; + options.keyField = 'plugin_uid'; + options.valueField = 'settings'; services.push(new pb.DBEntityService(options)); return new pb.SimpleLayeredService(services, serviceName); }; diff --git a/include/service/entities/plugin_setting_service.js b/include/service/entities/plugin_setting_service.js index 05be0c487..a62436d8a 100644 --- a/include/service/entities/plugin_setting_service.js +++ b/include/service/entities/plugin_setting_service.js @@ -498,8 +498,8 @@ module.exports = function PluginSettingServiceModule(pb) { } //always add DB - options.keyField = 'settings'; - options.valueField = 'plugin_uid'; + options.keyField = 'plugin_uid'; + options.valueField = 'settings'; services.push(new pb.DBEntityService(options)); return new pb.SimpleLayeredService(services, serviceName); }; From c315c5eab605e320a18754de4dedf2e324445379 Mon Sep 17 00:00:00 2001 From: iandtrapp Date: Thu, 30 Jul 2015 10:59:21 -0400 Subject: [PATCH 530/790] Added documentation --- include/service/db_entity_service.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/include/service/db_entity_service.js b/include/service/db_entity_service.js index 6962daeec..5b78cfa42 100755 --- a/include/service/db_entity_service.js +++ b/include/service/db_entity_service.js @@ -24,12 +24,14 @@ module.exports = function DbEntityServiceModule(pb) { * Database storage service * * @module Services - * @submodule Storage - * @class DbEntityService + * @class DBEntityService * @constructor - * @param {String} objType - * @param {String} valueField - * @param {String} keyField + * @param {Object} options + * @param {String} options.objType + * @param {String} options.keyField + * @param {String} [options.valueField=null] + * @param {String} [options.site=GLOBAL_SITE] + * @param {String} [options.onlyThisSite=false] */ function DbEntityService(options){ this.type = 'DB'; From 1b89795620b35f272cb7479dca6351f2f0b6050c Mon Sep 17 00:00:00 2001 From: iandtrapp Date: Thu, 30 Jul 2015 11:14:08 -0400 Subject: [PATCH 531/790] Fixed a single letter --- include/service/db_entity_service.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/service/db_entity_service.js b/include/service/db_entity_service.js index 5b78cfa42..3f53cb7f2 100755 --- a/include/service/db_entity_service.js +++ b/include/service/db_entity_service.js @@ -24,7 +24,7 @@ module.exports = function DbEntityServiceModule(pb) { * Database storage service * * @module Services - * @class DBEntityService + * @class DbEntityService * @constructor * @param {Object} options * @param {String} options.objType From 75c264acb5e618d98ae285541da3b09e0b62693b Mon Sep 17 00:00:00 2001 From: iandtrapp Date: Thu, 30 Jul 2015 11:15:54 -0400 Subject: [PATCH 532/790] Added documentation @submodule --- include/service/db_entity_service.js | 1 + 1 file changed, 1 insertion(+) diff --git a/include/service/db_entity_service.js b/include/service/db_entity_service.js index 3f53cb7f2..ddfeb765d 100755 --- a/include/service/db_entity_service.js +++ b/include/service/db_entity_service.js @@ -24,6 +24,7 @@ module.exports = function DbEntityServiceModule(pb) { * Database storage service * * @module Services + * @submodule Storage * @class DbEntityService * @constructor * @param {Object} options From 992b10f740ac20ce9699443f5bda74d0b13c7f64 Mon Sep 17 00:00:00 2001 From: iandtrapp Date: Thu, 30 Jul 2015 14:26:37 -0400 Subject: [PATCH 533/790] SiteQueryService Refator --- controllers/admin/base_admin_controller.js | 2 +- include/security/authentication/index.js | 2 +- include/service/base_object_service.js | 2 +- include/service/entities/article_service.js | 2 +- include/service/entities/custom_object_service.js | 2 +- include/service/entities/media_service.js | 2 +- include/service/entities/section_service.js | 2 +- include/service/entities/site_query_service.js | 15 ++++++++++----- include/service/entities/url_service.js | 2 +- include/service/entities/user_service.js | 4 ++-- .../actions/admin/users/delete_unverified_user.js | 2 +- .../actions/admin/users/verify_user.js | 2 +- .../controllers/actions/forgot_password.js | 2 +- plugins/pencilblue/controllers/actions/setup.js | 2 +- .../actions/user/manage_account/profile.js | 2 +- .../actions/user/resend_verification.js | 2 +- .../controllers/actions/user/reset_password.js | 2 +- .../controllers/actions/user/sign_up.js | 4 ++-- .../controllers/actions/user/verify_email.js | 2 +- .../controllers/api/comments/new_comment.js | 2 +- .../pencilblue/controllers/api/content/search.js | 2 +- plugins/pencilblue/controllers/index.js | 2 +- .../controllers/user/change_password.js | 2 +- plugins/portfolio/controllers/blog.js | 2 +- plugins/portfolio/controllers/index.js | 2 +- plugins/wp_import/services/wp_xml_parse.js | 2 +- 26 files changed, 37 insertions(+), 32 deletions(-) diff --git a/controllers/admin/base_admin_controller.js b/controllers/admin/base_admin_controller.js index 35968009f..ce57a5506 100644 --- a/controllers/admin/base_admin_controller.js +++ b/controllers/admin/base_admin_controller.js @@ -51,7 +51,7 @@ module.exports = function BaseAdminControllerModule(pb) { * @param {Function} cb */ BaseAdminController.prototype.extendedInit = function(cb) { - this.siteQueryService = new pb.SiteQueryService(this.site, true); + this.siteQueryService = new pb.SiteQueryService({site: this.site, onlyThisSite: true}); this.settings = pb.SettingServiceFactory.getServiceBySite(this.site, true); cb(); }; diff --git a/include/security/authentication/index.js b/include/security/authentication/index.js index a625fe0a0..28364ccfd 100755 --- a/include/security/authentication/index.js +++ b/include/security/authentication/index.js @@ -63,7 +63,7 @@ module.exports = function AuthenticationModule(pb) { var dao; if (credentials.hasOwnProperty('site')) { - dao = new pb.SiteQueryService(credentials.site, false); + dao = new pb.SiteQueryService({site: credentials.site, onlyThisSite: false}); } else { dao = new pb.DAO(); } diff --git a/include/service/base_object_service.js b/include/service/base_object_service.js index ffe68c5ab..e0fce7b42 100644 --- a/include/service/base_object_service.js +++ b/include/service/base_object_service.js @@ -60,7 +60,7 @@ module.exports = function(pb) { * @property dao * @type {DAO} */ - this.dao = new pb.SiteQueryService(context.site, context.onlyThisSite) + this.dao = new pb.SiteQueryService({site: context.site, onlyThisSite: context.onlyThisSite}) } /** diff --git a/include/service/entities/article_service.js b/include/service/entities/article_service.js index 3cba9b5ef..748afa584 100755 --- a/include/service/entities/article_service.js +++ b/include/service/entities/article_service.js @@ -36,7 +36,7 @@ module.exports = function ArticleServiceModule(pb) { function ArticleService(siteUid, onlyThisSite){ this.object_type = ARTICLE_TYPE; this.site = pb.SiteService.getCurrentSite(siteUid); - this.siteQueryService = new pb.SiteQueryService(this.site, onlyThisSite); + this.siteQueryService = new pb.SiteQueryService({site: this.site, onlyThisSite: onlyThisSite}); } /** diff --git a/include/service/entities/custom_object_service.js b/include/service/entities/custom_object_service.js index bfa8f29e7..7aa3a5e34 100644 --- a/include/service/entities/custom_object_service.js +++ b/include/service/entities/custom_object_service.js @@ -33,7 +33,7 @@ module.exports = function CustomObjectServiceModule(pb) { this.typesNametoId = {}; this.site = pb.SiteService.getCurrentSite(siteUid); - this.siteQueryService = new pb.SiteQueryService(this.site, onlyThisSite); + this.siteQueryService = new pb.SiteQueryService({site: this.site, onlyThisSite: onlyThisSite}); } //statics diff --git a/include/service/entities/media_service.js b/include/service/entities/media_service.js index 14a220f97..7f46d38d0 100755 --- a/include/service/entities/media_service.js +++ b/include/service/entities/media_service.js @@ -38,7 +38,7 @@ module.exports = function MediaServiceModule(pb) { */ function MediaService(provider, site, onlyThisSite) { this.site = pb.SiteService.getCurrentSite(site); - this.siteQueryService = new pb.SiteQueryService(this.site, onlyThisSite); + this.siteQueryService = new pb.SiteQueryService({site: this.site, onlyThisSite: onlyThisSite}); if (util.isNullOrUndefined(provider)) { provider = MediaService.loadMediaProvider(); } diff --git a/include/service/entities/section_service.js b/include/service/entities/section_service.js index f2972cc8a..19cf20e5e 100755 --- a/include/service/entities/section_service.js +++ b/include/service/entities/section_service.js @@ -32,7 +32,7 @@ module.exports = function SectionServiceModule(pb) { function SectionService(site, onlyThisSite) { this.site = pb.SiteService.getCurrentSite(site); this.settings = pb.SettingServiceFactory.getServiceBySite(this.site, onlyThisSite); - this.siteQueryService = new pb.SiteQueryService(this.site, onlyThisSite); + this.siteQueryService = new pb.SiteQueryService({site: this.site, onlyThisSite: onlyThisSite}); } /** diff --git a/include/service/entities/site_query_service.js b/include/service/entities/site_query_service.js index bb5b18ae9..7b347b79f 100644 --- a/include/service/entities/site_query_service.js +++ b/include/service/entities/site_query_service.js @@ -28,13 +28,18 @@ module.exports = function SiteQueryServiceModule(pb) { /** * Create an instance of the site query service specific to the given site * - * @param {String} siteUId UID of site, should already be sanitized by SiteService - * @param {Boolean} onlyThisSite for q, return results specific to this site instead of also looking in global + * @module Services + * @class SiteQueryService * @constructor + * @param {Object} options + * @param {String} [options.site=GLOBAL_SITE] + * @param {String} [options.onlyThisSite=false] */ - function SiteQueryService(siteUId, onlyThisSite) { - this.siteUId = pb.SiteService.getCurrentSite(siteUId); - this.onlyThisSite = onlyThisSite; + function SiteQueryService(options) { + if(options) { + this.siteUId = options.site || GLOBAL_SITE; + this.onlyThisSite = options.onlyThisSite || false; + } DAO.call(this); } diff --git a/include/service/entities/url_service.js b/include/service/entities/url_service.js index 2be5f23a7..aa8fa32c1 100755 --- a/include/service/entities/url_service.js +++ b/include/service/entities/url_service.js @@ -34,7 +34,7 @@ module.exports = function UrlServiceModule(pb) { function UrlService(site, onlyThisSite) { this.site = pb.SiteService.getCurrentSite(site); this.onlyThisSite = onlyThisSite; - this.siteQueryService = new pb.SiteQueryService(this.site, this.onlyThisSite); + this.siteQueryService = new pb.SiteQueryService({site: this.site, onlyThisSite: this.onlyThisSite}); } //dependencies diff --git a/include/service/entities/user_service.js b/include/service/entities/user_service.js index a09659f7e..b174096f8 100755 --- a/include/service/entities/user_service.js +++ b/include/service/entities/user_service.js @@ -126,7 +126,7 @@ module.exports = function(pb) { }, where: pb.DAO.getIdInWhere(Object.keys(authorIds)) }; - var dao = new pb.SiteQueryService(this.context.site); + var dao = new pb.SiteQueryService({site: this.context.site}); dao.q('user', opts, function(err, authors) { if (util.isError(err)) { return cb(err); @@ -372,7 +372,7 @@ module.exports = function(pb) { return where; }; - var dao = (pb.SiteService.isGlobal(self.context.site)) ? new pb.DAO() : new pb.SiteQueryService(self.context.site, false); + var dao = (pb.SiteService.isGlobal(self.context.site)) ? new pb.DAO() : new pb.SiteQueryService({site: self.context.site, onlyThisSite: false}); var tasks = { verified_username: function(callback) { var expStr = util.escapeRegExp(username) + '$'; diff --git a/plugins/pencilblue/controllers/actions/admin/users/delete_unverified_user.js b/plugins/pencilblue/controllers/actions/admin/users/delete_unverified_user.js index dd7d2fbe6..2ae6db869 100644 --- a/plugins/pencilblue/controllers/actions/admin/users/delete_unverified_user.js +++ b/plugins/pencilblue/controllers/actions/admin/users/delete_unverified_user.js @@ -40,7 +40,7 @@ module.exports = function(pb) { } //ensure existence - var dao = new pb.SiteQueryService(self.site, true); + var dao = new pb.SiteQueryService({site: self.site, onlyThisSite: true}); dao.loadById(vars.id, 'unverified_user', function(err, user) { if(user === null) { cb({ diff --git a/plugins/pencilblue/controllers/actions/admin/users/verify_user.js b/plugins/pencilblue/controllers/actions/admin/users/verify_user.js index 91639cffc..f48f57782 100644 --- a/plugins/pencilblue/controllers/actions/admin/users/verify_user.js +++ b/plugins/pencilblue/controllers/actions/admin/users/verify_user.js @@ -39,7 +39,7 @@ module.exports = function VerifyUserModule(pb) { } //ensure existence - var dao = new pb.SiteQueryService(self.site, true); + var dao = new pb.SiteQueryService({site: self.site, onlyThisSite: true}); dao.loadById(vars.id, 'unverified_user', function(err, unverifiedUser) { if(unverifiedUser === null) { return cb({ diff --git a/plugins/pencilblue/controllers/actions/forgot_password.js b/plugins/pencilblue/controllers/actions/forgot_password.js index 89a68d9c4..54c264116 100755 --- a/plugins/pencilblue/controllers/actions/forgot_password.js +++ b/plugins/pencilblue/controllers/actions/forgot_password.js @@ -57,7 +57,7 @@ module.exports = function ForgotPasswordControllerModule(pb) { }; //search for user - var dao = new pb.SiteQueryService(self.site, true); + var dao = new pb.SiteQueryService({site: self.site, onlyThisSite: true}); dao.loadByValues(query, 'user', function(err, user) { if(util.isError(err) || user === null) { return self.formError(self.ls.get('NOT_REGISTERED'), returnURL, cb); diff --git a/plugins/pencilblue/controllers/actions/setup.js b/plugins/pencilblue/controllers/actions/setup.js index 33b5ac0c7..31a985f96 100755 --- a/plugins/pencilblue/controllers/actions/setup.js +++ b/plugins/pencilblue/controllers/actions/setup.js @@ -120,7 +120,7 @@ module.exports = function SetupActionControllerModule(pb) { function(callback) { var userDocument = pb.DocumentCreator.create('user', post); - var dao = new pb.SiteQueryService(pb.SiteService.GLOBAL_SITE); + var dao = new pb.SiteQueryService({site: pb.SiteService.GLOBAL_SITE}); dao.save(userDocument, callback); }, function(callback) { diff --git a/plugins/pencilblue/controllers/actions/user/manage_account/profile.js b/plugins/pencilblue/controllers/actions/user/manage_account/profile.js index 02d5dabe3..0d628982e 100755 --- a/plugins/pencilblue/controllers/actions/user/manage_account/profile.js +++ b/plugins/pencilblue/controllers/actions/user/manage_account/profile.js @@ -43,7 +43,7 @@ module.exports = function ProfileModule(pb) { post.last_name = BaseController.sanitize(post.last_name); post.photo = BaseController.sanitize(post.photo); - var dao = new pb.SiteQueryService(self.site, true); + var dao = new pb.SiteQueryService({site: self.site, onlyThisSite: true}); dao.loadById(self.session.authentication.user_id, 'user', function(err, user) { if(util.isError(err) || user === null) { self.formError(self.ls.get('ERROR_SAVING'), '/user/manage_account', cb); diff --git a/plugins/pencilblue/controllers/actions/user/resend_verification.js b/plugins/pencilblue/controllers/actions/user/resend_verification.js index e651c393b..dba5356b6 100755 --- a/plugins/pencilblue/controllers/actions/user/resend_verification.js +++ b/plugins/pencilblue/controllers/actions/user/resend_verification.js @@ -29,7 +29,7 @@ module.exports = function ResendVerificationModule(pb) { ResendVerification.prototype.render = function(cb) { var self = this; - var dao = new pb.SiteQueryService(self.site, true); + var dao = new pb.SiteQueryService({site: self.site, onlyThisSite: true}); dao.loadByValue('email', post.email, 'user', function(err, user) { if(util.isError(err)) { return cb(err); diff --git a/plugins/pencilblue/controllers/actions/user/reset_password.js b/plugins/pencilblue/controllers/actions/user/reset_password.js index 5bb817371..133203651 100755 --- a/plugins/pencilblue/controllers/actions/user/reset_password.js +++ b/plugins/pencilblue/controllers/actions/user/reset_password.js @@ -35,7 +35,7 @@ module.exports = function ResetPasswordModule(pb) { return; } - var dao = new pb.SiteQueryService(self.site, true); + var dao = new pb.SiteQueryService({site: self.site, onlyThisSite: true}); dao.loadByValue('email', get.email, 'user', function(err, user) { if(user === null) { self.formError(self.ls.get('INVALID_VERIFICATION'), '/user/login', cb); diff --git a/plugins/pencilblue/controllers/actions/user/sign_up.js b/plugins/pencilblue/controllers/actions/user/sign_up.js index 608f0a8b5..9b6988214 100755 --- a/plugins/pencilblue/controllers/actions/user/sign_up.js +++ b/plugins/pencilblue/controllers/actions/user/sign_up.js @@ -98,7 +98,7 @@ module.exports = function SignUpModule(pb) { content: pb.BaseController.apiResponse(pb.BaseController.API_ERROR, errMsg) }); } - var dao = new pb.SiteQueryService(self.site); + var dao = new pb.SiteQueryService({site: self.site}); dao.save(user, function(err, data) { // Handle errors if(util.isError(err)) { @@ -128,7 +128,7 @@ module.exports = function SignUpModule(pb) { SignUp.prototype.validateUniques = function(user, cb) { - var dao = new pb.SiteQueryService(this.site); + var dao = new pb.SiteQueryService({site: this.site}); var tasks = { verified_username: function(callback) { dao.count('user', {username: user.username}, callback); diff --git a/plugins/pencilblue/controllers/actions/user/verify_email.js b/plugins/pencilblue/controllers/actions/user/verify_email.js index 89500e37d..ef449230f 100755 --- a/plugins/pencilblue/controllers/actions/user/verify_email.js +++ b/plugins/pencilblue/controllers/actions/user/verify_email.js @@ -35,7 +35,7 @@ module.exports = function VerifyEmailModule(pb) { return; } - var dao = new pb.SiteQueryService(self.site, true); + var dao = new pb.SiteQueryService({site: self.site, onlyThisSite: true}); dao.count('user', {email: get.email}, function(err, count) { if(count > 0) { self.formError(self.ls.get('USER_VERIFIED'), '/user/login', cb); diff --git a/plugins/pencilblue/controllers/api/comments/new_comment.js b/plugins/pencilblue/controllers/api/comments/new_comment.js index 239356e7d..a23e5f708 100755 --- a/plugins/pencilblue/controllers/api/comments/new_comment.js +++ b/plugins/pencilblue/controllers/api/comments/new_comment.js @@ -30,7 +30,7 @@ module.exports = function NewCommentModule(pb) { NewComment.prototype.init = function (props, cb) { var self = this; pb.BaseController.prototype.init.call(self, props, function () { - self.siteQueryService = new pb.SiteQueryService(self.site, true); + self.siteQueryService = new pb.SiteQueryService({site: self.site, onlyThisSite: true}); cb(); }); }; diff --git a/plugins/pencilblue/controllers/api/content/search.js b/plugins/pencilblue/controllers/api/content/search.js index 7cc3dc1f4..ac8df9586 100755 --- a/plugins/pencilblue/controllers/api/content/search.js +++ b/plugins/pencilblue/controllers/api/content/search.js @@ -66,7 +66,7 @@ module.exports = function(pb) { limit: MAX_RESULTS }; - var queryService = new pb.SiteQueryService(this.site, true); + var queryService = new pb.SiteQueryService({site: this.site, onlyThisSite: true}); queryService.q(type, opts, function(err, items) { if (util.isError(err)) { var content = BaseController.apiResponse(BaseController.API_FAILURE, '', ''); diff --git a/plugins/pencilblue/controllers/index.js b/plugins/pencilblue/controllers/index.js index e751d4e20..acfcec142 100755 --- a/plugins/pencilblue/controllers/index.js +++ b/plugins/pencilblue/controllers/index.js @@ -41,7 +41,7 @@ module.exports = function IndexModule(pb) { var self = this; pb.BaseController.prototype.init.call(self, props, function () { - self.siteQueryService = new pb.SiteQueryService(self.site, true); + self.siteQueryService = new pb.SiteQueryService({site: self.site, onlyThisSite: true}); cb(); }); }; diff --git a/plugins/pencilblue/controllers/user/change_password.js b/plugins/pencilblue/controllers/user/change_password.js index 789a3c8e0..7d7e6de7b 100755 --- a/plugins/pencilblue/controllers/user/change_password.js +++ b/plugins/pencilblue/controllers/user/change_password.js @@ -38,7 +38,7 @@ module.exports = function ChangePasswordFormControllerModule(pb) { var self = this; //retrieve user - var dao = new pb.SiteQueryService(self.site, true); + var dao = new pb.SiteQueryService({site: self.site, onlyThisSite: true}); dao.loadById(self.session.authentication.user_id, 'user', function(err, user) { if(util.isError(err) || user === null) { self.redirect('/', cb); diff --git a/plugins/portfolio/controllers/blog.js b/plugins/portfolio/controllers/blog.js index 7b458d121..5097fecfa 100755 --- a/plugins/portfolio/controllers/blog.js +++ b/plugins/portfolio/controllers/blog.js @@ -40,7 +40,7 @@ module.exports = function BlogModule(pb) { var self = this; pb.BaseController.prototype.init.call(self, props, function () { self.navService = new pb.SectionService(self.site); - self.siteQueryService = new pb.SiteQueryService(self.site, true); + self.siteQueryService = new pb.SiteQueryService({site: self.site, onlyThisSite: true}); cb(); }); }; diff --git a/plugins/portfolio/controllers/index.js b/plugins/portfolio/controllers/index.js index c17a6cfc8..995c471e8 100755 --- a/plugins/portfolio/controllers/index.js +++ b/plugins/portfolio/controllers/index.js @@ -38,7 +38,7 @@ module.exports = function IndexModule(pb) { Index.prototype.init = function (props, cb) { var self = this; pb.BaseController.prototype.init.call(self, props, function () { - self.siteQueryService = new pb.SiteQueryService(self.site); + self.siteQueryService = new pb.SiteQueryService({site: self.site}); }); }; diff --git a/plugins/wp_import/services/wp_xml_parse.js b/plugins/wp_import/services/wp_xml_parse.js index 923f8c68f..8c568d39c 100644 --- a/plugins/wp_import/services/wp_xml_parse.js +++ b/plugins/wp_import/services/wp_xml_parse.js @@ -34,7 +34,7 @@ module.exports = function WPXMLParseServiceModule(pb) { */ function WPXMLParseService(site) { this.site = pb.SiteService.getCurrentSite(site); - this.siteQueryService = new pb.SiteQueryService(this.site, true); + this.siteQueryService = new pb.SiteQueryService({site: this.site, onlyThisSite: true}); } /** From b6c846afb821e78c196175de84607b56e9d93cc8 Mon Sep 17 00:00:00 2001 From: iandtrapp Date: Thu, 30 Jul 2015 14:38:12 -0400 Subject: [PATCH 534/790] Email Service Refactor --- include/email.js | 11 +++++++---- include/service/entities/user_service.js | 4 ++-- .../controllers/admin/site_settings/email.js | 2 +- .../api/admin/site_settings/email/send_test.js | 2 +- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/include/email.js b/include/email.js index 05f23556f..3d9626c87 100755 --- a/include/email.js +++ b/include/email.js @@ -27,11 +27,14 @@ module.exports = function EmailServiceModule(pb) { * @module Services * @class EmailService * @constructor + * @param {String} [options.site=GLOBAL_SITE] + * @param {String} [options.onlyThisSite=false] */ - function EmailService(siteUid, onlyThisSite) { - - this.site = pb.SiteService.getCurrentSite(siteUid); - this.onlyThisSite = onlyThisSite; + function EmailService(options) { + if (options) { + this.site = pb.SiteService.getCurrentSite(options.site) || GLOBAL_SITE; + this.onlyThisSite = options.onlyThisSite || false; + } } /** diff --git a/include/service/entities/user_service.js b/include/service/entities/user_service.js index a09659f7e..a531d8c97 100755 --- a/include/service/entities/user_service.js +++ b/include/service/entities/user_service.js @@ -262,7 +262,7 @@ module.exports = function(pb) { return cb(err, null); } // We need to see if email settings have been saved with verification content - var emailService = new pb.EmailService(self.context.site); + var emailService = new pb.EmailService({site: self.context.site}); emailService.getSettings(function (err, emailSettings) { if (pb.util.isError(err)) { pb.log.error("UserService: Failed to load email settings. ERROR[%s]", err.stack); @@ -322,7 +322,7 @@ module.exports = function(pb) { 'last_name': user.last_name } }; - var emailService = new pb.EmailService(self.context.site); + var emailService = new pb.EmailService({site: self.context.site}); emailService.sendFromTemplate(options, cb); }); }; diff --git a/plugins/pencilblue/controllers/admin/site_settings/email.js b/plugins/pencilblue/controllers/admin/site_settings/email.js index 3ab6b341e..a7cc5f8fb 100755 --- a/plugins/pencilblue/controllers/admin/site_settings/email.js +++ b/plugins/pencilblue/controllers/admin/site_settings/email.js @@ -52,7 +52,7 @@ module.exports = function(pb) { } ]; - var emailService = new pb.EmailService(this.site); + var emailService = new pb.EmailService({site: this.site}); emailService.getSettings(function(err, emailSettings) { var angularObjects = pb.ClientJs.getAngularObjects({ navigation: pb.AdminNavigation.get(self.session, ['settings', 'site_settings'], self.ls, self.site), diff --git a/plugins/pencilblue/controllers/api/admin/site_settings/email/send_test.js b/plugins/pencilblue/controllers/api/admin/site_settings/email/send_test.js index 767036149..c212a3784 100644 --- a/plugins/pencilblue/controllers/api/admin/site_settings/email/send_test.js +++ b/plugins/pencilblue/controllers/api/admin/site_settings/email/send_test.js @@ -43,7 +43,7 @@ module.exports = function(pb) { subject: 'Test email from PencilBlue', layout: 'This is a successful test email from the PencilBlue system.' }; - var emailService = new pb.EmailService(this.site); + var emailService = new pb.EmailService({site: this.site}); emailService.sendFromLayout(options, function(err, response) { if(err) { return cb({ From 71adc7d5bd02fbe543b555f2b758bcbefdd6685b Mon Sep 17 00:00:00 2001 From: iandtrapp Date: Thu, 30 Jul 2015 15:10:34 -0400 Subject: [PATCH 535/790] Doc fixes --- include/service/entities/site_query_service.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/service/entities/site_query_service.js b/include/service/entities/site_query_service.js index 7b347b79f..a06a41fe0 100644 --- a/include/service/entities/site_query_service.js +++ b/include/service/entities/site_query_service.js @@ -32,6 +32,8 @@ module.exports = function SiteQueryServiceModule(pb) { * @class SiteQueryService * @constructor * @param {Object} options + * @param {String} siteUId UID of site, should already be sanitized by SiteService + * @param {Boolean} onlyThisSite for q, return results specific to this site instead of also looking in global * @param {String} [options.site=GLOBAL_SITE] * @param {String} [options.onlyThisSite=false] */ From 3391b31ad389a3ddcba1afa67200e1c5f9fbd791 Mon Sep 17 00:00:00 2001 From: iandtrapp Date: Thu, 30 Jul 2015 15:11:13 -0400 Subject: [PATCH 536/790] Doc fixes --- include/service/entities/site_query_service.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/service/entities/site_query_service.js b/include/service/entities/site_query_service.js index a06a41fe0..c6791c2a9 100644 --- a/include/service/entities/site_query_service.js +++ b/include/service/entities/site_query_service.js @@ -33,8 +33,8 @@ module.exports = function SiteQueryServiceModule(pb) { * @constructor * @param {Object} options * @param {String} siteUId UID of site, should already be sanitized by SiteService - * @param {Boolean} onlyThisSite for q, return results specific to this site instead of also looking in global * @param {String} [options.site=GLOBAL_SITE] + * @param {Boolean} onlyThisSite for q, return results specific to this site instead of also looking in global * @param {String} [options.onlyThisSite=false] */ function SiteQueryService(options) { From 01150eb9b4b7d29994807f85f1296a40b0854715 Mon Sep 17 00:00:00 2001 From: iandtrapp Date: Thu, 30 Jul 2015 15:24:15 -0400 Subject: [PATCH 537/790] Actual doc fixes --- include/service/entities/site_query_service.js | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/include/service/entities/site_query_service.js b/include/service/entities/site_query_service.js index c6791c2a9..415134f38 100644 --- a/include/service/entities/site_query_service.js +++ b/include/service/entities/site_query_service.js @@ -32,10 +32,8 @@ module.exports = function SiteQueryServiceModule(pb) { * @class SiteQueryService * @constructor * @param {Object} options - * @param {String} siteUId UID of site, should already be sanitized by SiteService - * @param {String} [options.site=GLOBAL_SITE] - * @param {Boolean} onlyThisSite for q, return results specific to this site instead of also looking in global - * @param {String} [options.onlyThisSite=false] + * @param {String} [options.site=GLOBAL_SITE] UID of site, should already be sanitized by SiteService + * @param {Boolean} [options.onlyThisSite=false] onlyThisSite for q, return results specific to this site instead of also looking in global */ function SiteQueryService(options) { if(options) { From 74c05d5ae51982d227bf9d70149d4b181ea59d10 Mon Sep 17 00:00:00 2001 From: andparker Date: Fri, 31 Jul 2015 09:57:33 -0400 Subject: [PATCH 538/790] Calls a previously uncalled callback, which caused an infinite loop. --- plugins/portfolio/controllers/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/portfolio/controllers/index.js b/plugins/portfolio/controllers/index.js index c17a6cfc8..eacad25f4 100755 --- a/plugins/portfolio/controllers/index.js +++ b/plugins/portfolio/controllers/index.js @@ -39,6 +39,7 @@ module.exports = function IndexModule(pb) { var self = this; pb.BaseController.prototype.init.call(self, props, function () { self.siteQueryService = new pb.SiteQueryService(self.site); + cb(); }); }; From a19fc4a1435a1ee98a69e1ca06f5d3983192e8d1 Mon Sep 17 00:00:00 2001 From: andparker Date: Fri, 31 Jul 2015 10:36:18 -0400 Subject: [PATCH 539/790] Removes unnecessary method override. --- controllers/admin/base_admin_controller.js | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/controllers/admin/base_admin_controller.js b/controllers/admin/base_admin_controller.js index 35968009f..e5774800c 100644 --- a/controllers/admin/base_admin_controller.js +++ b/controllers/admin/base_admin_controller.js @@ -56,19 +56,6 @@ module.exports = function BaseAdminControllerModule(pb) { cb(); }; - /** - * Retrieves a context object that contains the necessary information for - * service prototypes - * @method getServiceContext - * @return {Object} the service context with onlyThisSite merged in - */ - BaseAdminController.prototype.getServiceContext = function(){ - var context = BaseAdminController.super_.prototype.getServiceContext.apply(this); - context.onlyThisSite = true; - return context; - }; - - /** * Centralized place to obtain the pills to be displayed on top of the admin controller * From 4459b1eb5feca67c7bf7f89f9ba3fffa250ed87f Mon Sep 17 00:00:00 2001 From: btidwell Date: Fri, 31 Jul 2015 11:36:16 -0400 Subject: [PATCH 540/790] add documentation and UserService to TokenAuthentication.prototype.authenticate --- include/security/authentication/index.js | 13 ++++++++----- .../controllers/actions/admin/sites/token_login.js | 3 ++- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/include/security/authentication/index.js b/include/security/authentication/index.js index 5f44b970d..95cc4558e 100755 --- a/include/security/authentication/index.js +++ b/include/security/authentication/index.js @@ -101,9 +101,14 @@ module.exports = function AuthenticationModule(pb) { * * @class TokenAuthentication * @constructor + * @param {Object} options + * @param {String} options.site - site uid + * @param {String} options.user - user id */ function TokenAuthentication(options) { this.options = options; + this.tokenService = new pb.TokenService(options); + this.userService = new pb.UserService(options); } /** @@ -112,8 +117,8 @@ module.exports = function AuthenticationModule(pb) { * @param {Function} cb */ TokenAuthentication.prototype.authenticate = function(token, cb) { - var tokenService = new pb.TokenService(this.options); - tokenService.validateUserToken(token, function(err, result) { + var self = this; + this.tokenService.validateUserToken(token, function(err, result) { if(util.isError(err)) { return cb(err, null); } @@ -121,9 +126,7 @@ module.exports = function AuthenticationModule(pb) { if(!result.tokenInfo || !result.valid || !result.tokenInfo.user) { return cb(); } - - var dao = new pb.DAO(); - dao.loadById(result.tokenInfo.user, 'user', cb); + self.userService.get(result.tokenInfo.user, cb); }); }; diff --git a/plugins/pencilblue/controllers/actions/admin/sites/token_login.js b/plugins/pencilblue/controllers/actions/admin/sites/token_login.js index 151ffcf58..a4460f8ec 100644 --- a/plugins/pencilblue/controllers/actions/admin/sites/token_login.js +++ b/plugins/pencilblue/controllers/actions/admin/sites/token_login.js @@ -34,7 +34,8 @@ module.exports = function TokenLoginControllerModule(pb) { TokenLoginController.prototype.render = function(cb) { var self = this; var options = { - site: this.site + site: this.site, + onlyThisSite: false }; var callback = this.query.callback; pb.security.authenticateSession(this.session, this.query.token, new pb.TokenAuthentication(options), function(err, user) { From 00513e708a2eae6d2d7bec4007c2ffab339aac3e Mon Sep 17 00:00:00 2001 From: btidwell Date: Fri, 31 Jul 2015 11:50:10 -0400 Subject: [PATCH 541/790] add site to token object and set onlyThisSite of query service to true when validating token This will help avoid token sharing between sites. --- include/service/entities/token_service.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/include/service/entities/token_service.js b/include/service/entities/token_service.js index 8ab5f8e6e..b5e207ee4 100644 --- a/include/service/entities/token_service.js +++ b/include/service/entities/token_service.js @@ -45,12 +45,13 @@ module.exports = function TokenServiceModule(pb) { TokenService.prototype.generateUserToken = function(cb) { var self = this; var token = util.uniqueId(); - //TODO: Create and store token entity var tokenInfo = { token: token, user: self.user, - used: false - } + used: false, + site: this.site + }; + this.saveToken(tokenInfo, function(err, result) { if(util.isError(err)) { return cb(err, null); @@ -69,7 +70,7 @@ module.exports = function TokenServiceModule(pb) { */ TokenService.prototype.validateUserToken = function(token, cb) { var self = this; - var dao = new pb.SiteQueryService(this.site, false); + var dao = new pb.SiteQueryService(this.site, true); dao.loadByValue('token', token, 'auth_token', function(err, tokenInfo){ if(util.isError(err)) { return cb(err, null); @@ -77,7 +78,7 @@ module.exports = function TokenServiceModule(pb) { if(!tokenInfo || tokenInfo.used) { return cb(null, false); } - + tokenInfo.used = true; self.saveToken(tokenInfo, function(err, result) { if(util.isError(err)) { From aa0d2a5d1fb9353689a2b19ed1313fc9b1bc4fe6 Mon Sep 17 00:00:00 2001 From: btidwell Date: Fri, 31 Jul 2015 11:50:51 -0400 Subject: [PATCH 542/790] combine if statements for error and validation checks --- include/service/entities/token_service.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/include/service/entities/token_service.js b/include/service/entities/token_service.js index b5e207ee4..ba0d4a1f7 100644 --- a/include/service/entities/token_service.js +++ b/include/service/entities/token_service.js @@ -72,13 +72,10 @@ module.exports = function TokenServiceModule(pb) { var self = this; var dao = new pb.SiteQueryService(this.site, true); dao.loadByValue('token', token, 'auth_token', function(err, tokenInfo){ - if(util.isError(err)) { - return cb(err, null); + if (util.isError(err) || !tokenInfo || tokenInfo.used) { + return cb(err, false); } - if(!tokenInfo || tokenInfo.used) { - return cb(null, false); - } - + tokenInfo.used = true; self.saveToken(tokenInfo, function(err, result) { if(util.isError(err)) { From 2b29f3347cb476b9ec1bdd774b1612afac9a1f10 Mon Sep 17 00:00:00 2001 From: btidwell Date: Fri, 31 Jul 2015 11:53:11 -0400 Subject: [PATCH 543/790] correct typo --- .../pencilblue/controllers/actions/admin/sites/token_login.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/pencilblue/controllers/actions/admin/sites/token_login.js b/plugins/pencilblue/controllers/actions/admin/sites/token_login.js index a4460f8ec..019b64c6d 100644 --- a/plugins/pencilblue/controllers/actions/admin/sites/token_login.js +++ b/plugins/pencilblue/controllers/actions/admin/sites/token_login.js @@ -61,8 +61,8 @@ module.exports = function TokenLoginControllerModule(pb) { }); }; - function jsonpResponse(callbakck, data) { - return callbakck + '(' + data + ')'; + function jsonpResponse(callback, data) { + return callback + '(' + data + ')'; } //exports From a5d526082ef91f3509ef282b7bd43419ceacbfdd Mon Sep 17 00:00:00 2001 From: Kyle Bechtel Date: Fri, 31 Jul 2015 13:05:04 -0400 Subject: [PATCH 544/790] fixed the local plugin overriding the global plugins settings --- include/service/entities/plugin_service.js | 6 +++--- include/service/jobs/plugins/plugin_install_job.js | 7 ++++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/include/service/entities/plugin_service.js b/include/service/entities/plugin_service.js index 1c5d1e12e..a6062a347 100755 --- a/include/service/entities/plugin_service.js +++ b/include/service/entities/plugin_service.js @@ -55,14 +55,14 @@ module.exports = function PluginServiceModule(pb) { * @property pluginSettingsService * @type {SimpleLayeredService} */ - this.pluginSettingsService = PluginService.genSettingsService('plugin_settings', caching.use_memory, caching.use_cache, 'PluginSettingService'); + this.pluginSettingsService = PluginService.genSettingsService('plugin_settings', caching.use_memory, caching.use_cache, 'PluginSettingService', this.site); /** * A setting service that sets and retrieves the settings for plugins * @property pluginSettingsService * @type {SimpleLayeredService} */ - this.themeSettingsService = PluginService.genSettingsService('theme_settings', caching.use_memory, caching.use_cache, 'ThemeSettingService'); + this.themeSettingsService = PluginService.genSettingsService('theme_settings', caching.use_memory, caching.use_cache, 'ThemeSettingService', this.site); } // Constants @@ -543,7 +543,7 @@ module.exports = function PluginServiceModule(pb) { var settings = pb.DocumentCreator.create('plugin_settings', baseDoc); //save it - var dao = new pb.DAO(); + var dao = new pb.SiteQueryService(self.site); dao.save(settings, function(err, result) { cb(err, !util.isError(err)); }); diff --git a/include/service/jobs/plugins/plugin_install_job.js b/include/service/jobs/plugins/plugin_install_job.js index d00c56ac3..19df07478 100644 --- a/include/service/jobs/plugins/plugin_install_job.js +++ b/include/service/jobs/plugins/plugin_install_job.js @@ -39,9 +39,14 @@ module.exports = function PluginInstallJobModule(pb) { * @constructor * @extends PluginJobRunner */ - function PluginInstallJob(){ + function PluginInstallJob(options){ + if(options){ + this.site = options.site || GLOBAL_SITE; + } + PluginInstallJob.super_.call(this); + this.pluginService = new pb.PluginService(this.site); //initialize this.init(); this.setParallelLimit(1); From e9e68442b6da7b0d81a9c7cb31ad287dd7a0dc0d Mon Sep 17 00:00:00 2001 From: iandtrapp Date: Mon, 3 Aug 2015 09:26:32 -0400 Subject: [PATCH 545/790] Section Service Refactor --- include/service/entities/section_service.js | 9 +++++---- include/theme/top_menu.js | 2 +- .../actions/admin/content/navigation/delete_nav_item.js | 2 +- .../actions/admin/content/navigation/edit_nav_item.js | 2 +- .../actions/admin/content/navigation/new_nav_item.js | 2 +- .../admin/content/navigation/nav_item_form.js | 2 +- plugins/portfolio/controllers/blog.js | 2 +- 7 files changed, 11 insertions(+), 10 deletions(-) diff --git a/include/service/entities/section_service.js b/include/service/entities/section_service.js index f2972cc8a..4379c6593 100755 --- a/include/service/entities/section_service.js +++ b/include/service/entities/section_service.js @@ -29,10 +29,11 @@ module.exports = function SectionServiceModule(pb) { * @param {String} site uid * @param {Boolean} onlyThisSite should section service only return value set specifically by site rather than defaulting to global */ - function SectionService(site, onlyThisSite) { - this.site = pb.SiteService.getCurrentSite(site); - this.settings = pb.SettingServiceFactory.getServiceBySite(this.site, onlyThisSite); - this.siteQueryService = new pb.SiteQueryService(this.site, onlyThisSite); + function SectionService(options) { + this.site = pb.SiteService.getCurrentSite(options.site) || GLOBAL_SITE; + this.onlyThisSite = options.onlyThisSite || false; + this.settings = pb.SettingServiceFactory.getServiceBySite(this.site, this.onlyThisSite); + this.siteQueryService = new pb.SiteQueryService(this.site, this.onlyThisSite) ; } /** diff --git a/include/theme/top_menu.js b/include/theme/top_menu.js index b2594e598..38e3f9f89 100755 --- a/include/theme/top_menu.js +++ b/include/theme/top_menu.js @@ -72,7 +72,7 @@ module.exports = function TopMenuServiceModule(pb) { }, formattedSections: function(callback) { - var sectionService = new SectionService(siteUId); + var sectionService = new SectionService({site: siteUId}); sectionService.getFormattedSections(localizationService, options.currUrl, function(err, formattedSections) { callback(null, formattedSections); }); diff --git a/plugins/pencilblue/controllers/actions/admin/content/navigation/delete_nav_item.js b/plugins/pencilblue/controllers/actions/admin/content/navigation/delete_nav_item.js index f1ab99f71..635e94fad 100644 --- a/plugins/pencilblue/controllers/actions/admin/content/navigation/delete_nav_item.js +++ b/plugins/pencilblue/controllers/actions/admin/content/navigation/delete_nav_item.js @@ -82,7 +82,7 @@ module.exports = function(pb) { }; DeleteNavItem.prototype.updateNavMap = function(removeID, cb) { - var sectionService = new pb.SectionService(this.site, true); + var sectionService = new pb.SectionService({site: this.site, onlyThisSite: true}); sectionService.removeFromSectionMap(removeID, cb); }; diff --git a/plugins/pencilblue/controllers/actions/admin/content/navigation/edit_nav_item.js b/plugins/pencilblue/controllers/actions/admin/content/navigation/edit_nav_item.js index ef68936f2..79107d0fc 100644 --- a/plugins/pencilblue/controllers/actions/admin/content/navigation/edit_nav_item.js +++ b/plugins/pencilblue/controllers/actions/admin/content/navigation/edit_nav_item.js @@ -29,7 +29,7 @@ module.exports = function(pb) { EditNavItem.prototype.init = function (props, cb) { var self = this; BaseAdminController.prototype.init.call(self, props, function () { - self.sectionService = new pb.SectionService(self.site, true); + self.sectionService = new pb.SectionService({site: self.site, onlyThisSite: true}); cb(); }); }; diff --git a/plugins/pencilblue/controllers/actions/admin/content/navigation/new_nav_item.js b/plugins/pencilblue/controllers/actions/admin/content/navigation/new_nav_item.js index bf0384973..f12c9fbe4 100644 --- a/plugins/pencilblue/controllers/actions/admin/content/navigation/new_nav_item.js +++ b/plugins/pencilblue/controllers/actions/admin/content/navigation/new_nav_item.js @@ -30,7 +30,7 @@ module.exports = function(pb) { NewNavItem.prototype.init = function (props, cb) { var self = this; BaseAdminController.prototype.init.call(self, props, function () { - self.sectionService = new pb.SectionService(self.site, true); + self.sectionService = new pb.SectionService({site: self.site, onlyThisSite: true}); cb(); }); }; diff --git a/plugins/pencilblue/controllers/admin/content/navigation/nav_item_form.js b/plugins/pencilblue/controllers/admin/content/navigation/nav_item_form.js index 3e7c3304b..70e6e67bc 100644 --- a/plugins/pencilblue/controllers/admin/content/navigation/nav_item_form.js +++ b/plugins/pencilblue/controllers/admin/content/navigation/nav_item_form.js @@ -82,7 +82,7 @@ module.exports = function(pb) { //get parents parents: function(callback) { - var sectionService = new SectionService(self.site, true); + var sectionService = new SectionService({site: self.site, onlyThisSite: true}); sectionService.getParentSelectList(self.pathVars.id, function(err, parents) { if(util.isError(err)) { callback(err, parents); diff --git a/plugins/portfolio/controllers/blog.js b/plugins/portfolio/controllers/blog.js index 7b458d121..3a17ac814 100755 --- a/plugins/portfolio/controllers/blog.js +++ b/plugins/portfolio/controllers/blog.js @@ -39,7 +39,7 @@ module.exports = function BlogModule(pb) { Blog.prototype.init = function(props, cb) { var self = this; pb.BaseController.prototype.init.call(self, props, function () { - self.navService = new pb.SectionService(self.site); + self.navService = new pb.SectionService({site: self.site}); self.siteQueryService = new pb.SiteQueryService(self.site, true); cb(); }); From b4e43c3261938a695ebae6b35c81da6cc202bee1 Mon Sep 17 00:00:00 2001 From: iandtrapp Date: Mon, 3 Aug 2015 09:51:31 -0400 Subject: [PATCH 546/790] Added CB back --- plugins/portfolio/controllers/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/portfolio/controllers/index.js b/plugins/portfolio/controllers/index.js index 995c471e8..714c6426f 100755 --- a/plugins/portfolio/controllers/index.js +++ b/plugins/portfolio/controllers/index.js @@ -39,6 +39,7 @@ module.exports = function IndexModule(pb) { var self = this; pb.BaseController.prototype.init.call(self, props, function () { self.siteQueryService = new pb.SiteQueryService({site: self.site}); + cb(); }); }; From e81a2fcfb0116cb457c2752845fbf3bc4f399733 Mon Sep 17 00:00:00 2001 From: iandtrapp Date: Mon, 3 Aug 2015 10:09:01 -0400 Subject: [PATCH 547/790] Content Service Refactor --- include/content.js | 11 ++++++++--- include/service/entities/article_service.js | 2 +- .../entities/content/content_object_service.js | 2 +- .../service/entities/content/content_view_loader.js | 2 +- include/theme/top_menu.js | 2 +- .../pencilblue/controllers/actions/user/sign_up.js | 2 +- .../admin/content/comments/manage_comments.js | 2 +- .../controllers/admin/site_settings/content.js | 2 +- .../controllers/api/comments/new_comment.js | 2 +- plugins/pencilblue/controllers/index.js | 2 +- plugins/pencilblue/controllers/section.js | 2 +- .../controllers/user/resend_verification.js | 2 +- plugins/pencilblue/controllers/user/sign_up.js | 2 +- plugins/portfolio/controllers/blog.js | 2 +- 14 files changed, 21 insertions(+), 16 deletions(-) diff --git a/include/content.js b/include/content.js index 5cbe8ddb6..ce66d5617 100755 --- a/include/content.js +++ b/include/content.js @@ -26,9 +26,14 @@ module.exports = function(pb) { * @class ContentService * @constructor */ - function ContentService(site, onlyThisSite) { - this.siteUid = pb.SiteService.getCurrentSite(site); - this.settingService = pb.SettingServiceFactory.getServiceBySite(this.siteUid, onlyThisSite); + function ContentService(options) { + if(options) { + this.siteUid = pb.SiteService.getCurrentSite(options.site) || ''; + this.onlyThisSite = options.onlyThisSite || false; + } + this.siteUid = ''; + this.onlyThisSite = false; + this.settingService = pb.SettingServiceFactory.getServiceBySite(this.siteUid, this.onlyThisSite); } /** diff --git a/include/service/entities/article_service.js b/include/service/entities/article_service.js index 3cba9b5ef..919e725d1 100755 --- a/include/service/entities/article_service.js +++ b/include/service/entities/article_service.js @@ -194,7 +194,7 @@ module.exports = function ArticleServiceModule(pb) { //get authors self.getArticleAuthors(articles, function(err, authors) { - var contentService = new pb.ContentService(self.site); + var contentService = new pb.ContentService({site: self.site}); contentService.getSettings(function(err, contentSettings) { var tasks = util.getTasks(articles, function(articles, i) { diff --git a/include/service/entities/content/content_object_service.js b/include/service/entities/content/content_object_service.js index 5c7dd58a2..1ba60513c 100644 --- a/include/service/entities/content/content_object_service.js +++ b/include/service/entities/content/content_object_service.js @@ -351,7 +351,7 @@ module.exports = function(pb) { return callback(null, self.contentSettings); } - var contentService = new pb.ContentService(self.site); + var contentService = new pb.ContentService({self: self.site}); contentService.getSettings(callback); } }; diff --git a/include/service/entities/content/content_view_loader.js b/include/service/entities/content/content_view_loader.js index 67cc56a4f..2ea5fdcb4 100644 --- a/include/service/entities/content/content_view_loader.js +++ b/include/service/entities/content/content_view_loader.js @@ -234,7 +234,7 @@ module.exports = function(pb) { return callback(null, self.contentSettings); } - var contentService = new pb.ContentService(self.site, self.onlyThisSite); + var contentService = new pb.ContentService({site: self.site, onlyThisSite: self.onlyThisSite}); contentService.getSettings(function(err, contentSettings) { self.contentSettings = contentSettings; callback(err, contentSettings); diff --git a/include/theme/top_menu.js b/include/theme/top_menu.js index 38e3f9f89..be870a8b1 100755 --- a/include/theme/top_menu.js +++ b/include/theme/top_menu.js @@ -105,7 +105,7 @@ module.exports = function TopMenuServiceModule(pb) { site = pb.siteService.GLOBAL_SITE; } - var contentService = new pb.ContentService(site); + var contentService = new pb.ContentService({site: site}); contentService.getSettings(function(err, contentSettings) { if (util.isError(err)) { return cb(err); diff --git a/plugins/pencilblue/controllers/actions/user/sign_up.js b/plugins/pencilblue/controllers/actions/user/sign_up.js index 608f0a8b5..a05bdfd9b 100755 --- a/plugins/pencilblue/controllers/actions/user/sign_up.js +++ b/plugins/pencilblue/controllers/actions/user/sign_up.js @@ -50,7 +50,7 @@ module.exports = function SignUpModule(pb) { }); } - var contentService = new pb.ContentService(self.site); + var contentService = new pb.ContentService({site: self.site}); contentService.getSettings(function(err, contentSettings) { //Handle errors if (util.isError(err)){ diff --git a/plugins/pencilblue/controllers/admin/content/comments/manage_comments.js b/plugins/pencilblue/controllers/admin/content/comments/manage_comments.js index 561a535b6..f961b83eb 100755 --- a/plugins/pencilblue/controllers/admin/content/comments/manage_comments.js +++ b/plugins/pencilblue/controllers/admin/content/comments/manage_comments.js @@ -58,7 +58,7 @@ module.exports = function(pb) { } //retrieve the content settings or defaults if they have not yet been configured - var contentService = new pb.ContentService(self.site); + var contentService = new pb.ContentService({site: self.site}); contentService.getSettings(function(err, contentSettings) { // Handle error if (util.isError(err)){ diff --git a/plugins/pencilblue/controllers/admin/site_settings/content.js b/plugins/pencilblue/controllers/admin/site_settings/content.js index 1cacbe8ec..083a6bce9 100755 --- a/plugins/pencilblue/controllers/admin/site_settings/content.js +++ b/plugins/pencilblue/controllers/admin/site_settings/content.js @@ -57,7 +57,7 @@ module.exports = function(pb) { } ]; - var contentService = new pb.ContentService(this.site, true); + var contentService = new pb.ContentService({site: this.site, onlyThisSite: true}); contentService.getSettings(function(err, contentSettings) { var angularObjects = pb.ClientJs.getAngularObjects({ navigation: pb.AdminNavigation.get(self.session, ['settings', 'site_settings'], self.ls, self.site), diff --git a/plugins/pencilblue/controllers/api/comments/new_comment.js b/plugins/pencilblue/controllers/api/comments/new_comment.js index 239356e7d..f7731ce9f 100755 --- a/plugins/pencilblue/controllers/api/comments/new_comment.js +++ b/plugins/pencilblue/controllers/api/comments/new_comment.js @@ -37,7 +37,7 @@ module.exports = function NewCommentModule(pb) { NewComment.prototype.onPostParamsRetrieved = function(post, cb) { var self = this; - var contentService = new pb.ContentService(self.site, true); + var contentService = new pb.ContentService({site: self.site, onlyThisSite: true}); contentService.getSettings(function(err, contentSettings) { if(!contentSettings.allow_comments) { cb({content: BaseController.apiResponse(BaseController.API_FAILURE, 'commenting not allowed'), code: 400}); diff --git a/plugins/pencilblue/controllers/index.js b/plugins/pencilblue/controllers/index.js index e751d4e20..8d2d9fbf9 100755 --- a/plugins/pencilblue/controllers/index.js +++ b/plugins/pencilblue/controllers/index.js @@ -55,7 +55,7 @@ module.exports = function IndexModule(pb) { var article = self.req.pencilblue_article || null; var page = self.req.pencilblue_page || null; - var contentService = new pb.ContentService(self.site, true); + var contentService = new pb.ContentService({site: self.site, onlyThisSite: true}); contentService.getSettings(function(err, contentSettings) { self.gatherData(function(err, data) { diff --git a/plugins/pencilblue/controllers/section.js b/plugins/pencilblue/controllers/section.js index 1ce549bd8..186b311d5 100755 --- a/plugins/pencilblue/controllers/section.js +++ b/plugins/pencilblue/controllers/section.js @@ -39,7 +39,7 @@ module.exports = function(pb) { var init = function(err) { //get content settings var serviceContext = self.getServiceContext(); - var contentService = new pb.ContentService(self.site, serviceContext.onlyThisSite); + var contentService = new pb.ContentService({site: self.site, onlyThisSite: serviceContext.onlyThisSite}); contentService.getSettings(function(err, contentSettings) { if (util.isError(err)) { return cb(err); diff --git a/plugins/pencilblue/controllers/user/resend_verification.js b/plugins/pencilblue/controllers/user/resend_verification.js index c2f9c4c1c..346a44fee 100755 --- a/plugins/pencilblue/controllers/user/resend_verification.js +++ b/plugins/pencilblue/controllers/user/resend_verification.js @@ -29,7 +29,7 @@ module.exports = function ResendVerificationModule(pb) { util.inherits(ResendVerification, pb.BaseController); ResendVerification.prototype.render = function(cb) { var self = this; - var contentService = new pb.ContentService(self.site, true); + var contentService = new pb.ContentService({site: self.site, onlyThisSite: true}); contentService.getSettings(function(err, contentSettings) { /*if(!contentSettings.allow_comments || !contentSettings.require_verification) { diff --git a/plugins/pencilblue/controllers/user/sign_up.js b/plugins/pencilblue/controllers/user/sign_up.js index 504152cc4..1757b2a9c 100755 --- a/plugins/pencilblue/controllers/user/sign_up.js +++ b/plugins/pencilblue/controllers/user/sign_up.js @@ -32,7 +32,7 @@ module.exports = function SignUpModule(pb) { SignUp.prototype.render = function(cb) { var self = this; - var contentService = new pb.ContentService(this.site); + var contentService = new pb.ContentService({site: this.site}); contentService.getSettings(function(err, contentSettings) { if(!contentSettings.allow_comments) { self.redirect('/', cb); diff --git a/plugins/portfolio/controllers/blog.js b/plugins/portfolio/controllers/blog.js index 3a17ac814..f59fe9adb 100755 --- a/plugins/portfolio/controllers/blog.js +++ b/plugins/portfolio/controllers/blog.js @@ -54,7 +54,7 @@ module.exports = function BlogModule(pb) { var article = self.req.pencilblue_article || null; var page = self.req.pencilblue_page || null; - var contentService = new pb.ContentService(self.site, true); + var contentService = new pb.ContentService({site: self.site, onlyThisSite: true}); contentService.getSettings(function(err, contentSettings) { self.gatherData(function(err, data) { var articleService = new pb.ArticleService(self.site, true); From fcfd0d102f1898df185431ac021bce04ca2d1f17 Mon Sep 17 00:00:00 2001 From: kylebechtel77 Date: Mon, 3 Aug 2015 10:23:36 -0400 Subject: [PATCH 548/790] Update plugin_install_job.js --- include/service/jobs/plugins/plugin_install_job.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/include/service/jobs/plugins/plugin_install_job.js b/include/service/jobs/plugins/plugin_install_job.js index 19df07478..996b9f59e 100644 --- a/include/service/jobs/plugins/plugin_install_job.js +++ b/include/service/jobs/plugins/plugin_install_job.js @@ -41,7 +41,9 @@ module.exports = function PluginInstallJobModule(pb) { */ function PluginInstallJob(options){ if(options){ - this.site = options.site || GLOBAL_SITE; + this.site = options.site || pb.SiteService.GLOBAL_SITE; + } else { + this.site = pb.SiteService.GLOBAL_SITE; } PluginInstallJob.super_.call(this); From afba7cc4a4761644a76fffca36f69f3ea4c8565e Mon Sep 17 00:00:00 2001 From: andparker Date: Mon, 3 Aug 2015 10:24:20 -0400 Subject: [PATCH 549/790] Url Service hostname parameter refactor. --- controllers/base_controller.js | 3 ++- controllers/delete_controller.js | 2 +- include/http/request_handler.js | 2 +- include/localization.js | 5 +++-- include/service/entities/content/article_renderer.js | 3 ++- include/service/entities/content/article_service_v2.js | 2 +- include/service/entities/content/content_view_loader.js | 4 ++-- include/service/entities/url_service.js | 3 +++ plugins/pencilblue/controllers/api/comments/new_comment.js | 2 +- plugins/pencilblue/controllers/blog.js | 2 +- .../pencilblue/controllers/user/locale_view_controller.js | 2 +- plugins/pencilblue/controllers/user/manage_account.js | 2 +- plugins/portfolio/controllers/index.js | 2 +- 13 files changed, 20 insertions(+), 14 deletions(-) diff --git a/controllers/base_controller.js b/controllers/base_controller.js index 26ee48c16..9dbed4664 100755 --- a/controllers/base_controller.js +++ b/controllers/base_controller.js @@ -177,6 +177,7 @@ module.exports = function BaseControllerModule(pb) { ls: this.ls, ts: this.ts, site: this.site, + hostname: this.hostname, activeTheme: this.activeTheme, onlyThisSite: true, siteObj: this.siteObj @@ -228,7 +229,7 @@ module.exports = function BaseControllerModule(pb) { BaseController.prototype.formError = function(message, redirectLocation, cb) { this.session.error = message; - var uri = pb.UrlService.createSystemUrl(redirectLocation); + var uri = pb.UrlService.createSystemUrl(redirectLocation, this.hostname); cb(pb.RequestHandler.generateRedirect(uri)); }; diff --git a/controllers/delete_controller.js b/controllers/delete_controller.js index ceaeed00f..b0f231169 100755 --- a/controllers/delete_controller.js +++ b/controllers/delete_controller.js @@ -172,7 +172,7 @@ module.exports = function(pb) { * @return {String} */ DeleteController.prototype.getSuccessRedirect = function() { - return pb.UrlService.createSystemUrl('/'); + return pb.UrlService.createSystemUrl('/', this.hostname); }; /** diff --git a/include/http/request_handler.js b/include/http/request_handler.js index c3bf6617f..f8453a798 100755 --- a/include/http/request_handler.js +++ b/include/http/request_handler.js @@ -1151,7 +1151,7 @@ module.exports = function RequestHandlerModule(pb) { if (self.session.authentication.user_id == null || self.session.authentication.user_id == undefined) { result.success = false; result.redirect = RequestHandler.isAdminURL(self.url.href) ? '/admin/login' : '/user/login'; - self.session.on_login = self.req.method.toLowerCase() === 'get' ? self.url.href : pb.UrlService.createSystemUrl('/admin'); + self.session.on_login = self.req.method.toLowerCase() === 'get' ? self.url.href : pb.UrlService.createSystemUrl('/admin', self.hostname); callback(result, result); return; } diff --git a/include/localization.js b/include/localization.js index 1c63d1e36..3c402e67a 100755 --- a/include/localization.js +++ b/include/localization.js @@ -93,9 +93,10 @@ module.exports = function LocalizationModule(pb) { * @method localize * @param {array} sets The localizations sets to search in * @param {string} text The text to localize + * @param {string} hostname The current hostname * @returns {string} The text where keys have been replaced with translated values */ - Localization.prototype.localize = function(sets, text){ + Localization.prototype.localize = function(sets, text, hostname){ if (pb.log.isSilly()) { pb.log.silly('Localization: Localizing text - Locale [%s] Sets %s', this.language, JSON.stringify(sets)); } @@ -117,7 +118,7 @@ module.exports = function LocalizationModule(pb) { // If the localization is for HTML output, load the localization into client side JS if (text.indexOf(' -1) { - text = text.concat(pb.ClientJs.includeJS(pb.UrlService.createSystemUrl('api/localization/script?locale=' + this.language))); + text = text.concat(pb.ClientJs.includeJS(pb.UrlService.createSystemUrl('api/localization/script?locale=' + this.language, hostname))); } return text; diff --git a/include/service/entities/content/article_renderer.js b/include/service/entities/content/article_renderer.js index 5b66f3bf5..5352791e6 100644 --- a/include/service/entities/content/article_renderer.js +++ b/include/service/entities/content/article_renderer.js @@ -38,6 +38,7 @@ module.exports = function(pb) { * @type {CommentService} */ this.commentService = new pb.CommentService(context); + this.hostname = context.hostname; } /** @@ -375,7 +376,7 @@ module.exports = function(pb) { ArticleRenderer.prototype.getReadMoreLink = function(content, anchorContent) { var path = pb.UrlService.urlJoin(this.getContentLinkPrefix() + content.url); - return '' + anchorContent + ''; + return '' + anchorContent + ''; }; /** diff --git a/include/service/entities/content/article_service_v2.js b/include/service/entities/content/article_service_v2.js index 2bd7d1c7c..3adf2e071 100644 --- a/include/service/entities/content/article_service_v2.js +++ b/include/service/entities/content/article_service_v2.js @@ -79,7 +79,7 @@ module.exports = function(pb) { * @return {ArticleRenderer} */ ArticleServiceV2.prototype.getRenderer = function() { - return new pb.ArticleRenderer(); + return new pb.ArticleRenderer(this.context); }; /** diff --git a/include/service/entities/content/content_view_loader.js b/include/service/entities/content/content_view_loader.js index 67cc56a4f..57fc21194 100644 --- a/include/service/entities/content/content_view_loader.js +++ b/include/service/entities/content/content_view_loader.js @@ -36,6 +36,7 @@ module.exports = function(pb) { this.service = context.service; this.site = context.site; this.siteObj = context.siteObj; + this.hostname = context.hostname; this.onlyThisSite = context.onlyThisSite; this.activeTheme = context.activeTheme; }; @@ -521,8 +522,7 @@ module.exports = function(pb) { */ ContentViewLoader.prototype.createContentPermalink = function(content) { var prefix = '/' + this.service.getType(); - var hostname = pb.SiteService.getHostWithProtocol(this.siteObj.hostname); - return pb.UrlService.createSystemUrl(pb.UrlService.urlJoin(prefix, content.url), hostname); + return pb.UrlService.createSystemUrl(pb.UrlService.urlJoin(prefix, content.url), this.hostname); }; /** diff --git a/include/service/entities/url_service.js b/include/service/entities/url_service.js index aa8fa32c1..22ec1445c 100755 --- a/include/service/entities/url_service.js +++ b/include/service/entities/url_service.js @@ -177,6 +177,9 @@ module.exports = function UrlServiceModule(pb) { }; UrlService.createSystemUrl = function(path, hostname) { + if (!hostname) { + hostname = pb.config.siteRoot; + } return UrlService.urlJoin(hostname, path); }; diff --git a/plugins/pencilblue/controllers/api/comments/new_comment.js b/plugins/pencilblue/controllers/api/comments/new_comment.js index a23e5f708..022de12fc 100755 --- a/plugins/pencilblue/controllers/api/comments/new_comment.js +++ b/plugins/pencilblue/controllers/api/comments/new_comment.js @@ -65,7 +65,7 @@ module.exports = function NewCommentModule(pb) { } var timestamp = pb.ContentService.getTimestampTextFromSettings(commentDocument.created, contentSettings, self.ls); - commentDocument.timestamp = self.localizationService.localize(['timestamp'], timestamp); + commentDocument.timestamp = self.localizationService.localize(['timestamp'], timestamp, self.hostname); cb({content: BaseController.apiResponse(BaseController.API_SUCCESS, 'comment created' , commentDocument)}); }); }); diff --git a/plugins/pencilblue/controllers/blog.js b/plugins/pencilblue/controllers/blog.js index 2e1df0454..6eda73037 100644 --- a/plugins/pencilblue/controllers/blog.js +++ b/plugins/pencilblue/controllers/blog.js @@ -32,7 +32,7 @@ module.exports = function(pb) { var init = function(err) { //get content settings - var contentService = new pb.ContentService(); + var contentService = new pb.ContentService(self.site, true); contentService.getSettings(function(err, contentSettings) { if (util.isError(err)) { return cb(err); diff --git a/plugins/pencilblue/controllers/user/locale_view_controller.js b/plugins/pencilblue/controllers/user/locale_view_controller.js index 743fe2331..cc72d9b23 100644 --- a/plugins/pencilblue/controllers/user/locale_view_controller.js +++ b/plugins/pencilblue/controllers/user/locale_view_controller.js @@ -51,7 +51,7 @@ module.exports = function(pb) { //calculate the redirect. Referrer if provided otherwise head home var redirect = this.req.headers.referer; if (!ValidationService.isNonEmptyStr(redirect, true)) { - redirect = UrlService.createSystemUrl('/'); + redirect = UrlService.createSystemUrl('/', this.hostname); } //when new locale is provided then set it in the session diff --git a/plugins/pencilblue/controllers/user/manage_account.js b/plugins/pencilblue/controllers/user/manage_account.js index 0cc282573..5900468e5 100755 --- a/plugins/pencilblue/controllers/user/manage_account.js +++ b/plugins/pencilblue/controllers/user/manage_account.js @@ -69,7 +69,7 @@ module.exports = function(pb) { return cb(err); } else if (data.user === null) { - return self.redirect(UrlService.createSystemUrl('/'), cb); + return self.redirect(UrlService.createSystemUrl('/', self.hostname), cb); } delete data.user.password; diff --git a/plugins/portfolio/controllers/index.js b/plugins/portfolio/controllers/index.js index 714c6426f..2b35769da 100755 --- a/plugins/portfolio/controllers/index.js +++ b/plugins/portfolio/controllers/index.js @@ -158,7 +158,7 @@ module.exports = function IndexModule(pb) { content.content = content.content.split('^hero_image^').join(settings.home_page_hero ? settings.home_page_hero : ''); content.content = content.content.split('^callouts^').join(calloutsHTML); - content.content = self.ls.localize([], content.content); + content.content = self.ls.localize([], content.content, self.hostname); var angularData = pb.ClientJs.getAngularController({}, ['ngSanitize']); content.content = content.content.concat(angularData); From f3256b1bd92327f1c7db19d1711886ffd7f75e40 Mon Sep 17 00:00:00 2001 From: iandtrapp Date: Mon, 3 Aug 2015 10:33:24 -0400 Subject: [PATCH 550/790] Fixed merge conflicts --- include/service/entities/section_service.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/service/entities/section_service.js b/include/service/entities/section_service.js index 4379c6593..a175cc47a 100755 --- a/include/service/entities/section_service.js +++ b/include/service/entities/section_service.js @@ -30,10 +30,10 @@ module.exports = function SectionServiceModule(pb) { * @param {Boolean} onlyThisSite should section service only return value set specifically by site rather than defaulting to global */ function SectionService(options) { - this.site = pb.SiteService.getCurrentSite(options.site) || GLOBAL_SITE; + this.site = pb.SiteService.getCurrentSite(options.site) || ''; this.onlyThisSite = options.onlyThisSite || false; this.settings = pb.SettingServiceFactory.getServiceBySite(this.site, this.onlyThisSite); - this.siteQueryService = new pb.SiteQueryService(this.site, this.onlyThisSite) ; + this.siteQueryService = new pb.SiteQueryService({site: this.site, onlyThisSite: this.onlyThisSite}); } /** From 96db9dbcdfe1af892ad2d25443fcdf7283d10399 Mon Sep 17 00:00:00 2001 From: btidwell Date: Mon, 3 Aug 2015 10:55:12 -0400 Subject: [PATCH 551/790] pass options object to site_query_service in plugin_service --- include/service/entities/plugin_service.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/service/entities/plugin_service.js b/include/service/entities/plugin_service.js index eeaa0a90d..49b3214bc 100755 --- a/include/service/entities/plugin_service.js +++ b/include/service/entities/plugin_service.js @@ -545,7 +545,7 @@ module.exports = function PluginServiceModule(pb) { var settings = pb.DocumentCreator.create('plugin_settings', baseDoc); //save it - var dao = new pb.SiteQueryService(self.site); + var dao = new pb.SiteQueryService({site: self.site}); dao.save(settings, function(err, result) { cb(err, !util.isError(err)); }); From 25425b40734679416e5c6f1aa4d8b1540b69bfce Mon Sep 17 00:00:00 2001 From: btidwell Date: Mon, 3 Aug 2015 10:55:32 -0400 Subject: [PATCH 552/790] Remove unnecessary console.log --- controllers/api/base_api_controller.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/controllers/api/base_api_controller.js b/controllers/api/base_api_controller.js index 5d666c040..5e7704e54 100644 --- a/controllers/api/base_api_controller.js +++ b/controllers/api/base_api_controller.js @@ -147,7 +147,7 @@ module.exports = function(pb) { * @param {String} rawOrder * @return {Object} Contains the order statement and an array of failures */ - BaseApiController.prototype.processOrder = function(rawOrder) {console.log(rawOrder); + BaseApiController.prototype.processOrder = function(rawOrder) { var order = null; var failures = []; From 36e1904df93d9296b927a5f0304b2c83e7c0ab05 Mon Sep 17 00:00:00 2001 From: iandtrapp Date: Mon, 3 Aug 2015 11:02:18 -0400 Subject: [PATCH 553/790] Merged 0.5.0 and fixed merge conflicts --- include/service/entities/section_service.js | 2 +- plugins/portfolio/controllers/blog.js | 5 ----- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/include/service/entities/section_service.js b/include/service/entities/section_service.js index 8dd6e694e..c4c47f4fb 100755 --- a/include/service/entities/section_service.js +++ b/include/service/entities/section_service.js @@ -29,7 +29,7 @@ module.exports = function SectionServiceModule(pb) { * @param {String} site uid * @param {Boolean} onlyThisSite should section service only return value set specifically by site rather than defaulting to global */ -<<<<<<< Temporary merge branch 1 + function SectionService(options) { this.site = pb.SiteService.getCurrentSite(options.site) || GLOBAL_SITE; this.onlyThisSite = options.onlyThisSite || false; diff --git a/plugins/portfolio/controllers/blog.js b/plugins/portfolio/controllers/blog.js index 27d87e173..b2e820568 100755 --- a/plugins/portfolio/controllers/blog.js +++ b/plugins/portfolio/controllers/blog.js @@ -39,13 +39,8 @@ module.exports = function BlogModule(pb) { Blog.prototype.init = function(props, cb) { var self = this; pb.BaseController.prototype.init.call(self, props, function () { -<<<<<<< Temporary merge branch 1 self.navService = new pb.SectionService({site: self.site}); - self.siteQueryService = new pb.SiteQueryService(self.site, true); -======= - self.navService = new pb.SectionService(self.site); self.siteQueryService = new pb.SiteQueryService({site: self.site, onlyThisSite: true}); ->>>>>>> Temporary merge branch 2 cb(); }); }; From 306c1b3bbbbfe8aefc16d8f32eb2961a684a14cb Mon Sep 17 00:00:00 2001 From: iandtrapp Date: Mon, 3 Aug 2015 11:07:46 -0400 Subject: [PATCH 554/790] Fixed buggy logic in Content Service --- include/content.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/include/content.js b/include/content.js index ce66d5617..dfdd6fbc9 100755 --- a/include/content.js +++ b/include/content.js @@ -28,11 +28,12 @@ module.exports = function(pb) { */ function ContentService(options) { if(options) { - this.siteUid = pb.SiteService.getCurrentSite(options.site) || ''; + this.siteUid = pb.SiteService.getCurrentSite(options.site) || pb.SiteService.GLOBAL_SITE; this.onlyThisSite = options.onlyThisSite || false; + } else { + this.siteUid = pb.SiteService.GLOBAL_SITE; + this.onlyThisSite = false; } - this.siteUid = ''; - this.onlyThisSite = false; this.settingService = pb.SettingServiceFactory.getServiceBySite(this.siteUid, this.onlyThisSite); } From 3082c703708fe1d55c33742d565437bf07e8b404 Mon Sep 17 00:00:00 2001 From: iandtrapp Date: Mon, 3 Aug 2015 11:09:26 -0400 Subject: [PATCH 555/790] Fixed section service merge conflict --- include/service/entities/section_service.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/service/entities/section_service.js b/include/service/entities/section_service.js index c4c47f4fb..092d99b1c 100755 --- a/include/service/entities/section_service.js +++ b/include/service/entities/section_service.js @@ -33,8 +33,8 @@ module.exports = function SectionServiceModule(pb) { function SectionService(options) { this.site = pb.SiteService.getCurrentSite(options.site) || GLOBAL_SITE; this.onlyThisSite = options.onlyThisSite || false; - this.settings = pb.SettingServiceFactory.getServiceBySite(this.site, onlyThisSite); - this.siteQueryService = new pb.SiteQueryService({site: this.site, onlyThisSite: onlyThisSite}); + this.settings = pb.SettingServiceFactory.getServiceBySite(this.site, this.onlyThisSite); + this.siteQueryService = new pb.SiteQueryService({site: this.site, onlyThisSite: this.onlyThisSite}); } /** From 08925546a3e0d43c715b17ee870f403a16ee032e Mon Sep 17 00:00:00 2001 From: btidwell Date: Mon, 3 Aug 2015 12:27:07 -0400 Subject: [PATCH 556/790] Update comment service and blog controller to pass options object to ContentService --- include/theme/comments.js | 2 +- plugins/pencilblue/controllers/blog.js | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/include/theme/comments.js b/include/theme/comments.js index beed8db20..49fe9e332 100755 --- a/include/theme/comments.js +++ b/include/theme/comments.js @@ -69,7 +69,7 @@ module.exports = function CommentServiceModule(pb) { * @property contentService * @type {ContentService} */ - this.contentService = new pb.ContentService(); + this.contentService = new pb.ContentService(context); } util.inherits(CommentService, BaseObjectService); diff --git a/plugins/pencilblue/controllers/blog.js b/plugins/pencilblue/controllers/blog.js index 2e1df0454..ce98b3691 100644 --- a/plugins/pencilblue/controllers/blog.js +++ b/plugins/pencilblue/controllers/blog.js @@ -32,7 +32,7 @@ module.exports = function(pb) { var init = function(err) { //get content settings - var contentService = new pb.ContentService(); + var contentService = new pb.ContentService({site: this.site}); contentService.getSettings(function(err, contentSettings) { if (util.isError(err)) { return cb(err); @@ -50,9 +50,6 @@ module.exports = function(pb) { cvlContext.service = self.service; self.contentViewLoader = new pb.ContentViewLoader(cvlContext); - //provide a dao - self.dao = new pb.DAO(); - cb(null, true); }); }; From 65a5961403cb0a55109e262ae8638f99288efdbe Mon Sep 17 00:00:00 2001 From: Christina Chatham Date: Tue, 4 Aug 2015 15:33:53 -0400 Subject: [PATCH 557/790] Fixing tests. --- include/service/entities/content/article_renderer.js | 12 ++++-------- test/include/util_tests.js | 5 +++-- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/include/service/entities/content/article_renderer.js b/include/service/entities/content/article_renderer.js index e003d7f0f..6a80b4906 100644 --- a/include/service/entities/content/article_renderer.js +++ b/include/service/entities/content/article_renderer.js @@ -31,14 +31,10 @@ module.exports = function(pb) { * @constructor */ function ArticleRenderer(context) { - - /** - * - * @property commentService - * @type {CommentService} - */ - this.commentService = new pb.CommentService(context); - this.hostname = context.hostname; + if (context) { + this.commentService = new pb.CommentService(context); + this.hostname = context.hostname; + } } /** diff --git a/test/include/util_tests.js b/test/include/util_tests.js index bd3903f26..8ce9f8bad 100644 --- a/test/include/util_tests.js +++ b/test/include/util_tests.js @@ -779,14 +779,15 @@ describe('Util', function() { util.getDirectories.bind(54, function(err, results) {}).should.throwError(); }); - it('should callback with an array with 1 path', function(done) { + it('should callback with an array with 2 paths', function(done) { util.getDirectories('./controllers', function(err, results) { should.not.exist(err); - results.should.be.instanceof(Array).and.have.lengthOf(1); + results.should.be.instanceof(Array).and.have.lengthOf(2); var expected = [ + path.join('controllers', 'admin'), path.join('controllers', 'api') ]; results.should.eql(expected); From 599a7098b688035f1c0203a7831f7f7c04586966 Mon Sep 17 00:00:00 2001 From: Brian Hyder Date: Tue, 4 Aug 2015 17:43:45 -0400 Subject: [PATCH 558/790] Made unit test more flexibile. Updated travis config to run in containers --- .travis.yml | 3 ++- test/include/util_tests.js | 8 ++------ 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index 2f894479a..6a2318778 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,4 +5,5 @@ node_js: - "iojs-1.4.2" after_script: - cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js - - rm -rf ./coverage \ No newline at end of file + - rm -rf ./coverage +sudo: false diff --git a/test/include/util_tests.js b/test/include/util_tests.js index 8ce9f8bad..c687603db 100644 --- a/test/include/util_tests.js +++ b/test/include/util_tests.js @@ -785,12 +785,8 @@ describe('Util', function() { should.not.exist(err); results.should.be.instanceof(Array).and.have.lengthOf(2); - - var expected = [ - path.join('controllers', 'admin'), - path.join('controllers', 'api') - ]; - results.should.eql(expected); + results.should.containEql(path.join('controllers', 'admin')) + results.should.containEql(path.join('controllers', 'api')); done(); }); }); From 0d703b887157fcb85db2d6ce8c2e431e92c5a325 Mon Sep 17 00:00:00 2001 From: Brian Hyder Date: Tue, 4 Aug 2015 20:10:02 -0400 Subject: [PATCH 559/790] Cleaning up code smells. --- controllers/base_controller.js | 5 +- include/admin_navigation.js | 22 +- include/dao/dao.js | 2 +- include/dao/db_manager.js | 2 +- include/http/request_handler.js | 11 +- include/repository/plugin_repository.js | 43 +++- include/service/base_object_service.js | 2 +- include/service/cache_entity_service.js | 20 +- include/service/db_entity_service.js | 2 +- .../entities/content/content_view_loader.js | 2 +- include/service/entities/plugin_service.js | 23 +- .../entities/plugin_setting_service.js | 177 ++++++++++----- include/service/entities/section_service.js | 3 +- .../service/entities/site_query_service.js | 212 +++++++++++++----- include/service/entities/site_service.js | 120 ++++++---- include/service/entities/user_service.js | 15 +- .../service/jobs/sites/site_activate_job.js | 13 +- .../service/jobs/sites/site_deactivate_job.js | 7 +- include/service/jobs/sites/site_job_runner.js | 15 +- .../actions/admin/sites/deactivate_site.js | 22 +- .../actions/admin/sites/edit_site.js | 4 +- .../actions/user/resend_verification.js | 39 ++-- .../admin/content/pages/manage_pages.js | 2 +- .../admin/plugins/manage_plugins.js | 2 +- .../controllers/admin/sites/site_form.js | 20 +- plugins/pencilblue/include/routes.js | 1 + plugins/portfolio/controllers/index.js | 2 +- plugins/portfolio/portfolio.js | 1 - 28 files changed, 531 insertions(+), 258 deletions(-) diff --git a/controllers/base_controller.js b/controllers/base_controller.js index f37f7e63e..c3825f824 100755 --- a/controllers/base_controller.js +++ b/controllers/base_controller.js @@ -16,9 +16,8 @@ */ //dependencies -var url = require('url'); -var Sanitizer = require('sanitize-html'); -var util = require('../include/util.js'); +var url = require('url'); +var util = require('../include/util.js'); module.exports = function BaseControllerModule(pb) { diff --git a/include/admin_navigation.js b/include/admin_navigation.js index de13a572a..439e7921c 100755 --- a/include/admin_navigation.js +++ b/include/admin_navigation.js @@ -278,8 +278,14 @@ module.exports = function AdminNavigationModule(pb) { */ function getChildrenAdditions(site) { return getAdditionsInScope(AdminNavigation.childrenAdditions, site); - }; + } + /** + * @private + * @method getAdditionsInScope + * @param {Object} additions + * @param {String} site + */ function getAdditionsInScope(additions, site) { if (additions.hasOwnProperty(site)) { return util.clone(additions[site]); @@ -287,9 +293,7 @@ module.exports = function AdminNavigationModule(pb) { else if (additions.hasOwnProperty(pb.SiteService.GLOBAL_SITE)) { return util.clone(additions[pb.SiteService.GLOBAL_SITE]); } - else { - return util.clone(additions); - } + return util.clone(additions); } /** @@ -350,7 +354,7 @@ module.exports = function AdminNavigationModule(pb) { }); return navigation; - }; + } /** * @private @@ -368,7 +372,7 @@ module.exports = function AdminNavigationModule(pb) { } }); return navigation; - }; + } /** * @private @@ -394,7 +398,7 @@ module.exports = function AdminNavigationModule(pb) { } } return false; - }; + } function exists(id, site) { var isGlobal = pb.SiteService.isGlobal(site); @@ -412,7 +416,7 @@ module.exports = function AdminNavigationModule(pb) { */ function isDefaultNode(id, site) { return isDuplicate(id, getDefaultNavigation(site)); - }; + } /** * Retrive the admin navigation hierarchy @@ -452,7 +456,7 @@ module.exports = function AdminNavigationModule(pb) { var additionsMap; if (!(site in AdminNavigation.childrenAdditions)) { - additionsMap = AdminNavigation.childrenAdditions[site] = {} + additionsMap = AdminNavigation.childrenAdditions[site] = {}; } else { additionsMap = AdminNavigation.childrenAdditions[site]; } diff --git a/include/dao/dao.js b/include/dao/dao.js index a6a340014..a58f93093 100755 --- a/include/dao/dao.js +++ b/include/dao/dao.js @@ -152,7 +152,7 @@ module.exports = function DAOModule(pb) { var siteIsGlobal = {}; siteIsGlobal[SITE_FIELD] = pb.SiteService.GLOBAL_SITE; where[key] = val; - where['$or'] = [ + where.$or = [ hasNoSite, siteIsGlobal ]; diff --git a/include/dao/db_manager.js b/include/dao/db_manager.js index d27a04933..06874a75f 100755 --- a/include/dao/db_manager.js +++ b/include/dao/db_manager.js @@ -200,7 +200,7 @@ module.exports = function DBManagerModule(pb) { }; cb(err, result); }); - } + }; /** diff --git a/include/http/request_handler.js b/include/http/request_handler.js index 172aa8ec4..17548c14f 100755 --- a/include/http/request_handler.js +++ b/include/http/request_handler.js @@ -653,9 +653,8 @@ module.exports = function RequestHandlerModule(pb) { this.session = session; //set the site -- how do we handle improper sites here? - this.siteObj = RequestHandler.sites[this.hostname] - ? RequestHandler.sites[this.hostname] - : this.serve404(); + this.siteObj = RequestHandler.sites[this.hostname] ? + RequestHandler.sites[this.hostname] : this.serve404(); this.site = this.siteObj.uid; this.siteName = this.siteObj.displayName; //find the controller to hand off to @@ -746,9 +745,9 @@ module.exports = function RequestHandlerModule(pb) { * @return {Boolean} */ RequestHandler.routeSupportsSiteTheme = function(route, theme, method, site) { - return !util.isNullOrUndefined(route.themes[site]) - && !util.isNullOrUndefined(route.themes[site][theme]) - && RequestHandler.routeSupportsMethod(route.themes[site][theme], method); + return !util.isNullOrUndefined(route.themes[site]) && + !util.isNullOrUndefined(route.themes[site][theme]) && + RequestHandler.routeSupportsMethod(route.themes[site][theme], method); }; RequestHandler.routeSupportsGlobalTheme = function(route, theme, method) { diff --git a/include/repository/plugin_repository.js b/include/repository/plugin_repository.js index 217fe75c4..4f177f5d7 100644 --- a/include/repository/plugin_repository.js +++ b/include/repository/plugin_repository.js @@ -1,10 +1,51 @@ +/* + Copyright (C) 2015 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +//dependencies var async = require('async'); var util = require('../util.js'); module.exports = function PluginRepositoryModule(pb) { + /** + * @private + * @static + * @readonly + * @property PLUGIN_COLL + * @type {String} + */ var PLUGIN_COLL = 'plugin'; + + /** + * @private + * @static + * @readonly + * @property GLOBAL_SITE + * @type {String} + */ var GLOBAL_SITE = pb.SiteService.GLOBAL_SITE; + + /** + * @private + * @static + * @readonly + * @property SITE_FIELD + * @type {String} + */ var SITE_FIELD = pb.SiteService.SITE_FIELD; /** @@ -202,7 +243,7 @@ module.exports = function PluginRepositoryModule(pb) { } ] }; - hasCorrectIdentifier['$or'][0][pb.DAO.getIdField()] = pluginID; + hasCorrectIdentifier.$or[0][pb.DAO.getIdField()] = pluginID; return hasCorrectIdentifier; } diff --git a/include/service/base_object_service.js b/include/service/base_object_service.js index e0fce7b42..e3ab7a836 100644 --- a/include/service/base_object_service.js +++ b/include/service/base_object_service.js @@ -60,7 +60,7 @@ module.exports = function(pb) { * @property dao * @type {DAO} */ - this.dao = new pb.SiteQueryService({site: context.site, onlyThisSite: context.onlyThisSite}) + this.dao = new pb.SiteQueryService({site: context.site, onlyThisSite: context.onlyThisSite}); } /** diff --git a/include/service/cache_entity_service.js b/include/service/cache_entity_service.js index 8f14b3ec3..1019431d8 100755 --- a/include/service/cache_entity_service.js +++ b/include/service/cache_entity_service.js @@ -85,32 +85,32 @@ module.exports = function CacheEntityServiceModule(pb) { } //make call back - return cb(null, getRightFieldFromValue(result, self.valueField)); + return cb(null, self.getRightFieldFromValue(result, self.valueField)); }); } else { //make call back - return cb(null, getRightFieldFromValue(result, self.valueField)); + return cb(null, self.getRightFieldFromValue(result, self.valueField)); } }); }; - function getRightFieldFromValue(result, valueField) { + CacheEntityService.prototype.getRightFieldFromValue(result, valueField) { var val = result; if (valueField != null){ var rawVal = JSON.parse(result); val = rawVal[valueField]; } else { - try{ - val = JSON.parse(val); - } - catch(e) { - pb.log.error('CacheEntityService: an unparcable value was provided to the cache service. Type=%s Value=%s', self.objType, val); + try{ + val = JSON.parse(val); + } + catch(e) { + pb.log.error('CacheEntityService: an unparcable value was provided to the cache service. Type=%s Value=%s', this.objType, val); + } } - } return val; - } + }; /** * Set a value in the cache diff --git a/include/service/db_entity_service.js b/include/service/db_entity_service.js index ddfeb765d..ad9e9de72 100755 --- a/include/service/db_entity_service.js +++ b/include/service/db_entity_service.js @@ -145,7 +145,7 @@ module.exports = function DbEntityServiceModule(pb) { siteIsGlobal[SITE_FIELD] = GLOBAL_SITE; if(!this.site || this.site === GLOBAL_SITE) { - where['$or'] = [ + where.$or = [ hasNoSite, siteIsGlobal ]; diff --git a/include/service/entities/content/content_view_loader.js b/include/service/entities/content/content_view_loader.js index f460dbeb0..9c2d313e3 100644 --- a/include/service/entities/content/content_view_loader.js +++ b/include/service/entities/content/content_view_loader.js @@ -493,7 +493,7 @@ module.exports = function(pb) { cts.registerLocal('commenter_position', comment.commenter_position ? ', ' + comment.commenter_position : ''); cts.registerLocal('content', comment.content); cts.registerLocal('timestamp', comment.timestamp); - cts.load(self.getDefaultCommentTemplatePath(), cb); + cts.load(this.getDefaultCommentTemplatePath(), cb); }; /** diff --git a/include/service/entities/plugin_service.js b/include/service/entities/plugin_service.js index b8047e1b1..344d72fb4 100755 --- a/include/service/entities/plugin_service.js +++ b/include/service/entities/plugin_service.js @@ -27,6 +27,13 @@ var util = require('../../util.js'); module.exports = function PluginServiceModule(pb) { + /** + * @private + * @static + * @readonly + * @property GLOBAL_SITE + * @type {String} + */ var GLOBAL_SITE = pb.SiteService.GLOBAL_SITE; /** @@ -39,12 +46,20 @@ module.exports = function PluginServiceModule(pb) { * @submodule Entities */ function PluginService(options){ - if(options) { - this.site = options.site; - } else { - this.site = GLOBAL_SITE; + if (!util.isObject(options)) { + options = {}; } + + /** + * @property site + * @type {String} + */ + this.site = options.site || GLOBAL_SITE; + /** + * @property _pluginRepository + * @type {PluginRepository} + */ this._pluginRepository = pb.PluginRepository; //construct settings services diff --git a/include/service/entities/plugin_setting_service.js b/include/service/entities/plugin_setting_service.js index a62436d8a..514192330 100644 --- a/include/service/entities/plugin_setting_service.js +++ b/include/service/entities/plugin_setting_service.js @@ -3,7 +3,22 @@ var util = require('../../util.js'); module.exports = function PluginSettingServiceModule(pb) { + /** + * @private + * @static + * @readonly + * @property GLOBAL_SITE + * @type {String} + */ var GLOBAL_SITE = pb.SiteService.GLOBAL_SITE; + + /** + * @private + * @static + * @readonly + * @property SITE_FIELD + * @type {String} + */ var SITE_FIELD = pb.SiteService.SITE_FIELD; /** @@ -13,14 +28,26 @@ module.exports = function PluginSettingServiceModule(pb) { */ function PluginSettingService(siteUID){ //construct settings services + + /** + * + * @property caching + * @type {Object} + */ this.caching = pb.config.plugins.caching; + + /** + * + * @property site + * @type {String} + */ + this.site = pb.config.multisite.enabled && siteUID ? siteUID : GLOBAL_SITE; - if(pb.config.multisite.enabled && siteUID) { - this.site = siteUID; - } else { - this.site = GLOBAL_SITE; - } - + /** + * + * @property pluginService + * @type {PluginService} + */ this.pluginService = new pb.PluginService({site: this.site}); /** @@ -28,14 +55,28 @@ module.exports = function PluginSettingServiceModule(pb) { * @property pluginSettingsService * @type {SimpleLayeredService} */ - this.pluginSettingsService = genSettingsService('plugin_settings', this.caching.useMemory, this.caching.useCache, 'PluginSettingService', this.site); + this.pluginSettingsService = genSettingsService({ + objType: 'plugin_settings', + useMemory: this.caching.useMemory, + useCache: this.caching.useCache, + serviceName: 'PluginSettingService', + site: this.site, + onlyThisSite: false + }); /** * A setting service that sets and retrieves the settings for plugins * @property pluginSettingsService * @type {SimpleLayeredService} */ - this.themeSettingsService = genSettingsService('theme_settings', this.caching.useMemory, this.caching.useCache, 'ThemeSettingService', this.site); + this.themeSettingsService = genSettingsService({ + objType: 'theme_settings', + useMemory: this.caching.useMemory, + useCache: this.caching.useCache, + serviceName: 'ThemeSettingService', + site: this.site, + onlyThisSite: false + }); } /** @@ -51,8 +92,7 @@ module.exports = function PluginSettingServiceModule(pb) { PluginSettingService.prototype.getSetting = function(settingName, pluginName, cb) { this.getSettings(pluginName, function(err, settings) { if (util.isError(err)) { - cb(err, null); - return; + return cb(err, null); } var val = null; @@ -132,10 +172,10 @@ module.exports = function PluginSettingServiceModule(pb) { //error checking if (!pb.PluginService.validateSettingValue(value)) { - cb(new Error("PluginService: The setting value is required when modifing a theme setting"), false); + return cb(new Error("PluginService: The setting value is required when modifing a theme setting"), false); } if (!pb.validation.validateNonEmptyStr(name, true)) { - cb(new Error("PluginService: The setting name is required when modifing a theme setting"), false); + return cb(new Error("PluginService: The setting name is required when modifing a theme setting"), false); } //retrieve the settings to modify @@ -177,18 +217,15 @@ module.exports = function PluginSettingServiceModule(pb) { //error checking if (!settings) { - cb(new Error("PluginSettingService: The settings object is required when making changes to plugin settings"), false); - return; + return cb(new Error("PluginSettingService: The settings object is required when making changes to plugin settings"), false); } if (!pluginName) { - cb(new Error("PluginSettingService: The plugin name is required when making changes to plugin settings"), false); - return; + return cb(new Error("PluginSettingService: The plugin name is required when making changes to plugin settings"), false); } this.pluginService.isInstalled(pluginName, function(err, isInstalled) { if (util.isError(err) || !isInstalled) { - cb(err, false); - return; + return cb(err, false); } self.pluginSettingsService.set(pluginName, settings, function(err, result) { @@ -212,17 +249,16 @@ module.exports = function PluginSettingServiceModule(pb) { //error checking if (!pb.PluginService.validateSettingValue(value)) { - cb(new Error("PluginService: The setting value is required when modifing a theme setting"), false); + return cb(new Error("PluginService: The setting value is required when modifing a theme setting"), false); } if (!pb.validation.validateNonEmptyStr(name, true)) { - cb(new Error("PluginService: The setting name is required when modifing a theme setting"), false); + return cb(new Error("PluginService: The setting name is required when modifing a theme setting"), false); } //retrieve the settings to modify this.getThemeSettingsBySite(pluginName, function(err, settings) { if (util.isError(err) || !settings) { - cb(err, false); - return; + return cb(err, false); } var wasFound = false; @@ -257,18 +293,15 @@ module.exports = function PluginSettingServiceModule(pb) { //error checking if (!settings) { - cb(new Error("PluginSettingService: The settings object is required when making changes to theme settings"), false); - return; + return cb(new Error("PluginSettingService: The settings object is required when making changes to theme settings"), false); } if (!pluginName) { - cb(new Error("PluginSettingService: The plugin name is required when making changes to theme settings"), false); - return; + return cb(new Error("PluginSettingService: The plugin name is required when making changes to theme settings"), false); } this.pluginService.isInstalled(pluginName, function(err, isInstalled) { if (util.isError(err) || !isInstalled) { - cb(err, false); - return; + return cb(err, false); } self.themeSettingsService.set(pluginName, settings, function(err, result) { @@ -288,8 +321,7 @@ module.exports = function PluginSettingServiceModule(pb) { PluginSettingService.prototype.getThemeSetting = function(settingName, pluginName, cb) { this.getThemeSettings(pluginName, function(err, settings) { if (util.isError(err)) { - cb(err, null); - return; + return cb(err, null); } var val = null; @@ -391,8 +423,8 @@ module.exports = function PluginSettingServiceModule(pb) { var settings = pb.DocumentCreator.create('plugin_settings', baseDoc); //save it - var dao = new pb.DAO(); - dao.save(settings, function(err, result) { + var dao = new pb.DAO(); + dao.save(settings, function(err/*, result*/) { cb(err, !util.isError(err)); }); }); @@ -416,22 +448,19 @@ module.exports = function PluginSettingServiceModule(pb) { //error checking var pluginName = details.uid; if (!details.theme || !details.theme.settings) { - cb(new Error("PluginService: Settings are required when attempting to reset a plugin's theme settings"), false); - return; + return cb(new Error("PluginService: Settings are required when attempting to reset a plugin's theme settings"), false); } //retrieve plugin to prove it exists (plus we need the id) this.pluginService.getPluginBySite(pluginName, function(err, plugin) { if (util.isError(err) || !plugin) { - cb(err, false); - return; + return cb(err, false); } //remove any existing settings self.themeSettingsService.purge(pluginName, function (err, result) { if (util.isError(err) || !result) { - cb(err, false); - return; + return cb(err, false); } //build the object to persist @@ -445,18 +474,28 @@ module.exports = function PluginSettingServiceModule(pb) { var settings = pb.DocumentCreator.create('theme_settings', baseDoc); //save it - var dao = new pb.DAO(); - dao.save(settings, function(err, result) { + var dao = new pb.DAO(); + dao.save(settings, function(err/*, result*/) { cb(err, !util.isError(err)); }); }); }); }; + /** + * @method purgePluginSettings + * @param {String} pluginUid + * @param {Function} cb + */ PluginSettingService.prototype.purgePluginSettings = function(pluginUid, cb) { this.pluginSettingsService.purge(pluginUid, cb); }; + /** + * @method purgeThemeSettings + * @param {String} pluginUid + * @param {Function} cb + */ PluginSettingService.prototype.purgeThemeSettings = function(pluginUid, cb) { this.themeSettingsService.purge(pluginUid, cb); }; @@ -467,33 +506,35 @@ module.exports = function PluginSettingServiceModule(pb) { * * @static * @method genSettingsService - * @param objType The type of object that will be dealt with. (plugin_settings, + * @param {String} opts.objType The type of object that will be dealt with. (plugin_settings, * theme_settings) - * @param useMemory {Boolean} Indicates if the generated layered service should + * @param {Boolean} opts.useMemory Indicates if the generated layered service should * use an in memory service. - * @param useCache {Boolean} Indicates if the generated layered service should + * @param {Boolean} opts.useCache Indicates if the generated layered service should * use a cache service. * @param serviceName The name of the service + * @param {String} opts.site + * @param {Boolean} opts.onlyThisSite * @return {SimpleLayeredService} */ - function genSettingsService(objType, useMemory, useCache, serviceName, site, onlyThisSite) { - + function genSettingsService(opts) { + //add in-memory service var services = []; var options = { - objType: objType, - site: site, - onlyThisSite: onlyThisSite + objType: opts.objType, + site: opts.site, + onlyThisSite: opts.onlyThisSite }; - if (useMemory) { + if (opts.useMemory) { options.timeout = pb.config.plugins.caching.memory_timeout; services.push(new pb.MemoryEntityService(options)); } //add cache service - if (useCache) { + if (opts.useCache) { services.push(new pb.CacheEntityService(options)); } @@ -501,19 +542,49 @@ module.exports = function PluginSettingServiceModule(pb) { options.keyField = 'plugin_uid'; options.valueField = 'settings'; services.push(new pb.DBEntityService(options)); - return new pb.SimpleLayeredService(services, serviceName); + return new pb.SimpleLayeredService(services, opts.serviceName); }; + /** + * @private + * @static + * @method getAdminPluginSettingsService + * @param {PluginSettingService} + * @returns {SimpleLayeredService} + */ function getAdminPluginSettingsService(self) { if(!self.adminPluginSettingsService) { - self.adminPluginSettingsService = genSettingsService('plugin_settings', self.caching.useMemory, self.caching.useCache, 'PluginSettingService', self.site, true); + var opts = { + objType: 'plugin_settings', + useMemory: self.caching.useMemory, + useCache: self.caching.useCache, + serviceName: 'PluginSettingService', + site: self.site, + onlyThisSite: true + }; + self.adminPluginSettingsService = genSettingsService(opts); } return self.adminPluginSettingsService; } + /** + * @private + * @static + * @method getAdminThemeSettingService + * @param {PluginSettingService} + * @returns {SimpleLayeredService} + */ function getAdminThemeSettingsService(self) { if(!self.adminThemeSettingsService) { - self.adminThemeSettingsService = genSettingsService('theme_settings', self.caching.useMemory, self.caching.useCache, 'ThemeSettingService', self.site, true); + var opts = { + objType: 'theme_settings', + useMemory: self.caching.useMemory, + useCache: self.caching.useCache, + serviceName: 'ThemeSettingService', + site: self.site, + onlyThisSite: true + }; + self.adminThemeSettingsService = genSettingsService(opts); } return self.adminThemeSettingsService; } diff --git a/include/service/entities/section_service.js b/include/service/entities/section_service.js index b77286078..9399a9e28 100755 --- a/include/service/entities/section_service.js +++ b/include/service/entities/section_service.js @@ -29,9 +29,8 @@ module.exports = function SectionServiceModule(pb) { * @param {String} site uid * @param {Boolean} onlyThisSite should section service only return value set specifically by site rather than defaulting to global */ - function SectionService(options) { - this.site = pb.SiteService.getCurrentSite(options.site) || GLOBAL_SITE; + this.site = pb.SiteService.getCurrentSite(options.site) || pb.SiteService.GLOBAL_SITE; this.onlyThisSite = options.onlyThisSite || false; this.settings = pb.SettingServiceFactory.getServiceBySite(this.site, this.onlyThisSite); this.siteQueryService = new pb.SiteQueryService({site: this.site, onlyThisSite: this.onlyThisSite}); diff --git a/include/service/entities/site_query_service.js b/include/service/entities/site_query_service.js index 415134f38..fc84b2838 100644 --- a/include/service/entities/site_query_service.js +++ b/include/service/entities/site_query_service.js @@ -15,15 +15,35 @@ along with this program. If not, see . */ +//dependencies +var async = require('async'); +var _ = require('lodash'); + module.exports = function SiteQueryServiceModule(pb) { - "use strict"; - var async = require('async'); - var SITE_FIELD = pb.SiteService.SITE_FIELD; - var GLOBAL_SITE = pb.SiteService.GLOBAL_SITE; - var _ = require('lodash'); - var util = pb.util; - var DAO = pb.DAO; - var SiteService = pb.SiteService; + "use strict"; + + //pb dependencies + var util = pb.util; + var DAO = pb.DAO; + var SiteService = pb.SiteService; + + /** + * @private + * @static + * @readonly + * @property SITE_FIELD + * @type {String} + */ + var SITE_FIELD = pb.SiteService.SITE_FIELD; + + /** + * @private + * @static + * @readonly + * @property GLOBAL_SITE + * @type {String} + */ + var GLOBAL_SITE = pb.SiteService.GLOBAL_SITE; /** * Create an instance of the site query service specific to the given site @@ -31,20 +51,43 @@ module.exports = function SiteQueryServiceModule(pb) { * @module Services * @class SiteQueryService * @constructor + * @extends DAO * @param {Object} options * @param {String} [options.site=GLOBAL_SITE] UID of site, should already be sanitized by SiteService * @param {Boolean} [options.onlyThisSite=false] onlyThisSite for q, return results specific to this site instead of also looking in global */ - function SiteQueryService(options) { - if(options) { - this.siteUId = options.site || GLOBAL_SITE; - this.onlyThisSite = options.onlyThisSite || false; - } - DAO.call(this); - } + function SiteQueryService(options) { + if(!util.isObject(options) { + options = { + site: GLOBAL_SITE, + onlyThisSite: false + }; + } + + /** + * @property siteUid + * @type {String} + */ + this.siteUid = options.site; + + /** + * @property onlyThisSite + * @type {Boolean} + */ + this.onlyThisSite = options.onlyThisSite; - util.inherits(SiteQueryService, DAO); + DAO.call(this); + } + util.inherits(SiteQueryService, DAO); + /** + * @private + * @static + * @method modifyLoadWhere + * @param {String} site + * @param {Object} where + * @returns {Object} + */ function modifyLoadWhere(site, where) { if (pb.config.multisite.enabled) { where = _.clone(where); @@ -62,6 +105,14 @@ module.exports = function SiteQueryServiceModule(pb) { return where; } + /** + * @private + * @static + * @method modifyLoadOptions + * @param {String} site + * @param {Object} options + * @returns {Object} + */ function modifyLoadOptions(site, options) { if (pb.config.multisite.enabled) { var target = _.clone(options); @@ -74,62 +125,107 @@ module.exports = function SiteQueryServiceModule(pb) { return options; } + /** + * @private + * @static + * @method addToOr + * @param {Object} whereClause + * @param {Array} conditions + */ function addToOr(whereClause, conditions) { if ('$or' in whereClause) { var orClause = whereClause.$or; addToAnd(whereClause, [{$or: orClause}, {$or: conditions}]); delete whereClause.$or; - } else { + } + else { whereClause.$or = conditions; } } - function addToAnd(whereClause, conditions) { - if ('$and' in whereClause) { - var andClause = whereClause.$and; - andClause.push.apply(andClause, conditions); - } else { - whereClause.$and = conditions; + /** + * @private + * @static + * @method addToAnd + * @param {Object} whereClause + * @param {Array} conditions + */ + function addToAnd(whereClause, conditions) { + if ('$and' in whereClause) { + var andClause = whereClause.$and; + andClause.push.apply(andClause, conditions); + } + else { + whereClause.$and = conditions; + } } - } - function applySiteOperation(self, callback, delegate) { - if (siteSpecific(self)) { - delegate(self.siteUId, callback); - } else { - delegate(self.siteUId, function (err, cursor) { - if (util.isError(err)) { - callback(err, cursor); - } else { - cursor.count(function (countError, count) { - if (util.isError(countError)) { - callback(countError); - } else if (count) { - callback(err, cursor); - } else { - delegate(GLOBAL_SITE, callback); - } - }); - } - }) + /** + * @private + * @static + * @method applySiteOperation + * @param {SiteQueryService} self + * @param {Function} callback + * @param {Function} delegate + */ + function applySiteOperation(self, callback, delegate) { + if (siteSpecific(self)) { + return delegate(self.siteUid, callback); + } + + delegate(self.siteUid, function (err, cursor) { + if (util.isError(err)) { + return callback(err, cursor); + } + + cursor.count(function (countError, count) { + if (util.isError(countError)) { + callback(countError); + } + else if (count) { + callback(err, cursor); + } + else { + delegate(GLOBAL_SITE, callback); + } + }); + }); } - } - function siteSpecific(self) { - return self.onlyThisSite || isGlobal(self.siteUId); - } + /** + * @private + * @method siteSpecific + * @param {SiteQueryService} self + * @returns {Boolean} + */ + function siteSpecific(self) { + return self.onlyThisSite || isGlobal(self.siteUid); + } - function isGlobal(siteUId) { - return !siteUId || siteUId === GLOBAL_SITE; - } + /** + * @private + * @method isGlobal + * @param {String} siteUid + * @returns {Boolean} + */ + function isGlobal(siteUid) { + return !siteUid || siteUid === GLOBAL_SITE; + } - function modifySave(site, objectToSave) { - if (pb.config.multisite.enabled && !(SITE_FIELD in objectToSave)) { - objectToSave[SITE_FIELD] = site; + /** + * @private + * @method modifySave + * @param {String} site + * @param {Object} objectToSave + * @returns {Object} The object to save + */ + function modifySave(site, objectToSave) { + if (pb.config.multisite.enabled && !(SITE_FIELD in objectToSave)) { + objectToSave[SITE_FIELD] = site; + } + // else do nothing + return objectToSave; } - // else do nothing - return objectToSave; - } /** * Overriding protected method of DAO to achieve site-aware query @@ -155,7 +251,7 @@ module.exports = function SiteQueryServiceModule(pb) { * @param callback */ SiteQueryService.prototype.save = function (dbObj, options, callback) { - dbObj = modifySave(this.siteUId, dbObj); + dbObj = modifySave(this.siteUid, dbObj); DAO.prototype.save.call(this, dbObj, options, callback); }; @@ -209,7 +305,7 @@ module.exports = function SiteQueryServiceModule(pb) { pb.log.error(err); return callback(err); } - self.delete({uid: siteid}, 'site', function(err, result) { + self.delete({uid: siteid}, 'site', function(err/*, result*/) { if (util.isError(err)) { pb.log.error("SiteQueryService: Failed to delete site: %s \n%s", siteid, err.stack); return callback(err); diff --git a/include/service/entities/site_service.js b/include/service/entities/site_service.js index e86d8af9b..cd2d090e5 100644 --- a/include/service/entities/site_service.js +++ b/include/service/entities/site_service.js @@ -29,10 +29,50 @@ module.exports = function SiteServiceModule(pb) { */ function SiteService(){} - SiteService.GLOBAL_SITE = 'global'; // represents default configuration, not actually a full site - SiteService.NO_SITE = 'no-site'; // represents a site that doesn't exist + /** + * represents default configuration, not actually a full site + * @static + * @readonly + * @property GLOBAL_SITE + * @type {String} + */ + SiteService.GLOBAL_SITE = 'global'; + + /** + * represents a site that doesn't exist + * @static + * @readonly + * @property NO_SITE + * @type {String} + */ + SiteService.NO_SITE = 'no-site'; + + /** + * + * @static + * @readonly + * @property SITE_FIELD + * @type {String} + */ SiteService.SITE_FIELD = 'site'; + + /** + * + * @static + * @readonly + * @property SITE_COLLECTION + * @type {String} + */ SiteService.SITE_COLLECTION = 'site'; + + /** + * + * @private + * @static + * @readonly + * @property SITE_COLL + * @type {String} + */ var SITE_COLL = SiteService.SITE_COLLECTION; @@ -243,7 +283,7 @@ module.exports = function SiteServiceModule(pb) { */ SiteService.prototype.createSite = function(site, id, cb) { site.active = false; - site.uid = getUid(); + site.uid = pb.util.uniqueId(); this.isDisplayNameOrHostnameTaken(site.displayName, site.hostname, id, function(err, isTaken, field) { if(util.isError(err) || isTaken) { cb(err, isTaken, field, null); @@ -272,14 +312,17 @@ module.exports = function SiteServiceModule(pb) { var dao = new pb.DAO(); dao.loadByValue('uid', siteUid, 'site', function(err, site) { if(util.isError(err)) { - cb(err, null) - } else if (!site) { + cb(err, null); + } + else if (!site) { cb(new Error('Site not found'), null); - } else if (!site.active) { + } + else if (!site.active) { cb(new Error('Site not active'), null); - } else { + } + else { pb.RequestHandler.activateSite(site); - cb(err, result) + cb(err, site); } }); }; @@ -294,14 +337,17 @@ module.exports = function SiteServiceModule(pb) { var dao = new pb.DAO(); dao.loadByValue('uid', siteUid, 'site', function(err, site) { if(util.isError(err)) { - cb(err, null) - } else if (!site) { + cb(err, null); + } + else if (!site) { cb(new Error('Site not found'), null); - } else if (site.active) { + } + else if (site.active) { cb(new Error('Site not deactivated'), null); - } else { + } + else { pb.RequestHandler.deactivateSite(site); - cb(err, result) + cb(err, site); } }); }; @@ -313,37 +359,31 @@ module.exports = function SiteServiceModule(pb) { */ SiteService.prototype.initSites = function(cb) { if (pb.config.multisite.enabled && !pb.config.multisite.globalRoot) { - cb(new Error("A Global Hostname must be configured with multisite turned on."), false); + return cb(new Error("A Global Hostname must be configured with multisite turned on."), false); } - else { - this.getAllSites(function (err, results) { - if (err) { - cb(err); - } else { - util.forEach(results, function (site) { - pb.RequestHandler.loadSite(site); - }); - // To remain backwards compatible, hostname is siteRoot for single tenant - // and active allows all routes to be hit. - // When multisite, use the configured hostname for global, turn off public facing routes, - // and maintain admin routes (active is false). - pb.RequestHandler.loadSite({ - displayName: pb.SiteService.GLOBAL_SITE, - uid: pb.SiteService.GLOBAL_SITE, - hostname: pb.config.multisite.enabled ? url.parse(pb.config.multisite.globalRoot).host : url.parse(pb.config.siteRoot).host, - active: pb.config.multisite.enabled ? false : true - }); - cb(err, true); - } + this.getAllSites(function (err, results) { + if (err) { + return cb(err); + } + + util.forEach(results, function (site) { + pb.RequestHandler.loadSite(site); }); - } + + // To remain backwards compatible, hostname is siteRoot for single tenant + // and active allows all routes to be hit. + // When multisite, use the configured hostname for global, turn off public facing routes, + // and maintain admin routes (active is false). + pb.RequestHandler.loadSite({ + displayName: pb.SiteService.GLOBAL_SITE, + uid: pb.SiteService.GLOBAL_SITE, + hostname: pb.config.multisite.enabled ? url.parse(pb.config.multisite.globalRoot).host : url.parse(pb.config.siteRoot).host, + active: pb.config.multisite.enabled ? false : true + }); + cb(err, true); + }); }; - // Generate a site unique id. - function getUid() { - return pb.util.uniqueId(); - } - /** * Runs a site activation job when command is received. * @static diff --git a/include/service/entities/user_service.js b/include/service/entities/user_service.js index 931800883..8c5796b43 100755 --- a/include/service/entities/user_service.js +++ b/include/service/entities/user_service.js @@ -160,7 +160,8 @@ module.exports = function(pb) { adminOptions = [ {name: ls.get('READER'), value: pb.SecurityService.ACCESS_USER}, {name: ls.get('WRITER'), value: pb.SecurityService.ACCESS_WRITER}, - {name: ls.get('EDITOR'), value: pb.SecurityService.ACCESS_EDITOR}] + {name: ls.get('EDITOR'), value: pb.SecurityService.ACCESS_EDITOR} + ]; } else { if (session.authentication.user.admin >= pb.SecurityService.ACCESS_MANAGING_EDITOR) { @@ -310,8 +311,8 @@ module.exports = function(pb) { return cb(err, null); } var root = pb.SiteService.getHostWithProtocol(siteInfo.hostname); - var verficationUrl = pb.UrlService.urlJoin(root, '/actions/user/reset_password') - + util.format('?email=%s&code=%s', encodeURIComponent(user.email), encodeURIComponent(passwordReset.verification_code)); + var verficationUrl = pb.UrlService.urlJoin(root, '/actions/user/reset_password') + + util.format('?email=%s&code=%s', encodeURIComponent(user.email), encodeURIComponent(passwordReset.verification_code)); var options = { to: user.email, subject: siteInfo.displayName + ' Password Reset', @@ -519,16 +520,14 @@ module.exports = function(pb) { }; UserService.prototype.determineUserSiteScope = function(accessLevel, siteid) { - if (accessLevel === pb.SecurityService.ACCESS_MANAGING_EDITOR - || accessLevel === pb.SecurityService.ACCESS_ADMINISTRATOR) { + if (accessLevel === pb.SecurityService.ACCESS_MANAGING_EDITOR || + accessLevel === pb.SecurityService.ACCESS_ADMINISTRATOR) { return pb.SiteService.GLOBAL_SITE; } else if (siteid === pb.SiteService.GLOBAL_SITE) { return null; } - else { - return siteid; - } + return siteid; }; /** diff --git a/include/service/jobs/sites/site_activate_job.js b/include/service/jobs/sites/site_activate_job.js index e350d0deb..311b7221d 100644 --- a/include/service/jobs/sites/site_activate_job.js +++ b/include/service/jobs/sites/site_activate_job.js @@ -7,8 +7,9 @@ module.exports = function SiteActivateJobModule(pb) { /** * Job to activate a site in the database to start accepting traffic. - * @extends SiteJobRunner + * @class SiteActivateJob * @constructor + * @extends SiteJobRunner */ function SiteActivateJob(){ SiteActivateJob.super_.call(this); @@ -16,7 +17,7 @@ module.exports = function SiteActivateJobModule(pb) { //initialize this.init(); this.setParallelLimit(1); - }; + } util.inherits(SiteActivateJob, pb.SiteJobRunner); /** @@ -28,8 +29,8 @@ module.exports = function SiteActivateJobModule(pb) { SiteActivateJob.prototype.getInitiatorTasks = function(cb) { var self = this; //progress function - var jobId = self.getId(); - var site = self.getSite(); + var jobId = self.getId(); + var site = self.getSite(); var activateCommand = { jobId: jobId, @@ -62,8 +63,6 @@ module.exports = function SiteActivateJobModule(pb) { */ SiteActivateJob.prototype.getWorkerTasks = function(cb) { var self = this; - - var pluginUid = this.getPluginUid(); var site = this.getSite(); var tasks = [ @@ -101,7 +100,7 @@ module.exports = function SiteActivateJobModule(pb) { } pb.RequestHandler.activateSite(site); - callback(err, result) + callback(err, result); }); }); } diff --git a/include/service/jobs/sites/site_deactivate_job.js b/include/service/jobs/sites/site_deactivate_job.js index 3d7435663..e6231ae47 100644 --- a/include/service/jobs/sites/site_deactivate_job.js +++ b/include/service/jobs/sites/site_deactivate_job.js @@ -7,6 +7,7 @@ module.exports = function SiteDeactivateJobModule(pb) { /** * Job to deactivate a site. + * @class SiteDeactivateJob * @constructor SiteDeactivateJob * @extends SiteJobRunner */ @@ -16,7 +17,7 @@ module.exports = function SiteDeactivateJobModule(pb) { //initialize this.init(); this.setParallelLimit(1); - }; + } util.inherits(SiteDeactivateJob, pb.SiteJobRunner); /** @@ -58,7 +59,6 @@ module.exports = function SiteDeactivateJobModule(pb) { SiteDeactivateJob.prototype.getWorkerTasks = function(cb) { var self = this; - var pluginUid = this.getPluginUid(); var site = this.getSite(); var tasks = [ @@ -76,7 +76,6 @@ module.exports = function SiteDeactivateJobModule(pb) { * @param {Function} cb - callback */ SiteDeactivateJob.prototype.doPersistenceTasks = function(cb) { - var self = this; var siteUid = this.getSite(); var tasks = [ @@ -104,7 +103,7 @@ module.exports = function SiteDeactivateJobModule(pb) { }); } ]; - async.series(tasks, function(err, results) { + async.series(tasks, function(err/*, results*/) { cb(err, !util.isError(err)); }); }; diff --git a/include/service/jobs/sites/site_job_runner.js b/include/service/jobs/sites/site_job_runner.js index a0da629da..8cd962291 100644 --- a/include/service/jobs/sites/site_job_runner.js +++ b/include/service/jobs/sites/site_job_runner.js @@ -11,7 +11,7 @@ module.exports = function SiteJobRunnerModule(pb) { SiteJobRunner.super_.call(this); this.siteService = new pb.SiteService(); - }; + } util.inherits(SiteJobRunner, pb.ClusterJobRunner); /** @@ -28,7 +28,7 @@ module.exports = function SiteJobRunnerModule(pb) { SiteJobRunner.prototype.setSite = function(site) { this.site = site; return this; - } + }; /** * Get the current site of this instance of SiteJobRunner. @@ -36,7 +36,7 @@ module.exports = function SiteJobRunnerModule(pb) { */ SiteJobRunner.prototype.getSite = function() { return this.site; - } + }; /** * Called when the tasks have completed execution and isInitiator = FALSE. The @@ -52,12 +52,11 @@ module.exports = function SiteJobRunnerModule(pb) { SiteJobRunner.prototype.processClusterResults = function(err, results, cb) { if (util.isError(err)) { this.log(err.stack); - cb(err, results); - return; + return cb(err, results); } - var firstErr = undefined; - var success = true; + var firstErr; + var success = true; for (var i = 0; i < results.length; i++) { if (!results[i]) { firstErr = util.format('An error occurred while attempting to execute the job for site [%s]. RESULT=[%s] TASK=[%d]', this.getSite(), util.inspect(results[i]), i); @@ -84,4 +83,4 @@ module.exports = function SiteJobRunnerModule(pb) { //exports return SiteJobRunner; -}; \ No newline at end of file +}; diff --git a/plugins/pencilblue/controllers/actions/admin/sites/deactivate_site.js b/plugins/pencilblue/controllers/actions/admin/sites/deactivate_site.js index 7d47eba74..11e0d82b4 100644 --- a/plugins/pencilblue/controllers/actions/admin/sites/deactivate_site.js +++ b/plugins/pencilblue/controllers/actions/admin/sites/deactivate_site.js @@ -20,11 +20,19 @@ module.exports = function(pb) { //pb dependencies var util = pb.util; - function DeactivateSite(){} - util.inherits(DeactivateSite, pb.BaseController); - - DeactivateSite.prototype.render = function(cb) - { + /** + * @class DeactivateSiteApiController + * @constructor + * @extends BaseController + */ + function DeactivateSiteApiController(){} + util.inherits(DeactivateSiteApiController, pb.BaseController); + + /** + * @method render + * @param {Function} cb + */ + DeactivateSiteApiController.prototype.render = function(cb) { var vars = this.pathVars; var message = this.hasRequiredParams(vars, ['id']); @@ -39,8 +47,8 @@ module.exports = function(pb) { var jobId = siteService.deactivateSite(vars.id); var content = pb.BaseController.apiResponse(pb.BaseController.API_SUCCESS, '', jobId); cb({content: content}); - } + }; //exports - return DeactivateSite; + return DeactivateSiteApiController; }; \ No newline at end of file diff --git a/plugins/pencilblue/controllers/actions/admin/sites/edit_site.js b/plugins/pencilblue/controllers/actions/admin/sites/edit_site.js index 1afe0f197..c92473817 100644 --- a/plugins/pencilblue/controllers/actions/admin/sites/edit_site.js +++ b/plugins/pencilblue/controllers/actions/admin/sites/edit_site.js @@ -47,7 +47,7 @@ module.exports = function EditSiteActionModule(pb) { var siteService = new pb.SiteService(); var dao = new pb.DAO(); dao.loadByValue('uid', siteid, 'site', function(err, data) { - siteService.isDisplayNameOrHostnameTaken(self.body.displayName, self.body.hostname, data._id, function (err, isTaken, field) { + siteService.isDisplayNameOrHostnameTaken(self.body.displayName, self.body.hostname, data._id, function (err, isTaken/*, field*/) { if(isTaken) { return cb({ code: 400, @@ -72,7 +72,7 @@ module.exports = function EditSiteActionModule(pb) { }; EditSiteAction.prototype.getRequiredFields = function() { - return['displayName', 'hostname'] + return['displayName', 'hostname']; }; //exports diff --git a/plugins/pencilblue/controllers/actions/user/resend_verification.js b/plugins/pencilblue/controllers/actions/user/resend_verification.js index dba5356b6..f9d279f5c 100755 --- a/plugins/pencilblue/controllers/actions/user/resend_verification.js +++ b/plugins/pencilblue/controllers/actions/user/resend_verification.js @@ -26,8 +26,9 @@ module.exports = function ResendVerificationModule(pb) { function ResendVerification(){} util.inherits(ResendVerification, pb.FormController); - ResendVerification.prototype.render = function(cb) { - var self = this; + ResendVerification.prototype.render = function(cb) { + var self = this; + var post = this.body; var dao = new pb.SiteQueryService({site: self.site, onlyThisSite: true}); dao.loadByValue('email', post.email, 'user', function(err, user) { @@ -46,32 +47,24 @@ module.exports = function ResendVerificationModule(pb) { return self.formError(self.ls.get('NOT_REGISTERED'), '/user/sign_up', cb); } - user.verification_code = util.uniqueId(); + user.verification_code = util.uniqueId(); - dao.save(user, function(err, result) { + dao.save(user, function(err, result) { if(util.isError(result)) { - self.formError(self.ls.get('ERROR_SAVING'), '/user/resend_verification', cb); - return; + return cb({ + code: 500, + content: pb.BaseController.apiResponse(pb.BaseController.API_ERROR, self.ls.get('ERROR_SAVING')) + }); } - dao.save(user, function(err, result) { - if(util.isError(result)) { - cb({ - code: 500, - content: pb.BaseController.apiResponse(pb.BaseController.API_ERROR, self.ls.get('ERROR_SAVING')) - }); - return; - } - - cb({ - content: pb.BaseController.apiResponse(pb.BaseController.API_SUCCESS, self.ls.get('VERIFICATION_SENT') + user.email) - }); - pb.users.sendVerificationEmail(user, util.cb); - }); + cb({ + content: pb.BaseController.apiResponse(pb.BaseController.API_SUCCESS, self.ls.get('VERIFICATION_SENT') + user.email) + }); + pb.users.sendVerificationEmail(user, util.cb); + }); + }); }); - }); - }); - }; + }; ResendVerification.prototype.getRequiredFields = function() { return ['email']; diff --git a/plugins/pencilblue/controllers/admin/content/pages/manage_pages.js b/plugins/pencilblue/controllers/admin/content/pages/manage_pages.js index a1154e4bd..a342e4cbc 100755 --- a/plugins/pencilblue/controllers/admin/content/pages/manage_pages.js +++ b/plugins/pencilblue/controllers/admin/content/pages/manage_pages.js @@ -88,7 +88,7 @@ module.exports = function(pb) { }); //Log error. Don't return if (util.isError(err)) { - pb.log.error("ManagePages: AdminSubnavService.getWithState callback error. ERROR[%s]", error.stack); + pb.log.error("ManagePages: AdminSubnavService.getWithState callback error. ERROR[%s]", err.stack); } //Only populate pills if we didn't fail else { diff --git a/plugins/pencilblue/controllers/admin/plugins/manage_plugins.js b/plugins/pencilblue/controllers/admin/plugins/manage_plugins.js index a039f36ae..f9cf4830d 100755 --- a/plugins/pencilblue/controllers/admin/plugins/manage_plugins.js +++ b/plugins/pencilblue/controllers/admin/plugins/manage_plugins.js @@ -68,7 +68,7 @@ module.exports = function(pb) { cb({content: result}); }); }); - }) + }); }; ManagePlugins.getSubNavItems = function(key, ls, data) { diff --git a/plugins/pencilblue/controllers/admin/sites/site_form.js b/plugins/pencilblue/controllers/admin/sites/site_form.js index 4e6d7c8a4..97f936736 100644 --- a/plugins/pencilblue/controllers/admin/sites/site_form.js +++ b/plugins/pencilblue/controllers/admin/sites/site_form.js @@ -17,6 +17,7 @@ module.exports = function SiteFormModule(pb) { + //pb dependencies var util = pb.util; /** @@ -27,6 +28,12 @@ module.exports = function SiteFormModule(pb) { function SiteForm(){} util.inherits(SiteForm, pb.BaseController); + /** + * @private + * @static + * @property SUB_NAV_KEY + * @type {String} + */ var SUB_NAV_KEY = 'sites_edit'; /** @@ -40,12 +47,17 @@ module.exports = function SiteFormModule(pb) { var id = this.pathVars.siteid; var dao = new pb.DAO(); dao.loadByValue('uid', id, 'site', function(err, data) { + if (util.isError(err)) { + return cb(err); + } + + var display, host, isActive, uid; if (data) { isNew = false; - var display = data.displayName.toString(); - var host = data.hostname.toString(); - var isActive = data.active; - var uid = data.uid; + display = data.displayName.toString(); + host = data.hostname.toString(); + isActive = data.active; + uid = data.uid; } var angularObjects = pb.ClientJs.getAngularObjects({ diff --git a/plugins/pencilblue/include/routes.js b/plugins/pencilblue/include/routes.js index 2c525595a..542e6b5ed 100644 --- a/plugins/pencilblue/include/routes.js +++ b/plugins/pencilblue/include/routes.js @@ -145,6 +145,7 @@ module.exports = function Routes(pb){ path: "/actions/user/resend_verification", auth_required: false, controller: path.join(pb.config.docRoot, 'plugins', 'pencilblue', 'controllers', 'actions', 'user', 'resend_verification.js'), + request_body: "application/json" }, { method: 'post', diff --git a/plugins/portfolio/controllers/index.js b/plugins/portfolio/controllers/index.js index 2b35769da..4d78e71e7 100755 --- a/plugins/portfolio/controllers/index.js +++ b/plugins/portfolio/controllers/index.js @@ -88,7 +88,7 @@ module.exports = function IndexModule(pb) { self.ts.registerLocal('meta_keywords', homePageKeywords); self.ts.registerLocal('meta_desc', homePageDescription); self.ts.registerLocal('meta_title', self.siteName); - self.ts.registerLocal('meta_lang', localizationLanguage); + self.ts.registerLocal('meta_lang', pb.config.localization.defaultLocale); self.ts.registerLocal('current_url', self.req.url); self.ts.registerLocal('navigation', new pb.TemplateValue(navigation, false)); self.ts.registerLocal('account_buttons', new pb.TemplateValue(accountButtons, false)); diff --git a/plugins/portfolio/portfolio.js b/plugins/portfolio/portfolio.js index 1e503e8cd..63fc17f20 100755 --- a/plugins/portfolio/portfolio.js +++ b/plugins/portfolio/portfolio.js @@ -42,7 +42,6 @@ module.exports = function PortfolioModule(pb) { Portfolio.onStartup = function(cb) { pb.AdminSubnavService.registerFor('plugin_settings', function(navKey, localization, data) { if(data.plugin.uid === 'portfolio') { - var href; return [ { name: 'home_page_settings', From 808e8eaa064de11363e0bed74c36e6b7aaf5583a Mon Sep 17 00:00:00 2001 From: Brian Hyder Date: Tue, 4 Aug 2015 20:14:18 -0400 Subject: [PATCH 560/790] Hopefully, fixed all the breakages --- include/email.js | 2 +- include/service/cache_entity_service.js | 2 +- include/service/entities/site_query_service.js | 2 +- include/service/jobs/plugins/plugin_job_runner.js | 4 ++-- include/service/jobs/plugins/plugin_uninstall_job.js | 2 +- plugins/pencilblue/controllers/index.js | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/include/email.js b/include/email.js index 3d9626c87..f57d37d04 100755 --- a/include/email.js +++ b/include/email.js @@ -32,7 +32,7 @@ module.exports = function EmailServiceModule(pb) { */ function EmailService(options) { if (options) { - this.site = pb.SiteService.getCurrentSite(options.site) || GLOBAL_SITE; + this.site = pb.SiteService.getCurrentSite(options.site) || pb.SiteService.GLOBAL_SITE; this.onlyThisSite = options.onlyThisSite || false; } } diff --git a/include/service/cache_entity_service.js b/include/service/cache_entity_service.js index 1019431d8..9063db578 100755 --- a/include/service/cache_entity_service.js +++ b/include/service/cache_entity_service.js @@ -95,7 +95,7 @@ module.exports = function CacheEntityServiceModule(pb) { }); }; - CacheEntityService.prototype.getRightFieldFromValue(result, valueField) { + CacheEntityService.prototype.getRightFieldFromValue = function(result, valueField) { var val = result; if (valueField != null){ var rawVal = JSON.parse(result); diff --git a/include/service/entities/site_query_service.js b/include/service/entities/site_query_service.js index fc84b2838..195955978 100644 --- a/include/service/entities/site_query_service.js +++ b/include/service/entities/site_query_service.js @@ -57,7 +57,7 @@ module.exports = function SiteQueryServiceModule(pb) { * @param {Boolean} [options.onlyThisSite=false] onlyThisSite for q, return results specific to this site instead of also looking in global */ function SiteQueryService(options) { - if(!util.isObject(options) { + if(!util.isObject(options)) { options = { site: GLOBAL_SITE, onlyThisSite: false diff --git a/include/service/jobs/plugins/plugin_job_runner.js b/include/service/jobs/plugins/plugin_job_runner.js index 22655a2d2..8863dbc82 100644 --- a/include/service/jobs/plugins/plugin_job_runner.js +++ b/include/service/jobs/plugins/plugin_job_runner.js @@ -69,11 +69,11 @@ module.exports = function PluginJobRunnerModule(pb) { this.site = site; this.pluginService = new pb.PluginService({site: site}); return this; - } + }; PluginJobRunner.prototype.getSite = function() { return this.site; - } + }; /** * Called when the tasks have completed execution and isInitiator = FALSE. The diff --git a/include/service/jobs/plugins/plugin_uninstall_job.js b/include/service/jobs/plugins/plugin_uninstall_job.js index 76c62cc66..873d54bf8 100644 --- a/include/service/jobs/plugins/plugin_uninstall_job.js +++ b/include/service/jobs/plugins/plugin_uninstall_job.js @@ -185,7 +185,7 @@ module.exports = function PluginUninstallJobModule(pb) { siteIsGlobal[SITE_FIELD] = GLOBAL_PREFIX; if(!site || site === GLOBAL_PREFIX) { - where['$or'] = [ + where.$or = [ hasNoSite, siteIsGlobal ]; diff --git a/plugins/pencilblue/controllers/index.js b/plugins/pencilblue/controllers/index.js index a3e805bac..ae45f4400 100755 --- a/plugins/pencilblue/controllers/index.js +++ b/plugins/pencilblue/controllers/index.js @@ -65,7 +65,7 @@ module.exports = function IndexModule(pb) { self.ts.registerLocal('meta_desc', data.section.description || meta.description); self.ts.registerLocal('meta_title', data.section.name || meta.title); self.ts.registerLocal('meta_thumbnail', meta.thumbnail); - self.ts.registerLocal('meta_lang', localizationLanguage); + self.ts.registerLocal('meta_lang', pb.config.localization.defaultLocale); self.ts.registerLocal('current_url', self.req.url); self.ts.registerLocal('navigation', new pb.TemplateValue(data.nav.navigation, false)); self.ts.registerLocal('account_buttons', new pb.TemplateValue(data.nav.accountButtons, false)); From 6cda0e2cdb23f71b0200505bb4e52b35a41e0e52 Mon Sep 17 00:00:00 2001 From: Brian Hyder Date: Wed, 5 Aug 2015 19:14:39 -0400 Subject: [PATCH 561/790] Fixed bug in plugin service Added documentation for undocumented function in request handler --- include/http/request_handler.js | 7 ++++ include/service/entities/plugin_service.js | 37 +++++++++++----------- 2 files changed, 26 insertions(+), 18 deletions(-) diff --git a/include/http/request_handler.js b/include/http/request_handler.js index 17548c14f..efeb9d992 100755 --- a/include/http/request_handler.js +++ b/include/http/request_handler.js @@ -750,6 +750,13 @@ module.exports = function RequestHandlerModule(pb) { RequestHandler.routeSupportsMethod(route.themes[site][theme], method); }; + /** + * @static + * @method routeSupportsGlobalTheme + * @param {Object} route + * @param {String} theme + * @param {String} method + */ RequestHandler.routeSupportsGlobalTheme = function(route, theme, method) { return RequestHandler.routeSupportsSiteTheme(route, theme, method, GLOBAL_SITE); }; diff --git a/include/service/entities/plugin_service.js b/include/service/entities/plugin_service.js index 344d72fb4..26a33ed42 100755 --- a/include/service/entities/plugin_service.js +++ b/include/service/entities/plugin_service.js @@ -1131,10 +1131,10 @@ module.exports = function PluginServiceModule(pb) { if (!mainModule) { return cb(new Error('Failed to load main module for plugin '+plugin.uid)); } - if(!ACTIVE_PLUGINS[plugin.site]) { - ACTIVE_PLUGINS[plugin.site] = {}; + if(!ACTIVE_PLUGINS[site]) { + ACTIVE_PLUGINS[site] = {}; } - ACTIVE_PLUGINS[plugin.site][details.uid] = { + ACTIVE_PLUGINS[site][details.uid] = { main_module: mainModule, public_dir: PluginService.getPublicPath(plugin.dirName), permissions: map, @@ -1173,17 +1173,18 @@ module.exports = function PluginServiceModule(pb) { pb.log.error('PluginService:[INIT] Plugin %s failed to start. %s', details.uid, err.stack); } }); - d.run(function () { - if (util.isFunction(mainModule.prototype.onStartup)) { - mainModule = new mainModule(site); + d.run(function () { + if (util.isFunction(mainModule.prototype.onStartup)) { + mainModule = new mainModule(site); } - if (util.isFunction(mainModule.onStartupWithContext)) { - var context = {site: site}; - mainModule.onStartupWithContext(context, startupCallback); - } else { - mainModule.onStartup(startupCallback); - } - function startupCallback(err, didStart) { + if (util.isFunction(mainModule.onStartupWithContext)) { + var context = {site: site}; + mainModule.onStartupWithContext(context, startupCallback); + } + else { + mainModule.onStartup(startupCallback); + } + function startupCallback(err, didStart) { if (util.isError(err)) { throw err; } @@ -1194,13 +1195,13 @@ module.exports = function PluginServiceModule(pb) { clearTimeout(timeoutProtect); callback(err, didStart); } - } + } }); } - else { - pb.log.warn("PluginService: Plugin %s did not provide an 'onStartup' function.", details.uid); - callback(null, false); - } + else { + pb.log.warn("PluginService: Plugin %s did not provide an 'onStartup' function.", details.uid); + callback(null, false); + } }, //load services From b8fd117b461da58ef93bc77a8c36e6fdda832b94 Mon Sep 17 00:00:00 2001 From: Logan Genet Date: Thu, 6 Aug 2015 12:17:07 -0400 Subject: [PATCH 562/790] Fixes issue with Localization not working correctly in 0.5.0 Localization service expected the locale to be in the form language_countrycode, however when loading from the files they come iin as language-country code. When the localization service searched through its record of supported languages, it could not find en-us due to the fact that its storage object had the id en_us. The fix adds an if-statement that converts en-us to en_us (works for any language/country code combination) --- include/localization.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/localization.js b/include/localization.js index b0b4bef4c..277fee3c6 100755 --- a/include/localization.js +++ b/include/localization.js @@ -282,6 +282,8 @@ module.exports = function LocalizationModule(pb) { if (!pb.validation.isNonEmptyStr(locale, true)) { return null; } + if(locale && locale.indexOf('_')<0) + locale = locale.replace('-','_'); return Localization.storage[locale.toLowerCase()] || null; }; From 38aaa97989e4ffd26d5857c45fb632708fff3b89 Mon Sep 17 00:00:00 2001 From: lgenet Date: Thu, 6 Aug 2015 12:42:51 -0400 Subject: [PATCH 563/790] Update localization.js Fixed style issues --- include/localization.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/localization.js b/include/localization.js index 277fee3c6..de344a100 100755 --- a/include/localization.js +++ b/include/localization.js @@ -282,7 +282,7 @@ module.exports = function LocalizationModule(pb) { if (!pb.validation.isNonEmptyStr(locale, true)) { return null; } - if(locale && locale.indexOf('_')<0) + if (locale && locale.indexOf('_') < 0) locale = locale.replace('-','_'); return Localization.storage[locale.toLowerCase()] || null; }; From c418324317464275ddcc15a769fd4f0e26dde62c Mon Sep 17 00:00:00 2001 From: Logan Genet Date: Thu, 6 Aug 2015 15:15:33 -0400 Subject: [PATCH 564/790] Fixed errors between master and 0.5.0 We removed the line that changes the default country code/language combo in the first place. Now when country codes come in as en-us, they will remain en-us instead of being converted to en_us. Also removed my fix to change - to _ in later functions. --- include/localization.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/include/localization.js b/include/localization.js index 277fee3c6..2dbe0a413 100755 --- a/include/localization.js +++ b/include/localization.js @@ -245,7 +245,7 @@ module.exports = function LocalizationModule(pb) { } //convert file name to locale - var locale = file.toLowerCase().substring(0, file.indexOf('.')).replace(/-/g, '_'); + var locale = file.toLowerCase().substring(0, file.indexOf('.')); //Register as a supported language Localization.storage[locale] = obj; @@ -282,8 +282,7 @@ module.exports = function LocalizationModule(pb) { if (!pb.validation.isNonEmptyStr(locale, true)) { return null; } - if(locale && locale.indexOf('_')<0) - locale = locale.replace('-','_'); + return Localization.storage[locale.toLowerCase()] || null; }; From 7aaf45aff5398dcadec2020fa53d5bf0b8f34c4a Mon Sep 17 00:00:00 2001 From: Brian Hyder Date: Thu, 6 Aug 2015 17:35:28 -0400 Subject: [PATCH 565/790] Updated NPM package --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 808a81f69..52d68194d 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,7 @@ "node-uuid": "1.4.3", "node.extend": "1.1.3", "nodemailer": "0.5.3", - "npm": "2.10.1", + "npm": "2.13.3", "process": "0.10.1", "redis": "0.12.1", "sanitize-html": "1.1.7", From 567edea475977a42d200c304a8b853fa264750cf Mon Sep 17 00:00:00 2001 From: Brian Hyder Date: Fri, 7 Aug 2015 22:32:09 -0400 Subject: [PATCH 566/790] First pass at PDF media renderer --- include/dao/db_manager.js | 6 +- include/requirements.js | 1 + include/service/entities/media_service.js | 40 ++- .../media/renderers/audio_media_renderer.js | 12 +- .../renderers/daily_motion_media_renderer.js | 10 + .../media/renderers/image_media_renderer.js | 10 + .../renderers/instagram_media_renderer.js | 10 + .../renderers/kickstarter_media_renderer.js | 10 + .../media/renderers/pdf_media_renderer.js | 295 ++++++++++++++++++ .../renderers/slideshare_media_renderer.js | 10 + .../media/renderers/storify_media_renderer.js | 10 + .../media/renderers/trinket_media_renderer.js | 10 + .../media/renderers/video_media_renderer.js | 10 + .../media/renderers/vimeo_media_renderer.js | 10 + .../media/renderers/vine_media_renderer.js | 10 + .../media/renderers/youtube_media_renderer.js | 10 + .../admin/content/media/media_form.js | 12 + .../admin/content/media/media_form.html | 2 +- 18 files changed, 469 insertions(+), 9 deletions(-) create mode 100644 include/service/media/renderers/pdf_media_renderer.js diff --git a/include/dao/db_manager.js b/include/dao/db_manager.js index 06874a75f..29b9ad1b8 100755 --- a/include/dao/db_manager.js +++ b/include/dao/db_manager.js @@ -154,14 +154,12 @@ module.exports = function DBManagerModule(pb) { this.processIndices = function(procedures, cb) { var self = this; if (!util.isArray(procedures)) { - cb(new Error('The procedures parameter must be an array of Objects')); - return; + return cb(new Error('The procedures parameter must be an array of Objects')); } this.dropUnconfiguredIndices(procedures, function(err) { if(util.isError(err)) { - cb(new Error('DBManager: Error occurred during index check/deletion ERROR[%s]', err.stack)); - return; + return cb(new Error(util.format('DBManager: Error occurred during index check/deletion ERROR[%s]', err.stack))); } self.ensureIndices(procedures, cb); }); diff --git a/include/requirements.js b/include/requirements.js index 245c615aa..50c398aea 100755 --- a/include/requirements.js +++ b/include/requirements.js @@ -236,6 +236,7 @@ module.exports = function PB(config) { pb.media.renderers.TrinketMediaRenderer = require(path.join(config.docRoot, '/include/service/media/renderers/trinket_media_renderer.js'))(pb), pb.media.renderers.StorifyMediaRenderer = require(path.join(config.docRoot, '/include/service/media/renderers/storify_media_renderer.js'))(pb), pb.media.renderers.KickStarterMediaRenderer = require(path.join(config.docRoot, '/include/service/media/renderers/kickstarter_media_renderer.js'))(pb); + pb.media.renderers.PdfMediaRenderer = require(path.join(config.docRoot, '/include/service/media/renderers/pdf_media_renderer.js'))(pb); //providers and service pb.MediaService = require(path.join(config.docRoot, '/include/service/entities/media_service.js'))(pb); diff --git a/include/service/entities/media_service.js b/include/service/entities/media_service.js index 7f46d38d0..832bc3b76 100755 --- a/include/service/entities/media_service.js +++ b/include/service/entities/media_service.js @@ -90,7 +90,8 @@ module.exports = function MediaServiceModule(pb) { pb.media.renderers.SlideShareMediaRenderer, pb.media.renderers.TrinketMediaRenderer, pb.media.renderers.StorifyMediaRenderer, - pb.media.renderers.KickStarterMediaRenderer + pb.media.renderers.KickStarterMediaRenderer, + pb.media.renderers.PdfMediaRenderer ]; /** @@ -846,10 +847,43 @@ module.exports = function MediaServiceModule(pb) { }; /** - * Retrieves the singleton instance of CommandService. + * Provides a mechanism to retrieve all of the supported extension types + * that can be uploaded into the system. + * @static + * @method getSupportedExtensions + * @returns {Array} provides an array of strings + */ + MediaService.getSupportedExtensions = function() { + + var extensions = {}; + REGISTERED_MEDIA_RENDERERS.forEach(function(provider) { + + //for backward compatibility check for existence of extension retrieval + if (!util.isFunction(provider.getSupportedExtensions)) { + pb.log.warn('MediaService: Renderer %s does provide an implementation for getSupportedExtensions', provider.getName()); + return; + } + + //retrieve the extensions + var exts = provider.getSupportedExtensions(); + if (!util.isArray(exts)) { + return; + } + + //add them to the hash + exts.forEach(function(extension) { + extensions[extension] = true; + }); + }); + + return Object.keys(extensions); + }; + + /** + * Retrieves the singleton instance of MediaProvider. * @static * @method getInstance - * @return {CommandService} + * @return {MediaProvider} */ MediaService.getInstance = function() { if (INSTANCE) { diff --git a/include/service/media/renderers/audio_media_renderer.js b/include/service/media/renderers/audio_media_renderer.js index 122057860..1f8bcfe8e 100644 --- a/include/service/media/renderers/audio_media_renderer.js +++ b/include/service/media/renderers/audio_media_renderer.js @@ -26,7 +26,7 @@ module.exports = function AudioMediaRendererModule(pb) { /** * - * @class VideoMediaRenderer + * @class AudioMediaRenderer * @constructor */ function AudioMediaRenderer(){} @@ -84,6 +84,16 @@ module.exports = function AudioMediaRendererModule(pb) { height: "35px" } }); + + /** + * Retrieves the supported extension types for the renderer. + * @static + * @method getSupportedExtensions + * @returns {Array} + */ + AudioMediaRenderer.getSupportedExtensions = function() { + return Object.keys(SUPPORTED); + }; /** * Retrieves the style for the specified type of view diff --git a/include/service/media/renderers/daily_motion_media_renderer.js b/include/service/media/renderers/daily_motion_media_renderer.js index 7d88b0067..260a207c5 100644 --- a/include/service/media/renderers/daily_motion_media_renderer.js +++ b/include/service/media/renderers/daily_motion_media_renderer.js @@ -67,6 +67,16 @@ module.exports = function AudioMediaRendererModule(pb) { height: "270px" } }); + + /** + * Retrieves the supported extension types for the renderer. + * @static + * @method getSupportedExtensions + * @returns {Array} + */ + DailyMotionMediaRenderer.getSupportedExtensions = function() { + return []; + }; /** * Retrieves the style for the specified type of view diff --git a/include/service/media/renderers/image_media_renderer.js b/include/service/media/renderers/image_media_renderer.js index a6fd9507c..698d361dc 100644 --- a/include/service/media/renderers/image_media_renderer.js +++ b/include/service/media/renderers/image_media_renderer.js @@ -86,6 +86,16 @@ module.exports = function ImageMediaRendererModule(pb) { post: { } }); + + /** + * Retrieves the supported extension types for the renderer. + * @static + * @method getSupportedExtensions + * @returns {Array} + */ + ImageMediaRenderer.getSupportedExtensions = function() { + return Object.keys(SUPPORTED); + }; /** * Retrieves the style for the specified type of view diff --git a/include/service/media/renderers/instagram_media_renderer.js b/include/service/media/renderers/instagram_media_renderer.js index 6e3027599..808d31bed 100644 --- a/include/service/media/renderers/instagram_media_renderer.js +++ b/include/service/media/renderers/instagram_media_renderer.js @@ -63,6 +63,16 @@ module.exports = function InstagramMediaRendererModule(pb) { height: "475px" } }); + + /** + * Retrieves the supported extension types for the renderer. + * @static + * @method getSupportedExtensions + * @returns {Array} + */ + InstagramMediaRenderer.getSupportedExtensions = function() { + return []; + }; /** * Retrieves the style for the specified type of view diff --git a/include/service/media/renderers/kickstarter_media_renderer.js b/include/service/media/renderers/kickstarter_media_renderer.js index faf75c355..0e9e67f68 100644 --- a/include/service/media/renderers/kickstarter_media_renderer.js +++ b/include/service/media/renderers/kickstarter_media_renderer.js @@ -64,6 +64,16 @@ module.exports = function KickStarterMediaRendererModule(pb) { } }); + /** + * Retrieves the supported extension types for the renderer. + * @static + * @method getSupportedExtensions + * @returns {Array} + */ + KickStarterMediaRenderer.getSupportedExtensions = function() { + return []; + }; + /** * Retrieves the style for the specified type of view * @static diff --git a/include/service/media/renderers/pdf_media_renderer.js b/include/service/media/renderers/pdf_media_renderer.js new file mode 100644 index 000000000..1f1db56ec --- /dev/null +++ b/include/service/media/renderers/pdf_media_renderer.js @@ -0,0 +1,295 @@ +/* + Copyright (C) 2015 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +//dependencies +var HtmlEncoder = require('htmlencode'); + +module.exports = function(pb) { + + //pb dependencies + var util = pb.util; + var BaseMediaRenderer = pb.media.renderers.BaseMediaRenderer; + + /** + * + * @class PdfMediaRenderer + * @constructor + */ + function PdfMediaRenderer(){} + + /** + * The media type supported by the provider + * @private + * @static + * @property TYPE + * @type {String} + */ + var TYPE = 'pdf'; + + /** + * The list of supported extensions + * @private + * @static + * @readonly + * @property SUPPORTED + * @type {Object} + */ + var SUPPORTED = Object.freeze({ + pdf: { + mime: 'application/pdf' + } + }); + + /** + * Provides the styles used by each type of view + * @private + * @static + * @property STYLES + * @type {Object} + */ + var STYLES = Object.freeze({ + + view: { + 'max-width': "100%", + 'max-height': "500px" + }, + + editor: { + width: "350px", + height: "350px" + }, + + post: { + width: "350px", + height: "350px" + } + }); + + /** + * Retrieves the supported extension types for the renderer. + * @static + * @method getSupportedExtensions + * @returns {Array} + */ + PdfMediaRenderer.getSupportedExtensions = function() { + return Object.keys(SUPPORTED); + }; + + /** + * Retrieves the style for the specified type of view + * @static + * @method getStyle + * @param {String} viewType The view type calling for a styling + * @return {Object} a hash of style properties + */ + PdfMediaRenderer.getStyle = function(viewType) { + return STYLES[viewType] || STYLES.view; + }; + + /** + * Retrieves the supported media types as a hash. + * @static + * @method getSupportedTypes + * @return {Object} + */ + PdfMediaRenderer.getSupportedTypes = function() { + var types = {}; + types[TYPE] = true; + return types; + }; + + /** + * Retrieves the name of the renderer. + * @static + * @method getName + * @return {String} + */ + PdfMediaRenderer.getName = function() { + return 'PdfMediaRenderer'; + }; + + /** + * Determines if the URL to a media object is supported by this renderer + * @static + * @method isSupported + * @param {String} urlStr + * @return {Boolean} TRUE if the URL is supported by the renderer, FALSE if not + */ + PdfMediaRenderer.isSupported = function(urlStr) { + var ext = util.getExtension(urlStr, {lower: true, sep: '/'}); + return SUPPORTED[ext] ? true : false; + }; + + /** + * Gets the specific type of the media resource represented by the provided URL + * @static + * @method getType + * @param {String} urlStr + * @return {String} + */ + PdfMediaRenderer.getType = function(urlStr) { + return PdfMediaRenderer.isSupported(urlStr) ? TYPE : null; + } + + /** + * Retrieves the Font Awesome icon class. It is safe to assume that the type + * provided will be a supported type by the renderer. + * @static + * @method getIcon + * @param {String} type + * @return {String} + */ + PdfMediaRenderer.getIcon = function(type) { + return 'fa-file-pdf-o'; + }; + + /** + * Renders the media resource via the raw URL to the resource + * @static + * @method renderByUrl + * @param {String} urlStr + * @param {Object} [options] + * @param {Object} [options.attrs] A hash of all attributes (excluding style) + * that will be applied to the element generated by the rendering + * @param {Object} [options.style] A hash of all attributes that will be + * applied to the style of the element generated by the rendering. + * @param {Function} cb A callback where the first parameter is an Error if + * occurred and the second is the rendering of the media resource as a HTML + * formatted string + */ + PdfMediaRenderer.renderByUrl = function(urlStr, options, cb) { + PdfMediaRenderer.getMediaId(urlStr, function(err, mediaId) { + if (util.isError(err)) { + return cb(err); + } + PdfMediaRenderer.render({location: mediaId}, options, cb); + }); + }; + + /** + * Renders the media resource via the media descriptor object. It is only + * guaranteed that the "location" property will be available at the time of + * rendering. + * @static + * @method render + * @param {Object} media + * @param {String} media.location The unique resource identifier (only to the + * media type) for the media resource + * @param {Object} [options] + * @param {Object} [options.attrs] A hash of all attributes (excluding style) + * that will be applied to the element generated by the rendering + * @param {Object} [options.style] A hash of all attributes that will be + * applied to the style of the element generated by the rendering. + * @param {Function} cb A callback where the first parameter is an Error if + * occurred and the second is the rendering of the media resource as a HTML + * formatted string + */ + PdfMediaRenderer.render = function(media, options, cb) { + if (util.isFunction(options)) { + cb = options; + options = {}; + } + + //try to look up mime if not provided + var mime = media.mime; + if (!mime) { + + var extension = SUPPORTED[util.getExtension(media.location, {lower: true})]; + if (extension) { + mime = extension.mime; + } + } + + //construct HTML snippet + var embedUrl = PdfMediaRenderer.getEmbedUrl(media.location); + var html = ' ^loc_SELECT_FILE^... - +
    Drop image and video files here
    - + ^tmp_admin=elements=error_success^ + ^tmp_admin=elements=sub_nav^ + ^tmp_admin=elements=search_input^ +
    + +
    +
    +
    + +
    ^tmp_admin=elements=pagination^ - ^tmp_admin=elements=delete_modal^ +
    +^tmp_admin=elements=delete_modal^ ^tmp_angular=admin=content=topics=manage_topics^ ^tmp_admin=footer^ diff --git a/plugins/pencilblue/templates/angular/admin/content/topics/manage_topics.html b/plugins/pencilblue/templates/angular/admin/content/topics/manage_topics.html index 345c5b995..9b0fef024 100644 --- a/plugins/pencilblue/templates/angular/admin/content/topics/manage_topics.html +++ b/plugins/pencilblue/templates/angular/admin/content/topics/manage_topics.html @@ -1,8 +1,13 @@ + diff --git a/public/js/angular/factories/admin/topic.js b/public/js/angular/factories/admin/topic.js new file mode 100644 index 000000000..0fd6246a7 --- /dev/null +++ b/public/js/angular/factories/admin/topic.js @@ -0,0 +1,29 @@ +(function() { + angular.module('pencilblue.factories.admin.topics', []) + .factory('topicFactory', function($http) { + return { + getTopics: function(cb) { + $http.get('/api/admin/content/topics') + .success(function(result) { + cb(null, result.data); + }) + .error(function(error) { + cb(error); + }); + }, + + deleteTopic: function(id, cb) { + $http({ + method: 'DELETE', + url: '/api/admin/content/topics/' + id + }) + .success(function(result) { + cb(null, result); + }) + .error(function(error) { + cb(error); + }); + } + }; + }); +}()); From fadd5bacdbd47b22552ff4db2e84f799fd6fad50 Mon Sep 17 00:00:00 2001 From: Blake Callens Date: Wed, 9 Sep 2015 13:46:14 -0400 Subject: [PATCH 613/790] removed dupe delete topic --- .../admin/content/topics/delete_topic.js | 69 ------------------- 1 file changed, 69 deletions(-) delete mode 100755 plugins/pencilblue/controllers/actions/admin/content/topics/delete_topic.js diff --git a/plugins/pencilblue/controllers/actions/admin/content/topics/delete_topic.js b/plugins/pencilblue/controllers/actions/admin/content/topics/delete_topic.js deleted file mode 100755 index e1b2289cf..000000000 --- a/plugins/pencilblue/controllers/actions/admin/content/topics/delete_topic.js +++ /dev/null @@ -1,69 +0,0 @@ -/* - Copyright (C) 2015 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 - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -module.exports = function(pb) { - - //pb dependencies - var util = pb.util; - - /** - * Deletes a topic - */ - function DeleteTopic(){} - util.inherits(DeleteTopic, pb.BaseController); - - DeleteTopic.prototype.render = function(cb) { - var self = this; - var vars = this.pathVars; - - var message = this.hasRequiredParams(vars, ['id']); - if (message) { - cb({ - code: 400, - content: pb.BaseController.apiResponse(pb.BaseController.API_ERROR, message) - }); - return; - } - - //ensure existence - var dao = new pb.DAO(); - dao.loadById(vars.id, 'topic', function(err, topic) { - if(topic === null) { - cb({ - code: 400, - content: pb.BaseController.apiResponse(pb.BaseController.API_ERROR, self.ls.get('INVALID_UID')) - }); - return; - } - - //delete the topic - dao.deleteById(vars.id, 'topic', function(err, result) { - if(util.isError(err) || result < 1) { - return cb({ - code: 500, - content: pb.BaseController.apiResponse(pb.BaseController.API_ERROR, self.ls.get('ERROR_DELETING')) - }); - } - - cb({content: pb.BaseController.apiResponse(pb.BaseController.API_SUCCESS, topic.name + ' ' + self.ls.get('DELETED'))}); - }); - }); - }; - - //exports - return DeleteTopic; -}; From cfd29f91170f19c41cf10dff5e112c5cdee7a6b9 Mon Sep 17 00:00:00 2001 From: Mark Baird Date: Wed, 9 Sep 2015 14:36:41 -0400 Subject: [PATCH 614/790] Use new API end-points for Admin UI article actions --- .../entities/content/article_service_v2.js | 6 --- .../admin/content/articles/article_form.html | 38 +++++++++++++++---- .../content/articles/manage_articles.html | 4 +- 3 files changed, 32 insertions(+), 16 deletions(-) diff --git a/include/service/entities/content/article_service_v2.js b/include/service/entities/content/article_service_v2.js index 3adf2e071..1cce85801 100644 --- a/include/service/entities/content/article_service_v2.js +++ b/include/service/entities/content/article_service_v2.js @@ -140,12 +140,6 @@ module.exports = function(pb) { dto.url = BaseObjectService.sanitize(dto.url); dto.publish_date = BaseObjectService.getDate(dto.publish_date); - if (util.isArray(dto.meta_keywords)) { - for (var i = 0; i < dto.meta_keywords.length; i++) { - dto.meta_keywords[i] = BaseObjectService.getDate(dto.meta_keywords[i]); - } - } - cb(null); }; diff --git a/plugins/pencilblue/templates/angular/admin/content/articles/article_form.html b/plugins/pencilblue/templates/angular/admin/content/articles/article_form.html index 03359c5d9..bc5318314 100644 --- a/plugins/pencilblue/templates/angular/admin/content/articles/article_form.html +++ b/plugins/pencilblue/templates/angular/admin/content/articles/article_form.html @@ -50,10 +50,11 @@ $scope.getArticleData(draft, function(articleData) { $scope.saving = true; if(articleData._id) { - $http.post('/actions/admin/content/articles/' + $scope.article._id, articleData) + // Update an existing article + $http.put('/api/content/articles/' + $scope.article._id, articleData) .success(function(result) { - $scope.successMessage = result.message; - $scope.article.last_modified = result.data.last_modified; + $scope.successMessage = 'SUCCESS'; + $scope.article.last_modified = result.last_modified; $scope.saving = false; }) .error(function(error, status) { @@ -62,9 +63,10 @@ }); } else { - $http.post('/actions/admin/content/articles', articleData) + // Save a new article + $http.post('/api/content/articles', articleData) .success(function(result) { - $scope.successMessage = result.message; + $scope.successMessage = 'SUCCESS'; $scope.saving = false; if(!result.data._id) { @@ -89,9 +91,9 @@ $scope.article.draft = true; $scope.getArticleData(true, function(articleData) { $scope.saving = true; - $http.post('/actions/admin/content/articles/' + $scope.article._id, articleData) + $http.put('/api/content/articles/' + $scope.article._id, articleData) .success(function(result) { - $scope.article.last_modified = result.data.last_modified; + $scope.article.last_modified = result.last_modified; $timeout($scope.saveArticleDraft, 30000); $scope.saving = false; @@ -112,7 +114,7 @@ $scope.getArticleData = function(draft, cb) { var articleData = angular.copy($scope.article); - articleData.publish_date = (new Date($filter('parsableDate')($scope.article.publish_date))).getTime(); + articleData.publish_date = (new Date($filter('parsableDate')($scope.article.publish_date))).toISOString(); articleData.draft = draft ? 1 : 0; var media = []; @@ -130,6 +132,26 @@ topics.push($scope.article.article_topics[i]._id.toString()); } + // Convert keyword string into array, trimming any excess whitespace and commas + if (typeof articleData.meta_keywords == "string") { + var words = articleData.meta_keywords.trim(); + articleData.meta_keywords = []; + + if (words.length > 0) { + var keywords = words.split(","); + for (var i = 0; i < keywords.length; i++) { + if (keywords[i].trim().length > 0) { + articleData.meta_keywords.push(keywords[i]); + } + } + } + } + + // This sometimes defaults to "undefined" instead of "false" on page load + if (typeof articleData.allow_comments == "undefined") { + articleData.allow_comments = false; + } + articleData.article_media = media; articleData.article_sections = sections; articleData.article_topics = topics; diff --git a/plugins/pencilblue/templates/angular/admin/content/articles/manage_articles.html b/plugins/pencilblue/templates/angular/admin/content/articles/manage_articles.html index 6b902a659..2a6ff4254 100644 --- a/plugins/pencilblue/templates/angular/admin/content/articles/manage_articles.html +++ b/plugins/pencilblue/templates/angular/admin/content/articles/manage_articles.html @@ -83,11 +83,11 @@ } $scope.deleting = true; - $http({method: 'DELETE', url: '/actions/admin/content/articles/' + $scope.objectToDelete._id}) + $http({method: 'DELETE', url: '/api/content/articles/' + $scope.objectToDelete._id}) .success(function(result) { $scope.articles.splice($scope.objectToDeleteIndex, 1); $scope.deleting = false; - $scope.successMessage = result.message; + $scope.successMessage = $scope.objectToDelete.headline + " was deleted"; $scope.paginate(0); $('#confirm_delete_modal').modal('hide'); }) From 372dc051ff4e1c7d09d30ec8072be5b061aec07e Mon Sep 17 00:00:00 2001 From: Mark Baird Date: Wed, 9 Sep 2015 14:49:38 -0400 Subject: [PATCH 615/790] Deprecate old article controllers --- .../controllers/actions/admin/content/articles/edit_article.js | 1 + .../controllers/actions/admin/content/articles/new_article.js | 1 + 2 files changed, 2 insertions(+) diff --git a/plugins/pencilblue/controllers/actions/admin/content/articles/edit_article.js b/plugins/pencilblue/controllers/actions/admin/content/articles/edit_article.js index 811efc45a..8a92371ab 100755 --- a/plugins/pencilblue/controllers/actions/admin/content/articles/edit_article.js +++ b/plugins/pencilblue/controllers/actions/admin/content/articles/edit_article.js @@ -22,6 +22,7 @@ module.exports = function(pb) { /** * Edits an article + * @deprecated Since 0.5.0 */ function EditArticle(){} util.inherits(EditArticle, pb.BaseAdminController); diff --git a/plugins/pencilblue/controllers/actions/admin/content/articles/new_article.js b/plugins/pencilblue/controllers/actions/admin/content/articles/new_article.js index 6b3a37099..212d9bbe7 100755 --- a/plugins/pencilblue/controllers/actions/admin/content/articles/new_article.js +++ b/plugins/pencilblue/controllers/actions/admin/content/articles/new_article.js @@ -22,6 +22,7 @@ module.exports = function(pb) { /** * Creates a new article + * @deprecated Since 0.5.0 */ function NewArticlePostController(){} util.inherits(NewArticlePostController, pb.BaseAdminController); From a4691c871d67368044b94fd2eac88ebf1fddfa1e Mon Sep 17 00:00:00 2001 From: Blake Callens Date: Thu, 10 Sep 2015 09:17:03 -0400 Subject: [PATCH 616/790] removed unnecessary controllers --- .../api/admin/content/topics/delete_topic.js | 69 ----------------- .../api/admin/content/topics/get_topics.js | 75 ------------------- 2 files changed, 144 deletions(-) delete mode 100644 plugins/pencilblue/controllers/api/admin/content/topics/delete_topic.js delete mode 100644 plugins/pencilblue/controllers/api/admin/content/topics/get_topics.js diff --git a/plugins/pencilblue/controllers/api/admin/content/topics/delete_topic.js b/plugins/pencilblue/controllers/api/admin/content/topics/delete_topic.js deleted file mode 100644 index 97f89a1dd..000000000 --- a/plugins/pencilblue/controllers/api/admin/content/topics/delete_topic.js +++ /dev/null @@ -1,69 +0,0 @@ -/* - Copyright (C) 2015 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 - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -module.exports = function(pb) { - - //pb dependencies - var util = pb.util; - - /** - * Deletes a topic - */ - function DeleteTopic(){} - util.inherits(DeleteTopic, pb.BaseController); - - DeleteTopic.prototype.render = function(cb) { - var self = this; - var vars = this.pathVars; - - var message = this.hasRequiredParams(vars, ['id']); - if (message) { - cb({ - code: 400, - content: pb.BaseController.apiResponse(pb.BaseController.API_ERROR, message) - }); - return; - } - - //ensure existence - var dao = new pb.DAO(); - dao.loadById(vars.id, 'topic', function(err, topic) { - if(topic === null) { - cb({ - code: 400, - content: pb.BaseController.apiResponse(pb.BaseController.API_ERROR, self.ls.get('INVALID_UID')) - }); - return; - } - - //delete the topic - dao.deleteById(vars.id, 'topic', function(err, result) { - if(util.isError(err) || result < 1) { - return cb({ - code: 500, - content: pb.BaseController.apiResponse(pb.BaseController.API_ERROR, self.ls.get('ERROR_DELETING')) - }); - } - - cb({content: pb.BaseController.apiResponse(pb.BaseController.API_SUCCESS, topic.name + ' ' + self.ls.get('DELETED'))}); - }); - }); - }; - - //exports - return DeleteTopic; -}; diff --git a/plugins/pencilblue/controllers/api/admin/content/topics/get_topics.js b/plugins/pencilblue/controllers/api/admin/content/topics/get_topics.js deleted file mode 100644 index 09f99047c..000000000 --- a/plugins/pencilblue/controllers/api/admin/content/topics/get_topics.js +++ /dev/null @@ -1,75 +0,0 @@ -/* - Copyright (C) 2015 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 - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . -*/ - -module.exports = function(pb) { - //pb dependencies - var util = pb.util; - - /** - * Interface for managing topics - */ - function GetTopics() {} - util.inherits(GetTopics, pb.BaseAdminController); - - /** - * Initializes the controller - * @method init - * @param {Object} context - * @param {Function} cb - */ - GetTopics.prototype.init = function(context, cb) { - var self = this; - var init = function(err) { - /** - * - * @property service - * @type {TopicService} - */ - self.service = new pb.TopicService(self.getServiceContext()); - - cb(err, true); - }; - GetTopics.super_.prototype.init.apply(this, [context, init]); - }; - - GetTopics.prototype.render = function(cb) { - var self = this; - - this.service.getAll(function(err, topics) { - if(util.isError(err)) { - return cb({ - code: 400, - content: pb.BaseController.apiResponse(pb.BaseController.API_ERROR, err) - }); - } - - //currently, mongo cannot do case-insensitive sorts. We do it manually - //until a solution for https://jira.mongodb.org/browse/SERVER-90 is merged. - topics.sort(function(a, b) { - var x = a.name.toLowerCase(); - var y = b.name.toLowerCase(); - - return ((x < y) ? -1 : ((x > y) ? 1 : 0)); - }); - - cb({content: pb.BaseController.apiResponse(pb.BaseController.API_SUCCESS, '', topics)}); - }); - }; - - //exports - return GetTopics; -}; From cee58b5ace860e6e416a86b01383c43d0ceb810d Mon Sep 17 00:00:00 2001 From: Blake Callens Date: Thu, 10 Sep 2015 09:17:53 -0400 Subject: [PATCH 617/790] cleaned up routes --- plugins/pencilblue/include/routes.js | 21 +-------------------- public/js/angular/factories/admin/topic.js | 4 ++-- 2 files changed, 3 insertions(+), 22 deletions(-) diff --git a/plugins/pencilblue/include/routes.js b/plugins/pencilblue/include/routes.js index ef08828f7..653e724c7 100644 --- a/plugins/pencilblue/include/routes.js +++ b/plugins/pencilblue/include/routes.js @@ -1370,25 +1370,6 @@ module.exports = function Routes(pb){ access_level: pb.SecurityService.ACCESS_WRITER, controller: path.join(pb.config.docRoot, 'plugins/pencilblue/controllers/api/content/page_api_controller.js'), request_body: ['application/json'] - }, - - { - method: 'get', - path: "/api/admin/content/topics", - auth_required: true, - inactive_site_access: true, - access_level: pb.SecurityService.ACCESS_WRITER, - controller: path.join(pb.config.docRoot, 'plugins/pencilblue/controllers/api/admin/content/topics/get_topics.js'), - content_type: 'application/json' - }, - { - method: 'delete', - path: "/api/admin/content/topics/:id", - access_level: pb.SecurityService.ACCESS_EDITOR, - auth_required: true, - inactive_site_access: true, - controller: path.join(pb.config.docRoot, 'plugins/pencilblue/controllers/api/admin/content/topics/delete_topic.js'), - content_type: 'application/json' - }, + } ]; }; diff --git a/public/js/angular/factories/admin/topic.js b/public/js/angular/factories/admin/topic.js index 0fd6246a7..252f59913 100644 --- a/public/js/angular/factories/admin/topic.js +++ b/public/js/angular/factories/admin/topic.js @@ -3,7 +3,7 @@ .factory('topicFactory', function($http) { return { getTopics: function(cb) { - $http.get('/api/admin/content/topics') + $http.get('/api/content/topics') .success(function(result) { cb(null, result.data); }) @@ -15,7 +15,7 @@ deleteTopic: function(id, cb) { $http({ method: 'DELETE', - url: '/api/admin/content/topics/' + id + url: '/api/content/topics/' + id }) .success(function(result) { cb(null, result); From 58440d6c37eb2f44521b669b0672a8080cde8c00 Mon Sep 17 00:00:00 2001 From: Blake Callens Date: Fri, 11 Sep 2015 08:47:41 -0400 Subject: [PATCH 618/790] asynchronous pagination --- controllers/api/base_api_controller.js | 130 +++++++-------- .../admin/content/topics/manage_topics.html | 1 + .../admin/content/topics/manage_topics.html | 149 ++++++++++-------- public/js/angular/factories/admin/topic.js | 6 +- public/js/angular/services/paginate.js | 38 +++-- 5 files changed, 178 insertions(+), 146 deletions(-) diff --git a/controllers/api/base_api_controller.js b/controllers/api/base_api_controller.js index 5e7704e54..e56c8e715 100644 --- a/controllers/api/base_api_controller.js +++ b/controllers/api/base_api_controller.js @@ -21,13 +21,13 @@ module.exports = function(pb) { var util = pb.util; /** - * + * * @class BaseApiController * @constructor */ function BaseApiController(){} util.inherits(BaseApiController, pb.BaseController); - + /** * Indicates if a field should be part of the projection * @static @@ -36,7 +36,7 @@ module.exports = function(pb) { * @type {String} */ BaseApiController.FIELD_ON = '1'; - + /** * Indicates if a field should be part of the projection * @static @@ -57,18 +57,18 @@ module.exports = function(pb) { }; /** - * Retrieves one or more resources from a collection. The endpoint + * Retrieves one or more resources from a collection. The endpoint * supports the following query string parameters: *
      - *
    • $select - A comma separated list of key/value pairs where a value - * of 1 indicates the field will be returned and 0 indicates the + *
    • $select - A comma separated list of key/value pairs where a value + * of 1 indicates the field will be returned and 0 indicates the * absensence. $select=_id=1,name=1,description=0
    • - *
    • $order - A comma separated list of key/value pairs where a value of - * 1 indicates ascending a value of 0 or less indicates descending. + *
    • $order - A comma separated list of key/value pairs where a value of + * 1 indicates ascending a value of 0 or less indicates descending. * $order=name=1,created_date=0
    • - *
    • $limit - An integer representing the maximum number of results to + *
    • $limit - An integer representing the maximum number of results to * return
    • - *
    • $offset - An integer representing the number of items to skip before + *
    • $offset - An integer representing the number of items to skip before * returning results
    • *
    • $where - Currently not supported
    • *
    @@ -79,16 +79,16 @@ module.exports = function(pb) { var options = this.processQuery(); this.service.getAllWithCount(options, this.handleGet(cb)); }; - + /** - * Prcoess the query string and builds the options for passing to the + * Prcoess the query string and builds the options for passing to the * object service * @method processQuery * @return {Object} The options representing the query */ BaseApiController.prototype.processQuery = function() { var q = this.query; - + //get limit & offset var limit = parseInt(q.$limit); if (isNaN(limit)) { @@ -98,23 +98,23 @@ module.exports = function(pb) { if (isNaN(offset)) { offset = null; } - + //process select var selectResult = this.processSelect(q.$select); - + //process the order var orderResult = this.processOrder(q.$order); - + //process where var whereResult = this.processWhere(q); - - //when failures occur combine them into a one big error and throw it to + + //when failures occur combine them into a one big error and throw it to //stop execution var failures = selectResult.failures.concat(orderResult.failures).concat(whereResult.failures); if (failures.length > 0) { throw pb.BaseObjectService.validationError(failures); } - + return { select: selectResult.select, where: whereResult.where, @@ -123,7 +123,7 @@ module.exports = function(pb) { offset: offset }; }; - + /** * Processes the query string to develop the where clause for the query request * @method processWhere @@ -133,14 +133,14 @@ module.exports = function(pb) { BaseApiController.prototype.processWhere = function(q) { var where = null; var failures = []; - + //TODO provide a default implementation return { where: where, failures: failures }; }; - + /** * Processes the value of a $order query string variable * @method processOrder @@ -152,34 +152,34 @@ module.exports = function(pb) { var failures = []; if (pb.ValidationService.isNonEmptyStr(rawOrder, true)) { - + order = []; var orderPieces = rawOrder.split(','); orderPieces.forEach(function(rawStatement) { - + var statement = rawStatement.split('='); - if (statement.length === 2 && - pb.ValidationService.isNonEmptyStr(statement[0], true) && + if (statement.length === 2 && + 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); } else { - + var msg = util.format('An invalid order statement was provided: %s=%s', statement[0], statement[1]); failures.push(pb.BaseObjectService.validationFailure('$order', msg)); } }); - } - + } + return { order: order, failures: failures }; }; - + /** * Processes the value of a $select query string variable * @method processSelect @@ -189,34 +189,34 @@ module.exports = function(pb) { BaseApiController.prototype.processSelect = function(rawSelect) { var select = null; var failures = []; - + if (pb.ValidationService.isNonEmptyStr(rawSelect, true)) { - + select = {}; var selectPieces = rawSelect.split(','); selectPieces.forEach(function(rawStatement) { - + var statement = rawStatement.split('='); - if (statement.length === 2 && - pb.ValidationService.isNonEmptyStr(statement[0], true) && + if (statement.length === 2 && + pb.ValidationService.isNonEmptyStr(statement[0], true) && (statement[1] === BaseApiController.FIELD_ON || statement[1] === BaseApiController.FIELD_OFF)) { - + select[statement[0]] = parseInt(statement[1]); } else { - + var msg = util.format('An invalid select statement was provided: %s=%s', statement[0], statement[1]); failures.push(pb.BaseObjectService.validationFailure('$select', msg)); } }); } - + return { select: select, failures: failures }; }; - + /** * Creates a resource * @method post @@ -226,21 +226,21 @@ module.exports = function(pb) { var dto = this.getPostDto(); this.service.save(dto, this.handleSave(cb, true)); }; - + /** - * Retrieves the request DTO. The function ensures that the id field is + * Retrieves the request DTO. The function ensures that the id field is * removed. * @method getPostDto - * @return {Object} + * @return {Object} */ BaseApiController.prototype.getPostDto = function() { var dto = this.body || {}; delete dto[pb.DAO.getIdField()]; return dto; }; - + /** - * Updates a resource with the ID specified in the body of the request. + * Updates a resource with the ID specified in the body of the request. * @method put * @param {Function} cb */ @@ -250,7 +250,7 @@ module.exports = function(pb) { }; /** - * Deletes the resource with the specified ID from the URI path ":id". + * Deletes the resource with the specified ID from the URI path ":id". * @method delete * @param {Function} cb */ @@ -258,11 +258,11 @@ module.exports = function(pb) { var id = this.pathVars.id; this.service.deleteById(id, this.handleDelete(cb)); }; - + /** - * Creates a handler that can be used to prepare a response for GET - * operations. When the result is NULL a 404 is generated. Otherwise a 200 - * response along with the object serialized as JSON is the generated + * Creates a handler that can be used to prepare a response for GET + * operations. When the result is NULL a 404 is generated. Otherwise a 200 + * response along with the object serialized as JSON is the generated * response * @method handleDelete * @param {Function} cb @@ -275,19 +275,19 @@ module.exports = function(pb) { return cb(err); } else if (util.isNullOrUndefined(obj)) { - return self.notFound(cb); + return self.notFound(cb); } - + cb({ content: obj }); }; }; - + /** - * Creates a handler that can be used to prepare a response for POST or PUT - * operations. Upon successful create a 201 status code is returned. Upon - * successful update a 200 status code is returned. Validation errors are + * Creates a handler that can be used to prepare a response for POST or PUT + * operations. Upon successful create a 201 status code is returned. Upon + * successful update a 200 status code is returned. Validation errors are * expected to be handled by the global error handler and should return 400 * @method handleSave * @param {Function} cb @@ -298,17 +298,17 @@ module.exports = function(pb) { if (util.isError(err)) { return cb(err); } - + cb({ content: obj, code: isCreate ? 201: 200 }); }; }; - + /** - * Creates a handler that can be used to prepare a response for DELETE - * operations. When the item cannot be found a 404 is issued. When the + * Creates a handler that can be used to prepare a response for DELETE + * operations. When the item cannot be found a 404 is issued. When the * object is successfully delete a 204 status is provided * @method handleDelete * @param {Function} cb @@ -321,18 +321,18 @@ module.exports = function(pb) { return cb(err); } else if (util.isNullOrUndefined(obj)) { - return self.reqHandler.serve404(); + return self.reqHandler.serve404(); } - + cb({ content: '', code: 204 }); }; }; - + /** - * Calls back to the request handler with an error representing a 404 not + * Calls back to the request handler with an error representing a 404 not * found * @method notFound */ @@ -344,4 +344,4 @@ module.exports = function(pb) { //exports return BaseApiController; -}; \ No newline at end of file +}; diff --git a/plugins/pencilblue/templates/admin/content/topics/manage_topics.html b/plugins/pencilblue/templates/admin/content/topics/manage_topics.html index 20a171f97..2e61488da 100755 --- a/plugins/pencilblue/templates/admin/content/topics/manage_topics.html +++ b/plugins/pencilblue/templates/admin/content/topics/manage_topics.html @@ -13,6 +13,7 @@ +
    ^tmp_admin=elements=pagination^ diff --git a/plugins/pencilblue/templates/angular/admin/content/topics/manage_topics.html b/plugins/pencilblue/templates/angular/admin/content/topics/manage_topics.html index 9b0fef024..39f91b19d 100644 --- a/plugins/pencilblue/templates/angular/admin/content/topics/manage_topics.html +++ b/plugins/pencilblue/templates/angular/admin/content/topics/manage_topics.html @@ -2,88 +2,99 @@ diff --git a/public/js/angular/factories/admin/topic.js b/public/js/angular/factories/admin/topic.js index 252f59913..d60af4207 100644 --- a/public/js/angular/factories/admin/topic.js +++ b/public/js/angular/factories/admin/topic.js @@ -2,10 +2,10 @@ angular.module('pencilblue.factories.admin.topics', []) .factory('topicFactory', function($http) { return { - getTopics: function(cb) { - $http.get('/api/content/topics') + getTopics: function(limit, offset, cb) { + $http.get('/api/content/topics?$limit=' + limit + '&$offset=' + offset) .success(function(result) { - cb(null, result.data); + cb(null, result.data, result.total); }) .error(function(error) { cb(error); diff --git a/public/js/angular/services/paginate.js b/public/js/angular/services/paginate.js index 140207e53..f5de65153 100644 --- a/public/js/angular/services/paginate.js +++ b/public/js/angular/services/paginate.js @@ -1,34 +1,54 @@ angular.module('paginate', []) .service('paginationService', function() { - this.paginate = function(items, testIndex, limit, cb) { + this.paginate = function(items, offset, limit, cb) { var itemCount = 0; for(var i = 0; i < items.length; i++) { if(!items[i].hidden) { itemCount++; - items[i].paginated = itemCount <= testIndex * limit || itemCount > testIndex * limit + limit; + items[i].paginated = itemCount <= offset * limit || itemCount > offset * limit + limit; } else { items[i].paginated = true; } } - var pageLimit = Math.ceil(itemCount / limit); + var pages = this.getPageArray(limit, itemCount); + + cb(items, pages); + }; + + this.getPageArray = function(offset, limit, total) { + var pageLimit = Math.ceil(total / limit); var pages = []; for(i = 0; i < pageLimit; i++) { - pages.push({active: i === testIndex}); + pages.push({active: i === offset}); } - cb(items, pages); + return pages; + }; + + this.paginationValid = function(newOffset, currentOffset, pageCount) { + if(newOffset === currentOffset) { + return false; + } + if(newOffset !== 0 && newOffset >= pageCount) { + return false; + } + if(newOffset < 0) { + return false; + } + + return true; }; - this.pageButtonVisible = function(testIndex, pageIndex, pageLimit, maxButtons) { + this.pageButtonVisible = function(offset, pageIndex, pageLimit, maxButtons) { if(typeof maxButtons === 'undefined') { maxButtons = 5; } if(pageIndex <= Math.floor(maxButtons / 2)) { - if(testIndex < maxButtons) { + if(offset < maxButtons) { return true; } @@ -36,7 +56,7 @@ angular.module('paginate', []) } if(pageIndex >= pageLimit - Math.ceil(maxButtons / 2)) { - if(testIndex > pageLimit - (maxButtons + 1)) { + if(offset > pageLimit - (maxButtons + 1)) { return true; } @@ -48,7 +68,7 @@ angular.module('paginate', []) upperLimit -= 1; } - if(testIndex >= pageIndex - Math.floor(maxButtons / 2) && testIndex <= pageIndex + upperLimit) { + if(offset >= pageIndex - Math.floor(maxButtons / 2) && offset <= pageIndex + upperLimit) { return true; } From 90e7b405cca22243529dfbcaf44d8eb8d5a4516e Mon Sep 17 00:00:00 2001 From: Blake Callens Date: Fri, 11 Sep 2015 09:38:39 -0400 Subject: [PATCH 619/790] asynchronous search --- .../admin/content/topics/import_topics.js | 6 +-- .../api/content/topic_api_controller.js | 33 ++++++++++--- .../admin/content/topics/manage_topics.html | 48 ++++++++++++++----- public/js/angular/factories/admin/topic.js | 10 ++++ public/js/angular/services/paginate.js | 2 +- 5 files changed, 76 insertions(+), 23 deletions(-) diff --git a/plugins/pencilblue/controllers/actions/admin/content/topics/import_topics.js b/plugins/pencilblue/controllers/actions/admin/content/topics/import_topics.js index 4e0ac333d..9510dcd38 100755 --- a/plugins/pencilblue/controllers/actions/admin/content/topics/import_topics.js +++ b/plugins/pencilblue/controllers/actions/admin/content/topics/import_topics.js @@ -21,10 +21,10 @@ var formidable = require('formidable'); var async = require('async'); module.exports = function(pb) { - + //pb dependencies var util = pb.util; - + /** * Imports a CSV of topics * @class ImportTopics @@ -91,7 +91,7 @@ module.exports = function(pb) { }); } - cb({content: pb.BaseController.apiResponse(pb.BaseController.API_SUCCESS, loc.topics.TOPICS_CREATED)}); + cb({content: pb.BaseController.apiResponse(pb.BaseController.API_SUCCESS, self.ls.get('TOPICS_CREATED'))}); }); }; diff --git a/plugins/pencilblue/controllers/api/content/topic_api_controller.js b/plugins/pencilblue/controllers/api/content/topic_api_controller.js index fee198892..c6a21321f 100644 --- a/plugins/pencilblue/controllers/api/content/topic_api_controller.js +++ b/plugins/pencilblue/controllers/api/content/topic_api_controller.js @@ -23,14 +23,14 @@ module.exports = function(pb) { var SecurityService = pb.SecurityService; /** - * + * * @class TopicApiController * @constructor * @extends BaseApiController */ function TopicApiController(){} util.inherits(TopicApiController, pb.BaseApiController); - + /** * Initializes the controller * @method init @@ -40,19 +40,40 @@ module.exports = function(pb) { TopicApiController.prototype.init = function(context, cb) { var self = this; var init = function(err) { - + /** - * + * * @property service * @type {TopicService} */ self.service = new TopicService(self.getServiceContext()); - + cb(err, true); }; TopicApiController.super_.prototype.init.apply(this, [context, init]); }; + TopicApiController.prototype.processWhere = function(q) { + var where = null; + var failures = []; + + //build query & get results + var search = q.q; + if (pb.ValidationService.isNonEmptyStr(search, true)) { + + var patternStr = ".*" + util.escapeRegExp(search) + ".*"; + var pattern = new RegExp(patternStr, "i"); + where = { + name: pattern + }; + } + + return { + where: where, + failures: failures + }; + }; + //exports return TopicApiController; -}; \ No newline at end of file +}; diff --git a/plugins/pencilblue/templates/angular/admin/content/topics/manage_topics.html b/plugins/pencilblue/templates/angular/admin/content/topics/manage_topics.html index 39f91b19d..ac5f4e15d 100644 --- a/plugins/pencilblue/templates/angular/admin/content/topics/manage_topics.html +++ b/plugins/pencilblue/templates/angular/admin/content/topics/manage_topics.html @@ -31,32 +31,54 @@ $scope.topics = topics; $scope.paginationTotal = total; - $scope.paginate($scope.paginationIndex); cb(topics, total); }); }; $scope.search = function() { - searchService.search($scope.searchText, $scope.topics, ['name'], function(topics) { - $scope.topics = topics; - $scope.paginate(0); - }); - } + $scope.paginate(0, true); + }; $scope.clearSearch = function() { $scope.searchText = ''; - $scope.search(); - } + $scope.paginate(0, true); + }; - $scope.paginate = function(paginationIndex) { - if(!paginationService.paginationValid(paginationIndex, $scope.paginationIndex, $scope.paginationPages.length)) { + $scope.queryTopics = function(cb) { + if(!cb) { + cb = function() {}; + } + + $scope.topics = null; + + topicFactory.searchTopics($scope.searchText, $scope.paginationLimit, $scope.paginationIndex, function(error, topics, total) { + if(error) { + $scope.errorMessage = error.message; + return; + } + + $scope.topics = topics; + $scope.paginationTotal = total; + cb(topics, total); + }); + }; + + $scope.paginate = function(paginationIndex, force) { + if(!force && !paginationService.paginationValid(paginationIndex, $scope.paginationIndex, $scope.paginationPages.length)) { return; } $scope.paginationIndex = paginationIndex; - $scope.getTopics(function() { - $scope.paginationPages = paginationService.getPageArray(paginationIndex, $scope.paginationLimit, $scope.paginationTotal); - }); + if($scope.searchText.length) { + $scope.queryTopics(function() { + $scope.paginationPages = paginationService.getPageArray(paginationIndex, $scope.paginationLimit, $scope.paginationTotal); + }); + } + else { + $scope.getTopics(function() { + $scope.paginationPages = paginationService.getPageArray(paginationIndex, $scope.paginationLimit, $scope.paginationTotal); + }); + } }; $scope.pageButtonVisible = function(testIndex) { diff --git a/public/js/angular/factories/admin/topic.js b/public/js/angular/factories/admin/topic.js index d60af4207..df373fc01 100644 --- a/public/js/angular/factories/admin/topic.js +++ b/public/js/angular/factories/admin/topic.js @@ -12,6 +12,16 @@ }); }, + searchTopics: function(query, limit, offset, cb) { + $http.get('/api/content/topics?$limit=' + limit + '&$offset=' + offset + '&q=' + query) + .success(function(result) { + cb(null, result.data, result.total); + }) + .error(function(error) { + cb(error); + }); + }, + deleteTopic: function(id, cb) { $http({ method: 'DELETE', diff --git a/public/js/angular/services/paginate.js b/public/js/angular/services/paginate.js index f5de65153..003513bc3 100644 --- a/public/js/angular/services/paginate.js +++ b/public/js/angular/services/paginate.js @@ -74,4 +74,4 @@ angular.module('paginate', []) return false; }; -}) +}); From 2432f1075629d594f62717bab4edd8db7336c3e8 Mon Sep 17 00:00:00 2001 From: Mark Baird Date: Fri, 11 Sep 2015 10:35:19 -0400 Subject: [PATCH 620/790] Call sanitize() on meta_keywords values. --- include/service/entities/content/article_service_v2.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/service/entities/content/article_service_v2.js b/include/service/entities/content/article_service_v2.js index 1cce85801..d347fbbb2 100644 --- a/include/service/entities/content/article_service_v2.js +++ b/include/service/entities/content/article_service_v2.js @@ -140,6 +140,12 @@ module.exports = function(pb) { dto.url = BaseObjectService.sanitize(dto.url); dto.publish_date = BaseObjectService.getDate(dto.publish_date); + if (util.isArray(dto.meta_keywords)) { + for (var i = 0; i < dto.meta_keywords.length; i++) { + dto.meta_keywords[i] = BaseObjectService.sanitize(dto.meta_keywords[i]); + } + } + cb(null); }; From 4e9cd5b6c7995568a00784560e61ba654a857fa8 Mon Sep 17 00:00:00 2001 From: Mark Baird Date: Fri, 11 Sep 2015 11:17:28 -0400 Subject: [PATCH 621/790] Use new API end-points for Admin UI page actions Updated both the default page form and the Portfolio theme's custom page form. Fixed a few bugs in page_service.js where it was looking for 'article_*' object properties instead of 'page_*' properties, which was causing validation errors. --- .../service/entities/content/page_service.js | 16 ++++---- .../actions/admin/content/pages/edit_page.js | 1 + .../actions/admin/content/pages/new_page.js | 1 + .../admin/content/articles/article_form.html | 10 ++--- .../admin/content/pages/manage_pages.html | 4 +- .../admin/content/pages/page_form.html | 39 ++++++++++++++----- .../admin/content/pages/page_form.html | 39 ++++++++++++++----- 7 files changed, 74 insertions(+), 36 deletions(-) diff --git a/include/service/entities/content/page_service.js b/include/service/entities/content/page_service.js index ef97ef206..a21c1944c 100644 --- a/include/service/entities/content/page_service.js +++ b/include/service/entities/content/page_service.js @@ -72,7 +72,7 @@ module.exports = function(pb) { /** * Retrieves an instance of a content renderer * @method getRenderer - * @return {ArticleRenderer} + * @return {PageRenderer} */ PageService.prototype.getRenderer = function() { return new pb.PageRenderer(); @@ -110,7 +110,7 @@ module.exports = function(pb) { if (util.isArray(dto.meta_keywords)) { for (var i = 0; i < dto.meta_keywords.length; i++) { - dto.meta_keywords[i] = BaseObjectService.getDate(dto.meta_keywords[i]); + dto.meta_keywords[i] = BaseObjectService.sanitize(dto.meta_keywords[i]); } } @@ -133,8 +133,8 @@ module.exports = function(pb) { obj.author = dto.author; obj.publish_date = dto.publish_date; obj.meta_keywords = dto.meta_keywords; - obj.page_media = dto.article_media; - obj.page_topics = dto.article_topics; + obj.page_media = dto.page_media; + obj.page_topics = dto.page_topics; obj.url = dto.url; obj.template = dto.template; obj.headline = dto.headline; @@ -145,7 +145,7 @@ module.exports = function(pb) { obj.meta_desc = dto.meta_desc; obj.thumbnail = dto.thumbnail; obj.draft = dto.draft; - obj.page_layout = dto.article_layout; + obj.page_layout = dto.page_layout; cb(null); }; @@ -188,7 +188,7 @@ module.exports = function(pb) { if (!util.isArray(obj.page_media)) { if (!util.isNullOrUndefined(obj.page_media)) { - errors.push(BaseObjectService.validationFailure('page_media', 'Article Media must be an array')); + errors.push(BaseObjectService.validationFailure('page_media', 'Page Media must be an array')); } } else { @@ -202,7 +202,7 @@ module.exports = function(pb) { if (!util.isArray(obj.page_topics)) { if (!util.isNullOrUndefined(obj.page_topics)) { - errors.push(BaseObjectService.validationFailure('page_topics', 'Article topics must be an array')); + errors.push(BaseObjectService.validationFailure('page_topics', 'Page topics must be an array')); } } else { @@ -250,7 +250,7 @@ module.exports = function(pb) { errors.push(BaseObjectService.validationFailure('draft', 'An invalid draft value was provided. Must be 1 or 0')); } - if (!ValidationService.isNonEmptyStr(obj.article_layout, true)) { + if (!ValidationService.isNonEmptyStr(obj.page_layout, true)) { errors.push(BaseObjectService.validationFailure('page_layout', 'The layout is required')); } diff --git a/plugins/pencilblue/controllers/actions/admin/content/pages/edit_page.js b/plugins/pencilblue/controllers/actions/admin/content/pages/edit_page.js index 90c9c7efb..d27bd2b9f 100755 --- a/plugins/pencilblue/controllers/actions/admin/content/pages/edit_page.js +++ b/plugins/pencilblue/controllers/actions/admin/content/pages/edit_page.js @@ -22,6 +22,7 @@ module.exports = function(pb) { /** * Edits a page + * @deprecated Since 0.5.0 * @cclass EditPagePostController * @constructor * @extends BaseAdminController diff --git a/plugins/pencilblue/controllers/actions/admin/content/pages/new_page.js b/plugins/pencilblue/controllers/actions/admin/content/pages/new_page.js index 50e36bacb..0c402ec62 100755 --- a/plugins/pencilblue/controllers/actions/admin/content/pages/new_page.js +++ b/plugins/pencilblue/controllers/actions/admin/content/pages/new_page.js @@ -22,6 +22,7 @@ module.exports = function(pb) { /** * Creates a new page + * @deprecated Since 0.5.0 * @class NewPagePostController * @constructor * @extends BaseAdminController diff --git a/plugins/pencilblue/templates/angular/admin/content/articles/article_form.html b/plugins/pencilblue/templates/angular/admin/content/articles/article_form.html index bc5318314..95ddb0dbf 100644 --- a/plugins/pencilblue/templates/angular/admin/content/articles/article_form.html +++ b/plugins/pencilblue/templates/angular/admin/content/articles/article_form.html @@ -13,7 +13,7 @@ $scope.article.publish_date = $filter('date')($scope.article.publish_date || new Date(), 'MM-dd-yyyy HH:mm'); $scope.article.article_media = $scope.article.article_media || []; $scope.layout = $sce.trustAsHtml($scope.article.article_layout); - $scope.article.meta_keywords = $scope.article.meta_keywords ? $scope.article.meta_keywords.join(',') : ''; + $scope.article.meta_keywords = $scope.article.meta_keywords ? $scope.article.meta_keywords.join(', ') : ''; $scope.editingObject = $scope.article; $scope.variablePrefix = 'article'; @@ -141,16 +141,14 @@ var keywords = words.split(","); for (var i = 0; i < keywords.length; i++) { if (keywords[i].trim().length > 0) { - articleData.meta_keywords.push(keywords[i]); + articleData.meta_keywords.push(keywords[i].trim()); } } } } // This sometimes defaults to "undefined" instead of "false" on page load - if (typeof articleData.allow_comments == "undefined") { - articleData.allow_comments = false; - } + articleData.allow_comments = articleData.allow_comments ? true : false; articleData.article_media = media; articleData.article_sections = sections; @@ -166,7 +164,7 @@ $window.open('/preview/article/' + $scope.article._id); } }); - } + }; $('#publish_date').datetimepicker({format: 'm-d-Y H:i'}); $timeout($scope.saveArticleDraft, 30000); diff --git a/plugins/pencilblue/templates/angular/admin/content/pages/manage_pages.html b/plugins/pencilblue/templates/angular/admin/content/pages/manage_pages.html index 3dfc1952d..51193bd63 100644 --- a/plugins/pencilblue/templates/angular/admin/content/pages/manage_pages.html +++ b/plugins/pencilblue/templates/angular/admin/content/pages/manage_pages.html @@ -83,11 +83,11 @@ } $scope.deleting = true; - $http({method: 'DELETE', url: '/actions/admin/content/pages/' + $scope.objectToDelete._id}) + $http({method: 'DELETE', url: '/api/content/pages/' + $scope.objectToDelete._id}) .success(function(result) { $scope.pages.splice($scope.objectToDeleteIndex, 1); $scope.deleting = false; - $scope.successMessage = result.message; + $scope.successMessage = $scope.objectToDelete.headline + " was deleted"; $scope.paginate(0); $('#confirm_delete_modal').modal('hide'); }) diff --git a/plugins/pencilblue/templates/angular/admin/content/pages/page_form.html b/plugins/pencilblue/templates/angular/admin/content/pages/page_form.html index 2733903db..82adfa62c 100644 --- a/plugins/pencilblue/templates/angular/admin/content/pages/page_form.html +++ b/plugins/pencilblue/templates/angular/admin/content/pages/page_form.html @@ -12,7 +12,7 @@ $scope.page.publish_date = $filter('date')($scope.page.publish_date || new Date(), 'MM-dd-yyyy HH:mm'); $scope.page.page_media = $scope.page.page_media || []; $scope.layout = $sce.trustAsHtml($scope.page.page_layout); - $scope.page.meta_keywords = $scope.page.meta_keywords ? $scope.page.meta_keywords.join(',') : ''; + $scope.page.meta_keywords = $scope.page.meta_keywords ? $scope.page.meta_keywords.join(', ') : ''; $scope.editingObject = $scope.page; $scope.variablePrefix = 'page'; @@ -45,10 +45,11 @@ $scope.getPageData(draft, function(pageData) { $scope.saving = true; if(pageData._id) { - $http.post('/actions/admin/content/pages/' + $scope.page._id, pageData) + // Update an existing page + $http.put('/api/content/pages/' + $scope.page._id, pageData) .success(function(result) { - $scope.successMessage = result.message; - $scope.page.last_modified = result.data.last_modified; + $scope.successMessage = 'SUCCESS'; + $scope.page.last_modified = result.last_modified; $scope.saving = false; }) .error(function(error, status) { @@ -57,9 +58,10 @@ }); } else { - $http.post('/actions/admin/content/pages', pageData) + // Save a new page + $http.post('/api/content/pages', pageData) .success(function(result) { - $scope.successMessage = result.message; + $scope.successMessage = 'SUCCESS'; $scope.saving = false; $window.location = '/admin/content/pages/' + result.data._id.toString(); }) @@ -79,9 +81,9 @@ $scope.page.draft = true; $scope.getPageData(true, function(pageData) { $scope.saving = true; - $http.post('/actions/admin/content/pages/' + $scope.page._id, pageData) + $http.put('/api/content/pages/' + $scope.page._id, pageData) .success(function(result) { - $scope.page.last_modified = result.data.last_modified; + $scope.page.last_modified = result.last_modified; $timeout($scope.savePageDraft, 30000); $scope.saving = false; @@ -102,7 +104,7 @@ $scope.getPageData = function(draft, cb) { var pageData = angular.copy($scope.page); - pageData.publish_date = (new Date($filter('parsableDate')($scope.page.publish_date))).getTime(); + pageData.publish_date = (new Date($filter('parsableDate')($scope.page.publish_date))).toISOString(); pageData.draft = draft ? 1 : 0; var media = []; @@ -115,6 +117,23 @@ topics.push($scope.page.page_topics[i]._id.toString()); } + // Convert keyword string into array, trimming any excess whitespace and commas + if (typeof pageData.meta_keywords == "string") { + var words = pageData.meta_keywords.trim(); + pageData.meta_keywords = []; + + if (words.length > 0) { + var keywords = words.split(","); + for (var i = 0; i < keywords.length; i++) { + if (keywords[i].trim().length > 0) { + pageData.meta_keywords.push(keywords[i].trim()); + } + } + } + } + + pageData.allow_comments = pageData.allow_comments ? true : false; + pageData.page_media = media; pageData.page_topics = topics; pageData.page_layout = $scope.layout; @@ -128,7 +147,7 @@ $window.open('/preview/page/' + $scope.page._id); } }); - } + }; $('#publish_date').datetimepicker({format: 'm-d-Y H:i'}); $timeout($scope.savePageDraft, 30000); diff --git a/plugins/portfolio/templates/angular/admin/content/pages/page_form.html b/plugins/portfolio/templates/angular/admin/content/pages/page_form.html index 2cd47ec29..47f164cf9 100644 --- a/plugins/portfolio/templates/angular/admin/content/pages/page_form.html +++ b/plugins/portfolio/templates/angular/admin/content/pages/page_form.html @@ -12,7 +12,7 @@ $scope.page.publish_date = $filter('date')($scope.page.publish_date || new Date(), 'MM-dd-yyyy HH:mm'); $scope.page.page_media = $scope.page.page_media || []; $scope.layout = $sce.trustAsHtml($scope.page.page_layout); - $scope.page.meta_keywords = $scope.page.meta_keywords ? $scope.page.meta_keywords.join(',') : ''; + $scope.page.meta_keywords = $scope.page.meta_keywords ? $scope.page.meta_keywords.join(', ') : ''; $scope.editingObject = $scope.page; $scope.variablePrefix = 'page'; $rootScope.photoValue = $scope.page.hero_image || null; @@ -46,10 +46,11 @@ $scope.getPageData(draft, function(pageData) { $scope.saving = true; if(pageData._id) { - $http.post('/actions/admin/content/pages/' + $scope.page._id, pageData) + // Update an existing page + $http.put('/api/content/pages/' + $scope.page._id, pageData) .success(function(result) { - $scope.successMessage = result.message; - $scope.page.last_modified = result.data.last_modified; + $scope.successMessage = 'SUCCESS'; + $scope.page.last_modified = result.last_modified; $scope.saving = false; }) .error(function(error, status) { @@ -58,9 +59,10 @@ }); } else { - $http.post('/actions/admin/content/pages', pageData) + // Save a new page + $http.post('/api/content/pages', pageData) .success(function(result) { - $scope.successMessage = result.message; + $scope.successMessage = 'SUCCESS'; $scope.saving = false; $window.location = '/admin/content/pages/' + result.data._id.toString(); }) @@ -80,9 +82,9 @@ $scope.page.draft = true; $scope.getPageData(true, function(pageData) { $scope.saving = true; - $http.post('/actions/admin/content/pages/' + $scope.page._id, pageData) + $http.put('/api/content/pages/' + $scope.page._id, pageData) .success(function(result) { - $scope.page.last_modified = result.data.last_modified; + $scope.page.last_modified = result.last_modified; $timeout($scope.savePageDraft, 30000); $scope.saving = false; @@ -103,7 +105,7 @@ $scope.getPageData = function(draft, cb) { var pageData = angular.copy($scope.page); - pageData.publish_date = (new Date($filter('parsableDate')($scope.page.publish_date))).getTime(); + pageData.publish_date = (new Date($filter('parsableDate')($scope.page.publish_date))).toISOString(); pageData.draft = draft ? 1 : 0; pageData.hero_image = $rootScope.photoValue; @@ -117,6 +119,23 @@ topics.push($scope.page.page_topics[i]._id.toString()); } + // Convert keyword string into array, trimming any excess whitespace and commas + if (typeof pageData.meta_keywords == "string") { + var words = pageData.meta_keywords.trim(); + pageData.meta_keywords = []; + + if (words.length > 0) { + var keywords = words.split(","); + for (var i = 0; i < keywords.length; i++) { + if (keywords[i].trim().length > 0) { + pageData.meta_keywords.push(keywords[i].trim()); + } + } + } + } + + pageData.allow_comments = pageData.allow_comments ? true : false; + pageData.page_media = media; pageData.page_topics = topics; pageData.page_layout = $scope.layout; @@ -130,7 +149,7 @@ $window.open('/preview/page/' + $scope.page._id); } }); - } + }; $('#publish_date').datetimepicker({format: 'm-d-Y H:i'}); $timeout($scope.savePageDraft, 30000); From b1009d10fe5450cf5da0e11ba6748e5701899167 Mon Sep 17 00:00:00 2001 From: Mark Baird Date: Fri, 11 Sep 2015 12:46:52 -0400 Subject: [PATCH 622/790] ArticleServiceV2 and PageService unit tests --- .../content/article_service_v2_tests.js | 91 +++++++++++++++++++ .../entities/content/page_service_tests.js | 90 ++++++++++++++++++ 2 files changed, 181 insertions(+) create mode 100644 test/include/service/entities/content/article_service_v2_tests.js create mode 100644 test/include/service/entities/content/page_service_tests.js diff --git a/test/include/service/entities/content/article_service_v2_tests.js b/test/include/service/entities/content/article_service_v2_tests.js new file mode 100644 index 000000000..414b4aed4 --- /dev/null +++ b/test/include/service/entities/content/article_service_v2_tests.js @@ -0,0 +1,91 @@ + +//depedencies +var should = require('should'); +var pb = {}; +pb.DAO = require('../../../../../include/dao/dao.js')(pb); +pb.BaseObjectService = require('../../../../../include/service/base_object_service.js')(pb); +pb.ValidationService = require('../../../../../include/validation/validation_service.js')(pb); +pb.ContentObjectService = require('../../../../../include/service/entities/content/content_object_service.js')(pb); +var ArticleServiceV2 = require('../../../../../include/service/entities/content/article_service_v2.js')(pb); + +describe('ArticleServiceV2', function() { + describe('ArticleServiceV2.format', function () { + it('should allow valid values', function () { + var article = getArticle(); + var article2 = getArticle(); + + // Set expected date to the parsed version of the date being passed to the service + article2.publish_date = pb.BaseObjectService.getDate(article2.publish_date) + + ArticleServiceV2.format({data: article}, function() {}); + should.deepEqual(article, article2); + }); + + it('should sanitize keywords', function () { + var article = getArticle(); + article.meta_keywords = ["A Keyword With
    HTML
    ", "Another HTML keyword"]; + + ArticleServiceV2.format({data: article}, function() {}); + article.meta_keywords[0].should.eql("A Keyword With HTML"); + article.meta_keywords[1].should.eql("Another HTML keyword"); + }); + }); + + describe('ArticleServiceV2.merge', function () { + it('should copy all properties', function () { + var article = getArticle(); + var article2 = {}; + + ArticleServiceV2.merge({data: article, object: article2}, function() {}); + should.deepEqual(article, article2); + }); + }); + + describe('ArticleServiceV2.validate', function () { + it('should allow valid values', function () { + var article = getArticle(); + var errors = []; + + // Set date to the parsed version of the date being passed to the service + article.publish_date = pb.BaseObjectService.getDate(article.publish_date); + + ArticleServiceV2.validate({data: article, validationErrors: errors}, function() {}); + errors.length.should.eql(0); + }); + + it('should find errors', function () { + var article = getArticle(); + var errors = []; + + article.meta_keywords = "This should be an array, not a string"; + + ArticleServiceV2.validate({data: article, validationErrors: errors}, function() {}); + + errors.length.should.eql(2); + errors[0].field.should.eql("publish_date"); + errors[1].field.should.eql("meta_keywords"); + }); + }); +}); + +var getArticle = function() { + return { + allow_comments: false, + draft: 0, + article_media: undefined, + article_sections: undefined, + article_topics: undefined, + author: "507f191e810c19729de860ea", // Random MongoDB compatible object ID + template: undefined, + thumbnail: null, + headline: "Test Headline", + subheading: "Test Subheading", + article_layout: "Simple Page Layout", + focus_keyword: "Testing", + seo_title: "SEO Title", + meta_desc: "This is a test article", + url: "http://test-size.com/article/test-article", + publish_date: "2015-09-08T01:55:28+00:00", // ISO Format + meta_keywords: ["Keyword One", "Keyword Two", "Keyword Three"] + } +}; \ No newline at end of file diff --git a/test/include/service/entities/content/page_service_tests.js b/test/include/service/entities/content/page_service_tests.js new file mode 100644 index 000000000..eba49dc4d --- /dev/null +++ b/test/include/service/entities/content/page_service_tests.js @@ -0,0 +1,90 @@ + +//depedencies +var should = require('should'); +var pb = {}; +pb.DAO = require('../../../../../include/dao/dao.js')(pb); +pb.BaseObjectService = require('../../../../../include/service/base_object_service.js')(pb); +pb.ValidationService = require('../../../../../include/validation/validation_service.js')(pb); +pb.ContentObjectService = require('../../../../../include/service/entities/content/content_object_service.js')(pb); +var PageService = require('../../../../../include/service/entities/content/page_service.js')(pb); + +describe('PageService', function() { + describe('PageService.format', function () { + it('should allow valid values', function () { + var page = getPage(); + var page2 = getPage(); + + // Set expected date to the parsed version of the date being passed to the service + page2.publish_date = pb.BaseObjectService.getDate(page2.publish_date) + + PageService.format({data: page}, function() {}); + should.deepEqual(page, page2); + }); + + it('should sanitize keywords', function () { + var page = getPage(); + page.meta_keywords = ["A Keyword With
    HTML
    ", "Another HTML keyword"]; + + PageService.format({data: page}, function() {}); + page.meta_keywords[0].should.eql("A Keyword With HTML"); + page.meta_keywords[1].should.eql("Another HTML keyword"); + }); + }); + + describe('PageService.merge', function () { + it('should copy all properties', function () { + var page = getPage(); + var page2 = {}; + + PageService.merge({data: page, object: page2}, function() {}); + should.deepEqual(page, page2); + }); + }); + + describe('PageService.validate', function () { + it('should allow valid values', function () { + var page = getPage(); + var errors = []; + + // Set date to the parsed version of the date being passed to the service + page.publish_date = pb.BaseObjectService.getDate(page.publish_date); + + PageService.validate({data: page, validationErrors: errors}, function() {}); + errors.length.should.eql(0); + }); + + it('should find errors', function () { + var page = getPage(); + var errors = []; + + page.meta_keywords = "This should be an array, not a string"; + + PageService.validate({data: page, validationErrors: errors}, function() {}); + + errors.length.should.eql(2); + errors[0].field.should.eql("publish_date"); + errors[1].field.should.eql("meta_keywords"); + }); + }); +}); + +var getPage = function() { + return { + allow_comments: false, + draft: 0, + page_media: undefined, + page_topics: undefined, + author: "507f191e810c19729de860ea", // Random MongoDB compatible object ID + template: undefined, + thumbnail: null, + headline: "Test Headline", + subheading: "Test Subheading", + page_layout: "Simple Page Layout", + focus_keyword: "Testing", + seo_title: "SEO Title", + meta_desc: "This is a test page", + url: "http://test-size.com/page/test-page", + publish_date: "2015-09-08T01:55:28+00:00", // ISO Format + meta_keywords: ["Keyword One", "Keyword Two", "Keyword Three"] + } +}; \ No newline at end of file From af99e80877498c3a664a371cdb72ce303a73e59a Mon Sep 17 00:00:00 2001 From: Brian Hyder Date: Tue, 15 Sep 2015 07:14:54 -0400 Subject: [PATCH 623/790] #677 More unit tests --- include/localization.js | 8 +-- .../formatters/error_formatters_tests.js | 2 +- test/include/localization_tests.js | 60 ++++++++++++++++++- 3 files changed, 64 insertions(+), 6 deletions(-) diff --git a/include/localization.js b/include/localization.js index c0a41caa4..3ff36b052 100755 --- a/include/localization.js +++ b/include/localization.js @@ -503,7 +503,7 @@ module.exports = function LocalizationModule(pb) { * @return {Boolean} */ Localization.isSupported = function(locale) { - if (!locale) { + if (!util.isString(locale) || locale.length === 0) { return false; } @@ -974,9 +974,6 @@ module.exports = function LocalizationModule(pb) { return { language: lang, countryCode: countryCode, - toString: function() { - return Localization.formatLocale(this.lang, this.countryCode); - } }; }; @@ -984,6 +981,9 @@ module.exports = function LocalizationModule(pb) { if (!util.isString(language)) { throw new Error('language parameter is required'); } + if (!util.isNullOrUndefined(countryCode) && !util.isString(countryCode)) { + throw new Error('countryCode parameter must be a string'); + } var localeStr = language.toLowerCase(); if (util.isString(countryCode)) { diff --git a/test/include/error/formatters/error_formatters_tests.js b/test/include/error/formatters/error_formatters_tests.js index 284baa1b4..aea3c5b81 100644 --- a/test/include/error/formatters/error_formatters_tests.js +++ b/test/include/error/formatters/error_formatters_tests.js @@ -108,7 +108,7 @@ describe('ErrorFormatters', function() { var params = { error: error }; - ErrorFormatters.xml(params, function(err, result){console.log(result); + ErrorFormatters.xml(params, function(err, result){ result.should.be.type('string'); next(err); diff --git a/test/include/localization_tests.js b/test/include/localization_tests.js index c9b6ca9f7..8d9463f07 100644 --- a/test/include/localization_tests.js +++ b/test/include/localization_tests.js @@ -68,7 +68,7 @@ describe('Localization', function() { }); }); - var unacceptable = ['en-GB', 'ar-SY']; + var unacceptable = ['en-GB', 'ar-SY', undefined, false, 0, 1, 2.2, null, '']; unacceptable.forEach(function(locale) { it('should return false when provided '+locale, function() { @@ -170,4 +170,62 @@ describe('Localization', function() { result.should.eql("PencilBlue is an amazing CMS. It is quite comprehensive and provides a lot of features."); }); }); + + describe('Localization.formatLocale', function() { + + [1, 2.2, false, {}, [], null, undefined].forEach(function(param) { + it('should throw an error when a non-string language parameter ' + param + ' is provided', function() { + Localization.formatLocale.bind(null, param).should.throwError(); + }); + }); + + [1, 2.2, false, {}, []].forEach(function(param) { + it('should throw an error when a non-string countryCode parameter ' + param + ' is provided', function() { + Localization.formatLocale.bind(null, 'en', param).should.throwError(); + }); + }); + + it('should format the locale with no country code when provided just the language', function() { + + var language = 'en'; + var result = Localization.formatLocale(language); + result.should.eql(language); + }); + + it('should format the locale with a country code when provided the language & country code', function() { + + var language = 'EN'; + var countryCode = 'us'; + var result = Localization.formatLocale(language, countryCode); + result.should.eql('en-US'); + }); + }); + + describe('Localization.parseLocaleStr', function() { + //TODO + }); + + describe('Localization.getSupportedWithDisplay', function() { + //TODO + }); + + describe('Localization.getSupported', function() { + //TODO + }); + + describe('Localization.containsParameters', function() { + //TODO + }); + + describe('Localization.unregisterLocale', function() { + //TODO + }); + + describe('Localization.registerLocalization', function() { + //TODO + }); + + describe('Localization.registerLocale', function() { + //TODO + }); }); From 6f645f87570df4f89ce27fd8faed5d417441d4e5 Mon Sep 17 00:00:00 2001 From: Brian Hyder Date: Tue, 15 Sep 2015 17:30:30 -0400 Subject: [PATCH 624/790] #677 More unit tests --- include/localization.js | 10 +++++++--- test/include/localization_tests.js | 24 +++++++++++++++++++++++- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/include/localization.js b/include/localization.js index 3ff36b052..d2d5788f7 100755 --- a/include/localization.js +++ b/include/localization.js @@ -950,8 +950,8 @@ module.exports = function LocalizationModule(pb) { if (!util.isString(filePath.language)) { throw new Error('filePath.language parameter is required'); } - if (!util.isString(filePath.countryCode)) { - throw new Error('filePath.countryCode parameter is required'); + if (!util.isNullOrUndefined(filePath.countryCode) && !util.isString(filePath.countryCode)) { + throw new Error('filePath.countryCode parameter must be a string'); } //we have a valid locale we can stop @@ -961,7 +961,11 @@ module.exports = function LocalizationModule(pb) { throw new Error('filePath parameter is required'); } - var lastSlashPos = filePath.lastIndexOf(path.sep); + //detect what file path separator we are using. Unix first then windows + var lastSlashPos = filePath.lastIndexOf('/'); + if (lastSlashPos < 0) { + lastSlashPos = filePath.lastIndexOf('\\'); + } var extPos = filePath.lastIndexOf(JS_EXT); if (extPos < 0) { extPos = filePath.length; diff --git a/test/include/localization_tests.js b/test/include/localization_tests.js index 8d9463f07..ecee045af 100644 --- a/test/include/localization_tests.js +++ b/test/include/localization_tests.js @@ -202,7 +202,29 @@ describe('Localization', function() { }); describe('Localization.parseLocaleStr', function() { - //TODO + + [ + ['en', 'en', null], + ['PO', 'po', null], + ['Ro', 'ro', null], + ['eS', 'es', null], + ['/unix/file/path/en.json', 'en', null], + ['C:\\windows\\file\\path\\en.js', 'en', null], + ['en-US', 'en', 'US'], + ['PO-us', 'po', 'US'], + ['Ro-Ro', 'ro', 'RO'], + ['eS-Es', 'es', 'ES'], + ['/unix/file/path/en-US.json', 'en', 'US'], + ['C:\\windows\\file\\path\\EN-us.js', 'en', 'US'] + ].forEach(function(testCaseParams) { + + it('should parse the locale as language lower case and country code upper case (when provided)', function() { + + var result = Localization.parseLocaleStr(testCaseParams[0]); + result.language.should.eql(testCaseParams[1]); + should.strictEqual(result.countryCode, testCaseParams[2]); + }); + }); }); describe('Localization.getSupportedWithDisplay', function() { From 10dee7217ffeb8a705c6bbf8cd544af9a197520b Mon Sep 17 00:00:00 2001 From: Mark Baird Date: Tue, 15 Sep 2015 19:09:45 -0400 Subject: [PATCH 625/790] Fix error after save of new article or page --- .../angular/admin/content/articles/article_form.html | 4 ++-- .../templates/angular/admin/content/pages/page_form.html | 2 +- .../templates/angular/admin/content/pages/page_form.html | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/pencilblue/templates/angular/admin/content/articles/article_form.html b/plugins/pencilblue/templates/angular/admin/content/articles/article_form.html index 95ddb0dbf..179451f86 100644 --- a/plugins/pencilblue/templates/angular/admin/content/articles/article_form.html +++ b/plugins/pencilblue/templates/angular/admin/content/articles/article_form.html @@ -69,11 +69,11 @@ $scope.successMessage = 'SUCCESS'; $scope.saving = false; - if(!result.data._id) { + if(!result._id) { $window.location = '/admin/content/articles'; return; } - $window.location = '/admin/content/articles/' + result.data._id.toString(); + $window.location = '/admin/content/articles/' + result._id.toString(); }) .error(function(error, status) { $scope.errorMessage = error.message; diff --git a/plugins/pencilblue/templates/angular/admin/content/pages/page_form.html b/plugins/pencilblue/templates/angular/admin/content/pages/page_form.html index 82adfa62c..f9653b181 100644 --- a/plugins/pencilblue/templates/angular/admin/content/pages/page_form.html +++ b/plugins/pencilblue/templates/angular/admin/content/pages/page_form.html @@ -63,7 +63,7 @@ .success(function(result) { $scope.successMessage = 'SUCCESS'; $scope.saving = false; - $window.location = '/admin/content/pages/' + result.data._id.toString(); + $window.location = '/admin/content/pages/' + result._id.toString(); }) .error(function(error, status) { $scope.errorMessage = error.message; diff --git a/plugins/portfolio/templates/angular/admin/content/pages/page_form.html b/plugins/portfolio/templates/angular/admin/content/pages/page_form.html index 47f164cf9..9d12649e5 100644 --- a/plugins/portfolio/templates/angular/admin/content/pages/page_form.html +++ b/plugins/portfolio/templates/angular/admin/content/pages/page_form.html @@ -64,7 +64,7 @@ .success(function(result) { $scope.successMessage = 'SUCCESS'; $scope.saving = false; - $window.location = '/admin/content/pages/' + result.data._id.toString(); + $window.location = '/admin/content/pages/' + result._id.toString(); }) .error(function(error, status) { $scope.errorMessage = error.message; From f6a38d398daf44d439dcc1c3402899b0fcffdbf2 Mon Sep 17 00:00:00 2001 From: Brian Hyder Date: Tue, 15 Sep 2015 21:02:53 -0400 Subject: [PATCH 626/790] #677 Unit tests --- test/include/localization_tests.js | 35 ++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/test/include/localization_tests.js b/test/include/localization_tests.js index ecee045af..51dc27784 100644 --- a/test/include/localization_tests.js +++ b/test/include/localization_tests.js @@ -225,6 +225,41 @@ describe('Localization', function() { should.strictEqual(result.countryCode, testCaseParams[2]); }); }); + + it('should return the locale object when passed in', function() { + var locale = { + language: 'en', + countryCode: 'US' + }; + var result = Localization.parseLocaleStr(locale); + result.should.eql(locale); + }); + + [ + 1, + 2.1, + true, + [], + {}, + null, + undefined, + { language: 1, countryCode: 'US' }, + { language: 1.2, countryCode: 'US' }, + { language: false, countryCode: 'US' }, + { language: [], countryCode: 'US' }, + { language: {}, countryCode: 'US' }, + { language: null, countryCode: 'US' }, + { language: "en", countryCode: 1 }, + { language: "en", countryCode: 2.2 }, + { language: "en", countryCode: false }, + { language: "en", countryCode: [] }, + { language: "en", countryCode: {} }, + ].forEach(function(locale) { + + it('should throw when provided an invalid locale '+ JSON.stringify(locale), function() { + Localization.parseLocaleStr.bind(null, locale).should.throwError(); + }); + }); }); describe('Localization.getSupportedWithDisplay', function() { From eab0579db63f503bcb2e5f768a7d9853bba2825a Mon Sep 17 00:00:00 2001 From: Brian Hyder Date: Wed, 16 Sep 2015 07:40:49 -0400 Subject: [PATCH 627/790] #677 More unit tests --- include/localization.js | 9 ++--- test/include/localization_tests.js | 60 ++++++++++++++++++++++++++++-- 2 files changed, 60 insertions(+), 9 deletions(-) diff --git a/include/localization.js b/include/localization.js index d2d5788f7..bdba97d93 100755 --- a/include/localization.js +++ b/include/localization.js @@ -930,19 +930,16 @@ module.exports = function LocalizationModule(pb) { * @return {Array} */ Localization.getSupportedWithDisplay = function() { - var locales = []; + var supported = Localization.getSupported(); - supported.forEach(function(locale) { + return supported.map(function(locale) { var localization = new Localization(locale); - - var kv = { + return { value: locale, name: localization.g('generic.LOCALE_DISPLAY'/*, {empty options}*/) }; - locales.push(kv); }); - return locales; }; Localization.parseLocaleStr = function(filePath) { diff --git a/test/include/localization_tests.js b/test/include/localization_tests.js index 51dc27784..d2acde35e 100644 --- a/test/include/localization_tests.js +++ b/test/include/localization_tests.js @@ -1,5 +1,6 @@ //depedencies +var path = require('path'); var should = require('should'); var Configuration = require('../../include/config.js'); var Lib = require('../../lib'); @@ -263,15 +264,59 @@ describe('Localization', function() { }); describe('Localization.getSupportedWithDisplay', function() { - //TODO + + it('should return an array with the same number of items as locale files', function(done) { + getLocalizationFiles(function(err, files) { + should.not.exist(err); + + var result = Localization.getSupportedWithDisplay(); + files.length.should.eql(result.length); + + done(); + }); + }); }); describe('Localization.getSupported', function() { - //TODO + + it('should return an array with the same number of items as locale files', function(done) { + getLocalizationFiles(function(err, files) { + should.not.exist(err); + + var result = Localization.getSupported(); + files.length.should.eql(result.length); + + done(); + }); + }); }); describe('Localization.containsParameters', function() { - //TODO + + [1, 2.2, false, [], {}, null, undefined].forEach(function(val) { + + it('should throw an error when provided an invalid value '+ val, function() { + Localization.containsParameters.bind(null, val).should.throwError(); + }); + }); + + [ + ["", false], + ["hello.world", false], + ["hello this is just a simple test", false], + ["hello {this is my", false], + ["} hello world", false], + ["}{ what about", false], + ["{what about}", true], + ["This is {param1} good {param2}", true] + ].forEach(function(testCaseParams) { + + it('should inspect the value and determine if parameters are found within it', function() { + console.log(testCaseParams); + var result = Localization.containsParameters(testCaseParams[0]); + result.should.eql(testCaseParams[1]); + }); + }); }); describe('Localization.unregisterLocale', function() { @@ -285,4 +330,13 @@ describe('Localization', function() { describe('Localization.registerLocale', function() { //TODO }); + + function getLocalizationFiles(cb) { + var options = { + recursive: false, + filter: function(filePath) { return filePath.indexOf('.js') === filePath.length - '.js'.length; } + }; + var dir = path.join(pb.config.docRoot, 'public/localization'); + pb.utils.getFiles(dir, options, cb); + } }); From be966404d3a801c9569b89ff7f69e345dd2d8e8e Mon Sep 17 00:00:00 2001 From: Blake Callens Date: Wed, 16 Sep 2015 10:42:21 -0400 Subject: [PATCH 628/790] query changes --- .../admin/content/topics/manage_topics.html | 15 ++++++++---- public/js/angular/factories/admin/topic.js | 24 ++++++++++--------- 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/plugins/pencilblue/templates/angular/admin/content/topics/manage_topics.html b/plugins/pencilblue/templates/angular/admin/content/topics/manage_topics.html index ac5f4e15d..830ea4fe1 100644 --- a/plugins/pencilblue/templates/angular/admin/content/topics/manage_topics.html +++ b/plugins/pencilblue/templates/angular/admin/content/topics/manage_topics.html @@ -23,7 +23,10 @@ $scope.topics = null; - topicFactory.getTopics($scope.paginationLimit, $scope.paginationIndex, function(error, topics, total) { + topicFactory.getTopics({ + $limit: $scope.paginationLimit, + $offset: $scope.paginationIndex + }, function(error, topics, total) { if(error) { $scope.errorMessage = error.message; return; @@ -44,14 +47,18 @@ $scope.paginate(0, true); }; - $scope.queryTopics = function(cb) { + $scope.query = function(cb) { if(!cb) { cb = function() {}; } $scope.topics = null; - topicFactory.searchTopics($scope.searchText, $scope.paginationLimit, $scope.paginationIndex, function(error, topics, total) { + topicFactory.getTopics({ + q: $scope.searchText, + $limit: $scope.paginationLimit, + $offset: $scope.paginationIndex + }, function(error, topics, total) { if(error) { $scope.errorMessage = error.message; return; @@ -70,7 +77,7 @@ $scope.paginationIndex = paginationIndex; if($scope.searchText.length) { - $scope.queryTopics(function() { + $scope.query(function() { $scope.paginationPages = paginationService.getPageArray(paginationIndex, $scope.paginationLimit, $scope.paginationTotal); }); } diff --git a/public/js/angular/factories/admin/topic.js b/public/js/angular/factories/admin/topic.js index df373fc01..873f3228d 100644 --- a/public/js/angular/factories/admin/topic.js +++ b/public/js/angular/factories/admin/topic.js @@ -2,18 +2,20 @@ angular.module('pencilblue.factories.admin.topics', []) .factory('topicFactory', function($http) { return { - getTopics: function(limit, offset, cb) { - $http.get('/api/content/topics?$limit=' + limit + '&$offset=' + offset) - .success(function(result) { - cb(null, result.data, result.total); - }) - .error(function(error) { - cb(error); - }); - }, + getTopics: function(options, cb) { + var queryString = ''; + for(var key in options) { + if(queryString.length) { + queryString += '&'; + } + else { + queryString += '?'; + } + + queryString += key + '=' + options[key]; + } - searchTopics: function(query, limit, offset, cb) { - $http.get('/api/content/topics?$limit=' + limit + '&$offset=' + offset + '&q=' + query) + $http.get('/api/content/topics' + queryString) .success(function(result) { cb(null, result.data, result.total); }) From 39679926a6b3d3b4ec61376e5135cebae98a9727 Mon Sep 17 00:00:00 2001 From: Blake Callens Date: Wed, 16 Sep 2015 13:54:43 -0400 Subject: [PATCH 629/790] started on media --- include/service/entities/media_service.js | 96 +++++++++---------- .../admin/content/media/manage_media.js | 25 +++-- .../api/content/media_api_controller.js | 79 +++++++++++++++ plugins/pencilblue/include/routes.js | 50 ++++++++++ .../admin/content/media/manage_media.html | 5 +- .../admin/content/media/manage_media.html | 92 ++++++++++++++---- public/js/angular/factories/admin/media.js | 41 ++++++++ 7 files changed, 316 insertions(+), 72 deletions(-) create mode 100644 plugins/pencilblue/controllers/api/content/media_api_controller.js create mode 100644 public/js/angular/factories/admin/media.js diff --git a/include/service/entities/media_service.js b/include/service/entities/media_service.js index 832bc3b76..7851871a6 100755 --- a/include/service/entities/media_service.js +++ b/include/service/entities/media_service.js @@ -45,7 +45,7 @@ module.exports = function MediaServiceModule(pb) { if (!provider) { throw new Error('A valid media provider is required. Please check your configuration'); } - + /** * * @property provider @@ -53,7 +53,7 @@ module.exports = function MediaServiceModule(pb) { */ this.provider = provider; } - + /** * * @private @@ -365,7 +365,7 @@ module.exports = function MediaServiceModule(pb) { }; /** - * Determines if the media URI is a file. It is determined to be a file if and + * Determines if the media URI is a file. It is determined to be a file if and * only if the URI does not begin with "http" or "//". * @static * @method isFile @@ -380,8 +380,8 @@ module.exports = function MediaServiceModule(pb) { * @method getMediaDescriptor * @param {String} mediaURL * @param {Boolean} isFile Indicates if the media resource was uploaded to the server. - * @param {Function} cb A callback with two parameters. First, an Error if - * occurred and second is an object that describes the media resource described + * @param {Function} cb A callback with two parameters. First, an Error if + * occurred and second is an object that describes the media resource described * by the given media URL */ MediaService.prototype.getMediaDescriptor = function(mediaUrl, cb) { @@ -426,19 +426,19 @@ module.exports = function MediaServiceModule(pb) { }; /** - * Renders a resource by type and location (mediaId). + * Renders a resource by type and location (mediaId). * @method renderByLocation * @param {Object} options * @param {String} options.location The unique media identifier for the type - * @param {String} [options.type] The type of provider that knows how to render + * @param {String} [options.type] The type of provider that knows how to render * the resource - * @param {Object} [options.attrs] The desired HTML attributes that will be + * @param {Object} [options.attrs] The desired HTML attributes that will be * added to the element that provides the rendering * @param {Object} [options.style] The desired style overrides for the media - * @param {String} [options.view] The view type that the media will be rendered - * for (view, editor, post). Any style options provided will override those + * @param {String} [options.view] The view type that the media will be rendered + * for (view, editor, post). Any style options provided will override those * provided by the default style associated with the view. - * @param {Function} cb A callback that provides two parameters. An Error if + * @param {Function} cb A callback that provides two parameters. An Error if * exists and the rendered HTML content for the media resource. */ MediaService.prototype.renderByLocation = function(options, cb) { @@ -456,18 +456,18 @@ module.exports = function MediaServiceModule(pb) { }; /** - * Renders a media resource by ID where ID refers the to the media descriptor + * Renders a media resource by ID where ID refers the to the media descriptor * id. * @method renderById * @param {String} The media resource ID * @param {Object} options - * @param {Object} [options.attrs] The desired HTML attributes that will be + * @param {Object} [options.attrs] The desired HTML attributes that will be * added to the element that provides the rendering * @param {Object} [options.style] The desired style overrides for the media - * @param {String} [options.view] The view type that the media will be rendered - * for (view, editor, post). Any style options provided will override those + * @param {String} [options.view] The view type that the media will be rendered + * for (view, editor, post). Any style options provided will override those * provided by the default style associated with the view. - * @param {Function} cb A callback that provides two parameters. An Error if + * @param {Function} cb A callback that provides two parameters. An Error if * exists and the rendered HTML content for the media resource. */ MediaService.prototype.renderById = function(id, options, cb) { @@ -475,7 +475,7 @@ module.exports = function MediaServiceModule(pb) { self.siteQueryService.loadById(id, MediaService.COLL, function (err, media) { if (util.isError(err)) { - return cb(err); + return cb(err); } else if (!media) { return cb(null, null); @@ -491,13 +491,13 @@ module.exports = function MediaServiceModule(pb) { * @method render * @param {String} The media resource ID * @param {Object} options - * @param {Object} [options.attrs] The desired HTML attributes that will be + * @param {Object} [options.attrs] The desired HTML attributes that will be * added to the element that provides the rendering * @param {Object} [options.style] The desired style overrides for the media - * @param {String} [options.view] The view type that the media will be rendered - * for (view, editor, post). Any style options provided will override those + * @param {String} [options.view] The view type that the media will be rendered + * for (view, editor, post). Any style options provided will override those * provided by the default style associated with the view. - * @param {Function} cb A callback that provides two parameters. An Error if + * @param {Function} cb A callback that provides two parameters. An Error if * exists and the rendered HTML content for the media resource. */ MediaService.prototype.renderByFlag = function(flag, options, cb) { @@ -528,13 +528,13 @@ module.exports = function MediaServiceModule(pb) { * @method render * @param {String} The media resource ID * @param {Object} options - * @param {Object} [options.attrs] The desired HTML attributes that will be + * @param {Object} [options.attrs] The desired HTML attributes that will be * added to the element that provides the rendering * @param {Object} [options.style] The desired style overrides for the media - * @param {String} [options.view] The view type that the media will be rendered - * for (view, editor, post). Any style options provided will override those + * @param {String} [options.view] The view type that the media will be rendered + * for (view, editor, post). Any style options provided will override those * provided by the default style associated with the view. - * @param {Function} cb A callback that provides two parameters. An Error if + * @param {Function} cb A callback that provides two parameters. An Error if * exists and the rendered HTML content for the media resource. */ MediaService.prototype.render = function(media, options, cb) { @@ -554,14 +554,14 @@ module.exports = function MediaServiceModule(pb) { }; /** - * Retrieves the base style for the given renderer and view. Overrides will be + * Retrieves the base style for the given renderer and view. Overrides will be * applied on top of the base style. * @static * @method getStyleForView * @param {MediaRenderer} renderer An implementation of MediaRenderer - * @param {String} view The view to retrieve the default styling for (view, + * @param {String} view The view to retrieve the default styling for (view, * editor, post) - * @param {Object} [overrides] A hash of style properties that will be applied + * @param {Object} [overrides] A hash of style properties that will be applied * to the base style for the given view */ MediaService.getStyleForView = function(renderer, view, overrides) { @@ -580,7 +580,7 @@ module.exports = function MediaServiceModule(pb) { * @static * @method getRendererByType * @param {String} type The media type - * @return {MediaRenderer} A media renderer interface implementation or NULL if + * @return {MediaRenderer} A media renderer interface implementation or NULL if * none support the given type. */ MediaService.getRendererByType = function(type) { @@ -607,7 +607,7 @@ module.exports = function MediaServiceModule(pb) { * @method getRendererByType * @param {String} mediaUrl The media URL * @param {Boolean} isFile TRUE if the URL represents an uploaded file, FALSE if not - * @return {MediaRenderer} A media renderer interface implementation or NULL if + * @return {MediaRenderer} A media renderer interface implementation or NULL if * none support the given URL. */ MediaService.getRenderer = function(mediaUrl, isFile) { @@ -637,7 +637,7 @@ module.exports = function MediaServiceModule(pb) { * @static * @method getMediaFlag * @param {String} mid The media descriptor ID - * @param {Object} [options] The list of attributes to be provided to the + * @param {Object} [options] The list of attributes to be provided to the * rendering element. * @return {String} */ @@ -663,7 +663,7 @@ module.exports = function MediaServiceModule(pb) { }; /** - * Given a content string the function will search for and extract the first + * Given a content string the function will search for and extract the first * occurance of a media flag. The parsed value that is returned will include: *
      *
    • startIndex - The index where the flag was found to start
    • @@ -707,7 +707,7 @@ module.exports = function MediaServiceModule(pb) { }; /** - * Parses a media flag and returns each part in an object. The parsed value that + * Parses a media flag and returns each part in an object. The parsed value that * is returned will include: *
        *
      • id - The media descriptor id that is referenced by the media flag
      • @@ -749,9 +749,9 @@ module.exports = function MediaServiceModule(pb) { }; /** - * The default editor implementations all for three position values to declared - * for embeded media (none, left, right, center). These values map to HTML - * alignments. This function retrieves the HTML style attribute for the + * The default editor implementations all for three position values to declared + * for embeded media (none, left, right, center). These values map to HTML + * alignments. This function retrieves the HTML style attribute for the * provided position. * @static * @method getStyleForPosition @@ -845,40 +845,40 @@ module.exports = function MediaServiceModule(pb) { }); return media; }; - + /** - * Provides a mechanism to retrieve all of the supported extension types + * Provides a mechanism to retrieve all of the supported extension types * that can be uploaded into the system. * @static * @method getSupportedExtensions * @returns {Array} provides an array of strings */ MediaService.getSupportedExtensions = function() { - + var extensions = {}; REGISTERED_MEDIA_RENDERERS.forEach(function(provider) { - + //for backward compatibility check for existence of extension retrieval if (!util.isFunction(provider.getSupportedExtensions)) { pb.log.warn('MediaService: Renderer %s does provide an implementation for getSupportedExtensions', provider.getName()); return; } - + //retrieve the extensions var exts = provider.getSupportedExtensions(); if (!util.isArray(exts)) { return; } - + //add them to the hash exts.forEach(function(extension) { extensions[extension] = true; }); }); - + return Object.keys(extensions); }; - + /** * Retrieves the singleton instance of MediaProvider. * @static @@ -889,18 +889,18 @@ module.exports = function MediaServiceModule(pb) { if (INSTANCE) { return INSTANCE; } - + INSTANCE = MediaService.loadMediaProvider(); if (INSTANCE === null) { throw new Error('A valid media provider was not available: PROVIDER_PATH: '+pb.config.media.provider+' TRIED='+JSON.stringify(paths)); } }; - + /** * * @static * @method loadMediaProvider - * @return {MediaProvider} An instance of a media provider or NULL when no + * @return {MediaProvider} An instance of a media provider or NULL when no * provider can be loaded. */ MediaService.loadMediaProvider = function() { @@ -910,7 +910,7 @@ module.exports = function MediaServiceModule(pb) { else if (pb.config.media.provider === 'mongo') { return new pb.media.providers.MongoMediaProvider(); } - + var instance = null; var paths = [path.join(pb.config.docRoot, pb.config.media.provider), pb.config.media.provider]; for(var i = 0; i < paths.length; i++) { diff --git a/plugins/pencilblue/controllers/admin/content/media/manage_media.js b/plugins/pencilblue/controllers/admin/content/media/manage_media.js index f9f547379..13b8bcb27 100755 --- a/plugins/pencilblue/controllers/admin/content/media/manage_media.js +++ b/plugins/pencilblue/controllers/admin/content/media/manage_media.js @@ -16,10 +16,10 @@ */ module.exports = function(pb) { - + //pb dependencies var util = pb.util; - + /** * Interface for managing media */ @@ -31,7 +31,20 @@ module.exports = function(pb) { ManageMedia.prototype.render = function(cb) { var self = this; - var options = { + + var angularObjects = pb.ClientJs.getAngularObjects({ + navigation: pb.AdminNavigation.get(self.session, ['content', 'media'], self.ls, self.site), + pills: self.getAdminPills(SUB_NAV_KEY, self.ls, SUB_NAV_KEY) + }); + + var title = self.ls.get('MANAGE_MEDIA'); + self.setPageName(title); + self.ts.registerLocal('angular_objects', new pb.TemplateValue(angularObjects, false)); + self.ts.load('admin/content/media/manage_media', function(err, result) { + cb({content: result}); + }); + + /*var options = { select: { name: 1, caption: 1, @@ -57,10 +70,10 @@ module.exports = function(pb) { cb({content: result}); }); }); - }); + });*/ }; - ManageMedia.prototype.getAngularObjects = function(mediaData, cb) { + /*ManageMedia.prototype.getAngularObjects = function(mediaData, cb) { var self = this; pb.AdminSubnavService.getWithSite(SUB_NAV_KEY, self.ls, SUB_NAV_KEY, {site: self.site}, function(err, pills) { var angularObjects = pb.ClientJs.getAngularObjects( @@ -80,7 +93,7 @@ module.exports = function(pb) { //TODO: err first arg for style. User experience error when no pills? cb(angularObjects); }); - }; + };*/ ManageMedia.getSubNavItems = function(key, ls, data) { return [{ diff --git a/plugins/pencilblue/controllers/api/content/media_api_controller.js b/plugins/pencilblue/controllers/api/content/media_api_controller.js new file mode 100644 index 000000000..265d35058 --- /dev/null +++ b/plugins/pencilblue/controllers/api/content/media_api_controller.js @@ -0,0 +1,79 @@ +/* + Copyright (C) 2015 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +module.exports = function(pb) { + + //PB dependencies + var util = pb.util; + var MediaService = pb.MediaService; + var SecurityService = pb.SecurityService; + + /** + * + * @class MediaApiController + * @constructor + * @extends BaseApiController + */ + function MediaApiController(){} + util.inherits(MediaApiController, pb.BaseApiController); + + /** + * Initializes the controller + * @method init + * @param {Object} context + * @param {Function} cb + */ + MediaApiController.prototype.init = function(context, cb) { + var self = this; + var init = function(err) { + + /** + * + * @property service + * @type {MediaService} + */ + self.service = new MediaService(self.getServiceContext()); + + cb(err, true); + }; + MediaApiController.super_.prototype.init.apply(this, [context, init]); + }; + + MediaApiController.prototype.processWhere = function(q) { + var where = null; + var failures = []; + + //build query & get results + var search = q.q; + if (pb.ValidationService.isNonEmptyStr(search, true)) { + + var patternStr = ".*" + util.escapeRegExp(search) + ".*"; + var pattern = new RegExp(patternStr, "i"); + where = { + name: pattern + }; + } + + return { + where: where, + failures: failures + }; + }; + + //exports + return MediaApiController; +}; diff --git a/plugins/pencilblue/include/routes.js b/plugins/pencilblue/include/routes.js index 653e724c7..1ebd77410 100644 --- a/plugins/pencilblue/include/routes.js +++ b/plugins/pencilblue/include/routes.js @@ -1370,6 +1370,56 @@ module.exports = function Routes(pb){ access_level: pb.SecurityService.ACCESS_WRITER, controller: path.join(pb.config.docRoot, 'plugins/pencilblue/controllers/api/content/page_api_controller.js'), request_body: ['application/json'] + }, + + //media + { + method: 'get', + path: "/api/content/media/:id", + handler: "get", + content_type: 'application/json', + auth_required: true, + access_level: pb.SecurityService.ACCESS_WRITER, + controller: path.join(pb.config.docRoot, 'plugins/pencilblue/controllers/api/content/media_api_controller.js') + }, + { + method: 'get', + path: "/api/content/media", + handler: "getAll", + content_type: 'application/json', + auth_required: true, + access_level: pb.SecurityService.ACCESS_WRITER, + controller: path.join(pb.config.docRoot, 'plugins/pencilblue/controllers/api/content/media_api_controller.js') + }, + { + method: 'delete', + path: "/api/content/media/:id", + handler: "delete", + content_type: 'application/json', + auth_required: true, + access_level: pb.SecurityService.ACCESS_EDITOR, + controller: path.join(pb.config.docRoot, 'plugins/pencilblue/controllers/api/content/media_api_controller.js') + }, + { + method: 'post', + path: "/api/content/media", + handler: "post", + content_type: 'application/json', + auth_required: true, + inactive_site_access: true, + access_level: pb.SecurityService.ACCESS_EDITOR, + controller: path.join(pb.config.docRoot, 'plugins/pencilblue/controllers/api/content/media_api_controller.js'), + request_body: ['application/json'] + }, + { + method: 'put', + path: "/api/content/topics/:id", + handler: "put", + content_type: 'application/json', + auth_required: true, + access_level: pb.SecurityService.ACCESS_EDITOR, + controller: path.join(pb.config.docRoot, 'plugins/pencilblue/controllers/api/content/topic_api_controller.js'), + request_body: ['application/json'] } ]; }; diff --git a/plugins/pencilblue/templates/admin/content/media/manage_media.html b/plugins/pencilblue/templates/admin/content/media/manage_media.html index e62705e05..4855274cd 100755 --- a/plugins/pencilblue/templates/admin/content/media/manage_media.html +++ b/plugins/pencilblue/templates/admin/content/media/manage_media.html @@ -3,7 +3,10 @@ ^tmp_admin=elements=error_success^ ^tmp_admin=elements=sub_nav^ ^tmp_admin=elements=search_input^ -
        +
        + +
        +
        ^tmp_admin=elements=table_headers^ diff --git a/plugins/pencilblue/templates/angular/admin/content/media/manage_media.html b/plugins/pencilblue/templates/angular/admin/content/media/manage_media.html index 319ee37dc..f45665e4e 100644 --- a/plugins/pencilblue/templates/angular/admin/content/media/manage_media.html +++ b/plugins/pencilblue/templates/angular/admin/content/media/manage_media.html @@ -1,14 +1,21 @@ + diff --git a/public/js/angular/factories/admin/media.js b/public/js/angular/factories/admin/media.js new file mode 100644 index 000000000..69e683399 --- /dev/null +++ b/public/js/angular/factories/admin/media.js @@ -0,0 +1,41 @@ +(function() { + angular.module('pencilblue.factories.admin.media', []) + .factory('mediaFactory', function($http) { + return { + getMedia: function(options, cb) { + var queryString = ''; + for(var key in options) { + if(queryString.length) { + queryString += '&'; + } + else { + queryString += '?'; + } + + queryString += key + '=' + options[key]; + } + + $http.get('/api/content/media' + queryString) + .success(function(result) { + cb(null, result.data, result.total); + }) + .error(function(error) { + cb(error); + }); + }, + + deleteMedia: function(id, cb) { + $http({ + method: 'DELETE', + url: '/api/content/media/' + id + }) + .success(function(result) { + cb(null, result); + }) + .error(function(error) { + cb(error); + }); + } + }; + }); +}()); From c8a40c3cd8d52f4f655c69f72a5a12b2c5541cca Mon Sep 17 00:00:00 2001 From: Brian Hyder Date: Wed, 16 Sep 2015 17:39:54 -0400 Subject: [PATCH 630/790] #677 Documentation and removal of duplicate code --- include/localization.js | 187 ++++++++++++++++++++--------- test/include/localization_tests.js | 1 - 2 files changed, 130 insertions(+), 58 deletions(-) diff --git a/include/localization.js b/include/localization.js index bdba97d93..78e3b85a8 100755 --- a/include/localization.js +++ b/include/localization.js @@ -247,7 +247,7 @@ module.exports = function LocalizationModule(pb) { * @param {Object} params * @param {Object} [options] * @param {String} [options.site=global] - * @returns {String} + * @return {String} */ Localization.prototype.g = function() { var key = arguments[0]; @@ -575,28 +575,14 @@ module.exports = function LocalizationModule(pb) { * @return {Boolean} */ Localization.registerLocale = function(locale, localizations, options) { - if (!util.isObject(options)) { - throw new Error('options parameter is required'); - } - if (!util.isString(options.plugin)) { - throw new Error('options.plugin is required'); - } + assertOptions(options); return Localization._registerLocale(locale, localizations, options); }; Localization._registerLocale = function(locale, localizations, options) { - if (util.isString(locale)) { - locale = Localization.parseLocaleStr(locale); - } - if (util.isObject(locale)) { - if (!util.isString(locale.language)) { - throw new Error('locale.language is required'); - } - } - else { - throw new Error('locale parameter is required'); - } + locale = parseLocale(locale); + if (!util.isObject(localizations)) { throw new Error('localizations parameter is required'); } @@ -656,17 +642,13 @@ module.exports = function LocalizationModule(pb) { * @return {Boolean} */ Localization.registerLocalization = function(locale, key, value, options) { - if (!util.isObject(options)) { - throw new Error('options parameter is required'); - } - if (!util.isString(options.plugin)) { - throw new Error('options.plugin is required'); - } + assertOptions(options); return Localization._registerLocalization(locale, key, value, options); }; /** + * * @private * @static * @method _registerLocalization @@ -678,17 +660,7 @@ module.exports = function LocalizationModule(pb) { * @return {Boolean} */ Localization._registerLocalization = function(locale, key, value, options) { - if (util.isString(locale)) { - locale = Localization.parseLocaleStr(locale); - } - if (util.isObject(locale)) { - if (!util.isString(locale.language)) { - throw new Error('locale.language is required'); - } - } - else { - throw new Error('locale is required'); - } + locale = parseLocale(locale); if (!util.isString(key)) { throw new Error('key parameter is required'); } @@ -751,18 +723,18 @@ module.exports = function LocalizationModule(pb) { return true; }; + /** + * Removes a locale and all keys associated with it. Optionally, the + * operation can be scoped to a single plugin. + * @static + * @method unregisterLocale + * @param {String|Object} locale + * @param {Object} [options] + * @param {String} [options.plugin] + * @returns {Boolean} + */ Localization.unregisterLocale = function(locale, options) { - if (util.isString(locale)) { - locale = Localization.parseLocaleStr(locale); - } - if (util.isObject(locale)) { - if (!util.isString(locale.language)) { - throw new Error('locale.language is required'); - } - } - else { - throw new Error('locale is required'); - } + locale = parseLocale(locale); //iterate over all of the keys var result = true; @@ -772,18 +744,21 @@ module.exports = function LocalizationModule(pb) { return result; }; + /** + * Unregisters a single key for the given locale. The locale can be just + * the language or the combination of the language and country code. + * Additionally, the operation can be scoped to a single plugin. + * @static + * @method unregisterLocalization + * @param {String|Object} locale + * @param {String} key + * @param {Object} [options] + * @param {String} [options.plugin] + * @returns {Boolean} + */ Localization.unregisterLocalization = function(locale, key, options) { - if (util.isString(locale)) { - locale = Localization.parseLocaleStr(locale); - } - if (util.isObject(locale)) { - if (!util.isString(locale.language)) { - throw new Error('locale.language is required'); - } - } - else { - throw new Error('locale is required'); - } + locale = parseLocale(locale); + if (!util.isString(key)) { throw new Error('key parameter is required'); } @@ -879,6 +854,13 @@ module.exports = function LocalizationModule(pb) { return util.clone(Localization.supported); }; + /** + * Determines if a raw localization value contains named parameters + * @static + * @method containsParameters + * @param {String} localizationValue + * @return {Boolean} + */ Localization.containsParameters = function(localizationValue) { if (!util.isString(localizationValue)) { throw new Error('localizationParameter is required'); @@ -886,6 +868,18 @@ module.exports = function LocalizationModule(pb) { return localizationValue.search(Localization.PARAM_REPLACEMENT_REGEX) >= 0; }; + /** + * Given a raw localization value and a set of parameters the function will + * attempt to replace the named parameters in the raw value with the values + * provided in the params. When a named parameter is found that was not + * provided a value the defaultVal parameter value is used. + * @static + * @method replaceParameters + * @param {String} value + * @param {Object} params + * @param {String} [defaultVal] + * @return {String} + */ Localization.replaceParameters = function(value, params, defaultVal) { if (!util.isString(value)) { throw new Error('value parameter is required'); @@ -942,6 +936,14 @@ module.exports = function LocalizationModule(pb) { }); }; + /** + * Parses a locale or file path to a locale file and extracts the language + * and country code into an object. + * @static + * @method parseLocaleStr + * @param {String} filePath + * @return {Object} + */ Localization.parseLocaleStr = function(filePath) { if (util.isObject(filePath)) { if (!util.isString(filePath.language)) { @@ -978,6 +980,15 @@ module.exports = function LocalizationModule(pb) { }; }; + /** + * Formats a language and an optional country code into a proper locale + * format (lang-COUNTRY) + * @static + * @method formatLocale + * @param {String} language + * @param {String} [countryCode] + * @return {String} + */ Localization.formatLocale = function(language, countryCode) { if (!util.isString(language)) { throw new Error('language parameter is required'); @@ -993,10 +1004,72 @@ module.exports = function LocalizationModule(pb) { return localeStr; }; + /** + * Asserts that the options parameter is provided and that it contains a + * property "plugin" that is a string. + * @private + * @static + * @method assertOptions + * @param {Object} options + * @param {String} options.plugin + */ + function assertOptions(options) { + if (!util.isObject(options)) { + throw new Error('options parameter is required'); + } + if (!util.isString(options.plugin)) { + throw new Error('options.plugin is required'); + } + } + + /** + * Takes a locale object or string representation. When a string it is + * parsed to an object. When an object is passed it is verified. The + * function throws an error when it finds invalid format. + * @private + * @static + * @method parseLocale + * @param {String|Object} locale + * @return {Object} + */ + function parseLocale(locale) { + if (util.isString(locale)) { + locale = Localization.parseLocaleStr(locale); + } + if (util.isObject(locale)) { + if (!util.isString(locale.language)) { + throw new Error('locale.language is required'); + } + } + else { + throw new Error('locale is required'); + } + return locale; + } + + /** + * Formats a given key to be formatted as a "private" property in the + * storage structure. This is to prevent collisions between localization + * keys. + * @private + * @static + * @method k + * @param {String} key + * @return {String} + */ function k(key) { return '__' + key; } + /** + * Navigates the storage structure to find where a localization key's + * values live + * @private + * @static + * @method findKeyBlock + * @param {String} key + * @return {Object} The object that contains the values for the key + */ function findKeyBlock(key) { //parse the key diff --git a/test/include/localization_tests.js b/test/include/localization_tests.js index d2acde35e..231b7d446 100644 --- a/test/include/localization_tests.js +++ b/test/include/localization_tests.js @@ -312,7 +312,6 @@ describe('Localization', function() { ].forEach(function(testCaseParams) { it('should inspect the value and determine if parameters are found within it', function() { - console.log(testCaseParams); var result = Localization.containsParameters(testCaseParams[0]); result.should.eql(testCaseParams[1]); }); From b76aafc4e1f363bf2133031f390778574d38b5c4 Mon Sep 17 00:00:00 2001 From: Brian Hyder Date: Wed, 16 Sep 2015 21:43:00 -0400 Subject: [PATCH 631/790] #677 Documentation --- include/localization.js | 46 ++++++++++++++++++++++++++++++++++------- 1 file changed, 38 insertions(+), 8 deletions(-) diff --git a/include/localization.js b/include/localization.js index 78e3b85a8..75ffcda4a 100755 --- a/include/localization.js +++ b/include/localization.js @@ -34,8 +34,13 @@ module.exports = function LocalizationModule(pb) { * @class Localization * @constructor * @param {Object} request The request object + * @param {Object} [options] + * @param {String} [options.activeTheme] */ - function Localization(request){ + function Localization(request, options){ + if (!util.isObject(options)) { + options = {}; + } //expected to be lowercase and of the form "en-us" this.language = Localization.best(request).toString(); @@ -47,6 +52,12 @@ module.exports = function LocalizationModule(pb) { * @type {Object} */ this.cache = {}; + + /** + * The currently active theme that should be prioritized when + * performing key lookup + */ + this.activeTheme = options.activeTheme; } /** @@ -241,12 +252,14 @@ module.exports = function LocalizationModule(pb) { }; /** - * + * * @method g * @param {String} key * @param {Object} params * @param {Object} [options] * @param {String} [options.site=global] + * @param {Object} [options.params={}] + * @param {Object} [options.plugin] * @return {String} */ Localization.prototype.g = function() { @@ -515,10 +528,11 @@ module.exports = function LocalizationModule(pb) { }; /** - * + * Retrieves the localization package for the specified locale * @static * @method getLocalizationPackage * @param {String} locale + * @param {Object} [options] See options for Localization.g * @return {Object} */ Localization.getLocalizationPackage = function(locale, options) { @@ -567,11 +581,14 @@ module.exports = function LocalizationModule(pb) { }; /** - * + * Registers a localization package for the provided locale and plugin. + * @private * @static - * @method registerLocale - * @param {String} locale + * @method _registerLocale + * @param {String|Object} locale * @param {Object} localizations + * @param {Object} [options] + * @param {String} [options.string] * @return {Boolean} */ Localization.registerLocale = function(locale, localizations, options) { @@ -579,7 +596,19 @@ module.exports = function LocalizationModule(pb) { return Localization._registerLocale(locale, localizations, options); }; - + + /** + * Registers a localization package for the provided locale. Optionally, + * the packaged can be scoped to a specific plugin. + * @private + * @static + * @method _registerLocale + * @param {String|Object} locale + * @param {Object} localizations + * @param {Object} [options] + * @param {String} [options.string] + * @return {Boolean} + */ Localization._registerLocale = function(locale, localizations, options) { locale = parseLocale(locale); @@ -631,6 +660,7 @@ module.exports = function LocalizationModule(pb) { }; /** + * Registers a single localization key for the provided locale and plugin. * @private * @static * @method _registerLocalization @@ -648,7 +678,7 @@ module.exports = function LocalizationModule(pb) { }; /** - * + * Registers a single localization key for the provided locale. Optionally, the localization can be scoped to a single plugin. * @private * @static * @method _registerLocalization From 2fc6ae78cdd3806b9000219b88ac0dfc428108b0 Mon Sep 17 00:00:00 2001 From: Brian Hyder Date: Thu, 17 Sep 2015 09:03:06 -0400 Subject: [PATCH 632/790] #738 & #744 --- include/dao/db_manager.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/include/dao/db_manager.js b/include/dao/db_manager.js index 9e775da49..91fb2a241 100755 --- a/include/dao/db_manager.js +++ b/include/dao/db_manager.js @@ -88,6 +88,10 @@ module.exports = function DBManagerModule(pb) { return cb(null, dbs[name]); } + //clone the config and set the name that is being asked for + var config = util.clone(pb.config); + config.db.name = name; + //build the connection string for the mongo cluster var dbURL = DBManager.buildConnectionStr(pb.config); var options = pb.config.db.options; @@ -374,6 +378,7 @@ module.exports = function DBManagerModule(pb) { */ DBManager.buildConnectionStr = function(config) { var str = PROTOCOL_PREFIX; + var options = '?'; for (var i = 0; i < config.db.servers.length; i++) { //check for prefix for backward compatibility @@ -381,12 +386,20 @@ module.exports = function DBManagerModule(pb) { if (hostAndPort.indexOf(PROTOCOL_PREFIX) === 0) { hostAndPort = hostAndPort.substring(PROTOCOL_PREFIX.length); } + + //check for options + var parts = hostAndPort.split('?'); + if (parts.length > 1) { + options += (options.length > 1 ? '&' : '') + parts[1]; + } + hostAndPort = parts[0]; + if (i > 0) { str += ','; } str += hostAndPort; }; - return pb.UrlService.urlJoin(str, config.db.name); + return pb.UrlService.urlJoin(str, config.db.name) + options; }; //exports From fc906448643d2fc31d2053e7fb957c4dce1491b0 Mon Sep 17 00:00:00 2001 From: Brian Hyder Date: Fri, 18 Sep 2015 07:29:32 -0400 Subject: [PATCH 633/790] #738 --- include/dao/db_manager.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/dao/db_manager.js b/include/dao/db_manager.js index 91fb2a241..f1a125621 100755 --- a/include/dao/db_manager.js +++ b/include/dao/db_manager.js @@ -94,7 +94,7 @@ module.exports = function DBManagerModule(pb) { //build the connection string for the mongo cluster var dbURL = DBManager.buildConnectionStr(pb.config); - var options = pb.config.db.options; + var options = config.db.options; pb.log.debug("Attempting connection to: %s with options: %s", dbURL, JSON.stringify(options)); var self = this; From b8f46846dc33461076a9bbb6b0d8bd629a5c8e58 Mon Sep 17 00:00:00 2001 From: Brian Hyder Date: Fri, 18 Sep 2015 08:06:40 -0400 Subject: [PATCH 634/790] Factories - Documentation updates because I hate warnings --- controllers/admin/base_admin_controller.js | 2 +- include/admin_navigation.js | 4 +-- include/dao/db_manager.js | 2 +- include/dao/db_migrate.js | 28 +++++++++++++++++-- include/localization.js | 15 ++++++++-- include/repository/plugin_repository.js | 1 + include/service/admin/admin_subnav_service.js | 2 +- include/service/entities/media_service.js | 2 +- include/service/entities/plugin_service.js | 22 ++++++++------- .../entities/plugin_setting_service.js | 15 ++++++---- .../service/entities/site_query_service.js | 16 ++++++----- include/service/entities/site_service.js | 14 +++++----- include/service/entities/template_service.js | 2 +- .../jobs/sites/site_create_edit_job.js | 1 + include/service/jobs/sites/site_job_runner.js | 9 ++++-- .../media/renderers/audio_media_renderer.js | 2 +- .../renderers/daily_motion_media_renderer.js | 2 +- .../media/renderers/image_media_renderer.js | 2 +- .../renderers/instagram_media_renderer.js | 2 +- .../renderers/kickstarter_media_renderer.js | 2 +- .../media/renderers/pdf_media_renderer.js | 2 +- .../renderers/slideshare_media_renderer.js | 2 +- .../media/renderers/storify_media_renderer.js | 2 +- .../media/renderers/trinket_media_renderer.js | 2 +- .../media/renderers/video_media_renderer.js | 2 +- .../media/renderers/vimeo_media_renderer.js | 2 +- .../media/renderers/vine_media_renderer.js | 2 +- .../media/renderers/youtube_media_renderer.js | 2 +- .../controllers/admin/sites/manage_sites.js | 2 +- .../controllers/admin/sites/site_form.js | 2 +- 30 files changed, 107 insertions(+), 58 deletions(-) diff --git a/controllers/admin/base_admin_controller.js b/controllers/admin/base_admin_controller.js index d9c091d4b..b41a37cca 100644 --- a/controllers/admin/base_admin_controller.js +++ b/controllers/admin/base_admin_controller.js @@ -58,7 +58,7 @@ module.exports = function BaseAdminControllerModule(pb) { /** * Centralized place to obtain the pills to be displayed on top of the admin controller - * + * @method getAdminPills * @param navKey * @param localizationService * @param activePill diff --git a/include/admin_navigation.js b/include/admin_navigation.js index aeb713928..24816c7e0 100755 --- a/include/admin_navigation.js +++ b/include/admin_navigation.js @@ -59,7 +59,7 @@ module.exports = function AdminNavigationModule(pb) { * @static * @readonly * @property MULTISITE_NAV - * @returns {Array} + * @return {Array} */ var MULTISITE_NAV = Object.freeze({ id: 'site_entity', @@ -77,7 +77,7 @@ module.exports = function AdminNavigationModule(pb) { * @static * @readonly * @property CONTENT_NAV - * @returns {Array} + * @return {Array} */ var CONTENT_NAV = Object.freeze({ id: 'content', diff --git a/include/dao/db_manager.js b/include/dao/db_manager.js index f1a125621..d332e198c 100755 --- a/include/dao/db_manager.js +++ b/include/dao/db_manager.js @@ -283,7 +283,7 @@ module.exports = function DBManagerModule(pb) { * @method compareIndices * @param {Object} stored * @param {Object} defined - * @returns {boolean} + * @return {boolean} */ this.compareIndices = function(stored, defined) { var keys = Object.keys(stored.key); diff --git a/include/dao/db_migrate.js b/include/dao/db_migrate.js index 8607cc794..e9ccdf8d4 100644 --- a/include/dao/db_migrate.js +++ b/include/dao/db_migrate.js @@ -57,10 +57,14 @@ module.exports = function DBMigrateModule(pb) { /** * On run, transforms a single tenant instance to a multi-tenant instance where the site defined * in the single tenant instance becomes a site under global's scope. + * @class DBMigrate * @constructor DBMigrate */ function DBMigrate() { + /** + * @method run + */ this.run = function (cb) { var self = this; var siteService = new pb.SiteService(); @@ -81,6 +85,9 @@ module.exports = function DBMigrateModule(pb) { }); }; + /** + * @method createSite + */ this.createSite = function (cb) { var siteService = new pb.SiteService(); var site = pb.DocumentCreator.create('site', { @@ -90,6 +97,9 @@ module.exports = function DBMigrateModule(pb) { siteService.createSite(site, '', cb); }; + /** + * @method migrateContentAndPluginData + */ this.migrateContentAndPluginData = function(cb) { var self = this; var tasks = util.getTasks(MIGRATE_ALL, function (collections, i) { @@ -101,14 +111,23 @@ module.exports = function DBMigrateModule(pb) { async.parallel(tasks, cb); }; + /** + * @method migrateSettings + */ this.migrateSettings = function (cb) { this.migrateGlobalSubCollection('setting', SITE_SPECIFIC_SETTINGS, 'key', cb); }; + /** + * @method migrateUsers + */ this.migrateUsers = function(cb) { this.migrateGlobalSubCollection('user', SITE_SPECIFIC_USERS, 'admin', cb); }; + /** + * @method migrateGlobalSubCollection + */ this.migrateGlobalSubCollection = function(collection, siteSpecificArr, compareTo, cb) { var self = this; var dao = new pb.DAO(); @@ -124,6 +143,9 @@ module.exports = function DBMigrateModule(pb) { }); }; + /** + * @method migrateCollection + */ this.migrateCollection = function (collection, siteUid, cb) { var self = this; var dao = new pb.DAO(); @@ -138,6 +160,9 @@ module.exports = function DBMigrateModule(pb) { }); }; + /** + * @method applySiteToDocument + */ this.applySiteToDocument = function (document, siteUid, callback) { document[pb.SiteService.SITE_FIELD] = siteUid; var dao = new pb.DAO(); @@ -145,5 +170,4 @@ module.exports = function DBMigrateModule(pb) { }; } return DBMigrate; - -}; \ No newline at end of file +}; diff --git a/include/localization.js b/include/localization.js index 75ffcda4a..06f22c138 100755 --- a/include/localization.js +++ b/include/localization.js @@ -43,7 +43,16 @@ module.exports = function LocalizationModule(pb) { } //expected to be lowercase and of the form "en-us" + /** + * @property language + * @type {String} + */ this.language = Localization.best(request).toString(); + + /** + * @property localeObj + * @type {Object} + */ this.localeObj = Localization.parseLocaleStr(this.language); /** @@ -56,6 +65,8 @@ module.exports = function LocalizationModule(pb) { /** * The currently active theme that should be prioritized when * performing key lookup + * @property activeTheme + * @type {String} */ this.activeTheme = options.activeTheme; } @@ -761,7 +772,7 @@ module.exports = function LocalizationModule(pb) { * @param {String|Object} locale * @param {Object} [options] * @param {String} [options.plugin] - * @returns {Boolean} + * @return {Boolean} */ Localization.unregisterLocale = function(locale, options) { locale = parseLocale(locale); @@ -784,7 +795,7 @@ module.exports = function LocalizationModule(pb) { * @param {String} key * @param {Object} [options] * @param {String} [options.plugin] - * @returns {Boolean} + * @return {Boolean} */ Localization.unregisterLocalization = function(locale, key, options) { locale = parseLocale(locale); diff --git a/include/repository/plugin_repository.js b/include/repository/plugin_repository.js index 4f177f5d7..0764199ea 100644 --- a/include/repository/plugin_repository.js +++ b/include/repository/plugin_repository.js @@ -50,6 +50,7 @@ module.exports = function PluginRepositoryModule(pb) { /** * Empty constructor because this object uses static methods. + * @class PluginRepository * @constructor */ function PluginRepository() {} diff --git a/include/service/admin/admin_subnav_service.js b/include/service/admin/admin_subnav_service.js index 1cd9f4f80..e2e1b21b3 100755 --- a/include/service/admin/admin_subnav_service.js +++ b/include/service/admin/admin_subnav_service.js @@ -136,7 +136,7 @@ module.exports = function AdminSubnavServiceModule(pb) { * @method addSiteToPills * @param {Array} standardPills list of pills * @param {String} siteName name of the site to add to the pill - * @returns {Array} a list of pills with site name added + * @return {Array} a list of pills with site name added */ AdminSubnavService.addSiteToPills = function (standardPills, siteName) { var pills = []; diff --git a/include/service/entities/media_service.js b/include/service/entities/media_service.js index 7851871a6..9cfb2a280 100755 --- a/include/service/entities/media_service.js +++ b/include/service/entities/media_service.js @@ -851,7 +851,7 @@ module.exports = function MediaServiceModule(pb) { * that can be uploaded into the system. * @static * @method getSupportedExtensions - * @returns {Array} provides an array of strings + * @return {Array} provides an array of strings */ MediaService.getSupportedExtensions = function() { diff --git a/include/service/entities/plugin_service.js b/include/service/entities/plugin_service.js index 5ff27a1cd..5fd55c273 100755 --- a/include/service/entities/plugin_service.js +++ b/include/service/entities/plugin_service.js @@ -206,7 +206,7 @@ module.exports = function PluginServiceModule(pb) { /** * Get a array of active plugin names with site name as a prefix: site_name_plugin_name * @method getAllActivePluginNames - * @returns {Array} array of active plugin names with site name prefix. + * @return {Array} array of active plugin names with site name prefix. */ PluginService.prototype.getAllActivePluginNames = function() { var pluginNames = []; @@ -342,8 +342,8 @@ module.exports = function PluginServiceModule(pb) { * Retrieves the theme settings for the specified plugin * * @method getThemeSettings - * @param pluginName The uid of the plugin - * @param cb A callback that provides two parameters: cb(err, settingsObject) + * @param {String} pluginName The uid of the plugin + * @param {Function} cb A callback that provides two parameters: cb(err, settingsObject) */ PluginService.prototype.getThemeSettings = function(pluginName, cb) { var settingService = getPluginSettingService(this); @@ -352,9 +352,9 @@ module.exports = function PluginServiceModule(pb) { /** * Retrieves the theme settings for the specified plugin only for the site set in the current plugin service - * - * @param pluginName - * @param cb + * @method getThemeSettingsBySite + * @param {String} pluginName + * @param {Function} cb */ PluginService.prototype.getThemeSettingsBySite = function (pluginName, cb) { var settingService = getPluginSettingService(this); @@ -386,8 +386,8 @@ module.exports = function PluginServiceModule(pb) { * persisted. * * @method resetSettings - * @param details The details object to extract the settings from - * @param cb A callback that provides two parameters: cb(error, TRUE/FALSE). + * @param {Object} details The details object to extract the settings from + * @param {Function} cb A callback that provides two parameters: cb(error, TRUE/FALSE). * TRUE if the settings were successfully cleared and reloaded. FALSE if not. */ PluginService.prototype.resetSettings = function(details, cb) { @@ -402,8 +402,8 @@ module.exports = function PluginServiceModule(pb) { * the callback. * * @method resetThemeSettings - * @param details The details object to extract the settings from - * @param cb A callback that provides two parameters: cb(error, TRUE/FALSE). + * @param {Object} details The details object to extract the settings from + * @param {Function} cb A callback that provides two parameters: cb(error, TRUE/FALSE). * TRUE if the settings were successfully cleared and reloaded. FALSE if not. */ PluginService.prototype.resetThemeSettings = function(details, cb) { @@ -413,6 +413,7 @@ module.exports = function PluginServiceModule(pb) { /** * Deletes the plugin settings for when plugin uninstalls. + * @method purgePluginSettings * @param {String} pluginUid - the plugin unique id * @param {Function} cb - callback function */ @@ -423,6 +424,7 @@ module.exports = function PluginServiceModule(pb) { /** * Deletes the theme settings for when plugin uninstalls. + * @method purgeThemeSettings * @param {String} pluginUid - the plugin unique id * @param {Function} cb - callback function */ diff --git a/include/service/entities/plugin_setting_service.js b/include/service/entities/plugin_setting_service.js index 6e9366c51..cc1186f65 100644 --- a/include/service/entities/plugin_setting_service.js +++ b/include/service/entities/plugin_setting_service.js @@ -23,8 +23,9 @@ module.exports = function PluginSettingServiceModule(pb) { /** * Constructor for service that retrieves plugin settings from the database. - * @param {String} siteUID - site unique id + * @class PluginSettingService * @constructor + * @param {String} siteUID - site unique id */ function PluginSettingService(siteUID){ //construct settings services @@ -123,6 +124,7 @@ module.exports = function PluginSettingServiceModule(pb) { /** * Gets the plugin settings for one site only. * Will not default to global plugin settings for given plugin. + * @method getSettingsBySite * @param {String} pluginName - name of plugin to retrieve settings for * @param {Function} cb - callback function */ @@ -351,6 +353,7 @@ module.exports = function PluginSettingServiceModule(pb) { /** * Retrieves theme settings for specified plugin and for only the specified site. * Will not default to global theme settings. + * @method getThemeSettingsBySite * @param {String} pluginName - the name of the plugin to get theme settings * @param {Function} cb - callback function */ @@ -512,7 +515,7 @@ module.exports = function PluginSettingServiceModule(pb) { * use an in memory service. * @param {Boolean} opts.useCache Indicates if the generated layered service should * use a cache service. - * @param serviceName The name of the service + * @param {String} opts.serviceName The name of the service * @param {String} opts.site * @param {Boolean} opts.onlyThisSite * @return {SimpleLayeredService} @@ -549,8 +552,8 @@ module.exports = function PluginSettingServiceModule(pb) { * @private * @static * @method getAdminPluginSettingsService - * @param {PluginSettingService} - * @returns {SimpleLayeredService} + * @param {PluginSettingService} self + * @return {SimpleLayeredService} */ function getAdminPluginSettingsService(self) { if(!self.adminPluginSettingsService) { @@ -571,8 +574,8 @@ module.exports = function PluginSettingServiceModule(pb) { * @private * @static * @method getAdminThemeSettingService - * @param {PluginSettingService} - * @returns {SimpleLayeredService} + * @param {PluginSettingService} self + * @return {SimpleLayeredService} */ function getAdminThemeSettingsService(self) { if(!self.adminThemeSettingsService) { diff --git a/include/service/entities/site_query_service.js b/include/service/entities/site_query_service.js index 37e7f987b..042792352 100644 --- a/include/service/entities/site_query_service.js +++ b/include/service/entities/site_query_service.js @@ -86,7 +86,7 @@ module.exports = function SiteQueryServiceModule(pb) { * @method modifyLoadWhere * @param {String} site * @param {Object} where - * @returns {Object} + * @return {Object} */ function modifyLoadWhere(site, where) { if (pb.config.multisite.enabled) { @@ -111,7 +111,7 @@ module.exports = function SiteQueryServiceModule(pb) { * @method modifyLoadOptions * @param {String} site * @param {Object} options - * @returns {Object} + * @return {Object} */ function modifyLoadOptions(site, options) { if (pb.config.multisite.enabled) { @@ -196,7 +196,7 @@ module.exports = function SiteQueryServiceModule(pb) { * @private * @method siteSpecific * @param {SiteQueryService} self - * @returns {Boolean} + * @return {Boolean} */ function siteSpecific(self) { return self.onlyThisSite || isGlobal(self.siteUid); @@ -206,7 +206,7 @@ module.exports = function SiteQueryServiceModule(pb) { * @private * @method isGlobal * @param {String} siteUid - * @returns {Boolean} + * @return {Boolean} */ function isGlobal(siteUid) { return !siteUid || siteUid === GLOBAL_SITE; @@ -217,7 +217,7 @@ module.exports = function SiteQueryServiceModule(pb) { * @method modifySave * @param {String} site * @param {Object} objectToSave - * @returns {Object} The object to save + * @return {Object} The object to save */ function modifySave(site, objectToSave) { if (pb.config.multisite.enabled && !(SITE_FIELD in objectToSave)) { @@ -245,7 +245,7 @@ module.exports = function SiteQueryServiceModule(pb) { /** * Wrapper for site-aware DAO.save. Saves object to database - * + * @method save * @param dbObj * @param options * @param callback @@ -257,6 +257,7 @@ module.exports = function SiteQueryServiceModule(pb) { /** * Gets all collection names + * @method getCollections * @param {Function} cb */ SiteQueryService.prototype.getCollections = function (cb) { @@ -270,6 +271,7 @@ module.exports = function SiteQueryServiceModule(pb) { /** * Deletes all site specific content + * @method deleteSiteSpecificContent * @param {Array} collections - array of collection names * @param {String} siteid - unique site id * @param {Function} callback - callback function @@ -318,4 +320,4 @@ module.exports = function SiteQueryServiceModule(pb) { }; return SiteQueryService; -}; \ No newline at end of file +}; diff --git a/include/service/entities/site_service.js b/include/service/entities/site_service.js index d17ddb6cb..9271b279a 100644 --- a/include/service/entities/site_service.js +++ b/include/service/entities/site_service.js @@ -241,7 +241,7 @@ module.exports = function SiteServiceModule(pb) { * @method activateSite * @param {String} siteUid - site unique id * @param {Function} cb - callback to run after job is completed - * @returns {String} the job id + * @return {String} the job id */ SiteService.prototype.activateSite = function(siteUid, cb) { cb = cb || util.cb; @@ -260,7 +260,7 @@ module.exports = function SiteServiceModule(pb) { * @method deactivateSite * @param {String} siteUid - site unique id * @param {Function} cb - callback to run after job is completed - * @returns {String} the job id + * @return {String} the job id */ SiteService.prototype.deactivateSite = function(siteUid, cb) { cb = cb || util.cb; @@ -281,7 +281,7 @@ module.exports = function SiteServiceModule(pb) { * @param {String} options.hostname - result of site hostname edit/create * @param {String} options.displayName - result of site display name edit/create * @param {Function} cb - callback to run after job is completed - * @returns {String} the job id + * @return {String} the job id */ SiteService.prototype.editSite = function(options, cb) { cb = cb || util.cb; @@ -487,7 +487,7 @@ module.exports = function SiteServiceModule(pb) { * Returns true if siteid given is global or non-existant (to remain backwards compatible) * @method isGlobal * @param {String} siteid - the site id to check - * @returns {Boolean} true if global or does not exist + * @return {Boolean} true if global or does not exist */ SiteService.isGlobal = function (siteid) { return (!siteid || siteid === SiteService.GLOBAL_SITE); @@ -522,7 +522,7 @@ module.exports = function SiteServiceModule(pb) { * Central place to get the current site. Backwards compatible cleansing * @method getCurrentSite * @param {String} siteid - site is to cleanse - * @returns {String} SiteService.GLOBAL_SITE if not specified, or siteid otherwise + * @return {String} SiteService.GLOBAL_SITE if not specified, or siteid otherwise */ SiteService.getCurrentSite = function (siteid) { return siteid || SiteService.GLOBAL_SITE; @@ -532,7 +532,7 @@ module.exports = function SiteServiceModule(pb) { * Return site field from object. * @method getSiteFromObject * @param {Object} object - * @returns {String} the value of the object's site field key + * @return {String} the value of the object's site field key */ SiteService.getSiteFromObject = function (object) { if (!object) { @@ -545,7 +545,7 @@ module.exports = function SiteServiceModule(pb) { * Determine whether http or https is being used for the site and return hostname attached to http(s) * @method getHostWithProtocol * @param {String} hostname - * @returns {String} hostname with protocol attached + * @return {String} hostname with protocol attached */ SiteService.getHostWithProtocol = function(hostname) { hostname = hostname.match(/^http/g) ? hostname : "//" + hostname; diff --git a/include/service/entities/template_service.js b/include/service/entities/template_service.js index 743037cb8..b4c82ece3 100755 --- a/include/service/entities/template_service.js +++ b/include/service/entities/template_service.js @@ -592,7 +592,7 @@ module.exports = function(pb) { * @param {Object} model The model is inspect * @param {String} [modelName] The optional name of the model. The name * will prefix all of the model's keys. - * @returns {Boolean} TRUE when all keys were successfully registered. + * @return {Boolean} TRUE when all keys were successfully registered. * FALSE if a single items fails to register. */ TemplateService.prototype.registerModel = function(model, modelName) { diff --git a/include/service/jobs/sites/site_create_edit_job.js b/include/service/jobs/sites/site_create_edit_job.js index dc23484db..8ffbaa58a 100644 --- a/include/service/jobs/sites/site_create_edit_job.js +++ b/include/service/jobs/sites/site_create_edit_job.js @@ -7,6 +7,7 @@ module.exports = function SiteCreateEditJobModule(pb) { /** * Job to create/edit a site. + * @class SiteCreateEditJob * @constructor SiteCreateEditJob * @extends SiteJobRunner */ diff --git a/include/service/jobs/sites/site_job_runner.js b/include/service/jobs/sites/site_job_runner.js index 6ca82ffa0..851e8ed39 100644 --- a/include/service/jobs/sites/site_job_runner.js +++ b/include/service/jobs/sites/site_job_runner.js @@ -4,6 +4,7 @@ module.exports = function SiteJobRunnerModule(pb) { /** * Setup for running site activation job. + * @class SiteJobRunner * @constructor SiteJobRunner * @extends ClusterJobRunner */ @@ -16,17 +17,19 @@ module.exports = function SiteJobRunnerModule(pb) { /** * The site for this instance of SiteJobRunner + * @property site * @type {string} - default to empty string */ SiteJobRunner.prototype.site = ''; /** * Set the site for an instance of SiteJobRunner. + * @method setSite * @param {Object} options - * @param {String} options.uid - site unique id * @param {String} options.hostname - result of site hostname edit/create * @param {String} options.displayName - result of site display name edit/create - * @returns {Object} the instance in which the site was set. + * @return {Object} the instance in which the site was set. */ SiteJobRunner.prototype.setSite = function(options) { this.site = options; @@ -35,7 +38,8 @@ module.exports = function SiteJobRunnerModule(pb) { /** * Get the current site of this instance of SiteJobRunner. - * @returns {Object} the site object + * @method getSite + * @return {Object} the site object */ SiteJobRunner.prototype.getSite = function() { return this.site; @@ -48,6 +52,7 @@ module.exports = function SiteJobRunnerModule(pb) { * that provides four properties: success (Boolean), id (String), pluginUid * (String), results (Array of raw results). * @override + * @method processClusterResults * @param {Error} err - error in the process or null * @param {Array} results - array of results from the tasks run * @param {Function} cb - callback function diff --git a/include/service/media/renderers/audio_media_renderer.js b/include/service/media/renderers/audio_media_renderer.js index 1f8bcfe8e..8dd3c8b4d 100644 --- a/include/service/media/renderers/audio_media_renderer.js +++ b/include/service/media/renderers/audio_media_renderer.js @@ -89,7 +89,7 @@ module.exports = function AudioMediaRendererModule(pb) { * Retrieves the supported extension types for the renderer. * @static * @method getSupportedExtensions - * @returns {Array} + * @return {Array} */ AudioMediaRenderer.getSupportedExtensions = function() { return Object.keys(SUPPORTED); diff --git a/include/service/media/renderers/daily_motion_media_renderer.js b/include/service/media/renderers/daily_motion_media_renderer.js index 260a207c5..ceb6bbb09 100644 --- a/include/service/media/renderers/daily_motion_media_renderer.js +++ b/include/service/media/renderers/daily_motion_media_renderer.js @@ -72,7 +72,7 @@ module.exports = function AudioMediaRendererModule(pb) { * Retrieves the supported extension types for the renderer. * @static * @method getSupportedExtensions - * @returns {Array} + * @return {Array} */ DailyMotionMediaRenderer.getSupportedExtensions = function() { return []; diff --git a/include/service/media/renderers/image_media_renderer.js b/include/service/media/renderers/image_media_renderer.js index 698d361dc..1eb4e5dd6 100644 --- a/include/service/media/renderers/image_media_renderer.js +++ b/include/service/media/renderers/image_media_renderer.js @@ -91,7 +91,7 @@ module.exports = function ImageMediaRendererModule(pb) { * Retrieves the supported extension types for the renderer. * @static * @method getSupportedExtensions - * @returns {Array} + * @return {Array} */ ImageMediaRenderer.getSupportedExtensions = function() { return Object.keys(SUPPORTED); diff --git a/include/service/media/renderers/instagram_media_renderer.js b/include/service/media/renderers/instagram_media_renderer.js index 808d31bed..8a0730132 100644 --- a/include/service/media/renderers/instagram_media_renderer.js +++ b/include/service/media/renderers/instagram_media_renderer.js @@ -68,7 +68,7 @@ module.exports = function InstagramMediaRendererModule(pb) { * Retrieves the supported extension types for the renderer. * @static * @method getSupportedExtensions - * @returns {Array} + * @return {Array} */ InstagramMediaRenderer.getSupportedExtensions = function() { return []; diff --git a/include/service/media/renderers/kickstarter_media_renderer.js b/include/service/media/renderers/kickstarter_media_renderer.js index 0e9e67f68..9a80f2a8b 100644 --- a/include/service/media/renderers/kickstarter_media_renderer.js +++ b/include/service/media/renderers/kickstarter_media_renderer.js @@ -68,7 +68,7 @@ module.exports = function KickStarterMediaRendererModule(pb) { * Retrieves the supported extension types for the renderer. * @static * @method getSupportedExtensions - * @returns {Array} + * @return {Array} */ KickStarterMediaRenderer.getSupportedExtensions = function() { return []; diff --git a/include/service/media/renderers/pdf_media_renderer.js b/include/service/media/renderers/pdf_media_renderer.js index 00998e22b..a0ebc906c 100644 --- a/include/service/media/renderers/pdf_media_renderer.js +++ b/include/service/media/renderers/pdf_media_renderer.js @@ -83,7 +83,7 @@ module.exports = function(pb) { * Retrieves the supported extension types for the renderer. * @static * @method getSupportedExtensions - * @returns {Array} + * @return {Array} */ PdfMediaRenderer.getSupportedExtensions = function() { return Object.keys(SUPPORTED); diff --git a/include/service/media/renderers/slideshare_media_renderer.js b/include/service/media/renderers/slideshare_media_renderer.js index 9fa6c233b..f89d67c77 100644 --- a/include/service/media/renderers/slideshare_media_renderer.js +++ b/include/service/media/renderers/slideshare_media_renderer.js @@ -69,7 +69,7 @@ module.exports = function SlideShareMediaRendererModule(pb) { * Retrieves the supported extension types for the renderer. * @static * @method getSupportedExtensions - * @returns {Array} + * @return {Array} */ SlideShareMediaRenderer.getSupportedExtensions = function() { return []; diff --git a/include/service/media/renderers/storify_media_renderer.js b/include/service/media/renderers/storify_media_renderer.js index 8a4bd2fe2..2475a6953 100644 --- a/include/service/media/renderers/storify_media_renderer.js +++ b/include/service/media/renderers/storify_media_renderer.js @@ -69,7 +69,7 @@ module.exports = function StorifyMediaRendererModule(pb) { * Retrieves the supported extension types for the renderer. * @static * @method getSupportedExtensions - * @returns {Array} + * @return {Array} */ StorifyMediaRenderer.getSupportedExtensions = function() { return []; diff --git a/include/service/media/renderers/trinket_media_renderer.js b/include/service/media/renderers/trinket_media_renderer.js index 8d2c03f98..66cf27878 100644 --- a/include/service/media/renderers/trinket_media_renderer.js +++ b/include/service/media/renderers/trinket_media_renderer.js @@ -68,7 +68,7 @@ module.exports = function TrinketMediaRendererModule(pb) { * Retrieves the supported extension types for the renderer. * @static * @method getSupportedExtensions - * @returns {Array} + * @return {Array} */ TrinketMediaRenderer.getSupportedExtensions = function() { return []; diff --git a/include/service/media/renderers/video_media_renderer.js b/include/service/media/renderers/video_media_renderer.js index 833aa3700..3dc80a45f 100644 --- a/include/service/media/renderers/video_media_renderer.js +++ b/include/service/media/renderers/video_media_renderer.js @@ -92,7 +92,7 @@ module.exports = function VideoMediaRendererModule(pb) { * Retrieves the supported extension types for the renderer. * @static * @method getSupportedExtensions - * @returns {Array} + * @return {Array} */ VideoMediaRenderer.getSupportedExtensions = function() { return Object.keys(SUPPORTED); diff --git a/include/service/media/renderers/vimeo_media_renderer.js b/include/service/media/renderers/vimeo_media_renderer.js index 37e65d117..ca9a7ccf3 100644 --- a/include/service/media/renderers/vimeo_media_renderer.js +++ b/include/service/media/renderers/vimeo_media_renderer.js @@ -70,7 +70,7 @@ module.exports = function VimeoMediaRendererModule(pb) { * Retrieves the supported extension types for the renderer. * @static * @method getSupportedExtensions - * @returns {Array} + * @return {Array} */ VimeoMediaRenderer.getSupportedExtensions = function() { return []; diff --git a/include/service/media/renderers/vine_media_renderer.js b/include/service/media/renderers/vine_media_renderer.js index caf5d2527..6a1493b66 100644 --- a/include/service/media/renderers/vine_media_renderer.js +++ b/include/service/media/renderers/vine_media_renderer.js @@ -69,7 +69,7 @@ module.exports = function VineMediaRendererModule(pb) { * Retrieves the supported extension types for the renderer. * @static * @method getSupportedExtensions - * @returns {Array} + * @return {Array} */ VineMediaRenderer.getSupportedExtensions = function() { return []; diff --git a/include/service/media/renderers/youtube_media_renderer.js b/include/service/media/renderers/youtube_media_renderer.js index 05bdeea3d..c78e49ee3 100644 --- a/include/service/media/renderers/youtube_media_renderer.js +++ b/include/service/media/renderers/youtube_media_renderer.js @@ -68,7 +68,7 @@ module.exports = function YouTubeMediaRendererModule(pb) { * Retrieves the supported extension types for the renderer. * @static * @method getSupportedExtensions - * @returns {Array} + * @return {Array} */ YouTubeMediaRenderer.getSupportedExtensions = function() { return []; diff --git a/plugins/pencilblue/controllers/admin/sites/manage_sites.js b/plugins/pencilblue/controllers/admin/sites/manage_sites.js index d28d4cf31..cb9743a81 100644 --- a/plugins/pencilblue/controllers/admin/sites/manage_sites.js +++ b/plugins/pencilblue/controllers/admin/sites/manage_sites.js @@ -57,7 +57,7 @@ module.exports = function(pb) { * @method getSubNavItems * @param {String} key * @param {Object} ls - * @returns {Array} array of nav items + * @return {Array} array of nav items */ ManageSites.getSubNavItems = function(key, ls) { return [{ diff --git a/plugins/pencilblue/controllers/admin/sites/site_form.js b/plugins/pencilblue/controllers/admin/sites/site_form.js index 71382521f..b4c5740ff 100644 --- a/plugins/pencilblue/controllers/admin/sites/site_form.js +++ b/plugins/pencilblue/controllers/admin/sites/site_form.js @@ -107,7 +107,7 @@ module.exports = function SiteFormModule(pb) { * @method getSubNavItems * @param key * @param {Object} ls - the localization service - * @returns {Array} the array of nav objects to render. + * @return {Array} the array of nav objects to render. */ SiteForm.getSubNavItems = function(key, ls) { return [{ From 19c738bbd1b14b832451218b7cdfb76ae9ca07ee Mon Sep 17 00:00:00 2001 From: Blake Callens Date: Fri, 18 Sep 2015 11:08:03 -0400 Subject: [PATCH 635/790] initial manage articles conversion --- .../admin/content/articles/manage_articles.js | 21 ++- .../api/content/article_api_controller.js | 48 ++++-- .../content/articles/manage_articles.html | 154 ++++++++++++++---- public/js/angular/factories/admin/article.js | 41 +++++ 4 files changed, 212 insertions(+), 52 deletions(-) create mode 100644 public/js/angular/factories/admin/article.js diff --git a/plugins/pencilblue/controllers/admin/content/articles/manage_articles.js b/plugins/pencilblue/controllers/admin/content/articles/manage_articles.js index a3e5f0421..e922725c6 100755 --- a/plugins/pencilblue/controllers/admin/content/articles/manage_articles.js +++ b/plugins/pencilblue/controllers/admin/content/articles/manage_articles.js @@ -16,11 +16,11 @@ */ module.exports = function(pb) { - + //pb dependencies var util = pb.util; var UserService = pb.UserService; - + /** * Interface for managing articles */ @@ -37,6 +37,21 @@ module.exports = function(pb) { where.author = this.session.authentication.user_id; } + var angularObjects = pb.ClientJs.getAngularObjects({ + navigation: pb.AdminNavigation.get(self.session, ['content', 'articles'], self.ls, self.site), + pills: self.getAdminPills(SUB_NAV_KEY, self.ls, SUB_NAV_KEY) + }); + + var manageArticlesStr = self.ls.get('MANAGE_ARTICLES'); + self.setPageName(self.ls.get('MANAGE_ARTICLES')); + self.ts.registerLocal('angular_objects', new pb.TemplateValue(angularObjects, false)); + self.ts.load('admin/content/articles/manage_articles', function (err, data) { + var result = '' + data; + cb({content: result}); + }); + + return; + var opts = { select: { headline: 1, @@ -98,7 +113,7 @@ module.exports = function(pb) { pills = []; pb.log.error("ManageArticles: AdminSubnavService.getWithSite callback error. ERROR[%s]", err.stack); } - + var angularObjects = pb.ClientJs.getAngularObjects( { navigation: pb.AdminNavigation.get(self.session, ['content', 'articles'], self.ls, self.site), diff --git a/plugins/pencilblue/controllers/api/content/article_api_controller.js b/plugins/pencilblue/controllers/api/content/article_api_controller.js index ee5c46b29..a07e3cd99 100644 --- a/plugins/pencilblue/controllers/api/content/article_api_controller.js +++ b/plugins/pencilblue/controllers/api/content/article_api_controller.js @@ -22,16 +22,17 @@ module.exports = function(pb) { var ArticleServiceV2 = pb.ArticleServiceV2; var SecurityService = pb.SecurityService; var CommentService = pb.CommentService; + var UserService = pb.UserService; /** - * + * * @class ArticleApiController * @constructor * @extends BaseApiController */ function ArticleApiController(){} util.inherits(ArticleApiController, pb.BaseApiController); - + /** * Initializes the controller * @method init @@ -41,26 +42,47 @@ module.exports = function(pb) { ArticleApiController.prototype.init = function(context, cb) { var self = this; var init = function(err) { - + /** - * + * * @property service * @type {ArticleServiceV2} */ self.service = new ArticleServiceV2(self.getServiceContext()); - + /** * * @property commentService * @type {CommentService} */ self.commentService = new CommentService(self.getServiceContext()); - + cb(err, true); }; ArticleApiController.super_.prototype.init.apply(this, [context, init]); }; - + + ArticleApiController.prototype.getAll = function(cb) { + var self = this; + var options = this.processQuery(); + + this.service.getAllWithCount(options, function(err, obj) { + if (util.isError(err)) { + return cb(err); + } + else if (util.isNullOrUndefined(obj)) { + return self.notFound(cb); + } + + var userService = new UserService(self.getServiceContext()); + userService.getAuthors(obj.data, function(err, articlesWithAuthorNames) { + cb({ + content: obj + }); + }); + }); + }; + /** * Processes the query string to develop the where clause for the query request * @method processWhere @@ -70,11 +92,11 @@ module.exports = function(pb) { ArticleApiController.prototype.processWhere = function(q) { var where = null; var failures = []; - + //build query & get results var search = q.q; if (pb.ValidationService.isNonEmptyStr(search, true)) { - + var patternStr = ".*" + util.escapeRegExp(search) + ".*"; var pattern = new RegExp(patternStr, "i"); where = { @@ -90,7 +112,7 @@ module.exports = function(pb) { failures: failures }; }; - + /** * Retrieves comments for an article * @method getAllComments @@ -101,7 +123,7 @@ module.exports = function(pb) { options.where.article = this.pathVars.articleId; this.commentService.getAllWithCount(options, this.handleGet(cb)); }; - + /** * Adds a comment to an article * @method addComment @@ -112,7 +134,7 @@ module.exports = function(pb) { dto.article = this.pathVars.articleId; this.commentService.save(dto, this.handleSave(cb, true)); }; - + /** * Deletes a comment from an article * @method deleteComment @@ -125,4 +147,4 @@ module.exports = function(pb) { //exports return ArticleApiController; -}; \ No newline at end of file +}; diff --git a/plugins/pencilblue/templates/angular/admin/content/articles/manage_articles.html b/plugins/pencilblue/templates/angular/admin/content/articles/manage_articles.html index 2a6ff4254..940229cca 100644 --- a/plugins/pencilblue/templates/angular/admin/content/articles/manage_articles.html +++ b/plugins/pencilblue/templates/angular/admin/content/articles/manage_articles.html @@ -1,14 +1,21 @@ + diff --git a/public/js/angular/factories/admin/article.js b/public/js/angular/factories/admin/article.js new file mode 100644 index 000000000..19b722d31 --- /dev/null +++ b/public/js/angular/factories/admin/article.js @@ -0,0 +1,41 @@ +(function() { + angular.module('pencilblue.factories.admin.articles', []) + .factory('articleFactory', function($http) { + return { + getArticles: function(options, cb) { + var queryString = ''; + for(var key in options) { + if(queryString.length) { + queryString += '&'; + } + else { + queryString += '?'; + } + + queryString += key + '=' + options[key]; + } + + $http.get('/api/content/articles' + queryString) + .success(function(result) { + cb(null, result.data, result.total); + }) + .error(function(error) { + cb(error); + }); + }, + + deleteArticle: function(id, cb) { + $http({ + method: 'DELETE', + url: '/api/content/articles/' + id + }) + .success(function(result) { + cb(null, result); + }) + .error(function(error) { + cb(error); + }); + } + }; + }); +}()); From 3abad50ffa00b15ed69e20da5bda49582e893bcb Mon Sep 17 00:00:00 2001 From: Blake Callens Date: Fri, 18 Sep 2015 13:27:41 -0400 Subject: [PATCH 636/790] manage articles completed w/ async sort --- .../admin/content/articles/manage_articles.js | 74 ------------------- .../content/articles/manage_articles.html | 17 +++-- public/js/angular/services/sort.js | 19 +++-- 3 files changed, 25 insertions(+), 85 deletions(-) diff --git a/plugins/pencilblue/controllers/admin/content/articles/manage_articles.js b/plugins/pencilblue/controllers/admin/content/articles/manage_articles.js index e922725c6..30fb09437 100755 --- a/plugins/pencilblue/controllers/admin/content/articles/manage_articles.js +++ b/plugins/pencilblue/controllers/admin/content/articles/manage_articles.js @@ -49,80 +49,6 @@ module.exports = function(pb) { var result = '' + data; cb({content: result}); }); - - return; - - var opts = { - select: { - headline: 1, - draft: 1, - url: 1, - author: 1, - publish_date: 1 - }, - where: where, - order: {publish_date: pb.DAO.ASC}, - - }; - self.siteQueryService.q('article', opts, function(err, articles) { - if(util.isError(err)) { - return self.reqHandler.serveError(err); - } - else if (articles.length <= 0) { - return self.redirect('/admin/content/articles/new', cb); - } - - var userService = new UserService(self.getServiceContext()); - userService.getAuthors(articles, function(err, articlesWithAuthorNames) { - articles = self.getArticleStatuses(articlesWithAuthorNames); - self.getAngularObjects(self.site, articles, function (angularObjects) { - var manageArticlesStr = self.ls.get('MANAGE_ARTICLES'); - self.setPageName(manageArticlesStr); - self.ts.registerLocal('angular_objects', new pb.TemplateValue(angularObjects, false)); - self.ts.load('admin/content/articles/manage_articles', function (err, data) { - var result = '' + data; - cb({content: result}); - }); - }); - }); - }); - }; - - ManageArticles.prototype.getArticleStatuses = function(articles) { - var now = new Date(); - for(var i = 0; i < articles.length; i++) { - if(articles[i].draft) { - articles[i].status = this.ls.get('DRAFT'); - } - else if(articles[i].publish_date > now) { - articles[i].status = this.ls.get('UNPUBLISHED'); - } - else { - articles[i].status = this.ls.get('PUBLISHED'); - } - } - - return articles; - }; - - ManageArticles.prototype.getAngularObjects = function(site, articles, cb) { - var self = this; - pb.AdminSubnavService.getWithSite(SUB_NAV_KEY, self.ls, SUB_NAV_KEY, {site: site}, function(err, pills) { - //Log error. Don't return - if (util.isError(err)){ - pills = []; - pb.log.error("ManageArticles: AdminSubnavService.getWithSite callback error. ERROR[%s]", err.stack); - } - - var angularObjects = pb.ClientJs.getAngularObjects( - { - navigation: pb.AdminNavigation.get(self.session, ['content', 'articles'], self.ls, self.site), - pills: pills, - articles: articles - }); - //TODO: err first arg for style. User experience error when no pills? - cb(angularObjects); - }); }; ManageArticles.getSubNavItems = function(key, ls, data) { diff --git a/plugins/pencilblue/templates/angular/admin/content/articles/manage_articles.html b/plugins/pencilblue/templates/angular/admin/content/articles/manage_articles.html index 940229cca..ec3f4d761 100644 --- a/plugins/pencilblue/templates/angular/admin/content/articles/manage_articles.html +++ b/plugins/pencilblue/templates/angular/admin/content/articles/manage_articles.html @@ -17,6 +17,7 @@ $scope.paginationLimit = 25; $scope.paginationPages = []; $scope.deleteNameKey = 'headline'; + $scope.orderString = 'publish_date=0' $scope.tableHeaders = [{ name: loc.articles.HEADLINE, @@ -41,8 +42,8 @@ }, { name: loc.articles.PUBLISH_DATE, field: 'publish_date', - sortAsc: true, - sortDesc: false + sortAsc: false, + sortDesc: true }]; $scope.getArticles = function(cb) { @@ -54,7 +55,8 @@ articleFactory.getArticles({ $limit: $scope.paginationLimit, - $offset: $scope.paginationIndex + $offset: $scope.paginationIndex, + $order: $scope.orderString }, function(error, articles, total) { if(error) { $scope.errorMessage = error.message; @@ -103,7 +105,8 @@ articleFactory.getArticles({ q: $scope.searchText, $limit: $scope.paginationLimit, - $offset: $scope.paginationIndex + $offset: $scope.paginationIndex, + $order: $scope.orderString }, function(error, articles, total) { if(error) { $scope.errorMessage = error.message; @@ -139,6 +142,11 @@ }; $scope.sort = function(headerIndex) { + var targetHeader = sortService.setSortHeader($scope.articles, $scope.tableHeaders, headerIndex); + $scope.orderString = targetHeader.field + '=' + (targetHeader.sortDesc ? '0' : '1'); + $scope.paginate(0, true); + + return; sortService.sortByHeader($scope.articles, $scope.tableHeaders, headerIndex, function(articles, headers) { $scope.articles = articles; $scope.headers = headers; @@ -180,6 +188,5 @@ } $scope.paginate(0); - //$scope.sort(4); }); diff --git a/public/js/angular/services/sort.js b/public/js/angular/services/sort.js index 6a5ddc189..96979bbb1 100644 --- a/public/js/angular/services/sort.js +++ b/public/js/angular/services/sort.js @@ -4,16 +4,18 @@ angular.module('sort', []) cb($filter('orderBy')(items, field, sortDesc)); }; - this.sortByHeader = function(items, headers, headerIndex, cb) { + this.setSortHeader = function(items, headers, headerIndex) { if(headers[headerIndex].unsorted) { cb(items, headers); return; } - var sortDesc = true; + var targetHeader; for(var i = 0; i < headers.length; i++) { if(i === headerIndex) { + targetHeader = headers[i]; + if(headers[i].sortAsc) { headers[i].sortAsc = false; headers[i].sortDesc = true; @@ -21,7 +23,6 @@ angular.module('sort', []) else { headers[i].sortAsc = true; headers[i].sortDesc = false; - sortDesc = false; } } else { @@ -30,8 +31,14 @@ angular.module('sort', []) } } - this.sort(items, headers[headerIndex].field, sortDesc, function(items) { + return targetHeader; + }; + + this.sortByHeader = function(items, headers, headerIndex, cb) { + var targetHeader = this.setSortHeader(items, headers, headerIndex); + + this.sort(items, headers[headerIndex].field, targetHeader.sortDesc, function(items) { cb(items, headers); }); - } -}) + }; +}); From 208bf2c2ee161d17ab1a19736147d2a4c0ffd76c Mon Sep 17 00:00:00 2001 From: Blake Callens Date: Fri, 18 Sep 2015 13:41:40 -0400 Subject: [PATCH 637/790] spinner to articles page --- .../content/articles/manage_articles.html | 35 +++++++++++-------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/plugins/pencilblue/templates/admin/content/articles/manage_articles.html b/plugins/pencilblue/templates/admin/content/articles/manage_articles.html index 3f7d3df38..5f4bb4545 100755 --- a/plugins/pencilblue/templates/admin/content/articles/manage_articles.html +++ b/plugins/pencilblue/templates/admin/content/articles/manage_articles.html @@ -1,23 +1,28 @@ ^tmp_admin=head^
        - ^tmp_admin=elements=error_success^ - ^tmp_admin=elements=sub_nav^ - ^tmp_admin=elements=search_input^ + ^tmp_admin=elements=error_success^ + ^tmp_admin=elements=sub_nav^ + ^tmp_admin=elements=search_input^ +
        + +
        +
        -
        - ^tmp_admin=elements=table_headers^ - - - - - - - - -
        + + ^tmp_admin=elements=table_headers^ + + + + + + + + +
        ^tmp_admin=elements=pagination^ - ^tmp_admin=elements=delete_modal^ +
        +^tmp_admin=elements=delete_modal^ ^tmp_angular=admin=content=articles=manage_articles^ ^tmp_admin=footer^ From 5fcbcea1956f7c418b904c0021b9624f729b853e Mon Sep 17 00:00:00 2001 From: Mark Baird Date: Sat, 19 Sep 2015 17:59:08 -0400 Subject: [PATCH 638/790] Allow configuration of media root URL --- include/config.js | 10 ++ .../media/renderers/audio_media_renderer.js | 2 +- .../media/renderers/base_media_renderer.js | 13 ++ .../media/renderers/image_media_renderer.js | 2 +- .../media/renderers/pdf_media_renderer.js | 2 +- .../media/renderers/video_media_renderer.js | 2 +- .../admin/site_settings/configuration.js | 1 + .../admin/site_settings/configuration.html | 4 + public/localization/de-DE.js | 1 + public/localization/en-US.js | 1 + public/localization/es-ES.js | 1 + public/localization/fr-FR.js | 1 + public/localization/pl-PL.js | 1 + public/localization/pt-BR.js | 1 + public/localization/ro-RO.js | 1 + .../content/article_renderer_tests.js | 2 +- .../content/article_service_v2_tests.js | 2 +- .../entities/content/page_service_tests.js | 2 +- .../media/renderers/media_root_tests.js | 128 ++++++++++++++++++ 19 files changed, 170 insertions(+), 7 deletions(-) create mode 100644 test/include/service/media/renderers/media_root_tests.js diff --git a/include/config.js b/include/config.js index 52d6d0b46..5f2327820 100755 --- a/include/config.js +++ b/include/config.js @@ -354,6 +354,11 @@ Configuration.getBaseConfig = function(multisite) { provider: 'fs', parent_dir: 'public', + //The root media URL. Example values: '//cdn.mydomain.com' or + //'http://example-bucket.s3-website-us-east-1.amazonaws.com'. Use this + //if media is served from a domain other than the site root. + urlRoot: '', + //The maximum size of media files that can be uploaded to the server in //bytes max_upload_size: 2 * 1024 * 1024 @@ -460,6 +465,11 @@ Configuration.mergeWithBase = function(overrides) { if (config.siteRoot.lastIndexOf('/') === (config.siteRoot.length - 1)) { config.siteRoot = config.siteRoot.substring(0, config.siteRoot.length - 1); } + + //special check to ensure that there is no ending slash on the media root + if (config.media.urlRoot.lastIndexOf('/') === (config.media.urlRoot.length - 1)) { + config.media.urlRoot = config.media.urlRoot.substring(0, config.media.urlRoot.length - 1); + } return config; }; diff --git a/include/service/media/renderers/audio_media_renderer.js b/include/service/media/renderers/audio_media_renderer.js index 1f8bcfe8e..b6d574dbc 100644 --- a/include/service/media/renderers/audio_media_renderer.js +++ b/include/service/media/renderers/audio_media_renderer.js @@ -243,7 +243,7 @@ module.exports = function AudioMediaRendererModule(pb) { * represented by the media Id */ AudioMediaRenderer.getEmbedUrl = function(mediaId) { - return mediaId; + return BaseMediaRenderer.getEmbedUrl(mediaId); }; /** diff --git a/include/service/media/renderers/base_media_renderer.js b/include/service/media/renderers/base_media_renderer.js index 6115a20c9..801699f3e 100644 --- a/include/service/media/renderers/base_media_renderer.js +++ b/include/service/media/renderers/base_media_renderer.js @@ -60,6 +60,19 @@ module.exports = function BaseMediaRenderer(pb) { '>'; }; + /** + * Retrieves the source URI that will be used when generating the rendering. + * This base implementation prepends the configured media urlRoot value to the media URI. + * @static + * @method getEmbedUrl + * @param {String} mediaId The unique (only to the type) media identifier + * @return {String} A properly formatted URI string that points to the resource + * represented by the media Id + */ + BaseMediaRenderer.getEmbedUrl = function(mediaId) { + return pb.UrlService.urlJoin(pb.config.media.urlRoot, mediaId); + }; + /** * Generates an attribute string from a hash of key/value pairs * @static diff --git a/include/service/media/renderers/image_media_renderer.js b/include/service/media/renderers/image_media_renderer.js index 698d361dc..e63e59dcc 100644 --- a/include/service/media/renderers/image_media_renderer.js +++ b/include/service/media/renderers/image_media_renderer.js @@ -225,7 +225,7 @@ module.exports = function ImageMediaRendererModule(pb) { * represented by the media Id */ ImageMediaRenderer.getEmbedUrl = function(mediaId) { - return mediaId; + return BaseMediaRenderer.getEmbedUrl(mediaId); }; /** diff --git a/include/service/media/renderers/pdf_media_renderer.js b/include/service/media/renderers/pdf_media_renderer.js index 00998e22b..05659d1c1 100644 --- a/include/service/media/renderers/pdf_media_renderer.js +++ b/include/service/media/renderers/pdf_media_renderer.js @@ -236,7 +236,7 @@ module.exports = function(pb) { * represented by the media Id */ PdfMediaRenderer.getEmbedUrl = function(mediaId) { - return mediaId; + return BaseMediaRenderer.getEmbedUrl(mediaId); }; /** diff --git a/include/service/media/renderers/video_media_renderer.js b/include/service/media/renderers/video_media_renderer.js index 833aa3700..89d9b6b32 100644 --- a/include/service/media/renderers/video_media_renderer.js +++ b/include/service/media/renderers/video_media_renderer.js @@ -246,7 +246,7 @@ module.exports = function VideoMediaRendererModule(pb) { * represented by the media Id */ VideoMediaRenderer.getEmbedUrl = function(mediaId) { - return mediaId; + return BaseMediaRenderer.getEmbedUrl(mediaId); }; /** diff --git a/plugins/pencilblue/controllers/admin/site_settings/configuration.js b/plugins/pencilblue/controllers/admin/site_settings/configuration.js index d17d4aa5a..ca206ee12 100755 --- a/plugins/pencilblue/controllers/admin/site_settings/configuration.js +++ b/plugins/pencilblue/controllers/admin/site_settings/configuration.js @@ -48,6 +48,7 @@ module.exports = function(pb) { var config = { siteName: self.siteObj.displayName, siteRoot: self.siteObj.hostname, + mediaRoot: pb.config.media.urlRoot ? pb.config.media.urlRoot : self.siteObj.hostname, documentRoot: pb.config.docRoot, siteIP: pb.config.siteIP, sitePort: pb.config.sitePort, diff --git a/plugins/pencilblue/templates/admin/site_settings/configuration.html b/plugins/pencilblue/templates/admin/site_settings/configuration.html index 6b5580d38..26880f810 100755 --- a/plugins/pencilblue/templates/admin/site_settings/configuration.html +++ b/plugins/pencilblue/templates/admin/site_settings/configuration.html @@ -14,6 +14,10 @@
    ^loc_SITE_ROOT^
    ^loc_MEDIA_ROOT^
    ^loc_DOCUMENT_ROOT^
    - ^tmp_admin=elements=table_headers^ - - - - - - - - -
    + + ^tmp_admin=elements=table_headers^ + + + + + + + + +
    ^tmp_admin=elements=pagination^ - ^tmp_admin=elements=delete_modal^ + +^tmp_admin=elements=delete_modal^ ^tmp_angular=admin=content=pages=manage_pages^ ^tmp_admin=footer^ diff --git a/plugins/pencilblue/templates/admin/elements/search_input.html b/plugins/pencilblue/templates/admin/elements/search_input.html index da976ec22..76701f7f1 100644 --- a/plugins/pencilblue/templates/admin/elements/search_input.html +++ b/plugins/pencilblue/templates/admin/elements/search_input.html @@ -1,5 +1,5 @@
    - + diff --git a/plugins/pencilblue/templates/angular/admin/content/articles/manage_articles.html b/plugins/pencilblue/templates/angular/admin/content/articles/manage_articles.html index ec3f4d761..3f81cf036 100644 --- a/plugins/pencilblue/templates/angular/admin/content/articles/manage_articles.html +++ b/plugins/pencilblue/templates/angular/admin/content/articles/manage_articles.html @@ -26,7 +26,7 @@ sortDesc: false }, { name: loc.generic.STATUS, - field: 'status', + field: 'draft', sortAsc: false, sortDesc: false }, { diff --git a/plugins/pencilblue/templates/angular/admin/content/pages/manage_pages.html b/plugins/pencilblue/templates/angular/admin/content/pages/manage_pages.html index 51193bd63..4b44bcc9c 100644 --- a/plugins/pencilblue/templates/angular/admin/content/pages/manage_pages.html +++ b/plugins/pencilblue/templates/angular/admin/content/pages/manage_pages.html @@ -1,15 +1,23 @@ + diff --git a/public/js/angular/factories/admin/page.js b/public/js/angular/factories/admin/page.js new file mode 100644 index 000000000..a3742f7dd --- /dev/null +++ b/public/js/angular/factories/admin/page.js @@ -0,0 +1,41 @@ +(function() { + angular.module('pencilblue.factories.admin.pages', []) + .factory('pageFactory', function($http) { + return { + getPages: function(options, cb) { + var queryString = ''; + for(var key in options) { + if(queryString.length) { + queryString += '&'; + } + else { + queryString += '?'; + } + + queryString += key + '=' + options[key]; + } + + $http.get('/api/content/pages' + queryString) + .success(function(result) { + cb(null, result.data, result.total); + }) + .error(function(error) { + cb(error); + }); + }, + + deletePage: function(id, cb) { + $http({ + method: 'DELETE', + url: '/api/content/pages/' + id + }) + .success(function(result) { + cb(null, result); + }) + .error(function(error) { + cb(error); + }); + } + }; + }); +}()); From a3befdc53534db86bc81f6882363395f3c619374 Mon Sep 17 00:00:00 2001 From: Mark Baird Date: Sun, 20 Sep 2015 13:34:53 -0400 Subject: [PATCH 640/790] Fix for subnav pills failing to load on media list page --- .../admin/content/media/manage_media.js | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/plugins/pencilblue/controllers/admin/content/media/manage_media.js b/plugins/pencilblue/controllers/admin/content/media/manage_media.js index f9f547379..5ada41f77 100755 --- a/plugins/pencilblue/controllers/admin/content/media/manage_media.js +++ b/plugins/pencilblue/controllers/admin/content/media/manage_media.js @@ -63,20 +63,18 @@ module.exports = function(pb) { ManageMedia.prototype.getAngularObjects = function(mediaData, cb) { var self = this; pb.AdminSubnavService.getWithSite(SUB_NAV_KEY, self.ls, SUB_NAV_KEY, {site: self.site}, function(err, pills) { + //Log error. Don't return + if (util.isError(err)){ + pills = []; + pb.log.error("ManageMedia: AdminSubnavService.getWithSite callback error. ERROR[%s]", err.stack); + } + var angularObjects = pb.ClientJs.getAngularObjects( { navigation: pb.AdminNavigation.get(self.session, ['content', 'media'], self.ls, self.site), - pills: [], + pills: pills, media: pb.MediaService.formatMedia(mediaData) }); - //Log error. Don't return - if (util.isError(err)){ - pb.log.error("ManageMedia: AdminSubnavService.getWithSite callback error. ERROR[%s]", err.stack); - } - //Only populate pills if we didn't fail - else { - angularObjects.pills = pills; - } //TODO: err first arg for style. User experience error when no pills? cb(angularObjects); }); From 717d6193bd7e38c34e76c37d8fa1853c38cc082a Mon Sep 17 00:00:00 2001 From: Brian Hyder Date: Mon, 21 Sep 2015 22:19:40 -0400 Subject: [PATCH 641/790] Fixes #755 Allows PB to listen for process signals and shutdown appropriately --- include/system/system.js | 3 +++ pencilblue.js | 1 + 2 files changed, 4 insertions(+) diff --git a/include/system/system.js b/include/system/system.js index b9624344e..bd4962ad1 100755 --- a/include/system/system.js +++ b/include/system/system.js @@ -31,6 +31,9 @@ var util = require('../util.js'); */ module.exports = function System(pb){ + //pb dependencies + var log = pb.log; + /** * * @private diff --git a/pencilblue.js b/pencilblue.js index c2c927216..e11668073 100755 --- a/pencilblue.js +++ b/pencilblue.js @@ -337,6 +337,7 @@ function PencilBlue(config){ */ this.start = function() { var self = this; + pb.system.registerSignalHandlers(true); pb.system.onStart(function(){ self.init(); }); From 35f1b75ef92e2dce7378fb9c6f83bb1b538e1e29 Mon Sep 17 00:00:00 2001 From: Blake Callens Date: Tue, 22 Sep 2015 11:29:01 -0400 Subject: [PATCH 642/790] reverted media --- include/service/entities/media_service.js | 98 +++++++++---------- .../admin/content/media/manage_media.js | 25 ++--- .../api/content/media_api_controller.js | 79 --------------- plugins/pencilblue/include/routes.js | 50 ---------- .../admin/content/media/manage_media.html | 5 +- .../admin/content/media/manage_media.html | 92 ++++------------- public/js/angular/factories/admin/media.js | 41 -------- 7 files changed, 73 insertions(+), 317 deletions(-) delete mode 100644 plugins/pencilblue/controllers/api/content/media_api_controller.js delete mode 100644 public/js/angular/factories/admin/media.js diff --git a/include/service/entities/media_service.js b/include/service/entities/media_service.js index 9cfb2a280..832bc3b76 100755 --- a/include/service/entities/media_service.js +++ b/include/service/entities/media_service.js @@ -45,7 +45,7 @@ module.exports = function MediaServiceModule(pb) { if (!provider) { throw new Error('A valid media provider is required. Please check your configuration'); } - + /** * * @property provider @@ -53,7 +53,7 @@ module.exports = function MediaServiceModule(pb) { */ this.provider = provider; } - + /** * * @private @@ -365,7 +365,7 @@ module.exports = function MediaServiceModule(pb) { }; /** - * Determines if the media URI is a file. It is determined to be a file if and + * Determines if the media URI is a file. It is determined to be a file if and * only if the URI does not begin with "http" or "//". * @static * @method isFile @@ -380,8 +380,8 @@ module.exports = function MediaServiceModule(pb) { * @method getMediaDescriptor * @param {String} mediaURL * @param {Boolean} isFile Indicates if the media resource was uploaded to the server. - * @param {Function} cb A callback with two parameters. First, an Error if - * occurred and second is an object that describes the media resource described + * @param {Function} cb A callback with two parameters. First, an Error if + * occurred and second is an object that describes the media resource described * by the given media URL */ MediaService.prototype.getMediaDescriptor = function(mediaUrl, cb) { @@ -426,19 +426,19 @@ module.exports = function MediaServiceModule(pb) { }; /** - * Renders a resource by type and location (mediaId). + * Renders a resource by type and location (mediaId). * @method renderByLocation * @param {Object} options * @param {String} options.location The unique media identifier for the type - * @param {String} [options.type] The type of provider that knows how to render + * @param {String} [options.type] The type of provider that knows how to render * the resource - * @param {Object} [options.attrs] The desired HTML attributes that will be + * @param {Object} [options.attrs] The desired HTML attributes that will be * added to the element that provides the rendering * @param {Object} [options.style] The desired style overrides for the media - * @param {String} [options.view] The view type that the media will be rendered - * for (view, editor, post). Any style options provided will override those + * @param {String} [options.view] The view type that the media will be rendered + * for (view, editor, post). Any style options provided will override those * provided by the default style associated with the view. - * @param {Function} cb A callback that provides two parameters. An Error if + * @param {Function} cb A callback that provides two parameters. An Error if * exists and the rendered HTML content for the media resource. */ MediaService.prototype.renderByLocation = function(options, cb) { @@ -456,18 +456,18 @@ module.exports = function MediaServiceModule(pb) { }; /** - * Renders a media resource by ID where ID refers the to the media descriptor + * Renders a media resource by ID where ID refers the to the media descriptor * id. * @method renderById * @param {String} The media resource ID * @param {Object} options - * @param {Object} [options.attrs] The desired HTML attributes that will be + * @param {Object} [options.attrs] The desired HTML attributes that will be * added to the element that provides the rendering * @param {Object} [options.style] The desired style overrides for the media - * @param {String} [options.view] The view type that the media will be rendered - * for (view, editor, post). Any style options provided will override those + * @param {String} [options.view] The view type that the media will be rendered + * for (view, editor, post). Any style options provided will override those * provided by the default style associated with the view. - * @param {Function} cb A callback that provides two parameters. An Error if + * @param {Function} cb A callback that provides two parameters. An Error if * exists and the rendered HTML content for the media resource. */ MediaService.prototype.renderById = function(id, options, cb) { @@ -475,7 +475,7 @@ module.exports = function MediaServiceModule(pb) { self.siteQueryService.loadById(id, MediaService.COLL, function (err, media) { if (util.isError(err)) { - return cb(err); + return cb(err); } else if (!media) { return cb(null, null); @@ -491,13 +491,13 @@ module.exports = function MediaServiceModule(pb) { * @method render * @param {String} The media resource ID * @param {Object} options - * @param {Object} [options.attrs] The desired HTML attributes that will be + * @param {Object} [options.attrs] The desired HTML attributes that will be * added to the element that provides the rendering * @param {Object} [options.style] The desired style overrides for the media - * @param {String} [options.view] The view type that the media will be rendered - * for (view, editor, post). Any style options provided will override those + * @param {String} [options.view] The view type that the media will be rendered + * for (view, editor, post). Any style options provided will override those * provided by the default style associated with the view. - * @param {Function} cb A callback that provides two parameters. An Error if + * @param {Function} cb A callback that provides two parameters. An Error if * exists and the rendered HTML content for the media resource. */ MediaService.prototype.renderByFlag = function(flag, options, cb) { @@ -528,13 +528,13 @@ module.exports = function MediaServiceModule(pb) { * @method render * @param {String} The media resource ID * @param {Object} options - * @param {Object} [options.attrs] The desired HTML attributes that will be + * @param {Object} [options.attrs] The desired HTML attributes that will be * added to the element that provides the rendering * @param {Object} [options.style] The desired style overrides for the media - * @param {String} [options.view] The view type that the media will be rendered - * for (view, editor, post). Any style options provided will override those + * @param {String} [options.view] The view type that the media will be rendered + * for (view, editor, post). Any style options provided will override those * provided by the default style associated with the view. - * @param {Function} cb A callback that provides two parameters. An Error if + * @param {Function} cb A callback that provides two parameters. An Error if * exists and the rendered HTML content for the media resource. */ MediaService.prototype.render = function(media, options, cb) { @@ -554,14 +554,14 @@ module.exports = function MediaServiceModule(pb) { }; /** - * Retrieves the base style for the given renderer and view. Overrides will be + * Retrieves the base style for the given renderer and view. Overrides will be * applied on top of the base style. * @static * @method getStyleForView * @param {MediaRenderer} renderer An implementation of MediaRenderer - * @param {String} view The view to retrieve the default styling for (view, + * @param {String} view The view to retrieve the default styling for (view, * editor, post) - * @param {Object} [overrides] A hash of style properties that will be applied + * @param {Object} [overrides] A hash of style properties that will be applied * to the base style for the given view */ MediaService.getStyleForView = function(renderer, view, overrides) { @@ -580,7 +580,7 @@ module.exports = function MediaServiceModule(pb) { * @static * @method getRendererByType * @param {String} type The media type - * @return {MediaRenderer} A media renderer interface implementation or NULL if + * @return {MediaRenderer} A media renderer interface implementation or NULL if * none support the given type. */ MediaService.getRendererByType = function(type) { @@ -607,7 +607,7 @@ module.exports = function MediaServiceModule(pb) { * @method getRendererByType * @param {String} mediaUrl The media URL * @param {Boolean} isFile TRUE if the URL represents an uploaded file, FALSE if not - * @return {MediaRenderer} A media renderer interface implementation or NULL if + * @return {MediaRenderer} A media renderer interface implementation or NULL if * none support the given URL. */ MediaService.getRenderer = function(mediaUrl, isFile) { @@ -637,7 +637,7 @@ module.exports = function MediaServiceModule(pb) { * @static * @method getMediaFlag * @param {String} mid The media descriptor ID - * @param {Object} [options] The list of attributes to be provided to the + * @param {Object} [options] The list of attributes to be provided to the * rendering element. * @return {String} */ @@ -663,7 +663,7 @@ module.exports = function MediaServiceModule(pb) { }; /** - * Given a content string the function will search for and extract the first + * Given a content string the function will search for and extract the first * occurance of a media flag. The parsed value that is returned will include: *