forked from External/greenlight
GRN2-128: Added the ability to manage rooms (#848)
* Added the ability to manage rooms * Small fixes * Fixed travis complaints * Fixed issues with role permissions * Fixed issue with delete room * Fixed rubocop and added testcases
This commit is contained in:
committed by
farhatahmad
parent
984e5cc085
commit
09de6b6739
@ -27,7 +27,7 @@ class Ability
|
||||
else
|
||||
highest_role = user.highest_priority_role
|
||||
if highest_role.get_permission("can_edit_site_settings")
|
||||
can [:index, :site_settings, :server_recordings, :update_settings, :coloring, :registration_method], :admin
|
||||
can [:index, :site_settings, :update_settings, :coloring, :registration_method], :admin
|
||||
end
|
||||
|
||||
if highest_role.get_permission("can_edit_roles")
|
||||
@ -39,8 +39,12 @@ class Ability
|
||||
:approve, :invite, :reset, :undelete], :admin
|
||||
end
|
||||
|
||||
if highest_role.get_permission("can_manage_rooms_recordings")
|
||||
can [:index, :server_recordings, :server_rooms], :admin
|
||||
end
|
||||
|
||||
if !highest_role.get_permission("can_edit_site_settings") && !highest_role.get_permission("can_edit_roles") &&
|
||||
!highest_role.get_permission("can_manage_users")
|
||||
!highest_role.get_permission("can_manage_users") && !highest_role.get_permission("can_manage_rooms_recordings")
|
||||
cannot :manage, AdminsController
|
||||
end
|
||||
end
|
||||
|
@ -68,6 +68,7 @@ class Role < ApplicationRecord
|
||||
update_permission("can_edit_site_settings", permissions[:can_edit_site_settings].to_s)
|
||||
update_permission("can_edit_roles", permissions[:can_edit_roles].to_s)
|
||||
update_permission("can_manage_users", permissions[:can_manage_users].to_s)
|
||||
update_permission("can_manage_rooms_recordings", permissions[:can_manage_rooms_recordings].to_s)
|
||||
end
|
||||
|
||||
# Updates the value of the permission and enables it
|
||||
|
@ -27,6 +27,34 @@ class Room < ApplicationRecord
|
||||
|
||||
belongs_to :owner, class_name: 'User', foreign_key: :user_id
|
||||
|
||||
def self.admins_search(string)
|
||||
active_database = Rails.configuration.database_configuration[Rails.env]["adapter"]
|
||||
# Postgres requires created_at to be cast to a string
|
||||
created_at_query = if active_database == "postgresql"
|
||||
"created_at::text"
|
||||
else
|
||||
"created_at"
|
||||
end
|
||||
|
||||
search_query = "rooms.name LIKE :search OR rooms.uid LIKE :search OR users.email LIKE :search" \
|
||||
" OR users.#{created_at_query} LIKE :search"
|
||||
|
||||
search_param = "%#{string}%"
|
||||
|
||||
joins(:owner).where(search_query, search: search_param)
|
||||
end
|
||||
|
||||
def self.admins_order(column, direction)
|
||||
# Include the owner of the table
|
||||
table = joins(:owner)
|
||||
|
||||
if table.column_names.include?(column) || column == "users.name"
|
||||
return table.order(Arel.sql("#{column} #{direction}"))
|
||||
end
|
||||
|
||||
table
|
||||
end
|
||||
|
||||
# Determines if a user owns a room.
|
||||
def owned_by?(user)
|
||||
return false if user.nil?
|
||||
|
Reference in New Issue
Block a user