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
|
|
|
class AdminsController < ApplicationController |
20
|
|
|
include Pagy::Backend |
21
|
|
|
include Themer |
22
|
|
|
include Emailer |
23
|
|
|
include Recorder |
24
|
|
|
|
25
|
|
|
manage_users = [:edit_user, :promote, :demote, :ban_user, :unban_user, :approve] |
26
|
|
|
site_settings = [:branding, :coloring, :coloring_lighten, :coloring_darken, |
27
|
|
|
:registration_method, :room_authentication, :room_limit, :default_recording_visibility] |
28
|
|
|
|
29
|
|
|
authorize_resource class: false |
30
|
|
|
before_action :find_user, only: manage_users |
31
|
|
|
before_action :verify_admin_of_user, only: manage_users |
32
|
|
|
before_action :find_setting, only: site_settings |
33
|
|
|
|
34
|
|
|
# GET /admins |
35
|
|
|
def index |
36
|
|
|
@search = params[:search] || "" |
37
|
|
|
@order_column = params[:column] && params[:direction] != "none" ? params[:column] : "created_at" |
38
|
|
|
@order_direction = params[:direction] && params[:direction] != "none" ? params[:direction] : "DESC" |
39
|
|
|
@role = params[:role] || "" |
40
|
|
|
|
41
|
|
|
@pagy, @users = pagy(user_list) |
42
|
|
|
end |
43
|
|
|
|
44
|
|
|
# GET /admins/site_settings |
45
|
|
|
def site_settings |
46
|
|
|
end |
47
|
|
|
|
48
|
|
|
# GET /admins/server_recordings |
49
|
|
|
def server_recordings |
50
|
|
|
server_rooms = if Rails.configuration.loadbalanced_configuration |
51
|
|
|
Room.includes(:owner).where(users: { provider: user_settings_provider }).pluck(:bbb_id) |
52
|
|
|
else |
53
|
|
|
Room.pluck(:bbb_id) |
54
|
|
|
end |
55
|
|
|
|
56
|
|
|
@search, @order_column, @order_direction, recs = |
57
|
|
|
all_recordings(server_rooms, @user_domain, params.permit(:search, :column, :direction), true, true) |
58
|
|
|
@pagy, @recordings = pagy_array(recs) |
59
|
|
|
end |
60
|
|
|
|
61
|
|
|
# MANAGE USERS |
62
|
|
|
|
63
|
|
|
# GET /admins/edit/:user_uid |
64
|
|
|
def edit_user |
65
|
|
|
end |
66
|
|
|
|
67
|
|
|
# POST /admins/promote/:user_uid |
68
|
|
|
def promote |
69
|
|
|
@user.add_role :admin |
70
|
|
|
|
71
|
|
|
send_user_promoted_email(@user) |
72
|
|
|
|
73
|
|
|
redirect_to admins_path, flash: { success: I18n.t("administrator.flash.promoted") } |
74
|
|
|
end |
75
|
|
|
|
76
|
|
|
# POST /admins/demote/:user_uid |
77
|
|
|
def demote |
78
|
|
|
@user.remove_role :admin |
79
|
|
|
|
80
|
|
|
send_user_demoted_email(@user) |
81
|
|
|
|
82
|
|
|
redirect_to admins_path, flash: { success: I18n.t("administrator.flash.demoted") } |
83
|
|
|
end |
84
|
|
|
|
85
|
|
|
# POST /admins/ban/:user_uid |
86
|
|
|
def ban_user |
87
|
|
|
@user.roles = [] |
88
|
|
|
@user.add_role :denied |
89
|
|
|
redirect_to admins_path, flash: { success: I18n.t("administrator.flash.banned") } |
90
|
|
|
end |
91
|
|
|
|
92
|
|
|
# POST /admins/unban/:user_uid |
93
|
|
|
def unban_user |
94
|
|
|
@user.remove_role :denied |
95
|
|
|
@user.add_role :user |
96
|
|
|
redirect_to admins_path, flash: { success: I18n.t("administrator.flash.unbanned") } |
97
|
|
|
end |
98
|
|
|
|
99
|
|
|
# POST /admins/approve/:user_uid |
100
|
|
|
def approve |
101
|
|
|
@user.remove_role :pending |
102
|
|
|
|
103
|
|
|
send_user_approved_email(@user) |
104
|
|
|
|
105
|
|
|
redirect_to admins_path, flash: { success: I18n.t("administrator.flash.approved") } |
106
|
|
|
end |
107
|
|
|
|
108
|
|
|
# POST /admins/invite |
109
|
|
|
def invite |
110
|
|
|
email = params[:invite_user][:email] |
111
|
|
|
|
112
|
|
|
begin |
113
|
|
|
invitation = create_or_update_invite(email) |
114
|
|
|
|
115
|
|
|
send_invitation_email(current_user.name, email, invitation.invite_token) |
116
|
|
|
rescue => e |
117
|
|
|
logger.error "Error in email delivery: #{e}" |
118
|
|
|
flash[:alert] = I18n.t(params[:message], default: I18n.t("delivery_error")) |
119
|
|
|
else |
120
|
|
|
flash[:success] = I18n.t("administrator.flash.invite", email: email) |
121
|
|
|
end |
122
|
|
|
|
123
|
|
|
redirect_to admins_path |
124
|
|
|
end |
125
|
|
|
|
126
|
|
|
# SITE SETTINGS |
127
|
|
|
|
128
|
|
|
# POST /admins/branding |
129
|
|
|
def branding |
130
|
|
|
@settings.update_value("Branding Image", params[:url]) |
131
|
|
|
redirect_to admin_site_settings_path, flash: { success: I18n.t("administrator.flash.settings") } |
132
|
|
|
end |
133
|
|
|
|
134
|
|
|
# POST /admins/color |
135
|
|
|
def coloring |
136
|
|
|
@settings.update_value("Primary Color", params[:color]) |
137
|
|
|
@settings.update_value("Primary Color Lighten", color_lighten(params[:color])) |
138
|
|
|
@settings.update_value("Primary Color Darken", color_darken(params[:color])) |
139
|
|
|
redirect_to admin_site_settings_path, flash: { success: I18n.t("administrator.flash.settings") } |
140
|
|
|
end |
141
|
|
|
|
142
|
|
View Code Duplication |
def coloring_lighten |
|
|
|
|
143
|
|
|
@settings.update_value("Primary Color Lighten", params[:color]) |
144
|
|
|
redirect_to admin_site_settings_path, flash: { success: I18n.t("administrator.flash.settings") } |
145
|
|
|
end |
146
|
|
|
|
147
|
|
View Code Duplication |
def coloring_darken |
|
|
|
|
148
|
|
|
@settings.update_value("Primary Color Darken", params[:color]) |
149
|
|
|
redirect_to admin_site_settings_path, flash: { success: I18n.t("administrator.flash.settings") } |
150
|
|
|
end |
151
|
|
|
|
152
|
|
|
# POST /admins/room_authentication |
153
|
|
|
def room_authentication |
154
|
|
|
@settings.update_value("Room Authentication", params[:value]) |
155
|
|
|
redirect_to admin_site_settings_path, flash: { success: I18n.t("administrator.flash.settings") } |
156
|
|
|
end |
157
|
|
|
|
158
|
|
|
# POST /admins/registration_method/:method |
159
|
|
|
def registration_method |
160
|
|
|
new_method = Rails.configuration.registration_methods[params[:method].to_sym] |
161
|
|
|
|
162
|
|
|
# Only allow change to Join by Invitation if user has emails enabled |
163
|
|
|
if !Rails.configuration.enable_email_verification && new_method == Rails.configuration.registration_methods[:invite] |
164
|
|
|
redirect_to admin_site_settings_path, |
165
|
|
|
flash: { alert: I18n.t("administrator.flash.invite_email_verification") } |
166
|
|
|
else |
167
|
|
|
@settings.update_value("Registration Method", new_method) |
168
|
|
|
redirect_to admin_site_settings_path, |
169
|
|
|
flash: { success: I18n.t("administrator.flash.registration_method_updated") } |
170
|
|
|
end |
171
|
|
|
end |
172
|
|
|
|
173
|
|
|
# POST /admins/room_limit |
174
|
|
|
def room_limit |
175
|
|
|
@settings.update_value("Room Limit", params[:limit]) |
176
|
|
|
redirect_to admin_site_settings_path, flash: { success: I18n.t("administrator.flash.settings") } |
177
|
|
|
end |
178
|
|
|
|
179
|
|
|
# POST /admins/default_recording_visibility |
180
|
|
|
def default_recording_visibility |
181
|
|
|
@settings.update_value("Default Recording Visibility", params[:visibility]) |
182
|
|
|
redirect_to admins_path, flash: { success: I18n.t("administrator.flash.settings") + ". " + |
183
|
|
|
I18n.t("administrator.site_settings.recording_visibility.warning") } |
184
|
|
|
end |
185
|
|
|
|
186
|
|
|
private |
187
|
|
|
|
188
|
|
|
def find_user |
189
|
|
|
@user = User.where(uid: params[:user_uid]).includes(:roles).first |
190
|
|
|
end |
191
|
|
|
|
192
|
|
|
def find_setting |
193
|
|
|
@settings = Setting.find_or_create_by!(provider: user_settings_provider) |
194
|
|
|
end |
195
|
|
|
|
196
|
|
|
def verify_admin_of_user |
197
|
|
|
redirect_to admins_path, |
198
|
|
|
flash: { alert: I18n.t("administrator.flash.unauthorized") } unless current_user.admin_of?(@user) |
199
|
|
|
end |
200
|
|
|
|
201
|
|
|
# Gets the list of users based on your configuration |
202
|
|
|
def user_list |
203
|
|
|
initial_list = if current_user.has_cached_role? :super_admin |
204
|
|
|
User.where.not(id: current_user.id).includes(:roles) |
205
|
|
|
else |
206
|
|
|
User.without_role(:super_admin).where.not(id: current_user.id).includes(:roles) |
207
|
|
|
end |
208
|
|
|
|
209
|
|
|
if Rails.configuration.loadbalanced_configuration |
210
|
|
|
initial_list.where(provider: user_settings_provider) |
211
|
|
|
.admins_search(@search, @role) |
212
|
|
|
.admins_order(@order_column, @order_direction) |
213
|
|
|
else |
214
|
|
|
initial_list.admins_search(@search, @role) |
215
|
|
|
.admins_order(@order_column, @order_direction) |
216
|
|
|
end |
217
|
|
|
end |
218
|
|
|
|
219
|
|
|
# Creates the invite if it doesn't exist, or updates the updated_at time if it does |
220
|
|
|
def create_or_update_invite(email) |
221
|
|
|
invite = Invitation.find_by(email: email, provider: @user_domain) |
222
|
|
|
|
223
|
|
|
# Invite already exists |
224
|
|
|
if invite.present? |
225
|
|
|
# Updates updated_at to now |
226
|
|
|
invite.touch |
227
|
|
|
else |
228
|
|
|
# Creates invite |
229
|
|
|
invite = Invitation.create(email: email, provider: @user_domain) |
230
|
|
|
end |
231
|
|
|
|
232
|
|
|
invite |
233
|
|
|
end |
234
|
|
|
end |
235
|
|
|
|