]> git.aero2k.de Git - sirius.git/commitdiff
simplifying print URL and adding more explicit permissions
authorMatt Webb <matt@interconnected.org>
Sun, 1 Mar 2015 14:24:12 +0000 (14:24 +0000)
committerMatt Webb <matt@interconnected.org>
Sun, 1 Mar 2015 14:24:12 +0000 (14:24 +0000)
sirius/web/printer_print.py
sirius/web/templates/overview.html
sirius/web/templates/printer_overview.html

index 3caaaa8ce3f262ed8d66c1ebd5c93c4219d4c626..f014954e6a1a615616e6bb784685e702078dd46e 100644 (file)
@@ -32,15 +32,24 @@ class PrintForm(flask_wtf.Form):
 
 
 @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
index c5e09f54ed7ddf132a844b080e6f14974651a0ca..65907654a0b773ce9e506c83f38412ebd2249873 100644 (file)
@@ -21,8 +21,6 @@
                                                                        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 %}
@@ -31,8 +29,6 @@
                <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 %}
index 5cff05c7962e91ec3ef4fdbae822a287a786045d..9d3e7dcc2ecfb9ca97710c12ed4b4c00d3db99b0 100644 (file)
@@ -6,8 +6,6 @@
 <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>