-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
361 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
default_requester_permissions = [ | ||
'service_catalog.view_instance', | ||
'service_catalog.view_request', | ||
'service_catalog.view_support', | ||
'service_catalog.add_support', | ||
'service_catalog.view_supportmessage', | ||
'service_catalog.add_supportmessage', | ||
'service_catalog.view_requestmessage', | ||
'service_catalog.add_requestmessage', | ||
'service_catalog.request_on_instance' | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from Squest.utils.squest_model_form import SquestModelForm | ||
from profiles.models import RequesterPermission | ||
|
||
|
||
class RequesterPermissionForm(SquestModelForm): | ||
class Meta: | ||
model = RequesterPermission | ||
fields = ["default_permissions"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Generated by Django 3.2.13 on 2023-09-26 15:39 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('profiles', '0019_alter_quota_options'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='RequesterPermission', | ||
fields=[ | ||
('abstractscope_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='profiles.abstractscope')), | ||
('default_permissions', models.ManyToManyField(blank=True, help_text='Permissions assigned to the owner of Squest objects.', limit_choices_to={'content_type__app_label__in': ['service_catalog']}, to='profiles.Permission')), | ||
], | ||
options={ | ||
'default_permissions': ('add', 'change', 'delete', 'view', 'list'), | ||
}, | ||
bases=('profiles.abstractscope',), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
from django.contrib.auth.models import User | ||
from django.core.cache import cache | ||
from django.db.models import ManyToManyField | ||
from django.urls import reverse | ||
|
||
from profiles.models import AbstractScope | ||
from profiles.models.squest_permission import Permission | ||
|
||
|
||
class RequesterPermission(AbstractScope): | ||
class Meta: | ||
default_permissions = ('add', 'change', 'delete', 'view', 'list') | ||
|
||
default_permissions = ManyToManyField( | ||
Permission, | ||
blank=True, | ||
help_text="Permissions assigned to the owner of Squest objects.", | ||
limit_choices_to={"content_type__app_label__in": ["service_catalog"]} | ||
) | ||
|
||
def __str__(self): | ||
return self.name | ||
|
||
def save(self, *args, **kwargs): | ||
super(RequesterPermission, self).save(*args, **kwargs) | ||
self.set_cache() | ||
|
||
def set_cache(self): | ||
cache.set(self.__class__.__name__, self) | ||
|
||
def get_absolute_url(self): | ||
return reverse("profiles:requesterpermission_details") | ||
|
||
def delete(self, *args, **kwargs): | ||
pass | ||
|
||
@classmethod | ||
def load(cls): | ||
if cache.get(cls.__name__) is None: | ||
obj, created = RequesterPermission.objects.get_or_create(name="RequesterPermission") | ||
if not created: | ||
obj.set_cache() | ||
return obj | ||
return cache.get(cls.__name__) | ||
|
||
def get_potential_users(self): | ||
return User.objects.all() | ||
|
||
def get_scopes(self): | ||
return AbstractScope.objects.filter(id=self.id) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
from Squest.utils.squest_views import * | ||
from profiles.forms import RequesterPermissionForm | ||
from profiles.models import RequesterPermission | ||
from profiles.tables import PermissionTable | ||
|
||
|
||
class RequesterPermissionEditView(SquestUpdateView): | ||
model = RequesterPermission | ||
form_class = RequesterPermissionForm | ||
|
||
def get_object(self, queryset=None): | ||
return RequesterPermission.load() | ||
|
||
def get_success_url(self): | ||
return reverse_lazy('profiles:requesterpermission_details') | ||
|
||
def dispatch(self, request, *args, **kwargs): | ||
self.kwargs['pk'] = self.get_object().id | ||
kwargs['pk'] = self.kwargs.get('pk') | ||
return super().dispatch(request, *args, **kwargs) | ||
|
||
def get_context_data(self, **kwargs): | ||
context = super().get_context_data(**kwargs) | ||
context['breadcrumbs'] = [ | ||
{'text': 'Requester permissions', 'url': reverse_lazy('profiles:requesterpermission_details')}, | ||
{'text': f'Edit', 'url': ""}, | ||
] | ||
return context | ||
|
||
|
||
class RequesterPermissionDetailsView(SquestDetailView): | ||
model = RequesterPermission | ||
|
||
def get_object(self, queryset=None): | ||
return RequesterPermission.load() | ||
|
||
def dispatch(self, request, *args, **kwargs): | ||
self.kwargs['pk'] = self.get_object().id | ||
kwargs['pk'] = self.kwargs.get('pk') | ||
return super().dispatch(request, *args, **kwargs) | ||
|
||
def get_context_data(self, **kwargs): | ||
context = super().get_context_data(**kwargs) | ||
context['breadcrumbs'] = None | ||
context['title'] = "Requester Permission" | ||
permission_table = PermissionTable(self.object.default_permissions.all()) | ||
permission_table.exclude = ("actions",) | ||
context['default_permissions'] = permission_table | ||
return context |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
{% extends 'base.html' %} | ||
{% block title %} | ||
Default permissions | ||
{% endblock %} | ||
{% load render_table from django_tables2 %} | ||
{% load static %} | ||
{% block header_button %} | ||
{% has_perm request.user "profiles.change_requesterpermission" object as can_change_requester_perm %} | ||
{% if can_change_requester_perm %} | ||
<a href="{% url 'profiles:requesterpermission_edit' %}" | ||
class="btn btn-primary"> | ||
<i class="fas fa-pencil-alt"></i> | ||
</a> | ||
{% endif %} | ||
{% endblock %} | ||
|
||
{% block main %} | ||
<div class="container-fluid"> | ||
<div class="row"> | ||
<div class="col-12"> | ||
<div class="card"> | ||
<div class="card-body"> | ||
<div class="callout callout-info"> | ||
List of permissions granted to the requester of an Instance and all related Requests and Supports | ||
</div> | ||
{% render_table default_permissions %} | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
{% endblock %} | ||
{% block custom_script %} | ||
<script>add_tab_management();</script> | ||
{% endblock %} |
Oops, something went wrong.