<commit_before>module GobiertoPeople
  class PeopleController < GobiertoPeople::ApplicationController

    include PoliticalGroupsHelper
    include PreviewTokenHelper
    include PeopleClassificationHelper
    include DatesRangeHelper

    before_action :check_active_submodules, except: :show

    LAST_ITEMS_SIZE = 4

    def index
      @political_groups = get_political_groups

      set_people
      set_events
      set_present_groups

      respond_to do |format|
        format.html
        format.js
        format.json { render json: @people }
        format.csv  { render csv: GobiertoExports::CSVRenderer.new(@people).to_csv, filename: 'people' }
      end
    end

    def show

      if valid_preview_token?
        redirect_to(
          gobierto_people_root_path,
          alert: t('gobierto_admin.admin_unauthorized')
        ) and return if !admin_permissions_for_person?

        people_scope = current_site.people
      else
        people_scope = current_site.people.active
      end

      @person = PersonDecorator.new(people_scope.find_by!(slug: params[:slug]))

      if active_submodules.size == 1 && agendas_submodule_active?
        redirect_to gobierto_people_person_events_path(@person.slug)
      end

      @upcoming_events = @person.attending_events.upcoming.sorted.first(3)
      @latest_activity = ActivityCollectionDecorator.new(Activity.for_recipient(@person).limit(30).sorted.page(params[:page]))

      # custom engine
      @last_events = @person.attending_events.with_interest_group.sorted_backwards.limit(LAST_ITEMS_SIZE)
      @last_trips = @person.trips.sorted.limit(LAST_ITEMS_SIZE)
      @last_invitations = @person.invitations.sorted.limit(LAST_ITEMS_SIZE)
      @last_gifts = @person.received_gifts.sorted.limit(LAST_ITEMS_SIZE)
    end

    private

    def check_active_submodules
      if !officials_submodule_active?
        redirect_to gobierto_people_root_path
      end
    end

    def set_people
      @people = current_site.people.active.sorted
      @people = @people.send(Person.categories.key(@person_category)) if @person_category
      @people = @people.send(Person.parties.key(@person_party)) if @person_party<commit_msg>Include filters by date on people_controller show action<commit_after>module GobiertoPeople
  class PeopleController < GobiertoPeople::ApplicationController

    include PoliticalGroupsHelper
    include PreviewTokenHelper
    include PeopleClassificationHelper
    include DatesRangeHelper

    before_action :check_active_submodules, except: :show

    LAST_ITEMS_SIZE = 4

    def index
      @political_groups = get_political_groups

      set_people
      set_events
      set_present_groups

      respond_to do |format|
        format.html
        format.js
        format.json { render json: @people }
        format.csv  { render csv: GobiertoExports::CSVRenderer.new(@people).to_csv, filename: 'people' }
      end
    end

    def show

      if valid_preview_token?
        redirect_to(
          gobierto_people_root_path,
          alert: t('gobierto_admin.admin_unauthorized')
        ) and return if !admin_permissions_for_person?

        people_scope = current_site.people
      else
        people_scope = current_site.people.active
      end

      @person = PersonDecorator.new(people_scope.find_by!(slug: params[:slug]))

      if active_submodules.size == 1 && agendas_submodule_active?
        redirect_to gobierto_people_person_events_path(@person.slug)
      end

      @upcoming_events = @person.attending_events.upcoming.sorted.first(3)
      @latest_activity = ActivityCollectionDecorator.new(Activity.for_recipient(@person).limit(30).sorted.page(params[:page]))

      # custom engine
      @last_events = QueryWithEvents.new(source: @person.attending_events.with_interest_group.sorted_backwards.limit(LAST_ITEMS_SIZE),
                                         start_date: filter_start_date,
                                         end_date: filter_end_date)
      @last_trips = @person.trips.between_dates(filter_start_date, filter_end_date).sorted.limit(LAST_ITEMS_SIZE)
      @last_invitations = @person.invitations.between_dates(filter_start_date, filter_end_date).sorted.limit(LAST_ITEMS_SIZE)
      @last_gifts = @person.received_gifts.between_dates(filter_start_date, filter_end_date).sorted.limit(LAST_ITEMS_SIZE)
    end

    private

    def check_active_submodules
      if !officials_submodule_active?
        redirect_to gobierto_people_root_path
      end
    end

    def set_people
      @people = current_site.people.active.sorted
      @people = @people.send(Person.categories.key(@person_category)) if @person_category
      @people = @people.send(Person.parties.key(@person_party)) if @person_party
{'fraction_non_alphanumeric': 0.07601351351351351, 'fraction_numerical': 0.0021114864864864866, 'mean_word_length': 3.353860294117647, '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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1557771', 'n_tokens_mistral': 1438, 'n_tokens_neox': 1395, 'n_words': 228}