Add hint to rules
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
parent
01a5f839c5
commit
ccc3ac241f
|
@ -1764,7 +1764,8 @@ Note that this differs from the Mastodon API variant: Mastodon API only returns
|
||||||
{
|
{
|
||||||
"id": "1",
|
"id": "1",
|
||||||
"priority": 1,
|
"priority": 1,
|
||||||
"text": "There are no rules"
|
"text": "There are no rules",
|
||||||
|
"hint": null
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
```
|
```
|
||||||
|
@ -1775,6 +1776,7 @@ Note that this differs from the Mastodon API variant: Mastodon API only returns
|
||||||
|
|
||||||
- Params:
|
- Params:
|
||||||
- `text`: string, required, rule content
|
- `text`: string, required, rule content
|
||||||
|
- `hint`: string, optional, rule description
|
||||||
- `priority`: integer, optional, rule ordering priority
|
- `priority`: integer, optional, rule ordering priority
|
||||||
|
|
||||||
- Response: JSON, a single rule
|
- Response: JSON, a single rule
|
||||||
|
@ -1785,6 +1787,7 @@ Note that this differs from the Mastodon API variant: Mastodon API only returns
|
||||||
|
|
||||||
- Params:
|
- Params:
|
||||||
- `text`: string, optional, rule content
|
- `text`: string, optional, rule content
|
||||||
|
- `hint`: string, optional, rule description
|
||||||
- `priority`: integer, optional, rule ordering priority
|
- `priority`: integer, optional, rule ordering priority
|
||||||
|
|
||||||
- Response: JSON, a single rule
|
- Response: JSON, a single rule
|
||||||
|
|
|
@ -14,13 +14,14 @@ defmodule Pleroma.Rule do
|
||||||
schema "rules" do
|
schema "rules" do
|
||||||
field(:priority, :integer, default: 0)
|
field(:priority, :integer, default: 0)
|
||||||
field(:text, :string)
|
field(:text, :string)
|
||||||
|
field(:hint, :string)
|
||||||
|
|
||||||
timestamps()
|
timestamps()
|
||||||
end
|
end
|
||||||
|
|
||||||
def changeset(%Rule{} = rule, params \\ %{}) do
|
def changeset(%Rule{} = rule, params \\ %{}) do
|
||||||
rule
|
rule
|
||||||
|> cast(params, [:priority, :text])
|
|> cast(params, [:priority, :text, :hint])
|
||||||
|> validate_required([:text])
|
|> validate_required([:text])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,8 @@ def render("show.json", %{rule: rule} = _opts) do
|
||||||
%{
|
%{
|
||||||
id: to_string(rule.id),
|
id: to_string(rule.id),
|
||||||
priority: rule.priority,
|
priority: rule.priority,
|
||||||
text: rule.text
|
text: rule.text,
|
||||||
|
hint: rule.hint
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -182,7 +182,8 @@ defp report do
|
||||||
type: :object,
|
type: :object,
|
||||||
properties: %{
|
properties: %{
|
||||||
id: %Schema{type: :string},
|
id: %Schema{type: :string},
|
||||||
text: %Schema{type: :string}
|
text: %Schema{type: :string},
|
||||||
|
hint: %Schema{type: :string, nullable: true}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,7 +84,8 @@ defp create_request do
|
||||||
required: [:text],
|
required: [:text],
|
||||||
properties: %{
|
properties: %{
|
||||||
priority: %Schema{type: :integer},
|
priority: %Schema{type: :integer},
|
||||||
text: %Schema{type: :string}
|
text: %Schema{type: :string},
|
||||||
|
hint: %Schema{type: :string}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
@ -94,7 +95,8 @@ defp update_request do
|
||||||
type: :object,
|
type: :object,
|
||||||
properties: %{
|
properties: %{
|
||||||
priority: %Schema{type: :integer},
|
priority: %Schema{type: :integer},
|
||||||
text: %Schema{type: :string}
|
text: %Schema{type: :string},
|
||||||
|
hint: %Schema{type: :string}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
@ -105,7 +107,8 @@ defp rule do
|
||||||
properties: %{
|
properties: %{
|
||||||
id: %Schema{type: :string},
|
id: %Schema{type: :string},
|
||||||
priority: %Schema{type: :integer},
|
priority: %Schema{type: :integer},
|
||||||
text: %Schema{type: :string}
|
text: %Schema{type: :string},
|
||||||
|
hint: %Schema{type: :string, nullable: true}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
|
@ -364,7 +364,8 @@ defp array_of_rules do
|
||||||
type: :object,
|
type: :object,
|
||||||
properties: %{
|
properties: %{
|
||||||
id: %Schema{type: :string},
|
id: %Schema{type: :string},
|
||||||
text: %Schema{type: :string}
|
text: %Schema{type: :string},
|
||||||
|
hint: %Schema{type: :string}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -85,7 +85,8 @@ def render("rules.json", _) do
|
||||||
def render("rule.json", %{rule: rule}) do
|
def render("rule.json", %{rule: rule}) do
|
||||||
%{
|
%{
|
||||||
id: to_string(rule.id),
|
id: to_string(rule.id),
|
||||||
text: rule.text
|
text: rule.text,
|
||||||
|
hint: rule.hint || ""
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
# Pleroma: A lightweight social networking server
|
||||||
|
# Copyright © 2017-2024 Pleroma Authors <https://pleroma.social/>
|
||||||
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
|
defmodule Pleroma.Repo.Migrations.AddHintToRules do
|
||||||
|
use Ecto.Migration
|
||||||
|
|
||||||
|
def change do
|
||||||
|
alter table(:rules) do
|
||||||
|
add_if_not_exists(:hint, :text)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -129,16 +129,27 @@ test "get instance information v2", %{conn: conn} do
|
||||||
end
|
end
|
||||||
|
|
||||||
test "get instance rules", %{conn: conn} do
|
test "get instance rules", %{conn: conn} do
|
||||||
Rule.create(%{text: "Example rule"})
|
Rule.create(%{text: "Example rule", hint: "Rule description", priority: 1})
|
||||||
Rule.create(%{text: "Second rule"})
|
Rule.create(%{text: "Third rule", priority: 2})
|
||||||
Rule.create(%{text: "Third rule"})
|
Rule.create(%{text: "Second rule", priority: 1})
|
||||||
|
|
||||||
conn = get(conn, "/api/v1/instance")
|
conn = get(conn, "/api/v1/instance")
|
||||||
|
|
||||||
assert result = json_response_and_validate_schema(conn, 200)
|
assert result = json_response_and_validate_schema(conn, 200)
|
||||||
|
|
||||||
rules = result["rules"]
|
assert [
|
||||||
|
%{
|
||||||
assert length(rules) == 3
|
"text" => "Example rule",
|
||||||
|
"hint" => "Rule description"
|
||||||
|
},
|
||||||
|
%{
|
||||||
|
"text" => "Second rule",
|
||||||
|
"hint" => ""
|
||||||
|
},
|
||||||
|
%{
|
||||||
|
"text" => "Third rule",
|
||||||
|
"hint" => ""
|
||||||
|
}
|
||||||
|
] = result["rules"]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue