Setup
Login as admin.
Access to "Site administration > Competencies > Competencies settings" and enable competencies.
Access to "Site administration > Users > Permissions > Define roles" and edit the "Authenticated user" role to remove the "View competency frameworks (moodle/competency:competencyview)" capability (unchecking the "Allow" checkbox).
Create a user (user1).
Create a course (Course1).
Enrol user1 in Course1.
Testing scenario
Login as user1.
Navigate to Course1.
Hit the "Competencies" link in the side menu.
CHECK that the user can access to the Competencies of the course and also that the "Sorry, but you do not currently have permissions to do that (View competency frameworks)." is not displayed.

Description

If a user is given capability to view course competencies (moodle/competency:coursecompetencyview) but does not have capability to view competency frameworks (moodle/competency:competencyview), page /admin/tool/lp/coursecompetencies.php throws an exception:

Sorry, but you do not currently have permissions to do that (View competency frameworks)

More information about this error

×Debug info:

Error code: nopermissions

×Stack trace:

line 4987 of /competency/classes/api.php: required_capability_exception thrown

line 58 of /admin/tool/lp/classes/course_competency_statistics.php: call to core_competency\api::get_least_proficient_competencies_for_course()

line 85 of /admin/tool/lp/classes/output/course_competencies_page.php: call to tool_lp\course_competency_statistics->__construct()

line 43 of /admin/tool/lp/coursecompetencies.php: call to tool_lp\output\course_competencies_page->__construct()

According to Fred, the capabilities check is not correct in core_competency\api::get_least_proficient_competencies_for_course() and it should be checking for coursecompetencyview and not competencyview

Another thing I noticed during work on MDL-55032:
if course has guest access and guests are given capability to view course competencies, the non-working link is displayed to the guest on this page