Skip to content

Commit

Permalink
add delete upload links api
Browse files Browse the repository at this point in the history
  • Loading branch information
imwhatiam committed Sep 3, 2024
1 parent 38c5efe commit 4df5079
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
1 change: 1 addition & 0 deletions seahub/api2/endpoints/repo_share_links.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def get_share_link_info(fileshare):
data['link'] = gen_shared_link(token, fileshare.s_type)
data['ctime'] = ctime
data['expire_date'] = expire_date
data['view_cnt'] = fileshare.view_cnt

return data

Expand Down
52 changes: 52 additions & 0 deletions seahub/api2/endpoints/repo_upload_links.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

logger = logging.getLogger(__name__)


def get_upload_link_info(upload_link):

data = {}
Expand Down Expand Up @@ -55,6 +56,7 @@ def get_upload_link_info(upload_link):
data['link'] = gen_shared_upload_link(token)
data['ctime'] = ctime
data['expire_date'] = expire_date
data['view_cnt'] = upload_link.view_cnt

return data

Expand Down Expand Up @@ -96,6 +98,56 @@ def get(self, request, repo_id):

return Response(result)

def delete(self, request, repo_id):
""" Delete upload links.
Permission checking:
1. default(NOT guest) user;
2. link owner;
"""

token_list = request.data.get('tokens')
if not token_list:
error_msg = 'token invalid.'
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)

result = {}
result['failed'] = []
result['success'] = []

username = request.user.username
for token in token_list:

try:
upload_link = UploadLinkShare.objects.get(token=token)
except UploadLinkShare.DoesNotExist:
result['success'].append({
'token': token,
})
continue

if not upload_link.is_owner(username):
result['failed'].append({
'token': token,
'error_msg': 'Permission denied.'
})
continue

try:
upload_link.delete()
result['success'].append({
'token': token,
})
except Exception as e:
logger.error(e)
result['failed'].append({
'token': token,
'error_msg': 'Internal Server Error'
})
continue

return Response(result)


class RepoUploadLink(APIView):

Expand Down

0 comments on commit 4df5079

Please sign in to comment.