Skip to content

OF-2549: Fix JavaScript error and improve UX in MUC Create Permission page#3239

Open
MilanTyagi2004 wants to merge 3 commits into
igniterealtime:mainfrom
MilanTyagi2004:OF-2549
Open

OF-2549: Fix JavaScript error and improve UX in MUC Create Permission page#3239
MilanTyagi2004 wants to merge 3 commits into
igniterealtime:mainfrom
MilanTyagi2004:OF-2549

Conversation

@MilanTyagi2004
Copy link
Copy Markdown
Collaborator

@MilanTyagi2004 MilanTyagi2004 commented Apr 2, 2026

This PR resolves a JavaScript error (Uncaught TypeError: Cannot read properties of undefined (reading 'focus')) on the MUC room creation permissions page and enhances the user interface to be more responsive.

Root Cause
The error was caused by a scope conflict where a radio button tried to focus an input field (userJID) located in a separate form. Additionally, the target field was often missing from the DOM because it was only rendered by the server when the room creation restriction was already enabled.

Changes

  • Dynamic Visibility: Replaced server-side JSP conditional rendering with client-side CSS toggling (display: block/none) for the "Allowed Users" section .

  • Robust Event Handling: Introduced a toggleAllowedUsers() JavaScript function to manage visibility and safely apply focus only when the element is available.

  • Improved UX: The "Allowed Users" section now appears or disappears immediately upon selecting a policy, without requiring a page reload.

  • Code Cleanup: Removed redundant and broken inline onclick handlers from JID and Group selection fields that were using incorrect this.form references.

Verification

  • Verified that the "Allowed Users" section shows/hides correctly on toggle.
  • Confirmed that the JID input field is automatically focused when "Only specific..." is selected.
  • Manually tested that no JavaScript errors are thrown in the browser console.
  • Ensured that "Add" and "Delete" actions still persist correctly after the UI changes.

Comment thread xmppserver/src/main/webapp/muc-create-permission.jsp Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the admin console MUC room creation permissions page to eliminate a JavaScript focus error and make the “Allowed Users” section respond immediately to policy selection without requiring a reload.

Changes:

  • Adds toggleAllowedUsers() to show/hide the Allowed Users UI and conditionally focus the JID input.
  • Replaces server-side conditional rendering of the Allowed Users section with always-rendered markup that is toggled via CSS display.
  • Removes broken inline click handlers that referenced the wrong form scope.
Comments suppressed due to low confidence (1)

xmppserver/src/main/webapp/muc-create-permission.jsp:252

  • The visibility of allowedUsersContainer is rendered from mucService.isRoomCreationRestricted(), but the new UI toggles it client-side based on the radio selection. If an admin selects “Only specific…” (shows the section) and then submits the Add/checkbox form, the server redirect can re-render with isRoomCreationRestricted()==false, hiding the section again even though the user just interacted with it. Consider persisting the selected policy across these submits (e.g., include/openPerms as a hidden field in the add form and/or derive initial display from a request param), or prevent using the Allowed Users form until the policy is saved.
<div id="allowedUsersContainer" style="display: <%= (mucService.isRoomCreationRestricted() ? "block" : "none") %>">
<!-- BEGIN 'Allowed Users' -->
<form action="muc-create-permission.jsp?add" method="post">
    <input type="hidden" name="csrf" value="${csrf}">
    <input type="hidden" name="mucname" value="<%= StringUtils.escapeForXML(mucname) %>" />
    <div class="jive-contentBoxHeader">

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread xmppserver/src/main/webapp/muc-create-permission.jsp Outdated
@MilanTyagi2004
Copy link
Copy Markdown
Collaborator Author

MilanTyagi2004 commented Apr 4, 2026

@guusdk changes are done, now this PR is okay to merge.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

xmppserver/src/main/webapp/muc-create-permission.jsp:252

  • With the Allowed Users form always present in the DOM, it’s now possible to select “Only specific…” (without submitting the Save form) and submit the Add form. The server-side add handler does not enable setRoomCreationRestricted(true), and after the redirect the page will revert to the current service setting (potentially hiding the Allowed Users section), which can make the Add appear to “disappear” and can leave configuration in an inconsistent/unclear state. Consider either preventing Add/Delete unless the service is restricted, or persisting/applying the policy choice when performing Add/Delete (eg submit the Save form automatically, or include/handle a policy param in the Add/Delete actions).
<div id="allowedUsersContainer" style="display: <%= (mucService.isRoomCreationRestricted() ? "block" : "none") %>">
<!-- BEGIN 'Allowed Users' -->
<form action="muc-create-permission.jsp?add" method="post">
    <input type="hidden" name="csrf" value="${csrf}">
    <input type="hidden" name="mucname" value="<%= StringUtils.escapeForXML(mucname) %>" />
    <div class="jive-contentBoxHeader">

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread xmppserver/src/main/webapp/muc-create-permission.jsp
@guusdk
Copy link
Copy Markdown
Member

guusdk commented Apr 6, 2026

Hi @MilanTyagi2004 - I wonder if something is broken.

When I open the page, and select "Only specific users/groups can create a chat room", and fill out a username, like below:
image

If I then press the 'add' button, then I get a 'success' message, but the option "Anyone can create a chat room" is selected.

image

You would expect the option "Only specific users/groups can create a chat room" to be selected!

Can you please fix this?

Copy link
Copy Markdown
Member

@guusdk guusdk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(as mentioned in my previous commit: the setting no longer seems to be saved correctly).

@MilanTyagi2004
Copy link
Copy Markdown
Collaborator Author

sure i will do this and squash commits into one commit.

@MilanTyagi2004
Copy link
Copy Markdown
Collaborator Author

image

i fix this, now it is working fine.

@MilanTyagi2004
Copy link
Copy Markdown
Collaborator Author

hi @guusdk,
once you review these changes, then i will squash the commits into one.

@MilanTyagi2004
Copy link
Copy Markdown
Collaborator Author

I squashes all the commits into one with all description.

@MilanTyagi2004 MilanTyagi2004 requested a review from guusdk April 14, 2026 06:31
@MilanTyagi2004
Copy link
Copy Markdown
Collaborator Author

@Fishbowler if you are not busy could you please review this.

@Fishbowler Fishbowler self-requested a review April 15, 2026 07:00
@Fishbowler
Copy link
Copy Markdown
Member

When I pick All Registered Users...

image

...it's cleared on save

image

Copy link
Copy Markdown
Member

@Fishbowler Fishbowler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note the issue above. I suspect this might be pre-existing, but I haven't checked.
Added one nitpick below.

<meta name="helpPage" content="set_group_chat_room_creation_permissions.html"/>
<script>
function toggleAllowedUsers() {
const isRestricted = document.getElementById('rb02').checked;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're gonna use the ID in JS, would renaming the ID to something more friendly make sense?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for review,
i will look into this.

@MilanTyagi2004
Copy link
Copy Markdown
Collaborator Author

MilanTyagi2004 commented May 7, 2026

@Fishbowler
image

request changes are fixed,
please review them when you have time.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 7, 2026

Review Change Stack
No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 65b4f507-6332-4e92-a324-7bb21c28bf0e

📥 Commits

Reviewing files that changed from the base of the PR and between b675c64 and c828328.

📒 Files selected for processing (1)
  • xmppserver/src/main/webapp/muc-create-permission.jsp
🚧 Files skipped from review as they are similar to previous changes (1)
  • xmppserver/src/main/webapp/muc-create-permission.jsp

📝 Walkthrough

Walkthrough

This JSP page refactors MUC room-creation permission handling to persist the allow-all-registered-users setting server-side and replace server-side JSP conditionals with client-side visibility toggling. The form now uses a hidden field to synchronize checkbox state, permission radios trigger visibility changes via JavaScript, and userJID values are XML-escaped. Copyright year updated to 2026.

Changes

MUC Room Creation Permission Refactoring

Layer / File(s) Summary
Maintenance
xmppserver/src/main/webapp/muc-create-permission.jsp
Copyright year range updated from 2017-2025 to 2017-2026.
Form State Structure
xmppserver/src/main/webapp/muc-create-permission.jsp
Hidden allowAllRegisteredUsersHidden input field added to preserve allow-all-registered-users permission state across form submissions.
Server-Side Permission Persistence
xmppserver/src/main/webapp/muc-create-permission.jsp
Save/open-perms handler now calls setAllRegisteredUsersAllowedToCreate(allowAllRegisteredUsers) in restricted mode. Add handler applies same setting before forcing setRoomCreationRestricted(true).
Client-Side Helper Functions
xmppserver/src/main/webapp/muc-create-permission.jsp
JavaScript functions added: toggleAllowedUsers() controls visibility of allowed-users container based on permission radio state; syncAllowAllRegistered() copies visible checkbox value into hidden field.
Form Markup & Event Wiring
xmppserver/src/main/webapp/muc-create-permission.jsp
Permission radio buttons now trigger toggleAllowedUsers() via onchange. Allowed-users container replaces server-side JSP conditional. Checkbox includes onchange syncing to hidden field. Multi-select JIDs click handler removed. User JID input rendered with XML-escaping and empty-string fallback. Container closing tag updated.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 A form takes shape with hidden might,
Permissions dance in JavaScripted light,
Server and client, now hand in hand,
With checkboxes synced as the code commands—
And copyright rolls to twenty-twenty-six! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description check ✅ Passed The PR description clearly relates to the changeset by detailing the JavaScript error fix, root cause analysis, and specific client/server-side changes made to the MUC creation permissions page.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


Comment @coderabbitai help to get the list of available commands and usage tips.

- Fix issue where "Only specific users/groups" selection was not preserved after adding users by ensuring roomCreationRestricted is set correctly
- Replace onclick with onchange on radio buttons to improve accessibility and ensure proper event handling
- Remove auto-submit from "allow all registered users" checkbox to prevent unintended state resets
- Improve UI responsiveness by correctly toggling Allowed Users section without page reload
- Clean up JavaScript handling for safer focus behavior
The 'All registered users' checkbox was in the 'Add' form but not in the 'Save Settings' form. When the user checked the checkbox and clicked 'Save Settings', the value was never submitted, causing it to revert to unchecked on page reload.

- Add hidden input for allowAllRegisteredUsers in the Save Settings form

- Sync visible checkbox state to the hidden input via JavaScript

- Persist allowAllRegisteredUsers in the save handler's restricted branch

- Rename radio button id to restrictedPermissionsRadio for clarity
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
xmppserver/src/main/webapp/muc-create-permission.jsp (2)

240-245: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Fix the label target for the restricted radio option.

Line 245 still points to rb02, but the input id is now restrictedPermissionsRadio. Clicking the label will no longer select the radio or trigger the visibility toggle.

Suggested fix
-                    <label for="rb02"><fmt:message key="muc.create.permission.specific_created" /></label>
+                    <label for="restrictedPermissionsRadio"><fmt:message key="muc.create.permission.specific_created" /></label>
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@xmppserver/src/main/webapp/muc-create-permission.jsp` around lines 240 - 245,
The label's for attribute is still pointing to "rb02" instead of the radio
input's id "restrictedPermissionsRadio", so update the label element associated
with the restricted option in muc-create-permission.jsp to use
for="restrictedPermissionsRadio" (so clicking the label selects the input and
triggers toggleAllowedUsers()); ensure the label that currently references rb02
is the one next to the input with id "restrictedPermissionsRadio" and change it
accordingly.

76-92: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Swap the audit log messages in the save branches.

These messages are inverted relative to the state being applied: the openPerms branch disables restriction, while the else branch enables it. Leaving this as-is will make the admin audit trail misleading.

Suggested fix
         if (openPerms) {
             // Remove all users who have the ability to create rooms
             for (JID user : mucService.getUsersAllowedToCreate()) {
                 mucService.removeUserAllowedToCreate(user);
             }
             mucService.setRoomCreationRestricted(false);
             // Log the event
-            webManager.logEvent("set MUC room creation to restricted for service "+mucname, null);
+            webManager.logEvent("set MUC room creation to not restricted for service "+mucname, null);
             response.sendRedirect("muc-create-permission.jsp?success=true&mucname="+URLEncoder.encode(mucname, StandardCharsets.UTF_8));
             return;
         }
         else {
             mucService.setRoomCreationRestricted(true);
             mucService.setAllRegisteredUsersAllowedToCreate(allowAllRegisteredUsers);
             // Log the event
-            webManager.logEvent("set MUC room creation to not restricted for service "+mucname, null);
+            webManager.logEvent("set MUC room creation to restricted for service "+mucname, null);
             response.sendRedirect("muc-create-permission.jsp?success=true&mucname="+URLEncoder.encode(mucname, StandardCharsets.UTF_8));
             return;
         }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@xmppserver/src/main/webapp/muc-create-permission.jsp` around lines 76 - 92,
The audit log messages are inverted: in the openPerms branch you call
mucService.setRoomCreationRestricted(false) but log "set MUC room creation to
restricted...", and in the else branch you set setRoomCreationRestricted(true)
but log "to not restricted...". Swap or correct the log message strings used in
the webManager.logEvent calls so the message matches the action performed (i.e.,
when calling mucService.setRoomCreationRestricted(false) log that room creation
was set to not restricted/open, and when calling setRoomCreationRestricted(true)
log that room creation was set to restricted/closed); update the two
webManager.logEvent(...) calls near the openPerms conditional to reflect the
correct state.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@xmppserver/src/main/webapp/muc-create-permission.jsp`:
- Around line 240-245: The label's for attribute is still pointing to "rb02"
instead of the radio input's id "restrictedPermissionsRadio", so update the
label element associated with the restricted option in muc-create-permission.jsp
to use for="restrictedPermissionsRadio" (so clicking the label selects the input
and triggers toggleAllowedUsers()); ensure the label that currently references
rb02 is the one next to the input with id "restrictedPermissionsRadio" and
change it accordingly.
- Around line 76-92: The audit log messages are inverted: in the openPerms
branch you call mucService.setRoomCreationRestricted(false) but log "set MUC
room creation to restricted...", and in the else branch you set
setRoomCreationRestricted(true) but log "to not restricted...". Swap or correct
the log message strings used in the webManager.logEvent calls so the message
matches the action performed (i.e., when calling
mucService.setRoomCreationRestricted(false) log that room creation was set to
not restricted/open, and when calling setRoomCreationRestricted(true) log that
room creation was set to restricted/closed); update the two
webManager.logEvent(...) calls near the openPerms conditional to reflect the
correct state.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: ed1f8652-7695-4990-9c85-9c83eb33197c

📥 Commits

Reviewing files that changed from the base of the PR and between 0842223 and d1a380b.

📒 Files selected for processing (3)
  • build/ci/updater/pom.xml
  • xmppserver/pom.xml
  • xmppserver/src/main/webapp/muc-create-permission.jsp

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
xmppserver/src/main/webapp/muc-create-permission.jsp (1)

240-245: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Broken label association after radio button ID rename.

Line 240 renames the second radio from rb02 to restrictedPermissionsRadio, but the corresponding <label> on line 245 still references for="rb02". No element with id="rb02" exists in the DOM, so clicking the label text no longer selects the radio button.

🐛 Proposed fix
-                    <label for="rb02"><fmt:message key="muc.create.permission.specific_created" /></label>
+                    <label for="restrictedPermissionsRadio"><fmt:message key="muc.create.permission.specific_created" /></label>
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@xmppserver/src/main/webapp/muc-create-permission.jsp` around lines 240 - 245,
The label's for attribute no longer matches the radio button id after renaming
the radio to restrictedPermissionsRadio, breaking click-to-select; update the
<label> that currently uses for="rb02" to use for="restrictedPermissionsRadio"
so it targets the input with id="restrictedPermissionsRadio" (leave
name="openPerms" and onchange="toggleAllowedUsers()" unchanged).
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@xmppserver/src/main/webapp/muc-create-permission.jsp`:
- Around line 240-245: The label's for attribute no longer matches the radio
button id after renaming the radio to restrictedPermissionsRadio, breaking
click-to-select; update the <label> that currently uses for="rb02" to use
for="restrictedPermissionsRadio" so it targets the input with
id="restrictedPermissionsRadio" (leave name="openPerms" and
onchange="toggleAllowedUsers()" unchanged).

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: fa99d316-6dd1-4f8f-9970-90ec0f695493

📥 Commits

Reviewing files that changed from the base of the PR and between d1a380b and b675c64.

📒 Files selected for processing (1)
  • xmppserver/src/main/webapp/muc-create-permission.jsp

@MilanTyagi2004 MilanTyagi2004 requested a review from Fishbowler May 8, 2026 16:05
Copy link
Copy Markdown
Member

@Fishbowler Fishbowler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! I've pushed one commit to do a label rename to match an id rename.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants