<commit_before>var _ = require('underscore');

/**
 * type property should match the value given from the API.
 */
var ALL_OPTIONS = [{
  privacy: 'PUBLIC',
  title: _t('components.modals.publish.privacy.public.title'),
  desc: _t('components.modals.publish.privacy.public.body'),
  cssClass: 'is-green'
}, {
  privacy: 'LINK',
  title: _t('components.modals.publish.privacy.link.title'),
  desc: _t('components.modals.publish.privacy.link.body'),
  cssClass: 'is-orange'
}, {
  privacy: 'PASSWORD',
  title: _t('components.modals.publish.privacy.password.title'),
  desc: _t('components.modals.publish.privacy.password.body'),
  cssClass: 'is-orange-dark'
}, {
  privacy: 'PRIVATE',
  title: _t('components.modals.publish.privacy.private.title'),
  desc: _t('components.modals.publish.privacy.private.body'),
  cssClass: 'is-red'
}];

module.exports = function (visDefinitionModel, userModel) {
  var isVisualization = visDefinitionModel.isVisualization();
  var actions = userModel.get('actions');
  var canSelectPremiumOptions = actions[ isVisualization ? 'private_maps' : 'private_tables' ];
  var currentPrivacy = visDefinitionModel.get('privacy');
  var availableOptions = visDefinitionModel.privacyOptions();

  return _.chain(ALL_OPTIONS)
    .filter(function (option) {
      return _.contains(availableOptions, option.privacy);
    })
    .map(function (option) {
      // Set state that depends on vis and user attrs, they should not vary during the lifecycle of this collection
      return _.defaults({
        selected: option.privacy === currentPrivacy,
        disabled: !(option.alwaysEnable || canSelectPremiumOptions)
      }, option);
    })
    .value();
};<commit_msg>Fixed problem mapping privacy options by user and vis type<commit_after>var _ = require('underscore');

/**
 * type property should match the value given from the API.
 */
var ALL_OPTIONS = [{
  privacy: 'PUBLIC',
  title: _t('components.modals.publish.privacy.public.title'),
  desc: _t('components.modals.publish.privacy.public.body'),
  alwaysEnabled: true,
  cssClass: 'is-green'
}, {
  privacy: 'LINK',
  title: _t('components.modals.publish.privacy.link.title'),
  desc: _t('components.modals.publish.privacy.link.body'),
  cssClass: 'is-orange'
}, {
  privacy: 'PASSWORD',
  title: _t('components.modals.publish.privacy.password.title'),
  desc: _t('components.modals.publish.privacy.password.body'),
  cssClass: 'is-orange-dark'
}, {
  privacy: 'PRIVATE',
  title: _t('components.modals.publish.privacy.private.title'),
  desc: _t('components.modals.publish.privacy.private.body'),
  cssClass: 'is-red'
}];

module.exports = function (visDefinitionModel, userModel) {
  var isVisualization = visDefinitionModel.isVisualization();
  var actions = userModel.get('actions');
  var canSelectPremiumOptions = actions[ isVisualization ? 'private_maps' : 'private_tables' ];
  var currentPrivacy = visDefinitionModel.get('privacy');
  var availableOptions = visDefinitionModel.privacyOptions();

  return _.chain(ALL_OPTIONS)
    .filter(function (option) {
      return _.contains(availableOptions, option.privacy);
    })
    .map(function (option) {
      // Set state that depends on vis and user attrs, they should not vary during the lifecycle of this collection
      return _.defaults({
        selected: option.privacy === currentPrivacy,
        disabled: !(option.alwaysEnabled || canSelectPremiumOptions)
      }, option);
    })
    .value();
};
{'fraction_non_alphanumeric': 0.14207016526529428, 'fraction_numerical': 0.0, 'mean_word_length': 4.4245283018867925, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '986459', 'n_tokens_mistral': 1065, 'n_tokens_neox': 1062, 'n_words': 223}