Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gutyán Gábor
/
circlestack
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
069f491e
authored
May 06, 2014
by
Őry Máté
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
vm: add InstanceActivity.is_abortable_for and ~_user
parent
028e8896
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
55 additions
and
4 deletions
+55
-4
circle/dashboard/templates/dashboard/vm-detail/_activity-timeline.html
+2
-2
circle/dashboard/views.py
+2
-2
circle/vm/models/activity.py
+7
-0
circle/vm/models/instance.py
+5
-0
circle/vm/tests/test_models.py
+39
-0
No files found.
circle/dashboard/templates/dashboard/vm-detail/_activity-timeline.html
View file @
069f491e
...
...
@@ -9,8 +9,8 @@
{{ a.get_readable_name }}{% if user.is_superuser %}
</a>
{% endif %}
</strong>
{{ a.started|date:"Y-m-d H:i" }}{% if a.user %}, {{ a.user }}{% endif %}
{% if
user.is_superuser and a.is_abortable
%}
<form
action=
""
method=
"POST"
class=
"pull-right"
>
{% if
a.is_abortable_for_user
%}
<form
action=
"
{{ a.instance.get_absolute_url }}
"
method=
"POST"
class=
"pull-right"
>
{% csrf_token %}
<input
type=
"hidden"
name=
"abort_operation"
/>
<input
type=
"hidden"
name=
"activity"
value=
"{{ a.pk }}"
/>
...
...
circle/dashboard/views.py
View file @
069f491e
...
...
@@ -427,11 +427,11 @@ class VmDetailView(CheckedDetailView):
def
__abort_operation
(
self
,
request
):
self
.
object
=
self
.
get_object
()
if
not
request
.
user
.
is_superuser
:
raise
PermissionDenied
()
activity
=
get_object_or_404
(
InstanceActivity
,
pk
=
request
.
POST
.
get
(
"activity"
))
if
not
activity
.
is_abortable_for
(
request
.
user
):
raise
PermissionDenied
()
activity
.
abort
()
return
redirect
(
"
%
s#activity"
%
self
.
object
.
get_absolute_url
())
...
...
circle/vm/models/activity.py
View file @
069f491e
...
...
@@ -107,6 +107,13 @@ class InstanceActivity(ActivityModel):
op
=
self
.
instance
.
get_operation_from_activity_code
(
self
.
activity_code
)
return
self
.
task_uuid
and
op
and
op
.
abortable
and
not
self
.
finished
def
is_abortable_for
(
self
,
user
):
"""Can the given user abort the activity?
"""
return
self
.
is_abortable
and
(
user
.
is_superuser
or
user
in
(
self
.
instance
.
owner
,
self
.
user
))
@property
def
is_aborted
(
self
):
"""Has the activity been aborted?
...
...
circle/vm/models/instance.py
View file @
069f491e
from
__future__
import
absolute_import
,
unicode_literals
from
datetime
import
timedelta
from
functools
import
partial
from
importlib
import
import_module
from
logging
import
getLogger
from
string
import
ascii_lowercase
...
...
@@ -886,4 +887,8 @@ class Instance(AclBase, VirtualMachineDescModel, StatusModel, OperatedMixin,
acts
=
(
self
.
activity_log
.
filter
(
parent
=
None
)
.
order_by
(
'-started'
)
.
select_related
(
'user'
)
.
prefetch_related
(
'children'
))
if
user
is
not
None
:
for
i
in
acts
:
i
.
is_abortable_for_user
=
partial
(
i
.
is_abortable_for
,
user
=
user
)
return
acts
circle/vm/tests/test_models.py
View file @
069f491e
...
...
@@ -262,6 +262,45 @@ class InstanceActivityTestCase(TestCase):
self
.
assertEquals
(
expected
,
InstanceActivity
.
is_aborted
.
fget
(
iaobj
))
def
test_is_abortable_for_activity_owner_if_not_abortable
(
self
):
iaobj
=
MagicMock
(
spec
=
InstanceActivity
,
is_abortable
=
False
,
user
=
MagicMock
(
spec
=
User
,
is_superuser
=
False
))
self
.
assertFalse
(
InstanceActivity
.
is_abortable_for
(
iaobj
,
iaobj
.
user
))
def
test_is_abortable_for_instance_owner
(
self
):
get_op
=
MagicMock
(
return_value
=
MagicMock
(
abortable
=
True
))
instance
=
MagicMock
(
get_operation_from_activity_code
=
get_op
,
owner
=
MagicMock
(
spec
=
User
,
is_superuser
=
False
))
iaobj
=
MagicMock
(
spec
=
InstanceActivity
,
activity_code
=
'test'
,
finished
=
False
,
instance
=
instance
,
task_uuid
=
'test'
,
user
=
MagicMock
(
spec
=
User
,
is_superuser
=
False
))
self
.
assertTrue
(
InstanceActivity
.
is_abortable_for
(
iaobj
,
iaobj
.
instance
.
owner
))
def
test_is_abortable_for_activity_owner
(
self
):
get_op
=
MagicMock
(
return_value
=
MagicMock
(
abortable
=
True
))
instance
=
MagicMock
(
get_operation_from_activity_code
=
get_op
)
iaobj
=
MagicMock
(
spec
=
InstanceActivity
,
activity_code
=
'test'
,
finished
=
False
,
instance
=
instance
,
task_uuid
=
'test'
,
user
=
MagicMock
(
spec
=
User
,
is_superuser
=
False
))
self
.
assertTrue
(
InstanceActivity
.
is_abortable_for
(
iaobj
,
iaobj
.
user
))
def
test_not_abortable_for_foreign
(
self
):
get_op
=
MagicMock
(
return_value
=
MagicMock
(
abortable
=
True
))
instance
=
MagicMock
(
get_operation_from_activity_code
=
get_op
)
iaobj
=
MagicMock
(
spec
=
InstanceActivity
,
activity_code
=
'test'
,
finished
=
False
,
instance
=
instance
,
task_uuid
=
'test'
)
self
.
assertFalse
(
InstanceActivity
.
is_abortable_for
(
iaobj
,
MagicMock
(
spec
=
User
,
is_superuser
=
False
)))
def
test_is_abortable_for_superuser
(
self
):
get_op
=
MagicMock
(
return_value
=
MagicMock
(
abortable
=
True
))
instance
=
MagicMock
(
get_operation_from_activity_code
=
get_op
)
iaobj
=
MagicMock
(
spec
=
InstanceActivity
,
activity_code
=
'test'
,
finished
=
False
,
instance
=
instance
,
task_uuid
=
'test'
)
su
=
MagicMock
(
spec
=
User
,
is_superuser
=
True
)
self
.
assertTrue
(
InstanceActivity
.
is_abortable_for
(
iaobj
,
su
))
def
test_disable_enabled
(
self
):
node
=
MagicMock
(
spec
=
Node
,
enabled
=
True
)
with
patch
(
'vm.models.node.node_activity'
)
as
nac
:
...
...
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