()
| 19 | @General_permissions.grant_permission_for(Roles = 'normal_user',apis_user_list = ['api_enabled_builder']) # Checking email is verified within function to return nice error message here |
| 20 | @limiter.limit("25 per day") |
| 21 | def project_new_api(): |
| 22 | spec_list = [{'project_name': str}, |
| 23 | {'goal': None}, |
| 24 | {'project_string_id': str}] |
| 25 | |
| 26 | log, input, untrusted_input = regular_input.master(request = request, |
| 27 | spec_list = spec_list) |
| 28 | if len(log["error"].keys()) >= 1: |
| 29 | return jsonify(log = log), 400 |
| 30 | |
| 31 | with sessionMaker.session_scope() as session: |
| 32 | |
| 33 | user = User.get(session = session) |
| 34 | member = get_member(session) |
| 35 | if settings.ONLY_SUPER_ADMINS_CREATE_PROJECTS and not user.is_super_admin: |
| 36 | log['error']['unauthorized'] = "Only super admins can create project." |
| 37 | return jsonify(log = log), 403 |
| 38 | if user.security_email_verified is not True: |
| 39 | log['error']['security_email_verified'] = "Please verify your email first" |
| 40 | return jsonify(log = log), 400 |
| 41 | |
| 42 | existing_project = session.query(Project).filter( |
| 43 | Project.project_string_id == input['project_string_id']).first() |
| 44 | |
| 45 | if existing_project is not None: |
| 46 | log['error']['project_string_id'] = "Project name already exists. Projects must be globally unique." |
| 47 | return jsonify(log = log), 400 |
| 48 | |
| 49 | default_project_limit = 10 |
| 50 | |
| 51 | if user.is_super_admin != True: |
| 52 | |
| 53 | """ |
| 54 | When we create a new project we don't have a great way |
| 55 | to get the user's "plan" to check if on free plan etc. |
| 56 | As a temporary work around, if the user is part of an org we increase limit |
| 57 | """ |
| 58 | |
| 59 | if len(user.projects) >= default_project_limit: |
| 60 | log['error'][ |
| 61 | 'limit'] = "oops looks like you have a few projects already! Please contact us to increase this limit." |
| 62 | return jsonify(log = log), 400 |
| 63 | |
| 64 | if not valid_project_name(input['project_name']): |
| 65 | log['error']['project_name'] = "Invalid name." |
| 66 | return jsonify(log = log), 400 |
| 67 | |
| 68 | if not valid_project_id(input['project_string_id']): |
| 69 | log['error']['project_id'] = "Invalid project id" |
| 70 | return jsonify(log = log), 400 |
| 71 | |
| 72 | project = Project.new( |
| 73 | session = session, |
| 74 | name = input['project_name'], |
| 75 | project_string_id = input['project_string_id'], |
| 76 | goal = input['goal'], |
| 77 | user = user, |
| 78 | member_created = user.member |
nothing calls this directly
no test coverage detected