Skip to content

Commit

Permalink
don't use fallback avatar in planner
Browse files Browse the repository at this point in the history
ENV.current_user.avatar_is_fallback will be set if the
avatar_image_url is a fallback and not set by the user,
so projects that don't want to display fallbacks can
distinguish these cases

test plan:
 - as a student with no avatar image, create a personal
   ToDo in the planner dashboard
 - the circle icon on the item should have your initials,
   not the generic gray face icon

fixes ADMIN-1086

Change-Id: I30cdf579dc74491d5af8c98770227da6c3bddd7a
Reviewed-on: https://gerrit.instructure.com/157262
Tested-by: Jenkins
Reviewed-by: Mysti Sadler <[email protected]>
QA-Review: Ed Schiebel <[email protected]>
Product-Review: Jeremy Stanley <[email protected]>
  • Loading branch information
jstanley0 committed Sep 5, 2018
1 parent da33ed2 commit 1a13896
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def js_env(hash = {}, overwrite = false)
enable_profiles: (@domain_root_account && @domain_root_account.settings[:enable_profiles] != false)
},
}
@js_env[:current_user] = @current_user ? Rails.cache.fetch(['user_display_json', @current_user].cache_key, :expires_in => 1.hour) { user_display_json(@current_user, :profile) } : {}
@js_env[:current_user] = @current_user ? Rails.cache.fetch(['user_display_json', @current_user].cache_key, :expires_in => 1.hour) { user_display_json(@current_user, :profile, [:avatar_is_fallback]) } : {}
@js_env[:page_view_update_url] = page_view_path(@page_view.id, page_view_token: @page_view.token) if @page_view
@js_env[:IS_LARGE_ROSTER] = true if !@js_env[:IS_LARGE_ROSTER] && @context.respond_to?(:large_roster?) && @context.large_roster?
@js_env[:context_asset_string] = @context.try(:asset_string) if !@js_env[:context_asset_string]
Expand Down
10 changes: 9 additions & 1 deletion app/helpers/avatar_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,19 @@ def avatar_url_for_group(blank_fallback=false)
)
end

def self.avatars_enabled_for_user?(user)
(@domain_root_account || user.account).service_enabled?(:avatars)
end

def avatars_enabled_for_user?(user)
AvatarHelper.avatars_enabled_for_user?(user)
end

def self.avatar_url_for_user(user, request, blank_fallback=false)
default_avatar = User.avatar_fallback_url(
blank_fallback ? '/images/blank.png' : User.default_avatar_fallback,
request)
url = if (@domain_root_account || user.account).service_enabled?(:avatars)
url = if avatars_enabled_for_user?(user)
user.avatar_url(nil,
(@domain_root_account && @domain_root_account.settings[:avatars] || 'enabled'),
default_avatar,
Expand Down
3 changes: 2 additions & 1 deletion lib/api/v1/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def users_json(users, current_user, session, includes = [], context = @context,
#
# if parent_context is :profile, the html_url will always be the user's
# public profile url, regardless of @current_user permissions
def user_display_json(user, parent_context = nil)
def user_display_json(user, parent_context = nil, includes = [])
return {} unless user
participant_url = case parent_context
when :profile
Expand All @@ -181,6 +181,7 @@ def user_display_json(user, parent_context = nil)
avatar_image_url: avatar_url_for_user(user, blank_fallback),
html_url: participant_url
}
hash[:avatar_is_fallback] = user.avatar_image_url.nil? if includes.include?(:avatar_is_fallback) && avatars_enabled_for_user?(user)
hash[:fake_student] = true if user.fake_student?
hash
end
Expand Down
2 changes: 1 addition & 1 deletion packages/canvas-planner/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ export default function loadPlannerDashboard ({changeDashboardView, getActiveApp
currentUser: {
id: env.current_user.id,
displayName: env.current_user.display_name,
avatarUrl: env.current_user.avatar_image_url,
avatarUrl: env.current_user.avatar_is_fallback ? null : env.current_user.avatar_image_url,
color: env.PREFERENCES.custom_colors[`user_${env.current_user.id}`]
},
ariaHideElement: document.getElementById('application'),
Expand Down
58 changes: 58 additions & 0 deletions spec/integration/avatar_is_fallback_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#
# Copyright (C) 2011 - present Instructure, Inc.
#
# This file is part of Canvas.
#
# Canvas is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, version 3 of the License.
#
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
#

require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')

describe UsersController do
context "avatar_is_fallback" do
before :once do
user_factory
end

before :each do
user_session @user
end

it 'is absent when avatars are turned off' do
get '/'
expect(assigns(:js_env)[:current_user]).not_to have_key :avatar_is_fallback
end

context "with avatars enabled" do
before :once do
Account.default.tap do |a|
a.enable_service(:avatars)
a.save!
end
end

it 'is true when there is no real avatar image' do
get '/'
expect(assigns(:js_env)[:current_user][:avatar_image_url]).to include User.default_avatar_fallback
expect(assigns(:js_env)[:current_user][:avatar_is_fallback]).to eq true
end

it 'is false when there is a real avatar image' do
@user.avatar_image_url = 'https://canvas.instructure.com/avi.png'; @user.save!
get '/'
expect(assigns(:js_env)[:current_user][:avatar_image_url]).to eq @user.avatar_image_url
expect(assigns(:js_env)[:current_user][:avatar_is_fallback]).to eq false
end
end
end
end

0 comments on commit 1a13896

Please sign in to comment.