├── tests ├── __init__.py ├── basic │ ├── __init__.py │ └── tests.py ├── allauth │ ├── __init__.py │ └── test_allauth.py ├── migrations │ ├── __init__.py │ └── 0001_initial.py ├── models.py ├── test_migrations.py └── conftest.py ├── invitations ├── __init__.py ├── management │ ├── __init__.py │ └── commands │ │ ├── __init__.py │ │ └── clear_expired_invitations.py ├── migrations │ ├── __init__.py │ ├── 0003_auto_20151126_1523.py │ ├── 0004_auto_20230328_1430.py │ ├── 0005_alter_invitation_inviter.py │ ├── 0002_auto_20151126_0426.py │ └── 0001_initial.py ├── locale │ ├── de │ │ └── LC_MESSAGES │ │ │ ├── django.mo │ │ │ └── django.po │ ├── fr │ │ └── LC_MESSAGES │ │ │ ├── django.mo │ │ │ └── django.po │ ├── ru │ │ └── LC_MESSAGES │ │ │ ├── django.mo │ │ │ └── django.po │ ├── uk │ │ └── LC_MESSAGES │ │ │ ├── django.mo │ │ │ └── django.po │ └── pt_BR │ │ └── LC_MESSAGES │ │ ├── django.mo │ │ └── django.po ├── templates │ └── invitations │ │ ├── email │ │ ├── email_invite_subject.txt │ │ └── email_invite_message.txt │ │ ├── messages │ │ ├── invite_expired.txt │ │ ├── invite_invalid.txt │ │ ├── invite_accepted.txt │ │ └── invite_already_accepted.txt │ │ └── forms │ │ └── _invite.html ├── apps.py ├── exceptions.py ├── signals.py ├── urls.py ├── managers.py ├── admin.py ├── base_invitation.py ├── utils.py ├── forms.py ├── models.py ├── app_settings.py ├── adapters.py └── views.py ├── .coveragerc ├── docs ├── requirements.txt ├── Makefile ├── index.rst ├── contributing.rst ├── installation.rst ├── conf.py ├── usage.rst ├── configuration.rst └── changelog.rst ├── .gitignore ├── test_urls.py ├── .readthedocs.yaml ├── Makefile ├── manage.py ├── .editorconfig ├── test_allauth_settings.py ├── .github └── workflows │ ├── test.yml │ ├── release.yml │ └── codeql.yml ├── tox.ini ├── README.md ├── setup.cfg ├── test_settings.py ├── .pre-commit-config.yaml ├── pyproject.toml ├── CONTRIBUTING.md ├── CHANGELOG.md └── LICENSE /tests/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /invitations/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/basic/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/allauth/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tests/migrations/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /invitations/management/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /invitations/migrations/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /invitations/management/commands/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.coveragerc: -------------------------------------------------------------------------------- 1 | [run] 2 | include = invitations* 3 | -------------------------------------------------------------------------------- /docs/requirements.txt: -------------------------------------------------------------------------------- 1 | django 2 | furo 3 | sphinx 4 | tomlkit 5 | -------------------------------------------------------------------------------- /invitations/locale/de/LC_MESSAGES/django.mo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jazzband/django-invitations/master/invitations/locale/de/LC_MESSAGES/django.mo -------------------------------------------------------------------------------- /invitations/locale/fr/LC_MESSAGES/django.mo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jazzband/django-invitations/master/invitations/locale/fr/LC_MESSAGES/django.mo -------------------------------------------------------------------------------- /invitations/locale/ru/LC_MESSAGES/django.mo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jazzband/django-invitations/master/invitations/locale/ru/LC_MESSAGES/django.mo -------------------------------------------------------------------------------- /invitations/locale/uk/LC_MESSAGES/django.mo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jazzband/django-invitations/master/invitations/locale/uk/LC_MESSAGES/django.mo -------------------------------------------------------------------------------- /invitations/locale/pt_BR/LC_MESSAGES/django.mo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jazzband/django-invitations/master/invitations/locale/pt_BR/LC_MESSAGES/django.mo -------------------------------------------------------------------------------- /invitations/templates/invitations/email/email_invite_subject.txt: -------------------------------------------------------------------------------- 1 | {% load i18n %} 2 | {% autoescape off %} 3 | {% blocktrans %}Invitation to join {{ site_name }}{% endblocktrans %} 4 | {% endautoescape %} 5 | -------------------------------------------------------------------------------- /invitations/templates/invitations/messages/invite_expired.txt: -------------------------------------------------------------------------------- 1 | {% load i18n %} 2 | {% autoescape off %} 3 | {% blocktrans %}The invitation for {{ email }} has expired.{% endblocktrans %} 4 | {% endautoescape %} 5 | -------------------------------------------------------------------------------- /invitations/templates/invitations/messages/invite_invalid.txt: -------------------------------------------------------------------------------- 1 | {% load i18n %} 2 | {% autoescape off %} 3 | {% blocktrans %}An invalid invitation key was submitted.{% endblocktrans %} 4 | {% endautoescape %} 5 | -------------------------------------------------------------------------------- /invitations/templates/invitations/messages/invite_accepted.txt: -------------------------------------------------------------------------------- 1 | {% load i18n %} 2 | {% autoescape off %} 3 | {% blocktrans %}Invitation to - {{ email }} - has been accepted{% endblocktrans %} 4 | {% endautoescape %} 5 | -------------------------------------------------------------------------------- /invitations/templates/invitations/messages/invite_already_accepted.txt: -------------------------------------------------------------------------------- 1 | {% load i18n %} 2 | {% autoescape off %} 3 | {% blocktrans %}The invitation for {{ email }} was already accepted.{% endblocktrans %} 4 | {% endautoescape %} 5 | -------------------------------------------------------------------------------- /tests/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | 3 | from invitations.models import Invitation 4 | 5 | 6 | class ExampleSwappableInvitation(Invitation): 7 | additonal_field = models.CharField(max_length=255, blank=True) 8 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | *.pyc 3 | *.py~ 4 | .tox/ 5 | dist/ 6 | .cache/ 7 | .coverage/ 8 | django_invitations.egg-info/ 9 | .gitchangelog.rc 10 | git-push.bat 11 | .python-version 12 | .coverage 13 | /.idea/ 14 | docs/_build/ 15 | -------------------------------------------------------------------------------- /invitations/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class Config(AppConfig): 5 | """Config.""" 6 | 7 | default_auto_field = "django.db.models.BigAutoField" 8 | name = "invitations" 9 | label = "invitations" 10 | -------------------------------------------------------------------------------- /invitations/templates/invitations/email/email_invite_message.txt: -------------------------------------------------------------------------------- 1 | {% load i18n %} 2 | {% autoescape off %} 3 | {% blocktrans %} 4 | 5 | Hello, 6 | 7 | You ({{ email }}) have been invited to join {{ site_name }} 8 | 9 | If you'd like to join, please go to {{ invite_url }} 10 | 11 | {% endblocktrans %} 12 | {% endautoescape %} 13 | -------------------------------------------------------------------------------- /invitations/management/commands/clear_expired_invitations.py: -------------------------------------------------------------------------------- 1 | from django.core.management.base import BaseCommand 2 | 3 | from ...utils import get_invitation_model 4 | 5 | Invitation = get_invitation_model() 6 | 7 | 8 | class Command(BaseCommand): 9 | def handle(self, *args, **options): 10 | Invitation.objects.delete_expired_confirmations() 11 | -------------------------------------------------------------------------------- /invitations/exceptions.py: -------------------------------------------------------------------------------- 1 | class AlreadyInvited(Exception): 2 | """User has a valid, pending invitation""" 3 | 4 | pass 5 | 6 | 7 | class AlreadyAccepted(Exception): 8 | """User has already accepted an invitation""" 9 | 10 | pass 11 | 12 | 13 | class UserRegisteredEmail(Exception): 14 | """This email is already registered by a site user""" 15 | 16 | pass 17 | -------------------------------------------------------------------------------- /test_urls.py: -------------------------------------------------------------------------------- 1 | from django.conf import settings 2 | from django.contrib import admin 3 | from django.urls import include, path 4 | 5 | admin.autodiscover() 6 | 7 | urlpatterns = [ 8 | path("invitations/", include("invitations.urls")), 9 | path("admin/", admin.site.urls), 10 | ] 11 | 12 | if "allauth" in settings.INSTALLED_APPS: 13 | urlpatterns.append(path("accounts/", include("allauth.urls"))) 14 | -------------------------------------------------------------------------------- /invitations/signals.py: -------------------------------------------------------------------------------- 1 | from django.dispatch import Signal 2 | 3 | invite_url_sent = Signal() 4 | invite_accepted = Signal() 5 | 6 | """ 7 | @receiver(invite_url_sent, sender=Invitation) 8 | def invite_url_sent(sender, instance, invite_url_sent, inviter, **kwargs): 9 | pass 10 | 11 | @receiver(invite_accepted, sender=Invitation) 12 | def handle_invite_accepted(sender, email, **kwargs): 13 | pass 14 | """ 15 | -------------------------------------------------------------------------------- /.readthedocs.yaml: -------------------------------------------------------------------------------- 1 | # .readthedocs.yaml 2 | # Read the Docs configuration file 3 | # See https://docs.readthedocs.io/en/stable/config-file/v2.html for details 4 | version: 2 5 | 6 | build: 7 | os: ubuntu-20.04 8 | tools: 9 | python: "3.11" 10 | 11 | sphinx: 12 | configuration: docs/conf.py 13 | 14 | python: 15 | install: 16 | - requirements: docs/requirements.txt 17 | - method: pip 18 | path: . 19 | -------------------------------------------------------------------------------- /tests/test_migrations.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | from django.core.management import call_command 3 | 4 | 5 | class TestMigrations: 6 | @pytest.mark.django_db 7 | def test_all_necessary_migrations_created(self): 8 | try: 9 | call_command("makemigrations", "--check", "--dry-run") 10 | all_necessary_migrations_created = True 11 | except SystemExit: 12 | all_necessary_migrations_created = False 13 | assert all_necessary_migrations_created 14 | -------------------------------------------------------------------------------- /invitations/urls.py: -------------------------------------------------------------------------------- 1 | from django.urls import path, re_path 2 | 3 | from . import views 4 | 5 | app_name = "invitations" 6 | urlpatterns = [ 7 | path("send-invite/", views.SendInvite.as_view(), name="send-invite"), 8 | path( 9 | "send-json-invite/", 10 | views.SendJSONInvite.as_view(), 11 | name="send-json-invite", 12 | ), 13 | re_path( 14 | r"^accept-invite/(?P\w+)/?$", 15 | views.AcceptInvite.as_view(), 16 | name="accept-invite", 17 | ), 18 | ] 19 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # You may wish to run this file under poetry's virtual environment, like this: 2 | # 3 | # poetry run make 4 | 5 | .DEFAULT_GOAL := mo 6 | .PHONY: po mo clean 7 | 8 | 9 | # Update .po files, used for translation 10 | po: 11 | cd invitations && python ../manage.py makemessages -a --no-wrap 12 | 13 | # Compile .mo files, used for translation 14 | mo: po 15 | cd invitations && python ../manage.py compilemessages 16 | 17 | # Clean files that are compiled by this Makefile 18 | clean: 19 | rm -f invitations/locale/*/LC_MESSAGES/*.mo 20 | -------------------------------------------------------------------------------- /invitations/migrations/0003_auto_20151126_1523.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | from __future__ import unicode_literals 3 | 4 | import django.db.models.deletion 5 | from django.conf import settings 6 | from django.db import migrations, models 7 | 8 | 9 | class Migration(migrations.Migration): 10 | 11 | dependencies = [ 12 | ('invitations', '0002_auto_20151126_0426'), 13 | ] 14 | 15 | operations = [ 16 | migrations.AlterField( 17 | model_name='invitation', 18 | name='inviter', 19 | field=models.ForeignKey(blank=True, to=settings.AUTH_USER_MODEL, null=True, on_delete=django.db.models.deletion.CASCADE), 20 | ), 21 | ] 22 | -------------------------------------------------------------------------------- /docs/Makefile: -------------------------------------------------------------------------------- 1 | # Minimal makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line, and also 5 | # from the environment for the first two. 6 | SPHINXOPTS ?= "-W" 7 | SPHINXBUILD ?= sphinx-build 8 | SOURCEDIR = . 9 | BUILDDIR = _build 10 | 11 | # Put it first so that "make" without argument is like "make help". 12 | help: 13 | @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 14 | 15 | .PHONY: help Makefile 16 | 17 | # Catch-all target: route all unknown targets to Sphinx using the new 18 | # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). 19 | %: Makefile 20 | @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 21 | -------------------------------------------------------------------------------- /invitations/managers.py: -------------------------------------------------------------------------------- 1 | from datetime import timedelta 2 | 3 | from django.db import models 4 | from django.db.models import Q 5 | from django.utils import timezone 6 | 7 | from .app_settings import app_settings 8 | 9 | 10 | class BaseInvitationManager(models.Manager): 11 | def all_expired(self): 12 | return self.filter(self.expired_q()) 13 | 14 | def all_valid(self): 15 | return self.exclude(self.expired_q()) 16 | 17 | def expired_q(self): 18 | sent_threshold = timezone.now() - timedelta(days=app_settings.INVITATION_EXPIRY) 19 | q = Q(accepted=True) | Q(sent__lt=sent_threshold) 20 | return q 21 | 22 | def delete_expired_confirmations(self): 23 | self.all_expired().delete() 24 | -------------------------------------------------------------------------------- /manage.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """Django's command-line utility for administrative tasks.""" 3 | import os 4 | import sys 5 | 6 | 7 | def main(): 8 | """Run administrative tasks.""" 9 | os.environ.setdefault("DJANGO_SETTINGS_MODULE", "test_settings") 10 | try: 11 | from django.core.management import execute_from_command_line 12 | except ImportError as exc: 13 | raise ImportError( 14 | "Couldn't import Django. Are you sure it's installed and " 15 | "available on your PYTHONPATH environment variable? Did you " 16 | "forget to activate a virtual environment?", 17 | ) from exc 18 | execute_from_command_line(sys.argv) 19 | 20 | 21 | if __name__ == "__main__": 22 | main() 23 | -------------------------------------------------------------------------------- /docs/index.rst: -------------------------------------------------------------------------------- 1 | django-invitations documentation 2 | ================================ 3 | 4 | Generic invitations solution with adaptable backend and support for django-allauth. All emails and messages are fully customisable. 5 | 6 | Originally written as an invitations solution for the excellent `django-allauth `_, this app has been refactored to remove the allauth dependency whilst retaining 100% backwards compatibility. 7 | 8 | .. toctree:: 9 | :maxdepth: 2 10 | :caption: Contents: 11 | 12 | installation 13 | usage 14 | configuration 15 | contributing 16 | changelog 17 | 18 | 19 | Indices and tables 20 | ================== 21 | 22 | * :ref:`genindex` 23 | * :ref:`modindex` 24 | * :ref:`search` 25 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | 2 | # top-most EditorConfig file 3 | root = true 4 | 5 | # Unix-style newlines with a newline ending every file 6 | [*] 7 | end_of_line = lf 8 | insert_final_newline = true 9 | 10 | # Matches multiple files with brace expansion notation 11 | # Set default charset 12 | [*.{js,py}] 13 | charset = utf-8 14 | 15 | # 4 space indentation 16 | [*.py] 17 | indent_style = space 18 | indent_size = 4 19 | 20 | # Tab indentation (no size specified) 21 | [Makefile] 22 | indent_style = tab 23 | 24 | # Indentation override for all JS under lib directory 25 | [lib/**.js] 26 | indent_style = space 27 | indent_size = 2 28 | 29 | # Matches the exact files either package.json or .travis.yml 30 | [{package.json,.travis.yml}] 31 | indent_style = space 32 | indent_size = 2 33 | -------------------------------------------------------------------------------- /test_allauth_settings.py: -------------------------------------------------------------------------------- 1 | from test_settings import * # noqa: F403 2 | 3 | INSTALLED_APPS = ( 4 | "django.contrib.auth", 5 | "django.contrib.admin", 6 | "django.contrib.contenttypes", 7 | "django.contrib.sessions", 8 | "django.contrib.sites", 9 | "django.contrib.messages", 10 | "allauth", 11 | "allauth.account", 12 | "allauth.socialaccount", 13 | "invitations", 14 | "tests", 15 | ) 16 | 17 | AUTHENTICATION_BACKENDS = ( 18 | "django.contrib.auth.backends.ModelBackend", 19 | "allauth.account.auth_backends.AuthenticationBackend", 20 | ) 21 | 22 | ACCOUNT_ADAPTER = "invitations.models.InvitationsAdapter" 23 | 24 | MIDDLEWARE.append("allauth.account.middleware.AccountMiddleware") # noqa: F405 25 | 26 | STATIC_URL = "" 27 | -------------------------------------------------------------------------------- /invitations/templates/invitations/forms/_invite.html: -------------------------------------------------------------------------------- 1 | {% load i18n %} 2 | 3 |

{% trans "Invite" %}

4 | {% trans "Please add an email below. The user will receive an email with instructions." %} 5 | 6 |
7 | {% csrf_token %} 8 |
9 | 10 |
11 |
12 | {% for error in form.email.errors %} 13 |
{{ error }}
14 | {% endfor %} 15 | {{ success_message }} 16 |
17 | 18 |
19 | -------------------------------------------------------------------------------- /invitations/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | 3 | from .utils import ( 4 | get_invitation_admin_add_form, 5 | get_invitation_admin_change_form, 6 | get_invitation_model, 7 | ) 8 | 9 | Invitation = get_invitation_model() 10 | InvitationAdminAddForm = get_invitation_admin_add_form() 11 | InvitationAdminChangeForm = get_invitation_admin_change_form() 12 | 13 | 14 | @admin.register(Invitation) 15 | class InvitationAdmin(admin.ModelAdmin): 16 | list_display = ("email", "sent", "accepted") 17 | autocomplete_fields = ["inviter"] 18 | 19 | def get_form(self, request, obj=None, **kwargs): 20 | if obj: 21 | kwargs["form"] = InvitationAdminChangeForm 22 | else: 23 | kwargs["form"] = InvitationAdminAddForm 24 | kwargs["form"].user = request.user 25 | kwargs["form"].request = request 26 | return super().get_form(request, obj, **kwargs) 27 | -------------------------------------------------------------------------------- /invitations/migrations/0004_auto_20230328_1430.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 3.2.15 on 2023-03-28 14:30 2 | 3 | from django.conf import settings 4 | from django.db import migrations, models 5 | import django.db.models.deletion 6 | 7 | 8 | class Migration(migrations.Migration): 9 | 10 | dependencies = [ 11 | migrations.swappable_dependency(settings.AUTH_USER_MODEL), 12 | ('invitations', '0003_auto_20151126_1523'), 13 | ] 14 | 15 | operations = [ 16 | migrations.AlterField( 17 | model_name='invitation', 18 | name='id', 19 | field=models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'), 20 | ), 21 | migrations.AlterField( 22 | model_name='invitation', 23 | name='inviter', 24 | field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL, verbose_name='inviter'), 25 | ), 26 | ] 27 | -------------------------------------------------------------------------------- /invitations/migrations/0005_alter_invitation_inviter.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 4.2.13 on 2024-06-13 12:44 2 | 3 | from django.conf import settings 4 | from django.db import migrations, models 5 | import django.db.models.deletion 6 | 7 | 8 | class Migration(migrations.Migration): 9 | 10 | dependencies = [ 11 | migrations.swappable_dependency(settings.AUTH_USER_MODEL), 12 | ("invitations", "0004_auto_20230328_1430"), 13 | ] 14 | 15 | operations = [ 16 | migrations.AlterField( 17 | model_name="invitation", 18 | name="inviter", 19 | field=models.ForeignKey( 20 | blank=True, 21 | null=True, 22 | on_delete=django.db.models.deletion.CASCADE, 23 | related_name="%(app_label)s_%(class)ss", 24 | related_query_name="%(app_label)s_%(class)s", 25 | to=settings.AUTH_USER_MODEL, 26 | verbose_name="inviter", 27 | ), 28 | ), 29 | ] 30 | -------------------------------------------------------------------------------- /invitations/migrations/0002_auto_20151126_0426.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | from __future__ import unicode_literals 3 | 4 | import django.db.models.deletion 5 | from django.conf import settings 6 | from django.db import migrations, models 7 | 8 | EMAIL_MAX_LENGTH = getattr(settings, 'INVITATIONS_EMAIL_MAX_LENGTH', 254) 9 | 10 | 11 | 12 | class Migration(migrations.Migration): 13 | 14 | dependencies = [ 15 | migrations.swappable_dependency(settings.AUTH_USER_MODEL), 16 | ('invitations', '0001_initial'), 17 | ] 18 | 19 | operations = [ 20 | migrations.AddField( 21 | model_name='invitation', 22 | name='inviter', 23 | field=models.ForeignKey(to=settings.AUTH_USER_MODEL, null=True, on_delete=django.db.models.deletion.CASCADE), 24 | ), 25 | migrations.AlterField( 26 | model_name='invitation', 27 | name='email', 28 | field=models.EmailField(unique=True, max_length=EMAIL_MAX_LENGTH, verbose_name='e-mail address'), 29 | ), 30 | ] 31 | -------------------------------------------------------------------------------- /invitations/migrations/0001_initial.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | from __future__ import unicode_literals 3 | 4 | import django.utils.timezone 5 | from django.db import migrations, models 6 | 7 | 8 | class Migration(migrations.Migration): 9 | 10 | dependencies = [ 11 | ] 12 | 13 | operations = [ 14 | migrations.CreateModel( 15 | name='Invitation', 16 | fields=[ 17 | ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), 18 | ('email', models.EmailField(unique=True, max_length=75, verbose_name='e-mail address')), 19 | ('accepted', models.BooleanField(default=False, verbose_name='accepted')), 20 | ('created', models.DateTimeField(default=django.utils.timezone.now, verbose_name='created')), 21 | ('key', models.CharField(unique=True, max_length=64, verbose_name='key')), 22 | ('sent', models.DateTimeField(null=True, verbose_name='sent')), 23 | ], 24 | options={ 25 | }, 26 | bases=(models.Model,), 27 | ), 28 | ] 29 | -------------------------------------------------------------------------------- /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | name: Test 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | build: 7 | name: build (Python ${{ matrix.python-version }}, Django ${{ matrix.django-version }}) 8 | runs-on: ubuntu-latest 9 | strategy: 10 | fail-fast: false 11 | matrix: 12 | python-version: ['3.8', '3.9', '3.10', '3.11', '3.12'] 13 | django-version: ['3.2', '4.0', '4.1', '4.2', '5.0'] 14 | 15 | steps: 16 | - uses: actions/checkout@v4 17 | 18 | - name: Set up Python ${{ matrix.python-version }} 19 | uses: actions/setup-python@v4 20 | with: 21 | python-version: ${{ matrix.python-version }} 22 | cache: 'pip' 23 | 24 | - name: Install dependencies 25 | run: | 26 | python -m pip install --upgrade pip 27 | python -m pip install pytest coverage 28 | python -m pip install tox tox-gh-actions 29 | 30 | - name: Tox tests 31 | run: tox -v 32 | env: 33 | DJANGO: ${{ matrix.django-version }} 34 | 35 | - name: Upload coverage 36 | uses: codecov/codecov-action@v3 37 | with: 38 | name: Python ${{ matrix.python-version }} 39 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: Release 2 | 3 | on: 4 | push: 5 | tags: 6 | - '*' 7 | 8 | jobs: 9 | build: 10 | if: github.repository == 'jazzband/django-invitations' 11 | runs-on: ubuntu-latest 12 | 13 | steps: 14 | - uses: actions/checkout@v2 15 | with: 16 | fetch-depth: 0 17 | 18 | - name: Set up Python 19 | uses: actions/setup-python@v2 20 | with: 21 | python-version: 3.8 22 | 23 | - name: Install dependencies 24 | run: | 25 | python -m pip install -U pip 26 | python -m pip install -U poetry 27 | 28 | - name: Update .po and .mo files 29 | run: | 30 | make po mo 31 | 32 | - name: Build package 33 | run: | 34 | poetry build 35 | 36 | - name: Upload packages to Jazzband 37 | if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags') 38 | run: | 39 | poetry config repositories.jazzband https://jazzband.co/projects/django-invitations/upload 40 | poetry config http-basic.jazzband jazzband ${{ secrets.JAZZBAND_RELEASE_KEY }} 41 | poetry publish -r jazzband 42 | -------------------------------------------------------------------------------- /tests/migrations/0001_initial.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # Generated by Django 1.11.1 on 2017-05-21 04:23 3 | from __future__ import unicode_literals 4 | 5 | from django.db import migrations, models 6 | import django.db.models.deletion 7 | 8 | 9 | class Migration(migrations.Migration): 10 | 11 | initial = True 12 | 13 | dependencies = [ 14 | ("invitations", "0003_auto_20151126_1523"), 15 | ] 16 | 17 | operations = [ 18 | migrations.CreateModel( 19 | name="ExampleSwappableInvitation", 20 | fields=[ 21 | ( 22 | "invitation_ptr", 23 | models.OneToOneField( 24 | auto_created=True, 25 | on_delete=django.db.models.deletion.CASCADE, 26 | parent_link=True, 27 | primary_key=True, 28 | serialize=False, 29 | to="invitations.Invitation", 30 | ), 31 | ), 32 | ("additonal_field", models.CharField(blank=True, max_length=255)), 33 | ], 34 | options={ 35 | "abstract": False, 36 | }, 37 | bases=("invitations.invitation",), 38 | ), 39 | ] 40 | -------------------------------------------------------------------------------- /tox.ini: -------------------------------------------------------------------------------- 1 | [tox] 2 | envlist = 3 | py{38,39,310}-django{32}-backend{Basic,Allauth} 4 | py{38,39,310,311}-django{40,41,42}-backend{Basic,Allauth} 5 | py{310,311,312}-django{50}-backend{Basic,Allauth} 6 | skipsdist = True 7 | usedevelop = True 8 | 9 | [gh-actions] 10 | python = 11 | 3.8: py38, flake8 12 | 3.9: py39 13 | 3.10: py310 14 | 3.11: py311 15 | 3.12: py312 16 | 17 | [gh-actions:testenv] 18 | DJANGO = 19 | 3.2: django32 20 | 4.0: django40 21 | 4.1: django41 22 | 4.2: django42 23 | 5.0: django50 24 | 25 | [pytest] 26 | python_files = tests.py test_*.py 27 | 28 | [testenv] 29 | description = Unit tests 30 | setenv = 31 | PYTHONWARNINGS = all 32 | commands = 33 | python -V 34 | backendBasic: pytest --cov-report term --cov=invitations --ignore=tests/allauth/ --ds=test_settings tests 35 | backendAllauth: pytest --cov-report term --cov=invitations --ignore=tests/basic/ --ds=test_allauth_settings tests 36 | coverage report 37 | deps = 38 | django32: Django>=3.2,<3.3 39 | django40: Django>=4.0,<4.1 40 | django41: Django>=4.1,<4.2 41 | django42: Django>=4.2,<5.0 42 | django50: Django>=5.0rc1,<5.1 43 | backendAllauth: django-allauth 44 | coverage 45 | pytest 46 | pytest-django 47 | pytest-cov 48 | freezegun 49 | whitelist_externals= 50 | pytest 51 | coverage 52 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Django-invitations - Generic invitations app 2 | 3 | [![Jazzband](https://jazzband.co/static/img/badge.svg)](https://jazzband.co/) 4 | [![PyPI Download](https://img.shields.io/pypi/v/django-invitations.svg)](https://pypi.python.org/pypi/django-invitations) 5 | [![PyPI Python Versions](https://img.shields.io/pypi/pyversions/django-invitations.svg)](https://pypi.python.org/pypi/django-invitations) 6 | [![Build status](https://github.com/jazzband/django-invitations/actions/workflows/test.yml/badge.svg)](https://github.com/jazzband/django-invitations/actions/workflows/test.yml) 7 | [![Coverage status](https://codecov.io/gh/jazzband/django-invitations/branch/master/graph/badge.svg?token=xxufPt4r3I)](https://codecov.io/gh/jazzband/django-invitations) 8 | [![Documentation Status](https://readthedocs.org/projects/django-invitations/badge/?version=latest)](https://django-invitations.readthedocs.io/en/latest/?badge=latest) 9 | 10 | ## About 11 | 12 | Generic invitations solution with adaptable backend and support for django-allauth. 13 | 14 | ## Contributing 15 | 16 | As we are members of a [JazzBand project](https://jazzband.co/projects), `django-invitations` contributors should adhere to the [Contributor Code of Conduct](https://jazzband.co/about/conduct). 17 | 18 | Get started contributing by reading [CONTRIBUTING.md](CONTRIBUTING.md). 19 | 20 | ### Documentation 21 | 22 | Documentation can be found at https://django-invitations.readthedocs.io/ 23 | -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | [metadata] 2 | name = django-invitations 3 | version = 1.9.3 4 | description = Generic invitations app with support for django-allauth 5 | long_description = file: README.md 6 | author = https://github.com/bee-keeper 7 | author_email = none@none.com 8 | url = https://github.com/jazzband/django-invitations.git 9 | keywords = django invitation django-allauth invite 10 | license = GPL-3.0-only 11 | classifiers = 12 | Development Status :: 4 - Beta 13 | Intended Audience :: Developers 14 | Topic :: Software Development :: Libraries :: Python Modules 15 | Environment :: Web Environment 16 | Topic :: Internet 17 | Framework :: Django 18 | Framework :: Django:: 3.2 19 | Framework :: Django:: 4.0 20 | Framework :: Django:: 4.1 21 | Framework :: Django:: 4.2 22 | Framework :: Django:: 5.0 23 | Programming Language :: Python 24 | Programming Language :: Python :: 3.8 25 | Programming Language :: Python :: 3.9 26 | Programming Language :: Python :: 3.10 27 | Programming Language :: Python :: 3.11 28 | Programming Language :: Python :: 3.12 29 | License :: OSI Approved :: GPL-3.0-only 30 | license_file = LICENSE 31 | 32 | [options] 33 | package_dir= 34 | =invitations 35 | packages = find: 36 | include_package_data = True 37 | python_requires = >=3.7 38 | zip_safe = False 39 | 40 | [options.package_data] 41 | invitations = "templates/*.*" 42 | 43 | [options.packages.find] 44 | where = invitations 45 | -------------------------------------------------------------------------------- /invitations/base_invitation.py: -------------------------------------------------------------------------------- 1 | from django.conf import settings 2 | from django.db import models 3 | from django.utils.translation import gettext_lazy as _ 4 | 5 | from .managers import BaseInvitationManager 6 | 7 | 8 | class AbstractBaseInvitation(models.Model): 9 | accepted = models.BooleanField(verbose_name=_("accepted"), default=False) 10 | key = models.CharField(verbose_name=_("key"), max_length=64, unique=True) 11 | sent = models.DateTimeField(verbose_name=_("sent"), null=True) 12 | inviter = models.ForeignKey( 13 | settings.AUTH_USER_MODEL, 14 | verbose_name=_("inviter"), 15 | null=True, 16 | blank=True, 17 | on_delete=models.CASCADE, 18 | related_name="%(app_label)s_%(class)ss", 19 | related_query_name="%(app_label)s_%(class)s", 20 | ) 21 | 22 | objects = BaseInvitationManager() 23 | 24 | class Meta: 25 | abstract = True 26 | 27 | @classmethod 28 | def create(cls, email, inviter=None, **kwargs): 29 | raise NotImplementedError("You should implement the create method class") 30 | 31 | def key_expired(self): 32 | raise NotImplementedError("You should implement the key_expired method") 33 | 34 | def send_invitation(self, request, **kwargs): 35 | raise NotImplementedError("You should implement the send_invitation method") 36 | 37 | def __str__(self): 38 | raise NotImplementedError("You should implement the __str__ method") 39 | -------------------------------------------------------------------------------- /docs/contributing.rst: -------------------------------------------------------------------------------- 1 | Contributing 2 | ============ 3 | 4 | JazzBand project 5 | ---------------- 6 | As we are members of a [JazzBand project](https://jazzband.co/projects), `django-invitations` contributors should adhere to the [Contributor Code of Conduct](https://jazzband.co/about/conduct). 7 | 8 | 9 | Testing 10 | ------- 11 | 12 | It's important that any new code is tested before submission. To quickly test code in your active development environment, you should first install all of the requirements by running: 13 | 14 | .. code-block:: bash 15 | 16 | source .venv/bin/activate 17 | pip install -e '.[testing]' -U 18 | 19 | Then, run the following command to execute tests: 20 | 21 | .. code-block:: bash 22 | 23 | pytest --cov-report term --cov=invitations --ignore=tests/allauth/ --ds=tests.settings tests 24 | 25 | To test the integration with django-allauth, first make sure you have it installed. Then run: 26 | 27 | .. code-block:: bash 28 | 29 | pytest --cov-report term --cov=invitations --ignore=tests/basic/ --ds=tests.settings_allauth tests 30 | 31 | Testing in a single environment is a quick and easy way to identify obvious issues with your code. However, it's important to test changes in other environments too, before they are submitted. In order to help with this, django-invitations is configured to use tox for multi-environment tests. They take longer to complete, but can be triggered with a simple command: 32 | 33 | .. code-block:: bash 34 | 35 | tox 36 | -------------------------------------------------------------------------------- /docs/installation.rst: -------------------------------------------------------------------------------- 1 | Installation 2 | ============ 3 | 4 | Requirements 5 | ------------ 6 | 7 | Python 3.8 to 3.12 supported. 8 | 9 | Django 3.2 to 5.0 supported. 10 | 11 | Installation 12 | ------------ 13 | 14 | 1. Install with `pip `_: 15 | 16 | .. code-block:: sh 17 | 18 | python -m pip install django-invitations 19 | 20 | 2. Add ``"invitations"`` to ``INSTALLED_APPS``: 21 | 22 | .. code-block:: python 23 | 24 | INSTALLED_APPS = [ 25 | ... 26 | "invitations", 27 | ... 28 | ] 29 | 30 | .. note:: **django-allauth support** 31 | 32 | For django-allauth support, ``"invitations"`` must come after ``"allauth"`` in the ``INSTALLED_APPS`` list. 33 | 34 | 3. If using `django-allauth `_, then add this configuration to your ``settings.py`` file: 35 | 36 | .. code-block:: python 37 | 38 | # django-allauth configuration: 39 | ACCOUNT_ADAPTER = "invitations.models.InvitationsAdapter" 40 | 41 | # django-invitations configuration: 42 | INVITATIONS_ADAPTER = ACCOUNT_ADAPTER 43 | 44 | 4. Add invitations URLs to your ``urlpatterns``: 45 | 46 | .. code-block:: python 47 | 48 | from django.urls import include, path 49 | 50 | urlpatterns = [ 51 | ... 52 | path("invitations/", include('invitations.urls', namespace='invitations')), 53 | ... 54 | ] 55 | 56 | 5. Run migrations: 57 | 58 | .. code-block:: sh 59 | 60 | python manage.py migrate 61 | -------------------------------------------------------------------------------- /invitations/utils.py: -------------------------------------------------------------------------------- 1 | from django.apps import apps as django_apps 2 | from django.core.exceptions import ImproperlyConfigured 3 | 4 | from .app_settings import app_settings 5 | 6 | try: 7 | import importlib 8 | except ImportError: 9 | from django.utils import importlib 10 | 11 | 12 | def import_attribute(path): 13 | assert isinstance(path, str) 14 | pkg, attr = path.rsplit(".", 1) 15 | ret = getattr(importlib.import_module(pkg), attr) 16 | return ret 17 | 18 | 19 | def get_invite_form(): 20 | """ 21 | Returns the form for sending an invite. 22 | """ 23 | return import_attribute(app_settings.INVITE_FORM) 24 | 25 | 26 | def get_invitation_admin_add_form(): 27 | """ 28 | Returns the form for creating a new invitation in admin. 29 | """ 30 | return import_attribute(app_settings.ADMIN_ADD_FORM) 31 | 32 | 33 | def get_invitation_admin_change_form(): 34 | """ 35 | Returns the form for changing invitations in admin. 36 | """ 37 | return import_attribute(app_settings.ADMIN_CHANGE_FORM) 38 | 39 | 40 | def get_invitation_model(): 41 | """ 42 | Returns the Invitation model that is active in this project. 43 | """ 44 | path = app_settings.INVITATION_MODEL 45 | try: 46 | return django_apps.get_model(path) 47 | except ValueError: 48 | raise ImproperlyConfigured("path must be of the form 'app_label.model_name'") 49 | except LookupError: 50 | raise ImproperlyConfigured( 51 | "path refers to model '%s' that\ 52 | has not been installed" 53 | % app_settings.INVITATION_MODEL, 54 | ) 55 | -------------------------------------------------------------------------------- /test_settings.py: -------------------------------------------------------------------------------- 1 | SECRET_KEY = "not_empty" 2 | SITE_ID = 1 3 | 4 | DATABASES = { 5 | "default": { 6 | "ENGINE": "django.db.backends.sqlite3", 7 | "NAME": ":memory:", 8 | }, 9 | } 10 | 11 | ROOT_URLCONF = "test_urls" 12 | STATIC_URL = "/static/" 13 | 14 | TEMPLATES = [ 15 | { 16 | "BACKEND": "django.template.backends.django.DjangoTemplates", 17 | "DIRS": [], 18 | "APP_DIRS": True, 19 | "OPTIONS": { 20 | "context_processors": [ 21 | "django.template.context_processors.debug", 22 | "django.template.context_processors.request", 23 | "django.contrib.auth.context_processors.auth", 24 | "django.contrib.messages.context_processors.messages", 25 | ], 26 | }, 27 | }, 28 | ] 29 | 30 | MIDDLEWARE = [ 31 | "django.middleware.security.SecurityMiddleware", 32 | "django.contrib.sessions.middleware.SessionMiddleware", 33 | "django.middleware.common.CommonMiddleware", 34 | "django.middleware.csrf.CsrfViewMiddleware", 35 | "django.contrib.auth.middleware.AuthenticationMiddleware", 36 | "django.contrib.messages.middleware.MessageMiddleware", 37 | "django.middleware.clickjacking.XFrameOptionsMiddleware", 38 | ] 39 | 40 | EMAIL_BACKEND = "django.core.mail.backends.locmem.EmailBackend" 41 | 42 | INSTALLED_APPS = ( 43 | "django.contrib.auth", 44 | "django.contrib.admin", 45 | "django.contrib.contenttypes", 46 | "django.contrib.sessions", 47 | "django.contrib.sites", 48 | "django.contrib.messages", 49 | "tests", 50 | "invitations", 51 | ) 52 | AUTHENTICATION_BACKENDS = ("django.contrib.auth.backends.ModelBackend",) 53 | -------------------------------------------------------------------------------- /.pre-commit-config.yaml: -------------------------------------------------------------------------------- 1 | default_language_version: 2 | python: python3 3 | exclude: ^.*\b(migrations)\b.*$ 4 | ci: 5 | autofix_prs: false 6 | repos: 7 | - repo: https://github.com/psf/black 8 | rev: 24.4.2 9 | hooks: 10 | - id: black 11 | - repo: https://github.com/pre-commit/pre-commit-hooks 12 | rev: v4.6.0 13 | hooks: 14 | - id: check-ast 15 | - id: check-merge-conflict 16 | - id: check-case-conflict 17 | - id: detect-private-key 18 | - id: check-added-large-files 19 | - id: check-json 20 | - id: check-symlinks 21 | - id: check-toml 22 | - id: end-of-file-fixer 23 | - id: trailing-whitespace 24 | - repo: https://github.com/pycqa/isort 25 | rev: 5.13.2 26 | hooks: 27 | - id: isort 28 | name: isort (python) 29 | args: ["--profile", "black", "--filter-files"] 30 | - repo: https://github.com/pycqa/flake8 31 | rev: 7.0.0 32 | hooks: 33 | - id: flake8 34 | additional_dependencies: 35 | - flake8-bugbear 36 | - flake8-comprehensions 37 | args: [--max-line-length=88] 38 | - repo: https://github.com/asottile/pyupgrade 39 | rev: v3.16.0 40 | hooks: 41 | - id: pyupgrade 42 | args: 43 | - --py37-plus 44 | exclude: migrations/ 45 | - repo: https://github.com/adamchainz/django-upgrade 46 | rev: 1.18.0 47 | hooks: 48 | - id: django-upgrade 49 | args: 50 | - --target-version=3.2 51 | - repo: https://github.com/asottile/yesqa 52 | rev: v1.5.0 53 | hooks: 54 | - id: yesqa 55 | - repo: https://github.com/hadialqattan/pycln 56 | rev: v2.4.0 57 | hooks: 58 | - id: pycln 59 | -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- 1 | [tool.poetry] 2 | name = "django-invitations" 3 | version = "2.1.0" 4 | description = "Generic invitations app with support for django-allauth" 5 | authors = ["bee-keeper"] 6 | homepage = "https://github.com/jazzband/django-invitations/" 7 | repository = "https://github.com/jazzband/django-invitations/" 8 | documentation = "https://django-invitations.readthedocs.io/en/latest/" 9 | license = "GPL-3.0-only" 10 | maintainers = ["JazzBand"] 11 | readme = "README.md" 12 | keywords = ['django', 'invitation', 'django-allauth', 'invite'] 13 | classifiers = [ 14 | "Development Status :: 5 - Production/Stable", 15 | "Intended Audience :: Developers", 16 | "Topic :: Software Development :: Libraries :: Python Modules", 17 | "Environment :: Web Environment", 18 | "Topic :: Internet", 19 | "Framework :: Django", 20 | "Framework :: Django :: 3.2", 21 | "Framework :: Django :: 4.0", 22 | "Framework :: Django :: 4.1", 23 | "Framework :: Django :: 4.2", 24 | "Framework :: Django :: 5.0", 25 | "Programming Language :: Python", 26 | "Programming Language :: Python :: 3.8", 27 | "Programming Language :: Python :: 3.9", 28 | "Programming Language :: Python :: 3.10", 29 | "Programming Language :: Python :: 3.11", 30 | "Programming Language :: Python :: 3.12", 31 | "License :: OSI Approved :: GNU General Public License v3 (GPLv3)" 32 | ] 33 | packages = [ 34 | { include = "invitations" } 35 | ] 36 | 37 | [tool.poetry.dependencies] 38 | python = "^3.8" 39 | django = ">=3.2" 40 | 41 | [tool.poetry.group.dev.dependencies] 42 | coverage = "^6.3.2" 43 | flake8 = "^5.0.4" 44 | freezegun = "^1.2.1" 45 | pytest = "^7.1.1" 46 | pytest-django = "^4.5.2" 47 | pytest-cov = "^3.0.0" 48 | tox = "3.26.0" 49 | black = "^22.1.0" 50 | pre-commit = "^3.2.0" 51 | 52 | [tool.black] 53 | line-length = 88 54 | target-version = ["py310"] 55 | extend-exclude = "/migrations/" 56 | 57 | [build-system] 58 | requires = ["poetry-core>=1.0.0"] 59 | build-backend = "poetry.core.masonry.api" 60 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | [![Jazzband](https://jazzband.co/static/img/jazzband.svg)](https://jazzband.co/) 2 | 3 | This is a [Jazzband](https://jazzband.co/) project. By contributing you agree to abide by the [Contributor Code of Conduct](https://jazzband.co/about/conduct) and follow the [guidelines](https://jazzband.co/about/guidelines). 4 | 5 | # Setting up 6 | 7 | `django-invitations` uses [Poetry] to build and package the project. 8 | We recommend that you use it to manage your virtual environment during development as well. 9 | You can install it using [`pipx`][pipx] like this: 10 | 11 | pipx install poetry 12 | 13 | Install all dependencies mentioned in `poetry.lock` by running: 14 | 15 | poetry install --with=dev 16 | 17 | # Translation files 18 | 19 | In order to update the Gettext `.po` files with any changed translatable strings, run: 20 | 21 | poetry run make po 22 | 23 | To compile `.mo` files from the `.po` files, run: 24 | 25 | poetry run make mo 26 | 27 | # Tests 28 | 29 | You can run the tests using [`tox`][tox], like this: 30 | 31 | poetry run tox 32 | 33 | There are also tests that check for simple coding issues and stylistic issues. 34 | We use a framework (confusingly) named [pre-commit] to check for these issues. 35 | Run it like this: 36 | 37 | poetry run pre-commit run --all-files 38 | 39 | If you would like to run the pre-commit tests automatically before making a Git commit, modify `.git/hooks/pre-commit`. 40 | You can do this in one step by running: 41 | 42 | poetry run pre-commit install 43 | 44 | # Documentation 45 | 46 | The docs are found under the `docs/` directory. They are in [reStructuredText]. 47 | To build the docs into HTML, run: 48 | 49 | cd docs 50 | make html 51 | 52 | Now open `docs/_build/html/index.html` in your browser. 53 | 54 | [Poetry]: https://python-poetry.org/ 55 | [pipx]: https://pipx.pypa.io/stable/ 56 | [tox]: https://tox.wiki/ 57 | [pre-commit]: https://pre-commit.com/ 58 | [reStructuredText]: https://www.sphinx-doc.org/en/master/usage/restructuredtext/basics.html 59 | -------------------------------------------------------------------------------- /tests/conftest.py: -------------------------------------------------------------------------------- 1 | import datetime 2 | 3 | import pytest 4 | from django.contrib.auth import get_user_model 5 | from django.utils import timezone 6 | from freezegun import freeze_time 7 | 8 | from invitations.app_settings import app_settings 9 | from invitations.utils import get_invitation_model 10 | 11 | Invitation = get_invitation_model() 12 | 13 | 14 | @pytest.fixture 15 | def invitation_a(db): 16 | freezer = freeze_time("2015-07-30 12:00:06") 17 | freezer.start() 18 | inivitation = Invitation.create("email@example.com") 19 | freezer.stop() 20 | return inivitation 21 | 22 | 23 | @pytest.fixture 24 | def invitation_b(db): 25 | return Invitation.create("invited@example.com") 26 | 27 | 28 | @pytest.fixture 29 | def user_a(db): 30 | return get_user_model().objects.create_user(username="flibble", password="password") 31 | 32 | 33 | @pytest.fixture 34 | def user_b(db): 35 | return get_user_model().objects.create_user( 36 | username="flobble", 37 | password="password", 38 | email="flobble@example.com", 39 | ) 40 | 41 | 42 | @pytest.fixture 43 | def super_user(db): 44 | return get_user_model().objects.create_superuser( 45 | username="flibble", 46 | password="password", 47 | email="mrflibble@example.com", 48 | ) 49 | 50 | 51 | @pytest.fixture 52 | def sent_invitation_by_user_a(db, user_a): 53 | invite = Invitation.create("email@example.com", inviter=user_a) 54 | invite.sent = timezone.now() 55 | invite.save() 56 | return invite 57 | 58 | 59 | @pytest.fixture 60 | def accepted_invitation(db, user_a): 61 | invite = Invitation.create("accepted@example.com", inviter=user_a) 62 | invite.sent = timezone.now() 63 | invite.accepted = True 64 | invite.save() 65 | return invite 66 | 67 | 68 | @pytest.fixture 69 | def pending_invitation(db, user_a): 70 | invite = Invitation.create("pending@example.com", inviter=user_a) 71 | invite.sent = timezone.now() - datetime.timedelta( 72 | days=app_settings.INVITATION_EXPIRY - 1, 73 | ) 74 | invite.save() 75 | return invite 76 | 77 | 78 | @pytest.fixture 79 | def expired_invitation(db, user_a): 80 | invite = Invitation.create("expired@example.com") 81 | invite.sent = timezone.now() - datetime.timedelta( 82 | days=app_settings.INVITATION_EXPIRY + 1, 83 | ) 84 | invite.save() 85 | return invite 86 | -------------------------------------------------------------------------------- /docs/conf.py: -------------------------------------------------------------------------------- 1 | # Configuration file for the Sphinx documentation builder. 2 | # 3 | # This file only contains a selection of the most common options. For a full 4 | # list see the documentation: 5 | # https://www.sphinx-doc.org/en/master/usage/configuration.html 6 | from __future__ import annotations 7 | 8 | import sys 9 | from pathlib import Path 10 | 11 | import tomlkit 12 | 13 | # -- Path setup -------------------------------------------------------------- 14 | 15 | here = Path(__file__).parent.resolve() 16 | sys.path.insert(0, str(here / "..")) 17 | 18 | # -- Project information ----------------------------------------------------- 19 | 20 | 21 | def _get_project_meta(): 22 | with open("../pyproject.toml") as pyproject: 23 | file_contents = pyproject.read() 24 | 25 | return tomlkit.parse(file_contents)["tool"]["poetry"] 26 | 27 | 28 | pkg_meta = _get_project_meta() 29 | project = str(pkg_meta["name"]) 30 | copyright = "-" 31 | author = "-" 32 | 33 | # The short X.Y version 34 | version = str(pkg_meta["version"]) 35 | # The full version, including alpha/beta/rc tags 36 | release = version 37 | 38 | # -- General configuration --------------------------------------------------- 39 | 40 | # Add any Sphinx extension module names here, as strings. They can be 41 | # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom 42 | # ones. 43 | extensions = [ 44 | "sphinx.ext.autodoc", 45 | "sphinx.ext.intersphinx", 46 | "sphinx.ext.viewcode", 47 | ] 48 | 49 | # List of patterns, relative to source directory, that match files and 50 | # directories to ignore when looking for source files. 51 | exclude_patterns = [ 52 | "_build", 53 | "venv", 54 | ] 55 | 56 | # -- Options for HTML output ------------------------------------------------- 57 | 58 | # The theme to use for HTML and HTML Help pages. See the documentation for 59 | # a list of builtin themes. 60 | # 61 | html_theme = "furo" 62 | 63 | # -- Options for LaTeX output ------------------------------------------ 64 | 65 | # Grouping the document tree into LaTeX files. List of tuples 66 | # (source start file, target name, title, author, documentclass 67 | # [howto/manual]). 68 | latex_documents = [ 69 | ( 70 | "index", 71 | "django-invitations.tex", 72 | "django-invitations Documentation", 73 | "Jazzband", 74 | "manual", 75 | ), 76 | ] 77 | 78 | # -- Options for Intersphinx ------------------------------------------- 79 | 80 | intersphinx_mapping = { 81 | "django": ( 82 | "https://docs.djangoproject.com/en/stable/", 83 | "https://docs.djangoproject.com/en/stable/_objects/", 84 | ), 85 | } 86 | -------------------------------------------------------------------------------- /invitations/forms.py: -------------------------------------------------------------------------------- 1 | from django import forms 2 | from django.contrib.auth import get_user_model 3 | from django.utils.translation import gettext_lazy as _ 4 | 5 | from .adapters import get_invitations_adapter 6 | from .exceptions import AlreadyAccepted, AlreadyInvited, UserRegisteredEmail 7 | from .utils import get_invitation_model 8 | 9 | Invitation = get_invitation_model() 10 | 11 | 12 | class CleanEmailMixin: 13 | def validate_invitation(self, email): 14 | if Invitation.objects.all_valid().filter(email__iexact=email, accepted=False): 15 | raise AlreadyInvited 16 | elif Invitation.objects.filter(email__iexact=email, accepted=True): 17 | raise AlreadyAccepted 18 | elif get_user_model().objects.filter(email__iexact=email): 19 | raise UserRegisteredEmail 20 | else: 21 | return True 22 | 23 | def clean_email(self): 24 | email = self.cleaned_data["email"] 25 | email = get_invitations_adapter().clean_email(email) 26 | 27 | errors = { 28 | "already_invited": _("This e-mail address has already been invited."), 29 | "already_accepted": _( 30 | "This e-mail address has already accepted an invite.", 31 | ), 32 | "email_in_use": _("An active user is using this e-mail address"), 33 | } 34 | try: 35 | self.validate_invitation(email) 36 | except AlreadyInvited: 37 | raise forms.ValidationError(errors["already_invited"]) 38 | except AlreadyAccepted: 39 | raise forms.ValidationError(errors["already_accepted"]) 40 | except UserRegisteredEmail: 41 | raise forms.ValidationError(errors["email_in_use"]) 42 | return email 43 | 44 | 45 | class InviteForm(forms.Form, CleanEmailMixin): 46 | email = forms.EmailField( 47 | label=_("E-mail"), 48 | required=True, 49 | widget=forms.TextInput(attrs={"type": "email", "size": "30"}), 50 | initial="", 51 | ) 52 | 53 | def save(self, email): 54 | return Invitation.create(email=email) 55 | 56 | 57 | class InvitationAdminAddForm(forms.ModelForm, CleanEmailMixin): 58 | email = forms.EmailField( 59 | label=_("E-mail"), 60 | required=True, 61 | widget=forms.TextInput(attrs={"type": "email", "size": "30"}), 62 | ) 63 | 64 | def save(self, *args, **kwargs): 65 | cleaned_data = super().clean() 66 | email = cleaned_data.get("email") 67 | params = {"email": email} 68 | if cleaned_data.get("inviter"): 69 | params["inviter"] = cleaned_data.get("inviter") 70 | instance = Invitation.create(**params) 71 | instance.send_invitation(self.request) 72 | super().save(*args, **kwargs) 73 | return instance 74 | 75 | class Meta: 76 | model = Invitation 77 | fields = ("email", "inviter") 78 | 79 | 80 | class InvitationAdminChangeForm(forms.ModelForm): 81 | class Meta: 82 | model = Invitation 83 | fields = "__all__" 84 | -------------------------------------------------------------------------------- /docs/usage.rst: -------------------------------------------------------------------------------- 1 | Usage 2 | ===== 3 | 4 | There are two primary ways to use `django-invitations` described below. 5 | 6 | Generic Invitation flow: 7 | 8 | * Privileged user invites prospective user by email (via either Django admin, form post, JSON post or programmatically) 9 | * User receives invitation email with confirmation link 10 | * User clicks link and is redirected to a preconfigured url (default is accounts/signup) 11 | 12 | Allauth Invitation flow: 13 | 14 | * As above but.. 15 | * User clicks link, their email is confirmed and they are redirected to signup 16 | * The signup URL has the email prefilled and upon signing up the user is logged into the site 17 | 18 | The user can enter any email address they wish when they sign up. 19 | They are not obligated to enter the same email address listed in the invitation. 20 | If ``allauth`` is being used under its default settings, then two ``EmailAddress`` instances will be created for that user, one for the email address used in the invitation, and one for the email address entered by the user. 21 | 22 | Further details can be found in the following sections. 23 | 24 | Sending Invites 25 | --------------- 26 | 27 | First import the model: 28 | 29 | .. code-block:: python 30 | 31 | from invitations.utils import get_invitation_model 32 | Invitation = get_invitation_model() 33 | 34 | In this version of ``django-invitations``, the ``email`` field in the ``Invitation`` model must be unique. 35 | (Even though email addresses are generally considered case *insensitive*, the unique constraint is case *sensitive*.) 36 | Because of this constraint, it is not possible to create two invitations to the exact same email address, even if the inviters are different users. 37 | We need to handle this case in our code. 38 | 39 | .. code-block:: python 40 | 41 | email_address = "Example@example.com" 42 | invitation = (Invitation.objects 43 | .filter(email__iexact=email_address) 44 | .order_by('created') 45 | .last() 46 | ) 47 | if invitation is None: 48 | # Do not use Invitation.objects.create or 49 | # Invitation.objects.update_or_create, but use Invitation.create 50 | # instead, because it sets the key to a secure random value 51 | invitation = Invitation.create(email=email_address) 52 | 53 | Then finally send the email out. 54 | 55 | .. code-block:: python 56 | 57 | invitation.send_invitation() 58 | 59 | To send invites via django admin, just add an invite and save. 60 | 61 | 62 | Bulk Invites 63 | ------------ 64 | 65 | Bulk invites are supported via JSON. Post a list of comma separated emails to the dedicated URL and Invitations will return a data object containing a list of valid and invalid invitations. 66 | 67 | Signals 68 | ------- 69 | 70 | The following signals are emitted: 71 | 72 | * ``invite_url_sent`` 73 | * ``invite_accepted`` 74 | 75 | 76 | Management Commands 77 | ------------------- 78 | 79 | Expired and accepted invites can be cleared with the ``clear_expired_invitations`` management command: 80 | 81 | .. code-block:: sh 82 | 83 | python manage.py clear_expired_invitations 84 | -------------------------------------------------------------------------------- /invitations/models.py: -------------------------------------------------------------------------------- 1 | import datetime 2 | 3 | from django.conf import settings 4 | from django.contrib.sites.shortcuts import get_current_site 5 | 6 | try: 7 | from django.urls import reverse 8 | except ImportError: 9 | from django.urls import reverse 10 | 11 | from django.db import models 12 | from django.utils import timezone 13 | from django.utils.crypto import get_random_string 14 | from django.utils.translation import gettext_lazy as _ 15 | 16 | from . import signals 17 | from .adapters import get_invitations_adapter 18 | from .app_settings import app_settings 19 | from .base_invitation import AbstractBaseInvitation 20 | 21 | 22 | class Invitation(AbstractBaseInvitation): 23 | email = models.EmailField( 24 | unique=True, 25 | verbose_name=_("e-mail address"), 26 | max_length=app_settings.EMAIL_MAX_LENGTH, 27 | ) 28 | created = models.DateTimeField(verbose_name=_("created"), default=timezone.now) 29 | 30 | @classmethod 31 | def create(cls, email, inviter=None, **kwargs): 32 | key = get_random_string(64).lower() 33 | instance = cls._default_manager.create( 34 | email=email, key=key, inviter=inviter, **kwargs 35 | ) 36 | return instance 37 | 38 | def key_expired(self): 39 | expiration_date = self.sent + datetime.timedelta( 40 | days=app_settings.INVITATION_EXPIRY, 41 | ) 42 | return expiration_date <= timezone.now() 43 | 44 | def send_invitation(self, request, **kwargs): 45 | current_site = get_current_site(request) 46 | invite_url = reverse(app_settings.CONFIRMATION_URL_NAME, args=[self.key]) 47 | invite_url = request.build_absolute_uri(invite_url) 48 | ctx = kwargs 49 | ctx.update( 50 | { 51 | "invite_url": invite_url, 52 | "site_name": current_site.name, 53 | "email": self.email, 54 | "key": self.key, 55 | "inviter": self.inviter, 56 | }, 57 | ) 58 | 59 | email_template = "invitations/email/email_invite" 60 | 61 | get_invitations_adapter().send_mail(email_template, self.email, ctx) 62 | self.sent = timezone.now() 63 | self.save() 64 | 65 | signals.invite_url_sent.send( 66 | sender=self.__class__, 67 | instance=self, 68 | invite_url_sent=invite_url, 69 | inviter=self.inviter, 70 | ) 71 | 72 | def __str__(self): 73 | return f"Invite: {self.email}" 74 | 75 | 76 | # here for backwards compatibility, historic allauth adapter 77 | if hasattr(settings, "ACCOUNT_ADAPTER"): 78 | if settings.ACCOUNT_ADAPTER == "invitations.models.InvitationsAdapter": 79 | from allauth.account.adapter import DefaultAccountAdapter 80 | from allauth.account.signals import user_signed_up 81 | 82 | class InvitationsAdapter(DefaultAccountAdapter): 83 | def is_open_for_signup(self, request): 84 | if hasattr(request, "session") and request.session.get( 85 | "account_verified_email", 86 | ): 87 | return True 88 | elif app_settings.INVITATION_ONLY is True: 89 | # Site is ONLY open for invites 90 | return False 91 | else: 92 | # Site is open to signup 93 | return True 94 | 95 | def get_user_signed_up_signal(self): 96 | return user_signed_up 97 | -------------------------------------------------------------------------------- /.github/workflows/codeql.yml: -------------------------------------------------------------------------------- 1 | # For most projects, this workflow file will not need changing; you simply need 2 | # to commit it to your repository. 3 | # 4 | # You may wish to alter this file to override the set of languages analyzed, 5 | # or to provide custom queries or build logic. 6 | # 7 | # ******** NOTE ******** 8 | # We have attempted to detect the languages in your repository. Please check 9 | # the `language` matrix defined below to confirm you have the correct set of 10 | # supported CodeQL languages. 11 | # 12 | name: "CodeQL" 13 | 14 | on: 15 | push: 16 | branches: [ "master" ] 17 | pull_request: 18 | # The branches below must be a subset of the branches above 19 | branches: [ "master" ] 20 | schedule: 21 | - cron: '25 1 * * 5' 22 | 23 | jobs: 24 | analyze: 25 | name: Analyze 26 | # Runner size impacts CodeQL analysis time. To learn more, please see: 27 | # - https://gh.io/recommended-hardware-resources-for-running-codeql 28 | # - https://gh.io/supported-runners-and-hardware-resources 29 | # - https://gh.io/using-larger-runners 30 | # Consider using larger runners for possible analysis time improvements. 31 | runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }} 32 | timeout-minutes: ${{ (matrix.language == 'swift' && 120) || 360 }} 33 | permissions: 34 | actions: read 35 | contents: read 36 | security-events: write 37 | 38 | strategy: 39 | fail-fast: false 40 | matrix: 41 | language: [ 'python' ] 42 | # CodeQL supports [ 'c-cpp', 'csharp', 'go', 'java-kotlin', 'javascript-typescript', 'python', 'ruby', 'swift' ] 43 | # Use only 'java-kotlin' to analyze code written in Java, Kotlin or both 44 | # Use only 'javascript-typescript' to analyze code written in JavaScript, TypeScript or both 45 | # Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support 46 | 47 | steps: 48 | - name: Checkout repository 49 | uses: actions/checkout@v3 50 | 51 | # Initializes the CodeQL tools for scanning. 52 | - name: Initialize CodeQL 53 | uses: github/codeql-action/init@v2 54 | with: 55 | languages: ${{ matrix.language }} 56 | # If you wish to specify custom queries, you can do so here or in a config file. 57 | # By default, queries listed here will override any specified in a config file. 58 | # Prefix the list here with "+" to use these queries and those in the config file. 59 | 60 | # For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs 61 | # queries: security-extended,security-and-quality 62 | 63 | 64 | # Autobuild attempts to build any compiled languages (C/C++, C#, Go, Java, or Swift). 65 | # If this step fails, then you should remove it and run the build manually (see below) 66 | - name: Autobuild 67 | uses: github/codeql-action/autobuild@v2 68 | 69 | # ℹ️ Command-line programs to run using the OS shell. 70 | # 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun 71 | 72 | # If the Autobuild fails above, remove it and uncomment the following three lines. 73 | # modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance. 74 | 75 | # - run: | 76 | # echo "Run, Build Application using script" 77 | # ./location_of_script_within_repo/buildscript.sh 78 | 79 | - name: Perform CodeQL Analysis 80 | uses: github/codeql-action/analyze@v2 81 | with: 82 | category: "/language:${{matrix.language}}" 83 | -------------------------------------------------------------------------------- /invitations/app_settings.py: -------------------------------------------------------------------------------- 1 | from django.conf import settings 2 | 3 | 4 | class AppSettings: 5 | def __init__(self, prefix): 6 | self.prefix = prefix 7 | 8 | def _setting(self, name, dflt): 9 | return getattr(settings, self.prefix + name, dflt) 10 | 11 | @property 12 | def INVITATION_EXPIRY(self): 13 | """How long before the invitation expires""" 14 | return self._setting("INVITATION_EXPIRY", 3) 15 | 16 | @property 17 | def INVITATION_ONLY(self): 18 | """Signup is invite only""" 19 | return self._setting("INVITATION_ONLY", False) 20 | 21 | @property 22 | def CONFIRM_INVITE_ON_GET(self): 23 | """Simple get request confirms invite""" 24 | return self._setting("CONFIRM_INVITE_ON_GET", True) 25 | 26 | @property 27 | def ACCEPT_INVITE_AFTER_SIGNUP(self): 28 | """Accept the invitation after the user finished signup.""" 29 | return self._setting("ACCEPT_INVITE_AFTER_SIGNUP", False) 30 | 31 | @property 32 | def GONE_ON_ACCEPT_ERROR(self): 33 | """ 34 | If an invalid/expired/previously accepted key is provided, return a 35 | HTTP 410 GONE response. 36 | """ 37 | return self._setting("GONE_ON_ACCEPT_ERROR", True) 38 | 39 | @property 40 | def ALLOW_JSON_INVITES(self): 41 | """Exposes json endpoint for mass invite creation""" 42 | return self._setting("ALLOW_JSON_INVITES", False) 43 | 44 | @property 45 | def SIGNUP_REDIRECT(self): 46 | """Where to redirect on email confirm of invite""" 47 | return self._setting("SIGNUP_REDIRECT", "account_signup") 48 | 49 | @property 50 | def LOGIN_REDIRECT(self): 51 | """Where to redirect on an expired or already accepted invite""" 52 | return self._setting("LOGIN_REDIRECT", settings.LOGIN_URL) 53 | 54 | @property 55 | def ADAPTER(self): 56 | """The adapter, setting ACCOUNT_ADAPTER overrides this default""" 57 | return self._setting("ADAPTER", "invitations.adapters.BaseInvitationsAdapter") 58 | 59 | @property 60 | def EMAIL_MAX_LENGTH(self): 61 | """ 62 | Adjust max_length of e-mail addresses 63 | """ 64 | return self._setting("EMAIL_MAX_LENGTH", 254) 65 | 66 | @property 67 | def EMAIL_SUBJECT_PREFIX(self): 68 | """ 69 | Subject-line prefix to use for email messages sent 70 | """ 71 | return self._setting("EMAIL_SUBJECT_PREFIX", None) 72 | 73 | @property 74 | def INVITATION_MODEL(self): 75 | """ 76 | Subject-line prefix to use for Invitation model setup 77 | """ 78 | return self._setting("INVITATION_MODEL", "invitations.Invitation") 79 | 80 | @property 81 | def INVITE_FORM(self): 82 | """ 83 | Form class used for sending invites outside admin. 84 | """ 85 | return self._setting("INVITE_FORM", "invitations.forms.InviteForm") 86 | 87 | @property 88 | def ADMIN_ADD_FORM(self): 89 | """ 90 | Form class used for sending invites in admin. 91 | """ 92 | return self._setting( 93 | "ADMIN_ADD_FORM", 94 | "invitations.forms.InvitationAdminAddForm", 95 | ) 96 | 97 | @property 98 | def ADMIN_CHANGE_FORM(self): 99 | """ 100 | Form class used for updating invitations in admin. 101 | """ 102 | return self._setting( 103 | "ADMIN_CHANGE_FORM", 104 | "invitations.forms.InvitationAdminChangeForm", 105 | ) 106 | 107 | @property 108 | def CONFIRMATION_URL_NAME(self): 109 | return self._setting("CONFIRMATION_URL_NAME", "invitations:accept-invite") 110 | 111 | 112 | app_settings = AppSettings("INVITATIONS_") 113 | -------------------------------------------------------------------------------- /invitations/locale/pt_BR/LC_MESSAGES/django.po: -------------------------------------------------------------------------------- 1 | # SOME DESCRIPTIVE TITLE. 2 | # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER 3 | # This file is distributed under the same license as the PACKAGE package. 4 | # FIRST AUTHOR , YEAR. 5 | # 6 | #, fuzzy 7 | msgid "" 8 | msgstr "" 9 | "Project-Id-Version: PACKAGE VERSION\n" 10 | "Report-Msgid-Bugs-To: \n" 11 | "POT-Creation-Date: 2024-06-14 06:18-0500\n" 12 | "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" 13 | "Last-Translator: FULL NAME \n" 14 | "Language-Team: LANGUAGE \n" 15 | "Language: \n" 16 | "MIME-Version: 1.0\n" 17 | "Content-Type: text/plain; charset=UTF-8\n" 18 | "Content-Transfer-Encoding: 8bit\n" 19 | "Plural-Forms: nplurals=2; plural=(n > 1);\n" 20 | 21 | #: base_invitation.py:9 22 | msgid "accepted" 23 | msgstr "aceito" 24 | 25 | #: base_invitation.py:10 26 | msgid "key" 27 | msgstr "chave" 28 | 29 | #: base_invitation.py:11 30 | msgid "sent" 31 | msgstr "enviado" 32 | 33 | #: base_invitation.py:14 34 | msgid "inviter" 35 | msgstr "Convidador" 36 | 37 | #: forms.py:28 38 | msgid "This e-mail address has already been invited." 39 | msgstr "Esse endereço de e-mail já foi convidado." 40 | 41 | #: forms.py:30 42 | msgid "This e-mail address has already accepted an invite." 43 | msgstr "Esse endereço de e-mail já aceitou um convite." 44 | 45 | #: forms.py:32 46 | msgid "An active user is using this e-mail address" 47 | msgstr "Um usuário ativo está usando esse endereço de e-mail" 48 | 49 | #: forms.py:47 forms.py:59 50 | msgid "E-mail" 51 | msgstr "E-mail" 52 | 53 | #: models.py:25 54 | msgid "e-mail address" 55 | msgstr "endereço de e-mail" 56 | 57 | #: models.py:28 58 | msgid "created" 59 | msgstr "criado" 60 | 61 | #: templates/invitations/email/email_invite_message.txt:3 62 | #, python-format 63 | msgid "" 64 | "\n" 65 | "\n" 66 | "Hello,\n" 67 | "\n" 68 | "You (%(email)s) have been invited to join %(site_name)s\n" 69 | "\n" 70 | "If you'd like to join, please go to %(invite_url)s\n" 71 | "\n" 72 | msgstr "" 73 | "\n" 74 | "\n" 75 | "Olá,\n" 76 | "\n" 77 | "Você (%(email)s) foi convidado a participar do site %(site_name)s\n" 78 | "\n" 79 | "Se for do seu interesse participar, siga o link %(invite_url)s\n" 80 | "\n" 81 | 82 | #: templates/invitations/email/email_invite_subject.txt:3 83 | #, python-format 84 | msgid "Invitation to join %(site_name)s" 85 | msgstr "Convite para participar do site %(site_name)s" 86 | 87 | #: templates/invitations/forms/_invite.html:3 88 | msgid "Invite" 89 | msgstr "Convite" 90 | 91 | #: templates/invitations/forms/_invite.html:4 92 | msgid "Please add an email below. The user will receive an email with instructions." 93 | msgstr "Por favor adicione um email abaixo. O usuário receberá um email com instruções." 94 | 95 | #: templates/invitations/forms/_invite.html:9 96 | msgid "Email" 97 | msgstr "Email" 98 | 99 | #: templates/invitations/messages/invite_accepted.txt:3 100 | #, python-format 101 | msgid "Invitation to - %(email)s - has been accepted" 102 | msgstr "O convite para - %(email)s - foi aceito" 103 | 104 | #: templates/invitations/messages/invite_already_accepted.txt:3 105 | #, python-format 106 | msgid "The invitation for %(email)s was already accepted." 107 | msgstr "O convite para %(email)s já foi aceito." 108 | 109 | #: templates/invitations/messages/invite_expired.txt:3 110 | #, python-format 111 | msgid "The invitation for %(email)s has expired." 112 | msgstr "O convite para %(email)s expirou." 113 | 114 | #: templates/invitations/messages/invite_invalid.txt:3 115 | msgid "An invalid invitation key was submitted." 116 | msgstr "Uma chave de convite inválida foi enviada." 117 | 118 | #: views.py:52 119 | #, python-format 120 | msgid "%(email)s has been invited" 121 | msgstr "%(email)s foi convidado" 122 | 123 | #: views.py:131 124 | msgid "405 Method Not Allowed" 125 | msgstr "" 126 | -------------------------------------------------------------------------------- /invitations/locale/fr/LC_MESSAGES/django.po: -------------------------------------------------------------------------------- 1 | # SOME DESCRIPTIVE TITLE. 2 | # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER 3 | # This file is distributed under the same license as the PACKAGE package. 4 | # FIRST AUTHOR , YEAR. 5 | # 6 | msgid "" 7 | msgstr "" 8 | "Project-Id-Version: \n" 9 | "Report-Msgid-Bugs-To: \n" 10 | "POT-Creation-Date: 2024-06-14 06:18-0500\n" 11 | "PO-Revision-Date: 2020-02-16 18:57+0100\n" 12 | "Last-Translator: \n" 13 | "Language-Team: \n" 14 | "Language: fr\n" 15 | "MIME-Version: 1.0\n" 16 | "Content-Type: text/plain; charset=UTF-8\n" 17 | "Content-Transfer-Encoding: 8bit\n" 18 | "Plural-Forms: nplurals=2; plural=(n > 1);\n" 19 | "X-Generator: Poedit 2.2.1\n" 20 | 21 | #: base_invitation.py:9 22 | msgid "accepted" 23 | msgstr "acceptée" 24 | 25 | #: base_invitation.py:10 26 | msgid "key" 27 | msgstr "clef" 28 | 29 | #: base_invitation.py:11 30 | msgid "sent" 31 | msgstr "envoyée" 32 | 33 | #: base_invitation.py:14 34 | #, fuzzy 35 | #| msgid "Invite" 36 | msgid "inviter" 37 | msgstr "Inviter" 38 | 39 | #: forms.py:28 40 | msgid "This e-mail address has already been invited." 41 | msgstr "Cette adresse e-mail a déjà reçu une invitation." 42 | 43 | #: forms.py:30 44 | msgid "This e-mail address has already accepted an invite." 45 | msgstr "Cette adresse e-mail a déjà accepté une invitation." 46 | 47 | #: forms.py:32 48 | msgid "An active user is using this e-mail address" 49 | msgstr "Un utilisateur actif utilise cette adresse e-mail" 50 | 51 | #: forms.py:47 forms.py:59 52 | msgid "E-mail" 53 | msgstr "E-mail" 54 | 55 | #: models.py:25 56 | msgid "e-mail address" 57 | msgstr "adresse e-mail" 58 | 59 | #: models.py:28 60 | msgid "created" 61 | msgstr "créée" 62 | 63 | #: templates/invitations/email/email_invite_message.txt:3 64 | #, python-format 65 | msgid "" 66 | "\n" 67 | "\n" 68 | "Hello,\n" 69 | "\n" 70 | "You (%(email)s) have been invited to join %(site_name)s\n" 71 | "\n" 72 | "If you'd like to join, please go to %(invite_url)s\n" 73 | "\n" 74 | msgstr "" 75 | "\n" 76 | "\n" 77 | "Bonjour,\n" 78 | "\n" 79 | "Vous (%(email)s) avez été invité·e à rejoindre %(site_name)s\n" 80 | "\n" 81 | "Si vous souhaitez vous inscrire, merci de suivre ce lien: %(invite_url)s\n" 82 | "\n" 83 | 84 | #: templates/invitations/email/email_invite_subject.txt:3 85 | #, python-format 86 | msgid "Invitation to join %(site_name)s" 87 | msgstr "Invitation à rejoindre %(site_name)s" 88 | 89 | #: templates/invitations/forms/_invite.html:3 90 | msgid "Invite" 91 | msgstr "Inviter" 92 | 93 | #: templates/invitations/forms/_invite.html:4 94 | msgid "Please add an email below. The user will receive an email with instructions." 95 | msgstr "Merci d'ajouter une adresse e-mail ci-dessous. L'utilisateur recevra un courriel avec des instructions." 96 | 97 | #: templates/invitations/forms/_invite.html:9 98 | msgid "Email" 99 | msgstr "Email" 100 | 101 | #: templates/invitations/messages/invite_accepted.txt:3 102 | #, python-format 103 | msgid "Invitation to - %(email)s - has been accepted" 104 | msgstr "L'invitation envoyée à - %(email)s - a été acceptée" 105 | 106 | #: templates/invitations/messages/invite_already_accepted.txt:3 107 | #, fuzzy, python-format 108 | #| msgid "Invitation to - %(email)s - has been accepted" 109 | msgid "The invitation for %(email)s was already accepted." 110 | msgstr "L'invitation envoyée à - %(email)s - a été acceptée" 111 | 112 | #: templates/invitations/messages/invite_expired.txt:3 113 | #, fuzzy, python-format 114 | #| msgid "Invitation to - %(email)s - has been accepted" 115 | msgid "The invitation for %(email)s has expired." 116 | msgstr "L'invitation envoyée à - %(email)s - a été acceptée" 117 | 118 | #: templates/invitations/messages/invite_invalid.txt:3 119 | msgid "An invalid invitation key was submitted." 120 | msgstr "" 121 | 122 | #: views.py:52 123 | #, python-format 124 | msgid "%(email)s has been invited" 125 | msgstr "%(email)s a été invité·e" 126 | 127 | #: views.py:131 128 | msgid "405 Method Not Allowed" 129 | msgstr "" 130 | -------------------------------------------------------------------------------- /invitations/locale/uk/LC_MESSAGES/django.po: -------------------------------------------------------------------------------- 1 | # SOME DESCRIPTIVE TITLE. 2 | # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER 3 | # This file is distributed under the same license as the PACKAGE package. 4 | # FIRST AUTHOR , YEAR. 5 | # 6 | #, fuzzy 7 | msgid "" 8 | msgstr "" 9 | "Project-Id-Version: PACKAGE VERSION\n" 10 | "Report-Msgid-Bugs-To: \n" 11 | "POT-Creation-Date: 2024-06-14 06:18-0500\n" 12 | "PO-Revision-Date: 2018-01-07 18:53+0500\n" 13 | "Last-Translator: FULL NAME \n" 14 | "Language-Team: LANGUAGE \n" 15 | "Language: \n" 16 | "MIME-Version: 1.0\n" 17 | "Content-Type: text/plain; charset=UTF-8\n" 18 | "Content-Transfer-Encoding: 8bit\n" 19 | "Plural-Forms: nplurals=4; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<12 || n%100>14) ? 1 : n%10==0 || (n%10>=5 && n%10<=9) || (n%100>=11 && n%100<=14)? 2 : 3);\n" 20 | 21 | #: base_invitation.py:9 22 | msgid "accepted" 23 | msgstr "прийнятий" 24 | 25 | #: base_invitation.py:10 26 | msgid "key" 27 | msgstr "ключ" 28 | 29 | #: base_invitation.py:11 30 | msgid "sent" 31 | msgstr "відправлений" 32 | 33 | #: base_invitation.py:14 34 | #, fuzzy 35 | #| msgid "Invite" 36 | msgid "inviter" 37 | msgstr "Запрошення" 38 | 39 | #: forms.py:28 40 | msgid "This e-mail address has already been invited." 41 | msgstr "На цей e-mail вже відправлено запрошення." 42 | 43 | #: forms.py:30 44 | msgid "This e-mail address has already accepted an invite." 45 | msgstr "Запрошення, відправлене на цей e-mail, вже прийнято" 46 | 47 | #: forms.py:32 48 | msgid "An active user is using this e-mail address" 49 | msgstr "Користувач з цим e-mail вже існує" 50 | 51 | #: forms.py:47 forms.py:59 52 | msgid "E-mail" 53 | msgstr "E-mail" 54 | 55 | #: models.py:25 56 | msgid "e-mail address" 57 | msgstr "e-mail адрес" 58 | 59 | #: models.py:28 60 | msgid "created" 61 | msgstr "створений" 62 | 63 | #: templates/invitations/email/email_invite_message.txt:3 64 | #, python-format 65 | msgid "" 66 | "\n" 67 | "\n" 68 | "Hello,\n" 69 | "\n" 70 | "You (%(email)s) have been invited to join %(site_name)s\n" 71 | "\n" 72 | "If you'd like to join, please go to %(invite_url)s\n" 73 | "\n" 74 | msgstr "" 75 | "\n" 76 | "\n" 77 | "Здрастуйте,\n" 78 | "\n" 79 | "Ви (%(email)s) запрошені приєднатися до проекту %(site_name)s\n" 80 | "\n" 81 | "Якщо ви хочете приєднатися, перейдіть за посиланням %(invite_url)s\n" 82 | "\n" 83 | 84 | #: templates/invitations/email/email_invite_subject.txt:3 85 | #, python-format 86 | msgid "Invitation to join %(site_name)s" 87 | msgstr "Запрошення приєднатися до %(site_name)s" 88 | 89 | #: templates/invitations/forms/_invite.html:3 90 | msgid "Invite" 91 | msgstr "Запрошення" 92 | 93 | #: templates/invitations/forms/_invite.html:4 94 | msgid "Please add an email below. The user will receive an email with instructions." 95 | msgstr "Введіть email нижче і користувач отримає лист з інструкціями." 96 | 97 | #: templates/invitations/forms/_invite.html:9 98 | msgid "Email" 99 | msgstr "Email" 100 | 101 | #: templates/invitations/messages/invite_accepted.txt:3 102 | #, python-format 103 | msgid "Invitation to - %(email)s - has been accepted" 104 | msgstr "Запрошення, надіслане на %(email)s, прийнято" 105 | 106 | #: templates/invitations/messages/invite_already_accepted.txt:3 107 | #, fuzzy, python-format 108 | #| msgid "Invitation to - %(email)s - has been accepted" 109 | msgid "The invitation for %(email)s was already accepted." 110 | msgstr "Запрошення, надіслане на %(email)s, прийнято" 111 | 112 | #: templates/invitations/messages/invite_expired.txt:3 113 | #, fuzzy, python-format 114 | #| msgid "Invitation to - %(email)s - has been accepted" 115 | msgid "The invitation for %(email)s has expired." 116 | msgstr "Запрошення, надіслане на %(email)s, прийнято" 117 | 118 | #: templates/invitations/messages/invite_invalid.txt:3 119 | msgid "An invalid invitation key was submitted." 120 | msgstr "" 121 | 122 | #: views.py:52 123 | #, python-format 124 | msgid "%(email)s has been invited" 125 | msgstr "Запрошення відправлено на %(email)s" 126 | 127 | #: views.py:131 128 | msgid "405 Method Not Allowed" 129 | msgstr "" 130 | -------------------------------------------------------------------------------- /invitations/locale/ru/LC_MESSAGES/django.po: -------------------------------------------------------------------------------- 1 | # SOME DESCRIPTIVE TITLE. 2 | # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER 3 | # This file is distributed under the same license as the PACKAGE package. 4 | # FIRST AUTHOR , YEAR. 5 | # 6 | #, fuzzy 7 | msgid "" 8 | msgstr "" 9 | "Project-Id-Version: PACKAGE VERSION\n" 10 | "Report-Msgid-Bugs-To: \n" 11 | "POT-Creation-Date: 2024-06-14 06:18-0500\n" 12 | "PO-Revision-Date: 2018-01-07 18:53+0500\n" 13 | "Last-Translator: FULL NAME \n" 14 | "Language-Team: LANGUAGE \n" 15 | "Language: \n" 16 | "MIME-Version: 1.0\n" 17 | "Content-Type: text/plain; charset=UTF-8\n" 18 | "Content-Transfer-Encoding: 8bit\n" 19 | "Plural-Forms: nplurals=4; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<12 || n%100>14) ? 1 : n%10==0 || (n%10>=5 && n%10<=9) || (n%100>=11 && n%100<=14)? 2 : 3);\n" 20 | 21 | #: base_invitation.py:9 22 | msgid "accepted" 23 | msgstr "принято" 24 | 25 | #: base_invitation.py:10 26 | msgid "key" 27 | msgstr "ключ" 28 | 29 | #: base_invitation.py:11 30 | msgid "sent" 31 | msgstr "отправлено" 32 | 33 | #: base_invitation.py:14 34 | #, fuzzy 35 | #| msgid "Invite" 36 | msgid "inviter" 37 | msgstr "Приглашение" 38 | 39 | #: forms.py:28 40 | msgid "This e-mail address has already been invited." 41 | msgstr "На этот e-mail уже отправлено приглашение." 42 | 43 | #: forms.py:30 44 | msgid "This e-mail address has already accepted an invite." 45 | msgstr "Приглашение, отправленное на этот e-mail, уже принято." 46 | 47 | #: forms.py:32 48 | msgid "An active user is using this e-mail address" 49 | msgstr "Пользователь с e-mail уже существует" 50 | 51 | #: forms.py:47 forms.py:59 52 | msgid "E-mail" 53 | msgstr "E-mail" 54 | 55 | #: models.py:25 56 | msgid "e-mail address" 57 | msgstr "e-mail адрес" 58 | 59 | #: models.py:28 60 | msgid "created" 61 | msgstr "создано" 62 | 63 | #: templates/invitations/email/email_invite_message.txt:3 64 | #, python-format 65 | msgid "" 66 | "\n" 67 | "\n" 68 | "Hello,\n" 69 | "\n" 70 | "You (%(email)s) have been invited to join %(site_name)s\n" 71 | "\n" 72 | "If you'd like to join, please go to %(invite_url)s\n" 73 | "\n" 74 | msgstr "" 75 | "\n" 76 | "\n" 77 | "Здравствуйте,\n" 78 | "\n" 79 | "Вы (%(email)s) приглашены присоединиться к проекту %(site_name)s\n" 80 | "\n" 81 | "Если Вы хотите присоединиться, перейдите по ссылке %(invite_url)s\n" 82 | "\n" 83 | 84 | #: templates/invitations/email/email_invite_subject.txt:3 85 | #, python-format 86 | msgid "Invitation to join %(site_name)s" 87 | msgstr "Приглашение присоединиться к %(site_name)s" 88 | 89 | #: templates/invitations/forms/_invite.html:3 90 | msgid "Invite" 91 | msgstr "Приглашение" 92 | 93 | #: templates/invitations/forms/_invite.html:4 94 | msgid "Please add an email below. The user will receive an email with instructions." 95 | msgstr "Введите email ниже и пользователь получит письмо с инструкциями." 96 | 97 | #: templates/invitations/forms/_invite.html:9 98 | msgid "Email" 99 | msgstr "Email" 100 | 101 | #: templates/invitations/messages/invite_accepted.txt:3 102 | #, python-format 103 | msgid "Invitation to - %(email)s - has been accepted" 104 | msgstr "Приглашение, отправленное на %(email)s, принято" 105 | 106 | #: templates/invitations/messages/invite_already_accepted.txt:3 107 | #, fuzzy, python-format 108 | #| msgid "Invitation to - %(email)s - has been accepted" 109 | msgid "The invitation for %(email)s was already accepted." 110 | msgstr "Приглашение, отправленное на %(email)s, принято" 111 | 112 | #: templates/invitations/messages/invite_expired.txt:3 113 | #, fuzzy, python-format 114 | #| msgid "Invitation to - %(email)s - has been accepted" 115 | msgid "The invitation for %(email)s has expired." 116 | msgstr "Приглашение, отправленное на %(email)s, принято" 117 | 118 | #: templates/invitations/messages/invite_invalid.txt:3 119 | msgid "An invalid invitation key was submitted." 120 | msgstr "" 121 | 122 | #: views.py:52 123 | #, python-format 124 | msgid "%(email)s has been invited" 125 | msgstr "Приглашение отправлено на %(email)s" 126 | 127 | #: views.py:131 128 | msgid "405 Method Not Allowed" 129 | msgstr "" 130 | -------------------------------------------------------------------------------- /invitations/locale/de/LC_MESSAGES/django.po: -------------------------------------------------------------------------------- 1 | # SOME DESCRIPTIVE TITLE. 2 | # Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER 3 | # This file is distributed under the same license as the PACKAGE package. 4 | # FIRST AUTHOR , YEAR. 5 | # 6 | #, fuzzy 7 | msgid "" 8 | msgstr "" 9 | "Project-Id-Version: PACKAGE VERSION\n" 10 | "Report-Msgid-Bugs-To: \n" 11 | "POT-Creation-Date: 2024-06-14 06:18-0500\n" 12 | "PO-Revision-Date: 2018-01-07 18:53+0500\n" 13 | "Last-Translator: FULL NAME \n" 14 | "Language-Team: LANGUAGE \n" 15 | "Language: \n" 16 | "MIME-Version: 1.0\n" 17 | "Content-Type: text/plain; charset=UTF-8\n" 18 | "Content-Transfer-Encoding: 8bit\n" 19 | "Plural-Forms: nplurals=2; plural=(n != 1);\n" 20 | 21 | #: base_invitation.py:9 22 | msgid "accepted" 23 | msgstr "angenommen" 24 | 25 | #: base_invitation.py:10 26 | msgid "key" 27 | msgstr "Schlüssel" 28 | 29 | #: base_invitation.py:11 30 | msgid "sent" 31 | msgstr "gesendet" 32 | 33 | #: base_invitation.py:14 34 | #, fuzzy 35 | #| msgid "Invite" 36 | msgid "inviter" 37 | msgstr "Einladung" 38 | 39 | #: forms.py:28 40 | msgid "This e-mail address has already been invited." 41 | msgstr "Diese E-Mail-Adresse wurde bereits eingeladen." 42 | 43 | #: forms.py:30 44 | msgid "This e-mail address has already accepted an invite." 45 | msgstr "Diese E-Mail-Adresse hat bereits eine Einladung angenommen." 46 | 47 | #: forms.py:32 48 | msgid "An active user is using this e-mail address" 49 | msgstr "Ein aktiver Benutzer verwendet diese E-Mail-Adresse" 50 | 51 | #: forms.py:47 forms.py:59 52 | msgid "E-mail" 53 | msgstr "E-Mail" 54 | 55 | #: models.py:25 56 | msgid "e-mail address" 57 | msgstr "E-Mail-Adresse" 58 | 59 | #: models.py:28 60 | msgid "created" 61 | msgstr "erstellt" 62 | 63 | #: templates/invitations/email/email_invite_message.txt:3 64 | #, python-format 65 | msgid "" 66 | "\n" 67 | "\n" 68 | "Hello,\n" 69 | "\n" 70 | "You (%(email)s) have been invited to join %(site_name)s\n" 71 | "\n" 72 | "If you'd like to join, please go to %(invite_url)s\n" 73 | "\n" 74 | msgstr "" 75 | "\n" 76 | "\n" 77 | "Hallo,\n" 78 | "\n" 79 | "Sie (%(email)s) wurden eingeladen, %(site_name)s s beizutreten\n" 80 | "\n" 81 | "Wenn Sie mitmachen möchten, gehen Sie bitte zu %(invite_url)s\n" 82 | "\n" 83 | 84 | #: templates/invitations/email/email_invite_subject.txt:3 85 | #, python-format 86 | msgid "Invitation to join %(site_name)s" 87 | msgstr "Einladung zum Beitritt %(site_name)s" 88 | 89 | #: templates/invitations/forms/_invite.html:3 90 | msgid "Invite" 91 | msgstr "Einladung" 92 | 93 | #: templates/invitations/forms/_invite.html:4 94 | #, fuzzy 95 | #| msgid "Please add an email below. The user will recieve an email with instructions." 96 | msgid "Please add an email below. The user will receive an email with instructions." 97 | msgstr "Bitte fügen Sie eine E-Mail unten hinzu. Der Benutzer erhält eine E-Mail mit Anweisungen." 98 | 99 | #: templates/invitations/forms/_invite.html:9 100 | msgid "Email" 101 | msgstr "E-mail" 102 | 103 | #: templates/invitations/messages/invite_accepted.txt:3 104 | #, python-format 105 | msgid "Invitation to - %(email)s - has been accepted" 106 | msgstr "Die an %(email)s gesendete Einladung wurde angenommen" 107 | 108 | #: templates/invitations/messages/invite_already_accepted.txt:3 109 | #, fuzzy, python-format 110 | #| msgid "Invitation to - %(email)s - has been accepted" 111 | msgid "The invitation for %(email)s was already accepted." 112 | msgstr "Die an %(email)s gesendete Einladung wurde angenommen" 113 | 114 | #: templates/invitations/messages/invite_expired.txt:3 115 | #, fuzzy, python-format 116 | #| msgid "Invitation to - %(email)s - has been accepted" 117 | msgid "The invitation for %(email)s has expired." 118 | msgstr "Die an %(email)s gesendete Einladung wurde angenommen" 119 | 120 | #: templates/invitations/messages/invite_invalid.txt:3 121 | msgid "An invalid invitation key was submitted." 122 | msgstr "" 123 | 124 | #: views.py:52 125 | #, python-format 126 | msgid "%(email)s has been invited" 127 | msgstr "Einladung ist an %(email)s gesendet" 128 | 129 | #: views.py:131 130 | msgid "405 Method Not Allowed" 131 | msgstr "" 132 | -------------------------------------------------------------------------------- /docs/configuration.rst: -------------------------------------------------------------------------------- 1 | Configuration 2 | ============= 3 | 4 | 5 | General settings 6 | ---------------- 7 | 8 | ``INVITATIONS_INVITATION_EXPIRY`` 9 | ********************************* 10 | 11 | Type: Integer 12 | 13 | Default: ``3`` 14 | 15 | How many days before the invitation expires. 16 | 17 | ---- 18 | 19 | ``INVITATIONS_CONFIRM_INVITE_ON_GET`` 20 | ************************************* 21 | 22 | Type: Boolean 23 | 24 | Default: ``True`` 25 | 26 | If confirmations can be accepted via a ``GET`` request. 27 | 28 | ---- 29 | 30 | ``INVITATIONS_ACCEPT_INVITE_AFTER_SIGNUP`` 31 | ****************************************** 32 | 33 | Type: Boolean 34 | 35 | Default: ``False`` 36 | 37 | If ``True``, invitations will be accepted after users finish signup. 38 | If ``False``, invitations will be accepted right after the invitation link is clicked. 39 | Note that this only works with Allauth for now, which means ``ACCOUNT_ADAPTER`` has to be 40 | ``invitations.models.InvitationsAdapter``. 41 | 42 | ---- 43 | 44 | ``INVITATIONS_GONE_ON_ACCEPT_ERROR`` 45 | ************************************ 46 | 47 | Type: Boolean 48 | 49 | Default: ``True`` 50 | 51 | If ``True``, return an HTTP 410 GONE response if the invitation key 52 | is invalid, or the invitation is expired or previously accepted when 53 | accepting an invite. If `False`, display an error message and redirect on 54 | errors: 55 | 56 | * Redirects to ``INVITATIONS_SIGNUP_REDIRECT`` on an expired key 57 | * Otherwise, redirects to ``INVITATIONS_LOGIN_REDIRECT`` on other errors. 58 | 59 | ---- 60 | 61 | ``INVITATIONS_ALLOW_JSON_INVITES`` 62 | ********************************** 63 | 64 | Type: Boolean 65 | 66 | Default: ``False`` 67 | 68 | Expose a URL for authenticated posting of invitees 69 | 70 | ---- 71 | 72 | ``INVITATIONS_SIGNUP_REDIRECT`` 73 | ******************************* 74 | 75 | Type: String 76 | 77 | Default: ``"account_signup"`` 78 | 79 | URL name of your signup URL. 80 | 81 | ---- 82 | 83 | ``INVITATIONS_LOGIN_REDIRECT`` 84 | ****************************** 85 | 86 | Type: String 87 | 88 | Default: ``LOGIN_URL`` from Django settings 89 | 90 | URL name of your login URL. 91 | 92 | ---- 93 | 94 | ``INVITATIONS_ADAPTER`` 95 | *********************** 96 | 97 | Type: String 98 | 99 | Default: ``"invitations.adapters.BaseInvitationsAdapter"`` 100 | 101 | Used for custom integrations. Set this to ``ACCOUNT_ADAPTER`` if using django-allauth. 102 | 103 | ---- 104 | 105 | ``INVITATIONS_EMAIL_MAX_LENGTH`` 106 | ******************************** 107 | 108 | Type: Integer 109 | 110 | Default: ``254`` 111 | 112 | If set to ``None`` (the default), invitation email max length will be set up to 254. Set this to an integer value to set up a custome email max length value. 113 | 114 | ---- 115 | 116 | ``INVITATIONS_EMAIL_SUBJECT_PREFIX`` 117 | ************************************ 118 | 119 | Type: String or None 120 | 121 | Default: ``None`` 122 | 123 | If set to ``None`` (the default), invitation email subjects will be prefixed with the name of the current Site in brackets (such as `[example.com]`). Set this to a string to for a custom email subject prefix, or an empty string for no prefix. 124 | 125 | ---- 126 | 127 | ``INVITATIONS_INVITATION_MODEL`` 128 | ******************************** 129 | 130 | Type: String 131 | 132 | Default: ``"invitations.Invitation"`` 133 | 134 | App registry path of the invitation model used in the current project, for customization purposes. 135 | 136 | ---- 137 | 138 | ``INVITATIONS_INVITE_FORM`` 139 | *************************** 140 | 141 | Type: String 142 | 143 | Default: ``"invitations.forms.InviteForm"`` 144 | 145 | Form class used for sending invites outside admin. 146 | 147 | ---- 148 | 149 | ``INVITATIONS_ADMIN_ADD_FORM`` 150 | ****************************** 151 | 152 | Type: String 153 | 154 | Default: ``"invitations.forms.InvitationAdminAddForm"`` 155 | 156 | Form class used for sending invites in admin. 157 | 158 | ---- 159 | 160 | ``INVITATIONS_ADMIN_CHANGE_FORM`` 161 | ********************************* 162 | 163 | Type: String 164 | 165 | Default: ``"invitations.forms.InvitationAdminChangeForm"`` 166 | 167 | Form class used for updating invites in admin. 168 | 169 | ---- 170 | 171 | ``INVITATIONS_CONFIRMATION_URL_NAME`` 172 | ************************************* 173 | Type: String 174 | 175 | Default: ``"invitations:accept-invite"`` 176 | 177 | Invitation confirmation URL 178 | 179 | Allauth related settings 180 | ------------------------ 181 | 182 | ``INVITATIONS_INVITATION_ONLY`` 183 | ******************************* 184 | 185 | Type: Boolean 186 | 187 | Default: ``False`` 188 | 189 | If the site is invite only, or open to all (only relevant when using allauth). 190 | -------------------------------------------------------------------------------- /invitations/adapters.py: -------------------------------------------------------------------------------- 1 | from django.conf import settings 2 | from django.contrib import messages 3 | from django.core.mail import EmailMessage, EmailMultiAlternatives 4 | from django.template import TemplateDoesNotExist 5 | from django.template.loader import render_to_string 6 | from django.utils.encoding import force_str 7 | 8 | from .app_settings import app_settings 9 | from .utils import import_attribute 10 | 11 | 12 | # Code credits here to django-allauth 13 | class BaseInvitationsAdapter: 14 | def stash_verified_email(self, request, email): 15 | request.session["account_verified_email"] = email 16 | 17 | def unstash_verified_email(self, request): 18 | ret = request.session.get("account_verified_email") 19 | request.session["account_verified_email"] = None 20 | return ret 21 | 22 | def format_email_subject(self, subject, context): 23 | prefix = app_settings.EMAIL_SUBJECT_PREFIX 24 | if prefix is None: 25 | site_name = context["site_name"] 26 | prefix = f"[{site_name}] " 27 | return prefix + force_str(subject) 28 | 29 | def render_mail(self, template_prefix, email, context): 30 | """ 31 | Renders an e-mail to `email`. `template_prefix` identifies the 32 | e-mail that is to be sent, e.g. "account/email/email_confirmation" 33 | """ 34 | subject = render_to_string(f"{template_prefix}_subject.txt", context) 35 | # remove superfluous line breaks 36 | subject = " ".join(subject.splitlines()).strip() 37 | subject = self.format_email_subject(subject, context) 38 | 39 | bodies = {} 40 | for ext in ["html", "txt"]: 41 | try: 42 | template_name = f"{template_prefix}_message.{ext}" 43 | bodies[ext] = render_to_string(template_name, context).strip() 44 | except TemplateDoesNotExist: 45 | if ext == "txt" and not bodies: 46 | # We need at least one body 47 | raise 48 | if "txt" in bodies: 49 | msg = EmailMultiAlternatives( 50 | subject, 51 | bodies["txt"], 52 | settings.DEFAULT_FROM_EMAIL, 53 | [email], 54 | ) 55 | if "html" in bodies: 56 | msg.attach_alternative(bodies["html"], "text/html") 57 | else: 58 | msg = EmailMessage( 59 | subject, 60 | bodies["html"], 61 | settings.DEFAULT_FROM_EMAIL, 62 | [email], 63 | ) 64 | msg.content_subtype = "html" # Main content is now text/html 65 | return msg 66 | 67 | def send_mail(self, template_prefix, email, context): 68 | msg = self.render_mail(template_prefix, email, context) 69 | msg.send() 70 | 71 | def is_open_for_signup(self, request): 72 | if hasattr(request, "session") and request.session.get( 73 | "account_verified_email", 74 | ): 75 | return True 76 | elif app_settings.INVITATION_ONLY is True: 77 | # Site is ONLY open for invites 78 | return False 79 | else: 80 | # Site is open to signup 81 | return True 82 | 83 | def clean_email(self, email): 84 | """ 85 | Validates an email value. You can hook into this if you want to 86 | (dynamically) restrict what email addresses can be chosen. 87 | """ 88 | return email 89 | 90 | def add_message( 91 | self, 92 | request, 93 | level, 94 | message_template, 95 | message_context=None, 96 | extra_tags="", 97 | ): 98 | """ 99 | Wrapper of `django.contrib.messages.add_message`, that reads 100 | the message text from a template. 101 | """ 102 | if "django.contrib.messages" in settings.INSTALLED_APPS: 103 | try: 104 | if message_context is None: 105 | message_context = {} 106 | message = render_to_string(message_template, message_context).strip() 107 | if message: 108 | messages.add_message(request, level, message, extra_tags=extra_tags) 109 | except TemplateDoesNotExist: 110 | pass 111 | 112 | 113 | def get_invitations_adapter(): 114 | # Compatibility with legacy allauth only version. 115 | LEGACY_ALLAUTH = ( 116 | hasattr(settings, "ACCOUNT_ADAPTER") 117 | and settings.ACCOUNT_ADAPTER == "invitations.models.InvitationsAdapter" 118 | ) 119 | if LEGACY_ALLAUTH: 120 | # defer to allauth 121 | from allauth.account.adapter import get_adapter 122 | 123 | return get_adapter() 124 | else: 125 | # load an adapter from elsewhere 126 | return import_attribute(app_settings.ADAPTER)() 127 | -------------------------------------------------------------------------------- /tests/allauth/test_allauth.py: -------------------------------------------------------------------------------- 1 | from invitations.app_settings import app_settings 2 | 3 | try: 4 | from django.urls import reverse 5 | except ImportError: 6 | from django.urls import reverse 7 | 8 | import pytest 9 | from allauth.account.models import EmailAddress 10 | from django.contrib.auth import REDIRECT_FIELD_NAME 11 | from django.test import Client 12 | from django.test.client import RequestFactory 13 | 14 | from invitations.adapters import get_invitations_adapter 15 | from invitations.models import InvitationsAdapter 16 | from invitations.utils import get_invitation_model 17 | 18 | Invitation = get_invitation_model() 19 | 20 | 21 | class TestAllAuthIntegrationAcceptAfterSignup: 22 | client = Client() 23 | adapter = get_invitations_adapter() 24 | 25 | @pytest.mark.parametrize( 26 | "method", 27 | [ 28 | ("get"), 29 | ("post"), 30 | ], 31 | ) 32 | def test_accept_invite_accepted_invitation_after_signup( 33 | self, 34 | settings, 35 | method, 36 | sent_invitation_by_user_a, 37 | user_a, 38 | ): 39 | settings.INVITATIONS_ACCEPT_INVITE_AFTER_SIGNUP = True 40 | client_with_method = getattr(self.client, method) 41 | resp = client_with_method( 42 | reverse( 43 | app_settings.CONFIRMATION_URL_NAME, 44 | kwargs={"key": sent_invitation_by_user_a.key}, 45 | ), 46 | follow=True, 47 | ) 48 | assert resp.status_code == 200 49 | 50 | invite = Invitation.objects.get(email="email@example.com") 51 | assert invite.inviter == user_a 52 | assert invite.accepted is False 53 | assert resp.request["PATH_INFO"] == reverse("account_signup") 54 | form = resp.context_data["form"] 55 | assert "email@example.com" == form.fields["email"].initial 56 | 57 | resp = self.client.post( 58 | reverse("account_signup"), 59 | { 60 | "email": "email@example.com", 61 | "username": "username", 62 | "password1": "password", 63 | "password2": "password", 64 | }, 65 | ) 66 | invite = Invitation.objects.get(email="email@example.com") 67 | assert invite.accepted is True 68 | 69 | @pytest.mark.parametrize( 70 | "method", 71 | [ 72 | ("get"), 73 | ("post"), 74 | ], 75 | ) 76 | def test_invite_accepted_after_signup_with_altered_case_email( 77 | self, 78 | settings, 79 | method, 80 | sent_invitation_by_user_a, 81 | user_a, 82 | ): 83 | settings.INVITATIONS_ACCEPT_INVITE_AFTER_SIGNUP = True 84 | client_with_method = getattr(self.client, method) 85 | resp = client_with_method( 86 | reverse( 87 | app_settings.CONFIRMATION_URL_NAME, 88 | kwargs={"key": sent_invitation_by_user_a.key}, 89 | ), 90 | follow=True, 91 | ) 92 | 93 | invite = Invitation.objects.get(email="email@example.com") 94 | assert invite.accepted is False 95 | form = resp.context_data["form"] 96 | assert "email@example.com" == form.fields["email"].initial 97 | 98 | resp = self.client.post( 99 | reverse("account_signup"), 100 | { 101 | "email": "EMAIL@EXAMPLE.COM", 102 | "username": "username", 103 | "password1": "password", 104 | "password2": "password", 105 | }, 106 | ) 107 | invite = Invitation.objects.get(email="email@example.com") 108 | assert invite.accepted is True 109 | 110 | 111 | class TestAllAuthIntegration: 112 | client = Client() 113 | adapter = get_invitations_adapter() 114 | 115 | @pytest.mark.parametrize( 116 | "method", 117 | [ 118 | ("get"), 119 | ("post"), 120 | ], 121 | ) 122 | def test_accept_invite_allauth( 123 | self, 124 | method, 125 | settings, 126 | user_a, 127 | sent_invitation_by_user_a, 128 | ): 129 | client_with_method = getattr(self.client, method) 130 | resp = client_with_method( 131 | reverse( 132 | app_settings.CONFIRMATION_URL_NAME, 133 | kwargs={"key": sent_invitation_by_user_a.key}, 134 | ), 135 | follow=True, 136 | ) 137 | invite = Invitation.objects.get(email="email@example.com") 138 | assert invite.accepted 139 | assert invite.inviter == user_a 140 | assert resp.request["PATH_INFO"] == reverse("account_signup") 141 | 142 | form = resp.context_data["form"] 143 | assert "email@example.com" == form.fields["email"].initial 144 | messages = resp.context["messages"] 145 | message_text = [message.message for message in messages] 146 | assert "Invitation to - email@example.com - has been accepted" in message_text 147 | 148 | resp = self.client.post( 149 | reverse("account_signup"), 150 | { 151 | "email": "email@example.com", 152 | "username": "username", 153 | "password1": "password", 154 | "password2": "password", 155 | }, 156 | ) 157 | 158 | allauth_email_obj = EmailAddress.objects.get(email="email@example.com") 159 | assert allauth_email_obj.verified is True 160 | 161 | @pytest.mark.django_db 162 | @pytest.mark.parametrize( 163 | "method", 164 | [ 165 | ("get"), 166 | ("post"), 167 | ], 168 | ) 169 | def test_accept_invite_with_signup_redirect( 170 | self, settings, sent_invitation_by_user_a, method 171 | ): 172 | client_with_method = getattr(self.client, method) 173 | next_ = "/foo/bar" 174 | url = reverse( 175 | app_settings.CONFIRMATION_URL_NAME, 176 | kwargs={ 177 | "key": sent_invitation_by_user_a.key, 178 | }, 179 | ) 180 | resp = client_with_method(f"{url}?{REDIRECT_FIELD_NAME}={next_}") 181 | 182 | assert resp.status_code == 302 183 | assert ( 184 | resp.url 185 | == f"{reverse(app_settings.SIGNUP_REDIRECT)}?{REDIRECT_FIELD_NAME}={next_}" 186 | ) 187 | 188 | @pytest.mark.django_db 189 | @pytest.mark.parametrize( 190 | "method", 191 | [ 192 | ("get"), 193 | ("post"), 194 | ], 195 | ) 196 | def test_accept_already_accepted_invite_with_login_redirect( 197 | self, settings, accepted_invitation, method 198 | ): 199 | # Disable old behavior (immediately returning a 410 GONE) 200 | settings.INVITATIONS_GONE_ON_ACCEPT_ERROR = False 201 | client_with_method = getattr(self.client, method) 202 | next_ = "/foo/bar" 203 | url = reverse( 204 | app_settings.CONFIRMATION_URL_NAME, 205 | kwargs={ 206 | "key": accepted_invitation.key, 207 | }, 208 | ) 209 | resp = client_with_method(f"{url}?{REDIRECT_FIELD_NAME}={next_}") 210 | 211 | assert resp.status_code == 302 212 | assert ( 213 | resp.url == f"{app_settings.LOGIN_REDIRECT}?{REDIRECT_FIELD_NAME}={next_}" 214 | ) 215 | 216 | @pytest.mark.django_db 217 | @pytest.mark.parametrize( 218 | "method", 219 | [ 220 | ("get"), 221 | ("post"), 222 | ], 223 | ) 224 | def test_accept_inviter_logged_in( 225 | self, settings, sent_invitation_by_user_a, method 226 | ): 227 | assert self.client.login(username="flibble", password="password") 228 | admin_resp = self.client.get(reverse("admin:index"), follow=True) 229 | assert admin_resp.wsgi_request.user.is_authenticated 230 | 231 | client_with_method = getattr(self.client, method) 232 | resp = client_with_method( 233 | reverse( 234 | app_settings.CONFIRMATION_URL_NAME, 235 | kwargs={"key": sent_invitation_by_user_a.key}, 236 | ) 237 | ) 238 | assert not resp.wsgi_request.user.is_authenticated 239 | 240 | def test_fetch_adapter(self): 241 | assert isinstance(self.adapter, InvitationsAdapter) 242 | 243 | def test_allauth_signup_open(self): 244 | signup_request = RequestFactory().get( 245 | reverse("account_signup", urlconf="allauth.account.urls"), 246 | ) 247 | assert self.adapter.is_open_for_signup(signup_request) is True 248 | 249 | @pytest.mark.django_db 250 | def test_allauth_adapter_invitation_only(self, settings): 251 | settings.INVITATIONS_INVITATION_ONLY = True 252 | signup_request = RequestFactory().get( 253 | reverse("account_signup", urlconf="allauth.account.urls"), 254 | ) 255 | assert self.adapter.is_open_for_signup(signup_request) is False 256 | response = self.client.get(reverse("account_signup")) 257 | assert "Sign Up Closed" in response.content.decode("utf8") 258 | -------------------------------------------------------------------------------- /docs/changelog.rst: -------------------------------------------------------------------------------- 1 | Changelog 2 | ========= 3 | 4 | 2.1.0 (2023-11-22) 5 | ------------------ 6 | 7 | - French translation `#142 `_ 8 | 9 | - Translation Portuguese (BR) `#193 `_ 10 | 11 | - Update pyproject.toml to include standard urls `#200 `_ 12 | 13 | - Add default_auto_field and migration `#211 `_ 14 | 15 | - Add missing configuration values for test_settings `#235 `_ 16 | 17 | - Remove mention of sites framework from docs `#220 `_ 18 | 19 | Supported versions: 20 | 21 | * Django: 3.2, 4.0, 4.1, 4.2, 5.0rc1 22 | * Python: 3.8, 3.9, 3.10, 3.11, 3.12 23 | 24 | `Full Changelog `_ 25 | 26 | 27 | 2.0.0 (2022-09-28) 28 | ------------------ 29 | 30 | - Joined Jazzband 31 | 32 | - Removed support for Django versions below 3.2 33 | 34 | - Added support for Django 4.0+. Thanks @saschahofmann `#169 `_ 35 | 36 | - Removed support for Python versions below 3.7 37 | 38 | - Added documentation 39 | 40 | - Set inviter on invitation in SendJSONInvite view. Thanks @rosexi `#151 `_ 41 | 42 | 43 | 1.9 (2017-02-11) 44 | ---------------- 45 | 46 | - Added get_signup_redirect to allow custom implementations by subclasses 47 | 48 | - Fixed invitation form displaying "None" when first displayed 49 | 50 | - Fixed deprecation warnings 51 | 52 | - Added get_signup_redirect to allow custom implementations by subclasses 53 | 54 | - Fixed flake8 errors 55 | 56 | - Import reverse from django.urls if available, otherwise fall back to old import 57 | 58 | - Set ForeignKey field to explicitly cascade on deletion 59 | 60 | - flake8 styling formatting 61 | 62 | - Add email max length setting 63 | 64 | 65 | 1.8 (2016-10-19) 66 | ---------------- 67 | 68 | Not available 69 | 70 | 71 | 1.7 (2016-02-10) 72 | ------------------------ 73 | 74 | - 1.7. [bee-keeper] 75 | 76 | - Merge pull request #34 from percipient/dont-404. [bee-keeper] 77 | 78 | Display a message on expired/erroneous/accepted keys. 79 | 80 | - Fix flake8 issues. [Patrick Cloke] 81 | 82 | - Fix a formatting mistake in the README. [Patrick Cloke] 83 | 84 | - Display a message on expired/erroneous/accepted keys. Related to #25. 85 | [Patrick Cloke] 86 | 87 | - Merge pull request #33 from percipient/readme-settings. [bee-keeper] 88 | 89 | Fix-up the settings in the README 90 | 91 | - Update the INVITATIONS_ADAPTER setting. [Patrick Cloke] 92 | 93 | - Update the readme with all the settings. [Patrick Cloke] 94 | 95 | - Removed uneeded check on send invite. [bee_keeper] 96 | 97 | - Test new url spec. [bee_keeper] 98 | 99 | - Merge pull request #32 from mjnaderi/patch-1. [bee-keeper] 100 | 101 | - Remove RemovedInDjango110Warning warnings in Django 1.9. [Mohammad 102 | Javad Naderi] 103 | 104 | 1.6 (2016-01-10) 105 | ---------------- 106 | 107 | - V1.6. [bee_keeper] 108 | 109 | - Dont override inviter from create step. [bee_keeper] 110 | 111 | - Merge pull request #30 from percipient/allauth-with-custom-adapter. 112 | [bee-keeper] 113 | 114 | Allow using custom allauth backends. 115 | 116 | - Make flake8 happy. [Patrick Cloke] 117 | 118 | - Don't return None from get_invitations_adapter. [Patrick Cloke] 119 | 120 | - Merge pull request #31 from percipient/set-inviter. [bee-keeper] 121 | 122 | Set the inviter in the SendInvite view. 123 | 124 | - Set the inviter in the SendInvite view. [Patrick Cloke] 125 | 126 | - Update README.md. [bee-keeper] 127 | 128 | 1.5 (2015-12-07) 129 | ---------------- 130 | 131 | - Update README.md. [bee-keeper] 132 | 133 | - Merge pull request #24 from bee-keeper/devel. [bee-keeper] 134 | 135 | Refactor as generic invite app 136 | 137 | - Removed the dependency on django-allauth, this package is now a 138 | generic invite app. [bee_keeper] 139 | 140 | 1.4 (2015-11-27) 141 | ---------------- 142 | 143 | - 1.4. [bee_keeper] 144 | 145 | - Merge pull request #23 from bee-keeper/devel. [bee-keeper] 146 | 147 | Coverage and exposing inviter in admin 148 | 149 | - Coverage and exposing inviter in admin. [bee_keeper] 150 | 151 | 1.3 (2015-11-26) 152 | ---------------- 153 | 154 | - Merge pull request #22 from bee-keeper/devel. [bee-keeper] 155 | 156 | Added inviter to invitation 157 | 158 | - Added inviter to invitation. [bee_keeper] 159 | 160 | - Merge pull request #21 from bee-keeper/devel. [bee-keeper] 161 | 162 | Support for django1.9 163 | 164 | - Testing for django1.9 and python 3.5. [bee_keeper] 165 | 166 | - Merge pull request #20 from bee-keeper/devel. [bee-keeper] 167 | 168 | Added json endpoint for invites 169 | 170 | - Added json endpoint for invites. [bee_keeper] 171 | 172 | - Merge pull request #19 from bee-keeper/devel. [bee-keeper] 173 | 174 | Made accept trailing slash optional 175 | 176 | - Made trailing slash optional and added flake8 to CI. [bee_keeper] 177 | 178 | Bumped to version 1.3 179 | 180 | - Update models.py. [bee-keeper] 181 | 182 | - Roadmap. [bee_keeper] 183 | 184 | 1.2 (2015-08-29) 185 | ---------------- 186 | 187 | - Test coverage done, ready for 1.2 release. [bee_keeper] 188 | 189 | - Dropping support for python 3.2. [bee_keeper] 190 | 191 | - Dropping support for python 3.2. [bee_keeper] 192 | 193 | - Signal test coverage, tweaking tox. [bee_keeper] 194 | 195 | - Coverage. [bee-keeper] 196 | 197 | - Tox+travis. [bee-keeper] 198 | 199 | - Tox. [bee-keeper] 200 | 201 | - Tox+travis. [bee-keeper] 202 | 203 | - Testing tox+travis. [bee-keeper] 204 | 205 | - Testing tox+travis. [bee-keeper] 206 | 207 | - Tox file. [bee_keeper] 208 | 209 | - Py3 fix. [bee_keeper] 210 | 211 | - Test for signup redirect. [bee_keeper] 212 | 213 | - Update README.md. [bee-keeper] 214 | 215 | - Py 3.2. [bee_keeper] 216 | 217 | - Py 3.2. [bee-keeper] 218 | 219 | - Print. [bee-keeper] 220 | 221 | - Tests and bug fixes. [bee-keeper] 222 | 223 | 1.1 (2015-08-05) 224 | ---------------- 225 | 226 | - V 1.1. [bee_keeper] 227 | 228 | - Readme. [bee_keeper] 229 | 230 | - Modified PR (15) + editorconfig. [bee_keeper] 231 | 232 | - Merge branch 'nwaxiomatic-master' [bee_keeper] 233 | 234 | - Admin invitations. [Nic] 235 | 236 | sends invitations from admin on save 237 | 238 | 1.0 (2015-07-26) 239 | ---------------- 240 | 241 | - Release 1.0. [bee_keeper] 242 | 243 | - Requirements. [bee_keeper] 244 | 245 | - Changing travis supported versions. [bee_keeper] 246 | 247 | - Travis. [bee_keeper] 248 | 249 | - Travis. [bee_keeper] 250 | 251 | - Remove 2.6 from testing. [bee_keeper] 252 | 253 | - Requirements and changelog. [bee_keeper] 254 | 255 | - Test settings. [bee_keeper] 256 | 257 | - Requirements.txt. [bee_keeper] 258 | 259 | - Travis. [bee_keeper] 260 | 261 | - Removing uneeded imports. [bee_keeper] 262 | 263 | - Removed ALLOWED_GROUPS setting. [bee_keeper] 264 | 265 | - Merge pull request #12 from tbarbugli/patch-1. [bee-keeper] 266 | 267 | fix invite form 268 | 269 | - Fix invite form. [Tommaso Barbugli] 270 | 271 | - Update views.py. [bee-keeper] 272 | 273 | - Teavis. [bee_keeper] 274 | 275 | - Travis. [bee_keeper] 276 | 277 | - Travis. [bee_keeper] 278 | 279 | - Travis. [bee_keeper] 280 | 281 | - Travis. [bee_keeper] 282 | 283 | - Travis. [bee_keeper] 284 | 285 | - App settings. [bee_keeper] 286 | 287 | - Merge pull request #6 from simonv3/master. [bee-keeper] 288 | 289 | # Redo pull request of adding inviter to signal. 290 | 291 | - Add reference to inviter in signal. [Simon] 292 | 293 | - .travis.yml. [bee_keeper] 294 | 295 | - .travis.yml. [bee_keeper] 296 | 297 | - Readme. [bee_keeper] 298 | 299 | - Fixing py3.2 import issues. [bee_keeper] 300 | 301 | - Invitations/app_settings.py. [bee_keeper] 302 | 303 | - Py3.2 issue. [bee_keeper] 304 | 305 | - Typo with import. [bee_keeper] 306 | 307 | - Module object has no attribute issue with 3.2. [bee_keeper] 308 | 309 | - Fixes import issue. [bee_keeper] 310 | 311 | - Py 3.2 unicode issue. [bee_keeper] 312 | 313 | - Travis. [bee_keeper] 314 | 315 | - Travis config. [bee_keeper] 316 | 317 | - Py3.2 format. [bee_keeper] 318 | 319 | - .travis.yml. [bee_keeper] 320 | 321 | - .travis.yml. [bee_keeper] 322 | 323 | - .travis.yml. [bee_keeper] 324 | 325 | - .travs.yml. [bee_keeper] 326 | 327 | - .travis.yml. [bee_keeper] 328 | 329 | - .travis.yml. [bee_keeper] 330 | 331 | - Test settings and more test coverage. [bee_keeper] 332 | 333 | - Tests and refactoring. [bee_keeper] 334 | 335 | - New style migrations. [bee_keeper] 336 | 337 | - 1.7 style migrations. [bee_keeper] 338 | 339 | 0.12 (2014-11-30) 340 | ----------------- 341 | 342 | - Release. [bee_keeper] 343 | 344 | 0.11 (2014-11-30) 345 | ----------------- 346 | 347 | - Template paths. [bee_keeper] 348 | 349 | - Setup.py. [bee_keeper] 350 | 351 | - Packaging. [bee_keeper] 352 | 353 | - Versions. [bee_keeper] 354 | 355 | 0.1 (2014-11-30) 356 | ---------------- 357 | 358 | - Packaging. [bee_keeper] 359 | 360 | - Include templates in package. [bee_keeper] 361 | 362 | - Packaging. [bee_keeper] 363 | 364 | - Template path. [bee_keeper] 365 | 366 | - Template path. [bee_keeper] 367 | 368 | - Name changes. [bee_keeper] 369 | -------------------------------------------------------------------------------- /invitations/views.py: -------------------------------------------------------------------------------- 1 | import json 2 | 3 | from django.contrib import messages 4 | from django.contrib.auth import REDIRECT_FIELD_NAME, logout 5 | from django.contrib.auth.decorators import login_required 6 | from django.core.exceptions import ValidationError 7 | from django.core.validators import validate_email 8 | from django.http import ( 9 | Http404, 10 | HttpResponse, 11 | HttpResponseNotAllowed, 12 | HttpResponseRedirect, 13 | ) 14 | from django.urls import reverse 15 | from django.urls.exceptions import NoReverseMatch 16 | from django.utils.decorators import method_decorator 17 | from django.utils.translation import gettext_lazy as _ 18 | from django.views.generic import FormView, View 19 | from django.views.generic.detail import SingleObjectMixin 20 | 21 | from .adapters import get_invitations_adapter 22 | from .app_settings import app_settings 23 | from .exceptions import AlreadyAccepted, AlreadyInvited, UserRegisteredEmail 24 | from .forms import CleanEmailMixin 25 | from .signals import invite_accepted 26 | from .utils import get_invitation_model, get_invite_form 27 | 28 | Invitation = get_invitation_model() 29 | InviteForm = get_invite_form() 30 | 31 | 32 | class SendInvite(FormView): 33 | template_name = "invitations/forms/_invite.html" 34 | form_class = InviteForm 35 | 36 | @method_decorator(login_required) 37 | def dispatch(self, request, *args, **kwargs): 38 | return super().dispatch(request, *args, **kwargs) 39 | 40 | def form_valid(self, form): 41 | email = form.cleaned_data["email"] 42 | 43 | try: 44 | invite = form.save(email) 45 | invite.inviter = self.request.user 46 | invite.save() 47 | invite.send_invitation(self.request) 48 | except Exception: 49 | return self.form_invalid(form) 50 | return self.render_to_response( 51 | self.get_context_data( 52 | success_message=_("%(email)s has been invited") % {"email": email}, 53 | ), 54 | ) 55 | 56 | def form_invalid(self, form): 57 | return self.render_to_response(self.get_context_data(form=form)) 58 | 59 | 60 | class SendJSONInvite(View): 61 | http_method_names = ["post"] 62 | 63 | @method_decorator(login_required) 64 | def dispatch(self, request, *args, **kwargs): 65 | if app_settings.ALLOW_JSON_INVITES: 66 | return super().dispatch(request, *args, **kwargs) 67 | else: 68 | raise Http404 69 | 70 | def post(self, request, *args, **kwargs): 71 | status_code = 400 72 | invitees = json.loads(request.body.decode()) 73 | response = {"valid": [], "invalid": []} 74 | if isinstance(invitees, list): 75 | for invitee in invitees: 76 | try: 77 | validate_email(invitee) 78 | CleanEmailMixin().validate_invitation(invitee) 79 | invite = Invitation.create(invitee) 80 | except (ValueError, KeyError): 81 | pass 82 | except ValidationError: 83 | response["invalid"].append({invitee: "invalid email"}) 84 | except AlreadyAccepted: 85 | response["invalid"].append({invitee: "already accepted"}) 86 | except AlreadyInvited: 87 | response["invalid"].append({invitee: "pending invite"}) 88 | except UserRegisteredEmail: 89 | response["invalid"].append({invitee: "user registered email"}) 90 | else: 91 | invite.inviter = self.request.user 92 | invite.save() 93 | invite.send_invitation(request) 94 | response["valid"].append({invitee: "invited"}) 95 | 96 | if response["valid"]: 97 | status_code = 201 98 | 99 | return HttpResponse( 100 | json.dumps(response), 101 | status=status_code, 102 | content_type="application/json", 103 | ) 104 | 105 | 106 | class AcceptInvite(SingleObjectMixin, View): 107 | form_class = InviteForm 108 | 109 | def get_signup_redirect(self): 110 | try: 111 | signup_redirect = reverse(app_settings.SIGNUP_REDIRECT) 112 | except NoReverseMatch: 113 | signup_redirect = app_settings.SIGNUP_REDIRECT 114 | if next_ := self.request.GET.get(REDIRECT_FIELD_NAME): 115 | signup_redirect += f"?{REDIRECT_FIELD_NAME}={next_}" 116 | return signup_redirect 117 | 118 | def get_login_redirect(self): 119 | try: 120 | login_redirect = reverse(app_settings.LOGIN_REDIRECT) 121 | except NoReverseMatch: 122 | login_redirect = app_settings.LOGIN_REDIRECT 123 | if next_ := self.request.GET.get(REDIRECT_FIELD_NAME): 124 | login_redirect += f"?{REDIRECT_FIELD_NAME}={next_}" 125 | return login_redirect 126 | 127 | def get(self, *args, **kwargs): 128 | if app_settings.CONFIRM_INVITE_ON_GET: 129 | return self.post(*args, **kwargs) 130 | else: 131 | return HttpResponseNotAllowed(["GET"], _("405 Method Not Allowed")) 132 | 133 | def post(self, *args, **kwargs): 134 | self.object = invitation = self.get_object() 135 | 136 | # Compatibility with older versions: return an HTTP 410 GONE if there 137 | # is an error. # Error conditions are: no key, expired key or 138 | # previously accepted key. 139 | if app_settings.GONE_ON_ACCEPT_ERROR and ( 140 | not invitation 141 | or (invitation and (invitation.accepted or invitation.key_expired())) 142 | ): 143 | return HttpResponse(status=410) 144 | 145 | # No invitation was found. 146 | if not invitation: 147 | # Newer behavior: show an error message and redirect. 148 | get_invitations_adapter().add_message( 149 | self.request, 150 | messages.ERROR, 151 | "invitations/messages/invite_invalid.txt", 152 | ) 153 | return HttpResponseRedirect(self.get_login_redirect()) 154 | 155 | # The invitation was previously accepted, redirect to the login 156 | # view. 157 | if invitation.accepted: 158 | logout(self.request) # prepare for redirection to login page 159 | get_invitations_adapter().add_message( 160 | self.request, 161 | messages.ERROR, 162 | "invitations/messages/invite_already_accepted.txt", 163 | {"email": invitation.email}, 164 | ) 165 | # Redirect to login since there's hopefully an account already. 166 | return HttpResponseRedirect(self.get_login_redirect()) 167 | 168 | # The key was expired. 169 | if invitation.key_expired(): 170 | logout(self.request) # prepare for redirection to signup page 171 | get_invitations_adapter().add_message( 172 | self.request, 173 | messages.ERROR, 174 | "invitations/messages/invite_expired.txt", 175 | {"email": invitation.email}, 176 | ) 177 | # Redirect to sign-up since they might be able to register anyway. 178 | return HttpResponseRedirect(self.get_signup_redirect()) 179 | 180 | # The invitation is valid. 181 | 182 | # Log out (if logged in) and clear session. Do this in order to prevent 183 | # user confusion and to ensure that the sign up page is displayed 184 | # correctly 185 | logout(self.request) 186 | 187 | # Mark it as accepted now if ACCEPT_INVITE_AFTER_SIGNUP is False. 188 | if not app_settings.ACCEPT_INVITE_AFTER_SIGNUP: 189 | accept_invitation( 190 | invitation=invitation, 191 | request=self.request, 192 | signal_sender=self.__class__, 193 | ) 194 | 195 | get_invitations_adapter().stash_verified_email(self.request, invitation.email) 196 | 197 | return HttpResponseRedirect(self.get_signup_redirect()) 198 | 199 | def get_object(self, queryset=None): 200 | if queryset is None: 201 | queryset = self.get_queryset() 202 | try: 203 | return queryset.get(key=self.kwargs["key"].lower()) 204 | except Invitation.DoesNotExist: 205 | return None 206 | 207 | def get_queryset(self): 208 | return Invitation.objects.all() 209 | 210 | 211 | def accept_invitation(invitation, request, signal_sender): 212 | invitation.accepted = True 213 | invitation.save() 214 | 215 | invite_accepted.send( 216 | sender=signal_sender, 217 | email=invitation.email, 218 | request=request, 219 | invitation=invitation, 220 | ) 221 | 222 | get_invitations_adapter().add_message( 223 | request, 224 | messages.SUCCESS, 225 | "invitations/messages/invite_accepted.txt", 226 | {"email": invitation.email}, 227 | ) 228 | 229 | 230 | def accept_invite_after_signup(sender, request, user, **kwargs): 231 | invitation = Invitation.objects.filter(email__iexact=user.email).first() 232 | if invitation: 233 | accept_invitation( 234 | invitation=invitation, 235 | request=request, 236 | signal_sender=Invitation, 237 | ) 238 | 239 | 240 | if app_settings.ACCEPT_INVITE_AFTER_SIGNUP: 241 | signed_up_signal = get_invitations_adapter().get_user_signed_up_signal() 242 | signed_up_signal.connect(accept_invite_after_signup) 243 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | Changelog 2 | ========= 3 | 4 | 2.1.0 (2022-11-22) 5 | ---------------- 6 | 7 | - French translation https://github.com/jazzband/django-invitations/pull/142 8 | 9 | - Translation Portuguese (BR) https://github.com/jazzband/django-invitations/pull/193 10 | 11 | - Update pyproject.toml to include standard urls https://github.com/jazzband/django-invitations/pull/200 12 | 13 | - Add version 2.0.0 changelog to docs https://github.com/jazzband/django-invitations/pull/201 14 | 15 | - Add default_auto_field and migration. https://github.com/jazzband/django-invitations/pull/211 16 | 17 | - Add missing configuration values for test_settings. https://github.com/jazzband/django-invitations/pull/235 18 | 19 | - Remove mention of sites framework from docs https://github.com/jazzband/django-invitations/pull/220 20 | 21 | Supported versions: 22 | - Django: 3.2, 4.0, 4.1, 4.2, 5.0rc1 23 | - Python: 3.8, 3.9, 3.10, 3.11, 3.12 24 | 25 | **Full Changelog**: https://github.com/jazzband/django-invitations/compare/2.0.0...2.1.0 26 | 27 | 2.0.0 (2022-09-28) 28 | ---------------- 29 | 30 | - Joined Jazzband 31 | 32 | - Removed support for Django versions below 3.2 33 | 34 | - Added support for Django 4.0+. Thanks @saschahofmann [#169](https://github.com/jazzband/django-invitations/pull/169) 35 | 36 | - Removed support for Python versions below 3.7 37 | 38 | - Added documentation 39 | 40 | - Set inviter on invitation in SendJSONInvite view. Thanks @rosexi [#151](https://github.com/jazzband/django-invitations/pull/151) 41 | 42 | 1.9 (2017-02-11) 43 | ---------------- 44 | 45 | - Added get_signup_redirect to allow custom implementations by subclasses 46 | 47 | - Fixed invitation form displaying "None" when first displayed 48 | 49 | - Fixed deprecation warnings 50 | 51 | - Added get_signup_redirect to allow custom implementations by subclasses 52 | 53 | - Fixed flake8 errors 54 | 55 | - Import reverse from django.urls if available, otherwise fall back to old import 56 | 57 | - Set ForeignKey field to explicitly cascade on deletion 58 | 59 | - flake8 styling formatting 60 | 61 | - Add email max length setting 62 | 63 | 1.8 (2016-10-19) 64 | ---------------- 65 | 66 | *TO BE ADDED* 67 | 68 | 69 | 1.7 (2016-02-10) 70 | ------------------------ 71 | 72 | - 1.7. [bee-keeper] 73 | 74 | - Merge pull request #34 from percipient/dont-404. [bee-keeper] 75 | 76 | Display a message on expired/erroneous/accepted keys. 77 | 78 | - Fix flake8 issues. [Patrick Cloke] 79 | 80 | - Fix a formatting mistake in the README. [Patrick Cloke] 81 | 82 | - Display a message on expired/erroneous/accepted keys. Related to #25. 83 | [Patrick Cloke] 84 | 85 | - Merge pull request #33 from percipient/readme-settings. [bee-keeper] 86 | 87 | Fix-up the settings in the README 88 | 89 | - Update the INVITATIONS_ADAPTER setting. [Patrick Cloke] 90 | 91 | - Update the readme with all the settings. [Patrick Cloke] 92 | 93 | - Removed uneeded check on send invite. [bee_keeper] 94 | 95 | - Test new url spec. [bee_keeper] 96 | 97 | - Merge pull request #32 from mjnaderi/patch-1. [bee-keeper] 98 | 99 | Remove RemovedInDjango110Warning warnings in Django 1.9 100 | 101 | - Remove RemovedInDjango110Warning warnings in Django 1.9. [Mohammad 102 | Javad Naderi] 103 | 104 | With Django 1.9, each time I run `python manage.py runserver`, it shows 2 warnings: 105 | 106 | ``` 107 | /someplace/.venv/lib/python2.7/site-packages/invitations/urls.py:15: RemovedInDjango110Warning: django.conf.urls.patterns() is deprecated and will be removed in Django 1.10. Update your urlpatterns to be a list of django.conf.urls.url() instances instead. 108 | name='accept-invite'), 109 | 110 | /someplace/.venv/lib/python2.7/site-packages/invitations/urls.py:15: RemovedInDjango110Warning: django.conf.urls.patterns() is deprecated and will be removed in Django 1.10. Update your urlpatterns to be a list of django.conf.urls.url() instances instead. 111 | name='accept-invite'), 112 | ``` 113 | 114 | This pull request fixes it. 115 | 116 | 1.6 (2016-01-10) 117 | ---------------- 118 | 119 | - V1.6. [bee_keeper] 120 | 121 | - Dont override inviter from create step. [bee_keeper] 122 | 123 | - Merge pull request #30 from percipient/allauth-with-custom-adapter. 124 | [bee-keeper] 125 | 126 | Allow using custom allauth backends. 127 | 128 | - Make flake8 happy. [Patrick Cloke] 129 | 130 | - Don't return None from get_invitations_adapter. [Patrick Cloke] 131 | 132 | - Merge pull request #31 from percipient/set-inviter. [bee-keeper] 133 | 134 | Set the inviter in the SendInvite view. 135 | 136 | - Set the inviter in the SendInvite view. [Patrick Cloke] 137 | 138 | - Update README.md. [bee-keeper] 139 | 140 | 1.5 (2015-12-07) 141 | ---------------- 142 | 143 | - Update README.md. [bee-keeper] 144 | 145 | - Merge pull request #24 from bee-keeper/devel. [bee-keeper] 146 | 147 | Refactor as generic invite app 148 | 149 | - Removed the dependency on django-allauth, this package is now a 150 | generic invite app. [bee_keeper] 151 | 152 | 1.4 (2015-11-27) 153 | ---------------- 154 | 155 | - 1.4. [bee_keeper] 156 | 157 | - Merge pull request #23 from bee-keeper/devel. [bee-keeper] 158 | 159 | Coverage and exposing inviter in admin 160 | 161 | - Coverage and exposing inviter in admin. [bee_keeper] 162 | 163 | 1.3 (2015-11-26) 164 | ---------------- 165 | 166 | - Merge pull request #22 from bee-keeper/devel. [bee-keeper] 167 | 168 | Added inviter to invitation 169 | 170 | - Added inviter to invitation. [bee_keeper] 171 | 172 | - Merge pull request #21 from bee-keeper/devel. [bee-keeper] 173 | 174 | Support for django1.9 175 | 176 | - Testing for django1.9 and python 3.5. [bee_keeper] 177 | 178 | - Merge pull request #20 from bee-keeper/devel. [bee-keeper] 179 | 180 | Added json endpoint for invites 181 | 182 | - Added json endpoint for invites. [bee_keeper] 183 | 184 | - Merge pull request #19 from bee-keeper/devel. [bee-keeper] 185 | 186 | Made accept trailing slash optional 187 | 188 | - Made trailing slash optional and added flake8 to CI. [bee_keeper] 189 | 190 | Bumped to version 1.3 191 | 192 | - Update models.py. [bee-keeper] 193 | 194 | - Roadmap. [bee_keeper] 195 | 196 | 1.2 (2015-08-29) 197 | ---------------- 198 | 199 | - Test coverage done, ready for 1.2 release. [bee_keeper] 200 | 201 | - Dropping support for python 3.2. [bee_keeper] 202 | 203 | - Dropping support for python 3.2. [bee_keeper] 204 | 205 | - Signal test coverage, tweaking tox. [bee_keeper] 206 | 207 | - Coverage. [bee-keeper] 208 | 209 | - Tox+travis. [bee-keeper] 210 | 211 | - Tox. [bee-keeper] 212 | 213 | - Tox+travis. [bee-keeper] 214 | 215 | - Testing tox+travis. [bee-keeper] 216 | 217 | - Testing tox+travis. [bee-keeper] 218 | 219 | - Tox file. [bee_keeper] 220 | 221 | - Py3 fix. [bee_keeper] 222 | 223 | - Test for signup redirect. [bee_keeper] 224 | 225 | - Update README.md. [bee-keeper] 226 | 227 | - Py 3.2. [bee_keeper] 228 | 229 | - Py 3.2. [bee-keeper] 230 | 231 | - Print. [bee-keeper] 232 | 233 | - Tests and bug fixes. [bee-keeper] 234 | 235 | 1.1 (2015-08-05) 236 | ---------------- 237 | 238 | - V 1.1. [bee_keeper] 239 | 240 | - Readme. [bee_keeper] 241 | 242 | - Modified PR (15) + editorconfig. [bee_keeper] 243 | 244 | - Merge branch 'nwaxiomatic-master' [bee_keeper] 245 | 246 | - Admin invitations. [Nic] 247 | 248 | sends invitations from admin on save 249 | 250 | 1.0 (2015-07-26) 251 | ---------------- 252 | 253 | - Release 1.0. [bee_keeper] 254 | 255 | - Requirements. [bee_keeper] 256 | 257 | - Changing travis supported versions. [bee_keeper] 258 | 259 | - Travis. [bee_keeper] 260 | 261 | - Travis. [bee_keeper] 262 | 263 | - Remove 2.6 from testing. [bee_keeper] 264 | 265 | - Requirements and changelog. [bee_keeper] 266 | 267 | - Test settings. [bee_keeper] 268 | 269 | - Requirements.txt. [bee_keeper] 270 | 271 | - Travis. [bee_keeper] 272 | 273 | - Removing uneeded imports. [bee_keeper] 274 | 275 | - Removed ALLOWED_GROUPS setting. [bee_keeper] 276 | 277 | - Merge pull request #12 from tbarbugli/patch-1. [bee-keeper] 278 | 279 | fix invite form 280 | 281 | - Fix invite form. [Tommaso Barbugli] 282 | 283 | - Update views.py. [bee-keeper] 284 | 285 | - Teavis. [bee_keeper] 286 | 287 | - Travis. [bee_keeper] 288 | 289 | - Travis. [bee_keeper] 290 | 291 | - Travis. [bee_keeper] 292 | 293 | - Travis. [bee_keeper] 294 | 295 | - Travis. [bee_keeper] 296 | 297 | - App settings. [bee_keeper] 298 | 299 | - Merge pull request #6 from simonv3/master. [bee-keeper] 300 | 301 | # Redo pull request of adding inviter to signal. 302 | 303 | - Add reference to inviter in signal. [Simon] 304 | 305 | - .travis.yml. [bee_keeper] 306 | 307 | - .travis.yml. [bee_keeper] 308 | 309 | - Readme. [bee_keeper] 310 | 311 | - Fixing py3.2 import issues. [bee_keeper] 312 | 313 | - Invitations/app_settings.py. [bee_keeper] 314 | 315 | - Py3.2 issue. [bee_keeper] 316 | 317 | - Typo with import. [bee_keeper] 318 | 319 | - Module object has no attribute issue with 3.2. [bee_keeper] 320 | 321 | - Fixes import issue. [bee_keeper] 322 | 323 | - Py 3.2 unicode issue. [bee_keeper] 324 | 325 | - Travis. [bee_keeper] 326 | 327 | - Travis config. [bee_keeper] 328 | 329 | - Py3.2 format. [bee_keeper] 330 | 331 | - .travis.yml. [bee_keeper] 332 | 333 | - .travis.yml. [bee_keeper] 334 | 335 | - .travis.yml. [bee_keeper] 336 | 337 | - .travs.yml. [bee_keeper] 338 | 339 | - .travis.yml. [bee_keeper] 340 | 341 | - .travis.yml. [bee_keeper] 342 | 343 | - Test settings and more test coverage. [bee_keeper] 344 | 345 | - Tests and refactoring. [bee_keeper] 346 | 347 | - New style migrations. [bee_keeper] 348 | 349 | - 1.7 style migrations. [bee_keeper] 350 | 351 | 0.12 (2014-11-30) 352 | ----------------- 353 | 354 | - Release. [bee_keeper] 355 | 356 | 0.11 (2014-11-30) 357 | ----------------- 358 | 359 | - Template paths. [bee_keeper] 360 | 361 | - Setup.py. [bee_keeper] 362 | 363 | - Packaging. [bee_keeper] 364 | 365 | - Versions. [bee_keeper] 366 | 367 | 0.1 (2014-11-30) 368 | ---------------- 369 | 370 | - Packaging. [bee_keeper] 371 | 372 | - Include templates in package. [bee_keeper] 373 | 374 | - Packaging. [bee_keeper] 375 | 376 | - Template path. [bee_keeper] 377 | 378 | - Template path. [bee_keeper] 379 | 380 | - Name changes. [bee_keeper] 381 | -------------------------------------------------------------------------------- /tests/basic/tests.py: -------------------------------------------------------------------------------- 1 | import datetime 2 | import json 3 | import re 4 | from unittest.mock import patch 5 | 6 | from django.test import Client 7 | from django.test.client import RequestFactory 8 | from django.test.utils import override_settings 9 | from django.utils import timezone 10 | 11 | try: 12 | from django.urls import reverse 13 | except ImportError: 14 | from django.urls import reverse 15 | 16 | import pytest 17 | from django.contrib.auth.models import AnonymousUser 18 | from django.core import mail 19 | from freezegun import freeze_time 20 | 21 | from invitations.adapters import BaseInvitationsAdapter, get_invitations_adapter 22 | from invitations.app_settings import app_settings 23 | from invitations.forms import InviteForm 24 | from invitations.utils import get_invitation_model 25 | from invitations.views import AcceptInvite, SendJSONInvite 26 | 27 | Invitation = get_invitation_model() 28 | 29 | 30 | class TestInvitationModel: 31 | @freeze_time("2015-07-30 12:00:06") 32 | def test_create_invitation(self, invitation_a): 33 | assert invitation_a.email == "email@example.com" 34 | assert invitation_a.key 35 | assert invitation_a.accepted is False 36 | assert invitation_a.created == timezone.now() 37 | 38 | def test_invitation_key_expiry(self, invitation_a): 39 | invitation_a.sent = timezone.now() - datetime.timedelta( 40 | days=app_settings.INVITATION_EXPIRY, 41 | minutes=1, 42 | ) 43 | assert invitation_a.key_expired() is True 44 | 45 | invitation_a.sent = timezone.now() - datetime.timedelta( 46 | days=app_settings.INVITATION_EXPIRY, 47 | minutes=-1, 48 | ) 49 | assert invitation_a.key_expired() is False 50 | 51 | def test_invitation_related_name(self, sent_invitation_by_user_a): 52 | user = sent_invitation_by_user_a.inviter 53 | assert user.invitations_invitations.all() 54 | assert user.invitations_invitations.count() == 1 55 | 56 | def test_invitation_related_query_name(self, sent_invitation_by_user_a): 57 | assert ( 58 | Invitation.objects.filter( 59 | inviter__invitations_invitation__id=sent_invitation_by_user_a.pk 60 | ).count() 61 | == 1 62 | ) 63 | 64 | 65 | class TestInvitationsAdapter: 66 | def test_fetch_adapter(self): 67 | adapter = get_invitations_adapter() 68 | assert isinstance(adapter, BaseInvitationsAdapter) 69 | 70 | def test_email_subject_prefix_settings_with_site(self): 71 | adapter = get_invitations_adapter() 72 | result = adapter.format_email_subject("Bar", context={"site_name": "Foo.com"}) 73 | assert result == "[Foo.com] Bar" 74 | 75 | @override_settings(INVITATIONS_EMAIL_SUBJECT_PREFIX="") 76 | def test_email_subject_prefix_settings_with_custom_override(self): 77 | adapter = get_invitations_adapter() 78 | result = adapter.format_email_subject("Bar", context={"site_name": "Foo.com"}) 79 | assert result == "Bar" 80 | 81 | 82 | class TestInvitationsSendView: 83 | client = Client() 84 | 85 | @pytest.mark.django_db 86 | def test_auth(self): 87 | response = self.client.post( 88 | reverse("invitations:send-invite"), 89 | {"email": "valid@example.com"}, 90 | follow=True, 91 | ) 92 | 93 | assert response.status_code == 404 94 | 95 | @pytest.mark.parametrize( 96 | "email, error", 97 | [ 98 | ("invalid@example", "Enter a valid email address"), 99 | ("invited@example.com", "This e-mail address has already been"), 100 | ("flobble@example.com", "An active user is"), 101 | ], 102 | ) 103 | def test_invalid_form_submissions(self, user_a, user_b, invitation_b, email, error): 104 | self.client.login(username="flibble", password="password") 105 | resp = self.client.post(reverse("invitations:send-invite"), {"email": email}) 106 | 107 | form = resp.context_data["form"] 108 | assert error in form.errors["email"][0] 109 | 110 | @freeze_time("2015-07-30 12:00:06") 111 | def test_valid_form_submission(self, user_a): 112 | self.client.login(username="flibble", password="password") 113 | resp = self.client.post( 114 | reverse("invitations:send-invite"), 115 | {"email": "email@example.com"}, 116 | ) 117 | invitation = Invitation.objects.get(email="email@example.com") 118 | 119 | assert resp.status_code == 200 120 | assert "success_message" in resp.context_data.keys() 121 | 122 | assert invitation.sent == timezone.now() 123 | assert len(mail.outbox) == 1 124 | assert mail.outbox[0].to[0] == "email@example.com" 125 | assert "Invitation to join example.com" in mail.outbox[0].subject 126 | url = re.search(r"(?P/invitations/[^\s]+)", mail.outbox[0].body).group( 127 | "url", 128 | ) 129 | assert url == reverse( 130 | app_settings.CONFIRMATION_URL_NAME, 131 | kwargs={"key": invitation.key}, 132 | ) 133 | 134 | @override_settings(INVITATION_MODEL="ExampleSwappableInvitation") 135 | @freeze_time("2015-07-30 12:00:06") 136 | def test_valid_form_submission_with_swapped_model(self, user_a): 137 | self.client.login(username="flibble", password="password") 138 | resp = self.client.post( 139 | reverse("invitations:send-invite"), 140 | {"email": "email@example.com"}, 141 | ) 142 | invitation = Invitation.objects.get(email="email@example.com") 143 | 144 | assert resp.status_code == 200 145 | assert "success_message" in resp.context_data.keys() 146 | 147 | assert invitation.sent == timezone.now() 148 | assert len(mail.outbox) == 1 149 | assert mail.outbox[0].to[0] == "email@example.com" 150 | assert "Invitation to join example.com" in mail.outbox[0].subject 151 | url = re.search(r"(?P/invitations/[^\s]+)", mail.outbox[0].body).group( 152 | "url", 153 | ) 154 | assert url == reverse( 155 | app_settings.CONFIRMATION_URL_NAME, 156 | kwargs={"key": invitation.key}, 157 | ) 158 | 159 | 160 | @pytest.mark.django_db 161 | class TestInvitationsAcceptView: 162 | client = Client() 163 | 164 | def test_accept_invite_get_is_405(self, settings, invitation_b): 165 | settings.INVITATIONS_CONFIRM_INVITE_ON_GET = False 166 | resp = self.client.get( 167 | reverse( 168 | app_settings.CONFIRMATION_URL_NAME, 169 | kwargs={"key": invitation_b.key}, 170 | ), 171 | follow=True, 172 | ) 173 | assert resp.status_code == 405 174 | 175 | @pytest.mark.parametrize( 176 | "method", 177 | [ 178 | ("get"), 179 | ("post"), 180 | ], 181 | ) 182 | def test_accept_invite_invalid_key(self, method): 183 | client_with_method = getattr(self.client, method) 184 | resp = client_with_method( 185 | reverse(app_settings.CONFIRMATION_URL_NAME, kwargs={"key": "invalidKey"}), 186 | follow=True, 187 | ) 188 | assert resp.status_code == 410 189 | 190 | @pytest.mark.parametrize( 191 | "method", 192 | [ 193 | ("get"), 194 | ("post"), 195 | ], 196 | ) 197 | def test_accept_invite_invalid_key_error_disabled(self, settings, method): 198 | settings.INVITATIONS_GONE_ON_ACCEPT_ERROR = False 199 | settings.INVITATIONS_LOGIN_REDIRECT = "/login-url/" 200 | client_with_method = getattr(self.client, method) 201 | resp = client_with_method( 202 | reverse(app_settings.CONFIRMATION_URL_NAME, kwargs={"key": "invalidKey"}), 203 | follow=True, 204 | ) 205 | assert resp.request["PATH_INFO"] == "/login-url/" 206 | 207 | @pytest.mark.parametrize( 208 | "method", 209 | [ 210 | ("get"), 211 | ("post"), 212 | ], 213 | ) 214 | def test_accept_invite_accepted_key(self, accepted_invitation, method): 215 | client_with_method = getattr(self.client, method) 216 | resp = client_with_method( 217 | reverse( 218 | app_settings.CONFIRMATION_URL_NAME, 219 | kwargs={"key": accepted_invitation.key}, 220 | ), 221 | follow=True, 222 | ) 223 | assert resp.status_code == 410 224 | 225 | @pytest.mark.parametrize( 226 | "method", 227 | [ 228 | ("get"), 229 | ("post"), 230 | ], 231 | ) 232 | def test_accept_invite_accepted_key_error_disabled( 233 | self, 234 | settings, 235 | accepted_invitation, 236 | method, 237 | ): 238 | settings.INVITATIONS_GONE_ON_ACCEPT_ERROR = False 239 | settings.INVITATIONS_LOGIN_REDIRECT = "/login-url/" 240 | client_with_method = getattr(self.client, method) 241 | resp = client_with_method( 242 | reverse( 243 | app_settings.CONFIRMATION_URL_NAME, 244 | kwargs={"key": accepted_invitation.key}, 245 | ), 246 | follow=True, 247 | ) 248 | assert resp.request["PATH_INFO"] == "/login-url/" 249 | 250 | @pytest.mark.parametrize( 251 | "method", 252 | [ 253 | ("get"), 254 | ("post"), 255 | ], 256 | ) 257 | def test_accept_invite_expired_key( 258 | self, 259 | settings, 260 | sent_invitation_by_user_a, 261 | method, 262 | ): 263 | settings.INVITATIONS_INVITATION_EXPIRY = 0 264 | client_with_method = getattr(self.client, method) 265 | resp = client_with_method( 266 | reverse( 267 | app_settings.CONFIRMATION_URL_NAME, 268 | kwargs={"key": sent_invitation_by_user_a.key}, 269 | ), 270 | follow=True, 271 | ) 272 | assert resp.status_code == 410 273 | 274 | @pytest.mark.parametrize( 275 | "method", 276 | [ 277 | ("get"), 278 | ("post"), 279 | ], 280 | ) 281 | def test_accept_invite_expired_key_error_disabled( 282 | self, 283 | sent_invitation_by_user_a, 284 | method, 285 | settings, 286 | ): 287 | settings.INVITATIONS_INVITATION_EXPIRY = 0 288 | settings.INVITATIONS_GONE_ON_ACCEPT_ERROR = False 289 | settings.INVITATIONS_SIGNUP_REDIRECT = "/signup-url/" 290 | client_with_method = getattr(self.client, method) 291 | resp = client_with_method( 292 | reverse( 293 | app_settings.CONFIRMATION_URL_NAME, 294 | kwargs={"key": sent_invitation_by_user_a.key}, 295 | ), 296 | follow=True, 297 | ) 298 | assert resp.request["PATH_INFO"] == "/signup-url/" 299 | 300 | @pytest.mark.parametrize( 301 | "method", 302 | [ 303 | ("get"), 304 | ("post"), 305 | ], 306 | ) 307 | def test_accept_invite(self, settings, sent_invitation_by_user_a, user_a, method): 308 | settings.INVITATIONS_SIGNUP_REDIRECT = "/non-existent-url/" 309 | client_with_method = getattr(self.client, method) 310 | resp = client_with_method( 311 | reverse( 312 | app_settings.CONFIRMATION_URL_NAME, 313 | kwargs={"key": sent_invitation_by_user_a.key}, 314 | ), 315 | follow=True, 316 | ) 317 | invite = Invitation.objects.get(email="email@example.com") 318 | assert invite.accepted is True 319 | assert invite.inviter == user_a 320 | assert resp.request["PATH_INFO"] == "/non-existent-url/" 321 | 322 | @pytest.mark.parametrize( 323 | "method", 324 | [ 325 | ("get"), 326 | ("post"), 327 | ], 328 | ) 329 | def test_accept_invite_when_logged_in( 330 | self, settings, sent_invitation_by_user_a, method 331 | ): 332 | assert self.client.login(username="flibble", password="password") 333 | admin_resp = self.client.get(reverse("admin:index"), follow=True) 334 | assert admin_resp.wsgi_request.user.is_authenticated 335 | 336 | settings.INVITATIONS_SIGNUP_REDIRECT = "/non-existent-url/" 337 | client_with_method = getattr(self.client, method) 338 | resp = client_with_method( 339 | reverse( 340 | app_settings.CONFIRMATION_URL_NAME, 341 | kwargs={"key": sent_invitation_by_user_a.key}, 342 | ), 343 | follow=True, 344 | ) 345 | assert not resp.wsgi_request.user.is_authenticated 346 | 347 | def test_signup_redirect(self, settings, sent_invitation_by_user_a): 348 | settings.INVITATIONS_SIGNUP_REDIRECT = "/non-existent-url/" 349 | resp = self.client.post( 350 | reverse( 351 | app_settings.CONFIRMATION_URL_NAME, 352 | kwargs={"key": sent_invitation_by_user_a.key}, 353 | ), 354 | follow=True, 355 | ) 356 | invite = Invitation.objects.get(email="email@example.com") 357 | assert invite.accepted is True 358 | assert resp.request["PATH_INFO"] == "/non-existent-url/" 359 | 360 | 361 | class TestInvitationSignals: 362 | client = Client() 363 | 364 | @patch("invitations.signals.invite_url_sent.send") 365 | def test_invite_url_sent_triggered_correctly( 366 | self, 367 | mock_signal, 368 | sent_invitation_by_user_a, 369 | user_a, 370 | ): 371 | invite_url = reverse( 372 | app_settings.CONFIRMATION_URL_NAME, 373 | args=[sent_invitation_by_user_a.key], 374 | ) 375 | request = RequestFactory().get("/") 376 | invite_url = request.build_absolute_uri(invite_url) 377 | 378 | sent_invitation_by_user_a.send_invitation(request) 379 | 380 | assert mock_signal.called 381 | assert mock_signal.call_count == 1 382 | 383 | mock_signal.assert_called_with( 384 | instance=sent_invitation_by_user_a, 385 | invite_url_sent=invite_url, 386 | inviter=user_a, 387 | sender=Invitation, 388 | ) 389 | 390 | @override_settings(INVITATIONS_SIGNUP_REDIRECT="/non-existent-url/") 391 | @patch("invitations.signals.invite_accepted.send") 392 | def test_invite_invite_accepted_triggered_correctly( 393 | self, 394 | mock_signal, 395 | sent_invitation_by_user_a, 396 | ): 397 | request = RequestFactory().get("/") 398 | sent_invitation_by_user_a.send_invitation(request) 399 | 400 | self.client.post( 401 | reverse( 402 | app_settings.CONFIRMATION_URL_NAME, 403 | kwargs={"key": sent_invitation_by_user_a.key}, 404 | ), 405 | follow=True, 406 | ) 407 | assert mock_signal.called 408 | assert mock_signal.call_count == 1 409 | 410 | assert mock_signal.call_args[1]["email"] == "email@example.com" 411 | assert mock_signal.call_args[1]["sender"] == AcceptInvite 412 | 413 | 414 | class TestInvitationsForm: 415 | @pytest.mark.parametrize( 416 | "email, form_validity, errors", 417 | [ 418 | ("bogger@example.com", True, None), 419 | ("accepted@example.com", False, "has already accepted an invite"), 420 | ("pending@example.com", False, "has already been invited"), 421 | ("flobble@example.com", False, "active user is using this"), 422 | ], 423 | ) 424 | def test_form( 425 | self, 426 | email, 427 | form_validity, 428 | errors, 429 | accepted_invitation, 430 | pending_invitation, 431 | user_b, 432 | ): 433 | form = InviteForm(data={"email": email}) 434 | if errors: 435 | assert errors in str(form.errors) 436 | else: 437 | assert form.errors == {} 438 | assert form.is_valid() is form_validity 439 | 440 | 441 | @pytest.mark.django_db 442 | class TestInvitationsManager: 443 | def test_managers( 444 | self, 445 | sent_invitation_by_user_a, 446 | accepted_invitation, 447 | expired_invitation, 448 | invitation_b, 449 | ): 450 | valid = Invitation.objects.all_valid().values_list("email", flat=True) 451 | expired = Invitation.objects.all_expired().values_list("email", flat=True) 452 | expected_valid = ["email@example.com", "invited@example.com"] 453 | expected_expired = ["accepted@example.com", "expired@example.com"] 454 | 455 | assert sorted(valid) == sorted(expected_valid) 456 | assert sorted(expired) == sorted(expected_expired) 457 | 458 | def test_delete_all(self): 459 | valid = Invitation.objects.all_valid().values_list("email", flat=True) 460 | Invitation.objects.delete_expired_confirmations() 461 | remaining_invites = Invitation.objects.all().values_list("email", flat=True) 462 | assert sorted(valid) == sorted(remaining_invites) 463 | 464 | 465 | class TestInvitationsJSON: 466 | client = Client() 467 | 468 | @pytest.mark.parametrize( 469 | "data, expected, status_code", 470 | [ 471 | ( 472 | ["accepted@example.com"], 473 | { 474 | "valid": [], 475 | "invalid": [{"accepted@example.com": "already accepted"}], 476 | }, 477 | 400, 478 | ), 479 | ( 480 | ["xample.com"], 481 | {"valid": [], "invalid": [{"xample.com": "invalid email"}]}, 482 | 400, 483 | ), 484 | ("xample.com", {"valid": [], "invalid": []}, 400), 485 | ( 486 | ["pending@example.com"], 487 | {"valid": [], "invalid": [{"pending@example.com": "pending invite"}]}, 488 | 400, 489 | ), 490 | ( 491 | ["flobble@example.com"], 492 | { 493 | "valid": [], 494 | "invalid": [{"flobble@example.com": "user registered email"}], 495 | }, 496 | 400, 497 | ), 498 | ( 499 | ["example@example.com"], 500 | {"valid": [{"example@example.com": "invited"}], "invalid": []}, 501 | 201, 502 | ), 503 | ], 504 | ) 505 | def test_post( 506 | self, 507 | settings, 508 | data, 509 | expected, 510 | status_code, 511 | user_a, 512 | accepted_invitation, 513 | pending_invitation, 514 | user_b, 515 | ): 516 | settings.INVITATIONS_ALLOW_JSON_INVITES = True 517 | self.client.login(username="flibble", password="password") 518 | response = self.client.post( 519 | reverse("invitations:send-json-invite"), 520 | data=json.dumps(data), 521 | content_type="application/json", 522 | ) 523 | 524 | assert response.status_code == status_code 525 | assert json.loads(response.content.decode()) == expected 526 | 527 | def test_json_setting(self, user_a): 528 | self.client.login(username="flibble", password="password") 529 | response = self.client.post( 530 | reverse("invitations:send-json-invite"), 531 | data=json.dumps(["example@example.com"]), 532 | content_type="application/json", 533 | ) 534 | 535 | assert response.status_code == 404 536 | 537 | @override_settings(INVITATIONS_ALLOW_JSON_INVITES=True) 538 | def test_anonymous_get(self): 539 | request = RequestFactory().get( 540 | reverse("invitations:send-json-invite"), 541 | content_type="application/json", 542 | ) 543 | request.user = AnonymousUser() 544 | response = SendJSONInvite.as_view()(request) 545 | 546 | assert response.status_code == 302 547 | 548 | def test_authenticated_get(self, settings, user_a): 549 | settings.INVITATIONS_ALLOW_JSON_INVITES = True 550 | request = RequestFactory().get( 551 | reverse("invitations:send-json-invite"), 552 | content_type="application/json", 553 | ) 554 | request.user = user_a 555 | response = SendJSONInvite.as_view()(request) 556 | 557 | assert response.status_code == 405 558 | 559 | 560 | class TestInvitationsAdmin: 561 | client = Client() 562 | 563 | def test_admin_form_add(self, super_user): 564 | self.client.login(username="flibble", password="password") 565 | response = self.client.post( 566 | reverse("admin:invitations_invitation_add"), 567 | {"email": "valid@example.com", "inviter": super_user.id}, 568 | follow=True, 569 | ) 570 | invite = Invitation.objects.get(email="valid@example.com") 571 | 572 | assert response.status_code == 200 573 | assert invite.sent 574 | assert invite.inviter == super_user 575 | 576 | def test_admin_form_change(self, super_user, invitation_b): 577 | self.client.login(username="flibble", password="password") 578 | response = self.client.get( 579 | reverse("admin:invitations_invitation_change", args=(invitation_b.id,)), 580 | follow=True, 581 | ) 582 | 583 | assert response.status_code == 200 584 | fields = list(response.context_data["adminform"].form.fields.keys()) 585 | expected_fields = ["accepted", "key", "sent", "inviter", "email", "created"] 586 | assert fields == expected_fields 587 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | {one line to give the program's name and a brief idea of what it does.} 635 | Copyright (C) {year} {name of author} 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | {project} Copyright (C) {year} {fullname} 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------