<commit_before>//--------------------------------------------------------------------------------------------------//
//--------------------------------------------- Filters --------------------------------------------//
//--------------------------------------------------------------------------------------------------//

Router._filters = {

  isReady: function () {
    if (!this.ready()) {
      // console.log('not ready')
      this.render(getTemplate('loading'));
    }else{
      this.next();
      // console.log('ready')
    }
  },

  clearSeenMessages: function () {
    clearSeenMessages();
    this.next();
  },

  resetScroll: function () {
    var scrollTo = window.currentScroll || 0;
    var $body = $('body');
    $body.scrollTop(scrollTo);
    $body.css("min-height", 0);
  },

  /*
  isLoggedIn: function () {
    if (!(Meteor.loggingIn() || Meteor.user())) {
      throwError(i18n.t('please_sign_in_first'));
      var current = getCurrentRoute();
      if (current){
        Session.set('fromWhere', current);
      }
      this.render('entrySignIn');
    } else {
      this.next();
    }
  },
  */
  isLoggedIn: AccountsTemplates.ensureSignedIn,

  isLoggedOut: function () {
    if(Meteor.user()){
      this.render('already_logged_in');
    } else {
      this.next();
    }
  },

  isAdmin: function () {
    if(!this.ready()) return;
    if(!isAdmin()){
      this.render(getTemplate('no_rights'));
    } else {
      this.next();
    }
  },

  canView: function () {
    if(!this.ready() || Meteor.loggingIn()){
      this.render(getTemplate('loading'));
    } else if (!can.view()) {
      this.render(getTemplate('no_rights'));
    } else {
      this.next();
    }
  },

  canViewPendingPosts: function () {
    var post = this.data();
    if (post.status == STATUS_PENDING && !can.viewPendingPosts()) {
      this.render(getTemplate('no_rights'));
    } else {
      this.next();
    }
  },

  canPost: function () {
    if(!this.ready() || Meteor.loggingIn()){
      this.render(getTemplate('loading'));
    } else if(!can.post()) {
      flashMessage(i18n.t("sorry_you_dont_have_permissions_to_add_new_items"), "error");
      this.render(getTemplate('no_rights'));
    } else {
      this.next();
    }
  },

  canEditPost: function () {
    if(!this.ready()) return;
    // Already subscribed to this post by route({waitOn: ...})
    var post = Posts.findOne(this.params._id);
    if(!can.currentUserEdit(post)){
      flashMessage(i18n.t("sorry_you_cannot_edit_this_post"), "error");
      this.render(getTemplate('no_rights'));<commit_msg>make sure post is defined<commit_after>//--------------------------------------------------------------------------------------------------//
//--------------------------------------------- Filters --------------------------------------------//
//--------------------------------------------------------------------------------------------------//

Router._filters = {

  isReady: function () {
    if (!this.ready()) {
      // console.log('not ready')
      this.render(getTemplate('loading'));
    }else{
      this.next();
      // console.log('ready')
    }
  },

  clearSeenMessages: function () {
    clearSeenMessages();
    this.next();
  },

  resetScroll: function () {
    var scrollTo = window.currentScroll || 0;
    var $body = $('body');
    $body.scrollTop(scrollTo);
    $body.css("min-height", 0);
  },

  /*
  isLoggedIn: function () {
    if (!(Meteor.loggingIn() || Meteor.user())) {
      throwError(i18n.t('please_sign_in_first'));
      var current = getCurrentRoute();
      if (current){
        Session.set('fromWhere', current);
      }
      this.render('entrySignIn');
    } else {
      this.next();
    }
  },
  */
  isLoggedIn: AccountsTemplates.ensureSignedIn,

  isLoggedOut: function () {
    if(Meteor.user()){
      this.render('already_logged_in');
    } else {
      this.next();
    }
  },

  isAdmin: function () {
    if(!this.ready()) return;
    if(!isAdmin()){
      this.render(getTemplate('no_rights'));
    } else {
      this.next();
    }
  },

  canView: function () {
    if(!this.ready() || Meteor.loggingIn()){
      this.render(getTemplate('loading'));
    } else if (!can.view()) {
      this.render(getTemplate('no_rights'));
    } else {
      this.next();
    }
  },

  canViewPendingPosts: function () {
    var post = this.data();
    if (!!post && post.status == STATUS_PENDING && !can.viewPendingPosts()) {
      this.render(getTemplate('no_rights'));
    } else {
      this.next();
    }
  },

  canPost: function () {
    if(!this.ready() || Meteor.loggingIn()){
      this.render(getTemplate('loading'));
    } else if(!can.post()) {
      flashMessage(i18n.t("sorry_you_dont_have_permissions_to_add_new_items"), "error");
      this.render(getTemplate('no_rights'));
    } else {
      this.next();
    }
  },

  canEditPost: function () {
    if(!this.ready()) return;
    // Already subscribed to this post by route({waitOn: ...})
    var post = Posts.findOne(this.params._id);
    if(!can.currentUserEdit(post)){
      flashMessage(i18n.t("sorry_you_cannot_edit_this_post"), "error");
      this.render(getTemplate('no_rights'));
{'fraction_non_alphanumeric': 0.2763411810111926, 'fraction_numerical': 0.0030876109610189118, 'mean_word_length': 1.865118850193477, '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': '314857', 'n_tokens_mistral': 1612, 'n_tokens_neox': 1551, 'n_words': 232}