Class: UsersController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- UsersController
- Defined in:
- app/controllers/users_controller.rb
Overview
Copyright © 2012 The Pennsylvania State University
Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at
www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Instance Method Summary collapse
-
#edit ⇒ Object
Display form for users to edit their profile information.
-
#follow ⇒ Object
Follow a user.
- #index ⇒ Object
-
#show ⇒ Object
Display user profile.
-
#unfollow ⇒ Object
Unfollow a user.
-
#update ⇒ Object
Process changes from profile form.
Instance Method Details
#edit ⇒ Object
Display form for users to edit their profile information
41 42 43 44 |
# File 'app/controllers/users_controller.rb', line 41 def edit @user = current_user @groups = @user.groups end |
#follow ⇒ Object
Follow a user
61 62 63 64 65 66 67 |
# File 'app/controllers/users_controller.rb', line 61 def follow unless current_user.following?(@user) current_user.follow(@user) Sufia.queue.push(UserFollowEventJob.new(current_user.user_key, @user.user_key)) end redirect_to sufia.profile_path(URI.escape(@user.to_s,'@.')), notice: "You are following #{@user.to_s}" end |
#index ⇒ Object
21 22 23 24 25 26 27 |
# File 'app/controllers/users_controller.rb', line 21 def index sort_val = get_sort query = params[:uq].blank? ? nil : "%"+params[:uq].downcase+"%" @users = User.where("(login like lower(?) OR display_name like lower(?)) and ldap_available = true ",query,query).paginate(:page => params[:page], :per_page => 10, :order => sort_val) unless query.blank? @users = User.where("ldap_available = true").paginate(:page => params[:page], :per_page => 10, :order => sort_val) if query.blank? end |
#show ⇒ Object
Display user profile
30 31 32 33 34 35 36 37 38 |
# File 'app/controllers/users_controller.rb', line 30 def show if @user.respond_to? :profile_events @events = @user.profile_events(100) else @events = [] end @followers = @user.followers @following = @user.all_following end |
#unfollow ⇒ Object
Unfollow a user
70 71 72 73 74 75 76 |
# File 'app/controllers/users_controller.rb', line 70 def unfollow if current_user.following?(@user) current_user.stop_following(@user) Sufia.queue.push(UserUnfollowEventJob.new(current_user.user_key, @user.user_key)) end redirect_to sufia.profile_path(URI.escape(@user.to_s,'@.')), notice: "You are no longer following #{@user.to_s}" end |
#update ⇒ Object
Process changes from profile form
47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'app/controllers/users_controller.rb', line 47 def update @user.update_attributes(params[:user]) @user.populate_attributes if params[:update_directory] @user.avatar = nil if params[:delete_avatar] unless @user.save redirect_to sufia.edit_profile_path(URI.escape(@user.to_s,'@.')), alert: @user.errors. return end Sufia.queue.push(UserEditProfileEventJob.new(@user.user_key)) redirect_to sufia.profile_path(URI.escape(@user.to_s,'@.')), notice: "Your profile has been updated" end |