Skip to content

Commit

Permalink
[Codebase improvement] Reuse handlers base require_fields (#3577)
Browse files Browse the repository at this point in the history
  • Loading branch information
Feeeenng authored and kravets-levko committed Mar 15, 2019
1 parent 852636f commit a8cb709
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 10 deletions.
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

0 comments on commit a8cb709

Please sign in to comment.