Skip to content

Commit 940cfc5

Browse files
committed
Add configuration "allow_private_skills" see BT#12902
- Skills can only visible for admins, teachers (related to a user via a course) and HRM users (if related to a user). - Add new function to handle permissions in the skill tool - Use Skill::isAllow() to block pages.
1 parent be7672d commit 940cfc5

38 files changed

+349
-229
lines changed

main/admin/index.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@
407407
$blocks['settings']['search_form'] = null;
408408

409409
// Skills
410-
if (api_get_setting('allow_skills_tool') == 'true') {
410+
if (Skill::isToolAvailable()) {
411411
$blocks['skills']['icon'] = Display::return_icon(
412412
'skill-badges.png',
413413
get_lang('Skills'),

main/admin/skill_badge.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111

1212
$this_section = SECTION_PLATFORM_ADMIN;
1313

14-
if (!api_is_platform_admin() || api_get_setting('allow_skills_tool') !== 'true') {
15-
api_not_allowed(true);
16-
}
14+
api_protect_admin_script();
15+
Skill::isAllow();
16+
1717
$backpack = 'https://backpack.openbadges.org/';
1818

1919
$configBackpack = api_get_setting('openbadges_backpack');
@@ -33,10 +33,11 @@
3333
'list_badges.png',
3434
get_lang('ManageSkills'),
3535
null,
36-
ICON_SIZE_MEDIUM),
36+
ICON_SIZE_MEDIUM
37+
),
3738
api_get_path(WEB_CODE_PATH).'admin/skill_list.php',
3839
['title' => get_lang('ManageSkills')]
39-
);
40+
);
4041

4142
$tpl = new Template(get_lang('Badges'));
4243
$tpl->assign('backpack', $backpack);

main/admin/skill_badge_create.php

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,18 @@
1313

1414
require_once __DIR__.'/../inc/global.inc.php';
1515

16-
if (!api_is_platform_admin() || api_get_setting('allow_skills_tool') !== 'true') {
17-
api_not_allowed(true);
18-
}
16+
api_protect_admin_script();
17+
Skill::isAllow();
1918

2019
$this_section = SECTION_PLATFORM_ADMIN;
2120

2221
$skillId = intval($_GET['id']);
23-
2422
$objSkill = new Skill();
2523
$skill = $objSkill->get($skillId);
2624

2725
$htmlHeadXtra[] = '<link href="'.api_get_path(WEB_LIBRARY_JS_PATH).'badge-studio/media/css/core.css" rel="stylesheet">';
2826

2927
// Add badge studio paths
30-
3128
$badgeStudio = [
3229
'core' => api_get_path(WEB_LIBRARY_JS_PATH).'badge-studio/',
3330
'media' => api_get_path(WEB_LIBRARY_JS_PATH).'badge-studio/media/',
@@ -45,13 +42,12 @@
4542
'id' => $skillId
4643
);
4744

48-
if ((isset($_FILES['image']) && $_FILES['image']['error'] == 0) || !empty($_POST['badge_studio_image'])) {
45+
if ((isset($_FILES['image']) && $_FILES['image']['error'] == 0) ||
46+
!empty($_POST['badge_studio_image'])
47+
) {
4948
$dirPermissions = api_get_permissions_for_new_directories();
50-
5149
$fileName = sha1($_POST['name']);
52-
5350
$badgePath = api_get_path(SYS_UPLOAD_PATH).'badges/';
54-
5551
$existsBadgesDirectory = is_dir($badgePath);
5652

5753
if (!$existsBadgesDirectory) {
@@ -68,7 +64,6 @@
6864
}
6965

7066
$skillImagePath = sprintf("%s%s.png", $badgePath, $fileName);
71-
7267
if (!empty($_POST['badge_studio_image'])) {
7368
$badgeImage = base64_decode(preg_replace('#^data:image/\w+;base64,#i', '', $_POST['badge_studio_image']));
7469
file_put_contents($skillImagePath, $badgeImage);

main/admin/skill_badge_list.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@
1313

1414
require_once __DIR__.'/../inc/global.inc.php';
1515

16-
if (!api_is_platform_admin() || api_get_setting('allow_skills_tool') !== 'true') {
17-
api_not_allowed(true);
18-
}
16+
api_protect_admin_script();
17+
Skill::isAllow();
1918

2019
$this_section = SECTION_PLATFORM_ADMIN;
2120

main/admin/skill_create.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@
1616
$this_section = SECTION_PLATFORM_ADMIN;
1717

1818
api_protect_admin_script();
19-
20-
if (api_get_setting('allow_skills_tool') != 'true') {
21-
api_not_allowed();
22-
}
19+
Skill::isAllow();
2320

2421
$interbreadcrumb[] = array("url" => 'index.php', "name" => get_lang('PlatformAdmin'));
2522
$interbreadcrumb[] = array('url' => 'skill_list.php', 'name' => get_lang('ManageSkills'));
@@ -49,7 +46,6 @@
4946
$allGradebooks = $objGradebook->find('all');
5047

5148
// This procedure is for check if there is already a Skill with no Parent (Root by default)
52-
5349
$isAlreadyRootSkill = false;
5450

5551
foreach ($allSkills as $checkedSkill) {

main/admin/skill_edit.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@
1616
$this_section = SECTION_PLATFORM_ADMIN;
1717

1818
api_protect_admin_script();
19-
20-
if (api_get_setting('allow_skills_tool') != 'true') {
21-
api_not_allowed();
22-
}
19+
Skill::isAllow();
2320

2421
$interbreadcrumb[] = array("url" => 'index.php', "name" => get_lang('PlatformAdmin'));
2522
$interbreadcrumb[] = array('url' => 'skill_list.php', 'name' => get_lang('ManageSkills'));

main/admin/skill_list.php

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@
1414
$this_section = SECTION_PLATFORM_ADMIN;
1515

1616
api_protect_admin_script();
17-
18-
if (api_get_setting('allow_skills_tool') != 'true') {
19-
api_not_allowed();
20-
}
17+
Skill::isAllow();
2118

2219
$action = isset($_GET['action']) ? $_GET['action'] : 'list';
2320
$skillId = isset($_GET['id']) ? intval($_GET['id']) : 0;
@@ -115,7 +112,7 @@
115112
//no break
116113
default:
117114
$interbreadcrumb[] = array("url" => 'index.php', "name" => get_lang('PlatformAdmin'));
118-
115+
119116
$toolbar = Display::url(
120117
Display::return_icon(
121118
'add.png',
@@ -125,7 +122,7 @@
125122
api_get_path(WEB_CODE_PATH).'admin/skill_create.php',
126123
['title' => get_lang('CreateSkill')]
127124
);
128-
125+
129126
$toolbar .= Display::url(
130127
Display::return_icon(
131128
'wheel_skill.png',
@@ -135,7 +132,7 @@
135132
api_get_path(WEB_CODE_PATH).'admin/skills_wheel.php',
136133
['title' => get_lang('SkillsWheel')]
137134
);
138-
135+
139136
$toolbar .= Display::url(
140137
Display::return_icon(
141138
'edit-skill.png',
@@ -145,7 +142,7 @@
145142
api_get_path(WEB_CODE_PATH).'admin/skill_badge_list.php',
146143
['title' => get_lang('BadgesManagement')]
147144
);
148-
145+
149146
$toolbar .= Display::url(
150147
Display::return_icon(
151148
'import_csv.png',
@@ -155,7 +152,7 @@
155152
api_get_path(WEB_CODE_PATH).'admin/skills_import.php',
156153
['title' => get_lang('ImportSkillsListCSV')]
157154
);
158-
155+
159156
$extraField = new ExtraField('skill');
160157
$arrayVals = $extraField->get_handler_field_info_by_tags('tags');
161158
$tags = [];

main/admin/skills.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@
1111
$this_section = SECTION_PLATFORM_ADMIN;
1212

1313
api_protect_admin_script();
14-
15-
if (api_get_setting('allow_skills_tool') != 'true') {
16-
api_not_allowed();
17-
}
14+
Skill::isAllow();
1815

1916
//Adds the JS needed to use the jqgrid
2017
$htmlHeadXtra[] = api_get_js('jquery.jsPlumb.all.js');

main/admin/skills_gradebook.php

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,31 +11,24 @@
1111
$this_section = SECTION_PLATFORM_ADMIN;
1212

1313
api_protect_admin_script();
14-
15-
if (api_get_setting('allow_skills_tool') != 'true') {
16-
api_not_allowed();
17-
}
14+
Skill::isAllow();
1815

1916
//Adds the JS needed to use the jqgrid
2017
$htmlHeadXtra[] = api_get_jqgrid_js();
2118

2219
$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : 'display';
2320

24-
2521
// setting breadcrumbs
26-
2722
$tool_name = get_lang('SkillsAndGradebooks');
2823
$interbreadcrumb[] = array('url' => 'index.php', 'name' => get_lang('PlatformAdmin'));
2924
if ($action == 'add_skill') {
3025
$interbreadcrumb[] = array('url' => 'skills_gradebook.php', 'name' => get_lang('SkillsAndGradebooks'));
3126
$tool_name = get_lang('Add');
3227
}
3328

34-
3529
Display::display_header($tool_name);
3630

3731
//jqgrid will use this URL to do the selects
38-
3932
$url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_gradebooks';
4033

4134
//The order is important you need to check the the $column variable in the model.ajax.php file
@@ -84,13 +77,13 @@
8477

8578
//With this function we can add actions to the jgrid (edit, delete, etc)
8679
$action_links = 'function action_formatter(cellvalue, options, rowObject) {
87-
//certificates
88-
if (rowObject[4] == 1) {
89-
return \'<a href="?action=add_skill&id=\'+options.rowId+\'">'.Display::return_icon('add.png', get_lang('AddSkill'), '', ICON_SIZE_SMALL).'</a>'.'\';
90-
} else {
91-
return \''.Display::return_icon('add_na.png', get_lang('YourGradebookFirstNeedsACertificateInOrderToBeLinkedToASkill'), '', ICON_SIZE_SMALL).''.'\';
92-
}
93-
}';
80+
//certificates
81+
if (rowObject[4] == 1) {
82+
return \'<a href="?action=add_skill&id=\'+options.rowId+\'">'.Display::return_icon('add.png', get_lang('AddSkill'), '', ICON_SIZE_SMALL).'</a>'.'\';
83+
} else {
84+
return \''.Display::return_icon('add_na.png', get_lang('YourGradebookFirstNeedsACertificateInOrderToBeLinkedToASkill'), '', ICON_SIZE_SMALL).''.'\';
85+
}
86+
}';
9487
?>
9588
<script>
9689
$(function() {
@@ -120,7 +113,6 @@
120113
}
121114
}
122115
$form->display();
123-
//echo Display::tag('h2',$gradebook_info['name']);
124116
break;
125117
}
126118
Display::display_footer();

main/admin/skills_profile.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,19 @@
1212
$this_section = SECTION_PLATFORM_ADMIN;
1313

1414
api_protect_admin_script();
15-
16-
if (api_get_setting('allow_skills_tool') != 'true') {
17-
api_not_allowed();
18-
}
15+
Skill::isAllow();
1916

2017
$interbreadcrumb[] = array(
2118
'url' => 'index.php',
2219
"name" => get_lang('PlatformAdmin'),
2320
);
2421

25-
$skill = new Skill();
26-
$skill_profile = new SkillProfile();
27-
$skill_rel_user = new SkillRelUser();
22+
$skill = new Skill();
23+
$skill_profile = new SkillProfile();
24+
$skill_rel_user = new SkillRelUser();
2825

2926
$url = api_get_path(WEB_AJAX_PATH).'skill.ajax.php';
30-
3127
$tpl = new Template(get_lang('Skills'));
32-
3328
$form = new FormValidator('profile_search');
3429

3530
$form->addElement('header', get_lang('SearchSkills'));

0 commit comments

Comments
 (0)