Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gelencsér Szabolcs
/
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
01328670
authored
Apr 03, 2014
by
Dudás Ádám
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
common, vm: make possibile to specify parent activity for operation
parent
407db0d3
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
8 deletions
+38
-8
circle/common/operations.py
+9
-4
circle/vm/operations.py
+29
-4
No files found.
circle/common/operations.py
View file @
01328670
...
...
@@ -25,10 +25,12 @@ class Operation(object):
"""
skip_checks
=
kwargs
.
setdefault
(
'system'
,
False
)
user
=
kwargs
.
setdefault
(
'user'
,
None
)
parent_activity
=
kwargs
.
pop
(
'parent_activity'
,
None
)
if
not
skip_checks
:
self
.
check_auth
(
user
)
self
.
check_precond
()
return
self
.
create_activity
(
user
=
user
)
return
self
.
create_activity
(
parent
=
parent_activity
,
user
=
user
)
def
_exec_op
(
self
,
activity
,
user
,
**
kwargs
):
"""Execute the operation inside the specified activity's context.
...
...
@@ -65,11 +67,14 @@ class Operation(object):
"""Execute the operation (synchronously).
Anticipated keyword arguments:
* user: The User invoking the operation. If this argument is not
present, it'll be provided with a default value of None.
* parent_activity: Parent activity for the operation. If this argument
is present, the operation's activity will be created
as a child activity of it.
* system: Indicates that the operation is invoked by the system, not a
User. If this argument is present and has a value of True,
then authorization checks are skipped.
* user: The User invoking the operation. If this argument is not
present, it'll be provided with a default value of None.
"""
activity
=
self
.
__prelude
(
kwargs
)
return
self
.
_exec_op
(
activity
=
activity
,
**
kwargs
)
...
...
@@ -82,7 +87,7 @@ class Operation(object):
raise
PermissionDenied
(
"
%
s doesn't have the required permissions."
%
user
)
def
create_activity
(
self
,
user
):
def
create_activity
(
self
,
parent
,
user
):
raise
NotImplementedError
def
on_abort
(
self
,
activity
,
error
):
...
...
circle/vm/operations.py
View file @
01328670
...
...
@@ -39,9 +39,22 @@ class InstanceOperation(Operation):
super
(
InstanceOperation
,
self
)
.
check_auth
(
user
=
user
)
def
create_activity
(
self
,
user
):
return
InstanceActivity
.
create
(
code_suffix
=
self
.
activity_code_suffix
,
instance
=
self
.
instance
,
user
=
user
)
def
create_activity
(
self
,
parent
,
user
):
if
parent
:
if
parent
.
instance
!=
self
.
instance
:
raise
ValueError
(
"The instance associated with the specified "
"parent activity does not match the instance "
"bound to the operation."
)
if
parent
.
user
!=
user
:
raise
ValueError
(
"The user associated with the specified "
"parent activity does not match the user "
"provided as parameter."
)
return
parent
.
create_sub
(
code_suffix
=
self
.
activity_code_suffix
)
else
:
return
InstanceActivity
.
create
(
code_suffix
=
self
.
activity_code_suffix
,
instance
=
self
.
instance
,
user
=
user
)
def
register_instance_operation
(
op_cls
,
op_id
=
None
):
...
...
@@ -420,7 +433,19 @@ class NodeOperation(Operation):
super
(
NodeOperation
,
self
)
.
__init__
(
subject
=
node
)
self
.
node
=
node
def
create_activity
(
self
,
user
):
def
create_activity
(
self
,
parent
,
user
):
if
parent
:
if
parent
.
node
!=
self
.
node
:
raise
ValueError
(
"The node associated with the specified "
"parent activity does not match the node "
"bound to the operation."
)
if
parent
.
user
!=
user
:
raise
ValueError
(
"The user associated with the specified "
"parent activity does not match the user "
"provided as parameter."
)
return
parent
.
create_sub
(
code_suffix
=
self
.
activity_code_suffix
)
else
:
return
NodeActivity
.
create
(
code_suffix
=
self
.
activity_code_suffix
,
node
=
self
.
node
,
user
=
user
)
...
...
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