Skip to content

Commit

Permalink
Merge pull request #519 from oakdbca/main
Browse files Browse the repository at this point in the history
Bug fixes and tweaks
  • Loading branch information
xzzy authored Aug 27, 2024
2 parents fcd548d + df4c0b2 commit fb10a7c
Show file tree
Hide file tree
Showing 30 changed files with 138 additions and 223 deletions.
43 changes: 26 additions & 17 deletions boranga/components/species_and_communities/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1220,7 +1220,7 @@ class Community(RevisionedMixin):
RELATED_ITEM_CHOICES = [("conservation_status", "Conservation Status")]

community_number = models.CharField(max_length=9, blank=True, default="")
renamed_from = models.OneToOneField(
renamed_from = models.ForeignKey(
"self",
on_delete=models.PROTECT,
null=True,
Expand Down Expand Up @@ -1509,23 +1509,20 @@ def get_related_items(self, filter_type, **kwargs):
)
)
# Add renamed to related items to the list (limited to one degree of separation)
if (
a_field.name == "renamed_to"
and hasattr(self, "renamed_to")
and self.renamed_to
):
if filter_type == "for_occurrence":
return_list.extend(
self.renamed_to.get_related_items(
"conservation_status_and_occurrences"
if self.renamed_to.exists():
for community in self.renamed_to.all():
if filter_type == "for_occurrence":
return_list.extend(
community.get_related_items(
"conservation_status_and_occurrences"
)
)
)
else:
return_list.extend(
self.renamed_to.get_related_items(
"all_except_renamed_community"
else:
return_list.extend(
community.get_related_items(
"all_except_renamed_community"
)
)
)

return return_list

Expand Down Expand Up @@ -1807,10 +1804,22 @@ def copy_for_rename(self, request):
new_community = Community.objects.get(pk=self.pk)
new_community.pk = None
new_community.community_number = ""
new_community.processing_status = Community.PROCESSING_STATUS_DRAFT
new_community.processing_status = Community.PROCESSING_STATUS_ACTIVE
new_community.renamed_from_id = self.id
new_community.save(version_user=request.user)

# Copy the community publishing status but set it to private (not public)
try:
publishing_status = CommunityPublishingStatus.objects.get(
id=self.community_publishing_status.id
)
publishing_status.pk = None
publishing_status.community = new_community
publishing_status.community_public = False
publishing_status.save()
except CommunityPublishingStatus.DoesNotExist:
CommunityPublishingStatus.objects.get_or_create(community=self)

new_community.regions.add(*self.regions.all())
new_community.districts.add(*self.districts.all())

Expand Down
8 changes: 8 additions & 0 deletions boranga/components/species_and_communities/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1278,6 +1278,7 @@ class InternalCommunitySerializer(BaseCommunitySerializer):
user_edit_mode = serializers.SerializerMethodField()
can_user_edit = serializers.SerializerMethodField()
can_add_log = serializers.SerializerMethodField()
can_user_reopen = serializers.SerializerMethodField()
renamed_from = SimpleCommunityDisplaySerializer(read_only=True, allow_null=True)
readonly = serializers.SerializerMethodField(read_only=True)

Expand All @@ -1302,6 +1303,7 @@ class Meta:
"readonly",
"can_user_edit",
"can_user_view",
"can_user_reopen",
"current_assessor",
"user_edit_mode",
"comment",
Expand Down Expand Up @@ -1346,6 +1348,12 @@ def get_can_user_edit(self, obj):
return obj.can_user_edit
return False

def get_can_user_reopen(self, obj):
request = self.context["request"]
if is_species_communities_approver(request):
return obj.can_user_reopen(request)
return False

def get_current_assessor(self, obj):
return {
"id": self.context["request"].user.id,
Expand Down
16 changes: 15 additions & 1 deletion boranga/components/users/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
SubmitterInformation,
)
from boranga.helpers import (
is_conservation_status_approver,
is_conservation_status_assessor,
is_contributor,
is_internal,
is_occurrence_approver,
Expand Down Expand Up @@ -265,6 +267,18 @@ def to_representation(self, instance):
if instance.email_user == request.user.id and is_contributor(request):
return ret

if not is_occurrence_assessor(request) and not is_occurrence_approver(request):
if (
hasattr(instance, "occurrence_report")
and (
not is_occurrence_assessor(request)
and not is_occurrence_approver(request)
)
or hasattr(instance, "conservation_status")
and (
not is_conservation_status_assessor(request)
and not is_conservation_status_approver(request)
)
):
ret.pop("contact_details")

return ret
16 changes: 13 additions & 3 deletions boranga/components/users/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,20 @@ def add_external_user_to_external_contributors_group(sender, user, request, **kw
"user_logged_in_signal running add_external_user_to_external_contributors_group function"
)

external_contributor_group = SystemGroup.objects.get(
name=settings.GROUP_NAME_EXTERNAL_CONTRIBUTOR
)

# Only add external users to the external contributors group
if is_internal(request):
# Check if the internal user is in the external contributors group and remove them if so
if SystemGroupPermission.objects.filter(
system_group=external_contributor_group, emailuser=user
).exists():
SystemGroupPermission.objects.filter(
system_group=external_contributor_group, emailuser=user
).delete()
external_contributor_group.save()
return

# If user is blacklisted, don't add them to the external contributors group
Expand All @@ -125,9 +137,7 @@ def add_external_user_to_external_contributors_group(sender, user, request, **kw
return

# If user is already in the external contributors group, don't add them again
external_contributor_group = SystemGroup.objects.get(
name=settings.GROUP_NAME_EXTERNAL_CONTRIBUTOR
)

if SystemGroupPermission.objects.filter(
system_group=external_contributor_group, emailuser=user
).exists():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -944,19 +944,6 @@ export default {
helpers.enablePopovers();
});
},
initialiseSearch: function () {
this.submitterSearch();
},
submitterSearch: function () {
let vm = this;
vm.$refs.communities_datatable.table.dataTableExt.afnFiltering.push(
function (settings, data, dataIndex, original) {
let filtered_submitter = vm.filterProposalSubmitter;
if (filtered_submitter == 'All') { return true; }
return filtered_submitter == original.submitter.email;
}
);
},
exportData: function (format) {
let vm = this;
const columns_new = {
Expand Down Expand Up @@ -1153,7 +1140,6 @@ export default {
this.$nextTick(() => {
vm.initialiseCommunityNameLookup();
vm.initialiseCommunityIdLookup();
vm.initialiseSearch();
vm.addEventListeners();
// -- to set the select2 field with the session value if exists onload()
if (sessionStorage.getItem("filterCommunityName") != 'all' && sessionStorage.getItem("filterCommunityName") != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
<label for="" class="col-sm-4 control-label fw-bold">Community Name <span
class="text-danger">*</span></label>
<div class="col-sm-8" :id="select_community_name">
<select :disabled="conservation_status_obj.readonly" :id="community_name_lookup"
<select :disabled="conservation_status_obj.readonly || 'Unlocked' == conservation_status_obj.processing_status" :id="community_name_lookup"
:name="community_name_lookup" :ref="community_name_lookup" class="form-control" />
</div>
</div>
Expand All @@ -76,14 +76,14 @@
<label for="change_code" class="col-sm-4 col-form-label fw-bold">Change Type <span
class="text-danger">*</span></label>
<div class="col-sm-8">
<template v-if="!isReadOnly">
<template v-if="!isReadOnly && 'Unlocked' != conservation_status_obj.processing_status">
<template
v-if="change_codes && change_codes.length > 0 && conservation_status_obj.change_code_id && !change_codes.map((d) => d.id).includes(conservation_status_obj.change_code_id)">
<input type="text" v-if="conservation_status_obj.change_code"
class="form-control mb-3"
:value="conservation_status_obj.change_code + ' (Now Archived)'" disabled />
<div class="mb-3 text-muted">
Change datum to:
Change change type to:
</div>
</template>
<select class="form-select" v-model="conservation_status_obj.change_code_id">
Expand All @@ -94,7 +94,7 @@
</select>
</template>
<template v-else>
<input class="form-control" type="text" :disabled="isReadOnly"
<input class="form-control" type="text" disabled
v-model="conservation_status_obj.change_code" />
</template>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
<label :for="scientific_name_lookup" class="col-sm-4 col-form-label fw-bold">Scientific Name: <span
class="text-danger">*</span></label>
<div class="col-sm-8" :id="select_scientific_name">
<select :disabled="isReadOnly" :id="scientific_name_lookup" :name="scientific_name_lookup"
<select :disabled="isReadOnly || 'Unlocked' == conservation_status_obj.processing_status" :id="scientific_name_lookup" :name="scientific_name_lookup"
:ref="scientific_name_lookup" class="form-control" />
</div>
</div>
Expand All @@ -84,14 +84,14 @@
<label for="change_code" class="col-sm-4 col-form-label fw-bold">Change Type <span
class="text-danger">*</span></label>
<div class="col-sm-8">
<template v-if="!isReadOnly">
<template v-if="!isReadOnly && 'Unlocked' != conservation_status_obj.processing_status">
<template
v-if="change_codes && change_codes.length > 0 && conservation_status_obj.change_code_id && !change_codes.map((d) => d.id).includes(conservation_status_obj.change_code_id)">
<input type="text" v-if="conservation_status_obj.change_code"
class="form-control mb-3"
:value="conservation_status_obj.change_code + ' (Now Archived)'" disabled />
<div class="mb-3 text-muted">
Change datum to:
Change change type to:
</div>
</template>
<select class="form-select" v-model="conservation_status_obj.change_code_id">
Expand All @@ -102,7 +102,7 @@
</select>
</template>
<template v-else>
<input class="form-control" type="text" :disabled="isReadOnly"
<input class="form-control" type="text" disabled
v-model="conservation_status_obj.change_code" />
</template>
</div>
Expand Down Expand Up @@ -614,7 +614,7 @@ export default {
) {
return true;
} else {
if (this.conservation_status_obj.processing_status == "Ready For Agenda") {
if (["Ready For Agenda", "Approved", "Closed", "DeListed", "Discarded"].includes(this.conservation_status_obj.processing_status)) {
return true;
}
if (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1275,19 +1275,6 @@ export default {
helpers.enablePopovers();
});
},
initialiseSearch: function () {
this.submitterSearch();
},
submitterSearch: function () {
let vm = this;
vm.$refs.cs_communities_datatable.table.dataTableExt.afnFiltering.push(
function (settings, data, dataIndex, original) {
let filtered_submitter = vm.filterProposalSubmitter;
if (filtered_submitter == 'All') { return true; }
return filtered_submitter == original.submitter.email;
}
);
},
exportData: function (format) {
let vm = this;
const columns_new = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1480,19 +1480,6 @@ export default {
helpers.enablePopovers();
});
},
initialiseSearch: function () {
this.submitterSearch();
},
submitterSearch: function () {
let vm = this;
vm.$refs.fauna_cs_datatable.table.dataTableExt.afnFiltering.push(
function (settings, data, dataIndex, original) {
let filtered_submitter = vm.filterProposalSubmitter;
if (filtered_submitter == 'All') { return true; }
return filtered_submitter == original.submitter.email;
}
);
},
exportData: function (format) {
let vm = this;
const columns_new = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1468,19 +1468,6 @@ export default {
helpers.enablePopovers();
});
},
initialiseSearch: function () {
this.submitterSearch();
},
submitterSearch: function () {
let vm = this;
vm.$refs.flora_cs_datatable.table.dataTableExt.afnFiltering.push(
function (settings, data, dataIndex, original) {
let filtered_submitter = vm.filterProposalSubmitter;
if (filtered_submitter == 'All') { return true; }
return filtered_submitter == original.submitter.email;
}
);
},
exportData: function (format) {
let vm = this;
const columns_new = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,10 @@ export async function queryLayerAtPoint(map_component, layer, coordinate) {
* @param {string=} subMode The submode to set the map to (e.g. draw: 'Polygon', 'Point')
*/
export function set_mode(mode, subMode = null) {
if (!this.map.getTargetElement()) {
console.warn('Map not initialized in set_mode function. Returning false.');
return false;
}
// Toggle map mode on/off when the new mode is the old one
if (this.mode == mode) {
if (this.subMode == subMode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -390,10 +390,8 @@ export default {
let vm = this;
this.$nextTick(() => {
vm.addEventListeners();
//vm.initialiseSearch();
});
},
}
</script>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -673,19 +673,6 @@ export default {
helpers.enablePopovers();
});
},
initialiseSearch: function () {
this.submitterSearch();
},
submitterSearch: function () {
let vm = this;
vm.$refs.community_occ_datatable.table.dataTableExt.afnFiltering.push(
function (settings, data, dataIndex, original) {
let filtered_submitter = vm.filterProposalSubmitter;
if (filtered_submitter == 'All') { return true; }
return filtered_submitter == original.submitter.email;
}
);
},
exportData: function (format) {
let vm = this;
const columns_new = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -667,19 +667,6 @@ export default {
helpers.enablePopovers();
});
},
initialiseSearch: function () {
this.submitterSearch();
},
submitterSearch: function () {
let vm = this;
vm.$refs.fauna_occ_datatable.table.dataTableExt.afnFiltering.push(
function (settings, data, dataIndex, original) {
let filtered_submitter = vm.filterProposalSubmitter;
if (filtered_submitter == 'All') { return true; }
return filtered_submitter == original.submitter.email;
}
);
},
exportData: function (format) {
let vm = this;
const columns_new = {
Expand Down
Loading

0 comments on commit fb10a7c

Please sign in to comment.