Skip to content

Commit 4d00b77

Browse files
feat(front): display who was last to modify notification (#505)
## πŸ“ Description renderedtext/project-tasks#2659 ## βœ… Checklist - [x] I have tested this change - [ ] This change requires documentation update
1 parent 09905de commit 4d00b77

File tree

3 files changed

+30
-6
lines changed

3 files changed

+30
-6
lines changed

β€Žfront/lib/front_web/controllers/notifications_controller.ex

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@ defmodule FrontWeb.NotificationsController do
44

55
alias Front.Async
66
alias Front.Audit
7-
8-
alias Front.Models.{
9-
Notification,
10-
Organization
11-
}
7+
alias Front.Models.{Notification, Organization, User}
128

139
plug(FrontWeb.Plugs.FetchPermissions, scope: "org")
1410
plug(FrontWeb.Plugs.PageAccess, permissions: "organization.view")
@@ -25,6 +21,7 @@ defmodule FrontWeb.NotificationsController do
2521

2622
{:ok, organization} = Async.await(fetch_organization)
2723
{:ok, notifications} = Async.await(fetch_notifications)
24+
notifications = add_user_data_to_notifications(notifications)
2825

2926
render(
3027
conn,
@@ -298,6 +295,27 @@ defmodule FrontWeb.NotificationsController do
298295
|> render("404.html")
299296
end
300297

298+
defp add_user_data_to_notifications(notifications) when is_list(notifications) do
299+
import Enum
300+
301+
creators =
302+
notifications
303+
|> map(& &1.metadata.creator_id)
304+
|> reject(&(&1 == ""))
305+
|> uniq()
306+
|> User.find_many()
307+
308+
map(notifications, fn n ->
309+
if n.metadata.creator_id != "" do
310+
default_username = Application.get_env(:front, :default_user_name)
311+
creator = find(creators, &(&1.id == n.metadata.creator_id)) || %{name: default_username}
312+
%{n | metadata: Map.put(n.metadata, :creator, creator)}
313+
else
314+
n
315+
end
316+
end)
317+
end
318+
301319
def get_rule_identifiers(params) do
302320
params
303321
|> Map.keys()

β€Žfront/lib/front_web/templates/notifications/_notifications.html.eex

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
<%= Enum.map(@notifications, fn notification -> %>
22
<div class="bg-white shadow-1 br3 pa3 mv3">
3-
<div class="f4 f3-m b mb2"><%= notification.metadata.name %></div>
3+
<div class="flex items-center justify-between mb2">
4+
<div class="f4 f3-m b"><%= notification.metadata.name %></div>
5+
<%= if Map.has_key?(notification.metadata, :creator) && Map.has_key?(notification.metadata.creator, :name) do %>
6+
<div class="f6 black-50 tr">last modified by <%= notification.metadata.creator.name %></div>
7+
<% end %>
8+
</div>
49

510
<div class="overflow-auto nowrap">
611
<%= Enum.map(notification.spec.rules, fn rule -> %>

β€Žnotifications/lib/notifications/api/public_api/serialization.ex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ defmodule Notifications.Api.PublicApi.Serialization do
1515
Notification.Metadata.new(
1616
name: notification.name,
1717
id: notification.id,
18+
creator_id: notification.creator_id,
1819
create_time: unix_timestamp(notification.inserted_at),
1920
update_time: unix_timestamp(notification.updated_at)
2021
)

0 commit comments

Comments
Β (0)