1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2024-12-25 07:35:22 +00:00

Add permission can view instances

This commit is contained in:
Info-IIG 2022-06-13 09:58:46 +02:00
parent 12f0c70069
commit c817d3e61a
4 changed files with 5 additions and 4 deletions

View file

@ -41,7 +41,7 @@ def console(request):
host = int(temptoken[0]) host = int(temptoken[0])
uuid = temptoken[1] uuid = temptoken[1]
if not request.user.is_superuser: if not request.user.is_superuser and not request.user.has_perm("instances.view_instances"):
try: try:
userInstance = UserInstance.objects.get( userInstance = UserInstance.objects.get(
instance__compute_id=host, instance__uuid=uuid, user__id=request.user.id instance__compute_id=host, instance__uuid=uuid, user__id=request.user.id

View file

@ -214,6 +214,7 @@ class PermissionSet(models.Model):
permissions = [ permissions = [
('clone_instances', 'Can clone instances'), ('clone_instances', 'Can clone instances'),
('passwordless_console', _('Can access console without password')), ('passwordless_console', _('Can access console without password')),
('view_instances', 'Can view instances'),
] ]
managed = False managed = False

View file

@ -25,7 +25,7 @@
{% endif %} {% endif %}
{% endfor %} {% endfor %}
<div class="col-lg-12"> <div class="col-lg-12">
{% if app_settings.VIEW_INSTANCES_LIST_STYLE == 'grouped' and request.user.is_superuser %} {% if app_settings.VIEW_INSTANCES_LIST_STYLE == 'grouped' and request.user.is_superuser or 'instances.view_instances' in perms %}
{% include 'allinstances_index_grouped.html' %} {% include 'allinstances_index_grouped.html' %}
{% else %} {% else %}
{% include 'allinstances_index_nongrouped.html' %} {% include 'allinstances_index_nongrouped.html' %}

View file

@ -46,7 +46,7 @@ def index(request):
for compute in computes: for compute in computes:
utils.refr(compute) utils.refr(compute)
if request.user.is_superuser: if request.user.is_superuser or request.user.has_perm("instances.view_instances"):
instances = Instance.objects.all().prefetch_related("userinstance_set") instances = Instance.objects.all().prefetch_related("userinstance_set")
else: else:
instances = Instance.objects.filter(userinstance__user=request.user).prefetch_related("userinstance_set") instances = Instance.objects.filter(userinstance__user=request.user).prefetch_related("userinstance_set")
@ -237,7 +237,7 @@ def get_instance(user, pk):
instance = get_object_or_404(Instance, pk=pk) instance = get_object_or_404(Instance, pk=pk)
user_instances = user.userinstance_set.all().values_list("instance", flat=True) user_instances = user.userinstance_set.all().values_list("instance", flat=True)
if user.is_superuser or instance.id in user_instances: if user.is_superuser or user.has_perm("instances.view_instances") or instance.id in user_instances:
return instance return instance
else: else:
raise Http404() raise Http404()