Revert "Fixes: U4-4211 User without media section permission will be logged out immediately when accessing a document type using a media picker datatype (u7.0.3) - this is done by using the entityResource in the mediaPicker but to do this we need to return a cut down version of the media properties in the additionalData which is tricky because the cropper stores json which is ntext and the existing sql didn't cater for this. This also cleans up the entity service and we no longer have this internal collection of properties, everything is just added to additionalData, then had to add mediaHelper method to deal with getting urls from a media 'entity' not just a media object."
This reverts commit c38c2ede11.
This commit is contained in:
@@ -129,79 +129,30 @@ function mediaHelper(umbRequestHelper) {
|
||||
_mediaFileResolvers[propertyEditorAlias] = func;
|
||||
},
|
||||
|
||||
/**
|
||||
* @ngdoc function
|
||||
* @name umbraco.services.mediaHelper#resolveFileFromEntity
|
||||
* @methodOf umbraco.services.mediaHelper
|
||||
* @function
|
||||
*
|
||||
* @description
|
||||
* Gets the media file url for a media entity returned with the entityResource
|
||||
*
|
||||
* @param {object} mediaEntity A media Entity returned from the entityResource
|
||||
* @param {boolean} thumbnail Whether to return the thumbnail url or normal url
|
||||
*/
|
||||
resolveFileFromEntity : function(mediaEntity, thumbnail) {
|
||||
|
||||
if (!angular.isObject(mediaEntity.metaData)) {
|
||||
throw "Cannot resolve the file url from the mediaEntity, it does not contain the required metaData";
|
||||
}
|
||||
|
||||
var values = _.values(mediaEntity.metaData);
|
||||
for (var i = 0; i < values.length; i++) {
|
||||
var val = values[i];
|
||||
if (angular.isObject(val) && val.PropertyEditorAlias) {
|
||||
for (var resolver in _mediaFileResolvers) {
|
||||
if (val.PropertyEditorAlias === resolver) {
|
||||
//we need to format a property variable that coincides with how the property would be structured
|
||||
// if it came from the mediaResource just to keep things slightly easier for the file resolvers.
|
||||
var property = { value: val.Value };
|
||||
|
||||
return _mediaFileResolvers[resolver](property, mediaEntity, thumbnail);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return "";
|
||||
},
|
||||
|
||||
/**
|
||||
* @ngdoc function
|
||||
* @name umbraco.services.mediaHelper#resolveFile
|
||||
* @methodOf umbraco.services.mediaHelper
|
||||
* @function
|
||||
*
|
||||
* @description
|
||||
* Gets the media file url for a media object returned with the mediaResource
|
||||
*
|
||||
* @param {object} mediaEntity A media Entity returned from the entityResource
|
||||
* @param {boolean} thumbnail Whether to return the thumbnail url or normal url
|
||||
*/
|
||||
/*jshint loopfunc: true */
|
||||
resolveFile : function(mediaItem, thumbnail){
|
||||
|
||||
function iterateProps(props){
|
||||
var res = null;
|
||||
var _props = [];
|
||||
function _iterateProps(props){
|
||||
var result = null;
|
||||
for(var resolver in _mediaFileResolvers) {
|
||||
var property = _.find(props, function(prop){ return prop.editor === resolver; });
|
||||
var property = _.find(props, function(property){ return property.editor === resolver; });
|
||||
if(property){
|
||||
res = _mediaFileResolvers[resolver](property, mediaItem, thumbnail);
|
||||
result = _mediaFileResolvers[resolver](property, mediaItem, thumbnail);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
return result;
|
||||
}
|
||||
|
||||
//we either have properties raw on the object, or spread out on tabs
|
||||
var result = "";
|
||||
if(mediaItem.properties){
|
||||
result = iterateProps(mediaItem.properties);
|
||||
result = _iterateProps(mediaItem.properties);
|
||||
}else if(mediaItem.tabs){
|
||||
for(var tab in mediaItem.tabs) {
|
||||
if(mediaItem.tabs[tab].properties){
|
||||
result = iterateProps(mediaItem.tabs[tab].properties);
|
||||
result = _iterateProps(mediaItem.tabs[tab].properties);
|
||||
if(result){
|
||||
break;
|
||||
}
|
||||
@@ -213,26 +164,26 @@ function mediaHelper(umbRequestHelper) {
|
||||
|
||||
/*jshint loopfunc: true */
|
||||
hasFilePropertyType : function(mediaItem){
|
||||
function iterateProps(props){
|
||||
var res = false;
|
||||
function _iterateProps(props){
|
||||
var result = false;
|
||||
for(var resolver in _mediaFileResolvers) {
|
||||
var property = _.find(props, function(prop){ return prop.editor === resolver; });
|
||||
var property = _.find(props, function(property){ return property.editor === resolver; });
|
||||
if(property){
|
||||
res = true;
|
||||
result = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return res;
|
||||
return result;
|
||||
}
|
||||
|
||||
//we either have properties raw on the object, or spread out on tabs
|
||||
var result = false;
|
||||
if(mediaItem.properties){
|
||||
result = iterateProps(mediaItem.properties);
|
||||
result = _iterateProps(mediaItem.properties);
|
||||
}else if(mediaItem.tabs){
|
||||
for(var tab in mediaItem.tabs) {
|
||||
if(mediaItem.tabs[tab].properties){
|
||||
result = iterateProps(mediaItem.tabs[tab].properties);
|
||||
result = _iterateProps(mediaItem.tabs[tab].properties);
|
||||
if(result){
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -125,15 +125,11 @@ function fileUploadController($scope, $element, $compile, imageHelper, fileManag
|
||||
angular.module("umbraco")
|
||||
.controller('Umbraco.PropertyEditors.FileUploadController', fileUploadController)
|
||||
.run(function(mediaHelper, umbRequestHelper){
|
||||
if (mediaHelper && mediaHelper.registerFileResolver) {
|
||||
|
||||
//NOTE: The 'entity' can be either a normal media entity or an "entity" returned from the entityResource
|
||||
// they contain different data structures so if we need to query against it we need to be aware of this.
|
||||
if(mediaHelper && mediaHelper.registerFileResolver){
|
||||
mediaHelper.registerFileResolver("Umbraco.UploadField", function(property, entity, thumbnail){
|
||||
if (thumbnail) {
|
||||
|
||||
if (mediaHelper.detectIfImageByExtension(property.value)) {
|
||||
|
||||
var thumbnailUrl = umbRequestHelper.getApiUrl(
|
||||
"imagesApiBaseUrl",
|
||||
"GetBigThumbnail",
|
||||
|
||||
@@ -98,14 +98,11 @@ angular.module('umbraco')
|
||||
})
|
||||
.run(function (mediaHelper, umbRequestHelper) {
|
||||
if (mediaHelper && mediaHelper.registerFileResolver) {
|
||||
|
||||
//NOTE: The 'entity' can be either a normal media entity or an "entity" returned from the entityResource
|
||||
// they contain different data structures so if we need to query against it we need to be aware of this.
|
||||
mediaHelper.registerFileResolver("Umbraco.ImageCropper", function (property, entity, thumbnail) {
|
||||
if (property.value.src) {
|
||||
|
||||
if (thumbnail === true) {
|
||||
return property.value.src + "?width=500&mode=max";
|
||||
return property.value.src + "?width=600&mode=max";
|
||||
}
|
||||
else {
|
||||
return property.value.src;
|
||||
@@ -117,7 +114,6 @@ angular.module('umbraco')
|
||||
if (thumbnail) {
|
||||
|
||||
if (mediaHelper.detectIfImageByExtension(property.value)) {
|
||||
|
||||
var thumbnailUrl = umbRequestHelper.getApiUrl(
|
||||
"imagesApiBaseUrl",
|
||||
"GetBigThumbnail",
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
//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, mediaResource, mediaHelper, $timeout) {
|
||||
|
||||
//check the pre-values for multi-picker
|
||||
var multiPicker = $scope.model.config.multiPicker && $scope.model.config.multiPicker !== '0' ? true : false;
|
||||
@@ -17,24 +17,18 @@ angular.module('umbraco').controller("Umbraco.PropertyEditors.MediaPickerControl
|
||||
if ($scope.model.value) {
|
||||
var ids = $scope.model.value.split(',');
|
||||
|
||||
//NOTE: We need to use the entityResource NOT the mediaResource here because
|
||||
// the mediaResource has server side auth configured for which the user must have
|
||||
// access to the media section, if they don't they'll get auth errors. The entityResource
|
||||
// acts differently in that it allows access if the user has access to any of the apps that
|
||||
// might require it's use. Therefore we need to use the metatData property to get at the thumbnail
|
||||
// value.
|
||||
|
||||
entityResource.getByIds(ids, "Media").then(function (medias) {
|
||||
|
||||
mediaResource.getByIds(ids).then(function (medias) {
|
||||
//img.media = media;
|
||||
_.each(medias, function (media, i) {
|
||||
|
||||
//only show non-trashed items
|
||||
if (media.parentId >= -1) {
|
||||
|
||||
if (!media.thumbnail) {
|
||||
media.thumbnail = mediaHelper.resolveFileFromEntity(media, true);
|
||||
if(media.parentId >= -1){
|
||||
if(!media.thumbnail){
|
||||
media.thumbnail = mediaHelper.resolveFile(media, true);
|
||||
}
|
||||
|
||||
//media.src = mediaHelper.getImagePropertyValue({ imageModel: media });
|
||||
//media.thumbnail = mediaHelper.getThumbnailFromPath(media.src);
|
||||
$scope.images.push(media);
|
||||
$scope.ids.push(media.id);
|
||||
}
|
||||
@@ -66,10 +60,10 @@ angular.module('umbraco').controller("Umbraco.PropertyEditors.MediaPickerControl
|
||||
|
||||
_.each(data, function(media, i) {
|
||||
|
||||
if (!media.thumbnail) {
|
||||
media.thumbnail = mediaHelper.resolveFileFromEntity(media, true);
|
||||
if(!media.thumbnail){
|
||||
media.thumbnail = mediaHelper.resolveFile(media, true);
|
||||
}
|
||||
|
||||
|
||||
$scope.images.push(media);
|
||||
$scope.ids.push(media.id);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user