allow members of a team to edit its profile

This commit is contained in:
Changaco 2015-10-01 17:49:51 +02:00
parent 06f546a245
commit ceeecac8b1
9 changed files with 72 additions and 63 deletions

View File

@ -36,6 +36,8 @@ Liberapay.init = function() {
);
}
$('.notification .close').click(function(){ $(this).parent().fadeOut() });
Liberapay.lookup.init();
};
Liberapay.error = function(jqXHR, textStatus, errorThrown) {

42
js/lookup.js Normal file
View File

@ -0,0 +1,42 @@
Liberapay.lookup = {};
Liberapay.lookup.init = function() {
$('form.username-lookup').each(function() {
var $form = $(this);
var $input = $form.find('input[name="username"]');
var $results = $form.find('.lookup-results');
var lookup_timeout = null;
function lookup() {
if (lookup_timeout) clearTimeout(lookup_timeout);
var query = $(this).val();
if (query.length < 3)
$results.empty();
else {
lookup_timeout = setTimeout(function() {
jQuery.get("/search.json", {scope: 'usernames', q: query}).success(drawLookupResults);
}, 300);
}
}
function drawLookupResults(results) {
var items = [];
var results = results.usernames;
for (var i=0, len=results.length; i<len; i++) {
var result = results[i];
items.push(Liberapay.jsonml(
['li', {"data-id": result.id}, result.username]
));
}
$results.html(items);
}
function selectLookupResult() {
$input.val($(this).html());
$results.empty();
}
$results.on('click', 'li', selectLookupResult);
$input.keyup(lookup);
});
};

View File

@ -1,39 +0,0 @@
Liberapay.team = (function() {
function init() {
$('#lookup-results').on('click', 'li', selectLookupResult);
$('#query').keyup(lookup);
}
var lookup_timeout = null;
var $query = $('#query');
function lookup() {
if (lookup_timeout) clearTimeout(lookup_timeout);
var query = $query.val();
if (query.length < 3)
$('#lookup-results').empty();
else {
lookup_timeout = setTimeout(function() {
jQuery.get("/search.json", {scope: 'usernames', q: query}).success(drawLookupResults);
}, 300);
}
}
function drawLookupResults(results) {
var items = [];
var results = results.usernames;
for (var i=0, len=results.length; i<len; i++) {
var result = results[i];
items.push(Liberapay.jsonml(
['li', {"data-id": result.id}, result.username]
));
}
$('#lookup-results').html(items);
}
function selectLookupResult() {
$('#query').val($(this).html());
$('#lookup-results').empty();
}
return {init: init};
})();

View File

@ -15,7 +15,7 @@ import liberapay
BEGINNING_OF_EPOCH = to_rfc822(datetime(1970, 1, 1)).encode('ascii')
def get_participant(state, restrict=True, redirect_stub=True):
def get_participant(state, restrict=True, redirect_stub=True, allow_member=False):
"""Given a Request, raise Response or return Participant.
If restrict is True then we'll restrict access to owners and admins.
@ -66,7 +66,9 @@ def get_participant(state, restrict=True, redirect_stub=True):
if restrict:
if participant != user:
if not user.is_admin:
if allow_member and participant.kind == 'group' and user.member_of(participant):
pass
elif not user.is_admin:
raise Response(403, _("You are not authorized to access this page."))
return participant

View File

@ -12,4 +12,8 @@
</li>
{% endfor %}
</ul>
{% if edit %}
<br>
{% include "templates/team-invite.html" %}
{% endif %}
</div>

View File

@ -0,0 +1,13 @@
<form action="/{{ participant.username }}/membership/invite?back_to={{ urlquote(request.line.uri) }}"
method="POST"
class="username-lookup">
<input name="csrf_token" type="hidden" value="{{ csrf_token }}" />
<div class="input-group">
<input name="username" class="form-control" autocomplete="off"
placeholder="{{ _('Enter a username') }}" />
<div class="input-group-btn">
<button class="btn btn-success">{{ _("Invite") }}</button>
</div>
</div>
<ul class="lookup-results"></ul>
</form>

View File

@ -9,7 +9,7 @@ from liberapay.utils import get_participant, markdown
from liberapay.utils.i18n import LANGUAGES_2
[---]
participant = get_participant(state, restrict=True)
participant = get_participant(state, restrict=True, allow_member=True)
if request.method == 'POST':
lang = request.body['lang']
@ -62,9 +62,7 @@ title = participant.username
{% endblock %}
{% block heading %}
{% if user == participant %}
<a href="." class="btn btn-success btn-lg pull-right">{{ _("View") }}</a>
{% endif %}
{{ super() }}
{% endblock %}
@ -169,8 +167,12 @@ title = participant.username
{% endif %}
</div>
{% if participant.kind == 'group' %}
{% include "templates/members-listing.html" %}
{% else %}
{% include "templates/connected-accounts.html" %}
{% include "templates/team-listing.html" %}
{% include "templates/community-listing.html" %}
{% endif %}
</div>
{% endblock %}

View File

@ -21,7 +21,7 @@ langs = 'en fr de it es'.split()
{% extends "templates/profile.html" %}
{% block heading %}
{% if user == participant %}
{% if user == participant or participant.kind == 'group' and user.member_of(participant) %}
<a href="edit" class="btn btn-primary btn-lg pull-right">{{ _("Edit") }}</a>
{% endif %}
{{ super() }}

View File

@ -25,11 +25,6 @@ subhead = _("Team Members")
[-----------------------------------------------------------------------------]
{% extends "templates/profile.html" %}
{% block scripts %}
<script>$(document).ready(Liberapay.team.init);</script>
{{ super() }}
{% endblock %}
{% block content %}
<div class="row paragraph">
<div class="col-md-12">
@ -74,19 +69,7 @@ subhead = _("Team Members")
{% if user.id in members %}
<h2>{{ _("Management") }}</h2>
<p>{{ _("As a member of this team you can invite other users to join it:") }}</p>
<div id="lookup-container">
<form action="invite/" method="POST">
<input name="csrf_token" type="hidden" value="{{ csrf_token }}" />
<div class="input-group">
<input id="query" name="username" class="form-control" autocomplete="off"
placeholder="{{ _('Enter a username') }}" />
<div class="input-group-btn">
<button class="btn btn-success">{{ _("Invite") }}</button>
</div>
</div>
<ul id="lookup-results"></ul>
</form>
</div>
{% include "templates/team-invite.html" %}
<br>
<p>{{ _("You can leave the team whenever you want:") }}</p>
<a class="btn btn-warning" href="leave">{{ _("Leave this team") }}</a>