(cls, data, authz, created_at=None)
| 235 | |
| 236 | @classmethod |
| 237 | def create(cls, data, authz, created_at=None): |
| 238 | foreign_id = data.get("foreign_id") or make_textid() |
| 239 | collection = cls.by_foreign_id(foreign_id, deleted=True) |
| 240 | |
| 241 | # A collection with the given foreign ID already exists |
| 242 | if collection and not collection.deleted_at: |
| 243 | raise ValueError("Invalid foreign_id") |
| 244 | |
| 245 | # A deleted collection with the foreign ID already exists, but the deleted |
| 246 | # collection was created by a different role |
| 247 | if collection and collection.creator_id != authz.role.id: |
| 248 | raise ValueError("Invalid foreign_id") |
| 249 | |
| 250 | if collection is None: |
| 251 | collection = cls() |
| 252 | collection.created_at = created_at |
| 253 | collection.foreign_id = foreign_id |
| 254 | collection.category = cls.CASEFILE |
| 255 | collection.creator = authz.role |
| 256 | collection.deleted_at = None |
| 257 | collection.data_updated_at = None |
| 258 | collection.update(data, authz) |
| 259 | db.session.flush() |
| 260 | if collection.creator is not None: |
| 261 | Permission.grant(collection, collection.creator, True, True) |
| 262 | return collection |
| 263 | |
| 264 | def __repr__(self): |
| 265 | fmt = "<Collection(%r, %r, %r)>" |
nothing calls this directly
no test coverage detected