Allow administrators to deactivate the guest users

This can be interesting in instances where the administrator has to create the
user accounts. Fixes #330
This commit is contained in:
Roland Geider
2016-09-20 22:58:14 +02:00
parent de3628cebd
commit 0a8caec376
9 changed files with 52 additions and 21 deletions

View File

@@ -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

View File

@@ -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.

View File

@@ -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

View File

@@ -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)

View File

@@ -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

View File

@@ -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 <wger@example.com>',
'TWITTER': False
}

View File

@@ -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 %}

View File

@@ -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)

View File

@@ -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()