diff --git a/app/models/o_auth_application.rb b/app/models/o_auth_application.rb index 11ed470c1adb8dfc8bc2ebee91a583daefb7a5a2..0d85e25a9d0972b13c1d4b9723c2007dbfb6d7b3 100644 --- a/app/models/o_auth_application.rb +++ b/app/models/o_auth_application.rb @@ -1,9 +1,7 @@ class OAuthApplication < ActiveRecord::Base belongs_to :user - validates :user_id, presence: true validates :client_id, presence: true, uniqueness: true validates :client_secret, presence: true - has_many :tokens end diff --git a/app/models/token.rb b/app/models/token.rb index 37849715a83b97e36d0ba291b149a9ae3d097207..d466c71cacf21110212d0bbbb40ca9a86af38452 100644 --- a/app/models/token.rb +++ b/app/models/token.rb @@ -1,5 +1,5 @@ class Token < ActiveRecord::Base - belongs_to :o_auth_application + belongs_to :user before_validation :setup, on: :create diff --git a/app/models/user.rb b/app/models/user.rb index 1a8ebf3f47aa3df7af5c557851f695ba23b4a668..1ab98f71ab84b862783a2041369b7e9625c2534b 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -77,6 +77,7 @@ class User < ActiveRecord::Base has_many :reports has_many :o_auth_applications + has_many :tokens before_save :guard_unconfirmed_email, :save_person! diff --git a/db/migrate/20150613202109_create_o_auth_applications.rb b/db/migrate/20150613202109_create_o_auth_applications.rb index b9309064ded74bdea93e760ef2b523032c8c90f1..8137f2b54552ecdfa7faf003bbd56820856af87c 100644 --- a/db/migrate/20150613202109_create_o_auth_applications.rb +++ b/db/migrate/20150613202109_create_o_auth_applications.rb @@ -4,6 +4,8 @@ class CreateOAuthApplications < ActiveRecord::Migration t.belongs_to :user, index: true t.string :client_id t.string :client_secret + t.string :name + t.string :redirect_uris t.timestamps null: false end diff --git a/db/migrate/20150614134031_create_tokens.rb b/db/migrate/20150614134031_create_tokens.rb index 9db140791c805103772a0c3d448284530c032126..5a5e292f42eebfe696c054208199ac1e22058034 100644 --- a/db/migrate/20150614134031_create_tokens.rb +++ b/db/migrate/20150614134031_create_tokens.rb @@ -1,9 +1,10 @@ class CreateTokens < ActiveRecord::Migration def self.up create_table :tokens do |t| - t.belongs_to :o_auth_application, index: true + t.belongs_to :user, index: true t.string :token t.datetime :expires_at + t.timestamps null: false end end diff --git a/db/schema.rb b/db/schema.rb index 7b36511f80e7c1372163b526f68885eb8f046ad3..27ab1e24ce1438fa056b2fc168f3d4bce0d00290 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -240,6 +240,8 @@ ActiveRecord::Schema.define(version: 20151003142048) do t.integer "user_id", limit: 4 t.string "client_id", limit: 255 t.string "client_secret", limit: 255 + t.string "name", limit: 255 + t.string "redirect_uris", limit: 255 t.datetime "created_at", null: false t.datetime "updated_at", null: false end @@ -539,14 +541,14 @@ ActiveRecord::Schema.define(version: 20151003142048) do add_index "tags", ["name"], name: "index_tags_on_name", unique: true, length: {"name"=>191}, using: :btree create_table "tokens", force: :cascade do |t| - t.integer "o_auth_application_id", limit: 4 - t.string "token", limit: 255 + t.integer "user_id", limit: 4 + t.string "token", limit: 255 t.datetime "expires_at" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end - add_index "tokens", ["o_auth_application_id"], name: "index_tokens_on_o_auth_application_id", using: :btree + add_index "tokens", ["user_id"], name: "index_tokens_on_user_id", using: :btree create_table "user_preferences", force: :cascade do |t| t.string "email_type", limit: 255