filr_rest: accept empty emails in share-folder (#74481)
gitea-wip/passerelle/pipeline/pr-main This commit looks good Details
gitea/passerelle/pipeline/head Something is wrong with the build of this commit Details

This commit is contained in:
Thomas NOËL 2023-02-14 12:31:28 +01:00
parent b29fa4998b
commit 00804299d9
3 changed files with 35 additions and 15 deletions

View File

@ -131,17 +131,20 @@ class Filr(BaseResource, HTTPResource):
def share_folder(self, request, post_data):
data = []
for email in post_data['emails']:
share_info = self._call(
'rest/folders/%s/shares' % post_data['folder_id'],
method='post',
params={'notify': 'true'},
json_data={
'days_to_expire': post_data['days_to_expire'],
'recipient': {'type': 'external_user', 'email': email},
'access': {'role': 'VIEWER'},
},
)
data.append(share_info)
if email and '@' in email:
share_info = self._call(
'rest/folders/%s/shares' % post_data['folder_id'],
method='post',
params={'notify': 'true'},
json_data={
'days_to_expire': post_data['days_to_expire'],
'recipient': {'type': 'external_user', 'email': email},
'access': {'role': 'VIEWER'},
},
)
data.append(share_info)
if not data:
raise APIError('no valid email in emails', http_status=400)
return {'data': data}
@endpoint(

View File

@ -70,8 +70,10 @@ SHARE_FOLDER = {
'type': 'array',
'description': _('Emails'),
'items': {
'type': 'string',
'format': 'email',
'oneOf': [
{'type': 'string'},
{'type': 'null'},
]
},
},
'days_to_expire': {'type': 'string', 'pattern': '^[0-9]+$'},

View File

@ -84,8 +84,11 @@ def test_upload_with_folder_creation(app, connector):
def test_share_folder(app, connector):
params = {
'folder_id': '1234',
'emails/0': 'foo@invalid',
'emails/1': 'bar@invalid',
'emails/0': 'foo@example.net',
'emails/1': '',
'emails/2': None,
'emails/3': 'not a mail',
'emails/4': 'bar@example.org',
'days_to_expire': '30',
}
with responses.RequestsMock() as rsps:
@ -95,6 +98,18 @@ def test_share_folder(app, connector):
assert json_resp['err'] == 0
assert json_resp['data'] == [{'id': 9}, {'id': 9}]
params = {
'folder_id': '1234',
'emails/0': '',
'emails/1': None,
'emails/2': 'not a mail',
'days_to_expire': '30',
}
with responses.RequestsMock():
resp = app.post_json('/filr-rest/filr/share-folder', params=params, status=400)
assert resp.json['err_desc'] == 'no valid email in emails'
assert resp.json['data'] is None
def test_delete_folder(app, connector):
params = {