Skip to content

Commit

Permalink
feat: remove 'account' column from 'Users' table
Browse files Browse the repository at this point in the history
  • Loading branch information
vhpoet committed Jan 6, 2017
1 parent a31687e commit 35b7377
Show file tree
Hide file tree
Showing 12 changed files with 17 additions and 59 deletions.
2 changes: 0 additions & 2 deletions api/src/controllers/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ function AuthControllerFactory(User, log, ledger, mailer) {
* HTTP/1.1 200 OK
* {
* "username": "alice",
* "account": "https://wallet.example/ledger/accounts/alice",
* "name": "Alice Faye",
* "balance": "1000",
* "id": 1
Expand Down Expand Up @@ -101,7 +100,6 @@ function AuthControllerFactory(User, log, ledger, mailer) {
* HTTP/1.1 200 OK
* {
* "username": "alice",
* "account": "https://wallet.example/ledger/accounts/alice",
* "name": "Alice Faye",
* "balance": "1000",
* "id": 1
Expand Down
1 change: 0 additions & 1 deletion api/src/controllers/misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ function MiscControllerFactory (Auth, log, config, ledger, utils) {
* {
* {
* "type": "local",
* "accountUri": "http://wallet.example/ledger/accounts/alice",
* "ledgerUri": "http://wallet.example/ledger",
* "paymentUri": "http://wallet.example/api/receivers/alice",
* "ilpAddress": "wallet.alice",
Expand Down
2 changes: 1 addition & 1 deletion api/src/controllers/payments.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ function PaymentsControllerFactory (Auth, Payment, log, ledger, config, utils, s
* @apiDescription Make payment
*
* @apiParam {String} id generated payment uuid
* @apiParam {String} destination destination account
* @apiParam {String} destination destination
* @apiParam {String} sourceAmount source amount
* @apiParam {String} destinationAmount destination amount
* @apiParam {String} message text message for the destination
Expand Down
6 changes: 0 additions & 6 deletions api/src/controllers/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ function UsersControllerFactory(auth, User, Invite, log, ledger, socket, config,
* HTTP/1.1 200 OK
* {
* "username": "alice",
* "account": "https://wallet.example/ledger/accounts/alice",
* "name": "Alice Faye",
* "balance": "1000",
* "id": 1
Expand Down Expand Up @@ -117,7 +116,6 @@ function UsersControllerFactory(auth, User, Invite, log, ledger, socket, config,
* HTTP/1.1 201 OK
* {
* "username": "alice",
* "account": "https://wallet.example/ledger/accounts/alice",
* "balance": "1000",
* "id": 1
* }
Expand Down Expand Up @@ -212,8 +210,6 @@ function UsersControllerFactory(auth, User, Invite, log, ledger, socket, config,
throw new UsernameTakenError('Ledger rejected username')
}

userObj.account = ledgerUser.id

// Create the db user
dbUser = new User()
dbUser.setDataExternal(userObj)
Expand Down Expand Up @@ -292,7 +288,6 @@ function UsersControllerFactory(auth, User, Invite, log, ledger, socket, config,
* HTTP/1.1 200 OK
* {
* "username": "alice",
* "account": "https://wallet.example/ledger/accounts/alice",
* "name": "Alice Faye",
* "balance": "1000",
* "id": 1
Expand Down Expand Up @@ -399,7 +394,6 @@ function UsersControllerFactory(auth, User, Invite, log, ledger, socket, config,
* HTTP/1.1 200 OK
* {
* "username": "alice",
* "account": "https://wallet.example/ledger/accounts/alice",
* "balance": "1000",
* "id": 1,
* "email_verified": true
Expand Down
8 changes: 0 additions & 8 deletions api/src/controllers/webfinger.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,6 @@ function WebfingerControllerFactory(log, config, ledger) {
* "href": "https://wallet.example/socket.io"
* },
* {
* "rel": "https://interledger.org/rel/ledgerAccount",
* "href": "https://wallet.example/ledger/accounts/alice"
* },
* {
* "rel": "https://interledger.org/rel/sender/payment",
* "href": "https://wallet.example/payments"
* },
Expand Down Expand Up @@ -117,10 +113,6 @@ function WebfingerControllerFactory(log, config, ledger) {
'rel': 'https://interledger.org/rel/ilpAddress',
'href': config.data.getIn(['ledger', 'prefix']) + ledgerUser.name
},
{
'rel': 'https://interledger.org/rel/ledgerAccount',
'href': config.data.getIn(['ledger', 'public_uri']) + '/accounts/' + ledgerUser.name
},
{
'rel': 'https://interledger.org/rel/sender/payment',
'href': config.data.getIn(['server', 'base_uri']) + '/payments'
Expand Down
2 changes: 1 addition & 1 deletion api/src/lib/connector.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ module.exports = class Conncetor {

const publicKey = hostInfo.publicKey

const token = getToken(this.config.get('secret'), hostInfo.publicKey)
const token = getToken(this.config.get('secret'), publicKey)
const ledgerName = 'peer.' + token.substring(0, 5) + '.' + peer.currency.toLowerCase() + '.'

yield connector.addPlugin(ledgerName, {
Expand Down
29 changes: 4 additions & 25 deletions api/src/lib/utils.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use strict"

const _ = require('lodash')
const url = require("url")
const url = require('url')
const WebFinger = require('webfinger.js')
const superagent = require('superagent-promise')(require('superagent'), Promise)

Expand All @@ -21,14 +21,6 @@ module.exports = class Utils {
this.localHost = config.data.getIn(['server', 'base_host'])
}

isAccountUri(destination) {
return destination.indexOf('http://') > -1 || destination.indexOf('https://') > -1
}

isForeignAccountUri(destination) {
return this.isAccountUri(destination) && destination.indexOf(this.ledgerUriPublic) === -1
}

* getAccount(accountUri) {
let response

Expand All @@ -50,13 +42,6 @@ module.exports = class Utils {
* getWebfingerAccount(address) {
const parsed = url.parse(address)

// This dirty hack will stay here until there's a resolution to
// https://github.com/silverbucket/webfinger.js/issues/18
if (parsed.protocol === 'http:' || parsed.protocol === 'https:') {
const username = parsed.path.match(/([^\/]*)\/*$/)[1]
address = username + '@' + parsed.hostname
}

const webfinger = new WebFinger({
webfist_fallback: false,
tls_only: true,
Expand Down Expand Up @@ -84,7 +69,6 @@ module.exports = class Utils {
}

return {
accountUri: _.filter(response.links, {rel: 'https://interledger.org/rel/ledgerAccount'})[0].href,
ledgerUri: _.filter(response.links, {rel: 'https://interledger.org/rel/ledgerUri'})[0].href,
paymentUri: _.filter(response.links, {rel: 'https://interledger.org/rel/receiver'})[0].href,
ilpAddress: _.filter(response.links, {rel: 'https://interledger.org/rel/ilpAddress'})[0].href
Expand All @@ -95,47 +79,42 @@ module.exports = class Utils {
* TODO better docs
*
* options
* - destination - string
* - destination - string (username or webfinger)
*/
* parseDestination(options) {
const self = this

const destination = options.destination

let accountUri
let ledgerUri
let paymentUri
let ilpAddress

// Webfinger lookup
if (self.isWebfinger(destination) || self.isForeignAccountUri(destination)) {
if (self.isWebfinger(destination)) {
// TODO use debug module
console.log('webfinger account')
const account = yield self.getWebfingerAccount(destination)

accountUri = account.accountUri
ledgerUri = account.ledgerUri
paymentUri = account.paymentUri
ilpAddress = account.ilpAddress
}

// Local account
else {
accountUri = self.isAccountUri(destination) ? destination : self.ledgerUriPublic + '/accounts/' + destination
ledgerUri = self.ledgerUriPublic
paymentUri = self.localUri + '/receivers/' + destination
ilpAddress = self.ledgerPrefix + destination

// Check if account exists
yield self.getAccount(accountUri)
yield self.getAccount(self.ledgerUriPublic + '/accounts/' + destination)
}

// Get SPSP receiver info
const receiver = yield self.getAccount(paymentUri)

return {
type: this.isForeignAccountUri(accountUri) ? 'foreign' : 'local',
accountUri: accountUri,
ledgerUri: ledgerUri,
paymentUri: paymentUri,
ilpAddress: ilpAddress,
Expand Down
10 changes: 10 additions & 0 deletions api/src/migrations/20170106-account.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const Sequelize = require('sequelize')

module.exports = {
up: (sequelize) => {
return sequelize.queryInterface.removeColumn('Users', 'account')
},
down: (sequelize) => {
return sequelize.queryInterface.addColumn('Users', 'account', Sequelize.STRING)
}
}
6 changes: 0 additions & 6 deletions api/src/models/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ function UserFactory (sequelize, validator, ledger, config, utils) {
dbUser = new this()

dbUser.username = username
dbUser.account = config.data.get(['ledger', 'public_uri']) + '/accounts/' + username

dbUser = this.fromDatabaseModel(yield dbUser.save())

Expand Down Expand Up @@ -121,7 +120,6 @@ function UserFactory (sequelize, validator, ledger, config, utils) {
dbUser = new this()

dbUser.username = username
dbUser.account = config.data.get(['ledger', 'public_uri']) + '/accounts/' + username

dbUser = this.fromDatabaseModel(yield dbUser.save())

Expand Down Expand Up @@ -235,10 +233,6 @@ function UserFactory (sequelize, validator, ledger, config, utils) {
type: Sequelize.STRING,
unique: true
},
account: {
type: Sequelize.STRING,
unique: true
},
email: {
type: Sequelize.STRING,
unique: true
Expand Down
5 changes: 1 addition & 4 deletions api/test/data/api.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"accounts": {
"admin": {
"id": 1,
"account": "http://localhost/accounts/admin",
"name": null,
"username": "admin",
"balance": 0,
Expand All @@ -13,7 +12,6 @@
},
"alice": {
"id": 1,
"account": "http://localhost/accounts/alice",
"name": null,
"username": "alice",
"balance": 1000,
Expand All @@ -24,7 +22,6 @@
},
"bob": {
"id": 1,
"account": "http://localhost/accounts/bob",
"name": null,
"username": "bob",
"balance": 1000,
Expand All @@ -34,4 +31,4 @@
"email_verified": null
}
}
}
}
4 changes: 0 additions & 4 deletions api/test/data/webfinger.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@
"rel": "https://interledger.org/rel/ilpAddress",
"href": "localhost.alice"
},
{
"rel": "https://interledger.org/rel/ledgerAccount",
"href": "http://localhost/ledger/accounts/alice"
},
{
"rel" : "https://interledger.org/rel/sender/payment",
"href" : "http://localhost/api/payments"
Expand Down
1 change: 0 additions & 1 deletion api/test/users.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ describe('Users', () => {
.expect({
id: 1,
username: 'alice',
account: 'http://localhost/accounts/alice',
name: null,
email: 'alice@example.com',
email_verified: null,
Expand Down

0 comments on commit 35b7377

Please sign in to comment.