Enforce restriction to create new rooms

This commit is contained in:
David Heinemeier Hansson committed 2025-12-01 15:22:37 +01:00
1 parent f56e33e323
commit 15db4033bc
6 files changed
+31 -2

No files matched your search

@@ -3,6 +3,7 @@ class Rooms::ClosedsController < RoomsController
before_action :ensure_can_administer, only: %i[ update ]
before_action :remember_last_room_visited, only: :show
before_action :force_room_type, only: %i[ edit update ]
before_action :ensure_eligible_to_create_rooms, only: %i[ new create ]
DEFAULT_ROOM_NAME = "New room"
@@ -3,6 +3,7 @@ class Rooms::OpensController < RoomsController
before_action :ensure_can_administer, only: %i[ update ]
before_action :remember_last_room_visited, only: :show
before_action :force_room_type, only: %i[ edit update ]
before_action :ensure_eligible_to_create_rooms, only: %i[ new create ]
DEFAULT_ROOM_NAME = "New room"
+6
View File
@@ -31,6 +31,12 @@ class RoomsController < ApplicationController
head :forbidden unless Current.user.can_administer?(@room)
end
def ensure_eligible_to_create_rooms
if Current.account.restrict_room_creation_to_administrators? && !Current.user.administrator?
head :forbidden
end
end
def find_messages
messages = @room.messages.with_creator.with_attachment_details.with_boosts
+4 -2
View File
@@ -36,8 +36,10 @@
<% end %>
</div>
<%= link_to new_rooms_open_path, class: "rooms__new-btn btn room align-center gap txt-reversed", aria: { label: "New Chat Room" } do %>
<%= image_tag "add.svg", size: 20, aria: { hidden: "true" }, style: "view-transition-name: new-room" %>
<% if Current.user.administrator? || !Current.account.restrict_room_creation_to_administrators? %>
<%= link_to new_rooms_open_path, class: "rooms__new-btn btn room align-center gap txt-reversed", aria: { label: "New Chat Room" } do %>
<%= image_tag "add.svg", size: 20, aria: { hidden: "true" }, style: "view-transition-name: new-room" %>
<% end %>
<% end %>
</div>