views.py 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797
  1. # GNU MediaGoblin -- federated, autonomous media hosting
  2. # Copyright (C) 2011, 2012 MediaGoblin contributors. See AUTHORS.
  3. #
  4. # This program is free software: you can redistribute it and/or modify
  5. # it under the terms of the GNU Affero General Public License as published by
  6. # the Free Software Foundation, either version 3 of the License, or
  7. # (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU Affero General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU Affero General Public License
  15. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. import json
  17. import io
  18. import mimetypes
  19. from werkzeug.datastructures import FileStorage
  20. from mediagoblin.decorators import oauth_required, require_active_login
  21. from mediagoblin.api.decorators import user_has_privilege
  22. from mediagoblin.db.models import User, MediaEntry, MediaComment, Activity
  23. from mediagoblin.tools.federation import create_activity, create_generator
  24. from mediagoblin.tools.routing import extract_url_arguments
  25. from mediagoblin.tools.response import redirect, json_response, json_error, \
  26. render_404, render_to_response
  27. from mediagoblin.meddleware.csrf import csrf_exempt
  28. from mediagoblin.submit.lib import new_upload_entry, api_upload_request, \
  29. api_add_to_feed
  30. # MediaTypes
  31. from mediagoblin.media_types.image import MEDIA_TYPE as IMAGE_MEDIA_TYPE
  32. # Getters
  33. def get_profile(request):
  34. """
  35. Gets the user's profile for the endpoint requested.
  36. For example an endpoint which is /api/{username}/feed
  37. as /api/cwebber/feed would get cwebber's profile. This
  38. will return a tuple (username, user_profile). If no user
  39. can be found then this function returns a (None, None).
  40. """
  41. username = request.matchdict["username"]
  42. user = User.query.filter_by(username=username).first()
  43. if user is None:
  44. return None, None
  45. return user, user.serialize(request)
  46. # Endpoints
  47. @oauth_required
  48. def profile_endpoint(request):
  49. """ This is /api/user/<username>/profile - This will give profile info """
  50. user, user_profile = get_profile(request)
  51. if user is None:
  52. username = request.matchdict["username"]
  53. return json_error(
  54. "No such 'user' with username '{0}'".format(username),
  55. status=404
  56. )
  57. # user profiles are public so return information
  58. return json_response(user_profile)
  59. @oauth_required
  60. def user_endpoint(request):
  61. """ This is /api/user/<username> - This will get the user """
  62. user, user_profile = get_profile(request)
  63. if user is None:
  64. username = request.matchdict["username"]
  65. return json_error(
  66. "No such 'user' with username '{0}'".format(username),
  67. status=404
  68. )
  69. return json_response({
  70. "nickname": user.username,
  71. "updated": user.created.isoformat(),
  72. "published": user.created.isoformat(),
  73. "profile": user_profile,
  74. })
  75. @oauth_required
  76. @csrf_exempt
  77. @user_has_privilege(u'uploader')
  78. def uploads_endpoint(request):
  79. """ Endpoint for file uploads """
  80. username = request.matchdict["username"]
  81. requested_user = User.query.filter_by(username=username).first()
  82. if requested_user is None:
  83. return json_error("No such 'user' with id '{0}'".format(username), 404)
  84. if request.method == "POST":
  85. # Ensure that the user is only able to upload to their own
  86. # upload endpoint.
  87. if requested_user.id != request.user.id:
  88. return json_error(
  89. "Not able to post to another users feed.",
  90. status=403
  91. )
  92. # Wrap the data in the werkzeug file wrapper
  93. if "Content-Type" not in request.headers:
  94. return json_error(
  95. "Must supply 'Content-Type' header to upload media."
  96. )
  97. mimetype = request.headers["Content-Type"]
  98. filename = mimetypes.guess_all_extensions(mimetype)
  99. filename = 'unknown' + filename[0] if filename else filename
  100. file_data = FileStorage(
  101. stream=io.BytesIO(request.data),
  102. filename=filename,
  103. content_type=mimetype
  104. )
  105. # Find media manager
  106. entry = new_upload_entry(request.user)
  107. entry.media_type = IMAGE_MEDIA_TYPE
  108. return api_upload_request(request, file_data, entry)
  109. return json_error("Not yet implemented", 501)
  110. @oauth_required
  111. @csrf_exempt
  112. def inbox_endpoint(request, inbox=None):
  113. """ This is the user's inbox
  114. Currently because we don't have the ability to represent the inbox in the
  115. database this is not a "real" inbox in the pump.io/Activity streams 1.0
  116. sense but instead just gives back all the data on the website
  117. inbox: allows you to pass a query in to limit inbox scope
  118. """
  119. username = request.matchdict["username"]
  120. user = User.query.filter_by(username=username).first()
  121. if user is None:
  122. return json_error("No such 'user' with id '{0}'".format(username), 404)
  123. # Only the user who's authorized should be able to read their inbox
  124. if user.id != request.user.id:
  125. return json_error(
  126. "Only '{0}' can read this inbox.".format(user.username),
  127. 403
  128. )
  129. if inbox is None:
  130. inbox = Activity.query
  131. # Count how many items for the "totalItems" field
  132. total_items = inbox.count()
  133. # We want to make a query for all media on the site and then apply GET
  134. # limits where we can.
  135. inbox = inbox.order_by(Activity.published.desc())
  136. # Limit by the "count" (default: 20)
  137. try:
  138. limit = int(request.args.get("count", 20))
  139. except ValueError:
  140. limit = 20
  141. # Prevent the count being too big (pump uses 200 so we shall)
  142. limit = limit if limit <= 200 else 200
  143. # Apply the limit
  144. inbox = inbox.limit(limit)
  145. # Offset (default: no offset - first <count> results)
  146. inbox = inbox.offset(request.args.get("offset", 0))
  147. # build the inbox feed
  148. feed = {
  149. "displayName": "Activities for {0}".format(user.username),
  150. "author": user.serialize(request),
  151. "objectTypes": ["activity"],
  152. "url": request.base_url,
  153. "links": {"self": {"href": request.url}},
  154. "items": [],
  155. "totalItems": total_items,
  156. }
  157. for activity in inbox:
  158. try:
  159. feed["items"].append(activity.serialize(request))
  160. except AttributeError:
  161. # As with the feed endpint this occurs because of how we our
  162. # hard-deletion method. Some activites might exist where the
  163. # Activity object and/or target no longer exist, for this case we
  164. # should just skip them.
  165. pass
  166. return json_response(feed)
  167. @oauth_required
  168. @csrf_exempt
  169. def inbox_minor_endpoint(request):
  170. """ Inbox subset for less important Activities """
  171. inbox = Activity.query.filter(
  172. (Activity.verb == "update") | (Activity.verb == "delete")
  173. )
  174. return inbox_endpoint(request=request, inbox=inbox)
  175. @oauth_required
  176. @csrf_exempt
  177. def inbox_major_endpoint(request):
  178. """ Inbox subset for most important Activities """
  179. inbox = Activity.query.filter_by(verb="post")
  180. return inbox_endpoint(request=request, inbox=inbox)
  181. @oauth_required
  182. @csrf_exempt
  183. def feed_endpoint(request, outbox=None):
  184. """ Handles the user's outbox - /api/user/<username>/feed """
  185. username = request.matchdict["username"]
  186. requested_user = User.query.filter_by(username=username).first()
  187. # check if the user exists
  188. if requested_user is None:
  189. return json_error("No such 'user' with id '{0}'".format(username), 404)
  190. if request.data:
  191. data = json.loads(request.data.decode())
  192. else:
  193. data = {"verb": None, "object": {}}
  194. if request.method in ["POST", "PUT"]:
  195. # Validate that the activity is valid
  196. if "verb" not in data or "object" not in data:
  197. return json_error("Invalid activity provided.")
  198. # Check that the verb is valid
  199. if data["verb"] not in ["post", "update", "delete"]:
  200. return json_error("Verb not yet implemented", 501)
  201. # We need to check that the user they're posting to is
  202. # the person that they are.
  203. if requested_user.id != request.user.id:
  204. return json_error(
  205. "Not able to post to another users feed.",
  206. status=403
  207. )
  208. # Handle new posts
  209. if data["verb"] == "post":
  210. obj = data.get("object", None)
  211. if obj is None:
  212. return json_error("Could not find 'object' element.")
  213. if obj.get("objectType", None) == "comment":
  214. # post a comment
  215. if not request.user.has_privilege(u'commenter'):
  216. return json_error(
  217. "Privilege 'commenter' required to comment.",
  218. status=403
  219. )
  220. comment = MediaComment(author=request.user.id)
  221. comment.unserialize(data["object"], request)
  222. comment.save()
  223. # Create activity for comment
  224. generator = create_generator(request)
  225. activity = create_activity(
  226. verb="post",
  227. actor=request.user,
  228. obj=comment,
  229. target=comment.get_entry,
  230. generator=generator
  231. )
  232. return json_response(activity.serialize(request))
  233. elif obj.get("objectType", None) == "image":
  234. # Posting an image to the feed
  235. media_id = int(extract_url_arguments(
  236. url=data["object"]["id"],
  237. urlmap=request.app.url_map
  238. )["id"])
  239. media = MediaEntry.query.filter_by(id=media_id).first()
  240. if media is None:
  241. return json_response(
  242. "No such 'image' with id '{0}'".format(media_id),
  243. status=404
  244. )
  245. if media.uploader != request.user.id:
  246. return json_error(
  247. "Privilege 'commenter' required to comment.",
  248. status=403
  249. )
  250. if not media.unserialize(data["object"]):
  251. return json_error(
  252. "Invalid 'image' with id '{0}'".format(media_id)
  253. )
  254. # Add location if one exists
  255. if "location" in data:
  256. Location.create(data["location"], self)
  257. media.save()
  258. activity = api_add_to_feed(request, media)
  259. return json_response(activity.serialize(request))
  260. elif obj.get("objectType", None) is None:
  261. # They need to tell us what type of object they're giving us.
  262. return json_error("No objectType specified.")
  263. else:
  264. # Oh no! We don't know about this type of object (yet)
  265. object_type = obj.get("objectType", None)
  266. return json_error(
  267. "Unknown object type '{0}'.".format(object_type)
  268. )
  269. # Updating existing objects
  270. if data["verb"] == "update":
  271. # Check we've got a valid object
  272. obj = data.get("object", None)
  273. if obj is None:
  274. return json_error("Could not find 'object' element.")
  275. if "objectType" not in obj:
  276. return json_error("No objectType specified.")
  277. if "id" not in obj:
  278. return json_error("Object ID has not been specified.")
  279. obj_id = int(extract_url_arguments(
  280. url=obj["id"],
  281. urlmap=request.app.url_map
  282. )["id"])
  283. # Now try and find object
  284. if obj["objectType"] == "comment":
  285. if not request.user.has_privilege(u'commenter'):
  286. return json_error(
  287. "Privilege 'commenter' required to comment.",
  288. status=403
  289. )
  290. comment = MediaComment.query.filter_by(id=obj_id).first()
  291. if comment is None:
  292. return json_error(
  293. "No such 'comment' with id '{0}'.".format(obj_id)
  294. )
  295. # Check that the person trying to update the comment is
  296. # the author of the comment.
  297. if comment.author != request.user.id:
  298. return json_error(
  299. "Only author of comment is able to update comment.",
  300. status=403
  301. )
  302. if not comment.unserialize(data["object"], request):
  303. return json_error(
  304. "Invalid 'comment' with id '{0}'".format(obj["id"])
  305. )
  306. comment.save()
  307. # Create an update activity
  308. generator = create_generator(request)
  309. activity = create_activity(
  310. verb="update",
  311. actor=request.user,
  312. obj=comment,
  313. generator=generator
  314. )
  315. return json_response(activity.serialize(request))
  316. elif obj["objectType"] == "image":
  317. image = MediaEntry.query.filter_by(id=obj_id).first()
  318. if image is None:
  319. return json_error(
  320. "No such 'image' with the id '{0}'.".format(obj["id"])
  321. )
  322. # Check that the person trying to update the comment is
  323. # the author of the comment.
  324. if image.uploader != request.user.id:
  325. return json_error(
  326. "Only uploader of image is able to update image.",
  327. status=403
  328. )
  329. if not image.unserialize(obj):
  330. return json_error(
  331. "Invalid 'image' with id '{0}'".format(obj_id)
  332. )
  333. image.generate_slug()
  334. image.save()
  335. # Create an update activity
  336. generator = create_generator(request)
  337. activity = create_activity(
  338. verb="update",
  339. actor=request.user,
  340. obj=image,
  341. generator=generator
  342. )
  343. return json_response(activity.serialize(request))
  344. elif obj["objectType"] == "person":
  345. # check this is the same user
  346. if "id" not in obj or obj["id"] != requested_user.id:
  347. return json_error(
  348. "Incorrect user id, unable to update"
  349. )
  350. requested_user.unserialize(obj)
  351. requested_user.save()
  352. generator = create_generator(request)
  353. activity = create_activity(
  354. verb="update",
  355. actor=request.user,
  356. obj=requested_user,
  357. generator=generator
  358. )
  359. return json_response(activity.serialize(request))
  360. elif data["verb"] == "delete":
  361. obj = data.get("object", None)
  362. if obj is None:
  363. return json_error("Could not find 'object' element.")
  364. if "objectType" not in obj:
  365. return json_error("No objectType specified.")
  366. if "id" not in obj:
  367. return json_error("Object ID has not been specified.")
  368. # Parse out the object ID
  369. obj_id = int(extract_url_arguments(
  370. url=obj["id"],
  371. urlmap=request.app.url_map
  372. )["id"])
  373. if obj.get("objectType", None) == "comment":
  374. # Find the comment asked for
  375. comment = MediaComment.query.filter_by(
  376. id=obj_id,
  377. author=request.user.id
  378. ).first()
  379. if comment is None:
  380. return json_error(
  381. "No such 'comment' with id '{0}'.".format(obj_id)
  382. )
  383. # Make a delete activity
  384. generator = create_generator(request)
  385. activity = create_activity(
  386. verb="delete",
  387. actor=request.user,
  388. obj=comment,
  389. generator=generator
  390. )
  391. # Unfortunately this has to be done while hard deletion exists
  392. context = activity.serialize(request)
  393. # now we can delete the comment
  394. comment.delete()
  395. return json_response(context)
  396. if obj.get("objectType", None) == "image":
  397. # Find the image
  398. entry = MediaEntry.query.filter_by(
  399. id=obj_id,
  400. uploader=request.user.id
  401. ).first()
  402. if entry is None:
  403. return json_error(
  404. "No such 'image' with id '{0}'.".format(obj_id)
  405. )
  406. # Make the delete activity
  407. generator = create_generator(request)
  408. activity = create_activity(
  409. verb="delete",
  410. actor=request.user,
  411. obj=entry,
  412. generator=generator
  413. )
  414. # This is because we have hard deletion
  415. context = activity.serialize(request)
  416. # Now we can delete the image
  417. entry.delete()
  418. return json_response(context)
  419. elif request.method != "GET":
  420. return json_error(
  421. "Unsupported HTTP method {0}".format(request.method),
  422. status=501
  423. )
  424. feed = {
  425. "displayName": "Activities by {user}@{host}".format(
  426. user=request.user.username,
  427. host=request.host
  428. ),
  429. "objectTypes": ["activity"],
  430. "url": request.base_url,
  431. "links": {"self": {"href": request.url}},
  432. "author": request.user.serialize(request),
  433. "items": [],
  434. }
  435. # Create outbox
  436. if outbox is None:
  437. outbox = Activity.query.filter_by(actor=request.user.id)
  438. else:
  439. outbox = outbox.filter_by(actor=request.user.id)
  440. # We want the newest things at the top (issue: #1055)
  441. outbox = outbox.order_by(Activity.published.desc())
  442. # Limit by the "count" (default: 20)
  443. limit = request.args.get("count", 20)
  444. try:
  445. limit = int(limit)
  446. except ValueError:
  447. limit = 20
  448. # The upper most limit should be 200
  449. limit = limit if limit < 200 else 200
  450. # apply the limit
  451. outbox = outbox.limit(limit)
  452. # Offset (default: no offset - first <count> result)
  453. outbox = outbox.offset(request.args.get("offset", 0))
  454. # Build feed.
  455. for activity in outbox:
  456. try:
  457. feed["items"].append(activity.serialize(request))
  458. except AttributeError:
  459. # This occurs because of how we hard-deletion and the object
  460. # no longer existing anymore. We want to keep the Activity
  461. # in case someone wishes to look it up but we shouldn't display
  462. # it in the feed.
  463. pass
  464. feed["totalItems"] = len(feed["items"])
  465. return json_response(feed)
  466. @oauth_required
  467. def feed_minor_endpoint(request):
  468. """ Outbox for minor activities such as updates """
  469. # If it's anything but GET pass it along
  470. if request.method != "GET":
  471. return feed_endpoint(request)
  472. outbox = Activity.query.filter(
  473. (Activity.verb == "update") | (Activity.verb == "delete")
  474. )
  475. return feed_endpoint(request, outbox=outbox)
  476. @oauth_required
  477. def feed_major_endpoint(request):
  478. """ Outbox for all major activities """
  479. # If it's anything but a GET pass it along
  480. if request.method != "GET":
  481. return feed_endpoint(request)
  482. outbox = Activity.query.filter_by(verb="post")
  483. return feed_endpoint(request, outbox=outbox)
  484. @oauth_required
  485. def object_endpoint(request):
  486. """ Lookup for a object type """
  487. object_type = request.matchdict["object_type"]
  488. try:
  489. object_id = request.matchdict["id"]
  490. except ValueError:
  491. error = "Invalid object ID '{0}' for '{1}'".format(
  492. request.matchdict["id"],
  493. object_type
  494. )
  495. return json_error(error)
  496. if object_type not in ["image"]:
  497. # not sure why this is 404, maybe ask evan. Maybe 400?
  498. return json_error(
  499. "Unknown type: {0}".format(object_type),
  500. status=404
  501. )
  502. media = MediaEntry.query.filter_by(id=object_id).first()
  503. if media is None:
  504. return json_error(
  505. "Can't find '{0}' with ID '{1}'".format(object_type, object_id),
  506. status=404
  507. )
  508. return json_response(media.serialize(request))
  509. @oauth_required
  510. def object_comments(request):
  511. """ Looks up for the comments on a object """
  512. media = MediaEntry.query.filter_by(id=request.matchdict["id"]).first()
  513. if media is None:
  514. return json_error("Can't find '{0}' with ID '{1}'".format(
  515. request.matchdict["object_type"],
  516. request.matchdict["id"]
  517. ), 404)
  518. comments = media.serialize(request)
  519. comments = comments.get("replies", {
  520. "totalItems": 0,
  521. "items": [],
  522. "url": request.urlgen(
  523. "mediagoblin.api.object.comments",
  524. object_type=media.object_type,
  525. id=media.id,
  526. qualified=True
  527. )
  528. })
  529. comments["displayName"] = "Replies to {0}".format(comments["url"])
  530. comments["links"] = {
  531. "first": comments["url"],
  532. "self": comments["url"],
  533. }
  534. return json_response(comments)
  535. ##
  536. # RFC6415 - Web Host Metadata
  537. ##
  538. def host_meta(request):
  539. """
  540. This provides the host-meta URL information that is outlined
  541. in RFC6415. By default this should provide XRD+XML however
  542. if the client accepts JSON we will provide that over XRD+XML.
  543. The 'Accept' header is used to decude this.
  544. A client should use this endpoint to determine what URLs to
  545. use for OAuth endpoints.
  546. """
  547. links = [
  548. {
  549. "rel": "lrdd",
  550. "type": "application/json",
  551. "href": request.urlgen(
  552. "mediagoblin.webfinger.well-known.webfinger",
  553. qualified=True
  554. )
  555. },
  556. {
  557. "rel": "registration_endpoint",
  558. "href": request.urlgen(
  559. "mediagoblin.oauth.client_register",
  560. qualified=True
  561. ),
  562. },
  563. {
  564. "rel": "http://apinamespace.org/oauth/request_token",
  565. "href": request.urlgen(
  566. "mediagoblin.oauth.request_token",
  567. qualified=True
  568. ),
  569. },
  570. {
  571. "rel": "http://apinamespace.org/oauth/authorize",
  572. "href": request.urlgen(
  573. "mediagoblin.oauth.authorize",
  574. qualified=True
  575. ),
  576. },
  577. {
  578. "rel": "http://apinamespace.org/oauth/access_token",
  579. "href": request.urlgen(
  580. "mediagoblin.oauth.access_token",
  581. qualified=True
  582. ),
  583. },
  584. {
  585. "rel": "http://apinamespace.org/activitypub/whoami",
  586. "href": request.urlgen(
  587. "mediagoblin.webfinger.whoami",
  588. qualified=True
  589. ),
  590. },
  591. ]
  592. if "application/json" in request.accept_mimetypes:
  593. return json_response({"links": links})
  594. # provide XML+XRD
  595. return render_to_response(
  596. request,
  597. "mediagoblin/api/host-meta.xml",
  598. {"links": links},
  599. mimetype="application/xrd+xml"
  600. )
  601. def lrdd_lookup(request):
  602. """
  603. This is the lrdd endpoint which can lookup a user (or
  604. other things such as activities). This is as specified by
  605. RFC6415.
  606. The cleint must provide a 'resource' as a GET parameter which
  607. should be the query to be looked up.
  608. """
  609. if "resource" not in request.args:
  610. return json_error("No resource parameter", status=400)
  611. resource = request.args["resource"]
  612. if "@" in resource:
  613. # Lets pull out the username
  614. resource = resource[5:] if resource.startswith("acct:") else resource
  615. username, host = resource.split("@", 1)
  616. # Now lookup the user
  617. user = User.query.filter_by(username=username).first()
  618. if user is None:
  619. return json_error(
  620. "Can't find 'user' with username '{0}'".format(username))
  621. return json_response([
  622. {
  623. "rel": "http://webfinger.net/rel/profile-page",
  624. "href": user.url_for_self(request.urlgen),
  625. "type": "text/html"
  626. },
  627. {
  628. "rel": "self",
  629. "href": request.urlgen(
  630. "mediagoblin.api.user",
  631. username=user.username,
  632. qualified=True
  633. )
  634. },
  635. {
  636. "rel": "activity-outbox",
  637. "href": request.urlgen(
  638. "mediagoblin.api.feed",
  639. username=user.username,
  640. qualified=True
  641. )
  642. }
  643. ])
  644. else:
  645. return json_error("Unrecognized resource parameter", status=404)
  646. def whoami(request):
  647. """ /api/whoami - HTTP redirect to API profile """
  648. if request.user is None:
  649. return json_error("Not logged in.", status=401)
  650. profile = request.urlgen(
  651. "mediagoblin.api.user.profile",
  652. username=request.user.username,
  653. qualified=True
  654. )
  655. return redirect(request, location=profile)