GRN2-225, GRN2-227: Images sent by Office365 Institutional accounts break the rooms (#753)

* Validate profile image url

* Add rake task to migrate old office365 accounts
This commit is contained in:
shawn-higgins1 2019-08-21 14:23:00 -04:00 committed by Jesus Federico
parent 915ed9381d
commit 3d2a0a060b
3 changed files with 42 additions and 1 deletions

View File

@ -17,6 +17,7 @@
# with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
require 'bbb_api'
require 'uri'
require 'i18n/language/mapping'
module ApplicationHelper
@ -139,4 +140,11 @@ module ApplicationHelper
def google_analytics_url
"https://www.googletagmanager.com/gtag/js?id=#{ENV['GOOGLE_ANALYTICS_TRACKING_ID']}"
end
def valid_url?(input)
uri = URI.parse(input)
!uri.host.nil?
rescue URI::InvalidURIError
false
end
end

View File

@ -44,7 +44,7 @@
<div class="dropdown">
<a href="#" class="nav-link pr-0" data-toggle="dropdown">
<% if current_user.image.blank? %>
<% if current_user.image.blank? || !valid_url?(current_user.image) %>
<span class="avatar"><%= current_user.name.first %></span>
<% else %>
<span id="user-avatar" class="avatar d-none"><%= current_user.name.first %></span>

View File

@ -0,0 +1,33 @@
# frozen_string_literal: true
namespace :office365 do
desc "Migrates over old office365 users to new account"
task :migrate, [] => :environment do |_task, _args|
old_office_users = User.where(provider: "microsoft_office365")
old_office_users.each do |old_user|
new_social_uid = if old_user.email.match("^outlook_[0-9a-zA-Z]+@outlook.com$")
old_user.email.last(old_user.email.length - 8).split('@')[0]
else
old_user.social_uid.split('@')[0]
end
new_user = User.where(provider: "office365", social_uid: new_social_uid).first
if new_user.nil?
old_user.provider = "office365"
old_user.social_uid = new_social_uid
old_user.save!
else
old_main_room = old_user.main_room
old_main_room.name = "Old " + old_main_room.name
old_main_room.save!
new_user.rooms << old_user.rooms
new_user.role_ids = new_user.role_ids | old_user.role_ids
new_user.save!
old_user.delete
end
end
end
end