Skip to content

enhancement/organization-apis#77

Merged
mdawoud27 merged 9 commits into
mainfrom
enhancement/29/organization_apis
Apr 5, 2025
Merged

enhancement/organization-apis#77
mdawoud27 merged 9 commits into
mainfrom
enhancement/29/organization_apis

Conversation

@mdawoud27
Copy link
Copy Markdown
Contributor

PR Checklist (required)

Please check if your PR fulfills the following requirements:

  • The commit message follows our guidelines.

  • Tests for the changes have been added (for bug fixes / features)

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation changes
  • Other... Please describe:

Related Issue

Closes #29

@mdawoud27 mdawoud27 linked an issue Apr 5, 2025 that may be closed by this pull request
@mdawoud27 mdawoud27 requested a review from Copilot April 5, 2025 16:02
@mdawoud27 mdawoud27 self-assigned this Apr 5, 2025
@mdawoud27 mdawoud27 added documentation Improvements or additions to documentation enhancement New feature or request labels Apr 5, 2025
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.

Copilot reviewed 5 out of 6 changed files in this pull request and generated 3 comments.

Files not reviewed (1)
  • src/docs/swagger.json: Language not supported
Comments suppressed due to low confidence (2)

src/routes/organization.routes.js:38

  • Removal of verifyAdminPermission middleware from the update route might allow unauthorized organization updates. Please confirm that this change is intentional and that updateOrganization is sufficiently protected by other mechanisms.
verifyAdminPermission,

src/middlewares/verifyUserPermission.middleware.js:2

  • The removal of the email check (req.user.email === req.params.email) may reduce flexibility in permission verification. Confirm that this simplified logic meets all intended use cases.
if (req.params.id === req.user.id || req.user.role === 'ADMIN') {

const parts = url.pathname.split('/');

// Cloudinary's publicId includes folders, so we remove `/image/upload/` and get everything after
const uploadIndex = parts.findIndex((part) => part === 'upload');
Copy link

Copilot AI Apr 5, 2025

Choose a reason for hiding this comment

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

Potential bug: If 'upload' is not found in the URL pathname, uploadIndex will be -1 leading to incorrect publicId extraction. Consider validating uploadIndex before slicing the parts array.

Suggested change
const uploadIndex = parts.findIndex((part) => part === 'upload');
const uploadIndex = parts.findIndex((part) => part === 'upload');
if (uploadIndex === -1) {
throw new Error('Invalid image URL: "upload" segment not found in pathname');
}

Copilot uses AI. Check for mistakes.
// Rest of the function remains the same...
// Handle boolean filter
if (filters.isVerified !== undefined) {
where.isVerified = ['true', '1', true].includes(filters.isVerified);
Copy link

Copilot AI Apr 5, 2025

Choose a reason for hiding this comment

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

Potential bug: The boolean conversion for filters.isVerified does not explicitly handle false-equivalent values (e.g., 'false', '0'). Consider expanding the logic to clearly determine both true and false conditions.

Suggested change
where.isVerified = ['true', '1', true].includes(filters.isVerified);
if (['true', '1', true].includes(filters.isVerified)) {
where.isVerified = true;
} else if (['false', '0', false].includes(filters.isVerified)) {
where.isVerified = false;
}

Copilot uses AI. Check for mistakes.
Comment on lines +401 to 402
const isMember = organization.users.length > 0;

Copy link

Copilot AI Apr 5, 2025

Choose a reason for hiding this comment

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

Bug: The membership check only verifies that there are users in the organization, rather than confirming that the current user is a member. Consider checking if organization.users includes the current user's id.

Suggested change
const isMember = organization.users.length > 0;
const isMember = organization.users.some(
(user) => user.id === req.user.id,
);

Copilot uses AI. Check for mistakes.
@mdawoud27 mdawoud27 merged commit 91ff8d9 into main Apr 5, 2025
11 checks passed
@mdawoud27 mdawoud27 deleted the enhancement/29/organization_apis branch April 5, 2025 16:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ENHANCEMENT]: Organization APIs

2 participants