13.2.71. camcops_server.cc_modules.cc_taskfactory

camcops_server/cc_modules/cc_taskfactory.py


Copyright (C) 2012-2019 Rudolf Cardinal (rudolf@pobox.com).

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 <http://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:
Returns:

the task, or None if the PK doesn’t exist

Raises:

HTTPBadRequest if the table doesn’t exist

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 if the table doesn’t exist

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:
Returns:

a filtered query (or the original query, if no filtering was required)