Exemple #1
0
    def acceptShare(self, request, inviteUID, summary):

        # Accept the share
        try:
            shareeView = yield self._newStoreHome.acceptShare(
                inviteUID, summary)
        except DirectoryRecordNotFoundError:
            # Missing sharer record => fail request
            raise HTTPError(
                ErrorResponse(
                    responsecode.FORBIDDEN,
                    (calendarserver_namespace, "invalid-share"),
                    "Invite UID not valid",
                ))
        if shareeView is None:
            raise HTTPError(
                ErrorResponse(
                    responsecode.FORBIDDEN,
                    (calendarserver_namespace, "invalid-share"),
                    "Invite UID not valid",
                ))

        # Return the URL of the shared collection
        sharedAsURL = joinURL(self.url(), shareeView.shareName())
        returnValue(
            XMLResponse(code=responsecode.OK,
                        element=customxml.SharedAs(
                            element.HRef.fromString(sharedAsURL))))
Exemple #2
0
    def directShare(self, request):
        """
        Directly bind an accessible calendar/address book collection into the
        current principal's calendar/addressbook home.

        @param request: the request triggering this action
        @type request: L{IRequest}

        @return: the (asynchronous) HTTP result to respond to the direct-share
            request.
        @rtype: L{Deferred} firing L{txweb2.http.Response}, failing with
            L{HTTPError}
        """

        # Need to have at least DAV:read to do this
        yield self.authorize(request, (element.Read(), ))

        # Find current principal
        authz_principal = self.currentPrincipal(request).children[0]
        if not isinstance(authz_principal, element.HRef):
            raise HTTPError(
                ErrorResponse(
                    responsecode.FORBIDDEN,
                    (calendarserver_namespace, "valid-principal"),
                    "Current user principal not a DAV:href",
                ))
        principalURL = str(authz_principal)
        if not principalURL:
            raise HTTPError(
                ErrorResponse(
                    responsecode.FORBIDDEN,
                    (calendarserver_namespace, "valid-principal"),
                    "Current user principal not specified",
                ))
        sharee = (yield request.locateResource(principalURL))

        # Check enabled for service
        from twistedcaldav.directory.principal import DirectoryCalendarPrincipalResource
        if not isinstance(sharee, DirectoryCalendarPrincipalResource):
            raise HTTPError(
                ErrorResponse(
                    responsecode.FORBIDDEN,
                    (calendarserver_namespace, "invalid-principal"),
                    "Current user principal is not a calendar/addressbook enabled principal",
                ))

        # Get the home collection
        if self.isCalendarCollection():
            shareeHomeResource = yield sharee.calendarHome(request)
        elif self.isAddressBookCollection() or self.isGroup():
            shareeHomeResource = yield sharee.addressBookHome(request)
        else:
            raise HTTPError(
                ErrorResponse(
                    responsecode.FORBIDDEN,
                    (calendarserver_namespace, "invalid-principal"),
                    "No calendar/addressbook home for principal",
                ))

        # TODO: Make sure principal is not sharing back to themselves
        hostURL = (yield self.canonicalURL(request))
        shareeHomeURL = shareeHomeResource.url()
        if hostURL.startswith(shareeHomeURL):
            raise HTTPError(
                ErrorResponse(
                    responsecode.FORBIDDEN,
                    (calendarserver_namespace, "invalid-share"),
                    "Can't share your own calendar or addressbook",
                ))

        # Accept it
        shareeView = yield self._newStoreObject.directShareWithUser(
            sharee.principalUID())

        # Return the URL of the shared calendar
        sharedAsURL = joinURL(shareeHomeResource.url(), shareeView.name())
        returnValue(
            XMLResponse(code=responsecode.OK,
                        element=customxml.SharedAs(
                            element.HRef.fromString(sharedAsURL))))