diff --git a/lib/safira_web/controllers/auth_json.ex b/lib/safira_web/controllers/auth_json.ex index 4bfd0673..1899f8ed 100644 --- a/lib/safira_web/controllers/auth_json.ex +++ b/lib/safira_web/controllers/auth_json.ex @@ -21,8 +21,9 @@ defmodule SafiraWeb.AuthJSON do |> Map.merge(CompanyView.render("company.json", company: company)) end - def data(%{user: %{type: "staff"}} = user) do + def data(%{user: %{type: "staff", staff: staff}} = user) do user_data(user) + |> Map.merge(%{is_admin: staff.is_admin}) end defp user_data(%{user: user}) do diff --git a/test/safira_web/controllers/auth_controller_test.exs b/test/safira_web/controllers/auth_controller_test.exs index 8e71b8fc..5fb161a9 100644 --- a/test/safira_web/controllers/auth_controller_test.exs +++ b/test/safira_web/controllers/auth_controller_test.exs @@ -61,7 +61,7 @@ defmodule SafiraWeb.AuthControllerTest do end test "when user is a staff", %{user: user} do - insert(:staff, user: user) + insert(:staff, is_admin: false, user: user) %{conn: conn, user: _user} = api_authenticate(user) @@ -72,7 +72,8 @@ defmodule SafiraWeb.AuthControllerTest do expected_user = %{ "email" => user.email, "id" => user.id, - "type" => "staff" + "type" => "staff", + "is_admin" => false } assert json_response(conn, 200) == expected_user