From 9d1f86972da11f3e88f30614e1034bd4813b3cc3 Mon Sep 17 00:00:00 2001 From: Joao Gilberto Balsini Moura Date: Tue, 15 Sep 2020 05:47:19 -0300 Subject: [PATCH] Hide from users actions he/she cannot do --- .../live/property_live/index.html.leex | 12 +++++++++--- .../live/property_live/show.html.leex | 8 ++++++-- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/lib/real_estate_web/live/property_live/index.html.leex b/lib/real_estate_web/live/property_live/index.html.leex index 9f5c80c..712efba 100644 --- a/lib/real_estate_web/live/property_live/index.html.leex +++ b/lib/real_estate_web/live/property_live/index.html.leex @@ -28,9 +28,15 @@ <%= property.description %> - <%= live_redirect "Show", to: Routes.property_show_path(@socket, :show, property) %> - <%= live_patch "Edit", to: Routes.property_index_path(@socket, :edit, property) %> - <%= link "Delete", to: "#", phx_click: "delete", phx_value_id: property.id, data: [confirm: "Are you sure?"] %> + <%= if Roles.can?(@current_user, property, :show) do %> + <%= live_redirect "Show", to: Routes.property_show_path(@socket, :show, property) %> + <% end %> + <%= if Roles.can?(@current_user, property, :edit) do %> + <%= live_patch "Edit", to: Routes.property_index_path(@socket, :edit, property) %> + <% end %> + <%= if Roles.can?(@current_user, property, :delete) do %> + <%= link "Delete", to: "#", phx_click: "delete", phx_value_id: property.id, data: [confirm: "Are you sure?"] %> + <% end %> <% end %> diff --git a/lib/real_estate_web/live/property_live/show.html.leex b/lib/real_estate_web/live/property_live/show.html.leex index a342993..9da9cf7 100644 --- a/lib/real_estate_web/live/property_live/show.html.leex +++ b/lib/real_estate_web/live/property_live/show.html.leex @@ -28,5 +28,9 @@ -<%= live_patch "Edit", to: Routes.property_show_path(@socket, :edit, @property), class: "button" %> -<%= live_redirect "Back", to: Routes.property_index_path(@socket, :index) %> +<%= if Roles.can?(@current_user, @property, :edit) do %> + <%= live_patch "Edit", to: Routes.property_show_path(@socket, :edit, @property), class: "button" %> +<% end %> +<%= if Roles.can?(@current_user, @property, :index) do %> + <%= live_redirect "Back", to: Routes.property_index_path(@socket, :index) %> +<% end %>