Add scopes and authorization models
This commit is contained in:
parent
88d02ea35b
commit
059933f076
9 changed files with 54 additions and 0 deletions
7
app/models/authorization.rb
Normal file
7
app/models/authorization.rb
Normal 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
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
class OAuthApplication < ActiveRecord::Base
|
class OAuthApplication < ActiveRecord::Base
|
||||||
belongs_to :user
|
belongs_to :user
|
||||||
|
|
||||||
|
has_many :authorizations
|
||||||
|
|
||||||
validates :client_id, presence: true, uniqueness: true
|
validates :client_id, presence: true, uniqueness: true
|
||||||
validates :client_secret, presence: true
|
validates :client_secret, presence: true
|
||||||
|
|
||||||
|
|
|
||||||
8
app/models/scope.rb
Normal file
8
app/models/scope.rb
Normal 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
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
class Token < ActiveRecord::Base
|
class Token < ActiveRecord::Base
|
||||||
belongs_to :user
|
belongs_to :user
|
||||||
|
has_and_belongs_to_many :scopes
|
||||||
|
|
||||||
before_validation :setup, on: :create
|
before_validation :setup, on: :create
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -77,6 +77,7 @@ class User < ActiveRecord::Base
|
||||||
has_many :reports
|
has_many :reports
|
||||||
|
|
||||||
has_many :o_auth_applications
|
has_many :o_auth_applications
|
||||||
|
has_many :authorizations
|
||||||
has_many :tokens
|
has_many :tokens
|
||||||
|
|
||||||
before_save :guard_unconfirmed_email,
|
before_save :guard_unconfirmed_email,
|
||||||
|
|
|
||||||
10
db/migrate/20150708153926_create_authorizations.rb
Normal file
10
db/migrate/20150708153926_create_authorizations.rb
Normal 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
|
||||||
9
db/migrate/20150708154727_create_scope.rb
Normal file
9
db/migrate/20150708154727_create_scope.rb
Normal 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
|
||||||
|
|
@ -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
|
||||||
|
|
@ -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
|
||||||
Loading…
Reference in a new issue