From e4f413b4b3d39ce48e6a2eaa8181ad043b67a42c Mon Sep 17 00:00:00 2001 From: Martin Dougiamas Date: Thu, 22 Jul 2010 09:05:13 +0000 Subject: [PATCH] MDL-23302 Credit to Aparup. New cap moodle/user:manageownfiles to control private user files area --- blocks/private_files/block_private_files.php | 4 +++- lang/en/role.php | 1 + lib/db/access.php | 14 +++++++++++++- user/filesedit.php | 4 ++-- 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/blocks/private_files/block_private_files.php b/blocks/private_files/block_private_files.php index 1f2189a9809..4e3f0c8296d 100755 --- a/blocks/private_files/block_private_files.php +++ b/blocks/private_files/block_private_files.php @@ -60,7 +60,9 @@ class block_private_files extends block_base { $renderer = $this->page->get_renderer('block_private_files'); $this->content->text = $renderer->private_files_tree(); - $this->content->text .= $OUTPUT->single_button(new moodle_url('/user/filesedit.php'), get_string('myfilesmanage'), 'get'); + if (has_capability('moodle/user:manageownfiles', $this->context)) { + $this->content->text .= $OUTPUT->single_button(new moodle_url('/user/filesedit.php'), get_string('myfilesmanage'), 'get'); + } $this->content->footer = ''; } diff --git a/lang/en/role.php b/lang/en/role.php index 4dd18cb08a1..c4c777c7323 100644 --- a/lang/en/role.php +++ b/lang/en/role.php @@ -353,6 +353,7 @@ $string['user:editprofile'] = 'Edit user profile'; $string['user:loginas'] = 'Login as other users'; $string['user:manageblocks'] = 'Manage blocks on user profile of other users'; $string['user:manageownblocks'] = 'Manage blocks on own public user profile'; +$string['user:manageownfiles'] = 'Manage files on own private file areas'; $string['user:managesyspages'] = 'Configure default page layout for public user profiles'; $string['user:readuserblogs'] = 'See all user blogs'; $string['user:readuserposts'] = 'See all user posts'; diff --git a/lib/db/access.php b/lib/db/access.php index a4106583648..f941eec609e 100644 --- a/lib/db/access.php +++ b/lib/db/access.php @@ -522,7 +522,19 @@ $capabilities = array( 'captype' => 'write', 'contextlevel' => CONTEXT_SYSTEM, 'archetypes' => array( - 'user' => CAP_ALLOW, + 'user' => CAP_ALLOW + ) + ), + + // can the user manage their own files? + 'moodle/user:manageownfiles' => array( + + 'riskbitmap' => RISK_SPAM | RISK_PERSONAL, + + 'captype' => 'write', + 'contextlevel' => CONTEXT_SYSTEM, + 'archetypes' => array( + 'user' => CAP_ALLOW ) ), diff --git a/user/filesedit.php b/user/filesedit.php index 139c1a3892c..70646d8e2cd 100644 --- a/user/filesedit.php +++ b/user/filesedit.php @@ -31,9 +31,9 @@ require_login(); if (isguestuser()) { die(); } -//TODO: add capability check here! - $context = get_context_instance(CONTEXT_USER, $USER->id); +require_capability('moodle/user:manageownfiles', $context); + $title = get_string('myfiles'); $struser = get_string('user');