Skip to content

Commit

Permalink
[#766] Added permissions form to user management page
Browse files Browse the repository at this point in the history
  • Loading branch information
KasperBrandt committed Oct 13, 2014
1 parent 85fe8e3 commit e048e07
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 9 deletions.
11 changes: 11 additions & 0 deletions akvo/rsr/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,3 +205,14 @@ def save(self, request):
# TODO: The approval process of users
request.user.organisations.add(self.cleaned_data['organisation'])


class UserPermissionsForm(forms.Form):
permission = forms.ChoiceField(
choices=(
('', 'Pending'),
('2', 'User'),
('4', 'Editor'),
('3', 'Admin')
),
label=''
)
7 changes: 5 additions & 2 deletions akvo/rsr/models/organisation.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,11 @@ def all_projects(self):
from .project import Project
return Project.objects.filter(partnerships__organisation__in=self)

def users(self):
"returns a queryset of all users belonging to the organisation(s)"
from .user import User
return User.objects.filter(employments__organisation__in=self).distinct()

def __unicode__(self):
return self.name

Expand Down Expand Up @@ -291,8 +296,6 @@ def dollar_funds_needed(self):
# the ORM aggregate() doesn't work here since we may have multiple partnership relations to the same project
return self._aggregate_funds_needed(self.published_projects().dollars().distinct())

# New API end

class Meta:
app_label = 'rsr'
verbose_name = _(u'organisation')
Expand Down
15 changes: 10 additions & 5 deletions akvo/rsr/views/my_rsr.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

import json

from akvo.rsr.forms import PasswordForm, ProfileForm, UserOrganisationForm
from akvo.rsr.models import Project, User
from django.contrib.auth.decorators import login_required
from akvo.rsr.forms import PasswordForm, ProfileForm, UserOrganisationForm, UserPermissionsForm
from akvo.rsr.models import Project
from django.contrib.auth.decorators import login_required, permission_required
from django.http import HttpResponse
from django.shortcuts import render, render_to_response
from django.template import RequestContext
Expand Down Expand Up @@ -69,8 +69,13 @@ def my_projects(request):
context = {'projects': Project.objects.published()}
return render(request, 'myrsr/my_projects.html', context)


@permission_required('rsr.delete_user', raise_exception=True)
@login_required
def user_management(request):
context = {'users': User.objects.all()}
organisations = request.user.organisations.all()
permissionsForm = UserPermissionsForm()
context = {
'users': organisations.users(),
'permissionsForm': permissionsForm
}
return render(request, 'myrsr/user_management.html', context)
2 changes: 1 addition & 1 deletion akvo/settings/10-base.conf
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ INSTALLED_APPS = (

gettext = lambda s: s

LOGIN_URL = '/signin/'
LOGIN_URL = '/sign_in/'
LOGIN_REDIRECT_URL = '/'

MIDDLEWARE_CLASSES = (
Expand Down
11 changes: 10 additions & 1 deletion akvo/templates/myrsr/user_management.html
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,16 @@ <h1>User management</h1>
{% endfor %}
</ul>
</td>
<td><i>Permission settings</i></td>
<td><form method="" action="" id="permissionsForm">{% csrf_token %}
{% for field in permissionsForm %}
{% bootstrap_field field %}
{% endfor %}
{% buttons %}
<button type="submit" class="btn btn-primary">
{% trans 'Save' %}
</button>
{% endbuttons %}
</form></td>
<td><button type="button" action="/rest/v1/user/{{ user.pk }}/?format=json" class="btn btn-danger delete-button" user_id="{{ user.pk }}">X</button></td></tr>
{% endfor %}
</table>
Expand Down

0 comments on commit e048e07

Please sign in to comment.