示例#1
0
def save_from_email_reply(reply_text):
    parser = CommEmailParser(reply_text)
    if hasattr(parser, 'decode_error'):
        return False

    uuid = parser.get_uuid()

    if not uuid:
        return False
    try:
        tok = CommunicationThreadToken.objects.get(uuid=uuid)
    except CommunicationThreadToken.DoesNotExist:
        log.error('An email was skipped with non-existing uuid %s.' % uuid)
        return False

    if user_has_perm_thread(tok.thread, tok.user) and tok.is_valid():
        t, note = create_comm_note(tok.thread.addon, tok.thread.version,
                                   tok.user, parser.get_body())
        log.info('A new note has been created (from %s using tokenid %s).' %
                 (tok.user.id, uuid))
        return note
    elif tok.is_valid():
        log.error('%s did not have perms to reply to comm email thread %s.' %
                  (tok.user.email, tok.thread.id))
    else:
        log.error('%s tried to use an invalid comm token for thread %s.' %
                  (tok.user.email, tok.thread.id))

    return False
示例#2
0
文件: utils.py 项目: KKcorps/zamboni
def save_from_email_reply(reply_text):
    parser = CommEmailParser(reply_text)
    if hasattr(parser, "decode_error"):
        return False

    uuid = parser.get_uuid()

    if not uuid:
        return False
    try:
        tok = CommunicationThreadToken.objects.get(uuid=uuid)
    except CommunicationThreadToken.DoesNotExist:
        log.error("An email was skipped with non-existing uuid %s." % uuid)
        return False

    if user_has_perm_thread(tok.thread, tok.user) and tok.is_valid():
        t, note = create_comm_note(tok.thread.addon, tok.thread.version, tok.user, parser.get_body())
        log.info("A new note has been created (from %s using tokenid %s)." % (tok.user.id, uuid))
        return note
    elif tok.is_valid():
        log.error("%s did not have perms to reply to comm email thread %s." % (tok.user.email, tok.thread.id))
    else:
        log.error("%s tried to use an invalid comm token for thread %s." % (tok.user.email, tok.thread.id))

    return False
示例#3
0
文件: utils.py 项目: petercpg/zamboni
def save_from_email_reply(reply_text):
    parser = CommEmailParser(reply_text)
    if hasattr(parser, "decode_error"):
        return False

    uuid = parser.get_uuid()

    if not uuid:
        return False
    try:
        tok = CommunicationThreadToken.objects.get(uuid=uuid)
    except CommunicationThreadToken.DoesNotExist:
        log.error("An email was skipped with non-existing uuid %s." % uuid)
        return False

    if user_has_perm_thread(tok.thread, tok.user) and tok.is_valid():
        # Deduce an appropriate note type.
        note_type = comm.NO_ACTION
        if tok.user.addonuser_set.filter(addon=tok.thread.addon).exists():
            note_type = comm.DEVELOPER_COMMENT
        elif acl.action_allowed_user(tok.user, "Apps", "Review"):
            note_type = comm.REVIEWER_COMMENT

        t, note = create_comm_note(
            tok.thread.addon, tok.thread.version, tok.user, parser.get_body(), note_type=note_type
        )
        log.info("A new note has been created (from %s using tokenid %s)." % (tok.user.id, uuid))
        return note
    elif tok.is_valid():
        log.error("%s did not have perms to reply to comm email thread %s." % (tok.user.email, tok.thread.id))
    else:
        log.error("%s tried to use an invalid comm token for thread %s." % (tok.user.email, tok.thread.id))

    return False
示例#4
0
文件: api.py 项目: prodigeni/zamboni
    def has_object_permission(self, request, view, obj):
        """
        Make sure we give correct permissions to read/write the thread.
        """
        if not request.user.is_authenticated() or obj.read_permission_public:
            return obj.read_permission_public

        return user_has_perm_thread(obj, request.amo_user)
示例#5
0
    def has_object_permission(self, request, view, obj):
        """
        Make sure we give correct permissions to read/write the thread.
        """
        if not request.user.is_authenticated() or obj.read_permission_public:
            return obj.read_permission_public

        return user_has_perm_thread(obj, request.amo_user)
示例#6
0
def save_from_email_reply(reply_text):
    from mkt.comm.utils import create_comm_note

    log.debug("Saving from email reply")

    parser = CommEmailParser(reply_text)
    if hasattr(parser, 'decode_error'):
        return False

    uuid = parser.get_uuid()

    if not uuid:
        return False
    try:
        tok = CommunicationThreadToken.objects.get(uuid=uuid)
    except CommunicationThreadToken.DoesNotExist:
        log.error('An email was skipped with non-existing uuid %s.' % uuid)
        return False

    thread = tok.thread
    if user_has_perm_thread(thread, tok.user) and tok.is_valid():
        # Deduce an appropriate note type.
        note_type = comm.NO_ACTION

        # grep: comm-content-type.
        if (thread.obj.__class__ == Webapp
                and tok.user.addonuser_set.filter(addon=thread.obj).exists()):
            note_type = comm.DEVELOPER_COMMENT
        elif (thread.obj.__class__ == Extension
              and tok.user.extension_set.filter(id=thread.obj.id).exists()):
            note_type = comm.DEVELOPER_COMMENT
        elif (acl.action_allowed_user(tok.user, 'Apps', 'Review')
              or acl.action_allowed_user(tok.user, 'ContentTools',
                                         'AddonReview')):
            note_type = comm.REVIEWER_PUBLIC_COMMENT

        t, note = create_comm_note(tok.thread.obj,
                                   tok.thread.version,
                                   tok.user,
                                   parser.get_body(),
                                   note_type=note_type)
        log.info('A new note has been created (from %s using tokenid %s).' %
                 (tok.user.id, uuid))
        return note
    elif tok.is_valid():
        log.error('%s did not have perms to reply to comm email thread %s.' %
                  (tok.user.email, tok.thread.id))
    else:
        log.error('%s tried to use an invalid comm token for thread %s.' %
                  (tok.user.email, tok.thread.id))

    return False
示例#7
0
def save_from_email_reply(reply_text):
    from mkt.comm.utils import create_comm_note

    log.debug("Saving from email reply")

    parser = CommEmailParser(reply_text)
    if hasattr(parser, 'decode_error'):
        return False

    uuid = parser.get_uuid()

    if not uuid:
        return False
    try:
        tok = CommunicationThreadToken.objects.get(uuid=uuid)
    except CommunicationThreadToken.DoesNotExist:
        log.error('An email was skipped with non-existing uuid %s.' % uuid)
        return False

    thread = tok.thread
    if user_has_perm_thread(thread, tok.user) and tok.is_valid():
        # Deduce an appropriate note type.
        note_type = comm.NO_ACTION

        # grep: comm-content-type.
        if (thread.obj.__class__ == Webapp and
                tok.user.addonuser_set.filter(addon=thread.obj).exists()):
            note_type = comm.DEVELOPER_COMMENT
        elif (thread.obj.__class__ == Extension and
                tok.user.extension_set.filter(id=thread.obj.id).exists()):
            note_type = comm.DEVELOPER_COMMENT
        elif (acl.action_allowed_user(tok.user, 'Apps', 'Review') or
              acl.action_allowed_user(tok.user, 'ContentTools',
                                      'AddonReview')):
            note_type = comm.REVIEWER_COMMENT

        t, note = create_comm_note(tok.thread.obj, tok.thread.version,
                                   tok.user, parser.get_body(),
                                   note_type=note_type)
        log.info('A new note has been created (from %s using tokenid %s).'
                 % (tok.user.id, uuid))
        return note
    elif tok.is_valid():
        log.error('%s did not have perms to reply to comm email thread %s.'
                  % (tok.user.email, tok.thread.id))
    else:
        log.error('%s tried to use an invalid comm token for thread %s.'
                  % (tok.user.email, tok.thread.id))

    return False
示例#8
0
def create_comm_note(app, version, author, body, note_type=comm.NO_ACTION,
                     perms=None):
    """
    Creates a note on an app version's thread.
    Creates a thread if a thread doesn't already exist.
    CC's app's Mozilla contacts to auto-join thread.

    app -- app object.
    version -- app version.
    author -- UserProfile for the note's author.
    body -- string/text for note comment.
    note_type -- integer for note_type (mkt constant), defaults to 0/NO_ACTION
                 (e.g. comm.APPROVAL, comm.REJECTION, comm.NO_ACTION).
    perms -- object of groups to grant permission to, will set flags on Thread.
             (e.g. {'developer': False, 'staff': True}).

    """
    if not waffle.switch_is_active('comm-dashboard'):
        return None, None

    # Dict of {'read_permission_GROUP_TYPE': boolean}.
    # Perm for dev, reviewer, senior_reviewer, moz_contact, staff all True by
    # default.
    perms = perms or {}
    create_perms = dict(('read_permission_%s' % key, has_perm)
                        for key, has_perm in perms.iteritems())

    # Get or create thread w/ custom permissions.
    thread = None
    threads = app.threads.filter(version=version)
    if threads.exists():
        thread = threads[0]
    else:
        # See if user has perms to create thread for this app.
        thread = CommunicationThread(addon=app, version=version,
                                     **create_perms)
        if user_has_perm_thread(thread, author):
            thread.save()
        else:
            raise PermissionDenied

    # Create note.
    note = thread.notes.create(note_type=note_type, body=body, author=author,
                               **create_perms)

    post_create_comm_note(note)

    return thread, note
示例#9
0
文件: utils.py 项目: imclab/olympia
def save_from_email_reply(reply_text):
    parser = CommEmailParser(reply_text)
    uuid = parser.get_uuid()

    if not uuid:
        return False
    try:
        tok = CommunicationThreadToken.objects.get(uuid=uuid)
    except CommunicationThreadToken.DoesNotExist:
        log.error('An email was skipped with non-existing uuid %s' % uuid)
        return False

    if (user_has_perm_thread(tok.thread, tok.user) and tok.is_valid()):
        n = CommunicationNote.objects.create(note_type=comm.NO_ACTION,
            thread=tok.thread, author=tok.user, body=parser.get_body())
        log.info('A new note has been created (from %s using tokenid %s)' %
                 (tok.user.id, uuid))
        return n
    return False
示例#10
0
def save_from_email_reply(reply_text):
    parser = CommEmailParser(reply_text)
    uuid = parser.get_uuid()

    if not uuid:
        return False
    try:
        tok = CommunicationThreadToken.objects.get(uuid=uuid)
    except CommunicationThreadToken.DoesNotExist:
        log.error('An email was skipped with non-existing uuid %s' % uuid)
        return False

    if (user_has_perm_thread(tok.thread, tok.user) and tok.is_valid()):
        n = CommunicationNote.objects.create(note_type=comm.NO_ACTION,
                                             thread=tok.thread,
                                             author=tok.user,
                                             body=parser.get_body())
        log.info('A new note has been created (from %s using tokenid %s)' %
                 (tok.user.id, uuid))
        return n
    return False
示例#11
0
 def _eq_obj_perm(self, val):
     if self.type == 'note':
         eq_(user_has_perm_note(self.obj, self.user), val)
     else:
         eq_(user_has_perm_thread(self.obj, self.user), val)
示例#12
0
 def _eq_obj_perm(self, val):
     if self.type == 'note':
         eq_(user_has_perm_note(self.obj, self.user), val)
     else:
         eq_(user_has_perm_thread(self.obj, self.user), val)