Skip to content

Commit

Permalink
refactor: remove models __delattr__ methods
Browse files Browse the repository at this point in the history
  • Loading branch information
azmeuk committed Nov 21, 2023
1 parent 8b3802d commit 3a39fc1
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 24 deletions.
7 changes: 0 additions & 7 deletions canaille/backends/ldap/ldapobject.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,6 @@ def __setattr__(self, name, value):
ldap_name = self.python_attribute_to_ldap(name)
self.set_ldap_attribute(ldap_name, value)

def __delattr__(self, name):
ldap_name = self.python_attribute_to_ldap(name)
self.delete_ldap_attribute(ldap_name)

def has_ldap_attribute(self, name):
return name in self.ldap_object_attributes() and (
name in self.changes or name in self.state
Expand Down Expand Up @@ -213,9 +209,6 @@ def set_ldap_attribute(self, name, value):
value = listify(value)
self.changes[name] = value

def delete_ldap_attribute(self, name):
self.changes[name] = [None]

@property
def rdn_value(self):
value = self.get_ldap_attribute(self.rdn_attribute)
Expand Down
11 changes: 0 additions & 11 deletions canaille/backends/memory/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,17 +208,6 @@ def __setattr__(self, name, value):
else:
super().__setattr__(name, value)

def __delattr__(self, name):
try:
del self.state[name]
except KeyError:
pass

try:
del self.cache[name]
except KeyError:
pass

@property
def identifier(self):
return getattr(self, self.identifier_attribute)
Expand Down
6 changes: 3 additions & 3 deletions canaille/core/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ def profile_create(current_app, form):
setattr(user, attribute.name, data)

if "photo" in form and form["photo_delete"].data:
del user.photo
user.photo = None

given_name = user.given_name if user.given_name else ""
family_name = user.family_name if user.family_name else ""
Expand Down Expand Up @@ -522,7 +522,7 @@ def profile_edition_main_form_validation(user, edited_user, profile_form):
setattr(edited_user, attribute.name, data)

if "photo" in profile_form and profile_form["photo_delete"].data:
del edited_user.photo
edited_user.photo = None

if "preferred_language" in request.form:
# Refresh the babel cache in case the lang is updated
Expand Down Expand Up @@ -731,7 +731,7 @@ def profile_settings(user, edited_user):
and edited_user.locked
):
flash(_("The account has been unlocked"), "success")
del edited_user.lock_date
edited_user.lock_date = None
edited_user.save()

return profile_settings_edit(user, edited_user)
Expand Down
6 changes: 3 additions & 3 deletions tests/core/test_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def test_user_password_deleted_during_login(testclient, backend):
res = res.form.submit().follow()
res.form["password"] = "correct horse battery staple"

del u.password
u.password = None
u.save()

res = res.form.submit(status=302)
Expand Down Expand Up @@ -362,7 +362,7 @@ def test_account_locking(user, backend):
"Your account has been locked.",
)

del user.lock_date
user.lock_date = None
user.save()
assert not user.locked
assert not models.User.get(id=user.id).locked
Expand Down Expand Up @@ -416,7 +416,7 @@ def test_signin_locked_account(testclient, user):
res = res.form.submit()
res.mustcontain("Your account has been locked.")

del user.lock_date
user.lock_date = None
user.save()


Expand Down

0 comments on commit 3a39fc1

Please sign in to comment.