Coverage for cc_modules/cc_ipuse.py: 93%
29 statements
« prev ^ index » next coverage.py v7.9.2, created at 2025-07-15 14:23 +0100
« prev ^ index » next coverage.py v7.9.2, created at 2025-07-15 14:23 +0100
1"""
2camcops_server/cc_modules/cc_ipuse.py
4===============================================================================
6 Copyright (C) 2012, University of Cambridge, Department of Psychiatry.
7 Created by Rudolf Cardinal (rnc1001@cam.ac.uk).
9 This file is part of CamCOPS.
11 CamCOPS is free software: you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation, either version 3 of the License, or
14 (at your option) any later version.
16 CamCOPS is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with CamCOPS. If not, see <https://www.gnu.org/licenses/>.
24===============================================================================
26IP Use flags that determine the contexts in which CamCOPS is to be used (and
27hence the tasks that will be permitted).
29"""
31from typing import Any
33from cardinal_pythonlib.reprfunc import auto_repr, auto_str
34from sqlalchemy.orm import Mapped, mapped_column
36from camcops_server.cc_modules.cc_sqlalchemy import Base
39_DEFAULT_APPLICABILITY = False
42class IpContexts(object):
43 """
44 String constants, used as form parameter names etc.
45 """
47 CLINICAL = "clinical"
48 COMMERCIAL = "commercial"
49 EDUCATIONAL = "educational"
50 RESEARCH = "research"
53class IpUse(Base):
54 __tablename__ = "_security_ip_use"
56 CONTEXTS = (
57 IpContexts.CLINICAL,
58 IpContexts.COMMERCIAL,
59 IpContexts.EDUCATIONAL,
60 IpContexts.RESEARCH,
61 )
62 _DEFAULT = False
64 id: Mapped[int] = mapped_column(
65 primary_key=True,
66 autoincrement=True,
67 index=True,
68 comment="IP Use ID",
69 )
71 clinical: Mapped[bool] = mapped_column(
72 default=_DEFAULT,
73 comment="Applicable to a clinical context",
74 )
75 commercial: Mapped[bool] = mapped_column(
76 default=_DEFAULT,
77 comment="Applicable to a commercial context",
78 )
79 educational: Mapped[bool] = mapped_column(
80 default=_DEFAULT,
81 comment="Applicable to an educational context",
82 )
83 research: Mapped[bool] = mapped_column(
84 default=_DEFAULT,
85 comment="Applicable to a research context",
86 )
88 def __init__(
89 self,
90 clinical: bool = _DEFAULT_APPLICABILITY,
91 commercial: bool = _DEFAULT_APPLICABILITY,
92 educational: bool = _DEFAULT_APPLICABILITY,
93 research: bool = _DEFAULT_APPLICABILITY,
94 **kwargs: Any
95 ) -> None:
96 """
97 We provide __init__() so we can create a default object without
98 touching the database.
99 """
100 super().__init__(**kwargs)
101 self.clinical = clinical
102 self.commercial = commercial
103 self.educational = educational
104 self.research = research
106 def __repr__(self) -> str:
107 return auto_repr(self)
109 def __str__(self) -> str:
110 return auto_str(self)