diff options
author | Eugen Rochko <eugen@zeonfederated.com> | 2016-03-14 17:49:13 +0100 |
---|---|---|
committer | Eugen Rochko <eugen@zeonfederated.com> | 2016-03-14 17:49:13 +0100 |
commit | 6fec8afc3f91166930c8b4dfca441a5a70a24d5b (patch) | |
tree | 4cd02810b87de1dccf7b96630910921d76357921 | |
parent | 25d7c1b6eaf03ddaec892c82f7d93a128b79a872 (diff) |
Bind oauth applications to users
-rw-r--r-- | app/assets/javascripts/oauth/applications.coffee | 3 | ||||
-rw-r--r-- | app/assets/stylesheets/dashboard.scss | 6 | ||||
-rw-r--r-- | app/assets/stylesheets/oauth/applications.scss | 3 | ||||
-rw-r--r-- | app/controllers/oauth/applications_controller.rb | 18 | ||||
-rw-r--r-- | app/helpers/oauth/applications_helper.rb | 2 | ||||
-rw-r--r-- | app/models/user.rb | 2 | ||||
-rw-r--r-- | config/initializers/doorkeeper.rb | 2 | ||||
-rw-r--r-- | config/routes.rb | 4 | ||||
-rw-r--r-- | db/migrate/20160314164231_add_owner_to_application.rb | 7 | ||||
-rw-r--r-- | db/schema.rb | 5 | ||||
-rw-r--r-- | spec/controllers/oauth/applications_controller_spec.rb | 5 | ||||
-rw-r--r-- | spec/helpers/oauth/applications_helper_spec.rb | 15 |
12 files changed, 69 insertions, 3 deletions
diff --git a/app/assets/javascripts/oauth/applications.coffee b/app/assets/javascripts/oauth/applications.coffee new file mode 100644 index 000000000..24f83d18b --- /dev/null +++ b/app/assets/javascripts/oauth/applications.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/app/assets/stylesheets/dashboard.scss b/app/assets/stylesheets/dashboard.scss index 166ce42c1..08a9415d1 100644 --- a/app/assets/stylesheets/dashboard.scss +++ b/app/assets/stylesheets/dashboard.scss @@ -247,6 +247,12 @@ input[type=file] { display: block; } + + .hint { + display: block; + margin-top: 5px; + color: lighten(#282c37, 25%); + } } } diff --git a/app/assets/stylesheets/oauth/applications.scss b/app/assets/stylesheets/oauth/applications.scss new file mode 100644 index 000000000..50933741e --- /dev/null +++ b/app/assets/stylesheets/oauth/applications.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the oauth::applications controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/oauth/applications_controller.rb b/app/controllers/oauth/applications_controller.rb new file mode 100644 index 000000000..4614ef2f7 --- /dev/null +++ b/app/controllers/oauth/applications_controller.rb @@ -0,0 +1,18 @@ +class Oauth::ApplicationsController < Doorkeeper::ApplicationsController + before_filter :authenticate_user! + + def index + @applications = current_user.oauth_applications + end + + def create + @application = Doorkeeper::Application.new(application_params) + @application.owner = current_user + + if @application.save + redirect_to oauth_application_url(@application) + else + render :new + end + end +end diff --git a/app/helpers/oauth/applications_helper.rb b/app/helpers/oauth/applications_helper.rb new file mode 100644 index 000000000..2c1818055 --- /dev/null +++ b/app/helpers/oauth/applications_helper.rb @@ -0,0 +1,2 @@ +module Oauth::ApplicationsHelper +end diff --git a/app/models/user.rb b/app/models/user.rb index 038ff21c6..b17eabcc4 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -5,4 +5,6 @@ class User < ActiveRecord::Base accepts_nested_attributes_for :account validates :account, presence: true + + has_many :oauth_applications, class_name: 'Doorkeeper::Application', as: :owner end diff --git a/config/initializers/doorkeeper.rb b/config/initializers/doorkeeper.rb index 69a730cac..f84f12378 100644 --- a/config/initializers/doorkeeper.rb +++ b/config/initializers/doorkeeper.rb @@ -45,7 +45,7 @@ Doorkeeper.configure do # Optional parameter :confirmation => true (default false) if you want to enforce ownership of # a registered application # Note: you must also run the rails g doorkeeper:application_owner generator to provide the necessary support - # enable_application_owner :confirmation => false + enable_application_owner :confirmation => true # Define access token scopes for your provider # For more information go to diff --git a/config/routes.rb b/config/routes.rb index 7f8a66814..3dd6e3469 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,7 @@ Rails.application.routes.draw do - use_doorkeeper + use_doorkeeper do + controllers applications: 'oauth/applications' + end get '.well-known/host-meta', to: 'xrd#host_meta', as: :host_meta get '.well-known/webfinger', to: 'xrd#webfinger', as: :webfinger diff --git a/db/migrate/20160314164231_add_owner_to_application.rb b/db/migrate/20160314164231_add_owner_to_application.rb new file mode 100644 index 000000000..7d5e6d07d --- /dev/null +++ b/db/migrate/20160314164231_add_owner_to_application.rb @@ -0,0 +1,7 @@ +class AddOwnerToApplication < ActiveRecord::Migration + def change + add_column :oauth_applications, :owner_id, :integer, null: true + add_column :oauth_applications, :owner_type, :string, null: true + add_index :oauth_applications, [:owner_id, :owner_type] + end +end \ No newline at end of file diff --git a/db/schema.rb b/db/schema.rb index 9710bb965..a5e87024a 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20160312193225) do +ActiveRecord::Schema.define(version: 20160314164231) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -107,8 +107,11 @@ ActiveRecord::Schema.define(version: 20160312193225) do t.string "scopes", default: "", null: false t.datetime "created_at" t.datetime "updated_at" + t.integer "owner_id" + t.string "owner_type" end + add_index "oauth_applications", ["owner_id", "owner_type"], name: "index_oauth_applications_on_owner_id_and_owner_type", using: :btree add_index "oauth_applications", ["uid"], name: "index_oauth_applications_on_uid", unique: true, using: :btree create_table "statuses", force: :cascade do |t| diff --git a/spec/controllers/oauth/applications_controller_spec.rb b/spec/controllers/oauth/applications_controller_spec.rb new file mode 100644 index 000000000..7f2ca8cd9 --- /dev/null +++ b/spec/controllers/oauth/applications_controller_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Oauth::ApplicationsController, type: :controller do + +end diff --git a/spec/helpers/oauth/applications_helper_spec.rb b/spec/helpers/oauth/applications_helper_spec.rb new file mode 100644 index 000000000..bb0b7b3f6 --- /dev/null +++ b/spec/helpers/oauth/applications_helper_spec.rb @@ -0,0 +1,15 @@ +require 'rails_helper' + +# Specs in this file have access to a helper object that includes +# the Oauth::ApplicationsHelper. For example: +# +# describe Oauth::ApplicationsHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# expect(helper.concat_strings("this","that")).to eq("this that") +# end +# end +# end +RSpec.describe Oauth::ApplicationsHelper, type: :helper do + pending "add some examples to (or delete) #{__FILE__}" +end |