<commit_before>App.Controllers.Policies = {

  initialize: function () {
    page("/policies",
      this.loadPolicies.bind(this),
      this.overview.bind(this)
    );

    page("/policies/new",
      this.loadPolicy.bind(this),
      this.loadServiceProviders.bind(this),
      this.loadAllowedAttributes.bind(this),
      this.detail.bind(this)
    );

    page("/policies/:id",
      this.loadPolicy.bind(this),
      this.loadServiceProviders.bind(this),
      this.loadAllowedAttributes.bind(this),
      this.detail.bind(this)
    );

    page("/policies/:id/revisions",
      this.loadRevisions.bind(this),
      this.revisions.bind(this)
    );
  },

  overview: function (ctx) {
    App.render(App.Pages.PolicyOverview({key: "policies", policies: ctx.policies}));
  },

  loadPolicies: function (ctx, next) {
    $.get(App.apiUrl("/policies"), function (data) {
      ctx.policies = data.payload;
      next();
    });
  },

  loadPolicy: function (ctx, next) {
    var url = ctx.params.id ?
      App.apiUrl("/policies/:id", {id: ctx.params.id}) : App.apiUrl("/policies/new");
    $.get(url, function (data) {
      ctx.policy = data.payload;
      next();
    });
  },

  loadServiceProviders: function (ctx, next) {
    $.get(App.apiUrl("/services"), function (data) {
      ctx.serviceProviders = data.payload;
      next();
    });
  },

  loadIdentityProviders: function (ctx, next) {
    $.get(App.apiUrl(""), function (data) {
      ctx.identityProviders = data.payload;
      next();
    });
  },

  loadAllowedAttributes: function (ctx, next) {
    $.get(App.apiUrl("/policies/attributes"), function (data) {
      ctx.allowedAttributes = data.payload;
      next();
    });
  },

  detail: function (ctx) {
    App.render(App.Pages.PolicyDetail({
      key: "policies",
      policy: ctx.policy,
      identityProviders: App.currentUser.institutionIdps,
      serviceProviders: ctx.serviceProviders,
      allowedAttributes: ctx.allowedAttributes
    }));
  },

  saveOrUpdatePolicy: function (policy, failureCallback) {
    var type = policy.id ? "PUT" : "POST";
    var json = JSON.stringify(policy);
    var action = policy.id ? I18n.t("policies.flash_updated") : I18n.t("policies.flash_created");
    var jqxhr = $.ajax({
      url: App.apiUrl("/policies"),
      type: type,
      data: json
    }).done(function () {
      //App.setFlash(I18n.t("policies.flash", {policyName: policy.name, action:action}));
      page("/policies");
    }).fail(function () {
      failureCallback(jqxhr);
    });
  },

  deletePolicy: function (policy) {
    $.ajax({
      url: App.apiUrl("/policies/:id", {id: policy.id}),
      type: 'DELETE'
    }).done(function () {
      //App.setFlash(I18n.t("policies.flash", {policyName: policy.name, action: I18n.t("policies.flash_deleted")}));
      page("/policies");
    });
  },

  loadRevisions: function (ctx, next) {
    var url = App.apiUrl("/policies/:id/revisions", {id: ctx.params.id});
    $.get(url, function (data) {
      ctx.revisions = data.payload;
      next();
    });
  },

  revisions: function (ctx) {
    App.render(App.Pages.PolicyRevisions({
      key: "policies",
      revisions: ctx.revisions
    }));
  }

};
<commit_msg>Disable policies pages when policies is not available<commit_after>App.Controllers.Policies = {

  initialize: function () {
    if (!App.policiesAvailable) {
      return;
    }

    page("/policies",
      this.loadPolicies.bind(this),
      this.overview.bind(this)
    );

    page("/policies/new",
      this.loadPolicy.bind(this),
      this.loadServiceProviders.bind(this),
      this.loadAllowedAttributes.bind(this),
      this.detail.bind(this)
    );

    page("/policies/:id",
      this.loadPolicy.bind(this),
      this.loadServiceProviders.bind(this),
      this.loadAllowedAttributes.bind(this),
      this.detail.bind(this)
    );

    page("/policies/:id/revisions",
      this.loadRevisions.bind(this),
      this.revisions.bind(this)
    );
  },

  overview: function (ctx) {
    App.render(App.Pages.PolicyOverview({key: "policies", policies: ctx.policies}));
  },

  loadPolicies: function (ctx, next) {
    $.get(App.apiUrl("/policies"), function (data) {
      ctx.policies = data.payload;
      next();
    });
  },

  loadPolicy: function (ctx, next) {
    var url = ctx.params.id ?
      App.apiUrl("/policies/:id", {id: ctx.params.id}) : App.apiUrl("/policies/new");
    $.get(url, function (data) {
      ctx.policy = data.payload;
      next();
    });
  },

  loadServiceProviders: function (ctx, next) {
    $.get(App.apiUrl("/services"), function (data) {
      ctx.serviceProviders = data.payload;
      next();
    });
  },

  loadIdentityProviders: function (ctx, next) {
    $.get(App.apiUrl(""), function (data) {
      ctx.identityProviders = data.payload;
      next();
    });
  },

  loadAllowedAttributes: function (ctx, next) {
    $.get(App.apiUrl("/policies/attributes"), function (data) {
      ctx.allowedAttributes = data.payload;
      next();
    });
  },

  detail: function (ctx) {
    App.render(App.Pages.PolicyDetail({
      key: "policies",
      policy: ctx.policy,
      identityProviders: App.currentUser.institutionIdps,
      serviceProviders: ctx.serviceProviders,
      allowedAttributes: ctx.allowedAttributes
    }));
  },

  saveOrUpdatePolicy: function (policy, failureCallback) {
    var type = policy.id ? "PUT" : "POST";
    var json = JSON.stringify(policy);
    var action = policy.id ? I18n.t("policies.flash_updated") : I18n.t("policies.flash_created");
    var jqxhr = $.ajax({
      url: App.apiUrl("/policies"),
      type: type,
      data: json
    }).done(function () {
      //App.setFlash(I18n.t("policies.flash", {policyName: policy.name, action:action}));
      page("/policies");
    }).fail(function () {
      failureCallback(jqxhr);
    });
  },

  deletePolicy: function (policy) {
    $.ajax({
      url: App.apiUrl("/policies/:id", {id: policy.id}),
      type: 'DELETE'
    }).done(function () {
      //App.setFlash(I18n.t("policies.flash", {policyName: policy.name, action: I18n.t("policies.flash_deleted")}));
      page("/policies");
    });
  },

  loadRevisions: function (ctx, next) {
    var url = App.apiUrl("/policies/:id/revisions", {id: ctx.params.id});
    $.get(url, function (data) {
      ctx.revisions = data.payload;
      next();
    });
  },

  revisions: function (ctx) {
    App.render(App.Pages.PolicyRevisions({
      key: "policies",
      revisions: ctx.revisions
    }));
  }

};

{'fraction_non_alphanumeric': 0.17325134511913912, 'fraction_numerical': 0.0030745580322828594, 'mean_word_length': 2.83834808259587, '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': '6640174', 'n_tokens_mistral': 2181, 'n_tokens_neox': 2192, 'n_words': 352}