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 %} -
-
- {% for error in form.non_field_errors %} -
- {{ error }} +
+
+ {% for error in form.non_field_errors %} +
+ {{ error }} +
+ {% endfor %}
- {% endfor %}
-
{% endif %}

- {% trans "Create Announcements." %} + {% trans "Create " %} {{form.verbose_name}}

-
diff --git a/base/templates/announcement/announcement_one.html b/base/templates/announcement/announcement_one.html index 784aa013a..6d328eaa6 100644 --- a/base/templates/announcement/announcement_one.html +++ b/base/templates/announcement/announcement_one.html @@ -8,7 +8,7 @@
- {% trans "Announcement." %} + {% trans "Announcement" %}
+

+ {% trans "Update" %} {{form.verbose_name}} +

+
-
-
{{ form.non_field_errors }}
- {% for field in form.visible_fields %} -
+{% load static i18n widget_tweaks %} + +
+
{{ form.non_field_errors }}
+ {% for field in form.visible_fields %} + {% if field.field.widget.input_type != "checkbox" %} +
- - {% if field.help_text != '' %} + + {% if field.help_text %} {% endif %}
- {% if field.field.widget.input_type == 'checkbox' %} -
{{ field|add_class:'oh-switch__checkbox' }}
- {% else %} - {{ field|add_class:'form-control' }} - {% endif %} + {{ field|add_class:"form-control" }} {{ field.errors }} + {% if field.name == "attachments" and field.field.widget.input_type == "file" and field.field.widget.attrs.multiple %} {% if form.instance.pk %}
{% for file in form.instance.attachments.all %} - - - + + @@ -41,9 +33,30 @@ {% endif %} {% endif %}
+ {% endif %} + {% endfor %} +
+ {% for field in form.visible_fields %} + {% if field.field.widget.input_type == "checkbox" %} +
+
+ + {% if field.help_text %} + + {% endif %} +
+
+ {{ field|add_class:"oh-switch__checkbox" }} +
+ {{ field.errors }} +
+ {% endif %} {% endfor %}
- {% for field in form.hidden_fields %} - {{ field }} + + {# hidden fields #} + {% for hidden in form.hidden_fields %} + {{ hidden }} {% endfor %}
diff --git a/base/templates/announcement/comment_view.html b/base/templates/announcement/comment_view.html index f56ff5b63..e6264ef4c 100644 --- a/base/templates/announcement/comment_view.html +++ b/base/templates/announcement/comment_view.html @@ -4,95 +4,97 @@ {% if messages %}
- {% for message in messages %} -
{{ message }}
- {% endfor %} + {% for message in messages %} +
{{ message }}
+ {% endfor %}
{% endif %} +
+ + + + {{announcement.title}}{% trans "'s comments" %} +
-
- - - - {{announcement.title}}{% trans "'s comments" %} -
- - {% csrf_token %}
- - -
+ + +
- + -{% if no_comments %} + {% if no_comments %}
- {% trans "There are no comments to show." %} - + {% trans "There are no comments to show." + %} +
-{% else %} + {% else %}
    - {% for comment in comments %} -
  1. + {% for comment in comments %} +
  2. + {{ comment.comment }} {% if perms.base.delete_announcementcomment or request.user == comment.created_by %} - {{ comment.comment }} - - - + + {% endif %} + - -
    - {% trans "By" %} -
    -
    - -
    - - {{ comment.employee_id }} - + +
    + {% trans "By" %} +
    +
    +
    -
    - -
    - {% trans "Date & Time" %} - - {% trans "on" %}  {{ comment.created_at|date:"F j, Y" }}   - {% trans "at" %}   {{ comment.created_at|time:"g:i A" }} + + {{ comment.employee_id }}
    - -
  3. +
- {% endfor %} - +
+ {% trans "Date & Time" %} + + {% trans "on" %}  {{ comment.created_at|date:"F j, Y" }} +   + {% trans "at" %}   {{ comment.created_at|time:"g:i A" }} + +
+ + + {% endfor %} + + + {% endif %} +{% else %} +
+ Page not found. 404. +
{% trans "Comments have been disabled for this announcement." %}
+
{% endif %} diff --git a/static/build/css/sweetalert2.min.css b/static/build/css/sweetalert2.min.css index e1e0084c7..632b32ee2 100644 --- a/static/build/css/sweetalert2.min.css +++ b/static/build/css/sweetalert2.min.css @@ -1556,4 +1556,4 @@ body.swal2-toast-shown .swal2-container.swal2-bottom-right { right: 0; bottom: 0; left: auto -} \ No newline at end of file +} diff --git a/static/images/ui/no_comments.png b/static/images/ui/no_comments.png new file mode 100644 index 000000000..b80168a6e Binary files /dev/null and b/static/images/ui/no_comments.png differ