Skip to content

Commit 2651857

Browse files
fix: TT-210 Don't allow activities deleting (#275)
* fix:TT-210 Dont allow activities deleting * fix: TT-210 Dont-allow activities deleting * fix: TT-210 format Co-authored-by: Pablo <Solorzano> Co-authored-by: Sandro Castillo <[email protected]>
1 parent c133c5d commit 2651857

File tree

5 files changed

+275
-147
lines changed

5 files changed

+275
-147
lines changed

commons/data_access_layer/cosmos_db.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,31 @@ def create_sql_condition_for_visibility(
133133
return 'AND NOT IS_DEFINED(%s.deleted)' % container_name
134134
return ''
135135

136+
@staticmethod
137+
def create_sql_active_condition(
138+
status_value: str, container_name='c'
139+
) -> str:
140+
if status_value != None:
141+
not_defined_condition = ''
142+
condition_operand = ' AND '
143+
if status_value == 'active':
144+
not_defined_condition = (
145+
'AND NOT IS_DEFINED({container_name}.status)'.format(
146+
container_name=container_name
147+
)
148+
)
149+
condition_operand = ' OR '
150+
151+
defined_condition = '(IS_DEFINED({container_name}.status) \
152+
AND {container_name}.status = \'{status_value}\')'.format(
153+
container_name=container_name, status_value=status_value
154+
)
155+
return (
156+
not_defined_condition + condition_operand + defined_condition
157+
)
158+
159+
return ''
160+
136161
@staticmethod
137162
def create_sql_where_conditions(
138163
conditions: dict, container_name='c'
@@ -246,13 +271,20 @@ def find_all(
246271
{"name": "@offset", "value": offset},
247272
{"name": "@max_count", "value": max_count},
248273
]
274+
275+
status_value = None
276+
if conditions.get('status') != None:
277+
status_value = conditions.get('status')
278+
conditions.pop('status')
279+
249280
params.extend(self.generate_params(conditions))
250281
params.extend(custom_params)
251282
query_str = """
252283
SELECT * FROM c
253284
WHERE c.{partition_key_attribute}=@partition_key_value
254285
{conditions_clause}
255286
{visibility_condition}
287+
{active_condition}
256288
{custom_sql_conditions_clause}
257289
{order_clause}
258290
OFFSET @offset LIMIT @max_count
@@ -261,6 +293,7 @@ def find_all(
261293
visibility_condition=self.create_sql_condition_for_visibility(
262294
visible_only
263295
),
296+
active_condition=self.create_sql_active_condition(status_value),
264297
conditions_clause=self.create_sql_where_conditions(conditions),
265298
custom_sql_conditions_clause=self.create_custom_sql_conditions(
266299
custom_sql_conditions

0 commit comments

Comments
 (0)