15.2.162. camcops_server.cc_modules.cc_taskfactory¶
camcops_server/cc_modules/cc_taskfactory.py
Copyright (C) 2012, University of Cambridge, Department of Psychiatry. Created by Rudolf Cardinal (rnc1001@cam.ac.uk).
This file is part of CamCOPS.
CamCOPS is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
CamCOPS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with CamCOPS. If not, see <https://www.gnu.org/licenses/>.
Functions to fetch tasks from the database.
- camcops_server.cc_modules.cc_taskfactory.task_factory(req: CamcopsRequest, basetable: str, serverpk: int) Optional[camcops_server.cc_modules.cc_task.Task] [source]¶
Load a task from the database and return it. Filters to tasks permitted to the current user.
- Parameters
req – the
camcops_server.cc_modules.cc_request.CamcopsRequest
basetable – name of the task’s base table
serverpk – server PK of the task
- Returns
the task, or
None
if the PK doesn’t exist- Raises
HTTPBadRequest –
- camcops_server.cc_modules.cc_taskfactory.task_factory_clientkeys_no_security_checks(dbsession: sqlalchemy.orm.session.Session, basetable: str, client_id: int, device_id: int, era: str) Optional[camcops_server.cc_modules.cc_task.Task] [source]¶
Load a task from the database and return it. Filters to tasks permitted to the current user.
- Parameters
dbsession – a
sqlalchemy.orm.session.Session
basetable – name of the task’s base table
client_id – task’s
_id
valuedevice_id – task’s
_device_id
valueera – task’s
_era
value
- Returns
the task, or
None
if it doesn’t exist- Raises
KeyError –
- camcops_server.cc_modules.cc_taskfactory.task_factory_no_security_checks(dbsession: sqlalchemy.orm.session.Session, basetable: str, serverpk: int) Optional[camcops_server.cc_modules.cc_task.Task] [source]¶
Load a task from the database and return it. Filters to tasks permitted to the current user.
- Parameters
dbsession – a
sqlalchemy.orm.session.Session
basetable – name of the task’s base table
serverpk – server PK of the task
- Returns
the task, or
None
if the PK doesn’t exist- Raises
KeyError –
- camcops_server.cc_modules.cc_taskfactory.task_query_restricted_to_permitted_users(req: CamcopsRequest, q: sqlalchemy.orm.query.Query, cls: Union[Type[camcops_server.cc_modules.cc_task.Task], Type[camcops_server.cc_modules.cc_taskindex.TaskIndexEntry]], as_dump: bool) Optional[sqlalchemy.orm.query.Query] [source]¶
Restricts an SQLAlchemy ORM query to permitted users, for a given task class. THIS IS A KEY SECURITY FUNCTION.
- Parameters
req – the
camcops_server.cc_modules.cc_request.CamcopsRequest
q – the SQLAlchemy ORM query
cls – the class of the task type, or the
camcops_server.cc_modules.cc_taskindex.TaskIndexEntry
classas_dump – use the “dump” permissions rather than the “view” permissions?
- Returns
a filtered query (or the original query, if no filtering was required)