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
8235a2f2
Commit
8235a2f2
authored
4 years ago
by
Flavio TARSETTI
Browse files
Options
Downloads
Patches
Plain Diff
[accounts][views] load temporary url
parent
0e82886b
No related branches found
No related tags found
1 merge request
!328
Improve automatic emails with temporary urls
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
beat/web/accounts/views.py
+149
-1
149 additions, 1 deletion
beat/web/accounts/views.py
with
149 additions
and
1 deletion
beat/web/accounts/views.py
+
149
−
1
View file @
8235a2f2
...
@@ -25,19 +25,42 @@
...
@@ -25,19 +25,42 @@
# #
# #
###############################################################################
###############################################################################
from
django.conf
import
settings
from
django.shortcuts
import
render
from
django.shortcuts
import
render
from
django.shortcuts
import
get_object_or_404
from
django.contrib.auth.decorators
import
login_required
from
django.contrib.auth.decorators
import
login_required
from
django.contrib.auth.forms
import
PasswordChangeForm
from
django.contrib.auth.forms
import
PasswordChangeForm
from
django.contrib.auth.models
import
User
from
django.contrib.auth.models
import
User
from
django.contrib
import
messages
from
django.contrib
import
messages
from
django.db
import
models
from
django.db
import
models
from
django.db.models
import
Q
from
django.db.models
import
Q
from
rest_framework.authtoken.models
import
Token
from
rest_framework.authtoken.models
import
Token
from
rest_framework.response
import
Response
from
rest_framework
import
status
from
.forms
import
AccountSettingsForm
from
.forms
import
AccountSettingsForm
from
.models
import
AccountSettings
from
.models
import
AccountSettings
from
.models
import
SupervisionTrack
,
Profile
from
.models
import
SupervisionTrack
from
.models
import
Profile
from
.models
import
TemporaryUrl
from
..utils
import
mail
from
..common.responses
import
BadRequestResponse
,
ForbiddenResponse
from
datetime
import
datetime
,
timedelta
import
datetime
try
:
from
urlparse
import
urlparse
except
ImportError
:
from
urllib.parse
import
urlparse
@login_required
@login_required
def
account_settings
(
request
):
def
account_settings
(
request
):
...
@@ -114,3 +137,128 @@ def account_settings(request):
...
@@ -114,3 +137,128 @@ def account_settings(request):
'
supervisors_valid
'
:
supervisors_valid
,
'
supervisors_valid
'
:
supervisors_valid
,
'
supervisors_pending
'
:
supervisors_pending
,
'
supervisors_pending
'
:
supervisors_pending
,
'
token
'
:
user
.
auth_token
})
'
token
'
:
user
.
auth_token
})
def
load_temporary_url
(
request
,
hash_url
):
temp_url
=
get_object_or_404
(
TemporaryUrl
,
url_hash
=
hash_url
)
supervisiontrack
=
temp_url
.
supervision_track
supervisee
=
supervisiontrack
.
supervisee
now
=
datetime
.
datetime
.
now
()
if
temp_url
.
status
==
TemporaryUrl
.
VALIDATION
:
# Supervisor validates new Supervisee
if
supervisee
.
profile
.
status
!=
Profile
.
ACCEPTED
and
now
<
temp_url
.
expires
:
supervisiontrack
.
is_valid
=
True
expiration_date_delta
=
datetime
.
timedelta
(
days
=
settings
.
ACCOUNT_EXPIRATION_DAYS
)
supervisiontrack
.
expiration_date
=
now
+
expiration_date_delta
supervisiontrack
.
start_date
=
now
supervisiontrack
.
last_validation_date
=
now
supervisee
.
profile
.
status
=
Profile
.
ACCEPTED
supervisee
.
profile
.
rejection_date
=
None
supervisiontrack
.
save
()
supervisee
.
profile
.
save
()
supervisee
.
is_active
=
True
supervisee
.
save
()
parsed_url
=
urlparse
(
settings
.
URL_PREFIX
)
server_address
=
'
%s://%s
'
%
(
parsed_url
.
scheme
,
parsed_url
.
hostname
)
context
=
{
'
supervisor
'
:
supervisiontrack
.
supervisor
,
'
supervisee
'
:
supervisee
,
'
prefix
'
:
server_address
,
}
mail
.
send_email
(
'
registration/mail.supervisor_validated.subject.txt
'
,
'
registration/mail.supervisor_validated.message.txt
'
,
context
,
[
supervisee
.
email
])
temp_url
.
delete
()
return
render
(
request
,
'
accounts/url_validation.html
'
,
{
'
supervisiontrack
'
:
supervisiontrack
})
else
:
#Track already valid
temp_url
.
delete
()
return
render
(
request
,
'
accounts/url_validation_failed.html
'
)
elif
temp_url
.
status
==
TemporaryUrl
.
YEARREVALIDATION
:
# Supervisee re-validation
if
supervisee
.
profile
.
supervision_key
is
not
None
and
now
<
temp_url
.
expires
:
if
supervisiontrack
.
is_valid
:
if
supervisee
.
profile
.
status
==
Profile
.
YEARREVALIDATION
:
#Check Supervisor validity
supervisor
=
supervisiontrack
.
supervisor
#If Supervisor account is not valid. Reject the account (though this should already be done during supervisor rejection)
if
supervisor
.
profile
.
status
!=
Profile
.
BLOCKED
:
#Change status
supervisee
.
profile
.
status
=
Profile
.
ACCEPTED
#Extend supervisiontrack validity for another 12 months
expiration_date_delta
=
datetime
.
timedelta
(
days
=
settings
.
ACCOUNT_EXPIRATION_DAYS
)
new_expiration_date
=
supervisiontrack
.
expiration_date
+
expiration_date_delta
supervisiontrack
.
expiration_date
=
new_expiration_date
supervisiontrack
.
last_validation_date
=
now
else
:
#Change status
expiration_date_delta
=
datetime
.
timedelta
(
days
=
settings
.
ACCOUNT_BLOCKAGE_AFTER_FIRST_REJECTION_DAYS
)
supervisiontrack
.
expiration_date
=
now
supervisiontrack
.
is_valid
=
False
supervisee
.
profile
.
status
=
Profile
.
REJECTED
supervisee
.
profile
.
rejection_date
=
now
+
expiration_date_delta
supervisee
.
profile
.
supervision_key
=
None
#save
supervisiontrack
.
save
()
supervisee
.
profile
.
save
()
supervisee
.
save
()
else
:
#Track already valid
error_message
=
"
You don
'
t need to revalidate at the moment, your supervision is still valid
"
temp_url
.
delete
()
return
render
(
request
,
'
accounts/url_revalidation_failed.html
'
,
{
'
error_message
'
:
error_message
})
else
:
#A pending request already exist
error_message
=
"
You are not able to perform this action as you already have a pending supervision request
"
temp_url
.
delete
()
return
render
(
request
,
'
accounts/url_revalidation_failed.html
'
,
{
'
error_message
'
:
error_message
})
else
:
#No key is present in supervisee
#Make sure all tracks are invalid
supervisiontracks
=
SupervisionTrack
.
objects
.
filter
(
supervisee
=
supervisee
,
is_valid
=
True
)
# This should never be the case but if it happens invalidate all tracks
if
supervisiontracks
.
count
()
>
0
:
now
=
datetime
.
datetime
.
now
()
for
track
in
supervisiontracks
:
track
.
is_valid
=
False
track
.
expiration_date
=
now
track
.
save
()
#Not allowed to do this (unproper profile.status)
error_message
=
"
You are not allowed to perform this action, you first need to get a valid supervision
"
temp_url
.
delete
()
return
render
(
request
,
'
accounts/url_revalidation_failed.html
'
,
{
'
error_message
'
:
error_message
})
temp_url
.
delete
()
return
render
(
request
,
'
accounts/url_validation.html
'
,
{
'
supervisiontrack
'
:
supervisiontrack
})
else
:
#Track already valid
temp_url
.
delete
()
return
render
(
request
,
'
accounts/url_validation_failed.html
'
)
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