Home rooms are created for all users with role if can_create_rooms is enabled (#1694)

This commit is contained in:
Ahmad Farhat
2020-05-28 14:48:18 -04:00
committed by GitHub
parent 5e4fe3b306
commit fe363e742b
3 changed files with 35 additions and 5 deletions

View File

@ -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

View File

@ -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