Skip to content

Enforce local context role detection in Learning Style block - #68

Merged
jairoserrano merged 13 commits into
ISCOUTB:mainfrom
IsaacDev2024:patch-11
Jan 19, 2026
Merged

jairoserrano merged 13 commits into
ISCOUTB:mainfrom
IsaacDev2024:patch-11

Conversation

@IsaacDev2024

@IsaacDev2024 IsaacDev2024 commented Jan 18, 2026 •

Copy link
Copy Markdown
Contributor

This PR addresses an issue where the Learning Style block would incorrectly identify a user's role based on global permissions (like Site Admin or moodle/course:viewhiddensections) rather than their specific enrollment in the current course.

Previously, an admin or manager enrolled as a student in a specific course would see the Teacher Dashboard and be unable to take the test.

Changes

  • Updated can_view_dashboard in block_learning_style.php.
  • Removed checks for is_siteadmin() and generic moodle/course:viewhiddensections.
  • Now strictly relies on has_capability('block/learning_style:viewreports', $context), ensuring the local course context is respected.
  • Bold in the main block title for consistency with the others

This aligns the behavior with the other blocks.

Previously, the block checked for is_siteadmin() and 'moodle/course:viewhiddensections', forcing the teacher dashboard even for admins/managers acting as students. Now it strictly checks 'block/learning_style:viewreports' in the current context to respect local course roles, matching the behavior of other test blocks.
Simplify unauthorized user checks by removing redundant site admin condition.
Updated the can_view_dashboard method to accept an optional user ID parameter, allowing capability checks for specific users. Adjusted related logic to utilize the updated method for determining teacher access and filtering student IDs.
Refactor access checks to streamline permission validation.
Removed redundant admin checks in key views and improved role detection. Added bold formatting to block title for better visibility.
@sonarqubecloud

Copy link
Copy Markdown

@IsaacDev2024 IsaacDev2024 mentioned this pull request Jan 19, 2026
@jairoserrano
jairoserrano merged commit 5bc2d5c into ISCOUTB:main Jan 19, 2026
3 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