Skip to content

Commit

Permalink
Allow administrators to deactivate the guest users
Browse files Browse the repository at this point in the history
This can be interesting in instances where the administrator has to create the
user accounts. Fixes #330
  • Loading branch information
rolandgeider committed Sep 20, 2016
1 parent de3628c commit 0a8caec
Show file tree
Hide file tree
Showing 9 changed files with 52 additions and 21 deletions.
16 changes: 7 additions & 9 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand All @@ -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
Expand All @@ -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
Expand Down
4 changes: 4 additions & 0 deletions docs/settings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
3 changes: 3 additions & 0 deletions wger/core/tests/test_registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,15 @@ def test_registration_captcha(self):
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)

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)
Expand Down Expand Up @@ -97,6 +99,7 @@ def test_registration_deactivated(self):

with self.settings(WGER_SETTINGS={'USE_RECAPTCHA': False,
'REMOVE_WHITESPACE': False,
'ALLOW_GUEST_USERS': True,
'ALLOW_REGISTRATION': False}):

# Fetch the registration page
Expand Down
33 changes: 24 additions & 9 deletions wger/core/tests/test_temporary_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,13 @@
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
Expand All @@ -44,7 +43,23 @@ def count_temp_users():
'''
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
Expand All @@ -55,7 +70,7 @@ def test_demo_data(self):
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)
Expand Down
4 changes: 4 additions & 0 deletions wger/core/views/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions wger/settings_global.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,10 +362,13 @@
#
# 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
}
2 changes: 1 addition & 1 deletion wger/software/templates/features.html
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}

Expand Down
3 changes: 2 additions & 1 deletion wger/software/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
5 changes: 4 additions & 1 deletion wger/utils/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

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
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 0a8caec

Please sign in to comment.