'POST /api/roles
Creates a new role.'

@web.expose_api
def create(self, trans, payload, **kwd):

    if (not trans.user_is_admin()):
        trans.response.status = 403
        return 'You    are    not    authorized    to    create    a    new    role.'
    name = payload.get('name', None)
    description = payload.get('description', None)
    if ((not name) or (not description)):
        trans.response.status = 400
        return 'Enter    a    valid    name    and    a    description'
    if trans.sa_session.query(trans.app.model.Role).filter((trans.app.model.Role.table.c.name == name)).first():
        trans.response.status = 400
        return 'A    role    with    that    name    already    exists'
    role_type = trans.app.model.Role.types.ADMIN
    role = trans.app.model.Role(name=name, description=description, type=role_type)
    trans.sa_session.add(role)
    user_ids = payload.get('user_ids', [])
    users = [trans.sa_session.query(trans.model.User).get(trans.security.decode_id(i)) for i in user_ids]
    group_ids = payload.get('group_ids', [])
    groups = [trans.sa_session.query(trans.model.Group).get(trans.security.decode_id(i)) for i in group_ids]
    for user in users:
        trans.app.security_agent.associate_user_role(user, role)
    for group in groups:
        trans.app.security_agent.associate_group_role(group, role)
    trans.sa_session.flush()
    encoded_id = trans.security.encode_id(role.id)
    item = role.to_dict(view='element', value_mapper={'id': trans.security.encode_id})
    item['url'] = url_for('role', id=encoded_id)
    return [item]
