Skip to content

Commit

Permalink
Merge pull request #244 from ImMin5/master
Browse files Browse the repository at this point in the history
Add Workspace Member permissions for cost report data analyze
  • Loading branch information
ImMin5 authored Jun 21, 2024
2 parents 8cedf9b + ed894c9 commit 25f01dd
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/spaceone/cost_analysis/manager/cost_report_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def filter_cost_reports(self, **conditions) -> QuerySet:
return self.cost_report_model.filter(**conditions)

def list_cost_reports(self, query: dict) -> Tuple[QuerySet, int]:
_LOGGER.debug(f"[list_cost_reports] query: {query}")
return self.cost_report_model.query(**query)

def stat_cost_reports(self, query: dict) -> dict:
Expand Down
21 changes: 20 additions & 1 deletion src/spaceone/cost_analysis/model/cost_report/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,24 @@ class CostReport(MongoModel):
"-created_at",
"-report_number",
],
"indexes": ["cost_report_config_id", "status", "domain_id", "workspace_id"],
"indexes": [
{
"fields": [
"cost_report_config_id",
"status",
"domain_id",
"workspace_id",
],
"name": "COMPOUND_INDEX_FOR_CONFIRM_REPORT",
},
{
"fields": [
"report_month",
"status",
"domain_id",
"workspace_id",
],
"name": "COMPOUND_INDEX_FOR_CONFIRM_REPORT_2",
},
],
}
21 changes: 15 additions & 6 deletions src/spaceone/cost_analysis/model/cost_report_data/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ class CostReportData(MongoModel):
data_source_id = StringField(max_length=40)
cost_report_id = StringField(max_length=40)
cost_report_config_id = StringField(max_length=40)
workspace_id = StringField(
max_length=40, default=None, null=True
) # todo workspace_id required
project_id = StringField(max_length=40, default=None, null=True)
workspace_id = StringField(max_length=40)
domain_id = StringField(max_length=40)
created_at = DateTimeField(auto_now_add=True)

Expand All @@ -36,9 +35,19 @@ class CostReportData(MongoModel):
"workspace_id",
],
"ordering": ["is_confirmed", "-report_year"],
"change_query_keys": {"user_projects": "project_id"},
"indexes": [
"cost_report_config_id",
"cost_report_id",
"domain_id",
{
"fields": [
"cost_report_config_id",
"cost_report_id",
"domain_id",
],
"name": "COMPOUND_INDEX_FOR_DEFAULT_COST_REPORT_DATA",
},
{
"fields": ["is_confirmed", "domain_id", "workspace_id", "project_id"],
"name": "COMPOUND_INDEX_FOR_WORKSPACE_LANDING",
},
],
}
3 changes: 3 additions & 0 deletions src/spaceone/cost_analysis/model/cost_report_data/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ class CostReportDataAnalyzeQueryRequest(BaseModel):
product: Union[str, None] = None
provider: Union[str, None] = None
data_source_id: Union[str, None] = None
cost_report_id: Union[str, None] = None
cost_report_config_id: Union[str, None] = None
user_projects: Union[list, None] = None
project_id: Union[str, None] = None
workspace_id: Union[str, None] = None
domain_id: str

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,18 +77,21 @@ def list(

@transaction(
permission="cost-analysis:CostReportData.read",
role_types=["DOMAIN_ADMIN", "WORKSPACE_OWNER"],
role_types=["DOMAIN_ADMIN", "WORKSPACE_OWNER", "WORKSPACE_MEMBER"],
)
@append_query_filter(
[
"product",
"provider",
"is_confirmed",
"cost_report_config_id",
"cost_report_id",
"cost_report_data_id",
"data_source_id",
"workspace_id",
"domain_id",
"project_id",
"user_projects",
]
)
@append_keyword_filter(
Expand Down

0 comments on commit 25f01dd

Please sign in to comment.