diff --git a/app/models/authorization.rb b/app/models/authorization.rb new file mode 100644 index 0000000000000000000000000000000000000000..157b4f77a1a53781a167aeed38ccd341a835df3c --- /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 f40816b323248f3b3fbe1b333d950c748ca8cf4a..5ac6b9e635465169b34b7ef0eb7d2921bd6a33d2 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 0000000000000000000000000000000000000000..a586fe631983227791cee7e3e0b42751f678291f --- /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 d466c71cacf21110212d0bbbb40ca9a86af38452..da4aea70d4eb5001693cfa7e5cb9ca0444715860 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 1ab98f71ab84b862783a2041369b7e9625c2534b..6c98eeb73d691bd1eac40cdefc2bdd7159fbcc23 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 0000000000000000000000000000000000000000..572bdc83c5070892045f05e141db5e90d5f3d4c1 --- /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 0000000000000000000000000000000000000000..8d2c51c0282a67ed4cc7ca37937b1b1bbed0f456 --- /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 0000000000000000000000000000000000000000..c91e50d1161324e05563991c2c7883a20c3d3d48 --- /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 0000000000000000000000000000000000000000..b0416e5e835bc6bd2333d9fbe909b04d8cf5e37e --- /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