Skip to content

Commit

Permalink
Merge commit '8355c59b00750e82822f0e9f67537a832baa15a3' into v2-infor…
Browse files Browse the repository at this point in the history
…matik

* commit '8355c59b00750e82822f0e9f67537a832baa15a3':
  Upgrade LDAP gem version (bigbluebutton#1700)
  Fixed room remove task (bigbluebutton#1695)
  Home rooms are created for all users with role if can_create_rooms is enabled (bigbluebutton#1694)
  Translate '/config/locales/en.yml' in 'zh_CN' (bigbluebutton#1683)
  Fixed user create rake task (bigbluebutton#1690)
  • Loading branch information
sawh committed May 30, 2020
2 parents 87ee88b + 8355c59 commit ea42758
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ gem 'omniauth-twitter'
gem 'omniauth-google-oauth2'
gem 'omniauth-bn-launcher', '~> 0.1.3'
gem 'net-ldap'
gem 'bn-ldap-authentication', '~> 0.1.2'
gem 'bn-ldap-authentication', '~> 0.1.3'
gem 'omniauth-bn-office365', '~> 0.1.1'

# BigBlueButton API wrapper.
Expand Down
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ GEM
bigbluebutton-api-ruby (1.7.0)
xml-simple (~> 1.1)
bindex (0.8.1)
bn-ldap-authentication (0.1.2)
bn-ldap-authentication (0.1.3)
net-ldap (~> 0)
bootsnap (1.4.6)
msgpack (~> 1.0)
Expand Down Expand Up @@ -337,7 +337,7 @@ DEPENDENCIES
action-cable-testing
bcrypt (~> 3.1.7)
bigbluebutton-api-ruby
bn-ldap-authentication (~> 0.1.2)
bn-ldap-authentication (~> 0.1.3)
bootsnap (>= 1.1.0)
bootstrap (~> 4.3.1)
byebug
Expand Down
12 changes: 12 additions & 0 deletions app/controllers/concerns/rolify.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,18 @@ def update_permissions(role)
role.update(colour: permission_params[:colour])
role.update_all_role_permissions(permission_params)

# Create home rooms for all users with this role if users with this role are now able to create rooms
create_home_rooms(role.name) if !role.get_permission("can_create_rooms") && permission_params["can_create_rooms"] == "true"

role.save!
end

private

# Create home rooms for users since they are now able to create rooms
def create_home_rooms(role_name)
User.with_role(role_name).each do |user|
user.create_home_room if user.main_room.nil?
end
end
end
10 changes: 5 additions & 5 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,11 @@ def self.without_role(role)
User.includes(:role).where.not(roles: { name: role })
end

def create_home_room
room = Room.create!(owner: self, name: I18n.t("home_room"))
update_attributes(main_room: room)
end

private

# Destory a users rooms when they are removed.
Expand Down Expand Up @@ -227,11 +232,6 @@ def check_if_email_can_be_blank
end
end

def create_home_room
room = Room.create!(owner: self, name: I18n.t("home_room"))
update_attributes(main_room: room)
end

def role_provider
Rails.configuration.loadbalanced_configuration ? provider : "greenlight"
end
Expand Down
21 changes: 20 additions & 1 deletion config/locales/zh_CN.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@ zh_CN:
placeholder: 品牌形象URL地址
title: 网站标志
invalid: 无效的URL
legal:
change: 更改URL
info: 更改页面底部显示的声明链接
placeholder: 合法URL...
title: 合法的
invalid: 无效的URL
privpolicy:
change: 更改URL
info: 更改页面底部显示的隐私策略链接
placeholder: 隐私政策URL...
title: 隐私政策
invalid: 无效的URL
cache:
info: 清除缓存,强制新请求获取已更新的信息
title: 清除网站缓存
Expand Down Expand Up @@ -145,9 +157,12 @@ zh_CN:
rooms:
title: 服务器所有会议室
table:
ended: "已结束: %{session}"
id: ID
not_running: 没有运行
participants: 参与者
running: 运行中
started: "已开始: %{session}"
status: 状态
view: 查看
title: 网站管理
Expand Down Expand Up @@ -245,6 +260,8 @@ zh_CN:
designs: 定制设计
authentication: 用户认证
footer:
legal: 合法的
privpolicy: 隐私政策
powered_by: "Powered by%{href}"
forgot_password:
subtitle: 忘记密码
Expand Down Expand Up @@ -367,7 +384,7 @@ zh_CN:
warning: 您将<b>无法</b> 恢复这个会议室
recording_warning: "或任意 %{recordings_num} 的相关录像"
invite_user:
email_placeholder: 输入用户的电子邮箱(用逗号分隔)
email_placeholder: 输入用户的电子邮件(用逗号分隔)
footer: 用户将收到一封电子邮件,其中包含如何注册的说明。
send: 发送邀请
title: 邀请用户
Expand Down Expand Up @@ -468,6 +485,7 @@ zh_CN:
remove: 删除
rename: 重命名
reset_password:
invalid_token: 密码重置令牌无效。请再次尝试重置密码。
subtitle: 重置密码
password: 新密码
confirm: 确认新密码
Expand Down Expand Up @@ -536,6 +554,7 @@ zh_CN:
roles: 用户角色
subtitle: 更新帐户信息
title: 帐户信息
reset_password: 重置用户密码
delete:
button: 我确定要删除我的帐户
disclaimer: 删除帐户后<b>无法</b>恢复。帐户所有相关信息都会被移除,包括设置、会议室和录像。
Expand Down
15 changes: 12 additions & 3 deletions lib/tasks/room.rake
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,19 @@ require 'bigbluebutton_api'
namespace :room do
desc "Removes all rooms for users that can't create rooms"
task :remove, [:include_used] => :environment do |_task, args|
roles = Role.where(role_permissions: { name: "can_create_rooms", value: "false" }).pluck(:name)
users = User.with_role(roles)
roles = Role.where(role_permissions: { name: "can_create_rooms", value: "false" }).pluck(:name, :priority)
other_roles = Role.where(role_permissions: { name: "can_create_rooms", value: "", enabled: "false" }).pluck(:name, :priority)

roles_without_rooms = roles + other_roles
roles_arr = []

roles_without_rooms.each do |role|
roles_arr << role[0]
end

users = User.with_role(roles_arr)
users.each do |user|
puts "Destroying #{user.uid} rooms"
puts "Destroying #{user.uid} rooms - role: #{user.role.name}"
user.rooms.each do |room|
if room.sessions.positive? && args[:include_used] != "true"
puts "Skipping room #{room.uid}"
Expand Down
10 changes: 5 additions & 5 deletions lib/tasks/user.rake
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ namespace :user do
exit
end

if u[:role] == "super_admin"
user.remove_role(:user)
user.set_role(:super_admin)
elsif u[:role] == "admin"
user.set_role(:admin)
unless Role.exists?(name: u[:role], provider: u[:provider])
puts "Invalid Role - Role does not exist"
exit
end

user.set_role(u[:role])

puts "Account succesfully created."
puts "Email: #{u[:email]}"
puts "Password: #{u[:password]}"
Expand Down
18 changes: 18 additions & 0 deletions spec/controllers/admins_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,24 @@
expect(new_role.get_permission("send_promoted_email")).to eq(false)
expect(response).to redirect_to admin_roles_path(selected_role: new_role.id)
end

it "creates the users home room if can_create_rooms is enabled" do
new_role = Role.create(name: "test2", priority: 2, provider: "provider1")
new_role.update_permission("can_create_rooms", "false")

@request.session[:user_id] = @admin.id

new_user = create(:user, role: new_role)
expect(new_user.role.get_permission("can_create_rooms")).to eq(false)
expect(new_user.main_room).to be_nil

patch :update_role, params: { role_id: new_role.id, role: { name: "test", can_create_rooms: true,
colour: "#45434" } }

new_user.reload
expect(new_user.role.get_permission("can_create_rooms")).to eq(true)
expect(new_user.main_room).not_to be_nil
end
end

context "DELETE delete_role" do
Expand Down

0 comments on commit ea42758

Please sign in to comment.