Skip to content
Snippets Groups Projects
Commit 7be1f69b authored by Benjamin Ledel's avatar Benjamin Ledel
Browse files

* first draft working

parent ac952d71
No related branches found
No related tags found
No related merge requests found
# Polaris Gateway # # Polaris Gateway #
TODO Describe the plugin shortly here. The plugin is a gateway for the polaris infrastructure, espaclliy the rights engine.
We provide an external web service to access the required data.
TODO Provide more detailed description here. Finally, you should open the following page and see the course structure the user with the email USER_EMAIL.
https://HOST/webservice/rest/server.php?wstoken={GENERATED_TOKEN}&wsfunction=local_polaris_gateway_collect_groups&moodlewsrestformat=json&user_email={USER_EMAIL}
## Installing via uploaded ZIP file ## ## Installing via uploaded ZIP file ##
...@@ -27,6 +29,13 @@ Alternatively, you can run ...@@ -27,6 +29,13 @@ Alternatively, you can run
to complete the installation from the command line. to complete the installation from the command line.
## Configuration ##
1. Activiate the web services in moodle
2. Create a service user
3. Allow the service user to use the Polaris Gateway service
4. Generate a token and add the url to the provider schema
## License ## ## License ##
2023 Digital Learning GmbH <support@digitallearning.gmbh> 2023 Digital Learning GmbH <support@digitallearning.gmbh>
......
<?php <?php
namespace local_polaris_gateway\external; namespace local_polaris_gateway\external;
use context_system;
use external_function_parameters; use external_function_parameters;
use external_multiple_structure; use external_multiple_structure;
use external_single_structure; use external_single_structure;
use external_value; use external_value;
class create_groups extends \core_external\external_api { class collect_groups extends \external_api {
/** /**
* Returns description of method parameters * Returns description of method parameters
...@@ -14,35 +15,45 @@ class create_groups extends \core_external\external_api { ...@@ -14,35 +15,45 @@ class create_groups extends \core_external\external_api {
*/ */
public static function execute_parameters() { public static function execute_parameters() {
return new external_function_parameters([ return new external_function_parameters([
'groups' => new external_multiple_structure( 'user_email' => new external_value(PARAM_TEXT, 'email of the user')
new external_single_structure([
'courseid' => new external_value(PARAM_INT, 'id of course'),
'name' => new external_value(
PARAM_TEXT,
'multilang compatible name, course unique'
),
'description' => new external_value(
PARAM_RAW,
'group description text'
),
'enrolmentkey' => new external_value(
PARAM_RAW,
'group enrol secret phrase'
),
])
)
]); ]);
} }
public static function execute_returns() { public static function execute_returns() {
return new external_multiple_structure( return new external_multiple_structure(
new external_single_structure([ new external_single_structure([
'id' => new external_value(PARAM_INT, 'group record id'), 'group_id' => new external_value(PARAM_INT, 'id of course'),
'courseid' => new external_value(PARAM_INT, 'id of course'),
'name' => new external_value(PARAM_TEXT, 'multilang compatible name, course unique'), 'name' => new external_value(PARAM_TEXT, 'multilang compatible name, course unique'),
'description' => new external_value(PARAM_RAW, 'group description text'), 'description' => new external_value(PARAM_TEXT, 'group description text'),
'enrolmentkey' => new external_value(PARAM_RAW, 'group enrol secret phrase'),
]) ])
); );
} }
public static function execute($user_email) {
global $CFG, $DB;
$params = self::validate_parameters(self::execute_parameters(), ['user_email' => $user_email]);
// now security checks
$context = context_system::instance();
self::validate_context($context);
require_capability('local/polaris_gateway:access_api', $context);
$result = [];
$user = $DB->get_record('user', ['email' => $params["user_email"]]);
$courses = enrol_get_users_courses($user->id, true);
foreach($courses as $course)
{
$singleCourse = [];
$singleCourse["group_id"] = $course->id;
$singleCourse["name"] = $course->shortname;
$singleCourse["description"] = $course->name;
$result[] = $singleCourse;
}
return $result;
}
} }
\ No newline at end of file
<?php
$capabilities = [
'local/polaris_gateway:access_api' => [
'riskbitmask' => RISK_PERSONAL ,
'captype' => 'write',
'contextlevel' => CONTEXT_SYSTEM,
],
];
\ No newline at end of file
...@@ -5,6 +5,7 @@ $functions = [ ...@@ -5,6 +5,7 @@ $functions = [
'local_polaris_gateway_collect_groups' => [ 'local_polaris_gateway_collect_groups' => [
// The name of the namespaced class that the function is located in. // The name of the namespaced class that the function is located in.
'classname' => 'local_polaris_gateway\external\collect_groups', 'classname' => 'local_polaris_gateway\external\collect_groups',
'classpath' => 'local/polaris_gateway/classes/external/collect_groups.php',
// A brief, human-readable, description of the web service function. // A brief, human-readable, description of the web service function.
'description' => 'Collects information about courses members to show them in polaris', 'description' => 'Collects information about courses members to show them in polaris',
...@@ -25,20 +26,9 @@ $services = [ ...@@ -25,20 +26,9 @@ $services = [
'Polaris Gateway' => [ 'Polaris Gateway' => [
'functions' => [ 'functions' => [
'local_polaris_gateway_collect_groups', 'local_polaris_gateway_collect_groups',
'local_o365_get_onenoteassignment',
'local_o365_update_onenoteassignment',
'local_o365_delete_onenoteassignment',
'local_o365_get_teachercourses',
'local_o365_get_course_users',
'local_o365_get_assignments',
'local_o365_get_bot_message',
'local_o365_update_grade',
'mod_assign_get_assignments',
'mod_assign_get_grades',
'mod_assign_save_grade',
], ],
'restrictedusers' => 0, 'restrictedusers' => 1,
'enabled' => 0, 'enabled' => 1,
'shortname' => 'polaris_gateway', 'shortname' => 'polaris_gateway',
] ]
]; ];
\ No newline at end of file
...@@ -26,3 +26,4 @@ ...@@ -26,3 +26,4 @@
defined('MOODLE_INTERNAL') || die(); defined('MOODLE_INTERNAL') || die();
$string['pluginname'] = 'Polaris Gateway'; $string['pluginname'] = 'Polaris Gateway';
$string['polaris_gateway:access_api'] = "API Zugriff, nur an den Service-Nutzer vergeben";
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment