From 98eeaca5d5c1f7f3e267a474a7c2870fba9bfae1 Mon Sep 17 00:00:00 2001 From: Shannon Date: Tue, 7 Oct 2014 14:59:07 +1100 Subject: [PATCH] Fixes: U4-5597 ServerVariables cannot include dynamic data like a users start node Ids --- .../common/directives/umbtree.directive.js | 26 +++++--- .../common/mocks/umbraco.servervariables.js | 4 -- .../src/common/services/tinymce.service.js | 64 ++++++++++--------- .../src/common/services/user.service.js | 10 +++ .../mediapicker/mediapicker.controller.js | 10 ++- .../Editors/BackOfficeController.cs | 7 -- .../Models/ContentEditing/UserDetail.cs | 6 ++ .../Models/Mapping/UserModelMapper.cs | 2 + 8 files changed, 75 insertions(+), 54 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/common/directives/umbtree.directive.js b/src/Umbraco.Web.UI.Client/src/common/directives/umbtree.directive.js index 346592dfdf..481827bd56 100644 --- a/src/Umbraco.Web.UI.Client/src/common/directives/umbtree.directive.js +++ b/src/Umbraco.Web.UI.Client/src/common/directives/umbtree.directive.js @@ -3,7 +3,7 @@ * @name umbraco.directives.directive:umbTree * @restrict E **/ -function umbTreeDirective($compile, $log, $q, $rootScope, treeService, notificationsService, $timeout) { +function umbTreeDirective($compile, $log, $q, $rootScope, treeService, notificationsService, $timeout, userService) { return { restrict: 'E', @@ -141,18 +141,24 @@ function umbTreeDirective($compile, $log, $q, $rootScope, treeService, notificat // and previous so that the tree syncs properly. The tree syncs from the top down and if there are parts // of the tree's path in there that don't actually exist in the dom/model then syncing will not work. - var startNodes = [Umbraco.Sys.ServerVariables.security.startContentId, Umbraco.Sys.ServerVariables.security.startMediaId]; - _.each(startNodes, function (i) { - var found = _.find(args.path, function(p) { - return String(p) === String(i); + userService.getCurrentUser().then(function(userData) { + + var startNodes = [userData.startContentId, userData.startMediaId]; + _.each(startNodes, function (i) { + var found = _.find(args.path, function (p) { + return String(p) === String(i); + }); + if (found) { + args.path = args.path.splice(_.indexOf(args.path, found)); + } }); - if (found) { - args.path = args.path.splice(_.indexOf(args.path, found)); - } + + + loadPath(args.path, args.forceReload, args.activate); + }); + - - loadPath(args.path, args.forceReload, args.activate); return deferred.promise; }; diff --git a/src/Umbraco.Web.UI.Client/src/common/mocks/umbraco.servervariables.js b/src/Umbraco.Web.UI.Client/src/common/mocks/umbraco.servervariables.js index d52ef28814..8049b452d3 100644 --- a/src/Umbraco.Web.UI.Client/src/common/mocks/umbraco.servervariables.js +++ b/src/Umbraco.Web.UI.Client/src/common/mocks/umbraco.servervariables.js @@ -33,10 +33,6 @@ Umbraco.Sys.ServerVariables = { { alias: "myTree", packageFolder: "MyPackage" } ] }, - security : { - startContentId: -1, - startMediaId: -1 - }, isDebuggingEnabled: true, application: { assemblyVersion: "1", diff --git a/src/Umbraco.Web.UI.Client/src/common/services/tinymce.service.js b/src/Umbraco.Web.UI.Client/src/common/services/tinymce.service.js index dc277de34a..1e5758bb55 100644 --- a/src/Umbraco.Web.UI.Client/src/common/services/tinymce.service.js +++ b/src/Umbraco.Web.UI.Client/src/common/services/tinymce.service.js @@ -6,7 +6,7 @@ * @description * A service containing all logic for all of the Umbraco TinyMCE plugins */ -function tinyMceService(dialogService, $log, imageHelper, $http, $timeout, macroResource, macroService, $routeParams, umbRequestHelper, angularHelper) { +function tinyMceService(dialogService, $log, imageHelper, $http, $timeout, macroResource, macroService, $routeParams, umbRequestHelper, angularHelper, userService) { return { /** @@ -100,44 +100,48 @@ function tinyMceService(dialogService, $log, imageHelper, $http, $timeout, macro }; } - dialogService.mediaPicker({ - currentTarget: currentTarget, - onlyImages: true, - showDetails: true, - startNodeId: Umbraco.Sys.ServerVariables.security.startMediaId, - callback: function (img) { + userService.getCurrentUser().then(function(userData) { + dialogService.mediaPicker({ + currentTarget: currentTarget, + onlyImages: true, + showDetails: true, + startNodeId: userData.startMediaId, + callback: function (img) { - if (img) { - - var data = { - alt: img.altText, - src: (img.url) ? img.url : "nothing.jpg", - rel: img.id, - id: '__mcenew' - }; + if (img) { - editor.insertContent(editor.dom.createHTML('img', data)); + var data = { + alt: img.altText, + src: (img.url) ? img.url : "nothing.jpg", + rel: img.id, + id: '__mcenew' + }; - $timeout(function () { - var imgElm = editor.dom.get('__mcenew'); - var size = editor.dom.getSize(imgElm); + editor.insertContent(editor.dom.createHTML('img', data)); - if (editor.settings.maxImageSize && editor.settings.maxImageSize !== 0) { - var newSize = imageHelper.scaleToMaxSize(editor.settings.maxImageSize, size.w, size.h); + $timeout(function () { + var imgElm = editor.dom.get('__mcenew'); + var size = editor.dom.getSize(imgElm); - var s = "width: " + newSize.width + "px; height:" + newSize.height + "px;"; - editor.dom.setAttrib(imgElm, 'style', s); - editor.dom.setAttrib(imgElm, 'id', null); + if (editor.settings.maxImageSize && editor.settings.maxImageSize !== 0) { + var newSize = imageHelper.scaleToMaxSize(editor.settings.maxImageSize, size.w, size.h); - if (img.url) { - var src = img.url + "?width=" + newSize.width + "&height=" + newSize.height; - editor.dom.setAttrib(imgElm, 'data-mce-src', src); + var s = "width: " + newSize.width + "px; height:" + newSize.height + "px;"; + editor.dom.setAttrib(imgElm, 'style', s); + editor.dom.setAttrib(imgElm, 'id', null); + + if (img.url) { + var src = img.url + "?width=" + newSize.width + "&height=" + newSize.height; + editor.dom.setAttrib(imgElm, 'data-mce-src', src); + } } - } - }, 500); + }, 500); + } } - } + }); }); + + } }); }, diff --git a/src/Umbraco.Web.UI.Client/src/common/services/user.service.js b/src/Umbraco.Web.UI.Client/src/common/services/user.service.js index df5213afd0..b78f643cba 100644 --- a/src/Umbraco.Web.UI.Client/src/common/services/user.service.js +++ b/src/Umbraco.Web.UI.Client/src/common/services/user.service.js @@ -227,6 +227,16 @@ angular.module('umbraco.services') var result = { user: data, authenticated: true, lastUserId: lastUserId }; + //TODO: This is a mega backwards compatibility hack... These variables SHOULD NOT exist in the server variables + // since they are not supposed to be dynamic but I accidentally added them there in 7.1.5 IIRC so some people might + // now be relying on this :( + if (Umbraco && Umbraco.Sys && Umbraco.Sys.ServerVariables) { + Umbraco.Sys.ServerVariables["security"] = { + startContentId: data.startContentId, + startMediaId: data.startMediaId + } + } + if (args && args.broadcastEvent) { //broadcast a global event, will inform listening controllers to load in the user specific data eventsService.emit("app.authenticated", result); diff --git a/src/Umbraco.Web.UI.Client/src/views/propertyeditors/mediapicker/mediapicker.controller.js b/src/Umbraco.Web.UI.Client/src/views/propertyeditors/mediapicker/mediapicker.controller.js index d4f5901802..d2342ec5bc 100644 --- a/src/Umbraco.Web.UI.Client/src/views/propertyeditors/mediapicker/mediapicker.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/propertyeditors/mediapicker/mediapicker.controller.js @@ -1,13 +1,17 @@ //this controller simply tells the dialogs service to open a mediaPicker window //with a specified callback, this callback will receive an object with a selection on it angular.module('umbraco').controller("Umbraco.PropertyEditors.MediaPickerController", - function ($rootScope, $scope, dialogService, entityResource, mediaResource, mediaHelper, $timeout) { + function ($rootScope, $scope, dialogService, entityResource, mediaResource, mediaHelper, $timeout, userService) { //check the pre-values for multi-picker var multiPicker = $scope.model.config.multiPicker && $scope.model.config.multiPicker !== '0' ? true : false; - if (!$scope.model.config.startNodeId) - $scope.model.config.startNodeId = Umbraco.Sys.ServerVariables.security.startMediaId; + if (!$scope.model.config.startNodeId) { + userService.getCurrentUser().then(function (userData) { + $scope.model.config.startNodeId = userData.startMediaId; + }); + } + function setupViewModel() { diff --git a/src/Umbraco.Web/Editors/BackOfficeController.cs b/src/Umbraco.Web/Editors/BackOfficeController.cs index 7e23b20023..9ff5bd4af8 100644 --- a/src/Umbraco.Web/Editors/BackOfficeController.cs +++ b/src/Umbraco.Web/Editors/BackOfficeController.cs @@ -250,13 +250,6 @@ namespace Umbraco.Web.Editors {"trees", GetTreePluginsMetaData()} } }, - { - "security", new Dictionary - { - {"startContentId", Security.CurrentUser.StartContentId}, - {"startMediaId", Security.CurrentUser.StartMediaId} - } - }, {"isDebuggingEnabled", HttpContext.IsDebuggingEnabled}, { "application", GetApplicationState() diff --git a/src/Umbraco.Web/Models/ContentEditing/UserDetail.cs b/src/Umbraco.Web/Models/ContentEditing/UserDetail.cs index 1ab322e3f3..f32a379218 100644 --- a/src/Umbraco.Web/Models/ContentEditing/UserDetail.cs +++ b/src/Umbraco.Web/Models/ContentEditing/UserDetail.cs @@ -31,6 +31,12 @@ namespace Umbraco.Web.Models.ContentEditing [DataMember(Name = "remainingAuthSeconds")] public double SecondsUntilTimeout { get; set; } + [DataMember(Name = "startContentId")] + public int StartContentId { get; set; } + + [DataMember(Name = "startMediaId")] + public int StartMediaId { get; set; } + /// /// A list of sections the user is allowed to view. /// diff --git a/src/Umbraco.Web/Models/Mapping/UserModelMapper.cs b/src/Umbraco.Web/Models/Mapping/UserModelMapper.cs index 3ee3e80098..0bda50e1fc 100644 --- a/src/Umbraco.Web/Models/Mapping/UserModelMapper.cs +++ b/src/Umbraco.Web/Models/Mapping/UserModelMapper.cs @@ -15,6 +15,8 @@ namespace Umbraco.Web.Models.Mapping config.CreateMap() .ForMember(detail => detail.UserId, opt => opt.MapFrom(user => GetIntId(user.Id))) .ForMember(detail => detail.UserType, opt => opt.MapFrom(user => user.UserType.Alias)) + .ForMember(detail => detail.StartContentId, opt => opt.MapFrom(user => user.StartContentId)) + .ForMember(detail => detail.StartMediaId, opt => opt.MapFrom(user => user.StartMediaId)) .ForMember(detail => detail.Culture, opt => opt.MapFrom(user => ui.Culture(user))) .ForMember( detail => detail.EmailHash,