Ejemplo n.º 1
0
def release_delete(request, project_slug, release_slug):
    release = get_object_or_404(Release,
                                slug=release_slug,
                                project__slug=project_slug)
    if request.method == 'POST':
        import copy
        release_ = copy.copy(release)
        release.delete()
        messages.success(
            request,
            _("The release '%s' was deleted.") % release.full_name)

        # ActionLog & Notification
        nt = 'project_release_deleted'
        context = {'release': release_, 'sender': request.user}
        action_logging(request.user, [release_.project], nt, context=context)
        if settings.ENABLE_NOTICES:
            txnotification.send_observation_notices_for(release_.project,
                                                        signal=nt,
                                                        extra_context=context)

        return HttpResponseRedirect(
            reverse('project_detail', args=(project_slug, )))
    else:
        return HttpResponseRedirect(
            reverse('release_edit', args=(project_slug, release_slug)))
Ejemplo n.º 2
0
def team_request_deny(request, project_slug, language_code):

    team_request = get_object_or_404(TeamRequest, project__slug=project_slug,
        language__code=language_code)
    project = team_request.project

    if request.POST:
        try:
            team_request.delete()
            messages.success(request, _(
                "You rejected the request by '%(user)s' for a '%(team)s' team."
                ) % {'team':team_request.language.name,
                     'user':team_request.user})

            # ActionLog & Notification
            # TODO: Use signals
            nt = 'project_team_request_denied'
            context = {'team_request': team_request,
                       'performer': request.user}

            # Logging action
            action_logging(request.user, [project], nt, context=context)

            if settings.ENABLE_NOTICES:
                # Send notification for those that are observing this project
                txnotification.send_observation_notices_for(project,
                        signal=nt, extra_context=context)
                # Send notification for maintainers and the user
                notification.send(set(itertools.chain(project.maintainers.all(),
                    [team_request.user])), nt, context)

        except IntegrityError, e:
            transaction.rollback()
            logger.error("Something weird happened: %s" % str(e))
Ejemplo n.º 3
0
def team_join_withdraw(request, project_slug, language_code):

    team = get_object_or_404(Team, project__slug=project_slug,
        language__code=language_code)
    project = team.project
    access_request = get_object_or_404(TeamAccessRequest, team__pk=team.pk,
        user__pk=request.user.pk)

    if request.POST:
        try:
            access_request.delete()
            messages.success(request,_(
                "You withdrew your request to join the '%s' team."
                ) % team.language.name)

            # ActionLog & Notification
            # TODO: Use signals
            nt = 'project_team_join_withdrawn'
            context = {'access_request': access_request,
                       'performer': request.user,}

            # Logging action
            action_logging(request.user, [project, team], nt, context=context)

            if settings.ENABLE_NOTICES:
                # Send notification for those that are observing this project
                txnotification.send_observation_notices_for(project,
                        signal=nt, extra_context=context)
                # Send notification for maintainers, coordinators
                notification.send(set(itertools.chain(project.maintainers.all(),
                    team.coordinators.all())), nt, context)

        except IntegrityError, e:
            transaction.rollback()
            logger.error("Something weird happened: %s" % str(e))
Ejemplo n.º 4
0
def release_delete(request, project_slug, release_slug):
    release = get_object_or_404(Release, slug=release_slug,
                                project__slug=project_slug)
    if request.method == 'POST':
        import copy
        release_ = copy.copy(release)
        release.delete()
        messages.success(request,
                        _("The release '%s' was deleted.") % release.full_name)

        # ActionLog & Notification
        nt = 'project_release_deleted'
        context = {'release': release_,
                   'sender': request.user}
        action_logging(request.user, [release_.project], nt, context=context)
        if settings.ENABLE_NOTICES:
            txnotification.send_observation_notices_for(release_.project,
                                signal=nt, extra_context=context)

        return HttpResponseRedirect(reverse('project_detail',
                                     args=(project_slug,)))
    else:
        return render_to_response('projects/release_confirm_delete.html',
                                  {'release': release,},
                                  context_instance=RequestContext(request))
Ejemplo n.º 5
0
def team_delete(request, project_slug, language_code):

    project = get_object_or_404(Project, slug=project_slug)
    team = get_object_or_404(Team, project__pk=project.pk,
        language__code=language_code)

    if request.method == "POST":
        _team = copy.copy(team)
        team.delete()
        messages.success(request, _("The team '%s' was deleted.") % _team.language.name)

        # ActionLog & Notification
        # TODO: Use signals
        nt = 'project_team_deleted'
        context = {'team': _team}

        # Logging action
        action_logging(request.user, [project, _team], nt, context=context)

        if settings.ENABLE_NOTICES:
            # Send notification for those that are observing this project
            txnotification.send_observation_notices_for(project,
                    signal=nt, extra_context=context)
            # Send notification for maintainers
            notification.send(project.maintainers.all(), nt, context)

        return HttpResponseRedirect(reverse("team_list",
                                     args=(project_slug,)))
    else:
        return render_to_response("teams/team_confirm_delete.html",
                                  {"team": team,},
                                  context_instance=RequestContext(request))
Ejemplo n.º 6
0
def team_join_request(request, project_slug, language_code):

    team = get_object_or_404(Team,
                             project__slug=project_slug,
                             language__code=language_code)
    project = team.project

    if request.POST:
        if request.user in team.members.all() or \
            request.user in team.coordinators.all():
            messages.warning(
                request,
                _("You are already on the '%s' team.") % team.language.name)
        try:
            # send pre_team_join signal
            cla_sign = 'cla_sign' in request.POST and request.POST['cla_sign']
            cla_sign = cla_sign and True
            pre_team_join.send(sender='join_team_view',
                               project=project,
                               user=request.user,
                               cla_sign=cla_sign)

            access_request = TeamAccessRequest(team=team, user=request.user)
            access_request.save()
            messages.success(
                request,
                _("You requested to join the '%s' team.") % team.language.name)
            # ActionLog & Notification
            # TODO: Use signals
            nt = 'project_team_join_requested'
            context = {
                'access_request': access_request,
                'sender': request.user
            }

            # Logging action
            action_logging(request.user, [project, team], nt, context=context)

            if settings.ENABLE_NOTICES:
                # Send notification for those that are observing this project
                txnotification.send_observation_notices_for(
                    project, signal=nt, extra_context=context)
                # Send notification for maintainers and coordinators
                notification.send(
                    set(
                        itertools.chain(project.maintainers.all(),
                                        team.coordinators.all())), nt, context)

        except IntegrityError:
            transaction.rollback()
            messages.error(
                request,
                _("You already requested to join the '%s' team.") %
                team.language.name)
        except ClaNotSignedError, e:
            messages.error(request,
                             _("You need to sign the Contribution License Agreement for this "\
                "project before you join a translation team"))
Ejemplo n.º 7
0
def team_join_approve(request, project_slug, language_code, username):

    team = get_object_or_404(Team,
                             project__slug=project_slug,
                             language__code=language_code)
    project = team.project
    user = get_object_or_404(User, username=username)
    access_request = get_object_or_404(TeamAccessRequest,
                                       team__pk=team.pk,
                                       user__pk=user.pk)

    if request.POST:
        if user in team.members.all() or \
            user in team.coordinators.all():
            messages.warning(
                request,
                _("User '%(user)s' is already on the '%(team)s' team.") % {
                    'user': user,
                    'team': team.language.name
                })
            access_request.delete()
        try:
            team.members.add(user)
            team.save()
            messages.success(
                request,
                _("You added '%(user)s' to the '%(team)s' team.") % {
                    'user': user,
                    'team': team.language.name
                })
            access_request.delete()

            # ActionLog & Notification
            # TODO: Use signals
            nt = 'project_team_join_approved'
            context = {
                'access_request': access_request,
                'sender': request.user
            }

            # Logging action
            action_logging(request.user, [project, team], nt, context=context)

            if settings.ENABLE_NOTICES:
                # Send notification for those that are observing this project
                txnotification.send_observation_notices_for(
                    project, signal=nt, extra_context=context)
                # Send notification for maintainers, coordinators and the user
                notification.send(
                    set(
                        itertools.chain(project.maintainers.all(),
                                        team.coordinators.all(),
                                        [access_request.user])), nt, context)

        except IntegrityError, e:
            transaction.rollback()
            logger.error("Something weird happened: %s" % str(e))
Ejemplo n.º 8
0
def _project_create_update(request, project_slug=None, template_name="projects/project_form.html"):
    """
    Handler for creating and updating a project.

    This function helps to eliminate duplication of code between those two
    actions, and also allows to apply different permission checks in the
    respective views.
    """

    if project_slug:
        project = get_object_or_404(Project, slug=project_slug)
    else:
        project = None

    if request.method == "POST":
        project_form = ProjectForm(request.POST, instance=project, prefix="project")
        if project_form.is_valid():
            project = project_form.save(commit=False)
            project_id = project.id
            # Only here the owner is written to the project model
            if not project_id:
                project.owner = request.user

            # provide the form data to any signal handlers before project_save
            Signal.send(signals.pre_proj_save, sender=Project, instance=project, form=project_form)
            project.save()
            project_form.save_m2m()

            # TODO: Not sure if here is the best place to put it
            Signal.send(signals.post_proj_save_m2m, sender=Project, instance=project, form=project_form)

            # ActionLog & Notification
            context = {"project": project}
            if not project_id:
                nt = "project_added"
                action_logging(request.user, [project], nt, context=context)
            else:
                nt = "project_changed"
                action_logging(request.user, [project], nt, context=context)
                if settings.ENABLE_NOTICES:
                    txnotification.send_observation_notices_for(project, signal=nt, extra_context=context)

            return HttpResponseRedirect(reverse("project_detail", args=[project.slug]))
    else:
        # Make the current user the maintainer when adding a project
        if project:
            initial_data = {}
        else:
            initial_data = {"maintainers": [request.user.pk]}

        project_form = ProjectForm(instance=project, prefix="project", initial=initial_data)

    return render_to_response(
        template_name, {"project_form": project_form, "project": project}, context_instance=RequestContext(request)
    )
Ejemplo n.º 9
0
def _notify_resourcewatchers(project, resource, signal):
    """
    Notify watchers of a resource add/change
    """
    context = {"project": project, "resource": resource}
    logger.debug("addon-watches: Sending notification for '%s'" % resource)
    if signal == "project_resource_added":
        observed_instance = project
    else:
        observed_instance = resource
    txnotification.send_observation_notices_for(observed_instance, signal=signal, extra_context=context)
Ejemplo n.º 10
0
def _notify_translationwatchers(resource, language):
    """
    Notify the watchers for a specific TranslationWatch
    """
    context = {"project": resource.project, "resource": resource, "language": language}

    twatch = TranslationWatch.objects.get_or_create(resource=resource, language=language)[0]

    logger.debug("addon-watches: Sending notification for '%s'" % twatch)
    txnotification.send_observation_notices_for(
        twatch, signal="project_resource_translation_changed", extra_context=context
    )
Ejemplo n.º 11
0
def team_leave(request, project_slug, language_code):

    team = get_object_or_404(Team,
                             project__slug=project_slug,
                             language__code=language_code)
    project = team.project

    if request.POST:
        try:
            if (team.members.filter(username=request.user.username).exists()
                    or team.reviewers.filter(
                        username=request.user.username).exists()):
                team.members.remove(request.user)
                team.reviewers.remove(request.user)
                messages.info(
                    request,
                    _("You left the '%s' team.") % team.language.name)

                # ActionLog & Notification
                # TODO: Use signals
                nt = 'project_team_left'
                context = {
                    'team': team,
                    'performer': request.user,
                    'sender': request.user
                }

                # Logging action
                action_logging(request.user, [project, team],
                               nt,
                               context=context)

                if settings.ENABLE_NOTICES:
                    # Send notification for those that are observing this project
                    txnotification.send_observation_notices_for(
                        project, signal=nt, extra_context=context)
                    # Send notification for maintainers, coordinators
                    notification.send(
                        set(
                            itertools.chain(project.maintainers.all(),
                                            team.coordinators.all())), nt,
                        context)
            else:
                messages.info(
                    request,
                    _("You are not in the '%s' team.") % team.language.name)

        except IntegrityError, e:
            transaction.rollback()
            logger.error("Something weird happened: %s" % str(e))
Ejemplo n.º 12
0
def on_resource_delete(sender, instance, user,**kwargs):
    """
    Called on resource post delete to file an action log for this action.
    Passes a user object along with the deleted instance for use in the logging
    mechanism.
    """
    # ActionLog & Notification
    context = {'resource': instance}
    object_list = [instance.project, instance]
    nt = 'project_resource_deleted'
    action_logging(user, object_list, nt, context=context)
    if settings.ENABLE_NOTICES:
        txnotification.send_observation_notices_for(instance.project,
                signal=nt, extra_context=context)
Ejemplo n.º 13
0
def _delete_project(request, project):
    import copy
    project_ = copy.copy(project)
    project.delete()

    messages.success(request, _("The project '%s' was deleted." % project.name))

    # ActionLog & Notification
    nt = 'project_deleted'
    context = {'project': project_}
    action_logging(request.user, [project_], nt, context=context)
    if settings.ENABLE_NOTICES:
        txnotification.send_observation_notices_for(project_,
            signal=nt, extra_context=context)
Ejemplo n.º 14
0
def exit(request, project_slug, lang_code, resource_slug=None, *args, **kwargs):
    """
    Exiting Lotte
    """

    # Permissions handling
    # Project should always be available
    project = get_object_or_404(Project, slug=project_slug)
    team = Team.objects.get_or_none(project, lang_code)
    check = ProjectPermission(request.user)
    if not check.submit_translations(team or project) and not\
        check.maintain(project):
        return permission_denied(request)

    language = Language.objects.by_code_or_alias(lang_code)

    resources = []
    if resource_slug:
        resources = Resource.objects.filter(slug=resource_slug, project=project)
        if not resources:
            raise Http404
        url = reverse('resource_detail', args=[project_slug, resource_slug])
    else:
        resources = Resource.objects.filter(project=project)
        url = reverse('project_detail', args=[project_slug])

    if request.POST.get('updated', None) == 'true':
        modified = True
        # ActionLog & Notification
        for resource in resources:
            nt = 'project_resource_translated'
            context = {'project': project,
                       'resource': resource,
                       'language': language}
            object_list = [project, resource, language]
            action_logging(request.user, object_list, nt, context=context)
            if settings.ENABLE_NOTICES:
                txnotification.send_observation_notices_for(project,
                        signal=nt, extra_context=context)
    else:
        modified = False

    lotte_done.send(None, request=request, resources=resources,
        language=language, modified=modified)

    if request.is_ajax():
        json = simplejson.dumps(dict(redirect=url))
        return HttpResponse(json, mimetype='application/json')

    return HttpResponseRedirect(url)
Ejemplo n.º 15
0
def team_join_request(request, project_slug, language_code):

    team = get_object_or_404(Team, project__slug=project_slug,
        language__code=language_code)
    project = team.project

    if request.POST:
        if request.user in team.members.all() or \
            request.user in team.coordinators.all():
            messages.warning(request,
                          _("You are already on the '%s' team.") % team.language.name)
        try:
            # send pre_team_join signal
            cla_sign = 'cla_sign' in request.POST and request.POST['cla_sign']
            cla_sign = cla_sign and True
            pre_team_join.send(sender='join_team_view', project=project,
                               user=request.user, cla_sign=cla_sign)

            access_request = TeamAccessRequest(team=team, user=request.user)
            access_request.save()
            messages.success(request,
                _("You requested to join the '%s' team.") % team.language.name)
            # ActionLog & Notification
            # TODO: Use signals
            nt = 'project_team_join_requested'
            context = {'access_request': access_request,
                       'sender': request.user}

            # Logging action
            action_logging(request.user, [project, team], nt, context=context)

            if settings.ENABLE_NOTICES:
                # Send notification for those that are observing this project
                txnotification.send_observation_notices_for(project,
                        signal=nt, extra_context=context)
                # Send notification for maintainers and coordinators
                notification.send(set(itertools.chain(project.maintainers.all(),
                    team.coordinators.all())), nt, context)


        except IntegrityError:
            transaction.rollback()
            messages.error(request,
                            _("You already requested to join the '%s' team.")
                             % team.language.name)
        except ClaNotSignedError, e:
            messages.error(request,
                             _("You need to sign the Contribution License Agreement for this "\
                "project before you join a translation team"))
Ejemplo n.º 16
0
def on_resource_delete(sender, instance, user, **kwargs):
    """
    Called on resource post delete to file an action log for this action.
    Passes a user object along with the deleted instance for use in the logging
    mechanism.
    """
    # ActionLog
    context = {'resource': instance,
               'sender': user}
    object_list = [instance.project, instance]
    nt = 'project_resource_deleted'
    action_logging(user, object_list, nt, context=context)
    if settings.ENABLE_NOTICES:
        txnotification.send_observation_notices_for(instance.project,
                signal=nt, extra_context=context)
Ejemplo n.º 17
0
def send_notices_for_formats(signal, context):
    """
    Send notifications to watching users that a resource has been changed.

    Args:
        signal: The signal to send.
        context: The context of the signal.
    """
    resource = context['resource']
    project = context['project']
    language = context['language']

    txnotification.send_observation_notices_for(project, signal, context)
    if language == resource.source_language:
        _notify_all_on_source_change(resource, context)
Ejemplo n.º 18
0
def send_notices_for_formats(signal, context):
    """
    Send notifications to watching users that a resource has been changed.

    Args:
        signal: The signal to send.
        context: The context of the signal.
    """
    resource = context['resource']
    project = context['project']
    language = context['language']

    txnotification.send_observation_notices_for(project, signal, context)
    if language == resource.source_language:
        _notify_all_on_source_change(resource, context)
Ejemplo n.º 19
0
def _notify_resourcewatchers(project, resource, signal):
    """
    Notify watchers of a resource add/change
    """
    context = {
        'project': project,
        'resource': resource,
    }
    logger.debug("addon-watches: Sending notification for '%s'" % resource)
    if signal == 'project_resource_added':
        observed_instance = project
    else:
        observed_instance = resource
    txnotification.send_observation_notices_for(observed_instance,
                                                signal=signal,
                                                extra_context=context)
Ejemplo n.º 20
0
def _notify_all_on_source_change(resource, context):
    """
    Send notifications to everyone involved with a resource.

    Args:
        resource: The updated resource.
    """
    signal_name = 'project_resource_translation_changed'
    msg = "addon-watches: Sending notification for '%s'"
    TWatch = get_model('watches', 'TranslationWatch')

    for l in resource.available_languages:
        twatch = TWatch.objects.get_or_create(resource=resource, language=l)[0]
        logger.debug(msg % twatch)
        txnotification.send_observation_notices_for(twatch,
                                                    signal=signal_name,
                                                    extra_context=context)
Ejemplo n.º 21
0
def _delete_project(request, project):
    project_ = copy.copy(project)
    project.delete()
    Permission.objects.filter(content_type__model="project",
                              object_id=project_.id).delete()

    messages.success(request,
                     _("The project '%s' was deleted." % project.name))

    # ActionLog & Notification
    nt = 'project_deleted'
    context = {'project': project_, 'sender': request.user}
    action_logging(request.user, [project_], nt, context=context)
    if settings.ENABLE_NOTICES:
        txnotification.send_observation_notices_for(project_,
                                                    signal=nt,
                                                    extra_context=context)
Ejemplo n.º 22
0
def _notify_all_on_source_change(resource, context):
    """
    Send notifications to everyone involved with a resource.

    Args:
        resource: The updated resource.
    """
    signal_name = 'project_resource_translation_changed'
    msg = "addon-watches: Sending notification for '%s'"
    TWatch = get_model('watches', 'TranslationWatch')

    for l in resource.available_languages:
        twatch = TWatch.objects.get_or_create(resource=resource, language=l)[0]
        logger.debug(msg % twatch)
        txnotification.send_observation_notices_for(
            twatch, signal=signal_name, extra_context=context
        )
Ejemplo n.º 23
0
def team_request_approve(request, project_slug, language_code):

    team_request = get_object_or_404(TeamRequest,
                                     project__slug=project_slug,
                                     language__code=language_code)
    project = team_request.project

    if request.POST:
        try:
            team = Team(project=team_request.project,
                        language=team_request.language,
                        creator=request.user)
            team.save()
            team.coordinators.add(team_request.user)
            team.save()
            team_request.delete()
            messages.success(
                request,
                _("You approved the '%(team)s' team requested by '%(user)s'.")
                % {
                    'team': team.language.name,
                    'user': team_request.user
                })

            # ActionLog & Notification
            # TODO: Use signals
            nt = 'project_team_added'
            context = {'team': team, 'sender': request.user}

            # Logging action
            action_logging(request.user, [project, team], nt, context=context)

            if settings.ENABLE_NOTICES:
                # Send notification for those that are observing this project
                txnotification.send_observation_notices_for(
                    project, signal=nt, extra_context=context)
                # Send notification for maintainers and coordinators
                notification.send(
                    set(
                        itertools.chain(project.maintainers.all(),
                                        team.coordinators.all())), nt, context)

        except IntegrityError, e:
            transaction.rollback()
            logger.error("Something weird happened: %s" % str(e))
Ejemplo n.º 24
0
def _notify_translationwatchers(resource, language):
    """
    Notify the watchers for a specific TranslationWatch
    """
    context = {
        'project': resource.project,
        'resource': resource,
        'language': language,
    }

    twatch = TranslationWatch.objects.get_or_create(resource=resource,
                                                    language=language)[0]

    logger.debug("addon-watches: Sending notification for '%s'" % twatch)
    txnotification.send_observation_notices_for(
        twatch,
        signal='project_resource_translation_changed',
        extra_context=context)
Ejemplo n.º 25
0
def team_join_approve(request, project_slug, language_code, username):

    team = get_object_or_404(Team, project__slug=project_slug,
        language__code=language_code)
    project = team.project
    user = get_object_or_404(User, username=username)
    access_request = get_object_or_404(TeamAccessRequest, team__pk=team.pk,
        user__pk=user.pk)

    if request.POST:
        if user in team.members.all() or \
            user in team.coordinators.all():
            messages.warning(request,
                            _("User '%(user)s' is already on the '%(team)s' team.")
                            % {'user':user, 'team':team.language.name})
            access_request.delete()
        try:
            team.members.add(user)
            team.save()
            messages.success(request,
                            _("You added '%(user)s' to the '%(team)s' team.")
                            % {'user':user, 'team':team.language.name})
            access_request.delete()

            # ActionLog & Notification
            # TODO: Use signals
            nt = 'project_team_join_approved'
            context = {'access_request': access_request,
                       'sender': request.user}

            # Logging action
            action_logging(request.user, [project, team], nt, context=context)

            if settings.ENABLE_NOTICES:
                # Send notification for those that are observing this project
                txnotification.send_observation_notices_for(project,
                        signal=nt, extra_context=context)
                # Send notification for maintainers, coordinators and the user
                notification.send(set(itertools.chain(project.maintainers.all(),
                    team.coordinators.all(), [access_request.user])), nt, context)

        except IntegrityError, e:
            transaction.rollback()
            logger.error("Something weird happened: %s" % str(e))
Ejemplo n.º 26
0
def team_request_deny(request, project_slug, language_code):

    team_request = get_object_or_404(TeamRequest,
                                     project__slug=project_slug,
                                     language__code=language_code)
    project = team_request.project

    if request.POST:
        try:
            team_request.delete()
            messages.success(
                request,
                _("You rejected the request by '%(user)s' for a '%(team)s' team."
                  ) % {
                      'team': team_request.language.name,
                      'user': team_request.user
                  })

            # ActionLog & Notification
            # TODO: Use signals
            nt = 'project_team_request_denied'
            context = {
                'team_request': team_request,
                'performer': request.user,
                'sender': request.user
            }

            # Logging action
            action_logging(request.user, [project], nt, context=context)

            if settings.ENABLE_NOTICES:
                # Send notification for those that are observing this project
                txnotification.send_observation_notices_for(
                    project, signal=nt, extra_context=context)
                # Send notification for maintainers and the user
                notification.send(
                    set(
                        itertools.chain(project.maintainers.all(),
                                        [team_request.user])), nt, context)

        except IntegrityError, e:
            transaction.rollback()
            logger.error("Something weird happened: %s" % str(e))
Ejemplo n.º 27
0
def team_join_withdraw(request, project_slug, language_code):

    team = get_object_or_404(Team,
                             project__slug=project_slug,
                             language__code=language_code)
    project = team.project
    access_request = get_object_or_404(TeamAccessRequest,
                                       team__pk=team.pk,
                                       user__pk=request.user.pk)

    if request.POST:
        try:
            access_request.delete()
            messages.success(
                request,
                _("You withdrew your request to join the '%s' team.") %
                team.language.name)

            # ActionLog & Notification
            # TODO: Use signals
            nt = 'project_team_join_withdrawn'
            context = {
                'access_request': access_request,
                'performer': request.user,
                'sender': request.user
            }

            # Logging action
            action_logging(request.user, [project, team], nt, context=context)

            if settings.ENABLE_NOTICES:
                # Send notification for those that are observing this project
                txnotification.send_observation_notices_for(
                    project, signal=nt, extra_context=context)
                # Send notification for maintainers, coordinators
                notification.send(
                    set(
                        itertools.chain(project.maintainers.all(),
                                        team.coordinators.all())), nt, context)

        except IntegrityError, e:
            transaction.rollback()
            logger.error("Something weird happened: %s" % str(e))
Ejemplo n.º 28
0
def team_delete(request, project_slug, language_code):

    project = get_object_or_404(Project, slug=project_slug)
    team = get_object_or_404(Team,
                             project__pk=project.pk,
                             language__code=language_code)

    if request.method == "POST":
        _team = copy.copy(team)
        team.delete()
        messages.success(request,
                         _("The team '%s' was deleted.") % _team.language.name)

        # ActionLog & Notification
        # TODO: Use signals
        nt = 'project_team_deleted'
        context = {'team': _team, 'sender': request.user}

        #Delete rlstats for this team in outsourced projects
        for p in project.outsourcing.all():
            RLStats.objects.select_related('resource').by_project_and_language(
                p, _team.language).filter(translated=0).delete()

        # Logging action
        action_logging(request.user, [project, _team], nt, context=context)

        if settings.ENABLE_NOTICES:
            # Send notification for those that are observing this project
            txnotification.send_observation_notices_for(project,
                                                        signal=nt,
                                                        extra_context=context)
            # Send notification for maintainers
            notification.send(project.maintainers.all(), nt, context)

        return HttpResponseRedirect(
            reverse("project_detail", args=(project_slug, )))
    else:
        return render_to_response("teams/team_confirm_delete.html", {
            "team": team,
            "project": team.project
        },
                                  context_instance=RequestContext(request))
Ejemplo n.º 29
0
def on_resource_save(sender, instance, created, user, **kwargs):
    """
    Called on resource post save and passes a user object in addition to the
    saved instance. Used for logging the create/update of a resource.
    """
    # ActionLog & Notification
    context = {'resource': instance}
    object_list = [instance.project, instance]
    if created:
        nt = 'project_resource_added'
        action_logging(user, object_list, nt, context=context)
        if settings.ENABLE_NOTICES:
            txnotification.send_observation_notices_for(instance.project,
                    signal=nt, extra_context=context)
    else:
        nt = 'project_resource_changed'
        action_logging(user, object_list, nt, context=context)
        if settings.ENABLE_NOTICES:
            txnotification.send_observation_notices_for(instance.project,
                    signal=nt, extra_context=context)
Ejemplo n.º 30
0
def team_leave(request, project_slug, language_code):

    team = get_object_or_404(Team, project__slug=project_slug,
        language__code=language_code)
    project = team.project

    if request.POST:
        try:
            if (team.members.filter(username=request.user.username).exists() or
                team.reviewers.filter(username=request.user.username).exists()):
                team.members.remove(request.user)
                team.reviewers.remove(request.user)
                messages.info(request, _(
                    "You left the '%s' team."
                    ) % team.language.name)

                # ActionLog & Notification
                # TODO: Use signals
                nt = 'project_team_left'
                context = {'team': team,
                           'performer': request.user,
                           'sender': request.user}

                # Logging action
                action_logging(request.user, [project, team], nt, context=context)

                if settings.ENABLE_NOTICES:
                    # Send notification for those that are observing this project
                    txnotification.send_observation_notices_for(project,
                            signal=nt, extra_context=context)
                    # Send notification for maintainers, coordinators
                    notification.send(set(itertools.chain(project.maintainers.all(),
                        team.coordinators.all())), nt, context)
            else:
                messages.info(request, _(
                    "You are not in the '%s' team."
                    ) % team.language.name)

        except IntegrityError, e:
            transaction.rollback()
            logger.error("Something weird happened: %s" % str(e))
Ejemplo n.º 31
0
def team_delete(request, project_slug, language_code):

    project = get_object_or_404(Project, slug=project_slug)
    team = get_object_or_404(Team, project__pk=project.pk,
        language__code=language_code)

    if request.method == "POST":
        _team = copy.copy(team)
        team.delete()
        messages.success(request, _("The team '%s' was deleted.") % _team.language.name)

        # ActionLog & Notification
        # TODO: Use signals
        nt = 'project_team_deleted'
        context = {'team': _team,
                   'sender': request.user}

        #Delete rlstats for this team in outsourced projects
        for p in project.outsourcing.all():
            RLStats.objects.select_related('resource').by_project_and_language(
                    p, _team.language).filter(translated=0).delete()

        # Logging action
        action_logging(request.user, [project, _team], nt, context=context)

        if settings.ENABLE_NOTICES:
            # Send notification for those that are observing this project
            txnotification.send_observation_notices_for(project,
                    signal=nt, extra_context=context)
            # Send notification for maintainers
            notification.send(project.maintainers.all(), nt, context)

        return HttpResponseRedirect(reverse("project_detail",
                                     args=(project_slug,)))
    else:
        return render_to_response(
            "teams/team_confirm_delete.html",
            {"team": team, "project": team.project},
            context_instance=RequestContext(request)
        )
Ejemplo n.º 32
0
def team_request_approve(request, project_slug, language_code):

    team_request = get_object_or_404(TeamRequest, project__slug=project_slug,
        language__code=language_code)
    project = team_request.project

    if request.POST:
        try:
            team = Team(project=team_request.project,
                language=team_request.language, creator=request.user)
            team.save()
            team.coordinators.add(team_request.user)
            team.save()
            team_request.delete()
            messages.success(request, _(
                "You approved the '%(team)s' team requested by '%(user)s'."
                ) % {'team':team.language.name, 'user':team_request.user})

            # ActionLog & Notification
            # TODO: Use signals
            nt = 'project_team_added'
            context = {'team': team,
                       'sender': request.user}

            # Logging action
            action_logging(request.user, [project, team], nt, context=context)

            if settings.ENABLE_NOTICES:
                # Send notification for those that are observing this project
                txnotification.send_observation_notices_for(project,
                        signal=nt, extra_context=context)
                # Send notification for maintainers and coordinators
                notification.send(set(itertools.chain(project.maintainers.all(),
                    team.coordinators.all())), nt, context)

        except IntegrityError, e:
            transaction.rollback()
            logger.error("Something weird happened: %s" % str(e))
Ejemplo n.º 33
0
                invalidate_stats_cache(self.resource, self.language, user=user)

                if self.language == self.resource.source_language:
                    nt = 'project_resource_changed'
                else:
                    nt = 'project_resource_translated'
                context = {'project': self.resource.project,
                            'resource': self.resource,
                            'language': self.language}
                object_list = [self.resource.project, self.resource, self.language]
                # if we got no user, skip the log
                if user:
                    action_logging(user, object_list, nt, context=context)

                if settings.ENABLE_NOTICES:
                    txnotification.send_observation_notices_for(self.resource.project,
                            signal=nt, extra_context=context)

                    # if language is source language, notify all languages for the change
                    if self.language == self.resource.source_language:
                        for l in self.resource.available_languages:
                            twatch = TranslationWatch.objects.get_or_create(
                                resource=self.resource, language=l)[0]
                            logger.debug("addon-watches: Sending notification"
                                " for '%s'" % twatch)
                            txnotification.send_observation_notices_for(twatch,
                            signal='project_resource_translation_changed',
                                 extra_context=context)

            transaction.commit()
            return strings_added, strings_updated
Ejemplo n.º 34
0
def _project_create_update(request,
                           project_slug=None,
                           template_name='projects/project_form.html'):
    """
    Handler for creating and updating a project.

    This function helps to eliminate duplication of code between those two
    actions, and also allows to apply different permission checks in the
    respective views.
    """

    if project_slug:
        project = get_object_or_404(Project, slug=project_slug)
    else:
        project = None

    if request.method == 'POST':
        owner = project and project.owner or request.user
        project_form = ProjectForm(request.POST,
                                   request.FILES,
                                   instance=project,
                                   prefix='project',
                                   owner=owner)
        if project_form.is_valid():
            project = project_form.save(commit=False)
            project_id = project.id
            # Only here the owner is written to the project model
            if not project_id:
                project.owner = request.user

            # provide the form data to any signal handlers before project_save
            Signal.send(signals.pre_proj_save,
                        sender=Project,
                        instance=project,
                        form=project_form)
            project.save()
            project_form.save_m2m()

            # TODO: Not sure if here is the best place to put it
            Signal.send(signals.post_proj_save_m2m,
                        sender=Project,
                        instance=project,
                        form=project_form)

            # ActionLog & Notification
            context = {'project': project, 'sender': request.user}
            if not project_id:
                nt = 'project_added'
                action_logging(request.user, [project], nt, context=context)
            else:
                nt = 'project_changed'
                action_logging(request.user, [project], nt, context=context)
                if settings.ENABLE_NOTICES:
                    txnotification.send_observation_notices_for(
                        project, signal=nt, extra_context=context)

            return HttpResponseRedirect(
                reverse('project_detail', args=[project.slug]), )
    else:
        # Make the current user the maintainer when adding a project
        if project:
            initial_data = {}
        else:
            initial_data = {"maintainers": [request.user.pk]}

        project_form = ProjectForm(instance=project,
                                   prefix='project',
                                   initial=initial_data)

    return render_to_response(template_name, {
        'project_form': project_form,
        'project': project,
    },
                              context_instance=RequestContext(request))
Ejemplo n.º 35
0
def team_request(request, project_slug):

    if request.POST:
        language_pk = request.POST.get('language', None)
        if not language_pk:
            messages.error(
                request,
                _("Please select a language before submitting the form."))
            return HttpResponseRedirect(
                reverse("project_detail", args=[
                    project_slug,
                ]))

        project = get_object_or_404(Project, slug=project_slug)

        language = get_object_or_404(Language, pk=int(language_pk))

        try:
            team = Team.objects.get(project__pk=project.pk,
                                    language__pk=language.pk)
            messages.warning(
                request,
                _("'%s' team already exists.") % team.language.name)
        except Team.DoesNotExist:
            try:
                team_request = TeamRequest.objects.get(
                    project__pk=project.pk, language__pk=language.pk)
                messages.warning(
                    request,
                    _("A request to create the '%s' team already exists.") %
                    team_request.language.name)
            except TeamRequest.DoesNotExist:
                try:
                    # send pre_team_request signal
                    cla_sign = 'cla_sign' in request.POST and \
                            request.POST['cla_sign']
                    cla_sign = cla_sign and True
                    pre_team_request.send(sender='request_team_view',
                                          project=project,
                                          user=request.user,
                                          cla_sign=cla_sign)

                    team_request = TeamRequest(project=project,
                                               language=language,
                                               user=request.user)
                    team_request.save()
                    messages.info(
                        request,
                        _("You requested creation of the '%s' team.") %
                        team_request.language.name)

                    # ActionLog & Notification
                    # TODO: Use signals
                    nt = 'project_team_requested'
                    context = {
                        'team_request': team_request,
                        'sender': request.user
                    }

                    # Logging action
                    action_logging(request.user, [project],
                                   nt,
                                   context=context)

                    if settings.ENABLE_NOTICES:
                        # Send notification for those that are observing this project
                        txnotification.send_observation_notices_for(
                            project, signal=nt, extra_context=context)
                        # Send notification for maintainers
                        notification.send(project.maintainers.all(), nt,
                                          context)

                except IntegrityError, e:
                    transaction.rollback()
                    logger.error("Something weird happened: %s" % str(e))
                except ClaNotSignedError, e:
                    messages.error(request, _(
                        "You need to sign the Contribution License Agreement "\
                        "for this project before you submit a team creation "\
                        "request."
                    ))
Ejemplo n.º 36
0
def _team_create_update(request,
                        project_slug,
                        language_code=None,
                        extra_context=None):
    """
    Handler for creating and updating a team of a project.

    This function helps to eliminate duplication of code between those two
    actions, and also allows to apply different permission checks in the
    respective views.
    """
    project = get_object_or_404(Project, slug=project_slug)
    team, language = None, None

    if language_code:
        language = get_object_or_404(Language, code=language_code)
        try:
            team = Team.objects.get(project__pk=project.pk, language=language)
        except Team.DoesNotExist:
            pass

    if request.POST:
        form = TeamSimpleForm(project, language, request.POST, instance=team)
        form.data["creator"] = request.user.pk
        if form.is_valid():
            team = form.save(commit=False)
            team_id = team.id
            team.save()
            form.save_m2m()

            # Delete access requests for users that were added
            for member in itertools.chain(team.members.all(),
                                          team.coordinators.all()):
                tr = TeamAccessRequest.objects.get_or_none(team, member)
                if tr:
                    tr.delete()

            # ActionLog & Notification
            # TODO: Use signals
            if not team_id:
                nt = 'project_team_added'
            else:
                nt = 'project_team_changed'

            context = {'team': team, 'sender': request.user}

            # Logging action
            action_logging(request.user, [project, team], nt, context=context)
            update_team_request(team)

            if settings.ENABLE_NOTICES:
                # Send notification for those that are observing this project
                txnotification.send_observation_notices_for(
                    project, signal=nt, extra_context=context)
                # Send notification for maintainers and coordinators
                from notification.models import NoticeType
                try:
                    notification.send(
                        set(
                            itertools.chain(project.maintainers.all(),
                                            team.coordinators.all())), nt,
                        context)
                except NoticeType.DoesNotExist:
                    pass

            return HttpResponseRedirect(
                reverse("team_members",
                        args=[project.slug, team.language.code]))
    else:
        form = TeamSimpleForm(project, language, instance=team)

    context = {
        "project": project,
        "team": team,
        "project_team_form": form,
    }

    if extra_context:
        context.update(extra_context)

    return render_to_response("teams/team_form.html",
                              context,
                              context_instance=RequestContext(request))
Ejemplo n.º 37
0
def team_request(request, project_slug):

    if request.POST:
        language_pk = request.POST.get('language', None)
        if not language_pk:
            messages.error(request, _(
                "Please select a language before submitting the form."))
            return HttpResponseRedirect(reverse("team_list",
                                        args=[project_slug,]))


        project = get_object_or_404(Project, slug=project_slug)

        language = get_object_or_404(Language, pk=int(language_pk))

        try:
            team = Team.objects.get(project__pk=project.pk,
                language__pk=language.pk)
            messages.warning(request,_(
                "'%s' team already exists.") % team.language.name)
        except Team.DoesNotExist:
            try:
                team_request = TeamRequest.objects.get(project__pk=project.pk,
                    language__pk=language.pk)
                messages.warning(request, _(
                    "A request to create the '%s' team already exists.")
                    % team_request.language.name)
            except TeamRequest.DoesNotExist:
                try:
                    # send pre_team_request signal
                    cla_sign = 'cla_sign' in request.POST and \
                            request.POST['cla_sign']
                    cla_sign = cla_sign and True
                    pre_team_request.send(sender='request_team_view',
                                          project=project,
                                          user=request.user,
                                          cla_sign=cla_sign)

                    team_request = TeamRequest(project=project,
                        language=language, user=request.user)
                    team_request.save()
                    messages.info(request, _(
                        "You requested creation of the '%s' team.")
                        % team_request.language.name)

                    # ActionLog & Notification
                    # TODO: Use signals
                    nt = 'project_team_requested'
                    context = {'team_request': team_request}

                    # Logging action
                    action_logging(request.user, [project], nt, context=context)

                    if settings.ENABLE_NOTICES:
                        # Send notification for those that are observing this project
                        txnotification.send_observation_notices_for(project,
                                signal=nt, extra_context=context)
                        # Send notification for maintainers
                        notification.send(project.maintainers.all(), nt, context)

                except IntegrityError, e:
                    transaction.rollback()
                    logger.error("Something weird happened: %s" % str(e))
                except ClaNotSignedError, e:
                    messages.error(request, _(
                        "You need to sign the Contribution License Agreement "\
                        "for this project before you submit a team creation "\
                        "request."
                    ))
Ejemplo n.º 38
0
def _team_create_update(request, project_slug, language_code=None):
    """
    Handler for creating and updating a team of a project.

    This function helps to eliminate duplication of code between those two
    actions, and also allows to apply different permission checks in the
    respective views.
    """
    project = get_object_or_404(Project, slug=project_slug)
    team = None

    if language_code:
        try:
            team = Team.objects.get(project__pk=project.pk,
                language__code=language_code)
        except Team.DoesNotExist:
            pass

    if request.POST:
        form = TeamSimpleForm(project, language_code, request.POST, instance=team)
        form.data["creator"] = request.user.pk
        if form.is_valid():
            team=form.save(commit=False)
            team_id = team.id
            team.save()
            form.save_m2m()

            # Delete access requests for users that were added
            for member in itertools.chain(team.members.all(),
                team.coordinators.all()):
                tr = TeamAccessRequest.objects.get_or_none(team, member)
                if tr:
                    tr.delete()

            # ActionLog & Notification
            # TODO: Use signals
            if not team_id:
                nt = 'project_team_added'
            else:
                nt = 'project_team_changed'

            context = {'team': team}

            # Logging action
            action_logging(request.user, [project, team], nt, context=context)

            if settings.ENABLE_NOTICES:
                # Send notification for those that are observing this project
                txnotification.send_observation_notices_for(project,
                        signal=nt, extra_context=context)
                # Send notification for maintainers and coordinators
                from notification.models import NoticeType
                try:
                    notification.send(set(itertools.chain(project.maintainers.all(),
                        team.coordinators.all())), nt, context)
                except NoticeType.DoesNotExist:
                    pass

            return HttpResponseRedirect(reverse("team_detail",
                                        args=[project.slug, team.language.code]))
    else:
        form=TeamSimpleForm(project, language_code, instance=team)

    return render_to_response("teams/team_form.html",
                              {"project": project,
                               "team": team,
                               "project_team_form": form,
                               "project_team_page": True},
                                context_instance=RequestContext(request))