decidim-comments 0.20.1 → 0.21.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -39,6 +39,18 @@ module Decidim
39
39
 
40
40
  delegate :organization, to: :commentable
41
41
 
42
+ def self.positive
43
+ where(alignment: 1)
44
+ end
45
+
46
+ def self.neutral
47
+ where(alignment: 0)
48
+ end
49
+
50
+ def self.negative
51
+ where(alignment: -1)
52
+ end
53
+
42
54
  def participatory_space
43
55
  return root_commentable if root_commentable.is_a?(Decidim::Participable)
44
56
 
@@ -92,7 +104,7 @@ module Decidim
92
104
 
93
105
  # Public: Returns the comment message ready to display (it is expected to include HTML)
94
106
  def formatted_body
95
- @formatted_body ||= Decidim::ContentProcessor.render(sanitized_body)
107
+ @formatted_body ||= Decidim::ContentProcessor.render(sanitized_body, "div")
96
108
  end
97
109
 
98
110
  def self.export_serializer
@@ -125,9 +137,22 @@ module Decidim
125
137
  self.depth = commentable.depth + 1 if commentable.respond_to?(:depth)
126
138
  end
127
139
 
128
- # Private: Returns the comment body sanitized, stripping HTML tags
140
+ # Private: Returns the comment body sanitized, sanitizing HTML tags
129
141
  def sanitized_body
130
- Rails::Html::Sanitizer.full_sanitizer.new.sanitize(body)
142
+ Rails::Html::WhiteListSanitizer.new.sanitize(
143
+ render_markdown(body),
144
+ scrubber: Decidim::Comments::UserInputScrubber.new
145
+ ).try(:html_safe)
146
+ end
147
+
148
+ # Private: Initializes the Markdown parser
149
+ def markdown
150
+ @markdown ||= Decidim::Comments::Markdown.new
151
+ end
152
+
153
+ # Private: converts the string from markdown to html
154
+ def render_markdown(string)
155
+ markdown.render(string)
131
156
  end
132
157
  end
133
158
  end
@@ -30,8 +30,7 @@ module Decidim
30
30
  # loads comments replies. It uses Comment's MAX_DEPTH to load a maximum
31
31
  # level of nested replies.
32
32
  def query
33
- scope = Comment
34
- .where(commentable: commentable)
33
+ scope = base_scope
35
34
  .not_hidden
36
35
  .includes(:author, :user_group, :up_votes, :down_votes)
37
36
 
@@ -53,6 +52,13 @@ module Decidim
53
52
 
54
53
  private
55
54
 
55
+ def base_scope
56
+ id = @options[:id]
57
+ return Comment.where(root_commentable: commentable, id: id) if id.present?
58
+
59
+ Comment.where(commentable: commentable)
60
+ end
61
+
56
62
  def order_by_older(scope)
57
63
  scope.order(created_at: :asc)
58
64
  end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Decidim
4
+ module Comments
5
+ # Use this class as a scrubber to sanitize user input.
6
+ # https://stackoverflow.com/a/35073814/2110884.
7
+ class UserInputScrubber < Rails::Html::PermitScrubber
8
+ def initialize
9
+ super
10
+ self.tags = custom_allowed_tags
11
+ end
12
+
13
+ private
14
+
15
+ def custom_allowed_tags
16
+ %w(p blockquote)
17
+ end
18
+ end
19
+ end
20
+ end
@@ -29,9 +29,10 @@ module Decidim
29
29
  type !types[!CommentType]
30
30
 
31
31
  argument :orderBy, types.String, "Order the comments"
32
+ argument :singleCommentId, types.String, "ID of the single comment to look at"
32
33
 
33
34
  resolve lambda { |obj, args, _ctx|
34
- SortedComments.for(obj, order_by: args[:orderBy])
35
+ SortedComments.for(obj, order_by: args[:orderBy], id: args[:singleCommentId])
35
36
  }
36
37
  end
37
38
 
@@ -50,6 +50,7 @@ ar:
50
50
  against: ضد
51
51
  in_favor: لصالح
52
52
  deleted_user: مشارك محذوف
53
+ hide_replies: إخفاء الردود
53
54
  reply: الرد
54
55
  report:
55
56
  action: أبلغ عن
@@ -62,6 +63,8 @@ ar:
62
63
  offensive: يحتوي على العنصرية والتمييز الجنسي والتشهير والهجمات الشخصية والتهديدات بالقتل أو طلبات الانتحار أو أي شكل من أشكال خطاب الكراهية.
63
64
  spam: يحتوي على clickbait أو الإعلان أو الخدع أو روبوت البرامج النصية.
64
65
  title: الإبلاغ عن مشكلة
66
+ show_replies: اظهر الردود الـ %{replies_count}
67
+ single_comment_link_title: الحصول على رابط نحو تعليق واحد
65
68
  comment_order_selector:
66
69
  order:
67
70
  best_rated: أفضل تصنيف
@@ -74,7 +77,10 @@ ar:
74
77
  comments:
75
78
  blocked_comments_for_user_warning: لا يمكنك التعليق في هذه اللحظة ، ولكن يمكنك قراءة التعليقات السابقة.
76
79
  blocked_comments_warning: التعليقات معطلة في هذا الوقت ، لكن يمكنك قراءة التعليقات السابقة.
80
+ comment_details_title: تفاصيل التعليق
77
81
  loading: جارٍ تحميل التعليقات ...
82
+ single_comment_warning: يمكنك الإطلاع على التعليقات المتبقية الأخرى <a href="%{url}">هنا</a>.
83
+ single_comment_warning_title: إنك ترى تعليقا واحدا
78
84
  title: "%{count} تعليقات"
79
85
  events:
80
86
  comments:
@@ -42,6 +42,7 @@ ca:
42
42
  against: En contra
43
43
  in_favor: A favor
44
44
  deleted_user: Participant eliminada
45
+ hide_replies: Oculta les respostes
45
46
  reply: Respondre
46
47
  report:
47
48
  action: Denúncia
@@ -54,6 +55,8 @@ ca:
54
55
  offensive: Conté racisme, sexisme, insults, atacs personals, amenaces de mort, peticions de suïcidi o qualsevol forma de discurs d'odi.
55
56
  spam: Conté "clickbait", publicitat o estafes.
56
57
  title: Denúncia un problema
58
+ show_replies: Mostra %{replies_count} respostes
59
+ single_comment_link_title: Aconsegueix l'enllaç al comentari
57
60
  comment_order_selector:
58
61
  order:
59
62
  best_rated: Més ben valorats
@@ -66,7 +69,10 @@ ca:
66
69
  comments:
67
70
  blocked_comments_for_user_warning: No pots fer comentaris en aquest moment, però pots llegir els anteriors.
68
71
  blocked_comments_warning: Els comentaris estan desactivats en aquest moment, però pots llegir els anteriors.
72
+ comment_details_title: Detalls del comentari
69
73
  loading: Carregant els comentaris ...
74
+ single_comment_warning: 'Pots revisar la resta de comentaris a: <a href="%{url}">here</a>.'
75
+ single_comment_warning_title: Estàs veient un sol comentari
70
76
  title: "%{count} comentaris"
71
77
  events:
72
78
  comments:
@@ -46,6 +46,7 @@ cs:
46
46
  against: Proti
47
47
  in_favor: Ve prospěch
48
48
  deleted_user: Vymazaný uživatel
49
+ hide_replies: Skrýt odpovědi
49
50
  reply: Odpověď
50
51
  report:
51
52
  action: Zpráva
@@ -58,6 +59,8 @@ cs:
58
59
  offensive: Obsahuje rasismus, sexismus, podvody, osobní útoky, hrozby smrti, žádosti o sebevraždu nebo jakoukoli formu projevy nenávisti.
59
60
  spam: Obsahuje clickbait, reklama, podvody nebo skripty.
60
61
  title: Nahlásit problém
62
+ show_replies: Zobrazit %{replies_count} odpovědí
63
+ single_comment_link_title: Získat odkaz na jeden komentář
61
64
  comment_order_selector:
62
65
  order:
63
66
  best_rated: Nejlépe hodnocené
@@ -70,7 +73,10 @@ cs:
70
73
  comments:
71
74
  blocked_comments_for_user_warning: V tuto chvíli nemůžete komentovat, ale můžete si přečíst předchozí.
72
75
  blocked_comments_warning: Komentáře jsou v tuto chvíli zakázány, ale můžete si přečíst předchozí.
76
+ comment_details_title: Podrobnosti komentáře
73
77
  loading: Načítání komentářů ...
78
+ single_comment_warning: Můžete zkontrolovat zbytek komentářů <a href="%{url}">zde</a>.
79
+ single_comment_warning_title: Vidíte jeden komentář
74
80
  title: "%{count} komentářů"
75
81
  events:
76
82
  comments:
@@ -0,0 +1 @@
1
+ el:
@@ -43,6 +43,7 @@ en:
43
43
  against: Against
44
44
  in_favor: In favor
45
45
  deleted_user: Deleted participant
46
+ hide_replies: Hide replies
46
47
  reply: Reply
47
48
  report:
48
49
  action: Report
@@ -55,6 +56,8 @@ en:
55
56
  offensive: Contains racism, sexism, slurs, personal attacks, death threats, suicide requests or any form of hate speech.
56
57
  spam: Contains clickbait, advertising, scams or script bots.
57
58
  title: Report a problem
59
+ show_replies: Show %{replies_count} replies
60
+ single_comment_link_title: Get link to single comment
58
61
  comment_order_selector:
59
62
  order:
60
63
  best_rated: Best rated
@@ -67,7 +70,10 @@ en:
67
70
  comments:
68
71
  blocked_comments_for_user_warning: You are not able to comment at this moment, but you can read the previous ones.
69
72
  blocked_comments_warning: Comments are disabled at this time, but you can read the previous ones.
73
+ comment_details_title: Comment details
70
74
  loading: Loading comments ...
75
+ single_comment_warning: You can check the rest of the comments <a href="%{url}">here</a>.
76
+ single_comment_warning_title: You are seeing a single comment
71
77
  title: "%{count} comments"
72
78
  events:
73
79
  comments:
@@ -42,6 +42,7 @@ es-MX:
42
42
  against: En contra
43
43
  in_favor: A favor
44
44
  deleted_user: Usuario eliminado
45
+ hide_replies: Ocultar respuestas
45
46
  reply: Respuesta
46
47
  report:
47
48
  action: Denunciar
@@ -54,6 +55,8 @@ es-MX:
54
55
  offensive: Contiene racismo, sexismo, insultos, ataques personales, amenazas de muerte, solicitudes de suicidio o cualquier forma de discurso de odio.
55
56
  spam: Contiene clickbait, publicidad o estafas.
56
57
  title: Denunciar un problema
58
+ show_replies: Mostrar %{replies_count} respuestas
59
+ single_comment_link_title: Obtener enlace a un solo comentario
57
60
  comment_order_selector:
58
61
  order:
59
62
  best_rated: Mejor valoración
@@ -66,7 +69,10 @@ es-MX:
66
69
  comments:
67
70
  blocked_comments_for_user_warning: No puede hacer comentarios en este momento, pero puede leer los anteriores.
68
71
  blocked_comments_warning: Los comentarios están deshabilitados en este momento, pero puedes leer los anteriores.
72
+ comment_details_title: Detalles del comentario
69
73
  loading: Cargando los comentarios ...
74
+ single_comment_warning: Puedes revisar el resto de los comentarios <a href="%{url}">aquí</a>.
75
+ single_comment_warning_title: Estás viendo un solo comentario
70
76
  title: "%{count} comentarios"
71
77
  events:
72
78
  comments:
@@ -42,6 +42,7 @@ es-PY:
42
42
  against: En contra
43
43
  in_favor: A favor
44
44
  deleted_user: Usuario eliminado
45
+ hide_replies: Ocultar respuestas
45
46
  reply: Respuesta
46
47
  report:
47
48
  action: Denunciar
@@ -54,6 +55,8 @@ es-PY:
54
55
  offensive: Contiene racismo, sexismo, insultos, ataques personales, amenazas de muerte, solicitudes de suicidio o cualquier forma de discurso de odio.
55
56
  spam: Contiene clickbait, publicidad o estafas.
56
57
  title: Denunciar un problema
58
+ show_replies: Mostrar %{replies_count} respuestas
59
+ single_comment_link_title: Obtener enlace a un solo comentario
57
60
  comment_order_selector:
58
61
  order:
59
62
  best_rated: Mejor valoración
@@ -66,7 +69,10 @@ es-PY:
66
69
  comments:
67
70
  blocked_comments_for_user_warning: No puede hacer comentarios en este momento, pero puede leer los anteriores.
68
71
  blocked_comments_warning: Los comentarios están deshabilitados en este momento, pero puedes leer los anteriores.
72
+ comment_details_title: Detalles del comentario
69
73
  loading: Cargando los comentarios ...
74
+ single_comment_warning: Puedes revisar el resto de los comentarios <a href="%{url}">aquí</a>.
75
+ single_comment_warning_title: Estás viendo un solo comentario
70
76
  title: "%{count} comentarios"
71
77
  events:
72
78
  comments:
@@ -42,6 +42,7 @@ es:
42
42
  against: En contra
43
43
  in_favor: A favor
44
44
  deleted_user: Participante eliminada
45
+ hide_replies: Ocultar respuestas
45
46
  reply: Respuesta
46
47
  report:
47
48
  action: Denunciar
@@ -54,6 +55,8 @@ es:
54
55
  offensive: Contiene racismo, sexismo, insultos, ataques personales, amenazas de muerte, solicitudes de suicidio o cualquier forma de discurso de odio.
55
56
  spam: Contiene clickbait, publicidad o estafas.
56
57
  title: Denunciar un problema
58
+ show_replies: Mostrar %{replies_count} respuestas
59
+ single_comment_link_title: Obtener enlace a un solo comentario
57
60
  comment_order_selector:
58
61
  order:
59
62
  best_rated: Mejor valoración
@@ -66,7 +69,10 @@ es:
66
69
  comments:
67
70
  blocked_comments_for_user_warning: No puedes hacer comentarios en este momento, pero puedes leer los anteriores.
68
71
  blocked_comments_warning: Los comentarios están deshabilitados en este momento, pero puedes leer los anteriores.
72
+ comment_details_title: Detalles del comentario
69
73
  loading: Cargando los comentarios ...
74
+ single_comment_warning: Puedes revisar el resto de los comentarios <a href="%{url}">aquí</a>.
75
+ single_comment_warning_title: Estás viendo un solo comentario
70
76
  title: "%{count} comentarios"
71
77
  events:
72
78
  comments:
@@ -42,6 +42,7 @@ fi-pl:
42
42
  against: Vastaan
43
43
  in_favor: Puolesta
44
44
  deleted_user: Poistettu käyttäjä
45
+ hide_replies: Piilota vastaukset
45
46
  reply: Vastaa
46
47
  report:
47
48
  action: Tee ilmoitus
@@ -54,6 +55,8 @@ fi-pl:
54
55
  offensive: Sisältää rasismia, seksismiä, haukkumista, henkilökohtaisia hyökkäyksiä, tappouhkauksia, itsemurhapyyntöjä tai muuta vihapuhetta.
55
56
  spam: Sisältää klikkihoukutteita, mainostusta, huijauksia tai bottiskriptejä.
56
57
  title: Ilmoita ongelmasta
58
+ show_replies: Näytä %{replies_count} vastausta
59
+ single_comment_link_title: Hae linkki yksittäiseen kommenttiin
57
60
  comment_order_selector:
58
61
  order:
59
62
  best_rated: Parhaiksi arvioidut
@@ -66,7 +69,10 @@ fi-pl:
66
69
  comments:
67
70
  blocked_comments_for_user_warning: Et voi kommentoida tällä hetkellä, mutta voit lukea aikaisempia kommentteja.
68
71
  blocked_comments_warning: Kommentit on poistettu käytöstä tällä hetkellä, mutta voit lukea aikaisempia kommentteja.
72
+ comment_details_title: Kommentin yksityiskohdat
69
73
  loading: Ladataan kommentteja ...
74
+ single_comment_warning: Voit katsoa loput kommentit <a href="%{url}">täältä</a>.
75
+ single_comment_warning_title: Näet yhden kommentin
70
76
  title: "%{count} kommenttia"
71
77
  events:
72
78
  comments:
@@ -42,6 +42,7 @@ fi:
42
42
  against: Vastaan
43
43
  in_favor: Puolesta
44
44
  deleted_user: Poistettu käyttäjä
45
+ hide_replies: Piilota vastaukset
45
46
  reply: Vastaa
46
47
  report:
47
48
  action: Tee ilmoitus
@@ -54,6 +55,8 @@ fi:
54
55
  offensive: Sisältää rasismia, seksismiä, haukkumista, henkilökohtaisia hyökkäyksiä, tappouhkauksia, itsemurhapyyntöjä tai muuta vihapuhetta.
55
56
  spam: Sisältää klikkihoukutteita, mainostusta, huijauksia tai bottiskriptejä.
56
57
  title: Ilmoita ongelmasta
58
+ show_replies: Näytä %{replies_count} vastausta
59
+ single_comment_link_title: Hae linkki yksittäiseen kommenttiin
57
60
  comment_order_selector:
58
61
  order:
59
62
  best_rated: Parhaiksi arvioidut
@@ -66,7 +69,10 @@ fi:
66
69
  comments:
67
70
  blocked_comments_for_user_warning: Et voi kommentoida tällä hetkellä, mutta voit lukea aikaisempia kommentteja.
68
71
  blocked_comments_warning: Kommentit on poistettu käytöstä tällä hetkellä, mutta voit lukea aikaisempia kommentteja.
72
+ comment_details_title: Kommentin yksityiskohdat
69
73
  loading: Ladataan kommentteja ...
74
+ single_comment_warning: Voit katsoa loput kommentit <a href="%{url}">täältä</a>.
75
+ single_comment_warning_title: Näet yhden kommentin
70
76
  title: "%{count} kommenttia"
71
77
  events:
72
78
  comments:
@@ -42,6 +42,7 @@ hu:
42
42
  against: Ellenzem
43
43
  in_favor: Támogatom
44
44
  deleted_user: Törölt felhasználó
45
+ hide_replies: Válaszok elrejtése
45
46
  reply: Válasz
46
47
  report:
47
48
  action: Jelentés
@@ -54,6 +55,8 @@ hu:
54
55
  offensive: Rasszizmust, szexizmust, gyalázkodást, személyeskedést, halálos fenyegetést, öngyilkosságra való felhívást vagy gyűlöletbeszédet tartalmaz.
55
56
  spam: Klikkvadászat, reklám, átverés vagy script bot.
56
57
  title: Jelentem a problémát
58
+ show_replies: '%{replies_count} válasz mutatása'
59
+ single_comment_link_title: Link a kommenthez
57
60
  comment_order_selector:
58
61
  order:
59
62
  best_rated: Legjobbra értékelt
@@ -66,7 +69,10 @@ hu:
66
69
  comments:
67
70
  blocked_comments_for_user_warning: Ebben a pillanatban nem tud megjegyzéseket tenni, de elolvashatja az előzőeket.
68
71
  blocked_comments_warning: A megjegyzések jelenleg le vannak tiltva, de a korábbiakat elolvashatod.
72
+ comment_details_title: Megjegyzés részletei
69
73
  loading: Hozzászólások betöltése ...
74
+ single_comment_warning: A többi hozzászólást <a href="%{url}">itt</a> ellenőrizheti.
75
+ single_comment_warning_title: Egyetlen megjegyzést látsz
70
76
  title: "%{count} megjegyzés"
71
77
  events:
72
78
  comments:
@@ -42,6 +42,7 @@ it:
42
42
  against: Contro
43
43
  in_favor: A favore
44
44
  deleted_user: Utente cancellato
45
+ hide_replies: Nascondi risposte
45
46
  reply: Rispondi
46
47
  report:
47
48
  action: Report
@@ -54,6 +55,8 @@ it:
54
55
  offensive: Vi sono contenuti razzisti, sessisti, offensivi, attacchi di carattere personale, minacce di morte o altro tipo di minacci, istigazioni al suicidio o altre forme d'odio verbale.
55
56
  spam: Contiene pubblicità, truffe, clickbait ("esca da click") o altro contenuto mirato ad attrarre traffico internet.
56
57
  title: Segnala un problema
58
+ show_replies: Mostra %{replies_count} risposte
59
+ single_comment_link_title: Ottieni link a singolo commento
57
60
  comment_order_selector:
58
61
  order:
59
62
  best_rated: Favoriti
@@ -54,6 +54,7 @@ nl:
54
54
  offensive: Bevat racisme, seksisme, laster, persoonlijke aanvallen, bedreigingen met de dood, zelfmoord verzoeken of enige vorm van haatzaaien.
55
55
  spam: Bevat clickbait, reclame, oplichting of script bots.
56
56
  title: Meld een probleem
57
+ single_comment_link_title: Krijg link naar enkele reactie
57
58
  comment_order_selector:
58
59
  order:
59
60
  best_rated: Best beoordeeld
@@ -66,7 +67,10 @@ nl:
66
67
  comments:
67
68
  blocked_comments_for_user_warning: U kunt op dit moment geen opmerkingen maken, maar u kunt de vorige wel lezen.
68
69
  blocked_comments_warning: Reacties zijn op dit moment uitgeschakeld, maar je kan de vorige berichten lezen.
70
+ comment_details_title: Opmerking details
69
71
  loading: Reacties laden...
72
+ single_comment_warning: U kunt de rest van de opmerkingen <a href="%{url}">hier</a> controleren.
73
+ single_comment_warning_title: Je ziet een enkele reactie
70
74
  title: "%{count} reacties"
71
75
  events:
72
76
  comments:
@@ -42,6 +42,7 @@
42
42
  against: Imot
43
43
  in_favor: I favør
44
44
  deleted_user: Slettet deltaker
45
+ hide_replies: Skjul svar
45
46
  reply: Svar
46
47
  report:
47
48
  action: Rapport
@@ -54,6 +55,8 @@
54
55
  offensive: Inneholder rasisme, sexisme, banning, persjonangrep, dødstrusler, selvmords forespørsler eller all form for hatefullt språk.
55
56
  spam: Inneholder klikkagn, reklame, svindel eller manus-roboter.
56
57
  title: Rapporter et problem
58
+ show_replies: Vis %{replies_count} svar
59
+ single_comment_link_title: Få lenke til enkeltkommentar
57
60
  comment_order_selector:
58
61
  order:
59
62
  best_rated: Best vurdert
@@ -66,7 +69,10 @@
66
69
  comments:
67
70
  blocked_comments_for_user_warning: Du kan ikke kommentere for øyeblikket, men du kan lese de forrige.
68
71
  blocked_comments_warning: Kommenterer er deaktivert på dette tidspunktet, men du kan lese de forrige.
72
+ comment_details_title: Kommenter detaljer
69
73
  loading: Laster inn kommenterer ...
74
+ single_comment_warning: Du kan sjekke resten av kommentarene <a href="%{url}">her</a>.
75
+ single_comment_warning_title: Du ser en enkelt kommentar
70
76
  title: "%{count} kommentarer"
71
77
  events:
72
78
  comments: