From d8f32afeb01910f9b4a6272763e8d8e84f150c8c Mon Sep 17 00:00:00 2001 From: Trinity Pointard Date: Mon, 11 Jun 2018 16:05:18 +0200 Subject: [PATCH 1/7] allow html on user.summary --- src/models/users.rs | 11 ++++++----- templates/users/details.html.tera | 2 +- templates/users/followers.html.tera | 2 +- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/models/users.rs b/src/models/users.rs index 1b58710f..86771548 100644 --- a/src/models/users.rs +++ b/src/models/users.rs @@ -45,6 +45,7 @@ use models::{ posts::Post }; use schema::users; +use safe_string::SafeString; pub const AUTH_COOKIE: &'static str = "user_id"; @@ -56,7 +57,7 @@ pub struct User { pub outbox_url: String, pub inbox_url: String, pub is_admin: bool, - pub summary: String, + pub summary: SafeString, pub email: Option, pub hashed_password: Option, pub instance_id: i32, @@ -75,7 +76,7 @@ pub struct NewUser { pub outbox_url: String, pub inbox_url: String, pub is_admin: bool, - pub summary: String, + pub summary: SafeString, pub email: Option, pub hashed_password: Option, pub instance_id: i32, @@ -200,7 +201,7 @@ impl User { outbox_url: acct["outbox"].as_str().unwrap().to_string(), inbox_url: acct["inbox"].as_str().unwrap().to_string(), is_admin: false, - summary: acct["summary"].as_str().unwrap().to_string(), + summary: SafeString::new(&acct["summary"].as_str().unwrap().to_string()), email: None, hashed_password: None, instance_id: instance.id, @@ -371,7 +372,7 @@ impl APActor for User { } fn get_summary(&self) -> String { - self.summary.clone() + self.summary.get().clone() } fn get_instance(&self, conn: &PgConnection) -> Instance { @@ -561,7 +562,7 @@ impl NewUser { outbox_url: String::from(""), inbox_url: String::from(""), is_admin: is_admin, - summary: summary, + summary: SafeString::new(&summary), email: Some(email), hashed_password: Some(password), instance_id: instance_id, diff --git a/templates/users/details.html.tera b/templates/users/details.html.tera index ca681b28..d225a300 100644 --- a/templates/users/details.html.tera +++ b/templates/users/details.html.tera @@ -28,7 +28,7 @@
- {{ user.summary }} + {{ user.summary | safe }}
{% if recents | length != 0 %} diff --git a/templates/users/followers.html.tera b/templates/users/followers.html.tera index ed6a8244..5d6a956e 100644 --- a/templates/users/followers.html.tera +++ b/templates/users/followers.html.tera @@ -23,7 +23,7 @@ {% for follower in followers %}

{{ follower.display_name }} — @{{ follower.fqn }}

-

{{ follower.summary }}

+

{{ follower.summary | safe }}

{% endfor %} From 4ae19c6fa773ab1b0fb96a3beecb2778fd52477c Mon Sep 17 00:00:00 2001 From: Stephen Burgess Date: Mon, 11 Jun 2018 18:30:31 -0500 Subject: [PATCH 2/7] feat(Posts): Show username if no display name is present --- templates/posts/details.html.tera | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/templates/posts/details.html.tera b/templates/posts/details.html.tera index 5c658d37..e126f223 100644 --- a/templates/posts/details.html.tera +++ b/templates/posts/details.html.tera @@ -9,8 +9,13 @@ {% endblock header %} {% block content %} +{% if author.display_name %} + {% set name = author.display_name %} +{% else %} + {% set name = author.username %} +{% endif %}

- Written by {{ author.display_name }} + Written by {{name }}{{ date | date(format="%B %e, %Y") }}

@@ -49,8 +54,13 @@

Comments

{% for comment in comments %} + {% if comment.author.display_name %} + {% set commentAuthorName = comment.author.display_name %} + {% else %} + {% set commentAuthorName = comment.author.username %} + {% endif %}
- {{ comment.author.display_name }} + {{ name }}
{{ comment.content | safe }}
Respond
From 4b0114917d603c7ed204aeabcb2967106351be37 Mon Sep 17 00:00:00 2001 From: Stephen Burgess Date: Mon, 11 Jun 2018 18:31:44 -0500 Subject: [PATCH 3/7] chore(Posts): Fix typo --- templates/posts/details.html.tera | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/posts/details.html.tera b/templates/posts/details.html.tera index e126f223..1935da0c 100644 --- a/templates/posts/details.html.tera +++ b/templates/posts/details.html.tera @@ -15,7 +15,7 @@ {% set name = author.username %} {% endif %}

- Written by {{name }} + Written by {{ name }}{{ date | date(format="%B %e, %Y") }}

From df0fcb886d19a756986ddd97bc9810d1317e1ed1 Mon Sep 17 00:00:00 2001 From: Stephen Burgess Date: Tue, 12 Jun 2018 07:17:02 -0500 Subject: [PATCH 4/7] feat(UI): Fallback to username where ever display name is shown --- templates/macros.html.tera | 7 ++++++- templates/posts/details.html.tera | 6 +++--- templates/users/details.html.tera | 8 ++++++-- templates/users/followers.html.tera | 17 ++++++++++++++--- 4 files changed, 29 insertions(+), 9 deletions(-) diff --git a/templates/macros.html.tera b/templates/macros.html.tera index 49432656..900f96c3 100644 --- a/templates/macros.html.tera +++ b/templates/macros.html.tera @@ -1,7 +1,12 @@ {% macro post_card(article) %} +{% if article.author.display_name %} + {% set name = article.author.display_name %} +{% else %} + {% set name = article.author.username %} +{% endif %}

{{ article.post.title }}

{{ article.post.content | striptags | truncate(length=200) }}

-

By {{ article.author.display_name }} ⋅ {{ article.date | date(format="%B %e") }}

+

By {{ name }} ⋅ {{ article.date | date(format="%B %e") }}

{% endmacro post_card %} diff --git a/templates/posts/details.html.tera b/templates/posts/details.html.tera index 1935da0c..13e3e5ab 100644 --- a/templates/posts/details.html.tera +++ b/templates/posts/details.html.tera @@ -55,12 +55,12 @@
{% for comment in comments %} {% if comment.author.display_name %} - {% set commentAuthorName = comment.author.display_name %} + {% set comment_author_name = comment.author.display_name %} {% else %} - {% set commentAuthorName = comment.author.username %} + {% set comment_author_name = comment.author.username %} {% endif %}
- {{ name }} + {{ comment_author_name }}
{{ comment.content | safe }}
Respond
diff --git a/templates/users/details.html.tera b/templates/users/details.html.tera index d225a300..1eb6325d 100644 --- a/templates/users/details.html.tera +++ b/templates/users/details.html.tera @@ -2,13 +2,17 @@ {% import "macros" as macros %} {% block title %} -{{ user.display_name }} +{% if author.display_name %} + {% set name = author.display_name %} +{% else %} + {% set name = user.username %} +{% endif %} {% endblock title %} {% block content %}

- {{ user.display_name }} + {{ name }} {% if user.is_admin %} Admin {% endif %} diff --git a/templates/users/followers.html.tera b/templates/users/followers.html.tera index 5d6a956e..9b0bdf28 100644 --- a/templates/users/followers.html.tera +++ b/templates/users/followers.html.tera @@ -1,13 +1,19 @@ {% extends "base" %} {% block title %} -{{ user.display_name }}'s Followers +{% if user.display_name %} + {% set name = user.display_name %} +{% else %} + {% set name = user.username %} +{% endif %} + +{{ name }}'s Followers {% endblock title %} {% block content %}

- {{ user.display_name }} + {{ name }} {% if user.is_admin %} Admin {% endif %} @@ -21,8 +27,13 @@

Followers

{% for follower in followers %} + {% if follower.display_name %} + {% set follower_name = follower.display_name %} + {% else %} + {% set follower_name = follower.username %} + {% endif %}
-

{{ follower.display_name }} — @{{ follower.fqn }}

+

{{ follower_name }} — @{{ follower.fqn }}

{{ follower.summary | safe }}

{% endfor %} From 23bb405c92d98a6b0c3966090f865376a2ce27dc Mon Sep 17 00:00:00 2001 From: Stephen Burgess Date: Tue, 12 Jun 2018 07:42:34 -0500 Subject: [PATCH 5/7] fix(User/Details): Use user variable --- templates/users/details.html.tera | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/users/details.html.tera b/templates/users/details.html.tera index 1eb6325d..6e091c35 100644 --- a/templates/users/details.html.tera +++ b/templates/users/details.html.tera @@ -2,8 +2,8 @@ {% import "macros" as macros %} {% block title %} -{% if author.display_name %} - {% set name = author.display_name %} +{% if user.display_name %} + {% set name = user.display_name %} {% else %} {% set name = user.username %} {% endif %} From d32c7e4b66ea85032155ea9d7722ddb8a89adca9 Mon Sep 17 00:00:00 2001 From: Stephen Burgess Date: Tue, 12 Jun 2018 07:45:53 -0500 Subject: [PATCH 6/7] fix(User/Details): Display name --- templates/users/details.html.tera | 1 + 1 file changed, 1 insertion(+) diff --git a/templates/users/details.html.tera b/templates/users/details.html.tera index 6e091c35..15d44045 100644 --- a/templates/users/details.html.tera +++ b/templates/users/details.html.tera @@ -7,6 +7,7 @@ {% else %} {% set name = user.username %} {% endif %} +{{ name }} {% endblock title %} {% block content %} From 438778db398c5b0700683ea25ba52928afac05f4 Mon Sep 17 00:00:00 2001 From: Stephen Burgess Date: Tue, 12 Jun 2018 12:05:33 -0500 Subject: [PATCH 7/7] fix(Style): Adjust code style for consistency --- templates/macros.html.tera | 10 +++++----- templates/posts/details.html.tera | 3 ++- templates/users/details.html.tera | 3 ++- templates/users/followers.html.tera | 2 +- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/templates/macros.html.tera b/templates/macros.html.tera index 900f96c3..3cce7285 100644 --- a/templates/macros.html.tera +++ b/templates/macros.html.tera @@ -1,9 +1,9 @@ {% macro post_card(article) %} -{% if article.author.display_name %} - {% set name = article.author.display_name %} -{% else %} - {% set name = article.author.username %} -{% endif %} + {% if article.author.display_name %} + {% set name = article.author.display_name %} + {% else %} + {% set name = article.author.username %} + {% endif %}

{{ article.post.title }}

{{ article.post.content | striptags | truncate(length=200) }}

diff --git a/templates/posts/details.html.tera b/templates/posts/details.html.tera index 13e3e5ab..52e71b30 100644 --- a/templates/posts/details.html.tera +++ b/templates/posts/details.html.tera @@ -8,12 +8,13 @@ {{ blog.title }} {% endblock header %} -{% block content %} {% if author.display_name %} {% set name = author.display_name %} {% else %} {% set name = author.username %} {% endif %} + +{% block content %}

Written by {{ name }} — diff --git a/templates/users/details.html.tera b/templates/users/details.html.tera index 15d44045..51d6f94e 100644 --- a/templates/users/details.html.tera +++ b/templates/users/details.html.tera @@ -1,12 +1,13 @@ {% extends "base" %} {% import "macros" as macros %} -{% block title %} {% if user.display_name %} {% set name = user.display_name %} {% else %} {% set name = user.username %} {% endif %} + +{% block title %} {{ name }} {% endblock title %} diff --git a/templates/users/followers.html.tera b/templates/users/followers.html.tera index 9b0bdf28..595f6ae1 100644 --- a/templates/users/followers.html.tera +++ b/templates/users/followers.html.tera @@ -1,12 +1,12 @@ {% extends "base" %} -{% block title %} {% if user.display_name %} {% set name = user.display_name %} {% else %} {% set name = user.username %} {% endif %} +{% block title %} {{ name }}'s Followers {% endblock title %}