chamilo-lms icon indicating copy to clipboard operation
chamilo-lms copied to clipboard

Delete User: assignments work files not deleted

Open jderriks opened this issue 8 years ago • 12 comments

Current behavior / Resultado actual / Résultat actuel

A student has uploaded multiple assignments in multiple courses, 5GB of data. Then she graduates. Deleting this user will remove all database records of the user and her assignments will not be accessible anymore. BUT disk space still has 5GB of orphan file data in "work" folders.

Expected behavior / Resultado esperado / Résultat attendu

Deleting a user should delete the assignment files that are not accesible anymore. Not doing this will clutter up disk space. And it has privacy issues (you should be able to "forget" about people).

Steps to reproduce / Pasos para reproducir / Étapes pour reproduire

Delete a user that has uploaded assignments in groups of a course. Then look at the files in the work folders (using terminal access or ftp) and see the files are still there.

Chamilo Version / Versión de Chamilo / Version de Chamilo

1.11

Workaround: Don't keep courses for a long time; delete them and create "fresh" ones. Deleting a course WILL delete the work folders.

jderriks avatar Jul 18 '18 17:07 jderriks

Another way would be to use sessions, which can be time-limited, then delete them, yes. We are still in the process of fixing the deletion of files. It's always a bit complex to figure out whether we want to delete stuff or not, when, and what other things it might affect. Thanks for reporting!

ywarnier avatar Jul 18 '18 17:07 ywarnier

Sessions need manual user enrollments and we never used it in favour of using groups.

Looking at the courseManager code, work files WILL be deleted if a user is unsubscribed from a course. Different choices in different cases. So another workaround is to first unsubscribe the user from every course and then delete it from the platform. In a few years we managed to collect 3500 orphaned files in "work" folders.

jderriks avatar Jul 18 '18 20:07 jderriks

For the documents (nothing directly related to assignments), there is also a renaming of files instead of deleting them (to filename__DELETED[_possible_suffix]. We made a command line script to delete them (using https://github.com/chamilo/chash). But I think it's not the same for assignments.

From what you say, we could indeed change the deletion behaviour to ensure the student is first unsubscribed from all courses (that would make sense but would also take more time). There are different options here.

ywarnier avatar Jul 18 '18 20:07 ywarnier

Ah, the Chamilo version of Moodle's Moosh is called Chash! Will have a look at that. Work folders also contain DELETED files and folders if the global setting is not to remove deleted files. https://github.com/chamilo/chamilo-lms/blob/ef667cb9c1fd648ef616890503ef0c571c22c406/main/work/work.lib.php#L860

Maybe Chash is the best way to completely remove 1500 users from the platform without leaving traces. There is no "delete users from csv" option in the admin tool.

jderriks avatar Jul 19 '18 13:07 jderriks

Nice way to put it, but actually Chash doesn't inherit anything from Moosh (not even the name style). Chash (Chamilo Shell) comes from inspiration from Drush (Drupal Shell) and appeared on Github in 2013 (roughly the same time as the apparition of Moosh on Github).

I didn't remember the work tool also added the DELETED suffix, but if that's the case then the chash files:clean_deleted_documents command should definitely do the trick. I checked the code and it removes anything with the *DELETED* pattern inside the whole app/courses/ folder. So yes, it should work.

Chash doesn't have an option to delete users yet, but that should be relatively easy to add using the "disable-admins" command as a template: https://github.com/chamilo/chash/blob/master/src/Chash/Command/User/DisableAdminsCommand.php

Could you register an issue there explaining your use case (mainly how you are likely to launch the command for it to be useful to you)?

ywarnier avatar Jul 19 '18 14:07 ywarnier

Regarding the no "delete users from csv" option, we're very careful about deleting users because in our experience there is always someone with a tingly finger that has admin access when he/she shouldn't, and that creates much more issues than the opposite case (not having a mass delete option). We prefer disabling users. Note that in 1.11.8 we should have an option to anonymize one user at a time to match RGPD but still keep interesting learning data. I'll open the issue now (I was going to in the next few days anyway).

ywarnier avatar Jul 19 '18 14:07 ywarnier

First I thought the "Deleted files can(not) be restored" was a nice feature but I turned it off. Creating backups -both mysql dumps and filesystem [inremental] backups- should be the way to go, otherwise you will have backups full of DETELETED files and that is a waste of space.

To remove multiple users I am going for the webservice approach. With webservices I don't need terminal access to the server and still be able to do some automated scripting. https://11.chamilo.org/main/webservices/registration.soap.php?wsdl Shows some nice functions but the usage is poorly documented.

To unsubscribe a user from all courses on user_delete, only two line changes are needed in the UserManager class: --- a/main/inc/lib/usermanager.lib.php +++ b/main/inc/lib/usermanager.lib.php @@ -707,7 +707,7 @@ class UserManager $table_work = Database::get_course_table(TABLE_STUDENT_PUBLICATION);

     // Unsubscribe the user from all groups in all his courses
  •    $sql = "SELECT c.id 
    
  •    $sql = "SELECT c.id, c.code 
               FROM $table_course c 
               INNER JOIN $table_course_user cu
               ON (c.id = cu.c_id)
    

@@ -718,6 +718,9 @@ class UserManager

     $res = Database::query($sql);
     while ($course = Database::fetch_object($res)) {
  •        CourseManager::unsubscribe_user($user_id, $course->code);
           $sql = "DELETE FROM $table_group
                   WHERE c_id = {$course->id} AND user_id = $user_id";
           Database::query($sql);
    

jderriks avatar Aug 10 '18 08:08 jderriks

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jul 31 '20 19:07 stale[bot]

The issue at present (in the 2.0 branch) is that we treat student publications (assignments) as resources attached to a course, so when the user is deleted, we are not deleting their assignments.

The solution remains of deleting each subscription to a course before deleting the user, but that's not a clean solution.

Instead, we should fix the current user deletion process to use something similar to CourseManager::unsubscribe_user() (which deletes files in the course properly, I believe). At the moment, the src/CoreBundle/Repository/Node/UserRepository.php script (~line 265) does a raw delete from the course_rel_user table, which is frankly ugly.

The getRelations() method in the UserRepository.php should trigger a proper cascade of deletions. Not something blunt deleting everything (some things have to remain and be anonymized to avoid destroying course tracking), but we should review each relationship and treat them correctly. Adding a relationship like ['table' => 'c_student_publication', 'field' => 'user_id', 'action' => 'delete'] in getRelations() would be a "quick fix") to this specific original issue.

ywarnier avatar Mar 24 '26 12:03 ywarnier

It is fixed with this commit https://github.com/chamilo/chamilo-lms/pull/8392/changes/5694e6b6993d4335eca6e1d6ac42c91433578e05

christianbeeznest avatar May 11 '26 19:05 christianbeeznest

Assumed correct (untested by me)

ywarnier avatar Sep 01 '26 15:09 ywarnier