<commit_before>#encoding: utf-8
class GroupsController < ApplicationController
  include NotificationHelper, GroupsHelper

  layout :choose_layout

  before_filter :authenticate_user!, except: [:index, :show, :by_year_and_month]

  before_filter :load_group, except: [:index, :new, :create, :ask_for_multiple_follow]

  load_resource

  authorize_resource except: [:participation_request_confirm, :participation_request_decline]

  before_filter :admin_required, only: [:autocomplete]

  def autocomplete
    groups = Group.autocomplete(params[:term])
    groups = groups.map do |u|
      {id: u.id, identifier: "#{u.name}", image_path: "#{u.group_image_tag 20}"}
    end
    render json: groups
  end


  def index
    unless request.xhr?
      @tags = Tag.most_groups(10).shuffle
    end

    interest_border_key = params[:interest_border]
    if interest_border_key.to_s != ''
      ftype = interest_border_key[0, 1] #tipologia (primo carattere)
      fid = interest_border_key[2..-1] #chiave primaria (dal terzo all'ultimo carattere)
      @interest_border = InterestBorder.find_by_territory_type_and_territory_id(InterestBorder::I_TYPE_MAP[ftype], fid)
    end
    params[:interest_border_obj] = @interest_border

    @groups = Group.look(params)
    respond_to do |format|
      format.js
      format.html
    end
  end

  def show
    @group_posts = @group.post_publishings.accessible_by(current_ability).order('post_publishings.featured desc, blog_posts.published_at DESC')

    respond_to do |format|
      format.js {
        @group_posts = @group_posts.page(params[:page]).per(COMMENTS_PER_PAGE)
      }
      format.html {
        if request.url.split('?')[0] != group_url(@group)
          redirect_to group_url(@group), status: :moved_permanently
          return
        end
        @page_title = @group.name
        @group_participations = @group.participants
        @group_posts = @group_posts.page(params[:page]).per(COMMENTS_PER_PAGE)
        @archives = @group.blog_posts.select("COUNT(*) AS posts, extract(month from blog_posts.created_at) AS MONTH , extract(year from blog_posts.created_at) AS YEAR").group("MONTH, YEAR").order("YEAR desc, extract(month from blog_posts.created_at) desc")
      }
      format.atom
      format.json
    end
  end


  def by_year_and_month
    if current_user
      @group_posts = @group.post_publishings.viewable_by(current_user).order('post_publishings.featured desc, published_at DESC').select('post_publishings.*, published_at').uniq
    else
      @group_posts = @group.blog_posts.published.includes([:blog, {user: :image}, :tags]).order('post_publishings.featured desc, published_at DESC')
    end<commit_msg>fixed bug in redirect on groups page<commit_after>#encoding: utf-8
class GroupsController < ApplicationController
  include NotificationHelper, GroupsHelper

  layout :choose_layout

  before_filter :authenticate_user!, except: [:index, :show, :by_year_and_month]

  before_filter :load_group, except: [:index, :new, :create, :ask_for_multiple_follow]

  load_resource

  authorize_resource except: [:participation_request_confirm, :participation_request_decline]

  before_filter :admin_required, only: [:autocomplete]

  def autocomplete
    groups = Group.autocomplete(params[:term])
    groups = groups.map do |u|
      {id: u.id, identifier: "#{u.name}", image_path: "#{u.group_image_tag 20}"}
    end
    render json: groups
  end


  def index
    unless request.xhr?
      @tags = Tag.most_groups(10).shuffle
    end

    interest_border_key = params[:interest_border]
    if interest_border_key.to_s != ''
      ftype = interest_border_key[0, 1] #tipologia (primo carattere)
      fid = interest_border_key[2..-1] #chiave primaria (dal terzo all'ultimo carattere)
      @interest_border = InterestBorder.find_by_territory_type_and_territory_id(InterestBorder::I_TYPE_MAP[ftype], fid)
    end
    params[:interest_border_obj] = @interest_border

    @groups = Group.look(params)
    respond_to do |format|
      format.js
      format.html
    end
  end

  def show
    @group_posts = @group.post_publishings.accessible_by(current_ability).order('post_publishings.featured desc, blog_posts.published_at DESC')

    respond_to do |format|
      format.js {
        @group_posts = @group_posts.page(params[:page]).per(COMMENTS_PER_PAGE)
      }
      format.html {
        if request.url.split('?')[0] != group_url(@group).split('?')[0]
          redirect_to group_url(@group), status: :moved_permanently
          return
        end
        @page_title = @group.name
        @group_participations = @group.participants
        @group_posts = @group_posts.page(params[:page]).per(COMMENTS_PER_PAGE)
        @archives = @group.blog_posts.select("COUNT(*) AS posts, extract(month from blog_posts.created_at) AS MONTH , extract(year from blog_posts.created_at) AS YEAR").group("MONTH, YEAR").order("YEAR desc, extract(month from blog_posts.created_at) desc")
      }
      format.atom
      format.json
    end
  end


  def by_year_and_month
    if current_user
      @group_posts = @group.post_publishings.viewable_by(current_user).order('post_publishings.featured desc, published_at DESC').select('post_publishings.*, published_at').uniq
    else
      @group_posts = @group.blog_posts.published.includes([:blog, {user: :image}, :tags]).order('post_publishings.featured desc, published_at DESC')
    end
{'fraction_non_alphanumeric': 0.11076008176918788, 'fraction_numerical': 0.0039026203307935326, 'mean_word_length': 4.05827067669173, 'pattern_counts': {'":': 0, '<': 5, '<?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': '956790', 'n_tokens_mistral': 1786, 'n_tokens_neox': 1709, 'n_words': 335}