[sysadmin-bin] Add function for removing snippets-only users



commit 49e39d372c9183b53522ff765b742ea49faa3add
Author: Bartłomiej Piotrowski <bpiotrowski gnome org>
Date:   Mon Nov 29 13:00:49 2021 +0100

    Add function for removing snippets-only users

 gitlab/inactive-gitlab-users.py | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
---
diff --git a/gitlab/inactive-gitlab-users.py b/gitlab/inactive-gitlab-users.py
index df292e0..2c6ec1c 100755
--- a/gitlab/inactive-gitlab-users.py
+++ b/gitlab/inactive-gitlab-users.py
@@ -169,6 +169,24 @@ def get_inactive_users(gl, timedelta_unit, timedelta_value):
     return results
 
 
+def delete_snippets_only_users(gl):
+    trusted_users = gl.users.list(custom_attributes={"trusted": "true"}, all=True)
+    snippets = gl.snippets.public(per_page=100)
+
+    snippets_users = {x.attributes["author"]["id"] for x in snippets}
+    for user in snippets_users:
+        user = gl.users.get(user)
+        if user in trusted_users:
+            continue
+
+        if is_user_trusted(user):
+            continue
+
+        events = user.events.list(all=True, lazy=True)
+        if len(events) == 0:
+            print(f"removing {user.username}")
+
+
 def trust_user(gl, user_id):
     user = gl.users.get(user_id, lazy=True)
     user.customattributes.set("trusted", "true")
@@ -294,5 +312,7 @@ if __name__ == "__main__":
         trust_all_groups(gl)
     elif args.command == "trust-2fa":
         trust_2fa_users(gl)
+    elif args.command == "snippets":
+        delete_snippets_only_users(gl)
     else:
         parser.print_help()


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]