first commit

This commit is contained in:
CHIEFSOFT\ameye
2024-09-30 18:11:26 -04:00
commit e592ca6823
27270 changed files with 5002257 additions and 0 deletions
+10
View File
@@ -0,0 +1,10 @@
define("block_private_files/files_tree",["exports","core/tree"],(function(_exports,_tree){var obj;
/**
* Changes the display of directories and files into a tree.
*
* @module block_private_files/files_tree
* @copyright 2021 Shamim Rezaie <shamim@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=void 0,_tree=(obj=_tree)&&obj.__esModule?obj:{default:obj};_exports.init=blockId=>{new _tree.default("#".concat(blockId,' [role="tree"]'))}}));
//# sourceMappingURL=files_tree.min.js.map
@@ -0,0 +1 @@
{"version":3,"file":"files_tree.min.js","sources":["../src/files_tree.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see <http://www.gnu.org/licenses/>.\n\n/**\n * Changes the display of directories and files into a tree.\n *\n * @module block_private_files/files_tree\n * @copyright 2021 Shamim Rezaie <shamim@moodle.com>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\nimport Tree from 'core/tree';\n\n/**\n * The init function that does the job.\n * It changes the display of directories and files into a tree.\n *\n * @param {string} blockId\n */\nexport const init = (blockId) => {\n new Tree(`#${blockId} [role=\"tree\"]`);\n};\n"],"names":["blockId","Tree"],"mappings":";;;;;;;oJA8BqBA,cACbC,yBAASD"}
@@ -0,0 +1,33 @@
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Changes the display of directories and files into a tree.
*
* @module block_private_files/files_tree
* @copyright 2021 Shamim Rezaie <shamim@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
import Tree from 'core/tree';
/**
* The init function that does the job.
* It changes the display of directories and files into a tree.
*
* @param {string} blockId
*/
export const init = (blockId) => {
new Tree(`#${blockId} [role="tree"]`);
};
@@ -0,0 +1,77 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Manage user private area files
*
* @package block_private_files
* @copyright 2010 Dongsheng Cai <dongsheng@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class block_private_files extends block_base {
function init() {
$this->title = get_string('pluginname', 'block_private_files');
}
function specialization() {
}
function applicable_formats() {
return array('all' => true);
}
function instance_allow_multiple() {
return false;
}
function get_content() {
if ($this->content !== NULL) {
return $this->content;
}
if (empty($this->instance)) {
return null;
}
$this->content = new stdClass();
$this->content->text = '';
$this->content->footer = '';
if (isloggedin() && !isguestuser()) { // Show the block
$this->content = new stdClass();
//TODO: add capability check here!
$renderer = $this->page->get_renderer('block_private_files');
$this->content->text = $renderer->private_files_tree();
if (has_capability('moodle/user:manageownfiles', $this->context)) {
$this->content->footer = html_writer::link(
new moodle_url('/user/files.php'),
get_string('privatefilesmanage') . '...',
['data-action' => 'manageprivatefiles']);
$this->page->requires->js_call_amd(
'core_user/private_files',
'initModal',
['[data-action=manageprivatefiles]', \core_user\form\private_files::class]
);
}
}
return $this->content;
}
}
@@ -0,0 +1,46 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Privacy Subsystem implementation for block_private_files.
*
* @package block_private_files
* @copyright 2018 Zig Tan <zig@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace block_private_files\privacy;
defined('MOODLE_INTERNAL') || die();
/**
* Privacy Subsystem for block_private_files implementing null_provider.
*
* @copyright 2018 Zig Tan <zig@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider implements \core_privacy\local\metadata\null_provider {
/**
* Get the language string identifier with the component's language
* file to explain why this plugin stores no data.
*
* @return string
*/
public static function get_reason(): string {
return 'privacy:metadata';
}
}
+51
View File
@@ -0,0 +1,51 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Private files block caps.
*
* @package block_private_files
* @copyright Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$capabilities = array(
'block/private_files:myaddinstance' => array(
'captype' => 'write',
'contextlevel' => CONTEXT_SYSTEM,
'archetypes' => array(
'user' => CAP_ALLOW
),
'clonepermissionsfrom' => 'moodle/my:manageblocks'
),
'block/private_files:addinstance' => array(
'riskbitmask' => RISK_SPAM | RISK_XSS,
'captype' => 'write',
'contextlevel' => CONTEXT_BLOCK,
'archetypes' => array(
'editingteacher' => CAP_ALLOW,
'manager' => CAP_ALLOW
),
'clonepermissionsfrom' => 'moodle/site:manageblocks'
),
);
+29
View File
@@ -0,0 +1,29 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Manage files in folder in private area.
*
* This page is not used and now redirects to the page to manage the private files.
*
* @package block_private_files
* @copyright 2010 Petr Skoda (http://skodak.org)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require('../../config.php');
redirect(new moodle_url('/user/files.php'));
@@ -0,0 +1,29 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Strings for component 'block_private_files', language 'en', branch 'MOODLE_20_STABLE'
*
* @package block_private_files
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$string['pluginname'] = 'Private files';
$string['privatefiles'] = 'Private files';
$string['private_files:addinstance'] = 'Add a new private files block';
$string['private_files:myaddinstance'] = 'Add a new private files block to Dashboard';
$string['privacy:metadata'] = 'The Private files block only provides a view of, and a link to, the user\'s private files.';
+101
View File
@@ -0,0 +1,101 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Print private files tree
*
* @package block_private_files
* @copyright 2010 Dongsheng Cai <dongsheng@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
class block_private_files_renderer extends plugin_renderer_base {
/**
* Prints private files tree view
* @return string
*/
public function private_files_tree() {
return $this->render(new private_files_tree);
}
public function render_private_files_tree(private_files_tree $tree) {
if (empty($tree->dir['subdirs']) && empty($tree->dir['files'])) {
$html = $this->output->box(get_string('nofilesavailable', 'repository'));
} else {
$htmlid = 'private_files_tree_'.uniqid();
$this->page->requires->js_call_amd('block_private_files/files_tree', 'init', [$htmlid]);
$html = '<div id="'.$htmlid.'">';
$html .= $this->htmllize_tree($tree, $tree->dir, true);
$html .= '</div>';
}
return $html;
}
/**
* Internal function - creates htmls structure suitable for core/tree AMD.
*
* @param private_files_tree $tree The renderable tree.
* @param array $dir The directory in the tree
* @param bool $isroot If it is the root directory in the tree.
* @return string
*/
protected function htmllize_tree($tree, $dir, $isroot) {
global $CFG;
if (empty($dir['subdirs']) and empty($dir['files'])) {
return '';
}
if ($isroot) {
$result = '<ul role="tree" aria-label="' . s(get_string('privatefiles')) . '">';
} else {
$result = '<ul role="group" aria-hidden="true">';
}
foreach ($dir['subdirs'] as $subdir) {
$image = $this->output->pix_icon(file_folder_icon(), '');
$content = $this->htmllize_tree($tree, $subdir, false);
if ($content) {
$result .= '<li role="treeitem" aria-expanded="false"><p>' . $image . s($subdir['dirname']) . '</p>' .
$content . '</li>';
} else {
$result .= '<li role="treeitem"><p>' . $image . s($subdir['dirname']) . '</p></li>';
}
}
foreach ($dir['files'] as $file) {
$url = file_encode_url("$CFG->wwwroot/pluginfile.php", '/'.$tree->context->id.'/user/private'.$file->get_filepath().$file->get_filename(), true);
$filename = $file->get_filename();
$image = $this->output->pix_icon(file_file_icon($file), '');
$result .= '<li role="treeitem">'.html_writer::link($url, $image.$filename, ['tabindex' => -1]).'</li>';
}
$result .= '</ul>';
return $result;
}
}
class private_files_tree implements renderable {
public $context;
public $dir;
public function __construct() {
global $USER;
$this->context = context_user::instance($USER->id);
$fs = get_file_storage();
$this->dir = $fs->get_area_tree($this->context->id, 'user', 'private', 0);
}
}
+96
View File
@@ -0,0 +1,96 @@
/* Rule so that the table tree view works with word-wrap: break-word. */
.block_private_files .content table {
table-layout: fixed;
width: 100%;
}
.block_private_files .content .footer {
padding: 10px 0 0;
margin-top: .5em;
}
.block_private_files ul[role="tree"] {
margin: 0;
padding: 0;
}
.block_private_files ul,
.block_private_files li {
list-style: none;
}
.block_private_files [role="treeitem"] {
padding-left: 22px;
cursor: pointer;
}
.block_private_files [role="treeitem"] p {
margin-bottom: 0;
}
.block_private_files [role="treeitem"][aria-expanded] {
padding-left: 0;
}
.block_private_files [role="treeitem"][aria-expanded="false"] > p::before {
/*rtl:remove*/
content: url('[[pix:t/collapsed]]');
/*rtl:raw:
content: url('[[pix:t/collapsed_rtl]]');
*/
vertical-align: sub;
margin-right: 5px;
}
.block_private_files [role="treeitem"][aria-expanded="true"] > p::before {
content: url('[[pix:t/expanded]]');
vertical-align: sub;
margin-right: 5px;
}
.block_private_files [role="treeitem"]:not([aria-expanded]) {
background-image:
repeating-linear-gradient(
to right,
rgba(0, 0, 0, .5) 0,
rgba(0, 0, 0, .5) 1px,
rgba(255, 255, 255, 0) 1px,
rgba(255, 255, 255, 0) 2px
),
repeating-linear-gradient(
to top,
rgba(0, 0, 0, 0.5) 0,
rgba(0, 0, 0, 0.5) 1px,
rgba(255, 255, 255, 0) 1px,
rgba(255, 255, 255, 0) 2px
);
background-repeat: no-repeat, no-repeat;
/*rtl:remove*/
background-position: left 10px top 50%, left 8px top 0;
/*rtl:raw:
background-position: right 10px top 50%, right 8px top 0;
*/
background-size: 11px 1px, 1px 100%;
}
.block_private_files [role="treeitem"]:not([aria-expanded]):last-child {
background-size: 11px 1px, 1px 50%;
}
.block_private_files [role="group"] {
background-image:
repeating-linear-gradient(
to top,
rgba(0, 0, 0, 0.5) 0,
rgba(0, 0, 0, 0.5) 1px,
rgba(255, 255, 255, 0) 1px,
rgba(255, 255, 255, 0) 2px
);
background-repeat: no-repeat;
background-position: left 8px top 100%;
background-size: 1px 100%;
margin-left: 0;
}
.block_private_files [aria-hidden="true"]:not(.icon) {
display: none;
}
@@ -0,0 +1,28 @@
@block @block_private_files @_file_upload @javascript
Feature: The private files block allows users to store files privately in moodle on activity page
In order to store a private file in moodle
As a teacher
I can upload the file to my private files area using the private files block in an activity
Scenario: Upload a file to the private files block in an activity
Given the following "courses" exist:
| fullname | shortname | category |
| Course 1 | C1 | 0 |
And the following "users" exist:
| username | firstname | lastname | email |
| teacher1 | Teacher | 1 | teacher1@example.com |
And the following "course enrolments" exist:
| user | course | role |
| teacher1 | C1 | editingteacher |
And the following "activities" exist:
| activity | course | idnumber | name | intro |
| page | C1 | page1 | Test page name | Test page description |
And the following "blocks" exist:
| blockname | contextlevel | reference | pagetypepattern | defaultregion |
| private_files | Activity module | page1 | mod-page-* | side-pre |
And I am on the "Test page name" "page activity" page logged in as teacher1
And I should see "No files available" in the "Private files" "block"
When I follow "Manage private files..."
And I upload "blocks/private_files/tests/fixtures/testfile.txt" file to "Files" filemanager
And I press "Save changes"
Then I should see "testfile.txt" in the "Private files" "block"
@@ -0,0 +1,26 @@
@block @block_private_files @_file_upload @javascript
Feature: The private files block allows users to store files privately in moodle on course page
In order to store a private file in moodle
As a teacher
I can upload the file to my private files area using the private files block in a course
Scenario: Upload a file to the private files block from a course
Given the following "courses" exist:
| fullname | shortname | category |
| Course 1 | C1 | 0 |
And the following "users" exist:
| username | firstname | lastname | email |
| teacher1 | Teacher | 1 | teacher1@example.com |
And the following "course enrolments" exist:
| user | course | role |
| teacher1 | C1 | editingteacher |
And the following "blocks" exist:
| blockname | contextlevel | reference | pagetypepattern | defaultregion |
| private_files | Course | C1 | course-view-* | side-pre |
And I log in as "teacher1"
And I am on "Course 1" course homepage with editing mode on
And I should see "No files available" in the "Private files" "block"
When I follow "Manage private files..."
And I upload "blocks/private_files/tests/fixtures/testfile.txt" file to "Files" filemanager
And I press "Save changes"
Then I should see "testfile.txt" in the "Private files" "block"
@@ -0,0 +1,20 @@
@block @block_private_files @_file_upload @javascript
Feature: The private files block allows users to store files privately in moodle on dashboard
In order to store a private file in moodle
As a user
I can upload the file to my private files area using the private files block on the dashboard
Scenario: Upload a file to the private files block from the dashboard
Given the following "users" exist:
| username | firstname | lastname | email |
| teacher1 | Teacher | 1 | teacher1@example.com |
And the following "blocks" exist:
| blockname | contextlevel | reference | pagetypepattern | defaultregion |
| private_files | System | 1 | my-index | side-post |
And I log in as "teacher1"
And "Private files" "block" should exist
And I should see "No files available" in the "Private files" "block"
When I follow "Manage private files..."
And I upload "blocks/private_files/tests/fixtures/testfile.txt" file to "Files" filemanager
And I press "Save changes"
Then I should see "testfile.txt" in the "Private files" "block"
@@ -0,0 +1,32 @@
@block @block_private_files @_file_upload
Feature: The private files block allows users to store files privately in moodle on front page.
In order to store a private file in moodle
As a teacher
I can upload the file to my private files area using the private files block from the front page
Background:
Given the following "courses" exist:
| fullname | shortname | category |
| Course 1 | C1 | 0 |
And the following "users" exist:
| username | firstname | lastname | email |
| teacher1 | Teacher | 1 | teacher1@example.com |
And the following "blocks" exist:
| blockname | contextlevel | reference | pagetypepattern | defaultregion |
| private_files | System | 1 | site-index | side-pre |
Scenario: Try to view the private files block as a guest
Given I log in as "guest"
When I am on site homepage
Then "Private files" "block" should not exist
@javascript
Scenario: Upload a file to the private files block from the frontpage
Given I log in as "teacher1"
And I am on site homepage
And "Private files" "block" should exist
And I should see "No files available" in the "Private files" "block"
When I follow "Manage private files..."
And I upload "blocks/private_files/tests/fixtures/testfile.txt" file to "Files" filemanager
And I press "Save changes"
Then I should see "testfile.txt" in the "Private files" "block"
+1
View File
@@ -0,0 +1 @@
This is a test file
+29
View File
@@ -0,0 +1,29 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Version details
*
* @package block_private_files
* @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2024042200; // The current plugin version (Date: YYYYMMDDXX).
$plugin->requires = 2024041600; // Requires this Moodle version.
$plugin->component = 'block_private_files'; // Full name of the plugin (used for diagnostics)