Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
hypha
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ots
hypha
Commits
1828a9d8
Unverified
Commit
1828a9d8
authored
5 years ago
by
Fredrik Jonsson
Committed by
GitHub
5 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #1306 from OpenTechFund/feature/account-cleanup-command
Add a account clenup command.
parents
96eb9885
cf8efe70
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
hypha/apply/users/management/commands/accounts_cleanup.py
+31
-0
31 additions, 0 deletions
hypha/apply/users/management/commands/accounts_cleanup.py
with
31 additions
and
0 deletions
hypha/apply/users/management/commands/accounts_cleanup.py
0 → 100644
+
31
−
0
View file @
1828a9d8
from
datetime
import
timedelta
from
django.contrib.auth
import
get_user_model
from
django.core.management.base
import
BaseCommand
from
django.db
import
transaction
from
django.utils
import
timezone
class
Command
(
BaseCommand
):
help
=
"
1. Mark all accounts that has not logged in after 5 month after creation as inactive.
"
@transaction.atomic
def
handle
(
self
,
*
args
,
**
options
):
onehundredfifty_days_ago
=
timezone
.
now
()
-
timedelta
(
days
=
150
)
User
=
get_user_model
()
users_inactivate
=
User
.
objects
.
filter
(
date_joined__date__lte
=
onehundredfifty_days_ago
,
is_active
=
True
,
is_staff
=
False
,
last_login__isnull
=
True
)
for
user
in
users_inactivate
:
user
.
is_active
=
False
user
.
save
()
# TODO 2. Delete accounts that has never logged in and has no applications.
# As it is now might delete accounts that should remain.
# users_delete = User.objects.filter(date_joined__date__lte=onehundredfifty_days_ago, is_active=False, is_staff=False, last_login__isnull=True, groups__isnull=True, applicationsubmission__isnull=True).order_by('pk')
# for user in users_delete:
# # user.delete()
# print(f'Delete {user}:{user.pk}')
# delete_count = users_delete.count()
# print(f'Delete {delete_count} users')
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment