Ejemplo n.º 1
0
        private void MediaService_Deleting(IMediaService sender, DeleteEventArgs <IMedia> eventArgs)
        {
            try {
                EventModel deleteEvent = 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 == 4);
                    deleteEvent = scope.Database.Fetch <EventModel>(sql).FirstOrDefault();
                }

                foreach (var mediaItem in eventArgs.DeletedEntities)
                {
                    if (deleteEvent != null)
                    {
                        if (deleteEvent.mediaNodes.Split(',').Contains(mediaItem.Id.ToString()) || deleteEvent.disableEvent)
                        {
                            if (!deleteEvent.userExceptions.Split(',').Contains(_currentUserId.ToString()))
                            {
                                eventArgs.CancelOperation(new EventMessage("Action rejected. Contact website admin", "You cannot delete " + mediaItem.Name, EventMessageType.Error));
                            }
                        }
                    }
                }
            }
            catch (Exception ex) {
                _logger.Error <EventModel>("Media Protector failed for delete action: " + ex.Message);
            }
        }
        private void ContentService_Deleting(IContentService sender, DeleteEventArgs <IContent> eventArgs)
        {
            ActionModel delete = 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 == 4);
                    delete = scope.Database.Fetch <ActionModel>(sql).FirstOrDefault();
                }
            }
            catch (Exception ex) {
                _logger.Error <ActionModel>("Failed to get Content Protector setting for delete action: " + ex.Message);
            }

            foreach (var node in eventArgs.DeletedEntities)
            {
                if (delete != null)
                {
                    if (delete.nodes.Split(',').Contains(node.Id.ToString()) || delete.disableAction)
                    {
                        if (!delete.userExceptions.Split(',').Contains(_currentUserId.ToString()))
                        {
                            eventArgs.CancelOperation(new EventMessage("Action rejected. Contact website admin", "You cannot delete " + node.Name, EventMessageType.Error));
                        }
                    }
                }
            }
        }
 private void MemberService_Deleting(IMemberService sender, DeleteEventArgs <IMember> e)
 {
     foreach (var member in e.DeletedEntities)
     {
         e.CancelOperation(new EventMessage("Blocked", $"Deleting the member {member} has been cancelled. Deleting all members is disabled until the side-effects are handled.", EventMessageType.Warning));
         _logger.Info <DisableMemberDeleteEventComponent>("Deleting the member {member} has been cancelled. Deleting all members is disabled until the side-effects are handled.", member.Name);
     }
 }
 private void StopFormRteDelete(IDataTypeService sender, DeleteEventArgs <IDataType> e)
 {
     foreach (var dt in e.DeletedEntities)
     {
         if (dt.Name == FormRteName && e.CanCancel)
         {
             e.CancelOperation(new EventMessage("Error", "This data type is used by Umbraco Forms Rich Text field", EventMessageType.Error));
         }
     }
 }
        public void LatchDictionaryItemDeleting(ILocalizationService sender, DeleteEventArgs <IDictionaryItem> e)
        {
            if (!LatchesShouldBeChecked)
            {
                return;
            }

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

            if (latches.Any())
            {
                var latchesToApply    = GetLatchesApplyingToUser(latches, user.Id);
                var operationIsLocked = AnyLatchIsClosed(latchesToApply);
                if (operationIsLocked)
                {
                    var errorMessage = GetErrorMessage("dictionaryDelete");
                    var eventMessage = new EventMessage(LatchConstants.SectionName, errorMessage, EventMessageType.Error);
                    e.CancelOperation(eventMessage);
                }
            }
        }