@login.login_required
-@blueprint.route('/<int:user_id>/<username>/printer/<int:printer_id>/print', methods=['GET', 'POST'])
-def printer_print(user_id, username, printer_id):
- assert user_id == login.current_user.id
- assert username == login.current_user.username
-
+@blueprint.route('/printer/<int:printer_id>/print', methods=['GET', 'POST'])
+def printer_print(printer_id):
printer = hardware.Printer.query.get(printer_id)
if printer is None:
flask.abort(404)
+ # PERMISSIONS
+ # the printer must either belong to this user, or be
+ # owned by a friend
+ if printer.owner.id == login.current_user.id:
+ # fine
+ pass
+ elif printer.id in [p.id for p in login.current_user.friends_printers()]:
+ # fine
+ pass
+ else:
+ flask.abort(404)
+
form = PrintForm()
# Note that the form enforces access permissions: People can't
# submit a valid printer-id that's not owned by the user or one of
printer_id=p.id) }}">Overview</a>
<a class="btn btn-default btn-xs" href="{{
url_for('printer_print.printer_print',
- user_id=current_user.id,
- username=current_user.username,
printer_id=p.id) }}">Send message</a>
</li>
{% endfor %}
<li>{{ p.name }} (owned by @{{ p.owner.username }})
<a class="btn btn-default btn-xs" href="{{
url_for('printer_print.printer_print',
- user_id=current_user.id,
- username=current_user.username,
printer_id=p.id) }}">Send message</a>
</li>
{% endfor %}
<h1>Printer {{ printer.name }}</h1>
<a href="{{ url_for('printer_print.printer_print',
- user_id=current_user.id,
- username=current_user.username,
printer_id=printer.id) }}">
Print a thing
</a>