Fix
This commit is contained in:
parent
c531beadb7
commit
dc25c926ba
5 changed files with 33 additions and 13 deletions
|
@ -12,6 +12,7 @@ defmodule Nulla.Models.Note do
|
||||||
field :inReplyTo, :string
|
field :inReplyTo, :string
|
||||||
field :published, :utc_datetime
|
field :published, :utc_datetime
|
||||||
field :url, :string
|
field :url, :string
|
||||||
|
field :visibility, :string
|
||||||
field :to, {:array, :string}
|
field :to, {:array, :string}
|
||||||
field :cc, {:array, :string}
|
field :cc, {:array, :string}
|
||||||
field :sensitive, :boolean, default: false
|
field :sensitive, :boolean, default: false
|
||||||
|
@ -28,9 +29,11 @@ defmodule Nulla.Models.Note do
|
||||||
def changeset(note, attrs) do
|
def changeset(note, attrs) do
|
||||||
note
|
note
|
||||||
|> cast(attrs, [
|
|> cast(attrs, [
|
||||||
|
:id,
|
||||||
:inReplyTo,
|
:inReplyTo,
|
||||||
:published,
|
:published,
|
||||||
:url,
|
:url,
|
||||||
|
:visibility,
|
||||||
:to,
|
:to,
|
||||||
:cc,
|
:cc,
|
||||||
:sensitive,
|
:sensitive,
|
||||||
|
@ -41,12 +44,12 @@ defmodule Nulla.Models.Note do
|
||||||
|> validate_required([:published, :url, :to, :cc, :content, :language, :actor_id])
|
|> validate_required([:published, :url, :to, :cc, :content, :language, :actor_id])
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_note(attrs, visibility)
|
def create_note(attrs) when is_map(attrs) do
|
||||||
when is_map(attrs) and visibility in ["public", "unlisted", "followers", "private"] do
|
|
||||||
id = Map.get(attrs, :id, Snowflake.next_id())
|
id = Map.get(attrs, :id, Snowflake.next_id())
|
||||||
actor_id = Map.get(attrs, :actor_id)
|
actor_id = Map.get(attrs, :actor_id)
|
||||||
actor = Actor.get_actor(id: actor_id)
|
actor = Actor.get_actor(id: actor_id)
|
||||||
published = Map.get(attrs, :published, DateTime.utc_now())
|
published = Map.get(attrs, :published, DateTime.utc_now())
|
||||||
|
visibility = Map.get(attrs, :visibility, "public")
|
||||||
|
|
||||||
url =
|
url =
|
||||||
case Map.get(attrs, :url) do
|
case Map.get(attrs, :url) do
|
||||||
|
@ -82,15 +85,21 @@ defmodule Nulla.Models.Note do
|
||||||
cc = []
|
cc = []
|
||||||
|
|
||||||
{to, cc}
|
{to, cc}
|
||||||
|
|
||||||
|
_ ->
|
||||||
|
raise ArgumentError, "Invalid visibility: #{visibility}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
attrs =
|
||||||
|
attrs
|
||||||
|
|> Map.put(:id, id)
|
||||||
|
|> Map.put(:published, published)
|
||||||
|
|> Map.put(:url, url)
|
||||||
|
|> Map.put(:to, to)
|
||||||
|
|> Map.put(:cc, cc)
|
||||||
|
|
||||||
%__MODULE__{}
|
%__MODULE__{}
|
||||||
|> changeset(attrs)
|
|> changeset(attrs)
|
||||||
|> put_change(:id, id)
|
|
||||||
|> put_change(:published, published)
|
|
||||||
|> put_change(:url, url)
|
|
||||||
|> put_change(:to, to)
|
|
||||||
|> put_change(:cc, cc)
|
|
||||||
|> Repo.insert()
|
|> Repo.insert()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -95,13 +95,13 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="flex items-center space-x-2 text-sm text-gray-500">
|
<div class="flex items-center space-x-2 text-sm text-gray-500">
|
||||||
<%= case note.visibility do %>
|
<%= case note.visibility do %>
|
||||||
<% :public -> %>
|
<% "public" -> %>
|
||||||
<.icon name="hero-globe-americas" class="h-5 w-5" />
|
<.icon name="hero-globe-americas" class="h-5 w-5" />
|
||||||
<% :unlisted -> %>
|
<% "unlisted" -> %>
|
||||||
<.icon name="hero-moon" class="h-5 w-5" />
|
<.icon name="hero-moon" class="h-5 w-5" />
|
||||||
<% :followers -> %>
|
<% "followers" -> %>
|
||||||
<.icon name="hero-lock-closed" class="h-5 w-5" />
|
<.icon name="hero-lock-closed" class="h-5 w-5" />
|
||||||
<% :private -> %>
|
<% "private" -> %>
|
||||||
<.icon name="hero-at-symbol" class="h-5 w-5" />
|
<.icon name="hero-at-symbol" class="h-5 w-5" />
|
||||||
<% end %>
|
<% end %>
|
||||||
<span>{format_note_datetime_diff(note.inserted_at)}</span>
|
<span>{format_note_datetime_diff(note.inserted_at)}</span>
|
||||||
|
|
|
@ -7,6 +7,7 @@ defmodule Nulla.Repo.Migrations.CreateNotes do
|
||||||
add :inReplyTo, :string
|
add :inReplyTo, :string
|
||||||
add :published, :utc_datetime
|
add :published, :utc_datetime
|
||||||
add :url, :string
|
add :url, :string
|
||||||
|
add :visibility, :string
|
||||||
add :to, {:array, :string}
|
add :to, {:array, :string}
|
||||||
add :cc, {:array, :string}
|
add :cc, {:array, :string}
|
||||||
add :sensitive, :boolean, default: false
|
add :sensitive, :boolean, default: false
|
||||||
|
|
|
@ -5,6 +5,7 @@ defmodule Nulla.HTTPSignatureTest do
|
||||||
import Nulla.Fixtures.Data
|
import Nulla.Fixtures.Data
|
||||||
alias Nulla.HTTPSignature
|
alias Nulla.HTTPSignature
|
||||||
alias Nulla.Snowflake
|
alias Nulla.Snowflake
|
||||||
|
alias Nulla.Models.User
|
||||||
alias Nulla.Models.Actor
|
alias Nulla.Models.Actor
|
||||||
|
|
||||||
setup do
|
setup do
|
||||||
|
@ -15,6 +16,7 @@ defmodule Nulla.HTTPSignatureTest do
|
||||||
test "make_headers/3 creates valid signature headers and verify/2 validates them" do
|
test "make_headers/3 creates valid signature headers and verify/2 validates them" do
|
||||||
actor = Actor.get_actor(preferredUsername: "test")
|
actor = Actor.get_actor(preferredUsername: "test")
|
||||||
target_actor = Actor.get_actor(preferredUsername: "test2")
|
target_actor = Actor.get_actor(preferredUsername: "test2")
|
||||||
|
user = User.get_user(id: actor.id)
|
||||||
|
|
||||||
follow_activity = %{
|
follow_activity = %{
|
||||||
"@context" => "https://www.w3.org/ns/activitystreams",
|
"@context" => "https://www.w3.org/ns/activitystreams",
|
||||||
|
@ -25,7 +27,14 @@ defmodule Nulla.HTTPSignatureTest do
|
||||||
}
|
}
|
||||||
|
|
||||||
body = Jason.encode!(follow_activity)
|
body = Jason.encode!(follow_activity)
|
||||||
headers = HTTPSignature.make_headers(body, target_actor.inbox, actor)
|
|
||||||
|
headers =
|
||||||
|
HTTPSignature.make_headers(
|
||||||
|
body,
|
||||||
|
target_actor.inbox,
|
||||||
|
actor.publicKey["id"],
|
||||||
|
user.privateKeyPem
|
||||||
|
)
|
||||||
|
|
||||||
conn =
|
conn =
|
||||||
conn(:post, "/users/test2/inbox", body)
|
conn(:post, "/users/test2/inbox", body)
|
||||||
|
|
|
@ -48,7 +48,8 @@ defmodule Nulla.Fixtures.Data do
|
||||||
actor_url: actor.url,
|
actor_url: actor.url,
|
||||||
content: "Hello World from Nulla!",
|
content: "Hello World from Nulla!",
|
||||||
language: "en",
|
language: "en",
|
||||||
actor_id: actor.id
|
actor_id: actor.id,
|
||||||
|
visibility: "public"
|
||||||
})
|
})
|
||||||
|
|
||||||
{publicKeyPem, privateKeyPem} = KeyGen.gen()
|
{publicKeyPem, privateKeyPem} = KeyGen.gen()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue