public/js/main.js in conjur-asset-ui-api-1.1.1 vs public/js/main.js in conjur-asset-ui-api-1.2.0

- old
+ new

@@ -1,20 +1,25 @@ /** * @jsx React.DOM */ var namespace = NamespaceModel(); +function errback(err) { + console.log("error:", err); +} + var kind = ""; var lists = { "groups": new ResourceListModel("group"), "layers": new ResourceListModel("layer"), "variables": new VariableListModel(), "policies": new PolicyListModel(), "users": new UserListModel(), "hosts": new ResourceListModel("host") }; var conjurConfiguration; +var userId; var components = {}; var router; var globalIds; var endpoints; var flash = null; @@ -46,10 +51,11 @@ } return null; } conjurConfiguration = JSON.parse(decodeURIComponent(readCookie('conjur_configuration')).replace(/\+/g, ' ')); + userId = decodeURIComponent(readCookie('conjur_userid')); function createEndpoints(){ endpoints = {}; function genericEndpoint(path){ return function(){ @@ -111,29 +117,29 @@ ); component.setState({currentNamespace: namespace.currentNamespace, members: list.members(namespace.currentNamespace)}); }); } - function activateRecord(id, componentFunction) { - /* console.log("Record", kind, " :", id); */ + function activateRecord(k, id, componentFunction) { + /* console.log("Record", k, " :", id); */ + + $('#inlineSearchContainer').show(); + kind = pluralize(k); setActiveNav(kind); - new RecordModel(kind, id).fetch(function(record) { - /* console.log(record.object); */ + + var model; + if ( Record[_.capitalize(k)] ) + model = new Record[_.capitalize(k)](id); + else + model = new Record.Generic(kind, id); - function doRenderComponent(component) { - React.renderComponent( - component, - document.getElementById('content') - ); - } - - var component = componentFunction(record.object, function(result) { - doRenderComponent(result); - }); - if ( component ) { - doRenderComponent(component); - } + model.fetch(function(record) { + var component = componentFunction(record); + React.renderComponent( + component, + document.getElementById('content') + ); }, function(status, text, xhr){ if(status == 403){ window.flash = "You are not authorized to view " + kind + ":" + id + "."; window.history.back() }else{ @@ -174,13 +180,11 @@ document.getElementById('content') ); }, user: function(user){ - $('#inlineSearchContainer').show(); - kind = "users"; - activateRecord(user, function(record, callback){ + activateRecord("user", user, function(record){ return <User data={record}/>; }); }, users: function() { @@ -190,20 +194,12 @@ return <UserBox data={{namespaces: list.namespaces}} />; }); }, group: function(group) { - $('#inlineSearchContainer').show(); - kind = "groups"; - activateRecord(group, function(record, callback) { - $.ajax({ - url: "/api/authz/" + conjurConfiguration.account + "/roles/group/" + record.id + "?members", - success: function(result) { - callback(<Group data={{group: record, members: result}} />); - }, - error: error - }); + activateRecord("group", group, function(record) { + return <Group data={record} />; }); }, groups: function() { $('#inlineSearchContainer').show(); @@ -212,13 +208,13 @@ return <GroupBox data={{namespaces: list.namespaces}} />; }); }, host: function(host){ - $('#inlineSearchContainer').show(); - kind = "hosts"; - activateRecord(host, function(record){ return <Host data={record}/>;}); + activateRecord("host", host, function(record) { + return <Host data={record}/>; + }); }, hosts: function() { $('#inlineSearchContainer').show(); kind = "hosts"; @@ -226,28 +222,12 @@ return <HostBox data={{namespaces: list.namespaces}} />; }); }, layer: function(layer) { - $('#inlineSearchContainer').show(); - kind = "layers"; - activateRecord(layer, function(record, callback) { - var id = record.id.split(':')[2]; - async.map(['@/layer/' + record.id + '/use_host', '@/layer/' + record.id + '/admin_host' ], - function(role, cb) { - $.ajax({ - url: "/api/authz/" + conjurConfiguration.account + "/roles/" + role + "?members", - success: function(result) { cb(null, result) }, - error: cb - }); - }, - function(err, results) { - if ( err ) - error(err); - else - callback(<Layer data={{layer: record, users: _.pluck(results[0], 'member'), admins: _.pluck(results[1], 'member')}} />); - }); + activateRecord("layer", layer, function(record) { + return <Layer data={record} />; }); }, layers: function() { $('#inlineSearchContainer').show(); @@ -256,28 +236,11 @@ return <LayerBox data={{namespaces: list.namespaces}} /> }); }, variable: function(variable) { - $('#inlineSearchContainer').show(); - kind = "variables"; - activateRecord(variable, function(record, callback) { - async.map(['execute', 'update'], function(privilege, cb) { - $.ajax({ - url: "/api/authz/" + conjurConfiguration.account + "/roles/allowed_to/" + privilege + "/variable/" + record.id, - success: function(result) { - cb(null, result); - }, - error: cb - }); - }, - function(err, results) { - if ( err ) return error(err); - - var updaters = results[1]; - var fetchers = _.difference(results[0], updaters); - callback(<Variable data={{variable: record, fetchers: fetchers, updaters: updaters}} />); - }); + activateRecord("variable", variable, function(record) { + return <Variable data={record} />; }); }, variables: function() { $('#inlineSearchContainer').show();