Пример #1
0
def update_mod(mod_id):
    if current_user == None:
        return { 'error': True, 'reason': 'You are not logged in.' }, 401
    mod = Mod.query.filter(Mod.id == mod_id).first()
    if not mod:
        return { 'error': True, 'reason': 'Mod not found.' }, 404
    editable = False
    if current_user:
        if current_user.admin:
            editable = True
        if current_user.id == mod.user_id:
            editable = True
        if any([u.accepted and u.user == current_user for u in mod.shared_authors]):
            editable = True
    if not editable:
        return { 'error': True, 'reason': 'Not enought rights.' }, 401
    version = request.form.get('version')
    changelog = request.form.get('changelog')
    ksp_version = request.form.get('ksp-version')
    notify = request.form.get('notify-followers')
    zipball = request.files.get('zipball')
    if not version \
        or not ksp_version \
        or not zipball:
        # Client side validation means that they're just being pricks if they
        # get here, so we don't need to show them a pretty error reason
        # SMILIE: this doesn't account for "external" API use --> return a json error
        return { 'error': True, 'reason': 'All fields are required.' }, 400
    if notify == None:
        notify = False
    else:
        notify = (notify.lower() == "true" or notify.lower() == "yes")
    filename = secure_filename(mod.name) + '-' + secure_filename(version) + '.zip'
    base_path = os.path.join(secure_filename(current_user.username) + '_' + str(current_user.id), secure_filename(mod.name))
    full_path = os.path.join(_cfg('storage'), base_path)
    if not os.path.exists(full_path):
        os.makedirs(full_path)
    path = os.path.join(full_path, filename)
    if os.path.isfile(path):
        return { 'error': True, 'reason': 'We already have this version. Did you mistype the version number?' }, 400
    zipball.save(path)
    if not zipfile.is_zipfile(path):
        os.remove(path)
        return { 'error': True, 'reason': 'This is not a valid zip file.' }, 400
    version = ModVersion(secure_filename(version), ksp_version, os.path.join(base_path, filename))
    version.changelog = changelog
    # Assign a sort index
    if len(mod.versions) == 0:
        version.sort_index = 0
    else:
        version.sort_index = max([v.sort_index for v in mod.versions]) + 1
    mod.versions.append(version)
    mod.updated = datetime.now()
    if notify:
        send_update_notification(mod, version, current_user)
    db.add(version)
    db.commit()
    mod.default_version_id = version.id
    return { 'url': url_for("mods.mod", id=mod.id, mod_name=mod.name), "id": version.id  }
Пример #2
0
def update(mod_id, mod_name):
    user = get_user()
    mod = Mod.query.filter(Mod.id == mod_id).first()
    if not mod:
        abort(404)
    editable = False
    if user:
        if user.admin:
            editable = True
        if user.id == mod.user_id:
            editable = True
    if not editable:
        abort(401)
    version = request.form.get('version')
    changelog = request.form.get('changelog')
    ksp_version = request.form.get('ksp-version')
    notify = request.form.get('notify-followers')
    zipball = request.files.get('zipball')
    if not version \
        or not ksp_version \
        or not zipball:
        # Client side validation means that they're just being pricks if they
        # get here, so we don't need to show them a pretty error message
        abort(400)
    if notify == None:
        notify = False
    else:
        notify = notify.lower() == "on"
    filename = secure_filename(mod.name) + '-' + secure_filename(version) + '.zip'
    base_path = os.path.join(secure_filename(user.username) + '_' + str(user.id), secure_filename(mod.name))
    full_path = os.path.join(_cfg('storage'), base_path)
    if not os.path.exists(full_path):
        os.makedirs(full_path)
    path = os.path.join(full_path, filename)
    if os.path.isfile(path):
        # We already have this version
        # TODO: Error message
        abort(400)
    zipball.save(path)
    if not zipfile.is_zipfile(path):
        os.remove(path)
        abort(400) # TODO: Error message
    version = ModVersion(secure_filename(version), ksp_version, os.path.join(base_path, filename))
    version.changelog = changelog
    # Assign a sort index
    version.sort_index = max([v.sort_index for v in mod.versions]) + 1
    mod.versions.append(version)
    if notify:
        send_update_notification(mod)
    db.add(version)
    db.commit()
    mod.default_version_id = version.id
    return redirect('/mod/' + mod_id + '/' + secure_filename(mod.name))
Пример #3
0
def update_mod(mod_id):
    mod = Mod.query.filter(Mod.id == mod_id).first()
    if not mod:
        abort(404)
    editable = False
    if current_user:
        if current_user.admin:
            editable = True
        if current_user.id == mod.user_id:
            editable = True
        if any([u.accepted and u.user == current_user for u in mod.shared_authors]):
            editable = True
    if not editable:
        abort(401)
    version = request.form.get('version')
    changelog = request.form.get('changelog')
    ksp_version = request.form.get('ksp-version')
    notify = request.form.get('notify-followers')
    zipball = request.files.get('zipball')
    if not version \
        or not ksp_version \
        or not zipball:
        # Client side validation means that they're just being pricks if they
        # get here, so we don't need to show them a pretty error message
        abort(400)
    if notify == None:
        notify = False
    else:
        notify = notify.lower() == "true"
    filename = secure_filename(mod.name) + '-' + secure_filename(version) + '.zip'
    base_path = os.path.join(secure_filename(current_user.username) + '_' + str(current_user.id), secure_filename(mod.name))
    full_path = os.path.join(_cfg('storage'), base_path)
    if not os.path.exists(full_path):
        os.makedirs(full_path)
    path = os.path.join(full_path, filename)
    if os.path.isfile(path):
        return { 'error': True, 'message': 'We already have this version. Did you mistype the version number?' }, 400
    zipball.save(path)
    if not zipfile.is_zipfile(path):
        os.remove(path)
        return { 'error': True, 'message': 'This is not a valid zip file.' }, 400
    version = ModVersion(secure_filename(version), ksp_version, os.path.join(base_path, filename))
    version.changelog = changelog
    # Assign a sort index
    version.sort_index = max([v.sort_index for v in mod.versions]) + 1
    mod.versions.append(version)
    if notify:
        send_update_notification(mod, version, current_user)
    db.add(version)
    db.commit()
    mod.default_version_id = version.id
    return { 'url': url_for("mods.mod", id=mod.id, mod_name=mod.name) }
Пример #4
0
def update(mod_id, mod_name):
    user = get_user()
    mod = Mod.query.filter(Mod.id == mod_id).first()
    if not mod:
        abort(404)
    editable = False
    if user:
        if user.admin:
            editable = True
        if user.id == mod.user_id:
            editable = True
    if not editable:
        abort(401)
    if request.method == 'GET':
        return render_template("update.html", **{ 'mod': mod })
    else:
        version = request.form.get('version')
        changelog = request.form.get('changelog')
        ksp_version = request.form.get('ksp-version')
        zipball = request.files.get('zipball')
        if not version \
            or not ksp_version \
            or not zipball:
            # Client side validation means that they're just being pricks if they
            # get here, so we don't need to show them a pretty error message
            abort(400)
        filename = secure_filename(mod.name) + '-' + secure_filename(version) + '.zip'
        base_path = os.path.join(secure_filename(user.username) + '_' + str(user.id), secure_filename(mod.name))
        full_path = os.path.join(_cfg('storage'), base_path)
        if not os.path.exists(full_path):
            os.makedirs(full_path)
        path = os.path.join(full_path, filename)
        if os.path.isfile(path):
            # We already have this version
            # TODO: Error message
            abort(400)
        zipball.save(path)
        if not zipfile.is_zipfile(path):
            os.remove(path)
            abort(400) # TODO: Error message
        version = ModVersion(secure_filename(version), ksp_version, os.path.join(base_path, filename))
        version.changelog = changelog
        mod.versions.append(version)
        send_update_notification(mod)
        db.add(version)
        db.commit()
        return redirect('/mod/' + mod_id + '/' + secure_filename(mod.name))
Пример #5
0
def update_mod(mod_id):
    if current_user == None:
        return {'error': True, 'reason': 'You are not logged in.'}, 401
    mod = Mod.query.filter(Mod.id == mod_id).first()
    if not mod:
        return {'error': True, 'reason': 'Mod not found.'}, 404
    editable = False
    if current_user:
        if current_user.admin:
            editable = True
        if current_user.id == mod.user_id:
            editable = True
        if any([
                u.accepted and u.user == current_user
                for u in mod.shared_authors
        ]):
            editable = True
    if not editable:
        return {'error': True, 'reason': 'Not enought rights.'}, 401
    version = request.form.get('version')
    changelog = request.form.get('changelog')
    ksp_version = request.form.get('ksp-version')
    notify = request.form.get('notify-followers')
    zipball = request.files.get('zipball')
    if not version \
        or not ksp_version \
        or not zipball:
        # Client side validation means that they're just being pricks if they
        # get here, so we don't need to show them a pretty error reason
        # SMILIE: this doesn't account for "external" API use --> return a json error
        return {'error': True, 'reason': 'All fields are required.'}, 400
    if notify == None:
        notify = False
    else:
        notify = (notify.lower() == "true" or notify.lower() == "yes")
    filename = secure_filename(
        mod.name) + '-' + secure_filename(version) + '.zip'
    base_path = os.path.join(
        secure_filename(current_user.username) + '_' + str(current_user.id),
        secure_filename(mod.name))
    full_path = os.path.join(_cfg('storage'), base_path)
    if not os.path.exists(full_path):
        os.makedirs(full_path)
    path = os.path.join(full_path, filename)
    if os.path.isfile(path):
        return {
            'error':
            True,
            'reason':
            'We already have this version. Did you mistype the version number?'
        }, 400
    zipball.save(path)
    if not zipfile.is_zipfile(path):
        os.remove(path)
        return {'error': True, 'reason': 'This is not a valid zip file.'}, 400
    version = ModVersion(secure_filename(version), ksp_version,
                         os.path.join(base_path, filename))
    version.changelog = changelog
    # Assign a sort index
    version.sort_index = max([v.sort_index for v in mod.versions]) + 1
    mod.versions.append(version)
    mod.updated = datetime.now()
    if notify:
        send_update_notification(mod, version, current_user)
    db.add(version)
    db.commit()
    mod.default_version_id = version.id
    return {
        'url': url_for("mods.mod", id=mod.id, mod_name=mod.name),
        "id": version.id
    }
Пример #6
0
def update_mod(mod_id):
    if current_user == None:
        return {"error": True, "reason": "You are not logged in."}, 401
    mod = Mod.query.filter(Mod.id == mod_id).first()
    if not mod:
        return {"error": True, "reason": "Mod not found."}, 404
    editable = False
    if current_user:
        if current_user.admin:
            editable = True
        if current_user.id == mod.user_id:
            editable = True
        if any([u.accepted and u.user == current_user for u in mod.shared_authors]):
            editable = True
    if not editable:
        return {"error": True, "reason": "Not enought rights."}, 401
    version = request.form.get("version")
    changelog = request.form.get("changelog")
    game_version = request.form.get("game-version")
    notify = request.form.get("notify-followers")
    zipball = request.files.get("zipball")
    if not version or not game_version or not zipball:
        # Client side validation means that they're just being pricks if they
        # get here, so we don't need to show them a pretty error reason
        # SMILIE: this doesn't account for "external" API use --> return a json error
        return {"error": True, "reason": "All fields are required."}, 400
    test_gameversion = (
        GameVersion.query.filter(GameVersion.game_id == Mod.game_id)
        .filter(GameVersion.friendly_version == game_version)
        .first()
    )
    if not test_gameversion:
        return {"error": True, "reason": "Game version does not exist."}, 400
    game_version_id = test_gameversion.id
    if notify == None:
        notify = False
    else:
        notify = notify.lower() == "true" or notify.lower() == "yes"
    filename = secure_filename(mod.name) + "-" + secure_filename(version) + ".zip"
    base_path = os.path.join(
        secure_filename(current_user.username) + "_" + str(current_user.id), secure_filename(mod.name)
    )
    full_path = os.path.join(_cfg("storage"), base_path)
    if not os.path.exists(full_path):
        os.makedirs(full_path)
    path = os.path.join(full_path, filename)
    for v in mod.versions:
        if v.friendly_version == secure_filename(version):
            return {"error": True, "reason": "We already have this version. Did you mistype the version number?"}, 400
    if os.path.isfile(path):
        os.remove(path)
    zipball.save(path)
    if not zipfile.is_zipfile(path):
        os.remove(path)
        return {"error": True, "reason": "This is not a valid zip file."}, 400
    version = ModVersion(secure_filename(version), game_version_id, os.path.join(base_path, filename))
    version.changelog = changelog
    # Assign a sort index
    if len(mod.versions) == 0:
        version.sort_index = 0
    else:
        version.sort_index = max([v.sort_index for v in mod.versions]) + 1
    mod.versions.append(version)
    mod.updated = datetime.now()
    if notify:
        send_update_notification(mod, version, current_user)
    db.add(version)
    db.commit()
    mod.default_version_id = version.id
    db.commit()
    notify_ckan.delay(mod_id, "update")
    return {"url": url_for("mods.mod", id=mod.id, mod_name=mod.name), "id": version.id}