Current location

narf Source control manager Git

summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOlivier Mehani <shtrom@ssji.net>2015-10-10 16:42:03 +1100
committerOlivier Mehani <shtrom+mediagoblin@ssji.net>2020-05-17 01:38:55 +1000
commit7da6aedf697ec4da9a8c2ae255d36301912e69d1 (patch)
treebb4d2bf10a1fac154c1936234b0534d214222293
parent872eb9ad46b92597300b165b42740ca0e219561e (diff)
Limit access to media to logged in usersshtrom-s-v0.10.0
Issues: * Code is duplicated between collection and single-media display; * Login message is not translated. Signed-off-by: Olivier Mehani <shtrom@ssji.net> squash! Limit access to media to logged in users Prevent collection listing squash! Limit access to media to logged in users Add require_login option squash! squash! Limit access to media to logged in users Remove ATOM entries when not logged in
-rw-r--r--mediagoblin.example.ini3
-rw-r--r--mediagoblin/config_spec.ini3
-rw-r--r--mediagoblin/listings/views.py3
-rw-r--r--mediagoblin/templates/mediagoblin/user_pages/collection.html4
-rw-r--r--mediagoblin/templates/mediagoblin/user_pages/collection_list.html4
-rw-r--r--mediagoblin/templates/mediagoblin/user_pages/media.html4
-rw-r--r--mediagoblin/templates/mediagoblin/utils/object_gallery.html23
-rw-r--r--mediagoblin/templates/mediagoblin/utils/require_login.html8
-rw-r--r--mediagoblin/user_pages/views.py6
9 files changed, 49 insertions, 9 deletions
diff --git a/mediagoblin.example.ini b/mediagoblin.example.ini
index 6648fb91..2628d7c2 100644
--- a/mediagoblin.example.ini
+++ b/mediagoblin.example.ini
@@ -30,6 +30,9 @@ email_debug_mode = true
# Set to false to disable registrations
allow_registration = true
+# Set to true to only display media to logged-in users
+#require_login = false
+
# Set to false to disable the ability for users to report offensive content
allow_reporting = true
diff --git a/mediagoblin/config_spec.ini b/mediagoblin/config_spec.ini
index 8901cefa..4b056933 100644
--- a/mediagoblin/config_spec.ini
+++ b/mediagoblin/config_spec.ini
@@ -52,6 +52,9 @@ email_smtp_pass = string(default=None)
# Set to false to disable registrations
allow_registration = boolean(default=True)
+# Set to true to only display media to logged-in users
+require_login = boolean(default=False)
+
# tag parsing
tags_max_length = integer(default=255)
diff --git a/mediagoblin/listings/views.py b/mediagoblin/listings/views.py
index 6e1528ca..0b0050eb 100644
--- a/mediagoblin/listings/views.py
+++ b/mediagoblin/listings/views.py
@@ -105,6 +105,9 @@ def atom_feed(request):
id=link,
links=atomlinks)
+ if mg_globals.app_config["require_login"] and not request.user:
+ return feed.get_response()
+
for entry in cursor:
# Include a thumbnail image in content.
file_urls = get_media_file_paths(entry.media_files, request.urlgen)
diff --git a/mediagoblin/templates/mediagoblin/user_pages/collection.html b/mediagoblin/templates/mediagoblin/user_pages/collection.html
index 71ba4451..171de887 100644
--- a/mediagoblin/templates/mediagoblin/user_pages/collection.html
+++ b/mediagoblin/templates/mediagoblin/user_pages/collection.html
@@ -56,6 +56,9 @@
<a class="button_action" href="{{ delete_url }}">{% trans %}Delete{% endtrans %}</a>
{% endif %}
+ {% if app_config['require_login'] and not request.user %}
+ {% include "mediagoblin/utils/require_login.html" %}
+ {% else %}
<p>
{% autoescape False %}
{{ collection.description_html }}
@@ -68,5 +71,6 @@
user=user.username,
collection=collection.slug ) %}
{% include "mediagoblin/utils/feed_link.html" %}
+ {% endif %}
{% endblock %}
diff --git a/mediagoblin/templates/mediagoblin/user_pages/collection_list.html b/mediagoblin/templates/mediagoblin/user_pages/collection_list.html
index 4b449c76..8081cb39 100644
--- a/mediagoblin/templates/mediagoblin/user_pages/collection_list.html
+++ b/mediagoblin/templates/mediagoblin/user_pages/collection_list.html
@@ -44,6 +44,9 @@
{% endif %}
{% endif %}
+ {% if app_config['require_login'] and not request.user %}
+ {% include "mediagoblin/utils/require_login.html" %}
+ {% else %}
<ul>
{% for coll in collections %}
{%- set coll_url = coll.url_for_self(request.urlgen) %}
@@ -52,5 +55,6 @@
</li>
{% endfor %}
</ul>
+ {% endif %}
{% endblock %}
diff --git a/mediagoblin/templates/mediagoblin/user_pages/media.html b/mediagoblin/templates/mediagoblin/user_pages/media.html
index 39a09d45..3ba125d9 100644
--- a/mediagoblin/templates/mediagoblin/user_pages/media.html
+++ b/mediagoblin/templates/mediagoblin/user_pages/media.html
@@ -36,6 +36,9 @@
{% template_hook("media_head") %}
{% endblock mediagoblin_head %}
{% block mediagoblin_content %}
+ {%- if app_config['require_login'] and not request.user %}
+ {% include "mediagoblin/utils/require_login.html" %}
+ {% else %}
<div class="row foot">
<p class="eleven columns context">
{%- trans user_url=request.urlgen(
@@ -245,4 +248,5 @@
</div><!--end media_sidebar-->
<div class="clear"></div>
+ {%- endif %}
{% endblock %}
diff --git a/mediagoblin/templates/mediagoblin/utils/object_gallery.html b/mediagoblin/templates/mediagoblin/utils/object_gallery.html
index a01cb3d5..2a3cddaa 100644
--- a/mediagoblin/templates/mediagoblin/utils/object_gallery.html
+++ b/mediagoblin/templates/mediagoblin/utils/object_gallery.html
@@ -56,16 +56,20 @@
#}
{% macro object_gallery(request, media_entries, pagination,
pagination_base_url=None, col_number=5) %}
- {% if media_entries and media_entries.count() %}
- {{ media_grid(request, media_entries, col_number=col_number) }}
- <div class="clear"></div>
- {% if pagination_base_url %}
- {# different url, so set that and don't keep the get params #}
- {{ render_pagination(request, pagination, pagination_base_url, False) }}
- {% else %}
- {{ render_pagination(request, pagination) }}
- {% endif %}
+
+ {% if app_config['require_login'] and not request.user %}
+ {% include "mediagoblin/utils/require_login.html" %}
{% else %}
+ {% if media_entries and media_entries.count() %}
+ {{ media_grid(request, media_entries, col_number=col_number) }}
+ <div class="clear"></div>
+ {% if pagination_base_url %}
+ {# different url, so set that and don't keep the get params #}
+ {{ render_pagination(request, pagination, pagination_base_url, False) }}
+ {% else %}
+ {{ render_pagination(request, pagination) }}
+ {% endif %}
+ {% else %}
<p>
<i>
{%- trans -%}
@@ -79,4 +83,5 @@
</a>
</p>
{% endif %}
+ {%- endif %}
{% endmacro %}
diff --git a/mediagoblin/templates/mediagoblin/utils/require_login.html b/mediagoblin/templates/mediagoblin/utils/require_login.html
new file mode 100644
index 00000000..72bf4c4a
--- /dev/null
+++ b/mediagoblin/templates/mediagoblin/utils/require_login.html
@@ -0,0 +1,8 @@
+<p><a href=
+ {% if persona_auth is defined %}
+ "javascript:;" id="persona_login"
+ {% else %}
+ "{{ request.urlgen('mediagoblin.auth.login') }}"
+ {% endif %}
+ >{%- trans %}Log in{% endtrans -%}
+ </a> to access media.</p>
diff --git a/mediagoblin/user_pages/views.py b/mediagoblin/user_pages/views.py
index 62a4f151..8f353682 100644
--- a/mediagoblin/user_pages/views.py
+++ b/mediagoblin/user_pages/views.py
@@ -577,6 +577,9 @@ def atom_feed(request):
user=request.matchdict['user']),
links=atomlinks)
+ if mg_globals.app_config["require_login"] and not request.user:
+ return feed.get_response()
+
for entry in cursor:
# Include a thumbnail image in content.
file_urls = get_media_file_paths(entry.media_files, request.urlgen)
@@ -655,6 +658,9 @@ def collection_atom_feed(request):
slug=collection.slug),
links=atomlinks)
+ if mg_globals.app_config["require_login"] and not request.user:
+ return feed.get_response()
+
for item in cursor:
obj = item.get_object()
feed.add(