|
18 | 18 | from .s3 import upload_pbw, upload_asset, get_link_for_archive |
19 | 19 | from .settings import config |
20 | 20 | from .discord import audit_log |
| 21 | +from .discourse import get_topic_url_for_app, is_valid_topic_url, user_owns_discourse_topic, topic_url_to_id |
21 | 22 | from . import discord, discourse |
22 | 23 |
|
23 | 24 | parent_app = None |
@@ -649,6 +650,47 @@ def new_app_icon(app_id, size): |
649 | 650 |
|
650 | 651 | return jsonify(success=True, id=new_image_id, size=size) |
651 | 652 |
|
| 653 | +@devportal_api.route("/app/<app_id>/forum", methods=['GET']) |
| 654 | +def get_app_forum_url(app_id): |
| 655 | + try: |
| 656 | + app = App.query.filter(App.id == app_id).one() |
| 657 | + except NoResultFound: |
| 658 | + return jsonify(error="Unknown app", e="app.notfound"), 404 |
| 659 | + |
| 660 | + return jsonify(forum_url=get_topic_url_for_app(app)) |
| 661 | + |
| 662 | +@devportal_api.route("/app/<app_id>/forum", methods=['POST']) |
| 663 | +def update_app_forum_url(app_id): |
| 664 | + try: |
| 665 | + req = request.json |
| 666 | + except BadRequest: |
| 667 | + return jsonify(error="Invalid POST body. Expected JSON", e="body.invalid"), 400 |
| 668 | + |
| 669 | + if req is None: |
| 670 | + return jsonify(error="Invalid POST body. Expected JSON and 'Content-Type: application/json'", e="request.invalid"), 400 |
| 671 | + |
| 672 | + if "new_url" not in req: |
| 673 | + return jsonify(error="Missing required field: new_url", e="missing.field.new_url"), 400 |
| 674 | + |
| 675 | + try: |
| 676 | + app = App.query.filter(App.id == app_id).one() |
| 677 | + except NoResultFound: |
| 678 | + return jsonify(error="Unknown app", e="app.notfound"), 404 |
| 679 | + |
| 680 | + if not is_users_developer_id(app.developer_id): |
| 681 | + return jsonify(error="You do not have permission to modify that app", e="permission.denied"), 403 |
| 682 | + |
| 683 | + if not is_valid_topic_url(req["new_url"]): |
| 684 | + return jsonify(error="Invalid URL for new discourse topic", e="url.invalid"), 400 |
| 685 | + |
| 686 | + if not user_owns_discourse_topic(req["new_url"]): |
| 687 | + return jsonify(error="You are not the creator of the provided discourse topic", e="url.permissions.missing") |
| 688 | + |
| 689 | + app.discourse_topic_id = topic_url_to_id(req["new_url"]) |
| 690 | + db.session.commit() |
| 691 | + |
| 692 | + return jsonify(success=True, new_url=app.discourse_topic_id) |
| 693 | + |
652 | 694 |
|
653 | 695 |
|
654 | 696 | @devportal_api.route('/wizard/rename/<developer_id>', methods=['POST']) |
|
0 commit comments