mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Merge pull request #2161 from matmair/onboarding-group
Onboarding group
This commit is contained in:
commit
744befcc96
@ -4,10 +4,11 @@ Helper forms which subclass Django forms to provide additional functionality
|
|||||||
|
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
import logging
|
||||||
|
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
from django import forms
|
from django import forms
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User, Group
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
|
||||||
from crispy_forms.helper import FormHelper
|
from crispy_forms.helper import FormHelper
|
||||||
@ -21,6 +22,8 @@ from allauth.socialaccount.adapter import DefaultSocialAccountAdapter
|
|||||||
from part.models import PartCategory
|
from part.models import PartCategory
|
||||||
from common.models import InvenTreeSetting
|
from common.models import InvenTreeSetting
|
||||||
|
|
||||||
|
logger = logging.getLogger('inventree')
|
||||||
|
|
||||||
|
|
||||||
class HelperForm(forms.ModelForm):
|
class HelperForm(forms.ModelForm):
|
||||||
""" Provides simple integration of crispy_forms extension. """
|
""" Provides simple integration of crispy_forms extension. """
|
||||||
@ -262,6 +265,18 @@ class RegistratonMixin:
|
|||||||
return super().is_open_for_signup(request)
|
return super().is_open_for_signup(request)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def save_user(self, request, user, form, commit=True):
|
||||||
|
user = super().save_user(request, user, form, commit=commit)
|
||||||
|
start_group = InvenTreeSetting.get_setting('SIGNUP_GROUP')
|
||||||
|
if start_group:
|
||||||
|
try:
|
||||||
|
group = Group.objects.get(id=start_group)
|
||||||
|
user.groups.add(group)
|
||||||
|
except Group.DoesNotExist:
|
||||||
|
logger.error('The setting `SIGNUP_GROUP` contains an non existant group', start_group)
|
||||||
|
user.save()
|
||||||
|
return user
|
||||||
|
|
||||||
|
|
||||||
class CustomAccountAdapter(RegistratonMixin, DefaultAccountAdapter):
|
class CustomAccountAdapter(RegistratonMixin, DefaultAccountAdapter):
|
||||||
"""
|
"""
|
||||||
|
@ -11,7 +11,7 @@ import decimal
|
|||||||
import math
|
import math
|
||||||
|
|
||||||
from django.db import models, transaction
|
from django.db import models, transaction
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User, Group
|
||||||
from django.db.utils import IntegrityError, OperationalError
|
from django.db.utils import IntegrityError, OperationalError
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
|
||||||
@ -182,12 +182,9 @@ class BaseInvenTreeSetting(models.Model):
|
|||||||
else:
|
else:
|
||||||
choices = None
|
choices = None
|
||||||
|
|
||||||
"""
|
if callable(choices):
|
||||||
TODO:
|
|
||||||
if type(choices) is function:
|
|
||||||
# Evaluate the function (we expect it will return a list of tuples...)
|
# Evaluate the function (we expect it will return a list of tuples...)
|
||||||
return choices()
|
return choices()
|
||||||
"""
|
|
||||||
|
|
||||||
return choices
|
return choices
|
||||||
|
|
||||||
@ -479,6 +476,11 @@ class BaseInvenTreeSetting(models.Model):
|
|||||||
return value
|
return value
|
||||||
|
|
||||||
|
|
||||||
|
def settings_group_options():
|
||||||
|
"""build up group tuple for settings based on gour choices"""
|
||||||
|
return [('', _('No group')), *[(str(a.id), str(a)) for a in Group.objects.all()]]
|
||||||
|
|
||||||
|
|
||||||
class InvenTreeSetting(BaseInvenTreeSetting):
|
class InvenTreeSetting(BaseInvenTreeSetting):
|
||||||
"""
|
"""
|
||||||
An InvenTreeSetting object is a key:value pair used for storing
|
An InvenTreeSetting object is a key:value pair used for storing
|
||||||
@ -845,6 +847,12 @@ class InvenTreeSetting(BaseInvenTreeSetting):
|
|||||||
'default': True,
|
'default': True,
|
||||||
'validator': bool,
|
'validator': bool,
|
||||||
},
|
},
|
||||||
|
'SIGNUP_GROUP': {
|
||||||
|
'name': _('Group on signup'),
|
||||||
|
'description': _('Group new user are asigned on registration'),
|
||||||
|
'default': '',
|
||||||
|
'choices': settings_group_options
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
@ -14,7 +14,6 @@
|
|||||||
<table class='table table-striped table-condensed'>
|
<table class='table table-striped table-condensed'>
|
||||||
{% include "InvenTree/settings/header.html" %}
|
{% include "InvenTree/settings/header.html" %}
|
||||||
<tbody>
|
<tbody>
|
||||||
{% include "InvenTree/settings/setting.html" with key="LOGIN_ENABLE_REG" icon="fa-info-circle" %}
|
|
||||||
{% include "InvenTree/settings/setting.html" with key="LOGIN_ENABLE_SSO" icon="fa-info-circle" %}
|
{% include "InvenTree/settings/setting.html" with key="LOGIN_ENABLE_SSO" icon="fa-info-circle" %}
|
||||||
{% include "InvenTree/settings/setting.html" with key="LOGIN_ENABLE_PWD_FORGOT" icon="fa-info-circle" %}
|
{% include "InvenTree/settings/setting.html" with key="LOGIN_ENABLE_PWD_FORGOT" icon="fa-info-circle" %}
|
||||||
{% include "InvenTree/settings/setting.html" with key="LOGIN_MAIL_REQUIRED" icon="fa-info-circle" %}
|
{% include "InvenTree/settings/setting.html" with key="LOGIN_MAIL_REQUIRED" icon="fa-info-circle" %}
|
||||||
@ -22,9 +21,11 @@
|
|||||||
<td>{% trans 'Signup' %}</td>
|
<td>{% trans 'Signup' %}</td>
|
||||||
<td colspan='4'></td>
|
<td colspan='4'></td>
|
||||||
</tr>
|
</tr>
|
||||||
|
{% include "InvenTree/settings/setting.html" with key="LOGIN_ENABLE_REG" icon="fa-info-circle" %}
|
||||||
{% include "InvenTree/settings/setting.html" with key="LOGIN_SIGNUP_MAIL_TWICE" icon="fa-info-circle" %}
|
{% include "InvenTree/settings/setting.html" with key="LOGIN_SIGNUP_MAIL_TWICE" icon="fa-info-circle" %}
|
||||||
{% include "InvenTree/settings/setting.html" with key="LOGIN_SIGNUP_PWD_TWICE" icon="fa-info-circle" %}
|
{% include "InvenTree/settings/setting.html" with key="LOGIN_SIGNUP_PWD_TWICE" icon="fa-info-circle" %}
|
||||||
{% include "InvenTree/settings/setting.html" with key="LOGIN_SIGNUP_SSO_AUTO" icon="fa-info-circle" %}
|
{% include "InvenTree/settings/setting.html" with key="LOGIN_SIGNUP_SSO_AUTO" icon="fa-info-circle" %}
|
||||||
|
{% include "InvenTree/settings/setting.html" with key="SIGNUP_GROUP" %}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user