Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/algora/admin/admin.ex
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,10 @@ defmodule Algora.Admin do
where: t.provider_id == ^to_string(installation["id"])
),
set:
[provider_meta: Util.normalize_struct(installation)] ++
[
provider_meta: Util.normalize_struct(installation),
repository_selection: installation["repository_selection"]
] ++
if(target_user, do: [provider_user_id: target_user.id], else: [])
)

Expand Down
1 change: 0 additions & 1 deletion lib/algora/admin/migration/migration.ex
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,6 @@ defmodule Algora.Admin.Migration do
"provider" => "github",
"provider_id" => row["github_id"],
"provider_meta" => nil,
"avatar_url" => nil,
"repository_selection" => nil,
"owner_id" => nil,
"connected_user_id" => connected_user["id"],
Expand Down
8 changes: 3 additions & 5 deletions lib/algora/workspace/schemas/installation.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ defmodule Algora.Workspace.Installation do
field :provider, :string, null: false
field :provider_id, :string, null: false
field :provider_meta, :map
field :provider_user_id, :string

field :avatar_url, :string
field :repository_selection, :string

belongs_to :owner, User, null: false
belongs_to :owner, User
belongs_to :connected_user, User, null: false
# TODO: make non-nullable after migration
belongs_to :provider_user, User

has_many :activities, {"installation_activities", Activity}, foreign_key: :assoc_id
timestamps()
Expand All @@ -26,7 +26,6 @@ defmodule Algora.Workspace.Installation do
params = %{
owner_id: user.id,
connected_user_id: org.id,
avatar_url: data["account"]["avatar_url"],
repository_selection: data["repository_selection"],
provider_id: to_string(data["id"]),
provider_user_id: to_string(provider_user.id),
Expand All @@ -37,7 +36,6 @@ defmodule Algora.Workspace.Installation do
|> cast(params, [
:owner_id,
:connected_user_id,
:avatar_url,
:repository_selection,
:provider_id,
:provider_user_id,
Expand Down
13 changes: 11 additions & 2 deletions lib/algora/workspace/workspace.ex
Original file line number Diff line number Diff line change
Expand Up @@ -286,10 +286,19 @@ defmodule Algora.Workspace do
def get_installation(id), do: Repo.get(Installation, id)
def get_installation!(id), do: Repo.get!(Installation, id)

def list_installations_by(fields), do: Repo.all(from(i in Installation, where: ^fields))
def list_installations_by(fields),
do:
Repo.all(
from(i in Installation,
where: ^fields,
join: connected_user in assoc(i, :connected_user),
join: provider_user in assoc(i, :provider_user),
select_merge: %{connected_user: connected_user, provider_user: provider_user}
)
)

def list_user_installations(user_id) do
Repo.all(from(i in Installation, where: i.owner_id == ^user_id, preload: [:connected_user]))
list_installations_by(owner_id: user_id)
end

def fetch_command_response(ticket_id, command_type) do
Expand Down
30 changes: 4 additions & 26 deletions lib/algora_web/live/org/dashboard_live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -244,32 +244,10 @@ defmodule AlgoraWeb.Org.DashboardLive do
</.card_description>
</.card_header>
<.card_content>
<div class="flex flex-col gap-3">
<%= if @installations != [] do %>
<%= for installation <- @installations do %>
<div class="flex items-center gap-2">
<img src={installation.avatar_url} class="w-9 h-9 rounded-lg" />
<div>
<p class="font-medium">{installation.provider_meta["account"]["login"]}</p>
<p class="text-sm text-muted-foreground">
Algora app is installed in
<strong>{installation.repository_selection}</strong>
repositories
</p>
</div>
</div>
<% end %>
<.button phx-click="install_app" class="ml-auto gap-2">
<Logos.github class="w-4 h-4 mr-2 -ml-1" />
Manage {ngettext("installation", "installations", length(@installations))}
</.button>
<% else %>
<div class="flex flex-col gap-2">
<.button phx-click="install_app" class="ml-auto gap-2">
<Logos.github class="w-4 h-4 mr-2 -ml-1" /> Install GitHub App
</.button>
</div>
<% end %>
<div class="flex flex-col gap-2">
<.button phx-click="install_app" class="ml-auto gap-2">
<Logos.github class="w-4 h-4 mr-2 -ml-1" /> Install GitHub App
</.button>
</div>
</.card_content>
</.card>
Expand Down
4 changes: 2 additions & 2 deletions lib/algora_web/live/org/settings_live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ defmodule AlgoraWeb.Org.SettingsLive do
<%= if @installations != [] do %>
<%= for installation <- @installations do %>
<div class="flex items-center gap-2">
<img src={installation.avatar_url} class="w-9 h-9 rounded-lg" />
<img src={installation.provider_user.avatar_url} class="w-9 h-9 rounded-lg" />
<div>
<p class="font-medium">{installation.provider_meta["account"]["login"]}</p>
<p class="font-medium">{installation.provider_user.provider_login}</p>
<p class="text-sm text-muted-foreground">
Algora app is installed in <strong>{installation.repository_selection}</strong>
repositories
Expand Down
8 changes: 4 additions & 4 deletions lib/algora_web/live/user/installations_live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ defmodule AlgoraWeb.User.InstallationsLive do
<div class="flex items-center gap-4">
<div class="relative h-10 w-10">
<img
alt={installation.provider_login}
alt={installation.provider_user.provider_login}
class="rounded-lg"
src={installation.avatar_url}
src={installation.provider_user.avatar_url}
/>
</div>
<div>
<div class="text-xl font-semibold tracking-tight text-gray-100">
{installation.provider_login}
{installation.provider_user.provider_login}
</div>
<div>
<div class="text-sm text-gray-300">
Expand Down Expand Up @@ -126,7 +126,7 @@ defmodule AlgoraWeb.User.InstallationsLive do
end

def mount(_params, _session, socket) do
installations = Workspace.list_user_installations(socket.assigns.current_user.id)
installations = Workspace.list_installations_by(owner_id: socket.assigns.current_user.id)
{:ok, assign(socket, :installations, installations)}
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
defmodule Algora.Repo.Migrations.RemoveAvatarUrlFromInstallations do
use Ecto.Migration

def change do
alter table(:installations) do
remove :avatar_url
end
end
end
2 changes: 0 additions & 2 deletions test/support/factory.ex
Original file line number Diff line number Diff line change
Expand Up @@ -251,10 +251,8 @@ defmodule Algora.Factory do
provider_id: sequence(:provider_id, &"#{&1 + offset(:installation)}"),
provider_user_id: sequence(:provider_user_id, &"#{&1 + offset(:installation)}"),
provider_meta: %{
"account" => %{"avatar_url" => "https://algora.io/asset/storage/v1/object/public/mock/piedpiper-logo.png"},
"repository_selection" => "selected"
},
avatar_url: "https://algora.io/asset/storage/v1/object/public/mock/piedpiper-logo.png",
repository_selection: "selected"
}
end
Expand Down