Adapt clients.getAllWithDetailsByUserId() to new client types

This commit is contained in:
Johannes Zellner
2015-10-16 19:36:12 +02:00
parent c9f84f6259
commit a6a39cc4e6

View File

@@ -112,46 +112,29 @@ function getAllWithDetailsByUserId(userId, callback) {
if (error && error.reason === DatabaseError.NOT_FOUND) return callback(null, []); if (error && error.reason === DatabaseError.NOT_FOUND) return callback(null, []);
if (error) return callback(error); if (error) return callback(error);
// We have several types of records here
// 1) webadmin has an app id of 'webadmin'
// 2) oauth proxy records are always the app id prefixed with 'proxy-'
// 3) addon oauth records for apps prefixed with 'addon-'
// 4) external app records prefixed with 'external-'
// 5) normal apps on the cloudron without a prefix
var tmp = []; var tmp = [];
async.each(results, function (record, callback) { async.each(results, function (record, callback) {
if (record.appId === constants.ADMIN_CLIENT_ID) { if (record.type === clientdb.TYPE_ADMIN) {
record.name = constants.ADMIN_NAME; record.name = constants.ADMIN_NAME;
record.location = constants.ADMIN_LOCATION; record.location = constants.ADMIN_LOCATION;
record.type = 'webadmin';
tmp.push(record); tmp.push(record);
return callback(null); return callback(null);
} }
var appId = record.appId; appdb.get(record.appId, function (error, result) {
var type = 'app';
// Handle our different types of oauth clients
if (record.appId.indexOf('addon-') === 0) {
appId = record.appId.slice('addon-'.length);
type = 'addon';
} else if (record.appId.indexOf('proxy-') === 0) {
appId = record.appId.slice('proxy-'.length);
type = 'proxy';
}
appdb.get(appId, function (error, result) {
if (error) { if (error) {
console.error('Failed to get app details for oauth client', result, error); console.error('Failed to get app details for oauth client', result, error);
return callback(null); // ignore error so we continue listing clients return callback(null); // ignore error so we continue listing clients
} }
record.name = result.manifest.title + (record.appId.indexOf('proxy-') === 0 ? 'OAuth Proxy' : ''); if (record.type === clientdb.TYPE_PROXY) record.name = result.manifest.title + ' Website Proxy';
if (record.type === clientdb.TYPE_OAUTH) record.name = result.manifest.title + ' OAuth';
if (record.type === clientdb.TYPE_SIMPLE_AUTH) record.name = result.manifest.title + ' Simple Auth';
if (record.type === clientdb.TYPE_EXTERNAL) record.name = result.manifest.title + ' external';
record.location = result.location; record.location = result.location;
record.type = type;
tmp.push(record); tmp.push(record);