1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-04-28 03:10:45 +00:00
This commit is contained in:
r350178982 2024-10-22 16:29:47 +08:00
parent adb355e743
commit 0b8a77d153
2 changed files with 13 additions and 2 deletions

View File

@ -100,6 +100,7 @@ class Command(BaseCommand):
try:
seafile_db_api.update_repo_user_shares(repo_id, new_owner, org_id)
seafile_db_api.update_repo_group_shares(repo_id, new_owner, org_id)
seafile_db_api.delete_repo_user_token(repo_id, repo_owner)
UploadLinkShare.objects.filter(repo_id=repo_id).update(username=new_owner)
FileShare.objects.filter(repo_id=repo_id).update(username=new_owner)

View File

@ -374,13 +374,15 @@ class SeafileDB:
def set_repo_owner(self, repo_id, new_owner, org_id=None):
# transfert repo to user
repo_ids = self.get_repo_ids_in_repo(repo_id)
repo_ids_str = ','.join(["'%s'" % str(rid) for rid in repo_ids])
if org_id:
sql = f"""
UPDATE `{self.db_name}`.`OrgRepo` SET user="{new_owner}" WHERE org_id ={org_id} AND repo_id="{repo_id}"
UPDATE `{self.db_name}`.`OrgRepo` SET user="{new_owner}" WHERE org_id ={org_id} AND repo_id IN ({repo_ids_str})
"""
else:
sql = f"""
UPDATE `{self.db_name}`.`RepoOwner` SET owner_id="{new_owner}" WHERE repo_id="{repo_id}"
UPDATE `{self.db_name}`.`RepoOwner` SET owner_id="{new_owner}" WHERE repo_id IN ({repo_ids_str})
"""
with connection.cursor() as cursor:
cursor.execute(sql)
@ -430,3 +432,11 @@ class SeafileDB:
"""
with connection.cursor() as cursor:
cursor.execute(sql)
def delete_repo_user_token(self, repo_id, owner):
sql = f"""
DELETE FROM `{self.db_name}`.`RepoUserToken` where repo_id="{repo_id}" AND email="{owner}"
"""
with connection.cursor() as cursor:
cursor.execute(sql)