コード例 #1
0
 public void Handle(UserGroupWithUsersSavedNotification notification)
 {
     foreach (UserGroupWithUsers entity in notification.SavedEntities)
     {
         _distributedCache.RefreshUserGroupCache(entity.UserGroup.Id);
     }
 }
コード例 #2
0
        public void Handle(UserGroupWithUsersSavedNotification notification)
        {
            var performingUser = CurrentPerformingUser;

            foreach (var groupWithUser in notification.SavedEntities)
            {
                var group = groupWithUser.UserGroup;

                var dp       = string.Join(", ", ((UserGroup)group).GetWereDirtyProperties());
                var sections = ((UserGroup)group).WasPropertyDirty("AllowedSections")
                    ? string.Join(", ", group.AllowedSections)
                    : null;
                var perms = ((UserGroup)group).WasPropertyDirty("Permissions")
                    ? string.Join(", ", group.Permissions)
                    : null;

                var sb = new StringBuilder();
                sb.Append($"updating {(string.IsNullOrWhiteSpace(dp) ? "(nothing)" : dp)};");
                if (sections != null)
                {
                    sb.Append($", assigned sections: {sections}");
                }
                if (perms != null)
                {
                    if (sections != null)
                    {
                        sb.Append(", ");
                    }
                    sb.Append($"default perms: {perms}");
                }

                _auditService.Write(performingUser.Id, $"User \"{performingUser.Name}\" {FormatEmail(performingUser)}", PerformingIp,
                                    DateTime.UtcNow,
                                    -1, $"User Group {group.Id} \"{group.Name}\" ({group.Alias})",
                                    "umbraco/user-group/save", $"{sb}");

                // now audit the users that have changed

                foreach (var user in groupWithUser.RemovedUsers)
                {
                    _auditService.Write(performingUser.Id, $"User \"{performingUser.Name}\" {FormatEmail(performingUser)}", PerformingIp,
                                        DateTime.UtcNow,
                                        user.Id, $"User \"{user.Name}\" {FormatEmail(user)}",
                                        "umbraco/user-group/save", $"Removed user \"{user.Name}\" {FormatEmail(user)} from group {group.Id} \"{group.Name}\" ({group.Alias})");
                }

                foreach (var user in groupWithUser.AddedUsers)
                {
                    _auditService.Write(performingUser.Id, $"User \"{performingUser.Name}\" {FormatEmail(performingUser)}", PerformingIp,
                                        DateTime.UtcNow,
                                        user.Id, $"User \"{user.Name}\" {FormatEmail(user)}",
                                        "umbraco/user-group/save", $"Added user \"{user.Name}\" {FormatEmail(user)} to group {group.Id} \"{group.Name}\" ({group.Alias})");
                }
            }
        }