From 2b957501c9705b2620f66c9906571257120d97e5 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 25 Apr 2023 09:00:42 +0000 Subject: [PATCH 1/7] Bump sqlparse from 0.4.3 to 0.4.4 Bumps [sqlparse](https://github.com/andialbrecht/sqlparse) from 0.4.3 to 0.4.4. - [Release notes](https://github.com/andialbrecht/sqlparse/releases) - [Changelog](https://github.com/andialbrecht/sqlparse/blob/master/CHANGELOG) - [Commits](https://github.com/andialbrecht/sqlparse/compare/0.4.3...0.4.4) --- updated-dependencies: - dependency-name: sqlparse dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 2e8204b..c63e8eb 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 From c3ce4bd35e4f07476cc0063ab2abfd0b1d99cc2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Barbier?= Date: Thu, 4 May 2023 17:58:17 +0200 Subject: [PATCH 2/7] Bump to version 1.2.1 --- CHANGELOG.md | 4 ++++ docs/conf.py | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c6d226..f78804b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,10 @@ 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.2.1] - 2023-05-DD +### 🐛 Bug Fixes +- Toggle autosync fail (#80) + ## [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..ab961e0 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -67,7 +67,7 @@ # The short X.Y version. version = '1.2' # The full version, including alpha/beta/rc tags. -release = '1.2.0' +release = '1.2.1' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. From e0a6437fee6a1ae455495e854cff51e20a636307 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Barbier?= Date: Fri, 5 May 2023 09:11:57 +0200 Subject: [PATCH 3/7] Add test on PATCH for account entrypoint Related to #80 --- seven23/api/accounts/tests_accounts.py | 17 +++++++++++++++++ seven23/models/accounts/serializers.py | 1 - 2 files changed, 17 insertions(+), 1 deletion(-) 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/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 From 5ae1f2ec607c7963399b8befcbcc86bd71f337d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Barbier?= Date: Fri, 5 May 2023 09:37:15 +0200 Subject: [PATCH 4/7] Add auto_sync boolean to user profile model Related to #81 --- CHANGELOG.md | 2 +- docs/conf.py | 4 ++-- seven23/api/users/tests_users.py | 4 +++- .../migrations/0012_profile_auto_sync.py | 18 ++++++++++++++++++ seven23/models/profile/models.py | 1 + seven23/models/profile/serializers.py | 2 +- seven23/models/profile/tests.py | 3 ++- seven23/settings.py | 2 +- 8 files changed, 29 insertions(+), 7 deletions(-) create mode 100644 seven23/models/profile/migrations/0012_profile_auto_sync.py diff --git a/CHANGELOG.md b/CHANGELOG.md index f78804b..e60fb2a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,7 +21,7 @@ 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.2.1] - 2023-05-DD +## [1.3.0] - 2023-05-DD ### 🐛 Bug Fixes - Toggle autosync fail (#80) diff --git a/docs/conf.py b/docs/conf.py index ab961e0..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.1' +release = '1.3.0' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. 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/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..b3a8518 100644 --- a/seven23/settings.py +++ b/seven23/settings.py @@ -22,7 +22,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__)) From 6a803979198b19dadc2a20728fc576a35e4a18e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Barbier?= Date: Tue, 9 May 2023 22:19:02 +0200 Subject: [PATCH 5/7] Log config for easier deployment Related to #83 --- CHANGELOG.md | 6 +++++- docs/configuration.md | 2 +- seven23/logs.py | 19 +++++++++++++++++++ seven23/settings.py | 24 ++++++++++++++++++++++-- seven23/urls.py | 5 ++++- 5 files changed, 51 insertions(+), 5 deletions(-) create mode 100644 seven23/logs.py diff --git a/CHANGELOG.md b/CHANGELOG.md index e60fb2a..f0ba145 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,8 +22,12 @@ See for sample https://raw.githubusercontent.com/favoloso/conventional-changelog --> ## [1.3.0] - 2023-05-DD +### 🛠 Improvements +- Apply **auto_sync settings for all accounts** instead of individual one (#81) +- **Log config** for easier deployment (#83) ### 🐛 Bug Fixes -- Toggle autosync fail (#80) +- Settings **autosync** fails (#80) +- **Registration** returing 204 instead of 201 (#82) ## [1.2.0] - 2023-04-24 ### ✨ Feature 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/seven23/logs.py b/seven23/logs.py new file mode 100644 index 0000000..2573a99 --- /dev/null +++ b/seven23/logs.py @@ -0,0 +1,19 @@ +from . import settings + +def print_settings_report(): + print('################################') + print('##### Seven23_server ####') + print('################################') + + 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/settings.py b/seven23/settings.py index b3a8518..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 @@ -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: From 7df9cc2566220475a3cf8f015b2c06b56591ccc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Barbier?= Date: Tue, 9 May 2023 22:20:46 +0200 Subject: [PATCH 6/7] Update CHANGELOG date --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f0ba145..656b539 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,7 +21,7 @@ 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-DD +## [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) From 6feec2f33b576d229745cb439d51aa4a298cd5ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Barbier?= Date: Tue, 9 May 2023 22:22:36 +0200 Subject: [PATCH 7/7] Add DEBUG logs for settings on start Related to #83 --- seven23/logs.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/seven23/logs.py b/seven23/logs.py index 2573a99..0decb71 100644 --- a/seven23/logs.py +++ b/seven23/logs.py @@ -5,6 +5,9 @@ def print_settings_report(): 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: