Skip to content
This repository was archived by the owner on Apr 25, 2022. It is now read-only.

Commit 19e32f0

Browse files
jameswestmandanielsilverstone-ct
authored andcommitted
models: Fix error when deleting account
Fixes #149.
1 parent 62410e7 commit 19e32f0

File tree

1 file changed

+25
-18
lines changed

1 file changed

+25
-18
lines changed

app/models.py

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -83,24 +83,29 @@ def delete_hash(hasher: utils.Hasher, db, user):
8383
"""
8484
Add a user's information from Github to the hasher for token generation
8585
"""
86-
account = GithubAccount.by_user(db, user)
87-
hasher.add_number(account.github_userid)
88-
hasher.add_string(account.login)
89-
repos = [repo.reponame for repo in GithubRepository.all_by_account(db, account)]
90-
repos.sort()
91-
for repo in repos:
92-
hasher.add_string(repo)
86+
if account := GithubAccount.by_user(db, user):
87+
hasher.add_string("github")
88+
hasher.add_number(account.github_userid)
89+
hasher.add_string(account.login)
90+
repos = [
91+
repo.reponame for repo in GithubRepository.all_by_account(db, account)
92+
]
93+
repos.sort()
94+
for repo in repos:
95+
hasher.add_string(repo)
9396

9497
@staticmethod
9598
def delete_user(db, user):
9699
"""
97100
Delete a user's account and information related to Github
98101
"""
99-
gha = GithubAccount.by_user(db, user)
100-
db.session.execute(
101-
delete(GithubRepository).where(GithubRepository.github_account == gha.id)
102-
)
103-
db.session.delete(gha)
102+
if gha := GithubAccount.by_user(db, user):
103+
db.session.execute(
104+
delete(GithubRepository).where(
105+
GithubRepository.github_account == gha.id
106+
)
107+
)
108+
db.session.delete(gha)
104109

105110

106111
FlathubUser.TABLES_FOR_DELETE.append(GithubAccount)
@@ -208,9 +213,10 @@ def delete_hash(hasher: utils.Hasher, db, user):
208213
"""
209214
Add a user's information from Gitlab to the hasher for token generation
210215
"""
211-
account = GitlabAccount.by_user(db, user)
212-
hasher.add_number(account.gitlab_userid)
213-
hasher.add_string(account.login)
216+
if account := GitlabAccount.by_user(db, user):
217+
hasher.add_string("gitlab")
218+
hasher.add_number(account.gitlab_userid)
219+
hasher.add_string(account.login)
214220

215221
@staticmethod
216222
def delete_user(db, user):
@@ -271,9 +277,10 @@ def delete_hash(hasher: utils.Hasher, db, user):
271277
"""
272278
Add a user's information from Google to the hasher for token generation
273279
"""
274-
account = GoogleAccount.by_user(db, user)
275-
hasher.add_string(account.google_userid)
276-
hasher.add_string(account.login)
280+
if account := GoogleAccount.by_user(db, user):
281+
hasher.add_string("google")
282+
hasher.add_string(account.google_userid)
283+
hasher.add_string(account.login)
277284

278285
@staticmethod
279286
def delete_user(db, user):

0 commit comments

Comments
 (0)