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