diff --git a/base/announcement.py b/base/announcement.py index 48fe65486..6df76eeed 100644 --- a/base/announcement.py +++ b/base/announcement.py @@ -318,14 +318,15 @@ def comment_view(request, anoun_id): """ This method is used to view all comments in the announcements """ + announcement = Announcement.objects.get(id=anoun_id) comments = AnnouncementComment.objects.filter(announcement_id=anoun_id).order_by( "-created_at" ) - announcement = Announcement.objects.get(id=anoun_id) - comments = filter_own_records(request, comments, "base.view_announcementcomment") - no_comments = False - if not comments.exists(): - no_comments = True + if not announcement.public_comments: + comments = filter_own_records( + request, comments, "base.view_announcementcomment" + ) + no_comments = not comments.exists() return render( request, diff --git a/base/forms.py b/base/forms.py index f66a7ef6b..a64c9cbb7 100644 --- a/base/forms.py +++ b/base/forms.py @@ -2390,6 +2390,9 @@ class AnnouncementForm(ModelForm): self.fields["attachments"] = MultipleFileField(label=_("Attachments")) self.fields["attachments"].required = False self.fields["description"].required = False + self.fields["disable_comments"].widget.attrs.update( + {"hx-on:click": "togglePublicComments()"} + ) def save(self, commit: bool = ...) -> Any: attachement = [] diff --git a/base/models.py b/base/models.py index 0b50b373f..4583285c5 100644 --- a/base/models.py +++ b/base/models.py @@ -1518,7 +1518,15 @@ class Announcement(HorillaModel): company_id = models.ManyToManyField( Company, blank=True, related_name="announcement", verbose_name=_("Company") ) - disable_comments = models.BooleanField(default=False) + disable_comments = models.BooleanField( + default=False, verbose_name=_("Disable Comments") + ) + public_comments = models.BooleanField( + default=True, + verbose_name=_("Show Comments to All"), + help_text=_("If enabled, all employees can view each other's comments."), + ) + filtered_employees = models.ManyToManyField( Employee, related_name="announcement_filtered_employees", editable=False ) @@ -1544,6 +1552,14 @@ class Announcement(HorillaModel): viewed_emp.append(i.user) return viewed_emp + def save(self, *args, **kwargs): + """ + if comments are disabled, force public comments to be false + """ + if self.disable_comments: + self.public_comments = False + super().save(*args, **kwargs) + def __str__(self): return self.title diff --git a/base/templates/announcement/announcement_form.html b/base/templates/announcement/announcement_form.html index 628966dcb..fd8d99bf7 100644 --- a/base/templates/announcement/announcement_form.html +++ b/base/templates/announcement/announcement_form.html @@ -1,25 +1,26 @@ {% load i18n %} {% if messages %} - - + + {% endif %} {% if form.errors %} -