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
7f83651c
authored
Jun 01, 2018
by
Szabolcs Gelencser
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extract glance and template to c members on AclUpdateView
parent
af399a32
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
34 deletions
+23
-34
circle/dashboard/views/util.py
+23
-34
No files found.
circle/dashboard/views/util.py
View file @
7f83651c
...
...
@@ -459,9 +459,8 @@ class AclUpdateView(LoginRequiredMixin, View, SingleObjectMixin):
return
None
def
__accept_membership
(
self
,
project_id_of_user
):
template
=
self
.
get_object
()
glance
=
self
.
__get_glance_admin_client
(
project_id_of_user
)
glance
.
image_members
.
update
(
template
.
image_id
,
project_id_of_user
,
'accepted'
)
other_users_glance
=
self
.
__get_glance_admin_client
(
project_id_of_user
)
other_users_glance
.
image_members
.
update
(
self
.
template
.
image_id
,
project_id_of_user
,
'accepted'
)
def
__list_users_of_group
(
self
,
group_id
):
keystone
=
self
.
__get_keystone_admin_client
()
...
...
@@ -476,11 +475,10 @@ class AclUpdateView(LoginRequiredMixin, View, SingleObjectMixin):
def
__handle_group_assignment
(
self
):
new_group_name
=
self
.
request
.
POST
[
'name'
]
template
=
self
.
get_object
()
new_group
=
self
.
__get_group_by_name
(
new_group_name
)
old_groups
=
TemplateGroupMember
.
objects
.
filter
(
instancetemplate__image_id
=
template
.
image_id
)
instancetemplate__image_id
=
self
.
template
.
image_id
)
if
new_group
.
id
in
old_groups
:
msg
=
_
(
"Already shared with group
%
s"
%
new_group_name
)
messages
.
warning
(
self
.
request
,
msg
)
...
...
@@ -490,37 +488,34 @@ class AclUpdateView(LoginRequiredMixin, View, SingleObjectMixin):
group
.
save
()
except
IntegrityError
:
group
=
TemplateGroupMember
.
objects
.
get
(
group_id
=
new_group
.
id
)
template
.
groups
.
add
(
group
)
template
.
save
()
self
.
template
.
groups
.
add
(
group
)
self
.
template
.
save
()
msg
=
_
(
"Successfully shared with group
%
s"
%
new_group_name
)
messages
.
success
(
self
.
request
,
msg
)
def
__get_members_of_snapshot
(
self
,
glance
):
template
=
self
.
get_object
()
old_members_generator
=
glance
.
image_members
.
list
(
template
.
image_id
)
def
__get_members_of_snapshot
(
self
):
old_members_generator
=
self
.
glance
.
image_members
.
list
(
self
.
template
.
image_id
)
return
[
m
.
member_id
for
m
in
old_members_generator
]
def
__handle_user_assignment
(
self
):
glance
=
self
.
__get_glance_admin_client
(
self
.
request
.
user
.
tenant_id
)
template
=
self
.
get_object
()
new_template_user
=
self
.
request
.
POST
[
'name'
]
project_id_of_user
=
self
.
__get_project_id_by_name
(
new_template_user
)
old_members
=
self
.
__get_members_of_snapshot
(
glance
)
old_members
=
self
.
__get_members_of_snapshot
()
if
project_id_of_user
in
old_members
:
msg
=
_
(
"Template is already shared with
%
s"
%
new_template_user
)
messages
.
warning
(
self
.
request
,
msg
)
elif
project_id_of_user
is
not
None
:
glance
.
image_members
.
create
(
template
.
image_id
,
project_id_of_user
)
self
.
glance
.
image_members
.
create
(
self
.
template
.
image_id
,
project_id_of_user
)
self
.
__accept_membership
(
project_id_of_user
)
try
:
user
=
TemplateUserMember
(
project_id
=
project_id_of_user
,
name
=
new_template_user
)
user
.
save
()
except
IntegrityError
:
user
=
TemplateUserMember
.
objects
.
get
(
project_id
=
project_id_of_user
)
template
.
users
.
add
(
user
)
template
.
save
()
self
.
template
.
users
.
add
(
user
)
self
.
template
.
save
()
msg
=
_
(
"Successfully shared with
%
s"
%
new_template_user
)
messages
.
success
(
self
.
request
,
msg
)
else
:
...
...
@@ -554,15 +549,13 @@ class AclUpdateView(LoginRequiredMixin, View, SingleObjectMixin):
return
removes
def
__remove_user_from_db
(
self
,
member_id
):
template
=
self
.
get_object
()
user
=
TemplateUserMember
.
objects
.
get
(
project_id
=
member_id
)
template
.
users
.
remove
(
user
)
template
.
save
()
self
.
template
.
users
.
remove
(
user
)
self
.
template
.
save
()
def
__remove_group_from_db
(
self
,
member_id
):
template
=
self
.
get_object
()
template
.
groups
.
remove
(
member_id
)
template
.
save
()
self
.
template
.
groups
.
remove
(
member_id
)
self
.
template
.
save
()
def
__handle_removes_from_db
(
self
):
removes
=
self
.
__get_removes
()
...
...
@@ -574,8 +567,7 @@ class AclUpdateView(LoginRequiredMixin, View, SingleObjectMixin):
messages
.
success
(
self
.
request
,
_
(
"Successfully removed group"
))
def
__is_member_of_groups
(
self
,
member_id
):
template
=
self
.
get_object
()
for
group
in
template
.
groups
.
all
():
for
group
in
self
.
template
.
groups
.
all
():
group_members
=
self
.
__list_users_of_group
(
group
.
group_id
)
for
group_member
in
group_members
:
if
group_member
.
default_project_id
==
member_id
:
...
...
@@ -583,33 +575,30 @@ class AclUpdateView(LoginRequiredMixin, View, SingleObjectMixin):
return
False
def
__cleanup_member
(
self
,
member_id
):
template
=
self
.
get_object
()
try
:
template
.
users
.
get
(
project_id
=
member_id
)
self
.
template
.
users
.
get
(
project_id
=
member_id
)
return
# member is assigned as user
except
TemplateUserMember
.
DoesNotExist
:
pass
if
not
self
.
__is_member_of_groups
(
member_id
):
glance
=
self
.
__get_glance_admin_client
(
self
.
request
.
user
.
tenant_id
)
glance
.
image_members
.
delete
(
template
.
image_id
,
member_id
)
self
.
glance
.
image_members
.
delete
(
self
.
template
.
image_id
,
member_id
)
def
__cleanup_assigned_members_of_snapshot
(
self
):
template
=
self
.
get_object
()
glance
=
self
.
__get_glance_admin_client
(
self
.
request
.
user
.
tenant_id
)
member_ids
=
self
.
__get_members_of_snapshot
(
glance
)
member_ids
=
self
.
__get_members_of_snapshot
()
for
member_id
in
member_ids
:
self
.
__cleanup_member
(
member_id
)
def
post
(
self
,
request
,
*
args
,
**
kwargs
):
template
=
self
.
get_object
()
self
.
template
=
self
.
get_object
()
self
.
glance
=
self
.
__get_glance_admin_client
(
self
.
request
.
user
.
tenant_id
)
openstack_api
.
glance
.
image_update
(
request
,
template
.
image_id
,
visibility
=
"shared"
)
openstack_api
.
glance
.
image_update
(
request
,
self
.
template
.
image_id
,
visibility
=
"shared"
)
self
.
__handle_removes_from_db
()
self
.
__handle_assignments
()
self
.
__cleanup_assigned_members_of_snapshot
()
return
redirect
(
"
%
s#access"
%
template
.
get_absolute_url
())
return
redirect
(
"
%
s#access"
%
self
.
template
.
get_absolute_url
())
class
GraphMixin
(
object
):
...
...
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