Commit d55d6c44 authored by Claude Paroz's avatar Claude Paroz

Allow members of ADMIN_GROUP to change team coordinator

parent 9c2b7f18
......@@ -321,7 +321,7 @@ div.face_image {
ul.errorlist {
list-style: none;
margin-left: 0;
margin: 0.5em 0;
padding: 0;
}
......
......@@ -140,7 +140,7 @@ INTERNAL_IPS=('127.0.0.1',)
MESSAGE_STORAGE = 'django.contrib.messages.storage.fallback.FallbackStorage'
LOGIN_REDIRECT_URL = '/'
# Members of this group can edit all team's details
# Members of this group can edit all team's details and change team coordinatorship
ADMIN_GROUP = ''
try:
......
from django import forms
from django.utils.translation import ugettext as _
from teams.models import Team, ROLE_CHOICES
from common.utils import is_site_admin
from teams.models import Team, Role, ROLE_CHOICES
class EditTeamDetailsForm(forms.ModelForm):
class Meta:
model = Team
fields = ('webpage_url', 'mailing_list', 'mailing_list_subscribe', 'use_workflow', 'presentation')
widgets = {
'webpage_url': forms.TextInput(attrs={'size': 60}),
'mailing_list': forms.TextInput(attrs={'size': 60}),
'mailing_list_subscribe': forms.TextInput(attrs={'size': 60}),
'presentation': forms.Textarea(attrs={'cols': 60}),
}
def __init__(self, *args, **kwargs):
def __init__(self, user, *args, **kwargs):
super(EditTeamDetailsForm, self).__init__(*args, **kwargs)
for f in ('webpage_url', 'mailing_list', 'mailing_list_subscribe'):
self.fields[f].widget.attrs['size'] = 60
self.fields['presentation'].widget.attrs["cols"] = 60
self.user = user
if is_site_admin(user):
# Add coordinatorship dropdown
all_members = [(r.id, r.person.name) for r in Role.objects.select_related('person').filter(team=self.instance)]
all_members.insert(0, ('', '-------'))
try:
current_coord_pk = Role.objects.filter(team=self.instance, role='coordinator')[0].pk
except IndexError:
current_coord_pk = None
self.fields['coordinatorship'] = forms.ChoiceField(
label = _("Coordinator"),
choices = all_members,
required = False,
initial = current_coord_pk
)
def save(self, *args, **kwargs):
super(EditTeamDetailsForm, self).save(*args, **kwargs)
if 'coordinatorship' in self.changed_data and is_site_admin(self.user):
# Change coordinator
try:
# Pass current coordinator as committer
current_coord = Role.objects.filter(team=self.instance, role='coordinator')[0]
current_coord.role = 'committer'
current_coord.save()
except IndexError:
pass
if self.cleaned_data['coordinatorship']:
new_coord = Role.objects.get(pk=self.cleaned_data['coordinatorship'])
new_coord.role = 'coordinator'
new_coord.save()
class EditMemberRoleForm(forms.Form):
......
......@@ -16,7 +16,7 @@ urlpatterns = patterns('',
view = 'teams.views.teams',
name = 'teams'),
url(
regex = r'^(?P<team_slug>[\w\-@]+)$',
regex = r'^(?P<team_slug>[\w\-@]+)/$',
view = 'teams.views.team',
name = 'team_slug'),
url(
......
......@@ -125,7 +125,7 @@ def team_edit(request, team_slug):
team = get_object_or_404(Team, name=team_slug)
if not (team.can_edit(request.user) or utils.is_site_admin(request.user)):
return HttpResponseForbidden("You are not allowed to edit this team.")
form = EditTeamDetailsForm(request.POST or None, instance=team)
form = EditTeamDetailsForm(request.user, request.POST or None, instance=team)
if request.method == 'POST':
if form.is_valid():
form.save()
......
......@@ -17,12 +17,21 @@ $(document).ready(function() {
<form action="#" method="POST">
<table>
<tr><th>{{ form.webpage_url.label }}:</th><td>{{ form.webpage_url }}</td></tr>
<tr><th>{{ form.mailing_list.label }}:</th><td>{{ form.mailing_list }}</td></tr>
<tr><th>{{ form.mailing_list_subscribe.label }}:</th><td>{{ form.mailing_list_subscribe }}</td></tr>
<tr><th></th><td>{{ form.use_workflow }} <label for="id_use_workflow">{% trans "This team is using the Vertimus translation workflow" %}</label>
{% if form.coordinatorship %}
<tr><th>{{ form.coordinatorship.label }}:</th>
<td>{{ form.coordinatorship.errors}}{{ form.coordinatorship }}</td></tr>
{% endif %}
<tr><th>{{ form.webpage_url.label }}:</th>
<td>{{ form.webpage_url.errors}}{{ form.webpage_url }}</td></tr>
<tr><th>{{ form.mailing_list.label }}:</th>
<td>{{ form.mailing_list.errors }}{{ form.mailing_list }}</td></tr>
<tr><th>{{ form.mailing_list_subscribe.label }}:</th>
<td>{{ form.mailing_list_subscribe.errors }}{{ form.mailing_list_subscribe }}</td></tr>
<tr><th></th>
<td>{{ form.use_workflow }} <label for="id_use_workflow">{% trans "This team is using the Vertimus translation workflow" %}</label>
<tr><th valign="top"><span class="help">&nbsp;</span><br />{{ form.presentation.label }}:</th>
<td><span class="help">{% trans "This content may use <a href='http://en.wikipedia.org/wiki/Markdown'>Markdown</a> syntax" %}<br />
<td>{{ form.presentation.label.errors }}
<span class="help">{% trans "This content may use <a href='http://en.wikipedia.org/wiki/Markdown'>Markdown</a> syntax" %}<br />
{{ form.presentation }}</td></tr>
<tr><td colspan="2" align="right"><input type="submit" value="{% trans 'Save' %}"/></td></tr>
</table>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment