Moodle

delete_users

Details

  • Type: Task Task
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Fixed
  • Affects Version/s: 2.0
  • Fix Version/s: 2.0
  • Component/s: Web Services
  • Labels:
    None
  • Affected Branches:
    MOODLE_20_STABLE
  • Fixed Branches:
    MOODLE_20_STABLE

Description

Delete one or more users

Issue Links

Activity

Hide
David Castro added a comment -

We have implemented this functionality only by userid .

If we want delete some users by different criteria, we could do some functions like delete_users_by_id, delete_users_by_idnumber, delete_users_by_email, etc.

Or do it in a function delete_users ($array, $criteria);
where $criteria is a string {id, idnumber or email}
and $array is the array with values for specified criteria.

Show
David Castro added a comment - We have implemented this functionality only by userid . If we want delete some users by different criteria, we could do some functions like delete_users_by_id, delete_users_by_idnumber, delete_users_by_email, etc. Or do it in a function delete_users ($array, $criteria); where $criteria is a string {id, idnumber or email} and $array is the array with values for specified criteria.
Hide
Ludo ( Marc Alier) added a comment -

This is a general problem that we will find in all the API.
Shall we have just one funcion with complex parameters or do we want a looong list of functions.
Anyway : Maintenance is the issue.
IMO we should have only one function to do the actual work (so it can be modified when needed): The currently implemented delete_user(id) or similar.
The we can have a set of functions (or just one with complex parameters) that using this one allows more functionality.

Insigths?

Show
Ludo ( Marc Alier) added a comment - This is a general problem that we will find in all the API. Shall we have just one funcion with complex parameters or do we want a looong list of functions. Anyway : Maintenance is the issue. IMO we should have only one function to do the actual work (so it can be modified when needed): The currently implemented delete_user(id) or similar. The we can have a set of functions (or just one with complex parameters) that using this one allows more functionality. Insigths?
Hide
Jerome Mouneyrac added a comment - - edited

Hi David, hi ludo,
I read the specification (http://docs.moodle.org/en/Development:Web_services) and there is one delete_users() function with an array as parameter. Is that your question?

Show
Jerome Mouneyrac added a comment - - edited Hi David, hi ludo, I read the specification (http://docs.moodle.org/en/Development:Web_services) and there is one delete_users() function with an array as parameter. Is that your question?
Hide
Ludo ( Marc Alier) added a comment -

According to current spec: The function receives and array with

idnumber or
email or
id or
login

OK; NOW how do I know WHAT IS a value in the array ?
This is the question...

Show
Ludo ( Marc Alier) added a comment - According to current spec: The function receives and array with – idnumber or email or id or login – OK; NOW how do I know WHAT IS a value in the array ? This is the question...
Hide
David Castro added a comment -

Hi,

We think that the easiest way to solve this functionality is deleting only by id or idnumber, because all of them are unique on Moodle.

Show
David Castro added a comment - Hi, We think that the easiest way to solve this functionality is deleting only by id or idnumber, because all of them are unique on Moodle.
Hide
Jordi Piguillem Poch added a comment -

Some more PHPDoc from spec

/**

  • Deletes an user
  • User is marked as deleted
  • All it's role assignments are destroyed
  • @private ?
  • @param string $field Possible values:
  • <ul>
  • <li>id</li>
  • <li>idnumber</li>
  • <li>login</li>
  • <li>email</li>
  • </ul>
  • @param string $value
  • @return boolean
    */
    function delete_user($field, $values){
    }

/**

  • Deletes several users
  • Users are marked as deleted
  • All their role assignments are destroyed
  • @param string $field Possible values:
  • <ul>
  • <li>id</li>
  • <li>idnumber</li>
  • <li>login</li>
  • <li>email</li>
  • </ul>
  • @param array $values
  • @uses delete_user
    *
  • @return boolean
    */
    function delete_users($field, $values){
    }
Show
Jordi Piguillem Poch added a comment - Some more PHPDoc from spec /**
  • Deletes an user
  • User is marked as deleted
  • All it's role assignments are destroyed
  • @private ?
  • @param string $field Possible values:
  • <ul>
  • <li>id</li>
  • <li>idnumber</li>
  • <li>login</li>
  • <li>email</li>
  • </ul>
  • @param string $value
  • @return boolean */ function delete_user($field, $values){ }
/**
  • Deletes several users
  • Users are marked as deleted
  • All their role assignments are destroyed
  • @param string $field Possible values:
  • <ul>
  • <li>id</li>
  • <li>idnumber</li>
  • <li>login</li>
  • <li>email</li>
  • </ul>
  • @param array $values
  • @uses delete_user *
  • @return boolean */ function delete_users($field, $values){ }
Hide
Tusefomal added a comment -

I've just added in the CVS the add_user function working with an associative array as it's suggested. It can be find here:

http://cvs.moodle.org/contrib/patches/dfws/webservice/apis/user.lib.php?revision=1.4&view=markup

The name of the function is:

array mdl_user_delete_instances($userids, $idtype='idnumber')

The particles of the name are explained here: http://tracker.moodle.org/browse/MDL-13126?focusedCommentId=56209#action_56209

The function gets one mandatory param and am optional one, and returns an associative array of identifier=>boolean. The hot point of this function is that users can be identified by several fields:

-username
-email
-internal id
-idnumber (in my point of view is the best way)

So, to implement this function we decided to allow all of them. The default is 'idnumber' but, you can pass an array of internal ids, usernames or emails too, just by specify it in the second parameter.

Show
Tusefomal added a comment - I've just added in the CVS the add_user function working with an associative array as it's suggested. It can be find here: http://cvs.moodle.org/contrib/patches/dfws/webservice/apis/user.lib.php?revision=1.4&view=markup The name of the function is: array mdl_user_delete_instances($userids, $idtype='idnumber') The particles of the name are explained here: http://tracker.moodle.org/browse/MDL-13126?focusedCommentId=56209#action_56209 The function gets one mandatory param and am optional one, and returns an associative array of identifier=>boolean. The hot point of this function is that users can be identified by several fields: -username -email -internal id -idnumber (in my point of view is the best way) So, to implement this function we decided to allow all of them. The default is 'idnumber' but, you can pass an array of internal ids, usernames or emails too, just by specify it in the second parameter.
Hide
Tusefomal added a comment -

As Martin wants (and Pigui remember me), in delete_users the first param will be a criteria and the second an array of users. This makes default value impossible, but it's may be more polite. New code can be found threre:

http://cvs.moodle.org/contrib/patches/dfws/webservice/apis/user.lib.php?revision=1.5&view=markup

Show
Tusefomal added a comment - As Martin wants (and Pigui remember me), in delete_users the first param will be a criteria and the second an array of users. This makes default value impossible, but it's may be more polite. New code can be found threre: http://cvs.moodle.org/contrib/patches/dfws/webservice/apis/user.lib.php?revision=1.5&view=markup
Hide
David Castro added a comment -

Implemented and finished on CVS.

Show
David Castro added a comment - Implemented and finished on CVS.

Dates

  • Created:
    Updated:
    Resolved: