<commit_before>var postScript = require('./postScript');


function getTypes2(dat, callback) {

    var types = {};
    //console.log("yea");
    dat.forEach(function (obj) {
       if (null === obj){
          return;
       }
       types[obj["@reference"]] = obj
       types[obj["@id"]]        = obj
    });
    callback(types);
}


var extractMembers = function(type){
   var arr = []
   for(c in type['@context']){
      var entry = type['@context'][c];
      arr.push(entry['@property_name'])
   }

   return arr;
}


/*======================*/
/* get permissions page */
/*======================*/
module.exports = function(cmd_args) {

   return function (req, res, next) {

      //ID - name match for proper view
      var headi = {
         "Authorization": req.session.token
      };

      var path = "/api/v1/app_permissions_latest/" + req.session.api_key;

      postScript("GET", {}, path, headi, function (app_perms) {

         var app_perms = app_perms.result[0]
         req.session.appPerms = app_perms;

         if (undefined == app_perms) {
            res.status(500).send('OPENi Internal error: permission not set for this app.');
         }
         else if (req.session.appPerms.hasOwnProperty("permissions")) {

            var testAppPermJson = req.session.appPerms.permissions;
            //prepare html string based on manifest
            var app_perms = '';
            var showjson = {};
            var level = {}
            //USE getTypes for BASE 64

            if (req.session.appPerms.hasOwnProperty("types")) {

               getTypes2(req.session.appPerms.types, function (typesById) {


                  testAppPermJson.forEach(function (obj) {

                     //console.log("permissions.js", "obj", obj);
                     //console.log("permissions.js", "obj.ref", obj.ref);
                     //console.log("permissions.js", "typesById[obj.ref]", typesById[obj.ref]);

                     var type = typesById[obj.ref];

                     //console.log("permissions.js", type);

                     if (typeof showjson[type['@reference']] == 'undefined') {
                        showjson[type['@reference']] = [];
                     }
                     showjson[type['@reference']].push(obj.access_type);
                     if (undefined === level[type['@reference']] || level[type['@reference']] === 'APP') {
                        level[type['@reference']] = obj.access_level
                     }
                  });

                  for (var key in showjson) {
                     app_perms += ('<div class="contA">' +<commit_msg>Bug fix, stop null object from crashing the system<commit_after>var postScript = require('./postScript');


function getTypes2(dat, callback) {

    var types = {};
    //console.log("yea");
    dat.forEach(function (obj) {
       if (null === obj){
          return;
       }
       types[obj["@reference"]] = obj
       types[obj["@id"]]        = obj
    });
    callback(types);
}


var extractMembers = function(type){
   var arr = []
   for(c in type['@context']){
      var entry = type['@context'][c];
      arr.push(entry['@property_name'])
   }

   return arr;
}


/*======================*/
/* get permissions page */
/*======================*/
module.exports = function(cmd_args) {

   return function (req, res, next) {

      //ID - name match for proper view
      var headi = {
         "Authorization": req.session.token
      };

      var path = "/api/v1/app_permissions_latest/" + req.session.api_key;

      postScript("GET", {}, path, headi, function (app_perms) {

         var app_perms = app_perms.result[0]
         req.session.appPerms = app_perms;

         if (undefined == app_perms) {
            res.status(500).send('OPENi Internal error: permission not set for this app.');
         }
         else if (req.session.appPerms.hasOwnProperty("permissions")) {

            var testAppPermJson = req.session.appPerms.permissions;
            //prepare html string based on manifest
            var app_perms = '';
            var showjson = {};
            var level = {}
            //USE getTypes for BASE 64

            if (req.session.appPerms.hasOwnProperty("types")) {

               getTypes2(req.session.appPerms.types, function (typesById) {


                  testAppPermJson.forEach(function (obj) {

                     //console.log("permissions.js", "obj", obj);
                     //console.log("permissions.js", "obj.ref", obj.ref);
                     //console.log("permissions.js", "typesById[obj.ref]", typesById[obj.ref]);

                     var type = typesById[obj.ref];

                     if (undefined === type){
                        return;
                     }

                     //console.log("permissions.js", type);

                     if (typeof showjson[type['@reference']] == 'undefined') {
                        showjson[type['@reference']] = [];
                     }
                     showjson[type['@reference']].push(obj.access_type);
                     if (undefined === level[type['@reference']] || level[type['@reference']] === 'APP') {
                        level[type['@reference']] = obj.access_level
                     }
                  });

                  for (var key in showjson) {
                     app_perms += ('<div class="contA">' +
{'fraction_non_alphanumeric': 0.16204651162790698, 'fraction_numerical': 0.0033488372093023254, 'mean_word_length': 1.7854922279792746, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4294234', 'n_tokens_mistral': 1547, 'n_tokens_neox': 1460, 'n_words': 302}