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.
Passed
Pull Request — master (#848)
by Ahmad
04:48
created

Room   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 74
rs 10
c 0
b 0
f 0
wmc 12

8 Methods

Rating   Name   Duplication   Size   Complexity  
A admins_search() 0 16 2
A setup() 0 6 1
A notify_waiting() 0 3 1
A invite_path() 0 3 1
A admins_order() 0 10 3
A owned_by? 0 4 2
A random_room_uid() 0 3 1
A uid_chunk() 0 4 1
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 'bbb_api'
20
21
class Room < ApplicationRecord
22
  include Deleteable
23
24
  before_create :setup
25
26
  validates :name, presence: true
27
28
  belongs_to :owner, class_name: 'User', foreign_key: :user_id
29
30
  def self.admins_search(string)
31
    active_database = Rails.configuration.database_configuration[Rails.env]["adapter"]
32
    # Postgres requires created_at to be cast to a string
33
    created_at_query = if active_database == "postgresql"
34
      "created_at::text"
35
    else
36
      "created_at"
37
    end
38
39
    search_query = "rooms.name LIKE :search OR rooms.uid LIKE :search OR users.email LIKE :search" \
40
    " OR users.#{created_at_query} LIKE :search"
41
42
    search_param = "%#{string}%"
43
44
    joins(:owner).where(search_query, search: search_param)
45
  end
46
47
  def self.admins_order(column, direction)
48
    # Include the owner of the table
49
    table = joins(:owner)
50
51
    if table.column_names.include?(column) || column == "users.name"
52
      return table.order(Arel.sql("#{column} #{direction}"))
53
    end
54
55
    table
56
  end
57
58
  # Determines if a user owns a room.
59
  def owned_by?(user)
60
    return false if user.nil?
61
    user.rooms.include?(self)
62
  end
63
64
  # Determines the invite path for the room.
65
  def invite_path
66
    "#{Rails.configuration.relative_url_root}/#{CGI.escape(uid)}"
67
  end
68
69
  # Notify waiting users that a meeting has started.
70
  def notify_waiting
71
    ActionCable.server.broadcast("#{uid}_waiting_channel", action: "started")
72
  end
73
74
  private
75
76
  # Generates a uid for the room and BigBlueButton.
77
  def setup
78
    self.uid = random_room_uid
79
    self.bbb_id = Digest::SHA1.hexdigest(Rails.application.secrets[:secret_key_base] + Time.now.to_i.to_s).to_s
80
    self.moderator_pw = RandomPassword.generate(length: 12)
81
    self.attendee_pw = RandomPassword.generate(length: 12)
82
  end
83
84
  # Generates a three character uid chunk.
85
  def uid_chunk
86
    charset = ("a".."z").to_a - %w(b i l o s) + ("2".."9").to_a - %w(5 8)
87
    (0...3).map { charset.to_a[rand(charset.size)] }.join
88
  end
89
90
  # Generates a random room uid that uses the users name.
91
  def random_room_uid
92
    [owner.name_chunk, uid_chunk, uid_chunk].join('-').downcase
93
  end
94
end
95