Skip to content

Commit

Permalink
Home rooms are created for all users with role if can_create_rooms is…
Browse files Browse the repository at this point in the history
… enabled (bigbluebutton#1694)
  • Loading branch information
farhatahmad authored and pull[bot] committed May 30, 2020
1 parent 2e7e312 commit b7a58cc
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
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
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 b7a58cc

Please sign in to comment.