Commit 968e000d280f21668ee0bd67dda2eae8b4074256

Authored by Gustavo Jaruga Cruz
1 parent 7c0e23cb
Exists in oauth_login

Fix oauth_provider, upgrade doorkeeper to 3.0.1

-Fix undefined 'to_model' when creating a new applicationa
-Upgrade doorkeeper to 3.0.1
-Change several html forms to conform with the new version

Signed-off-by: Gustavo Jaruga Cruz <darksshades@gmail.com>
plugins/oauth_provider/Gemfile
1 -gem 'doorkeeper', '~> 1.4.0' 1 +gem 'doorkeeper', '~> 3.1.0'
plugins/oauth_provider/controllers/doorkeeper/application_controller.rb
@@ -2,7 +2,8 @@ module Doorkeeper @@ -2,7 +2,8 @@ module Doorkeeper
2 class ApplicationController < ApplicationController 2 class ApplicationController < ApplicationController
3 3
4 include Helpers::Controller 4 include Helpers::Controller
5 - helper 'doorkeeper/form_errors' 5 +
  6 + helper 'doorkeeper/dashboard'
6 7
7 end 8 end
8 end 9 end
plugins/oauth_provider/controllers/doorkeeper/applications_controller.rb 0 → 100644
@@ -0,0 +1,54 @@ @@ -0,0 +1,54 @@
  1 +module Doorkeeper
  2 + class ApplicationsController < Doorkeeper::ApplicationController
  3 + layout 'doorkeeper/admin'
  4 +
  5 + before_action :authenticate_admin!
  6 + before_action :set_application, only: [:show, :edit, :update, :destroy]
  7 +
  8 + def index
  9 + @applications = Application.all
  10 + end
  11 +
  12 + def new
  13 + @application = Application.new
  14 + end
  15 +
  16 + def create
  17 + @application = Application.new(application_params)
  18 + if @application.save
  19 + flash[:notice] = I18n.t(:notice, scope: [:doorkeeper, :flash, :applications, :create])
  20 + redirect_to oauth_application_url(@application)
  21 + else
  22 + render :new
  23 + end
  24 + end
  25 +
  26 + def update
  27 + if @application.update_attributes(application_params)
  28 + flash[:notice] = I18n.t(:notice, scope: [:doorkeeper, :flash, :applications, :update])
  29 + redirect_to oauth_application_url(@application)
  30 + else
  31 + render :edit
  32 + end
  33 + end
  34 +
  35 + def destroy
  36 + flash[:notice] = I18n.t(:notice, scope: [:doorkeeper, :flash, :applications, :destroy]) if @application.destroy
  37 + redirect_to oauth_applications_url
  38 + end
  39 +
  40 + private
  41 +
  42 + def set_application
  43 + @application = Application.find(params[:id])
  44 + end
  45 +
  46 + def application_params
  47 + if params.respond_to?(:permit)
  48 + params.require(:doorkeeper_application).permit(:name, :redirect_uri, :scopes)
  49 + else
  50 + params[:doorkeeper_application].slice(:name, :redirect_uri, :scopes) rescue nil
  51 + end
  52 + end
  53 + end
  54 +end
plugins/oauth_provider/controllers/oauth_provider_authorizations_controller.rb
@@ -6,4 +6,7 @@ class OauthProviderAuthorizationsController &lt; Doorkeeper::AuthorizationsControll @@ -6,4 +6,7 @@ class OauthProviderAuthorizationsController &lt; Doorkeeper::AuthorizationsControll
6 def index 6 def index
7 end 7 end
8 8
  9 + def show
  10 + end
  11 +
9 end 12 end
plugins/oauth_provider/views/doorkeeper/applications/_delete_form.html.erb
1 <%- submit_btn_css ||= 'btn btn-link' %> 1 <%- submit_btn_css ||= 'btn btn-link' %>
2 -<%= form_tag [:oauth, application] do %> 2 +<%= form_tag oauth_application_path(application) do %>
3 <input type="hidden" name="_method" value="delete"> 3 <input type="hidden" name="_method" value="delete">
4 - <%= submit_tag 'Destroy', onclick: "return confirm('Are you sure?')", class: submit_btn_css %> 4 + <%= submit_tag t('doorkeeper.applications.buttons.destroy'), onclick: "return confirm('#{ t('doorkeeper.applications.confirmations.destroy') }')", class: submit_btn_css %>
5 <% end %> 5 <% end %>
plugins/oauth_provider/views/doorkeeper/applications/_form.html.erb
1 -<%= form_for [:oauth, application], html: {class: 'form-horizontal', role: 'form'} do |f| %> 1 +<%= form_for application, url: doorkeeper_submit_path(application), html: {class: 'form-horizontal', role: 'form'} do |f| %>
2 <% if application.errors.any? %> 2 <% if application.errors.any? %>
3 <div class="alert alert-danger" data-alert> 3 <div class="alert alert-danger" data-alert>
4 <p><%= _('Whoops! Check your form for possible errors') %></p> 4 <p><%= _('Whoops! Check your form for possible errors') %></p>
plugins/oauth_provider/views/doorkeeper/applications/index.html.erb
@@ -17,15 +17,15 @@ @@ -17,15 +17,15 @@
17 <tbody> 17 <tbody>
18 <% @applications.each do |application| %> 18 <% @applications.each do |application| %>
19 <tr id="application_<%= application.id %>"> 19 <tr id="application_<%= application.id %>">
20 - <td><%= link_to application.name, [:oauth, application] %></td> 20 + <td><%= link_to application.name, oauth_application_path(application) %></td>
21 <td><%= application.redirect_uri %></td> 21 <td><%= application.redirect_uri %></td>
22 - <td><%= link_to _('Edit'), edit_oauth_application_path(application), class: 'btn btn-link' %></td> 22 + <td><%= link_to t('doorkeeper.applications.buttons.edit'), edit_oauth_application_path(application), class: 'btn btn-link' %></td>
23 <td><%= render 'delete_form', application: application %></td> 23 <td><%= render 'delete_form', application: application %></td>
24 </tr> 24 </tr>
25 <% end %> 25 <% end %>
26 </tbody> 26 </tbody>
27 </table> 27 </table>
28 -<div class="actions"> 28 +<div class="actions" style="padding-top: 5px;">
29 <%= button(:back, _('Go back'), {:controller => 'oauth_provider_plugin_admin', :action => 'index'}) %> 29 <%= button(:back, _('Go back'), {:controller => 'oauth_provider_plugin_admin', :action => 'index'}) %>
30 </div> 30 </div>
31 </div> 31 </div>
plugins/oauth_provider/views/doorkeeper/applications/show.html.erb
@@ -20,7 +20,8 @@ @@ -20,7 +20,8 @@
20 <td> 20 <td>
21 <code><%= uri %></code> 21 <code><%= uri %></code>
22 </td> 22 </td>
23 - <td> 23 + <td>
  24 + <%= link_to t('doorkeeper.applications.buttons.authorize'), oauth_authorization_path(client_id: @application.uid, redirect_uri: uri, response_type: 'code', scope: @application.scopes), class: 'btn btn-success', target: '_blank' %>
24 </td> 25 </td>
25 </tr> 26 </tr>
26 <% end %> 27 <% end %>
plugins/oauth_provider/views/doorkeeper/authorizations/new.html.erb
@@ -6,16 +6,16 @@ @@ -6,16 +6,16 @@
6 6
7 <main role="main"> 7 <main role="main">
8 <p class="h4"> 8 <p class="h4">
9 - <%= _('Authorize %s to use your account?') % "<strong class=\"text-info\">#{@pre_auth.client.name}</strong>" %> 9 + <%= raw _('Authorize %s to use your account?') % "<strong class=\"text-info\">#{@pre_auth.client.name}</strong>" %>
10 </p> 10 </p>
11 11
12 - <% if @pre_auth.scopes %> 12 + <% if @pre_auth.scopes.count > 0 %>
13 <div id="oauth-permissions"> 13 <div id="oauth-permissions">
14 <p><%= _('This application will be able to:') %></p> 14 <p><%= _('This application will be able to:') %></p>
15 15
16 <ul class="text-info"> 16 <ul class="text-info">
17 <% @pre_auth.scopes.each do |scope| %> 17 <% @pre_auth.scopes.each do |scope| %>
18 - <li><%= OauthProviderPlugin::SCOPE_TRANSLATION[scope] %></li> 18 + <li><%= t scope, scope: [:doorkeeper, :scopes] %></li>
19 <% end %> 19 <% end %>
20 </ul> 20 </ul>
21 </div> 21 </div>
plugins/oauth_provider/views/doorkeeper/authorized_applications/index.html.erb
@@ -25,7 +25,7 @@ @@ -25,7 +25,7 @@
25 </table> 25 </table>
26 </main> 26 </main>
27 27
28 -<div class="actions"> 28 +<div class="actions" style="padding-top: 5px;">
29 <%= button(:back, _('Go back'), :back) %> 29 <%= button(:back, _('Go back'), :back) %>
30 </div> 30 </div>
31 </div> 31 </div>