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
+57
View File
@@ -0,0 +1,57 @@
<?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/>.
/**
* Class for loading/storing access records from the DB.
*
* @package repository_onedrive
* @copyright 2017 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace repository_onedrive;
defined('MOODLE_INTERNAL') || die();
use core\persistent;
/**
* Class for loading/storing issuer from the DB
*
* @package repository_onedrive
* @copyright 2017 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class access extends persistent {
const TABLE = 'repository_onedrive_access';
/**
* Return the definition of the properties of this model.
*
* @return array
*/
protected static function define_properties() {
return array(
'permissionid' => array(
'type' => PARAM_RAW
),
'itemid' => array(
'type' => PARAM_RAW
)
);
}
}
@@ -0,0 +1,259 @@
<?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 repository_onedrive.
*
* @package repository_onedrive
* @copyright 2018 Zig Tan <zig@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace repository_onedrive\privacy;
use core_privacy\local\metadata\collection;
use core_privacy\local\request\approved_contextlist;
use core_privacy\local\request\approved_userlist;
use core_privacy\local\request\context;
use core_privacy\local\request\contextlist;
use core_privacy\local\request\transform;
use core_privacy\local\request\userlist;
use \core_privacy\local\request\writer;
defined('MOODLE_INTERNAL') || die();
/**
* Privacy Subsystem for repository_onedrive implementing metadata and plugin providers.
*
* @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\provider,
\core_privacy\local\request\core_userlist_provider,
\core_privacy\local\request\plugin\provider {
/**
* Returns meta data about this system.
*
* @param collection $collection The initialised collection to add items to.
* @return collection A listing of user data stored through this system.
*/
public static function get_metadata(collection $collection): collection {
$collection->add_external_location_link(
'onedrive.live.com',
[
'searchtext' => 'privacy:metadata:repository_onedrive:searchtext'
],
'privacy:metadata:repository_onedrive'
);
// The repository_onedrive has a 'repository_onedrive_access' table that contains user data.
$collection->add_database_table(
'repository_onedrive_access',
[
'itemid' => 'privacy:metadata:repository_onedrive:repository_onedrive_access:itemid',
'permissionid' => 'privacy:metadata:repository_onedrive:repository_onedrive_access:permissionid',
'timecreated' => 'privacy:metadata:repository_onedrive:repository_onedrive_access:timecreated',
'timemodified' => 'privacy:metadata:repository_onedrive:repository_onedrive_access:timemodified',
'usermodified' => 'privacy:metadata:repository_onedrive:repository_onedrive_access:usermodified'
],
'privacy:metadata:repository_onedrive'
);
return $collection;
}
/**
* Get the list of contexts that contain user information for the specified user.
*
* @param int $userid The user to search.
* @return contextlist $contextlist The contextlist containing the list of contexts used in this plugin.
*/
public static function get_contexts_for_userid(int $userid): contextlist {
$contextlist = new contextlist();
// The data is associated at the user context level, so retrieve the user's context id.
$sql = "SELECT c.id
FROM {repository_onedrive_access} roa
JOIN {context} c ON c.instanceid = roa.usermodified AND c.contextlevel = :contextuser
WHERE roa.usermodified = :userid
GROUP BY c.id";
$params = [
'contextuser' => CONTEXT_USER,
'userid' => $userid
];
$contextlist->add_from_sql($sql, $params);
return $contextlist;
}
/**
* Get the list of users who have data within a context.
*
* @param userlist $userlist The userlist containing the list of users who have data in this context/plugin combination.
*/
public static function get_users_in_context(userlist $userlist) {
$context = $userlist->get_context();
if (!$context instanceof \context_user) {
return;
}
// The data is associated at the user context level, so retrieve the user's context id.
$sql = "SELECT usermodified AS userid
FROM {repository_onedrive_access}
WHERE usermodified = ?";
$params = [$context->instanceid];
$userlist->add_from_sql('userid', $sql, $params);
}
/**
* Export all user data for the specified user, in the specified contexts.
*
* @param approved_contextlist $contextlist The approved contexts to export information for.
*/
public static function export_user_data(approved_contextlist $contextlist) {
global $DB;
// If the user has data, then only the User context should be present so get the first context.
$contexts = $contextlist->get_contexts();
if (count($contexts) == 0) {
return;
}
$context = reset($contexts);
// Sanity check that context is at the User context level, then get the userid.
if ($context->contextlevel !== CONTEXT_USER) {
return;
}
$userid = $context->instanceid;
$sql = "SELECT roa.id as id,
roa.itemid as itemid,
roa.permissionid as permissionid,
roa.timecreated as timecreated,
roa.timemodified as timemodified
FROM {repository_onedrive_access} roa
WHERE roa.usermodified = :userid";
$params = [
'userid' => $userid
];
$onedriveaccesses = $DB->get_records_sql($sql, $params);
$index = 0;
foreach ($onedriveaccesses as $onedriveaccess) {
// Data export is organised in: {User Context}/Repository plug-ins/{Plugin Name}/Access/{index}/data.json.
$index++;
$subcontext = [
get_string('plugin', 'core_repository'),
get_string('pluginname', 'repository_onedrive'),
get_string('access', 'repository_onedrive'),
$index
];
$data = (object) [
'itemid' => $onedriveaccess->itemid,
'permissionid' => $onedriveaccess->permissionid,
'timecreated' => transform::datetime($onedriveaccess->timecreated),
'timemodified' => transform::datetime($onedriveaccess->timemodified)
];
writer::with_context($context)->export_data($subcontext, $data);
}
}
/**
* Delete all data for all users in the specified context.
*
* @param context $context The specific context to delete data for.
*/
public static function delete_data_for_all_users_in_context(\context $context) {
global $DB;
// Sanity check that context is at the User context level, then get the userid.
if ($context->contextlevel !== CONTEXT_USER) {
return;
}
$userid = $context->instanceid;
$DB->delete_records('repository_onedrive_access', ['usermodified' => $userid]);
}
/**
* Delete all user data for the specified user, in the specified contexts.
*
* @param approved_contextlist $contextlist The approved contexts and user information to delete information for.
*/
public static function delete_data_for_user(approved_contextlist $contextlist) {
global $DB;
// If the user has data, then only the User context should be present so get the first context.
$contexts = $contextlist->get_contexts();
if (count($contexts) == 0) {
return;
}
$context = reset($contexts);
// Sanity check that context is at the User context level, then get the userid.
if ($context->contextlevel !== CONTEXT_USER) {
return;
}
$userid = $context->instanceid;
$DB->delete_records('repository_onedrive_access', ['usermodified' => $userid]);
}
/**
* Delete multiple users within a single context.
*
* @param approved_userlist $userlist The approved context and user information to delete information for.
*/
public static function delete_data_for_users(approved_userlist $userlist) {
global $DB;
$context = $userlist->get_context();
// Sanity check that context is at the User context level, then get the userid.
if ($context->contextlevel !== CONTEXT_USER) {
return;
}
$userids = $userlist->get_userids();
list($insql, $inparams) = $DB->get_in_or_equal($userids, SQL_PARAMS_NAMED);
$params = [
'contextid' => $context->id,
'contextuser' => CONTEXT_USER,
];
$params = array_merge($params, $inparams);
// Fetch the repository_onedrive_access IDs in the context for approved users.
$sql = "SELECT roa.id
FROM {repository_onedrive_access} roa
JOIN {context} c ON c.instanceid = roa.usermodified
AND c.contextlevel = :contextuser
AND c.id = :contextid
WHERE roa.usermodified {$insql}";
$accessids = $DB->get_fieldset_sql($sql, $params);
// Delete the relevant repository_onedrive_access data.
list($insql, $params) = $DB->get_in_or_equal($accessids, SQL_PARAMS_NAMED);
$DB->delete_records_select('repository_onedrive_access', "id {$insql}", $params);
}
}
@@ -0,0 +1,90 @@
<?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/>.
/**
* A scheduled task.
*
* @package repository_onedrive
* @copyright 2017 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace repository_onedrive;
use \core\task\scheduled_task;
use DateTime;
use DateInterval;
use repository_exception;
use \core\oauth2\rest_exception;
defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot . '/repository/lib.php');
/**
* Simple task to delete temporary permission records.
* @package repository_onedrive
* @copyright 2017 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class remove_temp_access_task extends scheduled_task {
/**
* Get a descriptive name for this task (shown to admins).
*
* @return string
*/
public function get_name() {
return get_string('removetempaccesstask', 'repository_onedrive');
}
/**
* Do the job.
* Throw exceptions on errors (the job will be retried).
*/
public function execute() {
$accessrecords = access::get_records();
$expires = new DateTime();
$expires->sub(new DateInterval("P7D"));
$timestamp = $expires->getTimestamp();
$issuerid = get_config('onedrive', 'issuerid');
$issuer = \core\oauth2\api::get_issuer($issuerid);
// Add the current user as an OAuth writer.
$systemauth = \core\oauth2\api::get_system_oauth_client($issuer);
if ($systemauth === false) {
$details = 'Cannot connect as system user';
throw new repository_exception('errorwhilecommunicatingwith', 'repository', '', $details);
}
$systemservice = new \repository_onedrive\rest($systemauth);
foreach ($accessrecords as $access) {
if ($access->get('timemodified') < $timestamp) {
$params = ['permissionid' => $access->get('permissionid'), 'itemid' => $access->get('itemid')];
try {
$systemservice->call('delete_permission', $params);
} catch (rest_exception $re) {
// We log and give up here or we will always fail for eternity.
mtrace('Failed to remove access from file: ' . $access->get('itemid'));
}
$access->delete();
}
}
}
}
+141
View File
@@ -0,0 +1,141 @@
<?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/>.
/**
* Microsoft Graph API Rest Interface.
*
* @package repository_onedrive
* @copyright 2017 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace repository_onedrive;
defined('MOODLE_INTERNAL') || die();
/**
* Microsoft Graph API Rest Interface.
*
* @copyright 2017 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class rest extends \core\oauth2\rest {
/**
* Define the functions of the rest API.
*
* @return array Example:
* [ 'listFiles' => [ 'method' => 'get', 'endpoint' => 'http://...', 'args' => [ 'folder' => PARAM_STRING ] ] ]
*/
public function get_api_functions() {
return [
'list' => [
'endpoint' => 'https://graph.microsoft.com/v1.0/me/drive/{parent}/children',
'method' => 'get',
'args' => [
'$select' => PARAM_RAW,
'$expand' => PARAM_RAW,
'parent' => PARAM_RAW,
'$skip' => PARAM_INT,
'$skipToken' => PARAM_RAW,
'$count' => PARAM_INT
],
'response' => 'json'
],
'search' => [
'endpoint' => 'https://graph.microsoft.com/v1.0/me/drive/{parent}/search(q=\'{search}\')',
'method' => 'get',
'args' => [
'search' => PARAM_NOTAGS,
'$select' => PARAM_RAW,
'parent' => PARAM_RAW,
'$skip' => PARAM_INT,
'$skipToken' => PARAM_RAW,
'$count' => PARAM_INT
],
'response' => 'json'
],
'get' => [
'endpoint' => 'https://graph.microsoft.com/v1.0/me/drive/items/{fileid}',
'method' => 'get',
'args' => [
'fileid' => PARAM_RAW,
'$select' => PARAM_RAW,
'$expand' => PARAM_RAW
],
'response' => 'json'
],
'create_permission' => [
'endpoint' => 'https://graph.microsoft.com/v1.0/me/drive/items/{fileid}/invite',
'method' => 'post',
'args' => [
'fileid' => PARAM_RAW
],
'response' => 'json'
],
'create_upload' => [
'endpoint' => 'https://graph.microsoft.com/v1.0/me/drive/items/{parentid}:/{filename}:/createUploadSession',
'method' => 'post',
'args' => [
'parentid' => PARAM_RAW,
'filename' => PARAM_RAW
],
'response' => 'json'
],
'get_file_by_path' => [
'endpoint' => 'https://graph.microsoft.com/v1.0/me/drive/root:/{fullpath}',
'method' => 'get',
'args' => [
'fullpath' => PARAM_RAW,
'$select' => PARAM_RAW
],
'response' => 'json'
],
'create_folder' => [
'endpoint' => 'https://graph.microsoft.com/v1.0/me/drive/items/{parentid}/children',
'method' => 'post',
'args' => [
'parentid' => PARAM_RAW
],
'response' => 'json'
],
'create_link' => [
'endpoint' => 'https://graph.microsoft.com/v1.0/me/drive/items/{fileid}/createLink',
'method' => 'post',
'args' => [
'fileid' => PARAM_RAW
],
'response' => 'json'
],
'delete_file_by_path' => [
'endpoint' => 'https://graph.microsoft.com/v1.0/me/drive/root:/{fullpath}',
'method' => 'delete',
'args' => [
'fullpath' => PARAM_RAW,
],
'response' => 'json'
],
'delete_permission' => [
'endpoint' => 'https://graph.microsoft.com/v1.0/me/drive/items/{fileid}/permissions/{permissionid}',
'method' => 'delete',
'args' => [
'fileid' => PARAM_RAW,
'permissionid' => PARAM_RAW
],
'response' => 'json'
],
];
}
}
+33
View File
@@ -0,0 +1,33 @@
<?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/>.
/**
* Capability definitions for onedrive repository
*
* @package repository_onedrive
* @copyright 2012 Lancaster University Network Services Ltd
* @author Dan Poltawski <dan.poltawski@luns.net.uk>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$capabilities = array(
'repository/onedrive:view' => array(
'captype' => 'read',
'contextlevel' => CONTEXT_MODULE,
'archetypes' => array(
'user' => CAP_ALLOW
)
)
);
+39
View File
@@ -0,0 +1,39 @@
<?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/>.
/**
* Cache definitions.
*
* @package repository_onedrive
* @copyright 2013 Dan Poltawski <dan@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$definitions = array(
// Used to store file ids for folders.
// The keys used are full path to the folder, the values are the id in office 365.
// The static acceleration size has been based upon the depths of a single path.
'folder' => array(
'mode' => cache_store::MODE_APPLICATION,
'simplekeys' => false,
'simpledata' => true,
'staticacceleration' => true,
'staticaccelerationsize' => 10,
'canuselocalstore' => true
),
);
+22
View File
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8" ?>
<XMLDB PATH="repository/onedrive/db" VERSION="20170314" COMMENT="XMLDB file for Moodle repository/onedrive"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd"
>
<TABLES>
<TABLE NAME="repository_onedrive_access" COMMENT="List of temporary access grants.">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
<FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="timecreated" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="usermodified" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="permissionid" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" COMMENT="The permission id in OneDrive."/>
<FIELD NAME="itemid" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" COMMENT="The item id in OneDrive."/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
<KEY NAME="usermodifiedkey" TYPE="foreign" FIELDS="usermodified" REFTABLE="user" REFFIELDS="id"/>
</KEYS>
</TABLE>
</TABLES>
</XMLDB>
+43
View File
@@ -0,0 +1,43 @@
<?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/>.
/**
* Definition of repository_onedrive scheduled tasks.
*
* The handlers defined on this file are processed and registered into
* the Moodle DB after any install or upgrade operation. All plugins
* support this.
*
* @package repository_onedrive
* @copyright 2017 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
/* List of handlers */
$tasks = array(
array(
'classname' => 'repository_onedrive\remove_temp_access_task',
'blocking' => 0,
'minute' => 'R',
'hour' => 'R',
'day' => '*',
'dayofweek' => 'R',
'month' => '*'
),
);
+38
View File
@@ -0,0 +1,38 @@
<?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/>.
/**
* Upgrade this plugin.
*
* @param int $oldversion the version we are upgrading from
* @package repository_onedrive
* @return bool result
*/
function xmldb_repository_onedrive_upgrade($oldversion) {
// Automatically generated Moodle v4.1.0 release upgrade line.
// Put any upgrade step following this.
// Automatically generated Moodle v4.2.0 release upgrade line.
// Put any upgrade step following this.
// Automatically generated Moodle v4.3.0 release upgrade line.
// Put any upgrade step following this.
// Automatically generated Moodle v4.4.0 release upgrade line.
// Put any upgrade step following this.
return true;
}
+57
View File
@@ -0,0 +1,57 @@
<?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/>.
/**
* Import files from skydrive.
*
* @package repository_onedrive
* @copyright 2017 Damyon Wiese <damyon@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once(__DIR__ . '/../../config.php');
$PAGE->set_url('/repository/onedrive/importskydrive.php');
$PAGE->set_context(context_system::instance());
$strheading = get_string('importskydrivefiles', 'repository_onedrive');
$PAGE->set_title($strheading);
$PAGE->set_heading($strheading);
require_login();
require_capability('moodle/site:config', context_system::instance());
$confirm = optional_param('confirm', false, PARAM_BOOL);
if ($confirm) {
require_sesskey();
require_once($CFG->dirroot . '/repository/lib.php');
require_once($CFG->dirroot . '/repository/onedrive/lib.php');
if (repository_onedrive::import_skydrive_files()) {
$mesg = get_string('skydrivefilesimported', 'repository_onedrive');
redirect(new moodle_url('/admin/repository.php'), $mesg, null, \core\output\notification::NOTIFY_SUCCESS);
} else {
$mesg = get_string('skydrivefilesnotimported', 'repository_onedrive');
redirect(new moodle_url('/admin/repository.php'), $mesg, null, \core\output\notification::NOTIFY_ERROR);
}
} else {
$continueurl = new moodle_url('/repository/onedrive/importskydrive.php', ['confirm' => true]);
$cancelurl = new moodle_url('/admin/repository.php');
echo $OUTPUT->header();
echo $OUTPUT->confirm(get_string('confirmimportskydrive', 'repository_onedrive'), $continueurl, $cancelurl);
echo $OUTPUT->footer();
}
@@ -0,0 +1,56 @@
<?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/>.
/**
* Language file definitions for onedrive repository
*
* @package repository_onedrive
* @copyright 2012 Lancaster University Network Services Ltd
* @author Dan Poltawski <dan.poltawski@luns.net.uk>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$string['access'] = 'Access';
$string['both'] = 'Internal and external';
$string['cachedef_folder'] = 'OneDrive file IDs for folders in the system account';
$string['configplugin'] = 'Configure OneDrive plugin';
$string['confirmimportskydrive'] = 'Are you sure you want to import all files from the Microsoft SkyDrive repository to the Microsoft OneDrive repository? The Microsoft OneDrive repository must be configured and working for imported files to continue working as before. Warning: This action cannot be undone!';
$string['defaultreturntype'] = 'Default return type';
$string['external'] = 'External (only links stored in Moodle)';
$string['fileoptions'] = 'The types and defaults for returned files is configurable here. Note that all files linked externally will be updated so that the owner is the Moodle system account.';
$string['importskydrivefiles'] = 'Import files from Microsoft SkyDrive repository';
$string['internal'] = 'Internal (files stored in Moodle)';
$string['issuer_help'] = 'Select the OAuth 2 service that is configured to talk to the OneDrive API. If the service does not exist yet, you will need to create it.';
$string['issuer'] = 'OAuth 2 service';
$string['mysitenotfound'] = 'You have never logged into OneDrive before. You must log in to OneDrive at least once before it can be used with Moodle.';
$string['oauth2serviceslink'] = '<a href="{$a}" title="Link to OAuth 2 services configuration">OAuth 2 services configuration</a>';
$string['owner'] = 'Owned by: {$a}';
$string['pluginname'] = 'Microsoft OneDrive';
$string['removetempaccesstask'] = 'Remove temporary write access from controlled links';
$string['searchfor'] = 'Search for {$a}';
$string['servicenotenabled'] = 'Access not configured.';
$string['skydrivefilesexist'] = 'The Microsoft SkyDrive repository is enabled but it has been deprecated. Please ensure you migrate files from SkyDrive to the OneDrive repository as soon as possible. In Moodle 4.4 it will no longer be possible.';
$string['skydrivefilesimported'] = 'All files were imported from the Microsoft SkyDrive repository.';
$string['skydrivefilesnotimported'] = 'Some files could not be imported from the Microsoft SkyDrive repository.';
$string['onedrive:view'] = 'View OneDrive repository';
$string['supportedreturntypes'] = 'Supported files';
$string['privacy:metadata:repository_onedrive'] = 'The Microsoft OneDrive repository stores temporary access grants, and transmits user data from Moodle to the remote system.';
$string['privacy:metadata:repository_onedrive:searchtext'] = 'The Microsoft OneDrive repository user search text query.';
$string['privacy:metadata:repository_onedrive:repository_onedrive_access:itemid'] = 'The Microsoft OneDrive with a temporary access grant item ID.';
$string['privacy:metadata:repository_onedrive:repository_onedrive_access:permissionid'] = 'The Microsoft OneDrive temporary access grant permission ID.';
$string['privacy:metadata:repository_onedrive:repository_onedrive_access:timecreated'] = 'The Microsoft OneDrive temporary access grant creation date/time.';
$string['privacy:metadata:repository_onedrive:repository_onedrive_access:timemodified'] = 'The Microsoft OneDrive temporary access grant modification date/time.';
$string['privacy:metadata:repository_onedrive:repository_onedrive_access:usermodified'] = 'The ID of the user modifying the Microsoft OneDrive temporary access grant.';
File diff suppressed because it is too large Load Diff
Binary file not shown.

After

Width:  |  Height:  |  Size: 853 B

+1
View File
@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" height="32" width="32" preserveAspectRatio="xMinYMid meet"><g transform="matrix(.55172 0 0 .55172 .552 .552)"><path fill="none" d="M-1-1h58v58H-1z"/></g><g transform="translate(-1.211 -2.066) scale(.6151)"><g fill="#094ab2" stroke="#094ab2"><path d="M47.963 32.467c7.527 4.344 6.331 9.334 3.062 11.029l-14.586-.014-18.065-.13c-2.65-1.029-3.842-2.589-4.106-6.403 1.148-4.123 1.167-4.085 6.664-6.195 1.515-4.786 4.461-7.46 8.008-7.813 3.685-.729 5.165 1.3 7.794 3.309 3.278.018 6.292-.597 8.922.875 1.718 1.59 1.735 3.522 2.307 5.342z"/><path d="M19.216 29.211c1.84-3.976 2.624-7.455 9.914-8.843 3.238-.016 5.273-.154 8.198 3.138l4.01.033c-2.19-6.436-6.606-10.06-11.881-9.444-3.962.266-7.562 2.55-8.714 5.304-3.467-.695-6.362-.2-7.769.166-2.787 1.231-4.41 2.822-5.097 8.758-3.847 1.111-4.882 3.31-5.328 5.647.017 3.83.678 6.237 4.03 7.577l6.368-.057c-1.52-3.856-1.958-10.591 6.269-12.279z"/></g></g></svg>

After

Width:  |  Height:  |  Size: 943 B

@@ -0,0 +1,387 @@
<?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/>.
/**
* Unit tests for the repository_onedrive implementation of the privacy API.
*
* @package repository_onedrive
* @category test
* @copyright 2018 Zig Tan <zig@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace repository_onedrive\privacy;
defined('MOODLE_INTERNAL') || die();
use core_privacy\local\metadata\collection;
use core_privacy\local\request\writer;
use core_privacy\local\request\approved_contextlist;
use core_privacy\local\request\approved_userlist;
use repository_onedrive\privacy\provider;
/**
* Unit tests for the repository_onedrive implementation of the privacy API.
*
* @copyright 2018 Zig Tan <zig@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider_test extends \core_privacy\tests\provider_testcase {
/**
* Overriding setUp() function to always reset after tests.
*/
public function setUp(): void {
$this->resetAfterTest(true);
}
/**
* Test for provider::get_contexts_for_userid().
*/
public function test_get_contexts_for_userid(): void {
global $DB;
// Test setup.
$user = $this->getDataGenerator()->create_user();
$this->setUser($user);
// Add two repository_onedrive_access records for the User.
$access = (object)[
'usermodified' => $user->id,
'itemid' => 'Some onedrive access item data',
'permissionid' => 'Some onedrive access permission data',
'timecreated' => date('u'),
'timemodified' => date('u'),
];
$DB->insert_record('repository_onedrive_access', $access);
$access = (object)[
'usermodified' => $user->id,
'itemid' => 'Another onedrive access item data',
'permissionid' => 'Another onedrive access permission data',
'timecreated' => date('u'),
'timemodified' => date('u'),
];
$DB->insert_record('repository_onedrive_access', $access);
// Test there are two repository_onedrive_access records for the User.
$access = $DB->get_records('repository_onedrive_access', ['usermodified' => $user->id]);
$this->assertCount(2, $access);
// Test the User's retrieved contextlist contains only one context.
$contextlist = provider::get_contexts_for_userid($user->id);
$contexts = $contextlist->get_contexts();
$this->assertCount(1, $contexts);
// Test the User's contexts equal the User's own context.
$context = reset($contexts);
$this->assertEquals(CONTEXT_USER, $context->contextlevel);
$this->assertEquals($user->id, $context->instanceid);
}
/**
* Test for provider::test_get_users_in_context().
*/
public function test_get_users_in_context(): void {
global $DB;
$component = 'repository_onedrive';
// Test setup.
$user1 = $this->getDataGenerator()->create_user();
$user2 = $this->getDataGenerator()->create_user();
$u1id = $user1->id;
$u2id = $user2->id;
// Add a repository_onedrive_access records for each user.
$this->setUser($user1);
$access = (object)[
'usermodified' => $u1id,
'itemid' => 'Some onedrive access item data',
'permissionid' => 'Some onedrive access permission data',
'timecreated' => date('u'),
'timemodified' => date('u'),
];
$DB->insert_record('repository_onedrive_access', $access);
$this->setUser($user2);
$access = (object)[
'usermodified' => $u2id,
'itemid' => 'Another onedrive access item data',
'permissionid' => 'Another onedrive access permission data',
'timecreated' => date('u'),
'timemodified' => date('u'),
];
$DB->insert_record('repository_onedrive_access', $access);
// Fetch the context of each user's access record.
$contextlist = provider::get_contexts_for_userid($u1id);
$u1contexts = $contextlist->get_contexts();
$this->assertCount(1, $u1contexts);
$contextlist = provider::get_contexts_for_userid($u2id);
$u2contexts = $contextlist->get_contexts();
$this->assertCount(1, $u2contexts);
$contexts = [
$u1id => $u1contexts[0],
$u2id => $u2contexts[0],
];
// Test context 1 only contains user 1.
$userlist = new \core_privacy\local\request\userlist($contexts[$u1id], $component);
provider::get_users_in_context($userlist);
$this->assertCount(1, $userlist);
$actual = $userlist->get_userids();
$this->assertEquals([$u1id], $actual);
// Test context 2 only contains user 2.
$userlist = new \core_privacy\local\request\userlist($contexts[$u2id], $component);
provider::get_users_in_context($userlist);
$this->assertCount(1, $userlist);
$actual = $userlist->get_userids();
$this->assertEquals([$u2id], $actual);
// Test the contexts match the users' contexts.
$this->assertEquals($u1id, $contexts[$u1id]->instanceid);
$this->assertEquals($u2id, $contexts[$u2id]->instanceid);
}
/**
* Test for provider::export_user_data().
*/
public function test_export_user_data(): void {
global $DB;
// Test setup.
$user = $this->getDataGenerator()->create_user();
$this->setUser($user);
// Add two repository_onedrive_access records for the User.
$access = (object)[
'usermodified' => $user->id,
'itemid' => 'Some onedrive access item data',
'permissionid' => 'Some onedrive access permission data',
'timecreated' => date('u'),
'timemodified' => date('u'),
];
$DB->insert_record('repository_onedrive_access', $access);
$access = (object)[
'usermodified' => $user->id,
'itemid' => 'Another onedrive access item data',
'permissionid' => 'Another onedrive access permission data',
'timecreated' => date('u'),
'timemodified' => date('u'),
];
$DB->insert_record('repository_onedrive_access', $access);
// Test there are two repository_onedrive_access records for the User.
$access = $DB->get_records('repository_onedrive_access', ['usermodified' => $user->id]);
$this->assertCount(2, $access);
// Test the User's retrieved contextlist contains only one context.
$contextlist = provider::get_contexts_for_userid($user->id);
$contexts = $contextlist->get_contexts();
$this->assertCount(1, $contexts);
// Test the User's contexts equal the User's own context.
$context = reset($contexts);
$this->assertEquals(CONTEXT_USER, $context->contextlevel);
$this->assertEquals($user->id, $context->instanceid);
$approvedcontextlist = new approved_contextlist($user, 'repository_onedrive', $contextlist->get_contextids());
// Retrieve repository_onedrive_access data only for this user.
provider::export_user_data($approvedcontextlist);
// Test the repository_onedrive_access data is exported at the User context level.
$user = $approvedcontextlist->get_user();
$contextuser = \context_user::instance($user->id);
$writer = writer::with_context($contextuser);
$this->assertTrue($writer->has_any_data());
}
/**
* Test for provider::delete_data_for_all_users_in_context().
*/
public function test_delete_data_for_all_users_in_context(): void {
global $DB;
// Test setup.
$user = $this->getDataGenerator()->create_user();
$this->setUser($user);
// Add two repository_onedrive_access records for the User.
$access = (object)[
'usermodified' => $user->id,
'itemid' => 'Some onedrive access item data',
'permissionid' => 'Some onedrive access permission data',
'timecreated' => date('u'),
'timemodified' => date('u'),
];
$DB->insert_record('repository_onedrive_access', $access);
$access = (object)[
'usermodified' => $user->id,
'itemid' => 'Another onedrive access item data',
'permissionid' => 'Another onedrive access permission data',
'timecreated' => date('u'),
'timemodified' => date('u'),
];
$DB->insert_record('repository_onedrive_access', $access);
// Test there are two repository_onedrive_access records for the User.
$access = $DB->get_records('repository_onedrive_access', ['usermodified' => $user->id]);
$this->assertCount(2, $access);
// Test the User's retrieved contextlist contains only one context.
$contextlist = provider::get_contexts_for_userid($user->id);
$contexts = $contextlist->get_contexts();
$this->assertCount(1, $contexts);
// Test the User's contexts equal the User's own context.
$context = reset($contexts);
$this->assertEquals(CONTEXT_USER, $context->contextlevel);
$this->assertEquals($user->id, $context->instanceid);
// Test delete all users content by context.
provider::delete_data_for_all_users_in_context($context);
$access = $DB->get_records('repository_onedrive_access', ['usermodified' => $user->id]);
$this->assertCount(0, $access);
}
/**
* Test for provider::delete_data_for_user().
*/
public function test_delete_data_for_user(): void {
global $DB;
// Test setup.
$user1 = $this->getDataGenerator()->create_user();
$user2 = $this->getDataGenerator()->create_user();
$this->setUser($user1);
// Add 3 repository_onedrive_accesss records for User 1.
$noaccess = 3;
for ($a = 0; $a < $noaccess; $a++) {
$access = (object)[
'usermodified' => $user1->id,
'itemid' => 'Some onedrive access item data - ' . $a,
'permissionid' => 'Some onedrive access permission data - ' . $a,
'timecreated' => date('u'),
'timemodified' => date('u'),
];
$DB->insert_record('repository_onedrive_access', $access);
}
// Add 1 repository_onedrive_accesss record for User 2.
$access = (object)[
'usermodified' => $user2->id,
'itemid' => 'Some onedrive access item data',
'permissionid' => 'Some onedrive access permission data',
'timecreated' => date('u'),
'timemodified' => date('u'),
];
$DB->insert_record('repository_onedrive_access', $access);
// Test the created repository_onedrive records for User 1 equals test number of access specified.
$communities = $DB->get_records('repository_onedrive_access', ['usermodified' => $user1->id]);
$this->assertCount($noaccess, $communities);
// Test the created repository_onedrive records for User 2 equals 1.
$communities = $DB->get_records('repository_onedrive_access', ['usermodified' => $user2->id]);
$this->assertCount(1, $communities);
// Test the deletion of repository_onedrive_access records for User 1 results in zero records.
$contextlist = provider::get_contexts_for_userid($user1->id);
$contexts = $contextlist->get_contexts();
$this->assertCount(1, $contexts);
// Test the User's contexts equal the User's own context.
$context = reset($contexts);
$this->assertEquals(CONTEXT_USER, $context->contextlevel);
$this->assertEquals($user1->id, $context->instanceid);
$approvedcontextlist = new approved_contextlist($user1, 'repository_onedrive', $contextlist->get_contextids());
provider::delete_data_for_user($approvedcontextlist);
$access = $DB->get_records('repository_onedrive_access', ['usermodified' => $user1->id]);
$this->assertCount(0, $access);
// Test that User 2's single repository_onedrive_access record still exists.
$contextlist = provider::get_contexts_for_userid($user2->id);
$contexts = $contextlist->get_contexts();
$this->assertCount(1, $contexts);
// Test the User's contexts equal the User's own context.
$context = reset($contexts);
$this->assertEquals(CONTEXT_USER, $context->contextlevel);
$this->assertEquals($user2->id, $context->instanceid);
$access = $DB->get_records('repository_onedrive_access', ['usermodified' => $user2->id]);
$this->assertCount(1, $access);
}
/**
* Test for provider::delete_data_for_users().
*/
public function test_delete_data_for_users(): void {
global $DB;
$component = 'repository_onedrive';
// Test setup.
$user1 = $this->getDataGenerator()->create_user();
$user2 = $this->getDataGenerator()->create_user();
$this->setUser($user1);
// Add 3 repository_onedrive_accesss records for User 1.
$noaccess = 3;
for ($a = 0; $a < $noaccess; $a++) {
$access = (object)[
'usermodified' => $user1->id,
'itemid' => 'Some onedrive access item data for user 1 - ' . $a,
'permissionid' => 'Some onedrive access permission data - ' . $a,
'timecreated' => date('u'),
'timemodified' => date('u'),
];
$DB->insert_record('repository_onedrive_access', $access);
}
// Add 1 repository_onedrive_accesss record for User 2.
$access = (object)[
'usermodified' => $user2->id,
'itemid' => 'Some onedrive access item data for user 2',
'permissionid' => 'Some onedrive access permission data',
'timecreated' => date('u'),
'timemodified' => date('u'),
];
$DB->insert_record('repository_onedrive_access', $access);
// Test the created repository_onedrive records for User 1 equals test number of access specified.
$communities = $DB->get_records('repository_onedrive_access', ['usermodified' => $user1->id]);
$this->assertCount($noaccess, $communities);
// Test the created repository_onedrive records for User 2 equals 1.
$communities = $DB->get_records('repository_onedrive_access', ['usermodified' => $user2->id]);
$this->assertCount(1, $communities);
// Fetch the context of each user's access record.
$contextlist = provider::get_contexts_for_userid($user1->id);
$u1contexts = $contextlist->get_contexts();
// Test the deletion of context 1 results in deletion of user 1's records only.
$approveduserids = [$user1->id, $user2->id];
$approvedlist = new approved_userlist($u1contexts[0], $component, $approveduserids);
provider::delete_data_for_users($approvedlist);
$access = $DB->get_records('repository_onedrive_access', ['usermodified' => $user1->id]);
$this->assertCount(0, $access);
// Ensure user 2's record still exists.
$access = $DB->get_records('repository_onedrive_access', ['usermodified' => $user2->id]);
$this->assertCount(1, $access);
}
}
+30
View File
@@ -0,0 +1,30 @@
<?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 for onedrive repository
*
* @package repository_onedrive
* @copyright 2012 Lancaster University Network Services Ltd
* @author Dan Poltawski <dan.poltawski@luns.net.uk>
* @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 = 'repository_onedrive'; // Full name of the plugin (used for diagnostics).