Ejemplo n.º 1
0
def role_create(request):
    check_permissions(request.user, 'permissions', [PERMISSION_ROLE_CREATE])

    return create_object(request,
                         model=Role,
                         template_name='generic_form.html',
                         post_save_redirect=reverse('role_list'))
Ejemplo n.º 2
0
def role_permissions(request, role_id):
    check_permissions(request.user, 'permissions', [PERMISSION_PERMISSION_GRANT, PERMISSION_PERMISSION_REVOKE])
            
    role = get_object_or_404(Role, pk=role_id)
    form = RoleForm_view(instance=role)

    role_permissions = Permission.objects.get_for_holder(role)
    subtemplates_dict = [
        {
            'name':'generic_list_subtemplate.html',
            'title':_(u'permissions'),
            'object_list':Permission.objects.all(),
            'extra_columns':[
                {'name':_(u'namespace'), 'attribute':'namespace'},
                {'name':_(u'name'), 'attribute':'label'},
                {'name':_(u'state'), 'attribute':lambda x: _role_permission_link(role, x, role_permissions)}
            ],
            'hide_link':True,
            'hide_object':True,
        },
    ]
           
    return render_to_response('generic_detail.html', {
        'form':form,
        'object':role,
        'object_name':_(u'role'),
        'subtemplates_dict':subtemplates_dict,
    }, context_instance=RequestContext(request))
Ejemplo n.º 3
0
def role_edit(request, role_id):
    check_permissions(request.user, 'permissions', [PERMISSION_ROLE_EDIT])

    return update_object(request,
                         template_name='generic_form.html',
                         form_class=RoleForm,
                         object_id=role_id,
                         extra_context={'object_name': _(u'role')})
Ejemplo n.º 4
0
def role_list(request):
    check_permissions(request.user, 'permissions', [PERMISSION_ROLE_VIEW])
            
    return object_list(
        request,
        queryset=Role.objects.all(),
        template_name='generic_list.html',
        extra_context={
            'title':_(u'roles'),
            'hide_link':True,
        },
    )
Ejemplo n.º 5
0
def role_list(request):
    check_permissions(request.user, 'permissions', [PERMISSION_ROLE_VIEW])

    return object_list(
        request,
        queryset=Role.objects.all(),
        template_name='generic_list.html',
        extra_context={
            'title': _(u'roles'),
            'hide_link': True,
        },
    )
Ejemplo n.º 6
0
def permission_grant_revoke(request, permission_id, app_label, module_name, pk, action):
    ct = get_object_or_404(ContentType, app_label=app_label, model=module_name)
    requester_model = ct.model_class()
    requester = get_object_or_404(requester_model, pk=pk)
    permission = get_object_or_404(Permission, pk=permission_id)

    if action == 'grant':
        permissions = [PERMISSION_PERMISSION_GRANT]
        try:
            check_permissions(request.user, 'permissions', permissions)
        except Unauthorized, e:
            raise Http404(e)
        title = _('Are you sure you wish to grant the permission "%s" to %s: %s') % (permission, ct.name, requester)
Ejemplo n.º 7
0
def role_delete(request, role_id):
    check_permissions(request.user, 'permissions', [PERMISSION_ROLE_DELETE])
            
    next = request.POST.get('next', request.GET.get('next', request.META.get('HTTP_REFERER', None)))
    previous = request.POST.get('previous', request.GET.get('previous', request.META.get('HTTP_REFERER', None)))
        
    return delete_object(request, model=Role, object_id=role_id, 
        template_name='generic_confirm.html', 
        post_delete_redirect=reverse('role_list'),
        extra_context={
            'delete_view':True,
            'next':next,
            'previous':previous,
            'object_name':_(u'role'),
        })
Ejemplo n.º 8
0
def permission_grant_revoke(request, permission_id, app_label, module_name, pk, action):
    ct = get_object_or_404(ContentType, app_label=app_label, model=module_name)
    requester_model = ct.model_class()
    requester = get_object_or_404(requester_model, pk=pk)
    permission = get_object_or_404(Permission, pk=permission_id)

    if action == 'grant':
        check_permissions(request.user, 'permissions', [PERMISSION_PERMISSION_GRANT])
        title = _('Are you sure you wish to grant the permission "%(permission)s" to %(ct_name)s: %(requester)s') % {
            'permission':permission, 'ct_name':ct.name, 'requester':requester}

    elif action == 'revoke':
        check_permissions(request.user, 'permissions', [PERMISSION_PERMISSION_REVOKE])
        title = _('Are you sure you wish to revoke the permission "%(permission)s" from %(ct_name)s: %(requester)s') % {
            'permission':permission, 'ct_name':ct.name, 'requester':requester}
    else:
        return HttpResponseRedirect('/')

    next = request.POST.get('next', request.GET.get('next', request.META.get('HTTP_REFERER', None)))
    previous = request.POST.get('previous', request.GET.get('previous', request.META.get('HTTP_REFERER', None)))


    if request.method == 'POST':
        if action == 'grant':
            permission_holder, created = PermissionHolder.objects.get_or_create(permission=permission, holder_type=ct, holder_id=requester.id)
            if created:
                messages.success(request, _(u'Permission "%(permission)s" granted to %(ct_name)s: %(requester)s.') % {
                    'permission':permission, 'ct_name':ct.name, 'requester':requester})
            else:
                messages.warning(request, _(u'%(ct_name)s: %(requester)s, already had the permission "%(permission)s" granted.') % {
                    'ct_name':ct.name, 'requester':requester, 'permission':permission})
        elif action == 'revoke':
            try:
                permission_holder = PermissionHolder.objects.get(permission=permission, holder_type=ct, holder_id=requester.id)
                permission_holder.delete()
                messages.success(request, _(u'Permission "%(permission)s" revoked from %(ct_name)s: %(requester)s.') % {
                    'permission':permission, 'ct_name':ct.name, 'requester':requester})
            except ObjectDoesNotExist:
                messages.warning(request, _(u'%(ct_name)s: %(requester)s doesn\'t have the permission "%(permission)s".') % {
                    'ct_name':ct.name, 'requester':requester, 'permission':permission})
        return HttpResponseRedirect(next)
        
    return render_to_response('generic_confirm.html', {
        'object':requester,
        'next':next,
        'previous':previous,
        'title':title,
    }, context_instance=RequestContext(request))
Ejemplo n.º 9
0
def role_permissions(request, role_id):
    check_permissions(
        request.user, 'permissions',
        [PERMISSION_PERMISSION_GRANT, PERMISSION_PERMISSION_REVOKE])

    role = get_object_or_404(Role, pk=role_id)
    form = RoleForm_view(instance=role)

    role_permissions = Permission.objects.get_for_holder(role)
    subtemplates_dict = [
        {
            'name':
            'generic_list_subtemplate.html',
            'title':
            _(u'permissions'),
            'object_list':
            Permission.objects.all(),
            'extra_columns': [{
                'name': _(u'namespace'),
                'attribute': 'namespace'
            }, {
                'name': _(u'name'),
                'attribute': 'label'
            }, {
                'name':
                _(u'state'),
                'attribute':
                lambda x: _role_permission_link(role, x, role_permissions)
            }],
            'hide_link':
            True,
            'hide_object':
            True,
        },
    ]

    return render_to_response('generic_detail.html', {
        'form': form,
        'object': role,
        'object_name': _(u'role'),
        'subtemplates_dict': subtemplates_dict,
    },
                              context_instance=RequestContext(request))
Ejemplo n.º 10
0
def role_delete(request, role_id):
    check_permissions(request.user, 'permissions', [PERMISSION_ROLE_DELETE])

    next = request.POST.get(
        'next', request.GET.get('next', request.META.get('HTTP_REFERER',
                                                         None)))
    previous = request.POST.get(
        'previous',
        request.GET.get('previous', request.META.get('HTTP_REFERER', None)))

    return delete_object(request,
                         model=Role,
                         object_id=role_id,
                         template_name='generic_confirm.html',
                         post_delete_redirect=reverse('role_list'),
                         extra_context={
                             'delete_view': True,
                             'next': next,
                             'previous': previous,
                             'object_name': _(u'role'),
                         })
Ejemplo n.º 11
0
def role_list(request):
    permissions = [PERMISSION_ROLE_VIEW]
    try:
        check_permissions(request.user, 'permissions', permissions)
    except Unauthorized, e:
        raise Http404(e)
Ejemplo n.º 12
0
def role_delete(request, role_id):
    permissions = [PERMISSION_ROLE_DELETE]
    try:
        check_permissions(request.user, 'permissions', permissions)
    except Unauthorized, e:
        raise Http404(e)
Ejemplo n.º 13
0
def role_create(request):
    permissions = [PERMISSION_ROLE_CREATE]
    try:
        check_permissions(request.user, 'permissions', permissions)
    except Unauthorized, e:
        raise Http404(e)
Ejemplo n.º 14
0
    requester_model = ct.model_class()
    requester = get_object_or_404(requester_model, pk=pk)
    permission = get_object_or_404(Permission, pk=permission_id)

    if action == 'grant':
        permissions = [PERMISSION_PERMISSION_GRANT]
        try:
            check_permissions(request.user, 'permissions', permissions)
        except Unauthorized, e:
            raise Http404(e)
        title = _('Are you sure you wish to grant the permission "%s" to %s: %s') % (permission, ct.name, requester)

    elif action == 'revoke':
        permissions = [PERMISSION_PERMISSION_REVOKE]
        try:
            check_permissions(request.user, 'permissions', permissions)
        except Unauthorized, e:
            raise Http404(e)
        title = _('Are you sure you wish to revoke the permission "%s" from %s: %s') % (permission, ct.name, requester)
    else:
        return HttpResponseRedirect('/')

    next = request.POST.get('next', request.GET.get('next', request.META.get('HTTP_REFERER', None)))
    previous = request.POST.get('previous', request.GET.get('previous', request.META.get('HTTP_REFERER', None)))


    if request.method == 'POST':
        if action == 'grant':
            permission_holder, created = PermissionHolder.objects.get_or_create(permission=permission, holder_type=ct, holder_id=requester.id)
            if created:
                messages.success(request, _(u'Permission "%s" granted to %s: %s.') % (permission, ct.name, requester))
Ejemplo n.º 15
0
def role_create(request):
    check_permissions(request.user, 'permissions', [PERMISSION_ROLE_CREATE])

    return create_object(request, model=Role, 
        template_name='generic_form.html',
        post_save_redirect=reverse('role_list'))
Ejemplo n.º 16
0
def role_permissions(request, role_id):
    permissions = [PERMISSION_PERMISSION_GRANT, PERMISSION_PERMISSION_REVOKE]
    try:
        check_permissions(request.user, 'permissions', permissions)
    except Unauthorized, e:
        raise Http404(e)
Ejemplo n.º 17
0
def permission_grant_revoke(request, permission_id, app_label, module_name, pk,
                            action):
    ct = get_object_or_404(ContentType, app_label=app_label, model=module_name)
    requester_model = ct.model_class()
    requester = get_object_or_404(requester_model, pk=pk)
    permission = get_object_or_404(Permission, pk=permission_id)

    if action == 'grant':
        check_permissions(request.user, 'permissions',
                          [PERMISSION_PERMISSION_GRANT])
        title = _(
            'Are you sure you wish to grant the permission "%(permission)s" to %(ct_name)s: %(requester)s'
        ) % {
            'permission': permission,
            'ct_name': ct.name,
            'requester': requester
        }

    elif action == 'revoke':
        check_permissions(request.user, 'permissions',
                          [PERMISSION_PERMISSION_REVOKE])
        title = _(
            'Are you sure you wish to revoke the permission "%(permission)s" from %(ct_name)s: %(requester)s'
        ) % {
            'permission': permission,
            'ct_name': ct.name,
            'requester': requester
        }
    else:
        return HttpResponseRedirect('/')

    next = request.POST.get(
        'next', request.GET.get('next', request.META.get('HTTP_REFERER',
                                                         None)))
    previous = request.POST.get(
        'previous',
        request.GET.get('previous', request.META.get('HTTP_REFERER', None)))

    if request.method == 'POST':
        if action == 'grant':
            permission_holder, created = PermissionHolder.objects.get_or_create(
                permission=permission, holder_type=ct, holder_id=requester.id)
            if created:
                messages.success(
                    request,
                    _(u'Permission "%(permission)s" granted to %(ct_name)s: %(requester)s.'
                      ) % {
                          'permission': permission,
                          'ct_name': ct.name,
                          'requester': requester
                      })
            else:
                messages.warning(
                    request,
                    _(u'%(ct_name)s: %(requester)s, already had the permission "%(permission)s" granted.'
                      ) % {
                          'ct_name': ct.name,
                          'requester': requester,
                          'permission': permission
                      })
        elif action == 'revoke':
            try:
                permission_holder = PermissionHolder.objects.get(
                    permission=permission,
                    holder_type=ct,
                    holder_id=requester.id)
                permission_holder.delete()
                messages.success(
                    request,
                    _(u'Permission "%(permission)s" revoked from %(ct_name)s: %(requester)s.'
                      ) % {
                          'permission': permission,
                          'ct_name': ct.name,
                          'requester': requester
                      })
            except ObjectDoesNotExist:
                messages.warning(
                    request,
                    _(u'%(ct_name)s: %(requester)s doesn\'t have the permission "%(permission)s".'
                      ) % {
                          'ct_name': ct.name,
                          'requester': requester,
                          'permission': permission
                      })
        return HttpResponseRedirect(next)

    return render_to_response('generic_confirm.html', {
        'object': requester,
        'next': next,
        'previous': previous,
        'title': title,
    },
                              context_instance=RequestContext(request))
Ejemplo n.º 18
0
def role_edit(request, role_id):
    permissions = [PERMISSION_ROLE_EDIT]
    try:
        check_permissions(request.user, 'permissions', permissions)
    except Unauthorized, e:
        raise Http404(e)
Ejemplo n.º 19
0
def role_edit(request, role_id):
    check_permissions(request.user, 'permissions', [PERMISSION_ROLE_EDIT])

    return update_object(request, template_name='generic_form.html', 
        form_class=RoleForm, object_id=role_id, extra_context={
        'object_name':_(u'role')})