Commit 8cafa0f1 authored by Sofia Papagiannaki's avatar Sofia Papagiannaki
Browse files

Enable group owner to add members

Refs: #2793
parent cfacc6c7
......@@ -572,5 +572,30 @@ class AstakosGroupUpdateForm(forms.ModelForm):
model = AstakosGroup
fields = ('homepage', 'desc')
class AddGroupMembersForm(forms.Form):
q = forms.CharField(max_length=800, widget=forms.Textarea, label=_('Search users'),
help_text=_('Add comma separated user emails'),
required=True)
def clean(self):
q = self.cleaned_data.get('q') or ''
users = q.split(',')
users = list(u.strip() for u in users if u)
db_entries = AstakosUser.objects.filter(email__in=users)
unknown = list(set(users) - set(u.email for u in db_entries))
if unknown:
raise forms.ValidationError(
_('Unknown users: %s' % unknown))
self.valid_users = db_entries
return self.cleaned_data
def get_valid_users(self):
"""Should be called after form cleaning"""
try:
return self.valid_users
except:
return ()
class AstakosGroupSearchForm(forms.Form):
q = forms.CharField(max_length=200, label='Search group')
......@@ -129,13 +129,15 @@
</div>
{% if user in object.owner.all and more_policies %}
{% if user in object.owner.all %}
<div class="full-dotted">
<form action="{% url group_policies_add object.id %}" method="post" class="withlabels">{% csrf_token %}
<h2>NEW POLICY</h2>
{% include "im/form_render.html" %}
<form action="{% url add_members object.id %}" method="post" class="withlabels">{% csrf_token %}
<h2>Enroll more members</h2>
{% with search_form as form %}
{% include "im/form_render.html" %}
{% endwith %}
<div class="form-row submit">
<input type="submit" class="submit altcol" value="ADD POLICY" />
<input type="submit" class="submit altcol" value="ADD MEMBERS" />
</div>
</form>
</div>
......
......@@ -42,12 +42,14 @@ urlpatterns = patterns('astakos.im.views',
url(r'^profile/?$',
'edit_profile', {}, name='edit_profile'),
url(r'^feedback/?$', 'feedback', {}, name='feedback'),
url(
r'^signup/?$', 'signup', {'on_success': 'im/login.html',
'extra_context': {'login_form': LoginForm()}}, name='signup'),
url(
r'^logout/?$', 'logout', {'template': 'im/login.html',
'extra_context': {'login_form': LoginForm()}}, name='logout'),
url(r'^signup/?$', 'signup',
{'on_success': 'im/login.html',
'extra_context': {'login_form': LoginForm()}},
name='signup'),
url(r'^logout/?$', 'logout',
{'template': 'im/login.html',
'extra_context': {'login_form': LoginForm()}},
name='logout'),
url(r'^activate/?$', 'activate', {}, name='activate'),
url(r'^approval_terms/?$',
'approval_terms', {}, name='latest_terms'),
......@@ -62,25 +64,24 @@ urlpatterns = patterns('astakos.im.views',
'group_add', {}, name='group_add'),
url(r'^group/list/?$',
'group_list', {}, name='group_list'),
url(r'^group/(?P<group_id>\d+)/?$', 'group_detail', {},
name='group_detail'),
url(r'^group/(?P<group_id>\d+)/?$', 'group_detail',
{}, name='group_detail'),
url(r'^group/update/(?P<group_id>\d+)/?$',
'group_update', {}, name='group_update'),
url(r'^group/search/?$',
'group_search', {}, name='group_search'),
url(r'^group/all/?$',
'group_all', {}, name='group_all'),
url(r'^group/(?P<group_id>\d+)/join/?$', 'group_join', {
},name='group_join'),
url(
r'^group/(?P<group_id>\d+)/leave/?$', 'group_leave', {},
name='group_leave'),
url(
r'^group/(?P<group_id>\d+)/(?P<user_id>\d+)/approve/?$',
'approve_member', {}, name='approve_member'),
url(
r'^group/(?P<group_id>\d+)/(?P<user_id>\d+)/disapprove/?$',
'disapprove_member', {}, name='disapprove_member'),
url(r'^group/(?P<group_id>\d+)/join/?$', 'group_join',
{}, name='group_join'),
url(r'^group/(?P<group_id>\d+)/leave/?$', 'group_leave',
{}, name='group_leave'),
url(r'^group/(?P<group_id>\d+)/(?P<user_id>\d+)/approve/?$',
'approve_member', {}, name='approve_member'),
url(r'^group/(?P<group_id>\d+)/(?P<user_id>\d+)/disapprove/?$',
'disapprove_member', {}, name='disapprove_member'),
url(r'^group/(?P<group_id>\d+)/add/?$',
'add_members', {}, name='add_members'),
url(r'^group/create/?$', 'group_create_list', {},
name='group_create_list'),
)
......
......@@ -67,7 +67,7 @@ from astakos.im.forms import (LoginForm, InvitationForm, ProfileForm,
FeedbackForm, SignApprovalTermsForm,
ExtendedPasswordChangeForm, EmailChangeForm,
AstakosGroupCreationForm, AstakosGroupSearchForm,
AstakosGroupUpdateForm)
AstakosGroupUpdateForm, AddGroupMembersForm)
from astakos.im.functions import (send_feedback, SendMailError,
invite as invite_func, logout as auth_logout,
activate as activate_func,
......@@ -733,11 +733,13 @@ def group_detail(request, group_id):
except AstakosGroup.DoesNotExist:
return HttpResponseBadRequest(_('Invalid group.'))
form = AstakosGroupUpdateForm(instance=group)
search_form = AddGroupMembersForm()
return object_detail(request,
AstakosGroup.objects.all(),
object_id=group_id,
extra_context={'quota': group.quota,
'form': form}
'form': form,
'search_form': search_form}
)
......@@ -753,11 +755,13 @@ def group_update(request, group_id):
form = AstakosGroupUpdateForm(request.POST, instance=group)
if form.is_valid():
form.save()
search_form = AddGroupMembersForm()
return object_detail(request,
AstakosGroup.objects.all(),
object_id=group_id,
extra_context={'quota': group.quota,
'form': form})
'form': form,
'search_form': search_form})
@signed_terms_required
@login_required
......@@ -896,6 +900,32 @@ def disapprove_member(request, membership):
messages.error(request, msg)
@signed_terms_required
@login_required
def add_members(request, group_id):
if request.method != 'POST':
return HttpResponseBadRequest(_('Bad method'))
try:
group = AstakosGroup.objects.select_related().get(id=group_id)
except AstakosGroup.DoesNotExist:
return HttpResponseBadRequest(_('Invalid group.'))
search_form = AddGroupMembersForm(request.POST)
if search_form.is_valid():
users = search_form.get_valid_users()
map(group.approve_member, users)
search_form = AddGroupMembersForm()
form = AstakosGroupUpdateForm(instance=group)
return object_detail(request,
AstakosGroup.objects.all(),
object_id=group_id,
extra_context={'quota': group.quota,
'form': form,
'search_form' : search_form}
)
@signed_terms_required
@login_required
def resource_list(request):
......
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