Compare View
Commits (1)
-
-Fix undefined 'to_model' when creating a new applicationa -Upgrade doorkeeper to 2.2.0 -Change several html forms to conform with the new version Signed-off-by: Gustavo Jaruga Cruz <darksshades@gmail.com> Signed-off-by: Thiago Ribeiro <thiagitosouza@gmail.com>
Showing
12 changed files
Show diff stats
plugins/oauth_provider/Gemfile
plugins/oauth_provider/controllers/doorkeeper/application_controller.rb
plugins/oauth_provider/controllers/doorkeeper/applications_controller.rb
0 → 100644
| ... | ... | @@ -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
plugins/oauth_provider/db/migrate/20140829153047_create_doorkeeper_tables.rb
| ... | ... | @@ -1,41 +0,0 @@ |
| 1 | -class CreateDoorkeeperTables < ActiveRecord::Migration | |
| 2 | - def change | |
| 3 | - create_table :oauth_applications do |t| | |
| 4 | - t.string :name, null: false | |
| 5 | - t.string :uid, null: false | |
| 6 | - t.string :secret, null: false | |
| 7 | - t.text :redirect_uri, null: false | |
| 8 | - t.timestamps | |
| 9 | - end | |
| 10 | - | |
| 11 | - add_index :oauth_applications, :uid, unique: true | |
| 12 | - | |
| 13 | - create_table :oauth_access_grants do |t| | |
| 14 | - t.integer :resource_owner_id, null: false | |
| 15 | - t.integer :application_id, null: false | |
| 16 | - t.string :token, null: false | |
| 17 | - t.integer :expires_in, null: false | |
| 18 | - t.text :redirect_uri, null: false | |
| 19 | - t.datetime :created_at, null: false | |
| 20 | - t.datetime :revoked_at | |
| 21 | - t.string :scopes | |
| 22 | - end | |
| 23 | - | |
| 24 | - add_index :oauth_access_grants, :token, unique: true | |
| 25 | - | |
| 26 | - create_table :oauth_access_tokens do |t| | |
| 27 | - t.integer :resource_owner_id | |
| 28 | - t.integer :application_id | |
| 29 | - t.string :token, null: false | |
| 30 | - t.string :refresh_token | |
| 31 | - t.integer :expires_in | |
| 32 | - t.datetime :revoked_at | |
| 33 | - t.datetime :created_at, null: false | |
| 34 | - t.string :scopes | |
| 35 | - end | |
| 36 | - | |
| 37 | - add_index :oauth_access_tokens, :token, unique: true | |
| 38 | - add_index :oauth_access_tokens, :resource_owner_id | |
| 39 | - add_index :oauth_access_tokens, :refresh_token, unique: true | |
| 40 | - end | |
| 41 | -end |
plugins/oauth_provider/db/migrate/20170718153047_create_doorkeeper_tables.rb
0 → 100644
| ... | ... | @@ -0,0 +1,42 @@ |
| 1 | +class CreateDoorkeeperTables < ActiveRecord::Migration | |
| 2 | + def change | |
| 3 | + create_table :oauth_applications do |t| | |
| 4 | + t.string :name, null: false | |
| 5 | + t.string :uid, null: false | |
| 6 | + t.string :secret, null: false | |
| 7 | + t.text :redirect_uri, null: false | |
| 8 | + t.string :scopes, null: false, default: '' | |
| 9 | + t.timestamps | |
| 10 | + end | |
| 11 | + | |
| 12 | + add_index :oauth_applications, :uid, unique: true | |
| 13 | + | |
| 14 | + create_table :oauth_access_grants do |t| | |
| 15 | + t.integer :resource_owner_id, null: false | |
| 16 | + t.integer :application_id, null: false | |
| 17 | + t.string :token, null: false | |
| 18 | + t.integer :expires_in, null: false | |
| 19 | + t.text :redirect_uri, null: false | |
| 20 | + t.datetime :created_at, null: false | |
| 21 | + t.datetime :revoked_at | |
| 22 | + t.string :scopes | |
| 23 | + end | |
| 24 | + | |
| 25 | + add_index :oauth_access_grants, :token, unique: true | |
| 26 | + | |
| 27 | + create_table :oauth_access_tokens do |t| | |
| 28 | + t.integer :resource_owner_id | |
| 29 | + t.integer :application_id | |
| 30 | + t.string :token, null: false | |
| 31 | + t.string :refresh_token | |
| 32 | + t.integer :expires_in | |
| 33 | + t.datetime :revoked_at | |
| 34 | + t.datetime :created_at, null: false | |
| 35 | + t.string :scopes | |
| 36 | + end | |
| 37 | + | |
| 38 | + add_index :oauth_access_tokens, :token, unique: true | |
| 39 | + add_index :oauth_access_tokens, :resource_owner_id | |
| 40 | + add_index :oauth_access_tokens, :refresh_token, unique: true | |
| 41 | + end | |
| 42 | +end | ... | ... |
plugins/oauth_provider/views/doorkeeper/applications/_delete_form.html.erb
| 1 | 1 | <%- submit_btn_css ||= 'btn btn-link' %> |
| 2 | -<%= form_tag [:oauth, application] do %> | |
| 2 | +<%= form_tag oauth_application_path(application) do %> | |
| 3 | 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 | 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 | 2 | <% if application.errors.any? %> |
| 3 | 3 | <div class="alert alert-danger" data-alert> |
| 4 | 4 | <p><%= _('Whoops! Check your form for possible errors') %></p> | ... | ... |
plugins/oauth_provider/views/doorkeeper/applications/index.html.erb
| ... | ... | @@ -17,15 +17,15 @@ |
| 17 | 17 | <tbody> |
| 18 | 18 | <% @applications.each do |application| %> |
| 19 | 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 | 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 | 23 | <td><%= render 'delete_form', application: application %></td> |
| 24 | 24 | </tr> |
| 25 | 25 | <% end %> |
| 26 | 26 | </tbody> |
| 27 | 27 | </table> |
| 28 | -<div class="actions"> | |
| 28 | +<div class="actions" style="padding-top: 5px;"> | |
| 29 | 29 | <%= button(:back, _('Go back'), {:controller => 'oauth_provider_plugin_admin', :action => 'index'}) %> |
| 30 | 30 | </div> |
| 31 | 31 | </div> | ... | ... |
plugins/oauth_provider/views/doorkeeper/applications/show.html.erb
| ... | ... | @@ -20,7 +20,8 @@ |
| 20 | 20 | <td> |
| 21 | 21 | <code><%= uri %></code> |
| 22 | 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 | 25 | </td> |
| 25 | 26 | </tr> |
| 26 | 27 | <% end %> | ... | ... |
plugins/oauth_provider/views/doorkeeper/authorizations/new.html.erb
| ... | ... | @@ -6,16 +6,16 @@ |
| 6 | 6 | |
| 7 | 7 | <main role="main"> |
| 8 | 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 | 10 | </p> |
| 11 | 11 | |
| 12 | - <% if @pre_auth.scopes %> | |
| 12 | + <% if @pre_auth.scopes.count > 0 %> | |
| 13 | 13 | <div id="oauth-permissions"> |
| 14 | 14 | <p><%= _('This application will be able to:') %></p> |
| 15 | 15 | |
| 16 | 16 | <ul class="text-info"> |
| 17 | 17 | <% @pre_auth.scopes.each do |scope| %> |
| 18 | - <li><%= OauthProviderPlugin::SCOPE_TRANSLATION[scope] %></li> | |
| 18 | + <li><%= t scope, scope: [:doorkeeper, :scopes] %></li> | |
| 19 | 19 | <% end %> |
| 20 | 20 | </ul> |
| 21 | 21 | </div> | ... | ... |
plugins/oauth_provider/views/doorkeeper/authorized_applications/index.html.erb