# Fill user if not already
token = authorization[u"oauth_token"]
- access_token = AccessToken.query.filter_by(token=token).first()
- if access_token is not None and request.user is None:
- user_id = access_token.user
+ request.access_token = AccessToken.query.filter_by(token=token).first()
+ if request.access_token is not None and request.user is None:
+ user_id = request.access_token.user
request.user = User.query.filter_by(id=user_id).first()
return controller(request, *args, **kwargs)
from mediagoblin.decorators import oauth_required, require_active_login
from mediagoblin.federation.decorators import user_has_privilege
from mediagoblin.db.models import User, MediaEntry, MediaComment, Activity
+from mediagoblin.tools.federation import create_activity, create_generator
from mediagoblin.tools.routing import extract_url_arguments
from mediagoblin.tools.response import redirect, json_response, json_error, \
render_404, render_to_response
comment = MediaComment(author=request.user.id)
comment.unserialize(data["object"], request)
comment.save()
+
+ # Create activity for comment
+ generator = create_generator(request)
+ activity = create_activity(
+ verb="post",
+ actor=request.user,
+ obj=comment,
+ target=comment.get_entry,
+ generator=generator
+ )
+
data = {
"verb": "post",
"object": comment.serialize(request)
from mediagoblin import mg_globals
from mediagoblin.tools.response import json_response
from mediagoblin.tools.text import convert_to_tag_list_of_dicts
-from mediagoblin.tools.federation import create_activity
+from mediagoblin.tools.federation import create_activity, create_generator
from mediagoblin.db.models import MediaEntry, ProcessingMetaData
from mediagoblin.processing import mark_entry_failed
from mediagoblin.processing.task import ProcessMedia
add_comment_subscription(request.user, entry)
# Create activity
- create_activity("post", entry, entry.uploader)
+ create_activity(
+ verb="post",
+ obj=entry,
+ actor=entry.uploader,
+ generator=create_generator(request)
+ )
entry.save()
run_process_media(entry, feed_url)
from mediagoblin.db.models import Activity, Generator, User
-def create_activity(verb, obj, actor, target=None):
+def create_generator(request):
+ """
+ This creates a Generator object based on the Client associated with the
+ OAuth credentials used. If the request has invalid OAuth credentials or
+ no OAuth credentials None is returned.
+ """
+ if not hasattr(request, "access_token"):
+ return None
+
+ client = request.access_token.get_requesttoken.get_client
+
+ # Check if there is a generator already
+ generator = Generator.query.filter_by(
+ name=client.application_name,
+ object_type="client"
+ ).first()
+ if generator is None:
+ generator = Generator(
+ name=client.application_name,
+ object_type="client"
+ )
+ generator.save()
+
+ return generator
+
+
+
+def create_activity(verb, obj, actor, target=None, generator=None):
"""
This will create an Activity object which for the obj if possible
and save it. The verb should be one of the following:
if verb not in Activity.VALID_VERBS:
raise ValueError("A invalid verb type has been supplied.")
- # This should exist as we're creating it by the migration for Generator
- generator = Generator.query.filter_by(name="GNU MediaGoblin").first()
if generator is None:
- generator = Generator(
- name="GNU MediaGoblin",
- object_type="service"
- )
- generator.save()
+ # This should exist as we're creating it by the migration for Generator
+ generator = Generator.query.filter_by(name="GNU MediaGoblin").first()
+ if generator is None:
+ generator = Generator(
+ name="GNU MediaGoblin",
+ object_type="service"
+ )
+ generator.save()
activity = Activity(verb=verb)
activity.set_object(obj)