Пример #1
0
 def getAccount(sessionToken):
     session = ReadOnlyAccess.getEntityCopy(Session, sessionToken)
     if session is None:
         return False, None
     if SessionUtility.isExpired(session):
         return False, None
     return True, ReadOnlyAccess.getEntityListCopy(Account, {"username": session.username})[0]
Пример #2
0
 def allowOwnerOf(self, cEntity, accountField, entityId):
     entity = ReadOnlyAccess.getEntityCopy(cEntity, entityId)
     if entity is not None:
         accountId = getattr(entity, accountField)
         if accountId == self.account.id:
             self.passed = True
     return self
Пример #3
0
 def validateUpdate(image):
     errors = []
     if PersistenceValidator.checkExists(Image, image.id):
         original = ReadOnlyAccess.getEntityCopy(Image, image.id)
     else:
         original = Image()
         errors.append(PersistenceValidator.entityDoesNotExist("Image", "id", image.id))
     return BaseValidator.getValidationMessage(ImageValidator.checkUniqueness(errors, image, original))
Пример #4
0
 def validateDelete(rentalId):
     errors = RentalValidator.validateRead(rentalId)
     rental = ReadOnlyAccess.getEntityCopy(Rental, rentalId)
     if Date.after(Date.toDate(rental.end),
                   Date.now()) and rental.status == RentlStatus.CONFIRMED:
         errors.append(PersistenceValidator.entityActive(
             "Rental", rentalId))
     return BaseValidator.getValidationMessage(errors)
Пример #5
0
 def validateUpdate(account):
     errors = []
     if PersistenceValidator.checkExists(Account, account.id):
         original = ReadOnlyAccess.getEntityCopy(Account, account.id)
     else:
         original = Account()
         errors.append(PersistenceValidator.entityDoesNotExist("Account", "id", account.id))
     return BaseValidator.getValidationMessage(AccountValidator.checkUniqueness(errors, account, original))
Пример #6
0
 def read(rentalId):
     # Validate in persistence level
     validatorResponse = RentalValidator.validateRead(rentalId)
     if FieldKey.ERROR in validatorResponse:
         return validatorResponse
     # Read Entity
     rental = ReadOnlyAccess.getEntityCopy(Rental, rentalId)
     # Return Result
     return {FieldKey.SUCCESS: rental}
Пример #7
0
 def validateRead(propertyId, imageId):
     errors = []
     if not PersistenceValidator.checkExists(Image, imageId):
         errors.append(PersistenceValidator.entityDoesNotExist("Image", "id", imageId))
     if not PersistenceValidator.checkExists(Property, propertyId):
         errors.append(PersistenceValidator.entityDoesNotExist("Property", "id", propertyId))
     if not ReadOnlyAccess.getEntityCopy(Image, imageId).propertyId == propertyId:
         errors.append(linkedDomainNotFoundError("Property", "Image", propertyId, imageId))
     return BaseValidator.getValidationMessage(errors)
Пример #8
0
 def read(propertyId, imageId):
     # Validate in persistence level
     validatorResponse = ImageValidator.validateRead(propertyId, imageId)
     if FieldKey.ERROR in validatorResponse:
         return validatorResponse
     # Create and process Tasks
     property = ReadOnlyAccess.getEntityCopy(Property, propertyId)
     # Return Result
     path = FileSystemUtil.getPath("images", property.ownerId)
     return os.path.join(path, imageId + ".jpg"), 'image/jpg'
Пример #9
0
 def remove(propertyId, imageId):
     # Validate in persistence level
     validatorResponse = ImageValidator.validateDelete(propertyId, imageId)
     if FieldKey.ERROR in validatorResponse:
         return validatorResponse
     # Get return copy, before delete
     image = ReadOnlyAccess.getEntityCopy(Image, imageId)
     property = ReadOnlyAccess.getEntityCopy(Property, propertyId)
     # Create and process Tasks
     processor = TaskProcessor()
     processor.add(
         RemoveFromFileSystemTask("images", property.ownerId, imageId,
                                  "jpg"))
     processor.add(DetachForeignKeyTask(Property, "mainImageId", imageId))
     processor.add(DeleteEntityTask(Image, imageId))
     processor.add(FlushDirectoryTask("images", []))
     processor.process()
     # Return Result
     return {FieldKey.SUCCESS: image}
Пример #10
0
 def read(customerId, viewingId):
     # Validate in persistence level
     validatorResponse = ViewingValidator.validateRead(
         customerId, viewingId)
     if FieldKey.ERROR in validatorResponse:
         return validatorResponse
     # Create and process Tasks
     viewing = ReadOnlyAccess.getEntityCopy(Viewing, viewingId)
     # Return Result
     return {FieldKey.SUCCESS: viewing}
Пример #11
0
 def validateUpdate(viewing):
     errors = []
     if PersistenceValidator.checkExists(Viewing, viewing.id):
         original = ReadOnlyAccess.getEntityCopy(Viewing, viewing.id)
     else:
         original = Viewing()
         errors.append(
             PersistenceValidator.entityDoesNotExist(
                 "Viewing", "id", viewing.id))
     return BaseValidator.getValidationMessage(
         ViewingValidator.checkUniqueness(errors, viewing, original))
Пример #12
0
 def validateUpdate(rental):
     errors = []
     if PersistenceValidator.checkExists(Rental, rental.id):
         original = ReadOnlyAccess.getEntityCopy(Rental, rental.id)
     else:
         original = Rental()
         errors.append(
             PersistenceValidator.entityDoesNotExist(
                 "Rental", "id", rental.id))
     return BaseValidator.getValidationMessage(
         RentalValidator.checkUniqueness(errors, rental, original))
Пример #13
0
 def validateUpdate(ownerId, property):
     errors = []
     if PersistenceValidator.checkExists(Property, property.id):
         original = ReadOnlyAccess.getEntityCopy(Property, property.id)
         PropertyValidator.checkOwner(errors, ownerId, property.id)
     else:
         original = Property()
         errors.append(
             PersistenceValidator.entityDoesNotExist(
                 "Property", "id", property.id))
     return BaseValidator.getValidationMessage(
         PropertyValidator.checkUniqueness(errors, property, original))
Пример #14
0
 def validateReadAll(ownerId):
     errors = []
     if not PersistenceValidator.checkExists(Account, ownerId):
         errors.append(
             PersistenceValidator.entityDoesNotExist(
                 "Owner", "id", ownerId))
     elif not ReadOnlyAccess.getEntityCopy(
             Account, ownerId).type == AccountType.OWNER:
         errors.append(
             PersistenceValidator.entityDoesNotExist(
                 "Owner", "id", ownerId))
     return BaseValidator.getValidationMessage(errors)
Пример #15
0
 def update(updatedImage):
     # Validate in persistence level
     validatorResponse = ImageValidator.validateUpdate(updatedImage)
     if FieldKey.ERROR in validatorResponse:
         return validatorResponse
     # Create and process Tasks
     processor = TaskProcessor()
     processor.add(
         UpdateEntityTask(Image, ImageService.mergeImages, updatedImage))
     processor.process()
     # Return Result
     image = ReadOnlyAccess.getEntityCopy(Image, updatedImage.id)
     return {FieldKey.SUCCESS: image}
Пример #16
0
 def validateCreate(property):
     errors = []
     if not PersistenceValidator.checkExists(Account, property.ownerId):
         errors.append(
             PersistenceValidator.entityDoesNotExist(
                 "Owner", "id", property.ownerId))
     elif not ReadOnlyAccess.getEntityCopy(
             Account, property.ownerId).type == AccountType.OWNER:
         errors.append(
             PersistenceValidator.entityDoesNotExist(
                 "Owner", "id", property.ownerId))
     return BaseValidator.getValidationMessage(
         PropertyValidator.checkUniqueness(errors, property))
Пример #17
0
 def delete(customerId, viewingId):
     # Validate in persistence level
     validatorResponse = ViewingValidator.validateDelete(
         customerId, viewingId)
     if FieldKey.ERROR in validatorResponse:
         return validatorResponse
     # Get return copy, before delete
     viewing = ReadOnlyAccess.getEntityCopy(Viewing, viewingId)
     # Create and process Tasks
     processor = TaskProcessor()
     processor.add(DeleteEntityTask(Viewing, viewingId))
     processor.process()
     # Return Result
     return {FieldKey.SUCCESS: viewing}
Пример #18
0
 def update(updatedRental):
     # Validate in persistence level
     validatorResponse = RentalValidator.validateUpdate(updatedRental)
     if FieldKey.ERROR in validatorResponse:
         return validatorResponse
     # Create and process Tasks
     processor = TaskProcessor()
     processor.add(
         UpdateEntityTask(Rental, RentalService.mergeRentals,
                          updatedRental))
     processor.process()
     # Return Result
     rental = ReadOnlyAccess.getEntityCopy(Rental, updatedRental.id)
     return {FieldKey.SUCCESS: rental}
Пример #19
0
 def update(updatedViewing):
     # Validate in persistence level
     validatorResponse = ViewingValidator.validateUpdate(updatedViewing)
     if FieldKey.ERROR in validatorResponse:
         return validatorResponse
     # Create and process Tasks
     processor = TaskProcessor()
     processor.add(
         UpdateEntityTask(Viewing, ViewingService.mergeViewings,
                          updatedViewing))
     processor.process()
     # Return Result
     viewing = ReadOnlyAccess.getEntityCopy(Viewing, updatedViewing.id)
     return {FieldKey.SUCCESS: viewing}
Пример #20
0
 def validateCreate(username, password):
     errors = []
     accounts = ReadOnlyAccess.getEntityListCopy(Account,
                                                 {"username": username})
     if len(accounts) > 1:
         raise Exception("Multiple Accounts with Username: " + username)
     elif len(accounts) < 1:
         errors.append(SessionValidator.incorrectUsernameOrPassword())
     else:
         credential = ReadOnlyAccess.getEntityCopy(Credential,
                                                   accounts[0].id)
         if credential is None or not PasswordUtility.checkHashedPassword(
                 password, credential.password):
             errors.append(SessionValidator.incorrectUsernameOrPassword())
     return BaseValidator.getValidationMessage(errors)
Пример #21
0
 def add(image):
     # Validate in persistence level
     validatorResponse = ImageValidator.validateCreate(image)
     if FieldKey.ERROR in validatorResponse:
         return validatorResponse
     # Get Property Info
     property = ReadOnlyAccess.getEntityCopy(Property, image.propertyId)
     # Create and process Tasks
     processor = TaskProcessor()
     processor.add(
         SaveToFileSystemTask("images", property.ownerId, image.id,
                              image.file, "jpg"))
     processor.add(SaveNewEntityTask(image))
     processor.process()
     # Return Result
     return {FieldKey.SUCCESS: image}
Пример #22
0
 def validateRead(customerId, viewingId):
     errors = []
     if not PersistenceValidator.checkExists(Account, customerId):
         errors.append(
             PersistenceValidator.entityDoesNotExist(
                 "Customer", "id", customerId))
     if not PersistenceValidator.checkExists(Viewing, viewingId):
         errors.append(
             PersistenceValidator.entityDoesNotExist(
                 "Viewing", "id", viewingId))
     if not ReadOnlyAccess.getEntityCopy(
             Viewing, viewingId).customerId == customerId:
         errors.append(
             PersistenceValidator.linkedDomainNotFoundError(
                 "Customer", "Viewing", customerId, viewingId))
     return errors
Пример #23
0
 def validateCreate(viewing):
     errors = []
     if not PersistenceValidator.checkExists(Account, viewing.customerId):
         errors.append(
             PersistenceValidator.entityDoesNotExist(
                 "Customer", "id", viewing.customerId))
     elif not ReadOnlyAccess.getEntityCopy(
             Account, viewing.customerId).type == AccountType.CUSTOMER:
         errors.append(
             PersistenceValidator.entityDoesNotExist(
                 "Customer", "id", viewing.customerId))
     if not PersistenceValidator.checkExists(Property, viewing.propertyId):
         errors.append(
             PersistenceValidator.entityDoesNotExist(
                 "Property", "id", viewing.propertyId))
     return BaseValidator.getValidationMessage(
         ViewingValidator.checkUniqueness(errors, viewing.propertyId))
Пример #24
0
    def setMain(propertyId, imageId):
        # Validate in persistence level
        validatorResponse = ImageValidator.validateSetMain(propertyId, imageId)
        if FieldKey.ERROR in validatorResponse:
            return validatorResponse
        # Create Updated Property
        updatedProperty = Property()
        updatedProperty.id = propertyId
        updatedProperty.mainImageId = imageId
        # Create and process Tasks
        processor = TaskProcessor()
        processor.add(
            UpdateEntityTask(Property, PropertyService.mergeProperties,
                             updatedProperty))
        processor.process()

        property = ReadOnlyAccess.getEntityCopy(Property, propertyId)
        return {FieldKey.SUCCESS: property}
Пример #25
0
 def validateCreate(rental):
     errors = []
     if not PersistenceValidator.checkExists(Account, rental.customer):
         errors.append(
             PersistenceValidator.entityDoesNotExist(
                 "Customer", "id", rental.customer))
     elif not ReadOnlyAccess.getEntityCopy(
             Account, rental.customer).type == AccountType.CUSTOMER:
         errors.append(
             PersistenceValidator.entityDoesNotExist(
                 "Customer", "id", rental.customer))
     if not PersistenceValidator.checkExists(Property, rental.property):
         errors.append(
             PersistenceValidator.entityDoesNotExist(
                 "Property", "id", rental.property))
     if not PersistenceValidator.checkExists(Property, rental.property):
         errors.append(
             PersistenceValidator.entityDoesNotExist(
                 "Property", "id", rental.property))
     return BaseValidator.getValidationMessage(
         RentalValidator.checkUniqueness(errors, rental))
Пример #26
0
 def checkOwner(errors, ownerId, propertyId):
     if not ReadOnlyAccess.getEntityCopy(Property,
                                         propertyId).ownerId == ownerId:
         errors.append(
             PersistenceValidator.linkedDomainNotFoundError(
                 "Owner", "Property", ownerId, propertyId))