Skip to content

Commit 6718067

Browse files
lastcanalzcesur
authored andcommitted
feat: activity notifications (#31)
* activities (with has_many on_replace: :ignore) * add more tables, test helpers add accounts test * add more user activity attributes * add Repo.insert_with_activity/2 * add notifier * rename * Repo.update/delete_with_activity * test register github user activities * add coveralls * add basic coverage for bounties, chat and reviews and coveralls.json * remove redundant * remove ecto fork * Setup notifier and signal module Send error signals when failing to link stripe accounts * account coverage * update coveralls * rename * fetch user activities from nested children * add notifier job template * satisfy the dialyzer format * filter out bounties without solver when onboarding dev, fix KeyError * lower Drawer z-index; it was hiding flash messages * load association for activities drop transaction activities and 'second' level activities associated with a user * use Dataloader for loading activity associations * add Mox to dev * add create_session to Stripe SeedImpl * format * use map for activity table lookups * add owned|created_tips to User * add bounty and tip activities * test * add activities dropdown in main nav and on company admin page * implement Algora.Analytics.get_company_analytics/0-2 * remove transaction activities * zero not implemented demo data * add activity redirect controller * add User#received_tips * cleanup * typo * load target association with Activities.get * show activities in header broadcast from Oban job enqueue email deilvery add mail templates * fix merge * Protocol.UndefinedError for claims when creating tips * adapt bounty testing to claims * add on true to inner_lateral_join * add redirect url to email body * remove vars from email subjects * use schema.preload/1 * add claim_submitted and bounty_awarded activities * add utility for making admins * remove unused alias * add mix algora.create_tip * send email job * rework activity views * assert mail job enqueued * add todos
1 parent 9e703e8 commit 6718067

File tree

93 files changed

+1930
-87
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+1930
-87
lines changed

config/config.exs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ config :algora, Oban,
3333
github_og_image: 5,
3434
notify_bounty: 1,
3535
notify_tip_intent: 1,
36-
notify_claim: 1
36+
notify_claim: 1,
37+
activity_notifier: 1,
38+
activity_mailer: 1
3739
]
3840

3941
# Configures the mailer

config/test.exs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,7 @@ config :algora,
4747
cloudflare_tunnel: System.get_env("CLOUDFLARE_TUNNEL"),
4848
swift_mode: false,
4949
auto_start_pollers: System.get_env("AUTO_START_POLLERS") == "true"
50+
51+
config :algora, :stripe,
52+
test_customer_id: System.get_env("STRIPE_TEST_CUSTOMER_ID"),
53+
test_account_id: System.get_env("STRIPE_TEST_ACCOUNT_ID")

coveralls.json

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"skip_files": [
3+
"lib/algora/integrations",
4+
"lib/algora/shared/*",
5+
"lib/algora/admin/admin.ex",
6+
"lib/algora_web/components",
7+
"lib/algora_web",
8+
"lib/mix/tasks",
9+
"priv/",
10+
"test/support"
11+
],
12+
"default_stop_words": [
13+
"defmodule",
14+
"defrecord",
15+
"defimpl",
16+
"def.+(.+\/\/.+).+do",
17+
"typed_schema",
18+
"use .+"
19+
],
20+
21+
"custom_stop_words": [
22+
],
23+
24+
"coverage_options": {
25+
"treat_no_relevant_lines_as_covered": true,
26+
"output_dir": "cover/",
27+
"html_filter_full_covered": true
28+
}
29+
}

lib/algora/accounts/accounts.ex

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,16 @@ defmodule Algora.Accounts do
312312
Repo.one(query)
313313
end
314314

315+
def get_user_by_handle(handle) do
316+
query =
317+
from(u in User,
318+
where: u.handle == ^handle,
319+
select: u
320+
)
321+
322+
Repo.one(query)
323+
end
324+
315325
def get_access_token(%User{} = user) do
316326
case Repo.one(from(i in Identity, where: i.user_id == ^user.id and i.provider == "github")) do
317327
%Identity{provider_token: token} -> {:ok, token}

lib/algora/accounts/schemas/identity.ex

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ defmodule Algora.Accounts.Identity do
44

55
alias Algora.Accounts.Identity
66
alias Algora.Accounts.User
7+
alias Algora.Activities.Activity
78

89
@derive {Inspect, except: [:provider_token, :provider_meta]}
910
typed_schema "identities" do
@@ -17,6 +18,8 @@ defmodule Algora.Accounts.Identity do
1718

1819
belongs_to :user, User
1920

21+
has_many :activities, {"identity_activities", Activity}, foreign_key: :assoc_id
22+
2023
timestamps()
2124
end
2225

@@ -40,6 +43,7 @@ defmodule Algora.Accounts.Identity do
4043
:provider_name,
4144
:provider_id
4245
])
46+
|> Activity.put_activity(%Identity{}, %{type: :identity_created})
4347
|> generate_id()
4448
|> validate_required([:provider_token, :provider_email, :provider_name, :provider_id])
4549
|> validate_length(:provider_meta, max: 10_000)
@@ -66,6 +70,7 @@ defmodule Algora.Accounts.Identity do
6670
:provider_name,
6771
:provider_id
6872
])
73+
|> Activity.put_activity(%Identity{}, %{type: :identity_created})
6974
|> generate_id()
7075
|> validate_required([:provider_token, :provider_email, :provider_name, :provider_id])
7176
|> validate_length(:provider_meta, max: 10_000)

lib/algora/accounts/schemas/user.ex

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ defmodule Algora.Accounts.User do
44

55
alias Algora.Accounts.Identity
66
alias Algora.Accounts.User
7+
alias Algora.Activities.Activity
78
alias Algora.Bounties.Bounty
9+
alias Algora.Bounties.Tip
810
alias Algora.Contracts.Contract
911
alias Algora.MoneyUtils
1012
alias Algora.Organizations.Member
@@ -78,6 +80,9 @@ defmodule Algora.Accounts.User do
7880
has_many :members, Member, foreign_key: :org_id
7981
has_many :owned_bounties, Bounty, foreign_key: :owner_id
8082
has_many :created_bounties, Bounty, foreign_key: :creator_id
83+
has_many :owned_tips, Tip, foreign_key: :owner_id
84+
has_many :created_tips, Tip, foreign_key: :creator_id
85+
has_many :received_tips, Tip, foreign_key: :recipient_id
8186
has_many :attempts, Algora.Bounties.Attempt
8287
has_many :claims, Algora.Bounties.Claim
8388
has_many :projects, Algora.Projects.Project
@@ -87,6 +92,7 @@ defmodule Algora.Accounts.User do
8792
has_many :connected_installations, Installation, foreign_key: :connected_user_id
8893
has_many :contractor_contracts, Contract, foreign_key: :contractor_id
8994
has_many :client_contracts, Contract, foreign_key: :client_id
95+
has_many :activities, {"user_activities", Activity}, foreign_key: :assoc_id
9096

9197
has_one :customer, Algora.Payments.Customer, foreign_key: :user_id
9298

@@ -302,6 +308,10 @@ defmodule Algora.Accounts.User do
302308
|> unique_constraint([:provider, :provider_id])
303309
end
304310

311+
def is_admin_changeset(user, is_admin) do
312+
cast(user, %{is_admin: is_admin}, [:is_admin])
313+
end
314+
305315
def validate_timezone(changeset) do
306316
validate_inclusion(changeset, :timezone, Tzdata.zone_list())
307317
end

0 commit comments

Comments
 (0)