pyceo/ceod/api/uwldap.py

36 lines
1.0 KiB
Python
Raw Normal View History

2021-08-03 10:09:07 -04:00
from flask import Blueprint, request
from flask.json import jsonify
2021-08-02 23:20:11 -04:00
from zope import component
2021-08-19 00:56:25 -04:00
from .utils import authz_restrict_to_syscom, is_truthy
2021-08-03 10:09:07 -04:00
from ceo_common.interfaces import IUWLDAPService, ILDAPService
2021-08-02 23:20:11 -04:00
bp = Blueprint('uwldap', __name__)
@bp.route('/<username>')
def get_user(username: str):
uwldap_srv = component.getUtility(IUWLDAPService)
2021-08-03 10:09:07 -04:00
record = uwldap_srv.get_user(username)
2021-08-02 23:20:11 -04:00
if record is None:
return {
'error': 'user not found',
}, 404
return record.to_dict()
2021-08-03 10:09:07 -04:00
@bp.route('/updateprograms', methods=['POST'])
@authz_restrict_to_syscom
def update_programs():
ldap_srv = component.getUtility(ILDAPService)
2021-08-19 00:56:25 -04:00
if request.headers.get('content-type') == 'application/json':
body = request.get_json()
else:
body = {}
kwargs = {'members': body.get('members')}
if body.get('dry_run') or is_truthy(request.args.get('dry_run', 'false')):
kwargs['dry_run'] = True
2021-08-17 21:59:24 -04:00
return jsonify(
ldap_srv.update_programs(**kwargs)
)