Merge pull request #4356 from sbwalker/dev
fix #4353 - add defensive logic when sending notifications and improve performance
This commit is contained in:
		| @ -203,19 +203,21 @@ namespace Oqtane.Infrastructure | ||||
|             } | ||||
|             if (Enum.Parse<LogLevel>(log.Level) >= notifylevel) | ||||
|             { | ||||
|                 var subject = $"Site {log.Level} Notification"; | ||||
|                 string body = $"Log Message: {log.Message}"; | ||||
|  | ||||
|                 var alias = _tenantManager.GetAlias(); | ||||
|                 foreach (var userrole in _userRoles.GetUserRoles(log.SiteId.Value)) | ||||
|                 if (alias != null) | ||||
|                 { | ||||
|                     if (userrole.Role.Name == RoleNames.Host) | ||||
|                     { | ||||
|                         var subject = $"{alias.Name} Site {log.Level} Notification"; | ||||
|                         var url = $"{_accessor.HttpContext.Request.Scheme}://{alias.Name}/admin/log?id={log.LogId}"; | ||||
|                         string body = $"Log Message: {log.Message}<br /><br />Please visit {url} for more information"; | ||||
|                         var notification = new Notification(log.SiteId.Value, userrole.User, subject, body); | ||||
|                         _notifications.AddNotification(notification); | ||||
|                     } | ||||
|                     subject = $"{alias.Name} Site {log.Level} Notification"; | ||||
|                     body = $"Log Message: {log.Message}<br /><br />Please visit {alias.Protocol}://{alias.Name}/admin/log?id={log.LogId} for more information"; | ||||
|                 } | ||||
|  | ||||
|                 foreach (var userrole in _userRoles.GetUserRoles(RoleNames.Host, log.SiteId.Value)) | ||||
|                 { | ||||
|                     var notification = new Notification(log.SiteId.Value, userrole.User, subject, body); | ||||
|                     _notifications.AddNotification(notification); | ||||
|                 } | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|  | ||||
| @ -7,6 +7,7 @@ namespace Oqtane.Repository | ||||
|     { | ||||
|         IEnumerable<UserRole> GetUserRoles(int siteId); | ||||
|         IEnumerable<UserRole> GetUserRoles(int userId, int siteId); | ||||
|         IEnumerable<UserRole> GetUserRoles(string roleName, int siteId); | ||||
|         UserRole AddUserRole(UserRole userRole); | ||||
|         UserRole UpdateUserRole(UserRole userRole); | ||||
|         UserRole GetUserRole(int userRoleId); | ||||
|  | ||||
| @ -23,16 +23,25 @@ namespace Oqtane.Repository | ||||
|             return db.UserRole | ||||
|                 .Include(item => item.Role) // eager load roles | ||||
|                 .Include(item => item.User) // eager load users | ||||
|                 .Where(item => item.Role.SiteId == siteId || item.Role.SiteId == null).ToList(); | ||||
|                 .Where(item => item.Role.SiteId == siteId || item.Role.SiteId == null || siteId == -1).ToList(); | ||||
|         } | ||||
|  | ||||
|         public IEnumerable<UserRole> GetUserRoles(int userId, int siteId) | ||||
|         { | ||||
|             using var db = _dbContextFactory.CreateDbContext(); | ||||
|             return db.UserRole.Where(item => item.UserId == userId) | ||||
|             return db.UserRole | ||||
|                 .Include(item => item.Role) // eager load roles | ||||
|                 .Include(item => item.User) // eager load users | ||||
|                 .Where(item => item.Role.SiteId == siteId || item.Role.SiteId == null || siteId == -1).ToList(); | ||||
|                 .Where(item => (item.Role.SiteId == siteId || item.Role.SiteId == null || siteId == -1) && item.UserId == userId).ToList(); | ||||
|         } | ||||
|  | ||||
|         public IEnumerable<UserRole> GetUserRoles(string roleName, int siteId) | ||||
|         { | ||||
|             using var db = _dbContextFactory.CreateDbContext(); | ||||
|             return db.UserRole | ||||
|                 .Include(item => item.Role) // eager load roles | ||||
|                 .Include(item => item.User) // eager load users | ||||
|                 .Where(item => (item.Role.SiteId == siteId || item.Role.SiteId == null || siteId == -1) && item.Role.Name == roleName).ToList(); | ||||
|         } | ||||
|  | ||||
|         public UserRole AddUserRole(UserRole userRole) | ||||
|  | ||||
| @ -68,10 +68,10 @@ namespace Oqtane.Models | ||||
|         } | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Protocol for the request from which the alias was resolved (ie. http:// or https:// ) | ||||
|         /// Protocol for the request from which the alias was resolved (ie. http or https ) | ||||
|         /// </summary> | ||||
|         [NotMapped] | ||||
|         public string Protocol { get; set; } | ||||
|         public string Protocol { get; set; } = "https"; // default value | ||||
|  | ||||
|         /// <summary> | ||||
|         /// Base Url for static resources (note that this will only be set for remote clients) | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 Shaun Walker
					Shaun Walker