File size: 789 Bytes
8da2481 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | defmodule Plausible.Site.GoogleAuth do
@moduledoc """
Struct for storing google auth token info used by search console.
"""
use Ecto.Schema
import Ecto.Changeset
schema "google_auth" do
field :email, :string
field :property, :string
field :refresh_token, :string
field :access_token, :string
field :expires, :naive_datetime
belongs_to :user, Plausible.Auth.User
belongs_to :site, Plausible.Site
timestamps()
end
def changeset(auth, attrs \\ %{}) do
auth
|> cast(attrs, [:refresh_token, :access_token, :expires, :email])
|> validate_required([:refresh_token, :access_token, :expires, :email])
|> unique_constraint(:site)
end
def set_property(auth, attrs \\ %{}) do
auth
|> cast(attrs, [:property])
end
end
|