36 lines
1.0 KiB
Python
36 lines
1.0 KiB
Python
|
from flask import Blueprint, request
|
||
|
from zope import component
|
||
|
|
||
|
from .utils import authz_restrict_to_staff, create_streaming_response
|
||
|
from ceo_common.errors import UserNotFoundError
|
||
|
from ceo_common.interfaces import ILDAPService
|
||
|
from ceod.transactions.members import AddMemberTransaction
|
||
|
|
||
|
bp = Blueprint('members', __name__)
|
||
|
|
||
|
|
||
|
@bp.route('/', methods=['POST'], strict_slashes=False)
|
||
|
@authz_restrict_to_staff
|
||
|
def create_user():
|
||
|
body = request.get_json(force=True)
|
||
|
txn = AddMemberTransaction(
|
||
|
uid=body['uid'],
|
||
|
cn=body['cn'],
|
||
|
program=body.get('program'),
|
||
|
terms=body.get('terms'),
|
||
|
non_member_terms=body.get('non_member_terms'),
|
||
|
forwarding_addresses=body.get('forwarding_addresses'),
|
||
|
)
|
||
|
return create_streaming_response(txn)
|
||
|
|
||
|
|
||
|
@bp.route('/<username>')
|
||
|
def get_user(username: str):
|
||
|
ldap_srv = component.getUtility(ILDAPService)
|
||
|
try:
|
||
|
return ldap_srv.get_user(username).to_dict()
|
||
|
except UserNotFoundError:
|
||
|
return {
|
||
|
'error': 'user not found'
|
||
|
}, 404
|