Skip to content

Commit e166cfd

Browse files
一旦前の実装に戻す
1 parent 448d978 commit e166cfd

File tree

2 files changed

+15
-20
lines changed

2 files changed

+15
-20
lines changed

src/common/settings.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,23 +88,19 @@
8888
},
8989
'fraud_user': {
9090
'reason': {
91-
'type': ['string'],
91+
'type': 'string',
9292
},
9393
'plagiarism_url': {
9494
'type': 'string',
9595
'format': 'uri',
96-
'pattern': r'^(https?|http?)://',
97-
'minLength': 1,
9896
'maxLength': 2048
9997
},
10098
'plagiarism_description': {
10199
'type': 'string',
102-
'minLength': 1,
103100
'maxLength': 1000
104101
},
105102
'illegal_content': {
106103
'type': 'string',
107-
'minLength': 1,
108104
'maxLength': 1000
109105
},
110106

src/handlers/me/articles/fraud/create/me_articles_fraud_create.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,6 @@ def get_schema(self):
2525
'properties': {
2626
'reason': {'enum': settings.FRAUD_REASONS}
2727
}
28-
},
29-
{
30-
'properties': {
31-
'reason': {'enum': settings.FRAUD_NEED_ORIGINAL_REASONS}
32-
},
33-
'anyOf': [
34-
{'required': ['plagiarism_url']},
35-
{'required': ['plagiarism_description']}
36-
]
37-
},
38-
{
39-
'properties': {
40-
'reason': {'enum': settings.FRAUD_NEED_DETAIL_REASONS}
41-
},
42-
'required': ['illegal_content']
4328
}
4429
],
4530
'required': ['article_id']
@@ -50,6 +35,7 @@ def validate_params(self):
5035
if self.event.get('pathParameters') is None:
5136
raise ValidationError('pathParameters is required')
5237
validate(self.params, self.get_schema())
38+
self.__validate_reason_dependencies(self.params)
5339
# relation
5440
DBUtil.validate_article_existence(
5541
self.dynamodb,
@@ -88,3 +74,16 @@ def __create_article_fraud_user(self, article_fraud_user_table):
8874
Item=article_fraud_user,
8975
ConditionExpression='attribute_not_exists(article_id)'
9076
)
77+
78+
def __validate_reason_dependencies(self, params):
79+
reason = params.get('reason', '')
80+
if reason in settings.FRAUD_NEED_ORIGINAL_REASONS:
81+
self.__validate_dependencies(params, ['plagiarism_url', 'plagiarism_description'])
82+
83+
if reason in settings.FRAUD_NEED_DETAIL_REASONS:
84+
self.__validate_dependencies(params, ['illegal_content'])
85+
86+
def __validate_dependencies(self, params, required_items):
87+
for item in required_items:
88+
if not params.get(item):
89+
raise ValidationError("%s is required" % item)

0 commit comments

Comments
 (0)