(20241211) Figuring out the inherited permissions system. Stuck at directory management with permissions handling.
This commit is contained in:
@@ -126,6 +126,16 @@ class CoreFileObjectSharingModel(BaseModel):
|
||||
frozen = True
|
||||
)
|
||||
|
||||
permissionType: Literal["explicit", "inherited"] = Field(
|
||||
description = "to know whether the permission was inherited from a parent dir, or explicitly granted",
|
||||
frozen = True
|
||||
)
|
||||
|
||||
inheritedFromId: ObjectId | None = Field(
|
||||
description = "when some permission was inherited, this tells you the id of the parent",
|
||||
frozen = True
|
||||
)
|
||||
|
||||
permissions: CoreFileObjectPermissionsModel = Field(
|
||||
description = "the permissions that the above mentioned user has to this file",
|
||||
frozen = True
|
||||
@@ -140,6 +150,18 @@ class CoreFileObjectSharingModel(BaseModel):
|
||||
extra = "allow"
|
||||
arbitrary_types_allowed = True
|
||||
|
||||
# ┓┏ ┓• ┓ •
|
||||
# ┃┃┏┓┃┓┏┫┏┓╋┓┏┓┏┓
|
||||
# ┗┛┗┻┗┗┗┻┗┻┗┗┗┛┛┗
|
||||
|
||||
@field_validator("inheritedFromId", mode = "before")
|
||||
def parse_oid(cls, value):
|
||||
try:
|
||||
if isinstance(value, str):
|
||||
value = ObjectId(value)
|
||||
except: pass
|
||||
return value
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
@@ -148,7 +170,7 @@ class CoreFileObjectInfoModel(BaseModel):
|
||||
|
||||
fileObjectId: ObjectId = Field(
|
||||
description = "the id of the document in mongodb that holds this information",
|
||||
frozen = True,
|
||||
frozen = False,
|
||||
default = None,
|
||||
alias = "_id"
|
||||
)
|
||||
@@ -187,7 +209,7 @@ class CoreFileObjectInfoModel(BaseModel):
|
||||
)
|
||||
|
||||
metadata: Dict[str, Any] = Field(
|
||||
description = "any addition data about this file/dir to filter it later",
|
||||
description = "any additional data about this file/dir to filter it later",
|
||||
frozen = False,
|
||||
default = {}
|
||||
)
|
||||
@@ -235,9 +257,21 @@ class CoreFileObjectInfoModel(BaseModel):
|
||||
def parse_date_time(cls, value):
|
||||
return date_time.parse_date_time(input_value = value, timezone = date_time.TIMEZONE_UTC)
|
||||
|
||||
@field_validator("metadata", mode = "before")
|
||||
def validate_metadata(cls, value):
|
||||
if value is None: value = {}
|
||||
return value
|
||||
|
||||
@field_validator("tags", mode = "before")
|
||||
def validate_tags(cls, value):
|
||||
if value is None: value = []
|
||||
return value
|
||||
|
||||
@field_validator("fileObjectId", "parentId", mode = "before")
|
||||
def parse_oid(cls, value):
|
||||
try: value = ObjectId(value)
|
||||
try:
|
||||
if isinstance(value, str):
|
||||
value = ObjectId(value)
|
||||
except: pass
|
||||
return value
|
||||
|
||||
@@ -249,7 +283,7 @@ class CoreFileObjectInfoModel(BaseModel):
|
||||
@property
|
||||
def summary(self):
|
||||
return {
|
||||
"user": self.user,
|
||||
"user": self.user.model_dump(),
|
||||
"isDir": self.isDir,
|
||||
"name": self.name,
|
||||
"createTs": self.createTs,
|
||||
@@ -258,6 +292,45 @@ class CoreFileObjectInfoModel(BaseModel):
|
||||
}
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
class CoreFileObjectAccessResponseModel(BaseModel):
|
||||
|
||||
success: bool = Field(
|
||||
description = "whether, or not, the operation was successful",
|
||||
frozen = False,
|
||||
default = False
|
||||
)
|
||||
|
||||
message: str | None = Field(
|
||||
description = "useful to note the reason in case of an unsuccessful operation",
|
||||
frozen = False,
|
||||
default = "message not documented"
|
||||
)
|
||||
|
||||
result: Any = Field(
|
||||
description = "the result of the operation",
|
||||
frozen = False,
|
||||
default = None
|
||||
)
|
||||
|
||||
exception: Exception | None = Field(
|
||||
description = "to document any exceptions that came up",
|
||||
frozen = False,
|
||||
default = None
|
||||
)
|
||||
|
||||
# ┏┓ ┏•
|
||||
# ┃ ┏┓┏┓╋┓┏┓
|
||||
# ┗┛┗┛┛┗┛┗┗┫
|
||||
# ┛
|
||||
|
||||
class Config:
|
||||
extra = "allow"
|
||||
arbitrary_types_allowed = True
|
||||
|
||||
|
||||
# *****************************************************************************************************************
|
||||
# ***** ****
|
||||
# *** MAIN PROGRAM ***
|
||||
@@ -270,7 +343,7 @@ if __name__ == "__main__":
|
||||
from utils_v2.string import json
|
||||
|
||||
file_info = CoreFileObjectInfoModel(
|
||||
# _id = "67519cf3a7804fcbc6f12452",
|
||||
_id = "67519cf3a7804fcbc6f12452",
|
||||
user = CoreUserInfoModel(
|
||||
fullName = "Bhopli Narangi",
|
||||
userId = 1,
|
||||
@@ -278,9 +351,10 @@ if __name__ == "__main__":
|
||||
billingAccountId = 3,
|
||||
departmentId = 4,
|
||||
branchId = 5,
|
||||
industry = "fashion"
|
||||
industry = "technology"
|
||||
),
|
||||
name = "Midnight-Snack.png",
|
||||
isDir = False,
|
||||
name = "Graduation Certificate.png",
|
||||
createTs = date_time.get_current_utc_date_time(as_string = False),
|
||||
length = 1024,
|
||||
hash = "abcdefgh12345678",
|
||||
@@ -288,11 +362,10 @@ if __name__ == "__main__":
|
||||
"camera": "iPhone 1000 Pro Max XS"
|
||||
},
|
||||
tags = [
|
||||
"image",
|
||||
"cute",
|
||||
"cat"
|
||||
"important"
|
||||
],
|
||||
parentId = "67519cf3a7804fcbc6f12452",
|
||||
# parentId = "67519cf3a7804fcbc6f12452",
|
||||
parentId = None,
|
||||
isPrivate = True,
|
||||
sharedWith = [
|
||||
CoreFileObjectSharingModel(
|
||||
@@ -305,6 +378,8 @@ if __name__ == "__main__":
|
||||
branchId = 10,
|
||||
industry = "entertainment"
|
||||
),
|
||||
permissionType = "explicit",
|
||||
inheritedFromId = None,
|
||||
permissions = CoreFileObjectPermissionsModel(
|
||||
read = True,
|
||||
write = False,
|
||||
|
||||
@@ -161,6 +161,12 @@ class CoreMessageModel(BaseModel):
|
||||
frozen = True
|
||||
)
|
||||
|
||||
usedAi: bool | None = Field(
|
||||
description = "to mark when a sent message was generated by ai; null means the status is not known",
|
||||
frozen = True,
|
||||
default = None
|
||||
)
|
||||
|
||||
# ┏┓ ┏•
|
||||
# ┃ ┏┓┏┓╋┓┏┓
|
||||
# ┗┛┗┛┛┗┛┗┗┫
|
||||
@@ -183,7 +189,9 @@ class CoreMessageModel(BaseModel):
|
||||
|
||||
@field_validator("tokenId", mode = "before")
|
||||
def parse_oid(cls, value):
|
||||
try: value = ObjectId(value)
|
||||
try:
|
||||
if isinstance(value, str):
|
||||
value = ObjectId(value)
|
||||
except: pass
|
||||
return value
|
||||
|
||||
|
||||
@@ -209,7 +209,9 @@ class CorePaymentModel(BaseModel):
|
||||
|
||||
@field_validator("tokenId", mode = "before")
|
||||
def parse_oid(cls, value):
|
||||
try: value = ObjectId(value)
|
||||
try:
|
||||
if isinstance(value, str):
|
||||
value = ObjectId(value)
|
||||
except: pass
|
||||
return value
|
||||
|
||||
|
||||
Reference in New Issue
Block a user