2019-07-23 13:49:22 +02:00
|
|
|
defmodule Mobilizon.Admin.ActionLog do
|
|
|
|
@moduledoc """
|
2019-09-08 02:06:28 +02:00
|
|
|
Represents an action log entity.
|
2019-07-23 13:49:22 +02:00
|
|
|
"""
|
2019-09-08 02:06:28 +02:00
|
|
|
|
2019-07-23 13:49:22 +02:00
|
|
|
use Ecto.Schema
|
2019-09-08 02:06:28 +02:00
|
|
|
|
2019-07-23 13:49:22 +02:00
|
|
|
import Ecto.Changeset
|
2019-09-08 02:06:28 +02:00
|
|
|
|
2019-07-23 13:49:22 +02:00
|
|
|
alias Mobilizon.Actors.Actor
|
2019-09-09 09:31:08 +02:00
|
|
|
alias Mobilizon.Admin.ActionLogAction
|
2019-07-23 13:49:22 +02:00
|
|
|
|
2019-09-08 02:06:28 +02:00
|
|
|
@type t :: %__MODULE__{
|
|
|
|
action: String.t(),
|
|
|
|
target_type: String.t(),
|
|
|
|
target_id: integer,
|
|
|
|
changes: map,
|
|
|
|
actor: Actor.t()
|
|
|
|
}
|
|
|
|
|
2019-07-23 13:49:22 +02:00
|
|
|
@required_attrs [:action, :target_type, :target_id, :changes, :actor_id]
|
2019-09-21 23:59:07 +02:00
|
|
|
@attrs @required_attrs
|
|
|
|
|
|
|
|
@timestamps_opts [type: :utc_datetime]
|
2019-07-23 13:49:22 +02:00
|
|
|
|
|
|
|
schema "admin_action_logs" do
|
2019-09-09 09:31:08 +02:00
|
|
|
field(:action, ActionLogAction)
|
2019-07-23 13:49:22 +02:00
|
|
|
field(:target_type, :string)
|
|
|
|
field(:target_id, :integer)
|
|
|
|
field(:changes, :map)
|
2019-09-08 02:06:28 +02:00
|
|
|
|
2019-07-23 13:49:22 +02:00
|
|
|
belongs_to(:actor, Actor)
|
|
|
|
|
|
|
|
timestamps()
|
|
|
|
end
|
|
|
|
|
|
|
|
@doc false
|
2019-09-13 01:55:45 +02:00
|
|
|
@spec changeset(t, map) :: Ecto.Changeset.t()
|
|
|
|
def changeset(%__MODULE__{} = action_log, attrs) do
|
2019-07-23 13:49:22 +02:00
|
|
|
action_log
|
2019-09-08 02:06:28 +02:00
|
|
|
|> cast(attrs, @attrs)
|
|
|
|
|> validate_required(@required_attrs)
|
2019-07-23 13:49:22 +02:00
|
|
|
end
|
|
|
|
end
|