Add scopes and authorization models

This commit is contained in:
theworldbright 2015-09-13 14:17:02 -07:00
parent 88d02ea35b
commit 059933f076
9 changed files with 54 additions and 0 deletions

View file

@ -0,0 +1,7 @@
class Authorization < ActiveRecord::Base
belongs_to :user
belongs_to :o_auth_application
has_and_belongs_to_many :scopes
# TODO: Incomplete class
end

View file

@ -1,6 +1,8 @@
class OAuthApplication < ActiveRecord::Base
belongs_to :user
has_many :authorizations
validates :client_id, presence: true, uniqueness: true
validates :client_secret, presence: true

8
app/models/scope.rb Normal file
View file

@ -0,0 +1,8 @@
class Scope < ActiveRecord::Base
has_and_belongs_to_many :tokens
has_and_belongs_to_many :authorizations
validates :name, presence: true, uniqueness: true
# TODO: Incomplete class
end

View file

@ -1,5 +1,6 @@
class Token < ActiveRecord::Base
belongs_to :user
has_and_belongs_to_many :scopes
before_validation :setup, on: :create

View file

@ -77,6 +77,7 @@ class User < ActiveRecord::Base
has_many :reports
has_many :o_auth_applications
has_many :authorizations
has_many :tokens
before_save :guard_unconfirmed_email,

View file

@ -0,0 +1,10 @@
class CreateAuthorizations < ActiveRecord::Migration
def change
create_table :authorizations do |t|
t.belongs_to :user, index: true
t.belongs_to :o_auth_application, index: true
t.timestamps null: false
end
end
end

View file

@ -0,0 +1,9 @@
class CreateScope < ActiveRecord::Migration
def change
create_table :scopes do |t|
t.string :name
t.timestamps null: false
end
end
end

View file

@ -0,0 +1,8 @@
class CreateAuthorizationsScopesJoinTable < ActiveRecord::Migration
def change
create_table :authorizations_scopes, id: false do |t|
t.belongs_to :authorization, index: true
t.belongs_to :scope, index: true
end
end
end

View file

@ -0,0 +1,8 @@
class CreateScopesTokensJoinTable < ActiveRecord::Migration
def change
create_table :scopes_tokens, id: false do |t|
t.belongs_to :scope, index: true
t.belongs_to :token, index: true
end
end
end