<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def user_organisations(cls, user_id, state=None, include_deactivated=False):
 """ Get organisations that the user has joined :param user_id: the user ID :param state: the user's "join" state :param include_deactivated: Include deactivated resources in response :returns: list of Organisation instances :raises: SocketError, CouchException """

        if state and state not in validators.VALID_STATES:
            raise exceptions.ValidationError('Invalid "state"')

        if include_deactivated:
            organisations = yield views.joined_organisations.get(
                key=[user_id, state], include_docs=True)
        else:
            organisations = yield views.active_joined_organisations.get(
                key=[user_id, state], include_docs=True)

        raise Return([cls(**org['doc']) for org in organisations['rows']])