Passed
Push — master ( 33ca92...23b088 )
by Ahmad
10:28
created

Joiner.room_setting_with_config()   B

Complexity

Conditions 8

Size

Total Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 8
dl 0
loc 21
rs 7.3333
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
module Joiner
20
  extend ActiveSupport::Concern
21
22
  # Displays the join room page to the user
23
  def show_user_join
24
    # Get users name
25
    @name = if current_user
26
      current_user.name
27
    elsif cookies.encrypted[:greenlight_name]
28
      cookies.encrypted[:greenlight_name]
29
    else
30
      ""
31
    end
32
33
    @search, @order_column, @order_direction, pub_recs =
34
      public_recordings(@room.bbb_id, params.permit(:search, :column, :direction), true)
35
36
    @pagy, @public_recordings = pagy_array(pub_recs)
37
38
    render :join
39
  end
40
41
  # create or update cookie to track the three most recent rooms a user joined
42
  def save_recent_rooms
43
    if current_user
44
      recently_joined_rooms = cookies.encrypted["#{current_user.uid}_recently_joined_rooms"].to_a
45
      cookies.encrypted["#{current_user.uid}_recently_joined_rooms"] =
46
        recently_joined_rooms.prepend(@room.id).uniq[0..2]
47
    end
48
  end
49
50
  def join_room(opts)
51
    @room_settings = JSON.parse(@room[:room_settings])
52
53
    if room_running?(@room.bbb_id) || @room.owned_by?(current_user) || room_setting_with_config("anyoneCanStart")
54
55
      # Determine if the user needs to join as a moderator.
56
      opts[:user_is_moderator] = @room.owned_by?(current_user) || room_setting_with_config("joinModerator") || @shared_room
57
      opts[:record] = record_meeting
58
      opts[:require_moderator_approval] = room_setting_with_config("requireModeratorApproval")
59
      opts[:mute_on_start] = room_setting_with_config("muteOnStart")
60
61
      if current_user
62
        redirect_to join_path(@room, current_user.name, opts, current_user.uid)
63
      else
64
        join_name = params[:join_name] || params[@room.invite_path][:join_name]
65
66
        redirect_to join_path(@room, join_name, opts, fetch_guest_id)
67
      end
68
    else
69
      search_params = params[@room.invite_path] || params
70
      @search, @order_column, @order_direction, pub_recs =
71
        public_recordings(@room.bbb_id, search_params.permit(:search, :column, :direction), true)
72
73
      @pagy, @public_recordings = pagy_array(pub_recs)
74
75
      # They need to wait until the meeting begins.
76
      render :wait
77
    end
78
  end
79
80
  def incorrect_user_domain
81
    Rails.configuration.loadbalanced_configuration && @room.owner.provider != @user_domain
82
  end
83
84
  # Default, unconfigured meeting options.
85
  def default_meeting_options
86
    invite_msg = I18n.t("invite_message")
87
    {
88
      user_is_moderator: false,
89
      meeting_logout_url: request.base_url + logout_room_path(@room),
90
      moderator_message: "#{invite_msg}\n\n#{request.base_url + room_path(@room)}",
91
      host: request.host,
92
      recording_default_visibility: @settings.get_value("Default Recording Visibility") == "public"
93
    }
94
  end
95
96
  private
97
98
  def fetch_guest_id
99
    return cookies[:guest_id] if cookies[:guest_id].present?
100
101
    guest_id = "gl-guest-#{SecureRandom.hex(12)}"
102
103
    cookies[:guest_id] = {
104
      value: guest_id,
105
      expires: 1.day.from_now
106
    }
107
108
    guest_id
109
  end
110
end
111