Skip to content

Add view-all-projects check and use in controller - #580

Merged
iftakharul-islam merged 3 commits into
weDevsOfficial:developfrom
arifulhoque7:fix/pm-manager-project-visibility
Feb 26, 2026
Merged

iftakharul-islam merged 3 commits into
weDevsOfficial:developfrom
arifulhoque7:fix/pm-manager-project-visibility

Conversation

@arifulhoque7

@arifulhoque7 arifulhoque7 commented Feb 16, 2026

Copy link
Copy Markdown
Contributor

Introduce wedevs_pm_can_view_all_projects() in libs/functions.php (wrapping existing admin capability check) to express intent that only PM Admins and WP Admins can view all projects. Update Project_Controller to use this helper so non-admin users (PM Managers) are limited to viewing only their assigned projects.

Close 272

Summary by CodeRabbit

  • Refactor
    • Updated permission requirements for project data access and filtering functionality

Introduce wedevs_pm_can_view_all_projects() in libs/functions.php (wrapping existing admin capability check) to express intent that only PM Admins and WP Admins can view all projects. Update Project_Controller to use this helper so non-admin users (PM Managers) are limited to viewing only their assigned projects.
@arifulhoque7 arifulhoque7 self-assigned this Feb 16, 2026
@arifulhoque7 arifulhoque7 added Needs Dev Review This PR needs review by a developer Needs Testing This issue/PR needs further testing labels Feb 16, 2026
@coderabbitai

coderabbitai Bot commented Feb 16, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 466266f and 02bf90f.

📒 Files selected for processing (2)
  • src/Project/Controllers/Project_Controller.php
  • src/Project/Helper/Project.php
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/Project/Helper/Project.php

Walkthrough

Two capability checks are updated from manage to admin level across the project codebase. In the Project controller's fetch_projects_by_category method and the Project helper's where_users method, wedevs_pm_has_manage_capability is replaced with wedevs_pm_has_admin_capability, affecting project visibility filtering logic.

Changes

Cohort / File(s) Summary
Capability Check Updates
src/Project/Controllers/Project_Controller.php, src/Project/Helper/Project.php
Replaced wedevs_pm_has_manage_capability with wedevs_pm_has_admin_capability in fetch_projects_by_category and where_users methods, altering access control rules for project visibility.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~4 minutes

Suggested reviewers

  • iftakharul-islam

Poem

🐰 A hop and a skip, permissions aligned,
From manage to admin, new gates we designed,
Two files now stricter, with elevated care,
Project visibility flows with fresh flair!

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Title check ⚠️ Warning The title claims to 'Add view-all-projects check' but the PR actually removed the wedevs_pm_can_view_all_projects() wrapper and replaced it with direct admin capability checks. Update the title to accurately reflect the changes, such as 'Replace view-all-projects check with admin capability check' or 'Use admin capability check instead of view-all wrapper'.
Docstring Coverage ⚠️ Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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 and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

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)
src/Project/Controllers/Project_Controller.php (1)

155-159: ⚠️ Potential issue | 🟠 Major

Update Search_Controller permission checks to match Project_Controller.

The permission function was changed from wedevs_pm_has_manage_capability (includes both admins and managers) to wedevs_pm_can_view_all_projects (admins only) in Project_Controller at line 155, but this change was not applied to Search_Controller. This creates a permission inconsistency: PM Managers will see all projects in search queries but only assigned projects in the project listing, depending on which endpoint they access.

Update the three permission checks in Search_Controller (lines 139, 159, and 422) to use wedevs_pm_can_view_all_projects instead of wedevs_pm_has_manage_capability to ensure consistent behavior across all project-fetching endpoints.

@Rubaiyat-E-Mohammad Rubaiyat-E-Mohammad added bug and removed Needs Testing This issue/PR needs further testing labels Feb 20, 2026
@Rubaiyat-E-Mohammad

Rubaiyat-E-Mohammad commented Feb 20, 2026

Copy link
Copy Markdown

PM_Manager still can see all projects @arifulhoque7 vai

Screen.Recording.2026-02-20.at.2.12.24.PM.mov

Replace wedevs_pm_has_manage_capability with wedevs_pm_can_view_all_projects when $inUsers is empty so users granted the 'view all projects' permission can proceed without needing the broader manage capability.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

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)
src/Project/Helper/Project.php (2)

1415-1427: ⚠️ Potential issue | 🟡 Minor

Unreachable return 10 at Line 1426.

The return on Line 1424 always exits the function; Line 1426 is dead code.

🧹 Proposed fix
 		$per_page = wedevs_pm_get_setting( 'project_per_page' );

-		return empty( $per_page ) ? 10 : (int) $per_page;
-
-		return 10;
+		return empty( $per_page ) ? 10 : (int) $per_page;
 	}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/Project/Helper/Project.php` around lines 1415 - 1427, The get_per_page()
function contains an unreachable final "return 10" after an earlier return;
remove the dead code and keep a single return path. Specifically, in
Project::get_per_page() remove the trailing "return 10;" and ensure the method
returns (int) $per_page when provided, falls back to
wedevs_pm_get_setting('project_per_page') and finally returns 10 if that setting
is empty—no extra return after those branches.

138-198: ⚠️ Potential issue | 🟠 Major

count_project_by_type() is not user-aware — exposes all-project counts to restricted users and breaks pagination.

count_project_by_type() queries the full projects table with no user join or filter:

SELECT DISTINCT COUNT(id) FROM {pm_projects} WHERE status = %d

These unfiltered counts populate total_incomplete, total_complete, total_pending, total_archived, and critically pagination.total (Line 155) in the response metadata. Meanwhile, total_projects and total_pages are derived from $this->found_rows (Line 147/157), which is filtered by the user-aware SQL query in get().

The practical result after this PR's access-control change: a PM Manager restricted to, say, 5 assigned projects will receive a pagination.total of 50 (all system projects), causing broken/phantom pagination pages and leaking the aggregate project count.

count_project_by_type needs to be rewritten to join against pm_role_user and filter by $current_user_id when the user is not an admin — mirroring the filtering logic in where_users().

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/Project/Helper/Project.php` around lines 138 - 198, count_project_by_type
currently counts across the whole pm_projects table and must be made user-aware;
change count_project_by_type($type) to apply the same user filtering used in
where_users() (join pm_role_user and filter by current user id when the current
user is not an admin) so the counts (used by get_pagination_total and
set_projects_meta) match $this->found_rows and the get() results; specifically,
reuse or mirror where_users() logic (join wedevs_pm_tb_prefix() .
'pm_role_user', filter by $this->current_user_id or get_current_user_id(), and
any capability checks) and update the SQL in count_project_by_type to include
that JOIN/WHERE, returning the filtered COUNT(id).
🧹 Nitpick comments (1)
src/Project/Helper/Project.php (1)

118-132: Remove commented-out dead code blocks.

There are several large commented-out code blocks across the file (Lines 118–132, 260–284, 304–314, 333–399). These should be deleted — version history covers their retrieval if ever needed.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/Project/Helper/Project.php` around lines 118 - 132, Remove the large
commented-out dead code blocks in src/Project/Helper/Project.php (the blocks
around lines 118–132, 260–284, 304–314, 333–399) so the file contains only
active logic; specifically delete the commented wrappers that reference methods
like fromat_project and set_projects_meta (and any duplicated commented
foreach/if branches) rather than uncommenting or changing them—rely on VCS
history if the old code is needed.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@src/Project/Helper/Project.php`:
- Around line 1415-1427: The get_per_page() function contains an unreachable
final "return 10" after an earlier return; remove the dead code and keep a
single return path. Specifically, in Project::get_per_page() remove the trailing
"return 10;" and ensure the method returns (int) $per_page when provided, falls
back to wedevs_pm_get_setting('project_per_page') and finally returns 10 if that
setting is empty—no extra return after those branches.
- Around line 138-198: count_project_by_type currently counts across the whole
pm_projects table and must be made user-aware; change
count_project_by_type($type) to apply the same user filtering used in
where_users() (join pm_role_user and filter by current user id when the current
user is not an admin) so the counts (used by get_pagination_total and
set_projects_meta) match $this->found_rows and the get() results; specifically,
reuse or mirror where_users() logic (join wedevs_pm_tb_prefix() .
'pm_role_user', filter by $this->current_user_id or get_current_user_id(), and
any capability checks) and update the SQL in count_project_by_type to include
that JOIN/WHERE, returning the filtered COUNT(id).

---

Nitpick comments:
In `@src/Project/Helper/Project.php`:
- Around line 118-132: Remove the large commented-out dead code blocks in
src/Project/Helper/Project.php (the blocks around lines 118–132, 260–284,
304–314, 333–399) so the file contains only active logic; specifically delete
the commented wrappers that reference methods like fromat_project and
set_projects_meta (and any duplicated commented foreach/if branches) rather than
uncommenting or changing them—rely on VCS history if the old code is needed.

@arifulhoque7 arifulhoque7 added Needs Testing This issue/PR needs further testing and removed bug labels Feb 23, 2026
@Rubaiyat-E-Mohammad Rubaiyat-E-Mohammad added QA Approved This PR is approved by the QA team and removed Needs Testing This issue/PR needs further testing labels Feb 24, 2026
Remove the deprecated wedevs_pm_can_view_all_projects wrapper from libs/functions.php and update calls to use wedevs_pm_has_admin_capability in Project_Controller and Project helper. This consolidates permission logic so only users with the admin capability can view all projects, removing the obsolete function.

@iftakharul-islam iftakharul-islam left a comment

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.

Please call existing

Comment thread libs/functions.php Outdated
* @param int|false $user_id
* @return bool
*/
function wedevs_pm_can_view_all_projects( $user_id = false ) {

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.

Please change this and call the existing function, as it is reflecting the purpose of checks.

@iftakharul-islam
iftakharul-islam merged commit a6b20e1 into weDevsOfficial:develop Feb 26, 2026
arifulhoque7 added a commit that referenced this pull request May 28, 2026
* Add view-all-projects check and use in controller

Introduce wedevs_pm_can_view_all_projects() in libs/functions.php (wrapping existing admin capability check) to express intent that only PM Admins and WP Admins can view all projects. Update Project_Controller to use this helper so non-admin users (PM Managers) are limited to viewing only their assigned projects.

* Use view-all-projects capability check

Replace wedevs_pm_has_manage_capability with wedevs_pm_can_view_all_projects when $inUsers is empty so users granted the 'view all projects' permission can proceed without needing the broader manage capability.

* Use admin capability check instead of view-all fn

Remove the deprecated wedevs_pm_can_view_all_projects wrapper from libs/functions.php and update calls to use wedevs_pm_has_admin_capability in Project_Controller and Project helper. This consolidates permission logic so only users with the admin capability can view all projects, removing the obsolete function.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs Dev Review This PR needs review by a developer QA Approved This PR is approved by the QA team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants