Commit aef328d4 by Kálmán Viktor

Merge branch 'issue-231' into 'master'

Slider ACL fixes

Closes #231
Closes #236
parents 7f04eeaa aafa29bf
...@@ -450,8 +450,10 @@ class TemplateForm(forms.ModelForm): ...@@ -450,8 +450,10 @@ class TemplateForm(forms.ModelForm):
self.allowed_fields = () self.allowed_fields = ()
else: else:
self.allowed_fields = ( self.allowed_fields = (
'name', 'access_method', 'description', 'system', 'tags') 'name', 'access_method', 'description', 'system', 'tags',
if self.user.has_perm('vm.change_template_resources'): 'arch', 'lease')
if (self.user.has_perm('vm.change_template_resources')
or not self.instance.pk):
self.allowed_fields += tuple(set(self.fields.keys()) - self.allowed_fields += tuple(set(self.fields.keys()) -
set(['raw_data'])) set(['raw_data']))
if self.user.is_superuser: if self.user.is_superuser:
...@@ -1126,6 +1128,14 @@ class VmResourcesForm(forms.ModelForm): ...@@ -1126,6 +1128,14 @@ class VmResourcesForm(forms.ModelForm):
'class': "form-control input-tags cpu-priority-input", 'class': "form-control input-tags cpu-priority-input",
})) }))
def __init__(self, *args, **kwargs):
self.can_edit = kwargs.pop("can_edit", None)
super(VmResourcesForm, self).__init__(*args, **kwargs)
if not self.can_edit:
for name, field in self.fields.items():
field.widget.attrs['disabled'] = "disabled"
class Meta: class Meta:
model = Instance model = Instance
fields = ('num_cores', 'priority', 'ram_size', ) fields = ('num_cores', 'priority', 'ram_size', )
...@@ -489,6 +489,10 @@ function addSliderMiscs() { ...@@ -489,6 +489,10 @@ function addSliderMiscs() {
}); });
$(".cpu-priority-input").trigger("change"); $(".cpu-priority-input").trigger("change");
$(".cpu-count-input, .ram-input").trigger("input"); $(".cpu-count-input, .ram-input").trigger("input");
$(".cpu-priority-slider").simpleSlider("setDisabled", $(".cpu-priority-input").prop("disabled"));
$(".cpu-count-slider").simpleSlider("setDisabled", $(".cpu-count-input").prop("disabled"));
$(".ram-slider").simpleSlider("setDisabled", $(".ram-input").prop("disabled"));
} }
......
...@@ -80,7 +80,7 @@ var __slice = [].slice, ...@@ -80,7 +80,7 @@ var __slice = [].slice,
}); });
} }
this.dragger.mousedown(function(e) { this.dragger.mousedown(function(e) {
if (e.which !== 1) { if (e.which !== 1 || _this.settings.disabled) {
return; return;
} }
_this.dragging = true; _this.dragging = true;
...@@ -170,6 +170,9 @@ var __slice = [].slice, ...@@ -170,6 +170,9 @@ var __slice = [].slice,
if (this.input.data("slider-showscale") != null) { if (this.input.data("slider-showscale") != null) {
options.showScale = this.input.data("slider-showscale"); options.showScale = this.input.data("slider-showscale");
} }
if (this.input.data("slider-disabled")) {
options.disabled = this.input.data("slider-disabled");
}
return options; return options;
} }
...@@ -207,8 +210,12 @@ var __slice = [].slice, ...@@ -207,8 +210,12 @@ var __slice = [].slice,
return this.valueChanged(value, ratio, "setValue"); return this.valueChanged(value, ratio, "setValue");
}; };
SimpleSlider.prototype.setDisabled = function(value) {
this.settings.disabled = value;
}
SimpleSlider.prototype.trackEvent = function(e) { SimpleSlider.prototype.trackEvent = function(e) {
if (e.which !== 1) { if (e.which !== 1 || this.settings.disabled) {
return; return;
} }
this.domDrag(e.pageX, e.pageY, true); this.domDrag(e.pageX, e.pageY, true);
...@@ -374,7 +381,7 @@ var __slice = [].slice, ...@@ -374,7 +381,7 @@ var __slice = [].slice,
simpleSlider: function() { simpleSlider: function() {
var params, publicMethods, settingsOrMethod; var params, publicMethods, settingsOrMethod;
settingsOrMethod = arguments[0], params = 2 <= arguments.length ? __slice.call(arguments, 1) : []; settingsOrMethod = arguments[0], params = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
publicMethods = ["setRatio", "setValue"]; publicMethods = ["setRatio", "setValue", "setDisabled", ];
return $(this).each(function() { return $(this).each(function() {
var obj, settings; var obj, settings;
if (settingsOrMethod && __indexOf.call(publicMethods, settingsOrMethod) >= 0) { if (settingsOrMethod && __indexOf.call(publicMethods, settingsOrMethod) >= 0) {
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
{% csrf_token %} {% csrf_token %}
{% include "dashboard/_resources-sliders.html" with field_priority=resources_form.priority field_num_cores=resources_form.num_cores field_ram_size=resources_form.ram_size %} {% include "dashboard/_resources-sliders.html" with field_priority=resources_form.priority field_num_cores=resources_form.num_cores field_ram_size=resources_form.ram_size %}
{% if can_change_resources %} {% if op.resources_change %}
<button type="submit" class="btn btn-success btn-sm change-resources-button" <button type="submit" class="btn btn-success btn-sm change-resources-button"
id="vm-details-resources-save" data-vm="{{ instance.pk }}" id="vm-details-resources-save" data-vm="{{ instance.pk }}"
{% if op.resources_change.disabled %}disabled{% endif %}> {% if op.resources_change.disabled %}disabled{% endif %}>
......
...@@ -295,7 +295,8 @@ class VmDetailView(CheckedDetailView): ...@@ -295,7 +295,8 @@ class VmDetailView(CheckedDetailView):
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super(VmDetailView, self).get_context_data(**kwargs) context = super(VmDetailView, self).get_context_data(**kwargs)
instance = context['instance'] instance = context['instance']
ops = get_operations(instance, self.request.user) user = self.request.user
ops = get_operations(instance, user)
context.update({ context.update({
'graphite_enabled': settings.GRAPHITE_URL is not None, 'graphite_enabled': settings.GRAPHITE_URL is not None,
'vnc_url': reverse_lazy("dashboard.views.detail-vnc", 'vnc_url': reverse_lazy("dashboard.views.detail-vnc",
...@@ -305,7 +306,7 @@ class VmDetailView(CheckedDetailView): ...@@ -305,7 +306,7 @@ class VmDetailView(CheckedDetailView):
}) })
# activity data # activity data
activities = instance.get_merged_activities(self.request.user) activities = instance.get_merged_activities(user)
show_show_all = len(activities) > 10 show_show_all = len(activities) > 10
activities = activities[:10] activities = activities[:10]
context['activities'] = activities context['activities'] = activities
...@@ -331,7 +332,11 @@ class VmDetailView(CheckedDetailView): ...@@ -331,7 +332,11 @@ class VmDetailView(CheckedDetailView):
context['ipv6_port'] = instance.get_connect_port(use_ipv6=True) context['ipv6_port'] = instance.get_connect_port(use_ipv6=True)
# resources forms # resources forms
context['resources_form'] = VmResourcesForm(instance=instance) can_edit = (
instance in Instance.get_objects_with_level("owner", user)
and self.request.user.has_perm("vm.change_resources"))
context['resources_form'] = VmResourcesForm(
can_edit=can_edit, instance=instance)
if self.request.user.is_superuser: if self.request.user.is_superuser:
context['traits_form'] = TraitsForm(instance=instance) context['traits_form'] = TraitsForm(instance=instance)
...@@ -1375,7 +1380,7 @@ class TemplateCreate(SuccessMessageMixin, CreateView): ...@@ -1375,7 +1380,7 @@ class TemplateCreate(SuccessMessageMixin, CreateView):
def get_context_data(self, *args, **kwargs): def get_context_data(self, *args, **kwargs):
context = super(TemplateCreate, self).get_context_data(*args, **kwargs) context = super(TemplateCreate, self).get_context_data(*args, **kwargs)
num_leases = Lease.get_objects_with_level("user", num_leases = Lease.get_objects_with_level("operator",
self.request.user).count() self.request.user).count()
can_create_leases = self.request.user.has_perm("create_leases") can_create_leases = self.request.user.has_perm("create_leases")
context.update({ context.update({
......
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