Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
beat.web
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
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
beat
beat.web
Commits
e212c3b2
Commit
e212c3b2
authored
5 years ago
by
Flavio TARSETTI
Browse files
Options
Downloads
Patches
Plain Diff
[accounts] refactor invalid users cleanup
parent
3fcaba13
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!312
Postpone date of users validation and clean out layer profiles after a crash
Pipeline
#36008
canceled
5 years ago
Stage: build
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
beat/web/accounts/management/commands/postpone_users_validation.py
+34
-26
34 additions, 26 deletions
...accounts/management/commands/postpone_users_validation.py
with
34 additions
and
26 deletions
beat/web/accounts/management/commands/postpone_users_validation.py
+
34
−
26
View file @
e212c3b2
...
...
@@ -75,33 +75,22 @@ class Command(BaseCommand):
postpone_count
=
0
now
=
datetime
.
datetime
.
now
()
for
invalid_profile
in
invalid_userprofiles_new_users
:
user
=
invalid_profile
.
user
expiration_date_delta
=
datetime
.
timedelta
(
days
=
settings
.
ACCOUNT_ACTIVATION_DAYS
)
if
user
.
profile
.
registration_date
+
expiration_date_delta
<=
now
:
count
+=
1
user
.
delete
()
invalid_profile
.
delete
()
SupervisionTrack
.
objects
.
filter
(
supervision_key
=
invalid_profile
.
supervision_key
).
delete
()
RegistrationProfile
.
objects
.
filter
(
user
=
invalid_profile
.
user
).
delete
()
expiration_date_delta_new_users
=
datetime
.
timedelta
(
days
=
settings
.
ACCOUNT_ACTIVATION_DAYS
)
for
invalid_profile
in
invalid_userprofiles_waiting_validation
:
user
=
invalid_profile
.
user
expiration_date_delta
=
datetime
.
timedelta
(
days
=
settings
.
ACCOUNT_ACTIVATION_DAYS_FROM_SUPERVISOR
)
if
user
.
profile
.
registration_date
+
expiration_date_delta
<=
now
:
count
+=
1
user
.
delete
()
invalid_profile
.
delete
()
SupervisionTrack
.
objects
.
filter
(
supervision_key
=
invalid_profile
.
supervision_key
).
delete
()
RegistrationProfile
.
objects
.
filter
(
user
=
invalid_profile
.
user
).
delete
()
expiration_date_delta_waiting_validation
=
datetime
.
timedelta
(
days
=
settings
.
ACCOUNT_ACTIVATION_DAYS_FROM_SUPERVISOR
)
count
+=
self
.
check_invalid_profiles
(
invalid_userprofiles_new_users
,
expiration_date_delta_new_users
,
now
)
count
+=
self
.
check_invalid_profiles
(
invalid_userprofiles_waiting_validation
,
expiration_date_delta_waiting_validation
,
now
,
)
supervisiontracks
=
SupervisionTrack
.
objects
.
all
()
expiration_date_delta
=
datetime
.
timedelta
(
...
...
@@ -140,6 +129,25 @@ class Command(BaseCommand):
)
)
def
check_invalid_profiles
(
self
,
invalid_profiles_list
,
expiration_date_delta
,
now
):
"""
Override this method if you want to customize data inputs or
"""
count_updated_users
=
0
for
invalid_profile
in
invalid_profiles_list
:
user
=
invalid_profile
.
user
if
user
.
profile
.
registration_date
+
expiration_date_delta
<=
now
:
count_updated_users
+=
1
user
.
delete
()
invalid_profile
.
delete
()
SupervisionTrack
.
objects
.
filter
(
supervision_key
=
invalid_profile
.
supervision_key
).
delete
()
RegistrationProfile
.
objects
.
filter
(
user
=
invalid_profile
.
user
).
delete
()
return
count_updated_users
def
get_input_data
(
self
,
message
,
default
=
None
):
"""
Override this method if you want to customize data inputs or
...
...
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