예제 #1
0
 def test_pseudo_objects(self):
     """
     If we give an argument of (Addon, 3615) ensure we get
     Addon.objects.get(pk=3615).
     """
     a = ActivityLog()
     a.arguments = [(Addon, 3615)]
     assert a.arguments[0] == Addon.objects.get(pk=3615)
예제 #2
0
 def test_pseudo_objects(self):
     """
     If we give an argument of (Addon, 3615) ensure we get
     Addon.objects.get(pk=3615).
     """
     a = ActivityLog()
     a.arguments = [(Addon, 3615)]
     eq_(a.arguments[0], Addon.objects.get(pk=3615))
예제 #3
0
 def test_pseudo_objects(self):
     """
     If we give an argument of (Addon, 3615) ensure we get
     Addon.objects.get(pk=3615).
     """
     activity_log = ActivityLog()
     activity_log.arguments = [(Addon, 3615)]
     assert activity_log.arguments[0] == Addon.objects.get(pk=3615)
예제 #4
0
def log(action, *args, **kw):
    """
    e.g. amo.log(amo.LOG.CREATE_ADDON, []),
         amo.log(amo.LOG.ADD_FILE_TO_VERSION, file, version)
    """
    from olympia.access.models import Group
    from olympia.addons.models import Addon
    from olympia.amo import get_user, logger_log
    from olympia.devhub.models import (ActivityLog, AddonLog, CommentLog,
                                       GroupLog, UserLog, VersionLog)
    from olympia.users.models import UserProfile
    from olympia.versions.models import Version

    user = kw.get('user', get_user())

    if not user:
        logger_log.warning('Activity log called with no user: %s' % action.id)
        return

    al = ActivityLog(user=user, action=action.id)
    al.arguments = args
    if 'details' in kw:
        al.details = kw['details']
    al.save()

    if 'details' in kw and 'comments' in al.details:
        CommentLog(comments=al.details['comments'], activity_log=al).save()

    # TODO(davedash): post-remora this may not be necessary.
    if 'created' in kw:
        al.created = kw['created']
        # Double save necessary since django resets the created date on save.
        al.save()

    for arg in args:
        if isinstance(arg, tuple):
            if arg[0] == Addon:
                AddonLog(addon_id=arg[1], activity_log=al).save()
            elif arg[0] == Version:
                VersionLog(version_id=arg[1], activity_log=al).save()
            elif arg[0] == UserProfile:
                UserLog(user_id=arg[1], activity_log=al).save()
            elif arg[0] == Group:
                GroupLog(group_id=arg[1], activity_log=al).save()
        elif isinstance(arg, Addon):
            AddonLog(addon=arg, activity_log=al).save()
        elif isinstance(arg, Version):
            VersionLog(version=arg, activity_log=al).save()
        elif isinstance(arg, UserProfile):
            # Index by any user who is mentioned as an argument.
            UserLog(activity_log=al, user=arg).save()
        elif isinstance(arg, Group):
            GroupLog(group=arg, activity_log=al).save()

    # Index by every user
    UserLog(activity_log=al, user=user).save()
    return al
예제 #5
0
def log(action, *args, **kw):
    """
    e.g. amo.log(amo.LOG.CREATE_ADDON, []),
         amo.log(amo.LOG.ADD_FILE_TO_VERSION, file, version)
    """
    from olympia.access.models import Group
    from olympia.addons.models import Addon
    from olympia.amo import get_user, logger_log
    from olympia.devhub.models import (
        ActivityLog, AddonLog, CommentLog, GroupLog, UserLog, VersionLog)
    from olympia.users.models import UserProfile
    from olympia.versions.models import Version

    user = kw.get('user', get_user())

    if not user:
        logger_log.warning('Activity log called with no user: %s' % action.id)
        return

    al = ActivityLog(user=user, action=action.id)
    al.arguments = args
    if 'details' in kw:
        al.details = kw['details']
    al.save()

    if 'details' in kw and 'comments' in al.details:
        CommentLog(comments=al.details['comments'], activity_log=al).save()

    # TODO(davedash): post-remora this may not be necessary.
    if 'created' in kw:
        al.created = kw['created']
        # Double save necessary since django resets the created date on save.
        al.save()

    for arg in args:
        if isinstance(arg, tuple):
            if arg[0] == Addon:
                AddonLog(addon_id=arg[1], activity_log=al).save()
            elif arg[0] == Version:
                VersionLog(version_id=arg[1], activity_log=al).save()
            elif arg[0] == UserProfile:
                UserLog(user_id=arg[1], activity_log=al).save()
            elif arg[0] == Group:
                GroupLog(group_id=arg[1], activity_log=al).save()
        elif isinstance(arg, Addon):
            AddonLog(addon=arg, activity_log=al).save()
        elif isinstance(arg, Version):
            VersionLog(version=arg, activity_log=al).save()
        elif isinstance(arg, UserProfile):
            # Index by any user who is mentioned as an argument.
            UserLog(activity_log=al, user=arg).save()
        elif isinstance(arg, Group):
            GroupLog(group=arg, activity_log=al).save()

    # Index by every user
    UserLog(activity_log=al, user=user).save()
    return al
예제 #6
0
 def test_bad_arguments(self):
     a = ActivityLog()
     a.arguments = []
     a.action = amo.LOG.ADD_USER_WITH_ROLE.id
     assert a.to_string() == 'Something magical happened.'
예제 #7
0
 def test_bad_arguments(self):
     a = ActivityLog()
     a.arguments = []
     a.action = amo.LOG.ADD_USER_WITH_ROLE.id
     eq_(a.to_string(), 'Something magical happened.')
예제 #8
0
 def test_bad_arguments(self):
     activity_log = ActivityLog()
     activity_log.arguments = []
     activity_log.action = amo.LOG.ADD_USER_WITH_ROLE.id
     assert activity_log.to_string() == 'Something magical happened.'