diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c6d226..656b539 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,14 @@ and this project adheres to [Semantic Versioning](http://semver.org/). See for sample https://raw.githubusercontent.com/favoloso/conventional-changelog-emoji/master/CHANGELOG.md --> +## [1.3.0] - 2023-05-09 +### 🛠 Improvements +- Apply **auto_sync settings for all accounts** instead of individual one (#81) +- **Log config** for easier deployment (#83) +### 🐛 Bug Fixes +- Settings **autosync** fails (#80) +- **Registration** returing 204 instead of 201 (#82) + ## [1.2.0] - 2023-04-24 ### ✨ Feature - Publish **docker** image ([#69](https://github.com/sebastienbarbier/seven23_server/issues/69)) diff --git a/docs/conf.py b/docs/conf.py index 625d22b..c44d0f3 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -65,9 +65,9 @@ # built documents. # # The short X.Y version. -version = '1.2' +version = '1.3' # The full version, including alpha/beta/rc tags. -release = '1.2.0' +release = '1.3.0' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/docs/configuration.md b/docs/configuration.md index ca87a55..eb9ac02 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -33,5 +33,5 @@ DEBUG=1 Disable the creation of new user throught the application. ```shell -ALLOW_ACCOUNT_CREATION=0 +ALLOW_ACCOUNT_CREATION=true # or False ``` \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 5f0fc02..ee6c7d4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -66,7 +66,7 @@ s3transfer==0.6.0 sentry-sdk==1.19.1 simplejson==3.19.1 six==1.16.0 -sqlparse==0.4.3 +sqlparse==0.4.4 stripe==5.4.0 terminaltables==3.1.10 typing_extensions==4.5.0 diff --git a/seven23/api/accounts/tests_accounts.py b/seven23/api/accounts/tests_accounts.py index 21afe76..fa784a5 100644 --- a/seven23/api/accounts/tests_accounts.py +++ b/seven23/api/accounts/tests_accounts.py @@ -104,6 +104,23 @@ def test_account_post(self): assert response.status_code == status.HTTP_200_OK assert response.json()['name'] == 'Test creation' + def test_account_patch(self): + """ + We try to edit an account object + """ + self.client.force_authenticate(user=self.user) + + response = self.client.get('/api/v1/accounts/%d' % self.account.id) + assert response.status_code == status.HTTP_200_OK + + assert self.account.name == "Private Account" + self.account.name = "Public Account" + response = self.client.patch('/api/v1/accounts/%d' % self.account.id, + {'name': self.account.name, + }) + assert response.status_code == status.HTTP_200_OK + assert response.json()['name'] == "Public Account" + def test_account_destroy(self): """ We try to edit an account object diff --git a/seven23/api/users/tests_users.py b/seven23/api/users/tests_users.py index 25cc2e7..4913096 100644 --- a/seven23/api/users/tests_users.py +++ b/seven23/api/users/tests_users.py @@ -47,4 +47,6 @@ def test_registration_new_user(self): self.assertEqual(data['username'], 'test') self.assertTrue('profile' in data) self.assertTrue('avatar' in data['profile']) - self.assertTrue('social_networks' in data['profile']) \ No newline at end of file + self.assertTrue('auto_sync' in data['profile']) + self.assertTrue('social_networks' in data['profile']) + self.assertFalse(data['profile']['auto_sync']) \ No newline at end of file diff --git a/seven23/logs.py b/seven23/logs.py new file mode 100644 index 0000000..0decb71 --- /dev/null +++ b/seven23/logs.py @@ -0,0 +1,22 @@ +from . import settings + +def print_settings_report(): + print('################################') + print('##### Seven23_server ####') + print('################################') + + if settings.DEBUG: + print('✅ 🔎 🐛 Debug is enabled') + + print(f'Version: {settings.VERSION[0]}.{settings.VERSION[1]}.{settings.VERSION[2]}') + + if 'SECRET_KEY' in settings.errors: + print('⚠️ Secret key generated. Please set the environment variable SECRET_KEY to avoid this message.') + + if 'ALLOW_ACCOUNT_CREATION' in settings.errors: + print('❌ 🙅‍♂️ Registration is disabled') + else: + print('✅ 🙋‍♂️ Registration is enabled') + + if 'EMAIL_BACKEND' in settings.errors: + print('❌ ✉️ Emails are displayed in console') \ No newline at end of file diff --git a/seven23/models/accounts/serializers.py b/seven23/models/accounts/serializers.py index cdf896d..acf9b9d 100644 --- a/seven23/models/accounts/serializers.py +++ b/seven23/models/accounts/serializers.py @@ -7,7 +7,6 @@ from seven23.models.accounts.models import Account, AccountGuests from seven23.models.currency.models import Currency - from rest_framework_bulk import ( BulkListSerializer, BulkSerializerMixin diff --git a/seven23/models/profile/migrations/0012_profile_auto_sync.py b/seven23/models/profile/migrations/0012_profile_auto_sync.py new file mode 100644 index 0000000..05a44f5 --- /dev/null +++ b/seven23/models/profile/migrations/0012_profile_auto_sync.py @@ -0,0 +1,18 @@ +# Generated by Django 4.1.8 on 2023-05-05 07:30 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('profile', '0011_profile_stripe_customer_id'), + ] + + operations = [ + migrations.AddField( + model_name='profile', + name='auto_sync', + field=models.BooleanField(default=False, verbose_name='Auto sync in app'), + ), + ] diff --git a/seven23/models/profile/models.py b/seven23/models/profile/models.py index 1e0a94e..5bb23d3 100644 --- a/seven23/models/profile/models.py +++ b/seven23/models/profile/models.py @@ -32,6 +32,7 @@ class Profile(models.Model): max_length=20, choices=AVATAR_OPTIONS, help_text=_(u'Select between different origins.')) + auto_sync = models.BooleanField(_(u'Auto sync in app'), default=False) social_networks = models.TextField(_('social_networks blob'), blank=True, null=False) last_api_call = models.DateField(_(u'Last API call'), help_text=_(u'Last call on the API as a registered user'), diff --git a/seven23/models/profile/serializers.py b/seven23/models/profile/serializers.py index 01cee83..cdb41b4 100644 --- a/seven23/models/profile/serializers.py +++ b/seven23/models/profile/serializers.py @@ -7,7 +7,7 @@ class ProfileSerializer(serializers.HyperlinkedModelSerializer): class Meta: model = Profile - fields = ['avatar', 'social_networks'] + fields = ['avatar', 'auto_sync', 'social_networks'] class DatetimeSerializer(serializers.HyperlinkedModelSerializer): diff --git a/seven23/models/profile/tests.py b/seven23/models/profile/tests.py index 81964c5..d8b5e5a 100644 --- a/seven23/models/profile/tests.py +++ b/seven23/models/profile/tests.py @@ -26,4 +26,5 @@ def test_profile_creation(self): expected_date = timezone.now() + datetime.timedelta(days=settings.TRIAL_PERIOD) self.assertEqual(self.user.profile.valid_until > timezone.now(), True) - self.assertEqual(self.user.profile.valid_until < expected_date, True) \ No newline at end of file + self.assertEqual(self.user.profile.valid_until < expected_date, True) + self.assertEqual(self.user.profile.auto_sync, False) \ No newline at end of file diff --git a/seven23/settings.py b/seven23/settings.py index 38b29f0..7e7656d 100644 --- a/seven23/settings.py +++ b/seven23/settings.py @@ -12,6 +12,14 @@ import os import dj_database_url +from django.core.management.utils import get_random_secret_key + +from seven23.logs import print_settings_report + +# Errors is an array of variable name as string +# to display report at the end of settings +errors = [] + if os.environ.get('SENTRY_DSN'): import sentry_sdk from sentry_sdk.integrations.django import DjangoIntegration @@ -22,7 +30,7 @@ integrations=[DjangoIntegration()] ) -VERSION = [1, 2, 0] +VERSION = [1, 3, 0] API_VERSION = [1, 0, 0] BASE_DIR = os.path.dirname(os.path.dirname(__file__)) @@ -31,13 +39,22 @@ # SECURITY WARNING: keep the secret key used in production secret! SECRET_KEY = os.environ.get('SECRET_KEY') +# If secret Key is empty we generate one +if not SECRET_KEY: + SECRET_KEY = get_random_secret_key() + errors.append("SECRET_KEY") # SECURITY WARNING: don't run with debug turned on in production! DEBUG = os.environ.get('DEBUG', 'false').lower() == 'true' MAINTENANCE = os.environ.get('MAINTENANCE', 'false').lower() == 'true' # Allow public account creation -ALLOW_ACCOUNT_CREATION = os.environ.get('ALLOW_ACCOUNT_CREATION', 'false').lower() == 'true' +ALLOW_ACCOUNT_CREATION = \ + os.environ.get('ALLOW_ACCOUNT_CREATION', 'false').lower() == 'true' or\ + os.environ.get('ALLOW_ACCOUNT_CREATION', '0') == '1' +if not ALLOW_ACCOUNT_CREATION: + errors.append("ALLOW_ACCOUNT_CREATION") + OLD_PASSWORD_FIELD_ENABLED = True APPEND_SLASH = True @@ -233,8 +250,11 @@ EMAIL_HOST_PASSWORD = os.environ.get('EMAIL_HOST_PASSWORD') EMAIL_USE_TLS = os.environ.get('EMAIL_USE_TLS') -if os.environ.get('EMAIL_BACKEND_CONSOLE', 'false').lower() == 'true' or not EMAIL_HOST: +if os.environ.get('EMAIL_BACKEND_CONSOLE', 'false').lower() == 'true' or\ + os.environ.get('EMAIL_BACKEND_CONSOLE', '0') == '1' or\ + not EMAIL_HOST: EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' + errors.append('EMAIL_BACKEND') # Internationalization # https://docs.djangoproject.com/en/1.6/topics/i18n/ diff --git a/seven23/urls.py b/seven23/urls.py index c0959c8..f449c42 100644 --- a/seven23/urls.py +++ b/seven23/urls.py @@ -11,9 +11,13 @@ from drf_yasg import openapi from . import views +from .logs import print_settings_report admin.autodiscover() +# Print settings errors load for easier deployment +print_settings_report() + schema_view = get_schema_view( openapi.Info( title="Seven23 API", @@ -26,7 +30,6 @@ permission_classes=(permissions.AllowAny,), ) - urlpatterns = [ # Examples: