Sha256: 5c35dfc4ebe9e0cb4f9da9f212461c0d563ed1bb8cf533efd0afc75042c41474

Contents?: true

Size: 1.1 KB

Versions: 26

Compression:

Stored size: 1.1 KB

Contents

class WcmsComponents::PeopleController < ApplicationController

  skip_after_action :verify_authorized
  skip_after_action :verify_policy_scoped

  def index
    if can_search_people?
      if params[:q].present?
        @people = permitted_people.custom_search(params[:q]).asc(:first_name, :last_name).limit(10)
      else
        # If no query string is present, return all faculty for pre-cached data.
        @people = []
      end

      render json: @people.map{|p| {id: p.id.to_s, name: p.name, email: p.biola_email, affiliations: p.affiliations.to_a.join(', '), image: p.profile_photo_url} }.to_json
    else
      user_not_authorized
    end
  end


  private

  def permitted_people
    # Return all people who are either employees, faculty, or not private.
    Person.where({'$or' => [{affiliations: 'employee'}, {affiliations: 'faculty'}, {privacy: { '$ne' => true }}] })
  end

  def can_search_people?
    # For security reasons, this should only be available to employees and student workers
    current_user.admin? || current_user.has_role?(:employee) || current_user.has_role?(:student_worker)
  end

end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
biola_wcms_components-0.24.1 app/controllers/wcms_components/people_controller.rb
biola_wcms_components-0.24.0 app/controllers/wcms_components/people_controller.rb
biola_wcms_components-0.23.0 app/controllers/wcms_components/people_controller.rb
biola_wcms_components-0.22.0 app/controllers/wcms_components/people_controller.rb
biola_wcms_components-0.21.0 app/controllers/wcms_components/people_controller.rb
biola_wcms_components-0.20.0 app/controllers/wcms_components/people_controller.rb
biola_wcms_components-0.19.0 app/controllers/wcms_components/people_controller.rb
biola_wcms_components-0.18.1 app/controllers/wcms_components/people_controller.rb
biola_wcms_components-0.18.0 app/controllers/wcms_components/people_controller.rb
biola_wcms_components-0.17.0 app/controllers/wcms_components/people_controller.rb
biola_wcms_components-0.16.0 app/controllers/wcms_components/people_controller.rb
biola_wcms_components-0.15.3 app/controllers/wcms_components/people_controller.rb
biola_wcms_components-0.15.2 app/controllers/wcms_components/people_controller.rb
biola_wcms_components-0.15.1 app/controllers/wcms_components/people_controller.rb
biola_wcms_components-0.15.0 app/controllers/wcms_components/people_controller.rb
biola_wcms_components-0.14.0 app/controllers/wcms_components/people_controller.rb
biola_wcms_components-0.13.0 app/controllers/wcms_components/people_controller.rb
biola_wcms_components-0.12.0 app/controllers/wcms_components/people_controller.rb
biola_wcms_components-0.11.0 app/controllers/wcms_components/people_controller.rb
biola_wcms_components-0.10.0 app/controllers/wcms_components/people_controller.rb