Skip to content

Commit 714e7d9

Browse files
protect routes modifying resources
1 parent 1c669cd commit 714e7d9

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

app/routes.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,13 +136,16 @@ def refresh():
136136

137137

138138
@app.route('/category/create', methods=['POST'])
139+
@jwt_required()
139140
def create_category():
140141
"""
141142
Create Category
142143
---
143144
tags:
144145
- Category
145146
description: Create a new category.
147+
security:
148+
- access_token: []
146149
requestBody:
147150
required: true
148151
description: name - Name of the category <br> subcategories - Array of subcategory ids (optional)
@@ -164,6 +167,8 @@ def create_category():
164167
description: Category created successfully.
165168
400:
166169
description: Invalid input.
170+
401:
171+
description: Token expired, missing or invalid.
167172
500:
168173
description: Error occurred.
169174
"""
@@ -210,13 +215,16 @@ def get_category(c_id):
210215

211216

212217
@app.route('/category/<int:c_id>/update', methods=['PUT'])
218+
@jwt_required()
213219
def update_category(c_id):
214220
"""
215221
Update Category
216222
---
217223
tags:
218224
- Category
219225
description: Update an existing category.
226+
security:
227+
- access_token: []
220228
parameters:
221229
- in: path
222230
name: c_id
@@ -268,13 +276,16 @@ def update_category(c_id):
268276

269277

270278
@app.route("/category/<int:c_id>", methods=["DELETE"])
279+
@jwt_required()
271280
def delete_category(c_id):
272281
"""
273282
Delete Category
274283
---
275284
tags:
276285
- Category
277286
description: Delete a category by ID.
287+
security:
288+
- access_token: []
278289
parameters:
279290
- in: path
280291
name: c_id
@@ -402,13 +413,16 @@ def get_category_products(c_id):
402413

403414

404415
@app.route('/subcategory/create', methods=['POST'])
416+
@jwt_required()
405417
def create_subcategory():
406418
"""
407419
Create Subcategory
408420
---
409421
tags:
410422
- Subcategory
411423
description: Create a new subcategory.
424+
security:
425+
- access_token: []
412426
requestBody:
413427
required: true
414428
description: name - Name of the subcategory <br> categories - Array of category ids (optional) <br> products - Array of product ids (optional)
@@ -502,13 +516,16 @@ def get_subcategory(sc_id):
502516

503517

504518
@app.route('/subcategory/<int:sc_id>/update', methods=['PUT'])
519+
@jwt_required()
505520
def update_subcategory(sc_id):
506521
"""
507522
Update Subcategory
508523
---
509524
tags:
510525
- Subcategory
511526
description: Update an existing subcategory.
527+
security:
528+
- access_token: []
512529
parameters:
513530
- in: path
514531
name: sc_id
@@ -568,13 +585,16 @@ def update_subcategory(sc_id):
568585

569586

570587
@app.route("/subcategory/<int:sc_id>", methods=["DELETE"])
588+
@jwt_required()
571589
def delete_subcategory(sc_id):
572590
"""
573591
Delete Subcategory
574592
---
575593
tags:
576594
- Subcategory
577595
description: Delete a subcategory by ID.
596+
security:
597+
- access_token: []
578598
parameters:
579599
- in: path
580600
name: sc_id
@@ -676,13 +696,16 @@ def get_subcategory_products(sc_id):
676696

677697

678698
@app.route('/product/create', methods=['POST'])
699+
@jwt_required()
679700
def create_product():
680701
"""
681702
Create Product
682703
---
683704
tags:
684705
- Product
685706
description: Create a new product.
707+
security:
708+
- access_token: []
686709
requestBody:
687710
required: true
688711
description: name - Name of the product <br> description - Description of the product (optional) <br> subcategories - Array of subcategory ids (optional)
@@ -755,13 +778,16 @@ def get_product(p_id):
755778

756779

757780
@app.route('/product/<int:p_id>/update', methods=['PUT'])
781+
@jwt_required()
758782
def update_product(p_id):
759783
"""
760784
Update Product
761785
---
762786
tags:
763787
- Product
764788
description: Update an existing product.
789+
security:
790+
- access_token: []
765791
consumes:
766792
- application/json
767793
parameters:
@@ -820,13 +846,16 @@ def update_product(p_id):
820846

821847

822848
@app.route("/product/<int:p_id>", methods=["DELETE"])
849+
@jwt_required()
823850
def delete_product(p_id):
824851
"""
825852
Delete Product
826853
---
827854
tags:
828855
- Product
829856
description: Delete a product by ID.
857+
security:
858+
- access_token: []
830859
parameters:
831860
- in: path
832861
name: p_id

0 commit comments

Comments
 (0)