From d5a9b79f6e50a3fae48833cd07ab2b9104da987b Mon Sep 17 00:00:00 2001 From: Michael Ball Date: Wed, 15 Jul 2020 23:37:40 -0700 Subject: [PATCH] Show profile pictures to admins and allow them to upload pics --- app/controllers/admin/users_controller.rb | 3 ++- app/models/user.rb | 1 - app/views/admin/users/_form.html.haml | 12 ++++++++++++ app/views/admin/users/show.html.haml | 3 +++ 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/app/controllers/admin/users_controller.rb b/app/controllers/admin/users_controller.rb index 4d7925dd..e49c02f5 100644 --- a/app/controllers/admin/users_controller.rb +++ b/app/controllers/admin/users_controller.rb @@ -43,7 +43,8 @@ module Admin # Variable @show_attributes holds the attributes that are visible for the 'show' action # If you want to change the attributes that are shown in the 'show' action of users # add/remove the attributes in the following string array - @show_attributes = %w(name email username nickname affiliation biography registered attended roles created_at + @show_attributes = %w(name email username nickname affiliation biography + profile_picture registered attended roles created_at updated_at sign_in_count current_sign_in_at last_sign_in_at current_sign_in_ip last_sign_in_ip) end diff --git a/app/models/user.rb b/app/models/user.rb index 8d5a935c..1a2b19b1 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -160,7 +160,6 @@ class User < ApplicationRecord # Partials should *not* directly call `gravatar_url` def profile_picture(opts = {}) return gravatar_url(opts) unless picture.present? - puts "ASKED FOR PROFILE PIC!! #{opts[:size]}" size = (opts[:size] || 0).to_i if size < 50 picture.tiny.url diff --git a/app/views/admin/users/_form.html.haml b/app/views/admin/users/_form.html.haml index 7604f0d3..845065dc 100644 --- a/app/views/admin/users/_form.html.haml +++ b/app/views/admin/users/_form.html.haml @@ -19,6 +19,18 @@ = f.input :username, :as => :string if @user.new_record? = f.input :email = f.input :password if @user.new_record? + .control-label + Gravatar + = image_tag(@user.profile_picture(size: '48'), alt: '') + %p + Or upload a picture. + = f.input :picture, hint: 'If you upload a picture, it will be used in place of Gravatar.' + - if @user.picture? + %p + Current Picture + %br + = image_tag(@user.picture.url, width: '20%') + = f.input :affiliation, as: :string = f.input :biography, input_html: { rows: 10, data: { provide: 'markdown' } }, hint: markdown_hint diff --git a/app/views/admin/users/show.html.haml b/app/views/admin/users/show.html.haml index c9048be4..b90e72d9 100644 --- a/app/views/admin/users/show.html.haml +++ b/app/views/admin/users/show.html.haml @@ -26,6 +26,9 @@ - elsif attr == 'biography' %td = markdown(@user.biography) + - elsif attr == 'profile_picture' + %td + = image_tag @user.profile_picture(size: '100'), alt: '' - elsif attr == 'email' %td = @user.send(attr)