update copyright years to 2019
[akkoma] / lib / pleroma / user / info.ex
index a5ce6010fecf1c5ccc7610a656bf7525c15f4c35..2f419a5a26066a73072bbffa6dacca7e9cda58b7 100644 (file)
@@ -1,14 +1,20 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
 defmodule Pleroma.User.Info do
   use Ecto.Schema
   import Ecto.Changeset
 
   embedded_schema do
     field(:banner, :map, default: %{})
-    field(:background, :string, default: nil)
+    field(:background, :map, default: %{})
     field(:source_data, :map, default: %{})
     field(:note_count, :integer, default: 0)
     field(:follower_count, :integer, default: 0)
     field(:locked, :boolean, default: false)
+    field(:confirmation_pending, :boolean, default: false)
+    field(:confirmation_token, :string, default: nil)
     field(:default_scope, :string, default: "public")
     field(:blocks, {:array, :string}, default: [])
     field(:domain_blocks, {:array, :string}, default: [])
@@ -23,9 +29,20 @@ defmodule Pleroma.User.Info do
     field(:uri, :string, default: nil)
     field(:topic, :string, default: nil)
     field(:hub, :string, default: nil)
-    # topic, subject, salmon, subscribe_address, uri
+    field(:salmon, :string, default: nil)
+    field(:hide_network, :boolean, default: false)
+
+    # Found in the wild
+    # ap_id -> Where is this used?
+    # bio -> Where is this used?
+    # avatar -> Where is this used?
+    # fqn -> Where is this used?
+    # host -> Where is this used?
+    # subject _> Where is this used?
   end
 
+  def superuser?(info), do: info.is_admin || info.is_moderator
+
   def set_activation_status(info, deactivated) do
     params = %{deactivated: deactivated}
 
@@ -104,7 +121,8 @@ defmodule Pleroma.User.Info do
       :magic_key,
       :uri,
       :hub,
-      :topic
+      :topic,
+      :salmon
     ])
   end
 
@@ -124,10 +142,47 @@ defmodule Pleroma.User.Info do
     |> cast(params, [
       :locked,
       :no_rich_text,
-      :default_scope
+      :default_scope,
+      :banner,
+      :hide_network,
+      :background
+    ])
+  end
+
+  def confirmation_changeset(info, :confirmed) do
+    confirmation_changeset(info, %{
+      confirmation_pending: false,
+      confirmation_token: nil
+    })
+  end
+
+  def confirmation_changeset(info, :unconfirmed) do
+    confirmation_changeset(info, %{
+      confirmation_pending: true,
+      confirmation_token: :crypto.strong_rand_bytes(32) |> Base.url_encode64()
+    })
+  end
+
+  def confirmation_changeset(info, params) do
+    cast(info, params, [:confirmation_pending, :confirmation_token])
+  end
+
+  def mastodon_profile_update(info, params) do
+    info
+    |> cast(params, [
+      :locked,
+      :banner
     ])
   end
 
+  def mastodon_settings_update(info, settings) do
+    params = %{settings: settings}
+
+    info
+    |> cast(params, [:settings])
+    |> validate_required([:settings])
+  end
+
   def set_source_data(info, source_data) do
     params = %{source_data: source_data}