Skip to content

Commit

Permalink
Merge pull request #25 from kang2453/master
Browse files Browse the repository at this point in the history
refactor: remove project_id references and update workspace handling
  • Loading branch information
kang2453 authored Jan 3, 2025
2 parents 8563e8c + ed456f8 commit 257d7bc
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 32 deletions.
10 changes: 5 additions & 5 deletions src/spaceone/file_manager/interface/rest/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,14 +229,14 @@ def get_download_url(self, response: dict ) -> str:
elif resource_group == "DOMAIN":
domain_id = response["domain_id"]
download_url = "/files/domain/" + domain_id + "/" + file_id
elif resource_group == "WORKSPACE":
elif resource_group == "WORKSPACE" or resource_group == "PROJECT":
domain_id = response["domain_id"]
workspace_id = response["workspace_id"]
download_url = "/files/domain/" + domain_id + "/workspace/" + workspace_id + "/" + file_id
elif resource_group == "PROJECT":
domain_id = response["domain_id"]
project_id = response["project_id"]
download_url = "/files/domain/" + domain_id + "/project/"+ project_id + "/" + file_id
# elif resource_group == "PROJECT":
# domain_id = response["domain_id"]
# project_id = response["project_id"]
# download_url = "/files/domain/" + domain_id + "/workspace/" + workspace_id + "/project/"+ project_id + "/" + file_id
else:
raise ERROR_NOT_SUPPORTED_RESOURCE_GROUP(resource_group=resource_group)

Expand Down
4 changes: 0 additions & 4 deletions src/spaceone/file_manager/manager/file_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ def get_file(
file_id: str,
domain_id: str = None,
workspace_id: str = None,
project_id: str = None,
) -> File:
conditions = {"file_id": file_id}

Expand All @@ -52,9 +51,6 @@ def get_file(
if workspace_id:
conditions["workspace_id"] = workspace_id

if project_id:
conditions["project_id"] = project_id

return self.file_model.get(**conditions)

def filter_files(self, **conditions) -> QuerySet:
Expand Down
14 changes: 7 additions & 7 deletions src/spaceone/file_manager/manager/identity_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ def check_workspace(self, workspace_id, domain_id):
token=system_token,
)

def check_project(self, project_id, domain_id):
system_token = config.get_global("TOKEN")
return self.identity_connector.dispatch(
"Project.check",
{"project_id": project_id, "domain_id": domain_id},
token=system_token,
)
# def check_project(self, project_id, domain_id):
# system_token = config.get_global("TOKEN")
# return self.identity_connector.dispatch(
# "Project.check",
# {"project_id": project_id, "domain_id": domain_id},
# token=system_token,
# )

# def check_user(self, user_id, domain_id):
# system_token = config.get_global("TOKEN")
Expand Down
4 changes: 1 addition & 3 deletions src/spaceone/file_manager/model/file/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ def to_dict(self):

class File(MongoModel):
file_id = StringField(max_length=40, generate_id="file", unique=True)
file_type = StringField(max_length=40, null=True, default=None)
name = StringField(max_length=255, required=True)
download_url = StringField(null=True, default=None)
tags = DictField()
Expand All @@ -25,7 +26,6 @@ class File(MongoModel):
)
workspace_id = StringField(max_length=40, null=True, default=None)
domain_id = StringField(max_length=40, null=True, default=None)
project_id = StringField(max_length=40, null=True, default=None)
created_at = DateTimeField(auto_now_add=True)

meta = {
Expand All @@ -37,7 +37,6 @@ class File(MongoModel):
"resource_group",
"workspace_id",
"domain_id",
"project_id",
],
"change_query_keys": {
"resource_type": "reference.resource_type",
Expand All @@ -50,7 +49,6 @@ class File(MongoModel):
"reference.resource_id",
"resource_group",
"workspace_id",
"project_id",
"domain_id",
],
}
6 changes: 0 additions & 6 deletions src/spaceone/file_manager/model/file/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ class FileAddRequest(BaseModel):
resource_group: ResourceGroup
domain_id: Union[str, None] = None
workspace_id: Union[str, None] = None
project_id: Union[str, None] = None


class FileUpdateRequest(BaseModel):
Expand All @@ -30,22 +29,19 @@ class FileUpdateRequest(BaseModel):
tags: Union[dict, None] = None
domain_id: Union[str, None] = None
workspace_id: Union[str, None] = None
project_id: Union[str, None] = None
download_url: Union[str, None] = None


class FileDeleteRequest(BaseModel):
file_id: str
domain_id: Union[str, None] = None
workspace_id: Union[str, None] = None
project_id: Union[str, None] = None


class FileGetRequest(BaseModel):
file_id: str
domain_id: Union[list, str, None] = None
workspace_id: Union[list, str, None] = None
project_id: Union[list, str, None] = None


class FileSearchQueryRequest(BaseModel):
Expand All @@ -56,11 +52,9 @@ class FileSearchQueryRequest(BaseModel):
resource_id: Union[str, None] = None
domain_id: Union[list, str, None] = None
workspace_id: Union[list, str, None] = None
project_id: Union[list, str, None] = None


class FileStatQueryRequest(BaseModel):
query: dict
domain_id: Union[list, str, None] = None
workspace_id: Union[list, str, None] = None
project_id: Union[list, str, None] = None
3 changes: 2 additions & 1 deletion src/spaceone/file_manager/model/file/response.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from datetime import datetime
from typing import Union, List

from pydantic import BaseModel

from spaceone.core import utils
Expand All @@ -10,14 +11,14 @@

class FileResponse(BaseModel):
file_id: Union[str, None] = None
file_type: Union[str, None] = None
name: Union[str, None] = None
download_url: Union[str, None] = None
reference: Union[dict, None] = None
tags: Union[dict, None] = None
resource_group: Union[ResourceGroup, None] = None
domain_id: Union[str, None] = None
workspace_id: Union[str, None] = None
project_id: Union[str, None] = None
created_at: Union[datetime, None] = None

def dict(self, *args, **kwargs):
Expand Down
6 changes: 0 additions & 6 deletions src/spaceone/file_manager/service/file_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ def add(self, params: FileAddRequest) -> Union[FileResponse, dict]:
'name': 'str', # required
'reference': 'dict',
'tags': 'dict',
'project_id': 'str',
'workspace_id': 'str', # injected from auth
'domain_id': 'str' # injected from auth
}
Expand Down Expand Up @@ -108,7 +107,6 @@ def update(self, params: FileUpdateRequest) -> Union[FileResponse, dict]:
params.file_id,
params.domain_id,
params.workspace_id,
params.project_id,
)

file_vo = self.file_mgr.update_file_by_vo(
Expand All @@ -133,7 +131,6 @@ def delete(self, params: FileDeleteRequest) -> None:
Args:
params (FileDeleteRequest): {
'file_id': 'str', # required
'project_id': 'str',
'workspace_id': 'str', # injected from auth
'domain_id': 'str' # injected from auth
}
Expand All @@ -146,7 +143,6 @@ def delete(self, params: FileDeleteRequest) -> None:
params.file_id,
params.domain_id,
params.workspace_id,
params.project_id,
)
try:

Expand Down Expand Up @@ -187,7 +183,6 @@ def get(self, params: FileGetRequest) -> Union[FileResponse, dict]:
params.file_id,
params.domain_id,
params.workspace_id,
params.project_id,
)

return FileResponse(**file_vo.to_dict())
Expand All @@ -211,7 +206,6 @@ def get(self, params: FileGetRequest) -> Union[FileResponse, dict]:
"resource_id",
"domain_id",
"workspace_id",
"project_id",
]
)
@append_keyword_filter(["file_id", "name"])
Expand Down

0 comments on commit 257d7bc

Please sign in to comment.