Esempio n. 1
0
    def test_set_task_user(self):
        @set_task_user
        def some_func():
            return get_user()

        set_user(UserProfile.objects.get(email='*****@*****.**'))
        eq_(get_user().pk, 999)
        eq_(some_func().pk, int(settings.TASK_USER_ID))
        eq_(get_user().pk, 999)
Esempio n. 2
0
    def test_set_task_user(self):
        @set_task_user
        def some_func():
            return get_user()

        set_user(UserProfile.objects.get(email='*****@*****.**'))
        eq_(get_user().pk, 999)
        eq_(some_func().pk, int(settings.TASK_USER_ID))
        eq_(get_user().pk, 999)
Esempio n. 3
0
    def save(self, addon, commit=True):
        if self.cleaned_data:
            self.instance.addon = addon
            if self.cleaned_data.get('DELETE'):
                # Existing preview.
                if self.instance.id:
                    self.instance.delete()
                # User has no desire to save this preview.
                return

            super(PreviewForm, self).save(commit=commit)
            if self.cleaned_data['upload_hash']:
                upload_hash = self.cleaned_data['upload_hash']
                upload_path = os.path.join(settings.TMP_PATH, 'preview',
                                           upload_hash)
                filetype = (os.path.splitext(upload_hash)[1][1:]
                                   .replace('-', '/'))
                if filetype in mkt.VIDEO_TYPES:
                    self.instance.update(filetype=filetype)
                    vtasks.resize_video.delay(upload_path, self.instance.pk,
                                              user_pk=mkt.get_user().pk)
                else:
                    self.instance.update(filetype='image/png')
                    tasks.resize_preview.delay(upload_path, self.instance.pk,
                                               set_modified_on=[self.instance])
Esempio n. 4
0
def log(action, *args, **kw):
    """
    e.g. mkt.log(mkt.LOG.CREATE_ADDON, []),
         mkt.log(mkt.LOG.ADD_FILE_TO_VERSION, file, version)
    """
    from mkt import get_user
    from mkt.developers.models import (ActivityLog, AppLog, CommentLog,
                                       GroupLog, UserLog, VersionLog)
    from mkt.access.models import Group
    from mkt.site.utils import log as logger_log
    from mkt.webapps.models import Webapp
    from mkt.users.models import UserProfile
    from mkt.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] == Webapp:
                AppLog(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()

        if isinstance(arg, Webapp):
            AppLog(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
Esempio n. 5
0
 def wrapper(*args, **kw):
     old_user = get_user()
     set_user(get_task_user())
     try:
         result = f(*args, **kw)
     finally:
         set_user(old_user)
     return result
Esempio n. 6
0
 def wrapper(*args, **kw):
     old_user = get_user()
     set_user(get_task_user())
     try:
         result = f(*args, **kw)
     finally:
         set_user(old_user)
     return result
Esempio n. 7
0
 def get_user(self, ident):
     pk = ident
     if pk == 'mine':
         user = mkt.get_user()
         if not user or not user.is_authenticated():
             # You must be logged in to use "mine".
             raise NotAuthenticated()
         pk = user.pk
     return pk
Esempio n. 8
0
 def get_user(self, ident):
     pk = ident
     if pk == 'mine':
         user = mkt.get_user()
         if not user or not user.is_authenticated():
             # You must be logged in to use "mine".
             raise NotAuthenticated()
         pk = user.pk
     return pk
Esempio n. 9
0
    def save(self, addon, commit=True):
        if self.cleaned_data:
            self.instance.addon = addon
            if self.cleaned_data.get("DELETE"):
                # Existing preview.
                if self.instance.id:
                    self.instance.delete()
                # User has no desire to save this preview.
                return

            super(PreviewForm, self).save(commit=commit)
            if self.cleaned_data["upload_hash"]:
                upload_hash = self.cleaned_data["upload_hash"]
                upload_path = os.path.join(settings.TMP_PATH, "preview", upload_hash)
                filetype = os.path.splitext(upload_hash)[1][1:].replace("-", "/")
                if filetype in mkt.VIDEO_TYPES:
                    self.instance.update(filetype=filetype)
                    vtasks.resize_video.delay(
                        upload_path, self.instance, user=mkt.get_user(), set_modified_on=[self.instance]
                    )
                else:
                    self.instance.update(filetype="image/png")
                    tasks.resize_preview.delay(upload_path, self.instance, set_modified_on=[self.instance])
Esempio n. 10
0
def log(action, *args, **kw):
    """
    e.g. mkt.log(mkt.LOG.CREATE_ADDON, []),
         mkt.log(mkt.LOG.ADD_FILE_TO_VERSION, file, version)
    """
    from mkt import get_user
    from mkt.developers.models import (ActivityLog, ActivityLogAttachment,
                                       AppLog, CommentLog, GroupLog, UserLog,
                                       VersionLog)
    from mkt.access.models import Group
    from mkt.site.utils import log as logger_log
    from mkt.webapps.models import Webapp
    from mkt.users.models import UserProfile
    from mkt.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()

    if 'attachments' in kw:
        formset = kw['attachments']
        storage = get_storage_class()()
        for form in formset:
            data = form.cleaned_data
            if 'attachment' in data:
                attachment = data['attachment']
                storage.save(
                    '%s/%s' %
                    (settings.REVIEWER_ATTACHMENTS_PATH, attachment.name),
                    attachment)
                ActivityLogAttachment(activity_log=al,
                                      description=data['description'],
                                      mimetype=attachment.content_type,
                                      filepath=attachment.name).save()

    for arg in args:
        if isinstance(arg, tuple):
            if arg[0] == Webapp:
                AppLog(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()

        if isinstance(arg, Webapp):
            AppLog(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
Esempio n. 11
0
 def __init__(self, *args, **kwargs):
     self.max_size = kwargs.pop('max_size', MAX_PACKAGED_APP_SIZE)
     self.user = kwargs.pop('user', get_user())
     self.addon = kwargs.pop('addon', None)
     self.file_upload = None
     super(NewPackagedAppForm, self).__init__(*args, **kwargs)
Esempio n. 12
0
def log(action, *args, **kw):
    """
    e.g. mkt.log(mkt.LOG.CREATE_ADDON, []),
         mkt.log(mkt.LOG.ADD_FILE_TO_VERSION, file, version)
    """
    from mkt import get_user
    from mkt.developers.models import (
        ActivityLog,
        ActivityLogAttachment,
        AppLog,
        CommentLog,
        GroupLog,
        UserLog,
        VersionLog,
    )
    from mkt.access.models import Group
    from mkt.site.utils import log as logger_log
    from mkt.webapps.models import Webapp
    from mkt.users.models import UserProfile
    from mkt.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()

    if "attachments" in kw:
        formset = kw["attachments"]
        storage = get_storage_class()()
        for form in formset:
            data = form.cleaned_data
            if "attachment" in data:
                attachment = data["attachment"]
                storage.save("%s/%s" % (settings.REVIEWER_ATTACHMENTS_PATH, attachment.name), attachment)
                ActivityLogAttachment(
                    activity_log=al,
                    description=data["description"],
                    mimetype=attachment.content_type,
                    filepath=attachment.name,
                ).save()

    for arg in args:
        if isinstance(arg, tuple):
            if arg[0] == Webapp:
                AppLog(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()

        if isinstance(arg, Webapp):
            AppLog(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
Esempio n. 13
0
 def some_func():
     return get_user()
Esempio n. 14
0
 def some_func():
     return get_user()