diff --git a/opentech/apply/funds/migrations/0021_round_lead.py b/opentech/apply/funds/migrations/0021_round_lead.py new file mode 100644 index 0000000000000000000000000000000000000000..6d9d8c2377dbe2b1b6e50c10a41ef19e74e9bbc6 --- /dev/null +++ b/opentech/apply/funds/migrations/0021_round_lead.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.8 on 2018-02-14 17:21 +from __future__ import unicode_literals + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ('funds', '0020_applicationsubmission_form_fields'), + ] + + operations = [ + migrations.AddField( + model_name='round', + name='lead', + field=models.ForeignKey(default=1, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL), + preserve_default=False, + ), + ] diff --git a/opentech/apply/funds/models.py b/opentech/apply/funds/models.py index 8d6a4d65a5ac3ff566c8b5ae61ff438191ba49d9..1bf83fec5a4844d5372c923d4559c3cb11799963 100644 --- a/opentech/apply/funds/models.py +++ b/opentech/apply/funds/models.py @@ -274,6 +274,7 @@ class Round(WorkflowStreamForm, SubmittableStreamForm): # type: ignore parent_page_types = ['funds.FundType'] subpage_types = [] # type: ignore + lead = models.ForeignKey(settings.AUTH_USER_MODEL, limit_choices_to={'is_staff': True}) start_date = models.DateField(default=date.today) end_date = models.DateField( blank=True, @@ -283,6 +284,7 @@ class Round(WorkflowStreamForm, SubmittableStreamForm): # type: ignore ) content_panels = SubmittableStreamForm.content_panels + [ + FieldPanel('lead'), MultiFieldPanel([ FieldRowPanel([ FieldPanel('start_date'), diff --git a/opentech/apply/users/models.py b/opentech/apply/users/models.py index 5e39dfb2ef57fd63691a26de9140ec21578b0333..162d1d1f5309d8a79b24330f44187c2e84e1438c 100644 --- a/opentech/apply/users/models.py +++ b/opentech/apply/users/models.py @@ -69,3 +69,6 @@ class User(AbstractUser): username = None objects = UserManager() + + def __str__(self): + return self.get_full_name() diff --git a/opentech/apply/users/piplines.py b/opentech/apply/users/piplines.py new file mode 100644 index 0000000000000000000000000000000000000000..0f608e6b179ca5560a6fe055abed465f493636ec --- /dev/null +++ b/opentech/apply/users/piplines.py @@ -0,0 +1,8 @@ +from django.conf import settings + + +def make_otf_staff(backend, user, response, *args, **kwargs): + _, email_domain = user.email.split('@') + if email_domain in settings.STAFF_EMAIL_DOMAINS: + user.is_staff = True + user.save() diff --git a/opentech/settings/base.py b/opentech/settings/base.py index 98a914eb542689104f6514b39b923bf6c44f237f..b90b8a3688f62dd3b2839abc1841be0da151e659 100644 --- a/opentech/settings/base.py +++ b/opentech/settings/base.py @@ -298,7 +298,8 @@ SOCIAL_AUTH_URL_NAMESPACE = 'social' # Set the Google OAuth2 credentials in ENV variables or local.py # To create a new set of credentials, go to https://console.developers.google.com/apis/credentials # Make sure the Google+ API is enabled for your API project -SOCIAL_AUTH_GOOGLE_OAUTH2_WHITELISTED_DOMAINS = ['opentechfund.org'] +STAFF_EMAIL_DOMAINS = ['opentechfund.org'] +SOCIAL_AUTH_GOOGLE_OAUTH2_WHITELISTED_DOMAINS = STAFF_EMAIL_DOMAINS SOCIAL_AUTH_GOOGLE_OAUTH2_KEY = '' SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET = '' @@ -318,6 +319,7 @@ SOCIAL_AUTH_PIPELINE = ( 'social_core.pipeline.social_auth.associate_user', 'social_core.pipeline.social_auth.load_extra_data', 'social_core.pipeline.user.user_details', + 'opentech.apply.users.pipeline.make_otf_staff', ) # Bleach Settings