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

Fix superadmin access #2307 with user-posted media #2318

Conversation

lokeshsingh3721
Copy link

@lokeshsingh3721 lokeshsingh3721 commented May 21, 2024

What kind of change does this PR introduce?

bugfix

Issue Number:

Fixes #2307

Did you add tests for your changes?

tested locally on the machine

Snapshots/Videos:

Screen.Recording.2024-05-21.at.11.55.04.AM.mov

If relevant, did you update the documentation?

No need

Summary

There was an issue with organization's post resolver which was not letting the super-admin accessing the organization in which user posted the media.

Does this PR introduce a breaking change?

NO

Other information

Have you read the contributing guide?

Yes

Summary by CodeRabbit

  • New Features

    • Improved post resolver to dynamically update imageUrl and videoUrl based on the context, ensuring URLs are always up-to-date.
  • Bug Fixes

    • Enhanced post data formatting and comparison in tests to ensure consistency and accuracy in post-related functionalities.

Copy link

coderabbitai bot commented May 21, 2024

Walkthrough

The update involves modifying the posts resolver in the Organization module to accept a context argument, allowing dynamic URL updates for imageUrl and videoUrl. Additionally, the corresponding tests have been refactored to align with these changes.

Changes

File/Path Change Summary
src/resolvers/Organization/posts.ts Updated posts resolver to accept context argument and map imageUrl and videoUrl with context.apiRootUrl.
tests/resolvers/Organization/posts.spec.ts Refactored tests to restructure post objects, update URLs, and adjust cursor comparisons.

Assessment against linked issues

Objective (Issue #2307) Addressed Explanation
Superadmin access to organizations with user-posted media
Superadmin should see all posts in the organization

🐇 In the code's warren, changes weave,
URLs update, new paths conceive.
Superadmins now can see,
All the posts, media set free.
Hopping forward, bugs we leave.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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.

Copy link

Our Pull Request Approval Process

We have these basic policies to make the approval process smoother for our volunteer team.

Testing Your Code

Please make sure your code passes all tests. Our test code coverage system will fail if these conditions occur:

  1. The overall code coverage drops below the target threshold of the repository
  2. Any file in the pull request has code coverage levels below the repository threshold
  3. Merge conflicts

The process helps maintain the overall reliability of the code base and is a prerequisite for getting your PR approved. Assigned reviewers regularly review the PR queue and tend to focus on PRs that are passing.

Reviewers

Do not assign reviewers. Our Queue Monitors will review your PR and assign them.
When your PR has been assigned reviewers contact them to get your code reviewed and approved via:

  1. comments in this PR or
  2. our slack channel

Reviewing Your Code

Your reviewer(s) will have the following roles:

  1. arbitrators of future discussions with other contributors about the validity of your changes
  2. point of contact for evaluating the validity of your work
  3. person who verifies matching issues by others that should be closed.
  4. person who gives general guidance in fixing your tests

CONTRIBUTING.md

Read our CONTRIBUTING.md file. Most importantly:

  1. PRs with issues not assigned to you will be closed by the reviewer
  2. Fix the first comment in the PR so that each issue listed automatically closes

Other

  1. 🎯 Please be considerate of our volunteers' time. Contacting the person who assigned the reviewers is not advised unless they ask for your input. Do not @ the person who did the assignment otherwise.
  2. Read the CONTRIBUTING.md file make

Copy link

@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.

Actionable comments posted: 1

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 99e1dd4 and 89136df.
Files selected for processing (1)
  • src/resolvers/Organization/posts.ts (2 hunks)
Additional comments not posted (2)
src/resolvers/Organization/posts.ts (2)

92-92: Rename objectList to posts in the return statement to match the new variable name and improve readability.


30-34: Ensure all calls to the posts resolver are updated to pass the context parameter.

Comment on lines 84 to 85
imageUrl: post.imageUrl ? `${context.apiRootUrl}${post.imageUrl}` : null,
videoUrl: post.videoUrl ? `${context.apiRootUrl}${post.videoUrl}` : null,
Copy link

@coderabbitai coderabbitai bot May 21, 2024

Choose a reason for hiding this comment

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

Refactor URL construction to handle potential leading slashes in imageUrl and videoUrl.

- imageUrl: post.imageUrl ? `${context.apiRootUrl}${post.imageUrl}` : null,
- videoUrl: post.videoUrl ? `${context.apiRootUrl}${post.videoUrl}` : null,
+ imageUrl: post.imageUrl ? new URL(post.imageUrl, context.apiRootUrl).toString() : null,
+ videoUrl: post.videoUrl ? new URL(post.videoUrl, context.apiRootUrl).toString() : null,

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
imageUrl: post.imageUrl ? `${context.apiRootUrl}${post.imageUrl}` : null,
videoUrl: post.videoUrl ? `${context.apiRootUrl}${post.videoUrl}` : null,
imageUrl: post.imageUrl ? new URL(post.imageUrl, context.apiRootUrl).toString() : null,
videoUrl: post.videoUrl ? new URL(post.videoUrl, context.apiRootUrl).toString() : null,

Copy link
Author

Choose a reason for hiding this comment

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

@palisadoes are you talking about these two ?

Copy link

Choose a reason for hiding this comment

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

Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!

Copy link
Contributor

Choose a reason for hiding this comment

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

@lokeshsingh3721 Please address this

Copy link
Author

Choose a reason for hiding this comment

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

@lokeshsingh3721 Please address this

image
I am sorry for stretching this out but i think I have already made these changes and i am not seeing any other suggestions . Can you please point out or share screenshots of another changes ?

Copy link

codecov bot commented May 21, 2024

Codecov Report

Attention: Patch coverage is 73.33333% with 4 lines in your changes are missing coverage. Please review.

Project coverage is 98.50%. Comparing base (c0468a4) to head (a9ae7f5).
Report is 558 commits behind head on develop.

Current head a9ae7f5 differs from pull request most recent head 8583c97

Please upload reports for the commit 8583c97 to get more accurate results.

Files Patch % Lines
src/resolvers/Organization/posts.ts 73.33% 4 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #2318      +/-   ##
===========================================
+ Coverage    98.17%   98.50%   +0.32%     
===========================================
  Files          184      349     +165     
  Lines        10767    25189   +14422     
  Branches       835     2354    +1519     
===========================================
+ Hits         10571    24813   +14242     
- Misses         186      373     +187     
+ Partials        10        3       -7     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

@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.

Actionable comments posted: 0

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 89136df and a9ae7f5.
Files selected for processing (1)
  • src/resolvers/Organization/posts.ts (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • src/resolvers/Organization/posts.ts

Copy link

@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.

Actionable comments posted: 1

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between a9ae7f5 and cdc875f.
Files selected for processing (1)
  • tests/resolvers/Organization/posts.spec.ts (2 hunks)

Comment on lines 73 to 131
const context = { apiRootUrl: undefined };

const formattedPost2 = {
...testPost2?.toObject(),
imageUrl: testPost2?.imageUrl
? new URL(testPost2.imageUrl, context.apiRootUrl).toString()
: null,
videoUrl: testPost2?.videoUrl
? new URL(testPost2.videoUrl, context.apiRootUrl).toString()
: null,
};

const formattedPost = {
...testPost?.toObject(),
imageUrl: testPost?.imageUrl
? new URL(testPost.imageUrl, context.apiRootUrl).toString()
: null,
videoUrl: testPost?.videoUrl
? new URL(testPost.videoUrl, context.apiRootUrl).toString()
: null,
};

expect(connection).toEqual({
edges: [
{
cursor: formattedPost2._id?.toString(),
node: {
...formattedPost2,
_id: formattedPost2._id?.toString(),
imageUrl: testPost?.imageUrl
? new URL(testPost.imageUrl, context.apiRootUrl).toString()
: null,
videoUrl: formattedPost2?.videoUrl
? new URL(formattedPost2.videoUrl, context.apiRootUrl).toString()
: null,
},
},
{
cursor: formattedPost._id?.toString(),
node: {
...formattedPost,
_id: formattedPost?._id?.toString(),
imageUrl: formattedPost?.imageUrl
? new URL(formattedPost.imageUrl, context.apiRootUrl).toString()
: null,
videoUrl: formattedPost?.videoUrl
? new URL(formattedPost.videoUrl, context.apiRootUrl).toString()
: null,
},
},
],
pageInfo: {
endCursor: testPost?._id.toString(),
hasNextPage: false,
hasPreviousPage: false,
startCursor: testPost2?._id.toString(),
},
totalCount,
});
Copy link

@coderabbitai coderabbitai bot May 22, 2024

Choose a reason for hiding this comment

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

Ensure apiRootUrl is defined in the test context.

The context object is initialized with apiRootUrl as undefined. This will cause the URL construction for imageUrl and videoUrl to fail, leading to incorrect test results. Consider initializing apiRootUrl with a valid URL to accurately test the URL formatting logic.

- const context = { apiRootUrl: undefined };
+ const context = { apiRootUrl: 'http://example.com' };

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
const context = { apiRootUrl: undefined };
const formattedPost2 = {
...testPost2?.toObject(),
imageUrl: testPost2?.imageUrl
? new URL(testPost2.imageUrl, context.apiRootUrl).toString()
: null,
videoUrl: testPost2?.videoUrl
? new URL(testPost2.videoUrl, context.apiRootUrl).toString()
: null,
};
const formattedPost = {
...testPost?.toObject(),
imageUrl: testPost?.imageUrl
? new URL(testPost.imageUrl, context.apiRootUrl).toString()
: null,
videoUrl: testPost?.videoUrl
? new URL(testPost.videoUrl, context.apiRootUrl).toString()
: null,
};
expect(connection).toEqual({
edges: [
{
cursor: formattedPost2._id?.toString(),
node: {
...formattedPost2,
_id: formattedPost2._id?.toString(),
imageUrl: testPost?.imageUrl
? new URL(testPost.imageUrl, context.apiRootUrl).toString()
: null,
videoUrl: formattedPost2?.videoUrl
? new URL(formattedPost2.videoUrl, context.apiRootUrl).toString()
: null,
},
},
{
cursor: formattedPost._id?.toString(),
node: {
...formattedPost,
_id: formattedPost?._id?.toString(),
imageUrl: formattedPost?.imageUrl
? new URL(formattedPost.imageUrl, context.apiRootUrl).toString()
: null,
videoUrl: formattedPost?.videoUrl
? new URL(formattedPost.videoUrl, context.apiRootUrl).toString()
: null,
},
},
],
pageInfo: {
endCursor: testPost?._id.toString(),
hasNextPage: false,
hasPreviousPage: false,
startCursor: testPost2?._id.toString(),
},
totalCount,
});
const context = { apiRootUrl: 'http://example.com' };
const formattedPost2 = {
...testPost2?.toObject(),
imageUrl: testPost2?.imageUrl
? new URL(testPost2.imageUrl, context.apiRootUrl).toString()
: null,
videoUrl: testPost2?.videoUrl
? new URL(testPost2.videoUrl, context.apiRootUrl).toString()
: null,
};
const formattedPost = {
...testPost?.toObject(),
imageUrl: testPost?.imageUrl
? new URL(testPost.imageUrl, context.apiRootUrl).toString()
: null,
videoUrl: testPost?.videoUrl
? new URL(testPost.videoUrl, context.apiRootUrl).toString()
: null,
};
expect(connection).toEqual({
edges: [
{
cursor: formattedPost2._id?.toString(),
node: {
...formattedPost2,
_id: formattedPost2._id?.toString(),
imageUrl: testPost?.imageUrl
? new URL(testPost.imageUrl, context.apiRootUrl).toString()
: null,
videoUrl: formattedPost2?.videoUrl
? new URL(formattedPost2.videoUrl, context.apiRootUrl).toString()
: null,
},
},
{
cursor: formattedPost._id?.toString(),
node: {
...formattedPost,
_id: formattedPost?._id?.toString(),
imageUrl: formattedPost?.imageUrl
? new URL(formattedPost.imageUrl, context.apiRootUrl).toString()
: null,
videoUrl: formattedPost?.videoUrl
? new URL(formattedPost.videoUrl, context.apiRootUrl).toString()
: null,
},
},
],
pageInfo: {
endCursor: testPost?._id.toString(),
hasNextPage: false,
hasPreviousPage: false,
startCursor: testPost2?._id.toString(),
},
totalCount,
});

Copy link
Contributor

@palisadoes palisadoes May 30, 2024

Choose a reason for hiding this comment

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

@lokeshsingh3721 Please address this

Copy link

Choose a reason for hiding this comment

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

@palisadoes, I've noted your directive to address the issue with the apiRootUrl being undefined in the test context. As previously suggested, initializing apiRootUrl with a valid URL, such as 'http://example.com', will ensure that the URL construction for imageUrl and videoUrl functions correctly in the test environment. This change should resolve the issue and provide accurate test results.

Please let me know if there's anything else you'd like to discuss or if you need further assistance with this modification!

Copy link

@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.

Actionable comments posted: 0

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between cdc875f and 8583c97.
Files selected for processing (1)
  • tests/resolvers/Organization/posts.spec.ts (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • tests/resolvers/Organization/posts.spec.ts

@palisadoes palisadoes changed the title Fix superadmin access issue with user-posted media Fix superadmin access #2307 with user-posted media May 23, 2024
@palisadoes
Copy link
Contributor

  1. Please address the suggestions by Code Rabbit
  2. Also increase the test code coverage to an acceptable level

@lokeshsingh3721
Copy link
Author

  1. Please address the suggestions by Code Rabbit

    1. Also increase the test code coverage to an acceptable level

i have made all the changes suggested by Code Rabbit and all the tests are passed .

@lokeshsingh3721
Copy link
Author

@palisadoes do i need to change anything ?

@palisadoes
Copy link
Contributor

  1. Please address the suggestions by Code Rabbit

    1. Also increase the test code coverage to an acceptable level

i have made all the changes suggested by Code Rabbit and all the tests are passed .

There are still 2 code rabbit suggestions that you have not addressed

@lokeshsingh3721
Copy link
Author

  1. Please address the suggestions by Code Rabbit

    1. Also increase the test code coverage to an acceptable level

i have made all the changes suggested by Code Rabbit and all the tests are passed .

There are still 2 code rabbit suggestions that you have not addressed

where to see them ?

@palisadoes palisadoes merged commit a02d462 into PalisadoesFoundation:develop Jun 1, 2024
9 checks passed
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