Exemplo n.º 1
0
    def update(cls, substance):
        def _validate(substance):
            if not substance:
                return False
            if not substance.get("author_name"):
                return False
            if not substance.get("mail_address"):
                return False
            return True

        author_id = substance.get("author_id")
        author_name = substance.get("author_name")
        mail_address = substance.get("mail_address")
        valid = substance.get("valid")

        if not _validate(substance):
            raise IllegalRequestError(None)

        author = Author.get_by_id(author_id)
        if not author:
            raise NoDataError(None)
        if author.mail_address != mail_address:
            if Author.exists_by_mail_address(substance.get("mail_address")):
                raise AlreadyRegisteredError(None)

        author.author_name = author_name
        author.mail_address = mail_address
        author.valid = valid
        author.put()
Exemplo n.º 2
0
 def test_to_hash(self):
     author = Author(
         mail_address="*****@*****.**",
         author_name="test user",
         password="******",
     )
     author_key = author.put()
     author.to_hash()
     self.assertEqual(1, 1)
Exemplo n.º 3
0
    def create(cls, substance):
        def _validate(substance):
            if not substance:
                return False
            return True

        if not _validate(substance):
            raise IllegalRequestError(None)

        author_id = substance.get("author_id")
        author_key = Author.get_key_by_id(author_id)

        category_id = substance.get("category_id")
        category_key = Category.get_key_by_id(category_id)

        kit = Kit(
            id=Kit.make_kit_id_hash(),
            kit_name=substance.get("kit_name"),
            author=author_key,
            category=category_key,
            tags=Kit.sanitize_tags(substance.get("tags")),
            description=substance.get("description"),
        )
        if substance.get("kit_file"):
            kit.kit_file_id = KitLogic._store_to_blobstore(substance.get("kit_file"))
        kit.put()
        return True
Exemplo n.º 4
0
    def _authenticated(cls, credential):
        author_id = credential.get("author_id")
        token = credential.get("token")

        if not KitProtectionProxy._validate(credential):
            raise IllegalRequestError(None)
        if not Author.is_login(author_id, token):
            raise IllegalAccessError(None)
Exemplo n.º 5
0
    def read(cls, substance):
        author_id = substance.get("author_id")

        if not author_id:
            raise IllegalRequestError(None)

        author = Author.get_by_id(author_id)
        if not author:
            raise NoDataError(None)
        return author.to_hash()
Exemplo n.º 6
0
    def release_provisional(cls, substance):
        author_id = substance.get("author_id")

        if not author_id:
            raise IllegalRequestError(None)

        author = Author.get_by_id(author_id)
        if not author:
            raise NoDataError(None)
        author.provisional = False
        author.put()
Exemplo n.º 7
0
    def update_password(cls, substance):
        def _validate(substance):
            if not substance:
                return False
            if not substance.get("author_id"):
                return False
            if not substance.get("password"):
                return False
            return True

        author_id = substance.get("author_id")
        password = substance.get("password")

        if not _validate(substance):
            raise IllegalRequestError(None)

        author = Author.get_by_id(author_id)
        if not author:
            raise NoDataError(None)
        author.password = Author.make_password_hash(password)
        author.put()
Exemplo n.º 8
0
    def create(cls, substance):
        def _validate(substance):
            if not substance:
                return False
            if not substance.get("author_name"):
                return False
            if not substance.get("mail_address"):
                return False
            if not substance.get("password"):
                return False
            return True

        if not _validate(substance):
            raise IllegalRequestError(None)
        if Author.exists_by_mail_address(substance.get("mail_address")):
            raise AlreadyRegisteredError(None)

        author = Author(
            id=Author.make_author_id_hash(),
            author_name=substance.get("author_name"),
            password=Author.make_password_hash(substance.get("password")),
            mail_address=substance.get("mail_address")
        )
        author.put()
        return True
Exemplo n.º 9
0
 def list(cls, substance):
     kit_list = []
     author_id = substance.get("author_id")
     category_id = substance.get("category_id")
     tags = substance.get("tags")
     if author_id:
         author_key = Author.get_key_by_id(author_id)
         if author_key:
             kit_list = [kit.to_hash_short() for kit in Kit.query(Kit.author == author_key)]
     elif category_id:
         category_key = Category.get_key_by_id(category_id)
         if category_key:
             kit_list = [kit.to_hash_short() for kit in Kit.query(Kit.category == category_key, True == Kit.valid)]
     elif tags:
         kit_list = [
             kit.to_hash_short() for kit in Kit.query(Kit.tags.IN(Kit.sanitize_tags(tags)), True == Kit.valid)
         ]
     else:
         kit_list = [kit.to_hash_short() for kit in Kit.query(True == Kit.valid)]
     return dict(items=kit_list)
Exemplo n.º 10
0
    def authentication(cls, substance):
        def _validate(substance):
            if not substance:
                return False
            if not substance.get("author_id"):
                return False
            if not substance.get("password"):
                return False
            return True

        mail_address = substance.get("mail_address")
        password = substance.get("password")

        if not _validate(substance):
            raise IllegalRequestError(None)

        token = Author.login(mail_address, password)
        if token:
            result = True
        else:
            result = False
        return dict(token=token, result=result)
Exemplo n.º 11
0
 def list(cls):
     author_list = [author.to_hash() for author in Author.query()]
     return dict(items=author_list)