Skip to content
Snippets Groups Projects
Commit 8a772ac0 authored by Ryan's avatar Ryan Committed by Megan Henning
Browse files

Resolve most pylint ERROR class issues

parent b6be0288
No related branches found
No related tags found
No related merge requests found
......@@ -292,7 +292,7 @@ def dispatcher(router, request, response):
if rv is not None:
response.write(json.dumps(rv, default=encoder.custom_json_serializer))
response.headers['Content-Type'] = 'application/json; charset=utf-8'
except webapp2.exc.HTTPException as e:
except webapp2.HTTPException as e:
util.send_json_http_exception(response, str(e), e.code)
except Exception as e:
if config.get_item('core', 'debug'):
......
......@@ -151,10 +151,15 @@ class CentralClient(base.RequestHandler):
self.abort(400, 'SSL cert not configured')
if not config.get_item('site', 'central_url'):
self.abort(400, 'Central URL not configured')
if not update(config.db, config.get_item('site', 'ssl_cert'), config.get_item('site', 'central_url')):
if not update(db=config.db,
api_uri=config.get_item('site', 'api_url'),
site_name=config.get_item('site', 'name'),
site_id=config.get_item('site', 'id'),
ssl_cert=config.get_item('site', 'ssl_cert'),
central_url=config.get_item('site', 'central_url'),):
fail_count += 1
else:
centralclient.fail_count = 0
if centralclient.fail_count == 3:
fail_count = 0
if fail_count == 3:
log.warning('scitran central unreachable, purging all remotes info')
clean_remotes(config.db)
clean_remotes(db=config.db, site_id=config.get_item('site', 'id'))
......@@ -144,7 +144,7 @@ class StringListStorage(ListStorage):
if payload is not None:
payload = payload.get('value')
if payload is None:
self.abort(400, 'Key "value" should be defined')
raise ValueError('payload Key "value" should be defined')
return super(StringListStorage, self).exec_op(action, _id, query_params, payload, exclude_params)
def _create_el(self, _id, payload, exclude_params):
......
......@@ -43,7 +43,7 @@ class CollectionsHandler(ContainerHandler):
if result.acknowledged:
return {'_id': result.inserted_id}
else:
self.abort(404, 'Element not added in collection {}'.format(_id))
self.abort(404, 'Element not added in collection {}'.format(self.uid))
def put(self, **kwargs):
_id = kwargs.pop('cid')
......@@ -66,7 +66,7 @@ class CollectionsHandler(ContainerHandler):
self._add_contents(contents, _id)
return {'modified': result.modified_count}
else:
self.abort(404, 'Element not updated in collection {} {}'.format(storage.cont_name, _id))
self.abort(404, 'Element not updated in collection {} {}'.format(self.storage.cont_name, _id))
def _add_contents(self, contents, _id):
if not contents:
......@@ -108,7 +108,7 @@ class CollectionsHandler(ContainerHandler):
query = {}
results = permchecker(self.storage.exec_op)('GET', query=query, public=self.public_request, projection=projection)
if results is None:
self.abort(404, 'Element not found in collection {} {}'.format(storage.cont_name, _id))
self.abort(404, 'Element not found in collection {}'.format(self.storage.cont_name))
self._filter_all_permissions(results, self.uid, self.user_site)
if self.is_true('counts'):
self._add_results_counts(results)
......@@ -198,5 +198,3 @@ class CollectionsHandler(ContainerHandler):
for acquisition in acquisitions:
acquisition = self.handle_origin(acquisition)
return acquisitions
......@@ -94,7 +94,7 @@ class ContainerHandler(base.RequestHandler):
except APIStorageException as e:
self.abort(400, e.message)
if result is None:
self.abort(404, 'Element not found in container {} {}'.format(storage.cont_name, _id))
self.abort(404, 'Element not found in container {} {}'.format(self.storage.cont_name, _id))
if not self.superuser_request:
self._filter_permissions(result, self.uid, self.user_site)
# build and insert file paths if they are requested
......@@ -254,7 +254,7 @@ class ContainerHandler(base.RequestHandler):
# this request executes the actual reqeust filtering containers based on the user permissions
results = permchecker(self.storage.exec_op)('GET', query=query, public=self.public_request, projection=projection)
if results is None:
self.abort(404, 'Element not found in container {} {}'.format(storage.cont_name, _id))
self.abort(404, 'Element not found in container {} {}'.format(self.storage.cont_name, _id))
# return only permissions of the current user
self._filter_all_permissions(results, self.uid, self.user_site)
# the "count" flag add a count for each container returned
......@@ -278,12 +278,12 @@ class ContainerHandler(base.RequestHandler):
result['permissions'] = [user_perm] if user_perm else []
return results
def _add_results_counts(self, results):
def _add_results_counts(self, results, cont_name):
dbc_name = self.config.get('children_cont')
el_cont_name = cont_name[:-1]
dbc = config.db.get(dbc_name)
counts = dbc.aggregate([
{'$match': {el_cont_name: {'$in': [res['_id'] for result in results]}}},
{'$match': {el_cont_name: {'$in': [res['_id'] for res in results]}}},
{'$group': {'_id': '$' + el_cont_name, 'count': {"$sum": 1}}}
])
counts = {elem['_id']: elem['count'] for elem in counts}
......@@ -320,7 +320,7 @@ class ContainerHandler(base.RequestHandler):
except APIStorageException as e:
self.abort(400, e.message)
if results is None:
self.abort(404, 'Element not found in container {} {}'.format(storage.cont_name, _id))
self.abort(404, 'Element not found in container {} {}'.format(self.storage.cont_name, uid))
self._filter_all_permissions(results, uid, user['site'])
if self.debug:
debuginfo.add_debuginfo(self, cont_name, results)
......@@ -364,7 +364,7 @@ class ContainerHandler(base.RequestHandler):
if result.acknowledged:
return {'_id': result.inserted_id}
else:
self.abort(404, 'Element not added in container {} {}'.format(storage.cont_name, _id))
self.abort(404, 'Element not added in container {} {}'.format(self.storage.cont_name, _id))
def put(self, cont_name, **kwargs):
_id = kwargs.pop('cid')
......@@ -423,7 +423,7 @@ class ContainerHandler(base.RequestHandler):
if result.modified_count == 1:
return {'modified': result.modified_count}
else:
self.abort(404, 'Element not updated in container {} {}'.format(storage.cont_name, _id))
self.abort(404, 'Element not updated in container {} {}'.format(self.storage.cont_name, _id))
def delete(self, cont_name, **kwargs):
_id = kwargs.pop('cid')
......@@ -441,7 +441,7 @@ class ContainerHandler(base.RequestHandler):
if result.deleted_count == 1:
return {'deleted': result.deleted_count}
else:
self.abort(404, 'Element not removed from container {} {}'.format(storage.cont_name, _id))
self.abort(404, 'Element not removed from container {} {}'.format(self.storage.cont_name, _id))
def get_groups_with_project(self):
"""
......
......@@ -93,7 +93,7 @@ class GroupHandler(base.RequestHandler):
self.response.status_int = 201
return {'_id': payload['_id']}
else:
self.abort(404, 'User {} not updated'.format(_id))
self.abort(404, 'Group {} not updated'.format(payload['_id']))
def _init_storage(self):
self.storage = containerstorage.GroupStorage('groups', use_object_id=False)
......
......@@ -238,6 +238,7 @@ class PermissionsListHandler(ListHandler):
"""
method to propagate permissions from a project to its sessions and acquisitions
"""
<<<<<<< 75b71f5b10aaa1fba79830084d057fb2aea50ab8
if cont_name == 'projects':
try:
oid = bson.ObjectId(_id)
......@@ -247,6 +248,19 @@ class PermissionsListHandler(ListHandler):
hierarchy.propagate_changes(cont_name, oid, {}, update)
except:
self.abort(500, 'permissions not propagated from project {} to sessions'.format(_id))
=======
try:
log.debug(_id)
oid = bson.ObjectId(_id)
update = {
'permissions': config.db.projects.find_one(oid)['permissions']
}
session_ids = [s['_id'] for s in config.db.sessions.find({'project': oid}, [])]
config.db.sessions.update_many({'project': oid}, {'$set': update})
config.db.acquisitions.update_many({'session': {'$in': session_ids}}, {'$set': update})
except Exception as e:
self.abort(500, 'permissions not propagated from project {} to sessions'.format(_id))
>>>>>>> Resolve most pylint ERROR class issues
class NotesListHandler(ListHandler):
......
......@@ -160,7 +160,7 @@ class UserHandler(base.RequestHandler):
if result.acknowledged:
return {'_id': result.inserted_id}
else:
self.abort(404, 'User {} not updated'.format(_id))
self.abort(404, 'User {} not updated'.format(payload['_id']))
def _init_storage(self):
self.storage = containerstorage.ContainerStorage('users', use_object_id=False)
......
......@@ -56,7 +56,7 @@ def mongo_sanitize_fields(d):
if isinstance(d, dict):
return {mongo_sanitize_fields(str(key)): value if isinstance(value, str) else mongo_sanitize_fields(value) for key,value in d.iteritems()}
elif isinstance(d, list):
return [mongo_sanitize_fields(element) for element in i]
return [mongo_sanitize_fields(element) for element in d]
elif isinstance(d, str):
# not allowing dots nor dollar signs in fieldnames
d = d.replace('.','_')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment