Example #1
0
            $params = array('objectid' => $serviceuser->externalserviceid, 'relateduserid' => $serviceuser->userid);
            $event = \core\event\webservice_service_user_added::create($params);
            $event->trigger();
        }
        $potentialuserselector->invalidate_selected_users();
        $alloweduserselector->invalidate_selected_users();
    }
}
/// Process removing user assignments to the service
if (optional_param('remove', false, PARAM_BOOL) && confirm_sesskey()) {
    $userstoremove = $alloweduserselector->get_selected_users();
    if (!empty($userstoremove)) {
        foreach ($userstoremove as $removeuser) {
            $webservicemanager->remove_ws_authorised_user($removeuser, $id);
            $params = array('objectid' => $id, 'relateduserid' => $removeuser->id);
            $event = \core\event\webservice_service_user_removed::create($params);
            $event->trigger();
        }
        $potentialuserselector->invalidate_selected_users();
        $alloweduserselector->invalidate_selected_users();
    }
}
/// Print the form.
/// display the UI
$renderer = $PAGE->get_renderer('core', 'webservice');
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('selectauthorisedusers', 'webservice'), 3, 'main');
$selectoroptions = new stdClass();
$selectoroptions->serviceid = $id;
$selectoroptions->alloweduserselector = $alloweduserselector;
$selectoroptions->potentialuserselector = $potentialuserselector;
Example #2
0
 public function test_service_user_removed()
 {
     global $CFG;
     // The Web service API doesn't allow the testing of the events directly by
     // calling some functions which trigger the events, so what we are going here
     // is just checking that the event returns the expected information.
     $sink = $this->redirectEvents();
     $params = array('objectid' => 1, 'relateduserid' => 2);
     $event = \core\event\webservice_service_user_removed::create($params);
     $event->trigger();
     $events = $sink->get_events();
     $this->assertCount(1, $events);
     $event = reset($events);
     $this->assertEquals(context_system::instance(), $event->get_context());
     $this->assertEquals(1, $event->objectid);
     $this->assertEquals(2, $event->relateduserid);
     $expected = array(SITEID, 'core', 'assign', $CFG->admin . '/webservice/service_users.php?id=' . $params['objectid'], 'remove', '', $params['relateduserid']);
     $this->assertEventLegacyLogData($expected, $event);
 }