Skip to content

Commit

Permalink
Merge
Browse files Browse the repository at this point in the history
  • Loading branch information
preranaandure committed Jul 25, 2024
2 parents 8e6c06e + 2f41459 commit b30a8c0
Show file tree
Hide file tree
Showing 67 changed files with 1,585 additions and 497 deletions.
3 changes: 2 additions & 1 deletion boranga/components/conservation_status/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1698,8 +1698,9 @@ def add_comms_log(self, request, *args, **kwargs):
comms = serializer.save()
for f in request.FILES:
document = comms.documents.create()
document.check_file(request.FILES[f])
document.name = str(request.FILES[f])
document._file = request.FILES[f]
document._file = request.FILES[f]
document.save()

return Response(serializer.data)
Expand Down
3 changes: 3 additions & 0 deletions boranga/components/conservation_status/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1379,6 +1379,7 @@ def final_approval(self, request, details):
name=str(proposal_approval_document),
)[0]

document.check_file(proposal_approval_document)
document.name = str(proposal_approval_document)
document._file = proposal_approval_document
document.save()
Expand Down Expand Up @@ -2035,6 +2036,7 @@ def add_documents(self, request, *args, **kwargs):
data = json.loads(request.data.get("data"))

for idx in range(data["num_files"]):
self.check_file(request.data.get("file-" + str(idx)))
_file = request.data.get("file-" + str(idx))
self._file = _file
self.name = _file.name
Expand Down Expand Up @@ -2499,6 +2501,7 @@ def add_documents(self, request):
document = self.cs_amendment_request_documents.create(
_file=_file, name=_file.name
)
document.check_file(request.data.get("file-" + str(idx)))
document.input_name = data["input_name"]
document.can_delete = True
document.save()
Expand Down
24 changes: 24 additions & 0 deletions boranga/components/main/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from django.contrib.gis import admin

from boranga.admin import DeleteProtectedModelAdmin
from boranga.components.main.models import UserSystemSettings, FileExtensionWhitelist, Document
from django.apps import apps
from django import forms

class UserSystemSettingsAdmin(admin.ModelAdmin):
list_display = ["user", "area_of_interest"]

class ModelForm(forms.ModelForm):
choices = (("all","all",),) + tuple(
map(lambda m: (m,m), filter(lambda m: Document in apps.get_app_config('boranga').models[m].__bases__, apps.get_app_config('boranga').models))
)

model = forms.ChoiceField(choices=choices)

class FileExtensionWhitelistAdmin(DeleteProtectedModelAdmin):
fields = ("name","model","compressed",)
list_display = ("name","model","compressed",)
form = ModelForm

admin.site.register(FileExtensionWhitelist, FileExtensionWhitelistAdmin)
admin.site.register(UserSystemSettings, UserSystemSettingsAdmin)
48 changes: 45 additions & 3 deletions boranga/components/main/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@
from django.conf import settings
from django.core.files.storage import FileSystemStorage
from django.db import models
from django.core.exceptions import ValidationError
from reversion.models import Version
from django.apps import apps
from django.core.cache import cache

from boranga.helpers import compressed_content_valid, file_extension_valid

private_storage = FileSystemStorage(
location=settings.BASE_DIR + "/private-media/", base_url="/private-media/"
Expand Down Expand Up @@ -108,6 +113,24 @@ class CommunicationsLogEntry(models.Model):
class Meta:
app_label = "boranga"

class FileExtensionWhitelist(models.Model):

name = models.CharField(
max_length=16
)
model = models.CharField(max_length=255, default="all")

compressed = models.BooleanField()

class Meta:
app_label = "boranga"
unique_together=("name","model")

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self._meta.get_field("model").choices = (("all","all",),) + tuple(
map(lambda m: (m,m), filter(lambda m: Document in apps.get_app_config('boranga').models[m].__bases__, apps.get_app_config('boranga').models))
)

class Document(RevisionedMixin):
name = models.CharField(
Expand Down Expand Up @@ -137,6 +160,25 @@ def filename(self):

def __str__(self):
return self.name or self.filename

def check_file(self,file):
#check if extension in whitelist
cache_key = settings.CACHE_KEY_FILE_EXTENSION_WHITELIST
whitelist = cache.get(cache_key)
if whitelist is None:
whitelist = FileExtensionWhitelist.objects.all()
cache.set(cache_key, whitelist, settings.CACHE_TIMEOUT_2_HOURS)

valid, compression = file_extension_valid(str(file), whitelist, self._meta.model_name)

if not valid:
raise ValidationError("File type/extension not supported")

if compression:
#supported compression check
valid = compressed_content_valid(file, whitelist, self._meta.model_name)
if not valid:
raise ValidationError("Unsupported type/extension in compressed file")


class GlobalSettings(models.Model):
Expand Down Expand Up @@ -198,10 +240,10 @@ def __str__(self):


class UserSystemSettings(models.Model):
# user = models.OneToOneField(EmailUser, related_name='system_settings', on_delete=models.CASCADE)
user = models.IntegerField(unique=True) # EmailUserRO
event_training_completed = models.BooleanField(default=False)
event_training_date = models.DateField(blank=True, null=True)
area_of_interest = models.ForeignKey(
"GroupType", on_delete=models.PROTECT, null=True, blank=True
)

class Meta:
app_label = "boranga"
Expand Down
5 changes: 3 additions & 2 deletions boranga/components/meetings/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,7 @@ def add_comms_log(self, request, *args, **kwargs):
# Save the files
for f in request.FILES:
document = comms.documents.create()
document.check_file(request.FILES[f])
document.name = str(request.FILES[f])
document._file = request.FILES[f]
document.save()
Expand Down Expand Up @@ -633,7 +634,7 @@ def update(self, request, *args, **kwargs):
)
serializer.is_valid(raise_exception=True)
serializer.save(no_revision=True)
instance.add_minutes_documents(request, version_user=request.user)
instance.add_documents(request, version_user=request.user)
instance.meeting.log_user_action(
MeetingUserAction.ACTION_UPDATE_MINUTE.format(
instance.minutes_number, instance.meeting.meeting_number
Expand All @@ -652,7 +653,7 @@ def create(self, request, *args, **kwargs):
serializer = SaveMinutesSerializer(data=json.loads(request.data.get("data")))
serializer.is_valid(raise_exception=True)
instance = serializer.save(no_revision=True)
instance.add_minutes_documents(request, version_user=request.user)
instance.add_documents(request, version_user=request.user)
instance.meeting.log_user_action(
MeetingUserAction.ACTION_ADD_MINUTE.format(
instance.minutes_number, instance.meeting.meeting_number
Expand Down
7 changes: 4 additions & 3 deletions boranga/components/meetings/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def __str__(self):
return str(self.room_name)


class Committee(models.Model):
class Committee(ArchivableModel):
name = models.CharField(max_length=328, blank=True, null=True)

class Meta:
Expand All @@ -63,7 +63,7 @@ def __str__(self):
return str(self.name)


class CommitteeMembers(models.Model):
class CommitteeMembers(ArchivableModel):
first_name = models.CharField(max_length=128, blank=True, null=True)
last_name = models.CharField(max_length=128, blank=True, null=True)
email = models.CharField(max_length=328, blank=True, null=True)
Expand Down Expand Up @@ -453,11 +453,12 @@ def save(self, *args, **kwargs):
super().save(*args, **kwargs)

@transaction.atomic
def add_minutes_documents(self, request, *args, **kwargs):
def add_documents(self, request, *args, **kwargs):
# save the files
data = json.loads(request.data.get("data"))

for idx in range(data["num_files"]):
self.check_file(request.data.get("file-" + str(idx)))
_file = request.data.get("file-" + str(idx))
self._file = _file
self.name = _file.name
Expand Down
4 changes: 4 additions & 0 deletions boranga/components/meetings/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ class MeetingSerializer(serializers.ModelSerializer):
location = serializers.CharField(
source="location.room_name", read_only=True, allow_null=True
)
committee = serializers.CharField(
source="committee.name", read_only=True, allow_null=True
)

class Meta:
model = Meeting
Expand All @@ -153,6 +156,7 @@ class Meta:
"start_date",
"end_date",
"location",
"committee",
"location_id",
"title",
"meeting_type",
Expand Down
43 changes: 32 additions & 11 deletions boranga/components/occurrence/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2076,6 +2076,7 @@ def add_comms_log(self, request, *args, **kwargs):
# Save the files
for f in request.FILES:
document = comms.documents.create()
document.check_file(request.FILES[f])
document.name = str(request.FILES[f])
document._file = request.FILES[f]
document.save()
Expand Down Expand Up @@ -2506,7 +2507,6 @@ def update(self, request, *args, **kwargs):
):
self.unlocked_back_to_assessor(instance.occurrence_report)

# TODO: Make sure this log action exists
instance.occurrence_report.log_user_action(
OccurrenceReportUserAction.ACTION_UPDATE_OBSERVER_DETAIL.format(
instance.observer_name,
Expand Down Expand Up @@ -4266,6 +4266,7 @@ def add_comms_log(self, request, *args, **kwargs):
# Save the files
for f in request.FILES:
document = comms.documents.create()
document.check_file(request.FILES[f])
document.name = str(request.FILES[f])
document._file = request.FILES[f]
document.save()
Expand Down Expand Up @@ -5758,12 +5759,20 @@ def occurrence_tenure_vesting_lookup(self, request, *args, **kwargs):
results = []
if search_term:
queryset = (
queryset.filter(vesting__label__icontains=search_term)
.values("vesting__id", "vesting__label")
queryset.annotate(
vesting_code_label=Concat(
"vesting__code", Value(" - "), "vesting__label"
)
)
.filter(vesting_code_label__icontains=search_term)
.values("vesting__id", "vesting__code", "vesting__label")
.distinct()[:10]
)
results = [
{"id": row["vesting__id"], "text": row["vesting__label"]}
{
"id": row["vesting__id"],
"text": f"{row['vesting__code']} - {row['vesting__label']}",
}
for row in queryset
]

Expand All @@ -5786,12 +5795,20 @@ def occurrence_tenure_purpose_lookup(self, request, *args, **kwargs):

if search_term:
queryset = (
queryset.filter(purpose__label__icontains=search_term)
.values("purpose__id", "purpose__label")
queryset.annotate(
purpose_code_label=Concat(
"purpose__code", Value(" - "), "purpose__label"
)
)
.filter(purpose_code_label__icontains=search_term)
.values("purpose__id", "purpose__code", "purpose__label")
.distinct()[:10]
)
results = [
{"id": row["purpose__id"], "text": row["purpose__label"]}
{
"id": row["purpose__id"],
"text": f"{row['purpose__code']} - {row['purpose__label']}",
}
for row in queryset
]

Expand Down Expand Up @@ -5845,12 +5862,16 @@ def create(self, request, *args, **kwargs):
detail=False,
)
def occurrence_tenure_list_of_values(self, request, *args, **kwargs):
purpose_list = list(OccurrenceTenurePurpose.objects.all().values("id", "label"))
vesting_list = list(OccurrenceTenureVesting.objects.all().values("id", "label"))
purposes = list(
OccurrenceTenurePurpose.objects.all().values("id", "code", "label")
)
vestings = list(
OccurrenceTenureVesting.objects.all().values("id", "code", "label")
)

res_json = {
"purpose_list": purpose_list,
"vesting_list": vesting_list,
"purposes": purposes,
"vestings": vestings,
}
res_json = json.dumps(res_json)
return HttpResponse(res_json, content_type="application/json")
Expand Down
11 changes: 8 additions & 3 deletions boranga/components/occurrence/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1202,7 +1202,7 @@ class OccurrenceReportUserAction(UserAction):
ACTION_DISCARD_PROPOSAL = "Discard occurrence report {}"
ACTION_REINSTATE_PROPOSAL = "Reinstate occurrence report {}"
ACTION_APPROVAL_LEVEL_DOCUMENT = "Assign Approval level document {}"

ACTION_UPDATE_OBSERVER_DETAIL = "Update Observer {} on occurrence report {}"
# Amendment
ACTION_ID_REQUEST_AMENDMENTS = "Request amendments"

Expand Down Expand Up @@ -1337,6 +1337,7 @@ def add_documents(self, request):
document = self.amendment_request_documents.create(
_file=_file, name=_file.name
)
document.check_file(request.data.get("file-" + str(idx)))
document.input_name = data["input_name"]
document.can_delete = True
document.save()
Expand Down Expand Up @@ -2929,6 +2930,7 @@ def add_documents(self, request, *args, **kwargs):
# documents_qs = self.filter(input_name='species_doc', visible=True)
# documents_qs.delete()
for idx in range(data["num_files"]):
self.check_file(request.data.get("file-" + str(idx)))
_file = request.data.get("file-" + str(idx))
self._file = _file
self.name = _file.name
Expand Down Expand Up @@ -3999,6 +4001,7 @@ def add_documents(self, request, *args, **kwargs):
# documents_qs = self.filter(input_name='species_doc', visible=True)
# documents_qs.delete()
for idx in range(data["num_files"]):
self.check_file(request.data.get("file-" + str(idx)))
_file = request.data.get("file-" + str(idx))
self._file = _file
self.name = _file.name
Expand Down Expand Up @@ -4700,26 +4703,28 @@ def full_name(self):

class OccurrenceTenurePurpose(models.Model):
label = models.CharField(max_length=100, blank=True, null=True)
code = models.CharField(max_length=20, blank=True, null=True)

class Meta:
app_label = "boranga"
verbose_name = "Occurrence Tenure Purpose"
verbose_name_plural = "Occurrence Tenure Purposes"

def __str__(self):
return self.name
return f"{self.code} - {self.label}"


class OccurrenceTenureVesting(models.Model):
label = models.CharField(max_length=100, blank=True, null=True)
code = models.CharField(max_length=20, blank=True, null=True)

class Meta:
app_label = "boranga"
verbose_name = "Occurrence Tenure Vesting"
verbose_name_plural = "Occurrence Tenure Vestings"

def __str__(self):
return self.name
return f"{self.code} - {self.label}"


def SET_NULL_AND_HISTORICAL(collector, field, sub_objs, using):
Expand Down
Loading

0 comments on commit b30a8c0

Please sign in to comment.