// Umbraco.Code.MapAll -Properties -Errors -Edited -Updater -Alias -IsContainer private void Map(IMedia source, MediaItemDisplay target, MapperContext context) { target.ContentApps = _commonMapper.GetContentApps(source); target.ContentType = _commonMapper.GetContentType(source, context); target.ContentTypeId = source.ContentType.Id; target.ContentTypeAlias = source.ContentType.Alias; target.ContentTypeName = source.ContentType.Name; target.CreateDate = source.CreateDate; target.Icon = source.ContentType.Icon; target.Id = source.Id; target.IsChildOfListView = DetermineIsChildOfListView(source); target.Key = source.Key; target.MediaLink = string.Join(",", source.GetUrls(Current.Configs.Settings().Content, _logger)); target.Name = source.Name; target.Owner = _commonMapper.GetOwner(source, context); target.ParentId = source.ParentId; target.Path = source.Path; target.SortOrder = source.SortOrder; target.State = null; target.Tabs = _tabsAndPropertiesMapper.Map(source, context); target.Trashed = source.Trashed; target.TreeNodeUrl = _commonMapper.GetTreeNodeUrl <MediaTreeController>(source); target.Udi = Udi.Create(Constants.UdiEntityType.Media, source.Key); target.UpdateDate = source.UpdateDate; target.VariesByCulture = source.ContentType.VariesByCulture(); }
private static void AfterMap(IMedia media, MediaItemDisplay display, IDataTypeService dataTypeService) { //map the tree node url if (HttpContext.Current != null) { var urlHelper = new UrlHelper(new RequestContext(new HttpContextWrapper(HttpContext.Current), new RouteData())); var url = urlHelper.GetUmbracoApiService <MediaTreeController>(controller => controller.GetTreeNode(display.Id.ToString(), null)); display.TreeNodeUrl = url; } if (media.ContentType.IsContainer) { TabsAndPropertiesResolver.AddListView(display, "media", dataTypeService); } TabsAndPropertiesResolver.MapGenericProperties(media, display); }
private static void AfterMap(IMedia media, MediaItemDisplay display) { //map the tree node url if (HttpContext.Current != null) { var urlHelper = new UrlHelper(new RequestContext(new HttpContextWrapper(HttpContext.Current), new RouteData())); var url = urlHelper.GetUmbracoApiService<MediaTreeController>(controller => controller.GetTreeNode(display.Id.ToString(), null)); display.TreeNodeUrl = url; } if (media.ContentType.IsContainer) { TabsAndPropertiesResolver.AddContainerView(display, "media"); } TabsAndPropertiesResolver.MapGenericProperties(media, display); }
/// <summary> /// Returns an item to be used to display the recycle bin for media /// </summary> /// <returns></returns> public MediaItemDisplay GetRecycleBin() { var apps = new List <ContentApp>(); apps.Add(ListViewContentAppFactory.CreateContentApp(_dataTypeService, _propertyEditors, "recycleBin", "media", Constants.DataTypes.DefaultMediaListView)); apps[0].Active = true; var display = new MediaItemDisplay { Id = Constants.System.RecycleBinMedia, Alias = "recycleBin", ParentId = -1, Name = _localizedTextService.Localize("general", "recycleBin"), ContentTypeAlias = "recycleBin", CreateDate = DateTime.Now, IsContainer = true, Path = "-1," + Constants.System.RecycleBinMedia, ContentApps = apps }; return(display); }
private Task <HttpResponseMessage> RemoveInacessibleMediaNodesFromPath(HttpRequestMessage request, CancellationToken cancellationToken) { IUser user = ContextHelpers.EnsureUmbracoContext().Security.CurrentUser; int[] startNodes = StartNodeRepository.GetCachedStartNodesByUserId(user.Id).Media; if (user.UserType.Alias == "admin" || startNodes == null) { return(base.SendAsync(request, cancellationToken)); } return(base.SendAsync(request, cancellationToken) .ContinueWith(task => { HttpResponseMessage response = task.Result; if (!response.IsSuccessStatusCode) { return response; } try { HttpContent data = response.Content; MediaItemDisplay media = ((ObjectContent)(data)).Value as MediaItemDisplay; if (!PathContainsAStartNode(media.Path, startNodes)) { response.StatusCode = HttpStatusCode.Forbidden; // prevent users from editing a node they shouldn't } media.Path = RemoveStartNodeAncestors(media.Path, startNodes); } catch (Exception ex) { LogHelper.Error <WebApiHandler>("Could not update path.", ex); } return response; } )); }
public ActionResult <MediaItemDisplay> PostSave( [ModelBinder(typeof(MediaItemBinder))] MediaItemSave contentItem) { //Recent versions of IE/Edge may send in the full client side file path instead of just the file name. //To ensure similar behavior across all browsers no matter what they do - we strip the FileName property of all //uploaded files to being *only* the actual file name (as it should be). if (contentItem.UploadedFiles != null && contentItem.UploadedFiles.Any()) { foreach (var file in contentItem.UploadedFiles) { file.FileName = Path.GetFileName(file.FileName); } } //If we've reached here it means: // * Our model has been bound // * and validated // * any file attachments have been saved to their temporary location for us to use // * we have a reference to the DTO object and the persisted object // * Permissions are valid //Don't update the name if it is empty if (contentItem.Name.IsNullOrWhiteSpace() == false) { contentItem.PersistedContent.Name = contentItem.Name; } MapPropertyValuesForPersistence <IMedia, MediaItemSave>( contentItem, contentItem.PropertyCollectionDto, (save, property) => property.GetValue(), //get prop val (save, property, v) => property.SetValue(v), //set prop val null); // media are all invariant //we will continue to save if model state is invalid, however we cannot save if critical data is missing. //TODO: Allowing media to be saved when it is invalid is odd - media doesn't have a publish phase so suddenly invalid data is allowed to be 'live' if (!ModelState.IsValid) { //check for critical data validation issues, we can't continue saving if this data is invalid if (!RequiredForPersistenceAttribute.HasRequiredValuesForPersistence(contentItem)) { //ok, so the absolute mandatory data is invalid and it's new, we cannot actually continue! // add the model state to the outgoing object and throw validation response MediaItemDisplay forDisplay = _umbracoMapper.Map <MediaItemDisplay>(contentItem.PersistedContent); return(ValidationProblem(forDisplay, ModelState)); } } //save the item var saveStatus = _mediaService.Save(contentItem.PersistedContent, _backofficeSecurityAccessor.BackOfficeSecurity.GetUserId().ResultOr(Constants.Security.SuperUserId)); //return the updated model var display = _umbracoMapper.Map <MediaItemDisplay>(contentItem.PersistedContent); //lastly, if it is not valid, add the model state to the outgoing object and throw a 403 if (!ModelState.IsValid) { return(ValidationProblem(display, ModelState, StatusCodes.Status403Forbidden)); } //put the correct msgs in switch (contentItem.Action) { case ContentSaveAction.Save: case ContentSaveAction.SaveNew: if (saveStatus.Success) { display.AddSuccessNotification( _localizedTextService.Localize("speechBubbles", "editMediaSaved"), _localizedTextService.Localize("speechBubbles", "editMediaSavedText")); } else { AddCancelMessage(display); //If the item is new and the operation was cancelled, we need to return a different // status code so the UI can handle it since it won't be able to redirect since there // is no Id to redirect to! if (saveStatus.Result.Result == OperationResultType.FailedCancelledByEvent && IsCreatingAction(contentItem.Action)) { return(ValidationProblem(display)); } } break; } return(display); }
private static void AfterMap(IMedia media, MediaItemDisplay display, IDataTypeService dataTypeService, ILocalizedTextService localizedText, IContentTypeService contentTypeService, ILogger logger) { // Adapted from ContentModelMapper //map the IsChildOfListView (this is actually if it is a descendant of a list view!) var parent = media.Parent(); display.IsChildOfListView = parent != null && (parent.ContentType.IsContainer || contentTypeService.HasContainerInPath(parent.Path)); //map the tree node url if (HttpContext.Current != null) { var urlHelper = new UrlHelper(HttpContext.Current.Request.RequestContext); var url = urlHelper.GetUmbracoApiService <MediaTreeController>(controller => controller.GetTreeNode(display.Id.ToString(), null)); display.TreeNodeUrl = url; } if (media.ContentType.IsContainer) { TabsAndPropertiesResolver.AddListView(display, "media", dataTypeService, localizedText); } var genericProperties = new List <ContentPropertyDisplay> { new ContentPropertyDisplay { Alias = string.Format("{0}doctype", Constants.PropertyEditors.InternalGenericPropertiesPrefix), Label = localizedText.Localize("content/mediatype"), Value = localizedText.UmbracoDictionaryTranslate(display.ContentTypeName), View = PropertyEditorResolver.Current.GetByAlias(Constants.PropertyEditors.NoEditAlias).ValueEditor.View } }; TabsAndPropertiesResolver.MapGenericProperties(media, display, localizedText, genericProperties, properties => { if (HttpContext.Current != null && UmbracoContext.Current != null && UmbracoContext.Current.Security.CurrentUser != null && UmbracoContext.Current.Security.CurrentUser.AllowedSections.Any(x => x.Equals(Constants.Applications.Settings))) { var mediaTypeLink = string.Format("#/settings/mediatypes/edit/{0}", media.ContentTypeId); //Replace the doctype property var docTypeProperty = properties.First(x => x.Alias == string.Format("{0}doctype", Constants.PropertyEditors.InternalGenericPropertiesPrefix)); docTypeProperty.Value = new List <object> { new { linkText = media.ContentType.Name, url = mediaTypeLink, target = "_self", icon = "icon-item-arrangement" } }; docTypeProperty.View = "urllist"; } // inject 'Link to media' as the first generic property var links = media.GetUrls(UmbracoConfig.For.UmbracoSettings().Content, logger); if (links.Any()) { var link = new ContentPropertyDisplay { Alias = string.Format("{0}urls", Constants.PropertyEditors.InternalGenericPropertiesPrefix), Label = localizedText.Localize("media/urls"), Value = string.Join(",", links), View = "urllist" }; properties.Insert(0, link); } }); }
public SendingMediaNotification(MediaItemDisplay media, IUmbracoContext umbracoContext) { Media = media; UmbracoContext = umbracoContext; }
public IEnumerable <ContentApp> Resolve(IMedia source, MediaItemDisplay destination, IEnumerable <ContentApp> destMember, ResolutionContext context) { return(_contentAppDefinitions.GetContentAppsFor(source)); }