Skip to content

Commit

Permalink
MDL-75316 core_moodlenet: Share to MoodleNet modal and activity menu
Browse files Browse the repository at this point in the history
Originally implemented as MDL-75785
  • Loading branch information
HuongNV13 authored and mickhawkins committed Apr 18, 2023
1 parent 6a877d4 commit 58ced4a
Show file tree
Hide file tree
Showing 36 changed files with 1,594 additions and 4 deletions.
57 changes: 57 additions & 0 deletions admin/moodlenet_oauth2_callback.php
@@ -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/>.

/**
* MoodleNet callback.
*
* @package core
* @copyright 2023 Huong Nguyen <huongnv13@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

use core\moodlenet\moodlenet_client;
use core\oauth2\api;

require_once(__DIR__ . '/../config.php');
require_login();

// Parameters.
$issuerid = required_param('issuerid', PARAM_INT);
$error = optional_param('error', '', PARAM_RAW);
$message = optional_param('error_description', null, PARAM_RAW);

// Headers to make it not cacheable.
header('Cache-Control: no-cache, must-revalidate');
header('Expires: Sat, 26 Jul 1997 05:00:00 GMT');

$PAGE->set_context(context_system::instance());
$PAGE->set_url('/admin/moodlenet_oauth2_callback.php');
$PAGE->set_pagelayout('popup');

// Wait as long as it takes for this script to finish.
core_php_time_limit::raise();

$issuer = api::get_issuer($issuerid);
$returnurl = new moodle_url('/admin/moodlenet_oauth2_callback.php');
$returnurl->param('issuerid', $issuerid);
$returnurl->param('callback', 'yes');
$returnurl->param('sesskey', sesskey());
$oauthclient = api::get_user_oauth_client($issuer, $returnurl, moodlenet_client::API_SCOPE_CREATE, true);
$oauthclient->is_logged_in(); // Will upgrade the auth code to a token.

echo $OUTPUT->header();
$PAGE->requires->js_call_amd('core/moodlenet/oauth2callback', 'init', [$error, $message]);
echo $OUTPUT->footer();
18 changes: 18 additions & 0 deletions lang/en/moodle.php
Expand Up @@ -1365,10 +1365,27 @@
$string['moodleversion'] = 'Moodle version';
$string['moodlerelease'] = 'Moodle release';
$string['moodleservicesandsupport'] = 'Services and support';
$string['moodlenet:cannotconnecttoserver'] = 'Cannot connect to MoodleNet server';
$string['moodlenet:configoauthservice'] = 'Select a MoodleNet OAuth 2 service to enable sharing to that MoodleNet site. If the service doesn\'t exist yet, you will need to <a href="{$a}">create</a> it.';
$string['moodlenet:eventresourceexported'] = 'Resource exported';
$string['moodlenet:gotomoodlenet'] = 'Go to MoodleNet drafts';
$string['moodlenet:issuerisnotauthorized'] = 'MoodleNet issuer is not authorized';
$string['moodlenet:issuerisnotenabled'] = 'MoodleNet issuer is not enabled';
$string['moodlenet:issuerisnotset'] = 'MoodleNet issuer is not set at site administration';
$string['moodlenet:outboundsettings'] = 'MoodleNet outbound settings';
$string['moodlenet:sharenotice'] = 'You are sharing this to MoodleNet as a {$a}';
$string['moodlenet:sharefailtitle'] = 'Something went wrong';
$string['moodlenet:sharefailtext'] = 'There was an error sharing your content to MoodleNet.<br>Please try again later.';
$string['moodlenet:sharefailtextwithsitesupport'] = 'There was an error sharing your content to MoodleNet.<br>Please try again later or <a href="{$a}">contact site support</a>.';
$string['moodlenet:sharefilesizelimitexceeded'] = 'The size of the resource being shared ({$a->filesize} bytes) exceeds the limit of {$a->filesizelimit} bytes.';
$string['moodlenet:sharesuccesstitle'] = 'Saved to MoodleNet drafts';
$string['moodlenet:sharesuccesstext'] = "Almost done! Visit your drafts in MoodleNet to finish sharing your content.";
$string['moodlenet:sharetomoodlenet'] = 'Share to MoodleNet';
$string['moodlenet:sharetyperesource'] = 'resource';
$string['moodlenet:sharingstatus'] = 'Sharing to MoodleNet';
$string['moodlenet:sharinglargefile'] = "Large files can take some time.";
$string['moodlenet:sharingto'] = 'Sharing to: ';
$string['moodlenet:packagingandsending'] = 'Packaging your file and sending to MoodleNet...';
$string['more'] = 'more';
$string['morehelp'] = 'More help';
$string['morehelpaboutmodule'] = 'More help about the {$a} activity';
Expand Down Expand Up @@ -1974,6 +1991,7 @@
$string['setpassword'] = 'Set password';
$string['setpasswordinstructions'] = 'Please enter your new password below, then save changes.';
$string['settings'] = 'Settings';
$string['share'] = 'Share';
$string['shortname'] = 'Short name'; /* @deprecated MDL-34652 - Use shortnamecourse or shortnameuser or some own context specific string. */
$string['shortnamecollisionwarning'] = '[*] = This shortname is already in use by a course and will need to be changed upon approval';
$string['shortnamecourse'] = 'Course short name';
Expand Down
11 changes: 11 additions & 0 deletions lib/amd/build/moodlenet/oauth2callback.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lib/amd/build/moodlenet/oauth2callback.min.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions lib/amd/build/moodlenet/send_activity_modal.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions lib/amd/build/moodlenet/send_activity_modal.min.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions lib/amd/build/moodlenet/send_resource.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 58ced4a

Please sign in to comment.