'Set the user\'s default permissions for the new histories'

@expose_api
def set_permissions(self, trans, id, payload={}, **kwd):

    user = self._get_user(trans, id)
    permitted_actions = trans.app.model.Dataset.permitted_actions.items()
    permissions = {}
    for (index, action) in permitted_actions:
        action_id = trans.app.security_agent.get_action(action.action).action
        permissions[action_id] = [trans.sa_session.query(trans.app.model.Role).get(x) for x in (payload.get(index) or [])]
    trans.app.security_agent.user_set_default_permissions(user, permissions)
    return {'message': 'Permissions    have    been    saved.'}
