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
cd7b0b2d
Commit
cd7b0b2d
authored
5 years ago
by
Flavio TARSETTI
Committed by
Flavio TARSETTI
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
[accounts] code refactoring on validation postpone command
parent
56032a46
No related branches found
No related tags found
1 merge request
!312
Postpone date of users validation and clean out layer profiles after a crash
Pipeline
#35969
passed
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
+52
-58
52 additions, 58 deletions
...accounts/management/commands/postpone_users_validation.py
with
52 additions
and
58 deletions
beat/web/accounts/management/commands/postpone_users_validation.py
+
52
−
58
View file @
cd7b0b2d
...
@@ -52,7 +52,6 @@ class Command(BaseCommand):
...
@@ -52,7 +52,6 @@ class Command(BaseCommand):
def
handle
(
self
,
*
args
,
**
options
):
def
handle
(
self
,
*
args
,
**
options
):
clean
=
True
if
options
[
'
interactive
'
]:
if
options
[
'
interactive
'
]:
try
:
try
:
...
@@ -63,63 +62,58 @@ class Command(BaseCommand):
...
@@ -63,63 +62,58 @@ class Command(BaseCommand):
if
answer
!=
'
y
'
:
if
answer
!=
'
y
'
:
self
.
stdout
.
write
(
'
Postpone canceled
'
)
self
.
stdout
.
write
(
'
Postpone canceled
'
)
sys
.
exit
(
1
)
sys
.
exit
(
0
)
if
clean
:
invalid_userprofiles_new_users
=
Profile
.
objects
.
filter
(
status
=
Profile
.
NEWUSER
)
invalid_userprofiles_new_users
=
Profile
.
objects
.
filter
(
status
=
Profile
.
NEWUSER
)
invalid_userprofiles_waiting_validation
=
Profile
.
objects
.
filter
(
status
=
Profile
.
WAITINGVALIDATION
)
invalid_userprofiles_waiting_validation
=
Profile
.
objects
.
filter
(
status
=
Profile
.
WAITINGVALIDATION
)
count
=
0
count
=
0
postpone_count
=
0
postpone_count
=
0
now
=
datetime
.
datetime
.
now
()
now
=
datetime
.
datetime
.
now
()
for
invalid_profile
in
invalid_userprofiles_new_users
:
for
invalid_profile
in
invalid_userprofiles_new_users
:
user
=
invalid_profile
.
user
user
=
invalid_profile
.
user
supervisiontracks
=
SupervisionTrack
.
objects
.
filter
(
supervision_key
=
invalid_profile
.
supervision_key
)
supervisiontracks
=
SupervisionTrack
.
objects
.
filter
(
supervision_key
=
invalid_profile
.
supervision_key
)
registration_profiles
=
RegistrationProfile
.
objects
.
filter
(
user
=
invalid_profile
.
user
)
registration_profiles
=
RegistrationProfile
.
objects
.
filter
(
user
=
invalid_profile
.
user
)
expiration_date_delta
=
datetime
.
timedelta
(
days
=
settings
.
ACCOUNT_ACTIVATION_DAYS
)
expiration_date_delta
=
datetime
.
timedelta
(
days
=
settings
.
ACCOUNT_ACTIVATION_DAYS
)
if
user
.
profile
.
registration_date
+
expiration_date_delta
<=
now
:
if
user
.
profile
.
registration_date
+
expiration_date_delta
<=
now
:
count
+=
1
count
+=
1
user
.
delete
()
user
.
delete
()
invalid_profile
.
delete
()
invalid_profile
.
delete
()
SupervisionTrack
.
objects
.
filter
(
supervision_key
=
invalid_profile
.
supervision_key
).
delete
()
for
_track
in
supervisiontracks
:
RegistrationProfile
.
objects
.
filter
(
user
=
invalid_profile
.
user
).
delete
()
_track
.
delete
()
for
_profile
in
registration_profiles
:
for
invalid_profile
in
invalid_userprofiles_waiting_validation
:
_profile
.
delete
()
user
=
invalid_profile
.
user
supervisiontracks
=
SupervisionTrack
.
objects
.
filter
(
supervision_key
=
invalid_profile
.
supervision_key
)
for
invalid_profile
in
invalid_userprofiles_waiting_validation
:
registration_profiles
=
RegistrationProfile
.
objects
.
filter
(
user
=
invalid_profile
.
user
)
user
=
invalid_profile
.
user
supervisiontracks
=
SupervisionTrack
.
objects
.
filter
(
supervision_key
=
invalid_profile
.
supervision_key
)
expiration_date_delta
=
datetime
.
timedelta
(
days
=
settings
.
ACCOUNT_ACTIVATION_DAYS_FROM_SUPERVISOR
)
registration_profiles
=
RegistrationProfile
.
objects
.
filter
(
user
=
invalid_profile
.
user
)
if
user
.
profile
.
registration_date
+
expiration_date_delta
<=
now
:
count
+=
1
expiration_date_delta
=
datetime
.
timedelta
(
days
=
settings
.
ACCOUNT_ACTIVATION_DAYS_FROM_SUPERVISOR
)
user
.
delete
()
if
user
.
profile
.
registration_date
+
expiration_date_delta
<=
now
:
invalid_profile
.
delete
()
count
+=
1
SupervisionTrack
.
objects
.
filter
(
supervision_key
=
invalid_profile
.
supervision_key
).
delete
()
user
.
delete
()
RegistrationProfile
.
objects
.
filter
(
user
=
invalid_profile
.
user
).
delete
()
invalid_profile
.
delete
()
for
_track
in
supervisiontracks
:
supervisiontracks
=
SupervisionTrack
.
objects
.
all
()
_track
.
delete
()
expiration_date_delta
=
datetime
.
timedelta
(
days
=
settings
.
ACCOUNT_BLOCKAGE_AFTER_FIRST_REJECTION_DAYS
)
for
_profile
in
registration_profiles
:
extra_days_delta
=
datetime
.
timedelta
(
days
=
(
settings
.
ACCOUNT_BLOCKAGE_AFTER_FIRST_REJECTION_DAYS
+
1
))
_profile
.
delete
()
for
supervisiontrack
in
supervisiontracks
:
if
supervisiontrack
.
is_valid
and
supervisiontrack
.
expiration_date
<
now
+
expiration_date_delta
:
supervisiontracks
=
SupervisionTrack
.
objects
.
all
()
postpone_count
+=
1
for
supervisiontrack
in
supervisiontracks
:
postpone_date
=
now
+
extra_days_delta
expiration_date_delta
=
datetime
.
timedelta
(
days
=
settings
.
ACCOUNT_BLOCKAGE_AFTER_FIRST_REJECTION_DAYS
)
supervisiontrack
.
expiration_date
=
postpone_date
if
supervisiontrack
.
is_valid
and
supervisiontrack
.
expiration_date
<
now
+
expiration_date_delta
:
supervisiontrack
.
save
()
postpone_count
+=
1
supervisee_profile
=
Profile
.
objects
.
get
(
user
=
supervisiontrack
.
supervisee
)
extra_days_delta
=
datetime
.
timedelta
(
days
=
(
settings
.
ACCOUNT_BLOCKAGE_AFTER_FIRST_REJECTION_DAYS
+
1
))
if
supervisee_profile
.
status
==
Profile
.
YEARREVALIDATION
:
postpone_date
=
now
+
extra_days_delta
supervisee_profile
.
status
=
Profile
.
ACCEPTED
supervisiontrack
.
expiration_date
=
postpone_date
supervisee_profile
.
save
()
supervisiontrack
.
save
()
supervisee_profile
=
Profile
.
objects
.
get
(
user
=
supervisiontrack
.
supervisee
)
if
supervisee_profile
.
status
==
Profile
.
YEARREVALIDATION
:
self
.
stdout
.
write
(
'
{} Invalid user(s) successfully cleaned/{} Total user(s) checked
'
.
format
(
count
,
invalid_userprofiles_new_users
.
count
()
+
invalid_userprofiles_waiting_validation
.
count
()))
supervisee_profile
.
status
=
Profile
.
ACCEPTED
self
.
stdout
.
write
(
'
{} Valid user(s) postponed/{} Total supervision track(s) checked
'
.
format
(
postpone_count
,
supervisiontracks
.
count
()))
supervisee_profile
.
save
()
self
.
stdout
.
write
(
'
{} Invalid user(s) successfully cleaned/
'
.
format
(
count
)
+
'
{} Total user(s) checked
'
.
format
(
invalid_userprofiles_new_users
.
count
()
+
invalid_userprofiles_waiting_validation
.
count
()))
self
.
stdout
.
write
(
'
{} Valid user(s) postponed/
'
.
format
(
postpone_count
)
+
'
{} Total supervision track(s) checked
'
.
format
(
supervisiontracks
.
count
()))
def
get_input_data
(
self
,
message
,
default
=
None
):
def
get_input_data
(
self
,
message
,
default
=
None
):
...
...
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