-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow document permissions to selected groups
- Loading branch information
1 parent
6e5d12f
commit b42dbd8
Showing
6 changed files
with
72 additions
and
22 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from wagtail.admin.forms import WagtailAdminModelForm | ||
|
||
from hypha.apply.users.groups import GROUPS_ORG_FACULTY | ||
from hypha.apply.users.models import Group | ||
|
||
|
||
class ContractDocumentCategoryAdminForm(WagtailAdminModelForm): | ||
def __init__(self, *args, **kwargs): | ||
super().__init__(*args, **kwargs) | ||
|
||
if not self.instance.pk: # New instance, not saved yet | ||
default_groups = Group.objects.filter(name__in=GROUPS_ORG_FACULTY) | ||
self.fields["document_access_view"].queryset = default_groups | ||
self.fields["document_access_view"].initial = default_groups.values_list( | ||
"pk", flat=True | ||
) | ||
self.initial["document_access_view"] = list( | ||
default_groups.values_list("pk", flat=True) | ||
) |
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
26 changes: 26 additions & 0 deletions
26
hypha/apply/projects/migrations/0089_auto_20240923_1154.py
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,26 @@ | ||
# Generated by Django 4.2.15 on 2024-09-23 11:54 | ||
|
||
from django.db import migrations | ||
from hypha.apply.users.groups import GROUPS_ORG_FACULTY | ||
|
||
|
||
def allow_internal_groups_to_contractdocumentcategory(apps, schema_editor): | ||
ContractDocumentCategory = apps.get_model( | ||
"application_projects", "ContractDocumentCategory" | ||
) | ||
Group = apps.get_model("auth", "Group") | ||
|
||
groups = Group.objects.filter(name__in=GROUPS_ORG_FACULTY) | ||
for category in ContractDocumentCategory.objects.all(): | ||
# Add the default groups to the document_access_view field | ||
category.document_access_view.add(*groups) | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("application_projects", "0088_contractdocumentcategory_document_access_view"), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(allow_internal_groups_to_contractdocumentcategory) | ||
] |
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