Skip to content

Commit

Permalink
Add missing permissions to varimport (apache#17468)
Browse files Browse the repository at this point in the history
(cherry picked from commit eb6af07)
(cherry picked from commit 2bbaec8)
  • Loading branch information
ashb authored and jedcunningham committed Sep 1, 2021
1 parent 0e0993b commit b1d28ec
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion airflow/www/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3104,7 +3104,6 @@ class VariableModelView(AirflowModelView):
'delete': 'delete',
'action_muldelete': 'delete',
'action_varexport': 'read',
'varimport': 'create',
}
base_permissions = [
permissions.ACTION_CAN_CREATE,
Expand Down Expand Up @@ -3167,6 +3166,7 @@ def action_varexport(self, items):
return response

@expose('/varimport', methods=["POST"])
@auth.has_access([(permissions.ACTION_CAN_CREATE, permissions.RESOURCE_VARIABLE)])
@action_logging
def varimport(self):
"""Import variables"""
Expand Down
13 changes: 13 additions & 0 deletions tests/www/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,19 @@ def test_import_variables_success(self):
)
self.check_content_in_response('4 variable(s) successfully updated.', resp)

def test_import_variables_anon(self):
assert self.session.query(models.Variable).count() == 0

content = '{"str_key": "str_value}'
bytes_content = io.BytesIO(bytes(content, encoding='utf-8'))

self.logout()
resp = self.client.post(
'/variable/varimport', data={'file': (bytes_content, 'test.json')}, follow_redirects=True
)
self.check_content_not_in_response('variable(s) successfully updated.', resp)
self.check_content_in_response('Sign In', resp)


class PluginOperator(BaseOperator):
pass
Expand Down

0 comments on commit b1d28ec

Please sign in to comment.