-
Notifications
You must be signed in to change notification settings - Fork 2
/
sandstorm.patch
230 lines (216 loc) · 7.88 KB
/
sandstorm.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
diff --git a/Pipfile b/Pipfile
index 62a51bb..4a20390 100644
--- a/Pipfile
+++ b/Pipfile
@@ -19,6 +19,7 @@ python-dotenv = "*"
django-storages = "*"
boto3 = "*"
django-import-export = "*"
+django-sandstorm = {editable = true,git = "https://github.com/cdubz/django-sandstorm.git"}
[dev-packages]
coveralls = "*"
diff --git a/babybuddy/forms.py b/babybuddy/forms.py
index 4f0a7fb..c386b61 100644
--- a/babybuddy/forms.py
+++ b/babybuddy/forms.py
@@ -6,20 +6,6 @@ from django.contrib.auth.models import User
from .models import Settings
-class UserAddForm(UserCreationForm):
- class Meta:
- model = User
- fields = ['username', 'first_name', 'last_name', 'email',
- 'is_staff', 'is_active']
-
- def save(self, commit=True):
- user = super(UserAddForm, self).save(commit=False)
- user.is_superuser = True
- if commit:
- user.save()
- return user
-
-
class UserUpdateForm(forms.ModelForm):
class Meta:
model = User
@@ -33,11 +19,6 @@ class UserForm(forms.ModelForm):
fields = ['first_name', 'last_name', 'email']
-class UserPasswordForm(PasswordChangeForm):
- class Meta:
- fields = ['old_password', 'new_password1', 'new_password2']
-
-
class UserSettingsForm(forms.ModelForm):
class Meta:
model = Settings
diff --git a/babybuddy/management/commands/migrate.py b/babybuddy/management/commands/migrate.py
index 0e22ab5..d78c258 100644
--- a/babybuddy/management/commands/migrate.py
+++ b/babybuddy/management/commands/migrate.py
@@ -8,10 +8,3 @@ class Command(migrate.Command):
def handle(self, *args, **kwargs):
super(Command, self).handle(*args, **kwargs)
-
- superusers = User.objects.filter(is_superuser=True)
- if len(superusers) == 0:
- default_user = User.objects.create_user('admin', password='admin')
- default_user.is_superuser = True
- default_user.is_staff = True
- default_user.save()
diff --git a/babybuddy/settings/sandstorm.py b/babybuddy/settings/sandstorm.py
new file mode 100644
index 0000000..7aa8682
--- /dev/null
+++ b/babybuddy/settings/sandstorm.py
@@ -0,0 +1,38 @@
+from .base import *
+
+
+# Django Sandstorm package configuration.
+
+INSTALLED_APPS.append('django_sandstorm')
+
+MIDDLEWARE.append('django_sandstorm.middleware.SandstormUserMiddleware')
+
+try:
+ csrf_index = MIDDLEWARE.index('django.middleware.csrf.CsrfViewMiddleware')
+ MIDDLEWARE.insert(
+ (csrf_index - 1),
+ 'django_sandstorm.middleware.SandstormPreCsrfViewMiddleware'
+ )
+except ValueError:
+ pass
+
+AUTHENTICATION_BACKENDS = [
+ 'django.contrib.auth.backends.RemoteUserBackend',
+]
+
+
+# Database
+# https://docs.djangoproject.com/en/3.0/ref/settings/#databases
+
+DATABASES = {
+ 'default': {
+ 'ENGINE': 'django.db.backends.sqlite3',
+ 'NAME': '/var/sqlite3/db.sqlite3',
+ }
+}
+
+
+# Media files (User uploaded content)
+# https://docs.djangoproject.com/en/3.0/topics/files/
+
+MEDIA_ROOT = '/var/media'
diff --git a/babybuddy/templates/babybuddy/nav-dropdown.html b/babybuddy/templates/babybuddy/nav-dropdown.html
index 14f02aa..034fd30 100644
--- a/babybuddy/templates/babybuddy/nav-dropdown.html
+++ b/babybuddy/templates/babybuddy/nav-dropdown.html
@@ -239,14 +239,11 @@
<div class="dropdown-menu dropdown-menu-right" aria-labelledby="nav-user-menu-link">
<h6 class="dropdown-header">{% trans "User" %}</h6>
<a href="{% url 'babybuddy:user-settings' %}" class="dropdown-item">{% trans "Settings" %}</a>
- <a href="{% url 'babybuddy:user-password' %}" class="dropdown-item">{% trans "Password" %}</a>
- <a href="{% url 'babybuddy:logout' %}" class="dropdown-item">{% trans "Logout" %}</a>
<h6 class="dropdown-header">{% trans "Site" %}</h6>
<a href="{% url 'api:api-root' %}"
class="dropdown-item"
target="_blank">{% trans "API Browser" %}</a>
{% if request.user.is_staff %}
- <a href="{% url 'babybuddy:user-list' %}" class="dropdown-item">{% trans "Users" %}</a>
<a href="{% url 'admin:index' %}" class="dropdown-item">{% trans "Database Admin" %}</a>
{% endif %}
<h6 class="dropdown-header">{% trans "Support" %}</h6>
diff --git a/babybuddy/urls.py b/babybuddy/urls.py
index a18f2a1..8fad3ae 100644
--- a/babybuddy/urls.py
+++ b/babybuddy/urls.py
@@ -9,34 +9,17 @@ from . import views
app_patterns = [
path('login/', auth_views.LoginView.as_view(), name='login'),
- path('logout/', auth_views.LogoutView.as_view(), name='logout'),
- path(
- 'password_reset/',
- auth_views.PasswordResetView.as_view(),
- name='password_reset'
- ),
path('', views.RootRouter.as_view(), name='root-router'),
path('welcome/', views.Welcome.as_view(), name='welcome'),
path('users/', views.UserList.as_view(), name='user-list'),
- path('users/add/', views.UserAdd.as_view(), name='user-add'),
path(
'users/<int:pk>/edit/',
views.UserUpdate.as_view(),
name='user-update'
),
- path(
- 'users/<int:pk>/delete/',
- views.UserDelete.as_view(),
- name='user-delete'
- ),
- path(
- 'user/password/',
- views.UserPassword.as_view(),
- name='user-password'
- ),
path(
'user/reset-api-key/',
views.UserResetAPIKey.as_view(),
diff --git a/babybuddy/views.py b/babybuddy/views.py
index 75f36b9..31eaab9 100644
--- a/babybuddy/views.py
+++ b/babybuddy/views.py
@@ -47,16 +47,6 @@ class UserList(StaffOnlyMixin, BabyBuddyFilterView):
filterset_fields = ('username', 'first_name', 'last_name', 'email')
-class UserAdd(StaffOnlyMixin, PermissionRequired403Mixin, SuccessMessageMixin,
- CreateView):
- model = User
- template_name = 'babybuddy/user_form.html'
- permission_required = ('admin.add_user',)
- form_class = forms.UserAddForm
- success_url = reverse_lazy('babybuddy:user-list')
- success_message = gettext_lazy('User %(username)s added!')
-
-
class UserUpdate(StaffOnlyMixin, PermissionRequired403Mixin,
SuccessMessageMixin, UpdateView):
model = User
@@ -67,42 +57,6 @@ class UserUpdate(StaffOnlyMixin, PermissionRequired403Mixin,
success_message = gettext_lazy('User %(username)s updated.')
-class UserDelete(StaffOnlyMixin, PermissionRequired403Mixin,
- DeleteView):
- model = User
- template_name = 'babybuddy/user_confirm_delete.html'
- permission_required = ('admin.delete_user',)
- success_url = reverse_lazy('babybuddy:user-list')
-
- def delete(self, request, *args, **kwargs):
- success_message = format_lazy(gettext_lazy(
- 'User {user} deleted.'), user=self.get_object()
- )
- messages.success(request, success_message)
- return super(UserDelete, self).delete(request, *args, **kwargs)
-
-
-class UserPassword(LoginRequiredMixin, View):
- """
- Handles user password changes.
- """
- form_class = forms.UserPasswordForm
- template_name = 'babybuddy/user_password_form.html'
-
- def get(self, request):
- return render(request, self.template_name, {
- 'form': self.form_class(request.user)
- })
-
- def post(self, request):
- form = PasswordChangeForm(request.user, request.POST)
- if form.is_valid():
- user = form.save()
- update_session_auth_hash(request, user)
- messages.success(request, _('Password updated.'))
- return render(request, self.template_name, {'form': form})
-
-
class UserResetAPIKey(LoginRequiredMixin, View):
"""
Resets the API key of the logged in user.