Skip to content

Commit 18f7fd7

Browse files
authored
feat: add page to seed jobs (#132)
1 parent ef66854 commit 18f7fd7

File tree

5 files changed

+521
-1
lines changed

5 files changed

+521
-1
lines changed

lib/algora/application.ex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ defmodule Algora.Application do
3838

3939
# Start the ETS tables
4040
AlgoraWeb.Admin.CampaignLive.start_link()
41+
AlgoraWeb.Admin.SeedLive.start_link()
4142

4243
# See https://hexdocs.pm/elixir/Supervisor.html
4344
# for other strategies and supported options

lib/algora/organizations/organizations.ex

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,82 @@ defmodule Algora.Organizations do
104104
end)
105105
end
106106

107+
def onboard_organization_from_domain(domain, opts \\ %{}) do
108+
case Algora.Crawler.fetch_site_metadata(domain) do
109+
{:ok, metadata} ->
110+
org_name =
111+
case get_in(metadata, [:display_name]) do
112+
nil ->
113+
domain
114+
|> String.split(".")
115+
|> List.first()
116+
|> String.capitalize()
117+
118+
name ->
119+
name
120+
end
121+
122+
org_handle =
123+
case get_in(metadata, [:handle]) do
124+
nil ->
125+
domain
126+
|> String.split(".")
127+
|> List.first()
128+
|> String.downcase()
129+
130+
handle ->
131+
handle
132+
end
133+
134+
params =
135+
Map.merge(
136+
%{
137+
display_name: org_name,
138+
bio:
139+
get_in(metadata, [:bio]) || get_in(metadata, [:og_description]) ||
140+
get_in(metadata, [:og_title]),
141+
avatar_url: get_in(metadata, [:avatar_url]) || get_in(metadata, [:favicon_url]),
142+
handle: org_handle,
143+
domain: domain,
144+
og_title: get_in(metadata, [:og_title]),
145+
og_image_url: get_in(metadata, [:og_image_url]),
146+
website_url: get_in(metadata, [:website_url]),
147+
twitter_url: get_in(metadata, [:socials, :twitter]),
148+
github_url: get_in(metadata, [:socials, :github]),
149+
youtube_url: get_in(metadata, [:socials, :youtube]),
150+
twitch_url: get_in(metadata, [:socials, :twitch]),
151+
discord_url: get_in(metadata, [:socials, :discord]),
152+
slack_url: get_in(metadata, [:socials, :slack]),
153+
linkedin_url: get_in(metadata, [:socials, :linkedin])
154+
},
155+
opts
156+
)
157+
158+
org = Repo.one(from o in User, where: o.domain == ^domain, limit: 1)
159+
160+
org_handle =
161+
case org do
162+
nil -> ensure_unique_org_handle(params.handle)
163+
org -> org.handle
164+
end
165+
166+
case org do
167+
nil ->
168+
%User{type: :organization}
169+
|> Org.changeset(Map.put(params, :handle, org_handle))
170+
|> Repo.insert()
171+
172+
existing_org ->
173+
existing_org
174+
|> Org.changeset(Map.delete(params, :handle))
175+
|> Repo.update()
176+
end
177+
178+
{:error, error} ->
179+
{:error, error}
180+
end
181+
end
182+
107183
def generate_handle_from_email(email) do
108184
email
109185
|> String.split("@")

lib/algora/psp/connect_countries.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ defmodule Algora.PSP.ConnectCountries do
140140
def account_type("BR"), do: :standard
141141
def account_type(_), do: :express
142142

143-
@spec regions() :: %{atom() => [String.t()]}
143+
@spec regions() :: %{String.t() => [String.t()]}
144144
def regions do
145145
%{
146146
"LATAM" => [

0 commit comments

Comments
 (0)