Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Permit Administrators to use the API #427

Merged
merged 1 commit into from
Mar 26, 2025
Merged

Conversation

allouis
Copy link
Collaborator

@allouis allouis commented Mar 24, 2025

ref https://linear.app/ghost/issue/AP-973

We don't update the /site endpoint as this is used for the handshake exposesthe webhook secret. There's no need for Administrators to have access to this.

Copy link

coderabbitai bot commented Mar 24, 2025

Walkthrough

The pull request changes the requireRole function to accept a variable number of roles instead of a single role. The function signature has been updated to requireRole(...roles: GhostRole[]) to enable checking if a user’s role is included in a set of allowed roles. The internal logic now verifies user authorization by ensuring that the role retrieved from the context is among the provided roles. All instances where requireRole is invoked have been updated to pass multiple roles, such as GhostRole.Owner and GhostRole.Administrator, across various routes, including those related to inbox handling, activity retrieval, and several action handlers. This update modifies the authorization checks to support users with multiple roles for accessing different parts of the application.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 496f604 and 53dabee.

📒 Files selected for processing (1)
  • src/app.ts (6 hunks)
🧰 Additional context used
🧬 Code Definitions (1)
src/app.ts (3)
src/http/api/profile.ts (2)
  • createGetProfileHandler (39-119)
  • createGetProfileFollowersHandler (308-428)
src/http/api/account.ts (3)
  • createGetAccountHandler (36-110)
  • createGetAccountPostsHandler (234-266)
  • createGetAccountLikedPostsHandler (274-308)
src/http/api/feed.ts (1)
  • createGetFeedHandler (24-124)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Build, Test and Push
🔇 Additional comments (25)
src/app.ts (25)

859-861: Function signature updated to support multiple roles.

The requireRole function now accepts a variable number of role arguments, allowing for more flexible authorization checks. The implementation correctly uses includes() to verify if the user's role is among the allowed roles.


872-873: Added Administrator role to inbox endpoint.

Appropriately expanded access to allow both Owners and Administrators to access the inbox endpoint, aligning with the PR objective.


877-878: Added Administrator role to activities endpoint.

Correctly updated to permit both Owners and Administrators to retrieve activities.


882-883: Added Administrator role to follow action endpoint.

Expanded access to allow Administrators to follow accounts, consistent with other authorization updates.


887-888: Added Administrator role to unfollow action endpoint.

Updated authorization to allow Administrators to unfollow accounts, maintaining feature parity with the follow action.


892-893: Added Administrator role to like action endpoint.

Correctly expanded access to allow Administrators to like posts.


899-900: Added Administrator role to unlike action endpoint.

Updated authorization to allow Administrators to unlike posts, maintaining feature parity with the like action.


906-907: Added Administrator role to reply action endpoint.

Appropriately expanded access to allow Administrators to reply to posts.


917-918: Added Administrator role to repost action endpoint.

Correctly updated to permit Administrators to repost content.


930-931: Added Administrator role to derepost action endpoint.

Updated authorization to allow Administrators to derepost content, maintaining feature parity with the repost action.


941-942: Added Administrator role to note creation endpoint.

Correctly expanded access to allow Administrators to create notes.


948-949: Added Administrator role to search endpoint.

Appropriately updated to permit Administrators to use the search functionality.


953-954: Added Administrator role to profile retrieval endpoint.

Correctly expanded access to allow Administrators to view profiles.


958-959: Added Administrator role to profile followers endpoint.

Updated authorization to allow Administrators to view profile followers.


963-964: Added Administrator role to profile following endpoint.

Correctly expanded access to allow Administrators to view accounts being followed by a profile.


968-969: Added Administrator role to profile posts endpoint.

Appropriately updated to permit Administrators to view posts from a profile.


977-978: Added Administrator role to account retrieval endpoint.

Correctly expanded access to allow Administrators to retrieve account information.


982-983: Added Administrator role to posts retrieval endpoint.

Updated authorization to allow Administrators to retrieve posts.


987-988: Added Administrator role to liked posts endpoint.

Correctly expanded access to allow Administrators to view liked posts.


992-993: Added Administrator role to account follows endpoint.

Appropriately updated to permit Administrators to view account follows.


997-998: Added Administrator role to feed endpoint.

Correctly expanded access to allow Administrators to retrieve the feed.


1002-1003: Added Administrator role to inbox retrieval endpoint.

Updated authorization to allow Administrators to access the inbox data.


1007-1008: Added Administrator role to post deletion endpoint.

Correctly expanded access to allow Administrators to delete posts.


1014-1014: Notification endpoint still restricted to Owner role only.

Notifications endpoint still requires the Owner role, which is appropriate since the PR states there's no need for Administrators to access this particular endpoint.


760-762: Site endpoint correctly remains restricted to Owner role.

The /site endpoint is still restricted to Owners only, which aligns with the PR objective stating that this endpoint is used for handshake and exposes webhook secrets.

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

ref https://linear.app/ghost/issue/AP-973

We don't update the /site endpoint as this is used for the handshake exposesthe
webhook secret. There's no need for Administrators to have access to this.
@allouis allouis force-pushed the add-permissions-for-administrators branch from 496f604 to 53dabee Compare March 24, 2025 14:33
@sagzy sagzy merged commit 8f9aa5f into main Mar 26, 2025
6 checks passed
@sagzy sagzy deleted the add-permissions-for-administrators branch March 26, 2025 07:09
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.

2 participants