Skip to content

Commit

Permalink
collaborationgroups web tested and running
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian Glatthard committed Aug 6, 2015
1 parent 5785176 commit 49c08af
Show file tree
Hide file tree
Showing 6 changed files with 190 additions and 44 deletions.
5 changes: 3 additions & 2 deletions ipynbsrv/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,12 +388,15 @@ def remove_admin(self, user):
def remove_member(self, user):
"""
Remove the member `user` from the group.
If the user appears to be a group admin, he/she will also be removed as admin.
:param user: The user to remove (if is member).
:return bool `True` if the user has been a member and removed.
"""
print("remove %s" % user)
if self.user_is_member(user):
self.remove_admin(user)
self.user_set.remove(user.django_user)
return True
return False
Expand All @@ -412,7 +415,6 @@ def user_is_admin(self, user):
:param user: The user to check.
"""
return user in self.admins.all()
user_is_admin.boolean = True

def user_is_member(self, user):
"""
Expand All @@ -421,7 +423,6 @@ def user_is_member(self, user):
:param user: The user to check for membership.
"""
return user in self.get_members()
user_is_member.boolean = True


class Container(models.Model):
Expand Down
10 changes: 5 additions & 5 deletions ipynbsrv/web/templates/web/collaborationgroups/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ <h1>My Groups</h1>
{% else %} {% if request.user.backend_user.id in group.member_ids %}<span class="label label-info">Member</span>{% endif %}{% endif %}
</td>
<td>
{% if request.user.backend_user.id != group.creator and group.creator %}
{% if request.user.backend_user.id != group.creator.id and group.creator %}
{% if request.user.backend_user.id in group.member_ids %}
<form action="{% url 'group_remove_member' %}" method="POST" role="form" class="form-action">
<form action="{% url 'group_leave' %}" method="POST" role="form" class="form-action">
{% csrf_token %}
<input type="hidden" name="group_id" value="{{ group.id }}">
<input type="hidden" name="user_id" value="{{ request.user.id }}">
Expand All @@ -50,18 +50,18 @@ <h1>My Groups</h1>
</button>
</form>
{% else %}
<form action="{% url 'group_add_members' %}" method="POST" role="form" class="form-action">
<form action="{% url 'group_join' %}" method="POST" role="form" class="form-action">
{% csrf_token %}
<input type="hidden" name="group_id" value="{{ group.id }}">
<input type="hidden" name="users" value="{{ request.user.id }}">
<input type="hidden" name="user_id" value="{{ request.user.id }}">
<button class="btn btn-sm btn-success" title="Join group?" data-toggle="confirmation" data-placement="left">
<i class="glyphicon glyphicon-plus-sign" aria-hidden="true"></i>
</button>
</form>
{% endif %}
{% endif %}

{% if request.user.backend_user.id == group.creator or request.user.id in group.admins %}
{% if request.user.backend_user.id == group.creator.id or request.user.id in group.admins %}
<form action="{% url 'group_delete' %}" method="POST" role="form" class="form-action">
{% csrf_token %}
<input type="hidden" name="group_id" value="{{ group.id }}">
Expand Down
39 changes: 29 additions & 10 deletions ipynbsrv/web/templates/web/collaborationgroups/manage.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,25 @@ <h1>Group</h1>
<form action="{% url 'group_delete' %}" method="POST" role="form">
{% csrf_token %}
<input type="hidden" name="group_id" value="{{ group.id }}">
<button type="submit" class="btn btn-primary btn-delete pull-right" data-toggle="modal" data-target="#modal-group-delete">
Delete Group
<button class="btn btn-danger btn-delete pull-right" title="Delete this group?" data-toggle="confirmation" data-placement="bottom">Delete Group
</button>
</form>
{% endif %}
{% if request.user.backend_user.id in group.admins and request.user.backend_user.id != group.creator %}
<form role="form">
<button type="button" class="btn btn-primary btn-leave pull-right" data-toggle="modal" data-target="#modal-group-leave">
Leave Group
{% if request.user.backend_user.id not in group.member_ids and group.is_public %}
<form action="{% url 'group_join' %}" method="POST" role="form">
{% csrf_token %}
<input type="hidden" name="group_id" value="{{ group.id }}">
<input type="hidden" name="user_id" value="{{ request.user.id }}">
<button class="btn btn-primary btn-delete pull-right" title="Join this public group?" data-toggle="confirmation" data-placement="bottom">Join Group
</button>
</form>
{% endif %}
{% if request.user.backend_user.id in group.member_ids and request.user.backend_user.id != group.creator %}
<form action="{% url 'group_leave' %}" method="POST" role="form">
{% csrf_token %}
<input type="hidden" name="group_id" value="{{ group.id }}">
<input type="hidden" name="user_id" value="{{ request.user.id }}">
<button class="btn btn-warning btn-delete pull-right" title="Leave this public group?" data-toggle="confirmation" data-placement="bottom">Leave Group
</button>
</form>
{% endif %}
Expand Down Expand Up @@ -66,8 +76,8 @@ <h2>Members</h2>
{% if member.id in group.admins %} <span class="label label-info">Admin</span>{% endif %}
{% if member.id == group.creator.id %} <span class="label label-info">Creator</span>{% endif %}</td>
<td style="text-align: right">
{% if request.user.backend_user.id != group.creator and group.creator and request.user.backend_user.id == member.id %}
<form action="{% url 'group_remove_member' %}" method="POST" role="form" class="form-action">
{% if request.user.backend_user.id != group.creator.id and group.creator and request.user.backend_user.id == member.id %}
<form action="{% url 'group_leave' %}" method="POST" role="form" class="form-action">
{% csrf_token %}
<input type="hidden" name="group_id" value="{{ group.id }}">
<input type="hidden" name="user_id" value="{{ request.user.id }}">
Expand All @@ -77,7 +87,6 @@ <h2>Members</h2>
</form>
{% endif %}
{% if request.user.backend_user.id in group.admins or request.user.backend_user.id == group.creator.id %}

{% if member.id != group.creator.id %}
<form action="{% url 'group_remove_member' %}" method="POST" role="form" class="form-action">
{% csrf_token %}
Expand All @@ -98,6 +107,16 @@ <h2>Members</h2>
</button>
</form>
{% endif %}
{% if member.id in group.admins and member.id != group.creator.id %}
<form action="{% url 'group_remove_admin' %}" method="POST" role="form" class="form-action">
{% csrf_token %}
<input type="hidden" name="group_id" value="{{ group.id }}">
<input type="hidden" name="user_id" value="{{ member.django_user.id }}">
<button class="btn btn-sm btn-warning" title="Remove from group admins?" data-toggle="confirmation" data-placement="left">
<i class="glyphicon glyphicon glyphicon-king" aria-hidden="true"></i>
</button>
</form>
{% endif %}

{% endif %}
</td>
Expand All @@ -106,7 +125,7 @@ <h2>Members</h2>
</tbody>
</table>

{% include 'web/collaborationgroups/modal_addusers.html' with users=users origin='manage' group=group member_ids=member_ids csrf_token=csrf_token only %}
{% include 'web/collaborationgroups/modal_addusers.html' with users=users origin='manage' group=group csrf_token=csrf_token only %}
</div>
</div>
{% endblock %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ <h4 class="modal-title">Add users</h4>
<div class="form-group">
<label for="recipient">Members</label>
{% for user in users %}
{% if user.backend_user and user.backend_user.id not in member_ids %}
{% if user.backend_user and user.backend_user.id not in group.member_ids %}
<div class="checkbox">
<label><input name="users" type="checkbox" value="{{ user.id }}">{{ user.username }}</label>
</div>
Expand Down
3 changes: 3 additions & 0 deletions ipynbsrv/web/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@
url(r'^groups/delete$', 'ipynbsrv.web.views.collaborationgroups.delete', name='group_delete'),
url(r'^groups/manage/(\d+)$', 'ipynbsrv.web.views.collaborationgroups.manage', name='group_manage'),
url(r'^groups/remove_member$', 'ipynbsrv.web.views.collaborationgroups.remove_member', name='group_remove_member'),
url(r'^groups/leave$', 'ipynbsrv.web.views.collaborationgroups.leave', name='group_leave'),
url(r'^groups/join$', 'ipynbsrv.web.views.collaborationgroups.join', name='group_join'),
url(r'^groups/add_admin$', 'ipynbsrv.web.views.collaborationgroups.add_admin', name='group_add_admin'),
url(r'^groups/remove_admin$', 'ipynbsrv.web.views.collaborationgroups.remove_admin', name='group_remove_admin'),
url(r'^groups/add_users$', 'ipynbsrv.web.views.collaborationgroups.add_members', name='group_add_members'),

# /container(s)/...
Expand Down
Loading

0 comments on commit 49c08af

Please sign in to comment.