Exemplo n.º 1
0
 def decorated(request, *args, **kwargs):
     objs = []
     if request.user.is_authenticated() or allow_anonymous:
         lookup_list = _model_lookups_handler(model_lookups, *args,
                                              **kwargs)
         granted = False
         for perm_type, perm in perms:
             if perm_type == "granular":
                 for model_class, lookup, value in lookup_list:
                     objs.append(
                         get_object_or_404(model_class,
                                           **{lookup: value}))
                 check = get_check(request.user, perm)
                 if check is not None:
                     granted = check(*objs)
             else:
                 if request.user.has_perm(perm):
                     granted = True
             if granted:
                 return view_func(request, *args, **kwargs)
     if redirect_to_login:
         path = urlquote(request.get_full_path())
         tup = login_url, redirect_field_name, path
         return HttpResponseRedirect('%s?%s=%s' % tup)
     return permission_denied(request)
Exemplo n.º 2
0
def cla_project_sign(request, project_slug):
    project = get_object_or_404(Project, slug=project_slug)
    cla = get_object_or_404(Cla, project=project)

    check = ProjectPermission(request.user)
    if not check.submit_translations(project, any_team=True):
        return permission_denied(request)

    try:
        signed_cla = request.user.cla_set.filter(project=project)[0]
    except IndexError:
        signed_cla = None

    if request.method == "POST" and not signed_cla:
        form = ClaForm(request.POST)
        if form.is_valid():
            kwargs = {"cla_sign": True, "project": project, "user": request.user}
            handle_pre_team(None, **kwargs)

            messages.success(request, _("You have signed the CLA."))

            return HttpResponseRedirect(reverse("cla_project_sign", args=[project_slug]))
    else:
        form = ClaForm()

    return render_to_response(
        "project_cla.html",
        {"project": project, "cla": cla, "signed_cla": signed_cla, "form": form},
        context_instance=RequestContext(request),
    )
Exemplo n.º 3
0
 def decorated(request, *args, **kwargs):
     objs = []
     if request.user.is_authenticated() or allow_anonymous:
         lookup_list = _model_lookups_handler(model_lookups, *args, **kwargs)
         granted = False
         for perm_type, perm in perms:
             if perm_type == "granular":
                 for model_class, lookup, value in lookup_list:
                     objs.append(get_object_or_404(model_class, **{lookup: value}))
                 check = get_check(request.user, perm)
                 if check is not None:
                     granted = check(*objs)
             else:
                 if request.user.has_perm(perm):
                     granted = True
             if granted:
                 return view_func(request, *args, **kwargs)
     if redirect_to_login:
         path = urlquote(request.get_full_path())
         tup = login_url, redirect_field_name, path
         return HttpResponseRedirect('%s?%s=%s' % tup)
     return permission_denied(request)
Exemplo n.º 4
0
def cla_project_sign(request, project_slug):
    project = get_object_or_404(Project, slug=project_slug)
    cla = get_object_or_404(Cla, project=project)

    check = ProjectPermission(request.user)
    if not check.submit_translations(project, any_team=True):
        return permission_denied(request)

    try:
        signed_cla = request.user.cla_set.filter(project=project)[0]
    except IndexError:
        signed_cla = None

    if request.method == 'POST' and not signed_cla:
        form = ClaForm(request.POST)
        if form.is_valid():
            kwargs = {
                'cla_sign': True,
                'project': project,
                'user': request.user
            }
            handle_pre_team(None, **kwargs)

            messages.success(request, _("You have signed the CLA."))

            return HttpResponseRedirect(
                reverse('cla_project_sign', args=[project_slug]), )
    else:
        form = ClaForm()

    return render_to_response("project_cla.html", {
        'project': project,
        'cla': cla,
        'signed_cla': signed_cla,
        'form': form
    },
                              context_instance=RequestContext(request))
Exemplo n.º 5
0
def resource_translation_toggle_watch(request, project_slug, resource_slug, language_code):
    """Add/Remove a TranslationWatch for a specific user."""

    if request.method != 'POST':
        return json_error(_('Must use POST to activate'))

    if not settings.ENABLE_NOTICES:
        return json_error(_('Notification is not enabled'))

    resource = get_object_or_404(Resource, slug=resource_slug,
                                project__slug=project_slug)
    project = resource.project
    language = get_object_or_404(Language, code=language_code)
    team = Team.objects.get_or_none(project, language_code)

    check = ProjectPermission(request.user)
    if not check.submit_translations(team or project) and not \
        check.maintain(project) and not \
        request.user.has_perm('watches.add_translationwatch') and not \
        request.user.has_perm('watches.delete_translationwatch'):
        return permission_denied(request)

    url = reverse('resource_translation_toggle_watch', args=(project_slug,
        resource_slug, language_code))

    try:
        twatch = TranslationWatch.objects.get(resource=resource,
            language=language)

        result = {
            'style': 'watch_add',
            'title': _('Watch it'),
            'id': twatch.id,
            'url': url,
            'error': None,
        }

        notification.stop_observing(twatch, request.user,
            signal='project_resource_translation_changed')

    except (TranslationWatch.DoesNotExist,
        notification.ObservedItem.DoesNotExist):

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

            result = {
                'style': 'watch_remove',
                'title': _('Stop watching'),
                'id': twatch.id,
                'url': url,
                'error': None,
            }

            notification.observe(twatch, request.user,
                'project_resource_translation_changed',
                signal='project_resource_translation_changed')

        except WatchException, e:
            return json_error(e.message, result)