From 9c2ec47440f4d2458a8c647d3fe6c5bdc3510b44 Mon Sep 17 00:00:00 2001 From: juslong Date: Sun, 21 Nov 2021 21:27:29 -0500 Subject: [PATCH 01/20] initial work --- js/10-base.js | 1 + js/viewUnsettling.js | 22 ++++++++++++++++++++++ liberapay/constants.py | 1 + www/%username/edit/privacy.spt | 2 ++ www/%username/index.html.spt | 32 +++++++++++++++++++++++++++++++- 5 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 js/viewUnsettling.js diff --git a/js/10-base.js b/js/10-base.js index f51db5ff5e..a7ea10d3cd 100644 --- a/js/10-base.js +++ b/js/10-base.js @@ -42,6 +42,7 @@ Liberapay.init = function() { Liberapay.payments.init(); Liberapay.s3_uploader_init(); Liberapay.stripe_init(); + Liberapay.view_unsettling.init(); $('div[href]').css('cursor', 'pointer').on('click auxclick', function(event) { if (event.target.tagName == 'A') { diff --git a/js/viewUnsettling.js b/js/viewUnsettling.js new file mode 100644 index 0000000000..86ea6a4287 --- /dev/null +++ b/js/viewUnsettling.js @@ -0,0 +1,22 @@ +Liberapay.view_unsettling = {}; + +Liberapay.view_unsettling.init = function () { + Liberapay.view_unsettling.once(); + Liberapay.view_unsettling.opt_in(); +}; + +Liberapay.view_unsettling.once = function () { + $(".display-unsettling-once").click(function () { + $(this).remove(); + $("#unsettling-content-display").remove(); + + + }); +}; + +Liberapay.view_unsettling.opt_in = function () { + $(".display-unsettling-opt-in").click(function () { + $(this).remove(); + $("#unsettling-content-display").remove(); + }); +}; diff --git a/liberapay/constants.py b/liberapay/constants.py index 306e389bee..b5bf202df7 100644 --- a/liberapay/constants.py +++ b/liberapay/constants.py @@ -388,6 +388,7 @@ def __missing__(self, currency): ('hide_from_search', (_("Hide this profile from search results on Liberapay."), True)), ('profile_noindex', (_("Tell web search engines not to index this profile."), True)), ('hide_from_lists', (_("Prevent this profile from being listed on Liberapay."), True)), + ('is_unsettling', (_("Mark this profile as unsettling"), True)), ]) PRIVACY_FIELDS_S = ' '.join(PRIVACY_FIELDS.keys()) diff --git a/www/%username/edit/privacy.spt b/www/%username/edit/privacy.spt index 5cd56fa8de..9a87e4491a 100644 --- a/www/%username/edit/privacy.spt +++ b/www/%username/edit/privacy.spt @@ -5,6 +5,8 @@ from liberapay.utils import form_post_success, get_participant participant = get_participant(state, restrict=True, allow_member=True) if request.method == 'POST': + print('participant is', participant) + print('request is', request) fields = request.body['privacy'].split() for field in fields: if field not in PRIVACY_FIELDS: diff --git a/www/%username/index.html.spt b/www/%username/index.html.spt index 62c5edf501..c7e0f0361a 100644 --- a/www/%username/index.html.spt +++ b/www/%username/index.html.spt @@ -17,7 +17,9 @@ MARK_CLASSES = { [-----------------------------------------------------------------------------] participant = get_participant(state, restrict=False) +print('participant is', participant.is_unsettling) title = _("{username}'s profile", username=participant.username) +print('request header cookies are', request.headers.cookie) lang = request.qs.get('lang') if lang: @@ -40,6 +42,13 @@ langs = participant.get_statement_langs() show_income = not participant.hide_receiving and participant.accepts_tips +is_unsettling = participant.is_unsettling +always_view_unsettling = False +if hasattr(request.headers, 'view_unsettling'): + always_view_unsettling = True +view_unsettling_content = is_unsettling and always_view_unsettling + + [-----------------------------------------------------------------------------] % extends "templates/layouts/profile.html" @@ -107,7 +116,7 @@ show_income = not participant.hide_receiving and participant.accepts_tips % endif % endblock -% block content +% block profile_info % if statement

{{ _("Statement") }}

@@ -215,3 +224,24 @@ show_income = not participant.hide_receiving and participant.accepts_tips % endif % endif % endblock + +% block content + % if is_unsettling and not view_unsettling +
+

The profile you are about to view is considered NSFW

+

Would you still like to view it?

+ + +
+ + +
+
+ +
+ {{ self.profile_info() }} +
+ % else + {{ self.profile_info() }} + % endif +% endblock \ No newline at end of file From adbc299353975742abfffa804bf14f44a21cabd3 Mon Sep 17 00:00:00 2001 From: juslong Date: Fri, 26 Nov 2021 18:16:40 -0500 Subject: [PATCH 02/20] Adding suggested changes --- js/viewUnsettling.js | 4 +-- templates/layouts/base.html | 48 ++++++++++++++++++++++--------- templates/macros/profile-box.html | 3 +- www/%username/index.html.spt | 31 +------------------- 4 files changed, 40 insertions(+), 46 deletions(-) diff --git a/js/viewUnsettling.js b/js/viewUnsettling.js index 86ea6a4287..0f9a04749d 100644 --- a/js/viewUnsettling.js +++ b/js/viewUnsettling.js @@ -9,8 +9,6 @@ Liberapay.view_unsettling.once = function () { $(".display-unsettling-once").click(function () { $(this).remove(); $("#unsettling-content-display").remove(); - - }); }; @@ -18,5 +16,7 @@ Liberapay.view_unsettling.opt_in = function () { $(".display-unsettling-opt-in").click(function () { $(this).remove(); $("#unsettling-content-display").remove(); + + document.cookie = 'always_view_unsettling=True'; }); }; diff --git a/templates/layouts/base.html b/templates/layouts/base.html index 0f41ec9f1e..5af0cfbcc4 100644 --- a/templates/layouts/base.html +++ b/templates/layouts/base.html @@ -96,21 +96,43 @@
- % block main - {% block before_container %}{% endblock %} -
- % block before_content - % block heading - % if title -

{{ title }}

- % endif + % if participant and participant.id != user.id + % set is_unsettling = participant.is_unsettling + % set hide_profile = is_unsettling and 'always_view_unsettling' not in request.headers.cookie + % endif + + % if hide_profile +
+

This page is marked as containing potentially upsetting or embarrassing content. Viewing it is unrecommended if you are a minor

+

Would you still like to view it?

+ + +
+ + +
+
+ +
+ % block main + {% block before_container %}{% endblock %} +
+ % block before_content + % block heading + % if title +

{{ title }}

+ % endif + % endblock + + % endblock + {% block content %}{% endblock %} + {% block after_content %}{% endblock %} +
% endblock - - % endblock - {% block content %}{% endblock %} - {% block after_content %}{% endblock %}
- % endblock + % else + {{ self.main() }} + % endif