diff --git a/app/models/authorization.rb b/app/models/authorization.rb new file mode 100644 index 000000000..157b4f77a --- /dev/null +++ b/app/models/authorization.rb @@ -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 diff --git a/app/models/o_auth_application.rb b/app/models/o_auth_application.rb index f40816b32..5ac6b9e63 100644 --- a/app/models/o_auth_application.rb +++ b/app/models/o_auth_application.rb @@ -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 diff --git a/app/models/scope.rb b/app/models/scope.rb new file mode 100644 index 000000000..a586fe631 --- /dev/null +++ b/app/models/scope.rb @@ -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 diff --git a/app/models/token.rb b/app/models/token.rb index d466c71ca..da4aea70d 100644 --- a/app/models/token.rb +++ b/app/models/token.rb @@ -1,5 +1,6 @@ class Token < ActiveRecord::Base belongs_to :user + has_and_belongs_to_many :scopes before_validation :setup, on: :create diff --git a/app/models/user.rb b/app/models/user.rb index 1ab98f71a..6c98eeb73 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 :authorizations has_many :tokens before_save :guard_unconfirmed_email, diff --git a/db/migrate/20150708153926_create_authorizations.rb b/db/migrate/20150708153926_create_authorizations.rb new file mode 100644 index 000000000..572bdc83c --- /dev/null +++ b/db/migrate/20150708153926_create_authorizations.rb @@ -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 diff --git a/db/migrate/20150708154727_create_scope.rb b/db/migrate/20150708154727_create_scope.rb new file mode 100644 index 000000000..8d2c51c02 --- /dev/null +++ b/db/migrate/20150708154727_create_scope.rb @@ -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 diff --git a/db/migrate/20150708155202_create_authorizations_scopes_join_table.rb b/db/migrate/20150708155202_create_authorizations_scopes_join_table.rb new file mode 100644 index 000000000..c91e50d11 --- /dev/null +++ b/db/migrate/20150708155202_create_authorizations_scopes_join_table.rb @@ -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 diff --git a/db/migrate/20150708155747_create_scopes_tokens_join_table.rb b/db/migrate/20150708155747_create_scopes_tokens_join_table.rb new file mode 100644 index 000000000..b0416e5e8 --- /dev/null +++ b/db/migrate/20150708155747_create_scopes_tokens_join_table.rb @@ -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