2019-09-09 09:31:08 +02:00
|
|
|
import EctoEnum
|
|
|
|
|
|
|
|
defenum(Mobilizon.Admin.ActionLogAction, [
|
|
|
|
"update",
|
|
|
|
"create",
|
|
|
|
"delete"
|
|
|
|
])
|
|
|
|
|
2019-07-23 13:49:22 +02:00
|
|
|
defmodule Mobilizon.Admin.ActionLog do
|
|
|
|
@moduledoc """
|
|
|
|
ActionLog entity schema
|
|
|
|
"""
|
|
|
|
use Ecto.Schema
|
|
|
|
import Ecto.Changeset
|
|
|
|
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-09 09:31:08 +02:00
|
|
|
@timestamps_opts [type: :utc_datetime]
|
2019-07-23 13:49:22 +02:00
|
|
|
@required_attrs [:action, :target_type, :target_id, :changes, :actor_id]
|
|
|
|
|
|
|
|
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)
|
|
|
|
belongs_to(:actor, Actor)
|
|
|
|
|
|
|
|
timestamps()
|
|
|
|
end
|
|
|
|
|
|
|
|
@doc false
|
|
|
|
def changeset(action_log, attrs) do
|
|
|
|
action_log
|
|
|
|
|> cast(attrs, @required_attrs)
|
|
|
|
|> validate_required(@required_attrs -- [:changes])
|
|
|
|
end
|
|
|
|
end
|