Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Allow administrators to deactivate the guest users

Roland Geider0a8caec3763e
diff --git a/docs/changelog.rst b/docs/changelog.rst
index 6f3a1903d..5f8e8ef91 100644
--- a/docs/changelog.rst
+++ b/docs/changelog.rst
@@ -26,10 +26,11 @@ New languages:
New features:
* Add repetition (minutes, kilometer, etc.) and weight options (kg, lb, plates, until failure) to sets `#216`_ and `#217`_
+* Allow administrators to deactivate the guest user account `#330`_
* Much improved landing page (thanks `@DeveloperMal`_) `#307`_
-* Use the metricsgraphics library to more easily draw charts `#188`_
* Add extended PDF options to schedules as well (thanks `@alelevinas`_ ) `#272`_
* Show trained secondary muscles in workout view (thanks `@alokhan`_ ) `#282`_
+* Use the metricsgraphics library to more easily draw charts `#188`_
Improvements:
@@ -42,28 +43,24 @@ Improvements:
* Update to D3js v4 `#314`_, `#302`_
* Remove hard-coded CC licence from documentation and website `#247`_
-Other improvements and bugfixes: `#25`_, `#243`_, `#279`_, `#275`_, `#270`_, `#258`_, `#257`_,
-`#263`_, `#269`_, `#296`_, `#297`_, `#303`_, `#311`_, `#312`_, `#313`_,
-`#322`_, `#324`_, `#325`_
+Other improvements and bugfixes: `#25`_, `#243`_, `#279`_, `#275`_, `#270`_,
+`#258`_, `#257`_, `#263`_, `#269`_, `#296`_, `#297`_, `#303`_, `#311`_, `#312`_,
+`#313`_, `#322`_, `#324`_, `#325`_
.. _#25: https://github.com/wger-project/wger/issues/25
.. _#78: https://github.com/wger-project/wger/issues/78
.. _#79: https://github.com/wger-project/wger/issues/79
.. _#188: https://github.com/wger-project/wger/issues/188
+.. _#201: https://github.com/wger-project/wger/issues/201
.. _#216: https://github.com/wger-project/wger/issues/216
.. _#217: https://github.com/wger-project/wger/issues/217
.. _#243: https://github.com/wger-project/wger/issues/243
.. _#247: https://github.com/wger-project/wger/issues/247
-.. _#257: https://github.com/wger-project/wger/issues/257
-.. _#258: https://github.com/wger-project/wger/issues/258
.. _#263: https://github.com/wger-project/wger/issues/263
.. _#269: https://github.com/wger-project/wger/issues/269
-.. _#270: https://github.com/wger-project/wger/issues/270
.. _#272: https://github.com/wger-project/wger/issues/272
.. _#274: https://github.com/wger-project/wger/issues/274
-.. _#275: https://github.com/wger-project/wger/issues/275
-.. _#279: https://github.com/wger-project/wger/issues/279
.. _#282: https://github.com/wger-project/wger/issues/282
.. _#293: https://github.com/wger-project/wger/issues/293
.. _#296: https://github.com/wger-project/wger/issues/296
@@ -81,6 +78,7 @@ Other improvements and bugfixes: `#25`_, `#243`_, `#279`_, `#275`_, `#270`_, `#2
.. _#322: https://github.com/wger-project/wger/issues/322
.. _#324: https://github.com/wger-project/wger/issues/324
.. _#325: https://github.com/wger-project/wger/issues/325
+.. _#330: https://github.com/wger-project/wger/issues/330
.. _@petervanderdoes: https://github.com/petervanderdoes
.. _@DeveloperMal: https://github.com/DeveloperMal
.. _@alelevinas: https://github.com/alelevinas
diff --git a/docs/settings.rst b/docs/settings.rst
index 111d44614..542548f31 100644
--- a/docs/settings.rst
+++ b/docs/settings.rst
@@ -10,6 +10,10 @@ dictionary in your settings file. Currently the following options are supported:
Controls whether users can register on their own or if a gym adminstrator has
to create the user accounts.
+**ALLOW_GUEST_USERS**: Default ``True``.
+ Controls whether users can use the site as a guest user or if an administrator
+ has to create the user accounts, as with the option above.
+
**USE_RECAPTCHA**: Default ``False``.
Controls whether a captcha challenge will be presented when new users register.
diff --git a/wger/core/tests/test_registration.py b/wger/core/tests/test_registration.py
index 9f2ed89b8..cbf88ed52 100644
--- a/wger/core/tests/test_registration.py
+++ b/wger/core/tests/test_registration.py
@@ -37,6 +37,7 @@ class RegistrationTestCase(WorkoutManagerTestCase):
with self.settings(WGER_SETTINGS={'USE_RECAPTCHA': True,
'REMOVE_WHITESPACE': False,
'ALLOW_REGISTRATION': True,
+ 'ALLOW_GUEST_USERS': True,
'TWITTER': False}):
response = self.client.get(reverse('core:user:registration'))
self.assertIsInstance(response.context['form'], RegistrationForm)
@@ -44,6 +45,7 @@ class RegistrationTestCase(WorkoutManagerTestCase):
with self.settings(WGER_SETTINGS={'USE_RECAPTCHA': False,
'REMOVE_WHITESPACE': False,
'ALLOW_REGISTRATION': True,
+ 'ALLOW_GUEST_USERS': True,
'TWITTER': False}):
response = self.client.get(reverse('core:user:registration'))
self.assertIsInstance(response.context['form'], RegistrationFormNoCaptcha)
@@ -97,6 +99,7 @@ class RegistrationTestCase(WorkoutManagerTestCase):
with self.settings(WGER_SETTINGS={'USE_RECAPTCHA': False,
'REMOVE_WHITESPACE': False,
+ 'ALLOW_GUEST_USERS': True,
'ALLOW_REGISTRATION': False}):
# Fetch the registration page
diff --git a/wger/core/tests/test_temporary_users.py b/wger/core/tests/test_temporary_users.py
index 56138a707..9c9db25d6 100644
--- a/wger/core/tests/test_temporary_users.py
+++ b/wger/core/tests/test_temporary_users.py
@@ -19,14 +19,13 @@ from django.contrib.auth.models import User
from django.core.management import call_command
from django.core.urlresolvers import reverse
-from wger.core.demo import create_demo_entries
-from wger.core.demo import create_temporary_user
+from wger.core.demo import create_demo_entries, create_temporary_user
from wger.core.tests.base_testcase import WorkoutManagerTestCase
-from wger.manager.models import Day
-from wger.manager.models import Schedule
-from wger.manager.models import ScheduleStep
-from wger.manager.models import Workout
-from wger.manager.models import WorkoutLog
+from wger.manager.models import (Day,
+ Schedule,
+ ScheduleStep,
+ Workout,
+ WorkoutLog)
from wger.nutrition.models import Meal
from wger.nutrition.models import NutritionPlan
from wger.weight.models import WeightEntry
@@ -44,7 +43,23 @@ class DemoUserTestCase(WorkoutManagerTestCase):
'''
return User.objects.filter(userprofile__is_temporary=1).count()
- def test_demo_data(self):
+ def test_demo_data_no_guest_account(self):
+ '''
+ Tests that the helper function creates demo data (workout, etc.)
+ for the demo users
+ '''
+ with self.settings(WGER_SETTINGS={'USE_RECAPTCHA': True,
+ 'REMOVE_WHITESPACE': False,
+ 'ALLOW_REGISTRATION': True,
+ 'ALLOW_GUEST_USERS': False,
+ 'TWITTER': False}):
+ self.assertEqual(self.count_temp_users(), 1)
+ self.client.get(reverse('core:dashboard'))
+ self.assertEqual(self.count_temp_users(), 1)
+ self.client.get(reverse('core:user:demo-entries'))
+ self.assertEqual(self.count_temp_users(), 1)
+
+ def test_demo_data_guest_account(self):
'''
Tests that the helper function creates demo data (workout, etc.)
for the demo users
@@ -55,7 +70,7 @@ class DemoUserTestCase(WorkoutManagerTestCase):
self.assertEqual(user.userprofile.is_temporary, True)
self.assertEqual(Workout.objects.filter(user=user).count(), 0)
- create_demo_entries(user)
+ self.client.get(reverse('core:user:demo-entries'))
# Workout
self.assertEqual(Workout.objects.filter(user=user).count(), 4)
self.assertEqual(Day.objects.filter(training__user=user).count(), 2)
diff --git a/wger/core/views/misc.py b/wger/core/views/misc.py
index 8e7151d9a..ce242ab37 100644
--- a/wger/core/views/misc.py
+++ b/wger/core/views/misc.py
@@ -16,6 +16,7 @@
import logging
+from django.conf import settings
from django.shortcuts import render
from django.http import HttpResponseRedirect
from django.core.exceptions import ObjectDoesNotExist
@@ -59,6 +60,9 @@ def demo_entries(request):
'''
Creates a set of sample entries for guest users
'''
+ if not settings.WGER_SETTINGS['ALLOW_GUEST_USERS']:
+ return HttpResponseRedirect(reverse('software:features'))
+
if (((not request.user.is_authenticated() or request.user.userprofile.is_temporary)
and not request.session['has_demo_data'])):
# If we reach this from a page that has no user created by the
diff --git a/wger/settings_global.py b/wger/settings_global.py
index ef5c3639d..1b681065e 100644
--- a/wger/settings_global.py
+++ b/wger/settings_global.py
@@ -362,10 +362,13 @@ IGNORABLE_404_URLS = (
#
# Application specific configuration options
#
+# Consult docs/settings.rst for more information
+#
WGER_SETTINGS = {
'USE_RECAPTCHA': False,
'REMOVE_WHITESPACE': False,
'ALLOW_REGISTRATION': True,
+ 'ALLOW_GUEST_USERS': True,
'EMAIL_FROM': 'wger Workout Manager <[email protected]>',
'TWITTER': False
}
diff --git a/wger/software/templates/features.html b/wger/software/templates/features.html
index 613107e75..a8543f9fe 100644
--- a/wger/software/templates/features.html
+++ b/wger/software/templates/features.html
@@ -26,7 +26,7 @@
<div class="intro-lead-in">{% trans "Your workouts." %}</div>
<div class="intro-lead-in">{% trans "Your data." %}</div>
<div class="intro-lead-in">{% trans "Your progress." %}</div>
- {% if not user.is_authenticated %}
+ {% if allow_guest_users and not user.is_authenticated %}
<a href="{% url 'core:user:demo-entries' %}" class="page-scroll btn btn-xl">{% trans "Try it now" %}</a>
{% endif %}
diff --git a/wger/software/views.py b/wger/software/views.py
index 5da21afb0..472e3d60a 100644
--- a/wger/software/views.py
+++ b/wger/software/views.py
@@ -28,5 +28,6 @@ def features(request):
Render the features page
'''
- context = {'allow_registration': settings.WGER_SETTINGS['ALLOW_REGISTRATION']}
+ context = {'allow_registration': settings.WGER_SETTINGS['ALLOW_REGISTRATION'],
+ 'allow_guest_users': settings.WGER_SETTINGS['ALLOW_GUEST_USERS']}
return render(request, 'features.html', context)
diff --git a/wger/utils/middleware.py b/wger/utils/middleware.py
index 85c7ad8b1..9083f6ea5 100644
--- a/wger/utils/middleware.py
+++ b/wger/utils/middleware.py
@@ -18,6 +18,7 @@ Custom middleware
import logging
+from django.conf import settings
from django.contrib import auth
from django.utils.functional import SimpleLazyObject
from django.contrib.auth import login as django_login
@@ -61,7 +62,9 @@ def get_user(request):
request.session['has_demo_data'] = False
# Django didn't find a user, so create one now
- if request.method == 'GET' and create_user and not user.is_authenticated():
+ if settings.WGER_SETTINGS['ALLOW_GUEST_USERS'] and \
+ request.method == 'GET' and \
+ create_user and not user.is_authenticated():
logger.debug('creating a new guest user now')
user = create_temporary_user()