Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reuse handlers base require_fields #3577

Merged
merged 5 commits into from
Mar 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions redash/handlers/data_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from sqlalchemy.exc import IntegrityError

from redash import models
from redash.handlers.base import BaseResource, get_object_or_404
from redash.handlers.base import BaseResource, get_object_or_404, require_fields
from redash.permissions import (require_access, require_admin,
require_permission, view_only)
from redash.query_runner import (get_configuration_schema_for_query_runner_type,
Expand Down Expand Up @@ -107,10 +107,7 @@ def get(self):
@require_admin
def post(self):
req = request.get_json(True)
required_fields = ('options', 'name', 'type')
for f in required_fields:
if f not in req:
abort(400)
require_fields(req, ('options', 'name', 'type'))

schema = get_configuration_schema_for_query_runner_type(req['type'])
if schema is None:
Expand Down
7 changes: 2 additions & 5 deletions redash/handlers/destinations.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from redash import models
from redash.destinations import (destinations,
get_configuration_schema_for_destination_type)
from redash.handlers.base import BaseResource
from redash.handlers.base import BaseResource, require_fields
from redash.permissions import require_admin
from redash.utils.configuration import ConfigurationContainer, ValidationError

Expand Down Expand Up @@ -86,10 +86,7 @@ def get(self):
@require_admin
def post(self):
req = request.get_json(True)
required_fields = ('options', 'name', 'type')
for f in required_fields:
if f not in req:
abort(400)
require_fields(req, ('options', 'name', 'type'))

schema = get_configuration_schema_for_destination_type(req['type'])
if schema is None:
Expand Down