Skip to content

Commit e907a63

Browse files
committed
miscellanea
1 parent ff5f664 commit e907a63

File tree

8 files changed

+103
-53
lines changed

8 files changed

+103
-53
lines changed

lib/algora/accounts/schemas/user.ex

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ defmodule Algora.Accounts.User do
421421

422422
def get_domain(_meta), do: nil
423423

424-
def github_changeset(meta) do
424+
def github_changeset(user \\ %User{}, meta) do
425425
params = %{
426426
provider_id: to_string(meta["id"]),
427427
provider_login: meta["login"],
@@ -432,13 +432,17 @@ defmodule Algora.Accounts.User do
432432
avatar_url: meta["avatar_url"],
433433
website_url: Util.normalize_url(meta["blog"]),
434434
github_url: meta["html_url"],
435-
domain: get_domain(meta)
435+
domain: get_domain(meta),
436+
provider: "github",
437+
provider_meta: meta
436438
}
437439

438-
%User{provider: "github", provider_meta: meta}
440+
user
439441
|> cast(
440442
params,
441443
[
444+
:provider,
445+
:provider_meta,
442446
:provider_id,
443447
:provider_login,
444448
:type,
@@ -502,7 +506,15 @@ defmodule Algora.Accounts.User do
502506
end
503507

504508
def hiring_changeset(%User{} = user, params) do
505-
cast(user, params, [:preferences, :executive_name, :executive_role, :billing_name, :billing_address, :hiring_keywords, :poaching_targets])
509+
cast(user, params, [
510+
:preferences,
511+
:executive_name,
512+
:executive_role,
513+
:billing_name,
514+
:billing_address,
515+
:hiring_keywords,
516+
:poaching_targets
517+
])
506518
end
507519

508520
defp validate_url(changeset, field) do

lib/algora/bounties/bounties.ex

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ defmodule Algora.Bounties do
5959
}) ::
6060
{:ok, Bounty.t()} | {:error, atom()}
6161
defp do_create_bounty(%{creator: creator, owner: owner, amount: amount, ticket: ticket} = params) do
62+
if owner.provider_login in Algora.Settings.get_blocked_users() or
63+
creator.provider_login in Algora.Settings.get_blocked_users() do
64+
raise "blocked"
65+
end
66+
6267
changeset =
6368
Bounty.changeset(%Bounty{}, %{
6469
amount: amount,
@@ -756,6 +761,11 @@ defmodule Algora.Bounties do
756761
) ::
757762
{:ok, Tip.t()} | {:error, atom()}
758763
def do_create_tip(%{creator: creator, owner: owner, recipient: recipient, amount: amount}, opts \\ []) do
764+
if owner.provider_login in Algora.Settings.get_blocked_users() or
765+
creator.provider_login in Algora.Settings.get_blocked_users() do
766+
raise "blocked"
767+
end
768+
759769
ticket_res =
760770
if ticket_ref = opts[:ticket_ref] do
761771
with {:ok, %{token: token}} <-
@@ -930,6 +940,10 @@ defmodule Algora.Bounties do
930940
) ::
931941
{:ok, String.t()} | {:error, atom()}
932942
def create_payment_session(%{owner: owner, amount: amount, description: description}, opts \\ []) do
943+
if owner.provider_login in Algora.Settings.get_blocked_users() do
944+
raise "blocked"
945+
end
946+
933947
tx_group_id = Nanoid.generate()
934948

935949
line_items =

lib/algora/integrations/github/poller/search_consumer.ex

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,16 @@ defmodule Algora.Github.Poller.SearchConsumer do
4040
provider_login: to_string(comment["author"]["login"])
4141
) do
4242
{:ok, user} ->
43-
strategy =
44-
case Repo.get_by(CommandResponse,
45-
provider: "github",
46-
provider_command_id: to_string(comment["databaseId"]),
47-
command_source: :comment
48-
) do
49-
nil -> :increase
50-
_ -> :set
51-
end
43+
strategy = :set
44+
# strategy =
45+
# case Repo.get_by(CommandResponse,
46+
# provider: "github",
47+
# provider_command_id: to_string(comment["databaseId"]),
48+
# command_source: :comment
49+
# ) do
50+
# nil -> :increase
51+
# _ -> :set
52+
# end
5253

5354
Algora.Activities.alert("Creating global bounty for #{inspect(args[:amount])}: #{inspect(ticket_ref)}", :info)
5455

lib/algora/workspace/workspace.ex

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,15 +198,37 @@ defmodule Algora.Workspace do
198198

199199
def ensure_user(token, owner) do
200200
case Repo.get_by(User, provider: "github", provider_login: owner) do
201-
%User{} = user -> {:ok, user}
202-
nil -> create_user_from_github(token, owner)
201+
%User{} = user ->
202+
if is_nil(user.provider_meta["followers"]) do
203+
with {:ok, user_data} <- Github.get_user_by_username(token, owner) do
204+
user
205+
|> User.github_changeset(user_data)
206+
|> Repo.update()
207+
end
208+
else
209+
{:ok, user}
210+
end
211+
212+
nil ->
213+
create_user_from_github(token, owner)
203214
end
204215
end
205216

206217
def ensure_user_by_provider_id(token, provider_id) do
207218
case Repo.get_by(User, provider: "github", provider_id: to_string(provider_id)) do
208-
%User{} = user -> {:ok, user}
209-
nil -> create_user_from_github_by_id(token, provider_id)
219+
%User{} = user ->
220+
if is_nil(user.provider_meta["followers"]) do
221+
with {:ok, user_data} <- Github.get_user(token, provider_id) do
222+
user
223+
|> User.github_changeset(user_data)
224+
|> Repo.update()
225+
end
226+
else
227+
{:ok, user}
228+
end
229+
230+
nil ->
231+
create_user_from_github_by_id(token, provider_id)
210232
end
211233
end
212234

lib/algora_web/controllers/webhooks/github_controller.ex

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -328,15 +328,16 @@ defmodule AlgoraWeb.Webhooks.GithubController do
328328

329329
ticket_number = get_github_ticket(webhook)["number"]
330330

331-
strategy =
332-
case Repo.get_by(CommandResponse,
333-
provider: "github",
334-
provider_command_id: to_string(command_id),
335-
command_source: command_source
336-
) do
337-
nil -> :increase
338-
_ -> :set
339-
end
331+
strategy = :set
332+
# strategy =
333+
# case Repo.get_by(CommandResponse,
334+
# provider: "github",
335+
# provider_command_id: to_string(command_id),
336+
# command_source: command_source
337+
# ) do
338+
# nil -> :increase
339+
# _ -> :set
340+
# end
340341

341342
# TODO: community bounties?
342343
with {:ok, role} <- authorize_user(webhook),

lib/algora_web/live/org/jobs_live.ex

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -130,23 +130,17 @@ defmodule AlgoraWeb.Org.JobsLive do
130130
<div class="flex flex-col md:flex-row md:items-center justify-between gap-4">
131131
<div>
132132
<div class="flex items-center gap-2">
133-
<%= if @current_user_role in [:admin, :mod] do %>
134-
<.link
135-
navigate={~p"/#{@current_org.handle}/job/#{job.id}"}
136-
class="text-lg sm:text-2xl font-semibold"
137-
>
138-
<span class="underline">{job.title}</span>
139-
<%= if @current_user.is_admin do %>
140-
<span class="text-xs font-muted-foreground">
141-
{job.location} - {job.compensation}
142-
</span>
143-
<% end %>
144-
</.link>
145-
<% else %>
146-
<div class="text-lg font-semibold">
147-
{job.title}
148-
</div>
149-
<% end %>
133+
<.link
134+
navigate={~p"/#{@current_org.handle}/job/#{job.id}"}
135+
class="text-lg font-semibold"
136+
>
137+
<span class="underline">{job.title}</span>
138+
<%= if @current_user && @current_user.is_admin do %>
139+
<span class="text-xs font-muted-foreground">
140+
{job.location} - {job.compensation}
141+
</span>
142+
<% end %>
143+
</.link>
150144
<%= if job.id in ["b4sFSeJvb2rteUEX", "M9yTwVXFjvQM2WJf"] do %>
151145
<.badge variant="success">Contract to Hire</.badge>
152146
<% end %>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
defmodule Algora.Repo.Migrations.AddPrestigeToExperiences do
2+
use Ecto.Migration
3+
4+
def change do
5+
alter table(:experiences) do
6+
add :prestige, :integer, default: 2
7+
end
8+
end
9+
end

test/algora/bounties_test.exs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -264,17 +264,14 @@ defmodule Algora.BountiesTest do
264264

265265
assert bounty.visibility == :community
266266

267-
# Simulate adding to bounty amount (like GitHub webhook would do)
267+
# Simulate updating bounty amount (like GitHub webhook would do)
268268
{:ok, updated_bounty} =
269-
Bounties.create_bounty(
270-
%{
271-
ticket_ref: ticket_ref,
272-
owner: owner,
273-
creator: creator,
274-
amount: ~M[50]usd
275-
},
276-
strategy: :increase
277-
)
269+
Bounties.create_bounty(%{
270+
ticket_ref: ticket_ref,
271+
owner: owner,
272+
creator: creator,
273+
amount: ~M[50]usd
274+
})
278275

279276
assert updated_bounty.visibility == :community
280277
end

0 commit comments

Comments
 (0)