Jakub Niedermertl has uploaded a new change for review.

Change subject: webadmin, userportal: Prevent blank template sub-templates - 
frontend
......................................................................

webadmin, userportal: Prevent blank template sub-templates - frontend

Change-Id: I6b35a0f1b79a22ad25a26bb57acf5f5c68cf79c6
Bug-Url: https://bugzilla.redhat.com/1205813
Signed-off-by: Jakub Niedermertl <jnied...@redhat.com>
---
M 
frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java
M 
frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/NewTemplateVmModelBehavior.java
M 
frontend/webadmin/modules/uicompat/src/main/java/org/ovirt/engine/ui/uicompat/UIConstants.java
M 
frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
M 
frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
5 files changed, 37 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/00/40500/1

diff --git 
a/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java
 
b/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java
index a11257c..23e1fc7 100644
--- 
a/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java
+++ 
b/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java
@@ -3810,4 +3810,7 @@
 
     @DefaultStringValue("Base64 part of vm icon is malformed.")
     String VM_ICON_BASE64_PART_MALFORMED();
+
+    @DefaultStringValue("Blank template can't have sub-templates.")
+    String BLANK_TEMPLATE_CANT_HAVE_SUBTEMPLATES();
 }
diff --git 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/NewTemplateVmModelBehavior.java
 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/NewTemplateVmModelBehavior.java
index 3fa7d7b..2d68b6e 100644
--- 
a/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/NewTemplateVmModelBehavior.java
+++ 
b/frontend/webadmin/modules/uicommonweb/src/main/java/org/ovirt/engine/ui/uicommonweb/models/vms/NewTemplateVmModelBehavior.java
@@ -35,9 +35,12 @@
 import org.ovirt.engine.ui.uicommonweb.models.SystemTreeItemType;
 import org.ovirt.engine.ui.uicommonweb.models.storage.DisksAllocationModel;
 import org.ovirt.engine.ui.uicompat.ConstantsManager;
+import org.ovirt.engine.ui.uicompat.UIConstants;
 
 public class NewTemplateVmModelBehavior extends 
VmModelBehaviorBase<UnitVmModel>
 {
+    private UIConstants constants = 
ConstantsManager.getInstance().getConstants();
+
     private final VM vm;
 
     public NewTemplateVmModelBehavior(VM vm)
@@ -190,17 +193,38 @@
     }
 
     private void postInitTemplate(List<VmTemplate> templates) {
-        List<VmTemplate> baseTemplates = keepBaseTemplates(templates);
+        List<VmTemplate> baseWithoutBlank = 
filterOutBlank(keepBaseTemplates(templates));
+
+        if (baseWithoutBlank.isEmpty()) {
+            // it is not allowed to create sub-templates of Blank template
+            getModel().getIsSubTemplate().setEntity(false);
+            getModel().getIsSubTemplate().setIsChangeable(false,
+                    constants.someNonDefaultTemplateHasToExistFirst());
+            return;
+        }
+
+        getModel().getIsSubTemplate().setEntity(false);
+        getModel().getIsSubTemplate().setIsChangeable(true);
 
         VmTemplate currentTemplate = Linq.firstOrDefault(templates,
                 new Linq.TemplatePredicate(vm.getVmtGuid()));
 
-        getModel().getBaseTemplate().setItems(baseTemplates);
+        getModel().getBaseTemplate().setItems(baseWithoutBlank);
 
-        
getModel().getBaseTemplate().setSelectedItem(Linq.firstOrDefault(baseTemplates,
+        
getModel().getBaseTemplate().setSelectedItem(Linq.firstOrDefault(baseWithoutBlank,
                 new 
Linq.TemplatePredicate(currentTemplate.getBaseTemplateId())));
     }
 
+    private List<VmTemplate> filterOutBlank(List<VmTemplate> templates) {
+        final ArrayList<VmTemplate> result = new ArrayList<>();
+        for (VmTemplate template : templates) {
+            if (!template.isBlank()) {
+                result.add(template);
+            }
+        }
+        return result;
+    }
+
     @Override
     public void dataCenterWithClusterSelectedItemChanged()
     {
diff --git 
a/frontend/webadmin/modules/uicompat/src/main/java/org/ovirt/engine/ui/uicompat/UIConstants.java
 
b/frontend/webadmin/modules/uicompat/src/main/java/org/ovirt/engine/ui/uicompat/UIConstants.java
index 8c3d0e8..692642b 100644
--- 
a/frontend/webadmin/modules/uicompat/src/main/java/org/ovirt/engine/ui/uicompat/UIConstants.java
+++ 
b/frontend/webadmin/modules/uicompat/src/main/java/org/ovirt/engine/ui/uicompat/UIConstants.java
@@ -2712,4 +2712,7 @@
 
     @DefaultStringValue("Icon file is not parsable.")
     String iconIsNotParsable();
+
+    @DefaultStringValue("Some non-default base template has to exist first.")
+    String someNonDefaultTemplateHasToExistFirst();
 }
diff --git 
a/frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
 
b/frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
index 287a01b..af0feb7 100644
--- 
a/frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
+++ 
b/frontend/webadmin/modules/userportal-gwtp/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
@@ -1115,3 +1115,5 @@
 PROVIDED_VM_ICON_HAS_INVALID_DIMENSIONS=Vm icon has invalid dimensions 
(${currentDimensions}). Allowed dimmension: ${allowedDimensions}
 DATA_SIZE_OF_PROVIDED_VM_ICON_TOO_LARGE=Data size of provided icon 
(${$currentSize}) is to big. Maximum allowd is ${$maxSize}
 VM_ICON_BASE64_PART_MALFORMED=Base64 part of vm icon is malformed.
+
+BLANK_TEMPLATE_CANT_HAVE_SUBTEMPLATES=Blank template can't have sub-templates.
diff --git 
a/frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
 
b/frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
index f0a658f..ad4d73d 100644
--- 
a/frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
+++ 
b/frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
@@ -1374,3 +1374,5 @@
 PROVIDED_VM_ICON_HAS_INVALID_DIMENSIONS=Vm icon has invalid dimensions 
(${currentDimensions}). Allowed dimmension: ${allowedDimensions}
 DATA_SIZE_OF_PROVIDED_VM_ICON_TOO_LARGE=Data size of provided icon 
(${$currentSize}) is to big. Maximum allowd is ${$maxSize}
 VM_ICON_BASE64_PART_MALFORMED=Base64 part of vm icon is malformed.
+
+BLANK_TEMPLATE_CANT_HAVE_SUBTEMPLATES=Blank template can't have sub-templates.


-- 
To view, visit https://gerrit.ovirt.org/40500
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I6b35a0f1b79a22ad25a26bb57acf5f5c68cf79c6
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Jakub Niedermertl <jnied...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to