-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: django-guardian support (#152)
- Loading branch information
1 parent
9cb1be8
commit 69cc922
Showing
15 changed files
with
390 additions
and
8 deletions.
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
Empty file.
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,6 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class GuardianConfig(AppConfig): | ||
name = "unfold.contrib.guardian" | ||
label = "unfoldguardian" |
13 changes: 13 additions & 0 deletions
13
src/unfold/contrib/guardian/templates/admin/guardian/model/change_form.html
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,13 @@ | ||
{% extends "admin/change_form.html" %} | ||
|
||
{% load i18n admin_urls %} | ||
|
||
{% block object-tools-items %} | ||
{% url opts|admin_urlname:'permissions' original.pk|admin_urlquote as history_url %} | ||
|
||
<a href="{% add_preserved_filters history_url %}" class="permissionslink mx-1 px-3 py-2 rounded-md transition-all hover:bg-gray-100 hover:text-gray-700 dark:hover:bg-gray-700 dark:hover:text-gray-200"> | ||
{% trans "Object permissions" %} | ||
</a> | ||
|
||
{{ block.super }} | ||
{% endblock %} |
11 changes: 11 additions & 0 deletions
11
src/unfold/contrib/guardian/templates/admin/guardian/model/field.html
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 @@ | ||
{% load unfold %} | ||
|
||
{% if field.is_checkbox %} | ||
{{ field }} | ||
|
||
<label for="{{ field.auto_id }}" class="required vCheckboxLabel"> | ||
{{ field.label }} | ||
</label> | ||
{% else %} | ||
{% include "unfold/helpers/field.html" with field=field|add_css_class:form_classes.text_input %} | ||
{% endif %} |
35 changes: 35 additions & 0 deletions
35
src/unfold/contrib/guardian/templates/admin/guardian/model/obj_perms_manage.html
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 "admin/change_form.html" %} | ||
|
||
{% load admin_urls i18n guardian_tags %} | ||
|
||
{% block breadcrumbs %}{% if not is_popup %} | ||
<div class="px-4 lg:px-12"> | ||
<div class="container mb-6 mx-auto -my-3 lg:mb-12"> | ||
<ul class="flex"> | ||
{% url 'admin:index' as link %} | ||
{% trans 'Home' as name %} | ||
{% include 'unfold/helpers/breadcrumb_item.html' with link=link name=name %} | ||
|
||
{% url 'admin:app_list' app_label=opts.app_label as link %} | ||
{% include 'unfold/helpers/breadcrumb_item.html' with link=link name=opts.app_config.verbose_name %} | ||
|
||
{% url opts|admin_urlname:'changelist' as link %} | ||
{% include 'unfold/helpers/breadcrumb_item.html' with link=link name=opts.verbose_name_plural|capfirst %} | ||
|
||
{% url opts|admin_urlname:'change' object.pk|admin_urlquote as link %} | ||
{% include 'unfold/helpers/breadcrumb_item.html' with link=link name=original|truncatewords:'18' %} | ||
|
||
{% trans 'Object permissions' as name %} | ||
{% include 'unfold/helpers/breadcrumb_item.html' with link='' name=name %} | ||
</ul> | ||
</div> | ||
</div> | ||
{% endif %}{% endblock %} | ||
|
||
{% block content %} | ||
{% include "unfold/guardian/user_form.html" %} | ||
|
||
<hr class="my-12 dark:border-gray-800"/> | ||
|
||
{% include "unfold/guardian/group_form.html" %} | ||
{% endblock %} |
55 changes: 55 additions & 0 deletions
55
src/unfold/contrib/guardian/templates/admin/guardian/model/obj_perms_manage_group.html
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,55 @@ | ||
{% extends "admin/change_form.html" %} | ||
{% load admin_urls i18n %} | ||
|
||
{% block extrahead %}{{ block.super }} | ||
{{ form.media }} | ||
{% endblock %} | ||
|
||
{% block breadcrumbs %}{% if not is_popup %} | ||
<div class="px-4 lg:px-12"> | ||
<div class="container mb-6 mx-auto -my-3 lg:mb-12"> | ||
<ul class="flex"> | ||
{% url 'admin:index' as link %} | ||
{% trans 'Home' as name %} | ||
{% include 'unfold/helpers/breadcrumb_item.html' with link=link name=name %} | ||
|
||
{% url 'admin:app_list' app_label=opts.app_label as link %} | ||
{% include 'unfold/helpers/breadcrumb_item.html' with link=link name=opts.app_config.verbose_name %} | ||
|
||
{% url opts|admin_urlname:'changelist' as link %} | ||
{% include 'unfold/helpers/breadcrumb_item.html' with link=link name=opts.verbose_name_plural|capfirst %} | ||
|
||
{% url opts|admin_urlname:'change' object.pk|admin_urlquote as link %} | ||
{% include 'unfold/helpers/breadcrumb_item.html' with link=link name=original|truncatewords:'18' %} | ||
|
||
{% trans 'Object permissions' as name %} | ||
{% include 'unfold/helpers/breadcrumb_item.html' with link="../../" name=name %} | ||
|
||
{% include 'unfold/helpers/breadcrumb_item.html' with link='' name=group_obj|truncatewords:"18" %} | ||
</ul> | ||
</div> | ||
</div> | ||
{% endif %}{% endblock %} | ||
|
||
{% block content %} | ||
<div class="border border-gray-200 overflow-hidden rounded-md p-3 shadow-sm dark:border-gray-800"> | ||
<form method="post"> | ||
{% csrf_token %} | ||
|
||
{% trans "Object" as title %} | ||
{% include "unfold/helpers/field_readonly.html" with title=title value=object %} | ||
|
||
{% trans "Group" as title %} | ||
{% include "unfold/helpers/field_readonly.html" with title=title value=group_obj %} | ||
|
||
{% include "unfold/helpers/field.html" with field=form.permissions %} | ||
|
||
<div class="bg-gray-50 border-t flex flex-row -m-3 p-3 dark:bg-white/[.02] dark:border-gray-800"> | ||
<div class="ml-auto"> | ||
{% trans "Save" as title %} | ||
{% include "unfold/helpers/submit.html" with title=title %} | ||
</div> | ||
</div> | ||
</form> | ||
</div> | ||
{% endblock %} |
56 changes: 56 additions & 0 deletions
56
src/unfold/contrib/guardian/templates/admin/guardian/model/obj_perms_manage_user.html
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,56 @@ | ||
{% extends "admin/change_form.html" %} | ||
|
||
{% load admin_urls i18n %} | ||
|
||
{% block extrahead %}{{ block.super }} | ||
{{ form.media }} | ||
{% endblock %} | ||
|
||
{% block breadcrumbs %}{% if not is_popup %} | ||
<div class="px-4 lg:px-12"> | ||
<div class="container mb-6 mx-auto -my-3 lg:mb-12"> | ||
<ul class="flex"> | ||
{% url 'admin:index' as link %} | ||
{% trans 'Home' as name %} | ||
{% include 'unfold/helpers/breadcrumb_item.html' with link=link name=name %} | ||
|
||
{% url 'admin:app_list' app_label=opts.app_label as link %} | ||
{% include 'unfold/helpers/breadcrumb_item.html' with link=link name=opts.app_config.verbose_name %} | ||
|
||
{% url opts|admin_urlname:'changelist' as link %} | ||
{% include 'unfold/helpers/breadcrumb_item.html' with link=link name=opts.verbose_name_plural|capfirst %} | ||
|
||
{% url opts|admin_urlname:'change' object.pk|admin_urlquote as link %} | ||
{% include 'unfold/helpers/breadcrumb_item.html' with link=link name=original|truncatewords:'18' %} | ||
|
||
{% trans 'Object permissions' as name %} | ||
{% include 'unfold/helpers/breadcrumb_item.html' with link="../../" name=name %} | ||
|
||
{% include 'unfold/helpers/breadcrumb_item.html' with link='' name=user_obj|truncatewords:"18" %} | ||
</ul> | ||
</div> | ||
</div> | ||
{% endif %}{% endblock %} | ||
|
||
{% block content %} | ||
<div class="border border-gray-200 overflow-hidden rounded-md p-3 shadow-sm dark:border-gray-800"> | ||
<form method="post"> | ||
{% csrf_token %} | ||
|
||
{% trans "Object" as title %} | ||
{% include "unfold/helpers/field_readonly.html" with title=title value=object %} | ||
|
||
{% trans "User" as title %} | ||
{% include "unfold/helpers/field_readonly.html" with title=title value=user_obj %} | ||
|
||
{% include "unfold/helpers/field.html" with field=form.permissions %} | ||
|
||
<div class="bg-gray-50 border-t flex flex-row -m-3 p-3 dark:bg-white/[.02] dark:border-gray-800"> | ||
<div class="ml-auto"> | ||
{% trans "Save" as title %} | ||
{% include "unfold/helpers/submit.html" with title=title %} | ||
</div> | ||
</div> | ||
</form> | ||
</div> | ||
{% endblock %} |
72 changes: 72 additions & 0 deletions
72
src/unfold/contrib/guardian/templates/unfold/guardian/group_form.html
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,72 @@ | ||
{% load i18n %} | ||
|
||
<form method="post"> | ||
{% csrf_token %} | ||
|
||
<h2 class="font-medium mb-3 text-sm text-gray-700 dark:text-gray-200"> | ||
{% trans "Group permissions" %} | ||
</h2> | ||
|
||
{% if groups_perms.items %} | ||
<table id="group-permissions" class="border-gray-200 border-spacing-none border-separate mb-6 text-gray-700 w-full dark:text-gray-400 lg:border lg:rounded-md lg:shadow-sm lg:dark:border-gray-800"> | ||
<thead class="hidden lg:table-header-group"> | ||
<tr> | ||
<th class="align-middle font-medium px-3 py-2 text-left text-gray-400 text-sm"> | ||
{% trans "Group" %} | ||
</th> | ||
|
||
{% for perm in model_perms %} | ||
<th class="align-middle font-medium px-3 py-2 text-left text-gray-400 text-sm"> | ||
{{ perm.name }} | ||
</th> | ||
{% endfor %} | ||
|
||
<th class="align-middle font-medium px-3 py-2 text-right text-gray-400 text-sm"> | ||
{% trans "Action" %} | ||
</th> | ||
</tr> | ||
</thead> | ||
|
||
<tbody> | ||
{% for group, group_perms in groups_perms.items %} | ||
<tr class="block border mb-3 rounded-md shadow-sm lg:table-row lg:border-none lg:mb-0 lg:shadow-none dark:border-gray-800"> | ||
<th class="align-middle flex border-t border-gray-200 font-normal px-3 py-2 text-left text-sm before:flex before:capitalize before:content-[attr(data-label)] before:items-center before:mr-auto before:text-gray-500 first:border-t-0 dark:before:text-gray-400 lg:before:hidden lg:first:border-t lg:py-3 lg:table-cell dark:border-gray-800" data-label="{% trans "User" %}"> | ||
<span class="text-gray-700 dark:text-gray-200"> | ||
{{ group }} | ||
</span> | ||
</th> | ||
|
||
{% for perm in model_perms %} | ||
<td class="align-middle flex border-t border-gray-200 font-normal px-3 py-2 text-left text-sm before:flex before:capitalize before:content-[attr(data-label)] before:items-center before:mr-auto before:text-gray-500 first:border-t-0 dark:before:text-gray-400 lg:before:hidden lg:first:border-t lg:py-3 lg:table-cell dark:border-gray-800" data-label="{{ perm.name }}"> | ||
{% if perm.codename in group_perms %} | ||
{% include "unfold/helpers/boolean.html" with value=False %} | ||
{% else %} | ||
{% include "unfold/helpers/boolean.html" with value=True %} | ||
{% endif %} | ||
</td> | ||
{% endfor %} | ||
|
||
<td class="align-middle flex border-t border-gray-200 font-normal px-3 py-2 text-right text-sm before:flex before:capitalize before:content-[attr(data-label)] before:items-center before:mr-auto before:text-gray-500 first:border-t-0 dark:before:text-gray-400 lg:before:hidden lg:first:border-t lg:py-3 lg:table-cell dark:border-gray-800" data-label="{% trans "Action" %}"> | ||
<a href="group-manage/{{ group.id|safe }}/" class="hover:text-gray-700 dark:hover:text-white"> | ||
{% trans "Edit" %} | ||
</a> | ||
</td> | ||
</tr> | ||
{% endfor %} | ||
</tbody> | ||
</table> | ||
{% endif %} | ||
|
||
<div class="border border-gray-200 overflow-hidden rounded-md p-3 shadow-sm dark:border-gray-800"> | ||
{% for field in group_form %} | ||
{% include "admin/guardian/model/field.html" %} | ||
{% endfor %} | ||
|
||
<div class="bg-gray-50 border-t flex flex-row -m-3 p-3 dark:bg-white/[.02] dark:border-gray-800"> | ||
<div class="ml-auto"> | ||
{% trans "Manage group" as title %} | ||
{% include "unfold/helpers/submit.html" with title=title name="submit_manage_group" %} | ||
</div> | ||
</div> | ||
</div> | ||
</form> |
Oops, something went wrong.