-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* init * migration * fix test * style auth page
- Loading branch information
Showing
42 changed files
with
1,339 additions
and
228 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
defmodule Canary.Accounts.Account do | ||
use Ash.Resource, | ||
domain: Canary.Accounts, | ||
data_layer: AshPostgres.DataLayer | ||
|
||
attributes do | ||
uuid_primary_key :id | ||
|
||
attribute :user_id, :uuid do | ||
allow_nil? false | ||
end | ||
|
||
attribute :name, :string do | ||
allow_nil? false | ||
end | ||
end | ||
|
||
relationships do | ||
many_to_many :users, Canary.Accounts.User do | ||
through Canary.Accounts.AccountUser | ||
end | ||
|
||
has_many :source_websites, Canary.Sources.Website | ||
has_many :client_websites, Canary.Clients.Website | ||
end | ||
|
||
actions do | ||
create :create do | ||
accept [:user_id, :name] | ||
end | ||
|
||
update :update do | ||
accept [:name] | ||
end | ||
end | ||
|
||
postgres do | ||
table "accounts" | ||
repo Canary.Repo | ||
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
defmodule Canary.Accounts.AccountUser do | ||
use Ash.Resource, | ||
domain: Canary.Accounts, | ||
data_layer: AshPostgres.DataLayer | ||
|
||
relationships do | ||
belongs_to :user, Canary.Accounts.User, primary_key?: true, allow_nil?: false | ||
belongs_to :account, Canary.Accounts.Account, primary_key?: true, allow_nil?: false | ||
end | ||
|
||
actions do | ||
defaults [:read, :destroy, create: :*, update: :*] | ||
end | ||
|
||
postgres do | ||
table "account_users" | ||
repo Canary.Repo | ||
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
defmodule Canary.Accounts do | ||
use Ash.Domain | ||
|
||
resources do | ||
resource Canary.Accounts.User | ||
resource Canary.Accounts.Token | ||
resource Canary.Accounts.Account | ||
resource Canary.Accounts.AccountUser | ||
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
defmodule Canary.Accounts.Changes.InitAccount do | ||
use Ash.Resource.Change | ||
|
||
@default_account_name "Default" | ||
|
||
@impl true | ||
def change(changeset, _, _) do | ||
Ash.Changeset.after_action(changeset, fn _, user -> | ||
case Canary.Accounts.Account | ||
|> Ash.Changeset.for_create(:create, %{user_id: user.id, name: @default_account_name}) | ||
|> Ash.create() do | ||
{:ok, _} -> {:ok, user} | ||
error -> error | ||
end | ||
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
defmodule Canary.Accounts.Secrets do | ||
use AshAuthentication.Secret | ||
|
||
def secret_for([:authentication, :tokens, :signing_secret], Canary.Accounts.User, _) do | ||
case Application.fetch_env(:canary, CanaryWeb.Endpoint) do | ||
{:ok, endpoint_config} -> Keyword.fetch(endpoint_config, :secret_key_base) | ||
:error -> :error | ||
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
defmodule Canary.Accounts.Token do | ||
use Ash.Resource, | ||
domain: Canary.Accounts, | ||
data_layer: AshPostgres.DataLayer, | ||
extensions: [AshAuthentication.TokenResource] | ||
|
||
postgres do | ||
table "tokens" | ||
repo Canary.Repo | ||
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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
defmodule Canary.Accounts.User do | ||
use Ash.Resource, | ||
domain: Canary.Accounts, | ||
data_layer: AshPostgres.DataLayer, | ||
extensions: [AshAuthentication] | ||
|
||
attributes do | ||
uuid_primary_key :id | ||
|
||
attribute :email, :ci_string do | ||
allow_nil? false | ||
public? true | ||
end | ||
|
||
attribute :hashed_password, :string, allow_nil?: false, sensitive?: true | ||
end | ||
|
||
relationships do | ||
many_to_many :accounts, Canary.Accounts.Account do | ||
through Canary.Accounts.AccountUser | ||
end | ||
end | ||
|
||
changes do | ||
change Canary.Accounts.Changes.InitAccount, on: [:create] | ||
end | ||
|
||
identities do | ||
identity :unique_email, [:email] | ||
end | ||
|
||
authentication do | ||
strategies do | ||
password :password do | ||
identity_field :email | ||
end | ||
end | ||
|
||
tokens do | ||
enabled? true | ||
token_resource Canary.Accounts.Token | ||
signing_secret Canary.Accounts.Secrets | ||
end | ||
end | ||
|
||
postgres do | ||
table "users" | ||
repo Canary.Repo | ||
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,7 @@ | ||
defmodule Canary.Clients do | ||
use Ash.Domain | ||
|
||
resources do | ||
resource Canary.Clients.Website | ||
end | ||
end |
2 changes: 1 addition & 1 deletion
2
core/lib/canary/clients/discord_bot.ex → core/lib/canary/clients/discord.ex
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,40 @@ | ||
defmodule Canary.Clients.Website do | ||
use Ash.Resource, | ||
domain: Canary.Clients, | ||
data_layer: AshPostgres.DataLayer | ||
|
||
attributes do | ||
uuid_primary_key :id | ||
|
||
attribute :account_id, :uuid do | ||
allow_nil? false | ||
end | ||
|
||
attribute :base_url, :string do | ||
allow_nil? false | ||
end | ||
|
||
attribute :public_key, :string do | ||
allow_nil? false | ||
default &Ash.UUID.generate/0 | ||
end | ||
end | ||
|
||
actions do | ||
defaults [:read, :destroy] | ||
|
||
create :create do | ||
accept [:base_url, :account_id] | ||
change set_attribute(:public_key, Ash.UUID.generate()) | ||
end | ||
end | ||
|
||
relationships do | ||
belongs_to :account, Canary.Accounts.Account | ||
end | ||
|
||
postgres do | ||
table "client_websites" | ||
repo Canary.Repo | ||
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 |
---|---|---|
@@ -1,5 +1,7 @@ | ||
defmodule Canary.Repo do | ||
use Ecto.Repo, | ||
otp_app: :canary, | ||
adapter: Ecto.Adapters.Postgres | ||
use AshPostgres.Repo, otp_app: :canary | ||
|
||
def installed_extensions do | ||
["uuid-ossp", "citext", "ash-functions"] | ||
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
defmodule Canary.Sources.Document do | ||
use Ash.Resource, | ||
domain: Canary.Sources, | ||
data_layer: AshPostgres.DataLayer | ||
|
||
attributes do | ||
integer_primary_key :id | ||
|
||
attribute :content, :string | ||
attribute :embedding, :vector | ||
end | ||
|
||
relationships do | ||
belongs_to :snapshot, Canary.Sources.Snapshot | ||
end | ||
|
||
actions do | ||
create :create do | ||
accept [:content, :embedding] | ||
end | ||
end | ||
|
||
postgres do | ||
table "source_documents" | ||
repo Canary.Repo | ||
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
defmodule Canary.Sources.Snapshot do | ||
use Ash.Resource, | ||
domain: Canary.Sources, | ||
data_layer: AshPostgres.DataLayer | ||
|
||
attributes do | ||
uuid_primary_key :id | ||
|
||
attribute :source_id, :uuid do | ||
allow_nil? false | ||
end | ||
|
||
create_timestamp :created_at | ||
end | ||
|
||
relationships do | ||
has_many :documents, Canary.Sources.Document | ||
end | ||
|
||
postgres do | ||
table "source_snapshots" | ||
repo Canary.Repo | ||
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
defmodule Canary.Sources do | ||
use Ash.Domain | ||
|
||
resources do | ||
resource Canary.Sources.Snapshot | ||
resource Canary.Sources.Document | ||
resource Canary.Sources.Website | ||
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
defmodule Canary.Sources.Website do | ||
use Ash.Resource, | ||
domain: Canary.Sources, | ||
data_layer: AshPostgres.DataLayer | ||
|
||
attributes do | ||
uuid_primary_key :id | ||
|
||
attribute :account_id, :uuid do | ||
allow_nil? false | ||
end | ||
|
||
attribute :base_url, :string do | ||
allow_nil? false | ||
end | ||
end | ||
|
||
actions do | ||
defaults [:destroy] | ||
|
||
create :create do | ||
accept [:base_url, :account_id] | ||
end | ||
end | ||
|
||
relationships do | ||
belongs_to :account, Canary.Accounts.Account | ||
|
||
has_many :snapshots, Canary.Sources.Snapshot do | ||
destination_attribute :source_id | ||
end | ||
end | ||
|
||
postgres do | ||
table "source_websites" | ||
repo Canary.Repo | ||
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
Oops, something went wrong.