Пример #1
0
def project_access_control_edit(request, project_slug):

    project = get_object_or_404(Project, slug=project_slug)
    if request.method == 'POST':
        access_control_form = ProjectAccessControlForm(request.POST,
            instance=project, user=request.user)
        if access_control_form.is_valid():
            access_control = access_control_form.cleaned_data['access_control']
            project = access_control_form.save()
            if 'free_for_all' == access_control:
                project.anyone_submit=True
            else:
                project.anyone_submit=False
            if 'outsourced_access' != access_control:
                project.outsource=None
            else:
                # TODO: Send notification for these projects, telling the
                # maintainers that the outsource project is not accepting
                # outsourcing anymore
                for p in project.project_set.all():
                    p.outsource=None
                    p.save()
            # Check if cla form exists before sending the signal
            if 'limited_access' == access_control and \
              access_control_form.cleaned_data.has_key('cla_license_text'):
                # send signal to save CLA
                signals.cla_create.send(
                    sender='project_access_control_edit_view',
                    project=project,
                    license_text=access_control_form.cleaned_data['cla_license_text'],
                    request=request
                )
            project.save()
            handle_stats_on_access_control_edit(project)
            return HttpResponseRedirect(request.POST['next'])
    else:
        access_control_form = ProjectAccessControlForm(instance=project,
            user=request.user)
    return render_to_response('projects/project_form_access_control.html', {
        'project_permission': True,
        'project': project,
        'project_access_control_form': access_control_form,
    }, context_instance=RequestContext(request))
Пример #2
0
def project_access_control_edit(request, project_slug):

    project = get_object_or_404(Project, slug=project_slug)
    if request.method == "POST":
        access_control_form = ProjectAccessControlForm(request.POST, instance=project)
        if access_control_form.is_valid():
            access_control = access_control_form.cleaned_data["access_control"]
            project = access_control_form.save()
            if "free_for_all" == access_control:
                project.anyone_submit = True
            else:
                project.anyone_submit = False
            if "outsourced_access" != access_control:
                project.outsource = None
            else:
                # TODO: Send notification for these projects, telling the
                # maintainers that the outsource project is not accepting
                # outsourcing anymore
                for p in project.project_set.all():
                    p.outsource = None
                    p.save()
            # Check if cla form exists before sending the signal
            if "limited_access" == access_control and access_control_form.cleaned_data.has_key("cla_license_text"):
                # send signal to save CLA
                signals.cla_create.send(
                    sender="project_access_control_edit_view",
                    project=project,
                    license_text=access_control_form.cleaned_data["cla_license_text"],
                    request=request,
                )
            project.save()
            handle_stats_on_access_control_edit(project)
            return HttpResponseRedirect(request.POST["next"])
    else:
        access_control_form = ProjectAccessControlForm(instance=project, user=request.user)
    return render_to_response(
        "projects/project_form_access_control.html",
        {"project_permission": True, "project": project, "project_access_control_form": access_control_form},
        context_instance=RequestContext(request),
    )
Пример #3
0
def project_add_permission(request, project_slug):
    """
    Return a view with a form for adding a permission for a user.

    This view is an abstraction of a txpermissions.views method to be able to
    apply granular permission on it using a decorator.
    """
    project = get_object_or_404(Project, slug=project_slug)

    # When adding a permission it's necessary to query the user object in
    # order to be able to pass the extra_context for the notification/actionlog
    try:
        username = request.POST['user']
        sendto = User.objects.get(username=username)
    except (MultiValueDictKeyError, User.DoesNotExist):
        sendto = None

    notice = {
        'type': 'project_submit_access_granted',
        'object': project,
        'sendto': [sendto],
        'extra_context': {
            'project': project,
            'user_request': sendto,
            'user_action': request.user,
        },
    }
    return add_permission_or_request(
        request,
        project,
        view_name='project_add_permission',
        approved=True,
        extra_context={
            'project_permission':
            True,
            'project':
            project,
            'project_access_control_form':
            ProjectAccessControlForm(instance=project),
            'notice':
            notice,
        },
        template_name='projects/project_form_permissions.html')
Пример #4
0
def project_access_control_edit(request, project_slug):
    project = get_object_or_404(Project, slug=project_slug)
    outsourced = project.outsource
    if request.method == 'POST':
        form = ProjectAccessControlForm(request.POST,
                                        instance=project,
                                        user=request.user)
        if form.is_valid():
            access_control = form.cleaned_data['access_control']
            project_type = form.cleaned_data['project_type']
            project = form.save(commit=False)
            project_hub = project.outsource
            hub_request = None

            # TODO call signal project_outsourced_changed
            if 'outsourced' != project_type:
                project.outsource = None
            else:
                check = ProjectPermission(request.user)
                if not (check.maintain(project)
                        and check.maintain(project_hub)):
                    # If the user is not maintainer of both projects it does
                    # not associate the outsource project directly.
                    # It does a request instead.
                    try:
                        hub_request = HubRequest.objects.get(project=project)
                    except ObjectDoesNotExist:
                        hub_request = HubRequest(project=project)
                    hub_request.project_hub = project_hub
                    hub_request.user = request.user
                    hub_request.save()

                    messages.success(
                        request,
                        _("Requested to join the '%s' project hub.") %
                        project_hub)
                    # ActionLog & Notification
                    # TODO: Use signals
                    nt = 'project_hub_join_requested'
                    context = {
                        'hub_request': hub_request,
                        'sender': request.user
                    }

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

                    if settings.ENABLE_NOTICES:
                        # Send notification for project hub maintainers
                        notification.send(project_hub.maintainers.all(), nt,
                                          context)

                    return HttpResponseRedirect(
                        reverse('project_detail', args=[project.slug]), )

            if 'hub' == project_type:
                project.is_hub = True
            else:
                project.is_hub = False

            if ('free_for_all' == access_control
                    and project_type != "outsourced"):
                project.anyone_submit = True
            else:
                project.anyone_submit = False

            # Check if cla form exists before sending the signal
            if 'limited_access' == access_control and \
            form.cleaned_data.has_key('cla_license_text'):
                # send signal to save CLA
                signals.cla_create.send(
                    sender='project_access_control_edit_view',
                    project=project,
                    license_text=form.cleaned_data['cla_license_text'],
                    request=request)

            project.save()
            form.save_m2m()
            handle_stats_on_access_control_edit(project)
            project_outsourced_changed.send(sender=project_hub)

            if outsourced and not project.outsource:
                # Drop resources from all-resources release of the hub project
                update_all_release(outsourced)

                # Logging action
                nt = 'project_hub_left'
                context = {
                    'project': project,
                    'project_hub': outsourced,
                    'sender': request.user
                }
                action_logging(request.user, [project, outsourced],
                               nt,
                               context=context)

            return HttpResponseRedirect(
                reverse('project_detail', args=[project.slug]), )

    else:
        form = ProjectAccessControlForm(instance=project, user=request.user)

    return render_to_response('projects/project_form_access_control.html', {
        'project_permission': True,
        'project': project,
        'form': form,
    },
                              context_instance=RequestContext(request))