MCPcopy Create free account
hub / github.com/alephdata/aleph / create

Method create

aleph/model/collection.py:237–262  ·  view source on GitHub ↗
(cls, data, authz, created_at=None)

Source from the content-addressed store, hash-verified

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)>"

Callers

nothing calls this directly

Calls 6

make_textidFunction · 0.90
getMethod · 0.45
by_foreign_idMethod · 0.45
updateMethod · 0.45
flushMethod · 0.45
grantMethod · 0.45

Tested by

no test coverage detected