/// <summary> /// Move the media type /// </summary> /// <param name="move"></param> /// <returns></returns> public IActionResult PostMove(MoveOrCopy move) { var toMove = _dataTypeService.GetDataType(move.Id); if (toMove == null) { return(NotFound()); } var result = _dataTypeService.Move(toMove, move.ParentId); if (result.Success) { return(Content(toMove.Path, MediaTypeNames.Text.Plain, Encoding.UTF8)); } switch (result.Result.Result) { case MoveOperationStatusType.FailedParentNotFound: return(NotFound()); case MoveOperationStatusType.FailedCancelledByEvent: return(ValidationProblem()); case MoveOperationStatusType.FailedNotAllowedByPath: var notificationModel = new SimpleNotificationModel(); notificationModel.AddErrorNotification(_localizedTextService.Localize("moveOrCopy", "notAllowedByPath"), ""); return(ValidationProblem(notificationModel)); default: throw new ArgumentOutOfRangeException(); } }
public IActionResult PostCopy(MoveOrCopy copy) { return(PerformCopy( copy, getContentType: i => _contentTypeService.Get(i), doCopy: (type, i) => _contentTypeService.Copy(type, i))); }
public IActionResult PostMove(MoveOrCopy move) { return(PerformMove( move, i => _mediaTypeService.Get(i), (type, i) => _mediaTypeService.Move(type, i))); }
/// <summary> /// Move /// </summary> /// <param name="move"></param> /// <param name="getContentType"></param> /// <param name="doCopy"></param> /// <returns></returns> protected IActionResult PerformCopy( MoveOrCopy move, Func <int, TContentType?> getContentType, Func <TContentType, int, Attempt <OperationResult <MoveOperationStatusType, TContentType>?> > doCopy) { TContentType?toMove = getContentType(move.Id); if (toMove == null) { return(NotFound()); } Attempt <OperationResult <MoveOperationStatusType, TContentType>?> result = doCopy(toMove, move.ParentId); if (result.Success) { return(Content(toMove.Path, MediaTypeNames.Text.Plain, Encoding.UTF8)); } switch (result.Result?.Result) { case MoveOperationStatusType.FailedParentNotFound: return(NotFound()); case MoveOperationStatusType.FailedCancelledByEvent: return(ValidationProblem()); case MoveOperationStatusType.FailedNotAllowedByPath: return(ValidationProblem(LocalizedTextService.Localize("moveOrCopy", "notAllowedByPath"))); default: throw new ArgumentOutOfRangeException(); } }
public IActionResult PostCopy(MoveOrCopy copy) { return(PerformCopy( copy, i => _memberTypeService.Get(i), (type, i) => _memberTypeService.Copy(type, i))); }
/// <summary> /// Move the media type /// </summary> /// <param name="move"></param> /// <returns></returns> public HttpResponseMessage PostMove(MoveOrCopy move) { return(PerformMove( move, getContentType: i => Services.MediaTypeService.Get(i), doMove: (type, i) => Services.MediaTypeService.Move(type, i))); }
public IActionResult PostMove(MoveOrCopy move) { return(PerformMove( move, getContentType: i => _contentTypeService.Get(i), doMove: (type, i) => _contentTypeService.Move(type, i))); }
/// <summary> /// Copy the media type /// </summary> /// <param name="copy"></param> /// <returns></returns> public HttpResponseMessage PostCopy(MoveOrCopy copy) { return(PerformCopy( copy, getContentType: i => Services.MediaTypeService.Get(i), doCopy: (type, i) => Services.MediaTypeService.Copy(type, i))); }
public IProcessorMutable CreateProcessor(string libraryPath, AlbumExplorerProcessor explorer) { explorer.OnFineProcessor = new AlbumToLibraryProcessor( libraryPath, (FileOperationProcessor.FileOperation)MoveOrCopy.Value <int>(), (FileOperationProcessor.ConflictSolving)Conflicts.Value <int>()); return(new DirectoryProcessor(explorer, true)); }
/// <summary> /// Ensures the item can be moved/copied to the new location /// </summary> /// <param name="model"></param> /// <returns></returns> private IMedia ValidateMoveOrCopy(MoveOrCopy model) { if (model == null) { throw new HttpResponseException(HttpStatusCode.NotFound); } var mediaService = Services.MediaService; var toMove = mediaService.GetById(model.Id); if (toMove == null) { throw new HttpResponseException(HttpStatusCode.NotFound); } if (model.ParentId < 0) { //cannot move if the content item is not allowed at the root unless there are //none allowed at root (in which case all should be allowed at root) var mediaTypeService = Services.MediaTypeService; if (toMove.ContentType.AllowedAsRoot == false && mediaTypeService.GetAll().Any(ct => ct.AllowedAsRoot)) { var notificationModel = new SimpleNotificationModel(); notificationModel.AddErrorNotification(Services.TextService.Localize("moveOrCopy/notAllowedAtRoot"), ""); throw new HttpResponseException(Request.CreateValidationErrorResponse(notificationModel)); } } else { var parent = mediaService.GetById(model.ParentId); if (parent == null) { throw new HttpResponseException(HttpStatusCode.NotFound); } //check if the item is allowed under this one var parentContentType = Services.MediaTypeService.Get(parent.ContentTypeId); if (parentContentType.AllowedContentTypes.Select(x => x.Id).ToArray() .Any(x => x.Value == toMove.ContentType.Id) == false) { var notificationModel = new SimpleNotificationModel(); notificationModel.AddErrorNotification(Services.TextService.Localize("moveOrCopy/notAllowedByContentType"), ""); throw new HttpResponseException(Request.CreateValidationErrorResponse(notificationModel)); } // Check on paths if ((string.Format(",{0},", parent.Path)).IndexOf(string.Format(",{0},", toMove.Id), StringComparison.Ordinal) > -1) { var notificationModel = new SimpleNotificationModel(); notificationModel.AddErrorNotification(Services.TextService.Localize("moveOrCopy/notAllowedByPath"), ""); throw new HttpResponseException(Request.CreateValidationErrorResponse(notificationModel)); } } return(toMove); }
/// <summary> /// Ensures the item can be moved/copied to the new location /// </summary> /// <param name="model"></param> /// <returns></returns> private ActionResult <IMedia> ValidateMoveOrCopy(MoveOrCopy model) { if (model == null) { return(NotFound()); } var toMove = _mediaService.GetById(model.Id); if (toMove == null) { return(NotFound()); } if (model.ParentId < 0) { //cannot move if the content item is not allowed at the root unless there are //none allowed at root (in which case all should be allowed at root) var mediaTypeService = _mediaTypeService; if (toMove.ContentType.AllowedAsRoot == false && mediaTypeService.GetAll().Any(ct => ct.AllowedAsRoot)) { var notificationModel = new SimpleNotificationModel(); notificationModel.AddErrorNotification(_localizedTextService.Localize("moveOrCopy", "notAllowedAtRoot"), ""); return(ValidationProblem(notificationModel)); } } else { var parent = _mediaService.GetById(model.ParentId); if (parent == null) { return(NotFound()); } //check if the item is allowed under this one var parentContentType = _mediaTypeService.Get(parent.ContentTypeId); if (parentContentType.AllowedContentTypes.Select(x => x.Id).ToArray() .Any(x => x.Value == toMove.ContentType.Id) == false) { var notificationModel = new SimpleNotificationModel(); notificationModel.AddErrorNotification(_localizedTextService.Localize("moveOrCopy", "notAllowedByContentType"), ""); return(ValidationProblem(notificationModel)); } // Check on paths if ((string.Format(",{0},", parent.Path)).IndexOf(string.Format(",{0},", toMove.Id), StringComparison.Ordinal) > -1) { var notificationModel = new SimpleNotificationModel(); notificationModel.AddErrorNotification(_localizedTextService.Localize("moveOrCopy", "notAllowedByPath"), ""); return(ValidationProblem(notificationModel)); } } return(new ActionResult <IMedia>(toMove)); }
public HttpResponseMessage PostMove(MoveOrCopy move) { var toMove = ValidateMoveOrCopy(move); Services.MediaService.Move(toMove, move.ParentId); var response = Request.CreateResponse(HttpStatusCode.OK); response.Content = new StringContent(toMove.Path, Encoding.UTF8, "application/json"); return(response); }
public HttpResponseMessage PostCopy(MoveOrCopy copy) { var toCopy = ValidateMoveOrCopy(copy); var c = Services.ContentService.Copy(toCopy, copy.ParentId, copy.RelateToOriginal, copy.Recursive); var response = Request.CreateResponse(HttpStatusCode.OK); response.Content = new StringContent(c.Path, Encoding.UTF8, "application/json"); return(response); }
public HttpResponseMessage Copy(MoveOrCopy copy) { var result = Services.DataTypeService.Copy(copy.Id, copy.ParentId); if (result.Success) { var response = Request.CreateResponse(HttpStatusCode.OK); response.Content = new StringContent(result.Result, Encoding.UTF8, MediaTypeNames.Text.Plain); return(response); } return(Request.CreateResponse(HttpStatusCode.InternalServerError)); }
/// <summary> /// Ensures the item can be moved/copied to the new location /// </summary> /// <param name="model"></param> /// <returns></returns> private IContent ValidateMoveOrCopy(MoveOrCopy model) { if (model == null) { throw new HttpResponseException(HttpStatusCode.NotFound); } var contentService = Services.ContentService; var toMove = contentService.GetById(model.Id); if (toMove == null) { throw new HttpResponseException(HttpStatusCode.NotFound); } if (model.ParentId < 0) { //cannot move if the content item is not allowed at the root if (toMove.ContentType.AllowedAsRoot == false) { throw new HttpResponseException( Request.CreateNotificationValidationErrorResponse( Services.TextService.Localize("moveOrCopy/notAllowedAtRoot"))); } } else { var parent = contentService.GetById(model.ParentId); if (parent == null) { throw new HttpResponseException(HttpStatusCode.NotFound); } //check if the item is allowed under this one if (parent.ContentType.AllowedContentTypes.Select(x => x.Id).ToArray() .Any(x => x.Value == toMove.ContentType.Id) == false) { throw new HttpResponseException( Request.CreateNotificationValidationErrorResponse( Services.TextService.Localize("moveOrCopy/notAllowedByContentType"))); } // Check on paths if ((string.Format(",{0},", parent.Path)).IndexOf(string.Format(",{0},", toMove.Id), StringComparison.Ordinal) > -1) { throw new HttpResponseException( Request.CreateNotificationValidationErrorResponse( Services.TextService.Localize("moveOrCopy/notAllowedByPath"))); } } return(toMove); }
/// <summary> /// Move /// </summary> /// <param name="move"></param> /// <param name="getContentType"></param> /// <param name="doCopy"></param> /// <returns></returns> protected HttpResponseMessage PerformCopy <TContentType>( MoveOrCopy move, Func <int, TContentType> getContentType, Func <TContentType, int, Attempt <OperationStatus <TContentType, MoveOperationStatusType> > > doCopy) where TContentType : IContentTypeComposition { var toMove = getContentType(move.Id); if (toMove == null) { return(Request.CreateResponse(HttpStatusCode.NotFound)); } var result = doCopy(toMove, move.ParentId); if (result.Success) { var copy = result.Result.Entity; var response = Request.CreateResponse(HttpStatusCode.OK); response.Content = new StringContent(copy.Path, Encoding.UTF8, "application/json"); return(response); } switch (result.Result.StatusType) { case MoveOperationStatusType.FailedParentNotFound: return(Request.CreateResponse(HttpStatusCode.NotFound)); case MoveOperationStatusType.FailedCancelledByEvent: //returning an object of INotificationModel will ensure that any pending // notification messages are added to the response. return(Request.CreateValidationErrorResponse(new SimpleNotificationModel())); case MoveOperationStatusType.FailedNotAllowedByPath: var notificationModel = new SimpleNotificationModel(); notificationModel.AddErrorNotification(Services.TextService.Localize("moveOrCopy/notAllowedByPath"), ""); return(Request.CreateValidationErrorResponse(notificationModel)); default: throw new ArgumentOutOfRangeException(); } }
/// <summary> /// Change the sort order for media /// </summary> /// <param name="move"></param> /// <returns></returns> public async Task <IActionResult> PostMove(MoveOrCopy move) { // Authorize... var requirement = new MediaPermissionsResourceRequirement(); AuthorizationResult authorizationResult = await _authorizationService.AuthorizeAsync(User, new MediaPermissionsResource(_mediaService.GetById(move.Id)), requirement); if (!authorizationResult.Succeeded) { return(Forbid()); } ActionResult <IMedia> toMoveResult = ValidateMoveOrCopy(move); IMedia?toMove = toMoveResult.Value; if (toMove is null && toMoveResult is IConvertToActionResult convertToActionResult) { return(convertToActionResult.Convert()); } var destinationParentID = move.ParentId; var sourceParentID = toMove?.ParentId; var moveResult = toMove is null ? false : _mediaService.Move(toMove, move.ParentId, _backofficeSecurityAccessor.BackOfficeSecurity?.GetUserId().Result ?? -1); if (sourceParentID == destinationParentID) { return(ValidationProblem(new SimpleNotificationModel(new BackOfficeNotification("", _localizedTextService.Localize("media", "moveToSameFolderFailed"), NotificationStyle.Error)))); } if (moveResult == false) { return(ValidationProblem()); } return(Content(toMove !.Path, MediaTypeNames.Text.Plain, Encoding.UTF8)); }
public HttpResponseMessage PostMove(MoveOrCopy move) { var toMove = ValidateMoveOrCopy(move); var destinationParentID = move.ParentId; var sourceParentID = toMove.ParentId; var moveResult = Services.MediaService.WithResult().Move(toMove, move.ParentId, Security.CurrentUser.Id); if (sourceParentID == destinationParentID) { return(Request.CreateValidationErrorResponse(new SimpleNotificationModel(new Notification("", Services.TextService.Localize("media/moveToSameFolderFailed"), SpeechBubbleIcon.Error)))); } if (moveResult == false) { return(Request.CreateValidationErrorResponse(new SimpleNotificationModel())); } else { var response = Request.CreateResponse(HttpStatusCode.OK); response.Content = new StringContent(toMove.Path, Encoding.UTF8, "application/json"); return(response); } }
public HttpResponseMessage PostMove(MoveOrCopy move) { var toMove = ValidateMoveOrCopy(move); var destinationParentID = move.ParentId; var sourceParentID = toMove.ParentId; var moveResult = Services.MediaService.Move(toMove, move.ParentId, Security.GetUserId().ResultOr(Constants.Security.SuperUserId)); if (sourceParentID == destinationParentID) { return(Request.CreateValidationErrorResponse(new SimpleNotificationModel(new Notification("", Services.TextService.Localize("media/moveToSameFolderFailed"), NotificationStyle.Error)))); } if (moveResult == false) { return(Request.CreateValidationErrorResponse(new SimpleNotificationModel())); } else { var response = Request.CreateResponse(HttpStatusCode.OK); response.Content = new StringContent(toMove.Path, Encoding.UTF8, "text/plain"); return(response); } }
/// <summary> /// Changes the structure for dictionary items /// </summary> /// <param name="move"></param> /// <returns></returns> public IActionResult?PostMove(MoveOrCopy move) { var dictionaryItem = _localizationService.GetDictionaryItemById(move.Id); if (dictionaryItem == null) { return(ValidationProblem(_localizedTextService.Localize("dictionary", "itemDoesNotExists"))); } var parent = _localizationService.GetDictionaryItemById(move.ParentId); if (parent == null) { if (move.ParentId == Constants.System.Root) { dictionaryItem.ParentId = null; } else { return(ValidationProblem(_localizedTextService.Localize("dictionary", "parentDoesNotExists"))); } } else { dictionaryItem.ParentId = parent.Key; if (dictionaryItem.Key == parent.ParentId) { return(ValidationProblem(_localizedTextService.Localize("moveOrCopy", "notAllowedByPath"))); } } _localizationService.Save(dictionaryItem); var model = _umbracoMapper.Map <IDictionaryItem, DictionaryDisplay>(dictionaryItem); return(Content(model !.Path, MediaTypeNames.Text.Plain, Encoding.UTF8)); }
/// <summary> /// Move the media type /// </summary> /// <param name="move"></param> /// <returns></returns> public HttpResponseMessage PostMove(MoveOrCopy move) { var toMove = Services.DataTypeService.GetDataType(move.Id); if (toMove == null) { return(Request.CreateResponse(HttpStatusCode.NotFound)); } var result = Services.DataTypeService.Move(toMove, move.ParentId); if (result.Success) { var response = Request.CreateResponse(HttpStatusCode.OK); response.Content = new StringContent(toMove.Path, Encoding.UTF8, "text/plain"); return(response); } switch (result.Result.Result) { case MoveOperationStatusType.FailedParentNotFound: return(Request.CreateResponse(HttpStatusCode.NotFound)); case MoveOperationStatusType.FailedCancelledByEvent: //returning an object of INotificationModel will ensure that any pending // notification messages are added to the response. return(Request.CreateValidationErrorResponse(new SimpleNotificationModel())); case MoveOperationStatusType.FailedNotAllowedByPath: var notificationModel = new SimpleNotificationModel(); notificationModel.AddErrorNotification(Services.TextService.Localize("moveOrCopy/notAllowedByPath"), ""); return(Request.CreateValidationErrorResponse(notificationModel)); default: throw new ArgumentOutOfRangeException(); } }
public IActionResult PostMove(MoveOrCopy move) => PerformMove( move, i => _contentTypeService.Get(i), (type, i) => _contentTypeService.Move(type, i));
private Task <HttpResponseMessage> RemoveInacessibleNodesFromPathPostMoveAndCopy(HttpRequestMessage request, CancellationToken cancellationToken) { ApplicationContext appContext = ContextHelpers.EnsureApplicationContext(); IUser user = ContextHelpers.EnsureUmbracoContext().Security.CurrentUser; int[] startNodes; if (request.RequestUri.AbsolutePath.ToLower().Contains("/content/")) { startNodes = StartNodeRepository.GetCachedStartNodesByUserId(user.Id, appContext, appContext.DatabaseContext).Content; } else if (request.RequestUri.AbsolutePath.ToLower().Contains("/media/")) { startNodes = StartNodeRepository.GetCachedStartNodesByUserId(user.Id, appContext, appContext.DatabaseContext).Media; } else { return(base.SendAsync(request, cancellationToken)); } if (user.UserType.Alias == "admin" || startNodes == null) { return(base.SendAsync(request, cancellationToken)); } //// prevent moving/copying into inaccessible locations // do some hackery to read the post data more than once - http://stackoverflow.com/questions/12007689/cannot-read-body-data-from-web-api-post MediaTypeHeaderValue contentType = request.Content.Headers.ContentType; MoveOrCopy postModel = request.Content.ReadAsAsync <MoveOrCopy>().Result; string contentInString = JsonConvert.SerializeObject(postModel); request.Content = new StringContent(contentInString); request.Content.Headers.ContentType = contentType; IUmbracoEntity parent = appContext.Services.EntityService.Get(postModel.ParentId); if (!PathContainsAStartNode(parent.Path, startNodes)) { // take error notification from https://github.com/umbraco/Umbraco-CMS/blob/a2a4ad39476f4a18c8fe2c04d42f6fa635551b63/src/Umbraco.Web/Editors/MediaController.cs#L656 SimpleNotificationModel notificationModel = new SimpleNotificationModel(); notificationModel.AddErrorNotification(appContext.Services.TextService.Localize("moveOrCopy/notValid", CultureInfo.CurrentCulture), ""); throw new HttpResponseException(request.CreateValidationErrorResponse(notificationModel)); } else { // perform default request return(base.SendAsync(request, cancellationToken) .ContinueWith(task => { HttpResponseMessage response = task.Result; if (!response.IsSuccessStatusCode) { return response; } try { string path = response.Content.ReadAsStringAsync().Result; path = RemoveStartNodeAncestors(path, startNodes); response.Content = new StringContent(path, Encoding.UTF8, "application/json"); } catch (Exception ex) { LogHelper.Error <WebApiHandler>("Could not update path.", ex); } return response; } )); } }
public IActionResult PostCopy(MoveOrCopy copy) => PerformCopy( copy, i => _mediaTypeService.Get(i), (type, i) => _mediaTypeService.Copy(type, i));