Skip to content

Commit

Permalink
Merge pull request #1490 from waychal/fix_1390_cifs_release
Browse files Browse the repository at this point in the history
fix in custom schema (rest api)
  • Loading branch information
Snehal Kumbhar authored May 9, 2018
2 parents 659bd6b + 48a2d97 commit d3ebdf1
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 13 deletions.
14 changes: 11 additions & 3 deletions aiida/restapi/translator/computer.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,18 @@ class ComputerTranslator(BaseTranslator):

_result_type = __label__

_default_projections = None

# Extract the default projections from custom_schema if they are defined
if 'columns' in custom_schema:
_default_projections = custom_schema['columns'][__label__]
else:
if custom_schema is not None:
try:
# check if schema is defined for given node type
if __label__ in custom_schema['columns'].keys():
_default_projections = custom_schema['columns'][__label__]
except KeyError:
pass

if _default_projections is None:
_default_projections = ['**']

def __init__(self, **kwargs):
Expand Down
14 changes: 11 additions & 3 deletions aiida/restapi/translator/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,18 @@ class GroupTranslator(BaseTranslator):

_result_type = __label__

_default_projections = None

# Extract the default projections from custom_schema if they are defined
if 'columns' in custom_schema:
_default_projections = custom_schema['columns'][__label__]
else:
if custom_schema is not None:
try:
# check if schema is defined for given node type
if __label__ in custom_schema['columns'].keys():
_default_projections = custom_schema['columns'][__label__]
except KeyError:
pass

if _default_projections is None:
_default_projections = ['**']


Expand Down
15 changes: 11 additions & 4 deletions aiida/restapi/translator/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,18 @@ def __init__(self, Class=None, **kwargs):
# basic initialization
super(NodeTranslator, self).__init__(Class=Class, **kwargs)

self._default_projections = None

# Extract the default projections from custom_schema if they are defined
if self.custom_schema is not None and 'columns' in self.custom_schema:
self._default_projections = self.custom_schema['columns'][
self.__label__]
else:
if self.custom_schema is not None:
try:
# check if schema is defined for given node type
if self.__label__ in self.custom_schema['columns'].keys():
self._default_projections = self.custom_schema['columns'][self.__label__]
except KeyError:
pass

if self._default_projections is None:
self._default_projections = ['**']

# Inspect the subclasses of NodeTranslator, to avoid hard-coding
Expand Down
14 changes: 11 additions & 3 deletions aiida/restapi/translator/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,18 @@ class UserTranslator(BaseTranslator):

_result_type = __label__

_default_projections = None

# Extract the default projections from custom_schema if they are defined
if 'columns' in custom_schema:
_default_projections = custom_schema['columns'][__label__]
else:
if custom_schema is not None:
try:
# check if schema is defined for given node type
if __label__ in custom_schema['columns'].keys():
_default_projections = custom_schema['columns'][__label__]
except KeyError:
pass

if _default_projections is None:
# send only white listed keys in default response for user for security reasons
_default_projections = ['id', 'first_name', "last_name", 'institution', 'date_joined']

Expand Down

0 comments on commit d3ebdf1

Please sign in to comment.