Commit 59814880 by Guba Sándor

Merge branch 'feature-update-template' into 'master'

ACL clone

![2014-10-16-134321_1920x1080_scrot](https://git.ik.bme.hu/uploads/circle/cloud/a91a5f4d81/2014-10-16-134321_1920x1080_scrot.png)

See merge request !248
parents d4c7fdc3 dc717ea3
......@@ -71,6 +71,17 @@ class AclBase(Model):
"""Define permission levels for Users/Groups per object."""
object_level_set = GenericRelation(ObjectLevel)
def clone_acl(self, other):
"""Clone full ACL from other object."""
assert self.id != other.id or type(self) != type(other)
self.object_level_set.clear()
for i in other.object_level_set.all():
ol = self.object_level_set.create(level=i.level)
for j in i.users.all():
ol.users.add(j)
for j in i.groups.all():
ol.groups.add(j)
@classmethod
def get_level_object(cls, level):
......
......@@ -90,9 +90,15 @@ class VmSaveForm(OperationForm):
def __init__(self, *args, **kwargs):
default = kwargs.pop('default', None)
clone = kwargs.pop('clone', False)
super(VmSaveForm, self).__init__(*args, **kwargs)
if default:
self.fields['name'].initial = default
if clone:
self.fields.insert(2, "clone", forms.BooleanField(
required=False, label=_("Clone template permissions"),
help_text=_("Clone the access list of parent template. Useful "
"for updating a template.")))
class VmCustomizeForm(forms.Form):
......
......@@ -457,6 +457,10 @@ class VmSaveView(FormOperationMixin, VmOperationView):
op = self.get_op()
val = super(VmSaveView, self).get_form_kwargs()
val['default'] = op._rename(op.instance.name)
obj = self.get_object()
if obj.template and obj.template.has_level(
self.request.user, "owner"):
val['clone'] = True
return val
......
......@@ -637,7 +637,7 @@ class SaveAsTemplateOperation(InstanceOperation):
disk.destroy()
def _operation(self, activity, user, system, name=None,
with_shutdown=True, task=None, **kwargs):
with_shutdown=True, clone=False, task=None, **kwargs):
if with_shutdown:
try:
ShutdownOperation(self.instance).call(parent_activity=activity,
......@@ -687,6 +687,8 @@ class SaveAsTemplateOperation(InstanceOperation):
tmpl = InstanceTemplate(**params)
tmpl.full_clean() # Avoiding database errors.
tmpl.save()
if clone:
tmpl.clone_acl(self.instance.template)
try:
tmpl.disks.add(*self.disks)
# create interface templates
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment