Class: PeopleController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- PeopleController
- Defined in:
- app/controllers/people_controller.rb
Defined Under Namespace
Classes: ClassProfileState
Instance Method Summary collapse
- #advanced ⇒ Object
-
#ajax_check_if_email_exists ⇒ Object
Checks whether the specified email account already exists.
-
#ajax_check_if_webiso_account_exists ⇒ Object
Checks whether the specified webiso account already exists.
- #class_profile ⇒ Object
-
#create ⇒ Object
POST /people POST /people.xml.
-
#destroy ⇒ Object
DELETE /people/1 DELETE /people/1.xml.
-
#download_csv ⇒ Object
GET /people/download_csv.
-
#download_vcf ⇒ Object
GET /people/download_vcf.
-
#edit ⇒ Object
GET /people/1/edit.
-
#index ⇒ Object
GET /people GET /people.xml.
-
#index_autocomplete ⇒ Object
Ajax call for autocomplete using params.
- #my_courses ⇒ Object
- #my_courses_verbose ⇒ Object
- #my_teams ⇒ Object
-
#new ⇒ Object
GET /people/new GET /people/new.xml.
- #perform ⇒ Object
- #photo_book ⇒ Object
-
#respond_with_existence(obj) ⇒ Object
Creates a response from the specified object.
- #revert_to_version ⇒ Object
- #robots ⇒ Object
-
#search ⇒ Object
GET /people_search.json.
-
#show ⇒ Object
GET /people/1 GET /people/1.xml GET /people/AndrewCarnegie GET /people/AndrewCarnegie.xml.
-
#show_by_twiki ⇒ Object
GET /people/twiki/AndrewCarnegie GET /people/twiki/AndrewCarnegie.xml.
-
#update ⇒ Object
PUT /people/1 PUT /people/1.xml.
- #upload_photo ⇒ Object
Methods inherited from ApplicationController
Instance Method Details
#advanced ⇒ Object
65 66 67 |
# File 'app/controllers/people_controller.rb', line 65 def advanced index end |
#ajax_check_if_email_exists ⇒ Object
Checks whether the specified email account already exists. Expected input is through the q=<[email protected]> parameter Output is an object with a single exists property set to whether the account exists. Requires user to be able to authenticate same-as-if creating. GET /people/check_email
345 346 347 |
# File 'app/controllers/people_controller.rb', line 345 def ajax_check_if_email_exists respond_with_existence User.find_by_email(params[:q]) end |
#ajax_check_if_webiso_account_exists ⇒ Object
Checks whether the specified webiso account already exists. Expected input is through the q=<[email protected]> parameter Output is an object with a single exists property set to whether the account exists. Requires user to be able to authenticate same-as-if creating. GET /people/check_webiso_account
335 336 337 |
# File 'app/controllers/people_controller.rb', line 335 def ajax_check_if_webiso_account_exists respond_with_existence User.find_by_webiso_account(params[:q]) end |
#class_profile ⇒ Object
455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 |
# File 'app/controllers/people_controller.rb', line 455 def class_profile if params[:class_profile_state] @class_profile_state = ClassProfileState.new @class_profile_state.program = params[:class_profile_state][:program] @class_profile_state.graduation_year = params[:class_profile_state][:graduation_year] @class_profile_state.is_part_time = params[:class_profile_state][:is_part_time] else @class_profile_state = ClassProfileState.new @class_profile_state.program = current_user.is_student ? current_user.masters_program : "SE" @class_profile_state.graduation_year = Date.today.year + 1 @class_profile_state.is_part_time = current_user.is_student && !current_user.is_part_time ? "FT" : "PT" end case @class_profile_state.is_part_time when "PT" @students = User.part_time_class_of(@class_profile_state.program, @class_profile_state.graduation_year.to_s) when "FT" @students = User.full_time_class_of(@class_profile_state.program, @class_profile_state.graduation_year.to_s) end @programs = [] ActiveRecord::Base.connection.execute("SELECT distinct masters_program FROM users u;").each do |result| @programs << result["masters_program"] end @tracks = [] ActiveRecord::Base.connection.execute("SELECT distinct masters_track FROM users u;").each do |result| @tracks << result["masters_track"] end @title = "Class profile for #{@class_profile_state.is_part_time} #{@class_profile_state.program} #{@class_profile_state.graduation_year}" respond_to do |format| if params[:layout] format.html { render :layout => false } # index.html.erb else format.html { render :layout => "cmu_sv" } # index.html.erb end end end |
#create ⇒ Object
POST /people POST /people.xml
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 |
# File 'app/controllers/people_controller.rb', line 244 def create :create, User @person = User.new(user_params) @person.org_unit_path = params[:user][:org_unit_path] @person.expires_at = params[:user][:expires_at] @person.updated_by_user_id = current_user.id @person.image_uri = ActionController::Base.helpers.asset_path('mascot.jpg') @person.image_uri_first = ActionController::Base.helpers.asset_path('mascot.jpg') @person.image_uri_second = ActionController::Base.helpers.asset_path('mascot.jpg') @person.image_uri_custom = ActionController::Base.helpers.asset_path('mascot.jpg') @person.photo_selection = 'first' respond_to do |format| if @person.save create_google_email = params[:create_google_email] create_twiki_account = params[:create_twiki_account] create_active_directory_account = params[:create_active_directory_account] Delayed::Job.enqueue(PersonJob.new(@person.id, create_google_email, create_twiki_account, create_active_directory_account)) unless create_google_email.nil? && create_twiki_account.nil? && create_active_directory_account.nil? flash[:notice] = 'Person was successfully created.' format.html { redirect_to person_path(@person) } format.xml { render :xml => @person, :status => :created, :location => @person } else format.html { render :action => 'new' } format.xml { render :xml => @person.errors, :status => :unprocessable_entity } end end end |
#destroy ⇒ Object
DELETE /people/1 DELETE /people/1.xml
375 376 377 378 379 380 381 382 383 384 385 386 387 388 |
# File 'app/controllers/people_controller.rb', line 375 def destroy if !current_user.is_admin? flash[:error] = 'You don' 't have permission to do this action.' redirect_to(people_url) and return end @person = User.find_by_param(params[:id]) @person.destroy respond_to do |format| format.html { redirect_to(people_url) } format.xml { head :ok } end end |
#download_csv ⇒ Object
GET /people/download_csv
Export the search results in csv format
497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 |
# File 'app/controllers/people_controller.rb', line 497 def download_csv if params[:search_id].blank? # this is for multiple contacts @people = get_search_or_key_contacts(params) else # this is for a single contact @people = [] @people << User.find_by_id(params[:search_id]) end respond_to do |format| format.csv do csv_string = CSV.generate do |csv| csv << ["Name", "Given Name", "Additional Name", "Family Name", "Yomi Name", "Given Name Yomi", "Additional Name Yomi", "Family Name Yomi", "Name Prefix", "Name Suffix", "Initials", "Nickname", "Short Name", "Maiden Name", "Birthday", "Gender", "Location", "Billing Information", "Directory Server", "Mileage", "Occupation", "Hobby", "Sensitivity", "Priority", "Subject", "Notes", "Group Membership", "E-mail 1 - Type", "E-mail 1 - Value", "E-mail 2 - Type", "E-mail 2 - Value", "Phone 1 - Type", "Phone 1 - Value", "Phone 2 - Type", "Phone 2 - Value", "Phone 3 - Type", "Phone 3 - Value", "Phone 4 - Type", "Phone 4 - Value", "Organization 1 - Type", "Organization 1 - Name", "Organization 1 - Yomi Name", "Organization 1 - Title", "Organization 1 - Department", "Organization 1 - Symbol", "Organization 1 - Location", "Organization 1 - Job Description"] @people.each do |user| org = user.organization_name.nil? ? "" : user.organization_name title = user.title.nil? ? "" : user.title csv << [user.first_name, user.first_name, "", user.last_name, "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", user.is_staff? ? "Work" : "Other", user.email, "Home", user.personal_email, csv_name_converter(user.telephone1_label), user.telephone1, csv_name_converter(user.telephone2_label), user.telephone2, csv_name_converter(user.telephone3_label), user.telephone3, csv_name_converter(user.telephone4_label), user.telephone4, "", org, "", title, "", "", "", ""] end end send_data csv_string, :type => "text/csv; charset=utf-8", :disposition => "attachment; filename=contact.csv" end end end |
#download_vcf ⇒ Object
GET /people/download_vcf
Export the search results in vCard format
532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 |
# File 'app/controllers/people_controller.rb', line 532 def download_vcf if params[:search_id].blank? # this is for multiple contacts @people = get_search_or_key_contacts(params) else # this is for a single contact @people = [] @people << User.find_by_id(params[:search_id]) end vcard_str="" @people.each do |user| card = Vpim::Vcard::Maker.make2 do |maker| maker.add_name do |name| name.prefix = '' name.given = user.first_name name.family = user.last_name end phones_hash = user.telephones_hash if (!user.email.blank?) maker.add_email(user.email) { |e| e.location = user.is_staff? ? 'work' : 'other' } end if (!user.personal_email.blank?) maker.add_email(user.personal_email) { |e| e.location = 'home' } end maker.title = user.title unless user.title.nil? maker.org = user.organization_name unless user.organization_name.nil? phones_hash.each do |k, v| # ignore empty telephone fields if (!v.blank?) maker.add_tel(v) do |tel| tel.location = "work" if k == "Work" tel.location = "home" if k == "Home" tel.location = "fax" if k == "Fax" tel.location = "cell" if k == "Mobile" tel.location = "voice" if k == "Google Voice" end end end end vcard_str << card.to_s end send_data vcard_str, :type => "text/vcf; charset=utf-8", :disposition => "attachment; filename=contact.vcf" end |
#edit ⇒ Object
GET /people/1/edit
233 234 235 236 237 238 239 240 |
# File 'app/controllers/people_controller.rb', line 233 def edit @person = User.find_by_param(params[:id]) unless can? :update, @person #@person.id == current_user.id or current_user.is_admin? flash[:error] = "You're not allowed to edit this user's profile." redirect_to user_path(@person) end end |
#index ⇒ Object
GET /people GET /people.xml
-
This method checks to see if the logged in user has entered sufficient information in his own profile to use the people_search functionality (lovingly called carrot & stick)
-
This method loads the search bar and default/key contacts for that user.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'app/controllers/people_controller.rb', line 30 def index # 1. carrot & stick if !current_user.is_profile_valid? flash[:notice] = "<div align='center'><b>Warning:</b><br/> You have to update your profile details.<br/> If you do not do so in 4 weeks, you will lose access to the search profile features.<br/><a href='#{url_for(edit_person_path(current_user))}'>Click here to edit your profile.</a></div>".html_safe flash[:error] = nil if current_user.should_be_redirected? flash[:notice] = nil flash[:error] = "<div align='center'><b>Warning:</b><br/> Your access to the user search features have temporarily been disabled. <br/>To continue, please update your biography/phone numbers and social handles.</div>".html_safe redirect_to edit_person_path(current_user) and return end end # 2. default/key contacts for that user @people = get_default_key_contacts # pick only the fields required to be shown in the view and return as a Hash @key_contact_results = @people.collect { |default_person| Hash[ # :image_uri => default_person.user.image_uri, :title => default_person.user.title, :human_name => default_person.user.human_name, :contact_dtls => default_person.user.telephones_hash, :email => default_person.user.email, :path => person_path(default_person.user), # first_name and last_name required for photobook view :first_name => default_person.user.first_name, :last_name => default_person.user.last_name ] } @key_contact_results.uniq! respond_to do |format| format.html { render :html => @key_contact_results } format.json { render :json => @key_contact_results } end end |
#index_autocomplete ⇒ Object
Ajax call for autocomplete using params
120 121 122 123 124 125 126 127 128 129 |
# File 'app/controllers/people_controller.rb', line 120 def index_autocomplete #if database is mysql #@people = User.where("human_name LIKE ?", "%#{params[:term]}%").all @people = User.where("human_name ILIKE ?", "%#{params[:term]}%").all respond_to do |format| format.html { render :html => @people } format.json { render :json => @people.collect { |person| person.human_name }, :layout => false } end end |
#my_courses ⇒ Object
418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 |
# File 'app/controllers/people_controller.rb', line 418 def my_courses @person = User.find_by_param(params[:id]) if @person.nil? flash[:error] = "Person with an id of #{params[:id]} is not in this system." redirect_to(people_url) and return end person_id = @person.id.to_i if (current_user.id != person_id) unless (current_user.is_staff?)||(current_user.is_admin?) flash[:error] = 'You don' 't have permission to see another person' 's courses.' redirect_to(people_url) and return end end @registered_for_these_courses = [] #@person.registered_for_these_courses @teaching_these_courses = @person.teaching_these_courses end |
#my_courses_verbose ⇒ Object
436 437 438 439 440 441 442 443 444 445 446 447 |
# File 'app/controllers/people_controller.rb', line 436 def my_courses_verbose @person = User.find_by_param(params[:id]) person_id = @person.id.to_i if (current_user.id != person_id) unless (current_user.is_staff?)||(current_user.is_admin?) flash[:error] = 'You don' 't have permission to see another person' 's courses.' redirect_to(people_url) and return end end @courses_registered_as_student = @person.registered_for_these_courses_during_current_semester @courses_teaching_as_faculty = @person.teaching_these_courses end |
#my_teams ⇒ Object
391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 |
# File 'app/controllers/people_controller.rb', line 391 def my_teams @person = User.find_by_param(params[:id]) if @person.nil? flash[:error] = "Person with an id of #{params[:id]} is not in this system." redirect_to(people_url) and return end person_id = @person.id.to_i if (current_user.id != person_id) unless (current_user.is_staff?)||(current_user.is_admin?) flash[:error] = 'You don' 't have permission to see another person' 's teams.' redirect_to(people_url) and return end end @course = Course.new() @current_year = Date.today.year() @current_semester = AcademicCalendar.current_semester() #SQL statements determined by Team Juran @current_teams_as_member = Team.find_current_by_person(@person) @past_teams_as_member = Team.find_past_by_person(@person) (@teams_map, @teams_students_map) = current_user.faculty_teams_map(person_id) a = 10 end |
#new ⇒ Object
GET /people/new GET /people/new.xml
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 |
# File 'app/controllers/people_controller.rb', line 205 def new :create, User @person = User.new @person.is_active = true @person.webiso_account = params[:webiso_account] @person.personal_email = params[:personal_email] @person.is_student = params[:is_student] @person.is_staff = params[:is_staff] @person.first_name = params[:first_name] @person.last_name = params[:last_name] @person.masters_program = params[:program] @person.expires_at = params[:expires_at] @person.org_unit_path = params[:org_unit_path] || '/Student' if Rails.env.development? @domain = GOOGLE_DOMAIN else @domain = 'sv.cmu.edu' end respond_to do |format| format.html # new.html.erb format.xml { render :xml => @person } end end |
#perform ⇒ Object
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'app/controllers/people_controller.rb', line 152 def perform if (:admin, root_path) @person = Person.find_by_param(params[:id]) create_google_email = params[:create_google_email] || false create_twiki_account = params[:create_twiki_account] || false create_active_directory_account = params[:create_active_directory_account] || false respond_to do |format| if @person.nil? flash[:error] = "Person with an id of #{params[:id]} is not in this system." format.html { redirect_to(people_url) } else = User.perform_create_accounts(@person.id, create_google_email, create_twiki_account, create_active_directory_account) flash[:error] = unless .blank? format.html { redirect_to(@person) } end end end end |
#photo_book ⇒ Object
69 70 71 |
# File 'app/controllers/people_controller.rb', line 69 def photo_book index end |
#respond_with_existence(obj) ⇒ Object
Creates a response from the specified object. Output is an object with a single exists property set to whether the object is not nil.
352 353 354 355 356 357 358 359 360 |
# File 'app/controllers/people_controller.rb', line 352 def respond_with_existence obj result = {} result[:exists] = !obj.nil? respond_to do |format| format.json { render :json => result } format.xml { render :xml => result, :status => 200 } end end |
#revert_to_version ⇒ Object
362 363 364 365 366 |
# File 'app/controllers/people_controller.rb', line 362 def revert_to_version @person = User.find_by_param(params[:id]) @person.revert_to! params[:version_id] redirect_to :action => 'show', :id => @person end |
#robots ⇒ Object
368 369 370 371 |
# File 'app/controllers/people_controller.rb', line 368 def robots logger.info('curriculum comment: robot detected') format.html # index.html.erb end |
#search ⇒ Object
GET /people_search.json
Ajax call for people search results using params. Sends back json object with search results (from database)
Number of requesting coming in here is controlled through a javascript timer (see js in views/people/index.html.erb for more details.)
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'app/controllers/people_controller.rb', line 80 def search # call the function that actually finds all releveant search results from database @people = search_db_fields # priority_results = prioritize_search_results # pick only the fields required to be shown in the view and return as a Hash @people_hash = @people.collect do |person| # program, the user is enrolled in needs to be constructed to include addtional info like full-time/part-time program = '' if person.is_student program += (person.masters_program + ' ') unless person.masters_program.blank? program += person.masters_track unless person.masters_track.blank? if person.is_part_time program += ' (PT)' else program += ' (FT)' end elsif person.is_staff program += 'Staff' end # constructing Hash/json containing results Hash[:id => person.twiki_name, :first_name => person.first_name, :last_name => person.last_name, :image_uri => ActionController::Base.helpers.asset_path(person.image_uri), :program => program, :contact_dtls => person.telephones_hash.map { |k, v| "#{k}: #{v}" }.to_a, :email => person.email, :path => person_path(person), :priority => priority_results.include?(person.id) ] end respond_to do |format| format.json { render :json => @people_hash, :layout => false } end end |
#show ⇒ Object
GET /people/1 GET /people/1.xml GET /people/AndrewCarnegie GET /people/AndrewCarnegie.xml
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'app/controllers/people_controller.rb', line 135 def show @person = Person.find_by_param(params[:id]) @person.revert_to params[:version_id] if params[:version_id] respond_to do |format| if @person.nil? flash[:error] = "Person with an id of #{params[:id]} is not in this system." format.html { redirect_to(people_url) } format.xml { render :xml => @person.errors, :status => :unprocessable_entity } else format.html # show.html.erb format.xml { render :xml => @person } format.json { render :json => @person, :layout => false } end end end |
#show_by_twiki ⇒ Object
GET /people/twiki/AndrewCarnegie GET /people/twiki/AndrewCarnegie.xml
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
# File 'app/controllers/people_controller.rb', line 174 def show_by_twiki redirect_to :action => 'robots' if robot? host = get_http_host() if !(host.include?("info.sv.cmu.edu") || host.include?("info.west.cmu.edu")) && (current_user.nil?) flash[:error] = "You don't have permissions to view this data." redirect_to(people_url) return end @machine_name = "http://whiteboard.sv.cmu.edu" twiki_name = params[:twiki_name] @person = User.find_by_twiki_name(twiki_name) respond_to do |format| if @person.nil? flash[:error] = "Person #{params[:twiki_name]} is not in this system." format.html { redirect_to(people_url) } format.xml { render :xml => @person.errors, :status => :unprocessable_entity } else format.html { render :html => @person, :layout => false } # show.html.erb format.xml { render :xml => @person } end end end |
#update ⇒ Object
PUT /people/1 PUT /people/1.xml
303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 |
# File 'app/controllers/people_controller.rb', line 303 def update @person = User.find_by_param(params[:id]) :update, @person Rails.logger.info("People#update #{request.env["REQUEST_PATH"]} #{current_user.human_name} #{params}") @person.updated_by_user_id = current_user.id respond_to do |format| @person.attributes = params[:user] @person.expires_at = params[:user][:expires_at] if current_user.is_admin? if @person.save unless @person.is_profile_valid flash[:error] = "Please update your (social handles or biography) and your contact information" end flash[:notice] = 'Person was successfully updated.' format.html { redirect_to(@person) } format.xml { head :ok } else format.html { render :action => "edit" } format.xml { render :xml => @person.errors, :status => :unprocessable_entity } end end end |
#upload_photo ⇒ Object
276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 |
# File 'app/controllers/people_controller.rb', line 276 def upload_photo @person = User.find_by_param(params[:id]) if (can? :upload_official_photo, User) && !params[:user][:photo_first].blank? @person.photo_first = params[:user][:photo_first] end if (can? :upload_official_photo, User) && !params[:user][:photo_second].blank? @person.photo_second = params[:user][:photo_second] end if !params[:user][:photo_custom].blank? @person.photo_custom = params[:user][:photo_custom] end @person.attributes = params[:user] respond_to do |format| if @person.save format.html { redirect_to edit_person_path(@person) } format.xml { head :ok } else format.html { render :action => "edit" } format.xml { render :xml => @person.errors, :status => :unprocessable_entity } end end end |