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
|
|
|
authorize_resource class: false |
22
|
|
|
before_action :find_user, only: [:edit_user, :promote, :demote, :ban_user, :unban_user] |
23
|
|
|
before_action :verify_admin_of_user, only: [:edit_user, :promote, :demote, :ban_user, :unban_user] |
24
|
|
|
before_action :find_setting, only: [:branding, :coloring] |
25
|
|
|
|
26
|
|
|
# GET /admins |
27
|
|
|
def index |
28
|
|
|
@search = params[:search] || "" |
29
|
|
|
@order_column = params[:column] && params[:direction] != "none" ? params[:column] : "created_at" |
30
|
|
|
@order_direction = params[:direction] && params[:direction] != "none" ? params[:direction] : "DESC" |
31
|
|
|
puts @order_direction.to_s |
32
|
|
|
|
33
|
|
|
if Rails.configuration.loadbalanced_configuration |
34
|
|
|
@pagy, @users = pagy(User.without_role(:super_admin) |
35
|
|
|
.where(provider: user_settings_provider) |
36
|
|
|
.where.not(id: current_user.id) |
37
|
|
|
.admins_search(@search) |
38
|
|
|
.admins_order(@order_column, @order_direction)) |
39
|
|
|
else |
40
|
|
|
@pagy, @users = pagy(User.where.not(id: current_user.id) |
41
|
|
|
.admins_search(@search) |
42
|
|
|
.admins_order(@order_column, @order_direction)) |
43
|
|
|
end |
44
|
|
|
end |
45
|
|
|
|
46
|
|
|
# GET /admins/edit/:user_uid |
47
|
|
|
def edit_user |
48
|
|
|
render "admins/index", locals: { setting_id: "account" } |
49
|
|
|
end |
50
|
|
|
|
51
|
|
|
# POST /admins/promote/:user_uid |
52
|
|
|
def promote |
53
|
|
|
@user.add_role :admin |
54
|
|
|
redirect_to admins_path, flash: { success: I18n.t("administrator.flash.promoted") } |
55
|
|
|
end |
56
|
|
|
|
57
|
|
|
# POST /admins/demote/:user_uid |
58
|
|
|
def demote |
59
|
|
|
@user.remove_role :admin |
60
|
|
|
redirect_to admins_path, flash: { success: I18n.t("administrator.flash.demoted") } |
61
|
|
|
end |
62
|
|
|
|
63
|
|
|
# POST /admins/branding |
64
|
|
|
def branding |
65
|
|
|
@settings.update_value("Branding Image", params[:url]) |
66
|
|
|
redirect_to admins_path |
67
|
|
|
end |
68
|
|
|
|
69
|
|
|
# POST /admins/color |
70
|
|
|
def coloring |
71
|
|
|
@settings.update_value("Primary Color", params[:color]) |
72
|
|
|
redirect_to admins_path(setting: "site_settings") |
73
|
|
|
end |
74
|
|
|
|
75
|
|
|
# POST /admins/ban/:user_uid |
76
|
|
|
def ban_user |
77
|
|
|
@user.add_role :denied |
78
|
|
|
redirect_to admins_path, flash: { success: I18n.t("administrator.flash.banned") } |
79
|
|
|
end |
80
|
|
|
|
81
|
|
|
# POST /admins/unban/:user_uid |
82
|
|
|
def unban_user |
83
|
|
|
@user.remove_role :denied |
84
|
|
|
redirect_to admins_path, flash: { success: I18n.t("administrator.flash.unbanned") } |
85
|
|
|
end |
86
|
|
|
|
87
|
|
|
private |
88
|
|
|
|
89
|
|
|
def find_user |
90
|
|
|
@user = User.find_by!(uid: params[:user_uid]) |
91
|
|
|
end |
92
|
|
|
|
93
|
|
|
def find_setting |
94
|
|
|
@settings = Setting.find_or_create_by!(provider: user_settings_provider) |
95
|
|
|
end |
96
|
|
|
|
97
|
|
|
def verify_admin_of_user |
98
|
|
|
redirect_to admins_path, |
99
|
|
|
flash: { alert: I18n.t("administrator.flash.unauthorized") } unless current_user.admin_of?(@user) |
100
|
|
|
end |
101
|
|
|
end |
102
|
|
|
|