Re-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 commit is contained in:
@@ -129,30 +129,79 @@ 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){
|
||||
var _props = [];
|
||||
function _iterateProps(props){
|
||||
var result = null;
|
||||
|
||||
function iterateProps(props){
|
||||
var res = null;
|
||||
for(var resolver in _mediaFileResolvers) {
|
||||
var property = _.find(props, function(property){ return property.editor === resolver; });
|
||||
var property = _.find(props, function(prop){ return prop.editor === resolver; });
|
||||
if(property){
|
||||
result = _mediaFileResolvers[resolver](property, mediaItem, thumbnail);
|
||||
res = _mediaFileResolvers[resolver](property, mediaItem, thumbnail);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
return res;
|
||||
}
|
||||
|
||||
//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;
|
||||
}
|
||||
@@ -164,26 +213,26 @@ function mediaHelper(umbRequestHelper) {
|
||||
|
||||
/*jshint loopfunc: true */
|
||||
hasFilePropertyType : function(mediaItem){
|
||||
function _iterateProps(props){
|
||||
var result = false;
|
||||
function iterateProps(props){
|
||||
var res = false;
|
||||
for(var resolver in _mediaFileResolvers) {
|
||||
var property = _.find(props, function(property){ return property.editor === resolver; });
|
||||
var property = _.find(props, function(prop){ return prop.editor === resolver; });
|
||||
if(property){
|
||||
result = true;
|
||||
res = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
return res;
|
||||
}
|
||||
|
||||
//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,11 +125,15 @@ function fileUploadController($scope, $element, $compile, imageHelper, fileManag
|
||||
angular.module("umbraco")
|
||||
.controller('Umbraco.PropertyEditors.FileUploadController', fileUploadController)
|
||||
.run(function(mediaHelper, umbRequestHelper){
|
||||
if(mediaHelper && mediaHelper.registerFileResolver){
|
||||
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.UploadField", function(property, entity, thumbnail){
|
||||
if (thumbnail) {
|
||||
|
||||
if (mediaHelper.detectIfImageByExtension(property.value)) {
|
||||
|
||||
var thumbnailUrl = umbRequestHelper.getApiUrl(
|
||||
"imagesApiBaseUrl",
|
||||
"GetBigThumbnail",
|
||||
|
||||
@@ -98,11 +98,14 @@ 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=600&mode=max";
|
||||
return property.value.src + "?width=500&mode=max";
|
||||
}
|
||||
else {
|
||||
return property.value.src;
|
||||
@@ -114,6 +117,7 @@ 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, mediaResource, mediaHelper, $timeout) {
|
||||
function ($rootScope, $scope, dialogService, entityResource, mediaResource, mediaHelper, $timeout) {
|
||||
|
||||
//check the pre-values for multi-picker
|
||||
var multiPicker = $scope.model.config.multiPicker && $scope.model.config.multiPicker !== '0' ? true : false;
|
||||
@@ -17,18 +17,24 @@ angular.module('umbraco').controller("Umbraco.PropertyEditors.MediaPickerControl
|
||||
if ($scope.model.value) {
|
||||
var ids = $scope.model.value.split(',');
|
||||
|
||||
mediaResource.getByIds(ids).then(function (medias) {
|
||||
//img.media = media;
|
||||
//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) {
|
||||
|
||||
_.each(medias, function (media, i) {
|
||||
|
||||
//only show non-trashed items
|
||||
if(media.parentId >= -1){
|
||||
if(!media.thumbnail){
|
||||
media.thumbnail = mediaHelper.resolveFile(media, true);
|
||||
if (media.parentId >= -1) {
|
||||
|
||||
if (!media.thumbnail) {
|
||||
media.thumbnail = mediaHelper.resolveFileFromEntity(media, true);
|
||||
}
|
||||
|
||||
//media.src = mediaHelper.getImagePropertyValue({ imageModel: media });
|
||||
//media.thumbnail = mediaHelper.getThumbnailFromPath(media.src);
|
||||
$scope.images.push(media);
|
||||
$scope.ids.push(media.id);
|
||||
}
|
||||
@@ -60,10 +66,10 @@ angular.module('umbraco').controller("Umbraco.PropertyEditors.MediaPickerControl
|
||||
|
||||
_.each(data, function(media, i) {
|
||||
|
||||
if(!media.thumbnail){
|
||||
media.thumbnail = mediaHelper.resolveFile(media, true);
|
||||
if (!media.thumbnail) {
|
||||
media.thumbnail = mediaHelper.resolveFileFromEntity(media, true);
|
||||
}
|
||||
|
||||
|
||||
$scope.images.push(media);
|
||||
$scope.ids.push(media.id);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user