GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Pull Request — master (#865)
by Ahmad
05:34
created

Uploader.convert_image_to_avatar()   A

Complexity

Conditions 3

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
dl 0
loc 13
rs 9.75
c 1
b 0
f 0
1
# frozen_string_literal: true
2
3
# BigBlueButton open source conferencing system - http://www.bigbluebutton.org/.
4
#
5
# Copyright (c) 2018 BigBlueButton Inc. and by respective authors (see below).
6
#
7
# This program is free software; you can redistribute it and/or modify it under the
8
# terms of the GNU Lesser General Public License as published by the Free Software
9
# Foundation; either version 3.0 of the License, or (at your option) any later
10
# version.
11
#
12
# BigBlueButton is distributed in the hope that it will be useful, but WITHOUT ANY
13
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
14
# PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
15
#
16
# You should have received a copy of the GNU Lesser General Public License along
17
# with BigBlueButton; if not, see <http://www.gnu.org/licenses/>.
18
19
require 'open-uri'
20
21
module Uploader
22
  extend ActiveSupport::Concern
23
24
  # Converts the users image link to an avatar file stored
25
  def convert_image_to_avatar(user)
26
    begin
27
      # Get the last part of the url
28
      name = user.image.split("/").last
29
30
      file = File.open(user.image)
31
32
      # Upload file if its an image
33
      user.avatar.attach(io: file, filename: name) if file.content_type.start_with?("image/")
34
    rescue e
35
      logger.error("Support: Image URL is not valid/available - #{user.uid} - #{user.image}")
36
    end
37
  end
38
39
  def invalid_image_upload(avatar)
40
    avatar.present? && !avatar.content_type.start_with?("image/")
41
  end
42
end
43