Skip to content
This repository has been archived by the owner on Aug 26, 2022. It is now read-only.

Commit

Permalink
Merge pull request #3091 from groovecoder/waffle-signup-1124419
Browse files Browse the repository at this point in the history
bug 1124419 - waffle user signup
  • Loading branch information
openjck committed Feb 25, 2015
2 parents c4e8337 + a347fa4 commit d60c880
Show file tree
Hide file tree
Showing 6 changed files with 110 additions and 12 deletions.
65 changes: 65 additions & 0 deletions docs/feature-toggles.rst
@@ -0,0 +1,65 @@
Feature Toggles
===============

MDN uses `feature toggles`_ to integrate un-finished feature changes as early
as possible, and to control the behavior of finished features.

Some site features are controlled using `django-waffle`_. You control these
features in the django admin site's `waffle section`_.

Some site features are controlled using `constance`_. You control these
features in the django admin site's `constance section`_.

Waffle Features
---------------

Switches
~~~~~~~~

`Waffle switches`_ are simple booleans - they are either on or off.

* ``welcome_email`` - send welcome email to new user registrations
* ``wiki_force_immediate_rendering`` - force wiki pages to render immediately in
the same http request in which they are saved (not in a background process)
* ``wiki_error_on_delete`` - throw an error if a user tries to delete a page
* ``render_stale_document_async`` - render stale documents in a background
sub-task

Flags
~~~~~

`Waffle flags`_ control behavior by specific users, groups, percentages, and
other advanced criteria.

* ``events_map`` - show the map on the events page
* ``search_explanation`` - show search results scoring details
* ``search_doc_navigator`` - show the search doc navigator feature
* ``search_drilldown_faceting`` - treat search filters as "drill-down" filters
- i.e., combine them with "AND" logic
* ``search_suggestions`` - show the advanced search filter suggestions
interface
* ``registration_disabled`` - enable/disable new user registration
* ``social_account_research`` - enable/disable social account research on the
"Sign in to Edit" page
* ``github_login`` - enable/disable sign in via github
* ``kumaediting`` - enable/disable wiki editing
* ``kumabanned`` - (deprecated) added to users to mark them as banned
* ``enable_customcss`` - enable/disable Template:CustomCSS styles in wiki pages
* ``top_contributors`` - enable/disable the "Top Contributors" feature on wiki
pages
* ``page_move`` - enable/disable page move feature

Constance Features
------------------

Constance configs let us set operational *values* for certain features in the
database - so we can control them without changing code. They are all listed
and documented in the admin site's `constance section`_.

.. _feature toggles: https://en.wikipedia.org/wiki/Feature_toggle
.. _django-waffle: http://waffle.readthedocs.org/en/latest/
.. _waffle section: https://developer-local.allizom.org/admin/waffle/
.. _constance: https://github.com/comoga/django-constance
.. _constance section: https://developer-local.allizom.org/admin/constance/config/
.. _Waffle switches: http://waffle.readthedocs.org/en/latest/types/switch.html
.. _Waffle flags: http://waffle.readthedocs.org/en/latest/types/flag.html
1 change: 1 addition & 0 deletions docs/index.rst
Expand Up @@ -15,6 +15,7 @@ Contents:

development
migrations
feature-toggles
localization
ckeditor
tests
Expand Down
10 changes: 2 additions & 8 deletions docs/installation-vagrant.rst
Expand Up @@ -105,14 +105,8 @@ You will want to make yourself an admin user to enable important site features.

Enable Important Site Features
------------------------------

Some site features are controlled using `django-waffle <http://waffle.readthedocs.org/en/latest/>`_.
You control these features in the `waffle admin
<https://developer-local.allizom.org/admin/waffle/>`_.

Some site features are controlled using `constance
<https://github.com/comoga/django-constance>`_. You control these features in
the `constance config admin panel`_.
You'll need to use :doc:`feature toggles <feature-toggles>` to enable some
basic features.

.. _GitHub Auth:

Expand Down
4 changes: 3 additions & 1 deletion kuma/users/adapters.py
Expand Up @@ -10,6 +10,7 @@
from allauth.socialaccount.adapter import DefaultSocialAccountAdapter
from allauth.socialaccount.models import SocialLogin
from tower import ugettext_lazy as _
from waffle import flag_is_active

from kuma.core.urlresolvers import reverse

Expand Down Expand Up @@ -103,7 +104,8 @@ def is_open_for_signup(self, request, sociallogin):
because the default adapter uses the account adpater above
as the default.
"""
return True
# Check if profile creation is disabled via waffle
return not flag_is_active(request, 'registration_disabled')

def validate_disconnect(self, account, accounts):
"""
Expand Down
6 changes: 3 additions & 3 deletions kuma/users/templates/account/signup_closed.html
@@ -1,12 +1,12 @@
{% extends "account/base.html" %}

{% block title %}{{ page_title(_("Sign Up Closed")) }}{% endblock %}
{% block title %}{{ page_title(_("Profile Creation Disabled")) }}{% endblock %}

{% block content %}
<div class="text-content readable-line-length">
<h1>{{ _("Sign Up Closed") }}</h1>
<h1>{{ _("Profile Creation Disabled") }}</h1>

<p>{{ _("We are sorry, but the sign up is currently closed.") }}</p>
<p>{{ _("We are sorry, but profile creation is currently disabled.") }}</p>
</div>
{% endblock %}

Expand Down
36 changes: 36 additions & 0 deletions kuma/users/tests/test_templates.py
@@ -1,6 +1,7 @@
import mock
from nose.tools import eq_, ok_
from pyquery import PyQuery as pq
from waffle import Flag

from django.conf import settings
from django.contrib.auth.models import User
Expand Down Expand Up @@ -40,6 +41,41 @@ def test_signup_page(self, mock_post):
verify_strings_in_response(test_strings, r)


@mock.patch('requests.post')
def test_signup_page_disabled(self, mock_post):
user_email = "newuser@test.com"
mock_post.return_value = mock_resp = mock.Mock()
mock_resp.json.return_value = {
"status": "okay",
"email": user_email,
"audience": "https://developer-local.allizom.org"
}

url = reverse('persona_login')

registration_disabled = Flag.objects.create(
name='registration_disabled',
everyone=True
)
r = self.client.post(url, follow=True)

eq_(200, r.status_code)
ok_('Sign In Failure' not in r.content)
test_strings = ['Sign Up Closed']
verify_strings_in_response(test_strings, r)

# re-enable registration
registration_disabled.everyone = False
registration_disabled.save()

r = self.client.post(url, follow=True)
eq_(200, r.status_code)
test_strings = ['Create your MDN profile to continue',
'choose a username',
'having trouble']
verify_strings_in_response(test_strings, r)


class AccountEmailTests(UserTestCase):
localizing_client = True

Expand Down

0 comments on commit d60c880

Please sign in to comment.