Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gyuricska Milán
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
77476b8c
authored
Mar 01, 2014
by
Őry Máté
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dashboard: notify owners about ownership transfer
parent
e97539b6
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
38 additions
and
14 deletions
+38
-14
circle/dashboard/templates/dashboard/notifications/ownership-accepted.html
+4
-0
circle/dashboard/templates/dashboard/notifications/ownership-offer.html
+5
-0
circle/dashboard/views.py
+29
-14
No files found.
circle/dashboard/templates/dashboard/notifications/ownership-accepted.html
0 → 100644
View file @
77476b8c
{%load i18n%}
{%blocktrans with instance=instance.name user=user.name%}
Your ownership offer of {{instance}} has been accepted by {{user}}.
{%endblocktrans%}
circle/dashboard/templates/dashboard/notifications/ownership-offer.html
0 → 100644
View file @
77476b8c
{%load i18n%}
{%blocktrans with instance=instance.name user=user.name%}
{{user}} offered you to take the ownership of his/her virtual machine
called {{instance}}.{%endblocktrans%}
<a
href=
"{{token}}"
class=
"btn btn-success btn-small"
>
{%trans "Accept"%}
</a>
circle/dashboard/views.py
View file @
77476b8c
...
...
@@ -37,7 +37,7 @@ from vm.models import (Instance, InstanceTemplate, InterfaceTemplate,
InstanceActivity
,
Node
,
instance_activity
,
Lease
,
Interface
,
NodeActivity
)
from
firewall.models
import
Vlan
,
Host
,
Rule
from
dashboard.models
import
Favourite
from
dashboard.models
import
Favourite
,
Profile
logger
=
logging
.
getLogger
(
__name__
)
...
...
@@ -1490,7 +1490,12 @@ class TransferOwnershipView(LoginRequiredMixin, DetailView):
try
:
new_owner
=
User
.
objects
.
get
(
username
=
request
.
POST
[
'name'
])
except
User
.
DoesNotExist
:
raise
Http404
()
new_owner
=
User
.
objects
.
get
(
email
=
request
.
POST
[
'name'
])
except
User
.
DoesNotExist
:
new_owner
=
User
.
objects
.
get
(
profile__org_id
=
request
.
POST
[
'name'
])
except
User
.
DoesNotExist
:
messages
.
error
(
request
,
_
(
'Can not find specified user.'
))
return
self
.
get
(
request
,
*
args
,
**
kwargs
)
except
KeyError
:
raise
SuspiciousOperation
()
...
...
@@ -1501,9 +1506,22 @@ class TransferOwnershipView(LoginRequiredMixin, DetailView):
token
=
signing
.
dumps
((
obj
.
pk
,
new_owner
.
pk
),
salt
=
TransferOwnershipConfirmView
.
get_salt
())
return
HttpResponse
(
"
%
s?key=
%
s"
%
(
reverse
(
'dashboard.views.vm-transfer-ownership-confirm'
),
token
),
content_type
=
"text/plain"
)
token_path
=
reverse
(
'dashboard.views.vm-transfer-ownership-confirm'
,
args
=
[
token
])
try
:
new_owner
.
profile
.
notify
(
_
(
'Ownership offer'
),
'dashboard/notifications/ownership-offer.html'
,
{
'instance'
:
obj
,
'token'
:
token_path
})
except
Profile
.
DoesNotExist
:
messages
.
error
(
request
,
_
(
'Can not notify selected user.'
))
else
:
messages
.
success
(
request
,
_
(
'User
%
s is notified about the offer.'
)
%
(
unicode
(
new_owner
),
))
return
redirect
(
reverse_lazy
(
"dashboard.views.detail"
,
kwargs
=
{
'pk'
:
obj
.
pk
}))
class
TransferOwnershipConfirmView
(
LoginRequiredMixin
,
View
):
...
...
@@ -1546,6 +1564,11 @@ class TransferOwnershipConfirmView(LoginRequiredMixin, View):
messages
.
success
(
request
,
self
.
success_message
)
logger
.
info
(
'Ownership of
%
s transferred from
%
s to
%
s.'
,
unicode
(
instance
),
unicode
(
old
),
unicode
(
request
.
user
))
if
old
.
profile
:
old
.
profile
.
notify
(
_
(
'Ownership accepted'
),
'dashboard/notifications/ownership-accepted.html'
,
{
'instance'
:
instance
})
return
HttpResponseRedirect
(
instance
.
get_absolute_url
())
def
get_instance
(
self
,
key
,
user
):
...
...
@@ -1555,15 +1578,7 @@ class TransferOwnershipConfirmView(LoginRequiredMixin, View):
instance
,
new_owner
=
(
signing
.
loads
(
key
,
max_age
=
self
.
max_age
,
salt
=
self
.
get_salt
()))
except
signing
.
BadSignature
as
e
:
logger
.
error
(
'Tried invalid token. Token:
%
s, user:
%
s.
%
s'
,
key
,
unicode
(
user
),
unicode
(
e
))
raise
SuspiciousOperation
()
except
ValueError
as
e
:
logger
.
error
(
'Tried invalid token. Token:
%
s, user:
%
s.
%
s'
,
key
,
unicode
(
user
),
unicode
(
e
))
raise
SuspiciousOperation
()
except
TypeError
as
e
:
except
(
signing
.
BadSignature
,
ValueError
,
TypeError
)
as
e
:
logger
.
error
(
'Tried invalid token. Token:
%
s, user:
%
s.
%
s'
,
key
,
unicode
(
user
),
unicode
(
e
))
raise
SuspiciousOperation
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment