Skip to content
Permalink
Browse files
Merge branch 'wip-MDL-61814-34' of git://github.com/abgreeve/moodle i…
…nto MOODLE_34_STABLE
  • Loading branch information
David Monllao committed May 8, 2018
2 parents b70613f + 00ee2d2 commit fe91efe959bf6a5bc9e8f57d6dc18d7c13dc5005
@@ -167,6 +167,12 @@
$string['portfolio'] = 'Portfolio';
$string['portfolios'] = 'Portfolios';
$string['privacy:metadata'] = 'The portfolio subsystem acts as a channel, passing requests from plugins to the various portfolio plugins.';
$string['privacy:metadata:name'] = 'Name of the preference.';
$string['privacy:metadata:instance'] = 'Identifier for the portfolio.';
$string['privacy:metadata:instancesummary'] = 'This stores portfolio both instances and preferences for the portfolios user is using.';
$string['privacy:metadata:value'] = 'Value for the preference';
$string['privacy:metadata:userid'] = 'The user Identifier.';
$string['privacy:path'] = 'Portfolio instances';
$string['queuesummary'] = 'Currently queued transfers';
$string['returntowhereyouwere'] = 'Return to where you were';
$string['save'] = 'Save';
@@ -184,3 +190,4 @@
$string['wanttowait_high'] = 'It is not recommended that you wait for this transfer to complete, but you can if you\'re sure and know what you\'re doing';
$string['wanttowait_moderate'] = 'Do you want to wait for this transfer? It might take a few minutes';


@@ -0,0 +1,119 @@
<?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 'user', language 'en', branch 'MOODLE_20_STABLE'
*
* @package core_user
* @copyright 2018 Adrian Greeve <adriangreeve.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

$string['privacy:courserequestpath'] = 'Requested courses';
$string['privacy:descriptionpath'] = 'Profile description';
$string['privacy:devicespath'] = 'User devices';
$string['privacy:draftfilespath'] = 'Draft files';
$string['privacy:lastaccesspath'] = 'Last access to courses';
$string['privacy:metadata:address'] = 'The address of the user.';
$string['privacy:metadata:aim'] = 'The AIM identifier of the user.';
$string['privacy:metadata:alternatename'] = 'An alternative name for the user.';
$string['privacy:metadata:appid'] = 'The app id, usually something like com.moodle.moodlemobile';
$string['privacy:metadata:auth'] = 'The authentication plugin used for this user record.';
$string['privacy:metadata:autosubscribe'] = 'A preference as to if the user should be auto-subscribed to forums the user posts in.';
$string['privacy:metadata:calendartype'] = 'A user preference for the type of calendar to use.';
$string['privacy:metadata:category'] = 'The category identifier.';
$string['privacy:metadata:city'] = 'The city of the user.';
$string['privacy:metadata:confirmed'] = 'If this is an active user or not.';
$string['privacy:metadata:country'] = 'The country that the user is in.';
$string['privacy:metadata:courseid'] = 'An identifier for a course.';
$string['privacy:metadata:currentlogin'] = 'The current login for this user.';
$string['privacy:metadata:data'] = 'Data relating to the custom user field from the user.';
$string['privacy:metadata:deleted'] = 'A flag to show if the user has been deleted or not.';
$string['privacy:metadata:department'] = 'The department that this user can be found in.';
$string['privacy:metadata:description'] = 'General details about this user.';
$string['privacy:metadata:devicename'] = 'The device name, occam or iPhone etc..';
$string['privacy:metadata:devicetablesummary'] = 'This table stores user\'s mobile devices information in order to send PUSH notifications';
$string['privacy:metadata:email'] = 'An email address for contact.';
$string['privacy:metadata:emailstop'] = 'A preference to stop email being sent to the user.';
$string['privacy:metadata:fieldid'] = 'The ID relating to the custom user field.';
$string['privacy:metadata:filelink'] = 'There are multiple different files for the user stored in the files table.';
$string['privacy:metadata:firstaccess'] = 'The time that this user first accessed the site.';
$string['privacy:metadata:firstip'] = 'The first IP address recorded';
$string['privacy:metadata:firstname'] = 'The first name of the user.';
$string['privacy:metadata:firstnamephonetic'] = 'The phonetic details about the user\'s first name.';
$string['privacy:metadata:fullname'] = 'The fullname for this course.';
$string['privacy:metadata:hash'] = 'A hash of a previous password.';
$string['privacy:metadata:icq'] = 'The ICQ number of the user.';
$string['privacy:metadata:id'] = 'The identifier for the user.';
$string['privacy:metadata:idnumber'] = 'An identification number given by the institution.';
$string['privacy:metadata:imagealt'] = 'Alternative text for the user\'s image.';
$string['privacy:metadata:infotablesummary'] = 'Stores custom user information.';
$string['privacy:metadata:institution'] = 'The institution that this user is a member of.';
$string['privacy:metadata:lang'] = 'A user preference for the language shown.';
$string['privacy:metadata:lastaccess'] = 'The time that the user last accessed the site.';
$string['privacy:metadata:lastaccesstablesummary'] = 'Information about the last time a user accessed a course.';
$string['privacy:metadata:lastip'] = 'The last IP address for the user.';
$string['privacy:metadata:lastlogin'] = 'The last login of this user.';
$string['privacy:metadata:lastname'] = 'The surname of the user.';
$string['privacy:metadata:lastnamephonetic'] = 'The phonetic details about the user\'s surname.';
$string['privacy:metadata:maildigest'] = 'A setting for the mail digest for this user.';
$string['privacy:metadata:maildisplay'] = 'A preference for the user about displaying their email address to other users.';
$string['privacy:metadata:middlename'] = 'The middle name of the user.';
$string['privacy:metadata:mnethostid'] = 'An identifier for the mnet host if used.';
$string['privacy:metadata:model'] = 'The device name, occam or iPhone etc..';
$string['privacy:metadata:msn'] = 'The MSN identifier of the user.';
$string['privacy:metadata:password'] = 'The password for this user to log into the system.';
$string['privacy:metadata:passwordresettablesummary'] = 'A table tracking password reset confirmation tokens';
$string['privacy:metadata:passwordtablesummary'] = 'A rotating log of hashes of previously used passwords for the user.';
$string['privacy:metadata:phone'] = 'A phone number for the user.';
$string['privacy:metadata:picture'] = 'The picture details associated with this user.';
$string['privacy:metadata:platform'] = 'The device platform, Android or iOS etc';
$string['privacy:metadata:policyagreed'] = 'A flag to determine if the user has agreed to the site policy.';
$string['privacy:metadata:pushid'] = 'The device PUSH token/key/identifier/registration id';
$string['privacy:metadata:reason'] = 'The reason for requesting this course.';
$string['privacy:metadata:requester'] = 'An identifier to a user that requested this course.';
$string['privacy:metadata:requestsummary'] = 'Stores information about requests for courses that users make.';
$string['privacy:metadata:suspended'] = 'A flag to show if the user has been suspended on this system.';
$string['privacy:metadata:username'] = 'The username for this user.';
$string['privacy:metadata:secret'] = 'Secret.. not sure.';
$string['privacy:metadata:sessdata'] = 'Session content';
$string['privacy:metadata:sessiontablesummary'] = 'Database based session storage';
$string['privacy:metadata:shortname'] = 'A short name for the course.';
$string['privacy:metadata:sid'] = 'The session ID';
$string['privacy:metadata:skype'] = 'The skype identifier of the user.';
$string['privacy:metadata:state'] = '0 means a normal session';
$string['privacy:metadata:summary'] = 'A description of the course.';
$string['privacy:metadata:theme'] = 'A user preference for the theme to display.';
$string['privacy:metadata:timeaccess'] = 'The time for access to the course.';
$string['privacy:metadata:timecreated'] = 'The time this record was created.';
$string['privacy:metadata:timemodified'] = 'The time this records was modified.';
$string['privacy:metadata:timererequested'] = 'The time the user re-requested the password reset.';
$string['privacy:metadata:timerequested'] = 'The time that the user first requested this password reset';
$string['privacy:metadata:timezone'] = 'The timezone that the user resides in.';
$string['privacy:metadata:token'] = 'secret set and emailed to user';
$string['privacy:metadata:trackforums'] = 'A preference for forums and tracking them.';
$string['privacy:metadata:trustbitmask'] = 'The trust bit mask';
$string['privacy:metadata:yahoo'] = 'The yahoo identifier of the user.';
$string['privacy:metadata:url'] = 'A URL related to this user.';
$string['privacy:metadata:userid'] = 'The user ID linked to this table.';
$string['privacy:metadata:usertablesummary'] = 'This table stores the main personal data about the user.';
$string['privacy:metadata:uuid'] = 'The device vendor UUID';
$string['privacy:metadata:version'] = 'The device version, 6.1.2, 4.2.2 etc..';
$string['privacy:passwordhistorypath'] = 'Password history';
$string['privacy:passwordresetpath'] = 'Password resets';
$string['privacy:profileimagespath'] = 'Profile images';
$string['privacy:privatefilespath'] = 'Private files';
$string['privacy:sessionpath'] = 'Session data';
@@ -27,6 +27,8 @@

use core_privacy\local\metadata\collection;
use core_privacy\local\request\context;
use core_privacy\local\request\contextlist;
use core_privacy\local\request\approved_contextlist;

/**
* Provider for the portfolio API.
@@ -35,10 +37,9 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider implements
// The Portfolio subsystem does not store any data itself.
// It has no database tables, and it purely acts as a conduit to the various portfolio plugins.
// The core portfolio system stores preferences related to the other portfolio subsystems.
\core_privacy\local\metadata\provider,

\core_privacy\local\request\plugin\provider,
// The portfolio subsystem will be called by other components.
\core_privacy\local\request\subsystem\plugin_provider {

@@ -49,7 +50,100 @@ class provider implements
* @return collection A listing of user data stored through this system.
*/
public static function get_metadata(collection $collection) : collection {
return $collection->add_plugintype_link('portfolio', [], 'privacy:metadata');
$collection->add_database_table('portfolio_instance_user', [
'instance' => 'privacy:metadata:instance',
'userid' => 'privacy:metadata:userid',
'name' => 'privacy:metadata:name',
'value' => 'privacy:metadata:value'
], 'privacy:metadata:instancesummary');
$collection->add_plugintype_link('portfolio', [], 'privacy:metadata');
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 {
$sql = "SELECT ctx.id
FROM {context} ctx
JOIN {portfolio_instance_user} piu ON ctx.instanceid = piu.userid AND ctx.contextlevel = :usercontext
WHERE piu.userid = :userid";
$params = ['userid' => $userid, 'usercontext' => CONTEXT_USER];
$contextlist = new contextlist();
$contextlist->add_from_sql($sql, $params);
return $contextlist;
}

/**
* 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 ($contextlist->get_component() != 'core_portfolio') {
return;
}

$correctusercontext = array_filter($contextlist->get_contexts(), function($context) use ($contextlist) {
if ($context->contextlevel == CONTEXT_USER && $context->instanceid == $contextlist->get_user()->id) {
return $context;
}
});

$usercontext = array_shift($correctusercontext);


$sql = "SELECT pi.name, piu.name AS preference, piu.value
FROM {portfolio_instance_user} piu
JOIN {portfolio_instance} pi ON piu.instance = pi.id
WHERE piu.userid = :userid";
$params = ['userid' => $usercontext->instanceid];
$instances = $DB->get_records_sql($sql, $params);
if (!empty($instances)) {
\core_privacy\local\request\writer::with_context($contextlist->current())->export_data(
[get_string('privacy:path', 'portfolio')], (object) $instances);
}
}

/**
* 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;
// Context could be anything, BEWARE!
if ($context->contextlevel == CONTEXT_USER) {
$DB->delete_records('portfolio_instance_user', ['userid' => $context->instanceid]);
}
}

/**
* 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 ($contextlist->get_component() != 'core_portfolio') {
return;
}

$correctusercontext = array_filter($contextlist->get_contexts(), function($context) use ($contextlist) {
if ($context->contextlevel == CONTEXT_USER && $context->instanceid == $contextlist->get_user()->id) {
return $context;
}
});

$usercontext = array_shift($correctusercontext);

$DB->delete_records('portfolio_instance_user', ['userid' => $usercontext->instanceid]);
}

/**
Loading

0 comments on commit fe91efe

Please sign in to comment.