diff --git a/fabfile.py b/fabfile.py new file mode 100644 index 0000000..d044d7a --- /dev/null +++ b/fabfile.py @@ -0,0 +1,23 @@ +from contextlib import contextmanager as _contextmanager +from fabric.api import run, sudo, env, cd, prefix + +env.use_ssh_config = True +env.hosts = ['lynx.neuf.no'] +env.project_path = '/var/www/neuf.no/mailman2-api-minimal' +env.user = 'gitdeploy' +env.activate = 'source {}/venv/bin/activate'.format(env.project_path) + + +@_contextmanager +def virtualenv(): + with cd(env.project_path), prefix(env.activate): + yield + + +def deploy(): + with virtualenv(): + run('git pull') # Get source + run('pip install -r requirements.txt') # install deps in virtualenv + + # Reload mxapi.neuf.no + sudo('/usr/bin/supervisorctl pid mailman-api.neuf.no | xargs kill -HUP', shell=False) diff --git a/mailman_api.py b/mailman_api.py index a4195cc..b35f21c 100644 --- a/mailman_api.py +++ b/mailman_api.py @@ -28,12 +28,12 @@ def list_lists_with_members(): dest_regex = request.args.get('destination_regex') lists_w_members = [] - for listname in Utils.list_names(): - if listname == 'mailman': + for list_name in Utils.list_names(): + if list_name == 'mailman': continue - mlist = MailList.MailList(listname, lock=False) - source = mlist.GetListEmail() + m_list = MailList.MailList(list_name, lock=False) + source = m_list.GetListEmail() # Correct domain if domain_name and not source.split()[-1].endswith(domain_name): @@ -43,7 +43,7 @@ def list_lists_with_members(): if source_regex and not matches_regex(source_regex, source): continue - destinations = mlist.getMembers() + destinations = m_list.getMembers() # Matching at least one destination if dest_regex and not matches_regex(dest_regex, "\n".join(destinations)): @@ -53,7 +53,7 @@ def list_lists_with_members(): 'destinations': destinations, 'name': source, 'type': 'mailman', - 'admin_url': 'https://lists.neuf.no/admin/{}/'.format(listname), + 'admin_url': 'https://lists.neuf.no/admin/{}/'.format(list_name), 'admin_type': 'selfservice', 'num': len(destinations) }) @@ -66,7 +66,19 @@ def list_lists_with_members(): @app.route('/', methods=['GET']) def list_lists(): - return jsonify({'lists': Utils.list_names()}) + all_lists = Utils.list_names() + email = request.args.get('email') + if not email: + return jsonify({'lists': all_lists}) + + lists = [] + for list_name in all_lists: + m_list = MailList.MailList(list_name, lock=False) + members = m_list.getMembers() + if email in members: + lists.append(list_name) + + return jsonify({'lists': lists}) if __name__ == '__main__': app.run() diff --git a/requirements.txt b/requirements.txt index 632a1ef..bb84e50 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,2 @@ -Flask==0.10.1 +Flask==0.12.2 +gunicorn==19.7.1