Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gelencsér Szabolcs
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
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,
...
@@ -37,7 +37,7 @@ from vm.models import (Instance, InstanceTemplate, InterfaceTemplate,
InstanceActivity
,
Node
,
instance_activity
,
Lease
,
InstanceActivity
,
Node
,
instance_activity
,
Lease
,
Interface
,
NodeActivity
)
Interface
,
NodeActivity
)
from
firewall.models
import
Vlan
,
Host
,
Rule
from
firewall.models
import
Vlan
,
Host
,
Rule
from
dashboard.models
import
Favourite
from
dashboard.models
import
Favourite
,
Profile
logger
=
logging
.
getLogger
(
__name__
)
logger
=
logging
.
getLogger
(
__name__
)
...
@@ -1490,7 +1490,12 @@ class TransferOwnershipView(LoginRequiredMixin, DetailView):
...
@@ -1490,7 +1490,12 @@ class TransferOwnershipView(LoginRequiredMixin, DetailView):
try
:
try
:
new_owner
=
User
.
objects
.
get
(
username
=
request
.
POST
[
'name'
])
new_owner
=
User
.
objects
.
get
(
username
=
request
.
POST
[
'name'
])
except
User
.
DoesNotExist
:
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
:
except
KeyError
:
raise
SuspiciousOperation
()
raise
SuspiciousOperation
()
...
@@ -1501,9 +1506,22 @@ class TransferOwnershipView(LoginRequiredMixin, DetailView):
...
@@ -1501,9 +1506,22 @@ class TransferOwnershipView(LoginRequiredMixin, DetailView):
token
=
signing
.
dumps
((
obj
.
pk
,
new_owner
.
pk
),
token
=
signing
.
dumps
((
obj
.
pk
,
new_owner
.
pk
),
salt
=
TransferOwnershipConfirmView
.
get_salt
())
salt
=
TransferOwnershipConfirmView
.
get_salt
())
return
HttpResponse
(
"
%
s?key=
%
s"
%
(
token_path
=
reverse
(
reverse
(
'dashboard.views.vm-transfer-ownership-confirm'
),
token
),
'dashboard.views.vm-transfer-ownership-confirm'
,
args
=
[
token
])
content_type
=
"text/plain"
)
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
):
class
TransferOwnershipConfirmView
(
LoginRequiredMixin
,
View
):
...
@@ -1546,6 +1564,11 @@ class TransferOwnershipConfirmView(LoginRequiredMixin, View):
...
@@ -1546,6 +1564,11 @@ class TransferOwnershipConfirmView(LoginRequiredMixin, View):
messages
.
success
(
request
,
self
.
success_message
)
messages
.
success
(
request
,
self
.
success_message
)
logger
.
info
(
'Ownership of
%
s transferred from
%
s to
%
s.'
,
logger
.
info
(
'Ownership of
%
s transferred from
%
s to
%
s.'
,
unicode
(
instance
),
unicode
(
old
),
unicode
(
request
.
user
))
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
())
return
HttpResponseRedirect
(
instance
.
get_absolute_url
())
def
get_instance
(
self
,
key
,
user
):
def
get_instance
(
self
,
key
,
user
):
...
@@ -1555,15 +1578,7 @@ class TransferOwnershipConfirmView(LoginRequiredMixin, View):
...
@@ -1555,15 +1578,7 @@ class TransferOwnershipConfirmView(LoginRequiredMixin, View):
instance
,
new_owner
=
(
instance
,
new_owner
=
(
signing
.
loads
(
key
,
max_age
=
self
.
max_age
,
signing
.
loads
(
key
,
max_age
=
self
.
max_age
,
salt
=
self
.
get_salt
()))
salt
=
self
.
get_salt
()))
except
signing
.
BadSignature
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
()
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
:
logger
.
error
(
'Tried invalid token. Token:
%
s, user:
%
s.
%
s'
,
logger
.
error
(
'Tried invalid token. Token:
%
s, user:
%
s.
%
s'
,
key
,
unicode
(
user
),
unicode
(
e
))
key
,
unicode
(
user
),
unicode
(
e
))
raise
SuspiciousOperation
()
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