forked from External/greenlight
Home rooms are created for all users with role if can_create_rooms is enabled (#1694)
This commit is contained in:
@ -146,6 +146,18 @@ module Rolify
|
||||
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
|
||||
|
@ -198,6 +198,11 @@ class User < ApplicationRecord
|
||||
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.
|
||||
@ -227,11 +232,6 @@ class User < ApplicationRecord
|
||||
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
|
||||
|
Reference in New Issue
Block a user