Add ownerId for apps

This tracks who installed the app.
This commit is contained in:
Girish Ramakrishnan
2018-05-13 21:02:57 -07:00
parent 38977858aa
commit dfa318e898
16 changed files with 171 additions and 62 deletions
+9 -6
View File
@@ -104,7 +104,8 @@ describe('Apps', function () {
accessRestriction: null,
memoryLimit: 0,
robotsTxt: null,
sso: false
sso: false,
ownerId: USER_0.id
};
var APP_1 = {
@@ -118,7 +119,8 @@ describe('Apps', function () {
},
portBindings: {},
accessRestriction: { users: [ 'someuser' ], groups: [ GROUP_0.id ] },
memoryLimit: 0
memoryLimit: 0,
ownerId: USER_0.id
};
var APP_2 = {
@@ -134,7 +136,8 @@ describe('Apps', function () {
accessRestriction: { users: [ 'someuser', USER_0.id ], groups: [ GROUP_1.id ] },
memoryLimit: 0,
robotsTxt: null,
sso: false
sso: false,
ownerId: USER_0.id
};
before(function (done) {
@@ -156,9 +159,9 @@ describe('Apps', function () {
groupdb.add.bind(null, GROUP_1.id, GROUP_1.name, [ /* roles */ ]),
groups.addMember.bind(null, constants.ADMIN_GROUP_ID, ADMIN_0.id),
groups.addMember.bind(null, GROUP_0.id, USER_1.id),
appdb.add.bind(null, APP_0.id, APP_0.appStoreId, APP_0.manifest, APP_0.location, APP_0.domain, APP_0.portBindings, APP_0),
appdb.add.bind(null, APP_1.id, APP_1.appStoreId, APP_1.manifest, APP_1.location, APP_1.domain, APP_1.portBindings, APP_1),
appdb.add.bind(null, APP_2.id, APP_2.appStoreId, APP_2.manifest, APP_2.location, APP_2.domain, APP_2.portBindings, APP_2),
appdb.add.bind(null, APP_0.id, APP_0.appStoreId, APP_0.manifest, APP_0.location, APP_0.domain, APP_0.ownerId, APP_0.portBindings, APP_0),
appdb.add.bind(null, APP_1.id, APP_1.appStoreId, APP_1.manifest, APP_1.location, APP_1.domain, APP_1.ownerId, APP_1.portBindings, APP_1),
appdb.add.bind(null, APP_2.id, APP_2.appStoreId, APP_2.manifest, APP_2.location, APP_2.domain, APP_2.ownerId, APP_2.portBindings, APP_2),
settingsdb.set.bind(null, settings.BACKUP_CONFIG_KEY, JSON.stringify({ provider: 'caas', token: 'BACKUP_TOKEN', bucket: 'Bucket', prefix: 'Prefix' }))
], done);
});
+18 -2
View File
@@ -19,6 +19,7 @@ var addons = require('../addons.js'),
nock = require('nock'),
paths = require('../paths.js'),
settings = require('../settings.js'),
userdb = require('../userdb.js'),
_ = require('underscore');
var MANIFEST = {
@@ -61,6 +62,19 @@ const DOMAIN_0 = {
tlsConfig: { provider: 'caas' }
};
var ADMIN = {
id: 'admin123',
username: 'admin123',
password: 'secret',
email: 'admin@me.com',
fallbackEmail: 'admin@me.com',
salt: 'morton',
createdAt: 'sometime back',
modifiedAt: 'now',
resetToken: '',
displayName: ''
};
var APP = {
id: 'appid',
appStoreId: 'appStoreId',
@@ -75,7 +89,8 @@ var APP = {
portBindings: null,
accessRestriction: null,
dnsRecordId: 'someDnsRecordId',
memoryLimit: 0
memoryLimit: 0,
ownerId: ADMIN.id
};
var awsHostedZones;
@@ -105,7 +120,8 @@ describe('apptask', function () {
database.initialize,
database._clear,
domains.add.bind(null, DOMAIN_0.domain, DOMAIN_0.zoneName, DOMAIN_0.provider, DOMAIN_0.config, null, DOMAIN_0.tlsConfig),
appdb.add.bind(null, APP.id, APP.appStoreId, APP.manifest, APP.location, APP.domain, APP.portBindings, APP),
userdb.add.bind(null, ADMIN.id, ADMIN),
appdb.add.bind(null, APP.id, APP.appStoreId, APP.manifest, APP.location, APP.domain, APP.ownerId, APP.portBindings, APP),
settings.initialize
], done);
});
+23 -9
View File
@@ -116,6 +116,14 @@ describe('database', function () {
});
describe('domains', function () {
before(function (done) {
userdb.add(USER_0.id, USER_0, done);
});
after(function (done) {
database._clear(done);
});
it('can add domain', function (done) {
domaindb.add(DOMAIN_0.domain, { zoneName: DOMAIN_0.zoneName, provider: DOMAIN_0.provider, config: DOMAIN_0.config, tlsConfig: DOMAIN_0.tlsConfig }, done);
});
@@ -223,11 +231,12 @@ describe('database', function () {
sso: true,
debugMode: null,
robotsTxt: null,
enableBackup: true
enableBackup: true,
ownerId: USER_0.id
};
it('cannot delete referenced domain', function (done) {
appdb.add(APP_0.id, APP_0.appStoreId, APP_0.manifest, APP_0.location, APP_0.domain, APP_0.portBindings, APP_0, function (error) {
appdb.add(APP_0.id, APP_0.appStoreId, APP_0.manifest, APP_0.location, APP_0.domain, APP_0.ownerId, APP_0.portBindings, APP_0, function (error) {
expect(error).to.be(null);
domaindb.del(DOMAIN_0.domain, function (error) {
@@ -713,7 +722,7 @@ describe('database', function () {
});
});
describe('app', function () {
describe('apps', function () {
var APP_0 = {
id: 'appid-0',
appStoreId: 'appStoreId-0',
@@ -737,7 +746,8 @@ describe('database', function () {
sso: true,
debugMode: null,
robotsTxt: null,
enableBackup: true
enableBackup: true,
ownerId: USER_0.id
};
var APP_1 = {
@@ -763,11 +773,15 @@ describe('database', function () {
sso: true,
debugMode: null,
robotsTxt: null,
enableBackup: true
enableBackup: true,
ownerId: USER_0.id
};
before(function (done) {
domaindb.add(DOMAIN_0.domain, { zoneName: DOMAIN_0.zoneName, provider: DOMAIN_0.provider, config: DOMAIN_0.config, tlsConfig: DOMAIN_0.tlsConfig }, done);
async.series([
userdb.add.bind(null, USER_0.id, USER_0),
domaindb.add.bind(null, DOMAIN_0.domain, { zoneName: DOMAIN_0.zoneName, provider: DOMAIN_0.provider, config: DOMAIN_0.config, tlsConfig: DOMAIN_0.tlsConfig })
], done);
});
after(function (done) {
@@ -788,7 +802,7 @@ describe('database', function () {
});
it('add succeeds', function (done) {
appdb.add(APP_0.id, APP_0.appStoreId, APP_0.manifest, APP_0.location, APP_0.domain, APP_0.portBindings, APP_0, function (error) {
appdb.add(APP_0.id, APP_0.appStoreId, APP_0.manifest, APP_0.location, APP_0.domain, APP_0.ownerId, APP_0.portBindings, APP_0, function (error) {
expect(error).to.be(null);
done();
});
@@ -812,7 +826,7 @@ describe('database', function () {
});
it('add of same app fails', function (done) {
appdb.add(APP_0.id, APP_0.appStoreId, APP_0.manifest, APP_0.location, APP_0.domain, [], APP_0, function (error) {
appdb.add(APP_0.id, APP_0.appStoreId, APP_0.manifest, APP_0.location, APP_0.domain, APP_0.ownerId, [], APP_0, function (error) {
expect(error).to.be.a(DatabaseError);
expect(error.reason).to.be(DatabaseError.ALREADY_EXISTS);
done();
@@ -884,7 +898,7 @@ describe('database', function () {
});
it('add second app succeeds', function (done) {
appdb.add(APP_1.id, APP_1.appStoreId, APP_1.manifest, APP_1.location, APP_1.domain, [], APP_1, function (error) {
appdb.add(APP_1.id, APP_1.appStoreId, APP_1.manifest, APP_1.location, APP_1.domain, APP_0.ownerId, [], APP_1, function (error) {
expect(error).to.be(null);
done();
});
+11 -11
View File
@@ -78,7 +78,8 @@ var APP_0 = {
accessRestriction: null,
restoreConfig: null,
oldConfig: null,
memoryLimit: 4294967296
memoryLimit: 4294967296,
ownerId: null
};
var dockerProxy;
@@ -99,21 +100,20 @@ function setup(done) {
ldapServer.start.bind(null),
domains.add.bind(null, DOMAIN_0.domain, DOMAIN_0.zoneName, DOMAIN_0.provider, DOMAIN_0.config, DOMAIN_0.fallbackCertificate, DOMAIN_0.tlsConfig),
maildb.add.bind(null, DOMAIN_0.domain),
appdb.add.bind(null, APP_0.id, APP_0.appStoreId, APP_0.manifest, APP_0.location, APP_0.domain, APP_0.portBindings, APP_0),
function (callback) {
users.createOwner(USER_0.username, USER_0.password, USER_0.email, USER_0.displayName, AUDIT_SOURCE, function (error, result) {
if (error) return callback(error);
USER_0.id = APP_0.ownerId = result.id;
appdb.add(APP_0.id, APP_0.appStoreId, APP_0.manifest, APP_0.location, APP_0.domain, APP_0.ownerId, APP_0.portBindings, APP_0, callback);
});
},
appdb.update.bind(null, APP_0.id, { containerId: APP_0.containerId }),
appdb.setAddonConfig.bind(null, APP_0.id, 'sendmail', [{ name: 'MAIL_SMTP_PASSWORD', value : 'sendmailpassword' }]),
appdb.setAddonConfig.bind(null, APP_0.id, 'recvmail', [{ name: 'MAIL_IMAP_PASSWORD', value : 'recvmailpassword' }]),
mailboxdb.addMailbox.bind(null, APP_0.location + '.app', APP_0.domain, APP_0.id, mailboxdb.OWNER_TYPE_APP),
function (callback) {
users.createOwner(USER_0.username, USER_0.password, USER_0.email, USER_0.displayName, AUDIT_SOURCE, function (error, result) {
if (error) return callback(error);
USER_0.id = result.id;
callback(null);
});
},
function (callback) {
users.create(USER_1.username, USER_1.password, USER_1.email, USER_0.displayName, { invitor: USER_0 }, AUDIT_SOURCE, function (error, result) {
if (error) return callback(error);
+30 -9
View File
@@ -278,7 +278,8 @@ describe('updatechecker - app - manual (email)', function () {
portBindings: { PORT: 5678 },
healthy: null,
accessRestriction: null,
memoryLimit: 0
memoryLimit: 0,
ownerId: null
};
before(function (done) {
@@ -294,8 +295,14 @@ describe('updatechecker - app - manual (email)', function () {
domains.add.bind(null, DOMAIN_0.domain, DOMAIN_0.zoneName, DOMAIN_0.provider, DOMAIN_0.config, DOMAIN_0.fallbackCertificate, DOMAIN_0.tlsConfig),
mail.addDomain.bind(null, DOMAIN_0.domain),
mailer._clearMailQueue,
appdb.add.bind(null, APP_0.id, APP_0.appStoreId, APP_0.manifest, APP_0.location, APP_0.domain, APP_0.portBindings, APP_0),
users.createOwner.bind(null, USER_0.username, USER_0.password, USER_0.email, USER_0.displayName, AUDIT_SOURCE),
function (next) {
users.createOwner(USER_0.username, USER_0.password, USER_0.email, USER_0.displayName, AUDIT_SOURCE, function (error, userObject) {
if (error) return next(error);
APP_0.ownerId = userObject.id;
appdb.add(APP_0.id, APP_0.appStoreId, APP_0.manifest, APP_0.location, APP_0.domain, APP_0.ownerId, APP_0.portBindings, APP_0, next);
});
},
settings.setAppAutoupdatePattern.bind(null, constants.AUTOUPDATE_PATTERN_NEVER),
settingsdb.set.bind(null, settings.APPSTORE_CONFIG_KEY, JSON.stringify({ userId: 'uid', cloudronId: 'cid', token: 'token' }))
], done);
@@ -394,7 +401,8 @@ describe('updatechecker - app - automatic (no email)', function () {
portBindings: { PORT: 5678 },
healthy: null,
accessRestriction: null,
memoryLimit: 0
memoryLimit: 0,
ownerId: null
};
before(function (done) {
@@ -410,8 +418,14 @@ describe('updatechecker - app - automatic (no email)', function () {
domains.add.bind(null, DOMAIN_0.domain, DOMAIN_0.zoneName, DOMAIN_0.provider, DOMAIN_0.config, DOMAIN_0.fallbackCertificate, DOMAIN_0.tlsConfig),
mail.addDomain.bind(null, DOMAIN_0.domain),
mailer._clearMailQueue,
appdb.add.bind(null, APP_0.id, APP_0.appStoreId, APP_0.manifest, APP_0.location, APP_0.domain, APP_0.portBindings, APP_0),
users.createOwner.bind(null, USER_0.username, USER_0.password, USER_0.email, USER_0.displayName, AUDIT_SOURCE),
function (next) {
users.createOwner(USER_0.username, USER_0.password, USER_0.email, USER_0.displayName, AUDIT_SOURCE, function (error, userObject) {
if (error) return next(error);
APP_0.ownerId = userObject.id;
appdb.add(APP_0.id, APP_0.appStoreId, APP_0.manifest, APP_0.location, APP_0.domain, APP_0.ownerId, APP_0.portBindings, APP_0, next);
});
},
settings.setAppAutoupdatePattern.bind(null, '00 00 1,3,5,23 * * *'),
settingsdb.set.bind(null, settings.APPSTORE_CONFIG_KEY, JSON.stringify({ userId: 'uid', cloudronId: 'cid', token: 'token' }))
], done);
@@ -460,7 +474,8 @@ describe('updatechecker - app - automatic free (email)', function () {
portBindings: { PORT: 5678 },
healthy: null,
accessRestriction: null,
memoryLimit: 0
memoryLimit: 0,
ownerId: null
};
before(function (done) {
@@ -476,8 +491,14 @@ describe('updatechecker - app - automatic free (email)', function () {
domains.add.bind(null, DOMAIN_0.domain, DOMAIN_0.zoneName, DOMAIN_0.provider, DOMAIN_0.config, DOMAIN_0.fallbackCertificate, DOMAIN_0.tlsConfig),
mail.addDomain.bind(null, DOMAIN_0.domain),
mailer._clearMailQueue,
appdb.add.bind(null, APP_0.id, APP_0.appStoreId, APP_0.manifest, APP_0.location, APP_0.domain, APP_0.portBindings, APP_0),
users.createOwner.bind(null, USER_0.username, USER_0.password, USER_0.email, USER_0.displayName, AUDIT_SOURCE),
function (next) {
users.createOwner(USER_0.username, USER_0.password, USER_0.email, USER_0.displayName, AUDIT_SOURCE, function (error, userObject) {
if (error) return next(error);
APP_0.ownerId = userObject.id;
appdb.add(APP_0.id, APP_0.appStoreId, APP_0.manifest, APP_0.location, APP_0.domain, APP_0.ownerId, APP_0.portBindings, APP_0, next);
});
},
settings.setAppAutoupdatePattern.bind(null, '00 00 1,3,5,23 * * *'),
settingsdb.set.bind(null, settings.APPSTORE_CONFIG_KEY, JSON.stringify({ userId: 'uid', cloudronId: 'cid', token: 'token' }))
], done);