[#468] User UI for OAuth permissions restriction. Standardized storage format for scopes fields, updated usages.

This commit is contained in:
Ivan Tashkinov 2019-02-14 00:29:29 +03:00
commit 063baca5e4
18 changed files with 98 additions and 43 deletions

View file

@ -1,10 +1,10 @@
defmodule Pleroma.Repo.Migrations.AddScopeToOAuthEntities do
defmodule Pleroma.Repo.Migrations.AddScopeSToOAuthEntities do
use Ecto.Migration
def change do
for t <- [:oauth_authorizations, :oauth_tokens] do
alter table(t) do
add :scope, :string
add :scopes, {:array, :string}, default: [], null: false
end
end
end

View file

@ -1,4 +1,4 @@
defmodule Pleroma.Repo.Migrations.DataMigrationPopulateOAuthScope do
defmodule Pleroma.Repo.Migrations.DataMigrationPopulateOAuthScopes do
use Ecto.Migration
require Ecto.Query
@ -11,16 +11,15 @@ defmodule Pleroma.Repo.Migrations.DataMigrationPopulateOAuthScope do
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]
set: [scopes: scopes]
)
Repo.update_all(
Query.from(token in Token, where: token.app_id == ^app.id),
set: [scope: scope]
set: [scopes: scopes]
)
end
end

View file

@ -0,0 +1,17 @@
defmodule Pleroma.Repo.Migrations.ChangeAppsScopesToVarcharArray do
use Ecto.Migration
@alter_apps_scopes "ALTER TABLE apps ALTER COLUMN scopes"
def up do
execute "#{@alter_apps_scopes} TYPE varchar(255)[] USING string_to_array(scopes, ',')::varchar(255)[];"
execute "#{@alter_apps_scopes} SET DEFAULT ARRAY[]::character varying[];"
execute "#{@alter_apps_scopes} SET NOT NULL;"
end
def down do
execute "#{@alter_apps_scopes} DROP NOT NULL;"
execute "#{@alter_apps_scopes} DROP DEFAULT;"
execute "#{@alter_apps_scopes} TYPE varchar(255) USING array_to_string(scopes, ',')::varchar(255);"
end
end