-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto-read and prune notifications (#1160)
- Loading branch information
1 parent
fe34b9f
commit 841bc70
Showing
17 changed files
with
145 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
apps/core/priv/repo/migrations/20230717151538_invite_admin.exs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
defmodule Core.Repo.Migrations.InviteAdmin do | ||
use Ecto.Migration | ||
|
||
def change do | ||
alter table(:invites) do | ||
add :admin, :boolean, default: false | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -369,6 +369,22 @@ defmodule Core.Services.AccountsTest do | |
assert_receive {:event, %PubSub.UserCreated{item: ^user}} | ||
end | ||
|
||
test "it can mark admins if selected", %{user: user, account: account} do | ||
{:ok, invite} = Accounts.create_invite(%{email: "[email protected]", admin: true}, user) | ||
|
||
{:ok, user} = Accounts.realize_invite(%{ | ||
password: "some long password", | ||
name: "Some User" | ||
}, invite.secure_id) | ||
|
||
assert user.email == invite.email | ||
assert user.account_id == account.id | ||
assert user.name == "Some User" | ||
assert user.roles.admin | ||
|
||
assert_receive {:event, %PubSub.UserCreated{item: ^user}} | ||
end | ||
|
||
test "it can bind users to groups when realizing an invite", %{user: user, account: account} do | ||
groups = insert_list(2, :group, account: account) | ||
{:ok, invite} = Accounts.create_invite(%{ | ||
|
@@ -418,7 +434,7 @@ defmodule Core.Services.AccountsTest do | |
assert user.email == invite.email | ||
assert user.account_id == account.id | ||
assert user.name == "Some User" | ||
refute user.roles | ||
refute user.roles.admin | ||
|
||
assert_receive {:event, %PubSub.UserCreated{item: ^user}} | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
defmodule Cron.Prune.Notifications do | ||
@moduledoc """ | ||
Wipes invites beyond the expiration time | ||
""" | ||
use Cron | ||
alias Core.Schema.Notification | ||
|
||
def run() do | ||
Notification.expired() | ||
|> Core.Repo.delete_all() | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
defmodule Cron.Prune.NotificationsTest do | ||
use Core.SchemaCase | ||
alias Cron.Prune.Notifications | ||
|
||
describe "#run/0" do | ||
test "it will prune old notifications" do | ||
old = insert_list(3, :notification, inserted_at: Timex.now() |> Timex.shift(months: -2)) | ||
notif = insert(:notification) | ||
|
||
{3, _} = Notifications.run() | ||
|
||
for n <- old, | ||
do: refute refetch(n) | ||
|
||
assert refetch(notif) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters