Skip to content

Commit

Permalink
hide button without permission
Browse files Browse the repository at this point in the history
  • Loading branch information
elias-boulharts committed Sep 18, 2023
1 parent 88e96ec commit 0fb5068
Show file tree
Hide file tree
Showing 19 changed files with 141 additions and 133 deletions.
6 changes: 3 additions & 3 deletions templates/generics/buttons/add_button.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{% with perm=django_content_type.app_label|add:".add_"|add:django_content_type.model %}
{% has_perm request.user perm as can_add %}
<span {% if not can_change %} title="Permission {{ perm }} needed" {% endif %}>
<a class="btn btn-success {% if not can_add %} disabled{% endif %}" href="{{ add_url }}">
{% if can_add %}
<a class="btn btn-success" href="{{ add_url }}">
<i class="fas fa-plus"></i> Add
</a>
</span>
{% endif %}
{% endwith %}
8 changes: 5 additions & 3 deletions templates/generics/buttons/bulk_delete_button.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{% has_perm request.user django_content_type.app_label|add:".delete_"|add:django_content_type.model as can_delete %}
<button class="btn btn-danger{% if not can_delete %} disabled{% endif %}" type="submit"{% if not can_delete %} disabled{% endif %}>
<i class="fas fa-trash"></i> Delete
</button>
{% if can_delete %}
<a class="btn btn-danger" type="submit">
<i class="fas fa-trash"></i> Delete
</a>
{% endif %}
12 changes: 6 additions & 6 deletions templates/generics/buttons/delete_button.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
{% with class=object|to_class_name|lower %}
{% with perm=app|add:".delete_"|add:class %}
{% has_perm request.user perm object as can_delete %}
<span {% if not can_change %} title="Permission {{ perm }} needed" {% endif %}>
<a href="{% url app|add:':'|add:class|add:'_delete' object.id %}"
class="btn btn-danger{% if not can_delete %} disabled{% endif %}">
<i class="fas fa-trash"></i>
</a>
</span>
{% if can_delete %}
<a href="{% url app|add:':'|add:class|add:'_delete' object.id %}"
class="btn btn-danger">
<i class="fas fa-trash"></i>
</a>
{% endif %}
{% endwith %}
{% endwith %}
{% endwith %}
6 changes: 3 additions & 3 deletions templates/generics/buttons/edit_button.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
{% with class=object|to_class_name|lower %}
{% with perm=app|add:".change_"|add:class %}
{% has_perm request.user perm object as can_change %}
<span {% if not can_change %} title="Permission {{ perm }} needed" {% endif %}>
{% if can_change %}
<a href="{% url app|add:':'|add:class|add:'_edit' object.id %}"
class="btn btn-primary{% if not can_change %} disabled{% endif %}">
class="btn btn-primary">
<i class="fas fa-pencil-alt"></i>
</a>
</span>
{% endif %}
{% endwith %}
{% endwith %}
{% endwith %}
31 changes: 14 additions & 17 deletions templates/generics/custom_columns/generic_delete.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,20 @@
{% with class=record|to_class_name|lower %}
{% with perm=app|add:".delete_"|add:class %}
{% has_perm request.user perm as can_delete %}
{% if parent_id %}
<span {% if not can_delete %} title="Permission {{ perm }} needed" {% endif %}>

<a href="{% url app|add:":"|add:class|add:"_delete" parent_id record.id %}"
class="btn btn-danger bg-sm{% if not can_delete %} disabled{% endif %}"
title="Delete">
<i class="fas fa-trash"></i>
</a>
</span>
{% else %}
<span {% if not can_delete %} title="Permission {{ perm }} needed" {% endif %}>
<a href="{% url app|add:":"|add:class|add:"_delete" record.id %}"
class="btn btn-danger bg-sm{% if not can_delete %} disabled{% endif %}"
title="Delete">
<i class="fas fa-trash"></i>
</a>
</span>
{% if can_delete %}
{% if parent_id %}
<a href="{% url app|add:":"|add:class|add:"_delete" parent_id record.id %}"
class="btn btn-danger bg-sm"
title="Delete">
<i class="fas fa-trash"></i>
</a>
{% else %}
<a href="{% url app|add:":"|add:class|add:"_delete" record.id %}"
class="btn btn-danger bg-sm"
title="Delete">
<i class="fas fa-trash"></i>
</a>
{% endif %}
{% endif %}
{% endwith %}
{% endwith %}
Expand Down
30 changes: 14 additions & 16 deletions templates/generics/custom_columns/generic_edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,21 @@
{% with class=record|to_class_name|lower %}
{% with perm=app|add:".change_"|add:class %}
{% has_perm request.user perm as can_change %}
{% if parent_id %}
<span {% if not can_change %} title="Permission {{ perm }} needed" {% endif %}>
{% if can_change %}
{% if parent_id %}

<a href="{% url app|add:":"|add:class|add:"_edit" parent_id record.id %}"
class="btn btn-primary bg-sm{% if not can_change %} disabled{% endif %}"
title="Edit">
<i class="fas fa-pencil-alt"></i>
</a>
</span>
{% else %}
<span {% if not can_change %} title="Permission {{ perm }} needed" {% endif %}>
<a href="{% url app|add:":"|add:class|add:"_edit" record.id %}"
class="btn btn-primary bg-sm{% if not can_change %} disabled{% endif %}"
title="Edit">
<i class="fas fa-pencil-alt"></i>
</a>
</span>
<a href="{% url app|add:":"|add:class|add:"_edit" parent_id record.id %}"
class="btn btn-primary bg-sm"
title="Edit">
<i class="fas fa-pencil-alt"></i>
</a>
{% else %}
<a href="{% url app|add:":"|add:class|add:"_edit" record.id %}"
class="btn btn-primary bg-sm"
title="Edit">
<i class="fas fa-pencil-alt"></i>
</a>
{% endif %}
{% endif %}
{% endwith %}
{% endwith %}
Expand Down
6 changes: 3 additions & 3 deletions templates/profiles/custom_columns/delete_all_user_roles.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{# can_delete_user come from {organization,team,globalpermission}_detail.html#}
{% with class_name=object|to_class_name|lower %}
<span {% if not can_delete_user %} title="Permission 'profiles.delete_role' needed" {% endif %}>
{% if can_delete_user %}
<a href="{% url "profiles:"|add:class_name|add:"_rbac_delete" object.id record.id %}"
class="btn btn-danger bg-sm{% if not can_delete_user %} disabled{% endif %}"
class="btn btn-danger bg-sm"
title="Delete">
<i class="fas fa-trash"></i>
</a>
</span>
{% endif %}
{% endwith %}
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
{% load static %}
{% block header_button %}
{% has_perm request.user "profiles.change_globalpermission" object as can_change_global_perm %}
<a href="{% url 'profiles:globalpermission_edit' %}"
class="btn btn-primary">
<i class="fas fa-pencil-alt {% if not can_change_global_perm %} disabled{% endif %}"></i>
</a>
{% if can_change_global_perm %}
<a href="{% url 'profiles:globalpermission_edit' %}"
class="btn btn-primary">
<i class="fas fa-pencil-alt"></i>
</a>
{% endif %}
{% endblock %}

{% block main %}
Expand Down
8 changes: 5 additions & 3 deletions templates/profiles/globalpermission_rbac_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
{% load static %}
{% block extra_header_button %}
{% has_perm request.user "profiles.add_users_globalpermission" object as can_add_users %}
<a href="{% url 'profiles:globalpermission_rbac_create' object.id %}"
class="btn btn-success{% if not can_add_users %} disabled{% endif %}"><i class="fas fa-user-plus"></i> Add Global RBAC
</a>
{% if can_add_users %}
<a href="{% url 'profiles:globalpermission_rbac_create' object.id %}"
class="btn btn-success"><i class="fas fa-user-plus"></i> Add Global RBAC
</a>
{% endif %}
{% endblock %}

{% block main %}
Expand Down
19 changes: 10 additions & 9 deletions templates/profiles/organization_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,27 @@
{% has_perm request.user "profiles.add_users_organization" object as can_add_user_in_organization %}
{% has_perm request.user "profiles.add_team" object as can_add_team %}
{% has_perm request.user "profiles.change_organization_quota" object as can_change_quota %}
<span {% if not can_change_quota %}title="Permission profiles.change_quota needed"{% endif %}>
{% if can_change_quota %}
<a href="{% url 'profiles:organization_quota_edit' object.id %}"
class="btn btn-primary{% if not can_change_quota %} disabled{% endif %}">
class="btn btn-primary">
<i class="fas fa-chart-pie"></i> Set quotas
</a>
</span>
{% endif %}

<span {% if not can_add_user_in_organization %}title="Permission profiles.add_users_organization needed"{% endif %}>
{% if can_add_user_in_organization %}
<a href="{% url 'profiles:organization_rbac_create' object.id %}"
class="btn btn-success{% if not can_add_user_in_organization %} disabled{% endif %}">
class="btn btn-success">
<i class="fas fa-user-plus"></i> Add Organization RBAC
</a>
</span>
{% endif %}

<span {% if not can_add_team %}title="Permission profiles.add_team needed"{% endif %}>
{% if can_add_team %}
<a href="{% url 'profiles:team_create' %}?org={{ object.id }}"
class="btn btn-success{% if not can_add_team %} disabled{% endif %}">
class="btn btn-success">
<i class="fas fa-users"></i> Add team
</a>
</span>
{% endif %}

{% endblock %}

{% block header_button %}
Expand Down
22 changes: 11 additions & 11 deletions templates/profiles/team_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@
{% block extra_header_button %}
{% has_perm request.user "profiles.add_users_team" object as can_add_user %}
{% has_perm request.user "profiles.change_team_quota" object as can_change_quota %}
<span {% if not can_change_quota %} title="Permission profiles.change_quota needed" {% endif %}>
<a href="{% url 'profiles:team_quota_edit' object.id %}"
class="btn btn-primary{% if not can_change_quota %} disabled{% endif %}"> <i
class="fas fa-chart-pie"></i> Set quotas
</a>
</span>
<span {% if not can_add_user %} title="Permission profiles.add_users_team needed" {% endif %}>
<a href="{% url 'profiles:team_rbac_create' object.id %}"
class="btn btn-success{% if not can_add_user %} disabled{% endif %}"><i class="fas fa-user-plus"></i> Add Team RBAC
</a>
</span>
{% if can_change_quota %}
<a href="{% url 'profiles:team_quota_edit' object.id %}"
class="btn btn-primary"> <i
class="fas fa-chart-pie"></i> Set quotas
</a>
{% endif %}
{% if can_add_user %}
<a href="{% url 'profiles:team_rbac_create' object.id %}"
class="btn btn-success"><i class="fas fa-user-plus"></i> Add Team RBAC
</a>
{% endif %}
{% endblock %}
{% block header_button %}
{% include 'generics/buttons/edit_button.html' %}
Expand Down
12 changes: 6 additions & 6 deletions templates/service_catalog/buttons/delete_operation_button.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{% with perm="service_catalog.delete_operation" %}
{% has_perm request.user perm object as can_delete %}
<span {% if not can_change %} title="Permission {{ perm }} needed" {% endif %}>
<a href="{% url 'service_catalog:operation_delete' object.service.id object.id %}"
class="btn btn-danger{% if not can_delete %} disabled{% endif %}">
<i class="fas fa-trash"></i>
</a>
</span>
{% if can_delete %}
<a href="{% url 'service_catalog:operation_delete' object.service.id object.id %}"
class="btn btn-danger">
<i class="fas fa-trash"></i>
</a>
{% endif %}
{% endwith %}
12 changes: 6 additions & 6 deletions templates/service_catalog/buttons/edit_operation_button.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{% with perm="service_catalog.change_operation" %}
{% has_perm request.user perm object as can_change %}
<span {% if not can_change %} title="Permission {{ perm }} needed" {% endif %}>
<a href="{% url 'service_catalog:operation_edit' object.service.id object.id %}"
class="btn btn-primary{% if not can_change %} disabled{% endif %}">
<i class="fas fa-pencil-alt"></i>
</a>
</span>
{% if can_change %}
<a href="{% url 'service_catalog:operation_edit' object.service.id object.id %}"
class="btn btn-primary">
<i class="fas fa-pencil-alt"></i>
</a>
{% endif %}
{% endwith %}
22 changes: 12 additions & 10 deletions templates/service_catalog/buttons/instance_buttons.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,16 @@
</a>
{% endif %}
{% endwith %}
{% if object.service.external_support_url is not None and object.service.external_support_url != '' %}
<a class="btn btn-success {% if not can_add_support %}disabled{% endif %}"
href="{% url 'service_catalog:support_create' object.id %}">
<i class="fas fa-link"></i> Open new support
</a>
{% else %}
<a class="btn btn-success {% if not can_add_support %}disabled{% endif %}"
href="{% url 'service_catalog:support_create' object.id %}">
<i class="fas fa-plus"></i> Open new support
</a>
{% if can_add_support %}
{% if object.service.external_support_url is not None and object.service.external_support_url != '' %}
<a class="btn btn-success"
href="{% url 'service_catalog:support_create' object.id %}">
<i class="fas fa-link"></i> Open new support
</a>
{% else %}
<a class="btn btn-success"
href="{% url 'service_catalog:support_create' object.id %}">
<i class="fas fa-plus"></i> Open new support
</a>
{% endif %}
{% endif %}
12 changes: 6 additions & 6 deletions templates/service_catalog/buttons/operation_survey_button.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% has_perm request.user "service_catalog.change_operation" as can_change %}
<span {% if not can_change %} title="Permission service_catalog.change_operation needed" {% endif %}>
<a href="{% url 'service_catalog:operation_edit_survey' service_id=object.service.id pk=object.id %}"
class="btn btn-default bg-sm {% if not can_change %} disabled {% endif %}">
<i class="fas fa-clipboard-list"></i> Survey
</a>
</span>
{% if can_change %}
<a href="{% url 'service_catalog:operation_edit_survey' service_id=object.service.id pk=object.id %}"
class="btn btn-default bg-sm">
<i class="fas fa-clipboard-list"></i> Survey
</a>
{% endif %}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
{% load static %}
{% block content %}
{% has_perm request.user "service_catalog.add_supportmessage" instance as can_comment_support %}
{% has_perm request.user "service_catalog.reopen_support" instance as can_reopen_support %}
{% has_perm request.user "service_catalog.close_support" instance as can_close_support %}
{% has_perm request.user "service_catalog.change_support" instance as can_change_support %}
<!-- Main content -->
Expand Down Expand Up @@ -69,15 +70,15 @@
</div>
</form>
{% endif %}
{% if support.get_state_display == "OPENED" %}
{% if support.get_state_display == "OPENED" and can_close_support %}
<a href="{% url 'service_catalog:support_close' instance_id=instance.id pk=support.id %}"
class="btn btn-danger{% if not can_close_support %} disabled{% endif %}">
class="btn btn-danger">
<i class="fas fa-times-circle"></i> Close
</a>
{% endif %}
{% if support.get_state_display == "CLOSED" %}
{% if support.get_state_display == "CLOSED" and can_reopen_support %}
<a href="{% url 'service_catalog:support_reopen' instance_id=instance.id pk=support.id %}"
class="btn btn-success{% if not can_change_support %} disabled{% endif %}">
class="btn btn-success">
<i class="fas fa-undo"></i> Re-open
</a>
{% endif %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
{% else %}
{% has_perm request.user "service_catalog.request_on_service" as can_request_operation %}
{% endif %}

<span {% if not can_request_operation %}title="Permission {% if record.is_admin_operation %}service_catalog.admin_request_on_service{% else %}service_catalog.request_on_service{% endif %} required"{% endif %}>
<a href="{% url 'service_catalog:request_service' service_id=service_id operation_id=record.id %}"
class="btn btn-info bg-sm {% if not can_request_operation %}disabled{% endif %}">
<i class="fas fa-shopping-cart"></i>
</a>
</span>
{% if can_request_operation %}
<a href="{% url 'service_catalog:request_service' service_id=service_id operation_id=record.id %}"
class="btn btn-info bg-sm">
<i class="fas fa-shopping-cart"></i>
</a>
{% endif %}
12 changes: 6 additions & 6 deletions templates/service_catalog/custom_columns/operation_actions.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{% has_perm request.user "service_catalog.change_operation" as can_change %}
<span {% if not can_change %} title="Permission service_catalog.change_operation needed" {% endif %}>
<a href="{% url 'service_catalog:operation_edit_survey' service_id=record.service.id pk=record.id %}"
class="btn btn-primary bg-sm {% if not can_change %} disabled {% endif %}">
<i class="fas fa-clipboard-list"></i>
</a>
</span>
{% if can_change %}
<a href="{% url 'service_catalog:operation_edit_survey' service_id=record.service.id pk=record.id %}"
class="btn btn-primary bg-sm">
<i class="fas fa-clipboard-list"></i>
</a>
{% endif %}
{% with parent_id=record.service.id %}
{% include 'generics/custom_columns/generic_actions.html' %}
{% endwith %}
Loading

0 comments on commit 0fb5068

Please sign in to comment.