Example #1
0
    def filterIntent(self, intent: str, session: DialogSession) -> bool:
        # Return if previous intent is not supported by this module
        if session.previousIntent and session.previousIntent not in self._supportedIntents:
            return False

        # Return if this intent is not supported by this module
        if not intent in self._supportedIntents:
            return False

        if intent in self._authOnlyIntents:
            # Return if intent is for auth users only but the user is unknown
            if session.user == constants.UNKNOWN_USER:
                self.endDialog(sessionId=session.sessionId,
                               text=self.TalkManager.randomTalk(
                                   talk='unknowUser', module='system'))
                raise AccessLevelTooLow()
            # Return if intent is for auth users only and the user doesn't have the accesslevel for it
            if not self.UserManager.hasAccessLevel(
                    session.user, self._authOnlyIntents[intent]):
                self.endDialog(sessionId=session.sessionId,
                               text=self.TalkManager.randomTalk(
                                   talk='noAccess', module='system'))
                raise AccessLevelTooLow()

        return True
Example #2
0
 def authenticateIntent(self, session: DialogSession):
     intent = self._supportedIntents[session.message.topic]
     # Return if intent is for auth users only but the user is unknown
     if session.user == constants.UNKNOWN_USER:
         self.endDialog(sessionId=session.sessionId,
                        text=self.TalkManager.randomTalk(talk='unknowUser',
                                                         skill='system'))
         raise AccessLevelTooLow()
     # Return if intent is for auth users only and the user doesn't have the accesslevel for it
     if not self.UserManager.hasAccessLevel(session.user, intent.authLevel):
         self.endDialog(sessionId=session.sessionId,
                        text=self.TalkManager.randomTalk(talk='noAccess',
                                                         skill='system'))
         raise AccessLevelTooLow()