+
{{ _('איפוס סיסמה') }}
{{ _('הזינו אימייל לצורך שליחת קישור לאיפוס הסיסמה:') }}
From fa56e55baf0ad603310bc50bf3d201924cb76404 Mon Sep 17 00:00:00 2001
From: Or Ronai
Date: Tue, 21 Sep 2021 09:25:22 +0300
Subject: [PATCH 46/51] Add migration
---
lms/lmsdb/bootstrap.py | 16 ++++++++++++++++
lms/lmsdb/models.py | 4 +---
2 files changed, 17 insertions(+), 3 deletions(-)
diff --git a/lms/lmsdb/bootstrap.py b/lms/lmsdb/bootstrap.py
index 0bc54d0c..03140e5b 100644
--- a/lms/lmsdb/bootstrap.py
+++ b/lms/lmsdb/bootstrap.py
@@ -1,4 +1,5 @@
from typing import Any, Callable, Optional, Tuple, Type
+from uuid import uuid4
from peewee import (
Entity, Expression, Field, Model, OP, OperationalError, ProgrammingError,
@@ -231,12 +232,26 @@ def _add_api_keys_to_users_table(table: Model, _column: Field) -> None:
user.save()
+def _add_uuid_to_users_table(table: Model, _colum: Field) -> None:
+ log.info('Adding UUIDs for all users, might take some extra time...')
+ with db_config.database.transaction():
+ for user in table:
+ user.uuid = uuid4()
+ user.save()
+
+
def _api_keys_migration() -> bool:
User = models.User
_add_not_null_column(User, User.api_key, _add_api_keys_to_users_table)
return True
+def _uuid_migration() -> bool:
+ User = models.User
+ _add_not_null_column(User, User.uuid, _add_uuid_to_users_table)
+ return True
+
+
def main():
with models.database.connection_context():
models.database.create_tables(models.ALL_MODELS, safe=True)
@@ -247,6 +262,7 @@ def main():
models.create_demo_users()
_api_keys_migration()
+ _uuid_migration()
text_fixer.fix_texts()
import_tests.load_tests_from_path('/app_dir/notebooks-tests')
diff --git a/lms/lmsdb/models.py b/lms/lmsdb/models.py
index f4304886..eee18c6a 100644
--- a/lms/lmsdb/models.py
+++ b/lms/lmsdb/models.py
@@ -928,9 +928,7 @@ def create_demo_users():
user = dict(zip(fields, entity))
password = User.random_password()
api_key = User.random_password(stronger=True)
- User.create(
- **user, password=password, api_key=api_key,
- )
+ User.create(**user, password=password, api_key=api_key)
print(f"User: {user['username']}, Password: {password}") # noqa: T001
From e7e80435360c1c7604c001bea38738dfb5f36d79 Mon Sep 17 00:00:00 2001
From: Or Ronai
Date: Tue, 21 Sep 2021 10:03:21 +0300
Subject: [PATCH 47/51] feat: add migration
---
lms/lmsdb/bootstrap.py | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/lms/lmsdb/bootstrap.py b/lms/lmsdb/bootstrap.py
index 03140e5b..981d520f 100644
--- a/lms/lmsdb/bootstrap.py
+++ b/lms/lmsdb/bootstrap.py
@@ -254,6 +254,10 @@ def _uuid_migration() -> bool:
def main():
with models.database.connection_context():
+ if models.database.table_exists(models.User.__name__.lower()):
+ _api_keys_migration()
+ _uuid_migration()
+
models.database.create_tables(models.ALL_MODELS, safe=True)
if models.Role.select().count() == 0:
@@ -261,8 +265,6 @@ def main():
if models.User.select().count() == 0:
models.create_demo_users()
- _api_keys_migration()
- _uuid_migration()
text_fixer.fix_texts()
import_tests.load_tests_from_path('/app_dir/notebooks-tests')
From 33da2423723894fa61694b8dfc5107a9406bb18e Mon Sep 17 00:00:00 2001
From: Or Ronai
Date: Tue, 21 Sep 2021 10:10:45 +0300
Subject: [PATCH 48/51] fix: bool expression
---
lms/lmsdb/bootstrap.py | 8 ++------
1 file changed, 2 insertions(+), 6 deletions(-)
diff --git a/lms/lmsdb/bootstrap.py b/lms/lmsdb/bootstrap.py
index 981d520f..7688c890 100644
--- a/lms/lmsdb/bootstrap.py
+++ b/lms/lmsdb/bootstrap.py
@@ -89,9 +89,7 @@ def get_details(table: Model, column: Field) -> Tuple[bool, str, str]:
column_name = column.column_name
cols = {col.name for col in db_config.database.get_columns(table_name)}
- if column_name in cols:
- return True, table_name, column_name
- return False, table_name, column_name
+ return column_name in cols, table_name, column_name
def _add_not_null_column(
@@ -219,9 +217,7 @@ def _drop_constraint_if_needed(table: Type[Model], column_name: str) -> bool:
def has_column_named(table: Model, column_name: str) -> bool:
db = db_config.database
columns = {col.name for col in db.get_columns(table.__name__.lower())}
- if column_name not in columns:
- return False
- return True
+ return column_name in columns
def _add_api_keys_to_users_table(table: Model, _column: Field) -> None:
From 1ca610293dd5589618e88dc9f28b24c057c50d68 Mon Sep 17 00:00:00 2001
From: Or Ronai
Date: Wed, 22 Sep 2021 10:06:12 +0300
Subject: [PATCH 49/51] Changed html name files
---
lms/lmsdb/bootstrap.py | 2 +-
.../translations/en/LC_MESSAGES/messages.po | 28 +++++++++----------
lms/lmsweb/views.py | 6 ++--
...angepassword.html => change-password.html} | 1 -
...verpassword.html => recover-password.html} | 1 -
...resetpassword.html => reset-password.html} | 0
tests/test_users.py | 8 +++---
7 files changed, 22 insertions(+), 24 deletions(-)
rename lms/templates/{changepassword.html => change-password.html} (90%)
rename lms/templates/{recoverpassword.html => recover-password.html} (90%)
rename lms/templates/{resetpassword.html => reset-password.html} (100%)
diff --git a/lms/lmsdb/bootstrap.py b/lms/lmsdb/bootstrap.py
index 7688c890..28f52a78 100644
--- a/lms/lmsdb/bootstrap.py
+++ b/lms/lmsdb/bootstrap.py
@@ -228,7 +228,7 @@ def _add_api_keys_to_users_table(table: Model, _column: Field) -> None:
user.save()
-def _add_uuid_to_users_table(table: Model, _colum: Field) -> None:
+def _add_uuid_to_users_table(table: Model, _column: Field) -> None:
log.info('Adding UUIDs for all users, might take some extra time...')
with db_config.database.transaction():
for user in table:
diff --git a/lms/lmsweb/translations/en/LC_MESSAGES/messages.po b/lms/lmsweb/translations/en/LC_MESSAGES/messages.po
index 8e6aaa7e..81b6ee74 100644
--- a/lms/lmsweb/translations/en/LC_MESSAGES/messages.po
+++ b/lms/lmsweb/translations/en/LC_MESSAGES/messages.po
@@ -135,7 +135,7 @@ msgid "עליך לאשר את מייל האימות"
msgstr "You have to confirm your registration with the link sent to your email"
#: templates/banned.html:8 templates/login.html:7
-#: templates/recoverpassword.html:8 templates/resetpassword.html:8
+#: templates/recover-password.html:8 templates/reset-password.html:8
#: templates/signup.html:8
msgid "תמונת הפרופיל של קורס פייתון"
msgstr "Profile picture of the Python Course"
@@ -152,31 +152,31 @@ msgstr "For more details please contact the management team."
msgid "מערכת הגשת תרגילים לקורס פייתון"
msgstr "Exercise submission system for the Python Course"
-#: templates/changepassword.html:8
+#: templates/change-password.html:8
#, fuzzy
msgid "שינוי סיסמה"
msgstr "Change Password"
-#: templates/changepassword.html:10
+#: templates/change-password.html:10
#, fuzzy
msgid "הזינו סיסמה ישנה וסיסמה חדשה לצורך שינוי הסיסמה:"
msgstr "Insert current password and new password for changing it:"
-#: templates/changepassword.html:13
+#: templates/change-password.html:13
msgid "סיסמה נוכחית"
msgstr "Current password"
-#: templates/changepassword.html:14 templates/recoverpassword.html:14
+#: templates/change-password.html:14 templates/recover-password.html:14
#, fuzzy
msgid "סיסמה חדשה"
msgstr "Password"
-#: templates/changepassword.html:15 templates/recoverpassword.html:15
+#: templates/change-password.html:15 templates/recover-password.html:15
#, fuzzy
msgid "אימות סיסמה חדשה"
msgstr "Password Confirmation"
-#: templates/changepassword.html:18 templates/user.html:19
+#: templates/change-password.html:18 templates/user.html:19
#, fuzzy
msgid "שנה סיסמה"
msgstr "Change Password"
@@ -273,35 +273,35 @@ msgstr "Check Exercises"
msgid "התנתקות"
msgstr "Logout"
-#: templates/recoverpassword.html:9 templates/resetpassword.html:9
+#: templates/recover-password.html:9 templates/reset-password.html:9
#, fuzzy
msgid "איפוס סיסמה"
msgstr "Reset Password"
-#: templates/recoverpassword.html:11
+#: templates/recover-password.html:11
#, fuzzy
msgid "הזינו סיסמה לצורך שינוי הסיסמה:"
msgstr "Insert password for changing it:"
-#: templates/recoverpassword.html:18
+#: templates/recover-password.html:18
#, fuzzy
msgid "אפס סיסמה"
msgstr "Reset Password"
-#: templates/resetpassword.html:11
+#: templates/reset-password.html:11
#, fuzzy
msgid "הזינו אימייל לצורך שליחת קישור לאיפוס הסיסמה:"
msgstr "Insert your email for getting link to reset it:"
-#: templates/resetpassword.html:14 templates/signup.html:15
+#: templates/reset-password.html:14 templates/signup.html:15
msgid "כתובת אימייל"
msgstr "Email Address"
-#: templates/resetpassword.html:15
+#: templates/reset-password.html:15
msgid "שלח מייל איפוס סיסמה"
msgstr "Send Reset Password Link"
-#: templates/resetpassword.html:18 templates/signup.html:25
+#: templates/reset-password.html:18 templates/signup.html:25
msgid "חזרה לדף ההתחברות"
msgstr "Back to login page"
diff --git a/lms/lmsweb/views.py b/lms/lmsweb/views.py
index 791dcf7e..54213be7 100644
--- a/lms/lmsweb/views.py
+++ b/lms/lmsweb/views.py
@@ -191,7 +191,7 @@ def change_password():
form = ChangePasswordForm(user)
if not form.validate_on_submit():
- return render_template('changepassword.html', form=form)
+ return render_template('change-password.html', form=form)
user.password = form.password.data
user.save()
@@ -209,7 +209,7 @@ def change_password():
def reset_password():
form = ResetPassForm()
if not form.validate_on_submit():
- return render_template('resetpassword.html', form=form)
+ return render_template('reset-password.html', form=form)
user = User.get(User.mail_address == form.email.data)
@@ -250,7 +250,7 @@ def recover_password_check(user: User, token: str):
form = RecoverPassForm()
if not form.validate_on_submit():
return render_template(
- 'recoverpassword.html', form=form, id=user.id, token=token,
+ 'recover-password.html', form=form, id=user.id, token=token,
)
user.password = form.password.data
user.save()
diff --git a/lms/templates/changepassword.html b/lms/templates/change-password.html
similarity index 90%
rename from lms/templates/changepassword.html
rename to lms/templates/change-password.html
index e4734f47..61c5ef71 100644
--- a/lms/templates/changepassword.html
+++ b/lms/templates/change-password.html
@@ -14,7 +14,6 @@ {{ _('שינוי סיסמה')
{{ render_field(form.password, cls="form-control form-control-lg", placeholder=_('סיסמה חדשה')) }}
{{ render_field(form.confirm, cls="form-control form-control-lg", placeholder=_('אימות סיסמה חדשה')) }}
-
diff --git a/lms/templates/recoverpassword.html b/lms/templates/recover-password.html
similarity index 90%
rename from lms/templates/recoverpassword.html
rename to lms/templates/recover-password.html
index 791c6b0b..a805977c 100644
--- a/lms/templates/recoverpassword.html
+++ b/lms/templates/recover-password.html
@@ -14,7 +14,6 @@