Esempio n. 1
0
        private static void ContentService_Trashing(IContentService sender, MoveEventArgs <IContent> moveEventArgs)
        {
            foreach (MoveEventInfo <IContent> trashingEntity in moveEventArgs.MoveInfoCollection)
            {
                List <IRelation> relations = RelationService.GetByChildId(trashingEntity.Entity.Id).ToList();

                if (relations.Any() == false)
                {
                    continue;
                }

                IEnumerable <IRelationType> relationsTypes = RelationService
                                                             .GetAllRelationTypes(
                    relations.Select(x => x.RelationTypeId).ToArray())
                                                             .Where(x => x.Alias == RelationTypes.BentoItemsAlias);

                if (!relationsTypes.Any())
                {
                    continue;
                }

                moveEventArgs.CancelOperation(new EventMessage("Bento setup",
                                                               $"This content is used in the following places: {string.Join(", ", relations.Select(x => sender.GetById(x.ParentId).Name))} (delete failed)",
                                                               EventMessageType.Error));
                break;
            }
        }
Esempio n. 2
0
        private void MediaService_Trashing(IMediaService sender, MoveEventArgs <IMedia> eventArgs)
        {
            try {
                EventModel trashEvent = null;
                int        _currentUserId;

                using (var contextReference = _context.EnsureUmbracoContext()) {
                    _currentUserId = contextReference.UmbracoContext.Security.CurrentUser.Id;
                }

                using (var scope = _scopeProvider.CreateScope(autoComplete: true)) {
                    var sql = scope.SqlContext.Sql().Select("*").From <EventModel>()
                              .Where <EventModel>(x => x.id == 3);
                    trashEvent = scope.Database.Fetch <EventModel>(sql).FirstOrDefault();
                }

                foreach (var mediaItem in eventArgs.MoveInfoCollection)
                {
                    if (trashEvent != null)
                    {
                        if (trashEvent.mediaNodes.Split(',').Contains(mediaItem.Entity.Id.ToString()) || trashEvent.disableEvent)
                        {
                            if (!trashEvent.userExceptions.Split(',').Contains(_currentUserId.ToString()))
                            {
                                eventArgs.CancelOperation(new EventMessage("Action rejected. Contact website admin", "You cannot trash " + mediaItem.Entity.Name, EventMessageType.Error));
                            }
                        }
                    }
                }
            }
            catch (Exception ex) {
                _logger.Error <EventModel>("Media Protector failed  trash action: " + ex.Message);
            }
        }
        private void ContentService_Trashing(IContentService sender, MoveEventArgs <IContent> eventArgs)
        {
            ActionModel trash = null;
            int         _currentUserId;

            using (var contextReference = _context.EnsureUmbracoContext()) {
                _currentUserId = contextReference.UmbracoContext.Security.CurrentUser.Id;
            }

            try {
                using (var scope = _scopeProvider.CreateScope(autoComplete: true)) {
                    var sql = scope.SqlContext.Sql().Select("*").From <ActionModel>()
                              .Where <ActionModel>(x => x.id == 3);
                    trash = scope.Database.Fetch <ActionModel>(sql).FirstOrDefault();
                }
            }
            catch (Exception ex) {
                _logger.Error <ActionModel>("Failed to get Content Protector setting for trash action: " + ex.Message);
            }

            foreach (var node in eventArgs.MoveInfoCollection)
            {
                if (trash != null)
                {
                    if (trash.nodes.Contains(node.Entity.Id.ToString()) || trash.disableAction)
                    {
                        if (!trash.userExceptions.Split(',').Contains(_currentUserId.ToString()))
                        {
                            eventArgs.CancelOperation(new EventMessage("Action rejected. Contact website admin", "You cannot trash " + node.Entity.Name, EventMessageType.Error));
                        }
                    }
                }
            }
        }
Esempio n. 4
0
 private void MediaService_Trashing(IMediaService sender, MoveEventArgs<IMedia> e)
 {
     //relationService = ApplicationContext.Current.Services.RelationService;
     foreach (var entity in e.MoveInfoCollection)
     {
         if (relationService.GetByParentOrChildId(entity.Entity.Id).Any())
         {
             //e.Cancel = true;
             e.CancelOperation(new Umbraco.Core.Events.EventMessage("UWS", "Cannot be deleted because the content is used elsewhere in the site. Please check the related content section for more information.", Umbraco.Core.Events.EventMessageType.Error));
             //e.Messages.Add(new Umbraco.Core.Events.EventMessage("UWS", "Cannot be deleted because the content is used elsewhere in the site. Please check the related content section for more information.", Umbraco.Core.Events.EventMessageType.Success));
             break;
         }
     }
 }
        public void LatchMediaTrashing(IMediaService sender, MoveEventArgs <IMedia> e)
        {
            if (!LatchesShouldBeChecked)
            {
                return;
            }

            var user    = HttpContext.Current.GetCurrentBackofficeUser();
            var latches = latchOperationSvc.GetLatches(LatchOperationType.Media, LatchOperationAction.Delete);

            if (latches.Any())
            {
                var latchesToApply    = GetLatchesApplyingToUser(latches, user.Id);
                var operationIsLocked = AnyLatchIsClosed(latchesToApply);
                if (operationIsLocked)
                {
                    var errorMessage = GetErrorMessage("mediaDelete");
                    var eventMessage = new EventMessage(LatchConstants.SectionName, errorMessage, EventMessageType.Error);
                    e.CancelOperation(eventMessage);
                }
            }
        }
Esempio n. 6
0
        public void LatchContentTrashing(IContentService sender, MoveEventArgs <IContent> e)
        {
            if (!LatchesShouldBeChecked)
            {
                return;
            }

            var latches      = latchOperationSvc.GetLatches(LatchOperationType.Content, LatchOperationAction.Delete);
            var contentItems = e.MoveInfoCollection.Select(x => x.Entity);
            var user         = HttpContext.Current.GetCurrentBackofficeUser();

            var parentItem = contentItems.First();
            var lockedNode = GetLockedNodeRecursively(latches, contentItems, user.Id);

            if (lockedNode != null)
            {
                var errorMessage = lockedNode.Id.Equals(parentItem.Id)
                    ? GetErrorMessage("contentDelete")
                    : GetErrorMessage("contentDeleteChildren");
                var eventMessage = new EventMessage(LatchConstants.SectionName, errorMessage, EventMessageType.Error);
                e.CancelOperation(eventMessage);
            }
        }