Exemplo n.º 1
0
Arquivo: views.py Projeto: bea/kitsune
def watch_ready(request):
    """Start watching ready-for-l10n revisions."""
    if request.LANGUAGE_CODE != settings.WIKI_DEFAULT_LANGUAGE:
        raise Http404
    ReadyRevisionEvent.notify(request.user)
    statsd.incr('wiki.watches.ready')
    return HttpResponse()
Exemplo n.º 2
0
    def test_product_specific_ready(self):
        """Verify product-specific ready for l10n notifications."""
        # Add a Firefox OS watcher.
        ReadyRevisionEvent.notify(user(save=True), product='firefox-os')

        # Create a document for Firefox
        doc = document(save=True)
        doc.products.add(product(slug='firefox', save=True))

        # Mark a revision a ready for L10n. There should be only one email
        # to the watcher created in setUp.
        self._mark_as_ready_revision(doc=doc)
        eq_(1, len(mail.outbox))
        _assert_ready_mail(mail.outbox[0])

        # Add firefox-os to the document's products. Mark as ready for l10n,
        # and there should be two new emails.
        doc.products.add(product(slug='firefox-os', save=True))
        self._mark_as_ready_revision(doc=doc)
        eq_(3, len(mail.outbox))
        _assert_ready_mail(mail.outbox[1])
        _assert_ready_mail(mail.outbox[2])

        # Add a Firefox watcher, mark as ready for l10n, and there should
        # be three new emails.
        ReadyRevisionEvent.notify(user(save=True), product='firefox')
        self._mark_as_ready_revision(doc=doc)
        eq_(6, len(mail.outbox))
Exemplo n.º 3
0
def watch_ready(request):
    """Start watching ready-for-l10n revisions."""
    if request.LANGUAGE_CODE != settings.WIKI_DEFAULT_LANGUAGE:
        raise Http404
    ReadyRevisionEvent.notify(request.user)
    statsd.incr('wiki.watches.ready')
    return HttpResponse()
Exemplo n.º 4
0
    def test_product_specific_ready(self):
        """Verify product-specific ready for l10n notifications."""
        # Add a Firefox OS watcher.
        ReadyRevisionEvent.notify(UserFactory(), product='firefox-os')

        # Create a document for Firefox
        doc = DocumentFactory()
        doc.products.add(ProductFactory(slug='firefox'))

        # Mark a revision a ready for L10n. There should be only one email
        # to the watcher created in setUp.
        self._mark_as_ready_revision(doc=doc)
        eq_(1, len(mail.outbox))
        _assert_ready_mail(mail.outbox[0])

        # Add firefox-os to the document's products. Mark as ready for l10n,
        # and there should be two new emails.
        doc.products.add(ProductFactory(slug='firefox-os'))
        self._mark_as_ready_revision(doc=doc)
        eq_(3, len(mail.outbox))
        _assert_ready_mail(mail.outbox[1])
        _assert_ready_mail(mail.outbox[2])

        # Add a Firefox watcher, mark as ready for l10n, and there should
        # be three new emails.
        ReadyRevisionEvent.notify(UserFactory(), product='firefox')
        self._mark_as_ready_revision(doc=doc)
        eq_(6, len(mail.outbox))
Exemplo n.º 5
0
    def setUp(self):
        """Have a user watch for revision approval. Log in."""
        self.ready_watcher = UserFactory(email='*****@*****.**')
        ReadyRevisionEvent.notify(self.ready_watcher)

        readyer = UserFactory()
        add_permission(readyer, Revision, 'mark_ready_for_l10n')
        self.client.login(username=readyer.username, password='******')
Exemplo n.º 6
0
    def setUp(self):
        """Have a user watch for revision approval. Log in."""
        self.ready_watcher = UserFactory(email="*****@*****.**")
        ReadyRevisionEvent.notify(self.ready_watcher)

        readyer = UserFactory()
        add_permission(readyer, Revision, "mark_ready_for_l10n")
        self.client.login(username=readyer.username, password="******")
Exemplo n.º 7
0
    def setUp(self):
        """Have a user watch for revision approval. Log in."""
        self.ready_watcher = user(email="*****@*****.**", save=True)
        ReadyRevisionEvent.notify(self.ready_watcher)

        readyer = user(save=True)
        add_permission(readyer, Revision, "mark_ready_for_l10n")
        self.client.login(username=readyer.username, password="******")
Exemplo n.º 8
0
    def setUp(self):
        """Have a user watch for revision approval. Log in."""
        self.ready_watcher = user(email='*****@*****.**', save=True)
        ReadyRevisionEvent.notify(self.ready_watcher)

        readyer = user(save=True)
        add_permission(readyer, Revision, 'mark_ready_for_l10n')
        self.client.login(username=readyer.username, password='******')
Exemplo n.º 9
0
def unwatch_ready(request, product=None):
    """Stop watching ready-for-l10n revisions for a given product."""
    if request.LANGUAGE_CODE != settings.WIKI_DEFAULT_LANGUAGE:
        raise Http404

    kwargs = {}
    if product is not None:
        kwargs['product'] = product
    ReadyRevisionEvent.stop_notifying(request.user, **kwargs)

    return HttpResponse()
Exemplo n.º 10
0
def unwatch_ready(request, product=None):
    """Stop watching ready-for-l10n revisions for a given product."""
    if request.LANGUAGE_CODE != settings.WIKI_DEFAULT_LANGUAGE:
        raise Http404

    kwargs = {}
    if product is not None:
        kwargs['product'] = product
    ReadyRevisionEvent.stop_notifying(request.user, **kwargs)

    return HttpResponse()
Exemplo n.º 11
0
def watch_ready(request, product=None):
    """Start watching ready-for-l10n revisions for given product."""
    if request.LANGUAGE_CODE != settings.WIKI_DEFAULT_LANGUAGE:
        raise Http404

    kwargs = {}
    if product is not None:
        kwargs['product'] = product
    ReadyRevisionEvent.notify(request.user, **kwargs)
    statsd.incr('wiki.watches.ready')

    return HttpResponse()
Exemplo n.º 12
0
    def test_user_watching_both(self):
        """If a single person is watching ready and approved revisions and a
        revision becomes ready, send only the readiness email, not the approval
        one."""
        # Have the Approved watcher watch Ready as well:
        ReadyRevisionEvent.notify(self.approved_watcher)

        self._review_revision(is_ready=True, significance=MEDIUM_SIGNIFICANCE)
        # 1 mail to watcher, 1 to creator, 1 to reviewer
        eq_(3, len(mail.outbox))
        _assert_ready_mail(mail.outbox[0])
        _assert_creator_mail(mail.outbox[1])
Exemplo n.º 13
0
def watch_ready(request, product=None):
    """Start watching ready-for-l10n revisions for given product."""
    if request.LANGUAGE_CODE != settings.WIKI_DEFAULT_LANGUAGE:
        raise Http404

    kwargs = {}
    if product is not None:
        kwargs['product'] = product
    ReadyRevisionEvent.notify(request.user, **kwargs)
    statsd.incr('wiki.watches.ready')

    return HttpResponse()
Exemplo n.º 14
0
    def test_user_watching_both(self):
        """If a single person is watching ready and approved revisions and a
        revision becomes ready, send only the readiness email, not the approval
        one."""
        # Have the Approved watcher watch Ready as well:
        ReadyRevisionEvent.notify(self.approved_watcher)

        self._review_revision(is_ready=True, significance=MEDIUM_SIGNIFICANCE)
        # 1 mail to watcher, 1 to creator, 1 to reviewer
        eq_(3, len(mail.outbox))
        _assert_ready_mail(mail.outbox[0])
        _assert_creator_mail(mail.outbox[1])
Exemplo n.º 15
0
def render_readouts(request, readouts, template, locale=None, extra_data=None,
                    product=None):
    """Render a readouts, possibly with overview page.

    Use the given template, pass the template the given readouts, limit the
    considered data to the given locale, and pass along anything in the
    `extra_data` dict to the template in addition to the standard data.

    """
    current_locale = locale or request.LANGUAGE_CODE
    on_default_locale = request.LANGUAGE_CODE == settings.WIKI_DEFAULT_LANGUAGE

    default_kwargs = {
        'locale': settings.WIKI_DEFAULT_LANGUAGE,
    }
    locale_kwargs = {
        'locale': request.LANGUAGE_CODE,
    }
    ready_kwargs = {}

    if product is not None:
        default_kwargs['product'] = product.slug
        locale_kwargs['product'] = product.slug
        ready_kwargs['product'] = product.slug

    data = {'readouts': SortedDict((slug, class_(request, locale=locale,
                                                 product=product))
                                   for slug, class_ in readouts.iteritems()
                                   if class_.should_show_to(request)),
            'default_locale': settings.WIKI_DEFAULT_LANGUAGE,
            'default_locale_name':
                LOCALES[settings.WIKI_DEFAULT_LANGUAGE].native,
            'current_locale': current_locale,
            'current_locale_name': LOCALES[current_locale].native,
            'request_locale_name': LOCALES[request.LANGUAGE_CODE].native,
            'is_watching_default_approved':
                ApproveRevisionInLocaleEvent.is_notifying(
                    request.user, **default_kwargs),
            'is_watching_other_approved':
                None if on_default_locale
                else ApproveRevisionInLocaleEvent.is_notifying(
                    request.user, **locale_kwargs),
            'is_watching_default_locale':
                ReviewableRevisionInLocaleEvent.is_notifying(
                    request.user, **default_kwargs),
            'is_watching_other_locale':
                None if on_default_locale
                else ReviewableRevisionInLocaleEvent.is_notifying(
                    request.user, **locale_kwargs),
            'is_watching_default_ready':
                ReadyRevisionEvent.is_notifying(request.user, **ready_kwargs),
            'on_default_locale': on_default_locale,
            'announce_form': AnnouncementForm(),
            'announcements': Announcement.get_for_locale_name(current_locale),
            'product': product,
            'products': Product.objects.filter(visible=True),
        }
    if extra_data:
        data.update(extra_data)
    return render(request, 'dashboards/' + template, data)
Exemplo n.º 16
0
def render_readouts(request, readouts, template, locale=None, extra_data=None, product=None):
    """Render a readouts, possibly with overview page.

    Use the given template, pass the template the given readouts, limit the
    considered data to the given locale, and pass along anything in the
    `extra_data` dict to the template in addition to the standard data.

    """
    current_locale = locale or request.LANGUAGE_CODE
    on_default_locale = request.LANGUAGE_CODE == settings.WIKI_DEFAULT_LANGUAGE

    default_kwargs = {
        'locale': settings.WIKI_DEFAULT_LANGUAGE,
    }
    locale_kwargs = {
        'locale': request.LANGUAGE_CODE,
    }
    ready_kwargs = {}

    if product is not None:
        default_kwargs['product'] = product.slug
        locale_kwargs['product'] = product.slug
        ready_kwargs['product'] = product.slug

    data = {
        'readouts': OrderedDict((slug, class_(request, locale=locale,
                                              product=product))
                                for slug, class_ in readouts.items()
                                if class_.should_show_to(request)),
        'default_locale': settings.WIKI_DEFAULT_LANGUAGE,
        'default_locale_name': LOCALES[settings.WIKI_DEFAULT_LANGUAGE].native,
        'current_locale': current_locale,
        'current_locale_name': LOCALES[current_locale].native,
        'request_locale_name': LOCALES[request.LANGUAGE_CODE].native,
        'is_watching_default_approved':
            ApproveRevisionInLocaleEvent.is_notifying(request.user, **default_kwargs),
        'is_watching_other_approved': (
            None if on_default_locale
            else ApproveRevisionInLocaleEvent.is_notifying(request.user, **locale_kwargs)),
        'is_watching_default_locale': (
            ReviewableRevisionInLocaleEvent.is_notifying(request.user, **default_kwargs)),
        'is_watching_other_locale': (
            None if on_default_locale
            else ReviewableRevisionInLocaleEvent.is_notifying(request.user, **locale_kwargs)),
        'is_watching_default_ready': ReadyRevisionEvent.is_notifying(request.user, **ready_kwargs),
        'on_default_locale': on_default_locale,
        'announce_form': AnnouncementForm(),
        'announcements': Announcement.get_for_locale_name(current_locale),
        'product': product,
        'products': Product.objects.filter(visible=True),
    }
    if extra_data:
        data.update(extra_data)
    return render(request, 'dashboards/' + template, data)
Exemplo n.º 17
0
def mark_ready_for_l10n_revision(request, document_slug, revision_id):
    """Mark a revision as ready for l10n."""
    revision = get_object_or_404(Revision, pk=revision_id,
                                 document__slug=document_slug)

    if not revision.document.allows(request.user, 'mark_ready_for_l10n'):
        raise PermissionDenied

    if revision.can_be_readied_for_localization():
        # We don't use update(), because that wouldn't update
        # Document.latest_localizable_revision.
        revision.is_ready_for_localization = True
        revision.readied_for_localization = datetime.now()
        revision.readied_for_localization_by = request.user
        revision.save()

        ReadyRevisionEvent(revision).fire(exclude=request.user)

        return HttpResponse(json.dumps({'message': revision_id}))

    return HttpResponseBadRequest()
Exemplo n.º 18
0
def _set_up_ready_watcher():
    """Make a user who watches for revision readiness."""
    ready_watcher = UserFactory(email="*****@*****.**")
    ReadyRevisionEvent.notify(ready_watcher)
    return ready_watcher
Exemplo n.º 19
0
def _set_up_ready_watcher():
    """Make a user who watches for revision readiness."""
    ready_watcher = UserFactory(email='*****@*****.**')
    ReadyRevisionEvent.notify(ready_watcher)
    return ready_watcher
Exemplo n.º 20
0
def _set_up_ready_watcher():
    """Make a user who watches for revision readiness."""
    ready_watcher = user(email='*****@*****.**', save=True)
    ReadyRevisionEvent.notify(ready_watcher)
    return ready_watcher
Exemplo n.º 21
0
def unwatch_ready(request):
    """Stop watching ready-for-l10n revisions."""
    if request.LANGUAGE_CODE != settings.WIKI_DEFAULT_LANGUAGE:
        raise Http404
    ReadyRevisionEvent.stop_notifying(request.user)
    return HttpResponse()
Exemplo n.º 22
0
def _set_up_ready_watcher():
    """Make a user who watches for revision readiness."""
    ready_watcher = user(email="*****@*****.**", save=True)
    ReadyRevisionEvent.notify(ready_watcher)
    return ready_watcher
Exemplo n.º 23
0
def review_revision(request, document_slug, revision_id):
    """Review a revision of a wiki document."""
    rev = get_object_or_404(Revision,
                            pk=revision_id,
                            document__slug=document_slug)
    doc = rev.document

    if not doc.allows(request.user, 'review_revision'):
        raise PermissionDenied

    form = ReviewForm(
        initial={
            'needs_change': doc.needs_change,
            'needs_change_comment': doc.needs_change_comment
        })

    # Don't ask significance if this doc is a translation or if it has no
    # former approved versions:
    should_ask_significance = not doc.parent and doc.current_revision

    based_on_revs = doc.revisions.all()
    last_approved_date = getattr(doc.current_revision, 'created',
                                 datetime.fromordinal(1))
    based_on_revs = based_on_revs.filter(created__gt=last_approved_date)
    revision_contributors = list(
        set(based_on_revs.values_list('creator__username', flat=True)))

    # Don't include the reviewer in the recent contributors list.
    if request.user.username in revision_contributors:
        revision_contributors.remove(request.user.username)

    if request.method == 'POST':
        form = ReviewForm(request.POST)
        if form.is_valid() and not rev.reviewed:
            # Don't allow revisions to be reviewed twice
            rev.is_approved = 'approve' in request.POST
            rev.reviewer = request.user
            rev.reviewed = datetime.now()

            if should_ask_significance and form.cleaned_data['significance']:
                rev.significance = form.cleaned_data['significance']
            elif not should_ask_significance and not doc.parent:
                # This is a new document without approved revisions.
                # Significance is MAJOR.
                rev.significance = MAJOR_SIGNIFICANCE

            # If document is localizable and revision was approved and
            # user has permission, set the is_ready_for_localization value.
            if (doc.allows(request.user, 'mark_ready_for_l10n')
                    and rev.is_approved
                    and rev.can_be_readied_for_localization()):
                rev.is_ready_for_localization = form.cleaned_data[
                    'is_ready_for_localization']

                # If the revision is ready for l10n, store the date
                # and the user.
                if rev.is_ready_for_localization:
                    rev.readied_for_localization = rev.reviewed
                    rev.readied_for_localization_by = rev.reviewer

            rev.save()

            # Update the needs change bit (if approved, default language and
            # user has permission).
            if (doc.locale == settings.WIKI_DEFAULT_LANGUAGE
                    and doc.allows(request.user, 'edit_needs_change')
                    and rev.is_approved):
                doc.needs_change = form.cleaned_data['needs_change']
                doc.needs_change_comment = \
                    form.cleaned_data['needs_change_comment']
                doc.save()

            # Send notifications of approvedness and readiness:
            if rev.is_ready_for_localization or rev.is_approved:
                events = [ApproveRevisionInLocaleEvent(rev)]
                if rev.is_ready_for_localization:
                    events.append(ReadyRevisionEvent(rev))
                ApprovedOrReadyUnion(*events).fire(
                    exclude=[rev.creator, request.user])

            # Send an email (not really a "notification" in the sense that
            # there's a Watch table entry) to revision creator.
            msg = form.cleaned_data['comment']
            send_reviewed_notification.delay(rev, doc, msg)
            send_contributor_notification(based_on_revs, rev, doc, msg)

            statsd.incr('wiki.review')
            render_document_cascade.delay(doc)

            return HttpResponseRedirect(
                reverse('wiki.document_revisions', args=[document_slug]))

    if doc.parent:  # A translation
        # For diffing the based_on revision against, to help the user see if he
        # translated all the recent changes:
        parent_revision = (rev.based_on
                           or doc.parent.localizable_or_latest_revision())
        template = 'wiki/review_translation.html'
    else:
        parent_revision = None
        template = 'wiki/review_revision.html'

    data = {
        'revision': rev,
        'document': doc,
        'form': form,
        'parent_revision': parent_revision,
        'revision_contributors': list(revision_contributors),
        'should_ask_significance': should_ask_significance
    }
    return render(request, template, data)
Exemplo n.º 24
0
Arquivo: views.py Projeto: bea/kitsune
def unwatch_ready(request):
    """Stop watching ready-for-l10n revisions."""
    if request.LANGUAGE_CODE != settings.WIKI_DEFAULT_LANGUAGE:
        raise Http404
    ReadyRevisionEvent.stop_notifying(request.user)
    return HttpResponse()