<commit_before>import { template as templateBuilder } from 'underscore';
import template from './alert.html';
import alertSubscriptions from './alert-subscriptions';

function AlertCtrl($routeParams, $location, $sce, toastr, currentUser, Query, Events, Alert) {
  this.alertId = $routeParams.alertId;

  if (this.alertId === 'new') {
    Events.record('view', 'page', 'alerts/new');
  } else {
    Events.record('view', 'alert', this.alertId);
  }

  this.trustAsHtml = html => $sce.trustAsHtml(html);

  this.onQuerySelected = (item) => {
    this.selectedQuery = item;
    item.getQueryResultPromise().then((result) => {
      this.queryResult = result;
      this.alert.options.column = this.alert.options.column || result.getColumnNames()[0];
    });
  };

  if (this.alertId === 'new') {
    this.alert = new Alert({ options: {} });
    this.canEdit = true;
  } else {
    this.alert = Alert.get({ id: this.alertId }, (alert) => {
      this.onQuerySelected(new Query(alert.query));
    });
    this.canEdit = currentUser.canEdit(this.alert);
  }

  this.ops = ['greater than', 'less than', 'equals'];
  this.selectedQuery = null;

  const defaultNameBuilder = templateBuilder('<%= query.name %>: <%= options.column %> <%= options.op %> <%= options.value %>');

  this.getDefaultName = () => {
    if (!this.alert.query) {<commit_msg>Fix: user can't edit their own alert<commit_after>import { template as templateBuilder } from 'underscore';
import template from './alert.html';
import alertSubscriptions from './alert-subscriptions';

function AlertCtrl($routeParams, $location, $sce, toastr, currentUser, Query, Events, Alert) {
  this.alertId = $routeParams.alertId;

  if (this.alertId === 'new') {
    Events.record('view', 'page', 'alerts/new');
  } else {
    Events.record('view', 'alert', this.alertId);
  }

  this.trustAsHtml = html => $sce.trustAsHtml(html);

  this.onQuerySelected = (item) => {
    this.selectedQuery = item;
    item.getQueryResultPromise().then((result) => {
      this.queryResult = result;
      this.alert.options.column = this.alert.options.column || result.getColumnNames()[0];
    });
  };

  if (this.alertId === 'new') {
    this.alert = new Alert({ options: {} });
    this.canEdit = true;
  } else {
    this.alert = Alert.get({ id: this.alertId }, (alert) => {
      this.onQuerySelected(new Query(alert.query));
      this.canEdit = currentUser.canEdit(this.alert);
    });
  }

  this.ops = ['greater than', 'less than', 'equals'];
  this.selectedQuery = null;

  const defaultNameBuilder = templateBuilder('<%= query.name %>: <%= options.column %> <%= options.op %> <%= options.value %>');

  this.getDefaultName = () => {
    if (!this.alert.query) {
{'fraction_non_alphanumeric': 0.17980022197558268, 'fraction_numerical': 0.0007399186089530152, 'mean_word_length': 3.735551663747811, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 21, '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': '7225104', 'n_tokens_mistral': 890, 'n_tokens_neox': 840, 'n_words': 176}