args file_id returns file (may be a new one)
(project_string_id, file_id)
| 39 | methods=['POST']) |
| 40 | @Project_permissions.user_has_project(["admin", "Editor"]) |
| 41 | def ann_is_complete_toggle(project_string_id, file_id): |
| 42 | """ |
| 43 | args |
| 44 | file_id |
| 45 | |
| 46 | returns |
| 47 | file (may be a new one) |
| 48 | |
| 49 | """ |
| 50 | |
| 51 | # TODO review if this should be shared with file update!!! |
| 52 | # probably yes!!! |
| 53 | |
| 54 | spec_list = [ |
| 55 | {'directory_id': int} |
| 56 | ] |
| 57 | |
| 58 | log, input, untrusted_input = regular_input.master(request=request, |
| 59 | spec_list=spec_list) |
| 60 | if len(log["error"].keys()) >= 1: |
| 61 | return jsonify(log=log), 400 |
| 62 | |
| 63 | with sessionMaker.session_scope() as session: |
| 64 | |
| 65 | # TODO this section should maybe be it's own sub function within File? |
| 66 | |
| 67 | user = User.get(session=session) |
| 68 | project = Project.get(session, project_string_id) |
| 69 | |
| 70 | directory = WorkingDir.get_with_fallback( |
| 71 | session=session, |
| 72 | directory_id=input['directory_id'], |
| 73 | project=project) |
| 74 | |
| 75 | if directory is False: |
| 76 | log['error']['directory'] = "No directory found" |
| 77 | return jsonify(log=log), 400 |
| 78 | |
| 79 | file = File.get_by_id_and_directory_untrusted( |
| 80 | session=session, |
| 81 | directory_id=directory.id, |
| 82 | file_id=file_id) |
| 83 | |
| 84 | if file is None: |
| 85 | return jsonify("file invalid"), 400 |
| 86 | |
| 87 | new_file = file.toggle_flag_shared(session) |
| 88 | |
| 89 | if new_file is False: |
| 90 | return jsonify(False), 400 |
| 91 | |
| 92 | Event.new( |
| 93 | session=session, |
| 94 | kind="file_complete_toggle", |
| 95 | member_id=user.member_id, |
| 96 | project_id=project.id, |
| 97 | file_id=file.id, |
| 98 | description=str(file.ann_is_complete) |
nothing calls this directly
no test coverage detected