Add :groups field to user struct

This commit is contained in:
Alexandre de Souza 2025-03-25 10:09:28 -03:00
parent 0435b4392b
commit 53b079c7cf
No known key found for this signature in database
GPG key ID: E39228FFBA346545
2 changed files with 12 additions and 2 deletions

View file

@ -17,6 +17,7 @@ defmodule Livebook.Users.User do
name: String.t() | nil,
email: String.t() | nil,
avatar_url: String.t() | nil,
groups: list(map()) | nil,
payload: map() | nil,
hex_color: hex_color()
}
@ -28,6 +29,7 @@ defmodule Livebook.Users.User do
field :name, :string
field :email, :string
field :avatar_url, :string
field :groups, {:array, :map}
field :payload, :map
field :hex_color, Livebook.EctoTypes.HexColor
end
@ -42,6 +44,7 @@ defmodule Livebook.Users.User do
name: nil,
email: nil,
avatar_url: nil,
groups: nil,
payload: nil,
hex_color: Livebook.EctoTypes.HexColor.random()
}
@ -49,7 +52,7 @@ defmodule Livebook.Users.User do
def changeset(user, attrs \\ %{}) do
user
|> cast(attrs, [:name, :email, :avatar_url, :hex_color, :payload])
|> cast(attrs, [:name, :email, :avatar_url, :groups, :hex_color, :payload])
|> validate_required([:hex_color])
end
end

View file

@ -157,12 +157,19 @@ defmodule Livebook.ZTA.LivebookTeams do
defp get_user_info(team, access_token) do
with {:ok, payload} <- Teams.Requests.get_user_info(team, access_token) do
%{"id" => id, "name" => name, "email" => email, "avatar_url" => avatar_url} = payload
%{
"id" => id,
"name" => name,
"email" => email,
"groups" => groups,
"avatar_url" => avatar_url
} = payload
metadata = %{
id: id,
name: name,
avatar_url: avatar_url,
groups: groups,
email: email,
payload: payload
}