-
Notifications
You must be signed in to change notification settings - Fork 2
/
sandstorm.patch
272 lines (257 loc) · 9.63 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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
diff --git a/Pipfile b/Pipfile
index 3fccb52..2725ed6 100644
--- a/Pipfile
+++ b/Pipfile
@@ -17,12 +17,12 @@ faker = "*"
gunicorn = "*"
pillow = "*"
plotly = "*"
-psycopg2-binary = "*"
python-dotenv = "*"
pyyaml = "*"
uritemplate = "*"
whitenoise = "*"
django-taggit = "==2.1.0"
+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 9c91cb5..0a500f9 100644
--- a/babybuddy/forms.py
+++ b/babybuddy/forms.py
@@ -1,31 +1,10 @@
# -*- coding: utf-8 -*-
from django import forms
-from django.contrib.auth.forms import PasswordChangeForm, UserCreationForm
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
@@ -45,11 +24,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 c9b732a..acfab3d 100644
--- a/babybuddy/management/commands/migrate.py
+++ b/babybuddy/management/commands/migrate.py
@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
-from django.contrib.auth.models import User
from django.core.management.commands import migrate
@@ -8,10 +7,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 080276a..34b1a26 100644
--- a/babybuddy/templates/babybuddy/nav-dropdown.html
+++ b/babybuddy/templates/babybuddy/nav-dropdown.html
@@ -345,17 +345,9 @@
<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>
- <form action="{% url 'babybuddy:logout' %}" role="form" method="post">
- {% csrf_token %}
- <button class="dropdown-item">
- {% trans "Logout" %}
- </button>
- </form>
<h6 class="dropdown-header">{% trans "Site" %}</h6>
<a href="{% url 'api:api-root' %}" class="dropdown-item">{% 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 e2d2e78..efca8f1 100644
--- a/babybuddy/urls.py
+++ b/babybuddy/urls.py
@@ -8,18 +8,26 @@ from django.urls import include, path
from . import views
app_patterns = [
- path("login/", auth_views.LoginView.as_view(), name="login"),
- path("logout/", views.LogoutView.as_view(), name="logout"),
+ path('login/', auth_views.LoginView.as_view(), name='login'),
+
+ 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/<int:pk>/edit/',
+ views.UserUpdate.as_view(),
+ name='user-update'
+ ),
path(
- "password_reset/", auth_views.PasswordResetView.as_view(), name="password_reset"
+ 'user/settings/',
+ views.UserSettings.as_view(),
+ name='user-settings'
),
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/settings/", views.UserSettings.as_view(), name="user-settings"),
]
diff --git a/babybuddy/views.py b/babybuddy/views.py
index a53cde1..0c64790 100644
--- a/babybuddy/views.py
+++ b/babybuddy/views.py
@@ -1,7 +1,5 @@
# -*- coding: utf-8 -*-
from django.contrib import messages
-from django.contrib.auth import update_session_auth_hash
-from django.contrib.auth.forms import PasswordChangeForm
from django.contrib.auth.models import User
from django.contrib.auth.views import LogoutView as LogoutViewBase
from django.contrib.messages.views import SuccessMessageMixin
@@ -12,7 +10,6 @@ from django.template import loader
from django.urls import reverse, reverse_lazy
from django.utils import translation
from django.utils.decorators import method_decorator
-from django.utils.text import format_lazy
from django.utils.translation import gettext as _, gettext_lazy
from django.views import csrf
from django.views.decorators.cache import never_cache
@@ -93,18 +90,8 @@ class UserList(StaffOnlyMixin, BabyBuddyFilterView):
filterset_fields = ("username", "first_name", "last_name", "email")
-class UserAdd(StaffOnlyMixin, PermissionRequiredMixin, 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, PermissionRequiredMixin, SuccessMessageMixin, UpdateView
-):
+class UserUpdate(StaffOnlyMixin, PermissionRequiredMixin,
+ SuccessMessageMixin, UpdateView):
model = User
template_name = "babybuddy/user_form.html"
permission_required = ("admin.change_user",)
@@ -113,40 +100,6 @@ class UserUpdate(
success_message = gettext_lazy("User %(username)s updated.")
-class UserDelete(
- StaffOnlyMixin, PermissionRequiredMixin, DeleteView, SuccessMessageMixin
-):
- model = User
- template_name = "babybuddy/user_confirm_delete.html"
- permission_required = ("admin.delete_user",)
- success_url = reverse_lazy("babybuddy:user-list")
-
- def get_success_message(self, cleaned_data):
- return format_lazy(gettext_lazy("User {user} deleted."), user=self.get_object())
-
-
-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 UserSettings(LoginRequiredMixin, View):
"""
Handles both the User and Settings models.