Skip to content

fix: Hide 'Create New' button when user has no creation permissions#41334

Open
prathamesh04 wants to merge 2 commits into
RocketChat:developfrom
prathamesh04:fix/hide-create-new-without-perms
Open

fix: Hide 'Create New' button when user has no creation permissions#41334
prathamesh04 wants to merge 2 commits into
RocketChat:developfrom
prathamesh04:fix/hide-create-new-without-perms

Conversation

@prathamesh04

@prathamesh04 prathamesh04 commented Jul 13, 2026

Copy link
Copy Markdown

Issue

Fixes #40731

Description

When a user has no permissions to create any resources (channel, team, discussion, DM), the "Create New" button in the sidebar navbar was still being rendered in a disabled state, causing unnecessary UI clutter.

Changes

  • Added an early return in NavBarItemCreateNew.tsx to render null when the sections array is empty
  • This ensures the button is completely hidden rather than shown as disabled

How to test

  1. Create a user with no creation permissions
  2. Verify the "+" (Create New) button is not visible in the sidebar
  3. Create a user with at least one creation permission
  4. Verify the button appears and works normally

Review in cubic

Summary by CodeRabbit

  • Bug Fixes
    • Prevented the “Create New” navbar menu from appearing when there are no available options.
    • Updated the “Create New” behavior so it’s hidden when creation permissions are not granted, rather than showing an empty/disabled menu state.
    • Improved menu rendering by ensuring only meaningful menu sections are produced and displayed.

@prathamesh04 prathamesh04 requested a review from a team as a code owner July 13, 2026 06:55
@dionisio-bot

dionisio-bot Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Looks like this PR is not ready to merge, because of the following issues:

  • This PR is missing the 'stat: QA assured' label
  • This PR is missing the required milestone or project

Please fix the issues and try again

If you have any trouble, please check the PR guidelines

@changeset-bot

changeset-bot Bot commented Jul 13, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 8a2a13e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@rocket.chat/meteor Patch
@rocket.chat/core-typings Patch
@rocket.chat/rest-typings Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 236f1b3b-f05c-4d68-b025-a12068586df7

📥 Commits

Reviewing files that changed from the base of the PR and between f3a119c and 8a2a13e.

📒 Files selected for processing (3)
  • .changeset/hide-create-new-no-perms.md
  • apps/meteor/client/navbar/NavBarPagesGroup/hooks/useCreateNewMenu.ts
  • packages/ui-client/src/components/GenericMenu/GenericMenu.tsx
💤 Files with no reviewable changes (1)
  • packages/ui-client/src/components/GenericMenu/GenericMenu.tsx
📜 Recent review details
⏰ Context from checks skipped due to timeout. (1)
  • GitHub Check: cubic · AI code reviewer
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx,js}

📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)

**/*.{ts,tsx,js}: Write concise, technical TypeScript/JavaScript with accurate typing in Playwright tests
Avoid code comments in the implementation

Files:

  • apps/meteor/client/navbar/NavBarPagesGroup/hooks/useCreateNewMenu.ts
🧠 Learnings (6)
📚 Learning: 2026-02-10T16:32:42.586Z
Learnt from: tassoevan
Repo: RocketChat/Rocket.Chat PR: 38528
File: apps/meteor/client/startup/roles.ts:14-14
Timestamp: 2026-02-10T16:32:42.586Z
Learning: In Rocket.Chat's Meteor client code, DDP streams use EJSON and Date fields arrive as Date objects; do not manually construct new Date() in stream handlers (for example, in sdk.stream()). Only REST API responses return plain JSON where dates are strings, so implement explicit conversion there if needed. Apply this guidance to all TypeScript files under apps/meteor/client to ensure consistent date handling in DDP streams and REST responses.

Applied to files:

  • apps/meteor/client/navbar/NavBarPagesGroup/hooks/useCreateNewMenu.ts
📚 Learning: 2026-05-11T20:30:35.265Z
Learnt from: tassoevan
Repo: RocketChat/Rocket.Chat PR: 40480
File: apps/meteor/client/meteor/startup/accounts.ts:59-61
Timestamp: 2026-05-11T20:30:35.265Z
Learning: In Rocket.Chat’s Meteor client code, when calling `dispatchToastMessage` with `{ type: 'error' }`, pass the raw caught error object as `message` without manual normalization. `dispatchToastMessage` is designed to accept `message: unknown` for error toasts, so avoid converting errors to strings (e.g., `String(error)`) or extracting `error.message` before passing them.

Applied to files:

  • apps/meteor/client/navbar/NavBarPagesGroup/hooks/useCreateNewMenu.ts
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In the Rocket.Chat repository, do not reference Biome lint rules in code review feedback. Biome is not used even if biome.json exists; only reference Biome rules if there is explicit, project-wide usage documented. For TypeScript files, review lint implications without Biome guidance unless the project enables Biome rules.

Applied to files:

  • apps/meteor/client/navbar/NavBarPagesGroup/hooks/useCreateNewMenu.ts
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In this repository (RocketChat/Rocket.Chat), Biome lint rules are not used even if a biome.json exists. When reviewing TypeScript files (e.g., packages/ui-voip/src/providers/useMediaSession.ts), ensure lint suggestions do not reference Biome-specific rules. Rely on general ESLint/TypeScript lint rules and project conventions instead.

Applied to files:

  • apps/meteor/client/navbar/NavBarPagesGroup/hooks/useCreateNewMenu.ts
📚 Learning: 2026-05-06T12:21:44.083Z
Learnt from: juliajforesti
Repo: RocketChat/Rocket.Chat PR: 40256
File: apps/meteor/client/components/CreateDiscussion/CreateDiscussion.tsx:121-149
Timestamp: 2026-05-06T12:21:44.083Z
Learning: Field wrappers in rocket.chat/fuselage-forms (Field, FieldLabel, FieldRow, FieldError, FieldHint) auto-create htmlFor/id associations, aria-describedby, and role="alert" for errors. Do not manually set htmlFor, id, aria-describedby, or role attributes when using these wrappers. This automatic wiring does not apply to plain rocket.chat/fuselage components, which require explicit ID wiring per the accessibility docs. In code reviews, prefer using fuselage-forms wrappers for form fields and verify there is no unnecessary manual ID/aria wiring in files that use these wrappers. If a component uses plain fuselage components, ensure proper id wiring as per docs.

Applied to files:

  • apps/meteor/client/navbar/NavBarPagesGroup/hooks/useCreateNewMenu.ts
📚 Learning: 2026-03-16T21:50:37.589Z
Learnt from: amitb0ra
Repo: RocketChat/Rocket.Chat PR: 39676
File: .changeset/migrate-users-register-openapi.md:3-3
Timestamp: 2026-03-16T21:50:37.589Z
Learning: For changes related to OpenAPI migrations in Rocket.Chat/OpenAPI, when removing endpoint types and validators from rocket.chat/rest-typings (e.g., UserRegisterParamsPOST, /v1/users.register) document this as a minor changeset (not breaking) per RocketChat/Rocket.Chat-Open-API#150 Rule 7. Note that the endpoint type is re-exposed via a module augmentation .d.ts in the consuming package (e.g., packages/web-ui-registration/src/users-register.d.ts). In reviews, ensure the changeset clearly states: this is a non-breaking change, the major version should not be bumped, and the changeset reflects a minor version bump. Do not treat this as a breaking change during OpenAPI migrations.

Applied to files:

  • .changeset/hide-create-new-no-perms.md
🔇 Additional comments (2)
apps/meteor/client/navbar/NavBarPagesGroup/hooks/useCreateNewMenu.ts (1)

10-12: LGTM!

.changeset/hide-create-new-no-perms.md (1)

1-5: LGTM!


Walkthrough

The create-new menu now filters out empty sections and returns null when no creation actions are available, hiding the navbar button. The GenericMenu section type no longer includes permission metadata.

Changes

Create menu visibility

Layer / File(s) Summary
Filter unavailable menu sections
apps/meteor/client/navbar/NavBarPagesGroup/hooks/useCreateNewMenu.ts, packages/ui-client/src/components/GenericMenu/GenericMenu.tsx
Menu sections are filtered by item availability, and the unused permission field is removed from the section prop type.
Empty menu render guard
apps/meteor/client/navbar/NavBarPagesGroup/NavBarItemCreateNew.tsx, .changeset/hide-create-new-no-perms.md
The navbar item returns null when no sections remain, with a patch changeset documenting the behavior.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested labels: type: bug

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and accurately summarizes the main change: hiding the Create New button when users lack creation permissions.
Linked Issues check ✅ Passed The PR hides the Create New button when no creation sections exist, matching #40731's requirement to hide it for users with no creation actions.
Out of Scope Changes check ✅ Passed The changes are tightly scoped to the navbar create-menu behavior and related type cleanup; no unrelated functionality is introduced.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No issues found across 1 file

Re-trigger cubic

- Fix useCreateNewMenu to filter sections by items.length instead of
  a broad permission check that always includes create-d
- Remove unused permission field from GenericMenu sections type
- Return null from NavBarItemCreateNew when sections are empty
- Add changeset
@prathamesh04

prathamesh04 commented Jul 13, 2026

Copy link
Copy Markdown
Author

Hi @tassoevan @juliajforesti @dougfabris — this PR fixes the issue where the "Create New" button stays visible even when a user has zero creation permissions.

The root cause was that used a broad permission check (including create-d which all users have) instead of checking whether there are actual items to display. The fix filters sections by items.length > 0 and returns null from the component when empty.

I've attached a video walkthrough demonstrating the fix locally. Happy to address any feedback!

Screencast.from.2026-07-13.16-14-48.webm

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create button remains visible when user has no creation permissions

1 participant