From 24a9e10c4cc2fc26cc647c4188834b1e6fc8bcb7 Mon Sep 17 00:00:00 2001 From: Sebastian Gierlinger Date: Tue, 18 Aug 2015 15:05:25 +0200 Subject: [PATCH] Add table columns for OAuth closes #4174 - added trusted domains - removed unique constraint from secret --- core/server/data/schema.js | 10 ++++++++-- core/server/models/client-trusted-domain.js | 17 +++++++++++++++++ core/server/models/client.js | 5 ++++- core/test/unit/migration_spec.js | 2 +- 4 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 core/server/models/client-trusted-domain.js diff --git a/core/server/data/schema.js b/core/server/data/schema.js index c7b653e6e3a..301cf098f08 100644 --- a/core/server/data/schema.js +++ b/core/server/data/schema.js @@ -161,17 +161,23 @@ var db = { uuid: {type: 'string', maxlength: 36, nullable: false}, name: {type: 'string', maxlength: 150, nullable: false, unique: true}, slug: {type: 'string', maxlength: 150, nullable: false, unique: true}, - secret: {type: 'string', maxlength: 150, nullable: false, unique: true}, + secret: {type: 'string', maxlength: 150, nullable: false}, redirection_uri: {type: 'string', maxlength: 2000, nullable: true}, logo: {type: 'string', maxlength: 2000, nullable: true}, status: {type: 'string', maxlength: 150, nullable: false, defaultTo: 'development'}, - type: {type: 'string', maxlength: 150, nullable: false, defaultTo: 'Client-Side'}, + type: {type: 'string', maxlength: 150, nullable: false, defaultTo: 'ua'}, description: {type: 'string', maxlength: 200, nullable: true}, created_at: {type: 'dateTime', nullable: false}, created_by: {type: 'integer', nullable: false}, updated_at: {type: 'dateTime', nullable: true}, updated_by: {type: 'integer', nullable: true} }, + client_trusted_domains: { + id: {type: 'increments', nullable: false, primary: true}, + uuid: {type: 'string', maxlength: 36, nullable: false}, + client_id: {type: 'integer', nullable: false, unsigned: true, references: 'clients.id'}, + trusted_domain: {type: 'string', maxlength: 2000, nullable: true} + }, accesstokens: { id: {type: 'increments', nullable: false, primary: true}, token: {type: 'string', nullable: false, unique: true}, diff --git a/core/server/models/client-trusted-domain.js b/core/server/models/client-trusted-domain.js new file mode 100644 index 00000000000..f851b257036 --- /dev/null +++ b/core/server/models/client-trusted-domain.js @@ -0,0 +1,17 @@ +var ghostBookshelf = require('./base'), + + ClientTrustedDomain, + ClientTrustedDomains; + +ClientTrustedDomain = ghostBookshelf.Model.extend({ + tableName: 'client_trusted_domains' +}); + +ClientTrustedDomains = ghostBookshelf.Collection.extend({ + model: ClientTrustedDomain +}); + +module.exports = { + ClientTrustedDomain: ghostBookshelf.model('ClientTrustedDomain', ClientTrustedDomain), + ClientTrustedDomains: ghostBookshelf.collection('ClientTrustedDomains', ClientTrustedDomains) +}; diff --git a/core/server/models/client.js b/core/server/models/client.js index ac880d803b9..e35e28378f6 100644 --- a/core/server/models/client.js +++ b/core/server/models/client.js @@ -4,7 +4,10 @@ var ghostBookshelf = require('./base'), Clients; Client = ghostBookshelf.Model.extend({ - tableName: 'clients' + tableName: 'clients', + trustedDomains: function trustedDomains() { + return this.hasMany('ClientTrustedDomain', 'client_id'); + } }); Clients = ghostBookshelf.Collection.extend({ diff --git a/core/test/unit/migration_spec.js b/core/test/unit/migration_spec.js index 5b6b396e322..6e36879984e 100644 --- a/core/test/unit/migration_spec.js +++ b/core/test/unit/migration_spec.js @@ -20,7 +20,7 @@ describe('Migrations', function () { describe('DB version integrity', function () { // Only these variables should need updating var currentDbVersion = '004', - currentSchemaHash = 'a27a018a8aef272fd298b33552c2446b', + currentSchemaHash = '45d72a3c103e36d9cde9f723a71287af', currentPermissionsHash = '42e486732270cda623fc5efc04808c0c'; // If this test is failing, then it is likely a change has been made that requires a DB version bump,