diff --git a/com/static/bundled/com/components/moderation-alert-index.ts b/com/static/bundled/com/components/moderation-alert-index.ts new file mode 100644 index 00000000..ba933b63 --- /dev/null +++ b/com/static/bundled/com/components/moderation-alert-index.ts @@ -0,0 +1,39 @@ +import { exportToHtml } from "#core:utils/globals"; +import Alpine from "alpinejs"; +import { newsDeleteNews, newsModerateNews } from "#openapi"; + +// This will be used in jinja templates, +// so we cannot use real enums as those are purely an abstraction of Typescript +const AlertState = { + // biome-ignore lint/style/useNamingConvention: this feels more like an enum + PENDING: 1, + // biome-ignore lint/style/useNamingConvention: this feels more like an enum + MODERATED: 2, + // biome-ignore lint/style/useNamingConvention: this feels more like an enum + DELETED: 3, +}; +exportToHtml("AlertState", AlertState); + +document.addEventListener("alpine:init", () => { + Alpine.data("moderationAlert", (newsId: number) => ({ + state: AlertState.PENDING, + newsId: newsId as number, + loading: false, + + async moderateNews() { + this.loading = true; + // biome-ignore lint/style/useNamingConvention: api is snake case + await newsModerateNews({ path: { news_id: this.newsId } }); + this.state = AlertState.MODERATED; + this.loading = false; + }, + + async deleteNews() { + this.loading = true; + // biome-ignore lint/style/useNamingConvention: api is snake case + await newsDeleteNews({ path: { news_id: this.newsId } }); + this.state = AlertState.DELETED; + this.loading = false; + }, + })); +}); diff --git a/com/static/com/css/news-list.scss b/com/static/com/css/news-list.scss index b068fb45..0df403b4 100644 --- a/com/static/com/css/news-list.scss +++ b/com/static/com/css/news-list.scss @@ -171,7 +171,9 @@ } .news_event { - display: block; + display: flex; + flex-direction: column; + gap: .5em; padding: 1em; header { diff --git a/com/templates/com/macros.jinja b/com/templates/com/macros.jinja new file mode 100644 index 00000000..388267d2 --- /dev/null +++ b/com/templates/com/macros.jinja @@ -0,0 +1,73 @@ +{% macro news_moderation_alert(news, user, alpineState = None) %} + {# An alert to display on top of non moderated news, + with actions to either moderate or delete them. + + The current state of the alert is accessible through + the given `alpineState` variable. + This state is a `AlertState`, as defined in `moderation-alert-index.ts` + + Example : + ```jinja +
+ {{ news_moderation_alert(news, user, "state") }} +
+ ``` + + Args: + news: The `News` object to which this alert is related + user: The request.user + alpineState: An alpine variable name + + Warning: + If you use this macro, you must also include `moderation-alert-index.ts` + in your template. + #} +
+ + + +
+{% endmacro %} diff --git a/com/templates/com/news_detail.jinja b/com/templates/com/news_detail.jinja index 454eb2ef..d517ee72 100644 --- a/com/templates/com/news_detail.jinja +++ b/com/templates/com/news_detail.jinja @@ -1,5 +1,6 @@ {% extends "core/base.jinja" %} {% from 'core/macros.jinja' import user_profile_link, facebook_share, tweet, link_news_logo, gen_news_metatags %} +{% from "com/macros.jinja" import news_moderation_alert %} {% block title %} {% trans %}News{% endtrans %} - @@ -16,39 +17,49 @@ {% endblock %} +{% block additional_js %} + +{% endblock %} + {% block content %}

{% trans %}Back to news{% endtrans %}

-
- -

{{ news.title }}

-

- {{ date.start_date|localtime|date(DATETIME_FORMAT) }} - {{ date.start_date|localtime|time(DATETIME_FORMAT) }} - - {{ date.end_date|localtime|date(DATETIME_FORMAT) }} - {{ date.end_date|localtime|time(DATETIME_FORMAT) }} -

-
-
{{ news.summary|markdown }}
-
-
{{ news.content|markdown }}
- {{ facebook_share(news) }} - {{ tweet(news) }} -
-

{% trans %}Author: {% endtrans %}{{ user_profile_link(news.author) }}

- {% if news.moderator %} -

{% trans %}Moderator: {% endtrans %}{{ user_profile_link(news.moderator) }}

- {% elif user.is_com_admin %} -

{% trans %}Moderate{% endtrans %}

- {% endif %} - {% if user.can_edit(news) %} -

{% trans %}Edit (will be moderated again){% endtrans %}

- {% endif %} +
+ + {% if not news.is_moderated %} + {{ news_moderation_alert(news, user, "newsState") }} + {% endif %} +
-
+

{{ news.title }}

+

+ {{ date.start_date|localtime|date(DATETIME_FORMAT) }} + {{ date.start_date|localtime|time(DATETIME_FORMAT) }} - + {{ date.end_date|localtime|date(DATETIME_FORMAT) }} + {{ date.end_date|localtime|time(DATETIME_FORMAT) }} +

+
+
{{ news.summary|markdown }}
+
+
{{ news.content|markdown }}
+ {{ facebook_share(news) }} + {{ tweet(news) }} +
+

{% trans %}Author: {% endtrans %}{{ user_profile_link(news.author) }}

+ {% if news.moderator %} +

{% trans %}Moderator: {% endtrans %}{{ user_profile_link(news.moderator) }}

+ {% elif user.is_com_admin %} +

{% trans %}Moderate{% endtrans %}

+ {% endif %} + {% if user.can_edit(news) %} +

{% trans %}Edit (will be moderated again){% endtrans %}

+ {% endif %} +
+
+ + {% endblock %} diff --git a/com/templates/com/news_list.jinja b/com/templates/com/news_list.jinja index 560eb569..80b07176 100644 --- a/com/templates/com/news_list.jinja +++ b/com/templates/com/news_list.jinja @@ -1,4 +1,5 @@ {% extends "core/base.jinja" %} +{% from "com/macros.jinja" import news_moderation_alert %} {% block title %} {% trans %}News{% endtrans %} @@ -14,6 +15,7 @@ {% block additional_js %} + {% endblock %} {% block content %} @@ -46,32 +48,39 @@
{% for date in dates_group %} -
-
- {% if date.news.club.logo %} - {{ date.news.club }} - {% else %} - {{ date.news.club }} - {% endif %} -
-

- - {{ date.news.title }} - -

- {{ date.news.club }} -
- - - +
+ {% if not date.news.is_moderated %} + {# if a non moderated news is in the object list, + the logged user is either an admin or the news author #} + {{ news_moderation_alert(date.news, user, "newsState") }} + {% endif %} +
+
+ {% if date.news.club.logo %} + {{ date.news.club }} + {% else %} + {{ date.news.club }} + {% endif %} +
+

+ + {{ date.news.title }} + +

+ {{ date.news.club }} +
+ - + +
+
+
+ {{ date.news.summary|markdown }}
-
-
- {{ date.news.summary|markdown }}
{% endfor %} diff --git a/core/static/core/style.scss b/core/static/core/style.scss index a89d33cf..06208579 100644 --- a/core/static/core/style.scss +++ b/core/static/core/style.scss @@ -244,6 +244,20 @@ body { } } + &.btn-green { + $bg-color: rgba(0, 210, 83, 0.4); + background-color: $bg-color; + color: $black-color; + + &:not(:disabled):hover { + background-color: darken($bg-color, 15%); + } + + &:disabled { + background-color: lighten($bg-color, 15%); + } + } + &.btn-red { background-color: #fc8181; color: black; diff --git a/locale/fr/LC_MESSAGES/django.po b/locale/fr/LC_MESSAGES/django.po index dc6b5ee6..134a903b 100644 --- a/locale/fr/LC_MESSAGES/django.po +++ b/locale/fr/LC_MESSAGES/django.po @@ -6,7 +6,7 @@ msgid "" msgstr "" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2025-01-19 18:12+0100\n" +"POT-Creation-Date: 2025-01-20 17:35+0100\n" "PO-Revision-Date: 2016-07-18\n" "Last-Translator: Maréchal \n" @@ -310,7 +310,7 @@ msgstr "Compte en banque : " #: accounting/templates/accounting/club_account_details.jinja #: accounting/templates/accounting/label_list.jinja #: club/templates/club/club_sellings.jinja club/templates/club/mailing.jinja -#: com/templates/com/mailing_admin.jinja +#: com/templates/com/macros.jinja com/templates/com/mailing_admin.jinja #: com/templates/com/news_admin_list.jinja com/templates/com/poster_edit.jinja #: com/templates/com/screen_edit.jinja com/templates/com/weekmail.jinja #: core/templates/core/file_detail.jinja @@ -935,10 +935,6 @@ msgstr "rôle" msgid "description" msgstr "description" -#: club/models.py -msgid "past member" -msgstr "ancien membre" - #: club/models.py msgid "Email address" msgstr "Adresse email" @@ -1408,12 +1404,25 @@ msgstr "temps d'affichage" msgid "Begin date should be before end date" msgstr "La date de début doit être avant celle de fin" -#: com/templates/com/mailing_admin.jinja com/views.py -#: core/templates/core/user_tools.jinja -msgid "Mailing lists administration" -msgstr "Administration des mailing listes" +#: com/templates/com/macros.jinja +msgid "Waiting moderation" +msgstr "En attente de modération" -#: com/templates/com/mailing_admin.jinja +#: com/templates/com/macros.jinja +msgid "" +"This news isn't moderated and is visible only by its author and the " +"communication admins." +msgstr "" +"Cette nouvelle n'est pas modérée et n'est visible que par son auteur et les " +"admins communication." + +#: com/templates/com/macros.jinja +msgid "It will stay hidden for other users until it has been moderated." +msgstr "" +"Elle sera cachée pour les autres utilisateurs tant qu'elle ne sera pas " +"modérée." + +#: com/templates/com/macros.jinja com/templates/com/mailing_admin.jinja #: com/templates/com/news_admin_list.jinja com/templates/com/news_detail.jinja #: core/templates/core/file_detail.jinja #: core/templates/core/file_moderation.jinja sas/templates/sas/moderation.jinja @@ -1421,6 +1430,19 @@ msgstr "Administration des mailing listes" msgid "Moderate" msgstr "Modérer" +#: com/templates/com/macros.jinja +msgid "News moderated" +msgstr "Nouvelle modérée" + +#: com/templates/com/macros.jinja +msgid "News deleted" +msgstr "Nouvelle supprimée" + +#: com/templates/com/mailing_admin.jinja com/views.py +#: core/templates/core/user_tools.jinja +msgid "Mailing lists administration" +msgstr "Administration des mailing listes" + #: com/templates/com/mailing_admin.jinja #, python-format msgid "Moderated by %(user)s" @@ -1578,14 +1600,6 @@ msgstr "Discord AE" msgid "Dev Team" msgstr "Pôle Informatique" -#: com/templates/com/news_list.jinja -msgid "Facebook" -msgstr "Facebook" - -#: com/templates/com/news_list.jinja -msgid "Instagram" -msgstr "Instagram" - #: com/templates/com/news_list.jinja msgid "Birthdays" msgstr "Anniversaires" @@ -1599,6 +1613,10 @@ msgstr "%(age)s ans" msgid "You need to subscribe to access this content" msgstr "Vous devez cotiser pour accéder à ce contenu" +#: com/templates/com/news_list.jinja +msgid "You cannot access this content" +msgstr "Vous n'avez pas accès à ce contenu" + #: com/templates/com/poster_edit.jinja com/templates/com/poster_list.jinja msgid "Poster" msgstr "Affiche" @@ -3299,8 +3317,8 @@ msgstr "Nom d'utilisateur, email, ou numéro de compte AE" #: core/views/forms.py msgid "" -"Profile: you need to be visible on the picture, in order to be recognized " -"(e.g. by the barmen)" +"Profile: you need to be visible on the picture, in order to be recognized (e." +"g. by the barmen)" msgstr "" "Photo de profil: vous devez être visible sur la photo afin d'être reconnu " "(par exemple par les barmen)" @@ -3906,8 +3924,8 @@ msgstr "" #: counter/templates/counter/mails/account_dump.jinja msgid "If you think this was a mistake, please mail us at ae@utbm.fr." msgstr "" -"Si vous pensez qu'il s'agit d'une erreur, veuillez envoyer un mail à " -"ae@utbm.fr." +"Si vous pensez qu'il s'agit d'une erreur, veuillez envoyer un mail à ae@utbm." +"fr." #: counter/templates/counter/mails/account_dump.jinja msgid ""