From: jerome Date: Fri, 16 Oct 2009 08:50:02 +0000 (+0000) Subject: webservice MDL-17135 add service user settings administration X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=bb1dff214d0d0ebc4b70061b76c33b1609e20186;p=moodle.git webservice MDL-17135 add service user settings administration --- diff --git a/admin/external_service_users.php b/admin/external_service_users.php index ca259e4a0f..b75daaf60e 100644 --- a/admin/external_service_users.php +++ b/admin/external_service_users.php @@ -34,7 +34,7 @@ $PAGE->set_url('admin/external_service_users.php', array('id'=>$id)); admin_externalpage_setup('externalserviceusers'); admin_externalpage_print_header(); - +global $DB; /// Get the user_selector we will need. $potentialuserselector = new service_user_selector('addselect', array('serviceid' => $id, 'displayallowedusers' => 0)); $alloweduserselector = new service_user_selector('removeselect', array('serviceid' => $id, 'displayallowedusers' => 1)); @@ -45,7 +45,6 @@ $alloweduserselector = new service_user_selector('removeselect', array('servicei if (!empty($userstoassign)) { foreach ($userstoassign as $adduser) { - global $DB; $serviceuser = new object(); $serviceuser->externalserviceid = $id; $serviceuser->userid = $adduser->id; @@ -64,8 +63,7 @@ $alloweduserselector = new service_user_selector('removeselect', array('servicei $userstoremove = $alloweduserselector->get_selected_users(); if (!empty($userstoremove)) { - foreach ($userstoremove as $removeuser) { - global $DB; + foreach ($userstoremove as $removeuser) { $DB->delete_records('external_services_users', array('externalserviceid' => $id, 'userid' => $removeuser->id)); add_to_log(1, 'core', 'assign', 'admin/external_service_users.php?id='.$id, 'remove', '', $removeuser->id); } @@ -106,4 +104,91 @@ $alloweduserselector = new service_user_selector('removeselect', array('servicei id = $serviceuserid; + $serviceuser->validuntil = $validuntil; + $serviceuser->iprestriction = $iprestriction; + $DB->update_record('external_services_users', $serviceuser); + + //TODO: assign capability +} + +//display the list of allowed users with their options (ip/timecreated / validuntil...) +//check that the user has the service required capability (if needed) +$sql = " SELECT u.id as id, esu.id as serviceuserid, u.email as email, u.firstname as firstname, u.lastname as lastname, + esu.iprestriction as iprestriction, esu.validuntil as validuntil, + esu.timecreated as timecreated + FROM {user} u, {external_services_users} esu + WHERE username <> 'guest' AND deleted = 0 AND confirmed = 1 + AND esu.userid = u.id + AND esu.externalserviceid = ?"; +$allowedusers = $DB->get_records_sql($sql, array($id)); +if (!empty($allowedusers)) { + echo $OUTPUT->box_start('generalbox', 'alloweduserlist'); + + echo ""; + echo "

"; //reduce font of the user settings + foreach($allowedusers as $user) { + + echo ""; + echo print_collapsible_region_start('', 'usersettings'.$user->id,$user->firstname." ".$user->lastname.", ".$user->email,false,true,true); + echo ""; + + //user settings form + $contents = "
"; + $form = new html_form(); + $form->url = new moodle_url('/admin/external_service_users.php', array('id' => $id, 'userid' => $user->id, 'updateuser' => 1, 'serviceuserid' => $user->serviceuserid)); // Required + $form->button = new html_button(); + $form->button->text = get_string('update'); // Required + $form->button->disabled = false; + $form->button->title = get_string('update'); + $form->method = 'post'; + $form->id = 'usersetting'.$user->id; + //ip restriction textfield + $contents .= "
"; + $field = new html_field(); + $field->name = 'iprestriction'; + $field->value = $user->iprestriction; + $field->style = 'width: 30em;'; + $contents .= $OUTPUT->textfield($field); + $contents .= "
"; + //valid until date selector + $contents .= "
"; + $selectors = html_select::make_time_selectors(array('days' => 'fromday','months' => 'frommonth', 'years' => 'fromyear'),$user->validuntil); + foreach ($selectors as $select) { + $contents .= $OUTPUT->select($select); + } + $contents .= "
"; + //TO IMPLEMENT : assign the required capability (if needed) + $contents .= "
"; + $checkbox = new html_select_option(); + $checkbox->value = $user->id; + $checkbox->selected = false; + $checkbox->text = ' '; + $checkbox->label->text = ' '; + $checkbox->alt = 'TODO:'.get_string('addrequiredcapability', 'webservice'); + $contents .= $OUTPUT->checkbox($checkbox, 'addcap')."
"; + $contents .= "
"; + echo $OUTPUT->form($form, $contents); + + echo print_collapsible_region_end(true); + + + } + echo "
"; + echo $OUTPUT->box_end(); +} + + echo $OUTPUT->footer(); \ No newline at end of file diff --git a/admin/webservice/lib.php b/admin/webservice/lib.php index 6132c8914b..84da28d2f9 100644 --- a/admin/webservice/lib.php +++ b/admin/webservice/lib.php @@ -32,10 +32,10 @@ class service_user_selector extends user_selector_base { const MAX_USERS_PER_PAGE = 100; protected $serviceid; - protected $displayallowedusers; //set to true if the selector display the - //allowed user on this service - //, set to false if the selector display the - // other user (false is the default default) + protected $displayallowedusers; //set to true if the selector displays the + //allowed users on this service + //, set to false if the selector displays the + // other users (false is the default default) public function __construct($name, $options) { parent::__construct($name, $options); @@ -48,6 +48,12 @@ class service_user_selector extends user_selector_base { $this->displayallowedusers = !empty($options['displayallowedusers']); } + /** + * Find allowed or not allowed users of a service (depend of $this->displayallowedusers) + * @global object $DB + * @param $search + * @return array + */ public function find_users($search) { global $DB; //by default wherecondition retrieves all users except the deleted, not @@ -104,6 +110,11 @@ class service_user_selector extends user_selector_base { return array($groupname => $availableusers); } + /** + * This options are automatically used by the AJAX search + * @global object $CFG + * @return object options pass to the constructor when AJAX search call a new selector + */ protected function get_options() { global $CFG; $options = parent::get_options(); diff --git a/lang/en_utf8/webservice.php b/lang/en_utf8/webservice.php index f0b9f3edff..3633fe38cd 100644 --- a/lang/en_utf8/webservice.php +++ b/lang/en_utf8/webservice.php @@ -1,6 +1,7 @@ function\" from service \"$a->service\"?'; @@ -23,8 +25,10 @@ $string['requiredcapability'] = 'Required capability'; $string['restrictedusers'] = 'Restricted users'; $string['servicesbuiltin'] = 'Built-in services'; $string['servicescustom'] = 'Custom services'; -$string['serviceusers'] = 'Allowed users'; -$string['serviceusersmatching'] = 'Allowed users matching'; +$string['serviceusers'] = 'Authorized users'; +$string['serviceusersmatching'] = 'Authorized users matching'; +$string['serviceuserssettings'] = 'Change settings for the Authorized users'; $string['test'] = 'Test'; $string['testclient'] = 'Test client'; +$string['validuntil'] = 'Valid until'; $string['webservices'] = 'Web services';