2023-02-15 19:31:23 +01:00
|
|
|
defmodule Mobilizon.Applications.ApplicationToken do
|
|
|
|
@moduledoc """
|
|
|
|
Module representing an application token
|
|
|
|
"""
|
|
|
|
use Ecto.Schema
|
|
|
|
import Ecto.Changeset
|
2023-02-21 14:50:09 +01:00
|
|
|
alias Mobilizon.Applications.{Application, ApplicationTokenStatus}
|
|
|
|
alias Mobilizon.Users.User
|
2023-02-15 19:31:23 +01:00
|
|
|
|
|
|
|
schema "application_tokens" do
|
2023-02-21 14:50:09 +01:00
|
|
|
belongs_to(:user, User)
|
|
|
|
belongs_to(:application, Application)
|
2023-02-15 19:31:23 +01:00
|
|
|
field(:authorization_code, :string)
|
2023-03-17 18:10:59 +01:00
|
|
|
field(:status, ApplicationTokenStatus, default: :pending)
|
2023-02-21 14:50:09 +01:00
|
|
|
field(:scope, :string)
|
2023-02-15 19:31:23 +01:00
|
|
|
|
|
|
|
timestamps()
|
|
|
|
end
|
|
|
|
|
2023-02-21 14:50:09 +01:00
|
|
|
@required_attrs [:user_id, :application_id, :scope]
|
2023-08-10 11:56:26 +02:00
|
|
|
@optional_attrs [:authorization_code, :status]
|
2023-02-15 19:31:23 +01:00
|
|
|
@attrs @required_attrs ++ @optional_attrs
|
|
|
|
|
|
|
|
@doc false
|
|
|
|
def changeset(application_token, attrs) do
|
|
|
|
application_token
|
|
|
|
|> cast(attrs, @attrs)
|
|
|
|
|> validate_required(@required_attrs)
|
|
|
|
end
|
|
|
|
end
|