'*POST /api/libraries/datasets/{encoded_dataset_id}/permissions
Set permissions of the given dataset to the given role ids.
:param  encoded_dataset_id:      the encoded id of the dataset to update permissions of
:type   encoded_dataset_id:      an encoded id string
:param   payload: dictionary structure containing:
:param  action:     (required) describes what action should be performed
available actions: make_private, remove_restrictions, set_permissions
:type   action:     string
:param  access_ids[]:      list of Role.id defining roles that should have access permission on the dataset
:type   access_ids[]:      string or list
:param  manage_ids[]:      list of Role.id defining roles that should have manage permission on the dataset
:type   manage_ids[]:      string or list
:param  modify_ids[]:      list of Role.id defining roles that should have modify permission on the library dataset item
:type   modify_ids[]:      string or list
:type:      dictionary
:returns:   dict of current roles for all available permission types
:rtype:     dictionary
:raises: RequestParameterInvalidException, ObjectNotFound, InsufficientPermissionsException, InternalServerError
RequestParameterMissingException'

@expose_api
def update_permissions(self, trans, encoded_dataset_id, payload=None, **kwd):

    if payload:
        kwd.update(payload)
    try:
        library_dataset = self.get_library_dataset(trans, id=encoded_dataset_id, check_ownership=False, check_accessible=False)
    except Exception as e:
        raise exceptions.ObjectNotFound(('Requested    dataset    was    not    found.' + str(e)))
    dataset = library_dataset.library_dataset_dataset_association.dataset
    current_user_roles = trans.get_current_user_roles()
    can_manage = (trans.app.security_agent.can_manage_dataset(current_user_roles, dataset) or trans.user_is_admin())
    if (not can_manage):
        raise exceptions.InsufficientPermissionsException('You    do    not    have    proper    permissions    to    manage    permissions    on    this    dataset.')
    new_access_roles_ids = util.listify(kwd.get('access_ids[]', None))
    new_manage_roles_ids = util.listify(kwd.get('manage_ids[]', None))
    new_modify_roles_ids = util.listify(kwd.get('modify_ids[]', None))
    action = kwd.get('action', None)
    if (action is None):
        raise exceptions.RequestParameterMissingException('The    mandatory    parameter    "action"    is    missing.')
    elif (action == 'remove_restrictions'):
        trans.app.security_agent.make_dataset_public(dataset)
        if (not trans.app.security_agent.dataset_is_public(dataset)):
            raise exceptions.InternalServerError('An    error    occured    while    making    dataset    public.')
    elif (action == 'make_private'):
        if (not trans.app.security_agent.dataset_is_private_to_user(trans, library_dataset)):
            private_role = trans.app.security_agent.get_private_user_role(trans.user)
            dp = trans.app.model.DatasetPermissions(trans.app.security_agent.permitted_actions.DATASET_ACCESS.action, dataset, private_role)
            trans.sa_session.add(dp)
            trans.sa_session.flush()
        if (not trans.app.security_agent.dataset_is_private_to_user(trans, library_dataset)):
            raise exceptions.InternalServerError('An    error    occured    and    the    dataset    is    NOT    private.')
    elif (action == 'set_permissions'):
        valid_access_roles = []
        invalid_access_roles_ids = []
        if (new_access_roles_ids is None):
            trans.app.security_agent.make_dataset_public(dataset)
        else:
            for role_id in new_access_roles_ids:
                role = self.role_manager.get(trans, self.__decode_id(trans, role_id, 'role'))
                (valid_roles, total_roles) = trans.app.security_agent.get_valid_roles(trans, dataset)
                if (role in valid_roles):
                    valid_access_roles.append(role)
                else:
                    invalid_access_roles_ids.append(role_id)
            if (len(invalid_access_roles_ids) > 0):
                log.warning(('The    following    roles    could    not    be    added    to    the    dataset    access    permission:    ' + str(invalid_access_roles_ids)))
            access_permission = dict(access=valid_access_roles)
            trans.app.security_agent.set_dataset_permission(dataset, access_permission)
        valid_manage_roles = []
        invalid_manage_roles_ids = []
        new_manage_roles_ids = util.listify(new_manage_roles_ids)
        active_access_roles = dataset.get_access_roles(trans)
        for role_id in new_manage_roles_ids:
            role = self.role_manager.get(trans, self.__decode_id(trans, role_id, 'role'))
            if (role in active_access_roles):
                valid_manage_roles.append(role)
            else:
                invalid_manage_roles_ids.append(role_id)
        if (len(invalid_manage_roles_ids) > 0):
            log.warning(('The    following    roles    could    not    be    added    to    the    dataset    manage    permission:    ' + str(invalid_manage_roles_ids)))
        manage_permission = {trans.app.security_agent.permitted_actions.DATASET_MANAGE_PERMISSIONS: valid_manage_roles}
        trans.app.security_agent.set_dataset_permission(dataset, manage_permission)
        valid_modify_roles = []
        invalid_modify_roles_ids = []
        new_modify_roles_ids = util.listify(new_modify_roles_ids)
        active_access_roles = dataset.get_access_roles(trans)
        for role_id in new_modify_roles_ids:
            role = self.role_manager.get(trans, self.__decode_id(trans, role_id, 'role'))
            if (role in active_access_roles):
                valid_modify_roles.append(role)
            else:
                invalid_modify_roles_ids.append(role_id)
        if (len(invalid_modify_roles_ids) > 0):
            log.warning(('The    following    roles    could    not    be    added    to    the    dataset    modify    permission:    ' + str(invalid_modify_roles_ids)))
        modify_permission = {trans.app.security_agent.permitted_actions.LIBRARY_MODIFY: valid_modify_roles}
        trans.app.security_agent.set_library_item_permission(library_dataset, modify_permission)
    else:
        raise exceptions.RequestParameterInvalidException('The    mandatory    parameter    "action"    has    an    invalid    value.    Allowed    values    are:    "remove_restrictions",    "make_private",    "set_permissions"')
    return self._get_current_roles(trans, library_dataset)
