Remove service_domain leftovers
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
parent
5a6be1dd6e
commit
512db8f6dc
5 changed files with 6 additions and 19 deletions
|
@ -13,7 +13,6 @@ defmodule Pleroma.Domain do
|
||||||
|
|
||||||
schema "domains" do
|
schema "domains" do
|
||||||
field(:domain, :string, default: "")
|
field(:domain, :string, default: "")
|
||||||
field(:service_domain, :string, default: "")
|
|
||||||
field(:public, :boolean, default: false)
|
field(:public, :boolean, default: false)
|
||||||
field(:resolves, :boolean, default: false)
|
field(:resolves, :boolean, default: false)
|
||||||
field(:last_checked_at, :naive_datetime)
|
field(:last_checked_at, :naive_datetime)
|
||||||
|
@ -25,10 +24,8 @@ def changeset(%__MODULE__{} = domain, params \\ %{}) do
|
||||||
domain
|
domain
|
||||||
|> cast(params, [:domain, :public])
|
|> cast(params, [:domain, :public])
|
||||||
|> validate_required([:domain])
|
|> validate_required([:domain])
|
||||||
|> maybe_add_service_domain()
|
|
||||||
|> update_change(:domain, &String.downcase/1)
|
|> update_change(:domain, &String.downcase/1)
|
||||||
|> unique_constraint(:domain)
|
|> unique_constraint(:domain)
|
||||||
|> unique_constraint(:service_domain)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_changeset(%__MODULE__{} = domain, params \\ %{}) do
|
def update_changeset(%__MODULE__{} = domain, params \\ %{}) do
|
||||||
|
@ -47,12 +44,6 @@ def update_state_changeset(%__MODULE__{} = domain, resolves) do
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
defp maybe_add_service_domain(%{changes: %{service_domain: _}} = changeset), do: changeset
|
|
||||||
|
|
||||||
defp maybe_add_service_domain(%{changes: %{domain: domain}} = changeset) do
|
|
||||||
change(changeset, service_domain: domain)
|
|
||||||
end
|
|
||||||
|
|
||||||
def list do
|
def list do
|
||||||
__MODULE__
|
__MODULE__
|
||||||
|> order_by(asc: :id)
|
|> order_by(asc: :id)
|
||||||
|
@ -61,9 +52,9 @@ def list do
|
||||||
|
|
||||||
def get(id), do: Repo.get(__MODULE__, id)
|
def get(id), do: Repo.get(__MODULE__, id)
|
||||||
|
|
||||||
def get_by_service_domain(domain) do
|
def get_by_name(domain) do
|
||||||
__MODULE__
|
__MODULE__
|
||||||
|> where(service_domain: ^domain)
|
|> where(domain: ^domain)
|
||||||
|> Repo.one()
|
|> Repo.one()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,7 @@ def create(%{body_params: params} = conn, _) do
|
||||||
with {:domain_not_used, true} <-
|
with {:domain_not_used, true} <-
|
||||||
{:domain_not_used, params[:domain] !== Pleroma.Web.WebFinger.host()},
|
{:domain_not_used, params[:domain] !== Pleroma.Web.WebFinger.host()},
|
||||||
{:ok, domain} <- Domain.create(params),
|
{:ok, domain} <- Domain.create(params),
|
||||||
_ <- @cachex.del(:domain, :domains_list) do
|
_ <- @cachex.del(:domain_cache, :domains_list) do
|
||||||
Pleroma.Workers.CheckDomainResolveWorker.enqueue("check_domain_resolve", %{
|
Pleroma.Workers.CheckDomainResolveWorker.enqueue("check_domain_resolve", %{
|
||||||
"id" => domain.id
|
"id" => domain.id
|
||||||
})
|
})
|
||||||
|
@ -62,14 +62,14 @@ def update(%{body_params: params} = conn, %{id: id}) do
|
||||||
params
|
params
|
||||||
|> Domain.update(id)
|
|> Domain.update(id)
|
||||||
|
|
||||||
@cachex.del(:domain, :domains_list)
|
@cachex.del(:domain_cache, :domains_list)
|
||||||
|
|
||||||
render(conn, "show.json", domain: domain)
|
render(conn, "show.json", domain: domain)
|
||||||
end
|
end
|
||||||
|
|
||||||
def delete(conn, %{id: id}) do
|
def delete(conn, %{id: id}) do
|
||||||
with {:ok, _} <- Domain.delete(id),
|
with {:ok, _} <- Domain.delete(id),
|
||||||
_ <- @cachex.del(:domain, :domains_list) do
|
_ <- @cachex.del(:domain_cache, :domains_list) do
|
||||||
json(conn, %{})
|
json(conn, %{})
|
||||||
else
|
else
|
||||||
_ -> json_response(conn, :bad_request, "")
|
_ -> json_response(conn, :bad_request, "")
|
||||||
|
|
|
@ -84,7 +84,6 @@ defp create_request do
|
||||||
required: [:domain],
|
required: [:domain],
|
||||||
properties: %{
|
properties: %{
|
||||||
domain: %Schema{type: :string},
|
domain: %Schema{type: :string},
|
||||||
service_domain: %Schema{type: :string, nullable: true},
|
|
||||||
public: %Schema{type: :boolean, nullable: true}
|
public: %Schema{type: :boolean, nullable: true}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -105,7 +104,6 @@ defp domain do
|
||||||
properties: %{
|
properties: %{
|
||||||
id: %Schema{type: :integer},
|
id: %Schema{type: :integer},
|
||||||
domain: %Schema{type: :string},
|
domain: %Schema{type: :string},
|
||||||
service_domain: %Schema{type: :string},
|
|
||||||
public: %Schema{type: :boolean},
|
public: %Schema{type: :boolean},
|
||||||
resolves: %Schema{type: :boolean},
|
resolves: %Schema{type: :boolean},
|
||||||
last_checked_at: %Schema{type: :string, format: "date-time", nullable: true}
|
last_checked_at: %Schema{type: :string, format: "date-time", nullable: true}
|
||||||
|
|
|
@ -17,7 +17,7 @@ def perform(%{host: domain} = conn, _opts) do
|
||||||
Pleroma.Config.get([__MODULE__, :domain]),
|
Pleroma.Config.get([__MODULE__, :domain]),
|
||||||
Pleroma.Web.Endpoint.host()
|
Pleroma.Web.Endpoint.host()
|
||||||
],
|
],
|
||||||
%Domain{} = domain <- Domain.get_by_service_domain(domain) do
|
%Domain{} = domain <- Domain.get_by_name(domain) do
|
||||||
Map.put(conn, :domain, domain)
|
Map.put(conn, :domain, domain)
|
||||||
else
|
else
|
||||||
_ -> conn
|
_ -> conn
|
||||||
|
|
|
@ -4,7 +4,6 @@ defmodule Pleroma.Repo.Migrations.CreateDomains do
|
||||||
def change do
|
def change do
|
||||||
create_if_not_exists table(:domains) do
|
create_if_not_exists table(:domains) do
|
||||||
add(:domain, :citext)
|
add(:domain, :citext)
|
||||||
add(:service_domain, :citext)
|
|
||||||
add(:public, :boolean)
|
add(:public, :boolean)
|
||||||
add(:resolves, :boolean)
|
add(:resolves, :boolean)
|
||||||
add(:last_checked_at, :naive_datetime)
|
add(:last_checked_at, :naive_datetime)
|
||||||
|
@ -13,7 +12,6 @@ def change do
|
||||||
end
|
end
|
||||||
|
|
||||||
create_if_not_exists(unique_index(:domains, [:domain]))
|
create_if_not_exists(unique_index(:domains, [:domain]))
|
||||||
create_if_not_exists(unique_index(:domains, [:service_domain]))
|
|
||||||
|
|
||||||
alter table(:users) do
|
alter table(:users) do
|
||||||
add(:domain_id, references(:domains))
|
add(:domain_id, references(:domains))
|
||||||
|
|
Loading…
Reference in a new issue