/// <summary>
        /// Called before saving the enumeration of entities.
        /// </summary>
        /// <param name="entities">The entities.</param>
        /// <param name="state">The state passed between the before save and after save callbacks.</param>
        /// <returns>
        /// True to cancel the save operation; false otherwise.
        /// </returns>
        public bool OnBeforeSave(IEnumerable <IEntity> entities, IDictionary <string, object> state)
        {
            foreach (IEntity entity in entities)
            {
                var report = entity.As <Report>();

                if (report == null)
                {
                    continue;
                }

                _auditLogEventTarget.GatherAuditLogEntityDetailsForSave(report, state);

                EnsureIsDefaultReportForType(report, state);
            }

            return(false);
        }
Example #2
0
        public void TestOnChangeAccessRuleQuery()
        {
            bool   success       = true;
            string subjectName   = "Role" + Guid.NewGuid();
            string typeName      = "Type" + Guid.NewGuid();
            string reportName    = "Report" + Guid.NewGuid();
            string newReportName = "Report" + Guid.NewGuid();

            var mockAuditLog = new Mock <IAuditLog>(MockBehavior.Strict);

            mockAuditLog.Setup(al => al.OnChangeAccessRuleQuery(success, subjectName, typeName, newReportName));

            var eventTarget = new AuditLogReportEventTarget(mockAuditLog.Object);

            var subject = new Role {
                Name = subjectName
            };
            var type = new EntityType {
                Name = typeName
            };
            var report = new Report {
                Name = reportName
            };

            var accessRule = new AccessRule {
                AllowAccessBy = subject.As <Subject>(), ControlAccess = type.As <SecurableEntity>(), AccessRuleReport = report
            };

            accessRule.Save();

            report.Name = newReportName;

            IDictionary <string, object> state = new Dictionary <string, object>();

            eventTarget.GatherAuditLogEntityDetailsForSave(report, state);
            eventTarget.WriteSaveAuditLogEntries(success, report.Id, state);

            mockAuditLog.VerifyAll();
        }