(20241211) Started more work on the files part and added validation to the phone no. in the API exposed for Nimbus.
This commit is contained in:
@@ -82,11 +82,11 @@ import datetime
|
||||
|
||||
class CoreAuthTokenModel(BaseModel):
|
||||
|
||||
version: str = Field(
|
||||
description = "a hint about the version no. of this message",
|
||||
min_length = 1,
|
||||
authTokenId: ObjectId = Field(
|
||||
description = "the id of the document in mongodb that holds this information",
|
||||
frozen = True,
|
||||
default = "2.0.0"
|
||||
default = None,
|
||||
alias = "_id"
|
||||
)
|
||||
|
||||
serviceType: Literal["email", "sms", "chat"] = Field(
|
||||
@@ -176,6 +176,9 @@ class CoreAuthTokenModel(BaseModel):
|
||||
extra = "allow"
|
||||
arbitrary_types_allowed = True
|
||||
|
||||
def model_dump(self, *args, **kwargs):
|
||||
return super().model_dump(*args, by_alias = True, **kwargs)
|
||||
|
||||
# ┓┏ ┓• ┓ •
|
||||
# ┃┃┏┓┃┓┏┫┏┓╋┓┏┓┏┓
|
||||
# ┗┛┗┻┗┗┗┻┗┻┗┗┗┛┛┗
|
||||
|
||||
@@ -80,22 +80,28 @@ import datetime
|
||||
# *****************************************************************************************************************
|
||||
|
||||
|
||||
class CoreFilePermissionsModel(BaseModel):
|
||||
class CoreFileObjectPermissionsModel(BaseModel):
|
||||
|
||||
read: bool = Field(
|
||||
description = "grants permissions to read/view this file",
|
||||
description = "grants permissions to read/view this file/dir",
|
||||
frozen = True,
|
||||
default = True
|
||||
)
|
||||
|
||||
write: bool = Field(
|
||||
description = "grants permissions to write new files this dir; irrelevant for files",
|
||||
frozen = True,
|
||||
default = False
|
||||
)
|
||||
|
||||
delete: bool = Field(
|
||||
description = "grants permissions to delete this file entirely",
|
||||
description = "grants permissions to delete this file/dir entirely",
|
||||
frozen = True,
|
||||
default = False
|
||||
)
|
||||
|
||||
changePermissions: bool = Field(
|
||||
description = "grants permissions to modify the permissions of this file",
|
||||
description = "grants permissions to modify the permissions of this file/dir",
|
||||
frozen = True,
|
||||
default = False
|
||||
)
|
||||
@@ -113,14 +119,14 @@ class CoreFilePermissionsModel(BaseModel):
|
||||
# ---------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
class CoreFileSharingModel(BaseModel):
|
||||
class CoreFileObjectSharingModel(BaseModel):
|
||||
|
||||
user: CoreUserInfoModel = Field(
|
||||
description = "to identify the user who has access to this file",
|
||||
frozen = True
|
||||
)
|
||||
|
||||
permissions: CoreFilePermissionsModel = Field(
|
||||
permissions: CoreFileObjectPermissionsModel = Field(
|
||||
description = "the permissions that the above mentioned user has to this file",
|
||||
frozen = True
|
||||
)
|
||||
@@ -138,66 +144,73 @@ class CoreFileSharingModel(BaseModel):
|
||||
# ---------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
class CoreFileInfoModel(BaseModel):
|
||||
class CoreFileObjectInfoModel(BaseModel):
|
||||
|
||||
version: str = Field(
|
||||
description = "a hint about the version no. of this message",
|
||||
min_length = 1,
|
||||
fileObjectId: ObjectId = Field(
|
||||
description = "the id of the document in mongodb that holds this information",
|
||||
frozen = True,
|
||||
default = "2.0.0"
|
||||
default = None,
|
||||
alias = "_id"
|
||||
)
|
||||
|
||||
user: CoreUserInfoModel = Field(
|
||||
description = "to identify the user who owns this file",
|
||||
description = "to identify the user who owns this file/dir",
|
||||
frozen = True
|
||||
)
|
||||
|
||||
filename: str = Field(
|
||||
description = "the name of this file",
|
||||
frozen = True
|
||||
)
|
||||
|
||||
uploadTs: AwareDatetime = Field(
|
||||
description = "the time (utc) at which this message was sent by the sender",
|
||||
frozen = True
|
||||
)
|
||||
|
||||
length: int = Field(
|
||||
description = "to note when the user has marked this message as unread",
|
||||
frozen = False,
|
||||
isDir: bool = Field(
|
||||
description = "to know whether this object is s file or a directory",
|
||||
frozen = True,
|
||||
default = False
|
||||
)
|
||||
|
||||
hash: str = Field(
|
||||
description = "a simple hash to verify the integrity of the uploaded data",
|
||||
name: str = Field(
|
||||
description = "the name of this file/dir",
|
||||
frozen = True
|
||||
)
|
||||
|
||||
createTs: AwareDatetime = Field(
|
||||
description = "the time (utc) at which this file/dir was created",
|
||||
frozen = True
|
||||
)
|
||||
|
||||
length: int | None = Field(
|
||||
description = "to note the size of the file; irrelevant for dirs",
|
||||
frozen = False,
|
||||
default = None
|
||||
)
|
||||
|
||||
hash: str | None = Field(
|
||||
description = "a simple hash to verify the integrity of the uploaded data; irrelevant for dirs",
|
||||
frozen = True,
|
||||
default = None
|
||||
)
|
||||
|
||||
metadata: Dict[str, Any] = Field(
|
||||
description = "any addition data about this file to filter it later",
|
||||
description = "any addition data about this file/dir to filter it later",
|
||||
frozen = False,
|
||||
default = {}
|
||||
)
|
||||
|
||||
tags: List[str] = Field(
|
||||
description = "a list of keywords to apply to this file to filter it later",
|
||||
description = "a list of keywords to apply to this file/dir to filter it later",
|
||||
frozen = False,
|
||||
default = [],
|
||||
examples = ["Bank Statement", "PDF", "bhopli@orange.com"]
|
||||
)
|
||||
|
||||
parentId: ObjectId | None = Field(
|
||||
description = "to identify the parent directory of this file; null means root directory",
|
||||
description = "to identify the parent dir of this file/dir; null means root dir",
|
||||
frozen = False
|
||||
)
|
||||
|
||||
isPrivate: bool = Field(
|
||||
description = "whether, or not, this file is a private file",
|
||||
description = "whether, or not, this file/dir is a private file",
|
||||
frozen = True
|
||||
)
|
||||
|
||||
sharedWith: List[CoreFileSharingModel] = Field(
|
||||
description = "sharing settings; specially relevant when the file is private",
|
||||
sharedWith: List[CoreFileObjectSharingModel] = Field(
|
||||
description = "sharing settings; specially relevant when the file/dir is private",
|
||||
frozen = True,
|
||||
default = []
|
||||
)
|
||||
@@ -211,20 +224,39 @@ class CoreFileInfoModel(BaseModel):
|
||||
extra = "allow"
|
||||
arbitrary_types_allowed = True
|
||||
|
||||
def model_dump(self, *args, **kwargs):
|
||||
return super().model_dump(*args, by_alias = True, **kwargs)
|
||||
|
||||
# ┓┏ ┓• ┓ •
|
||||
# ┃┃┏┓┃┓┏┫┏┓╋┓┏┓┏┓
|
||||
# ┗┛┗┻┗┗┗┻┗┻┗┗┗┛┛┗
|
||||
|
||||
@field_validator("uploadTs", mode = "before")
|
||||
@field_validator("createTs", mode = "before")
|
||||
def parse_date_time(cls, value):
|
||||
return date_time.parse_date_time(input_value = value, timezone = date_time.TIMEZONE_UTC)
|
||||
|
||||
@field_validator("parentId", mode = "before")
|
||||
@field_validator("fileObjectId", "parentId", mode = "before")
|
||||
def parse_oid(cls, value):
|
||||
try: value = ObjectId(value)
|
||||
except: pass
|
||||
return value
|
||||
|
||||
# ┏┓ •
|
||||
# ┃┃┏┓┏┓┏┓┏┓┏┓╋┓┏┓┏
|
||||
# ┣┛┛ ┗┛┣┛┗ ┛ ┗┗┗ ┛
|
||||
# ┛
|
||||
|
||||
@property
|
||||
def summary(self):
|
||||
return {
|
||||
"user": self.user,
|
||||
"isDir": self.isDir,
|
||||
"name": self.name,
|
||||
"createTs": self.createTs,
|
||||
"parentId": self.parentId,
|
||||
"isPrivate": self.isPrivate,
|
||||
}
|
||||
|
||||
|
||||
# *****************************************************************************************************************
|
||||
# ***** ****
|
||||
@@ -237,7 +269,8 @@ if __name__ == "__main__":
|
||||
|
||||
from utils_v2.string import json
|
||||
|
||||
file_info = CoreFileInfoModel(
|
||||
file_info = CoreFileObjectInfoModel(
|
||||
# _id = "67519cf3a7804fcbc6f12452",
|
||||
user = CoreUserInfoModel(
|
||||
fullName = "Bhopli Narangi",
|
||||
userId = 1,
|
||||
@@ -247,10 +280,10 @@ if __name__ == "__main__":
|
||||
branchId = 5,
|
||||
industry = "fashion"
|
||||
),
|
||||
filename = "Giga-Cat.png",
|
||||
uploadTs = date_time.get_current_utc_date_time(as_string = False),
|
||||
name = "Midnight-Snack.png",
|
||||
createTs = date_time.get_current_utc_date_time(as_string = False),
|
||||
length = 1024,
|
||||
hash = "abcdefgh",
|
||||
hash = "abcdefgh12345678",
|
||||
metadata = {
|
||||
"camera": "iPhone 1000 Pro Max XS"
|
||||
},
|
||||
@@ -262,7 +295,7 @@ if __name__ == "__main__":
|
||||
parentId = "67519cf3a7804fcbc6f12452",
|
||||
isPrivate = True,
|
||||
sharedWith = [
|
||||
CoreFileSharingModel(
|
||||
CoreFileObjectSharingModel(
|
||||
user = CoreUserInfoModel(
|
||||
fullName = "Polki Muchhwaali",
|
||||
userId = 6,
|
||||
@@ -272,8 +305,9 @@ if __name__ == "__main__":
|
||||
branchId = 10,
|
||||
industry = "entertainment"
|
||||
),
|
||||
permissions = CoreFilePermissionsModel(
|
||||
permissions = CoreFileObjectPermissionsModel(
|
||||
read = True,
|
||||
write = False,
|
||||
delete = False,
|
||||
changePermissions = False
|
||||
)
|
||||
@@ -79,11 +79,11 @@ import datetime
|
||||
|
||||
class CoreMessageModel(BaseModel):
|
||||
|
||||
version: str = Field(
|
||||
description = "a hint about the version no. of this message",
|
||||
min_length = 1,
|
||||
messageId: ObjectId = Field(
|
||||
description = "the id of the document in mongodb that holds this information",
|
||||
frozen = True,
|
||||
default = "2.0.0"
|
||||
default = None,
|
||||
alias = "_id"
|
||||
)
|
||||
|
||||
ts: AwareDatetime = Field(
|
||||
@@ -170,6 +170,9 @@ class CoreMessageModel(BaseModel):
|
||||
extra = "allow"
|
||||
arbitrary_types_allowed = True
|
||||
|
||||
def model_dump(self, *args, **kwargs):
|
||||
return super().model_dump(*args, by_alias = True, **kwargs)
|
||||
|
||||
# ┓┏ ┓• ┓ •
|
||||
# ┃┃┏┓┃┓┏┫┏┓╋┓┏┓┏┓
|
||||
# ┗┛┗┻┗┗┗┻┗┻┗┗┗┛┛┗
|
||||
|
||||
@@ -126,11 +126,11 @@ class PaymentEvent(BaseModel):
|
||||
|
||||
class CorePaymentModel(BaseModel):
|
||||
|
||||
version: str = Field(
|
||||
description = "a hint about the version no. of this message",
|
||||
min_length = 1,
|
||||
paymentId: ObjectId = Field(
|
||||
description = "the id of the document in mongodb that holds this information",
|
||||
frozen = True,
|
||||
default = "2.0.0"
|
||||
default = None,
|
||||
alias = "_id"
|
||||
)
|
||||
|
||||
paymentStatus: Literal[
|
||||
@@ -196,6 +196,9 @@ class CorePaymentModel(BaseModel):
|
||||
extra = "allow"
|
||||
arbitrary_types_allowed = True
|
||||
|
||||
def model_dump(self, *args, **kwargs):
|
||||
return super().model_dump(*args, by_alias = True, **kwargs)
|
||||
|
||||
# ┓┏ ┓• ┓ •
|
||||
# ┃┃┏┓┃┓┏┫┏┓╋┓┏┓┏┓
|
||||
# ┗┛┗┻┗┗┗┻┗┻┗┗┗┛┛┗
|
||||
|
||||
@@ -79,13 +79,6 @@ import datetime
|
||||
|
||||
class CoreUserInfoModel(BaseModel):
|
||||
|
||||
version: str = Field(
|
||||
description = "a hint about the version no. of this message",
|
||||
min_length = 1,
|
||||
frozen = True,
|
||||
default = "2.0.0"
|
||||
)
|
||||
|
||||
fullName: str | None = Field(
|
||||
description = "the full name of the user as found in the database",
|
||||
frozen = True,
|
||||
|
||||
Reference in New Issue
Block a user