'TEMPORARY ENDPOINT - added back to support admin-level user info
editing prior to adminjs.  This is code that was prematurely removed
from the user controller when the user-side editing functionality was
replaced.
The method manage_user_info, which follows this, should also be removed
at that time.
Edit user information = username, email or password.'

@web.expose
@web.require_admin
def edit_info(self, trans, cntrller, **kwd):

    params = util.Params(kwd)
    is_admin = ((cntrller == 'admin') and trans.user_is_admin())
    message = util.restore_text(params.get('message', ''))
    status = params.get('status', 'done')
    user_id = params.get('user_id', None)
    if (user_id and is_admin):
        user = trans.sa_session.query(trans.app.model.User).get(trans.security.decode_id(user_id))
    elif (user_id and ((not trans.user) or (trans.user.id != trans.security.decode_id(user_id)))):
        message = 'Invalid    user    id'
        status = 'error'
        user = None
    else:
        user = trans.user
    if (user and params.get('login_info_button', False)):
        email = util.restore_text(params.get('email', ''))
        username = util.restore_text(params.get('username', '')).lower()
        message = validate_email(trans, email, user)
        if ((not message) and username):
            message = validate_publicname(trans, username, user)
        if message:
            status = 'error'
        else:
            if (user.email != email):
                private_role = trans.app.security_agent.get_private_user_role(user)
                private_role.name = email
                private_role.description = ('Private    role    for    ' + email)
                user.email = email
                trans.sa_session.add_all((user, private_role))
                trans.sa_session.flush()
                if ((trans.webapp.name == 'galaxy') and trans.app.config.user_activation_on):
                    user.active = False
                    trans.sa_session.add(user)
                    trans.sa_session.flush()
                    is_activation_sent = self.send_verification_email(trans, user.email, user.username)
                    if is_activation_sent:
                        message = 'The    login    information    has    been    updated    with    the    changes.<br>Verification    email    has    been    sent    to    your    new    email    address.    Please    verify    it    by    clicking    the    activation    link    in    the    email.<br>Please    check    your    spam/trash    folder    in    case    you    cannot    find    the    message.'
                    else:
                        message = 'Unable    to    send    activation    email,    please    contact    your    local    Galaxy    administrator.'
                        if (trans.app.config.error_email_to is not None):
                            message += ('    Contact:    %s' % trans.app.config.error_email_to)
            if (user.username != username):
                user.username = username
                trans.sa_session.add(user)
                trans.sa_session.flush()
            message = 'The    login    information    has    been    updated    with    the    changes.'
    elif (user and params.get('edit_user_info_button', False)):
        user_type_fd_id = params.get('user_type_fd_id', 'none')
        if (user_type_fd_id not in ['none']):
            user_type_form_definition = trans.sa_session.query(trans.app.model.FormDefinition).get(trans.security.decode_id(user_type_fd_id))
        elif user.values:
            user_type_form_definition = user.values.form_definition
        else:
            user_type_form_definition = None
        if user_type_form_definition:
            values = self.get_form_values(trans, user, user_type_form_definition, **kwd)
        else:
            values = {}
        flush_needed = False
        if user.values:
            user.values.content = values
            trans.sa_session.add(user.values)
            flush_needed = True
        elif values:
            form_values = trans.model.FormValues(user_type_form_definition, values)
            trans.sa_session.add(form_values)
            user.values = form_values
            flush_needed = True
        if flush_needed:
            trans.sa_session.add(user)
            trans.sa_session.flush()
        message = 'The    user    information    has    been    updated    with    the    changes.'
    if (user and (trans.webapp.name == 'galaxy') and is_admin):
        kwd['user_id'] = trans.security.encode_id(user.id)
    kwd['id'] = user_id
    if message:
        kwd['message'] = util.sanitize_text(message)
    if status:
        kwd['status'] = status
    return trans.response.send_redirect(web.url_for(controller='user', action='manage_user_info', cntrller=cntrller, **kwd))
