X-Git-Url: https://git.squeep.com/?a=blobdiff_plain;ds=inline;f=lib%2Fpleroma%2Fweb%2Fo_auth%2Fapp.ex;h=dacfbadc8ed174c881e5664a8b7de58f2bb89077;hb=b7e8ce235073ab45db24dfc6c27bc6998b43a200;hp=df99472e19092d7175c245134ae5d7e6aa8acbfb;hpb=1172844ed18d94d84724dc6f11c6e9f72e0ba6ec;p=akkoma
diff --git a/lib/pleroma/web/o_auth/app.ex b/lib/pleroma/web/o_auth/app.ex
index df99472e1..dacfbadc8 100644
--- a/lib/pleroma/web/o_auth/app.ex
+++ b/lib/pleroma/web/o_auth/app.ex
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2020 Pleroma Authors
+# Copyright © 2017-2021 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.OAuth.App do
@@ -7,6 +7,7 @@ defmodule Pleroma.Web.OAuth.App do
import Ecto.Changeset
import Ecto.Query
alias Pleroma.Repo
+ alias Pleroma.User
@type t :: %__MODULE__{}
@@ -19,6 +20,8 @@ defmodule Pleroma.Web.OAuth.App do
field(:client_secret, :string)
field(:trusted, :boolean, default: false)
+ belongs_to(:user, User, type: FlakeId.Ecto.CompatType)
+
has_many(:oauth_authorizations, Pleroma.Web.OAuth.Authorization, on_delete: :delete_all)
has_many(:oauth_tokens, Pleroma.Web.OAuth.Token, on_delete: :delete_all)
@@ -27,7 +30,7 @@ defmodule Pleroma.Web.OAuth.App do
@spec changeset(t(), map()) :: Ecto.Changeset.t()
def changeset(struct, params) do
- cast(struct, params, [:client_name, :redirect_uris, :scopes, :website, :trusted])
+ cast(struct, params, [:client_name, :redirect_uris, :scopes, :website, :trusted, :user_id])
end
@spec register_changeset(t(), map()) :: Ecto.Changeset.t()
@@ -129,6 +132,12 @@ defmodule Pleroma.Web.OAuth.App do
{:ok, Repo.all(query), count}
end
+ @spec get_user_apps(User.t()) :: {:ok, [t()], non_neg_integer()}
+ def get_user_apps(%User{id: user_id}) do
+ from(a in __MODULE__, where: a.user_id == ^user_id)
+ |> Repo.all()
+ end
+
@spec destroy(pos_integer()) :: {:ok, t()} | {:error, Ecto.Changeset.t()}
def destroy(id) do
with %__MODULE__{} = app <- Repo.get(__MODULE__, id) do