From 4ad843fb9df838f36c014ddfb76d7107ba2b5c7b Mon Sep 17 00:00:00 2001 From: Ivan Tashkinov Date: Sat, 9 Feb 2019 17:09:08 +0300 Subject: [#468] Prototype of OAuth2 scopes support. TwitterAPI scope restrictions. --- ...20190208131753_add_scope_to_o_auth_entities.exs | 11 ++++++++ ...123318_data_migration_populate_o_auth_scope.exs | 29 ++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 priv/repo/migrations/20190208131753_add_scope_to_o_auth_entities.exs create mode 100644 priv/repo/migrations/20190209123318_data_migration_populate_o_auth_scope.exs (limited to 'priv') 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 -- cgit v1.2.3