From 6c809dfae84e702f7a49d3fac5725745264e0ff9 Mon Sep 17 00:00:00 2001 From: Timothy Andrew Date: Tue, 22 Nov 2016 14:27:31 +0530 Subject: Allow creating personal access tokens / OAuth applications with scopes. --- app/controllers/concerns/oauth_applications.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 app/controllers/concerns/oauth_applications.rb (limited to 'app/controllers/concerns/oauth_applications.rb') diff --git a/app/controllers/concerns/oauth_applications.rb b/app/controllers/concerns/oauth_applications.rb new file mode 100644 index 00000000000..34ad43ededd --- /dev/null +++ b/app/controllers/concerns/oauth_applications.rb @@ -0,0 +1,14 @@ +module OauthApplications + extend ActiveSupport::Concern + + included do + before_action :prepare_scopes, only: [:create, :update] + end + + def prepare_scopes + scopes = params.dig(:doorkeeper_application, :scopes) + if scopes + params[:doorkeeper_application][:scopes] = scopes.join(' ') + end + end +end -- cgit v1.2.1 From 4d6da770de94f4bf140507cdf43461b67269ce28 Mon Sep 17 00:00:00 2001 From: Timothy Andrew Date: Thu, 24 Nov 2016 13:07:22 +0530 Subject: Implement minor changes from @dbalexandre's review. - Mainly whitespace changes. - Require the migration adding the `scope` column to the `personal_access_tokens` table to have downtime, since API calls will fail if the new code is in place, but the migration hasn't run. - Minor refactoring - load `@scopes` in a `before_action`, since we're doing it in three different places. --- app/controllers/concerns/oauth_applications.rb | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'app/controllers/concerns/oauth_applications.rb') diff --git a/app/controllers/concerns/oauth_applications.rb b/app/controllers/concerns/oauth_applications.rb index 34ad43ededd..7210ed3eb32 100644 --- a/app/controllers/concerns/oauth_applications.rb +++ b/app/controllers/concerns/oauth_applications.rb @@ -7,8 +7,13 @@ module OauthApplications def prepare_scopes scopes = params.dig(:doorkeeper_application, :scopes) + if scopes params[:doorkeeper_application][:scopes] = scopes.join(' ') end end + + def load_scopes + @scopes = Doorkeeper.configuration.scopes + end end -- cgit v1.2.1 From 34ed74fab90904eb77c8b07779401650684af5b1 Mon Sep 17 00:00:00 2001 From: Douglas Barbosa Alexandre Date: Fri, 16 Dec 2016 19:59:53 -0200 Subject: Avoid use of Hash#dig to keep compatibility with Ruby 2.1 --- app/controllers/concerns/oauth_applications.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/controllers/concerns/oauth_applications.rb') diff --git a/app/controllers/concerns/oauth_applications.rb b/app/controllers/concerns/oauth_applications.rb index 7210ed3eb32..9849aa93fa6 100644 --- a/app/controllers/concerns/oauth_applications.rb +++ b/app/controllers/concerns/oauth_applications.rb @@ -6,7 +6,7 @@ module OauthApplications end def prepare_scopes - scopes = params.dig(:doorkeeper_application, :scopes) + scopes = params.fetch(:doorkeeper_application, {}).fetch(:scopes, nil) if scopes params[:doorkeeper_application][:scopes] = scopes.join(' ') -- cgit v1.2.1