MDL-59505 oauth2: Fix storage of access controlled links

When files are copied into the system account's drive, they are put into
folders respecting the structure of contexts. Folder names were based on
context names only and so were likely to collide (such as with users
with the same name).

The patch ads context instance identifiers to the name so that they can
be identified more reliably.
This commit is contained in:
David Mudrák
2017-09-21 22:15:47 +02:00
parent 50126511aa
commit d12b219aae
2 changed files with 38 additions and 4 deletions
+19 -2
View File
@@ -901,6 +901,8 @@ class repository_googledocs extends repository {
* @return string updated reference (final one before it's saved to db).
*/
public function reference_file_selected($reference, $context, $component, $filearea, $itemid) {
global $CFG, $SITE;
// What we need to do here is transfer ownership to the system user (or copy)
// then set the permissions so anyone with the share link can view,
// finally update the reference to contain the share link if it was not
@@ -949,8 +951,23 @@ class repository_googledocs extends repository {
$fullpath = 'root';
$allfolders = [];
foreach ($contextlist as $context) {
// Make sure a folder exists here.
$foldername = clean_param($context->get_context_name(), PARAM_PATH);
// Prepare human readable context folders names, making sure they are still unique within the site.
$prevlang = force_current_language($CFG->lang);
$foldername = $context->get_context_name();
force_current_language($prevlang);
if ($context->contextlevel == CONTEXT_SYSTEM) {
// Append the site short name to the root folder.
$foldername .= ' ('.$SITE->shortname.')';
// Append the relevant object id.
} else if ($context->instanceid) {
$foldername .= ' (id '.$context->instanceid.')';
} else {
// This does not really happen but just in case.
$foldername .= ' (ctx '.$context->id.')';
}
$foldername = clean_param($foldername, PARAM_PATH);
$allfolders[] = $foldername;
}
+19 -2
View File
@@ -848,6 +848,8 @@ class repository_onedrive extends repository {
* @return string $modifiedreference (final one before saving to DB)
*/
public function reference_file_selected($reference, $context, $component, $filearea, $itemid) {
global $CFG, $SITE;
// What we need to do here is transfer ownership to the system user (or copy)
// then set the permissions so anyone with the share link can view,
// finally update the reference to contain the share link if it was not
@@ -897,8 +899,23 @@ class repository_onedrive extends repository {
$fullpath = '';
$allfolders = [];
foreach ($contextlist as $context) {
// Make sure a folder exists here.
$foldername = urlencode(clean_param($context->get_context_name(), PARAM_PATH));
// Prepare human readable context folders names, making sure they are still unique within the site.
$prevlang = force_current_language($CFG->lang);
$foldername = $context->get_context_name();
force_current_language($prevlang);
if ($context->contextlevel == CONTEXT_SYSTEM) {
// Append the site short name to the root folder.
$foldername .= '_'.$SITE->shortname;
// Append the relevant object id.
} else if ($context->instanceid) {
$foldername .= '_id_'.$context->instanceid;
} else {
// This does not really happen but just in case.
$foldername .= '_ctx_'.$context->id;
}
$foldername = urlencode(clean_param($foldername, PARAM_PATH));
$allfolders[] = $foldername;
}