Skip to content

Commit

Permalink
Merge pull request #4876 from sbwalker/dev
Browse files Browse the repository at this point in the history
prevent notifications from being accessed by other users
  • Loading branch information
sbwalker authored Nov 26, 2024
2 parents f71a3a1 + ffea9e3 commit e83399a
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 9 deletions.
4 changes: 2 additions & 2 deletions Oqtane.Client/Modules/Admin/UserProfile/Index.razor
Original file line number Diff line number Diff line change
Expand Up @@ -230,13 +230,13 @@

@if (context.IsRead)
{
<td>@context.FromDisplayName</td>
<td>@(string.IsNullOrEmpty(context.FromDisplayName) ? SharedLocalizer["System"] : context.FromDisplayName)</td>
<td>@context.Subject</td>
<td>@string.Format("{0:dd-MMM-yyyy HH:mm:ss}", @context.CreatedOn)</td>
}
else
{
<td><b>@context.FromDisplayName</b></td>
<td><b>@(string.IsNullOrEmpty(context.FromDisplayName) ? SharedLocalizer["System"] : context.FromDisplayName)</b></td>
<td><b>@context.Subject</b></td>
<td><b>@string.Format("{0:dd-MMM-yyyy HH:mm:ss}", @context.CreatedOn)</b></td>
}
Expand Down
2 changes: 1 addition & 1 deletion Oqtane.Client/Modules/Admin/UserProfile/View.razor
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
createdon = notification.CreatedOn.ToString();
body = notification.Body;

if (title == "From")
if (title == "From" && !notification.IsRead)
{
notification.IsRead = true;
notification = await NotificationService.UpdateNotificationAsync(notification);
Expand Down
3 changes: 3 additions & 0 deletions Oqtane.Client/Resources/Modules/Admin/Site/Index.resx
Original file line number Diff line number Diff line change
Expand Up @@ -435,4 +435,7 @@
<data name="Functionality" xml:space="preserve">
<value>Functionality</value>
</data>
<data name="System" xml:space="preserve">
<value>System</value>
</data>
</root>
4 changes: 2 additions & 2 deletions Oqtane.Server/Controllers/NotificationController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public Notification Put(int id, [FromBody] Notification notification)
{
if (ModelState.IsValid && notification.SiteId == _alias.SiteId && notification.NotificationId == id && _notifications.GetNotification(notification.NotificationId, false) != null && (IsAuthorized(notification.FromUserId) || IsAuthorized(notification.ToUserId)))
{
if (!User.IsInRole(RoleNames.Admin))
if (!User.IsInRole(RoleNames.Admin) && notification.FromUserId != null)
{
// content must be HTML encoded for non-admins to prevent HTML injection
notification.Subject = WebUtility.HtmlEncode(notification.Subject);
Expand Down Expand Up @@ -223,7 +223,7 @@ public void Delete(int id)

private bool IsAuthorized(int? userid)
{
bool authorized = true;
bool authorized = false;
if (userid != null)
{
authorized = (_userPermissions.GetUser(User).UserId == userid);
Expand Down
8 changes: 4 additions & 4 deletions Oqtane.Shared/Models/Notification.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,25 +144,25 @@ private void ConstructNotification(int siteId, User from, string fromDisplayName
{
FromUserId = from.UserId;
FromDisplayName = from.DisplayName;
FromEmail = from.Email;
FromEmail = from.Email ?? "";
}
else
{
FromUserId = null;
FromDisplayName = fromDisplayName;
FromEmail = fromEmail;
FromEmail = fromEmail ?? "";
}
if (to != null)
{
ToUserId = to.UserId;
ToDisplayName = to.DisplayName;
ToEmail = to.Email;
ToEmail = to.Email ?? "";
}
else
{
ToUserId = null;
ToDisplayName = toDisplayName;
ToEmail = toEmail;
ToEmail = toEmail ?? "";
}
Subject = subject;
Body = body;
Expand Down

0 comments on commit e83399a

Please sign in to comment.