LiuHua
		
		Feiue
		
	commited on
		
		
					Commit 
							
							·
						
						ad6777f
	
1
								Parent(s):
							
							47aa5d5
								
Add Authorization checks (#2235)
Browse files### What problem does this PR solve?
Add Authorization checks
### Type of change
- [x] New Feature (non-breaking change which adds functionality)
Co-authored-by: Feiue <[email protected]>
- api/apps/canvas_app.py +12 -1
    	
        api/apps/canvas_app.py
    CHANGED
    
    | @@ -68,8 +68,11 @@ def save(): | |
| 68 | 
             
                    if not UserCanvasService.save(**req):
         | 
| 69 | 
             
                        return get_data_error_result(retmsg="Fail to save canvas.")
         | 
| 70 | 
             
                else:
         | 
|  | |
|  | |
|  | |
|  | |
| 71 | 
             
                    UserCanvasService.update_by_id(req["id"], req)
         | 
| 72 | 
            -
             | 
| 73 | 
             
                return get_json_result(data=req)
         | 
| 74 |  | 
| 75 |  | 
| @@ -91,6 +94,10 @@ def run(): | |
| 91 | 
             
                e, cvs = UserCanvasService.get_by_id(req["id"])
         | 
| 92 | 
             
                if not e:
         | 
| 93 | 
             
                    return get_data_error_result(retmsg="canvas not found.")
         | 
|  | |
|  | |
|  | |
|  | |
| 94 |  | 
| 95 | 
             
                if not isinstance(cvs.dsl, str):
         | 
| 96 | 
             
                    cvs.dsl = json.dumps(cvs.dsl, ensure_ascii=False)
         | 
| @@ -157,6 +164,10 @@ def reset(): | |
| 157 | 
             
                    e, user_canvas = UserCanvasService.get_by_id(req["id"])
         | 
| 158 | 
             
                    if not e:
         | 
| 159 | 
             
                        return get_data_error_result(retmsg="canvas not found.")
         | 
|  | |
|  | |
|  | |
|  | |
| 160 |  | 
| 161 | 
             
                    canvas = Canvas(json.dumps(user_canvas.dsl), current_user.id)
         | 
| 162 | 
             
                    canvas.reset()
         | 
|  | |
| 68 | 
             
                    if not UserCanvasService.save(**req):
         | 
| 69 | 
             
                        return get_data_error_result(retmsg="Fail to save canvas.")
         | 
| 70 | 
             
                else:
         | 
| 71 | 
            +
                    if not UserCanvasService.query(user_id=current_user.id, id=req["id"]):
         | 
| 72 | 
            +
                        return get_json_result(
         | 
| 73 | 
            +
                            data=False, retmsg=f'Only owner of canvas authorized for this operation.',
         | 
| 74 | 
            +
                            retcode=RetCode.OPERATING_ERROR)
         | 
| 75 | 
             
                    UserCanvasService.update_by_id(req["id"], req)
         | 
|  | |
| 76 | 
             
                return get_json_result(data=req)
         | 
| 77 |  | 
| 78 |  | 
|  | |
| 94 | 
             
                e, cvs = UserCanvasService.get_by_id(req["id"])
         | 
| 95 | 
             
                if not e:
         | 
| 96 | 
             
                    return get_data_error_result(retmsg="canvas not found.")
         | 
| 97 | 
            +
                if not UserCanvasService.query(user_id=current_user.id, id=req["id"]):
         | 
| 98 | 
            +
                    return get_json_result(
         | 
| 99 | 
            +
                        data=False, retmsg=f'Only owner of canvas authorized for this operation.',
         | 
| 100 | 
            +
                        retcode=RetCode.OPERATING_ERROR)
         | 
| 101 |  | 
| 102 | 
             
                if not isinstance(cvs.dsl, str):
         | 
| 103 | 
             
                    cvs.dsl = json.dumps(cvs.dsl, ensure_ascii=False)
         | 
|  | |
| 164 | 
             
                    e, user_canvas = UserCanvasService.get_by_id(req["id"])
         | 
| 165 | 
             
                    if not e:
         | 
| 166 | 
             
                        return get_data_error_result(retmsg="canvas not found.")
         | 
| 167 | 
            +
                    if not UserCanvasService.query(user_id=current_user.id, id=req["id"]):
         | 
| 168 | 
            +
                        return get_json_result(
         | 
| 169 | 
            +
                            data=False, retmsg=f'Only owner of canvas authorized for this operation.',
         | 
| 170 | 
            +
                            retcode=RetCode.OPERATING_ERROR)
         | 
| 171 |  | 
| 172 | 
             
                    canvas = Canvas(json.dumps(user_canvas.dsl), current_user.id)
         | 
| 173 | 
             
                    canvas.reset()
         |