aboutsummaryrefslogtreecommitdiff
path: root/priv
diff options
context:
space:
mode:
authorIvan Tashkinov <ivantashkinov@gmail.com>2019-02-09 17:09:08 +0300
committerIvan Tashkinov <ivantashkinov@gmail.com>2019-02-09 17:09:08 +0300
commit4ad843fb9df838f36c014ddfb76d7107ba2b5c7b (patch)
tree661ff9cb6e6cdadfdf8e980841f8d11b315df56a /priv
parent99fd199bda8bd90cd3e8c69d54087531ddc02eac (diff)
downloadpleroma-4ad843fb9df838f36c014ddfb76d7107ba2b5c7b.tar.gz
[#468] Prototype of OAuth2 scopes support. TwitterAPI scope restrictions.
Diffstat (limited to 'priv')
-rw-r--r--priv/repo/migrations/20190208131753_add_scope_to_o_auth_entities.exs11
-rw-r--r--priv/repo/migrations/20190209123318_data_migration_populate_o_auth_scope.exs29
2 files changed, 40 insertions, 0 deletions
diff --git a/priv/repo/migrations/20190208131753_add_scope_to_o_auth_entities.exs b/priv/repo/migrations/20190208131753_add_scope_to_o_auth_entities.exs
new file mode 100644
index 000000000..809e9ab22
--- /dev/null
+++ b/priv/repo/migrations/20190208131753_add_scope_to_o_auth_entities.exs
@@ -0,0 +1,11 @@
+defmodule Pleroma.Repo.Migrations.AddScopeToOAuthEntities do
+ use Ecto.Migration
+
+ def change do
+ for t <- [:oauth_authorizations, :oauth_tokens] do
+ alter table(t) do
+ add :scope, :string
+ end
+ end
+ end
+end
diff --git a/priv/repo/migrations/20190209123318_data_migration_populate_o_auth_scope.exs b/priv/repo/migrations/20190209123318_data_migration_populate_o_auth_scope.exs
new file mode 100644
index 000000000..722cd6cf9
--- /dev/null
+++ b/priv/repo/migrations/20190209123318_data_migration_populate_o_auth_scope.exs
@@ -0,0 +1,29 @@
+defmodule Pleroma.Repo.Migrations.DataMigrationPopulateOAuthScope do
+ use Ecto.Migration
+
+ require Ecto.Query
+
+ alias Ecto.Query
+ alias Pleroma.Repo
+ alias Pleroma.Web.OAuth
+ alias Pleroma.Web.OAuth.{App, Authorization, Token}
+
+ def up do
+ for app <- Repo.all(Query.from(app in App)) do
+ scopes = OAuth.parse_scopes(app.scopes)
+ scope = Enum.join(scopes, " ")
+
+ Repo.update_all(
+ Query.from(auth in Authorization, where: auth.app_id == ^app.id),
+ set: [scope: scope]
+ )
+
+ Repo.update_all(
+ Query.from(token in Token, where: token.app_id == ^app.id),
+ set: [scope: scope]
+ )
+ end
+ end
+
+ def down, do: :noop
+end